Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14636,6 +14636,27 @@ select * from t1 except (
},
},
},
{
// https://github.com/dolthub/dolt/issues/10243
Dialect: "mysql",
Name: "OR filters are simplified to correct type",
SetUpScript: []string{
"create table t0(c1 boolean)",
"insert into t0 values (true)",
"create table t1(c1 int)",
"insert into t1 values (2)",
},
Assertions: []ScriptTestAssertion{
{
Query: "select 1 from t0 where (19 or 's') != (7 != t0.c1);",
Expected: []sql.Row{},
},
{
Query: "SELECT * FROM t1 WHERE NOT EXISTS (SELECT 1 FROM t0 WHERE ((((19)OR('s')))!=(((7)!=(t0.c1)))));",
Expected: []sql.Row{{2}},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
8 changes: 4 additions & 4 deletions sql/analyzer/optimization_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
), transform.NewTree, nil
case *expression.Or:
if isTrue(ctx, e.LeftChild) {
return e.LeftChild, transform.NewTree, nil
return expression.NewLiteral(true, types.Boolean), transform.NewTree, nil
}

if isTrue(ctx, e.RightChild) {
return e.RightChild, transform.NewTree, nil
return expression.NewLiteral(true, types.Boolean), transform.NewTree, nil
}

if isFalse(ctx, e.LeftChild) && types.IsBoolean(e.RightChild.Type()) {
Expand All @@ -256,11 +256,11 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
return e, transform.SameTree, nil
case *expression.And:
if isFalse(ctx, e.LeftChild) {
return e.LeftChild, transform.NewTree, nil
return expression.NewLiteral(false, types.Boolean), transform.NewTree, nil
}

if isFalse(ctx, e.RightChild) {
return e.RightChild, transform.NewTree, nil
return expression.NewLiteral(false, types.Boolean), transform.NewTree, nil
}

if isTrue(ctx, e.LeftChild) && types.IsBoolean(e.RightChild.Type()) {
Expand Down