Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colexec: fix type schema for LEFT SEMI and LEFT ANTI joins #48659

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/sql/colexec/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,12 @@ func NewColOperator(
}
result.ColumnTypes = make([]*types.T, len(leftTypes)+len(rightTypes))
copy(result.ColumnTypes, leftTypes)
copy(result.ColumnTypes[len(leftTypes):], rightTypes)
if core.HashJoiner.Type == sqlbase.JoinType_LEFT_SEMI ||
core.HashJoiner.Type == sqlbase.JoinType_LEFT_ANTI {
result.ColumnTypes = result.ColumnTypes[:len(leftTypes):len(leftTypes)]
} else {
copy(result.ColumnTypes[len(leftTypes):], rightTypes)
}

if !core.HashJoiner.OnExpr.Empty() && core.HashJoiner.Type == sqlbase.JoinType_INNER {
if err = result.planAndMaybeWrapOnExprAsFilter(ctx, flowCtx, core.HashJoiner.OnExpr, streamingMemAccount, processorConstructor); err != nil {
Expand Down Expand Up @@ -945,7 +950,12 @@ func NewColOperator(
result.ToClose = append(result.ToClose, mj.(IdempotentCloser))
result.ColumnTypes = make([]*types.T, len(leftTypes)+len(rightTypes))
copy(result.ColumnTypes, leftTypes)
copy(result.ColumnTypes[len(leftTypes):], rightTypes)
if core.MergeJoiner.Type == sqlbase.JoinType_LEFT_SEMI ||
core.MergeJoiner.Type == sqlbase.JoinType_LEFT_ANTI {
result.ColumnTypes = result.ColumnTypes[:len(leftTypes):len(leftTypes)]
} else {
copy(result.ColumnTypes[len(leftTypes):], rightTypes)
}

if onExpr != nil {
if err = result.planAndMaybeWrapOnExprAsFilter(ctx, flowCtx, *onExpr, streamingMemAccount, processorConstructor); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/merge_join
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ SELECT * FROM t44798_0 NATURAL JOIN t44798_1
----
0
2

# Regression test for batch type schema prefix mismatch after LEFT ANTI join
# (48622).
statement ok
CREATE TABLE l (l INT PRIMARY KEY); INSERT INTO l VALUES (1), (2);
CREATE TABLE r (r INT PRIMARY KEY); INSERT INTO r VALUES (1)

query IB
SELECT *, true FROM (SELECT l FROM l WHERE l NOT IN (SELECT r FROM r))
----
2 true