Skip to content

Commit

Permalink
planner: fix wrong result when enabling dynamic mode in partition tab…
Browse files Browse the repository at this point in the history
…le for tiflash (pingcap#37442) (pingcap#37458)

close pingcap#37254
  • Loading branch information
ti-srebot authored Sep 19, 2022
1 parent dee851d commit 61b728d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,3 +1247,25 @@ func TestAggPushDownCountStar(t *testing.T) {

tk.MustQuery("select count(*) from c, o where c.c_id=o.c_id").Check(testkit.Rows("5"))
}

func TestTiflashEmptyDynamicPruneResult(t *testing.T) {
store, clean := testkit.CreateMockStore(t, withMockTiFlash(2))
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE `IDT_RP24833` ( `COL1` bigint(16) DEFAULT '15' COMMENT 'NUMERIC UNIQUE INDEX',\n `COL2` varchar(20) DEFAULT NULL,\n `COL4` datetime DEFAULT NULL,\n `COL3` bigint(20) DEFAULT NULL,\n `COL5` float DEFAULT NULL,\n KEY `UK_COL1` (`COL1`) /*!80000 INVISIBLE */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY RANGE ((`COL1`-57))\n(PARTITION `P0` VALUES LESS THAN (-3503857335115112215),\n PARTITION `P1` VALUES LESS THAN (-2987877108151063747),\n PARTITION `P2` VALUES LESS THAN (-1981049919102122710),\n PARTITION `P3` VALUES LESS THAN (-1635802972727465681),\n PARTITION `P4` VALUES LESS THAN (1186020639986357714),\n PARTITION `P5` VALUES LESS THAN (1220018677454711359),\n PARTITION `PMX` VALUES LESS THAN (MAXVALUE));")
tk.MustExec("alter table IDT_RP24833 set tiflash replica 1")
tb := external.GetTableByName(t, tk, "test", "IDT_RP24833")
err := domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)

tk.MustExec("insert into IDT_RP24833 values(-8448770111093677011, \"郇鋺篤堯擈斥鍮啸赠璭饱磟朅闑傒聎疫ᛄ怖霃\", \"8781-05-02 04:23:03\", -27252736532807028, -1.34554e38);")
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic';")
tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\";")
tk.MustExec("set @@session.tidb_allow_mpp=ON;")
tk.MustExec("set @@session.tidb_enforce_mpp = on;")
tk.MustQuery("select /*+ read_from_storage(tiflash[t1]) */ * from IDT_RP24833 partition(p3, p4) t1 where t1. col1 between -8448770111093677011 and -8448770111093677011;").Check(testkit.Rows())
tk.MustQuery("select /*+ read_from_storage(tiflash[t2]) */ * from IDT_RP24833 partition(p2) t2 where t2. col1 <= -8448770111093677011;").Check(testkit.Rows())
tk.MustQuery("select /*+ read_from_storage(tiflash[t1, t2]) */ * from IDT_RP24833 partition(p3, p4) t1 join IDT_RP24833 partition(p2) t2 on t1.col1 = t2.col1 where t1. col1 between -8448770111093677011 and -8448770111093677011 and t2. col1 <= -8448770111093677011;").Check(testkit.Rows())
}
12 changes: 11 additions & 1 deletion planner/core/fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,17 @@ func partitionPruning(ctx sessionctx.Context, tbl table.PartitionedTable, conds
}
}
if len(ret) == 0 {
ret = []table.PhysicalTable{tbl.GetPartition(pi.Definitions[0].ID)}
// TiFlash cannot process an empty task correctly, so choose to leave it with some data to read.
if len(partitionNames) == 0 {
ret = []table.PhysicalTable{tbl.GetPartition(pi.Definitions[0].ID)}
} else {
for _, def := range pi.Definitions {
if def.Name.L == partitionNames[0].L {
ret = []table.PhysicalTable{tbl.GetPartition(def.ID)}
break
}
}
}
}
return ret, nil
}
Expand Down

0 comments on commit 61b728d

Please sign in to comment.