Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor, codec: hash join build wrong hash key for ENUM/SET value (#49031) #49055

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,23 @@ func TestTiDBNAAJ(t *testing.T) {
tk.MustQuery("select ( table1 . a , table1 . b ) NOT IN ( SELECT 3 , 2 UNION SELECT 9, 2 ) AS field2 from t as table1 order by field2;").Check(testkit.Rows(
"0", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"))
}

func TestIssue48991(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists tbl_3")
tk.MustExec("create table tbl_3 ( col_11 mediumint unsigned not null default 8346281 ,col_12 enum ( 'Alice','Bob','Charlie','David' ) ,col_13 time not null default '07:10:30.00' ,col_14 timestamp ,col_15 varbinary ( 194 ) not null default '-ZpCzjqdl4hsyo' , key idx_5 ( col_14 ,col_11 ,col_12 ) ,primary key ( col_11 ,col_15 ) /*T![clustered_index] clustered */ ) charset utf8mb4 collate utf8mb4_bin partition by range ( col_11 ) ( partition p0 values less than (530262), partition p1 values less than (9415740), partition p2 values less than (11007444), partition p3 values less than (maxvalue) );")
tk.MustExec("insert into tbl_3 values ( 8838143,'David','23:41:27.00','1993-02-23','g0q~Z0b*PpMPKJxYbIE' );")
tk.MustExec("insert into tbl_3 values ( 9082223,'Alice','02:25:16.00','2035-11-08','i' );")
tk.MustExec("insert into tbl_3 values ( 2483729,'Charlie','14:43:13.00','1970-09-10','w6o6WFYyL5' );")
tk.MustExec("insert into tbl_3 values ( 4135401,'Charlie','19:30:34.00','2017-06-07','2FZmy9lanL8' );")
tk.MustExec("insert into tbl_3 values ( 1479390,'Alice','20:40:08.00','1984-06-10','LeoVONgN~iJz&inj' );")
tk.MustExec("insert into tbl_3 values ( 10427825,'Charlie','15:27:35.00','1986-12-25','tWJ' );")
tk.MustExec("insert into tbl_3 values ( 12794792,'Charlie','04:10:08.00','2034-08-08','hvpXVQyuP' );")
tk.MustExec("insert into tbl_3 values ( 4696775,'Charlie','05:07:43.00','1984-07-31','SKOW9I^sM$4xNk' );")
tk.MustExec("insert into tbl_3 values ( 8963236,'Alice','08:18:31.00','2022-04-17','v4DsE' );")
tk.MustExec("insert into tbl_3 values ( 9048951,'Alice','05:19:47.00','2018-09-22','sJ!vs' );")

res := tk.MustQuery("SELECT `col_14` FROM `test`.`tbl_3` WHERE ((`tbl_3`.`col_15` < 'dV') AND `tbl_3`.`col_12` IN (SELECT `col_12` FROM `test`.`tbl_3` WHERE NOT (ISNULL(`tbl_3`.`col_12`)))) ORDER BY IF(ISNULL(`col_14`),0,1),`col_14`;")
res.Check(testkit.Rows("1984-06-10 00:00:00", "1984-07-31 00:00:00", "2017-06-07 00:00:00"))
13 changes: 11 additions & 2 deletions expression/chunk_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package expression

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -179,7 +180,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
if result.IsNull(i) {
buf.AppendNull()
} else {
buf.AppendEnum(types.Enum{Value: 0, Name: result.GetString(i)})
enum, err := types.ParseEnumName(ft.GetElems(), result.GetString(i), ft.GetCollate())
if err != nil {
return errors.Errorf("Wrong enum value parsed during evaluation")
}
buf.AppendEnum(enum)
}
}
output.SetCol(colIdx, buf)
Expand All @@ -191,7 +196,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
if result.IsNull(i) {
buf.AppendNull()
} else {
buf.AppendSet(types.Set{Value: 0, Name: result.GetString(i)})
set, err := types.ParseSetName(ft.GetElems(), result.GetString(i), ft.GetCollate())
if err != nil {
return errors.Errorf("Wrong set value parsed during evaluation")
}
buf.AppendSet(set)
}
}
output.SetCol(colIdx, buf)
Expand Down