From c84e0bbad6208852787f911ac6466a6b47bea62e Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Wed, 25 Oct 2023 13:36:27 +0800 Subject: [PATCH] move partition_test.go --- pkg/executor/test/partitiontest/BUILD.bazel | 2 +- .../test/partitiontest/partition_test.go | 54 ------------------- .../r/executor/partition/table.result | 49 +++++++++++++++++ .../t/executor/partition/table.test | 41 ++++++++++++++ 4 files changed, 91 insertions(+), 55 deletions(-) diff --git a/pkg/executor/test/partitiontest/BUILD.bazel b/pkg/executor/test/partitiontest/BUILD.bazel index 1f2f0adfeeb71..eba32c340a02d 100644 --- a/pkg/executor/test/partitiontest/BUILD.bazel +++ b/pkg/executor/test/partitiontest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 5, + shard_count = 4, deps = [ "//pkg/testkit", "@com_github_pingcap_failpoint//:failpoint", diff --git a/pkg/executor/test/partitiontest/partition_test.go b/pkg/executor/test/partitiontest/partition_test.go index 28e9002060e27..cbffd97769b9e 100644 --- a/pkg/executor/test/partitiontest/partition_test.go +++ b/pkg/executor/test/partitiontest/partition_test.go @@ -447,57 +447,3 @@ func TestPartitionedTableDelete(t *testing.T) { tk.CheckExecResult(1, 0) tk.MustExec(`drop table t1;`) } - -func TestPartitionOnMissing(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create schema OnMissing") - tk.MustExec("use OnMissing") - tk.MustExec(`set global tidb_partition_prune_mode='dynamic'`) - tk.MustExec(`set session tidb_partition_prune_mode='dynamic'`) - - tk.MustExec(`CREATE TABLE tt1 ( - id INT NOT NULL, - listid INT, - name varchar(10), - primary key (listid) clustered - ) - PARTITION BY LIST (listid) ( - PARTITION p1 VALUES IN (1), - PARTITION p2 VALUES IN (2), - PARTITION p3 VALUES IN (3), - PARTITION p4 VALUES IN (4) - )`) - - tk.MustExec(`CREATE TABLE tt2 ( - id INT NOT NULL, - listid INT - )`) - - tk.MustExec(`create index idx_listid on tt1(id,listid)`) - tk.MustExec(`create index idx_listid on tt2(listid)`) - - tk.MustExec(`insert into tt1 values(1,1,1)`) - tk.MustExec(`insert into tt1 values(2,2,2)`) - tk.MustExec(`insert into tt1 values(3,3,3)`) - tk.MustExec(`insert into tt1 values(4,4,4)`) - tk.MustExec(`insert into tt2 values(1,1)`) - tk.MustExec(`insert into tt2 values(2,2)`) - tk.MustExec(`insert into tt2 values(3,3)`) - tk.MustExec(`insert into tt2 values(4,4)`) - tk.MustExec(`insert into tt2 values(5,5)`) - - tk.MustExec(`analyze table tt1`) - tk.MustExec(`analyze table tt2`) - - tk.MustQuery(`select /*+ inl_join(tt1)*/ count(*) from tt2 - left join tt1 on tt1.listid=tt2.listid and tt1.id=tt2.id`).Check(testkit.Rows("5")) - tk.MustQuery(`select /*+ inl_join(tt1)*/ count(*) from tt2 - left join tt1 on tt1.listid=tt2.listid`).Check(testkit.Rows("5")) - tk.MustQuery(`explain format = 'brief' select /*+ inl_join(tt1)*/ count(*) from tt2 - left join tt1 on tt1.listid=tt2.listid`).Check(testkit.Rows(""+ - "StreamAgg 1.00 root funcs:count(Column#13)->Column#7", - "└─IndexReader 1.00 root index:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#13", - " └─IndexFullScan 5.00 cop[tikv] table:tt2, index:idx_listid(listid) keep order:false")) -} diff --git a/tests/integrationtest/r/executor/partition/table.result b/tests/integrationtest/r/executor/partition/table.result index 0dc906bdc7301..99c99010a747a 100644 --- a/tests/integrationtest/r/executor/partition/table.result +++ b/tests/integrationtest/r/executor/partition/table.result @@ -494,3 +494,52 @@ select * from t where a > 7; a b rollback; set @@tidb_partition_prune_mode = default; +drop table if exists tt1, tt2; +set global tidb_partition_prune_mode='dynamic'; +set session tidb_partition_prune_mode='dynamic'; +CREATE TABLE tt1 ( +id INT NOT NULL, +listid INT, +name varchar(10), +primary key (listid) clustered +) +PARTITION BY LIST (listid) ( +PARTITION p1 VALUES IN (1), +PARTITION p2 VALUES IN (2), +PARTITION p3 VALUES IN (3), +PARTITION p4 VALUES IN (4) +); +CREATE TABLE tt2 ( +id INT NOT NULL, +listid INT +); +create index idx_listid on tt1(id,listid); +create index idx_listid on tt2(listid); +insert into tt1 values(1,1,1); +insert into tt1 values(2,2,2); +insert into tt1 values(3,3,3); +insert into tt1 values(4,4,4); +insert into tt2 values(1,1); +insert into tt2 values(2,2); +insert into tt2 values(3,3); +insert into tt2 values(4,4); +insert into tt2 values(5,5); +analyze table tt1; +analyze table tt2; +select /*+ inl_join(tt1)*/ count(*) from tt2 +left join tt1 on tt1.listid=tt2.listid and tt1.id=tt2.id; +count(*) +5 +select /*+ inl_join(tt1)*/ count(*) from tt2 +left join tt1 on tt1.listid=tt2.listid; +count(*) +5 +explain format = 'brief' select /*+ inl_join(tt1)*/ count(*) from tt2 +left join tt1 on tt1.listid=tt2.listid; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#13)->Column#7 +└─IndexReader 1.00 root index:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#13 + └─IndexFullScan 5.00 cop[tikv] table:tt2, index:idx_listid(listid) keep order:false +set global tidb_partition_prune_mode=default; +set session tidb_partition_prune_mode=default; diff --git a/tests/integrationtest/t/executor/partition/table.test b/tests/integrationtest/t/executor/partition/table.test index 337b949aa70f5..d3b8b7645cfbd 100644 --- a/tests/integrationtest/t/executor/partition/table.test +++ b/tests/integrationtest/t/executor/partition/table.test @@ -315,3 +315,44 @@ select * from t where a > 7; rollback; set @@tidb_partition_prune_mode = default; +# TestPartitionOnMissing +drop table if exists tt1, tt2; +set global tidb_partition_prune_mode='dynamic'; +set session tidb_partition_prune_mode='dynamic'; +CREATE TABLE tt1 ( + id INT NOT NULL, + listid INT, + name varchar(10), + primary key (listid) clustered +) +PARTITION BY LIST (listid) ( + PARTITION p1 VALUES IN (1), + PARTITION p2 VALUES IN (2), + PARTITION p3 VALUES IN (3), + PARTITION p4 VALUES IN (4) +); +CREATE TABLE tt2 ( + id INT NOT NULL, + listid INT +); +create index idx_listid on tt1(id,listid); +create index idx_listid on tt2(listid); +insert into tt1 values(1,1,1); +insert into tt1 values(2,2,2); +insert into tt1 values(3,3,3); +insert into tt1 values(4,4,4); +insert into tt2 values(1,1); +insert into tt2 values(2,2); +insert into tt2 values(3,3); +insert into tt2 values(4,4); +insert into tt2 values(5,5); +analyze table tt1; +analyze table tt2; +select /*+ inl_join(tt1)*/ count(*) from tt2 + left join tt1 on tt1.listid=tt2.listid and tt1.id=tt2.id; +select /*+ inl_join(tt1)*/ count(*) from tt2 + left join tt1 on tt1.listid=tt2.listid; +explain format = 'brief' select /*+ inl_join(tt1)*/ count(*) from tt2 + left join tt1 on tt1.listid=tt2.listid; +set global tidb_partition_prune_mode=default; +set session tidb_partition_prune_mode=default;