Skip to content

Commit

Permalink
util: fix range building for binary literal (#23699) (#24041)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot committed Apr 16, 2021
1 parent 25ab9ab commit 7f3fbe3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,15 @@ func (s *testIntegrationSerialSuite) TestCollationBasic(c *C) {
tk.MustQuery("select c from t where c = 'A';").Check(testkit.Rows("A"))
tk.MustQuery("select c from t where c = 'b';").Check(testkit.Rows("B"))
tk.MustQuery("select c from t where c = 'B';").Check(testkit.Rows("B"))

tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE `t1` (" +
" `COL1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL," +
" PRIMARY KEY (`COL1`(5)) clustered" +
")")
tk.MustExec("INSERT INTO `t1` VALUES ('Ȇ');")
tk.MustQuery("select * from t1 where col1 not in (0xc484, 0xe5a4bc, 0xc3b3);").Check(testkit.Rows("Ȇ"))
tk.MustQuery("select * from t1 where col1 >= 0xc484 and col1 <= 0xc3b3;").Check(testkit.Rows("Ȇ"))
}

func (s *testIntegrationSerialSuite) TestWeightString(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion util/ranger/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *conditionChecker) checkScalarFunction(scalar *expression.ScalarFunction
if !c.checkColumn(scalar.GetArgs()[0]) {
return false
}
if scalar.GetArgs()[1].GetType().EvalType() == types.ETString && !collate.CompatibleCollate(scalar.GetArgs()[0].GetType().Collate, collation) {
if scalar.GetArgs()[0].GetType().EvalType() == types.ETString && !collate.CompatibleCollate(scalar.GetArgs()[0].GetType().Collate, collation) {
return false
}
for _, v := range scalar.GetArgs()[1:] {
Expand Down
4 changes: 2 additions & 2 deletions util/ranger/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point {
// 1. for string type since we may eval the constant to another collation instead of its own collation.
// 2. for year type since 2-digit year value need adjustment, see https://dev.mysql.com/doc/refman/5.6/en/year.html
refineValue := func(col *expression.Column, value *types.Datum) (err error) {
if col.RetType.EvalType() == types.ETString && value.Kind() == types.KindString {
if col.RetType.EvalType() == types.ETString && (value.Kind() == types.KindString || value.Kind() == types.KindBinaryLiteral) {
value.SetString(value.GetString(), col.RetType.Collate)
}
if col.GetType().Tp == mysql.TypeYear {
Expand Down Expand Up @@ -468,7 +468,7 @@ func (r *builder) buildFromIn(expr *expression.ScalarFunction) ([]*point, bool)
hasNull = true
continue
}
if dt.Kind() == types.KindString {
if dt.Kind() == types.KindString || dt.Kind() == types.KindBinaryLiteral {
dt.SetString(dt.GetString(), colCollate)
}
if expr.GetArgs()[0].GetType().Tp == mysql.TypeYear {
Expand Down

0 comments on commit 7f3fbe3

Please sign in to comment.