From b08f6be9c07e2c90d0082b6b0ff81f0f2c4c2241 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Wed, 27 Jan 2021 10:34:23 +0800 Subject: [PATCH] expression: do not rewrite `like` to `=` if new collation is enabled (#21893) (#22531) Signed-off-by: ti-srebot --- planner/core/expression_rewriter.go | 4 ++-- util/ranger/ranger_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/planner/core/expression_rewriter.go b/planner/core/expression_rewriter.go index f4f98ef224246..4b548211a6c6b 100644 --- a/planner/core/expression_rewriter.go +++ b/planner/core/expression_rewriter.go @@ -1449,8 +1449,8 @@ func (er *expressionRewriter) patternLikeToExpression(v *ast.PatternLikeExpr) { var function expression.Expression fieldType := &types.FieldType{} isPatternExactMatch := false - // Treat predicate 'like' the same way as predicate '=' when it is an exact match. - if patExpression, ok := er.ctxStack[l-1].(*expression.Constant); ok { + // Treat predicate 'like' the same way as predicate '=' when it is an exact match and new collation is not enabled. + if patExpression, ok := er.ctxStack[l-1].(*expression.Constant); ok && !collate.NewCollationEnabled() { patString, isNull, err := patExpression.EvalString(nil, chunk.Row{}) if err != nil { er.err = err diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index 626963428ece5..db59755f59730 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -384,14 +384,14 @@ create table t( { indexPos: 0, exprStr: "a LIKE 'abc'", - accessConds: "[eq(test.t.a, abc)]", + accessConds: "[like(test.t.a, abc, 92)]", filterConds: "[]", resultStr: "[[\"abc\",\"abc\"]]", }, { indexPos: 0, exprStr: `a LIKE "ab\_c"`, - accessConds: "[eq(test.t.a, ab_c)]", + accessConds: "[like(test.t.a, ab\\_c, 92)]", filterConds: "[]", resultStr: "[[\"ab_c\",\"ab_c\"]]", }, @@ -405,14 +405,14 @@ create table t( { indexPos: 0, exprStr: `a LIKE '\%a'`, - accessConds: "[eq(test.t.a, %a)]", + accessConds: "[like(test.t.a, \\%a, 92)]", filterConds: "[]", resultStr: `[["%a","%a"]]`, }, { indexPos: 0, exprStr: `a LIKE "\\"`, - accessConds: "[eq(test.t.a, \\)]", + accessConds: "[like(test.t.a, \\, 92)]", filterConds: "[]", resultStr: "[[\"\\\",\"\\\"]]", },