From ce864de895515a9e6c58c1a1324afc02a6324cbb Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 13:50:06 +0800 Subject: [PATCH 1/3] expression: enum/set could be invalid during evaluation --- pkg/expression/chunk_executor.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/expression/chunk_executor.go b/pkg/expression/chunk_executor.go index f730c6aa61af0..d09217d78940e 100644 --- a/pkg/expression/chunk_executor.go +++ b/pkg/expression/chunk_executor.go @@ -15,12 +15,13 @@ 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" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" + "github.com/pingcap/tidb/pkg/util/logutil" + "go.uber.org/zap" ) // Vectorizable checks whether a list of expressions can employ vectorized execution. @@ -182,7 +183,7 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out } else { enum, err := types.ParseEnumName(ft.GetElems(), result.GetString(i), ft.GetCollate()) if err != nil { - return errors.Errorf("Wrong enum value parsed during evaluation") + logutil.BgLogger().Debug("Wrong enum value parsed during evaluation", zap.Error(err)) } buf.AppendEnum(enum) } @@ -198,7 +199,7 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out } else { set, err := types.ParseSetName(ft.GetElems(), result.GetString(i), ft.GetCollate()) if err != nil { - return errors.Errorf("Wrong set value parsed during evaluation") + logutil.BgLogger().Debug("Wrong set value parsed during evaluation", zap.Error(err)) } buf.AppendSet(set) } From 34218f7b751d8327b26360b780b0c201cf041b04 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 14:02:57 +0800 Subject: [PATCH 2/3] enrich the debug log --- pkg/expression/chunk_executor.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/expression/chunk_executor.go b/pkg/expression/chunk_executor.go index d09217d78940e..5a2c8e44c8041 100644 --- a/pkg/expression/chunk_executor.go +++ b/pkg/expression/chunk_executor.go @@ -183,7 +183,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out } else { enum, err := types.ParseEnumName(ft.GetElems(), result.GetString(i), ft.GetCollate()) if err != nil { - logutil.BgLogger().Debug("Wrong enum value parsed during evaluation", zap.Error(err)) + logutil.BgLogger().Debug("Wrong enum name parsed during evaluation", + zap.String("The name to be parsed in the ENUM", result.GetString(i)), + zap.Strings("The valid names in the ENUM", ft.GetElems()), + zap.Error(err), + ) } buf.AppendEnum(enum) } @@ -199,7 +203,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out } else { set, err := types.ParseSetName(ft.GetElems(), result.GetString(i), ft.GetCollate()) if err != nil { - logutil.BgLogger().Debug("Wrong set value parsed during evaluation", zap.Error(err)) + logutil.BgLogger().Debug("Wrong set name parsed during evaluation", + zap.String("The name to be parsed in the SET", result.GetString(i)), + zap.Strings("The valid names in the SET", ft.GetElems()), + zap.Error(err), + ) } buf.AppendSet(set) } From 716195daa9a511ff42bb6f94a87701171ee8b4ad Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 14:19:33 +0800 Subject: [PATCH 3/3] add test --- tests/integrationtest/r/expression/enum_set.result | 13 +++++++++++++ tests/integrationtest/t/expression/enum_set.test | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/integrationtest/r/expression/enum_set.result create mode 100644 tests/integrationtest/t/expression/enum_set.test diff --git a/tests/integrationtest/r/expression/enum_set.result b/tests/integrationtest/r/expression/enum_set.result new file mode 100644 index 0000000000000..1c40536bb1c2b --- /dev/null +++ b/tests/integrationtest/r/expression/enum_set.result @@ -0,0 +1,13 @@ +drop table if exists t01; +CREATE TABLE `t01` ( +`6524d87a` timestamp DEFAULT '2024-10-02 01:54:55', +`744e4d52` int(11) NOT NULL DEFAULT '2023959529', +`087de3b2` varchar(122) DEFAULT '36h0hvfpylz0f0iv9h0ownfcg3rehi4', +`26cbbf2a` enum('l7i9','3sdz3','83','4','92p','4g','8y5rn','7gp','7','1','e') NOT NULL DEFAULT '4', +PRIMARY KEY (`744e4d52`,`26cbbf2a`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci COMMENT='7ad99128' +PARTITION BY HASH (`744e4d52`) PARTITIONS 9; +insert ignore into t01 values ("2023-01-01 20:01:02", 123, 'abcd', ''); +select `t01`.`26cbbf2a` as r0 from `t01` where `t01`.`6524d87a` in ( '2010-05-25') or not( `t01`.`26cbbf2a` > '1' ) ; +r0 + diff --git a/tests/integrationtest/t/expression/enum_set.test b/tests/integrationtest/t/expression/enum_set.test new file mode 100644 index 0000000000000..5bd90859381ec --- /dev/null +++ b/tests/integrationtest/t/expression/enum_set.test @@ -0,0 +1,12 @@ +# https://github.com/pingcap/tidb/issues/49487 +drop table if exists t01; +CREATE TABLE `t01` ( + `6524d87a` timestamp DEFAULT '2024-10-02 01:54:55', + `744e4d52` int(11) NOT NULL DEFAULT '2023959529', + `087de3b2` varchar(122) DEFAULT '36h0hvfpylz0f0iv9h0ownfcg3rehi4', + `26cbbf2a` enum('l7i9','3sdz3','83','4','92p','4g','8y5rn','7gp','7','1','e') NOT NULL DEFAULT '4', + PRIMARY KEY (`744e4d52`,`26cbbf2a`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci COMMENT='7ad99128' +PARTITION BY HASH (`744e4d52`) PARTITIONS 9; +insert ignore into t01 values ("2023-01-01 20:01:02", 123, 'abcd', ''); +select `t01`.`26cbbf2a` as r0 from `t01` where `t01`.`6524d87a` in ( '2010-05-25') or not( `t01`.`26cbbf2a` > '1' ) ; \ No newline at end of file