Skip to content

Commit

Permalink
executor, codec: hash join build wrong hash key for ENUM/SET value (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Dec 6, 2023
1 parent 3aa520f commit 597805f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit 597805f

Please sign in to comment.