diff --git a/pkg/sql/opt/norm/join_funcs.go b/pkg/sql/opt/norm/join_funcs.go index aa70eb101503..7bdd1f9f8f4e 100644 --- a/pkg/sql/opt/norm/join_funcs.go +++ b/pkg/sql/opt/norm/join_funcs.go @@ -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