Skip to content

Commit

Permalink
expression: do not rewrite like to = if new collation is enabled (#…
Browse files Browse the repository at this point in the history
…21893) (#22531)

Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
ti-srebot authored Jan 27, 2021
1 parent 8d00a11 commit b08f6be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions util/ranger/ranger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]]",
},
Expand All @@ -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: "[[\"\\\",\"\\\"]]",
},
Expand Down

0 comments on commit b08f6be

Please sign in to comment.