diff --git a/compiler/optimizer/join.go b/compiler/optimizer/join.go index 339ae2567..e990267c2 100644 --- a/compiler/optimizer/join.go +++ b/compiler/optimizer/join.go @@ -150,6 +150,8 @@ func equiJoinKeyExprs(e dag.Expr, leftAlias, rightAlias string) (left, right dag if lhsFirst != leftAlias || rhsFirst != rightAlias { return nil, nil, false } + // This next step will mutate the input expression, do a copy here. + lhs, rhs = dag.CopyExpr(lhs), dag.CopyExpr(rhs) stripFirstThisPathComponent(lhs) stripFirstThisPathComponent(rhs) return lhs, rhs, true diff --git a/runtime/ztests/op/join-expr.yaml b/runtime/ztests/op/join-expr.yaml index b85df0f35..236aedacd 100644 --- a/runtime/ztests/op/join-expr.yaml +++ b/runtime/ztests/op/join-expr.yaml @@ -40,3 +40,17 @@ outputs: {a:1::int32,s:"a",b:6::int32} {a:2::int32,s:"B",b:6::int32} {a:3::int32,s:"c",b:error("missing")} + +--- + +# Issue #6361. +spq: | + values {a:1,x:5},{a:2,x:6} + | join ( + values {b:1,y:7},{b:2,y:4} + ) as {l,r} on l.a=r.b and l.x > r.y + +vector: true + +output: | + {l:{a:2,x:6},r:{b:2,y:4}}