diff --git a/compiler/optimizer/optimizer.go b/compiler/optimizer/optimizer.go index ebbc6f27e..a6c8e198d 100644 --- a/compiler/optimizer/optimizer.go +++ b/compiler/optimizer/optimizer.go @@ -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:]) diff --git a/compiler/ztests/sql/join-filter-pullup.yaml b/compiler/ztests/sql/join-filter-pullup.yaml index 39a55cd24..aa9e07bc6 100644 --- a/compiler/ztests/sql/join-filter-pullup.yaml +++ b/compiler/ztests/sql/join-filter-pullup.yaml @@ -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: @@ -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