diff --git a/pkg/planner/core/casetest/BUILD.bazel b/pkg/planner/core/casetest/BUILD.bazel index a9cac84c4ba66..037ae24961c47 100644 --- a/pkg/planner/core/casetest/BUILD.bazel +++ b/pkg/planner/core/casetest/BUILD.bazel @@ -12,7 +12,7 @@ go_test( ], data = glob(["testdata/**"]), flaky = True, - shard_count = 20, + shard_count = 21, deps = [ "//pkg/domain", "//pkg/parser", diff --git a/pkg/planner/core/casetest/integration_test.go b/pkg/planner/core/casetest/integration_test.go index 515f1d1e44821..edb5c5adeefcd 100644 --- a/pkg/planner/core/casetest/integration_test.go +++ b/pkg/planner/core/casetest/integration_test.go @@ -420,3 +420,38 @@ func TestFixControl45132(t *testing.T) { tk.MustExec(`set @@tidb_opt_fix_control = "45132:0"`) tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`) } + +func TestIssue52023(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`CREATE TABLE t ( + a binary(1) NOT NULL, + PRIMARY KEY (a) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin + PARTITION BY RANGE COLUMNS(a) + (PARTITION P0 VALUES LESS THAN (_binary 0x03), + PARTITION P4 VALUES LESS THAN (_binary 0xc0), + PARTITION PMX VALUES LESS THAN (MAXVALUE))`) + tk.MustExec(`insert into t values (0x5)`) + tk.MustExec(`analyze table t`) + tk.MustQuery(`select * from t`).Check(testkit.Rows("\u0005")) + tk.MustQuery(`select * from t where a = 0x5`).Check(testkit.Rows("\u0005")) + tk.MustQuery(`select * from t where a = 5`).Check(testkit.Rows()) + tk.MustQuery(`select * from t where a IN (5,55)`).Check(testkit.Rows()) + tk.MustQuery(`select * from t where a IN (0x5,55)`).Check(testkit.Rows("\u0005")) + tk.MustQuery(`explain select * from t where a = 0x5`).Check(testkit.Rows("Point_Get_1 1.00 root table:t, partition:P4, clustered index:PRIMARY(a) ")) + tk.MustQuery(`explain format='brief' select * from t where a = 5`).Check(testkit.Rows(""+ + "TableReader 0.80 root partition:all data:Selection", + "└─Selection 0.80 cop[tikv] eq(cast(test.t.a, double BINARY), 5)", + " └─TableFullScan 1.00 cop[tikv] table:t keep order:false")) + tk.MustQuery(`explain format='brief' select * from t where a IN (5,55)`).Check(testkit.Rows(""+ + "TableReader 0.96 root partition:all data:Selection", + "└─Selection 0.96 cop[tikv] or(eq(cast(test.t.a, double BINARY), 5), eq(cast(test.t.a, double BINARY), 55))", + " └─TableFullScan 1.00 cop[tikv] table:t keep order:false")) + tk.MustQuery(`explain format='brief' select * from t where a IN (0x5,55)`).Check(testkit.Rows(""+ + "TableReader 1.00 root partition:all data:Selection", + "└─Selection 1.00 cop[tikv] or(eq(test.t.a, \"0x05\"), eq(cast(test.t.a, double BINARY), 55))", + " └─TableFullScan 1.00 cop[tikv] table:t keep order:false")) +} diff --git a/pkg/planner/core/point_get_plan.go b/pkg/planner/core/point_get_plan.go index 550c8b989d209..de57206b5d4b5 100644 --- a/pkg/planner/core/point_get_plan.go +++ b/pkg/planner/core/point_get_plan.go @@ -1706,12 +1706,12 @@ func getNameValuePairs(ctx PlanContext, tbl *model.TableInfo, tblName model.CISt d.SetString(d.GetString(), col.FieldType.GetCollate()) } - if col.GetType() == mysql.TypeString && col.GetCollate() == charset.CollationBin { // This type we needn't to pad `\0` in here. - return append(nvPairs, nameValuePair{colName: colName.Name.Name.L, colFieldType: &col.FieldType, value: d, con: con}), false - } if !checkCanConvertInPointGet(col, d) { return nil, false } + if col.GetType() == mysql.TypeString && col.GetCollate() == charset.CollationBin { // This type we needn't to pad `\0` in here. + return append(nvPairs, nameValuePair{colName: colName.Name.Name.L, colFieldType: &col.FieldType, value: d, con: con}), false + } dVal, err := d.ConvertTo(stmtCtx.TypeCtx(), &col.FieldType) if err != nil { if terror.ErrorEqual(types.ErrOverflow, err) {