expression: fold const after rewrite between (#27834)

This commit is contained in:
xiongjiwei
2021-09-06 19:48:57 +08:00
committed by GitHub
parent 36a191bc16
commit 7abf5ae081
2 changed files with 3 additions and 0 deletions

View File

@ -1654,6 +1654,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

View File

@ -461,6 +461,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'")
}