Skip to content

Commit 60f97cd

Browse files
committed
rm push on anti and semi join
1 parent fff320b commit 60f97cd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

enginetest/join_planning_tests.go

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

5353
var JoinPlanningTests = []joinPlanScript{
54+
{
55+
// https://github.com/dolthub/dolt/issues/9977
56+
name: "filters with anti and semi joins",
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+
// When NOT IN and IN are combined, the IN filter should not be pushed into the Anti join
64+
q: "select * from xy where x > 0 and x not in (select 999) and x in (select 1 union select 2) order by x",
65+
types: []plan.JoinType{plan.JoinTypeLeftOuter},
66+
exp: []sql.Row{
67+
{1, 0},
68+
{2, 1},
69+
},
70+
},
71+
{
72+
q: "select * from xy where x > 0 and x not in (select 999) and x in (select 888 union select 777)",
73+
types: []plan.JoinType{plan.JoinTypeLeftOuter},
74+
exp: []sql.Row{},
75+
},
76+
},
77+
},
5478
{
5579
name: "filter pushdown through join uppercase name",
5680
setup: []string{

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.IsSemi() && !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)