Skip to content

Commit

Permalink
expression: fold const after rewrite between (pingcap#27834) (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Sep 6, 2021
1 parent daa260f commit 53251a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,8 @@ func (er *expressionRewriter) betweenToExpression(v *ast.BetweenExpr) {
}
l.SetCharsetAndCollation(dstCharset, dstCollation)
r.SetCharsetAndCollation(dstCharset, dstCollation)
l = expression.FoldConstant(l)
r = expression.FoldConstant(r)
function, err := er.newFunction(ast.LogicAnd, &v.Type, l, r)
if err != nil {
er.err = err
Expand Down
1 change: 1 addition & 0 deletions planner/core/expression_rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (s *testExpressionRewriterSuiteSerial) TestBetweenExprCollation(c *C) {
tk.MustExec("insert into t1 values ('a', 'B');")
tk.MustExec("insert into t1 values ('c', 'D');")
tk.MustQuery("select * from t1 where a between 'B' and c;").Check(testkit.Rows("c D"))
tk.MustQuery("explain select * from t1 where 'a' between 'g' and 'f';").Check(testkit.Rows("TableDual_6 0.00 root rows:0"))

tk.MustGetErrMsg("select * from t1 where a between 'B' collate utf8mb4_general_ci and c collate utf8mb4_unicode_ci;", "[expression:1270]Illegal mix of collations (latin1_bin,IMPLICIT), (utf8mb4_general_ci,EXPLICIT), (utf8mb4_unicode_ci,EXPLICIT) for operation 'between'")
}

0 comments on commit 53251a9

Please sign in to comment.