Skip to content

Commit 7363f34

Browse files
author
Mattias Jonsson
committed
WL#6035: Native InnoDB Partitioning.
Implementing partitioning natively in InnoDB, so it does not need ha_partition generic partition engine for supporting partitioning. ha_partition uses one ha_innobase handler for each partition which does not share common data with each other resulting in high resource usage which this WL fix. It also makes it easier to support other InnoDB features that partitioning currently does not support. A new handler ha_innopart is added, inheriting both ha_innobase (for InnoDB access) and Partition_helper (for partitioning support, see wl#4807). And to avoid a proxy object for Partition_handler (see wl#4807) it is also inherited. Also ha_partition is changed to inherit Partition_handler directly. As a result of this there is no longer any need for .par files for partitioned InnoDB tables, since InnoDB can use its internal data dictionary for finding partitions during rename and delete. The optimizer estimate is also changed, especially for records_in_range, where all used partitions are checked instead of only the biggest ones. rb#7636 Approved by Krunal and Annamalai
1 parent 1d05b68 commit 7363f34

File tree

73 files changed

+10188
-3329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10188
-3329
lines changed

mysql-test/include/have_log_bin.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ==== Purpose ====
2-
#
2+
#
33
# Ensure that the server is running with binlogging on
44
#
55
# ==== Usage ====

mysql-test/include/partition_default_functions.inc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ FLUSH STATUS;
1515
SET TIMESTAMP = 1234567890;
1616
INSERT INTO t3 (a) VALUES (NULL);
1717
--source include/get_handler_status_counts.inc
18-
--echo # 4 locks (1 table, 1 partition lock/unlock)
1918
}
2019
FLUSH STATUS;
2120
SET TIMESTAMP = 1234567891;
2221
INSERT INTO t3 VALUES ();
2322
--source include/get_handler_status_counts.inc
24-
--echo # 4 locks (1 table, 1 partition lock/unlock)
2523
FLUSH STATUS;
2624
INSERT INTO t3 (a) VALUES ('2011-01-01 00:00:00');
2725
--source include/get_handler_status_counts.inc
28-
--echo # 4 locks (1 table, 1 partition lock/unlock)
2926
FLUSH STATUS;
3027
INSERT INTO t3 (a) VALUES ('2011-01-01 00:00:01');
3128
--source include/get_handler_status_counts.inc
32-
--echo # 4 locks (1 table, 1 partition lock/unlock)
3329
FLUSH STATUS;
3430
INSERT INTO t3 (a) VALUES ('2011-01-01 00:00:02'), ('2011-01-01 00:00:03');
3531
--source include/get_handler_status_counts.inc
36-
--echo # 6 locks (1 table, 2 partition lock/unlock)
3732
--echo # 2 writes
3833
FLUSH STATUS;
3934
SET TIMESTAMP = 1234567892;
@@ -42,22 +37,19 @@ ON DUPLICATE KEY UPDATE b = "DUP_KEY";
4237
--source include/get_handler_status_counts.inc
4338
if ($default_update)
4439
{
45-
--echo # 8 locks (1 table, 3 partition lock/unlock)
4640
--echo # No pruning due to DEFAULT function on partitioning column
4741
--echo # 1 read_key + 1 delete + 2 write (1 failed + 1 ok)
4842
--echo # 1 delete + 1 write due to moved to different partition
4943
}
5044
if (!$default_update)
5145
{
52-
--echo # 4 locks (1 table, 1 partition lock/unlock)
5346
--echo # 1 read_key + 1 update (same partition)
5447
--echo # 1 (failed) write
5548
}
5649
FLUSH STATUS;
5750
INSERT INTO t3 (a) VALUES ('2011-01-01 00:00:01')
5851
ON DUPLICATE KEY UPDATE a = '2011-01-01 00:00:05', b = "DUP_KEY2";
5952
--source include/get_handler_status_counts.inc
60-
--echo # 8 locks (1 table, 3 partition lock/unlock)
6153
--echo # No pruning due to updating partitioning field.
6254
--echo # 1 read_key + 1 delete + 2 write (1 failed + 1 ok)
6355
--echo # 1 delete + 1 write due to moved to different partition
@@ -67,7 +59,6 @@ UPDATE t3 SET b = 'Updated' WHERE a = '2011-01-01 00:00:02';
6759
--source include/get_handler_status_counts.inc
6860
if ($default_update)
6961
{
70-
--echo # 8 locks (1 table, 3 partition lock/unlock)
7162
--echo # No pruning due to DEFAULT function on partitioning column
7263
--echo # 2 read_key + 1 read_rnd (1 read_key due to index lookup,
7364
--echo # 1 read_rnd + 1 read_key due to positioning before update)
@@ -76,18 +67,15 @@ if ($default_update)
7667
}
7768
if (!$default_update)
7869
{
79-
--echo # 4 locks (1 table, 1 partition lock/unlock)
8070
--echo # 1 read_key + 1 update (same partition)
8171
--echo # 1 (failed) write
8272
}
8373
FLUSH STATUS;
8474
REPLACE INTO t3 VALUES ('2011-01-01 00:00:04', 'Replace1');
8575
--source include/get_handler_status_counts.inc
86-
--echo # 4 locks (1 table, 1 partition lock/unlock)
8776
FLUSH STATUS;
8877
REPLACE INTO t3 VALUES ('2011-01-01 00:00:04', 'Replace2');
8978
--source include/get_handler_status_counts.inc
90-
--echo # 4 locks (1 table, 1 partition lock/unlock)
9179
--echo # 1 read_key + 1 update + 1 failed write
9280

9381
--echo #
@@ -98,12 +86,10 @@ FLUSH STATUS;
9886
SET TIMESTAMP = 1234567894;
9987
REPLACE INTO t3 (b) VALUES ('Replace3');
10088
--source include/get_handler_status_counts.inc
101-
--echo # 4 locks (1 table, 1 partition lock/unlock)
10289
FLUSH STATUS;
10390
SET TIMESTAMP = 1234567894;
10491
REPLACE INTO t3 (b) VALUES ('Replace4');
10592
--source include/get_handler_status_counts.inc
106-
--echo # 4 locks (1 table, 1 partition lock/unlock)
10793
--echo # 1 read_key + 1 update + 1 failed write
10894
--sorted_result
10995
SELECT * FROM t3;

mysql-test/r/partition_column.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Table Op Msg_type Msg_text
101101
test.t1 analyze status OK
102102
explain partitions select hex(a) from t1 where a like 'A_';
103103
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
104-
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 50.00 Using where
104+
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 1 100.00 Using where
105105
Warnings:
106106
Warning 1681 'PARTITIONS' is deprecated and will be removed in a future release.
107107
Note 1003 /* select#1 */ select hex(`test`.`t1`.`a`) AS `hex(a)` from `test`.`t1` where (`test`.`t1`.`a` like 'A_')
@@ -513,7 +513,7 @@ Table Op Msg_type Msg_text
513513
test.t1 analyze status OK
514514
explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
515515
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
516-
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 12.50 Using where
516+
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 1 100.00 Using where
517517
Warnings:
518518
Warning 1681 'PARTITIONS' is deprecated and will be removed in a future release.
519519
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`c` = 1) and (`test`.`t1`.`a` = 1) and (`test`.`t1`.`b` <= 'A'))
@@ -683,7 +683,7 @@ Table Op Msg_type Msg_text
683683
test.t1 analyze status OK
684684
explain partitions select * from t1 where b < 4;
685685
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
686-
1 SIMPLE t1 p0,p11,p12,p21 ALL NULL NULL NULL NULL 7 33.33 Using where
686+
1 SIMPLE t1 p0,p11,p12,p21 ALL NULL NULL NULL NULL 6 33.33 Using where
687687
Warnings:
688688
Warning 1681 'PARTITIONS' is deprecated and will be removed in a future release.
689689
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`b` < 4)

mysql-test/r/partition_column_prune.result

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ insert into t1 values ('a', NULL, 'd');
66
analyze table t1;
77
Table Op Msg_type Msg_text
88
test.t1 analyze status OK
9-
explain partitions select * from t1 where a = 'a' AND c = 'd';
9+
explain select * from t1 where a = 'a' AND c = 'd';
1010
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
11-
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 25.00 Using where
11+
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 1 100.00 Using where
1212
Warnings:
13-
Warning 1681 'PARTITIONS' is deprecated and will be removed in a future release.
1413
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`c` = 'd') and (`test`.`t1`.`a` = 'a'))
1514
select * from t1 where a = 'a' AND c = 'd';
1615
a b c

mysql-test/r/partition_debug_sync.result

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,44 @@ SET DEBUG_SYNC="now SIGNAL release";
130130
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
131131
AUTO_INCREMENT
132132
15
133-
DROP TABLE t1;
133+
#
134+
# Test with INSERT SELECT
135+
#
136+
TRUNCATE TABLE t1;
137+
CREATE TABLE t2 (a INT);
138+
INSERT INTO t1 VALUES (10);
139+
INSERT INTO t2 VALUES (3), (NULL), (4);
140+
SET DEBUG_SYNC="release_auto_increment SIGNAL auto_inc_held WAIT_FOR release";
141+
INSERT INTO t1 SELECT * FROM t2;
142+
# Con1
143+
SET DEBUG_SYNC="now WAIT_FOR auto_inc_held";
144+
INSERT INTO t1 VALUES (5);
145+
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
146+
AUTO_INCREMENT
147+
12
148+
SET DEBUG_SYNC="now SIGNAL release";
149+
# Default
150+
# Reaping: INSERT INTO t1 SELECT * FROM t2;
151+
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
152+
AUTO_INCREMENT
153+
12
154+
# Test with generating an auto inc value in Con1
155+
TRUNCATE TABLE t1;
156+
INSERT INTO t1 VALUES (10);
157+
SET DEBUG_SYNC="release_auto_increment SIGNAL auto_inc_held WAIT_FOR release";
158+
INSERT INTO t1 SELECT * FROM t2;
159+
# Con1
160+
SET DEBUG_SYNC="now WAIT_FOR auto_inc_held";
161+
INSERT INTO t1 VALUES (NULL);
162+
# Not really a bug, since no row has been assigned the number between
163+
# this and the next auto_inc value.
164+
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
165+
AUTO_INCREMENT
166+
13
167+
SET DEBUG_SYNC="now SIGNAL release";
168+
# Default
169+
# Reaping: INSERT INTO t1 SELECT * FROM t2;
170+
SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
171+
AUTO_INCREMENT
172+
13
173+
DROP TABLE t1, t2;

mysql-test/r/partition_debug_sync_stmt.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
8686
AUTO_INCREMENT
8787
13
8888
DROP TABLE t1, t2;
89+
SET DEBUG_SYNC='RESET';

mysql-test/r/partition_error.result

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ CREATE TABLE t1 (id INT, purchased DATE)
742742
PARTITION BY RANGE(YEAR(purchased))
743743
SUBPARTITION BY HASH(TO_DAYS(purchased))
744744
(PARTITION p0 VALUES LESS THAN MAXVALUE
745-
DATA DIRECTORY = '/tmp/not-existing'
746-
INDEX DIRECTORY = '/tmp/not-existing');
745+
DATA DIRECTORY = '/tmp/not-existing'
746+
INDEX DIRECTORY = '/tmp/not-existing');
747747
Warnings:
748748
Warning 1618 <DATA DIRECTORY> option ignored
749749
Warning 1618 <INDEX DIRECTORY> option ignored
@@ -764,8 +764,8 @@ PARTITION BY RANGE(YEAR(purchased))
764764
SUBPARTITION BY HASH(TO_DAYS(purchased)) SUBPARTITIONS 2
765765
(PARTITION p0 VALUES LESS THAN MAXVALUE
766766
(SUBPARTITION sp0
767-
DATA DIRECTORY = '/tmp/not-existing'
768-
INDEX DIRECTORY = '/tmp/not-existing',
767+
DATA DIRECTORY = '/tmp/not-existing'
768+
INDEX DIRECTORY = '/tmp/not-existing',
769769
SUBPARTITION sp1));
770770
Warnings:
771771
Warning 1618 <DATA DIRECTORY> option ignored
@@ -785,8 +785,8 @@ DROP TABLE t1;
785785
CREATE TABLE t1 (id INT, purchased DATE)
786786
PARTITION BY RANGE(YEAR(purchased))
787787
(PARTITION p0 VALUES LESS THAN MAXVALUE
788-
DATA DIRECTORY = '/tmp/not-existing'
789-
INDEX DIRECTORY = '/tmp/not-existing');
788+
DATA DIRECTORY = '/tmp/not-existing'
789+
INDEX DIRECTORY = '/tmp/not-existing');
790790
Warnings:
791791
Warning 1618 <DATA DIRECTORY> option ignored
792792
Warning 1618 <INDEX DIRECTORY> option ignored
@@ -1173,7 +1173,7 @@ partitions 2
11731173
(partition x1 values less than (4) tablespace ts1,
11741174
partition x2 values less than (8) tablespace ts2);
11751175
ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
1176-
CREATE TABLE t1 (
1176+
CREATE TABLE t1 (
11771177
a int not null,
11781178
b int not null,
11791179
c int not null,
@@ -1294,21 +1294,21 @@ a int not null,
12941294
b int not null,
12951295
c int not null,
12961296
primary key (a,b))
1297-
partition by key (a)
1297+
partition by key (a)
12981298
subpartition by list (a+b)
12991299
( partition x1
13001300
( subpartition x11,
13011301
subpartition x12),
1302-
partition x2
1302+
partition x2
13031303
( subpartition x21,
13041304
subpartition x22)
13051305
);
13061306
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'list (a+b)
13071307
( partition x1
13081308
( subpartition x11,
13091309
subpartition x12),
1310-
partition x2
1311-
(' at line 7
1310+
partition x2
1311+
( ' at line 7
13121312
CREATE TABLE t1 (
13131313
a int not null,
13141314
b int not null,
@@ -1340,7 +1340,7 @@ b int not null,
13401340
c int not null,
13411341
primary key(a,b))
13421342
partition by list (3+4)
1343-
partitions 2
1343+
partitions 2
13441344
(partition x1 values in (4) tablespace ts1,
13451345
partition x2 values in (8) tablespace ts2);
13461346
ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
@@ -1745,7 +1745,7 @@ ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitio
17451745
DROP TABLE old;
17461746
#
17471747
# Bug #56709: Memory leaks at running the 5.1 test suite
1748-
#
1748+
#
17491749
CREATE TABLE t1 (a TIMESTAMP NOT NULL PRIMARY KEY);
17501750
ALTER TABLE t1
17511751
PARTITION BY RANGE (EXTRACT(DAY FROM a)) (
@@ -1851,3 +1851,39 @@ pMax pMaxsp0 This is a long comment (2050 ascii characters) 50 pMax partition
18511851
pMax pMaxsp1 This is a long comment (2050 ascii characters) 50 pMax partition comment .80-!
18521852
DROP TABLE t1;
18531853
SET sql_mode = default;
1854+
#
1855+
# Test for increased coverage of misplaced record handling.
1856+
#
1857+
CREATE TABLE t1 (a int)
1858+
PARTITION BY LIST (a)
1859+
(PARTITION p1 VALUES IN (1),
1860+
PARTITION p3 VALUES IN (3,5),
1861+
PARTITION p6 VALUES IN (6,7));
1862+
# Intentionally insert illegal rows into p1.
1863+
CREATE TABLE t2 LIKE t1;
1864+
ALTER TABLE t2 REMOVE PARTITIONING;
1865+
INSERT INTO t2 VALUES (2),(3),(4),(6);
1866+
ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2 WITHOUT VALIDATION;
1867+
# These should fail gracefully (WHERE used to not trigger pruning!)
1868+
CALL mtr.add_suppression(" corrupted: row in wrong partition: ");
1869+
INSERT INTO t1 VALUES (2);
1870+
ERROR HY000: Table has no partition for value 2
1871+
INSERT INTO t1 PARTITION (p1) VALUES (3);
1872+
ERROR HY000: Found a row not matching the given partition set
1873+
UPDATE t1 SET a = 3 WHERE (a % 3) != 0;
1874+
ERROR HY000: Table has no partition for value 2
1875+
UPDATE t1 PARTITION (p1) SET a = 3 WHERE (a % 3) != 0;
1876+
ERROR HY000: Table has no partition for value 2
1877+
UPDATE t1 PARTITION (p1) SET a = 5 WHERE (a % 3) = 0;
1878+
ERROR HY000: Found a row not matching the given partition set
1879+
UPDATE t1 PARTITION (p1) SET a = 3 WHERE (a % 5) > 3;
1880+
ERROR HY000: Table has no partition for value 4
1881+
UPDATE t1 PARTITION (p1,p6) SET a = 7 WHERE (a % 7) > 5;
1882+
ERROR HY000: Found a row in wrong partition 0. Correct is 2 a:6
1883+
DELETE FROM t1 PARTITION (p1) WHERE (a % 7) > 2;
1884+
ERROR HY000: Found a row not matching the given partition set
1885+
DELETE FROM t1 PARTITION (p1,p6) WHERE (a % 7) > 5;
1886+
ERROR HY000: Found a row in wrong partition 0. Correct is 2 a:6
1887+
DELETE FROM t1 WHERE a > 0;
1888+
ERROR HY000: Table has no partition for value 2
1889+
DROP TABLE t1, t2;

mysql-test/r/partition_exchange.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ a b
15151515
163 163
15161516
164 164
15171517
200 Two hundred, end of values
1518-
call mtr.add_suppression("Cannot find index PRIMARY in InnoDB index translation table.");
1518+
call mtr.add_suppression("Cannot find index .PRIMARY. in InnoDB index translation table.");
15191519
ALTER TABLE tsp REBUILD PARTITION p1;
15201520
Got one of the listed errors
15211521
ALTER TABLE tsp REORGANIZE PARTITION p1 INTO

0 commit comments

Comments
 (0)