diff --git a/enginetest/queries/script_queries.go b/enginetest/queries/script_queries.go index cd77a1af72..ce7b74f832 100644 --- a/enginetest/queries/script_queries.go +++ b/enginetest/queries/script_queries.go @@ -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", + }, }, }, { diff --git a/sql/analyzer/optimization_rules.go b/sql/analyzer/optimization_rules.go index 329b83af1a..87472f3eae 100644 --- a/sql/analyzer/optimization_rules.go +++ b/sql/analyzer/optimization_rules.go @@ -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 }