From 64829807e1a11245426696d767286f9e2fed796b Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Thu, 23 Oct 2025 16:52:36 -0700 Subject: [PATCH 1/2] optimizer.joinFilterPullup: fix panic on const const Closes #6318 --- compiler/optimizer/optimizer.go | 2 +- compiler/ztests/sql/join-filter-pullup.yaml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/optimizer/optimizer.go b/compiler/optimizer/optimizer.go index ebbc6f27e..ec6faf7b8 100644 --- a/compiler/optimizer/optimizer.go +++ b/compiler/optimizer/optimizer.go @@ -595,7 +595,7 @@ 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) { + if c == nil && isConst(e) { c = e continue } 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 From 4741b84d6d554cf66cd1667642de941054cc45ef Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Fri, 24 Oct 2025 12:25:05 -0700 Subject: [PATCH 2/2] feedback --- compiler/optimizer/optimizer.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/optimizer/optimizer.go b/compiler/optimizer/optimizer.go index ec6faf7b8..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 c == nil && 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:])