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

Fix anti-join correctess bug #2623

Merged
merged 1 commit into from
Aug 7, 2024
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
30 changes: 30 additions & 0 deletions enginetest/join_op_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@ var DefaultJoinOpTests = []joinOpTest{
},
},
},
{
name: "empty join tests",
setup: [][]string{
setup.MydbData[0],
{
"CREATE table xy (x int primary key, y int);",
"CREATE table uv (u int primary key, v int);",
"insert into xy values (1,0), (2,1), (0,2), (3,3);",
"insert into uv values (0,1), (1,1), (2,2), (3,2);",
},
},
tests: []JoinOpTests{
{
Query: "select * from xy where y-1 = (select u from uv where u = 4);",
Expected: []sql.Row{},
},
{
Query: "select * from xy where x = 1 and x != (select u from uv where u = 4);",
Expected: []sql.Row{{1, 0}},
},
{
Query: "select * from xy where x = 1 and x not in (select u from uv where u = 4);",
Expected: []sql.Row{{1, 0}},
},
{
Query: "select * from xy where x = 1 and not exists (select u from uv where u = 4);",
Expected: []sql.Row{{1, 0}},
},
},
},
{
name: "issue 5633, nil comparison in merge join",
setup: [][]string{
Expand Down
18 changes: 14 additions & 4 deletions enginetest/join_planning_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,24 @@ order by 1;`,
},
tests: []JoinPlanTest{
{
q: "select * from xy where y-1 = (select u from uv limit 1 offset 5);",
q: "select * from xy where y-1 = (select u from uv where u = 4);",
types: []plan.JoinType{plan.JoinTypeSemi},
exp: []sql.Row{},
},
{
q: "select * from xy where x != (select u from uv limit 1 offset 5);",
types: []plan.JoinType{plan.JoinTypeAnti},
exp: []sql.Row{},
q: "select * from xy where x = 1 and x != (select u from uv where u = 4);",
types: []plan.JoinType{plan.JoinTypeLeftOuter},
exp: []sql.Row{{1, 0}},
},
{
q: "select * from xy where x = 1 and x not in (select u from uv where u = 4);",
types: []plan.JoinType{plan.JoinTypeLeftOuter},
exp: []sql.Row{{1, 0}},
},
{
q: "select * from xy where x = 1 and not exists (select u from uv where u = 4);",
types: []plan.JoinType{plan.JoinTypeLeftOuter},
exp: []sql.Row{{1, 0}},
},
},
},
Expand Down
8 changes: 0 additions & 8 deletions sql/rowexec/join_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func (i *existsIter) Next(ctx *sql.Context) (sql.Row, error) {
}
left = i.parentRow.Append(r)
rIter, err = i.b.Build(ctx, i.secondaryProvider, left)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -315,13 +314,6 @@ func (i *existsIter) Next(ctx *sql.Context) (sql.Row, error) {
if i.typ.IsSemi() {
// reset iter, no match
nextState = esIncLeft
} else if !i.rightIterNonEmpty && !isTrueLit(i.cond) {
// ANTI_JOIN with empty RHS is subject to special cases,
// the first two are a valid match.
// 1) If we matched no rows but rows were returned
// 2) No match and no rows returned, EXISTS check
// 3) No match and no rows returned, IN check
return nil, io.EOF
} else {
nextState = esRet
}
Expand Down
Loading