Skip to content

Commit 846cb71

Browse files
authored
fix not equal conversions (#2921)
1 parent de24f91 commit 846cb71

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Diff for: enginetest/queries/script_queries.go

+27
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,33 @@ where
78317831
{123},
78327832
},
78337833
},
7834+
{
7835+
Query: "select * from t where i != (false or i);",
7836+
Expected: []sql.Row{
7837+
{123},
7838+
},
7839+
},
7840+
},
7841+
},
7842+
{
7843+
Name: "negative int limits",
7844+
Dialect: "mysql",
7845+
SetUpScript: []string{
7846+
"CREATE TABLE t(i8 tinyint, i16 smallint, i24 mediumint, i32 int, i64 bigint);",
7847+
"INSERT INTO t VALUES(-128, -32768, -8388608, -2147483648, -9223372036854775808);",
7848+
},
7849+
Assertions: []ScriptTestAssertion{
7850+
{
7851+
SkipResultCheckOnServerEngine: true,
7852+
Query: "SELECT -i8, -i16, -i24, -i32 from t;",
7853+
Expected: []sql.Row{
7854+
{128, 32768, 8388608, 2147483648},
7855+
},
7856+
},
7857+
{
7858+
Query: "SELECT -i64 from t;",
7859+
ExpectedErrStr: "BIGINT out of range for -9223372036854775808",
7860+
},
78347861
},
78357862
},
78367863
{

Diff for: sql/analyzer/optimization_rules.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ func simplifyFilters(ctx *sql.Context, a *Analyzer, node sql.Node, scope *plan.S
246246
return e.RightChild, transform.NewTree, nil
247247
}
248248

249-
if isFalse(e.LeftChild) {
249+
if isFalse(e.LeftChild) && types.IsBoolean(e.RightChild.Type()) {
250250
return e.RightChild, transform.NewTree, nil
251251
}
252252

253-
if isFalse(e.RightChild) {
253+
if isFalse(e.RightChild) && types.IsBoolean(e.LeftChild.Type()) {
254254
return e.LeftChild, transform.NewTree, nil
255255
}
256256

0 commit comments

Comments
 (0)