Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
57524: opt: fix bug in ExtractJoinEqualities rule r=RaduBerinde a=RaduBerinde

If the join is semi/anti, this rule generates an incorrect projection
(which passes through columns not in input).

Similar to cockroachdb#57501. Other normalization rules prune the columns so this
doesn't lead to a bad outcome (at least in most cases).

I will add an assertion in CheckExpr for this condition in a separate
PR - without this fix, the assertion fires on an existing test.

Release note: None

Co-authored-by: Radu Berinde <[email protected]>
  • Loading branch information
craig[bot] and RaduBerinde committed Dec 4, 2020
2 parents 3c740d0 + 7614e3f commit aa69b42
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/sql/opt/norm/join_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,13 @@ func (c *CustomFuncs) ExtractJoinEquality(
)

// Project away the synthesized columns.
return c.f.ConstructProject(join, memo.EmptyProjectionsExpr, leftCols.Union(rightCols))
outputCols := leftCols
if joinOp != opt.SemiJoinOp && joinOp != opt.AntiJoinOp {
// Semi/Anti join only produce the left side columns. All other join types
// produce columns from both sides.
outputCols = leftCols.Union(rightCols)
}
return c.f.ConstructProject(join, memo.EmptyProjectionsExpr, outputCols)
}

// CommuteJoinFlags returns a join private for the commuted join (where the left
Expand Down

0 comments on commit aa69b42

Please sign in to comment.