Skip to content

fix not equal conversions #2921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 1, 2025
27 changes: 27 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7831,6 +7831,33 @@ where
{123},
},
},
{
Query: "select * from t where i != (false or i);",
Expected: []sql.Row{
{123},
},
},
},
},
{
Name: "negative int limits",
Dialect: "mysql",
SetUpScript: []string{
"CREATE TABLE t(i8 tinyint, i16 smallint, i24 mediumint, i32 int, i64 bigint);",
"INSERT INTO t VALUES(-128, -32768, -8388608, -2147483648, -9223372036854775808);",
},
Assertions: []ScriptTestAssertion{
{
SkipResultCheckOnServerEngine: true,
Query: "SELECT -i8, -i16, -i24, -i32 from t;",
Expected: []sql.Row{
{128, 32768, 8388608, 2147483648},
},
},
{
Query: "SELECT -i64 from t;",
ExpectedErrStr: "BIGINT out of range for -9223372036854775808",
},
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions sql/analyzer/optimization_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
return e.RightChild, transform.NewTree, nil
}

if isFalse(e.LeftChild) {
if isFalse(e.LeftChild) && types.IsBoolean(e.RightChild.Type()) {
return e.RightChild, transform.NewTree, nil
}

if isFalse(e.RightChild) {
if isFalse(e.RightChild) && types.IsBoolean(e.LeftChild.Type()) {
return e.LeftChild, transform.NewTree, nil
}

Expand Down