Skip to content

Commit

Permalink
planner: move TestBatchPointGetTablePartition to `integration_parti…
Browse files Browse the repository at this point in the history
…tion_test.go` (#45620)

ref #44940
  • Loading branch information
Defined2014 authored Jul 27, 2023
1 parent 5f1fa9f commit faa88c9
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 239 deletions.
2 changes: 1 addition & 1 deletion planner/core/casetest/partition/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 11,
shard_count = 12,
deps = [
"//planner/core/internal",
"//sessionctx/variable",
Expand Down
62 changes: 62 additions & 0 deletions planner/core/casetest/partition/integration_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,65 @@ func TestPartitionTableExplain(t *testing.T) {
tk.MustQuery(tt).Check(testkit.Rows(output[i].StaticPlan...))
}
}

func TestBatchPointGetTablePartition(t *testing.T) {
failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`)
defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune")

store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1,t2,t3,t4,t5,t6")

tk.MustExec("create table t1(a int, b int, primary key(a,b) nonclustered) partition by hash(b) partitions 2")
tk.MustExec("insert into t1 values(1,1),(1,2),(2,1),(2,2)")

tk.MustExec("create table t2(a int, b int, primary key(a,b) nonclustered) partition by range(b) (partition p0 values less than (2), partition p1 values less than maxvalue)")
tk.MustExec("insert into t2 values(1,1),(1,2),(2,1),(2,2)")

tk.MustExec("create table t3(a int, b int, primary key(a,b)) partition by hash(b) partitions 2")
tk.MustExec("insert into t3 values(1,1),(1,2),(2,1),(2,2)")

tk.MustExec("create table t4(a int, b int, primary key(a,b)) partition by range(b) (partition p0 values less than (2), partition p1 values less than maxvalue)")
tk.MustExec("insert into t4 values(1,1),(1,2),(2,1),(2,2)")

tk.MustExec("create table t5(a int, b int, primary key(a)) partition by hash(a) partitions 2")
tk.MustExec("insert into t5 values(1,0),(2,0),(3,0),(4,0)")

tk.MustExec("create table t6(a int, b int, primary key(a)) partition by range(a) (partition p0 values less than (3), partition p1 values less than maxvalue)")
tk.MustExec("insert into t6 values(1,0),(2,0),(3,0),(4,0)")

tk.MustExec(`analyze table t1, t2, t3, t4, t5, t6`)

var input []string
var output []struct {
SQL string
DynamicPlan []string
StaticPlan []string
Result []string
}

integrationPartitionSuiteData := getIntegrationPartitionSuiteData()
integrationPartitionSuiteData.LoadTestCases(t, &input, &output)
for i, tt := range input {
testdata.OnRecord(func() {
output[i].SQL = tt
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")
output[i].DynamicPlan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + tt).Rows())
dynamicRes := testdata.ConvertRowsToStrings(tk.MustQuery(tt).Sort().Rows())
tk.MustExec("set @@tidb_partition_prune_mode = 'static'")
output[i].StaticPlan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + tt).Rows())
staticRes := testdata.ConvertRowsToStrings(tk.MustQuery(tt).Sort().Rows())

require.Equal(t, dynamicRes, staticRes)
output[i].Result = staticRes
})

tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")
tk.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].DynamicPlan...))
tk.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...))
tk.MustExec("set @@tidb_partition_prune_mode = 'static'")
tk.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].StaticPlan...))
tk.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,22 @@
"explain format = 'brief' select * from t partition (P0,p1) where b = 1",
"explain format = 'brief' select * from t partition (p1,P2) where b = 1 OR b = 2"
]
},
{
"name": "TestBatchPointGetTablePartition",
"cases": [
"select * from t1 where a in (1,2) and b = 1",
"select * from t1 where a = 1 and b in (1,2)",
"select * from t2 where a in (1,2) and b = 1",
"select * from t2 where a = 1 and b in (1,2)",
"select * from t3 where a in (1,2) and b = 1",
"select * from t3 where a = 1 and b in (1,2)",
"select * from t4 where a in (1,2) and b = 1",
"select * from t4 where a = 1 and b in (1,2)",
"select * from t5 where a in (1,2) and 1 = 1",
"select * from t5 where a in (1,3) and 1 = 1",
"select * from t6 where a in (1,2) and 1 = 1",
"select * from t6 where a in (1,3) and 1 = 1"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -1667,5 +1667,193 @@
]
}
]
},
{
"Name": "TestBatchPointGetTablePartition",
"Cases": [
{
"SQL": "select * from t1 where a in (1,2) and b = 1",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t1, index:PRIMARY(a, b) keep order:false, desc:false"
],
"StaticPlan": [
"Batch_Point_Get 2.00 root table:t1, index:PRIMARY(a, b) keep order:false, desc:false"
],
"Result": [
"1 1",
"2 1"
]
},
{
"SQL": "select * from t1 where a = 1 and b in (1,2)",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t1, index:PRIMARY(a, b) keep order:false, desc:false"
],
"StaticPlan": [
"PartitionUnion 4.00 root ",
"├─Batch_Point_Get 2.00 root table:t1, index:PRIMARY(a, b) keep order:false, desc:false",
"└─Batch_Point_Get 2.00 root table:t1, index:PRIMARY(a, b) keep order:false, desc:false"
],
"Result": [
"1 1",
"1 2"
]
},
{
"SQL": "select * from t2 where a in (1,2) and b = 1",
"DynamicPlan": [
"IndexReader 2.00 root partition:p0 index:IndexRangeScan",
"└─IndexRangeScan 2.00 cop[tikv] table:t2, index:PRIMARY(a, b) range:[1 1,1 1], [2 1,2 1], keep order:false"
],
"StaticPlan": [
"IndexReader 2.00 root index:IndexRangeScan",
"└─IndexRangeScan 2.00 cop[tikv] table:t2, partition:p0, index:PRIMARY(a, b) range:[1 1,1 1], [2 1,2 1], keep order:false"
],
"Result": [
"1 1",
"2 1"
]
},
{
"SQL": "select * from t2 where a = 1 and b in (1,2)",
"DynamicPlan": [
"IndexReader 2.00 root partition:all index:IndexRangeScan",
"└─IndexRangeScan 2.00 cop[tikv] table:t2, index:PRIMARY(a, b) range:[1 1,1 1], [1 2,1 2], keep order:false"
],
"StaticPlan": [
"PartitionUnion 4.00 root ",
"├─IndexReader 2.00 root index:IndexRangeScan",
"│ └─IndexRangeScan 2.00 cop[tikv] table:t2, partition:p0, index:PRIMARY(a, b) range:[1 1,1 1], [1 2,1 2], keep order:false",
"└─IndexReader 2.00 root index:IndexRangeScan",
" └─IndexRangeScan 2.00 cop[tikv] table:t2, partition:p1, index:PRIMARY(a, b) range:[1 1,1 1], [1 2,1 2], keep order:false"
],
"Result": [
"1 1",
"1 2"
]
},
{
"SQL": "select * from t3 where a in (1,2) and b = 1",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t3, clustered index:PRIMARY(a, b) keep order:false, desc:false"
],
"StaticPlan": [
"Batch_Point_Get 2.00 root table:t3, clustered index:PRIMARY(a, b) keep order:false, desc:false"
],
"Result": [
"1 1",
"2 1"
]
},
{
"SQL": "select * from t3 where a = 1 and b in (1,2)",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t3, clustered index:PRIMARY(a, b) keep order:false, desc:false"
],
"StaticPlan": [
"PartitionUnion 2.00 root ",
"├─Batch_Point_Get 2.00 root table:t3, clustered index:PRIMARY(a, b) keep order:false, desc:false",
"└─Batch_Point_Get 2.00 root table:t3, clustered index:PRIMARY(a, b) keep order:false, desc:false"
],
"Result": [
"1 1",
"1 2"
]
},
{
"SQL": "select * from t4 where a in (1,2) and b = 1",
"DynamicPlan": [
"TableReader 2.00 root partition:p0 data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t4 range:[1 1,1 1], [2 1,2 1], keep order:false"
],
"StaticPlan": [
"TableReader 2.00 root data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t4, partition:p0 range:[1 1,1 1], [2 1,2 1], keep order:false"
],
"Result": [
"1 1",
"2 1"
]
},
{
"SQL": "select * from t4 where a = 1 and b in (1,2)",
"DynamicPlan": [
"TableReader 2.00 root partition:all data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t4 range:[1 1,1 1], [1 2,1 2], keep order:false"
],
"StaticPlan": [
"PartitionUnion 2.00 root ",
"├─TableReader 2.00 root data:TableRangeScan",
"│ └─TableRangeScan 2.00 cop[tikv] table:t4, partition:p0 range:[1 1,1 1], [1 2,1 2], keep order:false",
"└─TableReader 2.00 root data:TableRangeScan",
" └─TableRangeScan 2.00 cop[tikv] table:t4, partition:p1 range:[1 1,1 1], [1 2,1 2], keep order:false"
],
"Result": [
"1 1",
"1 2"
]
},
{
"SQL": "select * from t5 where a in (1,2) and 1 = 1",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t5 handle:[1 2], keep order:false, desc:false"
],
"StaticPlan": [
"PartitionUnion 4.00 root ",
"├─Batch_Point_Get 2.00 root table:t5 handle:[1 2], keep order:false, desc:false",
"└─Batch_Point_Get 2.00 root table:t5 handle:[1 2], keep order:false, desc:false"
],
"Result": [
"1 0",
"2 0"
]
},
{
"SQL": "select * from t5 where a in (1,3) and 1 = 1",
"DynamicPlan": [
"Batch_Point_Get 2.00 root table:t5 handle:[1 3], keep order:false, desc:false"
],
"StaticPlan": [
"Batch_Point_Get 2.00 root table:t5 handle:[1 3], keep order:false, desc:false"
],
"Result": [
"1 0",
"3 0"
]
},
{
"SQL": "select * from t6 where a in (1,2) and 1 = 1",
"DynamicPlan": [
"TableReader 2.00 root partition:p0 data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t6 range:[1,1], [2,2], keep order:false"
],
"StaticPlan": [
"TableReader 2.00 root data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t6, partition:p0 range:[1,1], [2,2], keep order:false"
],
"Result": [
"1 0",
"2 0"
]
},
{
"SQL": "select * from t6 where a in (1,3) and 1 = 1",
"DynamicPlan": [
"TableReader 2.00 root partition:all data:TableRangeScan",
"└─TableRangeScan 2.00 cop[tikv] table:t6 range:[1,1], [3,3], keep order:false"
],
"StaticPlan": [
"PartitionUnion 4.00 root ",
"├─TableReader 2.00 root data:TableRangeScan",
"│ └─TableRangeScan 2.00 cop[tikv] table:t6, partition:p0 range:[1,1], [3,3], keep order:false",
"└─TableReader 2.00 root data:TableRangeScan",
" └─TableRangeScan 2.00 cop[tikv] table:t6, partition:p1 range:[1,1], [3,3], keep order:false"
],
"Result": [
"1 0",
"3 0"
]
}
]
}
]
Loading

0 comments on commit faa88c9

Please sign in to comment.