Skip to content

Commit 5367ce9

Browse files
committed
fix
1 parent dfd11c7 commit 5367ce9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

executor/batch_point_get_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,23 @@ func TestBatchPointGetIssue46779(t *testing.T) {
379379
tk.MustExec("drop table if exists t1")
380380
tk.MustExec("CREATE TABLE t1 (id int, c varchar(128), primary key (id)) PARTITION BY HASH (id) PARTITIONS 3;")
381381
tk.MustExec(`insert into t1 values (1, "a"), (11, "b"), (21, "c")`)
382-
tk.MustQuery("select * from t1 where id in (1, 1, 11)").Sort().Check(testkit.Rows("1 a", "11 b"))
383-
tk.MustQuery("select * from t1 where id in (1, 11, 11, 21)").Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))
382+
query := "select * from t1 where id in (1, 1, 11)"
383+
require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used
384+
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b"))
385+
query = "select * from t1 where id in (1, 11, 11, 21)"
386+
require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used
387+
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))
384388

385389
tk.MustExec("drop table if exists t2")
386390
tk.MustExec(`CREATE TABLE t2 (id int, c varchar(128), primary key (id)) partition by range (id)(
387391
partition p0 values less than (10),
388392
partition p1 values less than (20),
389393
partition p2 values less than (30));`)
390394
tk.MustExec(`insert into t2 values (1, "a"), (11, "b"), (21, "c")`)
391-
tk.MustQuery("select * from t2 where id in (1, 1, 11)").Sort().Check(testkit.Rows("1 a", "11 b"))
392-
tk.MustQuery("select * from t2 where id in (1, 11, 11, 21)").Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))
395+
query = "select * from t2 where id in (1, 1, 11)"
396+
require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used
397+
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b"))
398+
require.True(t, tk.HasPlan(query, "Batch_Point_Get")) // check if BatchPointGet is used
399+
query = "select * from t2 where id in (1, 11, 11, 21)"
400+
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))
393401
}

executor/builder.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5229,20 +5229,18 @@ func (b *executorBuilder) buildBatchPointGet(plan *plannercore.BatchPointGetPlan
52295229
// Used for clear paritionIDs of duplicated rows.
52305230
dupPartPos := 0
52315231
if plan.IndexInfo == nil {
5232-
dupPartID := len(plan.PartitionIDs) >= len(plan.Handles)
52335232
for idx, handle := range plan.Handles {
52345233
if _, found := dedup.Get(handle); found {
52355234
continue
52365235
}
52375236
dedup.Set(handle, true)
52385237
handles = append(handles, handle)
5239-
if dupPartID {
5238+
if len(plan.PartitionIDs) > 0 {
52405239
e.planPhysIDs[dupPartPos] = e.planPhysIDs[idx]
52415240
dupPartPos++
52425241
}
52435242
}
52445243
} else {
5245-
dupPartID := len(plan.PartitionIDs) >= len(plan.IndexValues)
52465244
for idx, value := range plan.IndexValues {
52475245
if datumsContainNull(value) {
52485246
continue
@@ -5265,7 +5263,7 @@ func (b *executorBuilder) buildBatchPointGet(plan *plannercore.BatchPointGetPlan
52655263
}
52665264
dedup.Set(handle, true)
52675265
handles = append(handles, handle)
5268-
if dupPartID {
5266+
if len(plan.PartitionIDs) > 0 {
52695267
e.planPhysIDs[dupPartPos] = e.planPhysIDs[idx]
52705268
dupPartPos++
52715269
}

0 commit comments

Comments
 (0)