v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` PARTITION (`p0`) latin1 latin1_swedish_ci
FLUSH STATUS;
SELECT * FROM v1;
a
0
2
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_READ_RND_NEXT 3
HANDLER_TMP_WRITE 22
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
SELECT a FROM t1 PARTITION (p0);
a
0
2
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_READ_RND_NEXT 3
HANDLER_TMP_WRITE 22
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
INSERT INTO v1 VALUES (10);
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_TMP_WRITE 22
HANDLER_WRITE 2
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_TMP_WRITE 22
# 2 locks (1 table, all partitions pruned)
FLUSH STATUS;
SELECT * FROM v1;
a
0
10
2
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_READ_RND_NEXT 4
HANDLER_TMP_WRITE 22
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
SELECT a FROM t1 PARTITION (p0);
a
0
10
2
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_READ_RND_NEXT 4
HANDLER_TMP_WRITE 22
# 4 locks (1 table, 1 partition lock/unlock)
SELECT * FROM t1;
a
0
1
10
2
3
DROP VIEW v1;
CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0) WITH CHECK OPTION;
FLUSH STATUS;
INSERT INTO v1 VALUES (20);
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_TMP_WRITE 22
HANDLER_WRITE 2
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_TMP_WRITE 22
# 2 locks (1 table, all partitions pruned)
SELECT * FROM v1;
a
0
10
2
20
SELECT * FROM t1;
a
0
1
10
2
20
3
DROP VIEW v1;
CREATE VIEW v1 AS
SELECT a FROM t1 PARTITION (p0) WHERE a = 30 WITH CHECK OPTION;
FLUSH STATUS;
INSERT INTO v1 VALUES (30);
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_COMMIT 1
HANDLER_TMP_WRITE 22
HANDLER_WRITE 2
# 4 locks (1 table, 1 partition lock/unlock)
FLUSH STATUS;
INSERT INTO v1 VALUES (31);
ERROR HY000: CHECK OPTION failed 'test.v1'
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_ROLLBACK 1
HANDLER_TMP_WRITE 22
# 2 locks (1 table, all partitions pruned)
FLUSH STATUS;
INSERT INTO v1 VALUES (32);
ERROR HY000: CHECK OPTION failed 'test.v1'
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_ROLLBACK 1
HANDLER_TMP_WRITE 22
# 4 locks (1 table, 1 partition lock/unlock)
SELECT * FROM v1;
a
30
SELECT * FROM t1;
a
0
1
10
2
20
3
30
DROP VIEW v1;
DROP TABLE t1;
# 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_TMP_WRITE 22
SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
VARIABLE_NAME VARIABLE_VALUE
HANDLER_READ_RND_NEXT 26
HANDLER_TMP_WRITE 47
# 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 MariaDB 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 MariaDB 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: Unknown partition 'pNonExisting' in table 't1'
INSERT INTO t1 PARTITION (pNeg, pNonExisting) VALUES (1, "error");
ERROR HY000: Unknown partition 'pNonExisting' in table 't1'
# 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;
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 MariaDB 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 MariaDB 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_ROLLBACK 1
HANDLER_TMP_WRITE 22
HANDLER_WRITE 1
# 2 locks (1 ha_partition) x 2 (lock/unlock), Was 4 locks before WL4443
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_READ_FIRST 5
HANDLER_READ_NEXT 7
HANDLER_TMP_WRITE 22
HANDLER_WRITE 7
# 14 locks (2 table, 5 subpartitions lock/unlock)
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
-4 (pNeg-)subp0, Updated, Updated2, Updated from a = -2
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
-4 (pNeg-)subp0, Updated, Updated2, Updated from a = -2
-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 MariaDB 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;
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_READ_RND_NEXT 3
HANDLER_TMP_WRITE 22
# 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 6
HANDLER_READ_FIRST 1
HANDLER_READ_KEY 2
HANDLER_READ_NEXT 2
HANDLER_READ_RND 2
HANDLER_READ_RND_NEXT 16
HANDLER_TMP_WRITE 22
# 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
-4 (pNeg-)subp0, Updated, Updated2, Updated from a = -2
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
-4 (pNeg-)subp0, Updated, Updated2, Updated from a = -2
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 MariaDB 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_TMP_WRITE 22
# 6 locks (lock/unlock two subpartitions + table)
# Test on non partitioned table
SELECT * FROM t3 PARTITION (pNeg);
ERROR HY000: PARTITION () clause on non partitioned table
DROP TABLE t1, t2, t3;
# 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);
ALTER TABLE t1 PARTITION BY HASH (a) PARTITIONS 3;
DELETE FROM t1 PARTITION (p2);
SELECT * FROM t1;
a b
-1 -1
-3 -3
-4 -4
-6 -6
-7 -7
-9 negative nine
31 31
33 33
331 331
333 333
3331 3331
3333 3333
3334 3334
3336 3336
3337 3337
3339 Three thousand three hundred thirty nine
334 334
336 336
337 337
339 Three hundred thirty nine
34 34
36 36
37 37
39 Thirty nine
SELECT * FROM t1 PARTITION (p2);
a b
DROP TABLE t1;
#
# Test explicit partition selection on a non partitioned temp table
#
CREATE TEMPORARY TABLE t1 (a INT);
SELECT * FROM t1 PARTITION(pNonexisting);
ERROR HY000: PARTITION () clause on non partitioned table
DROP TEMPORARY TABLE t1;
#
# Test CREATE LIKE does not take PARTITION clause
#
CREATE TABLE t1 (a INT) PARTITION BY HASH (a) PARTITIONS 3;
CREATE TABLE t2 LIKE t1 PARTITION (p0, p2);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'PARTITION (p0, p2)' at line 1
DROP TABLE t1;
SET @@default_storage_engine = @old_default_storage_engine;