Skip to content

Commit

Permalink
executor, codec: hash join build wrong hash key for ENUM/SET value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros authored Nov 30, 2023
1 parent 6dcb074 commit 8d181ed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/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/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/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
26 changes: 26 additions & 0 deletions tests/integrationtest/r/executor/jointest/hash_join.result
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,29 @@ set @@tidb_max_chunk_size=default;
set @@tidb_index_lookup_join_concurrency=default;
set @@session.tidb_executor_concurrency = default;
set @@session.tidb_hash_join_concurrency = default;
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) );
insert into tbl_3 values ( 8838143,'David','23:41:27.00','1993-02-23','g0q~Z0b*PpMPKJxYbIE' );
insert into tbl_3 values ( 9082223,'Alice','02:25:16.00','2035-11-08','i' );
insert into tbl_3 values ( 2483729,'Charlie','14:43:13.00','1970-09-10','w6o6WFYyL5' );
insert into tbl_3 values ( 4135401,'Charlie','19:30:34.00','2017-06-07','2FZmy9lanL8' );
insert into tbl_3 values ( 1479390,'Alice','20:40:08.00','1984-06-10','LeoVONgN~iJz&inj' );
insert into tbl_3 values ( 10427825,'Charlie','15:27:35.00','1986-12-25','tWJ' );
insert into tbl_3 values ( 12794792,'Charlie','04:10:08.00','2034-08-08','hvpXVQyuP' );
insert into tbl_3 values ( 4696775,'Charlie','05:07:43.00','1984-07-31','SKOW9I^sM$4xNk' );
insert into tbl_3 values ( 8963236,'Alice','08:18:31.00','2022-04-17','v4DsE' );
insert into tbl_3 values ( 9048951,'Alice','05:19:47.00','2018-09-22','sJ!vs' );
SELECT `col_14`
FROM
tbl_3
WHERE
(
(`tbl_3`.`col_15` < 'dV')
AND `tbl_3`.`col_12` IN (
SELECT `col_12` FROM `tbl_3` WHERE NOT (ISNULL(`tbl_3`.`col_12`))
)
)
ORDER BY IF(ISNULL(`col_14`),0,1),`col_14`;
col_14
1984-06-10 00:00:00
1984-07-31 00:00:00
2017-06-07 00:00:00
26 changes: 26 additions & 0 deletions tests/integrationtest/t/executor/jointest/hash_join.test
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,29 @@ set @@tidb_max_chunk_size=default;
set @@tidb_index_lookup_join_concurrency=default;
set @@session.tidb_executor_concurrency = default;
set @@session.tidb_hash_join_concurrency = default;

## https://github.com/pingcap/tidb/issues/48991
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) );

insert into tbl_3 values ( 8838143,'David','23:41:27.00','1993-02-23','g0q~Z0b*PpMPKJxYbIE' );
insert into tbl_3 values ( 9082223,'Alice','02:25:16.00','2035-11-08','i' );
insert into tbl_3 values ( 2483729,'Charlie','14:43:13.00','1970-09-10','w6o6WFYyL5' );
insert into tbl_3 values ( 4135401,'Charlie','19:30:34.00','2017-06-07','2FZmy9lanL8' );
insert into tbl_3 values ( 1479390,'Alice','20:40:08.00','1984-06-10','LeoVONgN~iJz&inj' );
insert into tbl_3 values ( 10427825,'Charlie','15:27:35.00','1986-12-25','tWJ' );
insert into tbl_3 values ( 12794792,'Charlie','04:10:08.00','2034-08-08','hvpXVQyuP' );
insert into tbl_3 values ( 4696775,'Charlie','05:07:43.00','1984-07-31','SKOW9I^sM$4xNk' );
insert into tbl_3 values ( 8963236,'Alice','08:18:31.00','2022-04-17','v4DsE' );
insert into tbl_3 values ( 9048951,'Alice','05:19:47.00','2018-09-22','sJ!vs' );

SELECT `col_14`
FROM
tbl_3
WHERE
(
(`tbl_3`.`col_15` < 'dV')
AND `tbl_3`.`col_12` IN (
SELECT `col_12` FROM `tbl_3` WHERE NOT (ISNULL(`tbl_3`.`col_12`))
)
)
ORDER BY IF(ISNULL(`col_14`),0,1),`col_14`;

0 comments on commit 8d181ed

Please sign in to comment.