diff --git a/enginetest/queries/information_schema_queries.go b/enginetest/queries/information_schema_queries.go index b3540bc199..512a250d4f 100644 --- a/enginetest/queries/information_schema_queries.go +++ b/enginetest/queries/information_schema_queries.go @@ -1423,8 +1423,8 @@ FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='all_ty {"some_int", "3", "YES", "int", "int", nil, nil}, {"some_json", "json_object('a',1)", "YES", "json", "json", nil, nil}, {"line_string", "linestring(point(0,0),point(1,2))", "YES", "linestring", "linestring", nil, nil}, - {"long_blob", "'abc'", "YES", "longblob", "longblob", 4294967295, 4294967295}, - {"long_text", "'abc'", "YES", "longtext", "longtext", 1073741823, 4294967295}, + {"long_blob", "'abc'", "YES", "longblob", "longblob", 2147483647, 2147483647}, + {"long_text", "'abc'", "YES", "longtext", "longtext", 536870911, 2147483647}, {"medium_blob", "'abc'", "YES", "mediumblob", "mediumblob", 16777215, 16777215}, {"medium_int", "7", "YES", "mediumint", "mediumint", nil, nil}, {"medium_text", "'abc'", "YES", "mediumtext", "mediumtext", 4194303, 16777215}, diff --git a/server/handler_test.go b/server/handler_test.go index 9dae8b9ed4..a366ceba19 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -965,11 +965,11 @@ func TestSchemaToFields(t *testing.T) { {Name: "tinyblob", OrgName: "tinyblob", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary, ColumnLength: 255, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "blob", OrgName: "blob", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary, ColumnLength: 65_535, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "mediumblob", OrgName: "mediumblob", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary, ColumnLength: 16_777_215, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, - {Name: "longblob", OrgName: "longblob", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, + {Name: "longblob", OrgName: "longblob", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary, ColumnLength: 2_147_483_647, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "tinytext", OrgName: "tinytext", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 1020, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "text", OrgName: "text", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 262_140, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "mediumtext", OrgName: "mediumtext", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 67_108_860, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, - {Name: "longtext", OrgName: "longtext", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, + {Name: "longtext", OrgName: "longtext", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 2_147_483_647, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, {Name: "json", OrgName: "json", Table: "table1", OrgTable: "table1", Database: "db1", Type: query.Type_JSON, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295, Flags: uint32(query.MySqlFlag_NOT_NULL_FLAG)}, // Geometry Types diff --git a/sql/expression/function/extract.go b/sql/expression/function/extract.go index 24c6d65d31..951fdc301a 100644 --- a/sql/expression/function/extract.go +++ b/sql/expression/function/extract.go @@ -169,11 +169,11 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { ss := dateTime.Second() return dd + hh + mm + ss, nil case "DAY_MICROSECOND": - dd := dateTime.Day() * 1_00_00_00_000000 - hh := dateTime.Hour() * 1_00_00_000000 - mm := dateTime.Minute() * 1_00_000000 - ss := dateTime.Second() * 1_000000 - mmmmmm := dateTime.Nanosecond() / 1000 + dd := uint64(dateTime.Day()) * 1_00_00_00_000000 + hh := uint64(dateTime.Hour()) * 1_00_00_000000 + mm := uint64(dateTime.Minute()) * 1_00_000000 + ss := uint64(dateTime.Second()) * 1_000000 + mmmmmm := uint64(dateTime.Nanosecond()) / 1000 return dd + hh + mm + ss + mmmmmm, nil case "HOUR_MINUTE": hh := dateTime.Hour() * 1_00 @@ -185,10 +185,10 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { ss := dateTime.Second() return hh + mm + ss, nil case "HOUR_MICROSECOND": - hh := dateTime.Hour() * 1_00_00_000000 - mm := dateTime.Minute() * 1_00_000000 - ss := dateTime.Second() * 1_000000 - mmmmmm := dateTime.Nanosecond() / 1000 + hh := uint64(dateTime.Hour()) * 1_00_00_000000 + mm := uint64(dateTime.Minute()) * 1_00_000000 + ss := uint64(dateTime.Second()) * 1_000000 + mmmmmm := uint64(dateTime.Nanosecond()) / 1000 return hh + mm + ss + mmmmmm, nil case "MINUTE_SECOND": mm := dateTime.Minute() * 1_00 diff --git a/sql/expression/function/extract_test.go b/sql/expression/function/extract_test.go index d0a6b5c6d4..88dfa52bd8 100644 --- a/sql/expression/function/extract_test.go +++ b/sql/expression/function/extract_test.go @@ -132,7 +132,7 @@ func TestExtract(t *testing.T) { name: "get day_microsecond", unit: "DAY_MICROSECOND", dateTime: "2023-11-12 11:22:33.445566", - expected: 12112233445566, + expected: uint64(12112233445566), }, { name: "get hour_minute", @@ -150,7 +150,7 @@ func TestExtract(t *testing.T) { name: "get hour_microsecond", unit: "HOUR_MICROSECOND", dateTime: "2023-11-12 11:22:33.445566", - expected: 112233445566, + expected: uint64(112233445566), }, { name: "get minute_second", diff --git a/sql/rowexec/proc.go b/sql/rowexec/proc.go index 35af6c65e8..b78953d739 100644 --- a/sql/rowexec/proc.go +++ b/sql/rowexec/proc.go @@ -304,9 +304,9 @@ func (b *BaseBuilder) buildLoop(ctx *sql.Context, n *plan.Loop, row sql.Row) (sq selectSeen := false // It's technically valid to make an infinite loop, but we don't want to actually allow that - const maxIterationCount = 10_000_000_000 + const maxIterationCount uint64 = 10_000_000_000 - for loopIteration := 0; loopIteration <= maxIterationCount; loopIteration++ { + for loopIteration := uint64(0); loopIteration <= maxIterationCount; loopIteration++ { if loopIteration >= maxIterationCount { return nil, fmt.Errorf("infinite LOOP detected") } diff --git a/sql/types/geometry.go b/sql/types/geometry.go index 8a429ce480..7c750a506c 100644 --- a/sql/types/geometry.go +++ b/sql/types/geometry.go @@ -546,7 +546,7 @@ func (t GeometryType) MatchSRID(v interface{}) error { } func ValidateSRID(srid int, funcName string) error { - if srid < 0 || srid > math.MaxUint32 { + if srid < 0 || int64(srid) > int64(math.MaxUint32) { return sql.ErrInvalidSRID.New(funcName) } if _, ok := SupportedSRIDs[uint32(srid)]; !ok { diff --git a/sql/types/number.go b/sql/types/number.go index c346efbfc9..bffaf2f759 100644 --- a/sql/types/number.go +++ b/sql/types/number.go @@ -1114,27 +1114,27 @@ func convertToUint64(t NumberTypeImpl_, v interface{}) (uint64, sql.ConvertInRan return uint64(v.UTC().Unix()), sql.InRange, nil case int: if v < 0 { - return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil + return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil } return uint64(v), sql.InRange, nil case int8: if v < 0 { - return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil + return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil } return uint64(v), sql.InRange, nil case int16: if v < 0 { - return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil + return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil } return uint64(v), sql.InRange, nil case int32: if v < 0 { - return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil + return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil } return uint64(v), sql.InRange, nil case int64: if v < 0 { - return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil + return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil } return uint64(v), sql.InRange, nil case uint: @@ -1204,35 +1204,35 @@ func convertToUint32(t NumberTypeImpl_, v interface{}) (uint32, sql.ConvertInRan switch v := v.(type) { case int: if v < 0 { - return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil - } else if v > math.MaxUint32 { + return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil + } else if int64(v) > int64(math.MaxUint32) { return uint32(math.MaxUint32), sql.OutOfRange, nil } return uint32(v), sql.InRange, nil case int8: if v < 0 { - return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil - } else if int(v) > math.MaxUint32 { + return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil + } else if int64(v) > int64(math.MaxUint32) { return uint32(math.MaxUint32), sql.OutOfRange, nil } return uint32(v), sql.InRange, nil case int16: if v < 0 { - return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil - } else if int(v) > math.MaxUint32 { + return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil + } else if int64(v) > int64(math.MaxUint32) { return uint32(math.MaxUint32), sql.OutOfRange, nil } return uint32(v), sql.InRange, nil case int32: if v < 0 { - return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil - } else if int(v) > math.MaxUint32 { + return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil + } else if int64(v) > int64(math.MaxUint32) { return uint32(math.MaxUint32), sql.OutOfRange, nil } return uint32(v), sql.InRange, nil case int64: if v < 0 { - return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil + return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil } else if v > math.MaxUint32 { return uint32(math.MaxUint32), sql.OutOfRange, nil } diff --git a/sql/types/strings.go b/sql/types/strings.go index be4119680a..f45ea98734 100644 --- a/sql/types/strings.go +++ b/sql/types/strings.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "fmt" + "math" "reflect" "strconv" strings2 "strings" @@ -41,7 +42,7 @@ const ( TinyTextBlobMax = charBinaryMax TextBlobMax = varcharVarbinaryMax MediumTextBlobMax = 16_777_215 - LongTextBlobMax = int64(4_294_967_295) + LongTextBlobMax = int64(math.MaxInt32) ) var (