diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 2e2076d55fa93..6d98a8c9201b7 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -1764,6 +1764,25 @@ func (s *testIntegrationSuite) TestIssue15813(c *C) { tk.MustQuery("select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0").Check(testkit.Rows()) } +func (s *testIntegrationSuite) TestIssue31261(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec(`use test`) + tk.MustExec(`drop table if exists PK_MULTI_COL_5177`) + tk.MustExec(` CREATE TABLE PK_MULTI_COL_5177 ( + COL1 binary(10) NOT NULL, + COL2 varbinary(10) NOT NULL, + COL3 smallint(45) NOT NULL, + PRIMARY KEY (COL1(5),COL2,COL3), + UNIQUE KEY UIDXM (COL1(5),COL2), + UNIQUE KEY UIDX (COL2), + KEY IDX3 (COL3), + KEY IDXM (COL3,COL2))`) + tk.MustExec(`insert into PK_MULTI_COL_5177(col1, col2, col3) values(0x00000000000000000000, 0x002B200DF5BA03E59F82, 1)`) + c.Assert(len(tk.MustQuery(`select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 in (0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82)`).Rows()), Equals, 1) + c.Assert(len(tk.MustQuery(`select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 = 0x002B200DF5BA03E59F82`).Rows()), Equals, 1) +} + func (s *testIntegrationSuite) TestFullGroupByOrderBy(c *C) { tk := testkit.NewTestKit(c, s.store) diff --git a/util/ranger/points.go b/util/ranger/points.go index b4fc37bac5e20..3633c15690634 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -595,6 +595,9 @@ func (r *builder) buildFromIn(expr *expression.ScalarFunction) ([]*point, bool) continue } } + if expr.GetArgs()[0].GetType().EvalType() == types.ETString && (dt.Kind() == types.KindString || dt.Kind() == types.KindBinaryLiteral) { + dt.SetString(dt.GetString(), expr.GetArgs()[0].GetType().Collate) // refine the string like what we did in builder.buildFromBinOp + } var startValue, endValue types.Datum dt.Copy(&startValue) dt.Copy(&endValue)