#At file:///Users/mattiasj/mysql-bzr/merge-trunk-wl5217/ based on revid:marc.alff@stripped4p3so6ze0m
3551 Mattias Jonsson 2011-01-26 [merge]
merge of WL#5217 with latest mysql-trunk
added:
mysql-test/collections/mysql-trunk-wl5217.push
mysql-test/r/partition_explicit_prune.result
mysql-test/t/partition_explicit_prune.test
modified:
include/my_base.h
mysql-test/r/partition_exchange.result
mysql-test/suite/parts/r/partition_exch_qa_13.result
mysql-test/suite/parts/r/partition_exch_qa_2.result
mysql-test/suite/parts/r/partition_mgm_lc0_archive.result
mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result
mysql-test/suite/parts/r/partition_mgm_lc0_memory.result
mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result
mysql-test/suite/parts/r/partition_mgm_lc1_archive.result
mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result
mysql-test/suite/parts/r/partition_mgm_lc1_memory.result
mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result
mysql-test/suite/parts/r/partition_mgm_lc2_archive.result
mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result
mysql-test/suite/parts/r/partition_mgm_lc2_memory.result
mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result
mysql-test/suite/parts/r/partition_repair_myisam.result
mysql-test/suite/parts/t/partition_debug_myisam.test
mysql-test/suite/parts/t/partition_repair_myisam.test
mysys/hash.c
mysys/my_handler.c
mysys/my_handler_errors.h
sql/ha_partition.cc
sql/ha_partition.h
sql/handler.cc
sql/handler.h
sql/mysqld.cc
sql/opt_range.cc
sql/partition_info.cc
sql/partition_info.h
sql/share/errmsg-utf8.txt
sql/sql_base.cc
sql/sql_class.h
sql/sql_lex.cc
sql/sql_lex.h
sql/sql_parse.cc
sql/sql_partition.cc
sql/sql_yacc.yy
sql/table.cc
sql/table.h
=== modified file 'include/my_base.h'
--- a/include/my_base.h 2011-01-11 09:09:21 +0000
+++ b/include/my_base.h 2011-01-26 15:48:12 +0000
@@ -446,7 +446,9 @@ enum ha_base_keytype {
#define HA_ERR_FILE_TOO_SHORT 175 /* File too short */
#define HA_ERR_WRONG_CRC 176 /* Wrong CRC on page */
#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 177 /*Too many active concurrent transactions */
-#define HA_ERR_LAST 177 /* Copy of last error nr */
+/* There's no explicitly listed partition in table for the given value */
+#define HA_ERR_NOT_IN_LOCK_PARTITIONS 178
+#define HA_ERR_LAST 178 /* Copy of last error nr */
/* Number of different errors */
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)
=== added file 'mysql-test/collections/mysql-trunk-wl5217.push'
--- a/mysql-test/collections/mysql-trunk-wl5217.push 1970-01-01 00:00:00 +0000
+++ b/mysql-test/collections/mysql-trunk-wl5217.push 2010-12-17 12:48:18 +0000
@@ -0,0 +1,8 @@
+perl mysql-test-run.pl --suite=main,sys_vars,binlog,federated,rpl,innodb,perfschema,parts --force --timer --parallel=auto --comment=normal --skip-ndbcluster --report-features --experimental=collections/default.experimental
+perl mysql-test-run.pl --suite=main,sys_vars,binlog,federated,rpl,innodb,perfschema,parts --force --timer --parallel=auto --comment=ps --skip-ndbcluster --ps-protocol --experimental=collections/default.experimental
+perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs1+ps --suite=funcs_1 --ps-protocol --experimental=collections/default.experimental
+perl mysql-test-run.pl --force --timer --parallel=auto --comment=funcs2 --suite=funcs_2 --experimental=collections/default.experimental
+perl mysql-test-run.pl --force --timer --parallel=auto --comment=stress --suite=stress --experimental=collections/default.experimental
+perl mysql-test-run.pl --force --timer --parallel=auto --comment=jp --suite=jp --experimental=collections/default.experimental
+perl mysql-test-run.pl --suite=main,sys_vars,binlog,federated,rpl,innodb,perfschema,parts --force --timer --parallel=auto --comment=embedded --embedded-server --skip-rpl --skip-ndbcluster --experimental=collections/default.experimental
+perl mysql-test-run.pl --suite=main,sys_vars,binlog,federated,rpl,innodb,perfschema,parts --force --timer --parallel=auto --comment=debug --skip-ndbcluster --skip-rpl --report-features --experimental=collections/default.experimental
=== modified file 'mysql-test/r/partition_exchange.result'
--- a/mysql-test/r/partition_exchange.result 2010-11-16 00:55:42 +0000
+++ b/mysql-test/r/partition_exchange.result 2010-12-14 20:03:21 +0000
@@ -148,7 +148,7 @@ a b
63 Sixty three
64 Sixty four
ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
=== added file 'mysql-test/r/partition_explicit_prune.result'
--- a/mysql-test/r/partition_explicit_prune.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_explicit_prune.result 2011-01-26 15:48:12 +0000
@@ -0,0 +1,1435 @@
+# Original tests for WL#5217
+# Must have InnoDB as engine to get the same statistics results.
+# embedded uses MyISAM as default. CREATE SELECT uses the default engine.
+SET @old_default_storage_engine = @@default_storage_engine;
+SET @@default_storage_engine = 'InnoDB';
+# Test to show if I_S affects HANDLER_ counts
+FLUSH STATUS;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_WRITE 17
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 35
+# OK, seems to add number of variables processed before HANDLER_WRITE
+# and number of variables + 1 evaluated in the previous call in RND_NEXT
+CREATE TABLE t1
+(a INT NOT NULL,
+b varchar (64),
+INDEX (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0,
+SUBPARTITION subp1),
+PARTITION `p0-9` VALUES LESS THAN (10)
+(SUBPARTITION subp2,
+SUBPARTITION subp3),
+PARTITION `p10-99` VALUES LESS THAN (100)
+(SUBPARTITION subp4,
+SUBPARTITION subp5),
+PARTITION `p100-99999` VALUES LESS THAN (100000)
+(SUBPARTITION subp6,
+SUBPARTITION subp7));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) NOT NULL,
+ `b` varchar(64) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ KEY `b` (`b`,`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a)
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0 ENGINE = InnoDB,
+ SUBPARTITION subp1 ENGINE = InnoDB),
+ PARTITION `p0-9` VALUES LESS THAN (10)
+ (SUBPARTITION subp2 ENGINE = InnoDB,
+ SUBPARTITION subp3 ENGINE = InnoDB),
+ PARTITION `p10-99` VALUES LESS THAN (100)
+ (SUBPARTITION subp4 ENGINE = InnoDB,
+ SUBPARTITION subp5 ENGINE = InnoDB),
+ PARTITION `p100-99999` VALUES LESS THAN (100000)
+ (SUBPARTITION subp6 ENGINE = InnoDB,
+ SUBPARTITION subp7 ENGINE = InnoDB)) */
+# First test that the syntax is OK
+SHOW CREATE TABLE t1 PARTITION (subp0);
+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 'PARTITION (subp0)' at line 1
+# Not a correct partition list
+INSERT INTO t1 PARTITION () VALUES (1, "error");
+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 ') VALUES (1, "error")' at line 1
+INSERT INTO t1 PARTITION (pNonExisting) VALUES (1, "error");
+ERROR HY000: partition 'pNonExisting' doesn't exist
+INSERT INTO t1 PARTITION (pNeg, pNonExisting) VALUES (1, "error");
+ERROR HY000: partition 'pNonExisting' doesn't exist
+# Duplicate partitions and overlapping partitions and subpartitios is OK
+FLUSH STATUS;
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (-1, "pNeg(-subp1)");
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 6
+HANDLER_WRITE 18
+# Should be 1 commit
+# 6 external locks
+# (1 ha_partition + 2 ha_innobase) x 2 (lock + unlock)
+# and 18 write (1 ha_innobase + 17 internal I_S write)
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, "pNeg(-subp1)");
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, "(pNeg-)subp0");
+# should be correct
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (100, "`p100-99999`(-subp6)"), (101, "`p100-99999`(-subp7)"), (1000, "`p100-99999`(-subp6)");
+INSERT INTO t1 PARTITION(`p10-99`,subp3) VALUES (1, "subp3"), (10, "p10-99");
+FLUSH STATUS;
+INSERT INTO t1 PARTITION(subp3) VALUES (3, "subp3");
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_WRITE 18
+# Should be 1 commit
+# 4 external locks
+# (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+# and 18 write (1 ha_innobase + 17 internal I_S write)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_WRITE 17
+# should be 1 commit
+# 9 locks (1 ha_partition + 8 ha_innobase)
+# 17 writes (internal I_S)
+INSERT INTO t1 PARTITION(`p0-9`) VALUES (5, "p0-9:subp3");
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 36
+# + 1 commit
+# + 19 rnd next (internal I_S)
+# + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_RND_NEXT 38
+HANDLER_WRITE 54
+# + 9 locks (unlocks)
+# + 19 rnd next (internal I_S)
+# + 18 write (internal I_S)
+# Not matching partitions with inserted value
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (1, "error");
+ERROR HY000: Found a row not matching the given partition set
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (1, "error");
+ERROR HY000: Found a row not matching the given partition set
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1, "error"), (10, "error");
+ERROR HY000: Found a row not matching the given partition set
+INSERT INTO t1 VALUES (1000000, "error"), (9999999, "error");
+ERROR HY000: Table has no partition for value 1000000
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1000000, "error"), (9999999, "error");
+ERROR HY000: Table has no partition for value 1000000
+INSERT INTO t1 PARTITION (pNeg, subp4) VALUES (-7, "pNeg(-subp1)"), (-10, "pNeg(-subp0)"), (-1, "pNeg(-subp1)"), (-99, "pNeg(-subp1)");
+Got one of the listed errors
+SELECT * FROM t1 ORDER BY a;
+a b
+-3 pNeg(-subp1)
+-2 (pNeg-)subp0
+-1 pNeg(-subp1)
+1 subp3
+3 subp3
+5 p0-9:subp3
+10 p10-99
+100 `p100-99999`(-subp6)
+101 `p100-99999`(-subp7)
+1000 `p100-99999`(-subp6)
+SELECT PARTITION_NAME, SUBPARTITION_NAME, TABLE_ROWS
+FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_SCHEMA = 'test'
+AND TABLE_NAME = 't1' ORDER BY SUBPARTITION_NAME;
+PARTITION_NAME SUBPARTITION_NAME TABLE_ROWS
+pNeg subp0 1
+pNeg subp1 2
+p0-9 subp2 0
+p0-9 subp3 3
+p10-99 subp4 1
+p10-99 subp5 0
+p100-99999 subp6 2
+p100-99999 subp7 1
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (pNonexistent);
+ERROR HY000: partition 'pNonexistent' doesn't exist
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_WRITE 17
+# should have failed before locking (only 17 internal I_S writes)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2);
+a b
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 2
+HANDLER_WRITE 17
+# Should be 1 commit
+# 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+# 1 read first (also calls index_read)
+# 2 read key (first from innobase_get_index and second from index first)
+# 17 writes (internal I_S)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+a b
+-2 (pNeg-)subp0
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 8
+HANDLER_READ_FIRST 3
+HANDLER_READ_KEY 6
+HANDLER_READ_NEXT 3
+HANDLER_WRITE 17
+# Should be 1 commit
+# 8 locks (1 ha_partition + 2 + 1 ha_innobase) x 2
+# 3 read first (one for each partition)
+# 6 read key (3 from read first and 3 from innobase_get_index)
+# 3 read next (one next call after each read row)
+# 17 writes (internal I_S)
+FLUSH STATUS;
+LOCK TABLE t1 READ, t1 as TableAlias READ;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_KEY 18
+HANDLER_WRITE 17
+# 1 commit
+# 18 locks
+# 18 READ KEY from opening a new partition table instance,
+# (1 innobase_get_index for each index, per partition, 1 x 2 x 8 = 16
+# + info(HA_STATUS_CONST) call on the partition with the most number
+# of rows, 2 innobase_get_index for updating both index statistics)
+# 17 writes (internal I_S)
+SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+a b
+5 p0-9:subp3
+1 subp3
+3 subp3
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 20
+HANDLER_READ_NEXT 3
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 35
+# + 1 commit
+# + 1 read first (read first key from index in one partition)
+# + 2 read key (innobase_get_index from index_init + from index_first)
+# + 3 read next (one after each row)
+# + 19 rnd next (from the last I_S query)
+# + 18 write (internal I_S)
+SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+COUNT(*)
+1
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_FIRST 3
+HANDLER_READ_KEY 24
+HANDLER_READ_NEXT 4
+HANDLER_READ_RND_NEXT 38
+HANDLER_WRITE 53
+# + 1 commit
+# + 2 read first (one for each subpart)
+# + 4 read key (innobase_get_index from index_init + from index_first)
+# + 1 read next (one after each row)
+# + 19 rnd next (from the last I_S query)
+# + 18 write (internal I_S)
+SELECT * FROM t1 WHERE a = 1000000;
+a b
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 4
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_FIRST 3
+HANDLER_READ_KEY 24
+HANDLER_READ_NEXT 4
+HANDLER_READ_RND_NEXT 57
+HANDLER_WRITE 71
+# No matching partition, only + 1 commit + internal I_S.
+SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+a b
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 5
+HANDLER_EXTERNAL_LOCK 36
+HANDLER_READ_FIRST 3
+HANDLER_READ_KEY 24
+HANDLER_READ_NEXT 4
+HANDLER_READ_RND_NEXT 76
+HANDLER_WRITE 89
+# + 18 for unlock (same as lock above) (100 is not in pNeg, no match)
+# Test that EXPLAIN PARTITION works
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNonexistent);
+ERROR HY000: partition 'pNonexistent' doesn't exist
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2);
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p0-9_subp2 index NULL b 71 NULL 2 Using index
+FLUSH STATUS;
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE TableAlias pNeg_subp0,pNeg_subp1,p0-9_subp2 index NULL b 71 NULL 4 Using index
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 8
+HANDLER_WRITE 17
+# 8 locks (1 ha_partition + 3 ha_innobase) x 2 (lock/unlock)
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE TableAlias p0-9_subp3 index NULL b 71 NULL 3 Using index
+EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p10-99_subp4,p10-99_subp5 index NULL PRIMARY 4 NULL 2 Using index
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1000000;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+# Test how it changes the alias/keywords/reserved words
+SELECT * FROM t1 PARTITION;
+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 '' at line 1
+SELECT * FROM t1 `PARTITION`;
+a b
+-2 (pNeg-)subp0
+5 p0-9:subp3
+10 p10-99
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+1 subp3
+3 subp3
+100 `p100-99999`(-subp6)
+1000 `p100-99999`(-subp6)
+101 `p100-99999`(-subp7)
+SELECT * FROM t1 AS PARTITION;
+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 'PARTITION' at line 1
+SELECT * FROM t1 AS `PARTITION`;
+a b
+-2 (pNeg-)subp0
+5 p0-9:subp3
+10 p10-99
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+1 subp3
+3 subp3
+100 `p100-99999`(-subp6)
+1000 `p100-99999`(-subp6)
+101 `p100-99999`(-subp7)
+#
+# Test REPLACE
+#
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+ERROR HY000: Found a row not matching the given partition set
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 17
+# 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+# 1 rollback (failure)
+# 17 writes (I_S internal)
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'Insert by REPLACE');
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_WRITE 18
+# 1 commit
+# 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+# 18 writes (17 I_S internal, 1 ha_innobase)
+SELECT * FROM t1 PARTITION (pNeg);
+a b
+-2 (pNeg-)subp0
+-21 Insert by REPLACE
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_READ_KEY 2
+HANDLER_UPDATE 1
+HANDLER_WRITE 18
+# 1 commit
+# 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+# 2 read key (1 innobase_get_index when init the index + 1 index read
+# to get the position to update)
+# 1 update (updated one row, since there is no delete trigger, update
+# is used instead of delete+insert)
+# 18 write (17 from I_S, 1 for the failed insert)
+SELECT * FROM t1 PARTITION (pNeg);
+a b
+-2 (pNeg-)subp0
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+-21 REPLACEd by REPLACE
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_WRITE 17
+# 1 commit
+# 9 locks
+# 17 write (internal I_S)
+DELETE FROM t1 PARTITION(subp1) WHERE b = "REPLACEd by REPLACE";
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 3
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 35
+# + 1 commit
+# + 1 delete (one row deleted)
+# + 3 read key (1 innodb_get_index in records_in_range,
+# 1 innodb_get_index in index_init, 1 index_read in index_read_first)
+# + 1 read next (search for another row in secondary index)
+# + 19 rnd next (internal I_S)
+# + 18 write (internal I_S)
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+ERROR HY000: Found a row not matching the given partition set
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 3
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 38
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 53
+# Failed before start_stmt/execution.
+# + 19 rnd next (internal I_S)
+# + 1 rollback (failed statement)
+# + 18 write (internal I_S)
+REPLACE INTO t1 PARTITION (pNeg) VALUES (-21, 'Insert by REPLACE');
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 3
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 57
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 72
+# + 1 commit
+# + 19 rnd next (internal I_S)
+# + 19 write (18 internal I_S + 1 real write)
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 4
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 5
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 76
+HANDLER_ROLLBACK 1
+HANDLER_UPDATE 1
+HANDLER_WRITE 91
+# + 1 commit
+# + 2 read key (see non locked query)
+# + 19 rnd next (internal I_S)
+# + 1 update (see non locked query)
+# + 19 write (18 internal I_S + 1 failed write)
+SELECT * FROM t1 PARTITION (subp1);
+a b
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+-21 REPLACEd by REPLACE
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 5
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 7
+HANDLER_READ_NEXT 4
+HANDLER_READ_RND_NEXT 95
+HANDLER_ROLLBACK 1
+HANDLER_UPDATE 1
+HANDLER_WRITE 109
+# + 1 commit
+# + 1 read first
+# + 2 read key
+# + 3 read next
+# + 19 rnd next (internal I_S)
+# + 18 write (internal I_S)
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 5
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 7
+HANDLER_READ_NEXT 4
+HANDLER_READ_RND_NEXT 114
+HANDLER_ROLLBACK 1
+HANDLER_UPDATE 1
+HANDLER_WRITE 127
+# + 9 locks
+# + 19 rnd next (internal I_S)
+# + 18 write (internal I_S)
+#
+# Test LOAD
+#
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+a b
+-2 (pNeg-)subp0
+10 p10-99
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+-21 REPLACEd by REPLACE
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`) INTO OUTFILE 'loadtest.txt';
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 10
+HANDLER_READ_FIRST 4
+HANDLER_READ_KEY 8
+HANDLER_READ_NEXT 5
+HANDLER_WRITE 17
+# 1 commit
+# 10 locks (1 ha_partition + 4 ha_innobase) x 2 (lock/unlock)
+# 4 read first (for reading the first row in 4 partitions)
+# 8 read key (4 from read first + 4 for index init)
+# 5 read next (one after each row)
+# 17 write (internal I_S)
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_WRITE 17
+# 18 locks (Note that locks all partitions!!!)
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+a b
+FLUSH STATUS;
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg);
+ERROR HY000: Found a row not matching the given partition set
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK 6
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 18
+# 6 locks (1 ha_partiiton + 2 ha_innobase) x 2 (lock+unlock)
+# 1 rollback
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+a b
+FLUSH STATUS;
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, subp4, subp5);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 10
+HANDLER_WRITE 22
+# 10 lock (1 ha_partition + 4 ha_innobase) x 2 (lock + unlock)
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 18
+HANDLER_WRITE 17
+# 9 locks
+# 18 read key (ALTER forces table to be closed, see above for open)
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, `p10-99`);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 18
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 40
+# + 23 write (18 internal I_S + 5 rows)
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_KEY 18
+HANDLER_READ_RND_NEXT 38
+HANDLER_WRITE 58
+# + 9 locks
+#
+# Test UPDATE
+#
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated');
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 2
+HANDLER_READ_RND_NEXT 2
+HANDLER_UPDATE 1
+HANDLER_WRITE 17
+# 1 commit
+# 4 lock (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+# 1 read first (read first row, called from first rnd_next)
+# 2 read key (innobase_get_index from rnd_init +
+# read next row from second rnd_next)
+# 1 update (update the row)
+SELECT * FROM t1 PARTITION (subp0) ORDER BY a;
+a b
+-2 (pNeg-)subp0, Updated
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = 100;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_WRITE 17
+# 1 commit
+# 4 lock
+# nothing more since all partitions is pruned away.
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_WRITE 17
+# 1 commit
+# 4 lock
+# nothing more since all partitions is pruned away.
+FLUSH STATUS;
+UPDATE t1 PARTITION(`p100-99999`) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+ERROR HY000: Found a row not matching the given partition set
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK 6
+HANDLER_READ_KEY 4
+HANDLER_READ_RND 1
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 17
+# 6 lock
+# 4 read key (1 index init + 1 index read + 1 rnd init + 1 rnd pos)
+# 1 read rnd (rnd pos)
+# 1 rollback
+FLUSH STATUS;
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+Got one of the listed errors
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK 10
+HANDLER_READ_KEY 4
+HANDLER_READ_RND 1
+HANDLER_ROLLBACK 1
+HANDLER_WRITE 18
+# 10 locks
+# 4 read key
+# 1 read rnd
+# 1 rollback
+# 18 write (17 internal I_S + 1 failed insert)
+FLUSH STATUS;
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -222, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 10
+HANDLER_READ_KEY 4
+HANDLER_READ_RND 1
+HANDLER_WRITE 18
+# 1 commit
+# 1 delete
+# 4 read key
+# 1 read rnd
+# 18 write (17 internal I_S + 1 insert)
+SELECT * FROM t1 ORDER BY a;
+a b
+-222 `p100-99999`(-subp6), Updated from a = 100
+-21 REPLACEd by REPLACE
+-3 pNeg(-subp1)
+-2 (pNeg-)subp0, Updated
+-1 pNeg(-subp1)
+1 subp3
+3 subp3
+5 p0-9:subp3
+10 p10-99
+101 `p100-99999`(-subp7)
+1000 `p100-99999`(-subp6)
+# Test of non matching partition (i.e ER_NO_PARTITION_FOUND)
+FLUSH STATUS;
+UPDATE t1 SET b = concat(b, ', Updated2') WHERE a = 1000000;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_WRITE 17
+# only 18 lock and 1 commit (no matching partition found, but no pruning)
+FLUSH STATUS;
+UPDATE t1 PARTITION (pNeg) SET b = concat(b, ', Updated2') WHERE a = 1000000;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 6
+HANDLER_WRITE 17
+# only 6 lock and 1 commit (no matching partition found, with pruning)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_WRITE 17
+# 9 locks
+UPDATE t1 PARTITION (subp7) SET b = concat(b, ', Updated to 103'), a = 103 WHERE a = 101;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 4
+HANDLER_READ_RND 1
+HANDLER_READ_RND_NEXT 19
+HANDLER_UPDATE 1
+HANDLER_WRITE 35
+# + 4 read key
+# + 1 read rnd
+# + 1 update
+UPDATE t1 PARTITION (`p100-99999`) SET b = concat(b, ', Updated to 110'), a = 110 WHERE a = 103;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 8
+HANDLER_READ_RND 2
+HANDLER_READ_RND_NEXT 38
+HANDLER_UPDATE 1
+HANDLER_WRITE 54
+# + 1 delete
+# + 4 read key
+# + 1 read rnd
+# + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_KEY 8
+HANDLER_READ_RND 2
+HANDLER_READ_RND_NEXT 57
+HANDLER_UPDATE 1
+HANDLER_WRITE 72
++ 9 locks
+#
+# Test DELETE
+#
+SELECT * FROM t1 ORDER BY b, a;
+a b
+-2 (pNeg-)subp0, Updated
+5 p0-9:subp3
+10 p10-99
+-3 pNeg(-subp1)
+-1 pNeg(-subp1)
+-21 REPLACEd by REPLACE
+1 subp3
+3 subp3
+1000 `p100-99999`(-subp6)
+-222 `p100-99999`(-subp6), Updated from a = 100
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (pNeg) WHERE a = -1;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 6
+HANDLER_READ_KEY 2
+HANDLER_WRITE 17
+# 1 delete
+# 6 locks
+# 2 read key (index init + index read)
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (subp1) WHERE b like '%subp1%';
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 4
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 2
+HANDLER_READ_RND_NEXT 3
+HANDLER_WRITE 17
+# 1 delete
+# 4 locks
+# 1 read first
+# 2 read key
+# 3 read rnd
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_WRITE 17
+# 9 locks
+DELETE FROM t1 PARTITION (subp1) WHERE b = 'p0-9:subp3';
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 2
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 3
+HANDLER_READ_RND_NEXT 19
+HANDLER_WRITE 35
+# + 3 read key (1 innodb_get_index in records_in_range
+# + 1 innobase_get_index in index_init + 1 index read)
+DELETE FROM t1 PARTITION (`p0-9`) WHERE b = 'p0-9:subp3';
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 9
+HANDLER_READ_KEY 9
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 38
+HANDLER_WRITE 53
+# + 1 delete
+# + 6 read key (same as above, but for two subpartitions)
+# + 1 read next (read next after found row)
+UNLOCK TABLES;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 3
+HANDLER_DELETE 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_READ_KEY 9
+HANDLER_READ_NEXT 1
+HANDLER_READ_RND_NEXT 57
+HANDLER_WRITE 71
+# + 9 locks
+# Test multi-table DELETE
+# Can be expressed in two different ways.
+FLUSH STATUS;
+CREATE TABLE t2 LIKE t1;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_WRITE 17
+FLUSH STATUS;
+INSERT INTO t2 SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 30
+HANDLER_READ_FIRST 5
+HANDLER_READ_KEY 28
+HANDLER_READ_NEXT 5
+HANDLER_WRITE 22
+FLUSH STATUS;
+CREATE TABLE t3 SELECT * FROM t1 PARTITION (pNeg,subp3,`p100-99999`);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 14
+HANDLER_READ_FIRST 5
+HANDLER_READ_KEY 10
+HANDLER_READ_NEXT 7
+HANDLER_WRITE 24
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) NOT NULL,
+ `b` varchar(64) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ KEY `b` (`b`,`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a)
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0 ENGINE = InnoDB,
+ SUBPARTITION subp1 ENGINE = InnoDB),
+ PARTITION `p0-9` VALUES LESS THAN (10)
+ (SUBPARTITION subp2 ENGINE = InnoDB,
+ SUBPARTITION subp3 ENGINE = InnoDB),
+ PARTITION `p10-99` VALUES LESS THAN (100)
+ (SUBPARTITION subp4 ENGINE = InnoDB,
+ SUBPARTITION subp5 ENGINE = InnoDB),
+ PARTITION `p100-99999` VALUES LESS THAN (100000)
+ (SUBPARTITION subp6 ENGINE = InnoDB,
+ SUBPARTITION subp7 ENGINE = InnoDB)) */
+SELECT * FROM t1;
+a b
+-2 (pNeg-)subp0, Updated
+10 p10-99
+-21 REPLACEd by REPLACE
+1 subp3
+3 subp3
+1000 `p100-99999`(-subp6)
+-222 `p100-99999`(-subp6), Updated from a = 100
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) NOT NULL,
+ `b` varchar(64) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ KEY `b` (`b`,`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a)
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0 ENGINE = InnoDB,
+ SUBPARTITION subp1 ENGINE = InnoDB),
+ PARTITION `p0-9` VALUES LESS THAN (10)
+ (SUBPARTITION subp2 ENGINE = InnoDB,
+ SUBPARTITION subp3 ENGINE = InnoDB),
+ PARTITION `p10-99` VALUES LESS THAN (100)
+ (SUBPARTITION subp4 ENGINE = InnoDB,
+ SUBPARTITION subp5 ENGINE = InnoDB),
+ PARTITION `p100-99999` VALUES LESS THAN (100000)
+ (SUBPARTITION subp6 ENGINE = InnoDB,
+ SUBPARTITION subp7 ENGINE = InnoDB)) */
+SELECT * FROM t2;
+a b
+10 p10-99
+1 subp3
+3 subp3
+1000 `p100-99999`(-subp6)
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+SHOW CREATE TABLE t3;
+Table Create Table
+t3 CREATE TABLE `t3` (
+ `a` int(11) NOT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SELECT * FROM t3;
+a b
+-2 (pNeg-)subp0, Updated
+-21 REPLACEd by REPLACE
+1 subp3
+3 subp3
+1000 `p100-99999`(-subp6)
+-222 `p100-99999`(-subp6), Updated from a = 100
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+FLUSH STATUS;
+DELETE t1 PARTITION (pNeg), t3 FROM t1, t3
+WHERE t1.a = t3.a AND t3.b = 'subp3';
+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 'PARTITION (pNeg), t3 FROM t1, t3
+WHERE t1.a = t3.a AND t3.b = 'subp3'' at line 1
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_WRITE 17
+# Multi table delete without any matching rows
+FLUSH STATUS;
+DELETE t1, t2 FROM t1 PARTITION (pNeg), t3, t2 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t3.a = t2.a;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 12
+HANDLER_READ_FIRST 1
+HANDLER_READ_KEY 4
+HANDLER_READ_RND_NEXT 3
+HANDLER_WRITE 17
+# 12 locks (3 in t1, 1 in t3, 2 in t2) x 2 (lock + unlock)
+# 1 read first (first rnd_next in t2)
+# 4 read key (1 innodb_get_index in rnd_init in t2 + index read in t2
+# + 2 innodb_get_index in index_init in t1)
+# 3 read rnd next (3 rnd next in t2, 2 rows + 1 empty)
+# Multi table delete matching all rows in subp3 (2 rows in per table)
+FLUSH STATUS;
+DELETE FROM t2, t3 USING t2 PARTITION (`p0-9`), t3, t1 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t2.a = t1.a;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_DELETE 4
+HANDLER_EXTERNAL_LOCK 12
+HANDLER_READ_FIRST 3
+HANDLER_READ_KEY 17
+HANDLER_READ_NEXT 2
+HANDLER_READ_RND 4
+HANDLER_READ_RND_NEXT 16
+HANDLER_WRITE 17
+# 4 delete (2 in t2 + 2 in t3)
+# 12 locks (3 in t2, 1 in t3, 2 in t1) x 2 (lock + unlock)
+# 3 read first (1 in t1 + 1 in t3 + 1 in t3, for second row in t1)
+# 17 read key (1 index_init in t1 + 1 read first in t1 +
+# 2 index_init in t2 + 1 index read in t2 +
+# 1 index_init in t3 + 1 index read in t3 +
+# 1 index read in t2 +
+# 1 index_init in t3 + 1 index read in t3 +
+# 2 index_init in t2 + 2 index read in t2 (from rnd_pos)
+# 1 index_init in t3 + 2 index read in t3 (from rnd_pos))
+# 2 read next (1 in t1 + 1 in t1, second row)
+# 4 read rnd (position on 4 found rows to delete)
+# 16 rnd next (8 in t3 + 8 in t3, for second row)
+SELECT * FROM t1 ORDER BY a;
+a b
+-222 `p100-99999`(-subp6), Updated from a = 100
+-21 REPLACEd by REPLACE
+-2 (pNeg-)subp0, Updated
+1 subp3
+3 subp3
+10 p10-99
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+1000 `p100-99999`(-subp6)
+SELECT * FROM t2 ORDER BY a;
+a b
+10 p10-99
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+1000 `p100-99999`(-subp6)
+SELECT * FROM t3 ORDER BY a;
+a b
+-222 `p100-99999`(-subp6), Updated from a = 100
+-21 REPLACEd by REPLACE
+-2 (pNeg-)subp0, Updated
+110 `p100-99999`(-subp7), Updated to 103, Updated to 110
+1000 `p100-99999`(-subp6)
+# Test TRUNCATE TABLE (should fail, since one should use
+# ALTER TABLE ... TRUNCATE PARTITION instead)
+TRUNCATE TABLE t1 PARTITION(`p10-99`);
+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 'PARTITION(`p10-99`)' at line 1
+# Test of locking in TRUNCATE PARTITION
+# Note that it does not support truncating subpartitions
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME VARIABLE_VALUE
+HANDLER_COMMIT 1
+HANDLER_EXTERNAL_LOCK 18
+HANDLER_WRITE 17
+# 18 locks (Since ALTER, no lock pruning, the same with TRUNCATE...)
+# Test on non partitioned table
+SELECT * FROM t3 PARTITION (pNeg);
+ERROR HY000: PARTITION () clause on non partitioned table
+DROP TABLE t1, t2, t3;
+SET @@default_storage_engine = @old_default_storage_engine;
+# Test from superseeded WL# 2682
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+CREATE TABLE `t1` (
+`id` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+INSERT INTO `t1` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+SELECT * FROM t1;
+id
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+SELECT * FROM t1 PARTITION (p0);
+id
+1
+2
+3
+4
+5
+SELECT * FROM t1 PARTITION (p1);
+id
+6
+7
+8
+9
+10
+SELECT * FROM t1 PARTITION (p2);
+id
+11
+12
+13
+14
+15
+SELECT * FROM t1 PARTITION (p3);
+id
+16
+17
+18
+19
+20
+SELECT * FROM t1 PARTITION (p3) WHERE id = 2;
+id
+SELECT * FROM t1 PARTITION (foo);
+ERROR HY000: partition 'foo' doesn't exist
+CREATE TABLE `t2` (
+`id` int(11) NOT NULL DEFAULT 0,
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+INSERT INTO `t2` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+SELECT * FROM t2;
+id
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+SELECT * FROM t2 PARTITION (p0);
+id
+1
+2
+3
+4
+5
+SELECT * FROM t2 PARTITION (p1);
+id
+6
+7
+8
+9
+10
+SELECT * FROM t2 PARTITION (p2);
+id
+11
+12
+13
+14
+15
+SELECT * FROM t2 PARTITION (p3);
+id
+16
+17
+18
+19
+20
+SELECT * FROM t2 PARTITION (p3) ORDER BY id;
+id
+16
+17
+18
+19
+20
+SELECT * FROM t2 PARTITION (p3) WHERE id = 2;
+id
+SELECT * FROM t2 PARTITION (foo);
+ERROR HY000: partition 'foo' doesn't exist
+CREATE TABLE `t3` (
+`id` int(32) default NULL,
+`name` varchar(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY LIST (id) (
+PARTITION p0 VALUES IN (1,3,5,7),
+PARTITION p1 VALUES IN (0,2,4,6,8),
+PARTITION p2 VALUES IN (9,10,11,12,13)
+);
+INSERT INTO `t3` VALUES (1,'first'), (3,'third'),(5,'fifth'),(7,'seventh'),(0,'zilch'),(2,'second'),(4,'fourth'),(6,'sixth'),(8,'eighth'),(9,'ninth'),(10,'tenth'),(11,'eleventh'),(12,'twelfth'),(13,'thirteenth');
+SELECT * FROM `t3`;
+id name
+1 first
+3 third
+5 fifth
+7 seventh
+0 zilch
+2 second
+4 fourth
+6 sixth
+8 eighth
+9 ninth
+10 tenth
+11 eleventh
+12 twelfth
+13 thirteenth
+SELECT * FROM `t3` PARTITION (p0);
+id name
+1 first
+3 third
+5 fifth
+7 seventh
+SELECT * FROM `t3` PARTITION (p1);
+id name
+0 zilch
+2 second
+4 fourth
+6 sixth
+8 eighth
+SELECT * FROM `t3` PARTITION (p2);
+id name
+9 ninth
+10 tenth
+11 eleventh
+12 twelfth
+13 thirteenth
+SELECT * FROM `t3` PARTITION (p2) ORDER BY id;
+id name
+9 ninth
+10 tenth
+11 eleventh
+12 twelfth
+13 thirteenth
+DROP TABLE IF EXISTS `t4`;
+Warnings:
+Note 1051 Unknown table 'test.t4'
+CREATE TABLE `t4` (
+`id` int(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (id) ;
+INSERT INTO `t4` SELECT * FROM `t2`;
+INSERT INTO `t4` SELECT * FROM `t2` ORDER BY id;
+CREATE TABLE `t5` (
+id int(32),
+name varchar(64),
+purchased date)
+PARTITION BY RANGE( YEAR(purchased) )
+SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
+PARTITION p0 VALUES LESS THAN (1990) (
+SUBPARTITION s0,
+SUBPARTITION s1
+),
+PARTITION p1 VALUES LESS THAN (2000) (
+SUBPARTITION s2,
+SUBPARTITION s3
+),
+PARTITION p2 VALUES LESS THAN MAXVALUE (
+SUBPARTITION s4,
+SUBPARTITION s5
+)
+);
+INSERT INTO `t5` VALUES (1, 'aaaaaaa', '2006-01-05 00:00:00');
+INSERT INTO `t5` VALUES (2, 'bbbbbbb', '2005-08-05 00:00:00');
+INSERT INTO `t5` VALUES (3, 'ccccccc', '1985-08-07 00:00:00');
+INSERT INTO `t5` VALUES (4, 'ddddddd', '2000-01-01 00:00:00');
+INSERT INTO `t5` VALUES (5, 'eeeeeee', '1999-12-01 00:00:00');
+INSERT INTO `t5` VALUES (6, 'fffffff', '2003-11-12 00:00:00');
+INSERT INTO `t5` VALUES (7, 'ggggggg', '1990-01-05 00:00:00');
+INSERT INTO `t5` VALUES (8, 'hhhhhhh', '1978-01-05 00:00:00');
+INSERT INTO `t5` VALUES (9, 'iiiiiii', '1979-01-05 00:00:00');
+INSERT INTO `t5` VALUES (10, 'jjjjjjj', '1992-01-05 00:00:00');
+INSERT INTO `t5` VALUES (11, 'kkkkkkk', '1993-01-05 00:00:00');
+INSERT INTO `t5` VALUES (12, 'mmmmmmm', '1994-01-05 00:00:00');
+INSERT INTO `t5` VALUES (13, 'nnnnnnn', '1989-01-05 00:00:00');
+INSERT INTO `t5` VALUES (14, 'ooooooo', '1983-12-05 00:00:00');
+INSERT INTO `t5` VALUES (15, 'ppppppp', '1986-06-05 00:00:00');
+INSERT INTO `t5` VALUES (16, 'qqqqqqq', '1974-04-11 00:00:00');
+INSERT INTO `t5` VALUES (17, 'qqqqqqq', '1960-03-15 00:00:00');
+INSERT INTO `t5` VALUES (18, 'sssssss', '1950-09-23 00:00:00');
+INSERT INTO `t5` VALUES (19, 'ttttttt', '1999-08-02 00:00:00');
+INSERT INTO `t5` VALUES (20, 'uuuuuuu', '1994-05-28 00:00:00');
+SELECT * FROM `t5`;
+id name purchased
+8 hhhhhhh 1978-01-05
+13 nnnnnnn 1989-01-05
+14 ooooooo 1983-12-05
+18 sssssss 1950-09-23
+3 ccccccc 1985-08-07
+9 iiiiiii 1979-01-05
+15 ppppppp 1986-06-05
+16 qqqqqqq 1974-04-11
+17 qqqqqqq 1960-03-15
+5 eeeeeee 1999-12-01
+12 mmmmmmm 1994-01-05
+7 ggggggg 1990-01-05
+10 jjjjjjj 1992-01-05
+11 kkkkkkk 1993-01-05
+19 ttttttt 1999-08-02
+20 uuuuuuu 1994-05-28
+2 bbbbbbb 2005-08-05
+6 fffffff 2003-11-12
+1 aaaaaaa 2006-01-05
+4 ddddddd 2000-01-01
+SELECT * FROM `t5` PARTITION(p0) ORDER BY id;
+id name purchased
+3 ccccccc 1985-08-07
+8 hhhhhhh 1978-01-05
+9 iiiiiii 1979-01-05
+13 nnnnnnn 1989-01-05
+14 ooooooo 1983-12-05
+15 ppppppp 1986-06-05
+16 qqqqqqq 1974-04-11
+17 qqqqqqq 1960-03-15
+18 sssssss 1950-09-23
+SELECT * FROM `t5` PARTITION(s0) ORDER BY id;
+id name purchased
+8 hhhhhhh 1978-01-05
+13 nnnnnnn 1989-01-05
+14 ooooooo 1983-12-05
+18 sssssss 1950-09-23
+SELECT * FROM `t5` PARTITION(s1) ORDER BY id;
+id name purchased
+3 ccccccc 1985-08-07
+9 iiiiiii 1979-01-05
+15 ppppppp 1986-06-05
+16 qqqqqqq 1974-04-11
+17 qqqqqqq 1960-03-15
+SELECT * FROM `t5` PARTITION(p1) ORDER BY id;
+id name purchased
+5 eeeeeee 1999-12-01
+7 ggggggg 1990-01-05
+10 jjjjjjj 1992-01-05
+11 kkkkkkk 1993-01-05
+12 mmmmmmm 1994-01-05
+19 ttttttt 1999-08-02
+20 uuuuuuu 1994-05-28
+SELECT * FROM `t5` PARTITION(s2) ORDER BY id;
+id name purchased
+5 eeeeeee 1999-12-01
+12 mmmmmmm 1994-01-05
+SELECT * FROM `t5` PARTITION(s3) ORDER BY id;
+id name purchased
+7 ggggggg 1990-01-05
+10 jjjjjjj 1992-01-05
+11 kkkkkkk 1993-01-05
+19 ttttttt 1999-08-02
+20 uuuuuuu 1994-05-28
+SELECT * FROM `t5` PARTITION(p2) ORDER BY id;
+id name purchased
+1 aaaaaaa 2006-01-05
+2 bbbbbbb 2005-08-05
+4 ddddddd 2000-01-01
+6 fffffff 2003-11-12
+SELECT * FROM `t5` PARTITION(s4) ORDER BY id;
+id name purchased
+2 bbbbbbb 2005-08-05
+6 fffffff 2003-11-12
+SELECT * FROM `t5` PARTITION(s5) ORDER BY id;
+id name purchased
+1 aaaaaaa 2006-01-05
+4 ddddddd 2000-01-01
+drop table t1,t2,t3,t4,t5;
+create table t1 (a int) partition by hash(a) partitions 3;
+insert into t1 values(1),(2),(3);
+explain partitions select * from t1 where a=1;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 2 Using where
+explain partitions select * from t1 partition (p1) where a=1;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 2 Using where
+explain partitions select * from t1 partition (p1) where a=1 or a=2;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 2 Using where
+explain partitions select * from t1 partition (p2) where a=1;
+id select_type table partitions type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 0 Using where
+drop table t1;
=== modified file 'mysql-test/suite/parts/r/partition_exch_qa_13.result'
--- a/mysql-test/suite/parts/r/partition_exch_qa_13.result 2010-11-16 13:48:04 +0000
+++ b/mysql-test/suite/parts/r/partition_exch_qa_13.result 2010-12-14 20:03:21 +0000
@@ -101,7 +101,7 @@ a b
9 Nine
INSERT INTO t_10 VALUES (10, "TEN");
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
SELECT * FROM tp WHERE a < 11;
a b
2 Two
@@ -117,7 +117,7 @@ a b
9 Nine
INSERT INTO t_1000 VALUES (99, "Ninetynine");
ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
SELECT * FROM tp1 WHERE a < 1000 AND a > 98;
a b
112 Hundred twelve
@@ -157,7 +157,7 @@ a b
99 Ninetynine
INSERT INTO tsp_03 VALUES (20, "Twenty");
ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
SELECT * FROM tsp;
a b
112 Hundred twelve
=== modified file 'mysql-test/suite/parts/r/partition_exch_qa_2.result'
--- a/mysql-test/suite/parts/r/partition_exch_qa_2.result 2010-10-29 10:34:33 +0000
+++ b/mysql-test/suite/parts/r/partition_exch_qa_2.result 2010-12-14 15:13:57 +0000
@@ -127,9 +127,9 @@ ERROR HY000: Table to exchange with part
ALTER TABLE tsp EXCHANGE PARTITION p0 WITH TABLE t_10;
ERROR HY000: Subpartitioned table, use subpartition instead of partition
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_100;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_10;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE IF EXISTS t_10;
DROP TABLE IF EXISTS t_100;
DROP TABLE IF EXISTS t_1000;
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result 2010-08-16 14:22:16 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -309,7 +309,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Archive'
@@ -340,7 +340,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -565,7 +565,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -796,7 +796,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -309,7 +309,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'InnoDB'
@@ -340,7 +340,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -565,7 +565,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -796,7 +796,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -309,7 +309,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Memory'
@@ -340,7 +340,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -565,7 +565,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -796,7 +796,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -309,7 +309,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'MyISAM'
@@ -340,7 +340,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -565,7 +565,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -796,7 +796,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result 2010-08-16 14:22:16 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Archive'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'InnoDB'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Memory'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'MyISAM'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_archive.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result 2010-08-16 14:22:16 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Archive'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'InnoDB'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_memory.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'Memory'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result'
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result 2010-06-23 10:48:39 +0000
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result 2010-12-14 15:13:57 +0000
@@ -32,7 +32,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -135,7 +135,7 @@ Partc YES
ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
INSERT INTO TableB VALUES (11);
ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
-ERROR HY000: Found row that does not match the partition
+ERROR HY000: Found a row that does not match the partition
DROP TABLE TableB;
SELECT * FROM TableA;
a
@@ -300,7 +300,7 @@ PARTITION BY HASH (a)
PARTITION partA ,
PARTITION Parta ,
PARTITION PartA );
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
# Creating Hash partitioned table
CREATE TABLE TableA (a INT)
ENGINE = 'MyISAM'
@@ -331,7 +331,7 @@ ALTER TABLE TableA ADD PARTITION
(PARTITION partA,
PARTITION Parta,
PARTITION PartA);
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE,
PARTITION Partf,
@@ -547,7 +547,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES LESS THAN (MAXVALUE));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES LESS THAN (16),
PARTITION Partf VALUES LESS THAN (19),
@@ -770,7 +770,7 @@ a
# expecting duplicate partition name
ALTER TABLE TableA ADD PARTITION
(PARTITION partA VALUES IN (0));
-ERROR HY000: Duplicate partition name parta
+ERROR HY000: Duplicate partition name partA
ALTER TABLE TableA ADD PARTITION
(PARTITION partE VALUES IN (16),
PARTITION Partf VALUES IN (19),
=== modified file 'mysql-test/suite/parts/r/partition_repair_myisam.result'
--- a/mysql-test/suite/parts/r/partition_repair_myisam.result 2010-06-17 17:17:17 +0000
+++ b/mysql-test/suite/parts/r/partition_repair_myisam.result 2010-12-14 15:13:57 +0000
@@ -270,7 +270,7 @@ PARTITIONS 7;
SELECT COUNT(*) FROM t1_will_crash;
COUNT(*)
33
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
partition rows
0 2
1 5
@@ -279,7 +279,7 @@ partition rows
4 4
5 4
6 8
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
partition b a length(c)
0 0 lost 64
0 7 z lost 64
@@ -342,7 +342,7 @@ test.t1_will_crash repair status OK
SELECT COUNT(*) FROM t1_will_crash;
COUNT(*)
29
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
partition rows
1 4
2 5
@@ -350,7 +350,7 @@ partition rows
4 4
5 4
6 7
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
partition b a length(c)
1 1 abc 64
1 8 tuw 64
@@ -426,9 +426,9 @@ Table Op Msg_type Msg_text
test.t1_will_crash repair info Delete link points outside datafile at 340
test.t1_will_crash repair info Delete link points outside datafile at 340
test.t1_will_crash repair status OK
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
+ORDER BY `partition`, b, a;
partition b a length(c)
6 6 jkl 64
6 13 ooo 64
@@ -445,18 +445,18 @@ FLUSH TABLES;
# table, depending if one reads via index or direct on datafile.
# Since crash when reuse of deleted row space, CHECK MEDIUM or EXTENDED
# is required (MEDIUM is default) to verify correct behavior!
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
+ORDER BY `partition`, b, a;
partition b a length(c)
6 6 jkl 64
6 13 ooo 64
6 34 6 row 2 64
6 83 64
6 97 zzzzzZzzzzz 64
-SELECT (b % 7) AS partition, b, a FROM (SELECT b,a FROM t1_will_crash) q
+SELECT (b % 7) AS `partition`, b, a FROM (SELECT b,a FROM t1_will_crash) q
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
+ORDER BY `partition`, b, a;
partition b a
6 6 jkl
6 13 ooo
@@ -479,7 +479,7 @@ test.t1_will_crash repair status OK
SELECT COUNT(*) FROM t1_will_crash;
COUNT(*)
29
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
partition rows
1 4
2 4
@@ -487,7 +487,7 @@ partition rows
4 4
5 4
6 8
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
partition b a length(c)
1 1 abc 64
1 8 tuw 64
=== modified file 'mysql-test/suite/parts/t/partition_debug_myisam.test'
--- a/mysql-test/suite/parts/t/partition_debug_myisam.test 2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/t/partition_debug_myisam.test 2010-12-17 12:48:18 +0000
@@ -4,6 +4,8 @@
--source include/have_debug.inc
--source include/have_partition.inc
--source include/not_valgrind.inc
+# Crash tests don't work with embedded
+--source include/not_embedded.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
=== modified file 'mysql-test/suite/parts/t/partition_repair_myisam.test'
--- a/mysql-test/suite/parts/t/partition_repair_myisam.test 2010-06-17 21:17:30 +0000
+++ b/mysql-test/suite/parts/t/partition_repair_myisam.test 2010-12-14 15:13:57 +0000
@@ -190,8 +190,8 @@ eval INSERT INTO t1_will_crash VALUES
('6 row 7 (crash before completely written to datafile)', 27, '$lt$lt');
--enable_query_log
SELECT COUNT(*) FROM t1_will_crash;
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
FLUSH TABLES;
# testing p0, p1, p3, p6(1)
--echo # truncating p0 to simulate an empty datafile (not recovered!)
@@ -216,8 +216,8 @@ OPTIMIZE TABLE t1_will_crash;
CHECK TABLE t1_will_crash;
REPAIR TABLE t1_will_crash;
SELECT COUNT(*) FROM t1_will_crash;
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
FLUSH TABLES;
# testing p2, p4, p6(2, 3)
@@ -254,9 +254,9 @@ FLUSH TABLES;
#ALTER TABLE t1_will_crash OPTIMIZE PARTITION p6;
ALTER TABLE t1_will_crash CHECK PARTITION p6;
ALTER TABLE t1_will_crash REPAIR PARTITION p6;
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
+ORDER BY `partition`, b, a;
FLUSH TABLES;
--echo #
@@ -268,18 +268,18 @@ FLUSH TABLES;
--echo # table, depending if one reads via index or direct on datafile.
--echo # Since crash when reuse of deleted row space, CHECK MEDIUM or EXTENDED
--echo # is required (MEDIUM is default) to verify correct behavior!
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
-SELECT (b % 7) AS partition, b, a FROM (SELECT b,a FROM t1_will_crash) q
+ORDER BY `partition`, b, a;
+SELECT (b % 7) AS `partition`, b, a FROM (SELECT b,a FROM t1_will_crash) q
WHERE (b % 7) = 6
-ORDER BY partition, b, a;
+ORDER BY `partition`, b, a;
# NOTE: REBUILD PARTITION without CHECK before, 2 + (1) records will be lost!
#ALTER TABLE t1_will_crash REBUILD PARTITION p6;
ALTER TABLE t1_will_crash CHECK PARTITION p6;
ALTER TABLE t1_will_crash REPAIR PARTITION p6;
SELECT COUNT(*) FROM t1_will_crash;
-SELECT (b % 7) AS partition, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
-SELECT (b % 7) AS partition, b, a, length(c) FROM t1_will_crash ORDER BY partition, b, a;
+SELECT (b % 7) AS `partition`, COUNT(*) AS rows FROM t1_will_crash GROUP BY (b % 7);
+SELECT (b % 7) AS `partition`, b, a, length(c) FROM t1_will_crash ORDER BY `partition`, b, a;
ALTER TABLE t1_will_crash CHECK PARTITION all EXTENDED;
DROP TABLE t1_will_crash;
=== added file 'mysql-test/t/partition_explicit_prune.test'
--- a/mysql-test/t/partition_explicit_prune.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_explicit_prune.test 2011-01-26 15:48:12 +0000
@@ -0,0 +1,650 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--echo # Original tests for WL#5217
+
+--echo # Must have InnoDB as engine to get the same statistics results.
+--echo # embedded uses MyISAM as default. CREATE SELECT uses the default engine.
+SET @old_default_storage_engine = @@default_storage_engine;
+SET @@default_storage_engine = 'InnoDB';
+
+let $get_handler_status_counts= SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+
+--let $MYSQLD_DATADIR= `SELECT @@datadir`
+
+--echo # Test to show if I_S affects HANDLER_ counts
+FLUSH STATUS;
+eval $get_handler_status_counts;
+eval $get_handler_status_counts;
+--echo # OK, seems to add number of variables processed before HANDLER_WRITE
+--echo # and number of variables + 1 evaluated in the previous call in RND_NEXT
+
+CREATE TABLE t1
+(a INT NOT NULL,
+ b varchar (64),
+ INDEX (b,a),
+ PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 2
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0,
+ SUBPARTITION subp1),
+ PARTITION `p0-9` VALUES LESS THAN (10)
+ (SUBPARTITION subp2,
+ SUBPARTITION subp3),
+ PARTITION `p10-99` VALUES LESS THAN (100)
+ (SUBPARTITION subp4,
+ SUBPARTITION subp5),
+ PARTITION `p100-99999` VALUES LESS THAN (100000)
+ (SUBPARTITION subp6,
+ SUBPARTITION subp7));
+
+SHOW CREATE TABLE t1;
+--echo # First test that the syntax is OK
+--error ER_PARSE_ERROR
+SHOW CREATE TABLE t1 PARTITION (subp0);
+--echo # Not a correct partition list
+--error ER_PARSE_ERROR
+INSERT INTO t1 PARTITION () VALUES (1, "error");
+--error ER_NO_SUCH_PARTITION
+INSERT INTO t1 PARTITION (pNonExisting) VALUES (1, "error");
+--error ER_NO_SUCH_PARTITION
+INSERT INTO t1 PARTITION (pNeg, pNonExisting) VALUES (1, "error");
+--echo # Duplicate partitions and overlapping partitions and subpartitios is OK
+FLUSH STATUS;
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (-1, "pNeg(-subp1)");
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 6 external locks
+--echo # (1 ha_partition + 2 ha_innobase) x 2 (lock + unlock)
+--echo # and 18 write (1 ha_innobase + 17 internal I_S write)
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, "pNeg(-subp1)");
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, "(pNeg-)subp0");
+
+--echo # should be correct
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (100, "`p100-99999`(-subp6)"), (101, "`p100-99999`(-subp7)"), (1000, "`p100-99999`(-subp6)");
+INSERT INTO t1 PARTITION(`p10-99`,subp3) VALUES (1, "subp3"), (10, "p10-99");
+FLUSH STATUS;
+INSERT INTO t1 PARTITION(subp3) VALUES (3, "subp3");
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 4 external locks
+--echo # (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+--echo # and 18 write (1 ha_innobase + 17 internal I_S write)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # should be 1 commit
+--echo # 9 locks (1 ha_partition + 8 ha_innobase)
+--echo # 17 writes (internal I_S)
+INSERT INTO t1 PARTITION(`p0-9`) VALUES (5, "p0-9:subp3");
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 19 rnd next (internal I_S)
+--echo # + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks (unlocks)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+
+--echo # Not matching partitions with inserted value
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (pNeg, pNeg) VALUES (1, "error");
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (1, "error");
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1, "error"), (10, "error");
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 VALUES (1000000, "error"), (9999999, "error");
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+INSERT INTO t1 PARTITION (`p100-99999`) VALUES (1000000, "error"), (9999999, "error");
+--error ER_DUP_ENTRY,ER_DUP_KEY
+INSERT INTO t1 PARTITION (pNeg, subp4) VALUES (-7, "pNeg(-subp1)"), (-10, "pNeg(-subp0)"), (-1, "pNeg(-subp1)"), (-99, "pNeg(-subp1)");
+
+SELECT * FROM t1 ORDER BY a;
+SELECT PARTITION_NAME, SUBPARTITION_NAME, TABLE_ROWS
+FROM INFORMATION_SCHEMA.PARTITIONS
+WHERE TABLE_SCHEMA = 'test'
+AND TABLE_NAME = 't1' ORDER BY SUBPARTITION_NAME;
+FLUSH STATUS;
+--error ER_NO_SUCH_PARTITION
+SELECT * FROM t1 PARTITION (pNonexistent);
+eval $get_handler_status_counts;
+--echo # should have failed before locking (only 17 internal I_S writes)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2);
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 1 read first (also calls index_read)
+--echo # 2 read key (first from innobase_get_index and second from index first)
+--echo # 17 writes (internal I_S)
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # Should be 1 commit
+--echo # 8 locks (1 ha_partition + 2 + 1 ha_innobase) x 2
+--echo # 3 read first (one for each partition)
+--echo # 6 read key (3 from read first and 3 from innobase_get_index)
+--echo # 3 read next (one next call after each read row)
+--echo # 17 writes (internal I_S)
+FLUSH STATUS;
+LOCK TABLE t1 READ, t1 as TableAlias READ;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 18 locks
+--echo # 18 READ KEY from opening a new partition table instance,
+--echo # (1 innobase_get_index for each index, per partition, 1 x 2 x 8 = 16
+--echo # + info(HA_STATUS_CONST) call on the partition with the most number
+--echo # of rows, 2 innobase_get_index for updating both index statistics)
+--echo # 17 writes (internal I_S)
+SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 read first (read first key from index in one partition)
+--echo # + 2 read key (innobase_get_index from index_init + from index_first)
+--echo # + 3 read next (one after each row)
+--echo # + 19 rnd next (from the last I_S query)
+--echo # + 18 write (internal I_S)
+SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 2 read first (one for each subpart)
+--echo # + 4 read key (innobase_get_index from index_init + from index_first)
+--echo # + 1 read next (one after each row)
+--echo # + 19 rnd next (from the last I_S query)
+--echo # + 18 write (internal I_S)
+SELECT * FROM t1 WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # No matching partition, only + 1 commit + internal I_S.
+SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 18 for unlock (same as lock above) (100 is not in pNeg, no match)
+
+--echo # Test that EXPLAIN PARTITION works
+--error ER_NO_SUCH_PARTITION
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNonexistent);
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2);
+FLUSH STATUS;
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp2,pNeg) AS TableAlias;
+eval $get_handler_status_counts;
+--echo # 8 locks (1 ha_partition + 3 ha_innobase) x 2 (lock/unlock)
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (subp3) AS TableAlias;
+EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 PARTITION (`p10-99`);
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1000000;
+EXPLAIN PARTITIONS SELECT * FROM t1 PARTITION (pNeg) WHERE a = 100;
+
+--echo # Test how it changes the alias/keywords/reserved words
+--error ER_PARSE_ERROR
+SELECT * FROM t1 PARTITION;
+SELECT * FROM t1 `PARTITION`;
+--error ER_PARSE_ERROR
+SELECT * FROM t1 AS PARTITION;
+SELECT * FROM t1 AS `PARTITION`;
+
+--echo #
+--echo # Test REPLACE
+--echo #
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+eval $get_handler_status_counts;
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 1 rollback (failure)
+--echo # 17 writes (I_S internal)
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'Insert by REPLACE');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 18 writes (17 I_S internal, 1 ha_innobase)
+SELECT * FROM t1 PARTITION (pNeg);
+FLUSH STATUS;
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 locks (1 ha_partition + 1 ha_innobase) x 2 (lock/unlock)
+--echo # 2 read key (1 innobase_get_index when init the index + 1 index read
+--echo # to get the position to update)
+--echo # 1 update (updated one row, since there is no delete trigger, update
+--echo # is used instead of delete+insert)
+--echo # 18 write (17 from I_S, 1 for the failed insert)
+SELECT * FROM t1 PARTITION (pNeg);
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 9 locks
+--echo # 17 write (internal I_S)
+DELETE FROM t1 PARTITION(subp1) WHERE b = "REPLACEd by REPLACE";
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 delete (one row deleted)
+--echo # + 3 read key (1 innodb_get_index in records_in_range,
+--echo # 1 innodb_get_index in index_init, 1 index_read in index_read_first)
+--echo # + 1 read next (search for another row in secondary index)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+REPLACE INTO t1 PARTITION (subp0) VALUES (-21, 'Should fail!');
+eval $get_handler_status_counts;
+--echo # Failed before start_stmt/execution.
+--echo # + 19 rnd next (internal I_S)
+--echo # + 1 rollback (failed statement)
+--echo # + 18 write (internal I_S)
+REPLACE INTO t1 PARTITION (pNeg) VALUES (-21, 'Insert by REPLACE');
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 19 rnd next (internal I_S)
+--echo # + 19 write (18 internal I_S + 1 real write)
+REPLACE INTO t1 PARTITION (subp1) VALUES (-21, 'REPLACEd by REPLACE');
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 2 read key (see non locked query)
+--echo # + 19 rnd next (internal I_S)
+--echo # + 1 update (see non locked query)
+--echo # + 19 write (18 internal I_S + 1 failed write)
+SELECT * FROM t1 PARTITION (subp1);
+eval $get_handler_status_counts;
+--echo # + 1 commit
+--echo # + 1 read first
+--echo # + 2 read key
+--echo # + 3 read next
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+--echo # + 19 rnd next (internal I_S)
+--echo # + 18 write (internal I_S)
+
+--echo #
+--echo # Test LOAD
+--echo #
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`) INTO OUTFILE 'loadtest.txt';
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 10 locks (1 ha_partition + 4 ha_innobase) x 2 (lock/unlock)
+--echo # 4 read first (for reading the first row in 4 partitions)
+--echo # 8 read key (4 from read first + 4 for index init)
+--echo # 5 read next (one after each row)
+--echo # 17 write (internal I_S)
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+eval $get_handler_status_counts;
+--echo # 18 locks (Note that locks all partitions!!!)
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg);
+eval $get_handler_status_counts;
+--echo # 6 locks (1 ha_partiiton + 2 ha_innobase) x 2 (lock+unlock)
+--echo # 1 rollback
+SELECT * FROM t1 PARTITION (pNeg, `p10-99`);
+FLUSH STATUS;
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, subp4, subp5);
+eval $get_handler_status_counts;
+--echo # 10 lock (1 ha_partition + 4 ha_innobase) x 2 (lock + unlock)
+ALTER TABLE t1 TRUNCATE PARTITION pNeg, `p10-99`;
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+--echo # 18 read key (ALTER forces table to be closed, see above for open)
+LOAD DATA INFILE 'loadtest.txt' INTO TABLE t1 PARTITION (pNeg, `p10-99`);
+eval $get_handler_status_counts;
+--echo # + 23 write (18 internal I_S + 5 rows)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+--remove_file $MYSQLD_DATADIR/test/loadtest.txt
+
+--echo #
+--echo # Test UPDATE
+--echo #
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated');
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock (1 ha_partition + 1 ha_innobase) x 2 (lock + unlock)
+--echo # 1 read first (read first row, called from first rnd_next)
+--echo # 2 read key (innobase_get_index from rnd_init +
+--echo # read next row from second rnd_next)
+--echo # 1 update (update the row)
+SELECT * FROM t1 PARTITION (subp0) ORDER BY a;
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET b = concat(b, ', Updated2') WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock
+--echo # nothing more since all partitions is pruned away.
+FLUSH STATUS;
+UPDATE t1 PARTITION(subp0) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 4 lock
+--echo # nothing more since all partitions is pruned away.
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+UPDATE t1 PARTITION(`p100-99999`) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 6 lock
+--echo # 4 read key (1 index init + 1 index read + 1 rnd init + 1 rnd pos)
+--echo # 1 read rnd (rnd pos)
+--echo # 1 rollback
+FLUSH STATUS;
+--error ER_DUP_ENTRY,ER_DUP_KEY
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -2, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 10 locks
+--echo # 4 read key
+--echo # 1 read rnd
+--echo # 1 rollback
+--echo # 18 write (17 internal I_S + 1 failed insert)
+FLUSH STATUS;
+UPDATE t1 PARTITION(`p100-99999`, pNeg) SET a = -222, b = concat(b, ', Updated from a = 100')
+WHERE a = 100;
+eval $get_handler_status_counts;
+--echo # 1 commit
+--echo # 1 delete
+--echo # 4 read key
+--echo # 1 read rnd
+--echo # 18 write (17 internal I_S + 1 insert)
+
+SELECT * FROM t1 ORDER BY a;
+--echo # Test of non matching partition (i.e ER_NO_PARTITION_FOUND)
+FLUSH STATUS;
+UPDATE t1 SET b = concat(b, ', Updated2') WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # only 18 lock and 1 commit (no matching partition found, but no pruning)
+FLUSH STATUS;
+UPDATE t1 PARTITION (pNeg) SET b = concat(b, ', Updated2') WHERE a = 1000000;
+eval $get_handler_status_counts;
+--echo # only 6 lock and 1 commit (no matching partition found, with pruning)
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+UPDATE t1 PARTITION (subp7) SET b = concat(b, ', Updated to 103'), a = 103 WHERE a = 101;
+eval $get_handler_status_counts;
+--echo # + 4 read key
+--echo # + 1 read rnd
+--echo # + 1 update
+UPDATE t1 PARTITION (`p100-99999`) SET b = concat(b, ', Updated to 110'), a = 110 WHERE a = 103;
+eval $get_handler_status_counts;
+--echo # + 1 delete
+--echo # + 4 read key
+--echo # + 1 read rnd
+--echo # + 19 write (18 internal I_S + 1 insert)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo + 9 locks
+
+--echo #
+--echo # Test DELETE
+--echo #
+SELECT * FROM t1 ORDER BY b, a;
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (pNeg) WHERE a = -1;
+eval $get_handler_status_counts;
+--echo # 1 delete
+--echo # 6 locks
+--echo # 2 read key (index init + index read)
+FLUSH STATUS;
+DELETE FROM t1 PARTITION (subp1) WHERE b like '%subp1%';
+eval $get_handler_status_counts;
+--echo # 1 delete
+--echo # 4 locks
+--echo # 1 read first
+--echo # 2 read key
+--echo # 3 read rnd
+FLUSH STATUS;
+LOCK TABLE t1 WRITE;
+eval $get_handler_status_counts;
+--echo # 9 locks
+DELETE FROM t1 PARTITION (subp1) WHERE b = 'p0-9:subp3';
+eval $get_handler_status_counts;
+--echo # + 3 read key (1 innodb_get_index in records_in_range
+--echo # + 1 innobase_get_index in index_init + 1 index read)
+DELETE FROM t1 PARTITION (`p0-9`) WHERE b = 'p0-9:subp3';
+eval $get_handler_status_counts;
+--echo # + 1 delete
+--echo # + 6 read key (same as above, but for two subpartitions)
+--echo # + 1 read next (read next after found row)
+UNLOCK TABLES;
+eval $get_handler_status_counts;
+--echo # + 9 locks
+
+--echo # Test multi-table DELETE
+--echo # Can be expressed in two different ways.
+FLUSH STATUS;
+CREATE TABLE t2 LIKE t1;
+eval $get_handler_status_counts;
+FLUSH STATUS;
+INSERT INTO t2 SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+FLUSH STATUS;
+CREATE TABLE t3 SELECT * FROM t1 PARTITION (pNeg,subp3,`p100-99999`);
+eval $get_handler_status_counts;
+SHOW CREATE TABLE t1;
+SELECT * FROM t1;
+SHOW CREATE TABLE t2;
+SELECT * FROM t2;
+SHOW CREATE TABLE t3;
+SELECT * FROM t3;
+FLUSH STATUS;
+--error ER_PARSE_ERROR
+DELETE t1 PARTITION (pNeg), t3 FROM t1, t3
+WHERE t1.a = t3.a AND t3.b = 'subp3';
+eval $get_handler_status_counts;
+--echo # Multi table delete without any matching rows
+FLUSH STATUS;
+DELETE t1, t2 FROM t1 PARTITION (pNeg), t3, t2 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t3.a = t2.a;
+eval $get_handler_status_counts;
+--echo # 12 locks (3 in t1, 1 in t3, 2 in t2) x 2 (lock + unlock)
+--echo # 1 read first (first rnd_next in t2)
+--echo # 4 read key (1 innodb_get_index in rnd_init in t2 + index read in t2
+--echo # + 2 innodb_get_index in index_init in t1)
+--echo # 3 read rnd next (3 rnd next in t2, 2 rows + 1 empty)
+--echo # Multi table delete matching all rows in subp3 (2 rows in per table)
+FLUSH STATUS;
+DELETE FROM t2, t3 USING t2 PARTITION (`p0-9`), t3, t1 PARTITION (subp3)
+WHERE t1.a = t3.a AND t3.b = 'subp3' AND t2.a = t1.a;
+eval $get_handler_status_counts;
+--echo # 4 delete (2 in t2 + 2 in t3)
+--echo # 12 locks (3 in t2, 1 in t3, 2 in t1) x 2 (lock + unlock)
+--echo # 3 read first (1 in t1 + 1 in t3 + 1 in t3, for second row in t1)
+--echo # 17 read key (1 index_init in t1 + 1 read first in t1 +
+--echo # 2 index_init in t2 + 1 index read in t2 +
+--echo # 1 index_init in t3 + 1 index read in t3 +
+--echo # 1 index read in t2 +
+--echo # 1 index_init in t3 + 1 index read in t3 +
+--echo # 2 index_init in t2 + 2 index read in t2 (from rnd_pos)
+--echo # 1 index_init in t3 + 2 index read in t3 (from rnd_pos))
+--echo # 2 read next (1 in t1 + 1 in t1, second row)
+--echo # 4 read rnd (position on 4 found rows to delete)
+--echo # 16 rnd next (8 in t3 + 8 in t3, for second row)
+SELECT * FROM t1 ORDER BY a;
+SELECT * FROM t2 ORDER BY a;
+SELECT * FROM t3 ORDER BY a;
+
+
+--echo # Test TRUNCATE TABLE (should fail, since one should use
+--echo # ALTER TABLE ... TRUNCATE PARTITION instead)
+--error ER_PARSE_ERROR
+TRUNCATE TABLE t1 PARTITION(`p10-99`);
+
+--echo # Test of locking in TRUNCATE PARTITION
+--echo # Note that it does not support truncating subpartitions
+FLUSH STATUS;
+ALTER TABLE t1 TRUNCATE PARTITION pNeg;
+eval $get_handler_status_counts;
+--echo # 18 locks (Since ALTER, no lock pruning, the same with TRUNCATE...)
+
+--echo # Test on non partitioned table
+--error ER_PARTITION_CLAUSE_ON_NONPARTITIONED
+SELECT * FROM t3 PARTITION (pNeg);
+
+DROP TABLE t1, t2, t3;
+SET @@default_storage_engine = @old_default_storage_engine;
+#
+--echo # Test from superseeded WL# 2682
+# Partition select tests.
+#
+--disable_warnings
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+
+CREATE TABLE `t1` (
+`id` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+
+INSERT INTO `t1` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+
+SELECT * FROM t1;
+SELECT * FROM t1 PARTITION (p0);
+SELECT * FROM t1 PARTITION (p1);
+SELECT * FROM t1 PARTITION (p2);
+SELECT * FROM t1 PARTITION (p3);
+SELECT * FROM t1 PARTITION (p3) WHERE id = 2;
+--error ER_NO_SUCH_PARTITION
+SELECT * FROM t1 PARTITION (foo);
+
+# now try indexes
+CREATE TABLE `t2` (
+`id` int(11) NOT NULL DEFAULT 0,
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY RANGE (id) (
+PARTITION p0 VALUES LESS THAN (6) ENGINE = MyISAM,
+PARTITION p1 VALUES LESS THAN (11) ENGINE = MyISAM,
+PARTITION p2 VALUES LESS THAN (16) ENGINE = MyISAM,
+PARTITION p3 VALUES LESS THAN (21) ENGINE = MyISAM);
+
+INSERT INTO `t2` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10),
+(11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
+
+SELECT * FROM t2;
+SELECT * FROM t2 PARTITION (p0);
+SELECT * FROM t2 PARTITION (p1);
+SELECT * FROM t2 PARTITION (p2);
+SELECT * FROM t2 PARTITION (p3);
+SELECT * FROM t2 PARTITION (p3) ORDER BY id;
+SELECT * FROM t2 PARTITION (p3) WHERE id = 2;
+--error ER_NO_SUCH_PARTITION
+SELECT * FROM t2 PARTITION (foo);
+
+
+CREATE TABLE `t3` (
+ `id` int(32) default NULL,
+ `name` varchar(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+PARTITION BY LIST (id) (
+ PARTITION p0 VALUES IN (1,3,5,7),
+ PARTITION p1 VALUES IN (0,2,4,6,8),
+ PARTITION p2 VALUES IN (9,10,11,12,13)
+);
+
+INSERT INTO `t3` VALUES (1,'first'), (3,'third'),(5,'fifth'),(7,'seventh'),(0,'zilch'),(2,'second'),(4,'fourth'),(6,'sixth'),(8,'eighth'),(9,'ninth'),(10,'tenth'),(11,'eleventh'),(12,'twelfth'),(13,'thirteenth');
+
+SELECT * FROM `t3`;
+SELECT * FROM `t3` PARTITION (p0);
+SELECT * FROM `t3` PARTITION (p1);
+SELECT * FROM `t3` PARTITION (p2);
+SELECT * FROM `t3` PARTITION (p2) ORDER BY id;
+
+DROP TABLE IF EXISTS `t4`;
+CREATE TABLE `t4` (
+ `id` int(32) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (id) ;
+
+INSERT INTO `t4` SELECT * FROM `t2`;
+INSERT INTO `t4` SELECT * FROM `t2` ORDER BY id;
+# not sure how to do this, since names could be anything
+#SELECT * FROM `t4` PARTITION (p0);
+#SELECT * FROM `t4` PARTITION (p1);
+#SELECT * FROM `t4` PARTITION (p2);
+#SELECT * FROM `t4` PARTITION (p3);
+#SELECT * FROM `t4` PARTITION (p3) ORDER BY id;
+
+CREATE TABLE `t5` (
+ id int(32),
+ name varchar(64),
+ purchased date)
+PARTITION BY RANGE( YEAR(purchased) )
+ SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
+ PARTITION p0 VALUES LESS THAN (1990) (
+ SUBPARTITION s0,
+ SUBPARTITION s1
+ ),
+ PARTITION p1 VALUES LESS THAN (2000) (
+ SUBPARTITION s2,
+ SUBPARTITION s3
+ ),
+ PARTITION p2 VALUES LESS THAN MAXVALUE (
+ SUBPARTITION s4,
+ SUBPARTITION s5
+ )
+ );
+
+INSERT INTO `t5` VALUES (1, 'aaaaaaa', '2006-01-05 00:00:00');
+INSERT INTO `t5` VALUES (2, 'bbbbbbb', '2005-08-05 00:00:00');
+INSERT INTO `t5` VALUES (3, 'ccccccc', '1985-08-07 00:00:00');
+INSERT INTO `t5` VALUES (4, 'ddddddd', '2000-01-01 00:00:00');
+INSERT INTO `t5` VALUES (5, 'eeeeeee', '1999-12-01 00:00:00');
+INSERT INTO `t5` VALUES (6, 'fffffff', '2003-11-12 00:00:00');
+INSERT INTO `t5` VALUES (7, 'ggggggg', '1990-01-05 00:00:00');
+INSERT INTO `t5` VALUES (8, 'hhhhhhh', '1978-01-05 00:00:00');
+INSERT INTO `t5` VALUES (9, 'iiiiiii', '1979-01-05 00:00:00');
+INSERT INTO `t5` VALUES (10, 'jjjjjjj', '1992-01-05 00:00:00');
+INSERT INTO `t5` VALUES (11, 'kkkkkkk', '1993-01-05 00:00:00');
+INSERT INTO `t5` VALUES (12, 'mmmmmmm', '1994-01-05 00:00:00');
+INSERT INTO `t5` VALUES (13, 'nnnnnnn', '1989-01-05 00:00:00');
+INSERT INTO `t5` VALUES (14, 'ooooooo', '1983-12-05 00:00:00');
+INSERT INTO `t5` VALUES (15, 'ppppppp', '1986-06-05 00:00:00');
+INSERT INTO `t5` VALUES (16, 'qqqqqqq', '1974-04-11 00:00:00');
+INSERT INTO `t5` VALUES (17, 'qqqqqqq', '1960-03-15 00:00:00');
+INSERT INTO `t5` VALUES (18, 'sssssss', '1950-09-23 00:00:00');
+INSERT INTO `t5` VALUES (19, 'ttttttt', '1999-08-02 00:00:00');
+INSERT INTO `t5` VALUES (20, 'uuuuuuu', '1994-05-28 00:00:00');
+
+SELECT * FROM `t5`;
+SELECT * FROM `t5` PARTITION(p0) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s0) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s1) ORDER BY id;
+SELECT * FROM `t5` PARTITION(p1) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s2) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s3) ORDER BY id;
+SELECT * FROM `t5` PARTITION(p2) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s4) ORDER BY id;
+SELECT * FROM `t5` PARTITION(s5) ORDER BY id;
+
+--disable_warnings
+drop table t1,t2,t3,t4,t5;
+--enable_warnings
+
+# Tests for working together with partition pruning.
+create table t1 (a int) partition by hash(a) partitions 3;
+insert into t1 values(1),(2),(3);
+explain partitions select * from t1 where a=1;
+explain partitions select * from t1 partition (p1) where a=1;
+explain partitions select * from t1 partition (p1) where a=1 or a=2;
+explain partitions select * from t1 partition (p2) where a=1;
+
+drop table t1;
=== modified file 'mysys/hash.c'
--- a/mysys/hash.c 2010-07-08 21:20:08 +0000
+++ b/mysys/hash.c 2010-12-14 15:13:57 +0000
@@ -67,6 +67,7 @@ static my_hash_value_type calc_hash(cons
@param[in] get_key get the key for the hash
@param[in] free_element pointer to the function that
does cleanup
+ @param[in] flags flags set in the hash
@return inidicates success or failure of initialization
@retval 0 success
@retval 1 failure
=== modified file 'mysys/my_handler.c'
--- a/mysys/my_handler.c 2010-07-23 20:16:29 +0000
+++ b/mysys/my_handler.c 2010-12-14 15:13:57 +0000
@@ -587,7 +587,7 @@ void my_handler_error_register(void)
/*
If you got compilation error here about compile_time_assert array, check
that every HA_ERR_xxx constant has a corresponding error message in
- handler_error_messages[] list (check mysys/ma_handler_errors.h and
+ handler_error_messages[] list (check mysys/my_handler_errors.h and
include/my_base.h).
*/
compile_time_assert(HA_ERR_FIRST + array_elements(handler_error_messages) ==
=== modified file 'mysys/my_handler_errors.h'
--- a/mysys/my_handler_errors.h 2009-09-23 21:32:31 +0000
+++ b/mysys/my_handler_errors.h 2010-12-14 15:13:57 +0000
@@ -65,7 +65,8 @@ static const char *handler_error_message
"Got a fatal error during initialzaction of handler",
"File to short; Expected more data in file",
"Read page with wrong checksum",
- "Too many active concurrent transactions"
+ "Too many active concurrent transactions",
+ "Record not matching the given partition set"
};
#endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */
=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc 2011-01-03 15:45:43 +0000
+++ b/sql/ha_partition.cc 2011-01-26 15:48:12 +0000
@@ -64,6 +64,7 @@
#include "debug_sync.h"
+#define PAR_FILE_ENGINE_OFFSET 12
static const char *ha_par_ext= ".par";
/****************************************************************************
@@ -432,7 +433,7 @@ int ha_partition::delete_table(const cha
{
DBUG_ENTER("ha_partition::delete_table");
- DBUG_RETURN(del_ren_cre_table(name, NULL, NULL, NULL));
+ DBUG_RETURN(del_ren_table(name, NULL));
}
@@ -462,7 +463,7 @@ int ha_partition::rename_table(const cha
{
DBUG_ENTER("ha_partition::rename_table");
- DBUG_RETURN(del_ren_cre_table(from, to, NULL, NULL));
+ DBUG_RETURN(del_ren_table(from, to));
}
@@ -552,17 +553,86 @@ int ha_partition::create_handler_files(c
int ha_partition::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
- char t_name[FN_REFLEN];
+ int error;
+ char name_buff[FN_REFLEN], name_lc_buff[FN_REFLEN];
+ char *name_buffer_ptr;
+ const char *path;
+ uint i;
+ List_iterator_fast <partition_element> part_it(m_part_info->partitions);
+ partition_element *part_elem;
+ handler **file, **abort_file;
DBUG_ENTER("ha_partition::create");
- strmov(t_name, name);
DBUG_ASSERT(*fn_rext((char*)name) == '\0');
- if (del_ren_cre_table(t_name, NULL, table_arg, create_info))
+
+ /* Not allowed to create temporary partitioned tables */
+ if (create_info && create_info->options & HA_LEX_CREATE_TMP_TABLE)
{
- handler::delete_table(t_name);
- DBUG_RETURN(1);
+ my_error(ER_PARTITION_NO_TEMPORARY, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+
+ if (get_from_handler_file(name, ha_thd()->mem_root))
+ DBUG_RETURN(TRUE);
+ DBUG_ASSERT(m_file_buffer);
+ DBUG_PRINT("enter", ("name: (%s)", name));
+ name_buffer_ptr= m_name_buffer_ptr;
+ file= m_file;
+ /*
+ Since ha_partition has HA_FILE_BASED, it must alter underlying table names
+ if they do not have HA_FILE_BASED and lower_case_table_names == 2.
+ See Bug#37402, for Mac OS X.
+ The appended #P#<partname>[#SP#<subpartname>] will remain in current case.
+ Using the first partitions handler, since mixing handlers is not allowed.
+ */
+ path= get_canonical_filename(*file, name, name_lc_buff);
+ for (i= 0; i < m_part_info->num_parts; i++)
+ {
+ part_elem= part_it++;
+ if (m_is_sub_partitioned)
+ {
+ uint j;
+ List_iterator_fast <partition_element> sub_it(part_elem->subpartitions);
+ for (j= 0; j < m_part_info->num_subparts; j++)
+ {
+ part_elem= sub_it++;
+ create_partition_name(name_buff, path, name_buffer_ptr,
+ NORMAL_PART_NAME, FALSE);
+ if ((error= set_up_table_before_create(table_arg, name_buff,
+ create_info, part_elem)) ||
+ ((error= (*file)->ha_create(name_buff, table_arg, create_info))))
+ goto create_error;
+
+ name_buffer_ptr= strend(name_buffer_ptr) + 1;
+ file++;
+ }
+ }
+ else
+ {
+ create_partition_name(name_buff, path, name_buffer_ptr,
+ NORMAL_PART_NAME, FALSE);
+ if ((error= set_up_table_before_create(table_arg, name_buff,
+ create_info, part_elem)) ||
+ ((error= (*file)->ha_create(name_buff, table_arg, create_info))))
+ goto create_error;
+
+ name_buffer_ptr= strend(name_buffer_ptr) + 1;
+ file++;
+ }
}
DBUG_RETURN(0);
+
+create_error:
+ name_buffer_ptr= m_name_buffer_ptr;
+ for (abort_file= file, file= m_file; file < abort_file; file++)
+ {
+ create_partition_name(name_buff, path, name_buffer_ptr, NORMAL_PART_NAME,
+ FALSE);
+ (void) (*file)->ha_delete_table((const char*) name_buff);
+ name_buffer_ptr= strend(name_buffer_ptr) + 1;
+ }
+ handler::delete_table(name);
+ DBUG_RETURN(error);
}
@@ -1188,6 +1258,8 @@ int ha_partition::handle_opt_partitions(
@retval TRUE Error/Not supported
@retval FALSE Success
+
+ @note Called if open_table_from_share fails and ::is_crashed().
*/
bool ha_partition::check_and_repair(THD *thd)
@@ -1267,8 +1339,7 @@ int ha_partition::prepare_new_partition(
int error;
DBUG_ENTER("prepare_new_partition");
- if ((error= set_up_table_before_create(tbl, part_name, create_info,
- 0, p_elem)))
+ if ((error= set_up_table_before_create(tbl, part_name, create_info, p_elem)))
goto error_create;
if ((error= file->ha_create(part_name, tbl, create_info)))
{
@@ -1794,6 +1865,16 @@ void ha_partition::update_create_info(HA
}
+/**
+ Change the internal TABLE_SHARE pointer
+
+ @param table_arg TABLE object
+ @param share New share to use
+
+ @note Is used in error handling in ha_delete_table.
+ All handlers should exist (lock_partitions should not be used)
+*/
+
void ha_partition::change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
{
handler **file_array;
@@ -1844,34 +1925,25 @@ char *ha_partition::update_table_comment
}
+/**
+ Handle delete and rename table
-/*
- Handle delete, rename and create table
-
- SYNOPSIS
- del_ren_cre_table()
- from Full path of old table
- to Full path of new table
- table_arg Table object
- create_info Create info
+ @param from Full path of old table
+ @param to Full path of new table
- RETURN VALUE
- >0 Error
- 0 Success
+ @return Operation status
+ @retval >0 Error
+ @retval 0 Success
- DESCRIPTION
- Common routine to handle delete_table and rename_table.
- The routine uses the partition handler file to get the
- names of the partition instances. Both these routines
- are called after creating the handler without table
- object and thus the file is needed to discover the
- names of the partitions and the underlying storage engines.
+ @note Common routine to handle delete_table and rename_table.
+ The routine uses the partition handler file to get the
+ names of the partition instances. Both these routines
+ are called after creating the handler without table
+ object and thus the file is needed to discover the
+ names of the partitions and the underlying storage engines.
*/
-uint ha_partition::del_ren_cre_table(const char *from,
- const char *to,
- TABLE *table_arg,
- HA_CREATE_INFO *create_info)
+uint ha_partition::del_ren_table(const char *from, const char *to)
{
int save_error= 0;
int error;
@@ -1882,14 +1954,7 @@ uint ha_partition::del_ren_cre_table(con
const char *to_path= NULL;
uint i;
handler **file, **abort_file;
- DBUG_ENTER("del_ren_cre_table()");
-
- /* Not allowed to create temporary partitioned tables */
- if (create_info && create_info->options & HA_LEX_CREATE_TMP_TABLE)
- {
- my_error(ER_PARTITION_NO_TEMPORARY, MYF(0));
- DBUG_RETURN(TRUE);
- }
+ DBUG_ENTER("ha_partition::del_ren_table");
if (get_from_handler_file(from, ha_thd()->mem_root))
DBUG_RETURN(TRUE);
@@ -1897,7 +1962,7 @@ uint ha_partition::del_ren_cre_table(con
DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to ? to : "(nil)"));
name_buffer_ptr= m_name_buffer_ptr;
file= m_file;
- if (to == NULL && table_arg == NULL)
+ if (to == NULL)
{
/*
Delete table, start by delete the .par file. If error, break, otherwise
@@ -1923,21 +1988,16 @@ uint ha_partition::del_ren_cre_table(con
NORMAL_PART_NAME, FALSE);
if (to != NULL)
- { // Rename branch
+ { // Rename branch
create_partition_name(to_buff, to_path, name_buffer_ptr,
NORMAL_PART_NAME, FALSE);
error= (*file)->ha_rename_table(from_buff, to_buff);
if (error)
goto rename_error;
}
- else if (table_arg == NULL) // delete branch
- error= (*file)->ha_delete_table(from_buff);
- else
+ else // delete branch
{
- if ((error= set_up_table_before_create(table_arg, from_buff,
- create_info, i, NULL)) ||
- ((error= (*file)->ha_create(from_buff, table_arg, create_info))))
- goto create_error;
+ error= (*file)->ha_delete_table(from_buff);
}
name_buffer_ptr= strend(name_buffer_ptr) + 1;
if (error)
@@ -1954,16 +2014,6 @@ uint ha_partition::del_ren_cre_table(con
}
}
DBUG_RETURN(save_error);
-create_error:
- name_buffer_ptr= m_name_buffer_ptr;
- for (abort_file= file, file= m_file; file < abort_file; file++)
- {
- create_partition_name(from_buff, from_path, name_buffer_ptr, NORMAL_PART_NAME,
- FALSE);
- (void) (*file)->ha_delete_table((const char*) from_buff);
- name_buffer_ptr= strend(name_buffer_ptr) + 1;
- }
- DBUG_RETURN(error);
rename_error:
name_buffer_ptr= m_name_buffer_ptr;
for (abort_file= file, file= m_file; file < abort_file; file++)
@@ -1980,73 +2030,29 @@ rename_error:
DBUG_RETURN(error);
}
-/*
- Find partition based on partition id
-
- SYNOPSIS
- find_partition_element()
- part_id Partition id of partition looked for
-
- RETURN VALUE
- >0 Reference to partition_element
- 0 Partition not found
-*/
-
-partition_element *ha_partition::find_partition_element(uint part_id)
-{
- uint i;
- uint curr_part_id= 0;
- List_iterator_fast <partition_element> part_it(m_part_info->partitions);
-
- for (i= 0; i < m_part_info->num_parts; i++)
- {
- partition_element *part_elem;
- part_elem= part_it++;
- if (m_is_sub_partitioned)
- {
- uint j;
- List_iterator_fast <partition_element> sub_it(part_elem->subpartitions);
- for (j= 0; j < m_part_info->num_subparts; j++)
- {
- part_elem= sub_it++;
- if (part_id == curr_part_id++)
- return part_elem;
- }
- }
- else if (part_id == curr_part_id++)
- return part_elem;
- }
- DBUG_ASSERT(0);
- my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATALERROR));
- return NULL;
-}
-
-/*
- Set up table share object before calling create on underlying handler
+/**
+ Set up table share object before calling create on underlying handler
- SYNOPSIS
- set_up_table_before_create()
- table Table object
- info Create info
- part_id Partition id of partition to set-up
-
- RETURN VALUE
- TRUE Error
- FALSE Success
-
- DESCRIPTION
- Set up
- 1) Comment on partition
- 2) MAX_ROWS, MIN_ROWS on partition
- 3) Index file name on partition
- 4) Data file name on partition
+ @param table Table object
+ @param info Create info
+ @param part_elem[in,out] Pointer to used partition_element, searched if NULL
+
+ @return status
+ @retval TRUE Error
+ @retval FALSE Success
+
+ @details
+ Set up
+ 1) Comment on partition
+ 2) MAX_ROWS, MIN_ROWS on partition
+ 3) Index file name on partition
+ 4) Data file name on partition
*/
int ha_partition::set_up_table_before_create(TABLE *tbl,
const char *partition_name_with_path,
HA_CREATE_INFO *info,
- uint part_id,
partition_element *part_elem)
{
int error= 0;
@@ -2054,12 +2060,10 @@ int ha_partition::set_up_table_before_cr
THD *thd= ha_thd();
DBUG_ENTER("set_up_table_before_create");
+ DBUG_ASSERT(part_elem);
+
if (!part_elem)
- {
- part_elem= find_partition_element(part_id);
- if (!part_elem)
- DBUG_RETURN(1); // Fatal error
- }
+ DBUG_RETURN(1);
tbl->s->max_rows= part_elem->part_max_rows;
tbl->s->min_rows= part_elem->part_min_rows;
partition_name= strrchr(partition_name_with_path, FN_LIBCHAR);
@@ -2192,7 +2196,7 @@ bool ha_partition::create_handler_file(c
tot_len_byte= 4 * tot_len_words;
if (!(file_buffer= (uchar *) my_malloc(tot_len_byte, MYF(MY_ZEROFILL))))
DBUG_RETURN(TRUE);
- engine_array= (file_buffer + 12);
+ engine_array= (file_buffer + PAR_FILE_ENGINE_OFFSET);
name_buffer_ptr= (char*) (file_buffer + ((4 + tot_partition_words) * 4));
part_it.rewind();
for (i= 0; i < num_parts; i++)
@@ -2232,7 +2236,8 @@ bool ha_partition::create_handler_file(c
chksum= 0;
int4store(file_buffer, tot_len_words);
int4store(file_buffer + 8, tot_parts);
- int4store(file_buffer + 12 + (tot_partition_words * 4), tot_name_len);
+ int4store(file_buffer + PAR_FILE_ENGINE_OFFSET + (tot_partition_words * 4),
+ tot_name_len);
for (i= 0; i < tot_len_words; i++)
chksum^= uint4korr(file_buffer + 4 * i);
int4store(file_buffer + 4, chksum);
@@ -2269,11 +2274,16 @@ bool ha_partition::create_handler_file(c
void ha_partition::clear_handler_file()
{
if (m_engine_array)
+ {
plugin_unlock_list(NULL, m_engine_array, m_tot_parts);
- my_free(m_file_buffer);
- my_free(m_engine_array);
- m_file_buffer= NULL;
- m_engine_array= NULL;
+ my_free(m_engine_array);
+ m_engine_array= NULL;
+ }
+ if (m_file_buffer)
+ {
+ my_free(m_file_buffer);
+ m_file_buffer= NULL;
+ }
}
/*
@@ -2416,8 +2426,9 @@ bool ha_partition::get_from_handler_file
char buff[FN_REFLEN], *address_tot_name_len;
File file;
char *file_buffer, *name_buffer_ptr;
- handlerton **engine_array;
+ handlerton *first_engine;
uint i, len_bytes, len_words, tot_partition_words, tot_name_words, chksum;
+ enum legacy_db_type first_db_type, db_type;
DBUG_ENTER("ha_partition::get_from_handler_file");
DBUG_PRINT("enter", ("table name: '%s'", name));
@@ -2447,20 +2458,15 @@ bool ha_partition::get_from_handler_file
m_tot_parts= uint4korr((file_buffer) + 8);
DBUG_PRINT("info", ("No of parts = %u", m_tot_parts));
tot_partition_words= (m_tot_parts + 3) / 4;
- engine_array= (handlerton **) my_alloca(m_tot_parts * sizeof(handlerton*));
- for (i= 0; i < m_tot_parts; i++)
- {
- engine_array[i]= ha_resolve_by_legacy_type(ha_thd(),
- (enum legacy_db_type)
- *(uchar *) ((file_buffer) +
- 12 + i));
- if (!engine_array[i])
- goto err3;
- }
- address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
+ first_db_type= (enum legacy_db_type) file_buffer[PAR_FILE_ENGINE_OFFSET];
+ first_engine= ha_resolve_by_legacy_type(ha_thd(), first_db_type);
+ if (!first_engine)
+ goto err2;
+ address_tot_name_len= file_buffer + PAR_FILE_ENGINE_OFFSET +
+ 4 * tot_partition_words;
tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4;
if (len_words != (tot_partition_words + tot_name_words + 4))
- goto err3;
+ goto err2;
name_buffer_ptr= file_buffer + 16 + 4 * tot_partition_words;
(void) mysql_file_close(file, MYF(0));
m_file_buffer= file_buffer; // Will be freed in clear_handler_file()
@@ -2468,13 +2474,22 @@ bool ha_partition::get_from_handler_file
if (!(m_engine_array= (plugin_ref*)
my_malloc(m_tot_parts * sizeof(plugin_ref), MYF(MY_WME))))
- goto err3;
+ goto err2;
for (i= 0; i < m_tot_parts; i++)
- m_engine_array[i]= ha_lock_engine(NULL, engine_array[i]);
+ {
+ db_type= (enum legacy_db_type) file_buffer[PAR_FILE_ENGINE_OFFSET + i];
+ if (db_type != first_db_type)
+ {
+ DBUG_PRINT("error", ("partition %u engine %d is not same as "
+ "first partition %d", i, db_type,
+ (int) first_db_type));
+ DBUG_ASSERT(0);
+ goto err3;
+ }
+ m_engine_array[i]= ha_lock_engine(NULL, first_engine);
+ }
- my_afree((gptr) engine_array);
-
if (!m_file && create_handlers(mem_root))
{
clear_handler_file();
@@ -2483,9 +2498,12 @@ bool ha_partition::get_from_handler_file
DBUG_RETURN(FALSE);
err3:
- my_afree((gptr) engine_array);
+ plugin_unlock_list(NULL, m_engine_array, i);
+ my_free(m_engine_array);
+ m_engine_array= NULL;
err2:
my_free(file_buffer);
+ m_file_buffer= NULL;
err1:
(void) mysql_file_close(file, MYF(0));
DBUG_RETURN(TRUE);
@@ -2497,6 +2515,101 @@ err1:
****************************************************************************/
+bool ha_partition::insert_partition_name_in_hash(const char *name, uint part_id,
+ bool is_subpart)
+{
+ PART_NAME_DEF *part_def;
+ uchar *part_name;
+ uint part_name_length;
+ /*
+ Calculate and store the length here, to avoid doing it when
+ searching the hash.
+ */
+ part_name_length= strlen(name);
+ /*
+ Must use memory that lives as long as table_share.
+ Freed in ha_data_partition_destroy.
+ Since we use my_multi_malloc, then my_free(part_def) will also free
+ part_name, as a part of my_hash_free.
+ */
+ if (!my_multi_malloc(MY_WME,
+ &part_def, sizeof(PART_NAME_DEF),
+ &part_name, part_name_length + 1,
+ NULL))
+ return true;
+ memcpy(part_name, name, part_name_length + 1);
+ part_def->partition_name= part_name;
+ part_def->length= part_name_length;
+ part_def->part_id= part_id;
+ part_def->is_subpart= is_subpart;
+ if (my_hash_insert(&table_share->ha_part_data->partition_name_hash,
+ (uchar *) part_def))
+ return true;
+ return false;
+}
+
+
+/**
+ Populate the partition_name_hash in table_share->ha_part_data.
+
+ @note table_share->LOCK_ha_data mutex must be hold.
+*/
+
+bool ha_partition::populate_partition_name_hash()
+{
+ List_iterator<partition_element> part_it(m_part_info->partitions);
+ uint num_parts= m_part_info->num_parts;
+ uint num_subparts= m_is_sub_partitioned ? m_part_info->num_subparts : 1;
+ uint tot_names;
+ uint i= 0;
+#ifndef DBUG_OFF
+ if (table_share->tmp_table == NO_TMP_TABLE)
+ mysql_mutex_assert_owner(&table_share->LOCK_ha_data);
+#endif
+
+ DBUG_ENTER("ha_partition::populate_partition_name_hash");
+ tot_names= m_is_sub_partitioned ? m_tot_parts + num_parts : num_parts;
+ if (my_hash_init(&table_share->ha_part_data->partition_name_hash,
+ system_charset_info, tot_names, 0, 0,
+ (my_hash_get_key) get_part_name,
+ my_free, HASH_UNIQUE))
+ {
+ DBUG_RETURN(TRUE);
+ }
+
+ do
+ {
+ partition_element *part_elem= part_it++;
+ DBUG_ASSERT(part_elem->part_state == PART_NORMAL);
+ if (part_elem->part_state == PART_NORMAL)
+ {
+ if (insert_partition_name_in_hash(part_elem->partition_name,
+ i * num_subparts, false))
+ goto err;
+ if (m_is_sub_partitioned)
+ {
+ List_iterator<partition_element>
+ subpart_it(part_elem->subpartitions);
+ partition_element *sub_elem;
+ uint j= 0;
+ do
+ {
+ sub_elem= subpart_it++;
+ if (insert_partition_name_in_hash(sub_elem->partition_name,
+ i * num_subparts + j, true))
+ goto err;
+
+ } while (++j < num_subparts);
+ }
+ }
+ } while (++i < num_parts);
+ DBUG_RETURN(FALSE);
+err:
+ my_hash_free(&table_share->ha_part_data->partition_name_hash);
+ DBUG_RETURN(TRUE);
+}
+
+
/**
A destructor for partition-specific TABLE_SHARE data.
*/
@@ -2506,6 +2619,7 @@ void ha_data_partition_destroy(HA_DATA_P
if (ha_part_data)
{
mysql_mutex_destroy(&ha_part_data->LOCK_auto_inc);
+ my_hash_free(&ha_part_data->partition_name_hash);
}
}
@@ -2584,15 +2698,24 @@ int ha_partition::open(const char *name,
if (bitmap_init(&m_bulk_insert_started, NULL, m_tot_parts + 1, FALSE))
DBUG_RETURN(1);
bitmap_clear_all(&m_bulk_insert_started);
- /* Initialize the bitmap we use to determine what partitions are used */
+ /* Initialize the bitmap we use to keep track of locked partitions */
+ if (bitmap_init(&m_locked_partitions, NULL, m_tot_parts, FALSE))
+ {
+ bitmap_free(&m_bulk_insert_started);
+ DBUG_RETURN(1);
+ }
+ bitmap_clear_all(&m_locked_partitions);
+ /* Initialize the bitmap we use to determine what partitions are locked */
+ DBUG_ASSERT(m_part_info);
+ /* Initialize the bitmap for used partitions */
if (!is_clone)
{
- if (bitmap_init(&(m_part_info->used_partitions), NULL, m_tot_parts, TRUE))
+ if (m_part_info->set_partition_bitmaps(NULL))
{
bitmap_free(&m_bulk_insert_started);
+ bitmap_free(&m_locked_partitions);
DBUG_RETURN(1);
}
- bitmap_set_all(&(m_part_info->used_partitions));
}
file= m_file;
@@ -2652,23 +2775,24 @@ int ha_partition::open(const char *name,
mysql_mutex_lock(&table_share->LOCK_ha_data);
if (!table_share->ha_part_data)
{
- /* currently only needed for auto_increment */
+ /* currently only needed for auto_increment and partition_name_hash */
table_share->ha_part_data= (HA_DATA_PARTITION*)
alloc_root(&table_share->mem_root,
sizeof(HA_DATA_PARTITION));
if (!table_share->ha_part_data)
{
- if (is_not_tmp_table)
- mysql_mutex_unlock(&table_share->LOCK_ha_data);
- goto err_handler;
+ goto unlock_err_handler;
}
DBUG_PRINT("info", ("table_share->ha_part_data 0x%p",
table_share->ha_part_data));
+ /* zeros both auto_increment variables and partition_name_hash.records */
bzero(table_share->ha_part_data, sizeof(HA_DATA_PARTITION));
table_share->ha_part_data_destroy= ha_data_partition_destroy;
mysql_mutex_init(key_PARTITION_LOCK_auto_inc,
&table_share->ha_part_data->LOCK_auto_inc,
MY_MUTEX_INIT_FAST);
+ if (populate_partition_name_hash())
+ goto unlock_err_handler;
}
if (is_not_tmp_table)
mysql_mutex_unlock(&table_share->LOCK_ha_data);
@@ -2687,13 +2811,15 @@ int ha_partition::open(const char *name,
info(HA_STATUS_VARIABLE | HA_STATUS_CONST);
DBUG_RETURN(0);
+unlock_err_handler:
+ if (is_not_tmp_table)
+ mysql_mutex_unlock(&table_share->LOCK_ha_data);
err_handler:
DEBUG_SYNC(ha_thd(), "partition_open_error");
while (file-- != m_file)
(*file)->ha_close();
bitmap_free(&m_bulk_insert_started);
- if (!is_clone)
- bitmap_free(&(m_part_info->used_partitions));
+ bitmap_free(&m_locked_partitions);
DBUG_RETURN(error);
}
@@ -2740,8 +2866,8 @@ int ha_partition::close(void)
DBUG_ASSERT(table->s == table_share);
delete_queue(&m_queue);
bitmap_free(&m_bulk_insert_started);
- if (!is_clone)
- bitmap_free(&(m_part_info->used_partitions));
+ bitmap_free(&m_locked_partitions);
+ DBUG_ASSERT(m_part_info);
file= m_file;
repeat:
@@ -2803,41 +2929,59 @@ repeat:
int ha_partition::external_lock(THD *thd, int lock_type)
{
- bool first= TRUE;
uint error;
- handler **file;
+ uint i, first_used_partition;
+ MY_BITMAP *used_partitions;
DBUG_ENTER("ha_partition::external_lock");
DBUG_ASSERT(!auto_increment_lock && !auto_increment_safe_stmt_log_lock);
- file= m_file;
m_lock_type= lock_type;
-repeat:
- do
+ if (m_lock_type == F_UNLCK)
+ used_partitions= &m_locked_partitions;
+ else
+ used_partitions= &(m_part_info->lock_partitions);
+ first_used_partition= bitmap_get_first_set(used_partitions);
+ DBUG_ASSERT(first_used_partition != MY_BIT_NONE);
+ for (i= first_used_partition; i < m_tot_parts; i++)
{
- DBUG_PRINT("info", ("external_lock(thd, %d) iteration %d",
- lock_type, (int) (file - m_file)));
- if ((error= (*file)->ha_external_lock(thd, lock_type)))
+ if (bitmap_is_set(used_partitions, i))
{
- if (F_UNLCK != lock_type)
- goto err_handler;
+ DBUG_PRINT("info", ("external_lock(thd, %d) part %d", lock_type, i));
+ if ((error= m_file[i]->ha_external_lock(thd, lock_type)))
+ {
+ if (lock_type != F_UNLCK)
+ goto err_handler;
+ }
+ DBUG_PRINT("info", ("external_lock part %u lock %d", i, lock_type));
+ if (lock_type != F_UNLCK)
+ bitmap_set_bit(&m_locked_partitions, i);
}
- } while (*(++file));
+ }
+ if (m_lock_type == F_UNLCK)
+ bitmap_clear_all(used_partitions);
- if (first && m_added_file && m_added_file[0])
+ if (m_added_file && m_added_file[0])
{
+ handler **file= m_added_file;
DBUG_ASSERT(lock_type == F_UNLCK);
- file= m_added_file;
- first= FALSE;
- goto repeat;
+ do
+ {
+ (void) (*file)->ha_external_lock(thd, lock_type);
+ } while (*(++file));
}
DBUG_RETURN(0);
err_handler:
- while (file-- != m_file)
+ for (i= first_used_partition; i < m_tot_parts; i++)
{
- (*file)->ha_external_lock(thd, F_UNLCK);
+ if (bitmap_is_set(&m_locked_partitions, i))
+ {
+ (void) m_file[i]->ha_external_lock(thd, F_UNLCK);
+ }
}
+ m_lock_type= F_UNLCK;
+ bitmap_clear_all(&m_locked_partitions);
DBUG_RETURN(error);
}
@@ -2892,14 +3036,19 @@ THR_LOCK_DATA **ha_partition::store_lock
THR_LOCK_DATA **to,
enum thr_lock_type lock_type)
{
- handler **file;
+ uint i, first_used_partition;
DBUG_ENTER("ha_partition::store_lock");
- file= m_file;
- do
+
+ first_used_partition= bitmap_get_first_set(&(m_part_info->lock_partitions));
+ DBUG_ASSERT(first_used_partition != MY_BIT_NONE);
+ for (i= first_used_partition; i < m_tot_parts; i++)
{
- DBUG_PRINT("info", ("store lock %d iteration", (int) (file - m_file)));
- to= (*file)->store_lock(thd, to, lock_type);
- } while (*(++file));
+ if (bitmap_is_set(&(m_part_info->lock_partitions), i))
+ {
+ DBUG_PRINT("info", ("store lock %d iteration", i));
+ to= m_file[i]->store_lock(thd, to, lock_type);
+ }
+ }
DBUG_RETURN(to);
}
@@ -2923,15 +3072,17 @@ THR_LOCK_DATA **ha_partition::store_lock
int ha_partition::start_stmt(THD *thd, thr_lock_type lock_type)
{
int error= 0;
- handler **file;
+ uint i, first_used_partition;
DBUG_ENTER("ha_partition::start_stmt");
- file= m_file;
- do
+ first_used_partition= bitmap_get_first_set(&(m_part_info->lock_partitions));
+ DBUG_ASSERT(first_used_partition != MY_BIT_NONE);
+ for (i= first_used_partition; i < m_tot_parts; i++)
{
- if ((error= (*file)->start_stmt(thd, lock_type)))
- break;
- } while (*(++file));
+ if (bitmap_is_set(&(m_part_info->lock_partitions), i))
+ if ((error= m_file[i]->start_stmt(thd, lock_type)))
+ break;
+ }
DBUG_RETURN(error);
}
@@ -3008,7 +3159,7 @@ bool ha_partition::was_semi_consistent_r
{
DBUG_ENTER("ha_partition::was_semi_consistent_read");
DBUG_ASSERT(m_last_part < m_tot_parts &&
- bitmap_is_set(&(m_part_info->used_partitions), m_last_part));
+ bitmap_is_set(&(m_part_info->read_partitions), m_last_part));
DBUG_RETURN(m_file[m_last_part]->was_semi_consistent_read());
}
@@ -3033,13 +3184,15 @@ bool ha_partition::was_semi_consistent_r
*/
void ha_partition::try_semi_consistent_read(bool yes)
{
- handler **file;
+ uint i, first_used_partition;
DBUG_ENTER("ha_partition::try_semi_consistent_read");
- for (file= m_file; *file; file++)
+ first_used_partition= bitmap_get_first_set(&(m_part_info->read_partitions));
+ DBUG_ASSERT(first_used_partition != MY_BIT_NONE);
+ for (i= first_used_partition; i < m_tot_parts; i++)
{
- if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
- (*file)->try_semi_consistent_read(yes);
+ if (bitmap_is_set(&(m_part_info->read_partitions), i))
+ m_file[i]->try_semi_consistent_read(yes);
}
DBUG_VOID_RETURN;
}
@@ -3097,9 +3250,6 @@ int ha_partition::write_row(uchar * buf)
timestamp_auto_set_type saved_timestamp_type= table->timestamp_field_type;
sql_mode_t saved_sql_mode= thd->variables.sql_mode;
bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
-#ifdef NOT_NEEDED
- uchar *rec0= m_rec0;
-#endif
DBUG_ENTER("ha_partition::write_row");
DBUG_ASSERT(buf == m_rec0);
@@ -3151,26 +3301,20 @@ int ha_partition::write_row(uchar * buf)
}
old_map= dbug_tmp_use_all_columns(table, table->read_set);
-#ifdef NOT_NEEDED
- if (likely(buf == rec0))
-#endif
- error= m_part_info->get_partition_id(m_part_info, &part_id,
- &func_value);
-#ifdef NOT_NEEDED
- else
- {
- set_field_ptr(m_part_field_array, buf, rec0);
- error= m_part_info->get_partition_id(m_part_info, &part_id,
- &func_value);
- set_field_ptr(m_part_field_array, rec0, buf);
- }
-#endif
+ error= m_part_info->get_partition_id(m_part_info, &part_id, &func_value);
dbug_tmp_restore_column_map(table->read_set, old_map);
if (unlikely(error))
{
m_part_info->err_value= func_value;
goto exit;
}
+ if (!bitmap_is_set(&(m_part_info->lock_partitions), part_id))
+ {
+ DBUG_PRINT("info", ("Write to non-locked partition %u (func_value: %ld)",
+ part_id, (long) func_value));
+ error= HA_ERR_NOT_IN_LOCK_PARTITIONS;
+ goto exit;
+ }
m_last_part= part_id;
DBUG_PRINT("info", ("Insert in partition %d", part_id));
start_part_bulk_insert(thd, part_id);
@@ -3237,7 +3381,12 @@ int ha_partition::update_row(const uchar
m_part_info->err_value= func_value;
goto exit;
}
-
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), old_part_id));
+ if (!bitmap_is_set(&(m_part_info->lock_partitions), new_part_id))
+ {
+ error= HA_ERR_NOT_IN_LOCK_PARTITIONS;
+ goto exit;
+ }
m_last_part= new_part_id;
start_part_bulk_insert(thd, new_part_id);
if (new_part_id == old_part_id)
@@ -3344,6 +3493,11 @@ int ha_partition::delete_row(const uchar
DBUG_RETURN(error);
}
m_last_part= part_id;
+ /* Should never call delete_row on a partition which is not read */
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), part_id));
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->lock_partitions), part_id));
+ if (!bitmap_is_set(&(m_part_info->lock_partitions), part_id))
+ DBUG_RETURN(HA_ERR_NOT_IN_LOCK_PARTITIONS);
tmp_disable_binlog(thd);
error= m_file[part_id]->ha_delete_row(buf);
reenable_binlog(thd);
@@ -3528,6 +3682,7 @@ void ha_partition::start_part_bulk_inser
if (!bitmap_is_set(&m_bulk_insert_started, part_id) &&
bitmap_is_set(&m_bulk_insert_started, m_tot_parts))
{
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->lock_partitions), part_id));
old_buffer_size= thd->variables.read_buff_size;
/* Update read_buffer_size for this partition */
thd->variables.read_buff_size= estimate_read_buffer_size(old_buffer_size);
@@ -3712,9 +3867,9 @@ int ha_partition::rnd_init(bool scan)
}
/* Now we see what the index of our first important partition is */
- DBUG_PRINT("info", ("m_part_info->used_partitions: 0x%lx",
- (long) m_part_info->used_partitions.bitmap));
- part_id= bitmap_get_first_set(&(m_part_info->used_partitions));
+ DBUG_PRINT("info", ("m_part_info->read_partitions: 0x%lx",
+ (long) m_part_info->read_partitions.bitmap));
+ part_id= bitmap_get_first_set(&(m_part_info->read_partitions));
DBUG_PRINT("info", ("m_part_spec.start_part %d", part_id));
if (MY_BIT_NONE == part_id)
@@ -3743,7 +3898,7 @@ int ha_partition::rnd_init(bool scan)
{
for (i= part_id; i < m_tot_parts; i++)
{
- if (bitmap_is_set(&(m_part_info->used_partitions), i))
+ if (bitmap_is_set(&(m_part_info->read_partitions), i))
{
if ((error= m_file[i]->ha_rnd_init(scan)))
goto err;
@@ -3759,7 +3914,7 @@ int ha_partition::rnd_init(bool scan)
err:
while ((int)--i >= (int)part_id)
{
- if (bitmap_is_set(&(m_part_info->used_partitions), i))
+ if (bitmap_is_set(&(m_part_info->read_partitions), i))
m_file[i]->ha_rnd_end();
}
err1:
@@ -3798,7 +3953,7 @@ int ha_partition::rnd_end()
file= m_file;
do
{
- if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
+ if (bitmap_is_set(&(m_part_info->read_partitions), (file - m_file)))
(*file)->ha_rnd_end();
} while (*(++file));
break;
@@ -3876,7 +4031,7 @@ int ha_partition::rnd_next(uchar *buf)
/* Shift to next partition */
while (++part_id < m_tot_parts &&
- !bitmap_is_set(&(m_part_info->used_partitions), part_id))
+ !bitmap_is_set(&(m_part_info->read_partitions), part_id))
;
if (part_id >= m_tot_parts)
{
@@ -3928,6 +4083,7 @@ end_dont_reset_start_part:
void ha_partition::position(const uchar *record)
{
handler *file= m_file[m_last_part];
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), m_last_part));
DBUG_ENTER("ha_partition::position");
file->position(record);
@@ -3982,6 +4138,7 @@ int ha_partition::rnd_pos(uchar * buf, u
part_id= uint2korr((const uchar *) pos);
DBUG_ASSERT(part_id < m_tot_parts);
file= m_file[part_id];
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), part_id));
m_last_part= part_id;
DBUG_RETURN(file->ha_rnd_pos(buf, (pos + PARTITION_BYTES_IN_POS)));
}
@@ -4113,7 +4270,7 @@ int ha_partition::index_init(uint inx, b
do
{
/* TODO RONM: Change to index_init() when code is stable */
- if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
+ if (bitmap_is_set(&(m_part_info->read_partitions), (file - m_file)))
if ((error= (*file)->ha_index_init(inx, sorted)))
{
DBUG_ASSERT(0); // Should never happen
@@ -4152,7 +4309,7 @@ int ha_partition::index_end()
{
int tmp;
/* TODO RONM: Change to index_end() when code is stable */
- if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file)))
+ if (bitmap_is_set(&(m_part_info->read_partitions), (file - m_file)))
if ((tmp= (*file)->ha_index_end()))
error= tmp;
} while (*(++file));
@@ -4440,7 +4597,7 @@ int ha_partition::index_read_idx_map(uch
for (part= m_part_spec.start_part; part <= m_part_spec.end_part; part++)
{
- if (bitmap_is_set(&(m_part_info->used_partitions), part))
+ if (bitmap_is_set(&(m_part_info->read_partitions), part))
{
error= m_file[part]->ha_index_read_idx_map(buf, index, key,
keypart_map, find_flag);
@@ -4692,7 +4849,7 @@ int ha_partition::partition_scan_set_up(
Verify this, also bitmap must have at least one bit set otherwise
the result from this table is the empty set.
*/
- uint start_part= bitmap_get_first_set(&(m_part_info->used_partitions));
+ uint start_part= bitmap_get_first_set(&(m_part_info->read_partitions));
if (start_part == MY_BIT_NONE)
{
DBUG_PRINT("info", ("scan with no partition to scan"));
@@ -4809,7 +4966,7 @@ int ha_partition::handle_unordered_scan_
int error;
handler *file;
- if (!(bitmap_is_set(&(m_part_info->used_partitions), i)))
+ if (!(bitmap_is_set(&(m_part_info->read_partitions), i)))
continue;
file= m_file[i];
m_part_spec.start_part= i;
@@ -4900,7 +5057,7 @@ int ha_partition::handle_ordered_index_s
DBUG_PRINT("info", ("m_part_spec.start_part %d", m_part_spec.start_part));
for (i= m_part_spec.start_part; i <= m_part_spec.end_part; i++)
{
- if (!(bitmap_is_set(&(m_part_info->used_partitions), i)))
+ if (!(bitmap_is_set(&(m_part_info->read_partitions), i)))
continue;
uchar *rec_buf_ptr= rec_buf(i);
int error;
@@ -5177,6 +5334,10 @@ int ha_partition::info(uint flag)
uint extra_var_flag= flag & HA_STATUS_VARIABLE_EXTRA;
DBUG_ENTER("ha_partition::info");
+#ifndef DBUG_OFF
+ if (bitmap_is_set_all(&(m_part_info->read_partitions)))
+ DBUG_PRINT("info", ("All partitions are used"));
+#endif /* DBUG_OFF */
if (flag & HA_STATUS_AUTO)
{
bool auto_inc_is_first_in_idx= (table_share->next_number_keypart == 0);
@@ -5198,6 +5359,12 @@ int ha_partition::info(uint flag)
table_share->ha_part_data->next_auto_inc_val;
else
{
+ /*
+ The auto-inc mutex in the table_share is locked, so we do not need
+ to have the handlers locked.
+ HA_STATUS_NO_LOCK is not checked, since we cannot skip locking
+ the mutex, because it is initialized.
+ */
handler *file, **file_array;
ulonglong auto_increment_value= 0;
file_array= m_file;
@@ -5257,7 +5424,7 @@ int ha_partition::info(uint flag)
file_array= m_file;
do
{
- if (bitmap_is_set(&(m_part_info->used_partitions), (file_array - m_file)))
+ if (bitmap_is_set(&(m_part_info->read_partitions), (file_array - m_file)))
{
file= *file_array;
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag);
@@ -5340,7 +5507,7 @@ int ha_partition::info(uint flag)
file= *file_array;
/* Get variables if not already done */
if (!(flag & HA_STATUS_VARIABLE) ||
- !bitmap_is_set(&(m_part_info->used_partitions),
+ !bitmap_is_set(&(m_part_info->read_partitions),
(file_array - m_file)))
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag);
if (file->stats.records > max_records)
@@ -5398,6 +5565,7 @@ void ha_partition::get_dynamic_partition
uint part_id)
{
handler *file= m_file[part_id];
+ DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), part_id));
file->info(HA_STATUS_CONST | HA_STATUS_TIME | HA_STATUS_VARIABLE |
HA_STATUS_VARIABLE_EXTRA | HA_STATUS_NO_LOCK);
@@ -5421,7 +5589,6 @@ void ha_partition::get_dynamic_partition
General function to prepare handler for certain behavior.
@param[in] operation operation to execute
- operation Operation type for extra call
@return status
@retval 0 success
@@ -5888,22 +6055,36 @@ int ha_partition::extra(enum ha_extra_fu
0 Success
DESCRIPTION
- Called at end of each statement to reste buffers
+ Called at end of each statement to reset buffers
*/
int ha_partition::reset(void)
{
- int result= 0, tmp;
- handler **file;
+ int result= 0;
DBUG_ENTER("ha_partition::reset");
- if (m_part_info)
- bitmap_set_all(&m_part_info->used_partitions);
- file= m_file;
- do
+
+ /* May not have m_part_info set (in case of failed open or prune). */
+ if (m_part_info && m_part_info->bitmaps_are_initialized)
{
- if ((tmp= (*file)->ha_reset()))
- result= tmp;
- } while (*(++file));
+ handler **file;
+ int tmp;
+ uint first_used_partition;
+ first_used_partition= bitmap_get_first_set(&m_part_info->lock_partitions);
+ if (first_used_partition == MY_BIT_NONE)
+ DBUG_RETURN(result);
+
+ file= m_file + first_used_partition;
+ do
+ {
+ if (bitmap_is_set(&(m_part_info->lock_partitions), file - m_file))
+ {
+ if ((tmp= (*file)->ha_reset()))
+ result= tmp;
+ }
+ } while (*(++file));
+ /* Be sure lock_partitions are set if no pruning in the next statement */
+ m_part_info->set_partition_bitmaps(NULL);
+ }
DBUG_RETURN(result);
}
@@ -6003,14 +6184,11 @@ int ha_partition::loop_extra(enum ha_ext
{
int result= 0, tmp;
handler **file;
- bool is_select;
DBUG_ENTER("ha_partition::loop_extra()");
- is_select= (thd_sql_command(ha_thd()) == SQLCOM_SELECT);
for (file= m_file; *file; file++)
{
- if (!is_select ||
- bitmap_is_set(&(m_part_info->used_partitions), file - m_file))
+ if (bitmap_is_set(&(m_part_info->lock_partitions), file - m_file))
{
if ((tmp= (*file)->extra(operation)))
result= tmp;
@@ -6100,9 +6278,11 @@ void ha_partition::late_extra_no_cache(u
const key_map *ha_partition::keys_to_use_for_scanning()
{
+ uint first_used_partition;
DBUG_ENTER("ha_partition::keys_to_use_for_scanning");
- DBUG_RETURN(m_file[0]->keys_to_use_for_scanning());
+ first_used_partition= bitmap_get_first_set(&(m_part_info->read_partitions));
+ DBUG_RETURN(m_file[first_used_partition]->keys_to_use_for_scanning());
}
#define MAX_PARTS_FOR_OPTIMIZER_CALLS 10
@@ -6117,8 +6297,8 @@ void ha_partition::partitions_optimizer_
uint *num_used_parts,
uint *check_min_num)
{
- *first= bitmap_get_first_set(&(m_part_info->used_partitions));
- *num_used_parts= bitmap_bits_set(&(m_part_info->used_partitions));
+ *first= bitmap_get_first_set(&(m_part_info->read_partitions));
+ *num_used_parts= bitmap_bits_set(&(m_part_info->read_partitions));
*check_min_num= min(MAX_PARTS_FOR_OPTIMIZER_CALLS, *num_used_parts);
}
@@ -6139,10 +6319,11 @@ double ha_partition::scan_time()
uint first, part_id, num_used_parts, check_min_num, partitions_called= 0;
DBUG_ENTER("ha_partition::scan_time");
- partitions_optimizer_call_preparations(&first, &num_used_parts, &check_min_num);
+ partitions_optimizer_call_preparations(&first, &num_used_parts,
+ &check_min_num);
for (part_id= first; partitions_called < num_used_parts ; part_id++)
{
- if (!bitmap_is_set(&(m_part_info->used_partitions), part_id))
+ if (!bitmap_is_set(&(m_part_info->read_partitions), part_id))
continue;
scan_time+= m_file[part_id]->scan_time();
partitions_called++;
@@ -6172,12 +6353,12 @@ ha_rows ha_partition::estimate_rows(bool
{
ha_rows rows, estimated_rows= 0;
uint first, part_id, num_used_parts, check_min_num, partitions_called= 0;
- DBUG_ENTER("ha_partition::records_in_range");
+ DBUG_ENTER("ha_partition::estimate_rows");
partitions_optimizer_call_preparations(&first, &num_used_parts, &check_min_num);
for (part_id= first; partitions_called < num_used_parts ; part_id++)
{
- if (!bitmap_is_set(&(m_part_info->used_partitions), part_id))
+ if (!bitmap_is_set(&(m_part_info->read_partitions), part_id))
continue;
if (is_records_in_range)
rows= m_file[part_id]->records_in_range(inx, min_key, max_key);
@@ -6277,11 +6458,7 @@ double ha_partition::read_time(uint inde
/**
Number of rows in table. see handler.h
- SYNOPSIS
- records()
-
- RETURN VALUE
- Number of total rows in a partitioned table.
+ @return Number of records in the table (after pruning!)
*/
ha_rows ha_partition::records()
@@ -6293,10 +6470,13 @@ ha_rows ha_partition::records()
file= m_file;
do
{
- rows= (*file)->records();
- if (rows == HA_POS_ERROR)
- DBUG_RETURN(HA_POS_ERROR);
- tot_rows+= rows;
+ if (bitmap_is_set(&(m_part_info->read_partitions), file - m_file))
+ {
+ rows= (*file)->records();
+ if (rows == HA_POS_ERROR)
+ DBUG_RETURN(HA_POS_ERROR);
+ tot_rows+= rows;
+ }
} while (*(++file));
DBUG_RETURN(tot_rows);
}
@@ -6354,9 +6534,12 @@ uint8 ha_partition::table_cache_type()
const char *ha_partition::index_type(uint inx)
{
+ uint first_used_partition;
DBUG_ENTER("ha_partition::index_type");
- DBUG_RETURN(m_file[0]->index_type(inx));
+ first_used_partition= bitmap_get_first_set(&(m_part_info->read_partitions));
+ DBUG_ASSERT(first_used_partition != MY_BIT_NONE);
+ DBUG_RETURN(m_file[first_used_partition]->index_type(inx));
}
@@ -6365,6 +6548,7 @@ enum row_type ha_partition::get_row_type
handler **file;
enum row_type type= (*m_file)->get_row_type();
+ DBUG_ASSERT(bitmap_is_set_all(&(m_part_info->read_partitions)));
for (file= m_file, file++; *file; file++)
{
enum row_type part_type= (*file)->get_row_type();
@@ -6822,7 +7006,8 @@ void ha_partition::release_auto_incremen
if (table->s->next_number_keypart)
{
for (uint i= 0; i < m_tot_parts; i++)
- m_file[i]->ha_release_auto_increment();
+ if (bitmap_is_set(&(m_part_info->lock_partitions), i))
+ m_file[i]->ha_release_auto_increment();
}
else if (next_insert_id)
{
@@ -6889,6 +7074,7 @@ int ha_partition::disable_indexes(uint m
handler **file;
int error= 0;
+ DBUG_ASSERT(bitmap_is_set_all(&(m_part_info->lock_partitions)));
for (file= m_file; *file; file++)
{
if ((error= (*file)->ha_disable_indexes(mode)))
@@ -6913,6 +7099,7 @@ int ha_partition::enable_indexes(uint mo
handler **file;
int error= 0;
+ DBUG_ASSERT(bitmap_is_set_all(&(m_part_info->lock_partitions)));
for (file= m_file; *file; file++)
{
if ((error= (*file)->ha_enable_indexes(mode)))
@@ -6937,6 +7124,7 @@ int ha_partition::indexes_are_disabled(v
handler **file;
int error= 0;
+ DBUG_ASSERT(bitmap_is_set_all(&(m_part_info->lock_partitions)));
for (file= m_file; *file; file++)
{
if ((error= (*file)->indexes_are_disabled()))
=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h 2010-12-03 10:05:56 +0000
+++ b/sql/ha_partition.h 2010-12-14 20:03:21 +0000
@@ -164,6 +164,8 @@ private:
ha_rows m_bulk_inserted_rows;
/** used for prediction of start_bulk_insert rows */
enum_monotonicity_info m_part_func_monotonicity_info;
+ /** keep track of locked partitions */
+ MY_BITMAP m_locked_partitions;
public:
handler *clone(MEM_ROOT *mem_root);
virtual void set_part_info(partition_info *part_info)
@@ -243,11 +245,10 @@ private:
handler *file, const char *part_name,
partition_element *p_elem);
/*
- delete_table, rename_table and create uses very similar logic which
+ delete_table and rename_table uses very similar logic which
is packed into this routine.
*/
- uint del_ren_cre_table(const char *from, const char *to,
- TABLE *table_arg, HA_CREATE_INFO *create_info);
+ uint del_ren_table(const char *from, const char *to);
/*
One method to create the table_name.par file containing the names of the
underlying partitions, their engine and the number of partitions.
@@ -261,9 +262,11 @@ private:
int set_up_table_before_create(TABLE *table_arg,
const char *partition_name_with_path,
HA_CREATE_INFO *info,
- uint part_id,
partition_element *p_elem);
partition_element *find_partition_element(uint part_id);
+ bool insert_partition_name_in_hash(const char *name, uint part_id,
+ bool is_subpart);
+ bool populate_partition_name_hash();
public:
@@ -367,10 +370,13 @@ public:
virtual bool is_fatal_error(int error, uint flags)
{
if (!handler::is_fatal_error(error, flags) ||
- error == HA_ERR_NO_PARTITION_FOUND)
+ error == HA_ERR_NO_PARTITION_FOUND ||
+ error == HA_ERR_NOT_IN_LOCK_PARTITIONS)
return FALSE;
return TRUE;
}
+
+
/*
-------------------------------------------------------------------------
MODULE full table scan
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc 2011-01-21 10:50:31 +0000
+++ b/sql/handler.cc 2011-01-26 15:48:12 +0000
@@ -2155,6 +2155,8 @@ int handler::ha_open(TABLE *table_arg, c
table= table_arg;
DBUG_ASSERT(table->s == table_share);
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
+ DBUG_PRINT("info", ("old m_lock_type: %d F_UNLCK %d", m_lock_type, F_UNLCK));
DBUG_ASSERT(alloc_root_inited(&table->mem_root));
if ((error=open(name,mode,test_if_locked)))
@@ -2212,12 +2214,15 @@ int handler::ha_close(void)
}
#endif
DBUG_ASSERT(m_psi == NULL);
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
return close();
}
int handler::ha_rnd_next(uchar *buf)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2230,6 +2235,8 @@ int handler::ha_rnd_next(uchar *buf)
int handler::ha_rnd_pos(uchar *buf, uchar *pos)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2244,6 +2251,8 @@ int handler::ha_index_read_map(uchar *bu
enum ha_rkey_function find_flag)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2258,6 +2267,8 @@ int handler::ha_index_read_idx_map(uchar
enum ha_rkey_function find_flag)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2270,6 +2281,8 @@ int handler::ha_index_read_idx_map(uchar
int handler::ha_index_next(uchar * buf)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2282,6 +2295,8 @@ int handler::ha_index_next(uchar * buf)
int handler::ha_index_prev(uchar * buf)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2294,6 +2309,8 @@ int handler::ha_index_prev(uchar * buf)
int handler::ha_index_first(uchar * buf)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2306,6 +2323,8 @@ int handler::ha_index_first(uchar * buf)
int handler::ha_index_last(uchar * buf)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2318,6 +2337,8 @@ int handler::ha_index_last(uchar * buf)
int handler::ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2331,6 +2352,8 @@ int handler::ha_index_read(uchar *buf, c
enum ha_rkey_function find_flag)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2343,6 +2366,8 @@ int handler::ha_index_read(uchar *buf, c
int handler::ha_index_read_last(uchar *buf, const uchar *key, uint key_len)
{
int result;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
MYSQL_START_TABLE_IO_WAIT(locker, &state, m_psi,
@@ -2558,6 +2583,8 @@ int handler::update_auto_increment()
bool append= FALSE;
THD *thd= table->in_use;
struct system_variables *variables= &thd->variables;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
DBUG_ENTER("handler::update_auto_increment");
/*
@@ -2808,6 +2835,8 @@ void handler::get_auto_increment(ulonglo
void handler::ha_release_auto_increment()
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
release_auto_increment();
insert_id_for_cur_row= 0;
auto_inc_interval_for_cur_row.replace(0, 0, 0);
@@ -3031,6 +3060,9 @@ void handler::print_error(int error, myf
case HA_ERR_TOO_MANY_CONCURRENT_TRXS:
textno= ER_TOO_MANY_CONCURRENT_TRXS;
break;
+ case HA_ERR_NOT_IN_LOCK_PARTITIONS:
+ textno=ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET;
+ break;
default:
{
/* The error was "unknown" to this function.
@@ -3224,6 +3256,8 @@ err:
*/
uint handler::get_dup_key(int error)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
DBUG_ENTER("handler::get_dup_key");
table->file->errkey = (uint) -1;
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
@@ -3255,6 +3289,7 @@ int handler::delete_table(const char *na
int error= 0;
int enoent_or_zero= ENOENT; // Error if no file was deleted
char buff[FN_REFLEN];
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
for (const char **ext=bas_ext(); *ext ; ext++)
{
@@ -3329,6 +3364,8 @@ void handler::drop_table(const char *nam
int handler::ha_check(THD *thd, HA_CHECK_OPT *check_opt)
{
int error;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
if ((table->s->mysql_version >= MYSQL_VERSION_ID) &&
(check_opt->sql_flags & TT_FOR_UPGRADE))
@@ -3389,7 +3426,6 @@ handler::mark_trx_read_write()
int handler::ha_repair(THD* thd, HA_CHECK_OPT* check_opt)
{
int result;
-
mark_trx_read_write();
if ((result= repair(thd, check_opt)))
@@ -3408,6 +3444,8 @@ int
handler::ha_bulk_update_row(const uchar *old_data, uchar *new_data,
uint *dup_key_found)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return bulk_update_row(old_data, new_data, dup_key_found);
@@ -3423,6 +3461,8 @@ handler::ha_bulk_update_row(const uchar
int
handler::ha_delete_all_rows()
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return delete_all_rows();
@@ -3438,6 +3478,8 @@ handler::ha_delete_all_rows()
int
handler::ha_truncate()
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return truncate();
@@ -3453,6 +3495,8 @@ handler::ha_truncate()
int
handler::ha_reset_auto_increment(ulonglong value)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return reset_auto_increment(value);
@@ -3468,6 +3512,8 @@ handler::ha_reset_auto_increment(ulonglo
int
handler::ha_optimize(THD* thd, HA_CHECK_OPT* check_opt)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return optimize(thd, check_opt);
@@ -3483,6 +3529,8 @@ handler::ha_optimize(THD* thd, HA_CHECK_
int
handler::ha_analyze(THD* thd, HA_CHECK_OPT* check_opt)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
mark_trx_read_write();
return analyze(thd, check_opt);
@@ -3498,6 +3546,8 @@ handler::ha_analyze(THD* thd, HA_CHECK_O
bool
handler::ha_check_and_repair(THD *thd)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_UNLCK);
mark_trx_read_write();
return check_and_repair(thd);
@@ -3513,6 +3563,8 @@ handler::ha_check_and_repair(THD *thd)
int
handler::ha_disable_indexes(uint mode)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
mark_trx_read_write();
return disable_indexes(mode);
@@ -3528,6 +3580,8 @@ handler::ha_disable_indexes(uint mode)
int
handler::ha_enable_indexes(uint mode)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
mark_trx_read_write();
return enable_indexes(mode);
@@ -3543,6 +3597,8 @@ handler::ha_enable_indexes(uint mode)
int
handler::ha_discard_or_import_tablespace(my_bool discard)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return discard_or_import_tablespace(discard);
@@ -3560,6 +3616,8 @@ handler::ha_discard_or_import_tablespace
void
handler::ha_prepare_for_alter()
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type != F_UNLCK);
mark_trx_read_write();
prepare_for_alter();
@@ -3575,6 +3633,7 @@ handler::ha_prepare_for_alter()
int
handler::ha_rename_table(const char *from, const char *to)
{
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
mark_trx_read_write();
return rename_table(from, to);
@@ -3590,6 +3649,7 @@ handler::ha_rename_table(const char *fro
int
handler::ha_delete_table(const char *name)
{
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
mark_trx_read_write();
return delete_table(name);
@@ -3605,6 +3665,7 @@ handler::ha_delete_table(const char *nam
void
handler::ha_drop_table(const char *name)
{
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
mark_trx_read_write();
return drop_table(name);
@@ -3620,6 +3681,7 @@ handler::ha_drop_table(const char *name)
int
handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info)
{
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
mark_trx_read_write();
return create(name, form, info);
@@ -3636,6 +3698,7 @@ int
handler::ha_create_handler_files(const char *name, const char *old_name,
int action_flag, HA_CREATE_INFO *info)
{
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
mark_trx_read_write();
return create_handler_files(name, old_name, action_flag, info);
@@ -3656,6 +3719,8 @@ handler::ha_change_partitions(HA_CREATE_
const uchar *pack_frm_data,
size_t pack_frm_len)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return change_partitions(create_info, path, copied, deleted,
@@ -3672,6 +3737,8 @@ handler::ha_change_partitions(HA_CREATE_
int
handler::ha_drop_partitions(const char *path)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return drop_partitions(path);
@@ -3687,6 +3754,8 @@ handler::ha_drop_partitions(const char *
int
handler::ha_rename_partitions(const char *path)
{
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
mark_trx_read_write();
return rename_partitions(path);
@@ -5761,6 +5830,11 @@ int handler::ha_external_lock(THD *thd,
taken a table lock), ha_release_auto_increment() was too.
*/
DBUG_ASSERT(next_insert_id == 0);
+ /* Consecutive calls for lock without unlocking in between is not allowed */
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ ((lock_type != F_UNLCK && m_lock_type == F_UNLCK) ||
+ lock_type == F_UNLCK));
+
if (MYSQL_HANDLER_RDLOCK_START_ENABLED() ||
MYSQL_HANDLER_WRLOCK_START_ENABLED() ||
@@ -5783,8 +5857,10 @@ int handler::ha_external_lock(THD *thd,
}
}
+ ha_statistic_increment(&SSV::ha_external_lock_count);
MYSQL_START_TABLE_LOCK_WAIT(locker, &state, m_psi,
PSI_TABLE_EXTERNAL_LOCK, lock_type);
+
/*
We cache the table flags if the locking succeeded. Otherwise, we
keep them as they were when they were fetched in ha_open().
@@ -5827,6 +5903,8 @@ int handler::ha_external_lock(THD *thd,
/** @brief
Check handler usage and reset state of file to after 'open'
+
+ @note can be called regardless of it is locked or not.
*/
int handler::ha_reset()
{
@@ -5859,6 +5937,8 @@ int handler::ha_write_row(uchar *buf)
{
int error;
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
DBUG_ENTER("handler::ha_write_row");
@@ -5884,6 +5964,8 @@ int handler::ha_write_row(uchar *buf)
int handler::ha_update_row(const uchar *old_data, uchar *new_data)
{
int error;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
Log_func *log_func= Update_rows_log_event::binlog_row_logging_function;
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
@@ -5913,6 +5995,8 @@ int handler::ha_update_row(const uchar *
int handler::ha_delete_row(const uchar *buf)
{
int error;
+ DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+ m_lock_type == F_WRLCK);
Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
MYSQL_TABLE_WAIT_VARIABLES(locker, state) /* no ';' */
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2011-01-10 09:04:20 +0000
+++ b/sql/handler.h 2011-01-26 15:48:12 +0000
@@ -1442,7 +1442,6 @@ public:
uint ref_length;
FT_INFO *ft_handler;
enum {NONE=0, INDEX, RND} inited;
- bool locked;
bool implicit_emptied; /* Can be !=0 only if HEAP */
const Item *pushed_cond;
@@ -1511,15 +1510,19 @@ public:
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
ref_length(sizeof(my_off_t)),
ft_handler(0), inited(NONE),
- locked(FALSE), implicit_emptied(0),
+ implicit_emptied(0),
pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
next_insert_id(0), insert_id_for_cur_row(0),
auto_inc_intervals_count(0),
m_psi(NULL), m_lock_type(F_UNLCK)
- {}
+ {
+ DBUG_PRINT("info",
+ ("handler created F_UNLCK %d F_RDLCK %d F_WRLCK %d",
+ F_UNLCK, F_RDLCK, F_UNLCK));
+ }
virtual ~handler(void)
{
- DBUG_ASSERT(locked == FALSE);
+ DBUG_ASSERT(m_lock_type == F_UNLCK);
DBUG_ASSERT(inited == NONE);
}
virtual handler *clone(MEM_ROOT *mem_root);
@@ -1860,6 +1863,7 @@ public:
*/
virtual int rnd_pos_by_record(uchar *record)
{
+ DBUG_ASSERT(table_flags() & HA_PRIMARY_KEY_REQUIRED_FOR_POSITION);
position(record);
return ha_rnd_pos(record, ref);
}
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2011-01-17 09:52:59 +0000
+++ b/sql/mysqld.cc 2011-01-26 15:48:12 +0000
@@ -6669,6 +6669,7 @@ SHOW_VAR status_vars[]= {
{"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
{"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
{"Handler_discover", (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS},
+ {"Handler_external_lock", (char*) offsetof(STATUS_VAR, ha_external_lock_count), SHOW_LONG_STATUS},
{"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS},
{"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS},
{"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS},
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc 2010-12-29 00:38:59 +0000
+++ b/sql/opt_range.cc 2011-01-26 15:48:12 +0000
@@ -2660,7 +2660,7 @@ static void dbug_print_singlepoint_range
This function assumes that all partitions are marked as unused when it
is invoked. The function analyzes the condition, finds partitions that
need to be used to retrieve the records that match the condition, and
- marks them as used by setting appropriate bit in part_info->used_partitions
+ marks them as used by setting appropriate bit in part_info->read_partitions
In the worst case all partitions are marked as used.
NOTE
@@ -2721,7 +2721,7 @@ bool prune_partitions(THD *thd, TABLE *t
thd->no_errors=1; // Don't warn about NULL
thd->mem_root=&alloc;
- bitmap_clear_all(&part_info->used_partitions);
+ bitmap_clear_all(&part_info->read_partitions);
prune_param.key= prune_param.range_param.key_parts;
SEL_TREE *tree;
@@ -2804,6 +2804,11 @@ end:
thd->no_errors=0;
thd->mem_root= range_par->old_root;
free_root(&alloc,MYF(0)); // Return memory & allocator
+ /* Must be a subset of the locked partitions */
+ bitmap_intersect(&(prune_param.part_info->read_partitions),
+ &(prune_param.part_info->lock_partitions));
+ if (bitmap_is_clear_all(&(prune_param.part_info->read_partitions)))
+ retval= TRUE;
DBUG_RETURN(retval);
}
@@ -2879,7 +2884,7 @@ static void mark_full_partition_used_no_
{
DBUG_ENTER("mark_full_partition_used_no_parts");
DBUG_PRINT("enter", ("Mark partition %u as used", part_id));
- bitmap_set_bit(&part_info->used_partitions, part_id);
+ bitmap_set_bit(&part_info->read_partitions, part_id);
DBUG_VOID_RETURN;
}
@@ -2895,7 +2900,7 @@ static void mark_full_partition_used_wit
for (; start != end; start++)
{
DBUG_PRINT("info", ("1:Mark subpartition %u as used", start));
- bitmap_set_bit(&part_info->used_partitions, start);
+ bitmap_set_bit(&part_info->read_partitions, start);
}
DBUG_VOID_RETURN;
}
@@ -2923,7 +2928,7 @@ static int find_used_partitions_imerge_l
MY_BITMAP all_merges;
uint bitmap_bytes;
my_bitmap_map *bitmap_buf;
- uint n_bits= ppar->part_info->used_partitions.n_bits;
+ uint n_bits= ppar->part_info->read_partitions.n_bits;
bitmap_bytes= bitmap_buffer_size(n_bits);
if (!(bitmap_buf= (my_bitmap_map*) alloc_root(ppar->range_param.mem_root,
bitmap_bytes)))
@@ -2949,14 +2954,14 @@ static int find_used_partitions_imerge_l
}
if (res != -1)
- bitmap_intersect(&all_merges, &ppar->part_info->used_partitions);
+ bitmap_intersect(&all_merges, &ppar->part_info->read_partitions);
if (bitmap_is_clear_all(&all_merges))
return 0;
- bitmap_clear_all(&ppar->part_info->used_partitions);
+ bitmap_clear_all(&ppar->part_info->read_partitions);
}
- memcpy(ppar->part_info->used_partitions.bitmap, all_merges.bitmap,
+ memcpy(ppar->part_info->read_partitions.bitmap, all_merges.bitmap,
bitmap_bytes);
return 1;
}
@@ -3315,7 +3320,7 @@ int find_used_partitions(PART_PRUNE_PARA
{
for (uint i= 0; i < ppar->part_info->num_subparts; i++)
if (bitmap_is_set(&ppar->subparts_bitmap, i))
- bitmap_set_bit(&ppar->part_info->used_partitions,
+ bitmap_set_bit(&ppar->part_info->read_partitions,
part_id * ppar->part_info->num_subparts + i);
}
goto pop_and_go_right;
@@ -3377,7 +3382,7 @@ int find_used_partitions(PART_PRUNE_PARA
while ((part_id= ppar->part_iter.get_next(&ppar->part_iter)) !=
NOT_A_PARTITION_ID)
{
- bitmap_set_bit(&part_info->used_partitions,
+ bitmap_set_bit(&part_info->read_partitions,
part_id * part_info->num_subparts + subpart_id);
}
res= 1; /* Some partitions were marked as used */
@@ -3456,7 +3461,8 @@ pop_and_go_right:
static void mark_all_partitions_as_used(partition_info *part_info)
{
- bitmap_set_all(&part_info->used_partitions);
+ bitmap_copy(&(part_info->read_partitions),
+ &(part_info->lock_partitions));
}
=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc 2010-11-29 16:27:58 +0000
+++ b/sql/partition_info.cc 2011-01-25 20:26:00 +0000
@@ -27,6 +27,8 @@
#include "partition_info.h"
#include "sql_parse.h" // test_if_data_home_dir
#include "sql_acl.h" // *_ACL
+#include "table.h" // TABLE_LIST
+#include "my_bitmap.h" // bitmap*
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
@@ -34,17 +36,21 @@
partition_info *partition_info::get_clone()
{
+ DBUG_ENTER("partition_info::get_clone");
if (!this)
- return 0;
+ DBUG_RETURN(NULL);
List_iterator<partition_element> part_it(partitions);
partition_element *part;
partition_info *clone= new partition_info();
if (!clone)
{
mem_alloc_error(sizeof(partition_info));
- return NULL;
+ DBUG_RETURN(NULL);
}
memcpy(clone, this, sizeof(partition_info));
+ memset(&(clone->read_partitions), 0, sizeof(clone->read_partitions));
+ memset(&(clone->lock_partitions), 0, sizeof(clone->lock_partitions));
+ clone->bitmaps_are_initialized= FALSE;
clone->partitions.empty();
while ((part= (part_it++)))
@@ -55,7 +61,7 @@ partition_info *partition_info::get_clon
if (!part_clone)
{
mem_alloc_error(sizeof(partition_element));
- return NULL;
+ DBUG_RETURN(NULL);
}
memcpy(part_clone, part, sizeof(partition_element));
part_clone->subpartitions.empty();
@@ -65,16 +71,131 @@ partition_info *partition_info::get_clon
if (!subpart_clone)
{
mem_alloc_error(sizeof(partition_element));
- return NULL;
+ DBUG_RETURN(NULL);
}
memcpy(subpart_clone, subpart, sizeof(partition_element));
part_clone->subpartitions.push_back(subpart_clone);
}
clone->partitions.push_back(part_clone);
}
- return clone;
+ DBUG_RETURN(clone);
}
+
+/**
+ Prune away partitions not mentioned in the PARTITION () clause,
+ if used.
+
+ @param table_list Table list pointing to table to prune.
+
+ @return Operation status
+ @retval true Failure
+ @retval false Success
+*/
+bool partition_info::prune_partition_bitmaps(TABLE_LIST *table_list)
+{
+ List_iterator<String> partition_names_it(*(table_list->partition_names));
+ uint num_names= table_list->partition_names->elements;
+ uint i= 0;
+ HASH *part_name_hash;
+ DBUG_ENTER("partition_info::prune_partition_bitmaps");
+
+ DBUG_ASSERT(table && table->s && table->s->ha_part_data);
+ part_name_hash= &table->s->ha_part_data->partition_name_hash;
+ DBUG_ASSERT(part_name_hash->records);
+ if (num_names < 1)
+ DBUG_RETURN(true);
+
+ /*
+ TODO: When adding support for FK in partitioned tables, the referenced
+ table must probably lock all partitions for read, and also write depending
+ of ON DELETE/UPDATE.
+ */
+ bitmap_clear_all(&read_partitions);
+
+ /* No check for duplicate names or overlapping partitions/subpartitions. */
+
+ DBUG_PRINT("info", ("Searching through partition_name_hash"));
+ do
+ {
+ String *part_name_str= partition_names_it++;
+ const char *part_name= part_name_str->c_ptr_safe();
+ PART_NAME_DEF *part_def;
+ part_def= (PART_NAME_DEF*) my_hash_search(part_name_hash,
+ (const uchar*) part_name,
+ strlen(part_name));
+ if (!part_def)
+ {
+ my_error(ER_NO_SUCH_PARTITION, MYF(0), part_name);
+ DBUG_RETURN(true);
+ }
+
+ if (part_def->is_subpart)
+ {
+ bitmap_set_bit(&read_partitions, part_def->part_id);
+ }
+ else
+ {
+ if (is_sub_partitioned())
+ {
+ /* Mark all subpartitions in the partition */
+ uint j, start= part_def->part_id;
+ uint end= start + num_subparts;
+ for (j= start; j < end; j++)
+ bitmap_set_bit(&read_partitions, j);
+ }
+ else
+ bitmap_set_bit(&read_partitions, part_def->part_id);
+ }
+
+ DBUG_PRINT("info", ("Found partition %u is_subpart %d for name %s",
+ part_def->part_id, part_def->is_subpart,
+ part_name));
+ } while (++i < num_names);
+ DBUG_RETURN(false);
+}
+
+
+/**
+ Set read/lock_partitions bitmap over non pruned partitions
+
+ @param table_list Possible TABLE_LIST which can contain
+ list of partition names to query
+
+ @return Operation status
+ @retval FALSE OK
+ @retval TRUE Failed to allocate memory for bitmap or list of partitions
+ did not match
+
+ @note OK to call multiple times without the need for free_bitmaps.
+*/
+
+bool partition_info::set_partition_bitmaps(TABLE_LIST *table_list)
+{
+ DBUG_ENTER("partition_info::set_partition_bitmaps");
+
+ DBUG_ASSERT(bitmaps_are_initialized);
+ DBUG_ASSERT(table);
+ if (!bitmaps_are_initialized)
+ DBUG_RETURN(TRUE);
+
+ if (table_list &&
+ table_list->partition_names &&
+ table_list->partition_names->elements)
+ {
+ if (prune_partition_bitmaps(table_list))
+ DBUG_RETURN(TRUE);
+ }
+ else
+ {
+ bitmap_set_all(&read_partitions);
+ DBUG_PRINT("info", ("Set all partitions"));
+ }
+ bitmap_copy(&lock_partitions, &read_partitions);
+ DBUG_RETURN(FALSE);
+}
+
+
/*
Create a memory area where default partition names are stored and fill it
up with the names.
@@ -420,47 +541,6 @@ char* partition_info::has_unique_fields(
DBUG_RETURN(NULL);
}
-/*
- A support function to check if a partition element's name is unique
-
- SYNOPSIS
- has_unique_name()
- partition_element element to check
-
- RETURN VALUES
- TRUE Has unique name
- FALSE Doesn't
-*/
-
-bool partition_info::has_unique_name(partition_element *element)
-{
- DBUG_ENTER("partition_info::has_unique_name");
-
- const char *name_to_check= element->partition_name;
- List_iterator<partition_element> parts_it(partitions);
-
- partition_element *el;
- while ((el= (parts_it++)))
- {
- if (!(my_strcasecmp(system_charset_info, el->partition_name,
- name_to_check)) && el != element)
- DBUG_RETURN(FALSE);
-
- if (!el->subpartitions.is_empty())
- {
- partition_element *sub_el;
- List_iterator<partition_element> subparts_it(el->subpartitions);
- while ((sub_el= (subparts_it++)))
- {
- if (!(my_strcasecmp(system_charset_info, sub_el->partition_name,
- name_to_check)) && sub_el != element)
- DBUG_RETURN(FALSE);
- }
- }
- }
- DBUG_RETURN(TRUE);
-}
-
/**
@brief Get part_elem and part_id from partition name
@@ -528,6 +608,17 @@ partition_element *partition_info::get_p
}
+/**
+ Helper function to has_unique_names.
+*/
+
+static const char *get_part_name_from_elem(const char *name, size_t *length,
+ my_bool not_used __attribute__((unused)))
+{
+ *length= strlen(name);
+ return name;
+}
+
/*
A support function to check partition names for duplication in a
partitioned table
@@ -536,8 +627,8 @@ partition_element *partition_info::get_p
has_unique_names()
RETURN VALUES
- TRUE Has unique part and subpart names
- FALSE Doesn't
+ NULL Has unique part and subpart names
+ !NULL Pointer to duplicated name
DESCRIPTION
Checks that the list of names in the partitions doesn't contain any
@@ -546,28 +637,55 @@ partition_element *partition_info::get_p
char *partition_info::has_unique_names()
{
+ HASH partition_names;
+ uint max_names;
+ const uchar *curr_name= NULL;
+ size_t length;
+ List_iterator<partition_element> parts_it(partitions);
+ partition_element *p_elem;
+
DBUG_ENTER("partition_info::has_unique_names");
- List_iterator<partition_element> parts_it(partitions);
+ /*
+ TODO: If table->s->ha_part_data->partition_name_hash.elements is > 0,
+ then we could just return NULL, but that has not been verified.
+ And this only happens when in ALTER TABLE with full table copy.
+ */
- partition_element *el;
- while ((el= (parts_it++)))
- {
- if (! has_unique_name(el))
- DBUG_RETURN(el->partition_name);
-
- if (!el->subpartitions.is_empty())
- {
- List_iterator<partition_element> subparts_it(el->subpartitions);
- partition_element *subel;
- while ((subel= (subparts_it++)))
+ max_names= num_parts;
+ if (is_sub_partitioned())
+ max_names+= num_parts * num_subparts;
+ if (my_hash_init(&partition_names, system_charset_info, max_names, 0, 0,
+ (my_hash_get_key) get_part_name_from_elem, 0, HASH_UNIQUE))
+ {
+ DBUG_ASSERT(0);
+ curr_name= (const uchar*) "Internal failure";
+ goto error;
+ }
+ while ((p_elem= (parts_it++)))
+ {
+ curr_name= (const uchar*) p_elem->partition_name;
+ length= strlen(p_elem->partition_name);
+ if (my_hash_insert(&partition_names, curr_name))
+ goto error;
+
+ if (!p_elem->subpartitions.is_empty())
+ {
+ List_iterator<partition_element> subparts_it(p_elem->subpartitions);
+ partition_element *subp_elem;
+ while ((subp_elem= (subparts_it++)))
{
- if (! has_unique_name(subel))
- DBUG_RETURN(subel->partition_name);
+ curr_name= (const uchar*) subp_elem->partition_name;
+ if (my_hash_insert(&partition_names, curr_name))
+ goto error;
}
}
}
+ my_hash_free(&partition_names);
DBUG_RETURN(NULL);
+error:
+ my_hash_free(&partition_names);
+ DBUG_RETURN((char*) curr_name);
}
=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h 2010-10-21 09:49:16 +0000
+++ b/sql/partition_info.h 2010-12-14 15:13:57 +0000
@@ -23,6 +23,7 @@
#include "partition_element.h"
class partition_info;
+struct TABLE_LIST;
/* Some function typedefs */
typedef int (*get_part_id_func)(partition_info *part_info,
@@ -44,6 +45,8 @@ public:
List<char> part_field_list;
List<char> subpart_field_list;
+
+ TABLE *table;
/*
If there is no subpartitioning, use only this func to get partition ids.
@@ -111,14 +114,30 @@ public:
struct st_ddl_log_memory_entry *frm_log_entry;
/*
- A bitmap of partitions used by the current query.
+ Bitmaps of partitions used by the current query.
+ * read_partitions - partitions to be used for reading.
+ * lock_partitions - partitions that must be locked (read or write).
+ Usually read_partitions is the same set as lock_partitions, but
+ in case of UPDATE the WHERE clause can limit the read_partitions set,
+ but not neccesarily the lock_partitions set.
Usage pattern:
- * The handler->extra(HA_EXTRA_RESET) call at query start/end sets all
- partitions to be unused.
- * Before index/rnd_init(), partition pruning code sets the bits for used
- partitions.
- */
- MY_BITMAP used_partitions;
+ * Initialized in ha_partition::open().
+ * read+lock_partitions is set according to explicit PARTITION,
+ WL#5217, in open_and_lock_tables().
+ * Bits in read_partitions can be cleared in prune_partitions()
+ in the optimizing step.
+ (WL#4443 is about allowing prune_partitions() to affect lock_partitions
+ and be done before locking too).
+ * When the partition enabled handler get an external_lock call it locks
+ all partitions in lock_partitions (and remembers which partitions it
+ locked, so that it can unlock them later). In case of LOCK TABLES it will
+ lock all partitions, and keep them locked while lock_partitions can
+ change for each statement under LOCK TABLES.
+ * Freed at the same time item_free_list is freed.
+ */
+ MY_BITMAP read_partitions;
+ MY_BITMAP lock_partitions;
+ bool bitmaps_are_initialized;
union {
longlong *range_int_array;
@@ -209,7 +228,7 @@ public:
bool column_list;
partition_info()
- : get_partition_id(NULL), get_part_partition_id(NULL),
+ : table(NULL), get_partition_id(NULL), get_part_partition_id(NULL),
get_subpartition_id(NULL),
part_field_array(NULL), subpart_field_array(NULL),
part_charset_field_array(NULL),
@@ -219,6 +238,7 @@ public:
restore_part_field_ptrs(NULL), restore_subpart_field_ptrs(NULL),
part_expr(NULL), subpart_expr(NULL), item_free_list(NULL),
first_log_entry(NULL), exec_log_entry(NULL), frm_log_entry(NULL),
+ bitmaps_are_initialized(FALSE),
list_array(NULL), err_value(0),
part_info_string(NULL),
part_func_string(NULL), subpart_func_string(NULL),
@@ -248,6 +268,7 @@ public:
~partition_info() {}
partition_info *get_clone();
+ bool set_partition_bitmaps(TABLE_LIST *table_list);
/* Answers the question if subpartitioning is used for a certain table */
bool is_sub_partitioned()
{
@@ -306,7 +327,7 @@ private:
uint start_no);
char *create_default_subpartition_name(uint subpart_no,
const char *part_name);
- bool has_unique_name(partition_element *element);
+ bool prune_partition_bitmaps(TABLE_LIST *table_list);
};
uint32 get_next_partition_id_range(struct st_partition_iter* part_iter);
=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt 2010-12-05 22:51:49 +0000
+++ b/sql/share/errmsg-utf8.txt 2011-01-26 15:48:12 +0000
@@ -6418,8 +6418,8 @@ ER_TABLES_DIFFERENT_METADATA
eng "Tables have different definitions"
swe "Tabellerna har olika definitioner"
ER_ROW_DOES_NOT_MATCH_PARTITION
- eng "Found row that does not match the partition"
- swe "Hittade rad som inte passar i partitionen"
+ eng "Found a row that does not match the partition"
+ swe "Hittade en rad som inte passar i partitionen"
ER_BINLOG_CACHE_SIZE_GREATER_THAN_MAX
eng "Option binlog_cache_size (%lu) is greater than max_binlog_cache_size (%lu); setting binlog_cache_size equal to max_binlog_cache_size."
ER_WARN_INDEX_NOT_APPLICABLE
@@ -6454,3 +6454,28 @@ ER_STMT_CACHE_FULL
eng "Multi-row statements required more than 'max_binlog_stmt_cache_size' bytes of storage; increase this mysqld variable and try again"
ER_BINLOG_STMT_CACHE_SIZE_GREATER_THAN_MAX
eng "Option binlog_stmt_cache_size (%lu) is greater than max_binlog_stmt_cache_size (%lu); setting binlog_stmt_cache_size equal to max_binlog_stmt_cache_size."
+ER_PARTITION_CLAUSE_ON_NONPARTITIONED
+ eng "PARTITION () clause on non partitioned table"
+ swe "PARTITION () klausul för en icke partitionerad tabell"
+ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+ eng "Found a row not matching the given partition set"
+ swe "Hittade en rad som inte passar i någon given partition"
+ER_NO_SUCH_PARTITION
+ cze "partion '%-.64s' neexistuje"
+ dan "partition '%-.64s' eksisterer ikke"
+ nla "partition '%-.64s' bestaat niet"
+ eng "partition '%-.64s' doesn't exist"
+ est "partition '%-.64s' ei eksisteeri"
+ fre "La partition '%-.64s' n'existe pas"
+ ger "Die partition '%-.64s' existiert nicht"
+ hun "A '%-.64s' partition nem letezik"
+ ita "La tabella particione '%-.64s' non esiste"
+ nor "Partition '%-.64s' doesn't exist"
+ norwegian-ny "Partition '%-.64s' doesn't exist"
+ pol "Partition '%-.64s' doesn't exist"
+ por "Particion '%-.64s' n�o existe"
+ rum "Partition '%-.64s' nu exista"
+ serbian "Partition '%-.64s' ne postoji"
+ slo "Partition '%-.64s' doesn't exist"
+ spa "Particion '%-.64s' no existe"
+ swe "Det finns ingen partition som heter '%-.64s'"
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2011-01-11 11:45:02 +0000
+++ b/sql/sql_base.cc 2011-01-26 15:48:12 +0000
@@ -4670,6 +4670,47 @@ open_tables_check_upgradable_mdl(THD *th
}
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+/*
+ TODO: When adding support for FK in partitioned tables, update this function
+ so the referenced table get correct locking.
+*/
+static bool prune_partition_locks(TABLE_LIST *tables)
+{
+ TABLE_LIST *table;
+ DBUG_ENTER("prune_partition_locks");
+ for (table= tables; table; table= table->next_global)
+ {
+ /* Avoid to lock/start_stmt partitions not used in the statement. */
+ if (!table->placeholder())
+ {
+ if (table->table->part_info)
+ {
+ /*
+ Initialize and set partitions bitmaps, using table's mem_root,
+ destroyed in closefrm().
+ */
+ if (table->table->part_info->set_partition_bitmaps(table))
+ DBUG_RETURN(TRUE);
+ /*
+ TODO: Add prune_partitions() here as WL#4443.
+ Needs all items and conds fixed (as in first part in JOIN::optimize,
+ mysql_prepare_delete).
+ */
+ }
+ else if (table->partition_names && table->partition_names->elements)
+ {
+ /* Don't allow PARTITION () clause on a nonpartitioned table */
+ my_error(ER_PARTITION_CLAUSE_ON_NONPARTITIONED, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+#endif /* WITH_PARTITION_STORAGE_ENGINE */
+
+
/**
Open all tables in list
@@ -4931,6 +4972,15 @@ restart:
}
}
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+ /* Prune partitions to avoid unneccesary locks */
+ if (prune_partition_locks(*start))
+ {
+ error= TRUE;
+ goto err;
+ }
+#endif
+
err:
thd_proc_info(thd, 0);
free_root(&new_frm_mem, MYF(0)); // Free pre-alloced block
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2010-12-29 00:38:59 +0000
+++ b/sql/sql_class.h 2011-01-26 15:48:12 +0000
@@ -553,6 +553,7 @@ typedef struct system_status_var
ulong ha_discover_count;
ulong ha_savepoint_count;
ulong ha_savepoint_rollback_count;
+ ulong ha_external_lock_count;
/* KEY_CACHE parts. These are copies of the original */
ulong key_blocks_changed;
=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc 2011-01-15 05:56:24 +0000
+++ b/sql/sql_lex.cc 2011-01-26 15:48:12 +0000
@@ -2013,12 +2013,13 @@ bool st_select_lex_node::inc_in_sum_expr
uint st_select_lex_node::get_in_sum_expr() { return 0; }
TABLE_LIST* st_select_lex_node::get_table_list() { return 0; }
List<Item>* st_select_lex_node::get_item_list() { return 0; }
-TABLE_LIST *st_select_lex_node::add_table_to_list (THD *thd, Table_ident *table,
+TABLE_LIST *st_select_lex_node::add_table_to_list(THD *thd, Table_ident *table,
LEX_STRING *alias,
ulong table_join_options,
thr_lock_type flags,
enum_mdl_type mdl_type,
List<Index_hint> *hints,
+ List<String> *partition_names,
LEX_STRING *option)
{
return 0;
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2011-01-15 05:56:24 +0000
+++ b/sql/sql_lex.h 2011-01-26 15:48:12 +0000
@@ -481,6 +481,7 @@ public:
thr_lock_type flags= TL_UNLOCK,
enum_mdl_type mdl_type= MDL_SHARED_READ,
List<Index_hint> *hints= 0,
+ List<String> *partition_names= 0,
LEX_STRING *option= 0);
virtual void set_lock_for_tables(thr_lock_type lock_type) {}
@@ -792,6 +793,7 @@ public:
thr_lock_type flags= TL_UNLOCK,
enum_mdl_type mdl_type= MDL_SHARED_READ,
List<Index_hint> *hints= 0,
+ List<String> *partition_names= 0,
LEX_STRING *option= 0);
TABLE_LIST* get_table_list();
bool init_nested_join(THD *thd);
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2011-01-15 05:56:24 +0000
+++ b/sql/sql_parse.cc 2011-01-26 15:48:12 +0000
@@ -5775,6 +5775,7 @@ TABLE_LIST *st_select_lex::add_table_to_
thr_lock_type lock_type,
enum_mdl_type mdl_type,
List<Index_hint> *index_hints_arg,
+ List<String> *partition_names,
LEX_STRING *option)
{
register TABLE_LIST *ptr;
@@ -5919,6 +5920,9 @@ TABLE_LIST *st_select_lex::add_table_to_
*/
table_list.link_in_list(ptr, &ptr->next_local);
ptr->next_name_resolution_table= NULL;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+ ptr->partition_names= partition_names;
+#endif /* WITH_PARTITION_STORAGE_ENGINE */
/* Link table in global list (all used tables) */
lex->add_to_query_tables(ptr);
ptr->mdl_request.init(MDL_key::TABLE, ptr->db, ptr->table_name, mdl_type,
=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc 2011-01-10 16:37:47 +0000
+++ b/sql/sql_partition.cc 2011-01-26 15:48:12 +0000
@@ -1321,39 +1321,44 @@ void check_range_capable_PF(TABLE *table
}
-/*
- Set up partition bitmap
+/**
+ Set up partition bitmaps
- SYNOPSIS
- set_up_partition_bitmap()
- thd Thread object
- part_info Reference to partitioning data structure
+ @param thd Thread object
+ @param part_info Reference to partitioning data structure
- RETURN VALUE
- TRUE Memory allocation failure
- FALSE Success
+ @return Operation status
+ @retval TRUE Memory allocation failure
+ @retval FALSE Success
- DESCRIPTION
- Allocate memory for bitmap of the partitioned table
+ Allocate memory for bitmaps of the partitioned table
and initialise it.
*/
-static bool set_up_partition_bitmap(THD *thd, partition_info *part_info)
+static bool set_up_partition_bitmaps(THD *thd, partition_info *part_info)
{
uint32 *bitmap_buf;
uint bitmap_bits= part_info->num_subparts?
(part_info->num_subparts* part_info->num_parts):
part_info->num_parts;
uint bitmap_bytes= bitmap_buffer_size(bitmap_bits);
- DBUG_ENTER("set_up_partition_bitmap");
+ DBUG_ENTER("set_up_partition_bitmaps");
+
+ DBUG_ASSERT(!part_info->bitmaps_are_initialized);
- if (!(bitmap_buf= (uint32*)thd->alloc(bitmap_bytes)))
+ /* Allocate for both read and lock_partitions */
+ if (!(bitmap_buf= (uint32*) alloc_root(&part_info->table->mem_root,
+ bitmap_bytes * 2)))
{
- mem_alloc_error(bitmap_bytes);
+ mem_alloc_error(bitmap_bytes * 2);
DBUG_RETURN(TRUE);
}
- bitmap_init(&part_info->used_partitions, bitmap_buf, bitmap_bytes*8, FALSE);
- bitmap_set_all(&part_info->used_partitions);
+ bitmap_init(&part_info->read_partitions, bitmap_buf, bitmap_bits, FALSE);
+ /* Use the second half of the allocated buffer for lock_partitions */
+ bitmap_init(&part_info->lock_partitions, bitmap_buf + (bitmap_bytes / 4),
+ bitmap_bits, FALSE);
+ part_info->bitmaps_are_initialized= TRUE;
+ part_info->set_partition_bitmaps(NULL);
DBUG_RETURN(FALSE);
}
@@ -1873,7 +1878,7 @@ bool fix_partition_func(THD *thd, TABLE
(table->s->db_type()->partition_flags() & HA_CAN_PARTITION_UNIQUE))) &&
check_unique_keys(table)))
goto end;
- if (unlikely(set_up_partition_bitmap(thd, part_info)))
+ if (unlikely(set_up_partition_bitmaps(thd, part_info)))
goto end;
if (unlikely(part_info->set_up_charset_field_preps()))
{
@@ -3997,7 +4002,7 @@ err:
DESCRIPTION
This function is called to prune the range of partitions to scan by
- checking the used_partitions bitmap.
+ checking the read_partitions bitmap.
If start_part > end_part at return it means no partition needs to be
scanned. If start_part == end_part it always means a single partition
needs to be scanned.
@@ -4014,7 +4019,7 @@ void prune_partition_set(const TABLE *ta
DBUG_ENTER("prune_partition_set");
for (i= part_spec->start_part; i <= part_spec->end_part; i++)
{
- if (bitmap_is_set(&(part_info->used_partitions), i))
+ if (bitmap_is_set(&(part_info->read_partitions), i))
{
DBUG_PRINT("info", ("Partition %d is set", i));
if (last_partition == -1)
@@ -4096,7 +4101,7 @@ void get_partition_set(const TABLE *tabl
*/
get_full_part_id_from_key(table,buf,key_info,key_spec,part_spec);
/*
- Check if range can be adjusted by looking in used_partitions
+ Check if range can be adjusted by looking in read_partitions
*/
prune_partition_set(table, part_spec);
DBUG_VOID_RETURN;
@@ -4148,7 +4153,7 @@ void get_partition_set(const TABLE *tabl
get_full_part_id_from_key(table,buf,key_info,key_spec,part_spec);
clear_indicator_in_key_fields(key_info);
/*
- Check if range can be adjusted by looking in used_partitions
+ Check if range can be adjusted by looking in read_partitions
*/
prune_partition_set(table, part_spec);
DBUG_VOID_RETURN;
@@ -4218,7 +4223,7 @@ void get_partition_set(const TABLE *tabl
if (found_part_field)
clear_indicator_in_key_fields(key_info);
/*
- Check if range can be adjusted by looking in used_partitions
+ Check if range can be adjusted by looking in read_partitions
*/
prune_partition_set(table, part_spec);
DBUG_VOID_RETURN;
@@ -4367,6 +4372,7 @@ bool mysql_unpack_partition(THD *thd,
}
table->part_info= part_info;
table->file->set_part_info(part_info);
+ part_info->table= table;
if (!part_info->default_engine_type)
part_info->default_engine_type= default_db_type;
DBUG_ASSERT(part_info->default_engine_type == default_db_type);
@@ -7166,20 +7172,19 @@ void mem_alloc_error(size_t size)
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
-/*
- Return comma-separated list of used partitions in the provided given string
+/**
+ Return comma-separated list of used partitions in the provided given string.
- SYNOPSIS
- make_used_partitions_str()
- part_info IN Partitioning info
- parts_str OUT The string to fill
+ @param part_info Partitioning info
+ @param[out] parts_str The string to fill
- DESCRIPTION
- Generate a list of used partitions (from bits in part_info->used_partitions
+ Generate a list of used partitions (from bits in part_info->read_partitions
bitmap), asd store it into the provided String object.
- NOTE
+ @note
The produced string must not be longer then MAX_PARTITIONS * (1 + FN_LEN).
+ In case of UPDATE, only the partitions read is given, not the partitions
+ that was written or locked.
*/
void make_used_partitions_str(partition_info *part_info, String *parts_str)
@@ -7197,7 +7202,7 @@ void make_used_partitions_str(partition_
List_iterator<partition_element> it2(head_pe->subpartitions);
while ((pe= it2++))
{
- if (bitmap_is_set(&part_info->used_partitions, partition_id))
+ if (bitmap_is_set(&part_info->read_partitions, partition_id))
{
if (parts_str->length())
parts_str->append(',');
@@ -7217,7 +7222,7 @@ void make_used_partitions_str(partition_
{
while ((pe= it++))
{
- if (bitmap_is_set(&part_info->used_partitions, partition_id))
+ if (bitmap_is_set(&part_info->read_partitions, partition_id))
{
if (parts_str->length())
parts_str->append(',');
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2011-01-10 12:45:53 +0000
+++ b/sql/sql_yacc.yy 2011-01-26 15:48:12 +0000
@@ -780,10 +780,10 @@ bool my_yyoverflow(short **a, YYSTYPE **
%pure_parser /* We have threads */
/*
- Currently there are 167 shift/reduce conflicts.
+ Currently there are 164 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
-%expect 167
+%expect 164
/*
Comments for TOKENS.
@@ -1171,9 +1171,9 @@ bool my_yyoverflow(short **a, YYSTYPE **
%token PARAM_MARKER
%token PARSER_SYM
%token PARTIAL /* SQL-2003-N */
-%token PARTITIONING_SYM
-%token PARTITIONS_SYM
%token PARTITION_SYM /* SQL-2003-R */
+%token PARTITIONS_SYM
+%token PARTITIONING_SYM
%token PASSWORD
%token PHASE_SYM
%token PLUGINS_SYM
@@ -1507,7 +1507,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
btree_or_rtree
%type <string_list>
- using_list
+ using_list opt_use_partition use_partition
%type <key_part>
key_part
@@ -9411,6 +9411,22 @@ normal_join:
| CROSS JOIN_SYM {}
;
+/*
+ table PARTITION (list of partitions), reusing using_list instead of creating
+ a new rule for partition_list.
+*/
+opt_use_partition:
+ /* empty */ { $$= 0;}
+ | use_partition
+ ;
+
+use_partition:
+ PARTITION_SYM '(' using_list ')' have_partitioning
+ {
+ $$= $3;
+ }
+ ;
+
/*
This is a flattening of the rules <table factor> and <table primary>
in the SQL:2003 standard, since we don't have <sample clause>
@@ -9424,13 +9440,14 @@ table_factor:
SELECT_LEX *sel= Select;
sel->table_join_options= 0;
}
- table_ident opt_table_alias opt_key_definition
+ table_ident opt_use_partition opt_table_alias opt_key_definition
{
- if (!($$= Select->add_table_to_list(YYTHD, $2, $3,
+ if (!($$= Select->add_table_to_list(YYTHD, $2, $4,
Select->get_table_join_options(),
YYPS->m_lock_type,
YYPS->m_mdl_type,
- Select->pop_index_hints())))
+ Select->pop_index_hints(),
+ $3)))
MYSQL_YYABORT;
Select->add_joined_table($$);
}
@@ -9500,7 +9517,7 @@ table_factor:
if (ti == NULL)
MYSQL_YYABORT;
if (!($$= sel->add_table_to_list(lex->thd,
- new Table_ident(unit), $5, 0,
+ ti, $5, 0,
TL_READ, MDL_SHARED_READ)))
MYSQL_YYABORT;
@@ -10488,6 +10505,19 @@ table_name:
}
;
+table_name_with_opt_use_partition:
+ table_ident opt_use_partition
+ {
+ if (!Select->add_table_to_list(YYTHD, $1, NULL,
+ TL_OPTION_UPDATING,
+ YYPS->m_lock_type,
+ YYPS->m_mdl_type,
+ NULL,
+ $2))
+ MYSQL_YYABORT;
+ }
+ ;
+
table_alias_ref_list:
table_alias_ref
| table_alias_ref_list ',' table_alias_ref
@@ -10611,7 +10641,7 @@ insert2:
;
insert_table:
- table_name
+ table_name_with_opt_use_partition
{
LEX *lex=Lex;
lex->field_list.empty();
@@ -10811,11 +10841,13 @@ delete:
;
single_multi:
- FROM table_ident
+ FROM table_ident opt_use_partition
{
if (!Select->add_table_to_list(YYTHD, $2, NULL, TL_OPTION_UPDATING,
YYPS->m_lock_type,
- YYPS->m_mdl_type))
+ YYPS->m_mdl_type,
+ NULL,
+ $3))
MYSQL_YYABORT;
YYPS->m_lock_type= TL_READ_DEFAULT;
YYPS->m_mdl_type= MDL_SHARED_READ;
@@ -11577,18 +11609,18 @@ load:
if (!(lex->exchange= new sql_exchange($7.str, 0, $2)))
MYSQL_YYABORT;
}
- opt_duplicate INTO TABLE_SYM table_ident
+ opt_duplicate INTO TABLE_SYM table_ident opt_use_partition
{
LEX *lex=Lex;
if (!Select->add_table_to_list(YYTHD, $12, NULL, TL_OPTION_UPDATING,
- $4, MDL_SHARED_WRITE))
+ $4, MDL_SHARED_WRITE, NULL, $13))
MYSQL_YYABORT;
lex->field_list.empty();
lex->update_list.empty();
lex->value_list.empty();
}
opt_load_data_charset
- { Lex->exchange->cs= $14; }
+ { Lex->exchange->cs= $15; }
opt_xml_rows_identified_by
opt_field_term opt_line_term opt_ignore_lines opt_field_or_var_spec
opt_load_data_set_spec
@@ -12526,7 +12558,6 @@ keyword:
| OPTIONS_SYM {}
| OWNER_SYM {}
| PARSER_SYM {}
- | PARTITION_SYM {}
| PORT_SYM {}
| PREPARE_SYM {}
| REMOVE_SYM {}
=== modified file 'sql/table.cc'
--- a/sql/table.cc 2011-01-18 10:32:38 +0000
+++ b/sql/table.cc 2011-01-26 15:48:12 +0000
@@ -204,6 +204,17 @@ static uchar *get_field_name(Field **buf
}
+/**
+ A function to return the partition name from a partition element
+*/
+uchar *get_part_name(PART_NAME_DEF *part, size_t *length,
+ my_bool not_used __attribute__((unused)))
+{
+ *length= part->length;
+ return part->partition_name;
+}
+
+
/*
Returns pointer to '.frm' extension of the file name.
@@ -1974,8 +1985,9 @@ int open_table_from_share(THD *thd, TABL
}
outparam->part_info->is_auto_partitioned= share->auto_partitioned;
DBUG_PRINT("info", ("autopartitioned: %u", share->auto_partitioned));
- /* we should perform the fix_partition_func in either local or
- caller's arena depending on work_part_info_used value
+ /*
+ We should perform the fix_partition_func in either local or
+ caller's arena depending on work_part_info_used value.
*/
if (!work_part_info_used)
tmp= fix_partition_func(thd, outparam, is_create_table);
@@ -2126,6 +2138,7 @@ int closefrm(register TABLE *table, bool
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (table->part_info)
{
+ /* Allocated through table->mem_root, freed below */
free_items(table->part_info->item_free_list);
table->part_info->item_free_list= 0;
table->part_info= 0;
=== modified file 'sql/table.h'
--- a/sql/table.h 2010-12-29 00:38:59 +0000
+++ b/sql/table.h 2011-01-26 15:48:12 +0000
@@ -487,6 +487,18 @@ typedef struct st_table_field_def
#ifdef WITH_PARTITION_STORAGE_ENGINE
+/** Struct to be used for partition_name_hash */
+typedef struct st_part_name_def
+{
+ uchar *partition_name;
+ uint length;
+ uint32 part_id;
+ my_bool is_subpart;
+} PART_NAME_DEF;
+
+uchar *get_part_name(PART_NAME_DEF *part, size_t *length,
+ my_bool not_used __attribute__((unused)));
+
/**
Partition specific ha_data struct.
*/
@@ -495,6 +507,11 @@ typedef struct st_ha_data_partition
bool auto_inc_initialized;
mysql_mutex_t LOCK_auto_inc; /**< protecting auto_inc val */
ulonglong next_auto_inc_val; /**< first non reserved value */
+ /**
+ Hash of partition names. Initialized in the first ha_partition::open()
+ for the table_share. After that it is read-only, i.e. no locking required.
+ */
+ HASH partition_name_hash;
} HA_DATA_PARTITION;
#endif
@@ -1711,6 +1728,11 @@ struct TABLE_LIST
MDL_request mdl_request;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+ /* List to carry partition names from PARTITION (...) clause in statement */
+ List<String> *partition_names;
+#endif /* WITH_PARTITION_STORAGE_ENGINE */
+
void calc_md5(char *buffer);
void set_underlying_merge();
int view_check_option(THD *thd, bool ignore_failure);
No bundle (reason: revision is a merge).| Thread |
|---|
| • bzr commit into mysql-trunk branch (mattias.jonsson:3551) WL#5217 | Mattias Jonsson | 26 Jan |