Skip to content

Commit e5862b5

Browse files
committed
Merge remote-tracking branch 'origin/main' into nicktobey/wrapper
2 parents 56c0371 + 846cb71 commit e5862b5

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

enginetest/queries/script_queries.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,54 @@ 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+
},
7861+
},
7862+
},
7863+
{
7864+
Name: "negative int limits",
7865+
Dialect: "mysql",
7866+
SetUpScript: []string{
7867+
"CREATE TABLE t(i8 tinyint, i16 smallint, i24 mediumint, i32 int, i64 bigint);",
7868+
"INSERT INTO t VALUES(-128, -32768, -8388608, -2147483648, -9223372036854775808);",
7869+
},
7870+
Assertions: []ScriptTestAssertion{
7871+
{
7872+
SkipResultCheckOnServerEngine: true,
7873+
Query: "SELECT -i8, -i16, -i24, -i32 from t;",
7874+
Expected: []sql.Row{
7875+
{128, 32768, 8388608, 2147483648},
7876+
},
7877+
},
7878+
{
7879+
Query: "SELECT -i64 from t;",
7880+
ExpectedErrStr: "BIGINT out of range for -9223372036854775808",
7881+
},
78347882
},
78357883
},
78367884
}

sql/analyzer/optimization_rules.go

Lines changed: 2 additions & 2 deletions
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

sql/expression/arithmetic.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package expression
1616

1717
import (
1818
"fmt"
19+
"math"
1920
"reflect"
2021
"regexp"
2122
"strconv"
@@ -704,12 +705,24 @@ func (e *UnaryMinus) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
704705
case int:
705706
return -n, nil
706707
case int8:
708+
if n == math.MinInt8 {
709+
return -int16(n), nil
710+
}
707711
return -n, nil
708712
case int16:
713+
if n == math.MinInt16 {
714+
return -int32(n), nil
715+
}
709716
return -n, nil
710717
case int32:
718+
if n == math.MinInt32 {
719+
return -int64(n), nil
720+
}
711721
return -n, nil
712722
case int64:
723+
if n == math.MinInt64 {
724+
return nil, sql.ErrValueOutOfRange.New("BIGINT", fmt.Sprintf("%d", n))
725+
}
713726
return -n, nil
714727
case uint:
715728
return -int(n), nil

0 commit comments

Comments
 (0)