Skip to content

Commit 7b8fb20

Browse files
authored
Merge pull request #3302 from dolthub/angela/nullnotexists
Wrap nullable hoisted filter in IsTrue
2 parents 83d2fda + d90196f commit 7b8fb20

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

enginetest/queries/script_queries.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13439,6 +13439,20 @@ select * from t1 except (
1343913439
},
1344013440
},
1344113441
},
13442+
{
13443+
// https://github.com/dolthub/dolt/issues/10070
13444+
Name: "NOT EXISTS with nullable filter",
13445+
SetUpScript: []string{
13446+
"CREATE TABLE t0(c0 INT , c1 INT);",
13447+
"INSERT INTO t0(c0, c1) VALUES (1, -2);",
13448+
},
13449+
Assertions: []ScriptTestAssertion{
13450+
{
13451+
Query: `SELECT * FROM t0 WHERE NOT EXISTS (SELECT 1 FROM (SELECT 1) alias0 WHERE (CASE -1 WHEN t0.c1 THEN false END));`,
13452+
Expected: []sql.Row{{1, -2}},
13453+
},
13454+
},
13455+
},
1344213456
}
1344313457

1344413458
var SpatialScriptTests = []ScriptTest{

sql/analyzer/hoist_filters.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ func recurseSubqueryForOuterFilters(n sql.Node, a *Analyzer, corr sql.ColSet) (s
131131
newCorr = newCorr.Union(outOfScope)
132132
keepFilters = append(keepFilters, e)
133133
} else {
134-
// nothing tethers the subquery to this scope
134+
// nothing tethers the subquery or filter expression to this scope
135+
if sq == nil && e.IsNullable() {
136+
// If a filter expression has been hoisted out of a subquery, it needs to be made not nullable. This
137+
// is because filters that evaluate to null in an Exists or In subquery are treated the same as
138+
// false.
139+
e = expression.NewIsTrue(e)
140+
}
135141
hoistFilters = append(hoistFilters, e)
136142
}
137143
}

0 commit comments

Comments
 (0)