Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,8 @@ FROM task_instance INNER JOIN job ON job.id = task_instance.queued_by_job_id INN
Expected: []sql.Row{{"11"}},
ExpectedWarningsCount: 0,
},

{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test01 where pk in (11)",
Expected: []sql.Row{
Expand All @@ -1193,25 +1191,22 @@ FROM task_instance INNER JOIN job ON job.id = task_instance.queued_by_job_id INN
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Skip: true, // this passes in gms but not dolt
Dialect: "mysql",
Query: "select * from test01 where pk=3",
Expected: []sql.Row{
{" 3 12 4"},
{" 3. 12 4"},
{"3. 12 4"},
},
ExpectedWarningsCount: 12,
ExpectedWarning: mysql.ERTruncatedWrongValue,
},
{
// https://github.com/dolthub/dolt/issues/9739
Skip: true,
Dialect: "mysql",
Query: "select * from test01 where pk>=3 and pk < 4",
Expected: []sql.Row{
{" 3 12 4"},
{" 3. 12 4"},
{" 3.2 12 4"},
{"+3.1234"},
{"3. 12 4"},
Expand All @@ -1235,6 +1230,50 @@ FROM task_instance INNER JOIN job ON job.id = task_instance.queued_by_job_id INN
},
},
},
{
// https://github.com/dolthub/dolt/issues/9936
Name: "invisible hash index with different key types",
Dialect: "mysql",
SetUpScript: []string{
"create table t0(c0 varchar(500))",
"insert into t0(c0) values (77367106)",
"create index i0 using hash on t0(c0) invisible",
},
Assertions: []ScriptTestAssertion{
{
Query: "select c0 from t0 where 1630944823 >= t0.c0",
Expected: []sql.Row{{"77367106"}},
},
{
Query: "select c0 from t0 where 1630944823 <= t0.c0",
Expected: []sql.Row{},
},
{
Query: "select c0 from t0 where '1630944823' >= t0.c0",
Expected: []sql.Row{},
},
{
Query: "select c0 from t0 where '1630944823' <= t0.c0",
Expected: []sql.Row{{"77367106"}},
},
{
Query: "select c0 from t0 where 1630944823.2 >= t0.c0",
Expected: []sql.Row{{"77367106"}},
},
{
Query: "select c0 from t0 where 1630944823.2 <= t0.c0",
Expected: []sql.Row{},
},
{
Query: "select c0 from t0 where '1630944823.2' >= t0.c0",
Expected: []sql.Row{},
},
{
Query: "select c0 from t0 where '1630944823.2' <= t0.c0",
Expected: []sql.Row{{"77367106"}},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9821
Name: "strings with boolean operators",
Expand Down
12 changes: 12 additions & 0 deletions sql/index_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,23 @@ func (b *MySQLIndexBuilder) GreaterThan(ctx *Context, colExpr string, keyType Ty
return b
}

// isConvertibleKeyType checks if the key can be converted into the column type
func isConvertibleKeyType(colType Type, keyType Type) bool {
if IsStringType(colType) {
return !(IsNumberType(keyType) || IsDecimalType(keyType))
}
// TODO: check other types
return true
}

// convertKey converts the given key from keyType to colType, returning an error if the conversion fails.
func (b *MySQLIndexBuilder) convertKey(ctx *Context, colType Type, keyType Type, key interface{}) (interface{}, error) {
if et, ok := colType.(ExtendedType); ok {
return et.ConvertToType(ctx, keyType.(ExtendedType), key)
} else {
if !isConvertibleKeyType(colType, keyType) {
return nil, ErrInvalidValueType.New(key, colType)
}
k, _, err := colType.Convert(ctx, key)
if err != nil && !ErrTruncatedIncorrect.Is(err) {
return nil, err
Expand Down
15 changes: 15 additions & 0 deletions sql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ type NumberType interface {
DisplayWidth() int
}

func IsNumberType(t Type) bool {
_, ok := t.(NumberType)
return ok
}

// RoundingNumberType represents Number Types that implement an additional interface
// that supports rounding when converting rather than the default truncation.
type RoundingNumberType interface {
Expand All @@ -197,6 +202,11 @@ type StringType interface {
Length() int64
}

func IsStringType(t Type) bool {
_, ok := t.(StringType)
return ok
}

// DatetimeType represents DATE, DATETIME, and TIMESTAMP.
// https://dev.mysql.com/doc/refman/8.0/en/datetime.html
// The type of the returned value is time.Time.
Expand Down Expand Up @@ -277,6 +287,11 @@ type DecimalType interface {
Scale() uint8
}

func IsDecimalType(t Type) bool {
_, ok := t.(DecimalType)
return ok
}

type Type2 interface {
Type

Expand Down