Skip to content

Commit

Permalink
expression: enum/set could be invalid during evaluation (#49543) (#49550
Browse files Browse the repository at this point in the history
)

close #49487
  • Loading branch information
ti-chi-bot committed Dec 18, 2023
1 parent 950521e commit aab2da0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions expression/casetest/BUILD.bazel
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions 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(""))
}
15 changes: 12 additions & 3 deletions expression/chunk_executor.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit aab2da0

Please sign in to comment.