From aab2da047904901725e5a3bf745b47b1488eb8c7 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 18 Dec 2023 17:48:22 +0800 Subject: [PATCH] expression: enum/set could be invalid during evaluation (#49543) (#49550) close pingcap/tidb#49487 --- expression/casetest/BUILD.bazel | 2 ++ expression/casetest/issue_test.go | 40 +++++++++++++++++++++++++++++++ expression/chunk_executor.go | 15 +++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 expression/casetest/issue_test.go 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 019592c783891..4bc0a8e2d2a5b 100644 --- a/expression/chunk_executor.go +++ b/expression/chunk_executor.go @@ -15,12 +15,13 @@ package expression import ( - "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/util/logutil" + "go.uber.org/zap" ) // Vectorizable checks whether a list of expressions can employ vectorized execution. @@ -182,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 { - 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 +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 { - 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) }