From b59d5f98ca18883392d6905774af1c96f07add18 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 16:40:53 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #49543 Signed-off-by: ti-chi-bot --- expression/chunk_executor.go | 21 +++++++++++++++++-- .../r/expression/enum_set.result | 13 ++++++++++++ .../t/expression/enum_set.test | 12 +++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/integrationtest/r/expression/enum_set.result create mode 100644 tests/integrationtest/t/expression/enum_set.test diff --git a/expression/chunk_executor.go b/expression/chunk_executor.go index 019592c783891..5a8dfd3c10f9f 100644 --- a/expression/chunk_executor.go +++ b/expression/chunk_executor.go @@ -15,12 +15,21 @@ package expression import ( +<<<<<<< HEAD:expression/chunk_executor.go "github.com/pingcap/errors" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" +======= + "github.com/pingcap/tidb/pkg/parser/ast" + "github.com/pingcap/tidb/pkg/parser/mysql" + "github.com/pingcap/tidb/pkg/types" + "github.com/pingcap/tidb/pkg/util/chunk" + "github.com/pingcap/tidb/pkg/util/logutil" + "go.uber.org/zap" +>>>>>>> fb9d2203b99 (expression: enum/set could be invalid during evaluation (#49543)):pkg/expression/chunk_executor.go ) // Vectorizable checks whether a list of expressions can employ vectorized execution. @@ -182,7 +191,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 { - return errors.Errorf("Wrong enum value parsed during evaluation") + 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) } @@ -198,7 +211,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 { - return errors.Errorf("Wrong set value parsed during evaluation") + 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) } 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 From 286b8711b77304a2b49716096047b4d3b41333ba Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 17:00:16 +0800 Subject: [PATCH 2/3] fix merge conflict & add test --- expression/casetest/BUILD.bazel | 2 + expression/casetest/issue_test.go | 40 +++++++++++++++++++ expression/chunk_executor.go | 12 +----- .../r/expression/enum_set.result | 13 ------ .../t/expression/enum_set.test | 12 ------ 5 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 expression/casetest/issue_test.go delete mode 100644 tests/integrationtest/r/expression/enum_set.result delete mode 100644 tests/integrationtest/t/expression/enum_set.test diff --git a/expression/casetest/BUILD.bazel b/expression/casetest/BUILD.bazel index ee76a6ea2fdd1..c732d54670e00 100644 --- a/expression/casetest/BUILD.bazel +++ b/expression/casetest/BUILD.bazel @@ -6,10 +6,12 @@ go_test( srcs = [ "constant_propagation_test.go", "flag_simplify_test.go", + "issue_test.go", "main_test.go", ], data = glob(["testdata/**"]), flaky = True, + shard_count = 3, deps = [ "//config", "//testkit", diff --git a/expression/casetest/issue_test.go b/expression/casetest/issue_test.go new file mode 100644 index 0000000000000..57aa159e16785 --- /dev/null +++ b/expression/casetest/issue_test.go @@ -0,0 +1,40 @@ +// Copyright 2018 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package casetest + +import ( + "testing" + + "github.com/pingcap/tidb/testkit" +) + +func TestInvalidEnumName(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t01") + tk.MustExec(` + CREATE TABLE t01 ( + a timestamp DEFAULT '2024-10-02 01:54:55', + b int(11) NOT NULL DEFAULT '2023959529', + c varchar(122) DEFAULT '36h0hvfpylz0f0iv9h0ownfcg3rehi4', + d enum('l7i9','3sdz3','83','4','92p','4g','8y5rn','7gp','7','1','e') NOT NULL DEFAULT '4', + PRIMARY KEY (b, d) /*T![clustered_index] CLUSTERED */ + ) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci COMMENT='7ad99128' + PARTITION BY HASH (b) PARTITIONS 9;`) + tk.MustExec("insert ignore into t01 values ('2023-01-01 20:01:02', 123, 'abcd', '');") + tk.MustQuery("select `t01`.`d` as r0 from `t01` where `t01`.`a` in ( '2010-05-25') or not( `t01`.`d` > '1' ) ;").Check(testkit.Rows("")) +} diff --git a/expression/chunk_executor.go b/expression/chunk_executor.go index 5a8dfd3c10f9f..959d11a7bf88c 100644 --- a/expression/chunk_executor.go +++ b/expression/chunk_executor.go @@ -15,21 +15,13 @@ package expression import ( -<<<<<<< HEAD:expression/chunk_executor.go - "github.com/pingcap/errors" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" - "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" -======= - "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/chunk" - "github.com/pingcap/tidb/pkg/util/logutil" + "github.com/pingcap/tidb/util/logutil" + "github.com/pingcap/tidb/sessionctx" "go.uber.org/zap" ->>>>>>> fb9d2203b99 (expression: enum/set could be invalid during evaluation (#49543)):pkg/expression/chunk_executor.go ) // Vectorizable checks whether a list of expressions can employ vectorized execution. diff --git a/tests/integrationtest/r/expression/enum_set.result b/tests/integrationtest/r/expression/enum_set.result deleted file mode 100644 index 1c40536bb1c2b..0000000000000 --- a/tests/integrationtest/r/expression/enum_set.result +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 5bd90859381ec..0000000000000 --- a/tests/integrationtest/t/expression/enum_set.test +++ /dev/null @@ -1,12 +0,0 @@ -# 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 From 1e47e209abbac6088850ae7fd285cf6d68a517af Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 18 Dec 2023 17:18:17 +0800 Subject: [PATCH 3/3] fix fmt --- expression/chunk_executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/chunk_executor.go b/expression/chunk_executor.go index 959d11a7bf88c..4bc0a8e2d2a5b 100644 --- a/expression/chunk_executor.go +++ b/expression/chunk_executor.go @@ -17,10 +17,10 @@ package expression import ( "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" + "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/logutil" - "github.com/pingcap/tidb/sessionctx" "go.uber.org/zap" )