Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions compiler/optimizer/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,12 @@ func pullupExpr(alias string, expr dag.Expr) (dag.Expr, bool) {
}
var c dag.Expr
var this *dag.ThisExpr
for _, e := range []dag.Expr{e.RHS, e.LHS} {
if isConst(e) {
c = e
continue
}
if t, ok := e.(*dag.ThisExpr); ok && this == nil && len(t.Path) > 1 && t.Path[0] == alias {
this = t
continue
}
if t, ok := e.LHS.(*dag.ThisExpr); ok && isConst(e.RHS) {
this, c = t, e.RHS
} else if t, ok := e.RHS.(*dag.ThisExpr); ok && isConst(e.LHS) {
this, c = t, e.LHS
}
if c == nil || this == nil || len(this.Path) < 1 || this.Path[0] != alias {
return nil, false
}
path := slices.Clone(this.Path[1:])
Expand Down
2 changes: 2 additions & 0 deletions compiler/ztests/sql/join-filter-pullup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ script: |
and a1 in |[1,5,9]|
and a3 in (1,5,[9,11])
and (1 == a2 or a2 == 2)
and 1 == 1
"

outputs:
Expand Down Expand Up @@ -51,5 +52,6 @@ outputs:
| cross join as {left,right}
)
| cross join as {left,right}
| where 1==1
| values {a1:left.a1,a2:right.left.a2,a3:right.right.a3}
| output main