Skip to content
12 changes: 12 additions & 0 deletions enginetest/join_op_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,18 @@ SELECT SUM(x) FROM xy WHERE x IN (
},
},
},
{
name: "where not exists",
setup: [][]string{
setup.XyData[0],
},
tests: []JoinOpTests{
{
Query: `select * from xy_hasnull x where not exists(select 1 from ab_hasnull a where a.b = x.y)`,
Expected: []sql.Row{{1, 0}, {3, nil}},
},
},
},
{
name: "multi-column merge join",
setup: [][]string{
Expand Down
46,544 changes: 22,664 additions & 23,880 deletions enginetest/queries/imdb_plans.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions enginetest/queries/integration_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions enginetest/queries/query_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions enginetest/queries/tpch_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion sql/analyzer/indexed_joins.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ func convertAntiToLeftJoin(m *memo.Memo) error {
rightGrp := m.MemoizeProject(nil, anti.Right, projectExpressions)

// join is a new group
joinGrp := m.MemoizeLeftJoin(nil, anti.Left, rightGrp, plan.JoinTypeLeftOuterExcludeNulls, anti.Filter)
joinType := plan.JoinTypeLeftOuter
if anti.Op.IsExcludeNulls() {
joinType = plan.JoinTypeLeftOuterExcludeNulls
}
joinGrp := m.MemoizeLeftJoin(nil, anti.Left, rightGrp, joinType, anti.Filter)

// drop null projected columns on right table
nullFilters := make([]sql.Expression, len(nullify))
Expand Down
4 changes: 2 additions & 2 deletions sql/analyzer/unnest_exists_subqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func unnestExistSubqueries(ctx *sql.Context, scope *plan.Scope, a *Analyzer, fil
switch joinType {
case plan.JoinTypeAnti:
cond := expression.NewLiteral(true, types.Boolean)
ret = plan.NewAntiJoin(ret, s.inner, cond).WithComment(comment)
ret = plan.NewAntiJoinIncludingNulls(ret, s.inner, cond).WithComment(comment)
qFlags.Set(sql.QFlagInnerJoin)
case plan.JoinTypeSemi:
ret = plan.NewCrossJoin(ret, s.inner).WithComment(comment)
Expand All @@ -209,7 +209,7 @@ func unnestExistSubqueries(ctx *sql.Context, scope *plan.Scope, a *Analyzer, fil

switch joinType {
case plan.JoinTypeAnti:
ret = plan.NewAntiJoin(ret, s.inner, expression.JoinAnd(outerFilters...)).WithComment(comment)
ret = plan.NewAntiJoinIncludingNulls(ret, s.inner, expression.JoinAnd(outerFilters...)).WithComment(comment)
qFlags.Set(sql.QFlagInnerJoin)
case plan.JoinTypeSemi:
ret = plan.NewSemiJoin(ret, s.inner, expression.JoinAnd(outerFilters...)).WithComment(comment)
Expand Down
4 changes: 2 additions & 2 deletions sql/memo/join_order_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func (j *joinOrderBuilder) constructJoin(
rel = &LeftJoin{b}
case plan.JoinTypeSemi:
rel = &SemiJoin{b}
case plan.JoinTypeAnti:
case plan.JoinTypeAnti, plan.JoinTypeAntiIncludeNulls:
rel = &AntiJoin{b}
case plan.JoinTypeLateralInner, plan.JoinTypeLateralCross,
plan.JoinTypeLateralRight, plan.JoinTypeLateralLeft:
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func getOpIdx(e *edge) int {
return 1
case plan.JoinTypeSemi:
return 2
case plan.JoinTypeAnti:
case plan.JoinTypeAnti, plan.JoinTypeAntiIncludeNulls:
return 3
case plan.JoinTypeLeftOuter:
return 4
Expand Down
Loading
Loading