List:Commits« Previous MessageNext Message »
From:Mattias Jonsson Date:January 5 2012 12:41am
Subject:bzr push into mysql-trunk branch (mattias.jonsson:3700 to 3702) WL#4443
View as plain text  
 3702 Mattias Jonsson	2012-01-05
      WL#4443
      
      sql_lex.cc:
      Added fix for bug#13559657
      (explicit partiton selection not included in views)
      
      sql_update.cc:
      removed derived handling (cleanup)
      
      sql_view.cc:
      added delayed locking to be able to prune locks during create.

    modified:
      mysql-test/r/partition_explicit_prune.result
      mysql-test/r/partition_locking.result
      mysql-test/t/partition_explicit_prune.test
      mysql-test/t/partition_locking.test
      sql/sql_lex.cc
      sql/sql_update.cc
      sql/sql_view.cc
 3701 Mattias Jonsson	2012-01-04
      WL#4443
      
      Added test for TRUNCATE PARTITION
      
      Removed estimated rows for EXPLAIN DELETE on secondary
      index, due to unstable results.

    modified:
      mysql-test/r/partition_locking.result
      mysql-test/t/partition_locking.test
 3700 Mattias Jonsson	2012-01-03
      WL#4443
      
      Added handling of insert/update with triggers.
      
      Cannot prune INSERT/REPLACE when having BEFORE INSERT trigger.
      
      Cannot prune UPDATE(locks)/INSERT ON DUPLICATE KEY UPDATE
      when having BEFORE UPDATE trigger.

    modified:
      mysql-test/include/commit.inc
      mysql-test/r/commit_1innodb.result
      mysql-test/r/explain.result
      mysql-test/r/partition_locking.result
      mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result
      mysql-test/t/explain.test
      mysql-test/t/partition_locking.test
      sql/sql_insert.cc
      sql/sql_update.cc
=== modified file 'mysql-test/r/partition_explicit_prune.result'
--- a/mysql-test/r/partition_explicit_prune.result	revid:mattias.jonsson@stripped
+++ b/mysql-test/r/partition_explicit_prune.result	revid:mattias.jonsson@stripped
@@ -929,12 +929,54 @@ HANDLER_WRITE	71
 # + 9 locks
 # Test multi-table DELETE
 # Can be expressed in two different ways.
-FLUSH STATUS;
 CREATE TABLE t2 LIKE t1;
+FLUSH STATUS;
+INSERT INTO t2 PARTITION (`p10-99`, subp3, `p100-99999`) 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	24
+HANDLER_READ_FIRST	5
+HANDLER_READ_KEY	5
+HANDLER_READ_NEXT	5
+HANDLER_WRITE	22
+# 24 locks (2 table, 5 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+ALTER TABLE t2 TRUNCATE PARTITION `p10-99`, `p0-9`, `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_WRITE	17
+# 14 locks (1 table, 6 subpartitions lock/unlock)
+FLUSH STATUS;
+INSERT INTO t2 PARTITION (subp3) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+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	16
+HANDLER_READ_FIRST	2
+HANDLER_READ_KEY	2
+HANDLER_READ_NEXT	2
+HANDLER_ROLLBACK	1
+HANDLER_WRITE	19
+# 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+INSERT IGNORE INTO t2 PARTITION (subp3) 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	16
+HANDLER_READ_FIRST	5
+HANDLER_READ_KEY	5
+HANDLER_READ_NEXT	5
+HANDLER_WRITE	19
+# 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+TRUNCATE TABLE t2;
 FLUSH STATUS;
 INSERT INTO t2 SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
@@ -946,6 +988,7 @@ HANDLER_READ_FIRST	5
 HANDLER_READ_KEY	5
 HANDLER_READ_NEXT	5
 HANDLER_WRITE	22
+# 30 locks (2 table, 8 + 5 subpartitions lock/unlock)
 FLUSH STATUS;
 CREATE TABLE t3 SELECT * FROM t1 PARTITION (pNeg,subp3,`p100-99999`);
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
@@ -957,6 +1000,7 @@ HANDLER_READ_FIRST	5
 HANDLER_READ_KEY	5
 HANDLER_READ_NEXT	7
 HANDLER_WRITE	24
+# 14 locks (2 table, 5 subpartitions lock/unlock)
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (

=== modified file 'mysql-test/r/partition_locking.result'
--- a/mysql-test/r/partition_locking.result	revid:mattias.jonsson@stripped
+++ b/mysql-test/r/partition_locking.result	revid:mattias.jonsson@stripped
@@ -156,6 +156,19 @@ HANDLER_WRITE	19
 # 2 read_first, read_key and read_next.
 # 1 commit
 #
+# Test TRUNCATE PARTITION
+#
+FLUSH STATUS;
+ALTER TABLE t2 TRUNCATE PARTITION p1;
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+INSERT INTO t2 SELECT a, b FROM t1 WHERE a = 1;
+#
 # Test insert on duplicated key update
 #
 FLUSH STATUS;
@@ -1245,6 +1258,30 @@ HANDLER_WRITE	18
 # 1 read_rnd
 # 1 delete (due to moved to another partition)
 # 1 write
+FLUSH STATUS;
+UPDATE t1 SET b = CONCAT(b, ", same as min(a) + 2 in t2") WHERE a = (SELECT MIN(a) + 2 FROM t2);
+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	56
+HANDLER_READ_FIRST	13
+HANDLER_READ_KEY	14
+HANDLER_UPDATE	1
+HANDLER_WRITE	17
+# 56 locks (2 tables, 13 + 13 partitions lock/unlock)
+FLUSH STATUS;
+UPDATE t1 SET b = CONCAT(b, ", max(a) in t2: ", (SELECT MAX(a) FROM t2)) WHERE a = 5;
+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	32
+HANDLER_READ_KEY	14
+HANDLER_READ_LAST	13
+HANDLER_UPDATE	1
+HANDLER_WRITE	17
+# 32 locks (2 tables, 1 + 13 partitions lock/unlock)
 #
 # Test multi table update
 #
@@ -1253,9 +1290,9 @@ a	b
 0	First row, p0
 1	First row, p1
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
 26	Third row, p0, updated 1
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
@@ -1323,6 +1360,266 @@ HANDLER_WRITE	18
 # 2 rean_rnd_next
 # 2 update
 #
+# Test of views
+#
+# Found bug#13559657 (partition selection does not work with views)
+FLUSH STATUS;
+CREATE VIEW v1_25 AS SELECT a, b FROM t1 PARTITION (p2, p5);
+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
+# 6 locks (1 table, 2 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_25_check AS SELECT a, b FROM t1 PARTITION (p2, p5) t1_alias WITH CHECK OPTION;
+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
+# 6 locks (1 table, 2 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_9 AS SELECT a, b FROM t1 WHERE a = 9;
+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
+# 4 locks (1 table, 1 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_9_check AS SELECT a, b FROM t1 WHERE a = 9 WITH CHECK OPTION;
+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
+# 4 locks (1 table, 1 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_all AS SELECT a, b FROM t1;
+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	28
+HANDLER_WRITE	17
+# 28 locks (1 table, 13 partitions lock/unlock)
+SELECT TABLE_NAME, CHECK_OPTION, IS_UPDATABLE, VIEW_DEFINITION
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 'v1_%';
+TABLE_NAME	CHECK_OPTION	IS_UPDATABLE	VIEW_DEFINITION
+v1_25	NONE	YES	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` PARTITION (`p2`,`p5`)
+v1_25_check	CASCADED	YES	select `t1_alias`.`a` AS `a`,`t1_alias`.`b` AS `b` from `test`.`t1` PARTITION (`p2`,`p5`) `t1_alias`
+v1_9	NONE	YES	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = 9)
+v1_9_check	CASCADED	YES	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = 9)
+v1_all	NONE	YES	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`
+FLUSH STATUS;
+INSERT INTO v1_all VALUES (23, "Insert in v1_all");
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_25 VALUES (18, "Insert in v1_25");
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_25 VALUES (17, "Insert in v1_25 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	2
+HANDLER_WRITE	17
+# 2 locks (1 table, 0 partition lock/unlock)
+FLUSH STATUS;
+INSERT IGNORE INTO v1_25 VALUES (17, "Insert ignore in v1_25");
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK	2
+HANDLER_WRITE	17
+# 2 locks (1 table, 0 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_25_check VALUES (31, "Insert in v1_25_check");
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+# Bug#13559657, this should fail!
+FLUSH STATUS;
+INSERT INTO v1_25_check VALUES (30, "Insert in v1_25_check 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	2
+HANDLER_WRITE	17
+# 2 locks (1 table, 0 partition lock/unlock)
+FLUSH STATUS;
+INSERT IGNORE INTO v1_25_check VALUES (30, "Insert ignore in v1_25_check");
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK	2
+HANDLER_WRITE	17
+# 2 locks (1 table, 0 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_9 VALUES (9, "Insert in v1_9");
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_9 VALUES (8, "Insert in v1_9 NO CHECK!");
+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
+# 4 locks (1 table, 1 partition lock/unlock)
+SELECT * FROM t1 WHERE a = 8;
+a	b
+8	Insert in v1_9 NO CHECK!
+# DELETE will not find row not in view
+FLUSH STATUS;
+DELETE FROM v1_9_check WHERE a = 8;
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_WRITE	17
+# 0 locks, impossible where!
+# TODO: See if the reviewer in optimizer notices the difference :)
+# I.e. EXPLAIN DELETE for non partitioned tables does not optimize this
+# as SELECT would!
+EXPLAIN EXTENDED DELETE FROM v1_9_check WHERE a = 8;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
+EXPLAIN EXTENDED SELECT * FROM v1_9_check WHERE a = 8;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where 0
+SELECT * FROM t1 WHERE a = 8;
+a	b
+8	Insert in v1_9 NO CHECK!
+FLUSH STATUS;
+INSERT INTO v1_9_check VALUES (10, "Insert in v1_9_check fail");
+ERROR HY000: CHECK OPTION failed 'test.v1_9_check'
+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 table, 1 partition lock/unlock)
+SELECT * FROM t1 WHERE a = 9;
+a	b
+9	Insert in v1_9
+FLUSH STATUS;
+DELETE FROM v1_9_check WHERE a = 9;
+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_KEY	1
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1_9_check VALUES (9, "Insert in v1_9_check");
+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
+FLUSH STATUS;
+SELECT * FROM v1_9;
+a	b
+9	Insert in v1_9_check
+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	1
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+SELECT * FROM v1_25;
+a	b
+18	Insert in v1_25
+2	First row, p2
+31	Insert in v1_25_check
+5	REPLACE second, max(a) in t2: 4
+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_READ_FIRST	2
+HANDLER_READ_KEY	2
+HANDLER_READ_NEXT	4
+HANDLER_WRITE	17
+# 6 locks (1 table, 2 partition lock/unlock)
+FLUSH STATUS;
+SELECT * FROM v1_all;
+a	b
+0	First row, p0
+1	First row, p1
+104	No duplicate 104
+105	No duplicate
+113	Second row, p0, updated 1, updated 2 -> p8, updated 3, updated 4 -> p9
+18	Insert in v1_25
+2	First row, p2
+23	Insert in v1_all
+26	Third row, p0, updated 1
+3	First row, p3, same as min(a) + 2 in t2
+31	Insert in v1_25_check
+39	Fourth row, p0, updated 1
+4	First row, p4, t2.b:First row, p4
+5	REPLACE second, max(a) in t2: 4
+52	Fifth row, p0, updated 1
+65	No duplicate, INSERT_DUP_KEY_UPDATE
+78	No duplicate
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
+91	No duplicate, INSERT_DUP_KEY_UPDATE
+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	28
+HANDLER_READ_FIRST	13
+HANDLER_READ_KEY	13
+HANDLER_READ_NEXT	20
+HANDLER_WRITE	17
+# 28 locks (1 table, 13 partition lock/unlock)
+DROP VIEW v1_all;
+DROP VIEW v1_9, v1_9_check;
+DROP VIEW v1_25, v1_25_check;
+#
 # Test CREATE SELECT
 #
 FLUSH STATUS;
@@ -1334,7 +1631,7 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	10
 HANDLER_READ_FIRST	3
 HANDLER_READ_KEY	3
-HANDLER_READ_NEXT	11
+HANDLER_READ_NEXT	12
 HANDLER_WRITE	20
 # 10 locks (2 tables, 3 partitions lock/unlock)
 SELECT * FROM t3 ORDER BY a;
@@ -1359,7 +1656,7 @@ a	b
 0	First row, p0
 1	First row, p1
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4, t2.b:First row, p4
 DROP TABLE t3;
 #
@@ -1440,16 +1737,21 @@ a	b
 105	No duplicate
 111	Test111
 113	Second row, p0, updated 1, updated 2 -> p8, updated 3, updated 4 -> p9
+18	Insert in v1_25
 2	First row, p2
+23	Insert in v1_all
 26	Third row, p0, updated 1
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
+31	Insert in v1_25_check
 313	Test313
 39	Fourth row, p0, updated 1
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
 78	No duplicate
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
 91	No duplicate, INSERT_DUP_KEY_UPDATE
 98	Test98
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
@@ -1459,7 +1761,7 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	30
 HANDLER_READ_FIRST	13
 HANDLER_READ_KEY	14
-HANDLER_READ_NEXT	18
+HANDLER_READ_NEXT	23
 HANDLER_WRITE	17
 # 30 locks (procs table, t1 + 13 partitions lock/unlock)
 FLUSH STATUS;
@@ -1492,6 +1794,7 @@ HANDLER_WRITE	17
 FLUSH STATUS;
 CALL sp_select_partition("p8");
 a	b
+8	Insert in v1_9 NO CHECK!
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
 WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
 VARIABLE_NAME	VARIABLE_VALUE
@@ -1499,6 +1802,7 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	4
 HANDLER_READ_FIRST	1
 HANDLER_READ_KEY	1
+HANDLER_READ_NEXT	1
 HANDLER_WRITE	17
 # no proc locking since already in proc cache.
 # 4 locks (t1 + 1 partition lock/unlock)
@@ -1506,6 +1810,7 @@ FLUSH STATUS;
 CALL sp_select_partition("p7,p8");
 a	b
 111	Test111
+8	Insert in v1_9 NO CHECK!
 98	Test98
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
 WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
@@ -1514,7 +1819,7 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	6
 HANDLER_READ_FIRST	2
 HANDLER_READ_KEY	2
-HANDLER_READ_NEXT	2
+HANDLER_READ_NEXT	3
 HANDLER_WRITE	17
 # 6 locks (t1 + 2 partitions lock/unlock)
 FLUSH STATUS;
@@ -1522,9 +1827,9 @@ CALL sp_select_range(1,5);
 a	b
 1	First row, p1
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
 WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
 VARIABLE_NAME	VARIABLE_VALUE
@@ -1548,10 +1853,15 @@ a	b
 0	First row, p0
 1	First row, p1
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
+18	Insert in v1_25
+23	Insert in v1_all
 26	Third row, p0, updated 1
+31	Insert in v1_25_check
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
@@ -1574,10 +1884,11 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	4
 HANDLER_WRITE	17
 # 4 locks (1 table + 1 partition lock/unlock)
+# This EXPLAIN DELETE have an unstable row estimation.
 FLUSH STATUS;
 EXPLAIN DELETE FROM t1 WHERE b = "No duplicate";
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	range	PRIMARY,b	b	131	NULL	15	Using where
+1	SIMPLE	t1	range	PRIMARY,b	b	131	NULL	#	Using where
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
 WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
 VARIABLE_NAME	VARIABLE_VALUE
@@ -1596,10 +1907,11 @@ HANDLER_COMMIT	1
 HANDLER_EXTERNAL_LOCK	4
 HANDLER_WRITE	17
 # 4 locks (1 table + 1 partition lock/unlock)
+# This EXPLAIN DELETE have an unstable row estimation.
 FLUSH STATUS;
 EXPLAIN PARTITIONS DELETE FROM t1 WHERE b = "No duplicate";
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12	range	PRIMARY,b	b	131	NULL	15	Using where
+1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12	range	PRIMARY,b	b	131	NULL	#	Using where
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
 WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
 VARIABLE_NAME	VARIABLE_VALUE
@@ -1646,10 +1958,15 @@ a	b
 0	First row, p0
 1	First row, p1
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
+18	Insert in v1_25
+23	Insert in v1_all
 26	Third row, p0, updated 1
+31	Insert in v1_25_check
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
@@ -1752,10 +2069,15 @@ SELECT * FROM t1 ORDER BY a;
 a	b
 0	First row, p0
 2	First row, p2
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
+18	Insert in v1_25
+23	Insert in v1_all
 26	Third row, p0, updated 1
+31	Insert in v1_25_check
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
@@ -1917,7 +2239,7 @@ HANDLER_WRITE	17
 # t1, before update, after update
 SELECT * FROM t1 WHERE a = 3;
 a	b
-3	First row, p3
+3	First row, p3, same as min(a) + 2 in t2
 FLUSH STATUS;
 UPDATE t1 SET b = CONCAT(b, ", UPDATED2") WHERE a = 3;
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
@@ -1933,7 +2255,7 @@ HANDLER_WRITE	19
 # t1, before update, after update
 SELECT * FROM t1 WHERE a = 3;
 a	b
-3	First row, p3, UPDATED2
+3	First row, p3, same as min(a) + 2 in t2, UPDATED2
 FLUSH STATUS;
 INSERT INTO t1 VALUES (12, "First row, p12");
 SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
@@ -1975,12 +2297,17 @@ SELECT * FROM t1 ORDER BY a;
 a	b
 0	First row, p0 REPLACED4
 2	First row, p2, duplicate key 2, duplicate key 2
-3	First row, p3, UPDATED2
+3	First row, p3, same as min(a) + 2 in t2, UPDATED2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
 11	First row, p11
 12	First row, p12
+18	Insert in v1_25
+23	Insert in v1_all
 26	Third row, p0, updated 1
+31	Insert in v1_25_check
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
@@ -2063,12 +2390,17 @@ SELECT * FROM t1 ORDER BY a;
 a	b
 0	First row, p0 REPLACED4
 2	First row, p2, duplicate key 2, duplicate key 2
-3	First row, p3, UPDATED2
+3	First row, p3, same as min(a) + 2 in t2, UPDATED2
 4	First row, p4, t2.b:First row, p4
-5	REPLACE second
+5	REPLACE second, max(a) in t2: 4
+8	Insert in v1_9 NO CHECK!
+9	Insert in v1_9_check
 11	First row, p11
 12	First row, p12
+18	Insert in v1_25
+23	Insert in v1_all
 26	Third row, p0, updated 1
+31	Insert in v1_25_check
 39	Fourth row, p0, updated 1
 52	Fifth row, p0, updated 1
 65	No duplicate, INSERT_DUP_KEY_UPDATE
@@ -2100,8 +2432,8 @@ old_a	new_a	old_b	new_b
 2	2	AU: First row, p2	AU: First row, p2, duplicate key 2
 2	2	AU: First row, p2, duplicate key 2	AU: First row, p2, duplicate key 2, duplicate key 2
 2	2	BU: First row, p2, duplicate key 2	BU: First row, p2, duplicate key 2, duplicate key 2
-3	3	AU: First row, p3	AU: First row, p3, UPDATED2
-3	3	BU: First row, p3	BU: First row, p3, UPDATED2
+3	3	AU: First row, p3, same as min(a) + 2 in t2	AU: First row, p3, same as min(a) + 2 in t2, UPDATED2
+3	3	BU: First row, p3, same as min(a) + 2 in t2	BU: First row, p3, same as min(a) + 2 in t2, UPDATED2
 98	NULL	AD: Test98	NULL
 98	NULL	BD: Test98	NULL
 DROP TABLE t1, t2, t3;
@@ -2267,5 +2599,7 @@ DROP TABLE t1;
 # TODO: Document that functions in WHERE clause can now be evaluated
 #       before any locks are taken (i.e. if optimization is possible
 #       before locking). Like GET_LOCK/RELEASE_LOCK ?
-# TODO: How to make a trigger prune?
-# TODO: can stored procedures be pruned?
+# TODO: How to make a stored function or trigger prune?
+# Stored procedures does not prelock, so it will prune locks.
+# Stored functions, triggers and events prelocks all used tables
+# which makes prune locks impossible.

=== modified file 'mysql-test/t/partition_explicit_prune.test'
--- a/mysql-test/t/partition_explicit_prune.test	revid:mattias.jonsson@stripped
+++ b/mysql-test/t/partition_explicit_prune.test	revid:mattias.jonsson@stripped
@@ -446,15 +446,33 @@ eval $get_handler_status_counts;
 
 --echo # Test multi-table DELETE
 --echo # Can be expressed in two different ways.
-FLUSH STATUS;
 CREATE TABLE t2 LIKE t1;
+FLUSH STATUS;
+INSERT INTO t2 PARTITION (`p10-99`, subp3, `p100-99999`) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 24 locks (2 table, 5 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+ALTER TABLE t2 TRUNCATE PARTITION `p10-99`, `p0-9`, `p100-99999`;
+eval $get_handler_status_counts;
+--echo # 14 locks (1 table, 6 subpartitions lock/unlock)
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO t2 PARTITION (subp3) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
+eval $get_handler_status_counts;
+--echo # 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+FLUSH STATUS;
+INSERT IGNORE INTO t2 PARTITION (subp3) SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
 eval $get_handler_status_counts;
+--echo # 16 locks (2 tables, 1 + 5 subpartitions lock/unlock)
+TRUNCATE TABLE t2;
 FLUSH STATUS;
 INSERT INTO t2 SELECT * FROM t1 PARTITION (subp3, `p10-99`, `p100-99999`);
 eval $get_handler_status_counts;
+--echo # 30 locks (2 table, 8 + 5 subpartitions lock/unlock)
 FLUSH STATUS;
 CREATE TABLE t3 SELECT * FROM t1 PARTITION (pNeg,subp3,`p100-99999`);
 eval $get_handler_status_counts;
+--echo # 14 locks (2 table, 5 subpartitions lock/unlock)
 SHOW CREATE TABLE t1;
 SELECT * FROM t1;
 SHOW CREATE TABLE t2;

=== modified file 'mysql-test/t/partition_locking.test'
--- a/mysql-test/t/partition_locking.test	revid:mattias.jonsson@stripped
+++ b/mysql-test/t/partition_locking.test	revid:mattias.jonsson@stripped
@@ -108,6 +108,14 @@ eval $get_handler_status_counts;
 --echo # 2 read_first, read_key and read_next.
 --echo # 1 commit
 
+--echo #
+--echo # Test TRUNCATE PARTITION
+--echo #
+FLUSH STATUS;
+ALTER TABLE t2 TRUNCATE PARTITION p1;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+INSERT INTO t2 SELECT a, b FROM t1 WHERE a = 1;
 
 --echo #
 --echo # Test insert on duplicated key update
@@ -563,7 +571,14 @@ eval $get_handler_status_counts;
 --echo # 1 read_rnd
 --echo # 1 delete (due to moved to another partition)
 --echo # 1 write
-
+FLUSH STATUS;
+UPDATE t1 SET b = CONCAT(b, ", same as min(a) + 2 in t2") WHERE a = (SELECT MIN(a) + 2 FROM t2);
+eval $get_handler_status_counts;
+--echo # 56 locks (2 tables, 13 + 13 partitions lock/unlock)
+FLUSH STATUS;
+UPDATE t1 SET b = CONCAT(b, ", max(a) in t2: ", (SELECT MAX(a) FROM t2)) WHERE a = 5;
+eval $get_handler_status_counts;
+--echo # 32 locks (2 tables, 1 + 13 partitions lock/unlock)
 
 --echo #
 --echo # Test multi table update
@@ -597,6 +612,132 @@ eval $get_handler_status_counts;
 --echo # 2 update
 
 --echo #
+--echo # Test of views
+--echo #
+--echo # Found bug#13559657 (partition selection does not work with views)
+FLUSH STATUS;
+CREATE VIEW v1_25 AS SELECT a, b FROM t1 PARTITION (p2, p5);
+eval $get_handler_status_counts;
+--echo # 6 locks (1 table, 2 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_25_check AS SELECT a, b FROM t1 PARTITION (p2, p5) t1_alias WITH CHECK OPTION;
+eval $get_handler_status_counts;
+--echo # 6 locks (1 table, 2 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_9 AS SELECT a, b FROM t1 WHERE a = 9;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_9_check AS SELECT a, b FROM t1 WHERE a = 9 WITH CHECK OPTION;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partitions lock/unlock)
+FLUSH STATUS;
+CREATE VIEW v1_all AS SELECT a, b FROM t1;
+eval $get_handler_status_counts;
+--echo # 28 locks (1 table, 13 partitions lock/unlock)
+SELECT TABLE_NAME, CHECK_OPTION, IS_UPDATABLE, VIEW_DEFINITION
+FROM INFORMATION_SCHEMA.VIEWS
+WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME LIKE 'v1_%';
+
+FLUSH STATUS;
+INSERT INTO v1_all VALUES (23, "Insert in v1_all");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT INTO v1_25 VALUES (18, "Insert in v1_25");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO v1_25 VALUES (17, "Insert in v1_25 fail");
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, 0 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT IGNORE INTO v1_25 VALUES (17, "Insert ignore in v1_25");
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, 0 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT INTO v1_25_check VALUES (31, "Insert in v1_25_check");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+--echo # Bug#13559657, this should fail!
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO v1_25_check VALUES (30, "Insert in v1_25_check fail");
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, 0 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT IGNORE INTO v1_25_check VALUES (30, "Insert ignore in v1_25_check");
+eval $get_handler_status_counts;
+--echo # 2 locks (1 table, 0 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT INTO v1_9 VALUES (9, "Insert in v1_9");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT INTO v1_9 VALUES (8, "Insert in v1_9 NO CHECK!");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+SELECT * FROM t1 WHERE a = 8;
+--echo # DELETE will not find row not in view
+FLUSH STATUS;
+DELETE FROM v1_9_check WHERE a = 8;
+eval $get_handler_status_counts;
+--echo # 0 locks, impossible where!
+--echo # TODO: See if the reviewer in optimizer notices the difference :)
+--echo # I.e. EXPLAIN DELETE for non partitioned tables does not optimize this
+--echo # as SELECT would!
+EXPLAIN EXTENDED DELETE FROM v1_9_check WHERE a = 8;
+EXPLAIN EXTENDED SELECT * FROM v1_9_check WHERE a = 8;
+SELECT * FROM t1 WHERE a = 8;
+
+FLUSH STATUS;
+--error ER_VIEW_CHECK_FAILED
+INSERT INTO v1_9_check VALUES (10, "Insert in v1_9_check fail");
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+SELECT * FROM t1 WHERE a = 9;
+FLUSH STATUS;
+DELETE FROM v1_9_check WHERE a = 9;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+FLUSH STATUS;
+INSERT INTO v1_9_check VALUES (9, "Insert in v1_9_check");
+eval $get_handler_status_counts;
+
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1_9;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1_25;
+eval $get_handler_status_counts;
+--echo # 6 locks (1 table, 2 partition lock/unlock)
+
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1_all;
+eval $get_handler_status_counts;
+--echo # 28 locks (1 table, 13 partition lock/unlock)
+DROP VIEW v1_all;
+DROP VIEW v1_9, v1_9_check;
+DROP VIEW v1_25, v1_25_check;
+
+--echo #
 --echo # Test CREATE SELECT
 --echo #
 FLUSH STATUS;
@@ -719,7 +860,9 @@ FLUSH STATUS;
 EXPLAIN DELETE FROM t1 WHERE a = 105;
 eval $get_handler_status_counts;
 --echo # 4 locks (1 table + 1 partition lock/unlock)
+--echo # This EXPLAIN DELETE have an unstable row estimation.
 FLUSH STATUS;
+--replace_column 9 #
 EXPLAIN DELETE FROM t1 WHERE b = "No duplicate";
 eval $get_handler_status_counts;
 --echo # 28 locks (1 table + 13 partition lock/unlock)
@@ -727,7 +870,9 @@ FLUSH STATUS;
 EXPLAIN PARTITIONS DELETE FROM t1 WHERE a = 105;
 eval $get_handler_status_counts;
 --echo # 4 locks (1 table + 1 partition lock/unlock)
+--echo # This EXPLAIN DELETE have an unstable row estimation.
 FLUSH STATUS;
+--replace_column 10 #
 EXPLAIN PARTITIONS DELETE FROM t1 WHERE b = "No duplicate";
 eval $get_handler_status_counts;
 --echo # 28 locks (1 table + 13 partition lock/unlock)
@@ -1059,24 +1204,13 @@ DROP TABLE t1;
 --echo #       before any locks are taken (i.e. if optimization is possible
 --echo #       before locking). Like GET_LOCK/RELEASE_LOCK ?
 
-# TODO:
-# Triggers
---echo # TODO: How to make a trigger prune?
---echo # TODO: can stored procedures be pruned?
+--echo # TODO: How to make a stored function or trigger prune?
+--echo # Stored procedures does not prelock, so it will prune locks.
+--echo # Stored functions, triggers and events prelocks all used tables
+--echo # which makes prune locks impossible.
 
 
 #from the WL:
-# SELECT (including UNION and JOIN) should only lock the same partitions that
-# needs to read.
-# 
-# single table UPDATE will only be pruned for locking if no partitioning field is
-# given for update. (Not yet part of this worklog: One could optimize this if the
-# partitioning fields to be updated is constants only, then one could add those
-# matching partitions to be locked too).
-# 
-# multi table UPDATE will only prune locks for tables that does not update any
-# partitioning fields. (for enhancements see single table UPDATE). 
-# 
 # TODO: test if it makes sense to have an upper limit of inserted rows before just
 # use/lock all partitions, since the overhead of iterate over all rows to be
 # inserted can be higher than the overhead of locking all partitions.

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	revid:mattias.jonsson@stripped
+++ b/sql/sql_lex.cc	revid:mattias.jonsson@stripped
@@ -2494,6 +2494,20 @@ void TABLE_LIST::print(THD *thd, String 
         append_identifier(thd, str, table_name, table_name_length);
         cmp_name= table_name;
       }
+      if (partition_names && partition_names->elements)
+      {
+        int i, num_parts= partition_names->elements;
+        List_iterator<String> name_it(*(partition_names));
+        str->append(STRING_WITH_LEN(" PARTITION ("));
+        for (i= 1; i <= num_parts; i++)
+        {
+          String *name= name_it++;
+          append_identifier(thd, str, name->c_ptr(), name->length());
+          if (i != num_parts)
+            str->append(',');
+        }
+        str->append(')');
+      }
     }
     if (my_strcasecmp(table_alias_charset, cmp_name, alias))
     {

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	revid:mattias.jonsson@stripped
+++ b/sql/sql_update.cc	revid:mattias.jonsson@stripped
@@ -289,13 +289,6 @@ int mysql_update(THD *thd,
   if (open_query_tables(thd))
     DBUG_RETURN(1);
 
-  if (thd->fill_derived_tables() &&
-      mysql_handle_derived(thd->lex, &mysql_derived_create))
-  {
-    mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
-    DBUG_RETURN(1);
-  }
-
   if (table_list->multitable_view)
   {
     DBUG_ASSERT(table_list->view != 0);

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	revid:mattias.jonsson@stripped
+++ b/sql/sql_view.cc	revid:mattias.jonsson@stripped
@@ -448,7 +448,7 @@ bool mysql_create_view(THD *thd, TABLE_L
     goto err;
   }
 
-  if (open_and_lock_tables(thd, lex->query_tables, TRUE, 0))
+  if (open_query_tables(thd))
   {
     view= lex->unlink_first_table(&link_to_local);
     res= TRUE;
@@ -574,6 +574,15 @@ bool mysql_create_view(THD *thd, TABLE_L
     goto err;
   }
 
+  lex->link_first_table_back(view, link_to_local);
+  if (lock_query_tables(thd))
+  {
+    view= lex->unlink_first_table(&link_to_local);
+    res= TRUE;
+    goto err;
+  }
+  view= lex->unlink_first_table(&link_to_local);
+
   /* view list (list of view fields names) */
   if (lex->view_list.elements)
   {

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (mattias.jonsson:3700 to 3702) WL#4443Mattias Jonsson9 Jan