Skip to content

Commit

Permalink
move partition_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Oct 25, 2023
1 parent 82ef8cd commit c84e0bb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pkg/executor/test/partitiontest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 5,
shard_count = 4,
deps = [
"//pkg/testkit",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
54 changes: 0 additions & 54 deletions pkg/executor/test/partitiontest/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
49 changes: 49 additions & 0 deletions tests/integrationtest/r/executor/partition/table.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
41 changes: 41 additions & 0 deletions tests/integrationtest/t/executor/partition/table.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c84e0bb

Please sign in to comment.