List:Commits« Previous MessageNext Message »
From:daogang.qu Date:February 22 2011 8:20am
Subject:bzr commit into mysql-trunk branch (daogang.qu:3218) WL#5493
View as plain text  
#At file:///home/daogang/bzrwork/pushwl5493/mysql-trunk-wl5493/ based on revid:daogang.qu@stripped0221132329-osqt1wavz33yepvt

 3218 daogang.qu@greatopensource.com	2011-02-22 [merge]
      WL#5493  Binlog crash-safe when master crashed
      
      Auto merge

    added:
      mysql-test/r/multi_update_innodb.result
      mysql-test/r/partition_explicit_prune.result
      mysql-test/suite/parts/inc/partition-dml-1-1-modes.inc
      mysql-test/suite/parts/inc/partition-dml-1-1.inc
      mysql-test/suite/parts/inc/partition-dml-1-10.inc
      mysql-test/suite/parts/inc/partition-dml-1-11.inc
      mysql-test/suite/parts/inc/partition-dml-1-2.inc
      mysql-test/suite/parts/inc/partition-dml-1-3.inc
      mysql-test/suite/parts/inc/partition-dml-1-4.inc
      mysql-test/suite/parts/inc/partition-dml-1-5.inc
      mysql-test/suite/parts/inc/partition-dml-1-6.inc
      mysql-test/suite/parts/inc/partition-dml-1-7.inc
      mysql-test/suite/parts/inc/partition-dml-1-8.inc
      mysql-test/suite/parts/inc/partition-dml-1-9.inc
      mysql-test/suite/parts/inc/partition-dml_cr_tab.inc
      mysql-test/suite/parts/inc/partition-dml_ins_tab.inc
      mysql-test/suite/parts/inc/rpl-partition-dml-1-1.inc
      mysql-test/suite/parts/r/partition-dml-1-1-innodb-modes.result
      mysql-test/suite/parts/r/partition-dml-1-1-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-1-myisam-modes.result
      mysql-test/suite/parts/r/partition-dml-1-1-myisam.result
      mysql-test/suite/parts/r/partition-dml-1-10-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-10-myisam.result
      mysql-test/suite/parts/r/partition-dml-1-11-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-11-myisam.result
      mysql-test/suite/parts/r/partition-dml-1-2-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-2-myisam.result
      mysql-test/suite/parts/r/partition-dml-1-3-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-4-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-5-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-6-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-7-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-8-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-9-innodb.result
      mysql-test/suite/parts/r/partition-dml-1-9-myisam.result
      mysql-test/suite/parts/r/rpl-partition-dml-1-1-innodb.result
      mysql-test/suite/parts/r/rpl-partition-dml-1-1-myisam.result
      mysql-test/suite/parts/t/partition-dml-1-1-innodb-modes.test
      mysql-test/suite/parts/t/partition-dml-1-1-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-1-myisam-modes.test
      mysql-test/suite/parts/t/partition-dml-1-1-myisam.test
      mysql-test/suite/parts/t/partition-dml-1-10-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-10-myisam.test
      mysql-test/suite/parts/t/partition-dml-1-11-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-11-myisam.test
      mysql-test/suite/parts/t/partition-dml-1-2-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-2-myisam.test
      mysql-test/suite/parts/t/partition-dml-1-3-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-4-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-5-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-6-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-7-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-8-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-9-innodb.test
      mysql-test/suite/parts/t/partition-dml-1-9-myisam.test
      mysql-test/suite/parts/t/rpl-partition-dml-1-1-innodb.test
      mysql-test/suite/parts/t/rpl-partition-dml-1-1-myisam.test
      mysql-test/suite/sys_vars/r/core_file_basic.result
      mysql-test/suite/sys_vars/t/core_file_basic-master.opt
      mysql-test/suite/sys_vars/t/core_file_basic.test
      mysql-test/t/multi_update_innodb.test
      mysql-test/t/partition_explicit_prune.test
    modified:
      client/mysqldump.c
      include/my_base.h
      include/my_global.h
      include/mysql_embed.h
      include/welcome_copyright_notice.h
      mysql-test/include/mysqld--help.inc
      mysql-test/include/subquery_sj.inc
      mysql-test/r/alter_table.result
      mysql-test/r/func_time.result
      mysql-test/r/log_state.result
      mysql-test/r/log_tables.result
      mysql-test/r/multi_update.result
      mysql-test/r/mysqldump.result
      mysql-test/r/negation_elimination.result
      mysql-test/r/partition.result
      mysql-test/r/partition_exchange.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/system_mysql_db.result
      mysql-test/suite/funcs_1/r/is_columns_mysql.result
      mysql-test/suite/parts/inc/partition_fail.inc
      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_exch_qa_14.test
      mysql-test/suite/parts/t/partition_repair_myisam.test
      mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result
      mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result
      mysql-test/suite/perfschema/r/pfs_upgrade_lc2.result
      mysql-test/suite/sys_vars/r/slow_query_log_func.result
      mysql-test/suite/sys_vars/t/slow_query_log_func.test
      mysql-test/t/alter_table.test
      mysql-test/t/func_time.test
      mysql-test/t/log_state.test
      mysql-test/t/log_tables.test
      mysql-test/t/multi_update.test
      mysql-test/t/mysqldump.test
      mysql-test/t/negation_elimination.test
      mysql-test/t/partition.test
      mysql-test/t/partition_binlog.test
      mysys/hash.c
      mysys/my_handler.c
      mysys/my_handler_errors.h
      scripts/mysql_system_tables.sql
      scripts/mysql_system_tables_fix.sql
      scripts/mysqldumpslow.sh
      sql/ha_ndbcluster_cond.cc
      sql/ha_partition.cc
      sql/ha_partition.h
      sql/handler.cc
      sql/handler.h
      sql/item_cmpfunc.cc
      sql/item_cmpfunc.h
      sql/item_func.h
      sql/item_timefunc.cc
      sql/item_timefunc.h
      sql/log.cc
      sql/log.h
      sql/mysqld.cc
      sql/mysqld.h
      sql/opt_range.cc
      sql/partition_info.cc
      sql/partition_info.h
      sql/share/errmsg-utf8.txt
      sql/sql_base.cc
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_lex.cc
      sql/sql_lex.h
      sql/sql_parse.cc
      sql/sql_partition.cc
      sql/sql_plugin.cc
      sql/sql_plugin.h
      sql/sql_table.cc
      sql/sql_table.h
      sql/sql_update.cc
      sql/sql_yacc.yy
      sql/sys_vars.cc
      sql/sys_vars.h
      sql/table.cc
      sql/table.h
      storage/innobase/btr/btr0sea.c
      storage/innobase/include/ha0ha.h
      unittest/gunit/item-t.cc
=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2011-01-16 04:02:29 +0000
+++ b/client/mysqldump.c	2011-02-21 07:15:46 +0000
@@ -1164,6 +1164,9 @@ static int switch_db_collation(FILE *sql
 {
   if (strcmp(current_db_cl_name, required_db_cl_name) != 0)
   {
+    char quoted_db_buf[NAME_LEN * 2 + 3];
+    char *quoted_db_name= quote_name(db_name, quoted_db_buf, FALSE);
+
     CHARSET_INFO *db_cl= get_charset_by_name(required_db_cl_name, MYF(0));
 
     if (!db_cl)
@@ -1171,7 +1174,7 @@ static int switch_db_collation(FILE *sql
 
     fprintf(sql_file,
             "ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
-            (const char *) db_name,
+            (const char *) quoted_db_name,
             (const char *) db_cl->csname,
             (const char *) db_cl->name,
             (const char *) delimiter);
@@ -1192,6 +1195,9 @@ static int restore_db_collation(FILE *sq
                                 const char *delimiter,
                                 const char *db_cl_name)
 {
+  char quoted_db_buf[NAME_LEN * 2 + 3];
+  char *quoted_db_name= quote_name(db_name, quoted_db_buf, FALSE);
+
   CHARSET_INFO *db_cl= get_charset_by_name(db_cl_name, MYF(0));
 
   if (!db_cl)
@@ -1199,7 +1205,7 @@ static int restore_db_collation(FILE *sq
 
   fprintf(sql_file,
           "ALTER DATABASE %s CHARACTER SET %s COLLATE %s %s\n",
-          (const char *) db_name,
+          (const char *) quoted_db_name,
           (const char *) db_cl->csname,
           (const char *) db_cl->name,
           (const char *) delimiter);

=== modified file 'include/my_base.h'
--- a/include/my_base.h	2011-01-11 09:09:21 +0000
+++ b/include/my_base.h	2011-02-02 22:02:29 +0000
@@ -1,5 +1,4 @@
-/* Copyright (C) 2000, 2011, Oracle and/or its affiliates. All rights 
-   reserved
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,7 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /* This file includes constants used with all databases */
 
@@ -446,7 +445,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)

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2011-02-01 07:52:46 +0000
+++ b/include/my_global.h	2011-02-21 11:33:20 +0000
@@ -1485,7 +1485,6 @@ static inline double rint(double x)
 
 #undef HAVE_OPENSSL
 #undef HAVE_SMEM				/* No shared memory */
-#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
 
 #endif /* EMBEDDED_LIBRARY */
 

=== modified file 'include/mysql_embed.h'
--- a/include/mysql_embed.h	2010-11-09 14:53:53 +0000
+++ b/include/mysql_embed.h	2011-02-21 10:15:29 +0000
@@ -25,7 +25,6 @@
 
 #undef HAVE_DLOPEN				/* No udf functions */
 #undef HAVE_SMEM				/* No shared memory */
-#undef HAVE_NDBCLUSTER_DB /* No NDB cluster */
 
 #endif /* EMBEDDED_LIBRARY */
 #endif /* MYSQL_EMBED_INCLUDED */

=== modified file 'include/welcome_copyright_notice.h'
--- a/include/welcome_copyright_notice.h	2010-10-06 15:06:13 +0000
+++ b/include/welcome_copyright_notice.h	2011-02-02 22:02:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -11,7 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #ifndef _welcome_copyright_notice_h_
 #define _welcome_copyright_notice_h_

=== modified file 'mysql-test/include/mysqld--help.inc'
--- a/mysql-test/include/mysqld--help.inc	2010-09-30 13:52:39 +0000
+++ b/mysql-test/include/mysqld--help.inc	2011-02-22 05:37:44 +0000
@@ -8,7 +8,7 @@
 # force symbolic-links=0 (valgrind build has a different default)
 #
 
-exec $MYSQLD_BOOTSTRAP_CMD --symbolic-links=0 --lower-case-table-names=1 --help --verbose > $MYSQL_TMP_DIR/mysqld--help.txt 2>&1;
+exec $MYSQLD_BOOTSTRAP_CMD --symbolic-links=0 --lower-case-table-names=1 --help --verbose > $MYSQL_TMP_DIR/mysqld--help.txt 2>/dev/null;
 
 # The inline perl code below will copy $MYSQL_TMP_DIR/mysqld--help.txt
 # to output, but filter away some variable stuff (e.g. paths).

=== modified file 'mysql-test/include/subquery_sj.inc'
--- a/mysql-test/include/subquery_sj.inc	2011-01-27 11:38:22 +0000
+++ b/mysql-test/include/subquery_sj.inc	2011-02-21 10:36:31 +0000
@@ -3504,3 +3504,19 @@ deallocate prepare s;
 DROP TABLE ot1, ot2, ot3, it1;
 
 --echo # End of the test for bug#57623.
+
+--echo #
+--echo # Bug#11766642: crash in Item_field::register_field_in_read_map with view
+--echo #
+
+CREATE TABLE t1(a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+
+INSERT INTO t1 VALUES (0),(1),(2);
+
+SELECT a FROM t1 WHERE a IN 
+ (SELECT a XOR a FROM v1)
+ORDER BY a;
+
+DROP TABLE t1;
+DROP VIEW v1;

=== modified file 'mysql-test/r/alter_table.result'
--- a/mysql-test/r/alter_table.result	2010-08-30 06:38:09 +0000
+++ b/mysql-test/r/alter_table.result	2011-02-21 11:34:23 +0000
@@ -1383,3 +1383,11 @@ ALTER TABLE t1 CHANGE a id INT;
 affected rows: 0
 info: Records: 0  Duplicates: 0  Warnings: 0
 DROP TABLE t1;
+#
+# Bug#11754461 CANNOT ALTER TABLE WHEN KEY PREFIX TOO LONG
+#
+DROP DATABASE IF EXISTS db1;
+CREATE DATABASE db1 CHARACTER SET utf8;
+CREATE TABLE db1.t1 (bar TINYTEXT, KEY (bar(100)));
+ALTER TABLE db1.t1 ADD baz INT;
+DROP DATABASE db1;

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2011-02-02 18:31:39 +0000
+++ b/mysql-test/r/func_time.result	2011-02-21 08:23:02 +0000
@@ -136,7 +136,7 @@ dayname("1962-03-03")	dayname("1962-03-0
 Saturday	5
 select monthname("1972-03-04"),monthname("1972-03-04")+0;
 monthname("1972-03-04")	monthname("1972-03-04")+0
-March	3
+March	0
 select time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
 time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
 00|12|0|12|00|AM|12:00:00 AM|00|00:00:00
@@ -1400,3 +1400,11 @@ SELECT SUBDATE(STR_TO_DATE(NULL,0), INTE
 SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR)
 NULL
 #
+# BUG#59895 - setting storage engine to null segfaults mysqld
+#
+SELECT MONTHNAME(0), MONTHNAME(0) IS NULL, MONTHNAME(0) + 1;
+MONTHNAME(0)	MONTHNAME(0) IS NULL	MONTHNAME(0) + 1
+NULL	1	NULL
+SET storage_engine=NULL;
+ERROR 42000: Variable 'storage_engine' can't be set to the value of 'NULL'
+#

=== modified file 'mysql-test/r/log_state.result'
--- a/mysql-test/r/log_state.result	2010-11-02 11:53:54 +0000
+++ b/mysql-test/r/log_state.result	2011-02-10 11:13:41 +0000
@@ -41,7 +41,7 @@ select sleep(@long_query_time + 1);
 sleep(@long_query_time + 1)
 0
 select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
 # Switch to connection default
 set global slow_query_log= ON;
 # Switch to connection con1
@@ -50,8 +50,8 @@ select sleep(@long_query_time + 1);
 sleep(@long_query_time + 1)
 0
 select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
-TIMESTAMP	USER_HOST	QUERY_TIME	00:00:00	1	0	test	0	0	1	select sleep(@long_query_time + 1)
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
+TIMESTAMP	USER_HOST	QUERY_TIME	00:00:00	1	0	test	0	0	1	QUERY	THREAD_ID
 # Switch to connection default
 show global variables
 where Variable_name = 'log' or Variable_name = 'log_slow_queries' or

=== modified file 'mysql-test/r/log_tables.result'
--- a/mysql-test/r/log_tables.result	2010-11-15 16:43:41 +0000
+++ b/mysql-test/r/log_tables.result	2011-02-22 05:37:44 +0000
@@ -17,7 +17,7 @@ event_time	user_host	thread_id	server_id
 TIMESTAMP	USER_HOST	THREAD_ID	1	Query	select * from general_log
 truncate table slow_log;
 select * from slow_log;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
 truncate table general_log;
 select * from general_log where argument like '%general_log%';
 event_time	user_host	thread_id	server_id	command_type	argument
@@ -81,7 +81,8 @@ slow_log	CREATE TABLE `slow_log` (
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
-  `sql_text` mediumtext NOT NULL
+  `sql_text` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL
 ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
 show fields from mysql.slow_log;
 Field	Type	Null	Key	Default	Extra
@@ -96,6 +97,7 @@ last_insert_id	int(11)	NO		NULL
 insert_id	int(11)	NO		NULL	
 server_id	int(10) unsigned	NO		NULL	
 sql_text	mediumtext	NO		NULL	
+thread_id	int(11)	NO		NULL	
 flush logs;
 flush tables;
 SET GLOBAL GENERAL_LOG=ON;
@@ -146,8 +148,8 @@ select sleep(2);
 sleep(2)
 0
 select * from mysql.slow_log;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
-TIMESTAMP	USER_HOST	QUERY_TIME	00:00:00	1	0	mysql	0	0	1	select sleep(2)
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
+TIMESTAMP	USER_HOST	QUERY_TIME	00:00:00	1	0	mysql	0	0	1	QUERY	THREAD_ID
 set @@session.long_query_time = @saved_long_query_time;
 alter table mysql.general_log engine=myisam;
 ERROR HY000: You cannot 'ALTER' a log table if logging is enabled
@@ -184,7 +186,8 @@ slow_log	CREATE TABLE `slow_log` (
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
-  `sql_text` mediumtext NOT NULL
+  `sql_text` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL
 ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
 alter table mysql.general_log engine=myisam;
 alter table mysql.slow_log engine=myisam;
@@ -211,7 +214,8 @@ slow_log	CREATE TABLE `slow_log` (
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
-  `sql_text` mediumtext NOT NULL
+  `sql_text` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Slow log'
 set global general_log='ON';
 set global slow_query_log='ON';
@@ -281,7 +285,8 @@ ON UPDATE CURRENT_TIMESTAMP,
 `last_insert_id` int(11) NOT NULL,
 `insert_id` int(11) NOT NULL,
 `server_id` int(10) unsigned NOT NULL,
-`sql_text` mediumtext NOT NULL
+`sql_text` mediumtext NOT NULL,
+`thread_id` int(11) NOT NULL
 ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
 set global general_log='ON';
 set global slow_query_log='ON';
@@ -308,7 +313,7 @@ event_time	user_host	thread_id	server_id
 TIMESTAMP	USER_HOST	THREAD_ID	1	Query	select * from general_log
 truncate table slow_log;
 select * from slow_log;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
 create table general_log_new like general_log;
 rename table general_log TO renamed_general_log, general_log_new TO general_log;
 create table slow_log_new like slow_log;
@@ -329,9 +334,9 @@ TIMESTAMP	USER_HOST	THREAD_ID	1	Query	se
 TIMESTAMP	USER_HOST	THREAD_ID	1	Query	create table general_log_new like general_log
 TIMESTAMP	USER_HOST	THREAD_ID	1	Query	rename table general_log TO renamed_general_log, general_log_new TO general_log
 select * from slow_log;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
 select * from renamed_slow_log;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text
+start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	thread_id
 set global general_log='OFF';
 RENAME TABLE general_log TO general_log2;
 set global slow_query_log='OFF';
@@ -368,75 +373,6 @@ slow_log
 slow_log_new
 drop table slow_log_new, general_log_new;
 use test;
-SET GLOBAL LOG_OUTPUT = 'TABLE';
-SET GLOBAL general_log = 0;
-FLUSH LOGS;
-TRUNCATE TABLE mysql.general_log;
-ALTER TABLE mysql.general_log ENGINE = MyISAM;
-ALTER TABLE mysql.general_log
-ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
-SET GLOBAL general_log = 1;
-FLUSH LOGS;
-SELECT * FROM mysql.general_log;
-event_time	user_host	thread_id	server_id	command_type	argument	seq
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	FLUSH LOGS	1
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	2
-SELECT * FROM mysql.general_log;
-event_time	user_host	thread_id	server_id	command_type	argument	seq
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	FLUSH LOGS	1
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	2
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	3
-SELECT "My own query 1";
-My own query 1
-My own query 1
-SELECT "My own query 2";
-My own query 2
-My own query 2
-SELECT * FROM mysql.general_log;
-event_time	user_host	thread_id	server_id	command_type	argument	seq
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	FLUSH LOGS	1
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	2
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	3
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT "My own query 1"	4
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT "My own query 2"	5
-EVENT_TIME	USER_HOST	THREAD_ID	SERVER_ID	Query	SELECT * FROM mysql.general_log	6
-SET GLOBAL general_log = 0;
-FLUSH LOGS;
-ALTER TABLE mysql.general_log DROP COLUMN seq;
-ALTER TABLE mysql.general_log ENGINE = CSV;
-SET GLOBAL slow_query_log = 0;
-FLUSH LOGS;
-TRUNCATE TABLE mysql.slow_log;
-ALTER TABLE mysql.slow_log ENGINE = MyISAM;
-ALTER TABLE mysql.slow_log
-ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
-SET SESSION long_query_time = 1;
-SET GLOBAL slow_query_log = 1;
-FLUSH LOGS;
-SELECT "My own slow query", sleep(2);
-My own slow query	sleep(2)
-My own slow query	0
-SELECT "My own slow query", sleep(2);
-My own slow query	sleep(2)
-My own slow query	0
-SELECT "My own slow query", sleep(2);
-My own slow query	sleep(2)
-My own slow query	0
-SELECT "My own slow query", sleep(2);
-My own slow query	sleep(2)
-My own slow query	0
-SELECT * FROM mysql.slow_log WHERE seq >= 2 LIMIT 3;
-start_time	user_host	query_time	lock_time	rows_sent	rows_examined	db	last_insert_id	insert_id	server_id	sql_text	seq
-START_TIME	USER_HOST	QUERY_TIME	00:00:00	1	0	test	0	0	1	SELECT "My own slow query", sleep(2)	2
-START_TIME	USER_HOST	QUERY_TIME	00:00:00	1	0	test	0	0	1	SELECT "My own slow query", sleep(2)	3
-START_TIME	USER_HOST	QUERY_TIME	00:00:00	1	0	test	0	0	1	SELECT "My own slow query", sleep(2)	4
-SET GLOBAL slow_query_log = 0;
-SET SESSION long_query_time =@saved_long_query_time;
-FLUSH LOGS;
-ALTER TABLE mysql.slow_log DROP COLUMN seq;
-ALTER TABLE mysql.slow_log ENGINE = CSV;
-SET GLOBAL general_log = @old_general_log;
-SET GLOBAL slow_query_log = @old_slow_query_log;
 drop procedure if exists proc25422_truncate_slow;
 drop procedure if exists proc25422_truncate_general;
 drop procedure if exists proc25422_alter_slow;
@@ -533,7 +469,8 @@ CREATE TABLE `db_17876.slow_log_data` (
 `last_insert_id` int(11) default NULL,
 `insert_id` int(11) default NULL,
 `server_id` int(11) default NULL,
-`sql_text` mediumtext 
+`sql_text` mediumtext,
+`thread_id` int(11) default NULL
 );
 CREATE TABLE `db_17876.general_log_data` (
 `event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@@ -547,7 +484,7 @@ CREATE procedure `db_17876.archiveSlowLo
 BEGIN
 DECLARE start_time, query_time, lock_time CHAR(20);
 DECLARE user_host MEDIUMTEXT;
-DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id INT;
+DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id, thread_id INT;
 DECLARE dbname MEDIUMTEXT;
 DECLARE sql_text BLOB;
 DECLARE done INT DEFAULT 0;
@@ -561,14 +498,14 @@ DECLARE CONTINUE HANDLER FOR ER_SP_FETCH
 FETCH cur1 INTO
 start_time, user_host, query_time, lock_time,
 rows_set, rows_examined, dbname, last_insert_id,
-insert_id, server_id, sql_text;
+insert_id, server_id, sql_text, thread_id;
 END;
 IF NOT done THEN
 BEGIN
 INSERT INTO
 `db_17876.slow_log_data`
             VALUES(start_time, user_host, query_time, lock_time, rows_set, rows_examined,
-dbname, last_insert_id,  insert_id, server_id, sql_text);
+dbname, last_insert_id,  insert_id, server_id, sql_text, thread_id);
 END;
 END IF;
 END;

=== modified file 'mysql-test/r/multi_update.result'
--- a/mysql-test/r/multi_update.result	2010-12-14 11:15:13 +0000
+++ b/mysql-test/r/multi_update.result	2011-02-21 15:55:58 +0000
@@ -680,4 +680,21 @@ Warnings:
 Warning	1292	Truncated incorrect datetime value: '1'
 DROP FUNCTION f1;
 DROP TABLE t1;
+#
+# BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
+#            table is updated twice
+#
+CREATE TABLE t1(
+pk INT,
+a INT,
+PRIMARY KEY (pk)
+) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (0,0);
+UPDATE t1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+
+# Should be (1,2)
+SELECT * FROM t1;
+pk	a
+1	2
+DROP TABLE t1;
 end of tests

=== added file 'mysql-test/r/multi_update_innodb.result'
--- a/mysql-test/r/multi_update_innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/multi_update_innodb.result	2011-02-21 15:31:41 +0000
@@ -0,0 +1,29 @@
+#
+# BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
+#            table is updated twice
+#
+CREATE TABLE t1(
+pk INT,
+a INT,
+b INT,
+PRIMARY KEY (pk)
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (0,0,0);
+UPDATE t1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+SELECT * FROM t1;
+pk	a	b
+0	0	0
+CREATE VIEW v1 AS SELECT * FROM t1;
+UPDATE v1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+SELECT * FROM t1;
+pk	a	b
+0	0	0
+UPDATE t1 AS A, t1 AS B SET A.a = 1, B.b = 2;
+# Should be (0,1,2)
+SELECT * FROM t1;
+pk	a	b
+0	1	2
+DROP VIEW v1;
+DROP TABLE t1;

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2011-01-14 14:49:16 +0000
+++ b/mysql-test/r/mysqldump.result	2011-02-21 07:28:19 +0000
@@ -4596,11 +4596,48 @@ CREATE TABLE `comment_table` (i INT COMM
 </mysqldump>
 DROP TABLE `comment_table`;
 #
+# BUG#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH ("-") IN
+#                DATABASE NAMES IN ALTER DATABASE
+#
+CREATE DATABASE `test-database`;
+USE `test-database`;
+CREATE TABLE `test` (`c1` VARCHAR(10)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+CREATE TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW BEGIN
+END |
+ALTER DATABASE `test-database` CHARACTER SET latin1 COLLATE latin1_swedish_ci;
+ALTER DATABASE `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `test` (
+  `c1` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `test-database` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client      = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results     = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client  = latin1 */ ;
+/*!50003 SET character_set_results = latin1 */ ;
+/*!50003 SET collation_connection  = latin1_swedish_ci */ ;
+/*!50003 SET @saved_sql_mode       = @@sql_mode */ ;
+/*!50003 SET sql_mode              = '' */ ;
+DELIMITER ;;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW BEGIN
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode              = @saved_sql_mode */ ;
+/*!50003 SET character_set_client  = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection  = @saved_col_connection */ ;
+ALTER DATABASE `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+DROP DATABASE `test-database`;
+#
 # End of 5.1 tests
 #
 #
 # Test for --add-drop-trigger
 #
+USE `test`;
 CREATE TABLE t1 (a int, b int);
 CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW 
 SET NEW.b=NEW.a + 10;

=== modified file 'mysql-test/r/negation_elimination.result'
--- a/mysql-test/r/negation_elimination.result	2010-04-20 07:22:51 +0000
+++ b/mysql-test/r/negation_elimination.result	2011-02-21 10:36:31 +0000
@@ -375,6 +375,121 @@ a
 13
 14
 15
+# XOR (Note: XOR is negated by negating one of the operands)
+# Should return 6,7
+SELECT * FROM t1 WHERE ((a > 5) XOR (a > 7));
+a
+6
+7
+# Should return 0..5,8..19
+SELECT * FROM t1 WHERE ((NOT (a > 5)) XOR (a > 7));
+a
+0
+1
+2
+3
+4
+5
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+SELECT * FROM t1 WHERE ((a > 5) XOR (NOT (a > 7)));
+a
+0
+1
+2
+3
+4
+5
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+SELECT * FROM t1 WHERE NOT ((a > 5) XOR (a > 7));
+a
+0
+1
+2
+3
+4
+5
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+# Should return 6,7
+SELECT * FROM t1 WHERE NOT ((NOT (a > 5)) XOR (a > 7));
+a
+6
+7
+SELECT * FROM t1 WHERE NOT ((a > 5) XOR (NOT (a > 7)));
+a
+6
+7
+# Should return 0..5,8..19
+SELECT * FROM t1 WHERE NOT ((NOT (a > 5)) XOR (NOT (a > 7)));
+a
+0
+1
+2
+3
+4
+5
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+# Should have empty result
+SELECT * FROM t1 WHERE (NULL XOR (a > 7));
+a
+SELECT * FROM t1 WHERE NOT (NULL XOR (a > 7));
+a
+# Should be simplified to "...WHERE (a XOR a)
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE NOT ((NOT a) XOR (a));
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	a	5	NULL	21	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` xor `test`.`t1`.`a`)
+# Should be simplified to "...WHERE (a XOR a)
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE NOT (a XOR (NOT a));
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	a	5	NULL	21	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` xor `test`.`t1`.`a`)
+# End XOR
 delete from t1 where a > 3;
 select a, not(not(a)) from t1;
 a	not(not(a))

=== modified file 'mysql-test/r/partition.result'
--- a/mysql-test/r/partition.result	2011-01-10 16:37:47 +0000
+++ b/mysql-test/r/partition.result	2011-02-21 15:55:58 +0000
@@ -2263,3 +2263,51 @@ INSERT INTO t1 VALUES(0);
 DROP TABLE t1;
 SET GLOBAL myisam_use_mmap=default;
 End of 5.1 tests
+#
+# BUG#55385: UPDATE statement throws an error, but still updates
+#            the table entries
+CREATE TABLE t1_part (
+partkey int,
+nokey int
+) PARTITION BY LINEAR HASH(partkey) PARTITIONS 3;
+INSERT INTO t1_part VALUES (1, 1) , (10, 10);
+CREATE VIEW v1 AS SELECT * FROM t1_part;
+
+# Should be (1,1),(10,10)
+SELECT * FROM t1_part;
+partkey	nokey
+1	1
+10	10
+
+# Case 1
+# Update is refused because partitioning key is updated
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.partkey = 2, B.nokey = 3;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.nokey = 2, B.partkey = 3;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+
+# Case 2
+# Like 1, but partition accessed through a view
+UPDATE t1_part AS A NATURAL JOIN v1 as B SET A.nokey = 2 , B.partkey = 3;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+UPDATE v1 AS A NATURAL JOIN t1_part as B SET A.nokey = 2 , B.partkey = 3;
+ERROR HY000: Primary key/partition key update is not allowed since the table is updated both as 'A' and 'B'.
+
+# Should be (1,1),(10,10)
+SELECT * FROM t1_part;
+partkey	nokey
+1	1
+10	10
+
+# Case 3
+# Update is accepted because partitioning key is not updated
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.nokey = 2 , B.nokey = 3;
+
+# Should be (1,3),(10,3)
+SELECT * FROM t1_part;
+partkey	nokey
+1	3
+10	3
+
+DROP VIEW v1;
+DROP TABLE t1_part;

=== 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-02-01 11:38:39 +0000
@@ -0,0 +1,1671 @@
+# 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;
+# 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;
+#
+# Bug#59864: Crash if table empty: DELETE FROM t2 PARTITION (subp3).
+#
+CREATE TABLE t1
+(a INT NOT NULL,
+b varchar (64),
+INDEX (b,a),
+PRIMARY KEY (a))
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0,
+SUBPARTITION subp1,
+SUBPARTITION subp2),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3,
+SUBPARTITION subp4,
+SUBPARTITION subp5),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6,
+SUBPARTITION subp7,
+SUBPARTITION subp8),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9,
+SUBPARTITION subp10,
+SUBPARTITION subp11),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12,
+SUBPARTITION subp13,
+SUBPARTITION subp14));
+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,
+  SUBPARTITION subp2 ENGINE = InnoDB),
+ PARTITION `p0-29` VALUES LESS THAN (30)
+ (SUBPARTITION subp3 ENGINE = InnoDB,
+  SUBPARTITION subp4 ENGINE = InnoDB,
+  SUBPARTITION subp5 ENGINE = InnoDB),
+ PARTITION `p30-299` VALUES LESS THAN (300)
+ (SUBPARTITION subp6 ENGINE = InnoDB,
+  SUBPARTITION subp7 ENGINE = InnoDB,
+  SUBPARTITION subp8 ENGINE = InnoDB),
+ PARTITION `p300-2999` VALUES LESS THAN (3000)
+ (SUBPARTITION subp9 ENGINE = InnoDB,
+  SUBPARTITION subp10 ENGINE = InnoDB,
+  SUBPARTITION subp11 ENGINE = InnoDB),
+ PARTITION `p3000-299999` VALUES LESS THAN (300000)
+ (SUBPARTITION subp12 ENGINE = InnoDB,
+  SUBPARTITION subp13 ENGINE = InnoDB,
+  SUBPARTITION subp14 ENGINE = InnoDB)) */
+INSERT INTO t1 VALUES (-9, "negative nine"), (-8, "-8"), (-7, "-7"), (-6, "-6"), (-5, "-5"), (-4, "-4"), (-3, "-3"), (-2, "-2"), (-1, "-1");
+INSERT INTO t1 VALUES (9, "nine"), (8, "8"), (7, "7"), (6, "6"), (5, "5"), (4, "4"), (3, "3"), (2, "2"), (1, "1");
+INSERT INTO t1 VALUES (39, "Thirty nine"), (38, "38"), (37, "37"), (36, "36"), (35, "35"), (34, "34"), (33, "33"), (32, "32"), (31, "31");
+INSERT INTO t1 VALUES (339, "Three hundred thirty nine"), (338, "338"), (337, "337"), (336, "336"), (335, "335"), (334, "334"), (333, "333"), (332, "332"), (331, "331");
+INSERT INTO t1 VALUES (3339, "Three thousand three hundred thirty nine"), (3338, "3338"), (3337, "3337"), (3336, "3336"), (3335, "3335"), (3334, "3334"), (3333, "3333"), (3332, "3332"), (3331, "3331");
+SELECT * FROM t1;
+a	b
+-1	-1
+-2	-2
+-3	-3
+-4	-4
+-5	-5
+-6	-6
+-7	-7
+-8	-8
+-9	negative nine
+1	1
+2	2
+3	3
+31	31
+32	32
+33	33
+331	331
+332	332
+333	333
+3331	3331
+3332	3332
+3333	3333
+3334	3334
+3335	3335
+3336	3336
+3337	3337
+3338	3338
+3339	Three thousand three hundred thirty nine
+334	334
+335	335
+336	336
+337	337
+338	338
+339	Three hundred thirty nine
+34	34
+35	35
+36	36
+37	37
+38	38
+39	Thirty nine
+4	4
+5	5
+6	6
+7	7
+8	8
+9	nine
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+3	3
+6	6
+9	nine
+DELETE FROM t1 PARTITION (subp3);
+SELECT * FROM t1;
+a	b
+-1	-1
+-2	-2
+-3	-3
+-4	-4
+-5	-5
+-6	-6
+-7	-7
+-8	-8
+-9	negative nine
+1	1
+2	2
+31	31
+32	32
+33	33
+331	331
+332	332
+333	333
+3331	3331
+3332	3332
+3333	3333
+3334	3334
+3335	3335
+3336	3336
+3337	3337
+3338	3338
+3339	Three thousand three hundred thirty nine
+334	334
+335	335
+336	336
+337	337
+338	338
+339	Three hundred thirty nine
+34	34
+35	35
+36	36
+37	37
+38	38
+39	Thirty nine
+4	4
+5	5
+7	7
+8	8
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+DELETE FROM t1 PARTITION (`p0-29`);
+SELECT * FROM t1;
+a	b
+-1	-1
+-2	-2
+-3	-3
+-4	-4
+-5	-5
+-6	-6
+-7	-7
+-8	-8
+-9	negative nine
+31	31
+32	32
+33	33
+331	331
+332	332
+333	333
+3331	3331
+3332	3332
+3333	3333
+3334	3334
+3335	3335
+3336	3336
+3337	3337
+3338	3338
+3339	Three thousand three hundred thirty nine
+334	334
+335	335
+336	336
+337	337
+338	338
+339	Three hundred thirty nine
+34	34
+35	35
+36	36
+37	37
+38	38
+39	Thirty nine
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+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;
+SET @@default_storage_engine = @old_default_storage_engine;

=== modified file 'mysql-test/r/subquery_sj_none.result'
--- a/mysql-test/r/subquery_sj_none.result	2011-02-14 11:21:26 +0000
+++ b/mysql-test/r/subquery_sj_none.result	2011-02-21 10:36:31 +0000
@@ -5538,4 +5538,17 @@ a	a	a
 deallocate prepare s;
 DROP TABLE ot1, ot2, ot3, it1;
 # End of the test for bug#57623.
+#
+# Bug#11766642: crash in Item_field::register_field_in_read_map with view
+#
+CREATE TABLE t1(a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+INSERT INTO t1 VALUES (0),(1),(2);
+SELECT a FROM t1 WHERE a IN 
+(SELECT a XOR a FROM v1)
+ORDER BY a;
+a
+0
+DROP TABLE t1;
+DROP VIEW v1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/system_mysql_db.result'
--- a/mysql-test/r/system_mysql_db.result	2010-12-17 11:28:59 +0000
+++ b/mysql-test/r/system_mysql_db.result	2011-02-10 11:13:41 +0000
@@ -264,7 +264,8 @@ slow_log	CREATE TABLE `slow_log` (
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
-  `sql_text` mediumtext NOT NULL
+  `sql_text` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL
 ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
 show tables;
 Tables_in_test

=== modified file 'mysql-test/suite/funcs_1/r/is_columns_mysql.result'
--- a/mysql-test/suite/funcs_1/r/is_columns_mysql.result	2010-12-17 11:28:59 +0000
+++ b/mysql-test/suite/funcs_1/r/is_columns_mysql.result	2011-02-22 05:37:44 +0000
@@ -188,6 +188,7 @@ def	mysql	slow_log	rows_sent	5	NULL	NO	i
 def	mysql	slow_log	server_id	10	NULL	NO	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references	
 def	mysql	slow_log	sql_text	11	NULL	NO	mediumtext	16777215	16777215	NULL	NULL	utf8	utf8_general_ci	mediumtext			select,insert,update,references	
 def	mysql	slow_log	start_time	1	CURRENT_TIMESTAMP	NO	timestamp	NULL	NULL	NULL	NULL	NULL	NULL	timestamp		on update CURRENT_TIMESTAMP	select,insert,update,references	
+def	mysql	slow_log	thread_id	12	NULL	NO	int	NULL	NULL	10	0	NULL	NULL	int(11)			select,insert,update,references	
 def	mysql	slow_log	user_host	2	NULL	NO	mediumtext	16777215	16777215	NULL	NULL	utf8	utf8_general_ci	mediumtext			select,insert,update,references	
 def	mysql	tables_priv	Column_priv	8		NO	set	31	93	NULL	NULL	utf8	utf8_general_ci	set('Select','Insert','Update','References')			select,insert,update,references	
 def	mysql	tables_priv	Db	2		NO	char	64	192	NULL	NULL	utf8	utf8_bin	char(64)	PRI		select,insert,update,references	
@@ -511,6 +512,7 @@ NULL	mysql	slow_log	last_insert_id	int	N
 NULL	mysql	slow_log	insert_id	int	NULL	NULL	NULL	NULL	int(11)
 NULL	mysql	slow_log	server_id	int	NULL	NULL	NULL	NULL	int(10) unsigned
 1.0000	mysql	slow_log	sql_text	mediumtext	16777215	16777215	utf8	utf8_general_ci	mediumtext
+NULL	mysql	slow_log	thread_id	int	NULL	NULL	NULL	NULL	int(11)
 3.0000	mysql	tables_priv	Host	char	60	180	utf8	utf8_bin	char(60)
 3.0000	mysql	tables_priv	Db	char	64	192	utf8	utf8_bin	char(64)
 3.0000	mysql	tables_priv	User	char	16	48	utf8	utf8_bin	char(16)

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-1-modes.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-1-modes.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-1-modes.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,213 @@
+let $DATA_PATH=;
+let $INDEX_PATH=;
+--source include/have_partition.inc
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+--echo # Run in empty mode
+set @@global.sql_mode= '';
+--echo #######################################################
+--echo # UPDATE without partition selection
+
+connect (session1, localhost, test_user_1,'testpw',test);
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='table-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+--echo #######################################################
+--echo # UPDATE with partition selection
+#connect (session1, localhost, test_user_1,'testpw',test);
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+#connect (session2, localhost, test_user_2,'testpw',test);
+connection session2;
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='p0-29-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+disconnect session1;
+disconnect session2;
+
+connection default;
+DROP TABLE t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+--echo # Run in ANSI mode
+set @@global.sql_mode= ansi;
+--echo #######################################################
+--echo # UPDATE without partition selection
+
+connect (session1, localhost, test_user_1,'testpw',test);
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='table-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+--echo #######################################################
+--echo # UPDATE with partition selection
+#connect (session1, localhost, test_user_1,'testpw',test);
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+#connect (session2, localhost, test_user_2,'testpw',test);
+connection session2;
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='p0-29-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+disconnect session1;
+disconnect session2;
+
+connection default;
+DROP TABLE t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+--echo # Run in traditional mode
+set @@global.sql_mode= traditional;
+--echo #######################################################
+--echo # UPDATE without partition selection
+
+connect (session1, localhost, test_user_1,'testpw',test);
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='table-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+--echo #######################################################
+--echo # UPDATE with partition selection
+#connect (session1, localhost, test_user_1,'testpw',test);
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+#connect (session2, localhost, test_user_2,'testpw',test);
+connection session2;
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='p0-29-upd-1';
+--source include/wait_condition.inc
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo reap
+reap;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-1.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-1.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-1.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,102 @@
+let $DATA_PATH=;
+let $INDEX_PATH=;
+--source include/have_partition.inc
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='p0-29-upd-1';
+--source include/wait_condition.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+--sorted_result
+SELECT * FROM t1 PARTITION (subp4);
+--sorted_result
+SELECT * FROM t1 PARTITION (subp5);
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+
+connection session1;
+--echo reap
+reap;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+
+# 2) empty (sub)partitions 
+let $TABLENAME= t2;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+
+SELECT * FROM t2 PARTITION (`p30-299`);
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+SELECT * FROM t2 PARTITION (subp4);
+SELECT * FROM t2 PARTITION (subp5);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+DROP USER test_user_2;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-10.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-10.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-10.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,81 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+PREPARE st1 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=''p0-29-upd-1'' WHERE a BETWEEN 0 AND 9' ;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+PREPARE st2 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=? WHERE a BETWEEN 20 AND 29' ;
+
+connection session1;
+EXECUTE st1;
+
+connection session2;
+SET @var1= 'p0-29-upd-2';
+if ($engine == MyISAM)
+{
+EXECUTE st2 USING @var1;
+}
+if ($engine == InnoDB)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+EXECUTE st2 USING @var1;
+}
+
+connection session1;
+COMMIT WORK;
+
+connection session2;
+SET @var1= 'p0-29-upd-2';
+EXECUTE st2 USING @var1;
+
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+DEALLOCATE PREPARE st1;
+
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+COMMIT WORK;
+DEALLOCATE PREPARE st2;
+
+connection default;
+disconnect session1;
+disconnect session2;
+
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-11.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-11.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-11.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,122 @@
+# DATA DIRECTORY
+# Make directory for partition data
+let $data_dir_path= $MYSQLTEST_VARDIR/mysql-test-data-dir;
+--mkdir $data_dir_path
+let $DATA_PATH= DATA DIRECTORY = '$data_dir_path';
+
+# INDEX DIRECTORY
+# Make directory for partition index
+let $idx_dir_path= $MYSQLTEST_VARDIR/mysql-test-idx-dir;
+--mkdir $idx_dir_path
+let $INDEX_PATH= INDEX DIRECTORY = '$idx_dir_path';
+
+--source include/have_partition.inc
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--enable_result_log
+--enable_query_log
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--echo send
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+let $wait_condition= SELECT count(*)= 4 FROM t1 WHERE b ='p0-29-upd-1';
+--source include/wait_condition.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+--sorted_result
+SELECT * FROM t1 PARTITION (subp4);
+--sorted_result
+SELECT * FROM t1 PARTITION (subp5);
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+
+connection session1;
+--echo reap
+reap;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+
+# 2) empty (sub)partitions 
+let $TABLENAME= t2;
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--enable_result_log
+--enable_query_log
+
+SELECT * FROM t2 PARTITION (`p30-299`);
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+SELECT * FROM t2 PARTITION (subp4);
+SELECT * FROM t2 PARTITION (subp5);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+--rmdir $data_dir_path
+--rmdir $idx_dir_path
+DROP USER test_user_1;
+DROP USER test_user_2;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-2.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-2.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-2.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,86 @@
+let $DATA_PATH=;
+let $INDEX_PATH=;
+--source include/have_partition.inc
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+let $TABLENAME= t2;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+
+delimiter //;
+CREATE
+PROCEDURE p1 ()
+BEGIN
+DECLARE c11,c21 int;
+DECLARE c12,c22 varchar(64);
+DECLARE cur1 CURSOR FOR SELECT * FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`) ORDER BY a,b;
+DECLARE cur2 CURSOR FOR SELECT * FROM t1 ORDER BY a,b;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET @done = 1;
+OPEN cur1;
+OPEN cur2;
+read_loop: LOOP
+  FETCH cur1 INTO c11,c12;
+  FETCH cur2 INTO c21,c22;
+  IF !((c11=c21) AND (c12=c22)) THEN
+  SELECT c11,c12,c21,c22;
+  LEAVE read_loop;
+  END IF;
+  IF @done THEN
+  LEAVE read_loop;
+  END IF;
+END LOOP;
+CLOSE cur1;
+CLOSE cur2;
+END//
+
+CREATE PROCEDURE p2 ()
+BEGIN
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd' WHERE a BETWEEN 3 AND 10;
+END//
+
+CREATE PROCEDURE p3 ()
+BEGIN
+DELETE FROM t1 PARTITION (`p0-29`) WHERE b= 'p0-29-upd';
+END//
+
+CREATE TRIGGER tr1 AFTER INSERT ON t2
+FOR EACH ROW BEGIN
+    UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd-trigger' WHERE a BETWEEN 30 AND 40;
+END//
+
+delimiter ;//
+
+--disable_warnings
+CALL p1;
+--enable_warnings
+CALL p2;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+SELECT * FROM t1 WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+CALL p3;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+CALL p3;
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+SELECT * FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+SELECT * FROM t1 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 40 ORDER BY a,b ;
+
+DELETE FROM t1 PARTITION (pneg, `p30-299`);
+SELECT * FROM t1 ORDER BY a,b;
+
+--echo ########## Empty table t1 #########
+DELETE FROM t1;
+--disable_warnings
+CALL p1;
+--enable_warnings
+CALL p2;
+CALL p3;
+
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+DROP PROCEDURE p3;
+DROP TRIGGER tr1;
+DROP TABLE t1;
+DROP TABLE t2;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-3.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-3.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-3.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,82 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd-1' WHERE a BETWEEN 30 AND 39;
+
+connection session1;
+--echo ####### expect only p0-29 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session2;
+--echo ####### expect only p30-299 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session1;
+COMMIT WORK;
+--echo ####### expect only p0-29 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session2;
+--echo ####### expect only p30-299 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connect (session3, localhost, test_user_3,'testpw',test);
+--echo ####### expect only p0-29 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+disconnect session3;
+
+connection session2;
+COMMIT WORK;
+--echo ####### expect p0-29 and p30-299 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session1;
+--echo ####### expect only p30-299 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+COMMIT WORK;
+--echo ####### expect p0-29 and p30-299 is updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-4.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-4.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-4.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,60 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'serializable';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connect (session2, localhost, test_user_1,'testpw',test);
+--echo ####### expect p30-299 is readable, p0-29 is locked
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+--error ER_LOCK_WAIT_TIMEOUT 
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+COMMIT WORK;
+
+connection session2;
+--echo ####### expect p0-29 and p30-299 are readable
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-5.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-5.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-5.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,58 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'read-committed';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connect (session2, localhost, test_user_1,'testpw',test);
+--echo ####### expect not to see the updated values
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session1;
+COMMIT WORK;
+
+connection session2;
+--echo ####### expect to see the updated values.
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-6.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-6.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-6.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,58 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'read-uncommitted';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connect (session2, localhost, test_user_1,'testpw',test);
+--echo ####### expect not to see the updated values
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+connection session1;
+COMMIT WORK;
+
+connection session2;
+--echo ####### expect to see the updated values.
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-7.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-7.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-7.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,91 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+eval DROP INDEX ind_$TABLENAME ON $TABLENAME;
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9 ;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+--echo ####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+
+connection session1;
+COMMIT WORK;
+--echo ####### expect p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+--echo ####### expect p0-29 has not been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 20 AND 29 ;
+
+connection session1;
+--echo ####### expect only p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+
+connection session2;
+COMMIT WORK;
+--echo ####### expect p0-29 is completely updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo ####### expect only p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+COMMIT WORK;
+--echo ####### expect p0-29 is completely updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-8.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-8.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-8.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,91 @@
+--source include/have_partition.inc
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+let $DATA_PATH=;
+let $INDEX_PATH=;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9 ;
+
+connect (session2, localhost, test_user_2,'testpw',test);
+--echo ####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+
+connection session1;
+COMMIT WORK;
+--echo ####### expect p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session2;
+--echo ####### expect p0-29 has not been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 20 AND 29 ;
+
+connection session1;
+--echo ####### expect only p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+
+connection session2;
+COMMIT WORK;
+--echo ####### expect p0-29 is completely updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection session1;
+--echo ####### expect only p0-29 (0-9) has been updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+COMMIT WORK;
+--echo ####### expect p0-29 is completely updated
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml-1-9.inc'
--- a/mysql-test/suite/parts/inc/partition-dml-1-9.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml-1-9.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,190 @@
+let $DATA_PATH=;
+let $INDEX_PATH=;
+--source include/have_partition.inc
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+let $TABLENAME= t2;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+
+connect (session1, localhost, test_user_1,'testpw',test);
+--sorted_result
+CREATE VIEW v1 AS
+SELECT t1.a, t2.b FROM t1 PARTITION (`p0-29`), t2 
+WHERE t1.a = t2.a;
+SELECT * FROM v1;
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t2 PARTITION (`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+--sorted_result
+SELECT * FROM t2 PARTITION (subp6);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3), 
+t2 PARTITION (subp6);
+
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3,subp5);
+--sorted_result
+SELECT * FROM t2 PARTITION (subp6,subp8);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3,subp5), 
+t2 PARTITION (subp6,subp8);
+
+DELETE FROM t2 PARTITION (`p30-299`);
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t2  PARTITION (`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+
+DELETE FROM t1 PARTITION (`p0-29`);
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t2  PARTITION (`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+
+INSERT INTO t1 VALUES (1,'t1-p0-29-ins');
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t2  PARTITION (`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+
+INSERT INTO t2 VALUES (32,'t2-p30-299-ins');
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+--sorted_result
+SELECT * FROM t2  PARTITION (`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+
+DELETE FROM t1 PARTITION (`p30-299`);
+INSERT INTO t1 VALUES (31,'t1-p30-299-ins');
+DELETE FROM t2 PARTITION (`p0-29`);
+INSERT INTO t2 VALUES (2,'t2-p0-29-ins');
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+--sorted_result
+SELECT * FROM t2  PARTITION (`p0-29`,`p30-299`);
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`,`p30-299`), 
+t2 PARTITION (`p0-29`,`p30-299`);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+
+INSERT INTO t1 VALUES (32,'t2-p30-299-ins');
+INSERT INTO t2 VALUES (1,'t1-p0-29-ins');
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+
+--sorted_result
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+
+disconnect session1;
+connection default;
+DROP VIEW v1;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml_cr_tab.inc'
--- a/mysql-test/suite/parts/inc/partition-dml_cr_tab.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml_cr_tab.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,31 @@
+eval CREATE TABLE $TABLENAME 
+(a INT NOT NULL,
+ b varchar (64),
+ INDEX ind_$TABLENAME (b,a),
+ PRIMARY KEY (a))
+ENGINE = $ENGINE
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp1 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp2 $DATA_PATH $INDEX_PATH),
+ PARTITION `p0-29` VALUES LESS THAN (30)
+ (SUBPARTITION subp3 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp4 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp5 $DATA_PATH $INDEX_PATH),
+ PARTITION `p30-299` VALUES LESS THAN (300)
+ (SUBPARTITION subp6 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp7 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp8 $DATA_PATH $INDEX_PATH),
+ PARTITION `p300-2999` VALUES LESS THAN (3000)
+ (SUBPARTITION subp9 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp10 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp11 $DATA_PATH $INDEX_PATH),
+ PARTITION `p3000-299999` VALUES LESS THAN (300000)
+ (SUBPARTITION subp12 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp13 $DATA_PATH $INDEX_PATH,
+  SUBPARTITION subp14 $DATA_PATH $INDEX_PATH));
+
+#eval SHOW CREATE TABLE $TABLENAME;
+

=== added file 'mysql-test/suite/parts/inc/partition-dml_ins_tab.inc'
--- a/mysql-test/suite/parts/inc/partition-dml_ins_tab.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/partition-dml_ins_tab.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,40 @@
+eval INSERT INTO $TABLENAME PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+eval INSERT INTO $TABLENAME PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+eval INSERT INTO $TABLENAME PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+eval INSERT INTO $TABLENAME PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+eval INSERT INTO $TABLENAME PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+
+eval INSERT INTO $TABLENAME PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+eval INSERT INTO $TABLENAME PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+eval INSERT INTO $TABLENAME PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+

=== modified file 'mysql-test/suite/parts/inc/partition_fail.inc'
--- a/mysql-test/suite/parts/inc/partition_fail.inc	2010-10-01 13:59:07 +0000
+++ b/mysql-test/suite/parts/inc/partition_fail.inc	2011-02-02 23:23:34 +0000
@@ -23,6 +23,7 @@ DROP TABLE t1;
 --eval $create_statement
 --eval $insert_statement
 --echo # State before failure
+--replace_result #p# #P# #sp# #SP#
 --list_files $DATADIR/test
 SHOW CREATE TABLE t1;
 --sorted_result
@@ -32,6 +33,7 @@ LOCK TABLE t1 WRITE;
 --eval $fail_statement
 --enable_abort_on_error
 --echo # State after failure
+--replace_result #p# #P# #sp# #SP#
 --list_files $DATADIR/test
 SHOW CREATE TABLE t1;
 --sorted_result

=== added file 'mysql-test/suite/parts/inc/rpl-partition-dml-1-1.inc'
--- a/mysql-test/suite/parts/inc/rpl-partition-dml-1-1.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/inc/rpl-partition-dml-1-1.inc	2011-02-17 15:36:05 +0000
@@ -0,0 +1,80 @@
+let $DATA_PATH=;
+let $INDEX_PATH=;
+--source include/have_partition.inc
+--source include/master-slave.inc
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+--echo [on slave]
+connection slave;
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+# restart slave so that slave sql thread's binlog format is re-read
+# from @@global.binlog_format
+--source include/stop_slave.inc
+--source include/start_slave.inc
+
+connection master;
+
+--echo # Additional tests for WL#5217 by QA, testplan 1.1
+
+let $TABLENAME= t1;
+--source suite/parts/inc/partition-dml_cr_tab.inc
+--source suite/parts/inc/partition-dml_ins_tab.inc
+
+--enable_connect_log
+
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+--sync_slave_with_master
+--source include/check_slave_is_running.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+connection master;
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+
+--sync_slave_with_master
+--source include/check_slave_is_running.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (`p30-299`);
+
+connection master;
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+
+--sync_slave_with_master
+--source include/check_slave_is_running.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (`p300-2999`);
+
+connection master;
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+--sorted_result
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+
+--sync_slave_with_master
+--source include/check_slave_is_running.inc
+--sorted_result
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+
+connection master;
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+DROP TABLE t1;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-1-innodb-modes.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-1-innodb-modes.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-1-innodb-modes.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,655 @@
+set @save_sqlmode= @@global.sql_mode;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+# Run in empty mode
+set @@global.sql_mode= '';
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+# Run in ANSI mode
+set @@global.sql_mode= ansi;
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+# Run in traditional mode
+set @@global.sql_mode= traditional;
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+set @@global.sql_mode= @save_sqlmode;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-1-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-1-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-1-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,262 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	p3000-299999-upd
+3002	p3000-299999-upd
+3003	p3000-299999-upd
+3004	p3000-299999-upd
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-2
+2	p0-29-upd-2
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-2
+4	p0-29-upd-2
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	subp3-upd
+24	subp3-upd
+3	subp3-upd
+SELECT * FROM t1 PARTITION (subp4);
+a	b
+1	subp4-upd
+22	subp4-upd
+4	subp4-upd
+SELECT * FROM t1 PARTITION (subp5);
+a	b
+2	subp5-upd
+23	subp5-upd
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+3	subp3-upd
+21	subp3-upd
+24	subp3-upd
+1	subp4-upd
+4	subp4-upd
+22	subp4-upd
+2	subp5-upd
+23	subp5-upd
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+MUST BE TRUE (1)
+1
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+a	b
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+a	b
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+a	b
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+a	b
+SELECT * FROM t2 PARTITION (subp4);
+a	b
+SELECT * FROM t2 PARTITION (subp5);
+a	b
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+DROP USER test_user_2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-1-myisam-modes.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-1-myisam-modes.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-1-myisam-modes.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,655 @@
+set @save_sqlmode= @@global.sql_mode;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+# Run in empty mode
+set @@global.sql_mode= '';
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+# Run in ANSI mode
+set @@global.sql_mode= ansi;
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+# Run in traditional mode
+set @@global.sql_mode= traditional;
+#######################################################
+# UPDATE without partition selection
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+send
+UPDATE t1 SET b='table-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 SET b='table-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+INSERT INTO t1 VALUES (11, 'table-ins');
+INSERT INTO t1 VALUES (12, 'table-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+11	table-ins
+12	table-ins
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+DELETE FROM t1 WHERE b= 'table-ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+#######################################################
+# UPDATE with partition selection
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	table-upd-2
+2	table-upd-2
+3	table-upd-2
+4	table-upd-2
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connection session2;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (11, '(p0-29-)ins');
+INSERT INTO t1 PARTITION (`p0-29`, subp4) VALUES (12, '(p0-29-)ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+11	(p0-29-)ins
+12	(p0-29-)ins
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+DELETE FROM t1 PARTITION (`p0-29`,subp5) WHERE b= '(p0-29-)ins';
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-2
+2	p0-29-upd-2
+3	p0-29-upd-2
+4	p0-29-upd-2
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+set @@global.sql_mode= @save_sqlmode;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-1-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-1-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-1-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,262 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	p3000-299999-upd
+3002	p3000-299999-upd
+3003	p3000-299999-upd
+3004	p3000-299999-upd
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-2
+2	p0-29-upd-2
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-2
+4	p0-29-upd-2
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	subp3-upd
+24	subp3-upd
+3	subp3-upd
+SELECT * FROM t1 PARTITION (subp4);
+a	b
+1	subp4-upd
+22	subp4-upd
+4	subp4-upd
+SELECT * FROM t1 PARTITION (subp5);
+a	b
+2	subp5-upd
+23	subp5-upd
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+3	subp3-upd
+21	subp3-upd
+24	subp3-upd
+1	subp4-upd
+4	subp4-upd
+22	subp4-upd
+2	subp5-upd
+23	subp5-upd
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+MUST BE TRUE (1)
+1
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+a	b
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+a	b
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+a	b
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+a	b
+SELECT * FROM t2 PARTITION (subp4);
+a	b
+SELECT * FROM t2 PARTITION (subp5);
+a	b
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+DROP USER test_user_2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-10-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-10-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-10-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,139 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+PREPARE st1 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=''p0-29-upd-1'' WHERE a BETWEEN 0 AND 9' ;
+connect  session2, localhost, test_user_2,'testpw',test;
+PREPARE st2 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=? WHERE a BETWEEN 20 AND 29' ;
+connection session1;
+EXECUTE st1;
+connection session2;
+SET @var1= 'p0-29-upd-2';
+EXECUTE st2 USING @var1;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session1;
+COMMIT WORK;
+connection session2;
+SET @var1= 'p0-29-upd-2';
+EXECUTE st2 USING @var1;
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+DEALLOCATE PREPARE st1;
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+COMMIT WORK;
+DEALLOCATE PREPARE st2;
+connection default;
+disconnect session1;
+disconnect session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-10-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-10-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-10-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,138 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+PREPARE st1 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=''p0-29-upd-1'' WHERE a BETWEEN 0 AND 9' ;
+connect  session2, localhost, test_user_2,'testpw',test;
+PREPARE st2 FROM 'UPDATE t1 PARTITION (`p0-29`) SET b=? WHERE a BETWEEN 20 AND 29' ;
+connection session1;
+EXECUTE st1;
+connection session2;
+SET @var1= 'p0-29-upd-2';
+EXECUTE st2 USING @var1;
+connection session1;
+COMMIT WORK;
+connection session2;
+SET @var1= 'p0-29-upd-2';
+EXECUTE st2 USING @var1;
+connection session1;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+DEALLOCATE PREPARE st1;
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+COMMIT WORK;
+DEALLOCATE PREPARE st2;
+connection default;
+disconnect session1;
+disconnect session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+3	p0-29-upd-1
+4	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-11-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-11-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-11-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,206 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	p3000-299999-upd
+3002	p3000-299999-upd
+3003	p3000-299999-upd
+3004	p3000-299999-upd
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-2
+2	p0-29-upd-2
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-2
+4	p0-29-upd-2
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	subp3-upd
+24	subp3-upd
+3	subp3-upd
+SELECT * FROM t1 PARTITION (subp4);
+a	b
+1	subp4-upd
+22	subp4-upd
+4	subp4-upd
+SELECT * FROM t1 PARTITION (subp5);
+a	b
+2	subp5-upd
+23	subp5-upd
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+3	subp3-upd
+21	subp3-upd
+24	subp3-upd
+1	subp4-upd
+4	subp4-upd
+22	subp4-upd
+2	subp5-upd
+23	subp5-upd
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+MUST BE TRUE (1)
+1
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+a	b
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+a	b
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+a	b
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+a	b
+SELECT * FROM t2 PARTITION (subp4);
+a	b
+SELECT * FROM t2 PARTITION (subp5);
+a	b
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+DROP USER test_user_2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-11-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-11-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-11-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,206 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+send
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+UPDATE t1 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t1 PARTITION (`p3000-299999`);
+a	b
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+3001	p3000-299999-upd
+3002	p3000-299999-upd
+3003	p3000-299999-upd
+3004	p3000-299999-upd
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-2
+2	p0-29-upd-2
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-2
+4	p0-29-upd-2
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	subp3-upd
+24	subp3-upd
+3	subp3-upd
+SELECT * FROM t1 PARTITION (subp4);
+a	b
+1	subp4-upd
+22	subp4-upd
+4	subp4-upd
+SELECT * FROM t1 PARTITION (subp5);
+a	b
+2	subp5-upd
+23	subp5-upd
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+3	subp3-upd
+21	subp3-upd
+24	subp3-upd
+1	subp4-upd
+4	subp4-upd
+22	subp4-upd
+2	subp5-upd
+23	subp5-upd
+connection session1;
+reap
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection session2;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+SELECT 
+(SELECT count(*) FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`)) = 
+(SELECT count(*) FROM t1) as `MUST BE TRUE (1)` ;
+MUST BE TRUE (1)
+1
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+UPDATE t2 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+DELETE FROM t2 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t2 PARTITION (`p300-2999`);
+a	b
+UPDATE t2 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+DELETE FROM t2 PARTITION (`p300-2999`) WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t2 PARTITION (`p3000-299999`);
+a	b
+UPDATE t2 PARTITION (`p3000-299999`) SET b='p3000-299999-upd' WHERE a BETWEEN 3000 AND 3009;
+DELETE FROM t2 PARTITION (`p3000-299999`) WHERE a BETWEEN 3000 AND 3009;
+SELECT * FROM t2 PARTITION (`p0-29`);
+a	b
+UPDATE t2 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 0 AND 9;
+DELETE FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9;
+UPDATE t2 PARTITION (subp3) SET b='subp3-upd';
+DELETE FROM t2 PARTITION (subp3);
+UPDATE t2 PARTITION (subp4) SET b='subp4-upd';
+DELETE FROM t2 PARTITION (subp4);
+UPDATE t2 PARTITION (subp5) SET b='subp5-upd';
+DELETE FROM t2 PARTITION (subp5);
+UPDATE t2 PARTITION (subp4,subp5,subp3) SET b='subp-upd';
+DELETE FROM t2 PARTITION (subp4,subp5,subp3);
+SELECT * FROM t2 PARTITION (subp3);
+a	b
+SELECT * FROM t2 PARTITION (subp4);
+a	b
+SELECT * FROM t2 PARTITION (subp5);
+a	b
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1, t2;
+DROP USER test_user_1;
+DROP USER test_user_2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-2-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-2-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-2-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,181 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+CREATE
+PROCEDURE p1 ()
+BEGIN
+DECLARE c11,c21 int;
+DECLARE c12,c22 varchar(64);
+DECLARE cur1 CURSOR FOR SELECT * FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`) ORDER BY a,b;
+DECLARE cur2 CURSOR FOR SELECT * FROM t1 ORDER BY a,b;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET @done = 1;
+OPEN cur1;
+OPEN cur2;
+read_loop: LOOP
+FETCH cur1 INTO c11,c12;
+FETCH cur2 INTO c21,c22;
+IF !((c11=c21) AND (c12=c22)) THEN
+SELECT c11,c12,c21,c22;
+LEAVE read_loop;
+END IF;
+IF @done THEN
+LEAVE read_loop;
+END IF;
+END LOOP;
+CLOSE cur1;
+CLOSE cur2;
+END//
+CREATE PROCEDURE p2 ()
+BEGIN
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd' WHERE a BETWEEN 3 AND 10;
+END//
+CREATE PROCEDURE p3 ()
+BEGIN
+DELETE FROM t1 PARTITION (`p0-29`) WHERE b= 'p0-29-upd';
+END//
+CREATE TRIGGER tr1 AFTER INSERT ON t2
+FOR EACH ROW BEGIN
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd-trigger' WHERE a BETWEEN 30 AND 40;
+END//
+CALL p1;
+CALL p2;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+3	p0-29-upd
+4	p0-29-upd
+SELECT * FROM t1 WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+3	p0-29-upd
+4	p0-29-upd
+CALL p3;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+CALL p3;
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+SELECT * FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+4	(p0-29-)subp3
+SELECT * FROM t1 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 40 ORDER BY a,b ;
+a	b
+31	p30-299-upd-trigger
+32	p30-299-upd-trigger
+33	p30-299-upd-trigger
+34	p30-299-upd-trigger
+DELETE FROM t1 PARTITION (pneg, `p30-299`);
+SELECT * FROM t1 ORDER BY a,b;
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+########## Empty table t1 #########
+DELETE FROM t1;
+CALL p1;
+CALL p2;
+CALL p3;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+DROP PROCEDURE p3;
+DROP TRIGGER tr1;
+DROP TABLE t1;
+DROP TABLE t2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-2-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-2-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-2-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,181 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+CREATE
+PROCEDURE p1 ()
+BEGIN
+DECLARE c11,c21 int;
+DECLARE c12,c22 varchar(64);
+DECLARE cur1 CURSOR FOR SELECT * FROM t1 PARTITION (pneg,`p0-29`,`p30-299`,`p300-2999`,`p3000-299999`) ORDER BY a,b;
+DECLARE cur2 CURSOR FOR SELECT * FROM t1 ORDER BY a,b;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET @done = 1;
+OPEN cur1;
+OPEN cur2;
+read_loop: LOOP
+FETCH cur1 INTO c11,c12;
+FETCH cur2 INTO c21,c22;
+IF !((c11=c21) AND (c12=c22)) THEN
+SELECT c11,c12,c21,c22;
+LEAVE read_loop;
+END IF;
+IF @done THEN
+LEAVE read_loop;
+END IF;
+END LOOP;
+CLOSE cur1;
+CLOSE cur2;
+END//
+CREATE PROCEDURE p2 ()
+BEGIN
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd' WHERE a BETWEEN 3 AND 10;
+END//
+CREATE PROCEDURE p3 ()
+BEGIN
+DELETE FROM t1 PARTITION (`p0-29`) WHERE b= 'p0-29-upd';
+END//
+CREATE TRIGGER tr1 AFTER INSERT ON t2
+FOR EACH ROW BEGIN
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd-trigger' WHERE a BETWEEN 30 AND 40;
+END//
+CALL p1;
+CALL p2;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+3	p0-29-upd
+4	p0-29-upd
+SELECT * FROM t1 WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+3	p0-29-upd
+4	p0-29-upd
+CALL p3;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+CALL p3;
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+SELECT * FROM t2 PARTITION (`p0-29`) WHERE a BETWEEN 3 AND 10 ORDER BY a,b ;
+a	b
+4	(p0-29-)subp3
+SELECT * FROM t1 PARTITION (`p30-299`) WHERE a BETWEEN 30 AND 40 ORDER BY a,b ;
+a	b
+31	p30-299-upd-trigger
+32	p30-299-upd-trigger
+33	p30-299-upd-trigger
+34	p30-299-upd-trigger
+DELETE FROM t1 PARTITION (pneg, `p30-299`);
+SELECT * FROM t1 ORDER BY a,b;
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+########## Empty table t1 #########
+DELETE FROM t1;
+CALL p1;
+CALL p2;
+CALL p3;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+DROP PROCEDURE p3;
+DROP TRIGGER tr1;
+DROP TABLE t1;
+DROP TABLE t2;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-3-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-3-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-3-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,247 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+connect  session2, localhost, test_user_2,'testpw',test;
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd-1' WHERE a BETWEEN 30 AND 39;
+connection session1;
+####### expect only p0-29 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connection session2;
+####### expect only p30-299 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+31	p30-299-upd-1
+32	p30-299-upd-1
+33	p30-299-upd-1
+34	p30-299-upd-1
+4	(p0-29-)subp3
+connection session1;
+COMMIT WORK;
+####### expect only p0-29 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connection session2;
+####### expect only p30-299 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+31	p30-299-upd-1
+32	p30-299-upd-1
+33	p30-299-upd-1
+34	p30-299-upd-1
+4	(p0-29-)subp3
+connect  session3, localhost, test_user_3,'testpw',test;
+####### expect only p0-29 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+disconnect session3;
+connection session2;
+COMMIT WORK;
+####### expect p0-29 and p30-299 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	p30-299-upd-1
+32	p30-299-upd-1
+33	p30-299-upd-1
+34	p30-299-upd-1
+4	p0-29-upd-1
+connection session1;
+####### expect only p30-299 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+COMMIT WORK;
+####### expect p0-29 and p30-299 is updated
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	p30-299-upd-1
+32	p30-299-upd-1
+33	p30-299-upd-1
+34	p30-299-upd-1
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-4-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-4-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-4-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,146 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'serializable';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+@@global.innodb_lock_wait_timeout
+1
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connect  session2, localhost, test_user_1,'testpw',test;
+####### expect p30-299 is readable, p0-29 is locked
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+SELECT * FROM t1 PARTITION (`p0-29`);
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session1;
+COMMIT WORK;
+connection session2;
+####### expect p0-29 and p30-299 are readable
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-5-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-5-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-5-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,152 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'read-committed';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+@@global.innodb_lock_wait_timeout
+1
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connect  session2, localhost, test_user_1,'testpw',test;
+####### expect not to see the updated values
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	(p0-29-)subp3
+connection session1;
+COMMIT WORK;
+connection session2;
+####### expect to see the updated values.
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-6-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-6-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-6-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,152 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'read-uncommitted';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+SELECT @@global.innodb_lock_wait_timeout;
+@@global.innodb_lock_wait_timeout
+1
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connect  session2, localhost, test_user_1,'testpw',test;
+####### expect not to see the updated values
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+connection session1;
+COMMIT WORK;
+connection session2;
+####### expect to see the updated values.
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+24	(p0-29-)subp5
+3	p0-29-upd-1
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-7-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-7-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-7-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,199 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+DROP INDEX ind_t1 ON t1;
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9 ;
+connect  session2, localhost, test_user_2,'testpw',test;
+####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+3	(p0-29-)subp3
+21	(p0-29-)subp5
+24	(p0-29-)subp5
+1	(p0-29-)subp3
+4	(p0-29-)subp3
+22	(p0-29-)subp5
+2	(p0-29-)subp3
+23	(p0-29-)subp5
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session1;
+COMMIT WORK;
+####### expect p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection session2;
+####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 20 AND 29 ;
+connection session1;
+####### expect only p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session2;
+COMMIT WORK;
+####### expect p0-29 is completely updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection session1;
+####### expect only p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+COMMIT WORK;
+####### expect p0-29 is completely updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+3	p0-29-upd-1
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-8-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-8-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-8-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,198 @@
+SET @auto= @@global.autocommit;
+SET @@global.autocommit= off;
+SET @iso= @@global.tx_isolation;
+SET @@global.tx_isolation= 'repeatable-read';
+SET @completion= @@global.completion_type;
+SET @@global.completion_type= 'no_chain';
+SET @lock_timeout= @@global.lock_wait_timeout;
+SET @@global.lock_wait_timeout= 1;
+SELECT @@global.lock_wait_timeout;
+@@global.lock_wait_timeout
+1
+SET @innodb_lock_timeout= @@global.innodb_lock_wait_timeout;
+SET @@global.innodb_lock_wait_timeout= 1;
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_2 IDENTIFIED BY 'testpw';
+GRANT ALL PRIVILEGES ON test.* TO test_user_3 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9 ;
+connect  session2, localhost, test_user_2,'testpw',test;
+####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session1;
+COMMIT WORK;
+####### expect p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection session2;
+####### expect p0-29 has not been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+a	b
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-2' WHERE a BETWEEN 20 AND 29 ;
+connection session1;
+####### expect only p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 0 AND 9 LOCK IN SHARE MODE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM t1 PARTITION (`p0-29`) WHERE a BETWEEN 20 AND 29 FOR UPDATE;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+connection session2;
+COMMIT WORK;
+####### expect p0-29 is completely updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection session1;
+####### expect only p0-29 (0-9) has been updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+COMMIT WORK;
+####### expect p0-29 is completely updated
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	p0-29-upd-2
+22	p0-29-upd-2
+23	p0-29-upd-2
+24	p0-29-upd-2
+3	p0-29-upd-1
+4	p0-29-upd-1
+disconnect session1;
+disconnect session2;
+connection default;
+DROP TABLE t1;
+DROP USER test_user_1;
+DROP USER test_user_2;
+DROP USER test_user_3;
+SET @@global.autocommit= @auto;
+SET @@global.tx_isolation= @iso;
+SET @@global.completion_type= @completion;
+SET @@global.lock_wait_timeout= @lock_timeout;
+SET @@global.innodb_lock_wait_timeout= @innodb_lock_timeout;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-9-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-9-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-9-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,545 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+CREATE VIEW v1 AS
+SELECT t1.a, t2.b FROM t1 PARTITION (`p0-29`), t2 
+WHERE t1.a = t2.a;
+SELECT * FROM v1;
+a	b
+-4	(pNeg-)subp0
+-3	(pNeg-)subp0
+-2	(pNeg-)subp0
+-1	(pNeg-)subp0
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+1	231	(p0-29-)subp3	(p30-299-)subp8
+1	232	(p0-29-)subp3	(p30-299-)subp8
+1	233	(p0-29-)subp3	(p30-299-)subp8
+1	234	(p0-29-)subp3	(p30-299-)subp8
+1	31	(p0-29-)subp3	(p30-299-)subp6
+1	32	(p0-29-)subp3	(p30-299-)subp6
+1	33	(p0-29-)subp3	(p30-299-)subp6
+1	34	(p0-29-)subp3	(p30-299-)subp6
+2	231	(p0-29-)subp3	(p30-299-)subp8
+2	232	(p0-29-)subp3	(p30-299-)subp8
+2	233	(p0-29-)subp3	(p30-299-)subp8
+2	234	(p0-29-)subp3	(p30-299-)subp8
+2	31	(p0-29-)subp3	(p30-299-)subp6
+2	32	(p0-29-)subp3	(p30-299-)subp6
+2	33	(p0-29-)subp3	(p30-299-)subp6
+2	34	(p0-29-)subp3	(p30-299-)subp6
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	232	(p0-29-)subp5	(p30-299-)subp8
+21	233	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	31	(p0-29-)subp5	(p30-299-)subp6
+21	32	(p0-29-)subp5	(p30-299-)subp6
+21	33	(p0-29-)subp5	(p30-299-)subp6
+21	34	(p0-29-)subp5	(p30-299-)subp6
+22	231	(p0-29-)subp5	(p30-299-)subp8
+22	232	(p0-29-)subp5	(p30-299-)subp8
+22	233	(p0-29-)subp5	(p30-299-)subp8
+22	234	(p0-29-)subp5	(p30-299-)subp8
+22	31	(p0-29-)subp5	(p30-299-)subp6
+22	32	(p0-29-)subp5	(p30-299-)subp6
+22	33	(p0-29-)subp5	(p30-299-)subp6
+22	34	(p0-29-)subp5	(p30-299-)subp6
+23	231	(p0-29-)subp5	(p30-299-)subp8
+23	232	(p0-29-)subp5	(p30-299-)subp8
+23	233	(p0-29-)subp5	(p30-299-)subp8
+23	234	(p0-29-)subp5	(p30-299-)subp8
+23	31	(p0-29-)subp5	(p30-299-)subp6
+23	32	(p0-29-)subp5	(p30-299-)subp6
+23	33	(p0-29-)subp5	(p30-299-)subp6
+23	34	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	232	(p0-29-)subp5	(p30-299-)subp8
+24	233	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	31	(p0-29-)subp5	(p30-299-)subp6
+24	32	(p0-29-)subp5	(p30-299-)subp6
+24	33	(p0-29-)subp5	(p30-299-)subp6
+24	34	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	232	(p0-29-)subp3	(p30-299-)subp8
+3	233	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	31	(p0-29-)subp3	(p30-299-)subp6
+3	32	(p0-29-)subp3	(p30-299-)subp6
+3	33	(p0-29-)subp3	(p30-299-)subp6
+3	34	(p0-29-)subp3	(p30-299-)subp6
+4	231	(p0-29-)subp3	(p30-299-)subp8
+4	232	(p0-29-)subp3	(p30-299-)subp8
+4	233	(p0-29-)subp3	(p30-299-)subp8
+4	234	(p0-29-)subp3	(p30-299-)subp8
+4	31	(p0-29-)subp3	(p30-299-)subp6
+4	32	(p0-29-)subp3	(p30-299-)subp6
+4	33	(p0-29-)subp3	(p30-299-)subp6
+4	34	(p0-29-)subp3	(p30-299-)subp6
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (subp6);
+a	b
+231	(p30-299-)subp8
+234	(p30-299-)subp8
+33	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3), 
+t2 PARTITION (subp6);
+t1a	t2a	t1b	t2b
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	33	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	33	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	33	(p0-29-)subp3	(p30-299-)subp6
+SELECT * FROM t1 PARTITION (subp3,subp5);
+a	b
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (subp6,subp8);
+a	b
+231	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3,subp5), 
+t2 PARTITION (subp6,subp8);
+t1a	t2a	t1b	t2b
+2	231	(p0-29-)subp3	(p30-299-)subp8
+2	233	(p0-29-)subp3	(p30-299-)subp8
+2	234	(p0-29-)subp3	(p30-299-)subp8
+2	32	(p0-29-)subp3	(p30-299-)subp6
+2	33	(p0-29-)subp3	(p30-299-)subp6
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	233	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	32	(p0-29-)subp5	(p30-299-)subp6
+21	33	(p0-29-)subp5	(p30-299-)subp6
+23	231	(p0-29-)subp5	(p30-299-)subp8
+23	233	(p0-29-)subp5	(p30-299-)subp8
+23	234	(p0-29-)subp5	(p30-299-)subp8
+23	32	(p0-29-)subp5	(p30-299-)subp6
+23	33	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	233	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	32	(p0-29-)subp5	(p30-299-)subp6
+24	33	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	233	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	32	(p0-29-)subp3	(p30-299-)subp6
+3	33	(p0-29-)subp3	(p30-299-)subp6
+DELETE FROM t2 PARTITION (`p30-299`);
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+231	NULL	(p30-299-)subp8	NULL
+232	NULL	(p30-299-)subp8	NULL
+233	NULL	(p30-299-)subp8	NULL
+234	NULL	(p30-299-)subp8	NULL
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+31	NULL	(p30-299-)subp6	NULL
+32	NULL	(p30-299-)subp6	NULL
+33	NULL	(p30-299-)subp6	NULL
+34	NULL	(p30-299-)subp6	NULL
+4	4	(p0-29-)subp3	(p0-29-)subp3
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+t1a	t2a	t1b	t2b
+-1	NULL	(pNeg-)subp0	NULL
+-2	NULL	(pNeg-)subp0	NULL
+-3	NULL	(pNeg-)subp0	NULL
+-4	NULL	(pNeg-)subp0	NULL
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+231	NULL	(p30-299-)subp8	NULL
+232	NULL	(p30-299-)subp8	NULL
+233	NULL	(p30-299-)subp8	NULL
+234	NULL	(p30-299-)subp8	NULL
+24	24	(p0-29-)subp5	(p0-29-)subp5
+299996	NULL	(p3000-299999-)subp14	NULL
+299997	NULL	(p3000-299999-)subp14	NULL
+299998	NULL	(p3000-299999-)subp14	NULL
+299999	NULL	(p3000-299999-)subp14	NULL
+3	3	(p0-29-)subp3	(p0-29-)subp3
+3001	NULL	(p3000-299999-)subp12	NULL
+3002	NULL	(p3000-299999-)subp12	NULL
+3003	NULL	(p3000-299999-)subp12	NULL
+3004	NULL	(p3000-299999-)subp12	NULL
+301	NULL	(p300-2999-)subp8	NULL
+302	NULL	(p300-2999-)subp8	NULL
+303	NULL	(p300-2999-)subp8	NULL
+304	NULL	(p300-2999-)subp8	NULL
+31	NULL	(p30-299-)subp6	NULL
+32	NULL	(p30-299-)subp6	NULL
+33	NULL	(p30-299-)subp6	NULL
+34	NULL	(p30-299-)subp6	NULL
+4	4	(p0-29-)subp3	(p0-29-)subp3
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+4	4	(p0-29-)subp3	(p0-29-)subp3
+NULL	-1	NULL	(pNeg-)subp0
+NULL	-2	NULL	(pNeg-)subp0
+NULL	-3	NULL	(pNeg-)subp0
+NULL	-4	NULL	(pNeg-)subp0
+NULL	299996	NULL	(p3000-299999-)subp14
+NULL	299997	NULL	(p3000-299999-)subp14
+NULL	299998	NULL	(p3000-299999-)subp14
+NULL	299999	NULL	(p3000-299999-)subp14
+NULL	3001	NULL	(p3000-299999-)subp12
+NULL	3002	NULL	(p3000-299999-)subp12
+NULL	3003	NULL	(p3000-299999-)subp12
+NULL	3004	NULL	(p3000-299999-)subp12
+NULL	301	NULL	(p300-2999-)subp8
+NULL	302	NULL	(p300-2999-)subp8
+NULL	303	NULL	(p300-2999-)subp8
+NULL	304	NULL	(p300-2999-)subp8
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+4	4	(p0-29-)subp3	(p0-29-)subp3
+DELETE FROM t1 PARTITION (`p0-29`);
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+INSERT INTO t1 VALUES (1,'t1-p0-29-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	t1-p0-29-ins
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+INSERT INTO t2 VALUES (32,'t2-p30-299-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	t1-p0-29-ins
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+32	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+1	32	t1-p0-29-ins	t2-p30-299-ins
+DELETE FROM t1 PARTITION (`p30-299`);
+INSERT INTO t1 VALUES (31,'t1-p30-299-ins');
+DELETE FROM t2 PARTITION (`p0-29`);
+INSERT INTO t2 VALUES (2,'t2-p0-29-ins');
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	t1-p0-29-ins
+31	t1-p30-299-ins
+SELECT * FROM t2  PARTITION (`p0-29`,`p30-299`);
+a	b
+2	t2-p0-29-ins
+32	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`,`p30-299`), 
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	NULL	t1-p0-29-ins	NULL
+31	NULL	t1-p30-299-ins	NULL
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+NULL	2	NULL	t2-p0-29-ins
+NULL	32	NULL	t2-p30-299-ins
+INSERT INTO t1 VALUES (32,'t2-p30-299-ins');
+INSERT INTO t2 VALUES (1,'t1-p0-29-ins');
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	t1-p0-29-ins	t1-p0-29-ins
+32	32	t2-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	1	t1-p0-29-ins	t1-p0-29-ins
+32	32	t2-p30-299-ins	t2-p30-299-ins
+disconnect session1;
+connection default;
+DROP VIEW v1;
+DROP TABLE t1, t2;
+DROP USER test_user_1;

=== added file 'mysql-test/suite/parts/r/partition-dml-1-9-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-9-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-9-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,545 @@
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+CREATE TABLE t2 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t2 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t2 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+GRANT ALL PRIVILEGES ON test.* TO test_user_1 IDENTIFIED BY 'testpw';
+connect  session1, localhost, test_user_1,'testpw',test;
+CREATE VIEW v1 AS
+SELECT t1.a, t2.b FROM t1 PARTITION (`p0-29`), t2 
+WHERE t1.a = t2.a;
+SELECT * FROM v1;
+a	b
+-4	(pNeg-)subp0
+-3	(pNeg-)subp0
+-2	(pNeg-)subp0
+-1	(pNeg-)subp0
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+301	(p300-2999-)subp8
+302	(p300-2999-)subp8
+303	(p300-2999-)subp8
+304	(p300-2999-)subp8
+3001	(p3000-299999-)subp12
+3002	(p3000-299999-)subp12
+3003	(p3000-299999-)subp12
+3004	(p3000-299999-)subp12
+299996	(p3000-299999-)subp14
+299997	(p3000-299999-)subp14
+299998	(p3000-299999-)subp14
+299999	(p3000-299999-)subp14
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	(p30-299-)subp6
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+34	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+1	231	(p0-29-)subp3	(p30-299-)subp8
+1	232	(p0-29-)subp3	(p30-299-)subp8
+1	233	(p0-29-)subp3	(p30-299-)subp8
+1	234	(p0-29-)subp3	(p30-299-)subp8
+1	31	(p0-29-)subp3	(p30-299-)subp6
+1	32	(p0-29-)subp3	(p30-299-)subp6
+1	33	(p0-29-)subp3	(p30-299-)subp6
+1	34	(p0-29-)subp3	(p30-299-)subp6
+2	231	(p0-29-)subp3	(p30-299-)subp8
+2	232	(p0-29-)subp3	(p30-299-)subp8
+2	233	(p0-29-)subp3	(p30-299-)subp8
+2	234	(p0-29-)subp3	(p30-299-)subp8
+2	31	(p0-29-)subp3	(p30-299-)subp6
+2	32	(p0-29-)subp3	(p30-299-)subp6
+2	33	(p0-29-)subp3	(p30-299-)subp6
+2	34	(p0-29-)subp3	(p30-299-)subp6
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	232	(p0-29-)subp5	(p30-299-)subp8
+21	233	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	31	(p0-29-)subp5	(p30-299-)subp6
+21	32	(p0-29-)subp5	(p30-299-)subp6
+21	33	(p0-29-)subp5	(p30-299-)subp6
+21	34	(p0-29-)subp5	(p30-299-)subp6
+22	231	(p0-29-)subp5	(p30-299-)subp8
+22	232	(p0-29-)subp5	(p30-299-)subp8
+22	233	(p0-29-)subp5	(p30-299-)subp8
+22	234	(p0-29-)subp5	(p30-299-)subp8
+22	31	(p0-29-)subp5	(p30-299-)subp6
+22	32	(p0-29-)subp5	(p30-299-)subp6
+22	33	(p0-29-)subp5	(p30-299-)subp6
+22	34	(p0-29-)subp5	(p30-299-)subp6
+23	231	(p0-29-)subp5	(p30-299-)subp8
+23	232	(p0-29-)subp5	(p30-299-)subp8
+23	233	(p0-29-)subp5	(p30-299-)subp8
+23	234	(p0-29-)subp5	(p30-299-)subp8
+23	31	(p0-29-)subp5	(p30-299-)subp6
+23	32	(p0-29-)subp5	(p30-299-)subp6
+23	33	(p0-29-)subp5	(p30-299-)subp6
+23	34	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	232	(p0-29-)subp5	(p30-299-)subp8
+24	233	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	31	(p0-29-)subp5	(p30-299-)subp6
+24	32	(p0-29-)subp5	(p30-299-)subp6
+24	33	(p0-29-)subp5	(p30-299-)subp6
+24	34	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	232	(p0-29-)subp3	(p30-299-)subp8
+3	233	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	31	(p0-29-)subp3	(p30-299-)subp6
+3	32	(p0-29-)subp3	(p30-299-)subp6
+3	33	(p0-29-)subp3	(p30-299-)subp6
+3	34	(p0-29-)subp3	(p30-299-)subp6
+4	231	(p0-29-)subp3	(p30-299-)subp8
+4	232	(p0-29-)subp3	(p30-299-)subp8
+4	233	(p0-29-)subp3	(p30-299-)subp8
+4	234	(p0-29-)subp3	(p30-299-)subp8
+4	31	(p0-29-)subp3	(p30-299-)subp6
+4	32	(p0-29-)subp3	(p30-299-)subp6
+4	33	(p0-29-)subp3	(p30-299-)subp6
+4	34	(p0-29-)subp3	(p30-299-)subp6
+SELECT * FROM t1 PARTITION (subp3);
+a	b
+21	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (subp6);
+a	b
+231	(p30-299-)subp8
+234	(p30-299-)subp8
+33	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3), 
+t2 PARTITION (subp6);
+t1a	t2a	t1b	t2b
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	33	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	33	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	33	(p0-29-)subp3	(p30-299-)subp6
+SELECT * FROM t1 PARTITION (subp3,subp5);
+a	b
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+SELECT * FROM t2 PARTITION (subp6,subp8);
+a	b
+231	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+32	(p30-299-)subp6
+33	(p30-299-)subp6
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (subp3,subp5), 
+t2 PARTITION (subp6,subp8);
+t1a	t2a	t1b	t2b
+2	231	(p0-29-)subp3	(p30-299-)subp8
+2	233	(p0-29-)subp3	(p30-299-)subp8
+2	234	(p0-29-)subp3	(p30-299-)subp8
+2	32	(p0-29-)subp3	(p30-299-)subp6
+2	33	(p0-29-)subp3	(p30-299-)subp6
+21	231	(p0-29-)subp5	(p30-299-)subp8
+21	233	(p0-29-)subp5	(p30-299-)subp8
+21	234	(p0-29-)subp5	(p30-299-)subp8
+21	32	(p0-29-)subp5	(p30-299-)subp6
+21	33	(p0-29-)subp5	(p30-299-)subp6
+23	231	(p0-29-)subp5	(p30-299-)subp8
+23	233	(p0-29-)subp5	(p30-299-)subp8
+23	234	(p0-29-)subp5	(p30-299-)subp8
+23	32	(p0-29-)subp5	(p30-299-)subp6
+23	33	(p0-29-)subp5	(p30-299-)subp6
+24	231	(p0-29-)subp5	(p30-299-)subp8
+24	233	(p0-29-)subp5	(p30-299-)subp8
+24	234	(p0-29-)subp5	(p30-299-)subp8
+24	32	(p0-29-)subp5	(p30-299-)subp6
+24	33	(p0-29-)subp5	(p30-299-)subp6
+3	231	(p0-29-)subp3	(p30-299-)subp8
+3	233	(p0-29-)subp3	(p30-299-)subp8
+3	234	(p0-29-)subp3	(p30-299-)subp8
+3	32	(p0-29-)subp3	(p30-299-)subp6
+3	33	(p0-29-)subp3	(p30-299-)subp6
+DELETE FROM t2 PARTITION (`p30-299`);
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+231	NULL	(p30-299-)subp8	NULL
+232	NULL	(p30-299-)subp8	NULL
+233	NULL	(p30-299-)subp8	NULL
+234	NULL	(p30-299-)subp8	NULL
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+31	NULL	(p30-299-)subp6	NULL
+32	NULL	(p30-299-)subp6	NULL
+33	NULL	(p30-299-)subp6	NULL
+34	NULL	(p30-299-)subp6	NULL
+4	4	(p0-29-)subp3	(p0-29-)subp3
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+t1a	t2a	t1b	t2b
+-1	NULL	(pNeg-)subp0	NULL
+-2	NULL	(pNeg-)subp0	NULL
+-3	NULL	(pNeg-)subp0	NULL
+-4	NULL	(pNeg-)subp0	NULL
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+231	NULL	(p30-299-)subp8	NULL
+232	NULL	(p30-299-)subp8	NULL
+233	NULL	(p30-299-)subp8	NULL
+234	NULL	(p30-299-)subp8	NULL
+24	24	(p0-29-)subp5	(p0-29-)subp5
+299996	NULL	(p3000-299999-)subp14	NULL
+299997	NULL	(p3000-299999-)subp14	NULL
+299998	NULL	(p3000-299999-)subp14	NULL
+299999	NULL	(p3000-299999-)subp14	NULL
+3	3	(p0-29-)subp3	(p0-29-)subp3
+3001	NULL	(p3000-299999-)subp12	NULL
+3002	NULL	(p3000-299999-)subp12	NULL
+3003	NULL	(p3000-299999-)subp12	NULL
+3004	NULL	(p3000-299999-)subp12	NULL
+301	NULL	(p300-2999-)subp8	NULL
+302	NULL	(p300-2999-)subp8	NULL
+303	NULL	(p300-2999-)subp8	NULL
+304	NULL	(p300-2999-)subp8	NULL
+31	NULL	(p30-299-)subp6	NULL
+32	NULL	(p30-299-)subp6	NULL
+33	NULL	(p30-299-)subp6	NULL
+34	NULL	(p30-299-)subp6	NULL
+4	4	(p0-29-)subp3	(p0-29-)subp3
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+4	4	(p0-29-)subp3	(p0-29-)subp3
+NULL	-1	NULL	(pNeg-)subp0
+NULL	-2	NULL	(pNeg-)subp0
+NULL	-3	NULL	(pNeg-)subp0
+NULL	-4	NULL	(pNeg-)subp0
+NULL	299996	NULL	(p3000-299999-)subp14
+NULL	299997	NULL	(p3000-299999-)subp14
+NULL	299998	NULL	(p3000-299999-)subp14
+NULL	299999	NULL	(p3000-299999-)subp14
+NULL	3001	NULL	(p3000-299999-)subp12
+NULL	3002	NULL	(p3000-299999-)subp12
+NULL	3003	NULL	(p3000-299999-)subp12
+NULL	3004	NULL	(p3000-299999-)subp12
+NULL	301	NULL	(p300-2999-)subp8
+NULL	302	NULL	(p300-2999-)subp8
+NULL	303	NULL	(p300-2999-)subp8
+NULL	304	NULL	(p300-2999-)subp8
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`) 
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	(p0-29-)subp3	(p0-29-)subp3
+2	2	(p0-29-)subp3	(p0-29-)subp3
+21	21	(p0-29-)subp5	(p0-29-)subp5
+22	22	(p0-29-)subp5	(p0-29-)subp5
+23	23	(p0-29-)subp5	(p0-29-)subp5
+24	24	(p0-29-)subp5	(p0-29-)subp5
+3	3	(p0-29-)subp3	(p0-29-)subp3
+4	4	(p0-29-)subp3	(p0-29-)subp3
+DELETE FROM t1 PARTITION (`p0-29`);
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+INSERT INTO t1 VALUES (1,'t1-p0-29-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	t1-p0-29-ins
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+INSERT INTO t2 VALUES (32,'t2-p30-299-ins');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	t1-p0-29-ins
+SELECT * FROM t2  PARTITION (`p30-299`);
+a	b
+32	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`), 
+t2 PARTITION (`p30-299`);
+t1a	t2a	t1b	t2b
+1	32	t1-p0-29-ins	t2-p30-299-ins
+DELETE FROM t1 PARTITION (`p30-299`);
+INSERT INTO t1 VALUES (31,'t1-p30-299-ins');
+DELETE FROM t2 PARTITION (`p0-29`);
+INSERT INTO t2 VALUES (2,'t2-p0-29-ins');
+SELECT * FROM t1 PARTITION (`p0-29`,`p30-299`);
+a	b
+1	t1-p0-29-ins
+31	t1-p30-299-ins
+SELECT * FROM t2  PARTITION (`p0-29`,`p30-299`);
+a	b
+2	t2-p0-29-ins
+32	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM t1 PARTITION (`p0-29`,`p30-299`), 
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	2	t1-p0-29-ins	t2-p0-29-ins
+1	32	t1-p0-29-ins	t2-p30-299-ins
+31	2	t1-p30-299-ins	t2-p0-29-ins
+31	32	t1-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+LEFT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	NULL	t1-p0-29-ins	NULL
+31	NULL	t1-p30-299-ins	NULL
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+RIGHT JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+NULL	2	NULL	t2-p0-29-ins
+NULL	32	NULL	t2-p30-299-ins
+INSERT INTO t1 VALUES (32,'t2-p30-299-ins');
+INSERT INTO t2 VALUES (1,'t1-p0-29-ins');
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+INNER JOIN
+t2 PARTITION (`p0-29`,`p30-299`)
+USING (a,b);
+t1a	t2a	t1b	t2b
+1	1	t1-p0-29-ins	t1-p0-29-ins
+32	32	t2-p30-299-ins	t2-p30-299-ins
+SELECT t1.a AS t1a,t2.a AS t2a,t1.b AS t1b,t2.b AS t2b FROM 
+t1 PARTITION (`p0-29`,`p30-299`) 
+NATURAL JOIN
+t2 PARTITION (`p0-29`,`p30-299`);
+t1a	t2a	t1b	t2b
+1	1	t1-p0-29-ins	t1-p0-29-ins
+32	32	t2-p30-299-ins	t2-p30-299-ins
+disconnect session1;
+connection default;
+DROP VIEW v1;
+DROP TABLE t1, t2;
+DROP USER test_user_1;

=== 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

=== added file 'mysql-test/suite/parts/r/rpl-partition-dml-1-1-innodb.result'
--- a/mysql-test/suite/parts/r/rpl-partition-dml-1-1-innodb.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/rpl-partition-dml-1-1-innodb.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,217 @@
+include/master-slave.inc
+[connection master]
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format	@@session.binlog_format
+ROW	ROW
+[on slave]
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format	@@session.binlog_format
+ROW	ROW
+include/stop_slave.inc
+include/start_slave.inc
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = InnoDB
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection master;
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+connection master;
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+connection master;
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+connection master;
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+DROP TABLE t1;
+include/rpl_end.inc
+connection server_2;
+connection server_2;
+connection server_2;
+connection server_2;
+connection server_1;
+connection server_1;
+connection server_1;
+connection server_2;
+connection server_1;
+connection server_2;
+connection server_2;
+connection server_1;
+connection server_1;
+connection server_1;
+connection default;
+disconnect server_2;
+disconnect server_2_1;
+disconnect server_1;
+disconnect server_1_1;

=== added file 'mysql-test/suite/parts/r/rpl-partition-dml-1-1-myisam.result'
--- a/mysql-test/suite/parts/r/rpl-partition-dml-1-1-myisam.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/r/rpl-partition-dml-1-1-myisam.result	2011-02-17 15:36:05 +0000
@@ -0,0 +1,217 @@
+include/master-slave.inc
+[connection master]
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format	@@session.binlog_format
+ROW	ROW
+[on slave]
+set @old_global_binlog_format=  @@global.binlog_format;
+set @old_session_binlog_format=  @@session.binlog_format;
+SET GLOBAL binlog_format = 'ROW';
+SET SESSION binlog_format = 'ROW';
+select @@global.binlog_format, @@session.binlog_format;
+@@global.binlog_format	@@session.binlog_format
+ROW	ROW
+include/stop_slave.inc
+include/start_slave.inc
+# Additional tests for WL#5217 by QA, testplan 1.1
+CREATE TABLE t1 
+(a INT NOT NULL,
+b varchar (64),
+INDEX ind_t1 (b,a),
+PRIMARY KEY (a))
+ENGINE = MyISAM
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+(SUBPARTITION subp0  ,
+SUBPARTITION subp1  ,
+SUBPARTITION subp2  ),
+PARTITION `p0-29` VALUES LESS THAN (30)
+(SUBPARTITION subp3  ,
+SUBPARTITION subp4  ,
+SUBPARTITION subp5  ),
+PARTITION `p30-299` VALUES LESS THAN (300)
+(SUBPARTITION subp6  ,
+SUBPARTITION subp7  ,
+SUBPARTITION subp8  ),
+PARTITION `p300-2999` VALUES LESS THAN (3000)
+(SUBPARTITION subp9  ,
+SUBPARTITION subp10  ,
+SUBPARTITION subp11  ),
+PARTITION `p3000-299999` VALUES LESS THAN (300000)
+(SUBPARTITION subp12  ,
+SUBPARTITION subp13  ,
+SUBPARTITION subp14  ));
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-4, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-3, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-2, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (pNeg, subp0) VALUES (-1, '(pNeg-)subp0');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (4, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (3, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (2, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp3) VALUES (1, '(p0-29-)subp3');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (24, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (23, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (22, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p0-29`, subp5) VALUES (21, '(p0-29-)subp5');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (34, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (33, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (32, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp9) VALUES (31, '(p30-299-)subp6');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (234, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (233, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (232, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p30-299`, subp8) VALUES (231, '(p30-299-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (304, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (303, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (302, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p300-2999`, subp8) VALUES (301, '(p300-2999-)subp8');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3004, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3003, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3002, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp12) VALUES (3001, '(p3000-299999-)subp12');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299996, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299997, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299998, '(p3000-299999-)subp14');
+INSERT INTO t1 PARTITION (`p3000-299999`, subp14) VALUES (299999, '(p3000-299999-)subp14');
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	(p0-29-)subp3
+2	(p0-29-)subp3
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	(p0-29-)subp3
+4	(p0-29-)subp3
+UPDATE t1 PARTITION (`p0-29`) SET b='p0-29-upd-1' WHERE a BETWEEN 0 AND 9;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p0-29`);
+a	b
+1	p0-29-upd-1
+2	p0-29-upd-1
+21	(p0-29-)subp5
+22	(p0-29-)subp5
+23	(p0-29-)subp5
+24	(p0-29-)subp5
+3	p0-29-upd-1
+4	p0-29-upd-1
+connection master;
+UPDATE t1 PARTITION (`p30-299`) SET b='p30-299-upd' WHERE a BETWEEN 30 AND 39;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p30-299`);
+a	b
+231	(p30-299-)subp8
+232	(p30-299-)subp8
+233	(p30-299-)subp8
+234	(p30-299-)subp8
+31	p30-299-upd
+32	p30-299-upd
+33	p30-299-upd
+34	p30-299-upd
+connection master;
+UPDATE t1 PARTITION (`p300-2999`) SET b='p300-2999-upd' WHERE a BETWEEN 300 AND 309;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (`p300-2999`);
+a	b
+301	p300-2999-upd
+302	p300-2999-upd
+303	p300-2999-upd
+304	p300-2999-upd
+connection master;
+UPDATE t1 PARTITION (subp3) SET b='subp3-upd';
+UPDATE t1 PARTITION (subp4) SET b='subp4-upd';
+UPDATE t1 PARTITION (subp5) SET b='subp5-upd';
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+connection slave;
+include/check_slave_is_running.inc
+connection slave;
+connection slave;
+connection slave;
+SELECT * FROM t1 PARTITION (subp4,subp5,subp3) order by b,a;
+a	b
+1	subp4-upd
+2	subp5-upd
+21	subp3-upd
+22	subp4-upd
+23	subp5-upd
+24	subp3-upd
+3	subp3-upd
+4	subp4-upd
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+connection master;
+set @@global.binlog_format=  @old_global_binlog_format;
+set @@session.binlog_format=  @old_session_binlog_format;
+DROP TABLE t1;
+include/rpl_end.inc
+connection server_2;
+connection server_2;
+connection server_2;
+connection server_2;
+connection server_1;
+connection server_1;
+connection server_1;
+connection server_2;
+connection server_1;
+connection server_2;
+connection server_2;
+connection server_1;
+connection server_1;
+connection server_1;
+connection default;
+disconnect server_2;
+disconnect server_2_1;
+disconnect server_1;
+disconnect server_1_1;

=== added file 'mysql-test/suite/parts/t/partition-dml-1-1-innodb-modes.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-1-innodb-modes.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-1-innodb-modes.test	2011-02-19 21:36:09 +0000
@@ -0,0 +1,12 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+set @save_sqlmode= @@global.sql_mode;
+let $ENGINE=InnoDB;
+--source include/have_innodb.inc
+# Fails on --embedded-server because of bug#11791877.
+--source include/not_embedded.inc
+--source suite/parts/inc/partition-dml-1-1-modes.inc
+set @@global.sql_mode= @save_sqlmode;
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-1-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-1-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-1-innodb.test	2011-02-19 21:36:09 +0000
@@ -0,0 +1,10 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=InnoDB;
+--source include/have_innodb.inc
+# Fails on --embedded-server because of bug#11791877.
+--source include/not_embedded.inc
+--source suite/parts/inc/partition-dml-1-1.inc
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-1-myisam-modes.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-1-myisam-modes.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-1-myisam-modes.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,9 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+set @save_sqlmode= @@global.sql_mode;
+let $ENGINE=MyISAM;
+--source suite/parts/inc/partition-dml-1-1-modes.inc
+set @@global.sql_mode= @save_sqlmode;
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-1-myisam.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-1-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-1-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,7 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=MyISAM;
+--source suite/parts/inc/partition-dml-1-1.inc
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-10-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-10-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-10-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-10.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-10-myisam.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-10-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-10-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,2 @@
+let $engine= MyISAM;
+--source suite/parts/inc/partition-dml-1-10.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-11-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-11-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-11-innodb.test	2011-02-19 21:36:09 +0000
@@ -0,0 +1,10 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=InnoDB;
+--source include/have_innodb.inc
+# Fails on --embedded-server because of bug#11791877.
+--source include/not_embedded.inc
+--source suite/parts/inc/partition-dml-1-11.inc
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-11-myisam.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-11-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-11-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,7 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=MyISAM;
+--source suite/parts/inc/partition-dml-1-11.inc
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-2-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-2-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-2-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-2.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-2-myisam.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-2-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-2-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,2 @@
+let $engine= MyISAM;
+--source suite/parts/inc/partition-dml-1-2.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-3-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-3-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-3-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-3.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-4-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-4-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-4-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-4.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-5-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-5-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-5-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-5.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-6-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-6-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-6-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-6.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-7-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-7-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-7-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-7.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-8-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-8-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-8-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,3 @@
+let $engine= InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-8.inc

=== added file 'mysql-test/suite/parts/t/partition-dml-1-9-innodb.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-9-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-9-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,8 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/partition-dml-1-9.inc
+

=== added file 'mysql-test/suite/parts/t/partition-dml-1-9-myisam.test'
--- a/mysql-test/suite/parts/t/partition-dml-1-9-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/partition-dml-1-9-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,7 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=MyISAM;
+--source suite/parts/inc/partition-dml-1-9.inc
+

=== 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_exch_qa_14.test'
--- a/mysql-test/suite/parts/t/partition_exch_qa_14.test	2011-01-24 11:51:30 +0000
+++ b/mysql-test/suite/parts/t/partition_exch_qa_14.test	2011-02-19 21:36:09 +0000
@@ -3,6 +3,7 @@
 
 --source include/not_windows.inc
 --source include/have_partition.inc
+--source include/have_symlink.inc
 
 let $engine_table= MYISAM;
 let $engine_part= MYISAM;

=== 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/suite/parts/t/rpl-partition-dml-1-1-innodb.test'
--- a/mysql-test/suite/parts/t/rpl-partition-dml-1-1-innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/rpl-partition-dml-1-1-innodb.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,9 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=InnoDB;
+--source include/have_innodb.inc
+--source suite/parts/inc/rpl-partition-dml-1-1.inc
+--source include/rpl_end.inc
+

=== added file 'mysql-test/suite/parts/t/rpl-partition-dml-1-1-myisam.test'
--- a/mysql-test/suite/parts/t/rpl-partition-dml-1-1-myisam.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/parts/t/rpl-partition-dml-1-1-myisam.test	2011-02-17 15:36:05 +0000
@@ -0,0 +1,7 @@
+# Test of explicit partition selection in dml statements (wl5217)
+# Creation date: 01-07-10
+# Author: Horst Hunger
+
+let $ENGINE=MyISAM;
+--source suite/parts/inc/rpl-partition-dml-1-1.inc
+--source include/rpl_end.inc

=== modified file 'mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result'
--- a/mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result	2011-02-22 05:37:44 +0000
@@ -31,7 +31,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_table";
 Tables_in_performance_schema (user_table)
@@ -67,7 +67,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_view";
 Tables_in_performance_schema (user_view)
@@ -101,7 +101,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -135,7 +135,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -169,7 +169,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.event where db='performance_schema';
 name

=== modified file 'mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result'
--- a/mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result	2011-02-22 05:37:44 +0000
@@ -31,7 +31,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_table";
 Tables_in_performance_schema (user_table)
@@ -67,7 +67,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_view";
 Tables_in_performance_schema (user_view)
@@ -101,7 +101,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -135,7 +135,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -169,7 +169,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.event where db='performance_schema';
 name

=== modified file 'mysql-test/suite/perfschema/r/pfs_upgrade_lc2.result'
--- a/mysql-test/suite/perfschema/r/pfs_upgrade_lc2.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/pfs_upgrade_lc2.result	2011-02-22 02:58:40 +0000
@@ -31,7 +31,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_table";
 Tables_in_performance_schema (user_table)
@@ -67,7 +67,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_view";
 Tables_in_performance_schema (user_view)
@@ -101,7 +101,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -135,7 +135,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -169,7 +169,7 @@ ERROR 1050 (42S01) at line 341: Table 't
 ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
 ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1644 (HY000) at line 904: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.event where db='performance_schema';
 name

=== added file 'mysql-test/suite/sys_vars/r/core_file_basic.result'
--- a/mysql-test/suite/sys_vars/r/core_file_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/core_file_basic.result	2011-02-10 04:52:55 +0000
@@ -0,0 +1,6 @@
+SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE '%core%';
+VARIABLE_NAME	VARIABLE_VALUE
+CORE_FILE	ON
+SHOW GLOBAL VARIABLES LIKE '%core%';
+Variable_name	Value
+core_file	ON

=== modified file 'mysql-test/suite/sys_vars/r/slow_query_log_func.result'
--- a/mysql-test/suite/sys_vars/r/slow_query_log_func.result	2010-08-30 06:38:09 +0000
+++ b/mysql-test/suite/sys_vars/r/slow_query_log_func.result	2011-01-06 13:21:47 +0000
@@ -14,12 +14,17 @@ count(*)
 '----When slow_query_log = ON-----'
 SET @@global.slow_query_log = ON;
 TRUNCATE mysql.slow_log;
-SELECT sleep(2);
-sleep(2)
+SELECT sleep(2) AS bug53630;
+bug53630
 0
-SELECT count(*) > 0 FROM mysql.slow_log;
+SELECT count(*) > 0 FROM mysql.slow_log WHERE sql_text LIKE '% bug53630';
 count(*) > 0
 1
+SELECT thread_id - connection_id() FROM mysql.slow_log
+WHERE sql_text LIKE '% bug53630'
+                                   ORDER BY start_time DESC LIMIT 1;
+thread_id - connection_id()
+0
 'Bug#47905 stored procedures not logged correctly to slow query log'
 TRUNCATE mysql.slow_log;
 CREATE PROCEDURE p_test() 

=== added file 'mysql-test/suite/sys_vars/t/core_file_basic-master.opt'
--- a/mysql-test/suite/sys_vars/t/core_file_basic-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/core_file_basic-master.opt	2011-02-10 04:52:55 +0000
@@ -0,0 +1,2 @@
+--core-file
+

=== added file 'mysql-test/suite/sys_vars/t/core_file_basic.test'
--- a/mysql-test/suite/sys_vars/t/core_file_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/core_file_basic.test	2011-02-10 04:52:55 +0000
@@ -0,0 +1,2 @@
+SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE '%core%';
+SHOW GLOBAL VARIABLES LIKE '%core%';

=== modified file 'mysql-test/suite/sys_vars/t/slow_query_log_func.test'
--- a/mysql-test/suite/sys_vars/t/slow_query_log_func.test	2010-06-08 08:58:19 +0000
+++ b/mysql-test/suite/sys_vars/t/slow_query_log_func.test	2011-01-06 13:21:47 +0000
@@ -27,10 +27,12 @@ SELECT count(*) FROM mysql.slow_log;
 SET @@global.slow_query_log = ON;
 TRUNCATE mysql.slow_log;
 # The sleep is the slow query
-SELECT sleep(2);
-
-SELECT count(*) > 0 FROM mysql.slow_log;
+SELECT sleep(2) AS bug53630;
 
+SELECT count(*) > 0 FROM mysql.slow_log WHERE sql_text LIKE '% bug53630';
+SELECT thread_id - connection_id() FROM mysql.slow_log
+                                   WHERE sql_text LIKE '% bug53630'
+                                   ORDER BY start_time DESC LIMIT 1;
 
 #==========================================================================
 --echo 'Bug#47905 stored procedures not logged correctly to slow query log'

=== modified file 'mysql-test/t/alter_table.test'
--- a/mysql-test/t/alter_table.test	2010-07-26 09:22:38 +0000
+++ b/mysql-test/t/alter_table.test	2011-02-21 11:30:08 +0000
@@ -1144,3 +1144,18 @@ INSERT INTO t1 VALUES (1, 1), (2, 2);
 ALTER TABLE t1 CHANGE a id INT;
 --disable_info
 DROP TABLE t1;
+
+
+--echo #
+--echo # Bug#11754461 CANNOT ALTER TABLE WHEN KEY PREFIX TOO LONG
+--echo #
+
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+
+CREATE DATABASE db1 CHARACTER SET utf8;
+CREATE TABLE db1.t1 (bar TINYTEXT, KEY (bar(100)));
+ALTER TABLE db1.t1 ADD baz INT;
+
+DROP DATABASE db1;

=== modified file 'mysql-test/t/func_time.test'
--- a/mysql-test/t/func_time.test	2011-02-02 18:31:39 +0000
+++ b/mysql-test/t/func_time.test	2011-02-21 08:23:02 +0000
@@ -902,4 +902,11 @@ SELECT WEEK(STR_TO_DATE(NULL,0));
 SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR);
 
 --echo #
+--echo # BUG#59895 - setting storage engine to null segfaults mysqld
+--echo #
+SELECT MONTHNAME(0), MONTHNAME(0) IS NULL, MONTHNAME(0) + 1;
+--error ER_WRONG_VALUE_FOR_VAR
+SET storage_engine=NULL;
+
+--echo #
 

=== modified file 'mysql-test/t/log_state.test'
--- a/mysql-test/t/log_state.test	2010-11-02 11:53:54 +0000
+++ b/mysql-test/t/log_state.test	2011-02-10 11:13:41 +0000
@@ -48,7 +48,7 @@ connection con1;
 set @long_query_time = 2;
 set session long_query_time = @long_query_time;
 select sleep(@long_query_time + 1);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 11 QUERY 12 THREAD_ID
 select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
 --echo # Switch to connection default
 connection default;
@@ -58,7 +58,7 @@ set global slow_query_log= ON;
 connection con1;
 set session long_query_time = @long_query_time;
 select sleep(@long_query_time + 1);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 11 QUERY 12 THREAD_ID
 select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
 --echo # Switch to connection default
 connection default;

=== modified file 'mysql-test/t/log_tables.test'
--- a/mysql-test/t/log_tables.test	2010-11-08 14:35:45 +0000
+++ b/mysql-test/t/log_tables.test	2011-02-22 05:37:44 +0000
@@ -180,7 +180,7 @@ drop table bug16905;
 truncate table mysql.slow_log;
 set session long_query_time=1;
 select sleep(2);
---replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
+--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 11 QUERY 12 THREAD_ID
 select * from mysql.slow_log;
 set @@session.long_query_time = @saved_long_query_time;
 
@@ -311,7 +311,8 @@ CREATE TABLE `slow_log` (
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
-  `sql_text` mediumtext NOT NULL
+  `sql_text` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL
 ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
 
 set global general_log='ON';
@@ -471,77 +472,6 @@ drop table slow_log_new, general_log_new
 use test;
 
 #
-# Bug#27857 (Log tables supplies the wrong value for generating
-#            AUTO_INCREMENT numbers)
-#
-
-SET GLOBAL LOG_OUTPUT = 'TABLE';
-
-## test the general log
-
-SET GLOBAL general_log = 0;
-FLUSH LOGS;
-
-TRUNCATE TABLE mysql.general_log;
-ALTER TABLE mysql.general_log ENGINE = MyISAM;
-ALTER TABLE mysql.general_log
-  ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
-
-SET GLOBAL general_log = 1;
-FLUSH LOGS;
-
---replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
-SELECT * FROM mysql.general_log;
---replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
-SELECT * FROM mysql.general_log;
-SELECT "My own query 1";
-SELECT "My own query 2";
---replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
-SELECT * FROM mysql.general_log;
-
-SET GLOBAL general_log = 0;
-FLUSH LOGS;
-
-ALTER TABLE mysql.general_log DROP COLUMN seq;
-ALTER TABLE mysql.general_log ENGINE = CSV;
-
-## test the slow query log
-
-SET GLOBAL slow_query_log = 0;
-FLUSH LOGS;
-
-TRUNCATE TABLE mysql.slow_log;
-ALTER TABLE mysql.slow_log ENGINE = MyISAM;
-
-ALTER TABLE mysql.slow_log
-  ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
-
-SET SESSION long_query_time = 1;
-SET GLOBAL slow_query_log = 1;
-FLUSH LOGS;
-
-## FLUSH LOGS above might be slow, so the following is
-## logged as either seq 1-4 or seq 2-5
-SELECT "My own slow query", sleep(2);
-SELECT "My own slow query", sleep(2);
-SELECT "My own slow query", sleep(2);
-SELECT "My own slow query", sleep(2);
-
-## So we look for seq 2-4
---replace_column 1 START_TIME 2 USER_HOST 3 QUERY_TIME
-SELECT * FROM mysql.slow_log WHERE seq >= 2 LIMIT 3;
-
-SET GLOBAL slow_query_log = 0;
-SET SESSION long_query_time =@saved_long_query_time;
-FLUSH LOGS;
-
-ALTER TABLE mysql.slow_log DROP COLUMN seq;
-ALTER TABLE mysql.slow_log ENGINE = CSV;
-
-SET GLOBAL general_log = @old_general_log;
-SET GLOBAL slow_query_log = @old_slow_query_log;
-
-#
 # Bug#25422 (Hang with log tables)
 #
 
@@ -727,7 +657,8 @@ CREATE TABLE `db_17876.slow_log_data` (
   `last_insert_id` int(11) default NULL,
   `insert_id` int(11) default NULL,
   `server_id` int(11) default NULL,
-  `sql_text` mediumtext 
+  `sql_text` mediumtext,
+  `thread_id` int(11) default NULL
 );
 
 CREATE TABLE `db_17876.general_log_data` (
@@ -745,7 +676,7 @@ CREATE procedure `db_17876.archiveSlowLo
 BEGIN
   DECLARE start_time, query_time, lock_time CHAR(20);
   DECLARE user_host MEDIUMTEXT;
-  DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id INT;
+  DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id, thread_id INT;
   DECLARE dbname MEDIUMTEXT;
   DECLARE sql_text BLOB;
   DECLARE done INT DEFAULT 0;
@@ -763,7 +694,7 @@ BEGIN
         FETCH cur1 INTO
            start_time, user_host, query_time, lock_time,
            rows_set, rows_examined, dbname, last_insert_id,
-           insert_id, server_id, sql_text;
+           insert_id, server_id, sql_text, thread_id;
       END;
 
       IF NOT done THEN
@@ -771,7 +702,7 @@ BEGIN
           INSERT INTO
             `db_17876.slow_log_data`
             VALUES(start_time, user_host, query_time, lock_time, rows_set, rows_examined,
-                   dbname, last_insert_id,  insert_id, server_id, sql_text);
+                   dbname, last_insert_id,  insert_id, server_id, sql_text, thread_id);
         END;
       END IF;
     END;

=== modified file 'mysql-test/t/multi_update.test'
--- a/mysql-test/t/multi_update.test	2010-12-14 11:15:13 +0000
+++ b/mysql-test/t/multi_update.test	2011-02-21 15:55:58 +0000
@@ -683,4 +683,24 @@ UPDATE (SELECT 1 FROM t1 WHERE f1 = (SEL
 DROP FUNCTION f1;
 DROP TABLE t1;
 
+--echo #
+--echo # BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
+--echo #            table is updated twice
+--echo #
+
+# Results differ between storage engines.
+# See multi_update_innodb.test for the InnoDB variant of this test
+CREATE TABLE t1(
+  pk INT,
+  a INT,
+  PRIMARY KEY (pk)
+) ENGINE=MyISAM;
+
+INSERT INTO t1 VALUES (0,0);
+UPDATE t1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+--echo
+--echo # Should be (1,2)
+SELECT * FROM t1;
+DROP TABLE t1;
+
 --echo end of tests

=== added file 'mysql-test/t/multi_update_innodb.test'
--- a/mysql-test/t/multi_update_innodb.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/multi_update_innodb.test	2011-02-21 15:31:41 +0000
@@ -0,0 +1,33 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # BUG#57373: Multi update+InnoDB reports ER_KEY_NOT_FOUND if a
+--echo #            table is updated twice
+--echo #
+
+# Results differ between storage engines.
+# See multi_update.test for the MyISAM variant of this test
+CREATE TABLE t1(
+  pk INT,
+  a INT,
+  b INT,
+  PRIMARY KEY (pk)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (0,0,0);
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE t1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+SELECT * FROM t1;
+
+CREATE VIEW v1 AS SELECT * FROM t1;
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE v1 AS A, t1 AS B SET A.pk = 1, B.a = 2;
+SELECT * FROM t1;
+
+UPDATE t1 AS A, t1 AS B SET A.a = 1, B.b = 2;
+--echo # Should be (0,1,2)
+SELECT * FROM t1;
+
+DROP VIEW v1;
+DROP TABLE t1;
+

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2011-01-14 14:49:16 +0000
+++ b/mysql-test/t/mysqldump.test	2011-02-21 07:28:19 +0000
@@ -2191,13 +2191,34 @@ CREATE TABLE `comment_table` (i INT COMM
 DROP TABLE `comment_table`;
 
 --echo #
+--echo # BUG#11766310 : 59398: MYSQLDUMP 5.1 CAN'T HANDLE A DASH ("-") IN
+--echo #                DATABASE NAMES IN ALTER DATABASE
+--echo #
+
+CREATE DATABASE `test-database`;
+USE `test-database`;
+CREATE TABLE `test` (`c1` VARCHAR(10)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+DELIMITER |;
+CREATE TRIGGER `trig` BEFORE INSERT ON `test` FOR EACH ROW BEGIN
+END |
+DELIMITER ;|
+
+ALTER DATABASE `test-database` CHARACTER SET latin1 COLLATE latin1_swedish_ci;
+ALTER DATABASE `test-database` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--exec $MYSQL_DUMP --quote-names --compact test-database
+
+DROP DATABASE `test-database`;
+
+--echo #
 --echo # End of 5.1 tests
 --echo #
 
 --echo #
 --echo # Test for --add-drop-trigger
 --echo #
-
+USE `test`;
 CREATE TABLE t1 (a int, b int);
 CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW 
   SET NEW.b=NEW.a + 10;

=== modified file 'mysql-test/t/negation_elimination.test'
--- a/mysql-test/t/negation_elimination.test	2005-07-28 00:22:47 +0000
+++ b/mysql-test/t/negation_elimination.test	2011-02-21 10:36:31 +0000
@@ -65,6 +65,35 @@ select * from t1 where not((a < 5 and a
 explain select * from t1 where ((a between 5 and 15) and (not(a like 10)));
 select * from t1 where ((a between 5 and 15) and (not(a like 10)));
 
+--echo # XOR (Note: XOR is negated by negating one of the operands)
+
+--echo # Should return 6,7
+SELECT * FROM t1 WHERE ((a > 5) XOR (a > 7));
+
+--echo # Should return 0..5,8..19
+SELECT * FROM t1 WHERE ((NOT (a > 5)) XOR (a > 7));
+SELECT * FROM t1 WHERE ((a > 5) XOR (NOT (a > 7)));
+SELECT * FROM t1 WHERE NOT ((a > 5) XOR (a > 7));
+
+--echo # Should return 6,7
+SELECT * FROM t1 WHERE NOT ((NOT (a > 5)) XOR (a > 7));
+SELECT * FROM t1 WHERE NOT ((a > 5) XOR (NOT (a > 7)));
+
+--echo # Should return 0..5,8..19
+SELECT * FROM t1 WHERE NOT ((NOT (a > 5)) XOR (NOT (a > 7)));
+
+--echo # Should have empty result
+SELECT * FROM t1 WHERE (NULL XOR (a > 7));
+SELECT * FROM t1 WHERE NOT (NULL XOR (a > 7));
+
+--echo # Should be simplified to "...WHERE (a XOR a)
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE NOT ((NOT a) XOR (a));
+
+--echo # Should be simplified to "...WHERE (a XOR a)
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE NOT (a XOR (NOT a));
+
+--echo # End XOR
+
 delete from t1 where a > 3;
 select a, not(not(a)) from t1;
 explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "1"), not (a not in (1,2)), not(a != 2) from t1 where not(not(a)) having not(not(a));

=== modified file 'mysql-test/t/partition.test'
--- a/mysql-test/t/partition.test	2011-01-10 16:37:47 +0000
+++ b/mysql-test/t/partition.test	2011-02-21 15:55:58 +0000
@@ -2266,3 +2266,53 @@ DROP TABLE t1;
 SET GLOBAL myisam_use_mmap=default;
 
 --echo End of 5.1 tests
+
+--echo #
+--echo # BUG#55385: UPDATE statement throws an error, but still updates
+--echo #            the table entries
+
+CREATE TABLE t1_part (
+  partkey int,
+  nokey int
+) PARTITION BY LINEAR HASH(partkey) PARTITIONS 3;
+
+INSERT INTO t1_part VALUES (1, 1) , (10, 10);
+CREATE VIEW v1 AS SELECT * FROM t1_part;
+
+--echo
+--echo # Should be (1,1),(10,10)
+SELECT * FROM t1_part;
+
+--echo
+--echo # Case 1
+--echo # Update is refused because partitioning key is updated
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.partkey = 2, B.nokey = 3;
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.nokey = 2, B.partkey = 3;
+
+--echo
+--echo # Case 2
+--echo # Like 1, but partition accessed through a view
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE t1_part AS A NATURAL JOIN v1 as B SET A.nokey = 2 , B.partkey = 3;
+--error ER_MULTI_UPDATE_KEY_CONFLICT
+UPDATE v1 AS A NATURAL JOIN t1_part as B SET A.nokey = 2 , B.partkey = 3;
+
+--echo
+--echo # Should be (1,1),(10,10)
+SELECT * FROM t1_part;
+
+--echo
+--echo # Case 3
+--echo # Update is accepted because partitioning key is not updated
+UPDATE t1_part AS A NATURAL JOIN t1_part B SET A.nokey = 2 , B.nokey = 3;
+
+--echo
+--echo # Should be (1,3),(10,3)
+SELECT * FROM t1_part;
+
+--echo
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1_part;

=== modified file 'mysql-test/t/partition_binlog.test'
--- a/mysql-test/t/partition_binlog.test	2010-12-03 13:05:33 +0000
+++ b/mysql-test/t/partition_binlog.test	2011-02-09 22:35:46 +0000
@@ -1,4 +1,5 @@
 --source include/have_log_bin.inc
+--source include/have_partition.inc
 
 --disable_warnings
 DROP TABLE IF EXISTS t1;

=== 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-02-01 11:38:39 +0000
@@ -0,0 +1,720 @@
+--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;
+#
+--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;
+
+--echo #
+--echo # Bug#59864: Crash if table empty: DELETE FROM t2 PARTITION (subp3).
+--echo #
+CREATE TABLE t1
+(a INT NOT NULL,
+ b varchar (64),
+ INDEX (b,a),
+ PRIMARY KEY (a))
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH (a) SUBPARTITIONS 3
+(PARTITION pNeg VALUES LESS THAN (0)
+ (SUBPARTITION subp0,
+  SUBPARTITION subp1,
+  SUBPARTITION subp2),
+ PARTITION `p0-29` VALUES LESS THAN (30)
+ (SUBPARTITION subp3,
+  SUBPARTITION subp4,
+  SUBPARTITION subp5),
+ PARTITION `p30-299` VALUES LESS THAN (300)
+ (SUBPARTITION subp6,
+  SUBPARTITION subp7,
+  SUBPARTITION subp8),
+ PARTITION `p300-2999` VALUES LESS THAN (3000)
+ (SUBPARTITION subp9,
+  SUBPARTITION subp10,
+  SUBPARTITION subp11),
+ PARTITION `p3000-299999` VALUES LESS THAN (300000)
+ (SUBPARTITION subp12,
+  SUBPARTITION subp13,
+  SUBPARTITION subp14));
+
+eval SHOW CREATE TABLE t1;
+
+INSERT INTO t1 VALUES (-9, "negative nine"), (-8, "-8"), (-7, "-7"), (-6, "-6"), (-5, "-5"), (-4, "-4"), (-3, "-3"), (-2, "-2"), (-1, "-1");
+INSERT INTO t1 VALUES (9, "nine"), (8, "8"), (7, "7"), (6, "6"), (5, "5"), (4, "4"), (3, "3"), (2, "2"), (1, "1");
+INSERT INTO t1 VALUES (39, "Thirty nine"), (38, "38"), (37, "37"), (36, "36"), (35, "35"), (34, "34"), (33, "33"), (32, "32"), (31, "31");
+INSERT INTO t1 VALUES (339, "Three hundred thirty nine"), (338, "338"), (337, "337"), (336, "336"), (335, "335"), (334, "334"), (333, "333"), (332, "332"), (331, "331");
+INSERT INTO t1 VALUES (3339, "Three thousand three hundred thirty nine"), (3338, "3338"), (3337, "3337"), (3336, "3336"), (3335, "3335"), (3334, "3334"), (3333, "3333"), (3332, "3332"), (3331, "3331");
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+
+DELETE FROM t1 PARTITION (subp3);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (subp3);
+
+DELETE FROM t1 PARTITION (`p0-29`);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (`p0-29`);
+
+ALTER TABLE t1 PARTITION BY HASH (a) PARTITIONS 3;
+
+DELETE FROM t1 PARTITION (p2);
+
+--sorted_result
+SELECT * FROM t1;
+--sorted_result
+SELECT * FROM t1 PARTITION (p2);
+
+DROP TABLE t1;
+
+SET @@default_storage_engine = @old_default_storage_engine;

=== modified file 'mysys/hash.c'
--- a/mysys/hash.c	2010-07-08 21:20:08 +0000
+++ b/mysys/hash.c	2011-02-02 22:02:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -11,7 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /* The hash functions used for saveing keys */
 /* One of key_length or key_length_offset must be given */
@@ -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	2011-02-02 22:02:29 +0000
@@ -1,19 +1,17 @@
-/* Copyright (C) 2002-2006 MySQL AB
-   
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public
-   License as published by the Free Software Foundation; version 2
-   of the License.
-   
-   This library is distributed in the hope that it will be useful,
+/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with this library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include <my_global.h>
 #include <m_ctype.h>
@@ -587,7 +585,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	2011-02-02 22:02:29 +0000
@@ -1,6 +1,21 @@
 #ifndef MYSYS_MY_HANDLER_ERRORS_INCLUDED
 #define MYSYS_MY_HANDLER_ERRORS_INCLUDED
 
+/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+
 /*
   Errors a handler can give you
 */
@@ -65,7 +80,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 'scripts/mysql_system_tables.sql'
--- a/scripts/mysql_system_tables.sql	2011-01-03 13:39:18 +0000
+++ b/scripts/mysql_system_tables.sql	2011-02-22 02:58:40 +0000
@@ -89,7 +89,7 @@ DROP PREPARE stmt;
 
 -- Create slow_log if CSV is enabled.
 
-SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0');
+SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME NOT NULL, lock_time TIME NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL, thread_id INTEGER NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0');
 
 PREPARE stmt FROM @str;
 EXECUTE stmt;

=== modified file 'scripts/mysql_system_tables_fix.sql'
--- a/scripts/mysql_system_tables_fix.sql	2010-12-29 00:38:59 +0000
+++ b/scripts/mysql_system_tables_fix.sql	2011-02-09 08:12:43 +0000
@@ -255,6 +255,8 @@ ALTER TABLE slow_log
   MODIFY insert_id INTEGER NOT NULL,
   MODIFY server_id INTEGER UNSIGNED NOT NULL,
   MODIFY sql_text MEDIUMTEXT NOT NULL;
+ALTER TABLE slow_log
+  ADD COLUMN thread_id INTEGER NOT NULL AFTER sql_text;
 SET GLOBAL slow_query_log = @old_log_state;
 
 ALTER TABLE plugin

=== modified file 'scripts/mysqldumpslow.sh'
--- a/scripts/mysqldumpslow.sh	2010-12-28 23:47:05 +0000
+++ b/scripts/mysqldumpslow.sh	2011-02-09 08:12:43 +0000
@@ -99,7 +99,7 @@ while ( defined($_ = shift @pending) or
     }
 
     s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
-    my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
+    my ($user,$host,$dummy,$thread_id) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+)\s+\S+(\s+Id:\s+(\d+))?.*\n// ? ($1,$2,$3,$4) : ('','','','','');
 
     s/^# Query_time: ([0-9.]+)\s+Lock_time: ([0-9.]+)\s+Rows_sent: ([0-9.]+).*\n//;
     my ($t, $l, $r) = ($1, $2, $3);

=== modified file 'sql/ha_ndbcluster_cond.cc'
--- a/sql/ha_ndbcluster_cond.cc	2010-08-14 09:38:42 +0000
+++ b/sql/ha_ndbcluster_cond.cc	2011-02-21 11:33:20 +0000
@@ -1471,4 +1471,4 @@ int ha_ndbcluster_cond::generate_scan_fi
   DBUG_RETURN(0);
 }
 
-#endif /* HAVE_NDBCLUSTER_DB */
+#endif

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2011-01-26 21:12:56 +0000
+++ b/sql/ha_partition.cc	2011-02-02 22:02:29 +0000
@@ -1,17 +1,17 @@
 /* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
 
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; version 2 of the License.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software Foundation,
-  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /*
   This handler was developed by Mikael Ronstrom for version 5.1 of MySQL.
@@ -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);
@@ -3382,8 +3536,12 @@ int ha_partition::delete_all_rows()
   file= m_file;
   do
   {
-    if ((error= (*file)->ha_delete_all_rows()))
-      DBUG_RETURN(error);
+    /* Can be pruned, like DELETE FROM t PARTITION (pX) */
+    if (bitmap_is_set(&(m_part_info->read_partitions), file - m_file))
+    {
+      if ((error= (*file)->ha_delete_all_rows()))
+        DBUG_RETURN(error);
+    }
   } while (*(++file));
   DBUG_RETURN(0);
 }
@@ -3528,6 +3686,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 +3871,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 +3902,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 +3918,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 +3957,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 +4035,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 +4087,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 +4142,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 +4274,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 +4313,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 +4601,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 +4853,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 +4970,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 +5061,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 +5338,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 +5363,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 +5428,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 +5511,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 +5569,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 +5593,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 +6059,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 +6188,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 +6282,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 +6301,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 +6323,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 +6357,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 +6462,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 +6474,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);
 }
@@ -6379,9 +6563,12 @@ uint32 ha_partition::calculate_key_hash_
 
 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));
 }
 
 
@@ -6390,6 +6577,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();
@@ -6847,7 +7035,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)
   {
@@ -6914,6 +7103,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)))
@@ -6938,6 +7128,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)))
@@ -6962,6 +7153,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	2011-01-26 21:12:56 +0000
+++ b/sql/ha_partition.h	2011-02-02 22:02:29 +0000
@@ -1,20 +1,20 @@
 #ifndef HA_PARTITION_INCLUDED
 #define HA_PARTITION_INCLUDED
 
-/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
 
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; version 2 of the License.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software Foundation,
-  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #ifdef __GNUC__
 #pragma interface				/* gcc class implementation */
@@ -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, bool early)
@@ -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-02-08 15:54:12 +0000
+++ b/sql/handler.cc	2011-02-21 15:55:58 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /** @file handler.cc
 
@@ -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,10 @@ void handler::get_auto_increment(ulonglo
 
 void handler::ha_release_auto_increment()
 {
+#ifdef BUG60114_IS_FIXED
+  DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type != F_UNLCK);
+#endif
   release_auto_increment();
   insert_id_for_cur_row= 0;
   auto_inc_interval_for_cur_row.replace(0, 0, 0);
@@ -2879,6 +2910,7 @@ void handler::print_error(int error, myf
     break;
   case HA_ERR_KEY_NOT_FOUND:
   case HA_ERR_NO_ACTIVE_RECORD:
+  case HA_ERR_RECORD_DELETED:
   case HA_ERR_END_OF_FILE:
     textno=ER_KEY_NOT_FOUND;
     break;
@@ -3031,6 +3063,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 +3259,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 +3292,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 +3367,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 +3429,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 +3447,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 +3464,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 +3481,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 +3498,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 +3515,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 +3532,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 +3549,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 +3566,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 +3583,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 +3600,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 +3619,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 +3636,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 +3652,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 +3668,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 +3684,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 +3701,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 +3722,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 +3740,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 +3757,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 +5833,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 +5860,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 +5906,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 +5940,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 +5967,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 +5998,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-26 21:12:56 +0000
+++ b/sql/handler.h	2011-02-02 22:02:29 +0000
@@ -13,8 +13,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /* Definitions for parameters to do with handler-routines */
 
@@ -1445,7 +1445,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;
 
@@ -1514,15 +1513,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);
@@ -1863,6 +1866,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/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2011-02-18 07:43:02 +0000
+++ b/sql/item_cmpfunc.cc	2011-02-21 10:36:31 +0000
@@ -5333,23 +5333,21 @@ bool Item_func_like::turboBM_matches(con
     very fast to use.
 */
 
-longlong Item_cond_xor::val_int()
+longlong Item_func_xor::val_int()
 {
   DBUG_ASSERT(fixed == 1);
-  List_iterator<Item> li(list);
-  Item *item;
-  int result=0;	
-  null_value=0;
-  while ((item=li++))
+  int result= 0;
+  null_value= false;
+  for (uint i= 0; i < arg_count; i++)
   {
-    result^= (item->val_int() != 0);
-    if (item->null_value)
+    result^= (args[i]->val_int() != 0);
+    if (args[i]->null_value)
     {
-      null_value=1;
+      null_value= true;
       return 0;
     }
   }
-  return (longlong) result;
+  return result;
 }
 
 /**
@@ -5390,6 +5388,33 @@ Item *Item_bool_rowready_func2::neg_tran
   return item;
 }
 
+/**
+  XOR can be negated by negating one of the operands:
+
+  NOT (a XOR b)  => (NOT a) XOR b
+                 => a       XOR (NOT b)
+
+  @param thd     Thread handle
+  @return        New negated item
+*/
+Item *Item_func_xor::neg_transformer(THD *thd)
+{
+  Item *neg_operand;
+  Item_func_xor *new_item;
+  if ((neg_operand= args[0]->neg_transformer(thd)))
+    // args[0] has neg_tranformer
+    new_item= new(thd->mem_root) Item_func_xor(neg_operand, args[1]);
+  else if ((neg_operand= args[1]->neg_transformer(thd)))
+    // args[1] has neg_tranformer
+    new_item= new(thd->mem_root) Item_func_xor(args[0], neg_operand);
+  else
+  {
+    neg_operand= new(thd->mem_root) Item_func_not(args[0]);
+    new_item= new(thd->mem_root) Item_func_xor(neg_operand, args[1]);
+  }
+  return new_item;
+}
+
 
 /**
   a IS NULL  ->  a IS NOT NULL.

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2010-12-29 00:38:59 +0000
+++ b/sql/item_cmpfunc.h	2011-02-21 10:36:31 +0000
@@ -1,7 +1,7 @@
 #ifndef ITEM_CMPFUNC_INCLUDED
 #define ITEM_CMPFUNC_INCLUDED
 
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -411,6 +411,22 @@ public:
   bool subst_argument_checker(uchar **arg) { return TRUE; }
 };
 
+/**
+  XOR inherits from Item_bool_func2 because it is not optimized yet.
+  Later, when XOR is optimized, it needs to inherit from
+  Item_cond instead. See WL#5800. 
+*/
+class Item_func_xor :public Item_bool_func2
+{
+public:
+  Item_func_xor(Item *i1, Item *i2) :Item_bool_func2(i1, i2) {}
+  enum Functype functype() const { return XOR_FUNC; }
+  const char *func_name() const { return "xor"; }
+  longlong val_int();
+  void top_level_item() {}
+  Item *neg_transformer(THD *thd);
+};
+
 class Item_func_not :public Item_bool_func
 {
 public:
@@ -1759,45 +1775,6 @@ inline bool is_cond_or(Item *item)
   return (cond_item->functype() == Item_func::COND_OR_FUNC);
 }
 
-/*
-  XOR is Item_cond, not an Item_int_func because we could like to
-  optimize (a XOR b) later on. It's low prio, though
-*/
-
-class Item_cond_xor :public Item_cond
-{
-public:
-  Item_cond_xor(Item *i1,Item *i2) :Item_cond(i1,i2) 
-  {
-    /* 
-      Items must be stored in args[] as well because this Item_cond is
-      treated as a FUNC_ITEM (see type()). I.e., users of it will get
-      it's children by calling arguments(), not argument_list(). This
-      is a temporary solution until XOR is optimized and treated like
-      a full Item_cond citizen.
-     */
-    arg_count= 2;
-    args= tmp_arg;
-    args[0]= i1; 
-    args[1]= i2;
-  }
-  enum Functype functype() const { return COND_XOR_FUNC; }
-  /* TODO: remove the next line when implementing XOR optimization */
-  enum Type type() const { return FUNC_ITEM; }
-  longlong val_int();
-  const char *func_name() const { return "xor"; }
-  void top_level_item() {}
-  /* Since child Items are stored in args[], Items cannot be added.
-     However, since Item_cond_xor is treated as a FUNC_ITEM (see
-     type()), the methods below should never be called. 
-  */
-  bool add(Item *item) { DBUG_ASSERT(FALSE); return FALSE; }
-  bool add_at_head(Item *item) { DBUG_ASSERT(FALSE); return FALSE; }
-  bool add_at_head(List<Item> *nlist) { DBUG_ASSERT(FALSE); return FALSE; }
-  void copy_andor_arguments(THD *thd, Item_cond *item) { DBUG_ASSERT(FALSE); }
-};
-
-
 /* Some useful inline functions */
 
 inline Item *and_conds(Item *a, Item *b)

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2011-02-08 15:54:12 +0000
+++ b/sql/item_func.h	2011-02-21 10:36:31 +0000
@@ -46,7 +46,7 @@ public:
   enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
 		  GE_FUNC,GT_FUNC,FT_FUNC,
 		  LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
-		  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
+		  COND_AND_FUNC, COND_OR_FUNC, XOR_FUNC,
                   BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
 		  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
 		  SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC,

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2011-02-10 08:47:05 +0000
+++ b/sql/item_timefunc.cc	2011-02-21 08:23:02 +0000
@@ -1133,16 +1133,13 @@ String* Item_func_monthname::val_str(Str
 {
   DBUG_ASSERT(fixed == 1);
   const char *month_name;
-  uint month= (uint) val_int();
   uint err;
+  MYSQL_TIME ltime;
 
-  if (null_value || !month)
-  {
-    null_value=1;
-    return (String*) 0;
-  }
-  null_value=0;
-  month_name= locale->month_names->type_names[month-1];
+  if ((null_value= (get_arg0_date(&ltime, TIME_FUZZY_DATE) || !ltime.month)))
+    return (String *) 0;
+
+  month_name= locale->month_names->type_names[ltime.month - 1];
   str->copy(month_name, (uint) strlen(month_name), &my_charset_utf8_bin,
 	    collation.collation, &err);
   return str;

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2011-02-10 08:47:05 +0000
+++ b/sql/item_timefunc.h	2011-02-21 08:23:02 +0000
@@ -163,16 +163,19 @@ public:
 };
 
 
-class Item_func_monthname :public Item_func_month
+class Item_func_monthname :public Item_str_func
 {
   MY_LOCALE *locale;
 public:
-  Item_func_monthname(Item *a) :Item_func_month(a) {}
+  Item_func_monthname(Item *a) :Item_str_func(a) {}
   const char *func_name() const { return "monthname"; }
   String *val_str(String *str);
-  enum Item_result result_type () const { return STRING_RESULT; }
   void fix_length_and_dec();
   bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
+  bool check_valid_arguments_processor(uchar *int_arg)
+  {
+    return !has_date_args();
+  }
 };
 
 

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2011-02-09 07:31:17 +0000
+++ b/sql/log.cc	2011-02-22 02:58:40 +0000
@@ -48,6 +48,142 @@
 #define MAX_LOG_BUFFER_SIZE 1024
 #define MAX_TIME_SIZE 32
 
+static
+const TABLE_FIELD_TYPE slow_query_log_table_fields[SQLT_FIELD_COUNT] =
+{
+  {
+    { C_STRING_WITH_LEN("start_time") },
+    { C_STRING_WITH_LEN("timestamp") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("user_host") },
+    { C_STRING_WITH_LEN("mediumtext") },
+    { C_STRING_WITH_LEN("utf8") }
+  },
+  {
+    { C_STRING_WITH_LEN("query_time") },
+    { C_STRING_WITH_LEN("time") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("lock_time") },
+    { C_STRING_WITH_LEN("time") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("rows_sent") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("rows_examined") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("db") },
+    { C_STRING_WITH_LEN("varchar(512)") },
+    { C_STRING_WITH_LEN("utf8") }
+  },
+  {
+    { C_STRING_WITH_LEN("last_insert_id") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("insert_id") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("server_id") },
+    { C_STRING_WITH_LEN("int(10) unsigned") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("sql_text") },
+    { C_STRING_WITH_LEN("mediumtext") },
+    { C_STRING_WITH_LEN("utf8") }
+  },
+  {
+    { C_STRING_WITH_LEN("thread_id") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  }
+};
+
+static const TABLE_FIELD_DEF
+  slow_query_log_table_def= {SQLT_FIELD_COUNT, slow_query_log_table_fields};
+
+class Slow_query_log_table_intact : public Table_check_intact
+{
+protected:
+  void report_error(uint, const char *fmt, ...)
+  {
+    va_list args;
+    va_start(args, fmt);
+    error_log_print(ERROR_LEVEL, fmt, args);
+    va_end(args);
+  }
+};
+
+/** In case of an error, a message is printed to the error log. */
+static Slow_query_log_table_intact sqlt_intact;
+
+static
+const TABLE_FIELD_TYPE general_log_table_fields[GLT_FIELD_COUNT] =
+{
+  {
+    { C_STRING_WITH_LEN("event_time") },
+    { C_STRING_WITH_LEN("timestamp") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("user_host") },
+    { C_STRING_WITH_LEN("mediumtext") },
+    { C_STRING_WITH_LEN("utf8") }
+  },
+  {
+    { C_STRING_WITH_LEN("thread_id") },
+    { C_STRING_WITH_LEN("int(11)") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("server_id") },
+    { C_STRING_WITH_LEN("int(10) unsigned") },
+    { NULL, 0 }
+  },
+  {
+    { C_STRING_WITH_LEN("command_type") },
+    { C_STRING_WITH_LEN("varchar(64)") },
+    { C_STRING_WITH_LEN("utf8") }
+  },
+  {
+    { C_STRING_WITH_LEN("argument") },
+    { C_STRING_WITH_LEN("mediumtext") },
+    { C_STRING_WITH_LEN("utf8") }
+  }
+};
+
+static const TABLE_FIELD_DEF
+  general_log_table_def= {GLT_FIELD_COUNT, general_log_table_fields};
+
+class General_log_table_intact : public Table_check_intact
+{
+protected:
+  void report_error(uint, const char *fmt, ...)
+  {
+    va_list args;
+    va_start(args, fmt);
+    error_log_print(ERROR_LEVEL, fmt, args);
+    va_end(args);
+  }
+};
+
+/** In case of an error, a message is printed to the error log. */
+static General_log_table_intact glt_intact;
+
 LOGGER logger;
 
 static bool test_if_number(const char *str,
@@ -275,7 +411,7 @@ bool Log_to_csv_event_handler::
                             TL_WRITE_CONCURRENT_INSERT);
 
   /*
-    1) open_log_table generates an error of the
+    1) open_log_table generates an error if the
     table can not be opened or is corrupted.
     2) "INSERT INTO general_log" can generate warning sometimes.
 
@@ -293,6 +429,9 @@ bool Log_to_csv_event_handler::
 
   need_close= TRUE;
 
+  if (glt_intact.check(table_list.table, &general_log_table_def))
+    goto err;
+
   if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
       table->file->ha_rnd_init(0))
     goto err;
@@ -316,35 +455,40 @@ bool Log_to_csv_event_handler::
   if (table->s->fields < 6)
     goto err;
 
-  DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP);
+  DBUG_ASSERT(table->field[GLT_FIELD_EVENT_TIME]->type() == MYSQL_TYPE_TIMESTAMP);
 
-  ((Field_timestamp*) table->field[0])->store_timestamp((my_time_t)
-                                                        event_time);
+  ((Field_timestamp*) table->field[GLT_FIELD_EVENT_TIME])->store_timestamp(
+      (my_time_t) event_time);
 
   /* do a write */
-  if (table->field[1]->store(user_host, user_host_len, client_cs) ||
-      table->field[2]->store((longlong) thread_id, TRUE) ||
-      table->field[3]->store((longlong) server_id, TRUE) ||
-      table->field[4]->store(command_type, command_type_len, client_cs))
+  if (table->field[GLT_FIELD_USER_HOST]->store(user_host, user_host_len,
+                                               client_cs) ||
+      table->field[GLT_FIELD_THREAD_ID]->store((longlong) thread_id, TRUE) ||
+      table->field[GLT_FIELD_SERVER_ID]->store((longlong) server_id, TRUE) ||
+      table->field[GLT_FIELD_COMMAND_TYPE]->store(command_type,
+                                                  command_type_len, client_cs))
     goto err;
 
   /*
     A positive return value in store() means truncation.
     Still logging a message in the log in this case.
   */
-  table->field[5]->flags|= FIELDFLAG_HEX_ESCAPE;
-  if (table->field[5]->store(sql_text, sql_text_len, client_cs) < 0)
+  table->field[GLT_FIELD_ARGUMENT]->flags|= FIELDFLAG_HEX_ESCAPE;
+  if (table->field[GLT_FIELD_ARGUMENT]->store(sql_text, sql_text_len,
+                                              client_cs) < 0)
     goto err;
 
   /* mark all fields as not null */
-  table->field[1]->set_notnull();
-  table->field[2]->set_notnull();
-  table->field[3]->set_notnull();
-  table->field[4]->set_notnull();
-  table->field[5]->set_notnull();
+  table->field[GLT_FIELD_USER_HOST]->set_notnull();
+  table->field[GLT_FIELD_THREAD_ID]->set_notnull();
+  table->field[GLT_FIELD_SERVER_ID]->set_notnull();
+  table->field[GLT_FIELD_COMMAND_TYPE]->set_notnull();
+  table->field[GLT_FIELD_ARGUMENT]->set_notnull();
 
   /* Set any extra columns to their default values */
-  for (field_index= 6 ; field_index < table->s->fields ; field_index++)
+  for (field_index= GLT_FIELD_COUNT ;
+       field_index < table->s->fields ;
+       field_index++)
   {
     table->field[field_index]->set_default();
   }
@@ -439,6 +583,9 @@ bool Log_to_csv_event_handler::
 
   need_close= TRUE;
 
+  if (sqlt_intact.check(table_list.table, &slow_query_log_table_def))
+    goto err;
+
   if (table->file->extra(HA_EXTRA_MARK_AS_LOG_TABLE) ||
       table->file->ha_rnd_init(0))
     goto err;
@@ -450,15 +597,12 @@ bool Log_to_csv_event_handler::
 
   restore_record(table, s->default_values);    // Get empty record
 
-  /* check that all columns exist */
-  if (table->s->fields < 11)
-    goto err;
-
   /* store the time and user values */
-  DBUG_ASSERT(table->field[0]->type() == MYSQL_TYPE_TIMESTAMP);
-  ((Field_timestamp*) table->field[0])->store_timestamp((my_time_t)
-                                                        current_time);
-  if (table->field[1]->store(user_host, user_host_len, client_cs))
+  DBUG_ASSERT(table->field[SQLT_FIELD_START_TIME]->type() == MYSQL_TYPE_TIMESTAMP);
+  ((Field_timestamp*) table->field[SQLT_FIELD_START_TIME])->store_timestamp(
+      (my_time_t) current_time);
+  if (table->field[SQLT_FIELD_USER_HOST]->store(user_host, user_host_len,
+                                                client_cs))
     goto err;
 
   if (query_start_arg)
@@ -475,42 +619,43 @@ bool Log_to_csv_event_handler::
 
     /* fill in query_time field */
     calc_time_from_sec(&t, (long) min(query_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
-    if (table->field[2]->store_time(&t, MYSQL_TIMESTAMP_TIME))
+    if (table->field[SQLT_FIELD_QUERY_TIME]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* lock_time */
     calc_time_from_sec(&t, (long) min(lock_time, (longlong) TIME_MAX_VALUE_SECONDS), 0);
-    if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
+    if (table->field[SQLT_FIELD_LOCK_TIME]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* rows_sent */
-    if (table->field[4]->store((longlong) thd->sent_row_count, TRUE))
+    if (table->field[SQLT_FIELD_ROWS_SENT]->store((longlong) thd->sent_row_count, TRUE))
       goto err;
     /* rows_examined */
-    if (table->field[5]->store((longlong) thd->examined_row_count, TRUE))
+    if (table->field[SQLT_FIELD_ROWS_EXAMINED]->store((longlong) thd->examined_row_count, TRUE))
       goto err;
   }
   else
   {
-    table->field[2]->set_null();
-    table->field[3]->set_null();
-    table->field[4]->set_null();
-    table->field[5]->set_null();
+    table->field[SQLT_FIELD_QUERY_TIME]->set_null();
+    table->field[SQLT_FIELD_LOCK_TIME]->set_null();
+    table->field[SQLT_FIELD_ROWS_SENT]->set_null();
+    table->field[SQLT_FIELD_ROWS_EXAMINED]->set_null();
   }
   /* fill database field */
   if (thd->db)
   {
-    if (table->field[6]->store(thd->db, thd->db_length, client_cs))
+    if (table->field[SQLT_FIELD_DATABASE]->store(thd->db, thd->db_length,
+                                                 client_cs))
       goto err;
-    table->field[6]->set_notnull();
+    table->field[SQLT_FIELD_DATABASE]->set_notnull();
   }
 
   if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
   {
     if (table->
-        field[7]->store((longlong)
+        field[SQLT_FIELD_LAST_INSERT_ID]->store((longlong)
                         thd->first_successful_insert_id_in_prev_stmt_for_binlog,
                         TRUE))
       goto err;
-    table->field[7]->set_notnull();
+    table->field[SQLT_FIELD_LAST_INSERT_ID]->set_notnull();
   }
 
   /*
@@ -522,22 +667,27 @@ bool Log_to_csv_event_handler::
   if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
   {
     if (table->
-        field[8]->store((longlong)
+        field[SQLT_FIELD_INSERT_ID]->store((longlong)
           thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(), TRUE))
       goto err;
-    table->field[8]->set_notnull();
+    table->field[SQLT_FIELD_INSERT_ID]->set_notnull();
   }
 
-  if (table->field[9]->store((longlong) server_id, TRUE))
+  if (table->field[SQLT_FIELD_SERVER_ID]->store((longlong) server_id, TRUE))
     goto err;
-  table->field[9]->set_notnull();
+  table->field[SQLT_FIELD_SERVER_ID]->set_notnull();
 
   /*
     Column sql_text.
     A positive return value in store() means truncation.
     Still logging a message in the log in this case.
   */
-  if (table->field[10]->store(sql_text, sql_text_len, client_cs) < 0)
+  if (table->field[SQLT_FIELD_SQL_TEXT]->store(sql_text, sql_text_len,
+                                               client_cs) < 0)
+    goto err;
+
+  if (table->field[SQLT_FIELD_THREAD_ID]->store((longlong) thd->thread_id,
+                                                TRUE))
     goto err;
 
   /* log table entries are not replicated */
@@ -1769,12 +1919,9 @@ bool MYSQL_QUERY_LOG::write(THD *thd, ti
         if (my_b_write(&log_file, (uchar*) buff, buff_len))
           tmp_errno= errno;
       }
-      const uchar uh[]= "# User@Host: ";
-      if (my_b_write(&log_file, uh, sizeof(uh) - 1))
-        tmp_errno= errno;
-      if (my_b_write(&log_file, (uchar*) user_host, user_host_len))
-        tmp_errno= errno;
-      if (my_b_write(&log_file, (uchar*) "\n", 1))
+      buff_len= my_snprintf(buff, 14, "%5ld", (long) thd->thread_id);
+      if (my_b_printf(&log_file, "# User@Host: %s  Id: %s\n", user_host, buff)
+          == (uint) -1)
         tmp_errno= errno;
     }
     /* For slow query log */

=== modified file 'sql/log.h'
--- a/sql/log.h	2010-12-10 16:55:50 +0000
+++ b/sql/log.h	2011-02-09 08:12:43 +0000
@@ -216,6 +216,37 @@ public:
 #endif
 };
 
+
+enum enum_general_log_table_field
+{
+  GLT_FIELD_EVENT_TIME = 0,
+  GLT_FIELD_USER_HOST,
+  GLT_FIELD_THREAD_ID,
+  GLT_FIELD_SERVER_ID,
+  GLT_FIELD_COMMAND_TYPE,
+  GLT_FIELD_ARGUMENT,
+  GLT_FIELD_COUNT
+};
+
+
+enum enum_slow_query_log_table_field
+{
+  SQLT_FIELD_START_TIME = 0,
+  SQLT_FIELD_USER_HOST,
+  SQLT_FIELD_QUERY_TIME,
+  SQLT_FIELD_LOCK_TIME,
+  SQLT_FIELD_ROWS_SENT,
+  SQLT_FIELD_ROWS_EXAMINED,
+  SQLT_FIELD_DATABASE,
+  SQLT_FIELD_LAST_INSERT_ID,
+  SQLT_FIELD_INSERT_ID,
+  SQLT_FIELD_SERVER_ID,
+  SQLT_FIELD_SQL_TEXT,
+  SQLT_FIELD_THREAD_ID,
+  SQLT_FIELD_COUNT
+};
+
+
 class MYSQL_QUERY_LOG: public MYSQL_LOG
 {
 public:

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-02-16 17:13:30 +0000
+++ b/sql/mysqld.cc	2011-02-22 02:58:40 +0000
@@ -11,7 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include "my_global.h"                          /* NO_EMBEDDED_ACCESS_CHECKS */
 #include "sql_priv.h"
@@ -680,6 +680,12 @@ static char *opt_bin_logname;
 int orig_argc;
 char **orig_argv;
 
+void set_remaining_args(int argc, char **argv)
+{
+  remaining_argc= argc;
+  remaining_argv= argv;
+}
+
 /*
   Since buffered_option_error_reporter is only used currently
   for parsing performance schema options, this code is not needed
@@ -944,6 +950,7 @@ static int get_options(int *argc_ptr, ch
 static bool add_terminator(DYNAMIC_ARRAY *options);
 extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *);
 static void set_server_version(void);
+static int init_thread_environment();
 static char *get_relative_path(const char *path);
 static int fix_paths(void);
 void handle_connections_sockets();
@@ -1078,6 +1085,8 @@ static void close_connections(void)
     statements and inform their clients that the server is about to die.
   */
 
+  sql_print_information("Giving client threads a chance to die gracefully");
+
   THD *tmp;
   mysql_mutex_lock(&LOCK_thread_count); // For unlink from list
 
@@ -1110,6 +1119,8 @@ static void close_connections(void)
   mysql_mutex_unlock(&LOCK_thread_count); // For unlink from list
 
   Events::deinit();
+
+  sql_print_information("Shutting down slave threads");
   end_slave();
 
   if (thread_count)
@@ -1121,6 +1132,7 @@ static void close_connections(void)
     client on a blocking read call are aborted.
   */
 
+  sql_print_information("Forcefully disconnecting remaining clients");
   for (;;)
   {
     DBUG_PRINT("quit",("Locking LOCK_thread_count"));
@@ -1421,6 +1433,7 @@ void clean_up(bool print_message)
     make sure that handlers finish up
     what they have that is dependent on the binlog
   */
+  sql_print_information("Binlog end");
   ha_binlog_end(current_thd);
 
   logger.cleanup_base();
@@ -2887,7 +2900,8 @@ sizeof(load_default_groups)/sizeof(load_
 
 
 #ifndef EMBEDDED_LIBRARY
-static
+namespace {
+extern "C"
 int
 check_enough_stack_size()
 {
@@ -2896,6 +2910,7 @@ check_enough_stack_size()
   return check_stack_overrun(current_thd, STACK_MIN_SIZE,
                              &stack_top);
 }
+}
 #endif
 
 
@@ -3118,7 +3133,7 @@ rpl_make_log_name(const char *opt,
 }
 
 
-static int init_common_variables()
+int init_common_variables()
 {
   char buff[FN_REFLEN];
   umask(((~my_umask) & 0666));
@@ -3567,7 +3582,7 @@ You should consider changing lower_case_
 }
 
 
-int init_thread_environment()
+static int init_thread_environment()
 {
   mysql_mutex_init(key_LOCK_thread_count, &LOCK_thread_count, MY_MUTEX_INIT_FAST);
   mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
@@ -5138,11 +5153,17 @@ static bool read_init_file(char *file_na
   MYSQL_FILE *file;
   DBUG_ENTER("read_init_file");
   DBUG_PRINT("enter",("name: %s",file_name));
+
+  sql_print_information("Execution of init_file \'%s\' started.", file_name);
+
   if (!(file= mysql_file_fopen(key_file_init, file_name,
                                O_RDONLY, MYF(MY_WME))))
     DBUG_RETURN(TRUE);
   bootstrap(file);
   mysql_file_fclose(file, MYF(MY_WME));
+
+  sql_print_information("Execution of init_file \'%s\' ended.", file_name);
+
   DBUG_RETURN(FALSE);
 }
 
@@ -6685,6 +6706,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},
@@ -6862,7 +6884,7 @@ static void usage(void)
   if (!default_collation_name)
     default_collation_name= (char*) default_charset_info->name;
   print_version();
-  puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010"));
+  puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2011"));
   puts("Starts the MySQL database server.\n");
   printf("Usage: %s [OPTIONS]\n", my_progname);
   if (!opt_verbose)

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-02-01 07:52:46 +0000
+++ b/sql/mysqld.h	2011-02-18 11:39:05 +0000
@@ -72,7 +72,10 @@ bool one_thread_per_connection_end(THD *
 void flush_thread_cache();
 void refresh_status(THD *thd);
 bool is_secure_file_path(char *path);
-int init_thread_environment();
+
+// These are needed for unit testing.
+void set_remaining_args(int argc, char **argv);
+int init_common_variables();
 
 extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
 extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ;

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-12-29 00:38:59 +0000
+++ b/sql/opt_range.cc	2011-02-02 22:02:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /*
   TODO:
@@ -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-02-09 22:35:46 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2010 Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /* Some general useful functions */
 
@@ -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.
@@ -381,7 +502,7 @@ bool partition_info::set_up_defaults_for
   Support routine for check_partition_info
 
   SYNOPSIS
-    has_unique_fields
+    find_duplicate_field
     no parameters
 
   RETURN VALUE
@@ -392,13 +513,13 @@ bool partition_info::set_up_defaults_for
     Check that the user haven't defined the same field twice in
     key or column list partitioning.
 */
-char* partition_info::has_unique_fields()
+char* partition_info::find_duplicate_field()
 {
   char *field_name_outer, *field_name_inner;
   List_iterator<char> it_outer(part_field_list);
   uint num_fields= part_field_list.elements;
   uint i,j;
-  DBUG_ENTER("partition_info::has_unique_fields");
+  DBUG_ENTER("partition_info::find_duplicate_field");
 
   for (i= 0; i < num_fields; i++)
   {
@@ -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,46 +608,84 @@ partition_element *partition_info::get_p
 }
 
 
+/**
+  Helper function to find_duplicate_name.
+*/
+
+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
 
   SYNOPSIS
-    has_unique_names()
+    find_duplicate_name()
 
   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
     duplicated names.
 */
 
-char *partition_info::has_unique_names()
+char *partition_info::find_duplicate_name()
 {
-  DBUG_ENTER("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;  
 
-  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++)))
+  DBUG_ENTER("partition_info::find_duplicate_name");
+  
+  /*
+    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.
+  */
+
+  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);
 }
 
 
@@ -1255,12 +1373,12 @@ bool partition_info::check_partition_inf
   }
 
   if (part_field_list.elements > 0 &&
-      (same_name= has_unique_fields()))
+      (same_name= find_duplicate_field()))
   {
     my_error(ER_SAME_NAME_PARTITION_FIELD, MYF(0), same_name);
     goto end;
   }
-  if ((same_name= has_unique_names()))
+  if ((same_name= find_duplicate_name()))
   {
     my_error(ER_SAME_NAME_PARTITION, MYF(0), same_name);
     goto end;

=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h	2011-01-26 21:12:56 +0000
+++ b/sql/partition_info.h	2011-02-09 22:35:46 +0000
@@ -1,7 +1,7 @@
 #ifndef PARTITION_INFO_INCLUDED
 #define PARTITION_INFO_INCLUDED
 
-/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #ifdef USE_PRAGMA_INTERFACE
 #pragma interface			/* gcc class implementation */
@@ -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,7 +45,7 @@ public:
 
   List<char> part_field_list;
   List<char> subpart_field_list;
-  
+
   /* 
     If there is no subpartitioning, use only this func to get partition ids.
     If there is subpartitioning, use the this func to get partition id when
@@ -111,14 +112,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;
@@ -220,11 +237,12 @@ 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),
     curr_part_elem(NULL), current_partition(NULL),
-    curr_list_object(0), num_columns(0),
+    curr_list_object(0), num_columns(0), table(NULL),
     default_engine_type(NULL),
     part_type(NOT_A_PARTITION), subpart_type(NOT_A_PARTITION),
     part_info_len(0),
@@ -249,6 +267,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()
   {
@@ -263,8 +282,8 @@ public:
 
   bool set_up_defaults_for_partitioning(handler *file, HA_CREATE_INFO *info,
                                         uint start_no);
-  char *has_unique_fields();
-  char *has_unique_names();
+  char *find_duplicate_field();
+  char *find_duplicate_name();
   bool check_engine_mix(handlerton *engine_type, bool default_engine);
   bool check_range_constants(THD *thd);
   bool check_list_constants(THD *thd);
@@ -307,7 +326,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	2011-02-21 02:57:30 +0000
+++ b/sql/share/errmsg-utf8.txt	2011-02-21 15:55:58 +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
@@ -6452,8 +6452,38 @@ ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE
 
 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_MULTI_UPDATE_KEY_CONFLICT
+  eng "Primary key/partition key update is not allowed since the table is updated both as '%-.192s' and '%-.192s'."
+
 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_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT
   eng "Can't update table '%-.192s' while '%-.192s' is being created."
+
+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-02-08 15:54:12 +0000
+++ b/sql/sql_base.cc	2011-02-14 10:28:11 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 
 /* Basic functions needed by many modules */
@@ -4670,6 +4670,47 @@ open_tables_check_upgradable_mdl(THD *th
 }
 
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+/*
+  TODO: Move all this to prune_partitions() when implementing WL#4443.
+  Needs all items and conds fixed (as in first part in JOIN::optimize,
+  mysql_prepare_delete). Ensure that prune_partitions() is called for all
+  statements supported by WL#5217.
+
+  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);
+      }
+      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,16 @@ restart:
     }
   }
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+  /* TODO: move this to prune_partitions() when implementing WL#4443. */
+  /* 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.cc'
--- a/sql/sql_class.cc	2011-02-03 10:13:06 +0000
+++ b/sql/sql_class.cc	2011-02-18 11:39:05 +0000
@@ -929,8 +929,7 @@ extern "C"   THD *_current_thd_noinline(
 void THD::init(void)
 {
   mysql_mutex_lock(&LOCK_global_system_variables);
-  if (m_enable_plugins)
-    plugin_thdvar_init(this);
+  plugin_thdvar_init(this, m_enable_plugins);
   /*
     variables= global_system_variables above has reset
     variables.pseudo_thread_id to 0. We need to correct it here to

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-02-02 18:31:39 +0000
+++ b/sql/sql_class.h	2011-02-02 22:02:29 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 
 #ifndef SQL_CLASS_INCLUDED
@@ -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-02-03 10:13:06 +0000
+++ b/sql/sql_lex.cc	2011-02-14 10:28:11 +0000
@@ -2014,12 +2014,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-02-16 17:13:30 +0000
+++ b/sql/sql_lex.h	2011-02-19 21:36:09 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /**
   @defgroup Semantic_Analysis Semantic Analysis
@@ -480,6 +480,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) {}
 
@@ -791,6 +792,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-02-21 02:57:30 +0000
+++ b/sql/sql_parse.cc	2011-02-21 11:34:14 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #define MYSQL_LEX 1
 #include "my_global.h"
@@ -5776,6 +5776,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;
@@ -5920,6 +5921,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-28 13:49:59 +0000
+++ b/sql/sql_partition.cc	2011-02-02 22:02:29 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /*
   This file is a container for general functionality related
@@ -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()))
   {
@@ -3971,7 +3976,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.
@@ -3988,7 +3993,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)
@@ -4070,7 +4075,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;
@@ -4122,7 +4127,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; 
@@ -4192,7 +4197,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;
@@ -7141,20 +7146,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)
@@ -7172,7 +7176,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(',');
@@ -7192,7 +7196,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_plugin.cc'
--- a/sql/sql_plugin.cc	2011-02-01 07:52:46 +0000
+++ b/sql/sql_plugin.cc	2011-02-22 02:58:40 +0000
@@ -957,7 +957,10 @@ static void reap_plugins(void)
 
   list= reap;
   while ((plugin= *(--list)))
+  {
+    sql_print_information("Shutting down plugin '%s'", plugin->name.str);
     plugin_deinitialize(plugin, true);
+  }
 
   mysql_mutex_lock(&LOCK_plugin);
 
@@ -2599,7 +2602,7 @@ static char **mysql_sys_var_str(THD* thd
   return (char **) intern_sys_var_ptr(thd, offset, true);
 }
 
-void plugin_thdvar_init(THD *thd)
+void plugin_thdvar_init(THD *thd, bool enable_plugins)
 {
   plugin_ref old_table_plugin= thd->variables.table_plugin;
   DBUG_ENTER("plugin_thdvar_init");
@@ -2615,11 +2618,14 @@ void plugin_thdvar_init(THD *thd)
   thd->variables.dynamic_variables_size= 0;
   thd->variables.dynamic_variables_ptr= 0;
 
-  mysql_mutex_lock(&LOCK_plugin);
-  thd->variables.table_plugin=
-        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
-  intern_plugin_unlock(NULL, old_table_plugin);
-  mysql_mutex_unlock(&LOCK_plugin);
+  if (enable_plugins)
+  {
+    mysql_mutex_lock(&LOCK_plugin);
+    thd->variables.table_plugin=
+      my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
+    intern_plugin_unlock(NULL, old_table_plugin);
+    mysql_mutex_unlock(&LOCK_plugin);
+  }
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2010-12-21 15:27:40 +0000
+++ b/sql/sql_plugin.h	2011-02-18 11:39:05 +0000
@@ -152,7 +152,7 @@ extern bool mysql_install_plugin(THD *th
                                  const LEX_STRING *dl);
 extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
 extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
-extern void plugin_thdvar_init(THD *thd);
+extern void plugin_thdvar_init(THD *thd, bool enable_plugins);
 extern void plugin_thdvar_cleanup(THD *thd);
 extern SHOW_COMP_OPTION plugin_status(const char *name, int len, size_t type);
 extern bool check_valid_path(const char *path, size_t length);

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2011-01-30 16:55:22 +0000
+++ b/sql/sql_table.cc	2011-02-02 22:02:29 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 /* drop and alter of tables */
 

=== modified file 'sql/sql_table.h'
--- a/sql/sql_table.h	2010-11-22 14:57:22 +0000
+++ b/sql/sql_table.h	2011-02-02 22:02:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-12-29 00:38:59 +0000
+++ b/sql/sql_update.cc	2011-02-21 15:55:58 +0000
@@ -999,6 +999,98 @@ static table_map get_table_map(List<Item
   return map;
 }
 
+/**
+  If one row is updated through two different aliases and the first
+  update physically moves the row, the second update will error
+  because the row is no longer located where expected. This function
+  checks if the multiple-table update is about to do that and if so
+  returns with an error.
+
+  The following update operations physically moves rows:
+    1) Update of a column in a clustered primary key
+    2) Update of a column used to calculate which partition the row belongs to
+
+  This function returns with an error if both of the following are
+  true:
+
+    a) A table in the multiple-table update statement is updated
+       through multiple aliases (including views)
+    b) At least one of the updates on the table from a) may physically
+       moves the row. Note: Updating a column used to calculate which
+       partition a row belongs to does not necessarily mean that the
+       row is moved. The new value may or may not belong to the same
+       partition.
+
+  @param leaves               First leaf table
+  @param tables_for_update    Map of tables that are updated
+
+  @return
+    true   if the update is unsafe, in which case an error message is also set,
+    false  otherwise.
+*/
+static
+bool unsafe_key_update(TABLE_LIST *leaves, table_map tables_for_update)
+{
+  TABLE_LIST *tl= leaves;
+
+  for (tl= leaves; tl ; tl= tl->next_leaf)
+  {
+    if (tl->table->map & tables_for_update)
+    {
+      TABLE *table1= tl->table;
+      bool primkey_clustered= (table1->file->primary_key_is_clustered() &&
+                               table1->s->primary_key != MAX_KEY);
+
+      bool table_partitioned= false;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+      table_partitioned= (table1->part_info != NULL);
+#endif
+
+      if (!table_partitioned && !primkey_clustered)
+        continue;
+
+      for (TABLE_LIST* tl2= tl->next_leaf; tl2 ; tl2= tl2->next_leaf)
+      {
+        /*
+          Look at "next" tables only since all previous tables have
+          already been checked
+        */
+        TABLE *table2= tl2->table;
+        if (table2->map & tables_for_update && table1->s == table2->s)
+        {
+          // A table is updated through two aliases
+          if (table_partitioned &&
+              (partition_key_modified(table1, table1->write_set) ||
+               partition_key_modified(table2, table2->write_set)))
+          {
+            // Partitioned key is updated
+            my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0),
+                     tl->belong_to_view ? tl->belong_to_view->alias
+                                        : tl->alias,
+                     tl2->belong_to_view ? tl2->belong_to_view->alias
+                                         : tl2->alias);
+            return true;
+          }
+
+          if (primkey_clustered &&
+              (bitmap_is_set(table1->write_set, table1->s->primary_key) ||
+               bitmap_is_set(table2->write_set, table2->s->primary_key)))
+          {
+            // Clustered primary key is updated
+            my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0),
+                     tl->belong_to_view ? tl->belong_to_view->alias
+                                        : tl->alias,
+                     tl2->belong_to_view ? tl2->belong_to_view->alias
+                                         : tl2->alias);
+            return true;
+          }
+        }
+      }
+    }
+  }
+  return false;
+}
+
 
 /*
   make update specific preparation and checks after opening tables
@@ -1078,10 +1170,14 @@ int mysql_multi_update_prepare(THD *thd)
 
   thd->table_map_for_update= tables_for_update= get_table_map(fields);
 
+  leaves= lex->select_lex.leaf_tables;
+
+  if (unsafe_key_update(leaves, tables_for_update))
+    DBUG_RETURN(true);
+
   /*
     Setup timestamp handling and locking mode
   */
-  leaves= lex->select_lex.leaf_tables;
   for (tl= leaves; tl; tl= tl->next_leaf)
   {
     TABLE *table= tl->table;

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-02-16 17:13:30 +0000
+++ b/sql/sql_yacc.yy	2011-02-21 11:34:14 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011 Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -781,10 +781,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.
@@ -1172,9 +1172,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
@@ -1508,7 +1508,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
@@ -7620,7 +7620,7 @@ expr:
         | expr XOR expr %prec XOR
           {
             /* XOR is a proprietary extension */
-            $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
+            $$ = new (YYTHD->mem_root) Item_func_xor($1, $3);
             if ($$ == NULL)
               MYSQL_YYABORT;
           }
@@ -9412,6 +9412,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>
@@ -9425,13 +9441,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($$);
           }
@@ -9501,7 +9518,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;
@@ -10489,6 +10506,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
@@ -10612,7 +10642,7 @@ insert2:
         ;
 
 insert_table:
-          table_name
+          table_name_with_opt_use_partition
           {
             LEX *lex=Lex;
             lex->field_list.empty();
@@ -10812,11 +10842,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;
@@ -11561,18 +11593,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
@@ -12510,7 +12542,6 @@ keyword:
         | OPTIONS_SYM           {}
         | OWNER_SYM             {}
         | PARSER_SYM            {}
-        | PARTITION_SYM         {}
         | PORT_SYM              {}
         | PREPARE_SYM           {}
         | REMOVE_SYM            {}

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2011-02-17 11:58:08 +0000
+++ b/sql/sys_vars.cc	2011-02-22 02:58:40 +0000
@@ -359,6 +359,9 @@ static bool fix_binlog_format_after_upda
   return false;
 }
 
+static Sys_var_test_flag Sys_core_file(
+       "core_file", "write a core-file on crashes", TEST_CORE_ON_SIGNAL);
+
 static Sys_var_enum Sys_binlog_format(
        "binlog_format", "What form of binary logging the master will "
        "use: either ROW for row-based binary logging, STATEMENT "
@@ -1520,7 +1523,7 @@ static Sys_var_proxy_user Sys_proxy_user
        "proxy_user", "The proxy user account name used when logging in",
        IN_SYSTEM_CHARSET);
 
-static Sys_var_external_user Sys_exterenal_user(
+static Sys_var_external_user Sys_external_user(
        "external_user", "The external user account used when logging in",
        IN_SYSTEM_CHARSET);
 

=== modified file 'sql/sys_vars.h'
--- a/sql/sys_vars.h	2010-12-21 15:27:40 +0000
+++ b/sql/sys_vars.h	2011-02-10 05:29:15 +0000
@@ -842,6 +842,35 @@ public:
 };
 
 /**
+  The class for @test_flags (core_file for now).
+  It's derived from Sys_var_mybool.
+
+  Class specific constructor arguments:
+    Caller need not pass in a variable as we make up the value on the
+    fly, that is, we derive it from the global test_flags bit vector.
+
+  Backing store: my_bool
+*/
+class Sys_var_test_flag: public Sys_var_mybool
+{
+private:
+  my_bool test_flag_value;
+  uint    test_flag_mask;
+public:
+  Sys_var_test_flag(const char *name_arg, const char *comment, uint mask)
+  : Sys_var_mybool(name_arg, comment, READ_ONLY GLOBAL_VAR(test_flag_value),
+          NO_CMD_LINE, DEFAULT(FALSE))
+  {
+    test_flag_mask= mask;
+  }
+  uchar *global_value_ptr(THD *thd, LEX_STRING *base)
+  {
+    test_flag_value= ((test_flags & test_flag_mask) > 0);
+    return (uchar*) &test_flag_value;
+  }
+};
+
+/**
   The class for the @max_user_connections.
   It's derived from Sys_var_uint, but non-standard session value
   requires a new class.

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2011-02-09 15:17:14 +0000
+++ b/sql/table.cc	2011-02-14 10:28:11 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 
 /* Some general useful functions */
@@ -204,6 +204,19 @@ static uchar *get_field_name(Field **buf
 }
 
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+/**
+  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;
+}
+#endif
+
+
 /*
   Returns pointer to '.frm' extension of the file name.
 
@@ -1974,8 +1987,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 +2140,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-02-02 22:02:29 +0000
@@ -1,7 +1,7 @@
 #ifndef TABLE_INCLUDED
 #define TABLE_INCLUDED
 
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,8 +13,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
 
 #include "my_global.h"                          /* NO_EMBEDDED_ACCESS_CHECKS */
 #include "sql_plist.h"
@@ -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);

=== modified file 'storage/innobase/btr/btr0sea.c'
--- a/storage/innobase/btr/btr0sea.c	2011-02-17 14:06:09 +0000
+++ b/storage/innobase/btr/btr0sea.c	2011-02-18 16:16:09 +0000
@@ -1625,25 +1625,6 @@ btr_search_update_hash_node_on_insert(
 
 /********************************************************************//**
 Updates the page hash index when a single record is inserted on a page. */
-UNIV_INLINE
-void
-btr_search_insert_fold(
-/*===================*/
-	hash_table_t*   table,  /*!< in: hash table */
-	ulint           fold,   /*!< in: folded value of data; if a node with
-				the same fold value already exists, it is
-				updated to point to the same data, and no new
-				node is created! */
-	buf_block_t*    block,  /*!< in: buffer block containing the data */
-	void*           data)	/*!< in: data, must not be NULL */
-{
-	ha_insert_for_fold(table, fold, block, data);
-
-	MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED);
-}
-
-/********************************************************************//**
-Updates the page hash index when a single record is inserted on a page. */
 UNIV_INTERN
 void
 btr_search_update_hash_on_insert(
@@ -1722,7 +1703,7 @@ btr_search_update_hash_on_insert(
 
 			locked = TRUE;
 
-			btr_search_insert_fold(table, ins_fold, block, ins_rec);
+			ha_insert_for_fold(table, ins_fold, block, ins_rec);
 		}
 
 		goto check_next_rec;
@@ -1738,9 +1719,9 @@ btr_search_update_hash_on_insert(
 		}
 
 		if (!left_side) {
-			btr_search_insert_fold(table, fold, block, rec);
+			ha_insert_for_fold(table, fold, block, rec);
 		} else {
-			btr_search_insert_fold(table, ins_fold, block, ins_rec);
+			ha_insert_for_fold(table, ins_fold, block, ins_rec);
 		}
 	}
 
@@ -1755,7 +1736,7 @@ check_next_rec:
 				locked = TRUE;
 			}
 
-			btr_search_insert_fold(table, ins_fold, block, ins_rec);
+			ha_insert_for_fold(table, ins_fold, block, ins_rec);
 		}
 
 		goto function_exit;
@@ -1772,15 +1753,14 @@ check_next_rec:
 
 		if (!left_side) {
 
-			btr_search_insert_fold(table, ins_fold, block, ins_rec);
+			ha_insert_for_fold(table, ins_fold, block, ins_rec);
 			/*
 			fputs("Hash insert for ", stderr);
 			dict_index_name_print(stderr, cursor->index);
 			fprintf(stderr, " fold %lu\n", ins_fold);
 			*/
 		} else {
-			btr_search_insert_fold(table, next_fold, block,
-					       next_rec);
+			ha_insert_for_fold(table, next_fold, block, next_rec);
 		}
 	}
 

=== modified file 'storage/innobase/include/ha0ha.h'
--- a/storage/innobase/include/ha0ha.h	2011-02-17 14:06:09 +0000
+++ b/storage/innobase/include/ha0ha.h	2011-02-18 16:16:09 +0000
@@ -155,7 +155,10 @@ is inserted.
 @param f	in: folded value of data
 @param b	in: buffer block containing the data
 @param d	in: data, must not be NULL */
-# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,b,d)
+# define ha_insert_for_fold(t,f,b,d) 	do {		\
+	ha_insert_for_fold_func(t,f,b,d);		\
+	MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED);	\
+} while(0)
 #else /* UNIV_AHI_DEBUG || UNIV_DEBUG */
 /**
 Inserts an entry into a hash table. If an entry with the same fold number
@@ -166,7 +169,10 @@ is inserted.
 @param f	in: folded value of data
 @param b	ignored: buffer block containing the data
 @param d	in: data, must not be NULL */
-# define ha_insert_for_fold(t,f,b,d) ha_insert_for_fold_func(t,f,d)
+# define ha_insert_for_fold(t,f,b,d)	do {		\
+	ha_insert_for_fold_func(t,f,d);			\
+	MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED);	\
+} while (0)
 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
 
 /*********************************************************//**

=== modified file 'unittest/gunit/item-t.cc'
--- a/unittest/gunit/item-t.cc	2011-02-07 13:03:47 +0000
+++ b/unittest/gunit/item-t.cc	2011-02-21 10:36:31 +0000
@@ -1,6 +1,5 @@
 /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 
 
-
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.
@@ -36,7 +35,10 @@ protected:
    */
   static void SetUpTestCase()
   {
-    init_thread_environment();
+    static char *my_name= strdup(my_progname);
+    char *argv[] = { my_name, 0 };
+    set_remaining_args(1, argv);
+    init_common_variables();
     randominit(&sql_rand, 0, 0);
     xid_cache_init();
     delegates_init();
@@ -94,6 +96,9 @@ public:
     EXPECT_EQ(1, m_store_called);
   }
 
+  // Avoid warning about hiding other overloaded versions of store().
+  using Field_long::store;
+
   /*
     This is the only member function we need to override.
     We expect it to be called with specific arguments.
@@ -183,4 +188,101 @@ TEST_F(ItemTest, ItemFuncDesDecrypt)
   EXPECT_LE(item_decrypt->max_length, length);
 }
 
+
+/*
+  This is not an exhaustive test. It simply demonstrates that more of the
+  initializations in mysqld.cc are needed for testing Item_xxx classes.
+*/
+TEST_F(ItemTest, ItemFuncSetUserVar)
+{
+  const longlong val1= 1;
+  Item_decimal *item_dec= new Item_decimal(val1, false);
+  Item_string  *item_str= new Item_string("1", 1, &my_charset_latin1);
+
+  LEX_STRING var_name= { C_STRING_WITH_LEN("a") };
+  Item_func_set_user_var *user_var=
+    new Item_func_set_user_var(var_name, item_str);
+  EXPECT_FALSE(user_var->set_entry(m_thd, true));
+  EXPECT_FALSE(user_var->fix_fields(m_thd, NULL));
+  EXPECT_EQ(val1, user_var->val_int());
+  
+  my_decimal decimal;
+  my_decimal *decval_1= user_var->val_decimal(&decimal);
+  user_var->save_item_result(item_str);
+  my_decimal *decval_2= user_var->val_decimal(&decimal);
+  user_var->save_item_result(item_dec);
+
+  EXPECT_EQ(decval_1, decval_2);
+  EXPECT_EQ(decval_1, &decimal);
+}
+
+
+// Test of Item::operator new() when we simulate out-of-memory.
+TEST_F(ItemTest, OutOfMemory)
+{
+  Item_int *null_item= NULL;
+  Item_int *item= new Item_int(42);
+  EXPECT_NE(null_item, item);
+  delete null_item;
+
+#if !defined(DBUG_OFF)
+  // Setting debug flags triggers enter/exit trace, so redirect to /dev/null.
+  DBUG_SET("o," IF_WIN("NUL", "/dev/null"));
+
+  DBUG_SET("+d,simulate_out_of_memory");
+  item= new Item_int(42);
+  EXPECT_EQ(null_item, item);
+
+  DBUG_SET("+d,simulate_out_of_memory");
+  item= new (m_thd->mem_root) Item_int(42);
+  EXPECT_EQ(null_item, item);
+#endif
+}
+
+TEST_F(ItemTest, ItemFuncXor)
+{
+  const uint length= 1U;
+  Item_int *item_zero= new Item_int(0, length);
+  Item_int *item_one_a= new Item_int(1, length);
+
+  Item_func_xor *item_xor=
+    new Item_func_xor(item_zero, item_one_a);
+
+  EXPECT_FALSE(item_xor->fix_fields(m_thd, NULL));
+  EXPECT_EQ(1, item_xor->val_int());
+  EXPECT_EQ(1U, item_xor->decimal_precision());
+
+  Item_int *item_one_b= new Item_int(1, length);
+
+  Item_func_xor *item_xor_same=
+    new Item_func_xor(item_one_a, item_one_b);
+
+  EXPECT_FALSE(item_xor_same->fix_fields(m_thd, NULL));
+  EXPECT_EQ(0, item_xor_same->val_int());
+  EXPECT_FALSE(item_xor_same->val_bool());
+  EXPECT_FALSE(item_xor_same->is_null());
+
+  String print_buffer;
+  item_xor->print(&print_buffer, QT_ORDINARY);
+  EXPECT_STREQ("(0 xor 1)", print_buffer.c_ptr_safe());
+
+  Item *neg_xor= item_xor->neg_transformer(m_thd);
+  EXPECT_FALSE(neg_xor->fix_fields(m_thd, NULL));
+  EXPECT_EQ(0, neg_xor->val_int());
+  EXPECT_DOUBLE_EQ(0.0, neg_xor->val_real());
+  EXPECT_FALSE(neg_xor->val_bool());
+  EXPECT_FALSE(neg_xor->is_null());
+
+  print_buffer= String();
+  neg_xor->print(&print_buffer, QT_ORDINARY);
+  EXPECT_STREQ("((not(0)) xor 1)", print_buffer.c_ptr_safe());
+
+  Item_func_xor *item_xor_null=
+    new Item_func_xor(item_zero, new Item_null());
+  EXPECT_FALSE(item_xor_null->fix_fields(m_thd, NULL));
+
+  EXPECT_EQ(0, item_xor_null->val_int());
+  EXPECT_TRUE(item_xor_null->is_null());
+}
+
 }

No bundle (reason: revision is a merge (you can force generation of a bundle with env var BZR_FORCE_BUNDLE=1)).
Thread
bzr commit into mysql-trunk branch (daogang.qu:3218) WL#5493daogang.qu22 Feb