Skip to content

Commit e9c4668

Browse files
committed
add fix for const evals
1 parent 37976af commit e9c4668

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

enginetest/queries/script_queries.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,36 @@ type ScriptTestAssertion struct {
122122
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
123123
// the tests.
124124
var ScriptTests = []ScriptTest{
125+
{
126+
// https://github.com/dolthub/dolt/issues/9935
127+
Name: "Incorrect use of negation in AntiJoinIncludingNulls",
128+
SetUpScript: []string{
129+
"CREATE TABLE t0(c0 INT);",
130+
"INSERT INTO t0(c0) VALUES(1);",
131+
},
132+
Assertions: []ScriptTestAssertion{
133+
{
134+
Query: "SELECT * FROM t0 WHERE (! (1 || (EXISTS (SELECT 1))));",
135+
Expected: []sql.Row{},
136+
},
137+
{
138+
Query: "SELECT * FROM t0 WHERE (! (0 || (EXISTS (SELECT 1))));",
139+
Expected: []sql.Row{},
140+
},
141+
{
142+
Query: "SELECT * FROM t0 WHERE (! (0 || (EXISTS (SELECT 1 FROM t0 WHERE c0 = 2))));",
143+
Expected: []sql.Row{{1}},
144+
},
145+
{
146+
Query: "SELECT * FROM t0 WHERE (! (1 || (EXISTS (SELECT 1 FROM t0 WHERE c0 = 1))));",
147+
Expected: []sql.Row{},
148+
},
149+
{
150+
Query: "SELECT * FROM t0 WHERE (! (0 || (EXISTS (SELECT 1 FROM t0 WHERE c0 = 1))));",
151+
Expected: []sql.Row{},
152+
},
153+
},
154+
}
125155
{
126156
// https://github.com/dolthub/dolt/issues/9865
127157
Name: "Stored procedure containing a transaction does not return EOF",

sql/analyzer/unnest_exists_subqueries.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ func unnestExistSubqueries(ctx *sql.Context, scope *plan.Scope, a *Analyzer, fil
123123
var s *hoistSubquery
124124
var err error
125125

126+
if not, ok := f.(*expression.Not); ok {
127+
if lit, ok := not.Child.(*expression.Literal); ok {
128+
val, err := sql.ConvertToBool(ctx, lit.Value())
129+
if err != nil {
130+
// non-const
131+
} else if val {
132+
return plan.NewEmptyTableWithSchema(ret.Schema()), transform.NewTree, nil
133+
} else {
134+
continue // always true
135+
}
136+
}
137+
}
138+
126139
// match subquery expression
127140
joinType := plan.JoinTypeSemi
128141
var sq *plan.Subquery

0 commit comments

Comments
 (0)