Skip to content

Commit c036970

Browse files
committed
make equals in antijoins from not exists null safe
1 parent 2acc3ba commit c036970

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sql/analyzer/unnest_exists_subqueries.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ func unnestExistSubqueries(ctx *sql.Context, scope *plan.Scope, a *Analyzer, fil
209209

210210
switch joinType {
211211
case plan.JoinTypeAnti:
212+
outerFilters, _, err = transform.Exprs(outerFilters, func(e sql.Expression) (sql.Expression, transform.TreeIdentity, error) {
213+
if equals, ok := e.(*expression.Equals); ok {
214+
return equals.MakeNullSafe(), transform.NewTree, nil
215+
}
216+
return e, transform.SameTree, nil
217+
})
218+
if err != nil {
219+
return nil, transform.SameTree, err
220+
}
212221
ret = plan.NewAntiJoin(ret, s.inner, expression.JoinAnd(outerFilters...)).WithComment(comment)
213222
qFlags.Set(sql.QFlagInnerJoin)
214223
case plan.JoinTypeSemi:

sql/expression/comparison.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ func (e *Equals) ToComparer() (Comparer, error) {
408408
return e, nil
409409
}
410410

411+
// MakeNullSafe returns a new NullSafeEquals with the same children
412+
func (e *Equals) MakeNullSafe() *NullSafeEquals {
413+
return NewNullSafeEquals(e.LeftChild, e.RightChild)
414+
}
415+
411416
// NullSafeEquals is a comparison that checks an expression is equal to
412417
// another, where NULLs do not coalesce to NULL and two NULLs compare equal to
413418
// each other.

0 commit comments

Comments
 (0)