Skip to content

Commit 7960878

Browse files
committed
#261 auto detect index scans to fix perf problem with partitions
1 parent 4c8f691 commit 7960878

File tree

4 files changed

+291
-80
lines changed

4 files changed

+291
-80
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
set default_storage_engine='tokudb';
2+
drop table if exists t,t1,t2,t3;
3+
CREATE TABLE `t` (
4+
`num` int(10) unsigned auto_increment NOT NULL,
5+
`val` varchar(32) DEFAULT NULL,
6+
PRIMARY KEY (`num`)
7+
);
8+
INSERT INTO t values (null,null);
9+
INSERT INTO t SELECT null,null FROM t;
10+
INSERT INTO t SELECT null,null FROM t;
11+
INSERT INTO t SELECT null,null FROM t;
12+
INSERT INTO t SELECT null,null FROM t;
13+
INSERT INTO t SELECT null,null FROM t;
14+
INSERT INTO t SELECT null,null FROM t;
15+
INSERT INTO t SELECT null,null FROM t;
16+
INSERT INTO t SELECT null,null FROM t;
17+
INSERT INTO t SELECT null,null FROM t;
18+
INSERT INTO t SELECT null,null FROM t;
19+
INSERT INTO t SELECT null,null FROM t;
20+
INSERT INTO t SELECT null,null FROM t;
21+
INSERT INTO t SELECT null,null FROM t;
22+
INSERT INTO t SELECT null,null FROM t;
23+
INSERT INTO t SELECT null,null FROM t;
24+
INSERT INTO t SELECT null,null FROM t;
25+
INSERT INTO t SELECT null,null FROM t;
26+
INSERT INTO t SELECT null,null FROM t;
27+
INSERT INTO t SELECT null,null FROM t;
28+
INSERT INTO t SELECT null,null FROM t;
29+
INSERT INTO t SELECT null,null FROM t;
30+
INSERT INTO t SELECT null,null FROM t;
31+
INSERT INTO t SELECT null,null FROM t;
32+
SELECT count(*) FROM t;
33+
count(*)
34+
8388608
35+
CREATE TABLE `t1` (
36+
`num` int(10) unsigned NOT NULL,
37+
`val` varchar(32) DEFAULT NULL,
38+
PRIMARY KEY (`num`)
39+
);
40+
CREATE TABLE `t2` (
41+
`num` int(10) unsigned NOT NULL,
42+
`val` varchar(32) DEFAULT NULL,
43+
PRIMARY KEY (`num`)
44+
)
45+
PARTITION BY HASH (num) PARTITIONS 10;
46+
CREATE TABLE `t3` (
47+
`num` int(10) unsigned NOT NULL,
48+
`val` varchar(32) DEFAULT NULL,
49+
PRIMARY KEY (`num`)
50+
)
51+
PARTITION BY RANGE (num)
52+
(PARTITION p0 VALUES LESS THAN (1000000),
53+
PARTITION p1 VALUES LESS THAN (2000000),
54+
PARTITION p2 VALUES LESS THAN (3000000),
55+
PARTITION p3 VALUES LESS THAN (4000000),
56+
PARTITION p4 VALUES LESS THAN (5000000),
57+
PARTITION p5 VALUES LESS THAN (6000000),
58+
PARTITION p6 VALUES LESS THAN (7000000),
59+
PARTITION p7 VALUES LESS THAN (8000000),
60+
PARTITION px VALUES LESS THAN MAXVALUE);
61+
insert into t1 select * from t;
62+
insert into t2 select * from t;
63+
insert into t3 select * from t;
64+
select count(*) from t1;
65+
count(*)
66+
8388608
67+
select count(*) from t2;
68+
count(*)
69+
8388608
70+
1
71+
select count(*) from t3;
72+
count(*)
73+
8388608
74+
1
75+
select count(*) from t1 where num>7000000;
76+
count(*)
77+
1847274
78+
select count(*) from t2 where num>7000000;
79+
count(*)
80+
1847274
81+
1
82+
select count(*) from t3 where num>7000000;
83+
count(*)
84+
1847274
85+
1
86+
drop table if exists t,t1,t2,t3;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# verify that index scans on parititions are not slow
2+
# due totokudb bulk fetch not being used
3+
source include/have_tokudb.inc;
4+
set default_storage_engine='tokudb';
5+
disable_warnings;
6+
drop table if exists t,t1,t2,t3;
7+
8+
CREATE TABLE `t` (
9+
`num` int(10) unsigned auto_increment NOT NULL,
10+
`val` varchar(32) DEFAULT NULL,
11+
PRIMARY KEY (`num`)
12+
);
13+
14+
# put 8M rows into t
15+
INSERT INTO t values (null,null);
16+
INSERT INTO t SELECT null,null FROM t;
17+
INSERT INTO t SELECT null,null FROM t;
18+
INSERT INTO t SELECT null,null FROM t;
19+
INSERT INTO t SELECT null,null FROM t;
20+
INSERT INTO t SELECT null,null FROM t;
21+
INSERT INTO t SELECT null,null FROM t;
22+
INSERT INTO t SELECT null,null FROM t;
23+
INSERT INTO t SELECT null,null FROM t;
24+
INSERT INTO t SELECT null,null FROM t;
25+
INSERT INTO t SELECT null,null FROM t;
26+
INSERT INTO t SELECT null,null FROM t;
27+
INSERT INTO t SELECT null,null FROM t;
28+
INSERT INTO t SELECT null,null FROM t;
29+
INSERT INTO t SELECT null,null FROM t;
30+
INSERT INTO t SELECT null,null FROM t;
31+
INSERT INTO t SELECT null,null FROM t;
32+
INSERT INTO t SELECT null,null FROM t;
33+
INSERT INTO t SELECT null,null FROM t;
34+
INSERT INTO t SELECT null,null FROM t;
35+
INSERT INTO t SELECT null,null FROM t;
36+
INSERT INTO t SELECT null,null FROM t;
37+
INSERT INTO t SELECT null,null FROM t;
38+
INSERT INTO t SELECT null,null FROM t;
39+
SELECT count(*) FROM t;
40+
41+
CREATE TABLE `t1` (
42+
`num` int(10) unsigned NOT NULL,
43+
`val` varchar(32) DEFAULT NULL,
44+
PRIMARY KEY (`num`)
45+
);
46+
47+
CREATE TABLE `t2` (
48+
`num` int(10) unsigned NOT NULL,
49+
`val` varchar(32) DEFAULT NULL,
50+
PRIMARY KEY (`num`)
51+
)
52+
PARTITION BY HASH (num) PARTITIONS 10;
53+
54+
CREATE TABLE `t3` (
55+
`num` int(10) unsigned NOT NULL,
56+
`val` varchar(32) DEFAULT NULL,
57+
PRIMARY KEY (`num`)
58+
)
59+
PARTITION BY RANGE (num)
60+
(PARTITION p0 VALUES LESS THAN (1000000),
61+
PARTITION p1 VALUES LESS THAN (2000000),
62+
PARTITION p2 VALUES LESS THAN (3000000),
63+
PARTITION p3 VALUES LESS THAN (4000000),
64+
PARTITION p4 VALUES LESS THAN (5000000),
65+
PARTITION p5 VALUES LESS THAN (6000000),
66+
PARTITION p6 VALUES LESS THAN (7000000),
67+
PARTITION p7 VALUES LESS THAN (8000000),
68+
PARTITION px VALUES LESS THAN MAXVALUE);
69+
70+
insert into t1 select * from t;
71+
insert into t2 select * from t;
72+
insert into t3 select * from t;
73+
74+
# verify that full index scans on partitioned tables t2 and t3 are comparable to a non-partitioned table t1
75+
let $s = `select to_seconds(now())`;
76+
select count(*) from t1;
77+
let $t1 = `select to_seconds(now()) - $s`;
78+
# echo $t1;
79+
80+
let $s = `select to_seconds(now())`;
81+
select count(*) from t2;
82+
let $t2 = `select to_seconds(now()) - $s`;
83+
# echo $t2;
84+
let $d = `select abs($t2 - $t1) <= $t1`;
85+
echo $d;
86+
87+
let $s = `select to_seconds(now())`;
88+
select count(*) from t3;
89+
let $t3 = `select to_seconds(now()) - $s`;
90+
# echo $t3;
91+
let $d = `select abs($t3 - $t1) <= $t1`;
92+
echo $d;
93+
94+
let $s = `select to_seconds(now())`;
95+
select count(*) from t1 where num>7000000;
96+
let $t1 = `select to_seconds(now()) - $s`;
97+
# echo $t1;
98+
99+
let $s = `select to_seconds(now())`;
100+
select count(*) from t2 where num>7000000;
101+
let $t2 = `select to_seconds(now()) - $s`;
102+
# echo $t2;
103+
let $d = `select abs($t2 - $t1) <= $t1`;
104+
echo $d;
105+
106+
let $s = `select to_seconds(now())`;
107+
select count(*) from t3 where num>7000000;
108+
let $t3 = `select to_seconds(now()) - $s`;
109+
# echo $t3;
110+
let $d = `select abs($t3 - $t1) <= $t1`;
111+
echo $d;
112+
113+
enable_warnings;
114+
drop table if exists t,t1,t2,t3;

0 commit comments

Comments
 (0)