Skip to content

Commit 679d57c

Browse files
authored
Merge pull request #3275 from dolthub/elian/9977
dolthub/dolt#9977: Prevent filter pushdown for Anti joins for `NOT IN`
2 parents fa2db67 + 9ec0ff4 commit 679d57c

File tree

3 files changed

+114
-61
lines changed

3 files changed

+114
-61
lines changed

enginetest/join_planning_tests.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ type joinPlanScript struct {
5151
}
5252

5353
var JoinPlanningTests = []joinPlanScript{
54+
{
55+
// https://github.com/dolthub/dolt/issues/9977
56+
name: "no filter pushdown through anti join",
57+
setup: []string{
58+
"CREATE table xy (x int, y int, primary key(x,y));",
59+
"insert into xy values (1,0), (2,1), (0,2), (3,3);",
60+
},
61+
tests: []JoinPlanTest{
62+
{
63+
q: "select * from xy where x > 0 and x not in (select 999 union select 2 union select 3) order by x",
64+
types: nil,
65+
exp: []sql.Row{
66+
{1, 0},
67+
},
68+
},
69+
{
70+
q: "select * from xy where x > 0 and x not in (select 999) and x in (select 888 union select 777)",
71+
types: []plan.JoinType{plan.JoinTypeLeftOuter},
72+
exp: []sql.Row{},
73+
},
74+
},
75+
},
5476
{
5577
name: "filter pushdown through join uppercase name",
5678
setup: []string{

enginetest/queries/tpch_plans.go

Lines changed: 91 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sql/analyzer/pushdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func updateFilterNode(ctx *sql.Context, a *Analyzer, node *plan.Filter, filters
326326
}
327327

328328
// push filters into joinChild
329-
if joinChild, ok := node.Child.(*plan.JoinNode); ok && !joinChild.Op.IsOuter() {
329+
if joinChild, ok := node.Child.(*plan.JoinNode); ok && !joinChild.Op.IsOuter() && !joinChild.Op.IsAnti() {
330330
a.Log("pushing filters into join node")
331331
if joinChild.Op.IsCross() {
332332
return plan.NewInnerJoin(joinChild.Left(), joinChild.Right(), expression.JoinAnd(unhandled...))

0 commit comments

Comments
 (0)