List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:January 26 2012 1:12pm
Subject:bzr push into mysql-trunk-wl5534 branch (jon.hauglid:3469 to 3470)
View as plain text  
 3470 Jon Olav Hauglid	2012-01-26 [merge]
      Merge from mysql-trunk to mysql-trunk-wl5534
      No conflicts

    added:
      mysql-test/suite/sys_vars/r/stored_program_cache_basic.result
      mysql-test/suite/sys_vars/t/stored_program_cache_basic.test
    renamed:
      mysql-test/suite/sys_vars/r/innodb_sort_buf_size_basic.result => mysql-test/suite/sys_vars/r/innodb_sort_buffer_size_basic.result
      mysql-test/suite/sys_vars/t/innodb_sort_buf_size_basic.test => mysql-test/suite/sys_vars/t/innodb_sort_buffer_size_basic.test
    modified:
      cmake/build_configurations/mysql_release.cmake
      include/m_ctype.h
      mysql-test/extra/rpl_tests/rpl_start_stop_slave.test
      mysql-test/include/have_example_plugin.inc
      mysql-test/include/have_semisync_plugin.inc
      mysql-test/include/have_simple_parser.inc
      mysql-test/include/have_udf.inc
      mysql-test/include/order_by.inc
      mysql-test/include/range.inc
      mysql-test/include/show_slave_status.inc
      mysql-test/include/wait_for_ndb_to_binlog.inc
      mysql-test/mysql-test-run.pl
      mysql-test/r/bigint.result
      mysql-test/r/ctype_utf8.result
      mysql-test/r/date_formats.result
      mysql-test/r/func_in_icp.result
      mysql-test/r/func_in_icp_mrr.result
      mysql-test/r/func_in_mrr.result
      mysql-test/r/func_in_mrr_cost.result
      mysql-test/r/func_in_none.result
      mysql-test/r/func_str.result
      mysql-test/r/func_time.result
      mysql-test/r/innodb_icp.result
      mysql-test/r/innodb_icp_none.result
      mysql-test/r/innodb_mrr.result
      mysql-test/r/innodb_mrr_cost.result
      mysql-test/r/innodb_mrr_cost_icp.result
      mysql-test/r/innodb_mrr_icp.result
      mysql-test/r/innodb_mrr_none.result
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
      mysql-test/r/optimizer_debug_sync.result
      mysql-test/r/order_by_icp_mrr.result
      mysql-test/r/order_by_none.result
      mysql-test/r/partition_binlog_stmt.result
      mysql-test/r/partition_explicit_prune.result
      mysql-test/r/plugin.result
      mysql-test/r/range_all.result
      mysql-test/r/range_icp.result
      mysql-test/r/range_icp_mrr.result
      mysql-test/r/range_mrr.result
      mysql-test/r/range_mrr_cost.result
      mysql-test/r/range_none.result
      mysql-test/r/temporal_literal.result
      mysql-test/r/type_date.result
      mysql-test/r/type_temporal_fractional.result
      mysql-test/r/type_temporal_upgrade.result
      mysql-test/r/type_time.result
      mysql-test/r/view.result
      mysql-test/r/xa.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/rpl/r/rpl_heartbeat_basic.result
      mysql-test/suite/rpl/r/rpl_log_pos.result
      mysql-test/suite/rpl/r/rpl_manual_change_index_file.result
      mysql-test/suite/rpl/r/rpl_packet.result
      mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result
      mysql-test/suite/rpl/t/rpl_heartbeat_basic.test
      mysql-test/suite/sys_vars/r/innodb_undo_logs_basic.result
      mysql-test/suite/sys_vars/t/innodb_undo_logs_basic.test
      mysql-test/t/bigint.test
      mysql-test/t/ctype_utf8.test
      mysql-test/t/date_formats.test
      mysql-test/t/func_str.test
      mysql-test/t/func_time.test
      mysql-test/t/mysql_embedded.test
      mysql-test/t/optimizer_debug_sync.test
      mysql-test/t/partition_binlog_stmt.test
      mysql-test/t/partition_explicit_prune.test
      mysql-test/t/plugin.test
      mysql-test/t/temporal_literal.test
      mysql-test/t/type_date.test
      mysql-test/t/type_temporal_fractional.test
      mysql-test/t/type_temporal_upgrade.test
      mysql-test/t/type_time.test
      mysql-test/t/udf_skip_grants-master.opt
      mysql-test/t/view.test
      mysql-test/t/xa.test
      mysys/charset-def.c
      sql/debug_sync.cc
      sql/handler.cc
      sql/handler.h
      sql/item.cc
      sql/item_cmpfunc.cc
      sql/item_timefunc.cc
      sql/mysqld.cc
      sql/mysqld.h
      sql/opt_explain.cc
      sql/opt_range.cc
      sql/records.cc
      sql/rpl_master.cc
      sql/share/errmsg-utf8.txt
      sql/sp_cache.cc
      sql/sp_cache.h
      sql/sql_executor.cc
      sql/sql_lex.cc
      sql/sql_parse.cc
      sql/sql_prepare.cc
      sql/sql_select.cc
      sql/sql_tmp_table.cc
      sql/sql_view.cc
      sql/sys_vars.cc
      storage/example/ha_example.cc
      storage/innobase/btr/btr0btr.cc
      storage/innobase/btr/btr0cur.cc
      storage/innobase/buf/buf0buf.cc
      storage/innobase/buf/buf0dblwr.cc
      storage/innobase/buf/buf0flu.cc
      storage/innobase/data/data0data.cc
      storage/innobase/dict/dict0load.cc
      storage/innobase/dict/dict0stats.cc
      storage/innobase/fts/fts0fts.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/i_s.cc
      storage/innobase/ibuf/ibuf0ibuf.cc
      storage/innobase/include/btr0btr.h
      storage/innobase/include/buf0flu.h
      storage/innobase/include/data0data.h
      storage/innobase/include/data0data.ic
      storage/innobase/include/mtr0log.ic
      storage/innobase/lock/lock0lock.cc
      storage/innobase/os/os0file.cc
      storage/innobase/page/page0page.cc
      storage/innobase/row/row0ins.cc
      storage/innobase/row/row0sel.cc
      storage/innobase/row/row0umod.cc
      storage/innobase/row/row0upd.cc
      storage/innobase/srv/srv0srv.cc
      storage/innobase/trx/trx0purge.cc
      storage/innobase/trx/trx0rec.cc
      storage/innobase/trx/trx0trx.cc
      storage/innobase/ut/ut0crc32.cc
      storage/perfschema/ha_perfschema.cc
      storage/perfschema/pfs_engine_table.cc
      storage/perfschema/pfs_engine_table.h
      storage/perfschema/pfs_instr_class.cc
      storage/perfschema/pfs_instr_class.h
      storage/perfschema/pfs_server.cc
      storage/perfschema/table_esgs_by_account_by_event_name.cc
      storage/perfschema/table_esgs_by_account_by_event_name.h
      storage/perfschema/table_esgs_by_host_by_event_name.cc
      storage/perfschema/table_esgs_by_host_by_event_name.h
      storage/perfschema/table_esgs_by_thread_by_event_name.cc
      storage/perfschema/table_esgs_by_thread_by_event_name.h
      storage/perfschema/table_esgs_by_user_by_event_name.cc
      storage/perfschema/table_esgs_by_user_by_event_name.h
      storage/perfschema/table_esgs_global_by_event_name.cc
      storage/perfschema/table_esgs_global_by_event_name.h
      storage/perfschema/table_esms_by_account_by_event_name.cc
      storage/perfschema/table_esms_by_account_by_event_name.h
      storage/perfschema/table_esms_by_host_by_event_name.cc
      storage/perfschema/table_esms_by_host_by_event_name.h
      storage/perfschema/table_esms_by_thread_by_event_name.cc
      storage/perfschema/table_esms_by_thread_by_event_name.h
      storage/perfschema/table_esms_by_user_by_event_name.cc
      storage/perfschema/table_esms_by_user_by_event_name.h
      storage/perfschema/table_esms_global_by_event_name.cc
      storage/perfschema/table_esms_global_by_event_name.h
      storage/perfschema/table_events_stages.cc
      storage/perfschema/table_events_stages.h
      storage/perfschema/table_events_statements.cc
      storage/perfschema/table_events_statements.h
      storage/perfschema/table_events_waits.cc
      storage/perfschema/table_events_waits_summary.cc
      storage/perfschema/table_ews_by_account_by_event_name.cc
      storage/perfschema/table_ews_by_host_by_event_name.cc
      storage/perfschema/table_ews_by_thread_by_event_name.cc
      storage/perfschema/table_ews_by_user_by_event_name.cc
      storage/perfschema/table_ews_global_by_event_name.cc
      storage/perfschema/table_tiws_by_index_usage.cc
      storage/perfschema/table_tiws_by_index_usage.h
      storage/perfschema/table_tiws_by_table.cc
      storage/perfschema/table_tiws_by_table.h
      storage/perfschema/table_tlws_by_table.cc
      storage/perfschema/table_tlws_by_table.h
      strings/ctype-ucs2.c
      strings/ctype-utf8.c
      strings/dtoa.c
      mysql-test/suite/sys_vars/r/innodb_sort_buffer_size_basic.result
      mysql-test/suite/sys_vars/t/innodb_sort_buffer_size_basic.test
 3469 Jon Olav Hauglid	2012-01-26
      WL#5534 Online ALTER, Phase 1.
      
      Patch #77:
      Minor polish to reduce size of merge to trunk.

    modified:
      sql/handler.cc
      sql/handler.h
      sql/sql_insert.cc
      sql/sql_table.cc
=== modified file 'cmake/build_configurations/mysql_release.cmake'
--- a/cmake/build_configurations/mysql_release.cmake	2011-12-08 20:30:18 +0000
+++ b/cmake/build_configurations/mysql_release.cmake	2012-01-20 19:32:00 +0000
@@ -149,11 +149,19 @@ IF(UNIX)
   # Default GCC flags
   IF(CMAKE_COMPILER_IS_GNUCC)
     SET(COMMON_C_FLAGS               "-g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing")
+    # Disable inline optimizations for valgrind testing to avoid false positives
+    IF(WITH_VALGRIND)
+      SET(COMMON_C_FLAGS             "-fno-inline ${COMMON_C_FLAGS}")
+    ENDIF()
     SET(CMAKE_C_FLAGS_DEBUG          "-O ${COMMON_C_FLAGS}")
     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
   ENDIF()
   IF(CMAKE_COMPILER_IS_GNUCXX)
     SET(COMMON_CXX_FLAGS               "-g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing")
+    # Disable inline optimizations for valgrind testing to avoid false positives
+    IF(WITH_VALGRIND)
+      SET(COMMON_CXX_FLAGS             "-fno-inline ${COMMON_CXX_FLAGS}")
+    ENDIF()
     SET(CMAKE_CXX_FLAGS_DEBUG          "-O ${COMMON_CXX_FLAGS}")
     SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")
   ENDIF()
@@ -166,7 +174,7 @@ IF(UNIX)
         SET(COMMON_CXX_FLAGS               "+DSitanium2 -mt -Aa")
         SET(CMAKE_C_FLAGS_DEBUG            "+O0 -g ${COMMON_C_FLAGS}")
         SET(CMAKE_CXX_FLAGS_DEBUG          "+O0 -g ${COMMON_CXX_FLAGS}")
-	# We have seen compiler bugs with optimisation and -g, so disabled for now
+        # We have seen compiler bugs with optimisation and -g, so disabled for now
         SET(CMAKE_C_FLAGS_RELWITHDEBINFO   "+O2 ${COMMON_C_FLAGS}")
         SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "+O2 ${COMMON_CXX_FLAGS}")
       ENDIF()

=== modified file 'include/m_ctype.h'
--- a/include/m_ctype.h	2011-06-30 15:50:45 +0000
+++ b/include/m_ctype.h	2012-01-23 10:02:54 +0000
@@ -73,6 +73,7 @@ typedef struct unicase_info_st
 
 extern MY_UNICASE_INFO my_unicase_default;
 extern MY_UNICASE_INFO my_unicase_turkish;
+extern MY_UNICASE_INFO my_unicase_mysql500;
 extern MY_UNICASE_INFO my_unicase_unicode520;
 
 #define MY_UCA_MAX_CONTRACTION 6
@@ -454,6 +455,7 @@ extern CHARSET_INFO my_charset_tis620_bi
 extern CHARSET_INFO my_charset_ucs2_general_ci;
 extern CHARSET_INFO my_charset_ucs2_bin;
 extern CHARSET_INFO my_charset_ucs2_unicode_ci;
+extern CHARSET_INFO my_charset_ucs2_general_mysql500_ci;
 extern CHARSET_INFO my_charset_ujis_japanese_ci;
 extern CHARSET_INFO my_charset_ujis_bin;
 extern CHARSET_INFO my_charset_utf16_bin;
@@ -469,6 +471,7 @@ extern MYSQL_PLUGIN_IMPORT CHARSET_INFO
 extern CHARSET_INFO my_charset_utf8_tolower_ci;
 extern CHARSET_INFO my_charset_utf8_unicode_ci;
 extern CHARSET_INFO my_charset_utf8_bin;
+extern CHARSET_INFO my_charset_utf8_general_mysql500_ci;
 extern CHARSET_INFO my_charset_utf8mb4_bin;
 extern CHARSET_INFO my_charset_utf8mb4_general_ci;
 extern CHARSET_INFO my_charset_utf8mb4_unicode_ci;

=== modified file 'mysql-test/extra/rpl_tests/rpl_start_stop_slave.test'
--- a/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test	2012-01-17 22:32:29 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test	2012-01-19 20:03:07 +0000
@@ -179,7 +179,8 @@ DROP TABLE t1;
 sync_slave_with_master;
 
 #
-# bug#3593869-64035 uninitialized event_coordinates instance crashes server
+# bug#3593869-64035 attempt to read a member of event_coordinates
+# referenced by NULL pointer crashes server.
 # Testing how out of valid range position value is handled with an error.
 #
 
@@ -199,7 +200,7 @@ START SLAVE;
 --let $slave_param_value=1236
 --source include/wait_for_slave_param.inc
 
---let $slave_io_error_replace= / at [0-9]*/ at XXX/ /\.\/*master-bin/master-bin/
+--let $slave_field_result_replace= / at [0-9]*/ at XXX/
 --let $status_items= Last_IO_Errno, Last_IO_Error
 --source include/show_slave_status.inc
 

=== modified file 'mysql-test/include/have_example_plugin.inc'
--- a/mysql-test/include/have_example_plugin.inc	2010-11-17 10:16:13 +0000
+++ b/mysql-test/include/have_example_plugin.inc	2012-01-20 11:35:48 +0000
@@ -15,7 +15,7 @@ if (!$EXAMPLE_PLUGIN) {
 #
 # Check if --plugin-dir was setup for exampledb
 #
-if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$EXAMPLE_PLUGIN_OPT'`) {
+if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$EXAMPLE_PLUGIN_OPT/'`) {
   --skip Example plugin requires that --plugin-dir is set to the example plugin dir (either the .opt file does not contain \$EXAMPLE_PLUGIN_OPT or another plugin is in use)
 }
 enable_query_log;

=== modified file 'mysql-test/include/have_semisync_plugin.inc'
--- a/mysql-test/include/have_semisync_plugin.inc	2010-11-17 10:16:13 +0000
+++ b/mysql-test/include/have_semisync_plugin.inc	2012-01-20 11:35:48 +0000
@@ -16,6 +16,6 @@ if (!$SEMISYNC_MASTER_PLUGIN)
 #
 # Check if --plugin-dir was setup for semisync
 #
-if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$SEMISYNC_PLUGIN_OPT'`) {
+if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$SEMISYNC_PLUGIN_OPT/'`) {
   --skip SEMISYNC plugin requires that --plugin-dir is set to the semisync plugin dir (either the .opt file does not contain \$SEMISYNC_PLUGIN_OPT or another plugin is in use)
 }

=== modified file 'mysql-test/include/have_simple_parser.inc'
--- a/mysql-test/include/have_simple_parser.inc	2010-11-17 10:16:13 +0000
+++ b/mysql-test/include/have_simple_parser.inc	2012-01-20 11:35:48 +0000
@@ -15,6 +15,6 @@ if (!$SIMPLE_PARSER) {
 #
 # Check if --plugin-dir was setup for simple parser
 #
-if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$SIMPLE_PARSER_OPT'`) {
+if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$SIMPLE_PARSER_OPT/'`) {
   --skip simple parser requires that --plugin-dir is set to the udf plugin dir (either the .opt file does not contain \$UDF_EXAMPLE_LIB_OPT or another plugin is in use)
 }

=== modified file 'mysql-test/include/have_udf.inc'
--- a/mysql-test/include/have_udf.inc	2010-11-17 10:16:13 +0000
+++ b/mysql-test/include/have_udf.inc	2012-01-20 11:35:48 +0000
@@ -15,6 +15,6 @@ if (!$UDF_EXAMPLE_LIB) {
 #
 # Check if --plugin-dir was setup for udf
 #
-if (`SELECT CONCAT('--plugin-dir=', @@plugin_dir) != '$UDF_EXAMPLE_LIB_OPT'`) {
+if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$UDF_EXAMPLE_LIB_OPT/'`) {
   --skip UDF requires that --plugin-dir is set to the udf plugin dir (either the .opt file does not contain \$UDF_EXAMPLE_LIB_OPT or another plugin is in use)
 }

=== modified file 'mysql-test/include/order_by.inc'
--- a/mysql-test/include/order_by.inc	2011-12-19 09:22:28 +0000
+++ b/mysql-test/include/order_by.inc	2012-01-25 14:52:00 +0000
@@ -1750,3 +1750,34 @@ INSERT INTO t1 VALUES (1), (2);
 INSERT INTO t2 VALUES (1,2), (2,3);
 SELECT (SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC) FROM t2;
 DROP TABLE t1, t2;
+
+--echo #
+--echo # Bug #13531865
+--echo # TEST_IF_SKIP_SORT_ORDER() INCORRECTLY SKIP FILESORT IF
+--echo # 'TYPE' IS REF_OR_NULL 
+--echo # 
+--echo #
+
+CREATE TABLE t1 (
+  a INT,
+  c INT,
+  UNIQUE KEY a_c (a,c),
+  KEY (a)) engine=myisam;
+
+INSERT INTO t1 VALUES (1,10), (2,NULL), (2,10);
+ANALYZE TABLE t1;
+
+--echo # Using 'KEY a_c' for order-by opt, would have required 
+--echo # REF_OR_NULL access which never can be order_by skipped.
+--echo # -> Keep initial REF on 'KEY a' selected by cond. optimizer
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL);
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+
+DROP TABLE t1;

=== modified file 'mysql-test/include/range.inc'
--- a/mysql-test/include/range.inc	2011-12-09 15:06:50 +0000
+++ b/mysql-test/include/range.inc	2012-01-26 10:08:12 +0000
@@ -1392,6 +1392,82 @@ SELECT * FROM t1, t1 as t2 WHERE t1.i4 B
 
 DROP TABLE t1;
 
+--echo #
+--echo # BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+--echo # WITH/WITHOUT INDEX RANGE SCAN
+--echo #
+
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1;  
+insert into t1 select null from t1; 
+create table t2 (
+ id int unsigned not null auto_increment,
+ val decimal(5,3) not null,
+ primary key (id,val),
+ unique key (val,id),
+ unique key (id));  
+--disable_warnings
+insert into t2 select null,id*0.0009 from t1;
+--enable_warnings
+
+select count(val) from t2 ignore index (val) where val > 0.1155;
+select count(val) from t2 force index (val)  where val > 0.1155;
+
+drop table t2, t1;
+
+--echo #
+--echo # BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+--echo # RESULTS WITH DECIMAL CONVERSION
+--echo #
+
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+# show that the integer 3 is bigger than the decimal 2.9,
+# which should also apply to comparing "c" with 2.9
+# when c is 3.
+select convert(3, signed integer) > 2.9;
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+drop table t1;
+
+--echo #
+--echo # BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+--echo # RESULT AFTER MYSQL 5.1.
+--echo #
+
+CREATE TABLE t1(
+ F1 CHAR(5) NOT NULL,
+ F2 CHAR(5) NOT NULL,
+ F3 CHAR(5) NOT NULL,
+ PRIMARY KEY(F1),
+ INDEX IDX_F2(F2)
+);
+
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+
+SELECT * FROM t1 WHERE F1 = 'A    ';
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+SELECT * FROM t1 WHERE F1 > 'A    ';
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests
 
 #

=== modified file 'mysql-test/include/show_slave_status.inc'
--- a/mysql-test/include/show_slave_status.inc	2012-01-04 15:48:00 +0000
+++ b/mysql-test/include/show_slave_status.inc	2012-01-19 20:03:07 +0000
@@ -56,10 +56,17 @@
 #
 #       --let $status_items= Master_Log_File, Relay_Master_Log_File
 #
-#   $slave_io_error_replace
+#   $slave_field_result_replace
 #     If set, one or more regex patterns for replacing variable
 #     text in the error message. Syntax as --replace-regex
 #
+#   $slave_sql_mode
+#     If set, change the slave sql mode during this macro, reverting
+#     to the previous on exit. Default sql_mode is NO_BACKSLASH_ESCAPES
+#     to allow replace '\' by '/' making paths OS independent. Example:
+#
+#       --let $slave_sql_mode= NO_BACKSLASH_ESCAPES
+#
 
 
 --let $_show_slave_status_items= $status_items
@@ -69,13 +76,30 @@ if (!$status_items)
 }
 
 
+--let $_slave_sql_mode= NO_BACKSLASH_ESCAPES
+if ($slave_sql_mode)
+{
+  --let $_slave_sql_mode= $slave_sql_mode
+}
+--let $_previous_slave_sql_mode = `SELECT @@sql_mode`
+--disable_query_log
+eval SET sql_mode= '$_slave_sql_mode';
+--enable_query_log
+
+
 while ($_show_slave_status_items)
 {
   --let $_show_slave_status_name= `SELECT SUBSTRING_INDEX('$_show_slave_status_items', ',', 1)`
   --let $_show_slave_status_items= `SELECT LTRIM(SUBSTRING('$_show_slave_status_items', LENGTH('$_show_slave_status_name') + 2))`
 
   --let $_show_slave_status_value= query_get_value(SHOW SLAVE STATUS, $_show_slave_status_name, 1)
-  --replace_regex $slave_io_error_replace
+  --let $_slave_field_result_replace= /[\\]/\// $slave_field_result_replace
+  --replace_regex $_slave_field_result_replace
   --let $_show_slave_status_value= `SELECT REPLACE("$_show_slave_status_value", '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`
   --echo $_show_slave_status_name = '$_show_slave_status_value'
 }
+
+
+--disable_query_log
+eval SET sql_mode= '$_previous_slave_sql_mode';
+--enable_query_log

=== modified file 'mysql-test/include/wait_for_ndb_to_binlog.inc'
--- a/mysql-test/include/wait_for_ndb_to_binlog.inc	2009-11-26 23:32:01 +0000
+++ b/mysql-test/include/wait_for_ndb_to_binlog.inc	2012-01-23 16:50:54 +0000
@@ -1,13 +1,11 @@
 # ==== Purpose ====
 # 
-#   Several test primitives from mysql-test/extra/rpl_tests 
-# shared for test cases for MyISAM, InnoDB, NDB and other 
-# engines. But for NDB all events will be added by NDB 
-# injector and now there are no way to detect the state of 
-# NDB injector therefore this primitive waits 5 sec 
-# if engine type is NDB. 
-#   In future that should be fixed by waiting of proper 
-# state of NDB injector. 
+# Several test primitives from mysql-test/extra/rpl_tests 
+# are shared for test cases for MyISAM, InnoDB, NDB and
+# other engines.
+# For NDB engine all events will be added by NDB injector
+# so tests only can continue after injector is ready, 
+# this test waits for proper injector thread state.
 #
 # ==== Usage ====
 #
@@ -17,25 +15,12 @@
 # ==== Parameters =====
 #
 # $engine_type
-#   Type of engine. If type is NDB then it waits $wait_time sec 
-#   
-# $wait_time
-#   Test will wait $wait_time seconds
-
-let $_wait_time= 5;
-
-if (!$wait_time) {
-  let $_wait_time= $wait_time;
-}
+#   Type of engine. If type is NDB then it waits for injector
+#   thread proper state.
 
 if (`SELECT UPPER(LEFT('$engine_type',3)) = 'NDB'`) {
-  while (!$_wait_time) {
-    let $_wait_time_internal= 10;
-    while (!$_wait_time_internal) {
-      sleep 0.1;
-      dec $_wait_time_internal;
-    }
-    dec $_wait_time;
-  }
+  let $show_statement= SHOW PROCESSLIST;
+  let $field= State;
+  let $condition= = 'Waiting for event from ndbcluster';
+  source include/wait_show_condition.inc;
 }
-

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2011-12-23 08:55:18 +0000
+++ b/mysql-test/mysql-test-run.pl	2012-01-25 10:46:24 +0000
@@ -2014,7 +2014,8 @@ sub executable_setup () {
   $exe_mysql_plugin=   mtr_exe_exists("$path_client_bindir/mysql_plugin");
 
   $exe_mysql_embedded=
-    mtr_exe_maybe_exists("$bindir/libmysqld/examples/mysql_embedded",
+    mtr_exe_maybe_exists(vs_config_dirs('libmysqld/examples','mysql_embedded'),
+                         "$bindir/libmysqld/examples/mysql_embedded",
                          "$bindir/bin/mysql_embedded");
 
   if ( ! $opt_skip_ndbcluster )

=== modified file 'mysql-test/r/bigint.result'
--- a/mysql-test/r/bigint.result	2011-07-19 15:11:15 +0000
+++ b/mysql-test/r/bigint.result	2012-01-25 09:57:22 +0000
@@ -438,3 +438,67 @@ Level	Code	Message
 Note	1003	/* select#1 */ select 1 AS `1` from `test`.`t1` where ((`test`.`t1`.`a` = 0) and ('0' = `test`.`t1`.`b`))
 DROP TABLE t1;
 # End of 5.1 tests
+#
+# Bug#13463415 63502: INCORRECT RESULTS OF BIGINT AND DECIMAL COMPARISON
+#
+CREATE TABLE t_bigint(id BIGINT);
+INSERT INTO t_bigint VALUES (1), (2);
+SELECT id, id >= 1.1 FROM t_bigint;
+id	id >= 1.1
+1	0
+2	1
+SELECT id, 1.1 <= id FROM t_bigint;
+id	1.1 <= id
+1	0
+2	1
+SELECT id, id = 1.1 FROM t_bigint;
+id	id = 1.1
+1	0
+2	0
+SELECT id, 1.1 = id FROM t_bigint;
+id	1.1 = id
+1	0
+2	0
+SELECT * from t_bigint WHERE id = 1.1;
+id
+SELECT * from t_bigint WHERE id = 1.1e0;
+id
+SELECT * from t_bigint WHERE id = '1.1';
+id
+SELECT * from t_bigint WHERE id = '1.1e0';
+id
+SELECT * from t_bigint WHERE id IN (1.1, 2.2);
+id
+SELECT * from t_bigint WHERE id IN (1.1e0, 2.2e0);
+id
+SELECT * from t_bigint WHERE id IN ('1.1', '2.2');
+id
+SELECT * from t_bigint WHERE id IN ('1.1e0', '2.2e0');
+id
+SELECT * from t_bigint WHERE id BETWEEN 1.1 AND 1.9;
+id
+SELECT * from t_bigint WHERE id BETWEEN 1.1e0 AND 1.9e0;
+id
+SELECT * from t_bigint WHERE id BETWEEN '1.1' AND '1.9';
+id
+SELECT * from t_bigint WHERE id BETWEEN '1.1e0' AND '1.9e0';
+id
+DROP TABLE t_bigint;
+#
+# Bug#11758543 50756: BIGINT '100' MATCHES 1.001E2
+#
+CREATE TABLE t1 (a BIGINT);
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1 WHERE coalesce(a) BETWEEN 0 and 0.9;
+a
+SELECT * FROM t1 WHERE coalesce(a)=0.9;
+a
+SELECT * FROM t1 WHERE coalesce(a) in (0.8,0.9);
+a
+SELECT * FROM t1 WHERE a BETWEEN 0 AND 0.9;
+a
+SELECT * FROM t1 WHERE a=0.9;
+a
+SELECT * FROM t1 WHERE a IN (0.8,0.9);
+a
+DROP TABLE t1;

=== modified file 'mysql-test/r/ctype_utf8.result'
--- a/mysql-test/r/ctype_utf8.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/ctype_utf8.result	2012-01-23 10:02:54 +0000
@@ -2019,6 +2019,30 @@ D120
 SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
 HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20))
 D120D18E
+#
+# Bug#11752408 - 43593: DUMP/BACKUP/RESTORE/UPGRADE TOOLS FAILS BECAUSE OF UTF8_GENERAL_CI
+#
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci);
+INSERT INTO t1 VALUES ('a'),('r'),('s'),(_latin1 0xDF),(_latin1 0xF7),('t'),('z');
+SELECT * FROM t1 ORDER BY a;
+a
+a
+r
+s
+t
+z
+ß
+÷
+SELECT a, COUNT(*) FROM t1 GROUP BY a;
+a	COUNT(*)
+a	1
+r	1
+s	1
+t	1
+z	1
+ß	1
+÷	1
+DROP TABLE t1;
 End of 5.1 tests
 Start of 5.4 tests
 SET NAMES utf8mb3;

=== modified file 'mysql-test/r/date_formats.result'
--- a/mysql-test/r/date_formats.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/date_formats.result	2012-01-24 13:17:11 +0000
@@ -558,3 +558,34 @@ SET NAMES latin1;
 #
 # End of 5.1 tests
 #
+#
+# Start of 5.6 tests
+#
+#
+# WL#946 Fractional seconds precision
+# Testing Item_func_date_format with NULL argument.
+#
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS CHAR);
+CAST(TIME_FORMAT(NULL, '%s') AS CHAR)
+NULL
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS SIGNED);
+CAST(TIME_FORMAT(NULL, '%s') AS SIGNED)
+NULL
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DECIMAL(23,6));
+CAST(TIME_FORMAT(NULL, '%s') AS DECIMAL(23,6))
+NULL
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS TIME);
+CAST(TIME_FORMAT(NULL, '%s') AS TIME)
+NULL
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DATE);
+CAST(TIME_FORMAT(NULL, '%s') AS DATE)
+NULL
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DATETIME);
+CAST(TIME_FORMAT(NULL, '%s') AS DATETIME)
+NULL
+SELECT TIME_FORMAT(NULL, '%s')+0e0;
+TIME_FORMAT(NULL, '%s')+0e0
+NULL
+#
+# End of 5.6 tests
+#

=== modified file 'mysql-test/r/func_in_icp.result'
--- a/mysql-test/r/func_in_icp.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/func_in_icp.result	2012-01-25 09:57:22 +0000
@@ -470,6 +470,8 @@ SELECT HEX(a) FROM t2 WHERE a IN
 HEX(a)
 7FFFFFFFFFFFFFFE
 7FFFFFFFFFFFFFFF
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'abc'
 CREATE TABLE t3 (a BIGINT UNSIGNED);
 INSERT INTO t3 VALUES (9223372036854775551);
 SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

=== modified file 'mysql-test/r/func_in_icp_mrr.result'
--- a/mysql-test/r/func_in_icp_mrr.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/func_in_icp_mrr.result	2012-01-25 09:57:22 +0000
@@ -470,6 +470,8 @@ SELECT HEX(a) FROM t2 WHERE a IN
 HEX(a)
 7FFFFFFFFFFFFFFE
 7FFFFFFFFFFFFFFF
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'abc'
 CREATE TABLE t3 (a BIGINT UNSIGNED);
 INSERT INTO t3 VALUES (9223372036854775551);
 SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

=== modified file 'mysql-test/r/func_in_mrr.result'
--- a/mysql-test/r/func_in_mrr.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/func_in_mrr.result	2012-01-25 09:57:22 +0000
@@ -470,6 +470,8 @@ SELECT HEX(a) FROM t2 WHERE a IN
 HEX(a)
 7FFFFFFFFFFFFFFE
 7FFFFFFFFFFFFFFF
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'abc'
 CREATE TABLE t3 (a BIGINT UNSIGNED);
 INSERT INTO t3 VALUES (9223372036854775551);
 SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

=== modified file 'mysql-test/r/func_in_mrr_cost.result'
--- a/mysql-test/r/func_in_mrr_cost.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/func_in_mrr_cost.result	2012-01-25 09:57:22 +0000
@@ -470,6 +470,8 @@ SELECT HEX(a) FROM t2 WHERE a IN
 HEX(a)
 7FFFFFFFFFFFFFFE
 7FFFFFFFFFFFFFFF
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'abc'
 CREATE TABLE t3 (a BIGINT UNSIGNED);
 INSERT INTO t3 VALUES (9223372036854775551);
 SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

=== modified file 'mysql-test/r/func_in_none.result'
--- a/mysql-test/r/func_in_none.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/func_in_none.result	2012-01-25 09:57:22 +0000
@@ -469,6 +469,8 @@ SELECT HEX(a) FROM t2 WHERE a IN
 HEX(a)
 7FFFFFFFFFFFFFFE
 7FFFFFFFFFFFFFFF
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'abc'
 CREATE TABLE t3 (a BIGINT UNSIGNED);
 INSERT INTO t3 VALUES (9223372036854775551);
 SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2011-10-12 13:40:11 +0000
+++ b/mysql-test/r/func_str.result	2012-01-25 15:49:57 +0000
@@ -2876,6 +2876,42 @@ SELECT ((0xf3) * (rpad(1.0,2048,1)) << (
 ((0xf3) * (rpad(1.0,2048,1)) << (0xcc))
 0
 #
+# Bug#13359121 LARGE NUMBERS, /STRINGS/DTOA.C:662:
+#              BALLOC: ASSERTION `K <= 15' FAILED.
+# Bug#12985021 SIMPLE QUERY WITH DECIMAL NUMBERS TAKE AN 
+#              EXTRAORDINARY LONG TIME TO EXECUTE
+SELECT @tmp_max:= @@global.max_allowed_packet;
+@tmp_max:= @@global.max_allowed_packet
+1048576
+SET @@global.max_allowed_packet=1024*1024*1024;
+SELECT @@global.max_allowed_packet;
+@@global.max_allowed_packet
+1073741824
+do
+format(rpad('111111111.1',
+1111111,
+'999999999999999999999999999999999999999999'),0,'be_BY')
+;
+DO
+round(
+concat( (
+coalesce( (
+linefromwkb('2147483648',
+-b'1111111111111111111111111111111111111111111')),
+( convert('[.DC2.]',decimal(30,30)) ),
+bit_count('')
+) ),
+( lpad( ( elt('01','}:K5')),
+sha1('P'),
+( ( select '-9223372036854775808.1' > all (select '')))
+)
+)
+)
+);
+Warnings:
+Warning	1292	Truncated incorrect DECIMAL value: '[.DC2.]'
+SET @@global.max_allowed_packet:= @tmp_max;
+#
 # End of 5.5 tests
 #
 #

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2012-01-17 08:23:57 +0000
+++ b/mysql-test/r/func_time.result	2012-01-24 11:57:25 +0000
@@ -871,9 +871,7 @@ Warnings:
 Warning	1292	Incorrect datetime value: '2005-00-01'
 select last_day('2005-01-00');
 last_day('2005-01-00')
-NULL
-Warnings:
-Warning	1292	Incorrect datetime value: '2005-01-00'
+2005-01-31
 select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
 monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
 monthname(str_to_date(null, '%m'))	monthname(str_to_date(null, '%m'))	monthname(str_to_date(1, '%m'))	monthname(str_to_date(0, '%m'))
@@ -1068,6 +1066,8 @@ H
 select last_day('0000-00-00');
 last_day('0000-00-00')
 NULL
+Warnings:
+Warning	1292	Incorrect datetime value: '0000-00-00'
 select isnull(week(now() + 0)), isnull(week(now() + 0.2)),
 week(20061108), week(20061108.01), week(20061108085411.000002);
 isnull(week(now() + 0))	isnull(week(now() + 0.2))	week(20061108)	week(20061108.01)	week(20061108085411.000002)
@@ -1408,13 +1408,214 @@ Warning	1292	Incorrect datetime value: '
 #
 # Bug #13098726 MY_TIME.C:786: CALC_DAYNR: ASSERTION `DELSUM+(INT)
 # Y/4-TEMP > 0' FAILED
-#
 SELECT SUBTIME('0000-01-00 00:00','00:00');
 SUBTIME('0000-01-00 00:00','00:00')
 NULL
 SELECT LEAST(TIMESTAMP('0000-01-00','0'),'2011-10-24') > 0;
 LEAST(TIMESTAMP('0000-01-00','0'),'2011-10-24') > 0
 NULL
+#
+# BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
+# SIMILAR TO '2009-10-00' 
+#
+SELECT
+DATE('20091000'),
+STR_TO_DATE('200910','%Y%m'),
+LAST_DAY('2009-10-00'),
+LAST_DAY(DATE('2009-10-00')),
+LAST_DAY(DATE'2009-10-00'),
+LAST_DAY(STR_TO_DATE('200910','%Y%m')),
+WEEK('2009-10-00'),
+WEEK(DATE('2009-10-00')),
+WEEK(DATE'2009-10-00'),
+WEEK(STR_TO_DATE('200910','%Y%m')),
+WEEKOFYEAR('2009-10-00'),
+WEEKOFYEAR(DATE('2009-10-00')),
+WEEKOFYEAR(DATE'2009-10-00'),
+WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')),
+DAYOFYEAR('2009-10-00'),
+DAYOFYEAR(DATE('2009-10-00')),
+DAYOFYEAR(DATE'2009-10-00'),
+DAYOFYEAR(STR_TO_DATE('200910','%Y%m')),
+WEEKDAY('2009-10-00'),
+WEEKDAY(DATE('2009-10-00')),
+WEEKDAY(DATE'2009-10-00'),
+WEEKDAY(STR_TO_DATE('200910','%Y%m')),
+TO_DAYs('2009-10-00'),
+TO_DAYs(DATE('2009-10-00')),
+TO_DAYs(DATE'2009-10-00'),
+TO_DAYs(STR_TO_DATE('200910','%Y%m'));
+DATE('20091000')	2009-10-00
+STR_TO_DATE('200910','%Y%m')	2009-10-00
+LAST_DAY('2009-10-00')	2009-10-31
+LAST_DAY(DATE('2009-10-00'))	2009-10-31
+LAST_DAY(DATE'2009-10-00')	2009-10-31
+LAST_DAY(STR_TO_DATE('200910','%Y%m'))	2009-10-31
+WEEK('2009-10-00')	NULL
+WEEK(DATE('2009-10-00'))	NULL
+WEEK(DATE'2009-10-00')	NULL
+WEEK(STR_TO_DATE('200910','%Y%m'))	NULL
+WEEKOFYEAR('2009-10-00')	NULL
+WEEKOFYEAR(DATE('2009-10-00'))	NULL
+WEEKOFYEAR(DATE'2009-10-00')	NULL
+WEEKOFYEAR(STR_TO_DATE('200910','%Y%m'))	NULL
+DAYOFYEAR('2009-10-00')	NULL
+DAYOFYEAR(DATE('2009-10-00'))	NULL
+DAYOFYEAR(DATE'2009-10-00')	NULL
+DAYOFYEAR(STR_TO_DATE('200910','%Y%m'))	NULL
+WEEKDAY('2009-10-00')	NULL
+WEEKDAY(DATE('2009-10-00'))	NULL
+WEEKDAY(DATE'2009-10-00')	NULL
+WEEKDAY(STR_TO_DATE('200910','%Y%m'))	NULL
+TO_DAYs('2009-10-00')	NULL
+TO_DAYs(DATE('2009-10-00'))	NULL
+TO_DAYs(DATE'2009-10-00')	NULL
+TO_DAYs(STR_TO_DATE('200910','%Y%m'))	NULL
+Warnings:
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '200910' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '200910' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '200910' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '200910' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '2009-10-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '200910' for function str_to_date
+SELECT
+DATE('00000100'),
+STR_TO_DATE('000001','%Y%m'),
+LAST_DAY('0000-01-00'),
+LAST_DAY(DATE('0000-01-00')),
+LAST_DAY(DATE'0000-01-00'),
+LAST_DAY(STR_TO_DATE('000001','%Y%m')),
+WEEK('0000-01-00'),
+WEEK(DATE('0000-01-00')),
+WEEK(DATE'0000-01-00'),
+WEEK(STR_TO_DATE('000001','%Y%m')),
+WEEKOFYEAR('0000-01-00'),
+WEEKOFYEAR(DATE('0000-01-00')),
+WEEKOFYEAR(DATE'0000-01-00'),
+WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')),
+DAYOFYEAR('0000-01-00'),
+DAYOFYEAR(DATE('0000-01-00')),
+DAYOFYEAR(DATE'0000-01-00'),
+DAYOFYEAR(STR_TO_DATE('000001','%Y%m')),
+WEEKDAY('0000-01-00'),
+WEEKDAY(DATE('0000-01-00')),
+WEEKDAY(DATE'0000-01-00'),
+WEEKDAY(STR_TO_DATE('000001','%Y%m')),
+TO_DAYs('0000-01-00'),
+TO_DAYs(DATE('0000-01-00')),
+TO_DAYs(DATE'0000-01-00'),
+TO_DAYs(STR_TO_DATE('000001','%Y%m'));
+DATE('00000100')	0000-01-00
+STR_TO_DATE('000001','%Y%m')	0000-01-00
+LAST_DAY('0000-01-00')	0000-01-31
+LAST_DAY(DATE('0000-01-00'))	0000-01-31
+LAST_DAY(DATE'0000-01-00')	0000-01-31
+LAST_DAY(STR_TO_DATE('000001','%Y%m'))	0000-01-31
+WEEK('0000-01-00')	NULL
+WEEK(DATE('0000-01-00'))	NULL
+WEEK(DATE'0000-01-00')	NULL
+WEEK(STR_TO_DATE('000001','%Y%m'))	NULL
+WEEKOFYEAR('0000-01-00')	NULL
+WEEKOFYEAR(DATE('0000-01-00'))	NULL
+WEEKOFYEAR(DATE'0000-01-00')	NULL
+WEEKOFYEAR(STR_TO_DATE('000001','%Y%m'))	NULL
+DAYOFYEAR('0000-01-00')	NULL
+DAYOFYEAR(DATE('0000-01-00'))	NULL
+DAYOFYEAR(DATE'0000-01-00')	NULL
+DAYOFYEAR(STR_TO_DATE('000001','%Y%m'))	NULL
+WEEKDAY('0000-01-00')	NULL
+WEEKDAY(DATE('0000-01-00'))	NULL
+WEEKDAY(DATE'0000-01-00')	NULL
+WEEKDAY(STR_TO_DATE('000001','%Y%m'))	NULL
+TO_DAYs('0000-01-00')	NULL
+TO_DAYs(DATE('0000-01-00'))	NULL
+TO_DAYs(DATE'0000-01-00')	NULL
+TO_DAYs(STR_TO_DATE('000001','%Y%m'))	NULL
+Warnings:
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '000001' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '000001' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '000001' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '000001' for function str_to_date
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1292
+Message	Incorrect datetime value: '0000-01-00'
+Level	Warning
+Code	1411
+Message	Incorrect datetime value: '000001' for function str_to_date
 End of 5.1 tests
 #
 # BUG#43578 "MyISAM&Maria gives wrong rows with range access

=== modified file 'mysql-test/r/innodb_icp.result'
--- a/mysql-test/r/innodb_icp.result	2012-01-03 11:04:14 +0000
+++ b/mysql-test/r/innodb_icp.result	2012-01-25 12:45:56 +0000
@@ -992,7 +992,7 @@ FROM t2 JOIN t1 ON t2.col_int_key
 WHERE t2.pk < 7 AND t2.col_int_key <> 7
 GROUP BY field1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	range	PRIMARY,col_int_key	col_int_key	5	NULL	5	Using where
+1	SIMPLE	t2	range	PRIMARY,col_int_key	col_int_key	5	NULL	5	Using where; Using index
 1	SIMPLE	t1	index	NULL	col_int_key	5	NULL	4	Using index
 SELECT t2.col_int_key AS field1
 FROM t2 JOIN t1 ON t2.col_int_key

=== modified file 'mysql-test/r/innodb_icp_none.result'
--- a/mysql-test/r/innodb_icp_none.result	2012-01-03 11:04:14 +0000
+++ b/mysql-test/r/innodb_icp_none.result	2012-01-25 12:45:56 +0000
@@ -991,7 +991,7 @@ FROM t2 JOIN t1 ON t2.col_int_key
 WHERE t2.pk < 7 AND t2.col_int_key <> 7
 GROUP BY field1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	range	PRIMARY,col_int_key	col_int_key	5	NULL	5	Using where
+1	SIMPLE	t2	range	PRIMARY,col_int_key	col_int_key	5	NULL	5	Using where; Using index
 1	SIMPLE	t1	index	NULL	col_int_key	5	NULL	4	Using index
 SELECT t2.col_int_key AS field1
 FROM t2 JOIN t1 ON t2.col_int_key

=== modified file 'mysql-test/r/innodb_mrr.result'
--- a/mysql-test/r/innodb_mrr.result	2011-11-23 19:55:56 +0000
+++ b/mysql-test/r/innodb_mrr.result	2012-01-25 14:37:43 +0000
@@ -539,7 +539,7 @@ WHERE t2.i1 > 5
 AND t2.pk IS  NULL
 ORDER BY i1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	Using filesort
+1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	
 1	SIMPLE	t2	const	PRIMARY,k1	PRIMARY	4	const	1	Using where
 SELECT i1
 FROM t1 LEFT JOIN t2 ON t1.pk = t2.i2

=== modified file 'mysql-test/r/innodb_mrr_cost.result'
--- a/mysql-test/r/innodb_mrr_cost.result	2011-11-23 19:55:56 +0000
+++ b/mysql-test/r/innodb_mrr_cost.result	2012-01-25 14:37:43 +0000
@@ -539,7 +539,7 @@ WHERE t2.i1 > 5
 AND t2.pk IS  NULL
 ORDER BY i1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	Using filesort
+1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	
 1	SIMPLE	t2	const	PRIMARY,k1	PRIMARY	4	const	1	Using where
 SELECT i1
 FROM t1 LEFT JOIN t2 ON t1.pk = t2.i2

=== modified file 'mysql-test/r/innodb_mrr_cost_icp.result'
--- a/mysql-test/r/innodb_mrr_cost_icp.result	2011-12-01 14:12:10 +0000
+++ b/mysql-test/r/innodb_mrr_cost_icp.result	2012-01-25 14:37:43 +0000
@@ -539,7 +539,7 @@ WHERE t2.i1 > 5
 AND t2.pk IS  NULL
 ORDER BY i1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	Using filesort
+1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	
 1	SIMPLE	t2	const	PRIMARY,k1	PRIMARY	4	const	1	Using where
 SELECT i1
 FROM t1 LEFT JOIN t2 ON t1.pk = t2.i2

=== modified file 'mysql-test/r/innodb_mrr_icp.result'
--- a/mysql-test/r/innodb_mrr_icp.result	2011-12-01 14:12:10 +0000
+++ b/mysql-test/r/innodb_mrr_icp.result	2012-01-25 14:37:43 +0000
@@ -539,7 +539,7 @@ WHERE t2.i1 > 5
 AND t2.pk IS  NULL
 ORDER BY i1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	Using filesort
+1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	
 1	SIMPLE	t2	const	PRIMARY,k1	PRIMARY	4	const	1	Using where
 SELECT i1
 FROM t1 LEFT JOIN t2 ON t1.pk = t2.i2

=== modified file 'mysql-test/r/innodb_mrr_none.result'
--- a/mysql-test/r/innodb_mrr_none.result	2011-11-23 19:55:56 +0000
+++ b/mysql-test/r/innodb_mrr_none.result	2012-01-25 14:37:43 +0000
@@ -538,7 +538,7 @@ WHERE t2.i1 > 5
 AND t2.pk IS  NULL
 ORDER BY i1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	Using filesort
+1	SIMPLE	t1	system	PRIMARY	NULL	NULL	NULL	1	
 1	SIMPLE	t2	const	PRIMARY,k1	PRIMARY	4	const	1	Using where
 SELECT i1
 FROM t1 LEFT JOIN t2 ON t1.pk = t2.i2

=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result	2012-01-17 09:27:34 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result	2012-01-25 10:07:23 +0000
@@ -797,6 +797,9 @@ The following options may be given as th
  replication.
  --sql-mode=name     Syntax: sql-mode=mode[,mode[,mode...]]. See the manual
  for the complete list of valid sql modes
+ --stored-program-cache=# 
+ The soft upper limit for number of cached stored routines
+ for one connection.
  -s, --symbolic-links 
  Enable symbolic link support.
  --sync-binlog=#     Synchronously flush binary log to disk after every #th
@@ -1100,6 +1103,7 @@ slow-query-log FALSE
 sort-buffer-size 262144
 sporadic-binlog-dump-fail FALSE
 sql-mode 
+stored-program-cache 256
 symbolic-links FALSE
 sync-binlog 0
 sync-frm TRUE

=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result	2012-01-17 09:27:34 +0000
+++ b/mysql-test/r/mysqld--help-win.result	2012-01-26 07:01:30 +0000
@@ -805,6 +805,9 @@ The following options may be given as th
  --sql-mode=name     Syntax: sql-mode=mode[,mode[,mode...]]. See the manual
  for the complete list of valid sql modes
  --standalone        Dummy option to start as a standalone program (NT).
+ --stored-program-cache=# 
+ The soft upper limit for number of cached stored routines
+ for one connection.
  -s, --symbolic-links 
  Enable symbolic link support.
  --sync-binlog=#     Synchronously flush binary log to disk after every #th
@@ -1111,6 +1114,7 @@ slow-start-timeout 15000
 sort-buffer-size 262144
 sporadic-binlog-dump-fail FALSE
 sql-mode 
+stored-program-cache 256
 symbolic-links FALSE
 sync-binlog 0
 sync-frm TRUE

=== modified file 'mysql-test/r/optimizer_debug_sync.result'
--- a/mysql-test/r/optimizer_debug_sync.result	2011-03-01 14:57:53 +0000
+++ b/mysql-test/r/optimizer_debug_sync.result	2012-01-26 11:34:35 +0000
@@ -21,3 +21,20 @@ MAX(i)
 MAX(i)
 2
 DROP TABLE t;
+#
+# Bug #13536661: VALGRIND: DEFINITELY LOST: 552 BYTES IN 1 BLOCKS IN
+# CREATE_TMP_TABLE AND HIGHER
+#
+CREATE TABLE t1 ( a INT, b INT );
+INSERT INTO t1 VALUES (4, 40), (1, 10), (2, 20), (2, 20), (3, 30);
+SET debug_sync = "tmp_table_created SIGNAL parked WAIT_FOR go";
+# This should not leak memory.
+SELECT b, COUNT(DISTINCT b) FROM t1 GROUP BY b ORDER BY -b;
+SET debug_sync = "now WAIT_FOR parked";
+# Set locally to shadow the global variable.
+SET debug = '';
+SET GLOBAL debug = '+d,simulate_out_of_memory';
+SET debug_sync = "now SIGNAL go";
+ERROR HY000: Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space
+SET GLOBAL debug = '';
+DROP TABLE t1;

=== modified file 'mysql-test/r/order_by_icp_mrr.result'
--- a/mysql-test/r/order_by_icp_mrr.result	2011-12-19 09:22:28 +0000
+++ b/mysql-test/r/order_by_icp_mrr.result	2012-01-25 14:52:00 +0000
@@ -1461,7 +1461,7 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL)
 EXPLAIN
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ref_or_null	a_c,a	a_c	10	const,const	1	Using where
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
 # Must return 1 row
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
 col
@@ -1470,7 +1470,7 @@ col
 EXPLAIN
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-x	x	x	ref_or_null	a_c,a	x	x	x	x	x
+x	x	x	ref	a_c,a	x	x	x	x	x
 # Must return 1 row
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
 col
@@ -2600,4 +2600,43 @@ SELECT (SELECT 1 FROM t1 WHERE a=b AND c
 NULL
 NULL
 DROP TABLE t1, t2;
+#
+# Bug #13531865
+# TEST_IF_SKIP_SORT_ORDER() INCORRECTLY SKIP FILESORT IF
+# 'TYPE' IS REF_OR_NULL 
+# 
+#
+CREATE TABLE t1 (
+a INT,
+c INT,
+UNIQUE KEY a_c (a,c),
+KEY (a)) engine=myisam;
+INSERT INTO t1 VALUES (1,10), (2,NULL), (2,10);
+ANALYZE TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+# Using 'KEY a_c' for order-by opt, would have required 
+# REF_OR_NULL access which never can be order_by skipped.
+# -> Keep initial REF on 'KEY a' selected by cond. optimizer
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+c
+NULL
+10
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+c
+10
+NULL
+DROP TABLE t1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/order_by_none.result'
--- a/mysql-test/r/order_by_none.result	2011-12-19 09:22:28 +0000
+++ b/mysql-test/r/order_by_none.result	2012-01-25 14:52:00 +0000
@@ -1460,7 +1460,7 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL)
 EXPLAIN
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	ref_or_null	a_c,a	a_c	10	const,const	1	Using where
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
 # Must return 1 row
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
 col
@@ -1469,7 +1469,7 @@ col
 EXPLAIN
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-x	x	x	ref_or_null	a_c,a	x	x	x	x	x
+x	x	x	ref	a_c,a	x	x	x	x	x
 # Must return 1 row
 SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
 col
@@ -2599,4 +2599,43 @@ SELECT (SELECT 1 FROM t1 WHERE a=b AND c
 NULL
 NULL
 DROP TABLE t1, t2;
+#
+# Bug #13531865
+# TEST_IF_SKIP_SORT_ORDER() INCORRECTLY SKIP FILESORT IF
+# 'TYPE' IS REF_OR_NULL 
+# 
+#
+CREATE TABLE t1 (
+a INT,
+c INT,
+UNIQUE KEY a_c (a,c),
+KEY (a)) engine=myisam;
+INSERT INTO t1 VALUES (1,10), (2,NULL), (2,10);
+ANALYZE TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+# Using 'KEY a_c' for order-by opt, would have required 
+# REF_OR_NULL access which never can be order_by skipped.
+# -> Keep initial REF on 'KEY a' selected by cond. optimizer
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+c
+NULL
+10
+EXPLAIN
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	a_c,a	a	5	const	1	Using where; Using filesort
+SELECT c FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
+c
+10
+NULL
+DROP TABLE t1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/partition_binlog_stmt.result'
--- a/mysql-test/r/partition_binlog_stmt.result	2010-10-01 12:16:00 +0000
+++ b/mysql-test/r/partition_binlog_stmt.result	2012-01-20 13:19:39 +0000
@@ -8,6 +8,6 @@ name TINYBLOB NOT NULL,
 modified TIMESTAMP DEFAULT '0000-00-00 00:00:00',
 INDEX namelocs (name(255))) ENGINE = MyISAM
 PARTITION BY HASH(id) PARTITIONS 2;
-LOAD DATA LOCAL INFILE 'init_file.txt'
+LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/init_file.txt'
 INTO TABLE t1 (name);
 DROP TABLE t1;

=== modified file 'mysql-test/r/partition_explicit_prune.result'
--- a/mysql-test/r/partition_explicit_prune.result	2011-12-14 05:03:54 +0000
+++ b/mysql-test/r/partition_explicit_prune.result	2012-01-21 00:47:05 +0000
@@ -1,3 +1,182 @@
+#
+# Bug#13559657: PARTITION SELECTION DOES NOT WORK WITH VIEWS
+#
+CREATE TABLE t1 (a int)
+ENGINE = InnoDB
+PARTITION BY HASH (a) PARTITIONS 2;
+INSERT INTO t1 VALUES (0), (1), (2), (3);
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0);
+SHOW CREATE VIEW v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` PARTITION (`p0`)	latin1	latin1_swedish_ci
+FLUSH STATUS;
+SELECT * FROM v1;
+a
+0
+2
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_READ_FIRST	1
+HANDLER_READ_KEY	1
+HANDLER_READ_RND_NEXT	3
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+SELECT a FROM t1 PARTITION (p0);
+a
+0
+2
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_READ_FIRST	1
+HANDLER_READ_KEY	1
+HANDLER_READ_RND_NEXT	3
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (10);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_WRITE	18
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (11);
+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 table, 1 partition lock/unlock)
+FLUSH STATUS;
+SELECT * FROM v1;
+a
+0
+10
+2
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_READ_FIRST	1
+HANDLER_READ_KEY	1
+HANDLER_READ_RND_NEXT	4
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+SELECT a FROM t1 PARTITION (p0);
+a
+0
+10
+2
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_READ_FIRST	1
+HANDLER_READ_KEY	1
+HANDLER_READ_RND_NEXT	4
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+SELECT * FROM t1;
+a
+0
+1
+10
+2
+3
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0) WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (20);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_WRITE	18
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (21);
+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 table, 1 partition lock/unlock)
+SELECT * FROM v1;
+a
+0
+10
+2
+20
+SELECT * FROM t1;
+a
+0
+1
+10
+2
+20
+3
+DROP VIEW v1;
+CREATE VIEW v1 AS
+SELECT a FROM t1 PARTITION (p0) WHERE a = 30 WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (30);
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_COMMIT	1
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_WRITE	18
+# 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (31);
+ERROR HY000: CHECK OPTION failed 'test.v1'
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_ROLLBACK	1
+HANDLER_WRITE	17
+FLUSH STATUS;
+INSERT INTO v1 VALUES (32);
+ERROR HY000: CHECK OPTION failed 'test.v1'
+SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+VARIABLE_NAME	VARIABLE_VALUE
+HANDLER_EXTERNAL_LOCK	4
+HANDLER_ROLLBACK	1
+HANDLER_WRITE	17
+# 4 locks (1 table, 1 partition lock/unlock)
+SELECT * FROM v1;
+a
+30
+SELECT * FROM t1;
+a
+0
+1
+10
+2
+20
+3
+30
+DROP VIEW v1;
+DROP TABLE t1;
 # Original tests for WL#5217
 # Must have InnoDB as engine to get the same statistics results.
 # embedded uses MyISAM as default. CREATE SELECT uses the default engine.

=== modified file 'mysql-test/r/plugin.result'
--- a/mysql-test/r/plugin.result	2011-10-27 08:43:56 +0000
+++ b/mysql-test/r/plugin.result	2012-01-26 12:39:35 +0000
@@ -8,8 +8,30 @@ INSTALL PLUGIN EXAMPLE SONAME 'ha_exampl
 ERROR HY000: Function 'EXAMPLE' already exists
 UNINSTALL PLUGIN example;
 INSTALL PLUGIN example SONAME 'ha_example.so';
+# Example engine does not support indexes
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=EXAMPLE;
+ERROR 42000: Too many key parts specified; max 0 parts allowed
+CREATE TABLE t1 (a int, KEY (a)) ENGINE=EXAMPLE;
+ERROR 42000: Too many key parts specified; max 0 parts allowed
 CREATE TABLE t1(a int) ENGINE=EXAMPLE;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=EXAMPLE DEFAULT CHARSET=latin1
+# Let's do some advanced ops with the example engine :)
+INSERT INTO t1 VALUES (0);
+# Only supports table scans (and does always return zero rows :)
 SELECT * FROM t1;
+a
+SELECT * FROM t1 WHERE a = 0;
+a
+# Since there are no rows found, it will never do update_row.
+UPDATE t1 SET a = 1 WHERE a = 0;
+# Since there are no rows found, it will never do delete_row.
+DELETE FROM t1 WHERE a = 0;
+# No support for SQL HANDLER statement
+HANDLER t1 OPEN;
 ERROR HY000: Table storage engine for 't1' doesn't have this option
 DROP TABLE t1;
 set global example_ulong_var=500;

=== modified file 'mysql-test/r/range_all.result'
--- a/mysql-test/r/range_all.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_all.result	2012-01-26 10:08:12 +0000
@@ -1768,6 +1768,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/range_icp.result'
--- a/mysql-test/r/range_icp.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_icp.result	2012-01-26 10:08:12 +0000
@@ -1768,6 +1768,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/range_icp_mrr.result'
--- a/mysql-test/r/range_icp_mrr.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_icp_mrr.result	2012-01-26 10:08:12 +0000
@@ -1768,6 +1768,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/range_mrr.result'
--- a/mysql-test/r/range_mrr.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_mrr.result	2012-01-26 10:08:12 +0000
@@ -1768,6 +1768,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/range_mrr_cost.result'
--- a/mysql-test/r/range_mrr_cost.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_mrr_cost.result	2012-01-26 10:08:12 +0000
@@ -1768,6 +1768,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/range_none.result'
--- a/mysql-test/r/range_none.result	2011-12-09 15:06:50 +0000
+++ b/mysql-test/r/range_none.result	2012-01-26 10:08:12 +0000
@@ -1767,6 +1767,123 @@ id	select_type	table	type	possible_keys
 SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
 pk	i4	pk	i4
 DROP TABLE t1;
+#
+# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
+# WITH/WITHOUT INDEX RANGE SCAN
+#
+create table t1 (id int unsigned not null auto_increment primary key);
+insert into t1 values (null);
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+insert into t1 select null from t1;
+create table t2 (
+id int unsigned not null auto_increment,
+val decimal(5,3) not null,
+primary key (id,val),
+unique key (val,id),
+unique key (id));
+insert into t2 select null,id*0.0009 from t1;
+select count(val) from t2 ignore index (val) where val > 0.1155;
+count(val)
+128
+select count(val) from t2 force index (val)  where val > 0.1155;
+count(val)
+128
+drop table t2, t1;
+#
+# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
+# RESULTS WITH DECIMAL CONVERSION
+#
+create table t1 (a int,b int,c int,primary key (a,c));
+insert into t1 values (1,1,2),(1,1,3),(1,1,4);
+select convert(3, signed integer) > 2.9;
+convert(3, signed integer) > 2.9
+1
+select * from t1 force  index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c>= 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 force  index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+select * from t1 ignore index (primary) where a=1 and c> 2.9;
+a	b	c
+1	1	3
+1	1	4
+drop table t1;
+#
+# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
+# RESULT AFTER MYSQL 5.1.
+#
+CREATE TABLE t1(
+F1 CHAR(5) NOT NULL,
+F2 CHAR(5) NOT NULL,
+F3 CHAR(5) NOT NULL,
+PRIMARY KEY(F1),
+INDEX IDX_F2(F2)
+);
+INSERT INTO t1 VALUES
+('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
+('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
+SELECT * FROM t1 WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A    ';
+F1	F2	F3
+A	A	A
+SELECT * FROM t1 WHERE F1 >= 'A    ';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 > 'A    ';
+F1	F2	F3
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F1 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F2 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 WHERE F3 BETWEEN 'A    ' AND 'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A    ' AND
+'AAAAA';
+F1	F2	F3
+A	A	A
+AA	AA	AA
+AAA	AAA	AAA
+AAAA	AAAA	AAAA
+AAAAA	AAAAA	AAAAA
+DROP TABLE t1;
 End of 5.1 tests
 CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
 INSERT INTO t1 VALUES (1),(2),(3);

=== modified file 'mysql-test/r/temporal_literal.result'
--- a/mysql-test/r/temporal_literal.result	2011-11-10 15:14:11 +0000
+++ b/mysql-test/r/temporal_literal.result	2012-01-24 13:17:11 +0000
@@ -341,3 +341,15 @@ a
 0000-00-00 00:00:00
 0000-00-00 00:00:00
 DROP TABLE t1;
+#
+# Testing Item_date_literal::eq
+#
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES ('2001-01-01'),('2003-01-01');
+SELECT * FROM t1 WHERE a BETWEEN DATE'2001-01-01' AND DATE'2002-01-01';
+a
+2001-01-01
+SELECT DATE'2001-01-01' FROM t1 GROUP BY DATE'2001-01-01';
+DATE'2001-01-01'
+2001-01-01
+DROP TABLE t1;

=== modified file 'mysql-test/r/type_date.result'
--- a/mysql-test/r/type_date.result	2011-11-01 11:52:24 +0000
+++ b/mysql-test/r/type_date.result	2012-01-24 13:17:11 +0000
@@ -397,4 +397,91 @@ a
 0000-00-00
 DROP TABLE t1;
 SET timestamp=DEFAULT;
+#
+# Testing cast from DECIMAL to DATE
+#
+CREATE TABLE t1 (a DECIMAL(23,4));
+INSERT INTO t1 VALUES (NULL),(101010.9999),(-101010.9999);
+SELECT a, CAST(a AS DATE) FROM t1;
+a	CAST(a AS DATE)
+NULL	NULL
+101010.9999	2010-10-10
+-101010.9999	NULL
+Warnings:
+Warning	1292	Incorrect datetime value: '-101010.9999'
+DROP TABLE t1;
+#
+# Testing CASE with DATE type without a found item
+#
+SELECT CAST(CASE WHEN 0 THEN '2001-01-01' END AS DATE);
+CAST(CASE WHEN 0 THEN '2001-01-01' END AS DATE)
+NULL
+SELECT CAST(CASE WHEN 0 THEN DATE'2001-01-01' END AS DATE);
+CAST(CASE WHEN 0 THEN DATE'2001-01-01' END AS DATE)
+NULL
+#
+# Testing DATE field with NULL value with NOT IN
+#
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1 WHERE a NOT IN (DATE'2001-01-01',DATE'2002-02-02');
+a
+DROP TABLE t1;
+#
+# Testing COALESCE with DATE type without a found item
+#
+SELECT COALESCE(DATE(NULL));
+COALESCE(DATE(NULL))
+NULL
+#
+# Testing Item_func_min_max::val_str when DATE type and NULL
+#
+SELECT CAST(LEAST(DATE(NULL), DATE(NULL)) AS CHAR);
+CAST(LEAST(DATE(NULL), DATE(NULL)) AS CHAR)
+NULL
+#
+# Testing Item_func_min_max::get_date with non-temporal arguments
+#
+SELECT CAST(LEAST(20010101,20020202) AS DATE);
+CAST(LEAST(20010101,20020202) AS DATE)
+2001-01-01
+#
+#  Item::get_date_from_numeric
+#
+SELECT CAST(SUM(0) AS DATETIME);
+CAST(SUM(0) AS DATETIME)
+0000-00-00 00:00:00
+SELECT CAST(SUM(0 + 0e0) AS DATETIME);
+CAST(SUM(0 + 0e0) AS DATETIME)
+0000-00-00 00:00:00
+SET timestamp=1322115004;
+SELECT CAST(UNIX_TIMESTAMP() AS DATE);
+CAST(UNIX_TIMESTAMP() AS DATE)
+NULL
+Warnings:
+Warning	1292	Incorrect datetime value: '1322115004'
+SET timestamp=DEFAULT;
+#
+# Item::get_date_from_non_temporal
+#
+SELECT DATE(20110512154559.6 + 0e0);
+DATE(20110512154559.6 + 0e0)
+2011-05-12
+#
+# Item_name_const::get_date
+#
+SELECT DATE(NAME_CONST('a', 0));
+DATE(NAME_CONST('a', 0))
+0000-00-00
+#
+# Item_cache_datetime::get_date
+#
+SET timestamp=UNIX_TIMESTAMP('2011-11-24');
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES (0);
+SELECT DATE(MIN(a)) FROM t1;
+DATE(MIN(a))
+2011-11-24
+DROP TABLE t1;
+SET timestamp=DEFAULT;
 End of 5.6 tests

=== modified file 'mysql-test/r/type_temporal_fractional.result'
--- a/mysql-test/r/type_temporal_fractional.result	2011-12-20 09:45:15 +0000
+++ b/mysql-test/r/type_temporal_fractional.result	2012-01-24 13:17:11 +0000
@@ -508,6 +508,25 @@ t1	10:10:10.5
 t0	10:10:10
 DROP TABLE t1;
 #
+# Testing rounding when casting from DECIMAL to TIME(N)
+#
+CREATE TABLE t1 (a DECIMAL(23,4));
+INSERT INTO t1 VALUES (NULL),(101010.9999),(-101010.9999);
+INSERT INTO t1 VALUES (9999999999999999999999.1), (999999.1);
+Warnings:
+Warning	1264	Out of range value for column 'a' at row 1
+SELECT a, CAST(a AS TIME(3)) FROM t1;
+a	CAST(a AS TIME(3))
+NULL	NULL
+101010.9999	10:10:11.000
+-101010.9999	-10:10:11.000
+9999999999999999999.9999	NULL
+999999.1000	NULL
+Warnings:
+Warning	1292	Truncated incorrect time value: '9999999999999999999.9999'
+Warning	1292	Truncated incorrect time value: '999999.1000'
+DROP TABLE t1;
+#
 # Testing that CAST converts days to hours, while EXTRACT/HOUR do not
 #
 SELECT CAST('1 00:00:00' as TIME), EXTRACT(HOUR FROM '1 00:00:00'), HOUR('1 00:00:00');
@@ -5458,6 +5477,7 @@ DROP TABLE t1;
 CREATE TABLE t1 (id INT, a TIME(6));
 INSERT INTO t1 VALUES (1,'00:00:00.123456'), (1,'11:00:00.123456');
 INSERT INTO t1 VALUES (2,'00:01:00.123456'), (2,'11:01:00.123456');
+INSERT INTO t1 VALUES (3, NULL);
 SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t1 GROUP BY id);
 id	a
 1	11:00:00.123456
@@ -10377,6 +10397,7 @@ DROP TABLE t1;
 CREATE TABLE t1 (id INT, a DATETIME(6));
 INSERT INTO t1 VALUES (1, '2001-01-01 00:00:00.123456'), (1, '2001-01-01 11:00:00.123456');
 INSERT INTO t1 VALUES (2, '2001-01-01 00:01:00.123456'), (2, '2001-01-01 11:01:00.123456');
+INSERT INTO t1 VALUES (3, NULL);
 SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t1 GROUP BY id);
 id	a
 1	2001-01-01 11:00:00.123456
@@ -16938,6 +16959,15 @@ WHERE c_timestamp NOT IN (NULL, '0000-00
 c1
 DROP TABLE t1;
 #
+# Various tests for better gcov coverage
+#
+#
+# Comparing DATETIME value to TIME(NULL)
+#
+SELECT TIMESTAMP'2001-01-01 00:00:00' = TIME(NULL);
+TIMESTAMP'2001-01-01 00:00:00' = TIME(NULL)
+NULL
+#
 # BUG#13450867 - CRASH ON UPDATE A TIME COLUMN 
 #
 CREATE TABLE t1 (a TIME(6), b TIME(6), c TIME(6), d TIME(6));

=== modified file 'mysql-test/r/type_temporal_upgrade.result'
--- a/mysql-test/r/type_temporal_upgrade.result	2011-11-21 19:17:25 +0000
+++ b/mysql-test/r/type_temporal_upgrade.result	2012-01-24 13:17:11 +0000
@@ -10,6 +10,20 @@ t1	CREATE TABLE `t1` (
   `f_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   `f_datetime` datetime DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES (9999999, 999999999999999, 999999999999999);
+Warnings:
+Warning	1264	Out of range value for column 'f_time' at row 1
+Warning	1264	Out of range value for column 'f_datetime' at row 1
+Warning	1264	Out of range value for column 'f_timestamp' at row 1
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES (-9999999, -999999999999999, -999999999999999);
+Warnings:
+Warning	1264	Out of range value for column 'f_time' at row 1
+Warning	1265	Data truncated for column 'f_datetime' at row 1
+Warning	1264	Out of range value for column 'f_timestamp' at row 1
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES ('00:00:00', '0000-00-00 00:00:00','0000-00-00 00:00:00');
 SELECT * FROM t1;
 f_time	f_timestamp	f_datetime
 10:10:10	2031-11-21 17:11:01	2010-10-10 10:10:10
@@ -17,29 +31,48 @@ f_time	f_timestamp	f_datetime
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
 NULL	2015-11-21 17:11:01	2000-01-01 01:01:01
 00:00:00	2011-11-21 17:11:01	NULL
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+-838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00
 SELECT * FROM t1 ORDER BY f_time;
 f_time	f_timestamp	f_datetime
 NULL	2015-11-21 17:11:01	2000-01-01 01:01:01
+-838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
 00:00:00	2001-01-21 18:11:01	2000-01-01 01:01:01
 00:00:00	2011-11-21 17:11:01	NULL
+00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
 10:10:10	2031-11-21 17:11:01	2010-10-10 10:10:10
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
 SELECT * FROM t1 WHERE f_time > '00:00:00';
 f_time	f_timestamp	f_datetime
 10:10:10	2031-11-21 17:11:01	2010-10-10 10:10:10
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
 SELECT * FROM t1 WHERE f_time > '00:00:00' ORDER BY f_time;
 f_time	f_timestamp	f_datetime
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
 10:10:10	2031-11-21 17:11:01	2010-10-10 10:10:10
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
 SELECT * FROM t1 WHERE f_time = '01:01:10';
 f_time	f_timestamp	f_datetime
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
 SELECT * FROM t1 WHERE f_time IS NULL;
 f_time	f_timestamp	f_datetime
 NULL	2015-11-21 17:11:01	2000-01-01 01:01:01
+SELECT COUNT(*), MIN(f_time) FROM t1 GROUP BY f_time;
+COUNT(*)	MIN(f_time)
+1	NULL
+1	-838:59:59
+3	00:00:00
+1	01:01:10
+1	10:10:10
+1	838:59:59
 SELECT * FROM t1 ORDER BY f_timestamp;
 f_time	f_timestamp	f_datetime
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+-838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00
 01:01:10	1980-11-21 18:06:01	2020-01-01 01:01:01
 00:00:00	2001-01-21 18:11:01	2000-01-01 01:01:01
 00:00:00	2011-11-21 17:11:01	NULL
@@ -58,9 +91,30 @@ f_time	f_timestamp	f_datetime
 NULL	2015-11-21 17:11:01	2000-01-01 01:01:01
 SELECT * FROM t1 WHERE f_timestamp IS NULL;
 f_time	f_timestamp	f_datetime
+SELECT COUNT(*), MIN(f_timestamp) FROM t1 GROUP BY f_timestamp;
+COUNT(*)	MIN(f_timestamp)
+3	0000-00-00 00:00:00
+1	1980-11-21 18:06:01
+1	2001-01-21 18:11:01
+1	2011-11-21 17:11:01
+1	2015-11-21 17:11:01
+1	2031-11-21 17:11:01
+SELECT UNIX_TIMESTAMP(f_timestamp) FROM t1 ORDER BY f_timestamp;
+UNIX_TIMESTAMP(f_timestamp)
+0
+0
+0
+343667161
+980089861
+1321884661
+1448115061
+1953036661
 SELECT * FROM t1 ORDER BY f_datetime;
 f_time	f_timestamp	f_datetime
 00:00:00	2011-11-21 17:11:01	NULL
+838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+-838:59:59	0000-00-00 00:00:00	0000-00-00 00:00:00
+00:00:00	0000-00-00 00:00:00	0000-00-00 00:00:00
 00:00:00	2001-01-21 18:11:01	2000-01-01 01:01:01
 NULL	2015-11-21 17:11:01	2000-01-01 01:01:01
 10:10:10	2031-11-21 17:11:01	2010-10-10 10:10:10
@@ -79,6 +133,13 @@ f_time	f_timestamp	f_datetime
 SELECT * FROM t1 WHERE f_datetime IS NULL;
 f_time	f_timestamp	f_datetime
 00:00:00	2011-11-21 17:11:01	NULL
+SELECT COUNT(*), MIN(f_datetime) FROM t1 GROUP BY f_datetime;
+COUNT(*)	MIN(f_datetime)
+1	NULL
+3	0000-00-00 00:00:00
+2	2000-01-01 01:01:01
+1	2010-10-10 10:10:10
+1	2020-01-01 01:01:01
 #
 # Checking various val_xxx() methods for the old fields
 #
@@ -89,6 +150,9 @@ CAST(f_time AS CHAR)	CAST(f_time AS SIGN
 01:01:10	10110	10110.000000
 NULL	NULL	NULL
 00:00:00	0	0.000000
+838:59:59	8385959	8385959.000000
+-838:59:59	-8385959	-8385959.000000
+00:00:00	0	0.000000
 SELECT CAST(f_datetime AS CHAR), CAST(f_datetime AS SIGNED), CAST(f_datetime AS DECIMAL(23,6)) FROM t1;
 CAST(f_datetime AS CHAR)	CAST(f_datetime AS SIGNED)	CAST(f_datetime AS DECIMAL(23,6))
 2010-10-10 10:10:10	20101010101010	20101010101010.000000
@@ -96,6 +160,9 @@ CAST(f_datetime AS CHAR)	CAST(f_datetime
 2020-01-01 01:01:01	20200101010101	20200101010101.000000
 2000-01-01 01:01:01	20000101010101	20000101010101.000000
 NULL	NULL	NULL
+0000-00-00 00:00:00	0	0.000000
+0000-00-00 00:00:00	0	0.000000
+0000-00-00 00:00:00	0	0.000000
 SELECT CAST(f_timestamp AS CHAR), CAST(f_timestamp AS SIGNED), CAST(f_timestamp AS DECIMAL(23,6)) FROM t1;
 CAST(f_timestamp AS CHAR)	CAST(f_timestamp AS SIGNED)	CAST(f_timestamp AS DECIMAL(23,6))
 2031-11-21 17:11:01	20311121171101	20311121171101.000000
@@ -103,6 +170,9 @@ CAST(f_timestamp AS CHAR)	CAST(f_timesta
 1980-11-21 18:06:01	19801121180601	19801121180601.000000
 2015-11-21 17:11:01	20151121171101	20151121171101.000000
 2011-11-21 17:11:01	20111121171101	20111121171101.000000
+0000-00-00 00:00:00	0	0.000000
+0000-00-00 00:00:00	0	0.000000
+0000-00-00 00:00:00	0	0.000000
 #
 # Checking old table
 #
@@ -114,6 +184,9 @@ f_time	HEX(WEIGHT_STRING(f_time))
 01:01:10	80277E
 NULL	NULL
 00:00:00	800000
+838:59:59	FFF5A7
+-838:59:59	000A59
+00:00:00	800000
 22:22:23	83640F
 SELECT f_timestamp, HEX(WEIGHT_STRING(f_timestamp)) FROM t1;
 f_timestamp	HEX(WEIGHT_STRING(f_timestamp))
@@ -122,6 +195,9 @@ f_timestamp	HEX(WEIGHT_STRING(f_timestam
 1980-11-21 18:06:01	147BF1D9
 2015-11-21 17:11:01	56507B75
 2011-11-21 17:11:01	4ECA5BF5
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
 2011-11-21 22:22:23	4ECAA4EF
 SELECT f_datetime, HEX(WEIGHT_STRING(f_datetime)) FROM t1;
 f_datetime	HEX(WEIGHT_STRING(f_datetime))
@@ -130,6 +206,9 @@ f_datetime	HEX(WEIGHT_STRING(f_datetime)
 2020-01-01 01:01:01	0000125F33D85AB5
 2000-01-01 01:01:01	00001230A2EA8AB5
 NULL	NULL
+0000-00-00 00:00:00	0000000000000000
+0000-00-00 00:00:00	0000000000000000
+0000-00-00 00:00:00	0000000000000000
 2011-11-21 22:22:23	0000124A7C3C8A4F
 #
 # This ALTER does not change old fields to new fields
@@ -144,6 +223,9 @@ f_time	HEX(WEIGHT_STRING(f_time))
 01:01:10	80277E
 NULL	NULL
 00:00:00	800000
+838:59:59	FFF5A7
+-838:59:59	000A59
+00:00:00	800000
 22:22:23	83640F
 22:22:23	83640F
 SELECT f_timestamp, HEX(WEIGHT_STRING(f_timestamp)) FROM t1;
@@ -153,6 +235,9 @@ f_timestamp	HEX(WEIGHT_STRING(f_timestam
 1980-11-21 18:06:01	147BF1D9
 2015-11-21 17:11:01	56507B75
 2011-11-21 17:11:01	4ECA5BF5
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
 2011-11-21 22:22:23	4ECAA4EF
 2011-11-21 22:22:23	4ECAA4EF
 SELECT f_datetime, HEX(WEIGHT_STRING(f_datetime)) FROM t1;
@@ -162,6 +247,9 @@ f_datetime	HEX(WEIGHT_STRING(f_datetime)
 2020-01-01 01:01:01	0000125F33D85AB5
 2000-01-01 01:01:01	00001230A2EA8AB5
 NULL	NULL
+0000-00-00 00:00:00	0000000000000000
+0000-00-00 00:00:00	0000000000000000
+0000-00-00 00:00:00	0000000000000000
 2011-11-21 22:22:23	0000124A7C3C8A4F
 2011-11-21 22:22:23	0000124A7C3C8A4F
 #
@@ -177,6 +265,9 @@ f_time	HEX(WEIGHT_STRING(f_time))
 01:01:10	80104A
 NULL	NULL
 00:00:00	800000
+838:59:59	B46EFB
+-838:59:59	4B9105
+00:00:00	800000
 22:22:23	816597
 22:22:23	816597
 22:22:23	816597
@@ -187,6 +278,9 @@ f_timestamp	HEX(WEIGHT_STRING(f_timestam
 1980-11-21 18:06:01	147BF1D9
 2015-11-21 17:11:01	56507B75
 2011-11-21 17:11:01	4ECA5BF5
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
+0000-00-00 00:00:00	00000000
 2011-11-21 22:22:23	4ECAA4EF
 2011-11-21 22:22:23	4ECAA4EF
 2011-11-21 22:22:23	4ECAA4EF
@@ -197,6 +291,9 @@ f_datetime	HEX(WEIGHT_STRING(f_datetime)
 2020-01-01 01:01:01	99A5421041
 2000-01-01 01:01:01	9964421041
 NULL	NULL
+0000-00-00 00:00:00	8000000000
+0000-00-00 00:00:00	8000000000
+0000-00-00 00:00:00	8000000000
 2011-11-21 22:22:23	998AAB6597
 2011-11-21 22:22:23	998AAB6597
 2011-11-21 22:22:23	998AAB6597

=== modified file 'mysql-test/r/type_time.result'
--- a/mysql-test/r/type_time.result	2011-11-28 09:36:45 +0000
+++ b/mysql-test/r/type_time.result	2012-01-24 13:17:11 +0000
@@ -322,5 +322,113 @@ NULL
 Warnings:
 Warning	1292	Truncated incorrect time value: '10000090000:10:10.1999999999999'
 #
+# Checking Item_func_if::val_str with TIME arguments
+#
+SELECT CAST(IF(1, TIME'00:00:00',TIME'00:00:00') AS CHAR);
+CAST(IF(1, TIME'00:00:00',TIME'00:00:00') AS CHAR)
+00:00:00
+#
+# Checking Item_func_case::val_str with TIME arguments
+#
+SELECT CAST(CASE WHEN 1 THEN TIME'00:00:00' ELSE TIME'00:00:00' END AS CHAR);
+CAST(CASE WHEN 1 THEN TIME'00:00:00' ELSE TIME'00:00:00' END AS CHAR)
+00:00:00
+#
+# Testing CASE with TIME type without a found item
+#
+SELECT CAST(CASE WHEN 0 THEN '01:01:01' END AS TIME);
+CAST(CASE WHEN 0 THEN '01:01:01' END AS TIME)
+NULL
+SELECT CAST(CASE WHEN 0 THEN TIME'01:01:01' END AS TIME);
+CAST(CASE WHEN 0 THEN TIME'01:01:01' END AS TIME)
+NULL
+#
+# Testing COALESCE with TIME type without a found item
+#
+SELECT COALESCE(TIME(NULL));
+COALESCE(TIME(NULL))
+NULL
+#
+# Testing TIME field with NULL value with NOT IN
+#
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1 WHERE a NOT IN (TIME'20:20:20',TIME'10:10:10');
+a
+DROP TABLE t1;
+#
+# Testing Item_func_numhybrid::val_int when TIME type
+#
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES ('10:10:10');
+SELECT CAST(COALESCE(a,a) AS SIGNED) FROM t1;
+CAST(COALESCE(a,a) AS SIGNED)
+101010
+DROP TABLE t1;
+#
+# Testing Item_func_numhybrid::val_decimal when TIME type
+#
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES ('10:10:10');
+SELECT CAST(COALESCE(a,a) AS DECIMAL(23,6)) FROM t1;
+CAST(COALESCE(a,a) AS DECIMAL(23,6))
+101010.000000
+DROP TABLE t1;
+#
+# Testing Item_func_numhybrid::get_time  when non-temporal type
+#
+SELECT CAST(COALESCE(10,20) AS TIME);
+CAST(COALESCE(10,20) AS TIME)
+00:00:10
+#
+# Testing Item_func_min_max::get_time when DATE type and NULL
+#
+SELECT CAST(LEAST(DATE(NULL), DATE(NULL)) AS TIME);
+CAST(LEAST(DATE(NULL), DATE(NULL)) AS TIME)
+NULL
+#
+# Testing Item_func_min_max::get_time with non-temporal arguments
+#
+SELECT CAST(LEAST(111111,222222) AS TIME);
+CAST(LEAST(111111,222222) AS TIME)
+11:11:11
+#
+# Item::get_time_from_numeric
+#
+SELECT CAST(SUM(0) AS TIME);
+CAST(SUM(0) AS TIME)
+00:00:00
+SELECT CAST(SUM(0 + 0e0) AS TIME);
+CAST(SUM(0 + 0e0) AS TIME)
+00:00:00
+SET timestamp=1322115328;
+SELECT CAST(UNIX_TIMESTAMP() AS TIME);
+CAST(UNIX_TIMESTAMP() AS TIME)
+NULL
+Warnings:
+Warning	1292	Truncated incorrect time value: '1322115328'
+SET timestamp=default;
+#
+# Item::get_time_from_non_temporal
+#
+SELECT TIME(154559.616 + 0e0);
+TIME(154559.616 + 0e0)
+15:45:59.616000
+#
+# Item_name_const::get_time
+#
+SELECT TIME(NAME_CONST('a', 0));
+TIME(NAME_CONST('a', 0))
+00:00:00
+#
+# Item_cache_datetime::get_time
+#
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (0);
+SELECT TIME(MIN(a)) FROM t1;
+TIME(MIN(a))
+00:00:00
+DROP TABLE t1;
+#
 # End of 5.6 tests
 #

=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2012-01-10 18:58:10 +0000
+++ b/mysql-test/r/view.result	2012-01-23 10:52:59 +0000
@@ -4138,3 +4138,10 @@ CREATE TEMPORARY TABLE t1 (a INT) engine
 CREATE VIEW t1 AS SELECT 1;
 DROP VIEW t1;
 DROP TEMPORARY TABLE t1;
+#
+# Bug#13601606: FAILED VIEW CREATION ERROR MESSAGE (FOR DB NOT PRESENT) 
+#               NEEDS BIG IMPROVEMENT 
+#
+DROP DATABASE IF EXISTS nodb;
+CREATE VIEW nodb.a AS SELECT 1;
+ERROR 42000: Unknown database 'nodb'

=== modified file 'mysql-test/r/xa.result'
--- a/mysql-test/r/xa.result	2011-12-22 10:38:23 +0000
+++ b/mysql-test/r/xa.result	2012-01-20 10:07:05 +0000
@@ -217,12 +217,14 @@ INSERT INTO t2 SELECT a FROM t1;
 # Connection default
 # Waiting until INSERT ... is blocked
 DELETE FROM t1;
-COMMIT;
 # Connection con2
 # Reaping: INSERT INTO t2 SELECT a FROM t1
 ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
 XA COMMIT 'xid1';
 ERROR XA102: XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected
+# Connection default
+COMMIT;
+# Connection con2
 XA START 'xid1';
 XA END 'xid1';
 XA PREPARE 'xid1';

=== modified file 'mysql-test/suite/parts/r/partition-dml-1-9-innodb.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-9-innodb.result	2011-03-24 13:10:37 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-9-innodb.result	2012-01-20 14:44:16 +0000
@@ -126,10 +126,6 @@ SELECT t1.a, t2.b FROM t1 PARTITION (`p0
 WHERE t1.a = t2.a;
 SELECT * FROM v1;
 a	b
--3	(pNeg-)subp0
--4	(pNeg-)subp0
--1	(pNeg-)subp0
--2	(pNeg-)subp0
 3	(p0-29-)subp3
 21	(p0-29-)subp5
 24	(p0-29-)subp5
@@ -138,26 +134,6 @@ a	b
 22	(p0-29-)subp5
 2	(p0-29-)subp3
 23	(p0-29-)subp5
-33	(p30-299-)subp6
-231	(p30-299-)subp8
-234	(p30-299-)subp8
-31	(p30-299-)subp6
-34	(p30-299-)subp6
-232	(p30-299-)subp8
-32	(p30-299-)subp6
-233	(p30-299-)subp8
-303	(p300-2999-)subp8
-301	(p300-2999-)subp8
-304	(p300-2999-)subp8
-302	(p300-2999-)subp8
-3003	(p3000-299999-)subp12
-299997	(p3000-299999-)subp14
-3001	(p3000-299999-)subp12
-3004	(p3000-299999-)subp12
-299998	(p3000-299999-)subp14
-3002	(p3000-299999-)subp12
-299996	(p3000-299999-)subp14
-299999	(p3000-299999-)subp14
 SELECT * FROM t1 PARTITION (`p0-29`);
 a	b
 1	(p0-29-)subp3

=== modified file 'mysql-test/suite/parts/r/partition-dml-1-9-myisam.result'
--- a/mysql-test/suite/parts/r/partition-dml-1-9-myisam.result	2011-03-24 13:10:37 +0000
+++ b/mysql-test/suite/parts/r/partition-dml-1-9-myisam.result	2012-01-20 14:44:16 +0000
@@ -126,10 +126,6 @@ SELECT t1.a, t2.b FROM t1 PARTITION (`p0
 WHERE t1.a = t2.a;
 SELECT * FROM v1;
 a	b
--3	(pNeg-)subp0
--4	(pNeg-)subp0
--1	(pNeg-)subp0
--2	(pNeg-)subp0
 3	(p0-29-)subp3
 21	(p0-29-)subp5
 24	(p0-29-)subp5
@@ -138,26 +134,6 @@ a	b
 22	(p0-29-)subp5
 2	(p0-29-)subp3
 23	(p0-29-)subp5
-33	(p30-299-)subp6
-231	(p30-299-)subp8
-234	(p30-299-)subp8
-31	(p30-299-)subp6
-34	(p30-299-)subp6
-232	(p30-299-)subp8
-32	(p30-299-)subp6
-233	(p30-299-)subp8
-303	(p300-2999-)subp8
-301	(p300-2999-)subp8
-304	(p300-2999-)subp8
-302	(p300-2999-)subp8
-3003	(p3000-299999-)subp12
-299997	(p3000-299999-)subp14
-3001	(p3000-299999-)subp12
-3004	(p3000-299999-)subp12
-299998	(p3000-299999-)subp14
-3002	(p3000-299999-)subp12
-299996	(p3000-299999-)subp14
-299999	(p3000-299999-)subp14
 SELECT * FROM t1 PARTITION (`p0-29`);
 a	b
 1	(p0-29-)subp3

=== modified file 'mysql-test/suite/rpl/r/rpl_heartbeat_basic.result'
--- a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result	2011-11-19 08:08:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result	2012-01-25 18:17:41 +0000
@@ -329,6 +329,7 @@ include/rpl_change_topology.inc [new top
 Warnings:
 Note	1756	Sending passwords in plain text without SSL/TLS is extremely insecure.
 Note	1757	Storing MySQL user name or password information in the master.info repository is not secure and is therefore not recommended. Please see the MySQL Manual for more about this issue and possible alternatives.
+CHANGE MASTER TO MASTER_HEARTBEAT_PERIOD=1;
 include/start_slave.inc
 CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10));
 INSERT INTO t1 VALUES(1, 'on master');

=== modified file 'mysql-test/suite/rpl/r/rpl_log_pos.result'
--- a/mysql-test/suite/rpl/r/rpl_log_pos.result	2012-01-17 22:32:29 +0000
+++ b/mysql-test/suite/rpl/r/rpl_log_pos.result	2012-01-22 17:00:21 +0000
@@ -12,7 +12,7 @@ change master to master_log_pos=MASTER_L
 Read_Master_Log_Pos = '75'
 start slave;
 include/wait_for_slave_io_error.inc [errno=1236]
-Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the start event position from 'master-bin.000001' at XXX, the last event was read from 'master-bin.000001' at XXX, the last byte read was read from 'master-bin.000001' at XXX.''
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event 'master-bin.000001' at XXX, the last event read from 'master-bin.000001' at XXX, the last byte read from 'master-bin.000001' at XXX.''
 include/stop_slave_sql.inc
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB

=== modified file 'mysql-test/suite/rpl/r/rpl_manual_change_index_file.result'
--- a/mysql-test/suite/rpl/r/rpl_manual_change_index_file.result	2012-01-17 22:32:29 +0000
+++ b/mysql-test/suite/rpl/r/rpl_manual_change_index_file.result	2012-01-22 17:00:21 +0000
@@ -8,7 +8,7 @@ CREATE TABLE t1(c1 INT);
 FLUSH LOGS;
 call mtr.add_suppression('Got fatal error 1236 from master when reading data from binary log: .*could not find next log');
 include/wait_for_slave_io_error.inc [errno=1236]
-Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'could not find next log; the start event position from 'master-bin.000001' at XXX, the last event was read from 'master-bin.000002' at XXX, the last byte read was read from 'master-bin.000002' at XXX.''
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'could not find next log; the first event 'master-bin.000001' at XXX, the last event read from 'master-bin.000002' at XXX, the last byte read from 'master-bin.000002' at XXX.''
 CREATE TABLE t2(c1 INT);
 FLUSH LOGS;
 CREATE TABLE t3(c1 INT);

=== modified file 'mysql-test/suite/rpl/r/rpl_packet.result'
--- a/mysql-test/suite/rpl/r/rpl_packet.result	2012-01-17 22:32:29 +0000
+++ b/mysql-test/suite/rpl/r/rpl_packet.result	2012-01-22 17:00:21 +0000
@@ -40,7 +40,7 @@ DROP TABLE t1;
 CREATE TABLE t1 (f1 int PRIMARY KEY, f2 LONGTEXT, f3 LONGTEXT) ENGINE=MyISAM;
 INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), REPEAT('b', @@global.max_allowed_packet));
 include/wait_for_slave_io_error.inc [errno=1236]
-Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the start event position from '' at XXX, the last event was read from 'master-bin.000001' at XXX, the last byte read was read from 'master-bin.000001' at XXX.''
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; the first event '' at XXX, the last event read from 'master-bin.000001' at XXX, the last byte read from 'master-bin.000001' at XXX.''
 STOP SLAVE;
 RESET SLAVE;
 RESET MASTER;

=== modified file 'mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result'
--- a/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result	2012-01-17 22:32:29 +0000
+++ b/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result	2012-01-22 17:00:21 +0000
@@ -78,7 +78,7 @@ CHANGE MASTER TO master_log_pos=MASTER_P
 START SLAVE;
 include/wait_for_slave_param.inc [Last_IO_Errno]
 Last_IO_Errno = '1236'
-Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the start event position from 'master-bin.000001' at XXX, the last event was read from 'master-bin.000001' at XXX, the last byte read was read from 'master-bin.000001' at XXX.''
+Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from impossible position; the first event 'master-bin.000001' at XXX, the last event read from './master-bin.000001' at XXX, the last byte read from './master-bin.000001' at XXX.''
 include/stop_slave.inc
 RESET SLAVE;
 RESET MASTER;

=== modified file 'mysql-test/suite/rpl/t/rpl_heartbeat_basic.test'
--- a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test	2012-01-25 18:17:41 +0000
@@ -489,6 +489,12 @@ let $status_var_comparsion= >;
 --connection master
 #--replace_result $SLAVE_MYPORT SLAVE_PORT $slave_binlog SLAVE_BINLOG
 #eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SLAVE_MYPORT, MASTER_USER='root', MASTER_CONNECT_RETRY=$connect_retry, MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='$slave_binlog';
+
+# BUG#12403008 RPL_HEARTBEAT_BASIC FAILS SPORADICALLY ON PUSHBUILD
+# MASTER_HEARTBEAT_PERIOD had the default value (slave_net_timeout/2)
+# so wait on "Heartbeat event received on master", that only waits for
+# 1 minute, sometimes timeout before heartbeat arrives.
+CHANGE MASTER TO MASTER_HEARTBEAT_PERIOD=1;
 --source include/start_slave.inc
 
 # Insert data on master and on slave and make sure that it replicated for both directions

=== renamed file 'mysql-test/suite/sys_vars/r/innodb_sort_buf_size_basic.result' => 'mysql-test/suite/sys_vars/r/innodb_sort_buffer_size_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_sort_buf_size_basic.result	2011-11-17 11:02:53 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_sort_buffer_size_basic.result	2012-01-26 12:50:34 +0000
@@ -1,21 +1,21 @@
-select @@global.innodb_sort_buf_size;
-@@global.innodb_sort_buf_size
+select @@global.innodb_sort_buffer_size;
+@@global.innodb_sort_buffer_size
 1048576
-select @@session.innodb_sort_buf_size;
-ERROR HY000: Variable 'innodb_sort_buf_size' is a GLOBAL variable
-show global variables like 'innodb_sort_buf_size';
+select @@session.innodb_sort_buffer_size;
+ERROR HY000: Variable 'innodb_sort_buffer_size' is a GLOBAL variable
+show global variables like 'innodb_sort_buffer_size';
 Variable_name	Value
-innodb_sort_buf_size	1048576
-show session variables like 'innodb_sort_buf_size';
+innodb_sort_buffer_size	1048576
+show session variables like 'innodb_sort_buffer_size';
 Variable_name	Value
-innodb_sort_buf_size	1048576
-select * from information_schema.global_variables where variable_name='innodb_sort_buf_size';
+innodb_sort_buffer_size	1048576
+select * from information_schema.global_variables where variable_name='innodb_sort_buffer_size';
 VARIABLE_NAME	VARIABLE_VALUE
-INNODB_SORT_BUF_SIZE	1048576
-select * from information_schema.session_variables where variable_name='innodb_sort_buf_size';
+INNODB_SORT_BUFFER_SIZE	1048576
+select * from information_schema.session_variables where variable_name='innodb_sort_buffer_size';
 VARIABLE_NAME	VARIABLE_VALUE
-INNODB_SORT_BUF_SIZE	1048576
-set global innodb_sort_buf_size=1;
-ERROR HY000: Variable 'innodb_sort_buf_size' is a read only variable
-set session innodb_sort_buf_size=1;
-ERROR HY000: Variable 'innodb_sort_buf_size' is a read only variable
+INNODB_SORT_BUFFER_SIZE	1048576
+set global innodb_sort_buffer_size=1;
+ERROR HY000: Variable 'innodb_sort_buffer_size' is a read only variable
+set session innodb_sort_buffer_size=1;
+ERROR HY000: Variable 'innodb_sort_buffer_size' is a read only variable

=== modified file 'mysql-test/suite/sys_vars/r/innodb_undo_logs_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_undo_logs_basic.result	2011-07-19 08:04:19 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_undo_logs_basic.result	2012-01-25 05:52:50 +0000
@@ -29,3 +29,40 @@ ERROR HY000: Variable 'innodb_undo_logs'
 Expected error 'Variable is a GLOBAL variable'
 SELECT innodb_undo_logs = @@SESSION.innodb_undo_logs;
 ERROR 42S22: Unknown column 'innodb_undo_logs' in 'field list'
+Begin bug 13604034
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+128
+128 Expected
+set global innodb_undo_logs = 129;
+Warnings:
+Warning	1292	Truncated incorrect innodb_undo_logs value: '129'
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+128
+128 Expected
+set global innodb_undo_logs = 0;
+Warnings:
+Warning	1292	Truncated incorrect innodb_undo_logs value: '0'
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+1
+1 Expected
+set global innodb_undo_logs = -1;
+Warnings:
+Warning	1292	Truncated incorrect innodb_undo_logs value: '-1'
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+1
+1 Expected
+set global innodb_undo_logs = 50;
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+50
+50 Expected
+set global innodb_undo_logs = default;
+select @@innodb_undo_logs;
+@@innodb_undo_logs
+128
+128 Expected
+End bug 13604034

=== added file 'mysql-test/suite/sys_vars/r/stored_program_cache_basic.result'
--- a/mysql-test/suite/sys_vars/r/stored_program_cache_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/stored_program_cache_basic.result	2012-01-25 09:59:30 +0000
@@ -0,0 +1,59 @@
+# Saving initial value of stored_program_cache in a temporary variable
+SET @start_value = @@global.stored_program_cache;
+SELECT @start_value;
+@start_value
+256
+# Display the DEFAULT value of stored_program_cache
+SET @@global.stored_program_cache  = DEFAULT;
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+256
+# Verify default value of variable
+SELECT @@global.stored_program_cache  = 256;
+@@global.stored_program_cache  = 256
+1
+# Change the value of stored_program_cache to a valid value
+SET @@global.stored_program_cache  = 512;
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+512
+# Change the value of stored_program_cache to invalid value
+SET @@global.stored_program_cache  = -1;
+Warnings:
+Warning	1292	Truncated incorrect stored_program_cache value: '-1'
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+256
+SET @@global.stored_program_cache =100000000000;
+Warnings:
+Warning	1292	Truncated incorrect stored_program_cache value: '100000000000'
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+524288
+SET @@global.stored_program_cache = 0;
+Warnings:
+Warning	1292	Truncated incorrect stored_program_cache value: '0'
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+256
+SET @@global.stored_program_cache = 10000.01;
+ERROR 42000: Incorrect argument type to variable 'stored_program_cache'
+SET @@global.stored_program_cache = ON;
+ERROR 42000: Incorrect argument type to variable 'stored_program_cache'
+SET @@global.stored_program_cache= 'test';
+ERROR 42000: Incorrect argument type to variable 'stored_program_cache'
+SET @@global.stored_program_cache = '';
+ERROR 42000: Incorrect argument type to variable 'stored_program_cache'
+# Test if accessing session stored_program_cache gives error
+SET @@session.stored_program_cache = 0;
+ERROR HY000: Variable 'stored_program_cache' is a GLOBAL variable and should be set with SET GLOBAL
+# Check if accessing variable without SCOPE points to same global variable
+SET @@global.stored_program_cache = 512;
+SELECT @@stored_program_cache = @@global.stored_program_cache;
+@@stored_program_cache = @@global.stored_program_cache
+1
+# Restore initial value
+SET @@global.stored_program_cache = @start_value;
+SELECT @@global.stored_program_cache;
+@@global.stored_program_cache
+256

=== renamed file 'mysql-test/suite/sys_vars/t/innodb_sort_buf_size_basic.test' => 'mysql-test/suite/sys_vars/t/innodb_sort_buffer_size_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_sort_buf_size_basic.test	2011-11-17 11:02:53 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_sort_buffer_size_basic.test	2012-01-26 12:50:34 +0000
@@ -8,19 +8,19 @@
 #
 # show the global and session values;
 #
-select @@global.innodb_sort_buf_size;
+select @@global.innodb_sort_buffer_size;
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
-select @@session.innodb_sort_buf_size;
-show global variables like 'innodb_sort_buf_size';
-show session variables like 'innodb_sort_buf_size';
-select * from information_schema.global_variables where variable_name='innodb_sort_buf_size';
-select * from information_schema.session_variables where variable_name='innodb_sort_buf_size';
+select @@session.innodb_sort_buffer_size;
+show global variables like 'innodb_sort_buffer_size';
+show session variables like 'innodb_sort_buffer_size';
+select * from information_schema.global_variables where variable_name='innodb_sort_buffer_size';
+select * from information_schema.session_variables where variable_name='innodb_sort_buffer_size';
 
 #
 # show that it's read-only
 #
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
-set global innodb_sort_buf_size=1;
+set global innodb_sort_buffer_size=1;
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
-set session innodb_sort_buf_size=1;
+set session innodb_sort_buffer_size=1;
 

=== modified file 'mysql-test/suite/sys_vars/t/innodb_undo_logs_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_undo_logs_basic.test	2011-07-19 08:04:19 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_undo_logs_basic.test	2012-01-25 05:52:50 +0000
@@ -69,3 +69,27 @@ SELECT COUNT(@@SESSION.innodb_undo_logs)
 
 --Error ER_BAD_FIELD_ERROR
 SELECT innodb_undo_logs = @@SESSION.innodb_undo_logs;
+
+# Begin Bug 13604034
+# SET GLOBAL INNODB_UNDO_LOGS=0 SUCCEEDS BUT LEADS TO AN ASSERT
+# MAX_UNDO_LOGS > 0
+--echo Begin bug 13604034
+select @@innodb_undo_logs;
+--echo 128 Expected
+set global innodb_undo_logs = 129;
+select @@innodb_undo_logs;
+--echo 128 Expected
+set global innodb_undo_logs = 0;
+select @@innodb_undo_logs;
+--echo 1 Expected
+set global innodb_undo_logs = -1;
+select @@innodb_undo_logs;
+--echo 1 Expected
+set global innodb_undo_logs = 50;
+select @@innodb_undo_logs;
+--echo 50 Expected
+set global innodb_undo_logs = default;
+select @@innodb_undo_logs;
+--echo 128 Expected
+--echo End bug 13604034
+# End Bug 13604034

=== added file 'mysql-test/suite/sys_vars/t/stored_program_cache_basic.test'
--- a/mysql-test/suite/sys_vars/t/stored_program_cache_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/stored_program_cache_basic.test	2012-01-25 09:59:30 +0000
@@ -0,0 +1,59 @@
+# Variable Name: stored_program_cache
+# Scope: GLOBAL
+# Access Type: Dynamic
+# Data Type: numeric
+# Default Value: 256
+# Range: 256-524288
+
+--source include/load_sysvars.inc
+
+--echo # Saving initial value of stored_program_cache in a temporary variable
+SET @start_value = @@global.stored_program_cache;
+SELECT @start_value;
+
+--echo # Display the DEFAULT value of stored_program_cache
+SET @@global.stored_program_cache  = DEFAULT;
+SELECT @@global.stored_program_cache;
+
+--echo # Verify default value of variable
+SELECT @@global.stored_program_cache  = 256;
+
+--echo # Change the value of stored_program_cache to a valid value
+SET @@global.stored_program_cache  = 512;
+SELECT @@global.stored_program_cache;
+
+--echo # Change the value of stored_program_cache to invalid value
+SET @@global.stored_program_cache  = -1;
+SELECT @@global.stored_program_cache;
+
+SET @@global.stored_program_cache =100000000000;
+SELECT @@global.stored_program_cache;
+
+SET @@global.stored_program_cache = 0;
+SELECT @@global.stored_program_cache;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.stored_program_cache = 10000.01;
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.stored_program_cache = ON;
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.stored_program_cache= 'test';
+
+--Error ER_WRONG_TYPE_FOR_VAR
+SET @@global.stored_program_cache = '';
+
+--echo # Test if accessing session stored_program_cache gives error
+
+--Error ER_GLOBAL_VARIABLE
+SET @@session.stored_program_cache = 0;
+
+--echo # Check if accessing variable without SCOPE points to same global variable
+
+SET @@global.stored_program_cache = 512;
+SELECT @@stored_program_cache = @@global.stored_program_cache;
+
+--echo # Restore initial value
+
+SET @@global.stored_program_cache = @start_value;
+SELECT @@global.stored_program_cache;

=== modified file 'mysql-test/t/bigint.test'
--- a/mysql-test/t/bigint.test	2010-02-25 19:13:11 +0000
+++ b/mysql-test/t/bigint.test	2012-01-25 09:36:25 +0000
@@ -361,4 +361,51 @@ DROP TABLE t1;
 
 --echo # End of 5.1 tests
 
+--echo #
+--echo # Bug#13463415 63502: INCORRECT RESULTS OF BIGINT AND DECIMAL COMPARISON
+--echo #
 
+CREATE TABLE t_bigint(id BIGINT);
+INSERT INTO t_bigint VALUES (1), (2);
+
+SELECT id, id >= 1.1 FROM t_bigint;
+SELECT id, 1.1 <= id FROM t_bigint;
+
+SELECT id, id = 1.1 FROM t_bigint;
+SELECT id, 1.1 = id FROM t_bigint;
+
+SELECT * from t_bigint WHERE id = 1.1;
+SELECT * from t_bigint WHERE id = 1.1e0;
+SELECT * from t_bigint WHERE id = '1.1';
+SELECT * from t_bigint WHERE id = '1.1e0';
+
+SELECT * from t_bigint WHERE id IN (1.1, 2.2);
+SELECT * from t_bigint WHERE id IN (1.1e0, 2.2e0);
+SELECT * from t_bigint WHERE id IN ('1.1', '2.2');
+SELECT * from t_bigint WHERE id IN ('1.1e0', '2.2e0');
+
+SELECT * from t_bigint WHERE id BETWEEN 1.1 AND 1.9;
+SELECT * from t_bigint WHERE id BETWEEN 1.1e0 AND 1.9e0;
+SELECT * from t_bigint WHERE id BETWEEN '1.1' AND '1.9';
+SELECT * from t_bigint WHERE id BETWEEN '1.1e0' AND '1.9e0';
+
+DROP TABLE t_bigint;
+
+--echo #
+--echo # Bug#11758543 50756: BIGINT '100' MATCHES 1.001E2
+--echo #
+
+CREATE TABLE t1 (a BIGINT);
+INSERT INTO t1 VALUES (1);
+
+# a. These queries correctly return 0 rows:
+SELECT * FROM t1 WHERE coalesce(a) BETWEEN 0 and 0.9;
+SELECT * FROM t1 WHERE coalesce(a)=0.9;
+SELECT * FROM t1 WHERE coalesce(a) in (0.8,0.9);
+
+# b. These queries mistakenely returned 1 row:
+SELECT * FROM t1 WHERE a BETWEEN 0 AND 0.9;
+SELECT * FROM t1 WHERE a=0.9;
+SELECT * FROM t1 WHERE a IN (0.8,0.9);
+
+DROP TABLE t1;

=== modified file 'mysql-test/t/ctype_utf8.test'
--- a/mysql-test/t/ctype_utf8.test	2011-10-12 13:58:31 +0000
+++ b/mysql-test/t/ctype_utf8.test	2012-01-23 10:02:54 +0000
@@ -1475,6 +1475,14 @@ SELECT HEX(LPAD(_utf8 0xD18F, 3, 0x20));
 SELECT HEX(INSERT(_utf8 0xD18F, 2, 1, 0x20));
 SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
 
+--echo #
+--echo # Bug#11752408 - 43593: DUMP/BACKUP/RESTORE/UPGRADE TOOLS FAILS BECAUSE OF UTF8_GENERAL_CI
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci);
+INSERT INTO t1 VALUES ('a'),('r'),('s'),(_latin1 0xDF),(_latin1 0xF7),('t'),('z');
+SELECT * FROM t1 ORDER BY a;
+SELECT a, COUNT(*) FROM t1 GROUP BY a;
+DROP TABLE t1;
 
 --echo End of 5.1 tests
 

=== modified file 'mysql-test/t/date_formats.test'
--- a/mysql-test/t/date_formats.test	2010-11-12 10:20:58 +0000
+++ b/mysql-test/t/date_formats.test	2012-01-24 13:17:11 +0000
@@ -370,3 +370,25 @@ SET NAMES latin1;
 --echo #
 --echo # End of 5.1 tests
 --echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#946 Fractional seconds precision
+--echo # Testing Item_func_date_format with NULL argument.
+--echo #
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS CHAR);
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS SIGNED);
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DECIMAL(23,6));
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS TIME);
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DATE);
+SELECT CAST(TIME_FORMAT(NULL, '%s') AS DATETIME);
+SELECT TIME_FORMAT(NULL, '%s')+0e0;
+
+
+--echo #
+--echo # End of 5.6 tests
+--echo #

=== modified file 'mysql-test/t/func_str.test'
--- a/mysql-test/t/func_str.test	2011-10-12 13:40:11 +0000
+++ b/mysql-test/t/func_str.test	2012-01-25 15:49:57 +0000
@@ -1492,6 +1492,45 @@ SELECT stddev_samp(rpad(1.0,2048,1));
 SELECT ((127.1) not in ((rpad(1.0,2048,1)),(''),(-1.1)));
 SELECT ((0xf3) * (rpad(1.0,2048,1)) << (0xcc));
 
+--echo #
+--echo # Bug#13359121 LARGE NUMBERS, /STRINGS/DTOA.C:662:
+--echo #              BALLOC: ASSERTION `K <= 15' FAILED.
+--echo # Bug#12985021 SIMPLE QUERY WITH DECIMAL NUMBERS TAKE AN 
+--echo #              EXTRAORDINARY LONG TIME TO EXECUTE
+
+SELECT @tmp_max:= @@global.max_allowed_packet;
+SET @@global.max_allowed_packet=1024*1024*1024;
+# switching connection to allow the new max_allowed_packet take effect
+--connect (newconn, localhost, root,,)
+
+SELECT @@global.max_allowed_packet;
+
+do
+format(rpad('111111111.1',
+             1111111,
+             '999999999999999999999999999999999999999999'),0,'be_BY')
+;
+
+DO
+round(
+  concat( (
+    coalesce( (
+      linefromwkb('2147483648',
+                  -b'1111111111111111111111111111111111111111111')),
+      ( convert('[.DC2.]',decimal(30,30)) ),
+      bit_count('')
+    ) ),
+    ( lpad( ( elt('01','}:K5')),
+              sha1('P'),
+              ( ( select '-9223372036854775808.1' > all (select '')))
+          )
+    )
+  )
+);
+
+--connection default
+SET @@global.max_allowed_packet:= @tmp_max;
+--disconnect newconn
 
 --echo #
 --echo # End of 5.5 tests

=== modified file 'mysql-test/t/func_time.test'
--- a/mysql-test/t/func_time.test	2012-01-17 08:23:57 +0000
+++ b/mysql-test/t/func_time.test	2012-01-24 11:57:25 +0000
@@ -919,11 +919,70 @@ DO WEEK((DATE_ADD((CAST(0 AS DATE)), INT
 --echo #
 --echo # Bug #13098726 MY_TIME.C:786: CALC_DAYNR: ASSERTION `DELSUM+(INT)
 --echo # Y/4-TEMP > 0' FAILED
---echo #
-
 SELECT SUBTIME('0000-01-00 00:00','00:00');
 SELECT LEAST(TIMESTAMP('0000-01-00','0'),'2011-10-24') > 0;
 
+--echo #
+--echo # BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
+--echo # SIMILAR TO '2009-10-00' 
+--echo #
+
+query_vertical SELECT
+  DATE('20091000'),
+  STR_TO_DATE('200910','%Y%m'),
+  LAST_DAY('2009-10-00'),
+  LAST_DAY(DATE('2009-10-00')),
+  LAST_DAY(DATE'2009-10-00'),
+  LAST_DAY(STR_TO_DATE('200910','%Y%m')),
+  WEEK('2009-10-00'),
+  WEEK(DATE('2009-10-00')),
+  WEEK(DATE'2009-10-00'),
+  WEEK(STR_TO_DATE('200910','%Y%m')),
+  WEEKOFYEAR('2009-10-00'),
+  WEEKOFYEAR(DATE('2009-10-00')),
+  WEEKOFYEAR(DATE'2009-10-00'),
+  WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')),
+  DAYOFYEAR('2009-10-00'),
+  DAYOFYEAR(DATE('2009-10-00')),
+  DAYOFYEAR(DATE'2009-10-00'),
+  DAYOFYEAR(STR_TO_DATE('200910','%Y%m')),
+  WEEKDAY('2009-10-00'),
+  WEEKDAY(DATE('2009-10-00')),
+  WEEKDAY(DATE'2009-10-00'),
+  WEEKDAY(STR_TO_DATE('200910','%Y%m')),
+  TO_DAYs('2009-10-00'),
+  TO_DAYs(DATE('2009-10-00')),
+  TO_DAYs(DATE'2009-10-00'),
+  TO_DAYs(STR_TO_DATE('200910','%Y%m'));
+
+query_vertical SELECT
+  DATE('00000100'),
+  STR_TO_DATE('000001','%Y%m'),
+  LAST_DAY('0000-01-00'),
+  LAST_DAY(DATE('0000-01-00')),
+  LAST_DAY(DATE'0000-01-00'),
+  LAST_DAY(STR_TO_DATE('000001','%Y%m')),
+  WEEK('0000-01-00'),
+  WEEK(DATE('0000-01-00')),
+  WEEK(DATE'0000-01-00'),
+  WEEK(STR_TO_DATE('000001','%Y%m')),
+  WEEKOFYEAR('0000-01-00'),
+  WEEKOFYEAR(DATE('0000-01-00')),
+  WEEKOFYEAR(DATE'0000-01-00'),
+  WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')),
+  DAYOFYEAR('0000-01-00'),
+  DAYOFYEAR(DATE('0000-01-00')),
+  DAYOFYEAR(DATE'0000-01-00'),
+  DAYOFYEAR(STR_TO_DATE('000001','%Y%m')),
+  WEEKDAY('0000-01-00'),
+  WEEKDAY(DATE('0000-01-00')),
+  WEEKDAY(DATE'0000-01-00'),
+  WEEKDAY(STR_TO_DATE('000001','%Y%m')),
+  TO_DAYs('0000-01-00'),
+  TO_DAYs(DATE('0000-01-00')),
+  TO_DAYs(DATE'0000-01-00'),
+  TO_DAYs(STR_TO_DATE('000001','%Y%m'));
+
 --echo End of 5.1 tests
 
 --echo #

=== modified file 'mysql-test/t/mysql_embedded.test'
--- a/mysql-test/t/mysql_embedded.test	2011-12-05 12:01:10 +0000
+++ b/mysql-test/t/mysql_embedded.test	2012-01-25 10:46:24 +0000
@@ -9,10 +9,10 @@ if(!$MYSQL_EMBEDDED)
 {
   --skip Test requires mysql_embedded executable
 }
---exec $MYSQL_EMBEDDED --defaults-file=$PATH_CONFIG_FILE -e 'select 1'
+--exec $MYSQL_EMBEDDED --defaults-file=$PATH_CONFIG_FILE -e "select 1"
 
 --echo #
 --echo # Bug#11764633 : 57491: THD->MAIN_DA.IS_OK() ASSERT IN EMBEDDED
 --echo #
 
---exec $MYSQL_EMBEDDED --defaults-file=$PATH_CONFIG_FILE -e '\T foo/bar'
+--exec $MYSQL_EMBEDDED --defaults-file=$PATH_CONFIG_FILE -e "\T foo/bar"

=== modified file 'mysql-test/t/optimizer_debug_sync.test'
--- a/mysql-test/t/optimizer_debug_sync.test	2011-03-28 10:56:41 +0000
+++ b/mysql-test/t/optimizer_debug_sync.test	2012-01-26 11:34:35 +0000
@@ -59,3 +59,30 @@ DROP TABLE t;
 --exit
 
 --echo # End of BUG#56080
+
+--echo #
+--echo # Bug #13536661: VALGRIND: DEFINITELY LOST: 552 BYTES IN 1 BLOCKS IN
+--echo # CREATE_TMP_TABLE AND HIGHER
+--echo #
+CREATE TABLE t1 ( a INT, b INT );
+INSERT INTO t1 VALUES (4, 40), (1, 10), (2, 20), (2, 20), (3, 30);
+
+connect(con1,localhost,root,,);
+SET debug_sync = "tmp_table_created SIGNAL parked WAIT_FOR go";
+--echo # This should not leak memory.
+send SELECT b, COUNT(DISTINCT b) FROM t1 GROUP BY b ORDER BY -b;
+
+connection default;
+SET debug_sync = "now WAIT_FOR parked";
+--echo # Set locally to shadow the global variable.
+SET debug = '';
+SET GLOBAL debug = '+d,simulate_out_of_memory';
+
+SET debug_sync = "now SIGNAL go";
+
+connection con1;
+--error ER_OUT_OF_RESOURCES
+reap;
+SET GLOBAL debug = '';
+
+DROP TABLE t1;

=== modified file 'mysql-test/t/partition_binlog_stmt.test'
--- a/mysql-test/t/partition_binlog_stmt.test	2010-10-01 12:16:00 +0000
+++ b/mysql-test/t/partition_binlog_stmt.test	2012-01-20 13:19:39 +0000
@@ -8,7 +8,7 @@ DROP TABLE IF EXISTS t1;
 --echo #
 --echo # Bug#51851: Server with SBR locks mutex twice on LOAD DATA into
 --echo #            partitioned MyISAM table
---write_file init_file.txt
+--write_file $MYSQLTEST_VARDIR/tmp/init_file.txt
 abcd
 EOF
 
@@ -19,8 +19,9 @@ CREATE TABLE t1
  INDEX namelocs (name(255))) ENGINE = MyISAM
 PARTITION BY HASH(id) PARTITIONS 2;
 
-LOAD DATA LOCAL INFILE 'init_file.txt'
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval LOAD DATA LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/init_file.txt'
 INTO TABLE t1 (name);
 
---remove_file init_file.txt
+--remove_file $MYSQLTEST_VARDIR/tmp/init_file.txt
 DROP TABLE t1;

=== modified file 'mysql-test/t/partition_explicit_prune.test'
--- a/mysql-test/t/partition_explicit_prune.test	2011-02-01 11:38:39 +0000
+++ b/mysql-test/t/partition_explicit_prune.test	2012-01-21 00:47:05 +0000
@@ -1,6 +1,88 @@
 --source include/have_innodb.inc
 --source include/have_partition.inc
 
+# Helper statement
+let $get_handler_status_counts= SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
+WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
+
+--echo #
+--echo # Bug#13559657: PARTITION SELECTION DOES NOT WORK WITH VIEWS
+--echo #
+CREATE TABLE t1 (a int)
+ENGINE = InnoDB
+PARTITION BY HASH (a) PARTITIONS 2;
+INSERT INTO t1 VALUES (0), (1), (2), (3);
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0);
+SHOW CREATE VIEW v1;
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--sorted_result
+SELECT a FROM t1 PARTITION (p0);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+INSERT INTO v1 VALUES (10);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO v1 VALUES (11);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--sorted_result
+SELECT * FROM v1;
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--sorted_result
+SELECT a FROM t1 PARTITION (p0);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+CREATE VIEW v1 AS SELECT a FROM t1 PARTITION (p0) WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (20);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--error ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET
+INSERT INTO v1 VALUES (21);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+--sorted_result
+SELECT * FROM v1;
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+CREATE VIEW v1 AS
+SELECT a FROM t1 PARTITION (p0) WHERE a = 30 WITH CHECK OPTION;
+FLUSH STATUS;
+INSERT INTO v1 VALUES (30);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+FLUSH STATUS;
+--error ER_VIEW_CHECK_FAILED
+INSERT INTO v1 VALUES (31);
+eval $get_handler_status_counts;
+FLUSH STATUS;
+--error ER_VIEW_CHECK_FAILED
+INSERT INTO v1 VALUES (32);
+eval $get_handler_status_counts;
+--echo # 4 locks (1 table, 1 partition lock/unlock)
+--sorted_result
+SELECT * FROM v1;
+--sorted_result
+SELECT * FROM t1;
+DROP VIEW v1;
+DROP TABLE t1;
+
 --echo # Original tests for WL#5217
 
 --echo # Must have InnoDB as engine to get the same statistics results.
@@ -8,9 +90,6 @@
 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

=== modified file 'mysql-test/t/plugin.test'
--- a/mysql-test/t/plugin.test	2011-10-27 08:43:56 +0000
+++ b/mysql-test/t/plugin.test	2012-01-26 12:39:35 +0000
@@ -15,10 +15,33 @@ UNINSTALL PLUGIN example;
 --replace_regex /\.dll/.so/
 eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';
 
+--echo # Example engine does not support indexes
+--error ER_TOO_MANY_KEY_PARTS
+CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=EXAMPLE;
+--error ER_TOO_MANY_KEY_PARTS
+CREATE TABLE t1 (a int, KEY (a)) ENGINE=EXAMPLE;
+
+
 CREATE TABLE t1(a int) ENGINE=EXAMPLE;
 
---error ER_ILLEGAL_HA
+SHOW CREATE TABLE t1;
+
+--echo # Let's do some advanced ops with the example engine :)
+INSERT INTO t1 VALUES (0);
+
+--echo # Only supports table scans (and does always return zero rows :)
 SELECT * FROM t1;
+SELECT * FROM t1 WHERE a = 0;
+
+--echo # Since there are no rows found, it will never do update_row.
+UPDATE t1 SET a = 1 WHERE a = 0;
+
+--echo # Since there are no rows found, it will never do delete_row.
+DELETE FROM t1 WHERE a = 0;
+
+--echo # No support for SQL HANDLER statement
+--error ER_ILLEGAL_HA
+HANDLER t1 OPEN;
 
 DROP TABLE t1;
 

=== modified file 'mysql-test/t/temporal_literal.test'
--- a/mysql-test/t/temporal_literal.test	2011-11-10 15:14:11 +0000
+++ b/mysql-test/t/temporal_literal.test	2012-01-24 13:17:11 +0000
@@ -181,3 +181,12 @@ INSERT INTO t1 VALUES ('2001-01-00 00:00
 SELECT * FROM t1;
 DROP TABLE t1;
 
+--echo #
+--echo # Testing Item_date_literal::eq
+--echo #
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES ('2001-01-01'),('2003-01-01');
+SELECT * FROM t1 WHERE a BETWEEN DATE'2001-01-01' AND DATE'2002-01-01';
+SELECT DATE'2001-01-01' FROM t1 GROUP BY DATE'2001-01-01';
+DROP TABLE t1;
+

=== modified file 'mysql-test/t/type_date.test'
--- a/mysql-test/t/type_date.test	2011-11-01 11:52:24 +0000
+++ b/mysql-test/t/type_date.test	2012-01-24 13:17:11 +0000
@@ -332,6 +332,70 @@ SELECT * FROM t1;
 DROP TABLE t1;
 SET timestamp=DEFAULT;
 
+--echo #
+--echo # Testing cast from DECIMAL to DATE
+--echo #
+CREATE TABLE t1 (a DECIMAL(23,4));
+INSERT INTO t1 VALUES (NULL),(101010.9999),(-101010.9999);
+SELECT a, CAST(a AS DATE) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing CASE with DATE type without a found item
+--echo #
+SELECT CAST(CASE WHEN 0 THEN '2001-01-01' END AS DATE);
+SELECT CAST(CASE WHEN 0 THEN DATE'2001-01-01' END AS DATE);
+
+--echo #
+--echo # Testing DATE field with NULL value with NOT IN
+--echo #
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1 WHERE a NOT IN (DATE'2001-01-01',DATE'2002-02-02');
+DROP TABLE t1;
+
+--echo #
+--echo # Testing COALESCE with DATE type without a found item
+--echo #
+SELECT COALESCE(DATE(NULL));
+
+--echo #
+--echo # Testing Item_func_min_max::val_str when DATE type and NULL
+--echo #
+SELECT CAST(LEAST(DATE(NULL), DATE(NULL)) AS CHAR);
+
+--echo #
+--echo # Testing Item_func_min_max::get_date with non-temporal arguments
+--echo #
+SELECT CAST(LEAST(20010101,20020202) AS DATE);
 
+--echo #
+--echo #  Item::get_date_from_numeric
+--echo #
+SELECT CAST(SUM(0) AS DATETIME);
+SELECT CAST(SUM(0 + 0e0) AS DATETIME);
+SET timestamp=1322115004;
+SELECT CAST(UNIX_TIMESTAMP() AS DATE);
+SET timestamp=DEFAULT;
+
+--echo #
+--echo # Item::get_date_from_non_temporal
+--echo #
+SELECT DATE(20110512154559.6 + 0e0);
+
+--echo #
+--echo # Item_name_const::get_date
+--echo #
+SELECT DATE(NAME_CONST('a', 0));
+
+--echo #
+--echo # Item_cache_datetime::get_date
+--echo #
+SET timestamp=UNIX_TIMESTAMP('2011-11-24');
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES (0);
+SELECT DATE(MIN(a)) FROM t1;
+DROP TABLE t1;
+SET timestamp=DEFAULT;
 
 --echo End of 5.6 tests

=== modified file 'mysql-test/t/type_temporal_fractional.test'
--- a/mysql-test/t/type_temporal_fractional.test	2011-12-20 09:45:15 +0000
+++ b/mysql-test/t/type_temporal_fractional.test	2012-01-24 13:17:11 +0000
@@ -158,6 +158,15 @@ UPDATE t1 SET t0=a, t1=a, t2=a, t3=a, t4
 --query_vertical SELECT * FROM t1;
 DROP TABLE t1;
 
+--echo #
+--echo # Testing rounding when casting from DECIMAL to TIME(N)
+--echo #
+CREATE TABLE t1 (a DECIMAL(23,4));
+INSERT INTO t1 VALUES (NULL),(101010.9999),(-101010.9999);
+INSERT INTO t1 VALUES (9999999999999999999999.1), (999999.1);
+SELECT a, CAST(a AS TIME(3)) FROM t1;
+DROP TABLE t1;
+
 
 --echo #
 --echo # Testing that CAST converts days to hours, while EXTRACT/HOUR do not
@@ -1947,6 +1956,7 @@ DROP TABLE t1;
 CREATE TABLE t1 (id INT, a TIME(6));
 INSERT INTO t1 VALUES (1,'00:00:00.123456'), (1,'11:00:00.123456');
 INSERT INTO t1 VALUES (2,'00:01:00.123456'), (2,'11:01:00.123456');
+INSERT INTO t1 VALUES (3, NULL);
 SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t1 GROUP BY id);
 DROP TABLE t1;
 
@@ -3895,6 +3905,7 @@ DROP TABLE t1;
 CREATE TABLE t1 (id INT, a DATETIME(6));
 INSERT INTO t1 VALUES (1, '2001-01-01 00:00:00.123456'), (1, '2001-01-01 11:00:00.123456');
 INSERT INTO t1 VALUES (2, '2001-01-01 00:01:00.123456'), (2, '2001-01-01 11:01:00.123456');
+INSERT INTO t1 VALUES (3, NULL);
 SELECT * FROM t1 WHERE a IN (SELECT MAX(a) FROM t1 GROUP BY id);
 DROP TABLE t1;
 
@@ -7428,6 +7439,15 @@ SELECT c_time AS c1 FROM t1
 WHERE c_timestamp NOT IN (NULL, '0000-00-00 00:00:00');
 DROP TABLE t1;
 
+--echo #
+--echo # Various tests for better gcov coverage
+--echo #
+
+--echo #
+--echo # Comparing DATETIME value to TIME(NULL)
+--echo #
+SELECT TIMESTAMP'2001-01-01 00:00:00' = TIME(NULL);
+
 
 ## TS-TODO: SELECT CAST('00:00:00' AS DATETIME) -> should it use curdate?
 

=== modified file 'mysql-test/t/type_temporal_upgrade.test'
--- a/mysql-test/t/type_temporal_upgrade.test	2011-11-21 19:17:25 +0000
+++ b/mysql-test/t/type_temporal_upgrade.test	2012-01-24 13:17:11 +0000
@@ -15,6 +15,16 @@ let $MYSQLD_DATADIR= `select @@datadir`;
 
 SHOW CREATE TABLE t1;
 
+# Testing bad values
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES (9999999, 999999999999999, 999999999999999);
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES (-9999999, -999999999999999, -999999999999999);
+
+# Testing zero values
+INSERT INTO t1 (f_time, f_datetime, f_timestamp)
+VALUES ('00:00:00', '0000-00-00 00:00:00','0000-00-00 00:00:00');
+
 SELECT * FROM t1;
 
 SELECT * FROM t1 ORDER BY f_time;
@@ -22,18 +32,27 @@ SELECT * FROM t1 WHERE f_time > '00:00:0
 SELECT * FROM t1 WHERE f_time > '00:00:00' ORDER BY f_time;
 SELECT * FROM t1 WHERE f_time = '01:01:10';
 SELECT * FROM t1 WHERE f_time IS NULL;
+# Field_time::store_packed
+SELECT COUNT(*), MIN(f_time) FROM t1 GROUP BY f_time;
 
 SELECT * FROM t1 ORDER BY f_timestamp;
 SELECT * FROM t1 WHERE f_timestamp > '2011-11-21 17:11:01';
 SELECT * FROM t1 WHERE f_timestamp > '2011-11-21 17:11:01' ORDER BY f_timestamp;
 SELECT * FROM t1 WHERE f_timestamp = '2015-11-21 17:11:01';
 SELECT * FROM t1 WHERE f_timestamp IS NULL;
+# Field_timestamp::store_packed
+SELECT COUNT(*), MIN(f_timestamp) FROM t1 GROUP BY f_timestamp;
+# Field_timestamp::get_timestamp
+SELECT UNIX_TIMESTAMP(f_timestamp) FROM t1 ORDER BY f_timestamp;
 
 SELECT * FROM t1 ORDER BY f_datetime;
 SELECT * FROM t1 WHERE f_datetime > '2000-01-01 01:01:01';
 SELECT * FROM t1 WHERE f_datetime > '2000-01-01 01:01:01' ORDER BY f_datetime;
 SELECT * FROM t1 WHERE f_datetime = '2010-10-10 10:10:10';
 SELECT * FROM t1 WHERE f_datetime IS NULL;
+# Field_datetime::store_packed
+SELECT COUNT(*), MIN(f_datetime) FROM t1 GROUP BY f_datetime;
+
 
 --echo #
 --echo # Checking various val_xxx() methods for the old fields

=== modified file 'mysql-test/t/type_time.test'
--- a/mysql-test/t/type_time.test	2011-11-28 09:36:45 +0000
+++ b/mysql-test/t/type_time.test	2012-01-24 13:17:11 +0000
@@ -178,5 +178,93 @@ SELECT TIME('10000090000:10:10');
 SELECT TIME('10000090000:10:10.1999999999999');
 
 --echo #
+--echo # Checking Item_func_if::val_str with TIME arguments
+--echo #
+SELECT CAST(IF(1, TIME'00:00:00',TIME'00:00:00') AS CHAR);
+
+--echo #
+--echo # Checking Item_func_case::val_str with TIME arguments
+--echo #
+SELECT CAST(CASE WHEN 1 THEN TIME'00:00:00' ELSE TIME'00:00:00' END AS CHAR);
+
+--echo #
+--echo # Testing CASE with TIME type without a found item
+--echo #
+SELECT CAST(CASE WHEN 0 THEN '01:01:01' END AS TIME);
+SELECT CAST(CASE WHEN 0 THEN TIME'01:01:01' END AS TIME);
+
+--echo #
+--echo # Testing COALESCE with TIME type without a found item
+--echo #
+SELECT COALESCE(TIME(NULL));
+
+--echo #
+--echo # Testing TIME field with NULL value with NOT IN
+--echo #
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES (NULL);
+SELECT * FROM t1 WHERE a NOT IN (TIME'20:20:20',TIME'10:10:10');
+DROP TABLE t1;
+
+--echo #
+--echo # Testing Item_func_numhybrid::val_int when TIME type
+--echo #
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES ('10:10:10');
+SELECT CAST(COALESCE(a,a) AS SIGNED) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing Item_func_numhybrid::val_decimal when TIME type
+--echo #
+CREATE TABLE t1 (a TIME);
+INSERT INTO t1 VALUES ('10:10:10');
+SELECT CAST(COALESCE(a,a) AS DECIMAL(23,6)) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Testing Item_func_numhybrid::get_time  when non-temporal type
+--echo #
+SELECT CAST(COALESCE(10,20) AS TIME);
+
+--echo #
+--echo # Testing Item_func_min_max::get_time when DATE type and NULL
+--echo #
+SELECT CAST(LEAST(DATE(NULL), DATE(NULL)) AS TIME);
+
+--echo #
+--echo # Testing Item_func_min_max::get_time with non-temporal arguments
+--echo #
+SELECT CAST(LEAST(111111,222222) AS TIME);
+
+
+--echo #
+--echo # Item::get_time_from_numeric
+--echo #
+SELECT CAST(SUM(0) AS TIME);
+SELECT CAST(SUM(0 + 0e0) AS TIME);
+SET timestamp=1322115328;
+SELECT CAST(UNIX_TIMESTAMP() AS TIME);
+SET timestamp=default;
+
+--echo #
+--echo # Item::get_time_from_non_temporal
+--echo #
+SELECT TIME(154559.616 + 0e0);
+
+--echo #
+--echo # Item_name_const::get_time
+--echo #
+SELECT TIME(NAME_CONST('a', 0));
+
+--echo #
+--echo # Item_cache_datetime::get_time
+--echo #
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (0);
+SELECT TIME(MIN(a)) FROM t1;
+DROP TABLE t1;
+
+--echo #
 --echo # End of 5.6 tests
 --echo #

=== modified file 'mysql-test/t/udf_skip_grants-master.opt'
--- a/mysql-test/t/udf_skip_grants-master.opt	2007-12-24 14:42:13 +0000
+++ b/mysql-test/t/udf_skip_grants-master.opt	2012-01-20 11:35:48 +0000
@@ -1 +1,2 @@
 --skip-grant-tables
+$UDF_EXAMPLE_LIB_OPT

=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2011-12-09 08:59:22 +0000
+++ b/mysql-test/t/view.test	2012-01-23 10:52:59 +0000
@@ -4227,6 +4227,18 @@ DROP VIEW t1;
 DROP TEMPORARY TABLE t1;
 
 
+--echo #
+--echo # Bug#13601606: FAILED VIEW CREATION ERROR MESSAGE (FOR DB NOT PRESENT) 
+--echo #               NEEDS BIG IMPROVEMENT 
+--echo #
+
+--disable_warnings
+DROP DATABASE IF EXISTS nodb;
+--enable_warnings
+--error ER_BAD_DB_ERROR
+CREATE VIEW nodb.a AS SELECT 1;
+
+
 # Check that all connections opened by test cases in this file are really
 # gone so execution of other tests won't be affected by their presence.
 --source include/wait_until_count_sessions.inc

=== modified file 'mysql-test/t/xa.test'
--- a/mysql-test/t/xa.test	2011-12-22 09:27:58 +0000
+++ b/mysql-test/t/xa.test	2012-01-20 10:07:05 +0000
@@ -364,7 +364,6 @@ let $wait_condition=
 --echo # Waiting until INSERT ... is blocked
 --source include/wait_condition.inc
 DELETE FROM t1;
-COMMIT;
 
 --echo # Connection con2
 --connection con2
@@ -373,6 +372,14 @@ COMMIT;
 --reap
 --error ER_XA_RBDEADLOCK
 XA COMMIT 'xid1';
+
+--echo # Connection default
+connection default;
+
+COMMIT;
+
+--echo # Connection con2
+connection con2;
 # This caused the assert to be triggered
 XA START 'xid1';
 

=== modified file 'mysys/charset-def.c'
--- a/mysys/charset-def.c	2011-06-30 15:50:45 +0000
+++ b/mysys/charset-def.c	2012-01-23 10:02:54 +0000
@@ -223,6 +223,7 @@ my_bool init_compiled_charsets(myf flags
 #ifdef HAVE_CHARSET_ucs2
   add_compiled_collation(&my_charset_ucs2_general_ci);
   add_compiled_collation(&my_charset_ucs2_bin);
+  add_compiled_collation(&my_charset_ucs2_general_mysql500_ci);
 #ifdef HAVE_UCA_COLLATIONS
   add_compiled_collation(&my_charset_ucs2_unicode_ci);
   add_compiled_collation(&my_charset_ucs2_german2_uca_ci);
@@ -259,6 +260,7 @@ my_bool init_compiled_charsets(myf flags
 #ifdef HAVE_CHARSET_utf8
   add_compiled_collation(&my_charset_utf8_general_ci);
   add_compiled_collation(&my_charset_utf8_bin);
+  add_compiled_collation(&my_charset_utf8_general_mysql500_ci);
 #ifdef HAVE_UTF8_GENERAL_CS
   add_compiled_collation(&my_charset_utf8_general_cs);
 #endif

=== modified file 'sql/debug_sync.cc'
--- a/sql/debug_sync.cc	2011-08-29 12:08:58 +0000
+++ b/sql/debug_sync.cc	2012-01-24 11:24:54 +0000
@@ -1737,7 +1737,7 @@ static void debug_sync_execute(THD *thd,
     if (action->wait_for.length())
     {
       mysql_mutex_t *old_mutex;
-      mysql_cond_t  *old_cond;
+      mysql_cond_t  *old_cond= 0;
       int             error= 0;
       struct timespec abstime;
 

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2012-01-26 12:23:27 +0000
+++ b/sql/handler.cc	2012-01-26 13:11:26 +0000
@@ -5041,7 +5041,9 @@ handler::multi_range_read_info_const(uin
   if (total_rows != HA_POS_ERROR)
   {
     /* The following calculation is the same as in multi_range_read_info(): */
-    *flags |= HA_MRR_USE_DEFAULT_IMPL;
+    *flags|= HA_MRR_USE_DEFAULT_IMPL;
+    *flags|= HA_MRR_SUPPORT_SORTED;
+
     DBUG_ASSERT(cost->is_zero());
     if ((*flags & HA_MRR_INDEX_ONLY) && total_rows > 2)
       cost->add_io(index_only_read_time(keyno, total_rows) *
@@ -5095,7 +5097,8 @@ ha_rows handler::multi_range_read_info(u
 {
   *bufsz= 0; /* Default implementation doesn't need a buffer */
 
-  *flags |= HA_MRR_USE_DEFAULT_IMPL;
+  *flags|= HA_MRR_USE_DEFAULT_IMPL;
+  *flags|= HA_MRR_SUPPORT_SORTED;
 
   DBUG_ASSERT(cost->is_zero());
 
@@ -5259,13 +5262,15 @@ int DsMrr_impl::dsmrr_init(handler *h_ar
   handler *new_h2= 0;
   int retval= 0;
   DBUG_ENTER("DsMrr_impl::dsmrr_init");
+  THD *thd= current_thd;
 
   /*
     index_merge may invoke a scan on an object for which dsmrr_info[_const]
     has not been called, so set the owner handler here as well.
   */
   h= h_arg;
-  if (mode & HA_MRR_USE_DEFAULT_IMPL || mode & HA_MRR_SORTED)
+  if (!thd->optimizer_switch_flag(OPTIMIZER_SWITCH_MRR) ||
+      mode & (HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED)) // DS-MRR doesn't sort
   {
     use_default_impl= TRUE;
     retval= h->handler::multi_range_read_init(seq_funcs, seq_init_param,
@@ -5315,7 +5320,6 @@ int DsMrr_impl::dsmrr_init(handler *h_ar
   if (!h2)
   {
     /* Create a separate handler object to do rndpos() calls. */
-    THD *thd= current_thd;
     /*
       ::clone() takes up a lot of stack, especially on 64 bit platforms.
       The constant 5 is an empiric result.
@@ -5595,6 +5599,7 @@ ha_rows DsMrr_impl::dsmrr_info(uint keyn
     DBUG_PRINT("info", ("Default MRR implementation choosen"));
     *flags= def_flags;
     *bufsz= def_bufsz;
+    DBUG_ASSERT(*flags & HA_MRR_USE_DEFAULT_IMPL);
   }
   else
   {
@@ -5638,6 +5643,7 @@ ha_rows DsMrr_impl::dsmrr_info_const(uin
     DBUG_PRINT("info", ("Default MRR implementation choosen"));
     *flags= def_flags;
     *bufsz= def_bufsz;
+    DBUG_ASSERT(*flags & HA_MRR_USE_DEFAULT_IMPL);
   }
   else
   {
@@ -5677,12 +5683,11 @@ bool DsMrr_impl::choose_mrr_impl(uint ke
   bool res;
   THD *thd= current_thd;
   if (!thd->optimizer_switch_flag(OPTIMIZER_SWITCH_MRR) ||
-      *flags & HA_MRR_INDEX_ONLY ||
+      *flags & (HA_MRR_INDEX_ONLY | HA_MRR_SORTED) || // Unsupported by DS-MRR
       (keyno == table->s->primary_key && h->primary_key_is_clustered()) ||
        key_uses_partial_cols(table, keyno))
   {
-    /* Use the default implementation */
-    *flags |= HA_MRR_USE_DEFAULT_IMPL;
+    /* Use the default implementation, don't modify args: See comments  */
     return TRUE;
   }
   
@@ -5706,7 +5711,7 @@ bool DsMrr_impl::choose_mrr_impl(uint ke
   if (force_dsmrr || (dsmrr_cost.total_cost() <= cost->total_cost()))
   {
     *flags &= ~HA_MRR_USE_DEFAULT_IMPL;  /* Use the DS-MRR implementation */
-    *flags &= ~HA_MRR_SORTED;          /* We will return unordered output */
+    *flags &= ~HA_MRR_SUPPORT_SORTED;    /* We can't provide ordered output */
     *cost= dsmrr_cost;
     res= FALSE;
   }

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2012-01-26 12:23:27 +0000
+++ b/sql/handler.h	2012-01-26 13:11:26 +0000
@@ -1361,6 +1361,10 @@ void get_sweep_read_cost(TABLE *table, h
 /* 
   The MRR user will provide ranges in key order, and MRR implementation
   must return rows in key order.
+  Passing this flag to multi_read_range_init() may cause the
+  default MRR handler to be used even if HA_MRR_USE_DEFAULT_IMPL
+  was not specified.
+  (If the native MRR impl. can not provide SORTED result)
 */
 #define HA_MRR_SORTED 8
 
@@ -1389,6 +1393,15 @@ void get_sweep_read_cost(TABLE *table, h
 */
 #define HA_MRR_NO_NULL_ENDPOINTS 128
 
+/*
+  Set by the MRR implementation to signal that it will natively
+  produced sorted result if multi_range_read_init() is called with
+  the HA_MRR_SORTED flag - Else multi_range_read_init(HA_MRR_SORTED)
+  will revert to use the default MRR implementation. 
+*/
+#define HA_MRR_SUPPORT_SORTED 256
+
+
 class ha_statistics
 {
 public:

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2012-01-17 15:43:31 +0000
+++ b/sql/item.cc	2012-01-26 10:08:12 +0000
@@ -8186,9 +8186,13 @@ void resolve_const_item(THD *thd, Item *
           or less than the original Item. A 0 may also be returned if 
           out of memory.          
 
-  @note We only use this on the range optimizer/partition pruning,
+  @note We use this in the range optimizer/partition pruning,
         because in some cases we can't store the value in the field
         without some precision/character loss.
+
+        We similarly use it to verify that expressions like
+        BIGINT_FIELD <cmp> <literal value>
+        is done correctly (as int/decimal/float according to literal type).
 */
 
 int stored_field_cmp_to_item(THD *thd, Field *field, Item *item)
@@ -8242,7 +8246,7 @@ int stored_field_cmp_to_item(THD *thd, F
 
       return my_time_compare(&field_time, &item_time);
     }
-    return stringcmp(field_result, item_result);
+    return sortcmp(field_result, item_result, field->charset());
   }
   if (res_type == INT_RESULT)
     return 0;					// Both are of type int
@@ -8254,12 +8258,17 @@ int stored_field_cmp_to_item(THD *thd, F
     if (item->null_value)
       return 0;
     field_val= field->val_decimal(&field_buf);
-    return my_decimal_cmp(item_val, field_val);
+    return my_decimal_cmp(field_val, item_val);
   }
-  double result= item->val_real();
+  /*
+    The patch for Bug#13463415 started using this function for comparing
+    BIGINTs. That uncovered a bug in Visual Studio 32bit optimized mode.
+    Prefixing the auto variables with volatile fixes the problem....
+  */
+  volatile double result= item->val_real();
   if (item->null_value)
     return 0;
-  double field_result= field->val_real();
+  volatile double field_result= field->val_real();
   if (field_result < result)
     return -1;
   else if (field_result > result)

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2012-01-16 09:01:53 +0000
+++ b/sql/item_cmpfunc.cc	2012-01-25 09:57:22 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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
@@ -451,35 +451,54 @@ static bool convert_constant_item(THD *t
       orig_field_val= field->val_int();
     if (!(*item)->is_null() && !(*item)->save_in_field(field, 1)) // TS-TODO
     {
-      Item *tmp= field->type() == MYSQL_TYPE_TIME ?
+      int field_cmp= 0;
+      /*
+        If item is a decimal value, we must reject it if it was truncated.
+        TODO: consider doing the same for MYSQL_TYPE_YEAR,.
+        However: we have tests which assume that things '1999' and
+        '1991-01-01 01:01:01' can be converted to year.
+        Testing for MYSQL_TYPE_YEAR here, would treat such literals
+        as 'incorrect DOUBLE value'.
+        See Bug#13580652 YEAR COLUMN CAN BE EQUAL TO 1999.1
+      */
+      if (field->type() == MYSQL_TYPE_LONGLONG)
+      {
+        field_cmp= stored_field_cmp_to_item(thd, field, *item);
+        DBUG_PRINT("info", ("convert_constant_item %d", field_cmp));
+      }
+
+      if (0 == field_cmp)
+      {
+        Item *tmp= field->type() == MYSQL_TYPE_TIME ?
 #define OLD_CMP
 #ifdef OLD_CMP
-                   new Item_time_with_ref(field->decimals(),
-                                          field->val_time_temporal(), *item) :
+          new Item_time_with_ref(field->decimals(),
+                                 field->val_time_temporal(), *item) :
 #else
-                   new Item_time_with_ref(max((*item)->time_precision(),
-                                              field->decimals()),
-                                          (*item)->val_time_temporal(),
-                                          *item) :
+          new Item_time_with_ref(max((*item)->time_precision(),
+                                     field->decimals()),
+                                 (*item)->val_time_temporal(),
+                                 *item) :
 #endif
-                 field->is_temporal_with_date() ?
+          field->is_temporal_with_date() ?
 #ifdef OLD_CMP
-                   new Item_datetime_with_ref(field->type(),
-                                               field->decimals(),
-                                               field->val_date_temporal(),
-                                               *item) :
+          new Item_datetime_with_ref(field->type(),
+                                     field->decimals(),
+                                     field->val_date_temporal(),
+                                     *item) :
 #else
-                   new Item_datetime_with_ref(field->type(),
-                                              max((*item)->datetime_precision(),
-                                                  field->decimals()),
-                                              (*item)->val_date_temporal(),
-                                              *item) :
+          new Item_datetime_with_ref(field->type(),
+                                     max((*item)->datetime_precision(),
+                                         field->decimals()),
+                                     (*item)->val_date_temporal(),
+                                     *item) :
 #endif
-                   new Item_int_with_ref(field->val_int(), *item,
-                                         test(field->flags & UNSIGNED_FLAG));
-      if (tmp)
-        thd->change_item_tree(item, tmp);
-      result= 1;					// Item was replaced
+          new Item_int_with_ref(field->val_int(), *item,
+                                test(field->flags & UNSIGNED_FLAG));
+        if (tmp)
+          thd->change_item_tree(item, tmp);
+        result= 1;                              // Item was replaced
+      }
     }
     /* Restore the original field value. */
     if (save_field_value)
@@ -509,6 +528,8 @@ void Item_bool_func2::fix_length_and_dec
   if (!args[0] || !args[1])
     return;
 
+  DBUG_ENTER("Item_bool_func2::fix_length_and_dec");
+
   /* 
     We allow to convert to Unicode character sets in some cases.
     The conditions when conversion is possible are:
@@ -526,7 +547,7 @@ void Item_bool_func2::fix_length_and_dec
   if (args[0]->result_type() == STRING_RESULT &&
       args[1]->result_type() == STRING_RESULT &&
       agg_arg_charsets_for_comparison(coll, args, 2))
-    return;
+    DBUG_VOID_RETURN;
     
   args[0]->cmp_context= args[1]->cmp_context=
     item_cmp_type(args[0]->result_type(), args[1]->result_type());
@@ -535,7 +556,7 @@ void Item_bool_func2::fix_length_and_dec
   if (functype() == LIKE_FUNC)  // Disable conversion in case of LIKE function.
   {
     set_cmp_func();
-    return;
+    DBUG_VOID_RETURN;
   }
 
   thd= current_thd;
@@ -553,7 +574,7 @@ void Item_bool_func2::fix_length_and_dec
           cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
                            INT_RESULT);		// Works for all types.
           args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
-          return;
+          DBUG_VOID_RETURN;
         }
       }
     }
@@ -569,12 +590,13 @@ void Item_bool_func2::fix_length_and_dec
           cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
                            INT_RESULT); // Works for all types.
           args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
-          return;
+          DBUG_VOID_RETURN;
         }
       }
     }
   }
   set_cmp_func();
+  DBUG_VOID_RETURN;
 }
 
 
@@ -2546,10 +2568,19 @@ void Item_func_between::fix_length_and_d
         The following can't be recoded with || as convert_constant_item
         changes the argument
       */
-      if (convert_constant_item(thd, field_item, &args[1]))
-        cmp_type=INT_RESULT;			// Works for all types.
-      if (convert_constant_item(thd, field_item, &args[2]))
-        cmp_type=INT_RESULT;			// Works for all types.
+      const bool cvt_arg1= convert_constant_item(thd, field_item, &args[1]);
+      const bool cvt_arg2= convert_constant_item(thd, field_item, &args[2]);
+      if (args[0]->is_temporal())
+      { // special handling of date/time etc.
+        if (cvt_arg1 || cvt_arg2)
+          cmp_type=INT_RESULT;
+      }
+      else
+      {
+        if (cvt_arg1 && cvt_arg2)
+          cmp_type=INT_RESULT;
+      }
+
       if (args[0]->is_temporal() &&
           args[1]->is_temporal() &&
           args[2]->is_temporal())

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2012-01-13 08:36:43 +0000
+++ b/sql/item_timefunc.cc	2012-01-24 11:57:25 +0000
@@ -3428,19 +3428,25 @@ null_date:
 
 bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
 {
-  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
-      (ltime->month == 0))
+  if ((null_value= get_arg0_date(ltime, fuzzy_date)))
+    return true;
+
+  if (ltime->month == 0)
   {
-    null_value= 1;
-    return 1;
+    /*
+      Cannot calculate last day for zero month.
+      Let's print a warning and return NULL.
+    */
+    ltime->time_type= MYSQL_TIMESTAMP_DATE;
+    ErrConvString str(ltime, 0);
+    make_truncated_value_warning(ErrConvString(str), MYSQL_TIMESTAMP_ERROR);
+    return (null_value= true);
   }
-  null_value= 0;
-  uint month_idx= ltime->month-1;
+
+  uint month_idx= ltime->month - 1;
   ltime->day= days_in_month[month_idx];
-  if ( month_idx == 1 && calc_days_in_year(ltime->year) == 366)
+  if (month_idx == 1 && calc_days_in_year(ltime->year) == 366)
     ltime->day= 29;
-  ltime->hour= ltime->minute= ltime->second= 0;
-  ltime->second_part= 0;
-  ltime->time_type= MYSQL_TIMESTAMP_DATE;
-  return 0;
+  datetime_to_date(ltime);
+  return false;
 }

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2012-01-17 09:39:54 +0000
+++ b/sql/mysqld.cc	2012-01-25 10:07:23 +0000
@@ -526,6 +526,11 @@ uint sync_binlog_period= 0, sync_relaylo
      sync_relayloginfo_period= 0, sync_masterinfo_period= 0,
      opt_mts_checkpoint_period, opt_mts_checkpoint_group;
 ulong expire_logs_days = 0;
+/**
+  Soft upper limit for number of sp_head objects that can be stored
+  in the sp_cache for one connection.
+*/
+ulong stored_program_cache_size= 0;
 
 const double log_10[] = {
   1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009,

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-12-16 15:53:16 +0000
+++ b/sql/mysqld.h	2012-01-25 10:07:23 +0000
@@ -201,6 +201,7 @@ extern const char *binlog_checksum_type_
 extern my_bool opt_master_verify_checksum;
 extern my_bool opt_slave_sql_verify_checksum;
 extern ulong thread_cache_size;
+extern ulong stored_program_cache_size;
 extern ulong back_log;
 extern char language[FN_REFLEN];
 extern "C" MYSQL_PLUGIN_IMPORT ulong server_id;

=== modified file 'sql/opt_explain.cc'
--- a/sql/opt_explain.cc	2011-12-14 12:32:55 +0000
+++ b/sql/opt_explain.cc	2012-01-26 12:53:38 +0000
@@ -770,24 +770,25 @@ void Explain_table_base::explain_extra_c
   if (table->reginfo.not_exists_optimize)
     str_extra->append(STRING_WITH_LEN("; Not exists"));
 
-  if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE &&
-      !(((QUICK_RANGE_SELECT*)(select->quick))->mrr_flags &
-       (HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED)))
+  if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE)
   {
+    uint mrr_flags=
+      ((QUICK_RANGE_SELECT*)(select->quick))->mrr_flags;
+
     /*
       During normal execution of a query, multi_range_read_init() is
       called to initialize MRR. If HA_MRR_SORTED is set at this point,
       multi_range_read_init() for any native MRR implementation will
-      revert to default MRR because they cannot produce sorted output
-      currently.
+      revert to default MRR if not HA_MRR_SUPPORT_SORTED.
       Calling multi_range_read_init() can potentially be costly, so it
-      is not done when executing an EXPLAIN. We therefore make the
-      assumption that HA_MRR_SORTED means no MRR. If some MRR native
-      implementation will support sorted output in the future, a
-      function "bool mrr_supports_sorted()" should be added in the
-      handler.
+      is not done when executing an EXPLAIN. We therefore simulate
+      its effect here:
     */
-    str_extra->append(STRING_WITH_LEN("; Using MRR"));
+    if (mrr_flags & HA_MRR_SORTED && !(mrr_flags & HA_MRR_SUPPORT_SORTED))
+      mrr_flags|= HA_MRR_USE_DEFAULT_IMPL;
+
+    if (!(mrr_flags & HA_MRR_USE_DEFAULT_IMPL))
+      str_extra->append(STRING_WITH_LEN("; Using MRR"));
   }
 }
 

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2012-01-12 13:22:52 +0000
+++ b/sql/opt_range.cc	2012-01-26 12:53:38 +0000
@@ -1342,7 +1342,6 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT(
     if (file) 
     {
       range_end();
-      head->set_keyread(FALSE);
       if (free_file)
       {
         DBUG_PRINT("info", ("Freeing separate handler %p (free: %d)", file,
@@ -2569,7 +2568,7 @@ int SQL_SELECT::test_quick_select(THD *t
     param.imerge_cost_buff_size= 0;
     param.using_real_indexes= TRUE;
     param.remove_jump_scans= TRUE;
-    param.force_default_mrr= (interesting_order != ORDER::ORDER_NOT_RELEVANT);
+    param.force_default_mrr= (interesting_order == ORDER::ORDER_DESC);
     param.order_direction= interesting_order;
 
     thd->no_errors=1;				// Don't warn about NULL
@@ -5563,7 +5562,7 @@ QUICK_SELECT_I *TRP_ROR_INTERSECT::make_
     {
       if (!(quick= get_quick_select(param, (*current)->idx,
                                     (*current)->sel_arg,
-                                    HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED,
+                                    HA_MRR_SORTED,
                                     0, alloc)) ||
           quick_intrsect->push_quick_back(quick))
       {
@@ -5575,7 +5574,7 @@ QUICK_SELECT_I *TRP_ROR_INTERSECT::make_
     {
       if (!(quick= get_quick_select(param, cpk_scan->idx,
                                     cpk_scan->sel_arg,
-                                    HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED,
+                                    HA_MRR_SORTED,
                                     0, alloc)))
       {
         delete quick_intrsect;
@@ -6465,10 +6464,24 @@ get_mm_leaf(RANGE_OPT_PARAM *param, Item
       (field->type() == MYSQL_TYPE_DATE ||
        field->type() == MYSQL_TYPE_DATETIME))
     field->table->in_use->variables.sql_mode|= MODE_INVALID_DATES;
-  {
-    // Note that value may be a stored function call, executed here.
-    err= value->save_in_field_no_warnings(field, 1);
-  }
+
+  /*
+    We want to change "field > value" to "field OP V"
+    where:
+    * V is what is in "field" after we stored "value" in it via
+    save_in_field_no_warning() (such store operation may have done
+    rounding...)
+    * OP is > or >=, depending on what's correct.
+    For example, if c is an INT column,
+    "c > 2.9" is changed to "c OP 3"
+    where OP is ">=" (">" would not be correct, as 3 > 2.9, a comparison
+    done with stored_field_cmp_to_item()). And
+    "c > 3.1" is changed to "c OP 3" where OP is ">" (3 < 3.1...).
+  */
+
+  // Note that value may be a stored function call, executed here.
+  err= value->save_in_field_no_warnings(field, 1);
+
   if (err > 0)
   {
     if (field->cmp_type() != value->result_type())
@@ -8692,10 +8705,12 @@ ha_rows check_quick_select(PARAM *param,
     param->is_ror_scan= FALSE;
   
   *mrr_flags= param->force_default_mrr? HA_MRR_USE_DEFAULT_IMPL: 0;
+  *mrr_flags|= HA_MRR_NO_ASSOCIATION;
   /*
     Pass HA_MRR_SORTED to see if MRR implementation can handle sorting.
   */
-  *mrr_flags|= HA_MRR_NO_ASSOCIATION | HA_MRR_SORTED;
+  if (param->order_direction != ORDER::ORDER_NOT_RELEVANT)
+    *mrr_flags|= HA_MRR_SORTED;
 
   bool pk_is_clustered= file->primary_key_is_clustered();
   if (index_only && 
@@ -8704,7 +8719,7 @@ ha_rows check_quick_select(PARAM *param,
      *mrr_flags |= HA_MRR_INDEX_ONLY;
   
   if (current_thd->lex->sql_command != SQLCOM_SELECT)
-    *mrr_flags |= HA_MRR_USE_DEFAULT_IMPL;
+    *mrr_flags|= HA_MRR_SORTED; // Assumed to give faster ins/upd/del
 
   *bufsize= param->thd->variables.read_rnd_buff_size;
   // Sets is_ror_scan to false for some queries, e.g. multi-ranges
@@ -9229,7 +9244,7 @@ QUICK_RANGE_SELECT *get_quick_select_for
   quick->mrr_flags= HA_MRR_NO_ASSOCIATION | 
                     (table->key_read ? HA_MRR_INDEX_ONLY : 0);
   if (thd->lex->sql_command != SQLCOM_SELECT)
-    quick->mrr_flags |= HA_MRR_USE_DEFAULT_IMPL;
+    quick->mrr_flags|= HA_MRR_SORTED; // Assumed to give faster ins/upd/del
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
   if (!ref->null_ref_key && !key_has_nulls(key_info, range->min_key,
                                            ref->key_length))
@@ -10916,7 +10931,7 @@ get_best_group_min_max(PARAM *param, SEL
                                            &cur_param_idx);
       /* Check if this range tree can be used for prefix retrieval. */
       Cost_estimate dummy_cost;
-      uint mrr_flags= HA_MRR_USE_DEFAULT_IMPL;
+      uint mrr_flags= HA_MRR_SORTED;
       uint mrr_bufsize=0;
       cur_quick_prefix_records= check_quick_select(param, cur_param_idx, 
                                                    FALSE /*don't care*/, 
@@ -11551,7 +11566,6 @@ TRP_GROUP_MIN_MAX::make_quick(PARAM *par
       /* Make a QUICK_RANGE_SELECT to be used for group prefix retrieval. */
       quick->quick_prefix_select= get_quick_select(param, param_idx,
                                                    index_tree,
-                                                   HA_MRR_USE_DEFAULT_IMPL |
                                                    HA_MRR_SORTED,
                                                    0,
                                                    &quick->alloc);

=== modified file 'sql/records.cc'
--- a/sql/records.cc	2011-12-14 12:32:55 +0000
+++ b/sql/records.cc	2012-01-25 12:45:56 +0000
@@ -325,6 +325,10 @@ void end_read_record(READ_RECORD *info)
     my_free_lock(info->cache);
     info->cache=0;
   }
+  if (info->table && info->table->key_read)
+  {
+    info->table->set_keyread(FALSE);
+  }
   if (info->table && info->table->created)
   {
     filesort_free_buffers(info->table,0);

=== modified file 'sql/rpl_master.cc'
--- a/sql/rpl_master.cc	2012-01-17 22:32:29 +0000
+++ b/sql/rpl_master.cc	2012-01-22 17:00:21 +0000
@@ -629,7 +629,6 @@ void mysql_binlog_send(THD* thd, char* l
   String* packet = &thd->packet;
   int error;
   const char *errmsg = "Unknown error";
-  char llbuff0[22], llbuff1[22], llbuff2[22];
   char error_text[MAX_SLAVE_ERRMSG]; // to be send to slave via my_message()
   NET* net = &thd->net;
   mysql_mutex_t *log_lock;
@@ -1275,12 +1274,14 @@ err:
        detailing the fatal error message with coordinates 
        of the last position read.
     */
-    const char *fmt= "%s; the start event position from '%s' at %s, the last event was read from '%s' at %s, the last byte read was read from '%s' at %s.";
-    my_snprintf(error_text, sizeof(error_text), fmt, errmsg,
-                p_start_coord->file_name,
-                (llstr(p_start_coord->pos, llbuff0), llbuff0),
-                p_coord->file_name, (llstr(p_coord->pos, llbuff1), llbuff1),
-                log_file_name,    (llstr(my_b_tell(&log), llbuff2), llbuff2));
+    my_snprintf(error_text, sizeof(error_text),
+                "%s; the first event '%s' at %lld, "
+                "the last event read from '%s' at %lld, "
+                "the last byte read from '%s' at %lld.",
+                errmsg,
+                p_start_coord->file_name, p_start_coord->pos,
+                p_coord->file_name, p_coord->pos,
+                log_file_name, my_b_tell(&log));
   }
   else
     strcpy(error_text, errmsg);

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2012-01-19 09:57:36 +0000
+++ b/sql/share/errmsg-utf8.txt	2012-01-26 13:11:26 +0000
@@ -4701,14 +4701,14 @@ ER_NOT_SUPPORTED_YET 42000
         spa "Esta versión de MySQL no soporta todavia '%s'"
         swe "Denna version av MySQL kan ännu inte utföra '%s'"
 ER_MASTER_FATAL_ERROR_READING_BINLOG  
-        nla "Kreeg fatale fout %d: '%-.512s' van master tijdens lezen van data uit binaire log"
-        eng "Got fatal error %d from master when reading data from binary log: '%-.512s'"
-        ger "Schwerer Fehler %d: '%-.512s vom Master beim Lesen des binären Logs"
-        ita "Errore fatale %d: '%-.512s' dal master leggendo i dati dal log binario"
-        por "Obteve fatal erro %d: '%-.512s' do master quando lendo dados do binary log"
-        rus "Получена неисправимарвера в процессе выборки данныecibió fatal error %d: '%-.512s' del master cuando leyendo datos del binary log"
-        swe "Fick fatalt fel %d: '%-.512s' från master vid läsning av binärloggen"
+        nla "Kreeg fatale fout %d: '%-.320s' van master tijdens lezen van data uit binaire log"
+        eng "Got fatal error %d from master when reading data from binary log: '%-.320s'"
+        ger "Schwerer Fehler %d: '%-.320s vom Master beim Lesen des binären Logs"
+        ita "Errore fatale %d: '%-.320s' dal master leggendo i dati dal log binario"
+        por "Obteve fatal erro %d: '%-.320s' do master quando lendo dados do binary log"
+        rus "Получена неисправимая ошибк процессе выборки данных из двоичного журнала"
+        spa "Recibió fatal error %d: '%-.320s' del master cuando leyendo datos del binary log"
+        swe "Fick fatalt fel %d: '%-.320s' från master vid läsning av binärloggen"
 ER_SLAVE_IGNORED_TABLE  
         eng "Slave SQL thread ignored the query because of replicate-*-table rules"
         ger "Slave-SQL-Thread hat die Abfrage aufgrund von replicate-*-table-Regeln ignoriert"

=== modified file 'sql/sp_cache.cc'
--- a/sql/sp_cache.cc	2011-06-30 15:50:45 +0000
+++ b/sql/sp_cache.cc	2012-01-25 10:07:23 +0000
@@ -54,6 +54,20 @@ public:
   {
     my_hash_delete(&m_hashtable, (uchar *)sp);
   }
+
+  /**
+    Remove all elements from a stored routine cache if the current
+    number of elements exceeds the argument value.
+
+    @param[in] upper_limit_for_elements  Soft upper limit of elements that
+                                         can be stored in the cache.
+  */
+  void enforce_limit(ulong upper_limit_for_elements)
+  {
+    if (m_hashtable.records > upper_limit_for_elements)
+      my_hash_reset(&m_hashtable);
+  }
+
 private:
   void init();
   void cleanup();
@@ -222,6 +236,21 @@ ulong sp_cache_version()
 }
 
 
+/**
+  Enforce that the current number of elements in the cache don't exceed
+  the argument value by flushing the cache if necessary.
+
+  @param[in] c  Cache to check
+  @param[in] upper_limit_for_elements  Soft upper limit for number of sp_head
+                                       objects that can be stored in the cache.
+*/
+void
+sp_cache_enforce_limit(sp_cache *c, ulong upper_limit_for_elements)
+{
+ if (c)
+   c->enforce_limit(upper_limit_for_elements);
+}
+
 /*************************************************************************
   Internal functions 
  *************************************************************************/

=== modified file 'sql/sp_cache.h'
--- a/sql/sp_cache.h	2011-06-30 15:50:45 +0000
+++ b/sql/sp_cache.h	2012-01-25 10:07:23 +0000
@@ -58,5 +58,6 @@ sp_head *sp_cache_lookup(sp_cache **cp,
 void sp_cache_invalidate();
 void sp_cache_flush_obsolete(sp_cache **cp, sp_head **sp);
 ulong sp_cache_version();
+void sp_cache_enforce_limit(sp_cache *cp, ulong upper_limit_for_elements);
 
 #endif /* _SP_CACHE_H_ */

=== modified file 'sql/sql_executor.cc'
--- a/sql/sql_executor.cc	2012-01-17 15:43:31 +0000
+++ b/sql/sql_executor.cc	2012-01-25 08:46:00 +0000
@@ -798,9 +798,7 @@ JOIN::create_intermediate_table(List<Ite
         prepare_sum_aggregators(sum_funcs,
                                 !join_tab->is_using_agg_loose_index_scan()) ||
         setup_sum_funcs(thd, sum_funcs))
-    {
-      DBUG_RETURN(NULL);
-    }
+      goto err;
     group_list= NULL;
   }
   else
@@ -809,9 +807,7 @@ JOIN::create_intermediate_table(List<Ite
         prepare_sum_aggregators(sum_funcs,
                                 !join_tab->is_using_agg_loose_index_scan()) ||
         setup_sum_funcs(thd, sum_funcs))
-    {
-      DBUG_RETURN(NULL);
-    }
+      goto err;
 
     if (!group_list && !tab->distinct && order && simple_order)
     {
@@ -819,13 +815,16 @@ JOIN::create_intermediate_table(List<Ite
       THD_STAGE_INFO(thd, stage_sorting_for_order);
       if (create_sort_index(thd, this, order,
                             HA_POS_ERROR, HA_POS_ERROR, true))
-      {
-        DBUG_RETURN(NULL);
-      }
+        goto err;
       order= NULL;
     }
   }
   DBUG_RETURN(tab);
+
+err:
+  if (tab != NULL)
+    free_tmp_table(thd, tab);
+  DBUG_RETURN(NULL);
 }
 
 

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2012-01-16 10:32:15 +0000
+++ b/sql/sql_lex.cc	2012-01-26 13:11:26 +0000
@@ -2450,6 +2450,20 @@ void TABLE_LIST::print(THD *thd, String
         append_identifier(thd, str, table_name, table_name_length);
         cmp_name= table_name;
       }
+      if (partition_names && partition_names->elements)
+      {
+        int i, num_parts= partition_names->elements;
+        List_iterator<String> name_it(*(partition_names));
+        str->append(STRING_WITH_LEN(" PARTITION ("));
+        for (i= 1; i <= num_parts; i++)
+        {
+          String *name= name_it++;
+          append_identifier(thd, str, name->c_ptr(), name->length());
+          if (i != num_parts)
+            str->append(',');
+        }
+        str->append(')');
+      }
     }
     if (my_strcasecmp(table_alias_charset, cmp_name, alias))
     {

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2012-01-17 09:27:34 +0000
+++ b/sql/sql_parse.cc	2012-01-25 10:07:23 +0000
@@ -5904,6 +5904,8 @@ void mysql_parse(THD *thd, char *rawbuf,
       query_cache_abort(&thd->query_cache_tls);
     }
     THD_STAGE_INFO(thd, stage_freeing_items);
+    sp_cache_enforce_limit(thd->sp_proc_cache, stored_program_cache_size);
+    sp_cache_enforce_limit(thd->sp_func_cache, stored_program_cache_size);
     thd->end_statement();
     thd->cleanup_after_query();
     DBUG_ASSERT(thd->change_list.is_empty());

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2011-12-09 08:59:22 +0000
+++ b/sql/sql_prepare.cc	2012-01-25 10:07:23 +0000
@@ -2246,6 +2246,9 @@ void mysqld_stmt_prepare(THD *thd, const
 
   thd->protocol= save_protocol;
 
+  sp_cache_enforce_limit(thd->sp_proc_cache, stored_program_cache_size);
+  sp_cache_enforce_limit(thd->sp_func_cache, stored_program_cache_size);
+
   /* check_prepared_statemnt sends the metadata packet in case of success */
   DBUG_VOID_RETURN;
 }
@@ -2619,6 +2622,9 @@ void mysqld_stmt_execute(THD *thd, char
   stmt->execute_loop(&expanded_query, open_cursor, packet, packet_end);
   thd->protocol= save_protocol;
 
+  sp_cache_enforce_limit(thd->sp_proc_cache, stored_program_cache_size);
+  sp_cache_enforce_limit(thd->sp_func_cache, stored_program_cache_size);
+
   /* Close connection socket; for use with client testing (Bug#43560). */
   DBUG_EXECUTE_IF("close_conn_after_stmt_execute", vio_close(thd->net.vio););
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2012-01-17 09:27:34 +0000
+++ b/sql/sql_select.cc	2012-01-25 14:52:00 +0000
@@ -3565,6 +3565,38 @@ is_subkey(KEY_PART_INFO *key_part, KEY_P
 }
 
 /**
+  Test if REF_OR_NULL optimization will be used if the specified
+  ref_key is used for REF-access to 'tab'
+
+  @retval
+    true	JT_REF_OR_NULL will be used
+  @retval
+    false	no JT_REF_OR_NULL access
+*/
+bool
+is_ref_or_null_optimized(const JOIN_TAB *tab, uint ref_key)
+{
+  if (tab->keyuse)
+  {
+    const Key_use *keyuse= tab->keyuse;
+    while (keyuse->key != ref_key && keyuse->table == tab->table)
+      keyuse++;
+
+    const table_map const_tables= tab->join->const_table_map;
+    do
+    {
+      if (!(keyuse->used_tables & ~const_tables))
+      {
+        if (keyuse->optimize & KEY_OPTIMIZE_REF_OR_NULL)
+          return true;
+      }
+      keyuse++;
+    } while (keyuse->key == ref_key && keyuse->table == tab->table);
+  }
+  return false;
+}
+
+/**
   Test if we can use one of the 'usable_keys' instead of 'ref' key
   for sorting.
 
@@ -3577,12 +3609,13 @@ is_subkey(KEY_PART_INFO *key_part, KEY_P
 */
 
 static uint
-test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts,
+test_if_subkey(ORDER *order, JOIN_TAB *tab, uint ref, uint ref_key_parts,
 	       const key_map *usable_keys)
 {
   uint nr;
   uint min_length= (uint) ~0;
   uint best= MAX_KEY;
+  TABLE *table= tab->table;
   KEY_PART_INFO *ref_key_part= table->key_info[ref].key_part;
   KEY_PART_INFO *ref_key_part_end= ref_key_part + ref_key_parts;
 
@@ -3593,6 +3626,7 @@ test_if_subkey(ORDER *order, TABLE *tabl
 	table->key_info[nr].key_parts >= ref_key_parts &&
 	is_subkey(table->key_info[nr].key_part, ref_key_part,
 		  ref_key_part_end) &&
+        !is_ref_or_null_optimized(tab, nr) &&
 	test_if_order_by_key(order, table, nr))
     {
       min_length= table->key_info[nr].key_length;
@@ -3620,6 +3654,9 @@ public:
   */
   Plan_change_watchdog(const JOIN_TAB *tab_arg, bool no_changes_arg)
   {
+    // Only to keep gcc 4.1.2-44 silent about uninitialized variables
+    quick= NULL;
+    quick_index= 0;
     if (no_changes_arg)
     {
       tab= tab_arg;
@@ -3633,7 +3670,14 @@ public:
       index= tab->index;
     }
     else
+    {
       tab= NULL;
+      // Only to keep gcc 4.1.2-44 silent about uninitialized variables
+      type= JT_UNKNOWN;
+      select= NULL;
+      ref_key= ref_key_parts= index= 0;
+      use_quick= QS_NONE;
+    }
   }
   ~Plan_change_watchdog()
   {
@@ -3722,6 +3766,14 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
 
   Plan_change_watchdog watchdog(tab, no_changes);
 
+  /* Sorting a single row can always be skipped */
+  if (tab->type == JT_EQ_REF ||
+      tab->type == JT_CONST  ||
+      tab->type == JT_SYSTEM)
+  {
+    DBUG_RETURN(1);
+  }
+
   /*
     Keys disabled by ALTER TABLE ... DISABLE KEYS should have already
     been taken into account.
@@ -3803,7 +3855,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
       if (table->covering_keys.is_set(ref_key))
 	usable_keys.intersect(table->covering_keys);
 
-      if ((new_ref_key= test_if_subkey(order, table, ref_key, ref_key_parts,
+      if ((new_ref_key= test_if_subkey(order, tab, ref_key, ref_key_parts,
 				       &usable_keys)) < MAX_KEY)
       {
 	/* Found key that can be used to retrieve data in sorted order */
@@ -3825,6 +3877,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
                                  tab->join->const_table_map))
             goto use_filesort;
 
+          DBUG_ASSERT(tab->type != JT_REF_OR_NULL && tab->type != JT_FT);
           pick_table_access_method(tab);
 	}
 	else
@@ -3966,11 +4019,16 @@ check_reverse_order:
         (select && select->quick && select->quick!=save_quick);
 
       /* 
-         If ref_key used index tree reading only ('Using index' in EXPLAIN),
-         and best_key doesn't, then revert the decision.
+         If 'best_key' has changed from  prev. 'ref_key':
+         Update strategy for using index tree reading only
+         ('Using index' in EXPLAIN)
       */
-      if (!table->covering_keys.is_set(best_key))
-        table->set_keyread(FALSE);
+      if (best_key != ref_key)
+      {
+        const bool using_index= 
+          (table->covering_keys.is_set(best_key) && !table->no_keyread);
+        table->set_keyread(using_index);
+      }
       if (!quick_created)
       {
         if (select)                  // Throw any existing quick select
@@ -3981,8 +4039,6 @@ check_reverse_order:
                                 join_read_first:join_read_last;
         tab->type=JT_INDEX_SCAN;       // Read with index_first(), index_next()
 
-        if (table->covering_keys.is_set(best_key))
-          table->set_keyread(TRUE);
         table->file->ha_index_or_rnd_end();
         if (tab->join->select_options & SELECT_DESCRIBE)
         {
@@ -4000,6 +4056,7 @@ check_reverse_order:
           method is actually used.
         */
         DBUG_ASSERT(tab->select->quick);
+        DBUG_ASSERT(tab->select->quick->index==(uint)best_key);
         tab->type=JT_ALL;
         tab->use_quick=QS_RANGE;
         tab->ref.key= -1;

=== modified file 'sql/sql_tmp_table.cc'
--- a/sql/sql_tmp_table.cc	2012-01-12 10:21:25 +0000
+++ b/sql/sql_tmp_table.cc	2012-01-25 08:46:00 +0000
@@ -20,6 +20,7 @@
 #include "sql_executor.h"
 #include "sql_base.h"
 #include "opt_trace.h"
+#include "debug_sync.h"
 
 #include <algorithm>
 using std::max;
@@ -1133,6 +1134,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
 
   thd->mem_root= mem_root_save;
 
+  DEBUG_SYNC(thd, "tmp_table_created");
+
   DBUG_RETURN(table);
 
 err:

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2011-12-19 11:42:11 +0000
+++ b/sql/sql_view.cc	2012-01-23 10:52:59 +0000
@@ -455,6 +455,16 @@ bool mysql_create_view(THD *thd, TABLE_L
     goto err;
   }
 
+  /*
+    Checking the existence of the database in which the view is to be created
+  */
+  if (check_db_dir_existence(view->db))
+  {
+    my_error(ER_BAD_DB_ERROR, MYF(0), view->db);
+    res= TRUE;
+    goto err;
+  }
+
   view= lex->unlink_first_table(&link_to_local);
 
   if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view))

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2011-12-19 18:05:58 +0000
+++ b/sql/sys_vars.cc	2012-01-25 10:07:23 +0000
@@ -3767,3 +3767,10 @@ static Sys_var_charptr Sys_ignore_db_dir
        READ_ONLY GLOBAL_VAR(opt_ignore_db_dirs), 
        NO_CMD_LINE,
        IN_FS_CHARSET, DEFAULT(0));
+
+static Sys_var_ulong Sys_sp_cache_size(
+       "stored_program_cache",
+       "The soft upper limit for number of cached stored routines for "
+       "one connection.",
+       GLOBAL_VAR(stored_program_cache_size), CMD_LINE(REQUIRED_ARG),
+       VALID_RANGE(256, 512 * 1024), DEFAULT(256), BLOCK_SIZE(1));

=== modified file 'storage/example/ha_example.cc'
--- a/storage/example/ha_example.cc	2011-11-01 11:52:24 +0000
+++ b/storage/example/ha_example.cc	2012-01-26 09:29:33 +0000
@@ -554,7 +554,7 @@ int ha_example::index_last(uchar *buf)
 int ha_example::rnd_init(bool scan)
 {
   DBUG_ENTER("ha_example::rnd_init");
-  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
+  DBUG_RETURN(0);
 }
 
 int ha_example::rnd_end()

=== modified file 'storage/innobase/btr/btr0btr.cc'
--- a/storage/innobase/btr/btr0btr.cc	2011-11-20 20:17:41 +0000
+++ b/storage/innobase/btr/btr0btr.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -43,6 +43,27 @@ Created 6/2/1994 Heikki Tuuri
 #include "trx0trx.h"
 #include "srv0mon.h"
 
+/**************************************************************//**
+Report that an index page is corrupted. */
+UNIV_INTERN
+void
+btr_corruption_report(
+/*==================*/
+	const buf_block_t*	block,	/*!< in: corrupted block */
+	const dict_index_t*	index)	/*!< in: index tree */
+{
+	fprintf(stderr, "InnoDB: flag mismatch in space %u page %u"
+		" index %s of table %s\n",
+		(unsigned) buf_block_get_space(block),
+		(unsigned) buf_block_get_page_no(block),
+		index->name, index->table_name);
+	buf_page_print(buf_block_get_frame(block), 0);
+	if (block->page.zip.data) {
+		buf_page_print(block->page.zip.data,
+			       buf_block_get_zip_size(block));
+	}
+}
+
 #ifdef UNIV_BLOB_DEBUG
 # include "srv0srv.h"
 # include "ut0rbt.h"
@@ -693,8 +714,7 @@ btr_root_block_get(
 
 	block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH,
 			      index, mtr);
-	ut_a((ibool)!!page_is_comp(buf_block_get_frame(block))
-	     == dict_table_is_comp(index->table));
+	btr_assert_not_corrupted(block, index);
 #ifdef UNIV_BTR_DEBUG
 	if (!dict_index_is_ibuf(index)) {
 		const page_t*	root = buf_block_get_frame(block);
@@ -1717,7 +1737,7 @@ btr_page_reorganize_low(
 	ibool		success		= FALSE;
 
 	ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
-	ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table));
+	btr_assert_not_corrupted(block, index);
 #ifdef UNIV_ZIP_DEBUG
 	ut_a(!page_zip || page_zip_validate(page_zip, page));
 #endif /* UNIV_ZIP_DEBUG */
@@ -3347,7 +3367,7 @@ btr_compress(
 	page = btr_cur_get_page(cursor);
 	index = btr_cur_get_index(cursor);
 
-	ut_a((ibool) !!page_is_comp(page) == dict_table_is_comp(index->table));
+	btr_assert_not_corrupted(block, index);
 
 	ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
 				MTR_MEMO_X_LOCK));

=== modified file 'storage/innobase/btr/btr0cur.cc'
--- a/storage/innobase/btr/btr0cur.cc	2011-11-30 10:09:12 +0000
+++ b/storage/innobase/btr/btr0cur.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -413,7 +413,13 @@ btr_cur_search_to_nth_level(
 	ut_ad(dict_index_check_search_tuple(index, tuple));
 	ut_ad(!dict_index_is_ibuf(index) || ibuf_inside(mtr));
 	ut_ad(dtuple_check_typed(tuple));
+	ut_ad(!(index->type & DICT_FTS));
+	ut_ad(index->page != FIL_NULL);
 
+	UNIV_MEM_INVALID(&cursor->up_match, sizeof cursor->up_match);
+	UNIV_MEM_INVALID(&cursor->up_bytes, sizeof cursor->up_bytes);
+	UNIV_MEM_INVALID(&cursor->low_match, sizeof cursor->low_match);
+	UNIV_MEM_INVALID(&cursor->low_bytes, sizeof cursor->low_bytes);
 #ifdef UNIV_DEBUG
 	cursor->up_match = ULINT_UNDEFINED;
 	cursor->low_match = ULINT_UNDEFINED;
@@ -762,11 +768,11 @@ retry_page_get:
 
 	if (level != 0) {
 		/* x-latch the page */
-		page = btr_page_get(
+		buf_block_t*	child_block = btr_block_get(
 			space, zip_size, page_no, RW_X_LATCH, index, mtr);
 
-		ut_a((ibool)!!page_is_comp(page)
-		     == dict_table_is_comp(index->table));
+		page = buf_block_get_frame(child_block);
+		btr_assert_not_corrupted(child_block, index);
 	} else {
 		cursor->low_match = low_match;
 		cursor->low_bytes = low_bytes;

=== modified file 'storage/innobase/buf/buf0buf.cc'
--- a/storage/innobase/buf/buf0buf.cc	2012-01-16 08:15:20 +0000
+++ b/storage/innobase/buf/buf0buf.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -690,6 +690,8 @@ buf_page_print(
 #endif /* !UNIV_HOTBACKUP */
 	ulint		size = zip_size;
 
+	ut_ad(0);
+
 	if (!size) {
 		size = UNIV_PAGE_SIZE;
 	}

=== modified file 'storage/innobase/buf/buf0dblwr.cc'
--- a/storage/innobase/buf/buf0dblwr.cc	2011-12-23 13:17:36 +0000
+++ b/storage/innobase/buf/buf0dblwr.cc	2012-01-25 15:07:48 +0000
@@ -618,28 +618,6 @@ buf_dblwr_update(void)
 }
 
 /********************************************************************//**
-Flush a batch of writes to the datafiles that have already been
-written by the OS. */
-static
-void
-buf_dblwr_sync_datafiles(void)
-/*==========================*/
-{
-	/* Wake possible simulated aio thread to actually post the
-	writes to the operating system */
-	os_aio_simulated_wake_handler_threads();
-
-	/* Wait that all async writes to tablespaces have been posted to
-	the OS */
-	os_aio_wait_until_no_pending_writes();
-
-	/* Now we flush the data to disk (for example, with fsync) */
-	fil_flush_file_spaces(FIL_TABLESPACE);
-
-	return;
-}
-
-/********************************************************************//**
 Check the LSN values on the page. */
 static
 void
@@ -780,7 +758,7 @@ buf_dblwr_flush_buffered_writes(void)
 
 	if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
 		/* Sync the writes to the disk. */
-		buf_dblwr_sync_datafiles();
+		buf_flush_sync_datafiles();
 		return;
 	}
 
@@ -1094,7 +1072,7 @@ retry:
 	buf_dblwr_write_block_to_datafile((buf_block_t*) bpage);
 
 	/* Sync the writes to the disk. */
-	buf_dblwr_sync_datafiles();
+	buf_flush_sync_datafiles();
 
 	mutex_enter(&buf_dblwr->mutex);
 

=== modified file 'storage/innobase/buf/buf0flu.cc'
--- a/storage/innobase/buf/buf0flu.cc	2011-12-23 13:17:36 +0000
+++ b/storage/innobase/buf/buf0flu.cc	2012-01-25 15:07:48 +0000
@@ -822,6 +822,28 @@ buf_flush_init_for_writing(
 
 #ifndef UNIV_HOTBACKUP
 /********************************************************************//**
+Flush a batch of writes to the datafiles that have already been
+written by the OS. */
+UNIV_INTERN
+void
+buf_flush_sync_datafiles(void)
+/*==========================*/
+{
+	/* Wake possible simulated aio thread to actually post the
+	writes to the operating system */
+	os_aio_simulated_wake_handler_threads();
+
+	/* Wait that all async writes to tablespaces have been posted to
+	the OS */
+	os_aio_wait_until_no_pending_writes();
+
+	/* Now we flush the data to disk (for example, with fsync) */
+	fil_flush_file_spaces(FIL_TABLESPACE);
+
+	return;
+}
+
+/********************************************************************//**
 Does an asynchronous write of a buffer page. NOTE: in simulated aio and
 also when the doublewrite buffer is used, we must call
 buf_dblwr_flush_buffered_writes after we have posted a batch of
@@ -1063,6 +1085,7 @@ buf_flush_page_try(
 	/* The following call will release the buffer pool and
 	block mutex. */
 	buf_flush_page(buf_pool, &block->page, BUF_FLUSH_SINGLE_PAGE);
+	buf_flush_sync_datafiles();
 	return(TRUE);
 }
 # endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
@@ -1892,6 +1915,8 @@ buf_flush_single_page_from_LRU(
 	block mutex. */
 	buf_flush_page(buf_pool, bpage, BUF_FLUSH_SINGLE_PAGE);
 
+	buf_flush_sync_datafiles();
+
 	/* At this point the page has been written to the disk.
 	As we are not holding buffer pool or block mutex therefore
 	we cannot use the bpage safely. It may have been plucked out

=== modified file 'storage/innobase/data/data0data.cc'
--- a/storage/innobase/data/data0data.cc	2011-11-30 10:27:10 +0000
+++ b/storage/innobase/data/data0data.cc	2012-01-24 10:04:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -53,35 +53,6 @@ UNIV_INTERN ulint	data_dummy;
 #endif /* UNIV_DEBUG */
 
 #ifndef UNIV_HOTBACKUP
-/*********************************************************************//**
-Tests if dfield data length and content is equal to the given.
-@return	TRUE if equal */
-UNIV_INTERN
-ibool
-dfield_data_is_binary_equal(
-/*========================*/
-	const dfield_t*	field,	/*!< in: field */
-	ulint		len,	/*!< in: data length or UNIV_SQL_NULL */
-	const byte*	data)	/*!< in: data */
-{
-	if (len != dfield_get_len(field)) {
-
-		return(FALSE);
-	}
-
-	if (len == UNIV_SQL_NULL) {
-
-		return(TRUE);
-	}
-
-	if (0 != memcmp(dfield_get_data(field), data, len)) {
-
-		return(FALSE);
-	}
-
-	return(TRUE);
-}
-
 /************************************************************//**
 Compare two data tuples, respecting the collation of character fields.
 @return 1, 0 , -1 if tuple1 is greater, equal, less, respectively,

=== modified file 'storage/innobase/dict/dict0load.cc'
--- a/storage/innobase/dict/dict0load.cc	2012-01-18 15:39:14 +0000
+++ b/storage/innobase/dict/dict0load.cc	2012-01-20 08:32:09 +0000
@@ -2240,8 +2240,9 @@ dict_load_foreign(
 		/* Not found */
 
 		fprintf(stderr,
-			"InnoDB: Error A: cannot load foreign constraint "
-			"%.*s\n", (int) id_len, id);
+			"InnoDB: Error: cannot load foreign constraint "
+			"%.*s: could not find the relevant record in "
+			"SYS_FOREIGN\n", (int) id_len, id);
 
 		btr_pcur_close(&pcur);
 		mtr_commit(&mtr);
@@ -2256,8 +2257,9 @@ dict_load_foreign(
 	if (len != id_len || ut_memcmp(id, field, len) != 0) {
 
 		fprintf(stderr,
-			"InnoDB: Error B: cannot load foreign constraint "
-			"%.*s\n", (int) id_len, id);
+			"InnoDB: Error: cannot load foreign constraint "
+			"%.*s: found %.*s instead in SYS_FOREIGN\n",
+			(int) id_len, id, (int) len, field);
 
 		btr_pcur_close(&pcur);
 		mtr_commit(&mtr);

=== modified file 'storage/innobase/dict/dict0stats.cc'
--- a/storage/innobase/dict/dict0stats.cc	2012-01-17 09:04:19 +0000
+++ b/storage/innobase/dict/dict0stats.cc	2012-01-23 14:09:29 +0000
@@ -160,7 +160,7 @@ dict_stats_update_transient(
 	if (index == NULL) {
 		/* Table definition is corrupt */
 		ut_print_timestamp(stderr);
-		fprintf(stderr, "InnoDB: table %s has no indexes. "
+		fprintf(stderr, " InnoDB: table %s has no indexes. "
 			"Cannot calculate statistics.\n", table->name);
 		return;
 	}
@@ -2252,10 +2252,9 @@ dict_stats_update(
 	if (table->ibd_file_missing) {
 		ut_print_timestamp(stderr);
 		fprintf(stderr,
-			"  InnoDB: cannot calculate statistics for table %s\n"
-			"InnoDB: because the .ibd file is missing.  For help,"
-			" please refer to\n"
-			"InnoDB: " REFMAN "innodb-troubleshooting.html\n",
+			" InnoDB: cannot calculate statistics for table %s "
+			"because the .ibd file is missing. For help, please "
+			"refer to " REFMAN "innodb-troubleshooting.html\n",
 			table->name);
 
 		return(DB_TABLESPACE_DELETED);

=== modified file 'storage/innobase/fts/fts0fts.cc'
--- a/storage/innobase/fts/fts0fts.cc	2012-01-09 09:46:12 +0000
+++ b/storage/innobase/fts/fts0fts.cc	2012-01-23 14:18:42 +0000
@@ -2386,9 +2386,7 @@ fts_get_total_document_count(
 /*=========================*/
 	dict_table_t*   table)		/*!< in: table instance */
 {
-	if (!table->stat_initialized) {
-		dict_stats_update(table, DICT_STATS_RECALC_TRANSIENT, FALSE);
-	}
+	ut_ad(table->stat_initialized);
 
 	return((ulint) table->stat_n_rows);
 }

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2012-01-19 09:57:36 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2012-01-26 13:11:26 +0000
@@ -99,12 +99,8 @@ static bool innodb_inited = 0;
 
 #define INSIDE_HA_INNOBASE_CC
 
-/* In the Windows plugin, the return value of current_thd is
-undefined.  Map it to NULL. */
-
 #define EQ_CURRENT_THD(thd) ((thd) == current_thd)
 
-
 static struct handlerton* innodb_hton_ptr;
 
 static const long AUTOINC_OLD_STYLE_LOCKING = 0;
@@ -695,6 +691,16 @@ void
 innobase_commit_concurrency_init_default();
 /*=======================================*/
 
+/** @brief Initialize the default and max value of innodb_undo_logs.
+
+Once InnoDB is running, the default value and the max value of
+innodb_undo_logs must be equal to the available undo logs,
+given by srv_available_undo_logs. */
+static
+void
+innobase_undo_logs_init_default_max();
+/*==================================*/
+
 /************************************************************//**
 Validate the file format name and return its corresponding id.
 @return	valid file format id */
@@ -3003,6 +3009,9 @@ innobase_change_buffering_inited_ok:
 		goto mem_free_and_error;
 	}
 
+	/* Adjust the innodb_undo_logs config object */
+	innobase_undo_logs_init_default_max();
+
 	innobase_old_blocks_pct = buf_LRU_old_ratio_update(
 		innobase_old_blocks_pct, TRUE);
 
@@ -4528,7 +4537,7 @@ table_opened:
 	}
 
 	/* Index block size in InnoDB: used by MySQL in query optimization */
-	stats.block_size = 16 * 1024;
+	stats.block_size = UNIV_PAGE_SIZE;
 
 	/* Init table lock structure */
 	thr_lock_data_init(&share->lock,&lock,(void*) 0);
@@ -13312,38 +13321,6 @@ innodb_change_buffer_max_size_update(
 	ibuf_max_size_update(innobase_change_buffer_max_size);
 }
 
-/********************************************************************
-Check if innodb_undo_logs is valid. This function is registered as
-a callback with MySQL.
-@return	0 for valid innodb_undo_logs
-@see mysql_var_check_func */
-static
-int
-innodb_undo_logs_validate(
-/*======================*/
-	THD*				thd,	/*!< in: thread handle */
-	struct st_mysql_sys_var*	var,	/*!< in: ptr to sys var */
-	void*				save,	/*!< out: immediate result
-						for update function */
-	struct st_mysql_value*		value)	/*!< in: incoming string */
-{
-        long long rsegs;
-
-	DBUG_ENTER("innodb_undo_logs_validate");
-
-	DBUG_ASSERT(save != NULL);
-	DBUG_ASSERT(value != NULL);
-	DBUG_ASSERT(srv_available_undo_logs <= TRX_SYS_N_RSEGS);
-
-	value->val_int(value, &rsegs);
-
-        if (rsegs > (long long) srv_available_undo_logs) {
-		rsegs = srv_available_undo_logs;
-	}
-	*reinterpret_cast<ulint*>(save) = static_cast<ulint>(rsegs);
-
-	DBUG_RETURN(0);
-}
 
 /*************************************************************//**
 Find the corresponding ibuf_use_t value that indexes into
@@ -14570,10 +14547,10 @@ static MYSQL_SYSVAR_ULONG(ft_sort_pll_de
   "InnoDB Fulltext search parallel sort degree, will round up to nearest power of 2 number",
   NULL, NULL, 2, 1, 16, 0);
 
-static MYSQL_SYSVAR_ULONG(sort_buf_size, srv_sort_buf_size,
+static MYSQL_SYSVAR_ULONG(sort_buffer_size, srv_sort_buf_size,
   PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
-  "InnoDB Fulltext search sort buffer size",
-  NULL, NULL, 1048576, 524288, 64836480, 0);
+  "Memory buffer size for index creation",
+  NULL, NULL, 1048576, 524288, 64<<20, 0);
 
 static MYSQL_SYSVAR_BOOL(optimize_fulltext_only, innodb_optimize_fulltext_only,
   PLUGIN_VAR_NOCMDARG,
@@ -14694,7 +14671,7 @@ static MYSQL_SYSVAR_ULONG(undo_tablespac
 static MYSQL_SYSVAR_ULONG(undo_logs, srv_undo_logs,
   PLUGIN_VAR_OPCMDARG,
   "Number of undo logs to use.",
-  innodb_undo_logs_validate, NULL,
+  NULL, NULL,
   TRX_SYS_N_RSEGS,	/* Default setting */
   1,			/* Minimum value */
   TRX_SYS_N_RSEGS, 0);	/* Maximum value */
@@ -14886,7 +14863,7 @@ static struct st_mysql_sys_var* innobase
   MYSQL_SYSVAR(status_file),
   MYSQL_SYSVAR(strict_mode),
   MYSQL_SYSVAR(support_xa),
-  MYSQL_SYSVAR(sort_buf_size),
+  MYSQL_SYSVAR(sort_buffer_size),
   MYSQL_SYSVAR(analyze_is_persistent),
   MYSQL_SYSVAR(sync_spin_loops),
   MYSQL_SYSVAR(spin_wait_delay),
@@ -14992,6 +14969,21 @@ innobase_commit_concurrency_init_default
 		= innobase_commit_concurrency;
 }
 
+/** @brief Initialize the default and max value of innodb_undo_logs.
+
+Once InnoDB is running, the default value and the max value of
+innodb_undo_logs must be equal to the available undo logs,
+given by srv_available_undo_logs. */
+static
+void
+innobase_undo_logs_init_default_max()
+/*=================================*/
+{
+	MYSQL_SYSVAR_NAME(undo_logs).max_val
+		= MYSQL_SYSVAR_NAME(undo_logs).def_val
+		= srv_available_undo_logs;
+}
+
 #ifdef UNIV_COMPILE_TEST_FUNCS
 
 typedef struct innobase_convert_name_test_struct {
@@ -15222,4 +15214,3 @@ ha_innobase::idx_cond_push(
 	DBUG_RETURN(NULL);
 }
 
-

=== modified file 'storage/innobase/handler/i_s.cc'
--- a/storage/innobase/handler/i_s.cc	2012-01-18 15:39:14 +0000
+++ b/storage/innobase/handler/i_s.cc	2012-01-19 10:34:18 +0000
@@ -2596,6 +2596,11 @@ i_s_fts_deleted_generic_fill(
 
 	DBUG_ENTER("i_s_fts_deleted_generic_fill");
 
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+		DBUG_RETURN(0);
+	}
+
 	if (!fts_internal_tbl_name) {
 		DBUG_RETURN(0);
 	}
@@ -2833,6 +2838,11 @@ i_s_fts_inserted_fill(
 
 	DBUG_ENTER("i_s_fts_inserted_fill");
 
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+		DBUG_RETURN(0);
+	}
+
 	if (!fts_internal_tbl_name) {
 		DBUG_RETURN(0);
 	}
@@ -3107,6 +3117,11 @@ i_s_fts_index_cache_fill(
 
 	DBUG_ENTER("i_s_fts_index_cache_fill");
 
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+		DBUG_RETURN(0);
+	}
+
 	if (!fts_internal_tbl_name) {
 		DBUG_RETURN(0);
 	}
@@ -3412,6 +3427,11 @@ i_s_fts_index_table_fill(
 
 	DBUG_ENTER("i_s_fts_index_table_fill");
 
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+		DBUG_RETURN(0);
+	}
+
 	if (!fts_internal_tbl_name) {
 		DBUG_RETURN(0);
 	}
@@ -3566,6 +3586,11 @@ i_s_fts_config_fill(
 
 	DBUG_ENTER("i_s_fts_config_fill");
 
+	/* deny access to non-superusers */
+	if (check_global_access(thd, PROCESS_ACL)) {
+		DBUG_RETURN(0);
+	}
+
 	if (!fts_internal_tbl_name) {
 		DBUG_RETURN(0);
 	}

=== modified file 'storage/innobase/ibuf/ibuf0ibuf.cc'
--- a/storage/innobase/ibuf/ibuf0ibuf.cc	2012-01-16 12:30:58 +0000
+++ b/storage/innobase/ibuf/ibuf0ibuf.cc	2012-01-26 12:31:26 +0000
@@ -3753,6 +3753,7 @@ ibuf_insert_to_index_page_low(
 
 	fputs("InnoDB: Submit a detailed bug report"
 	      " to http://bugs.mysql.com\n", stderr);
+	ut_ad(0);
 }
 
 /************************************************************************
@@ -3946,6 +3947,11 @@ ibuf_set_del_mark(
 							  TRUE, mtr);
 		}
 	} else {
+		const page_t*		page
+			= page_cur_get_page(&page_cur);
+		const buf_block_t*	block
+			= page_cur_get_block(&page_cur);
+
 		ut_print_timestamp(stderr);
 		fputs("  InnoDB: unable to find a record to delete-mark\n",
 		      stderr);
@@ -3954,10 +3960,14 @@ ibuf_set_del_mark(
 		fputs("\n"
 		      "InnoDB: record ", stderr);
 		rec_print(stderr, page_cur_get_rec(&page_cur), index);
-		putc('\n', stderr);
-		fputs("\n"
-		      "InnoDB: Submit a detailed bug report"
-		      " to http://bugs.mysql.com\n", stderr);
+		fprintf(stderr, "\nspace %u offset %u"
+			" (%u records, index id %llu)\n"
+			"InnoDB: Submit a detailed bug report"
+			" to http://bugs.mysql.com\n",
+			(unsigned) buf_block_get_space(block),
+			(unsigned) buf_block_get_page_no(block),
+			(unsigned) page_get_n_recs(page),
+			(ulonglong) btr_page_get_index_id(page));
 		ut_ad(0);
 	}
 }
@@ -4001,12 +4011,31 @@ ibuf_delete(
 		offsets = rec_get_offsets(
 			rec, index, offsets, ULINT_UNDEFINED, &heap);
 
-		/* Refuse to delete the last record. */
-		ut_a(page_get_n_recs(page) > 1);
+		if (page_get_n_recs(page) <= 1
+		    || !(REC_INFO_DELETED_FLAG
+			 & rec_get_info_bits(rec, page_is_comp(page)))) {
+			/* Refuse to purge the last record or a
+			record that has not been marked for deletion. */
+			ut_print_timestamp(stderr);
+			fputs("  InnoDB: unable to purge a record\n",
+			      stderr);
+			fputs("InnoDB: tuple ", stderr);
+			dtuple_print(stderr, entry);
+			fputs("\n"
+			      "InnoDB: record ", stderr);
+			rec_print_new(stderr, rec, offsets);
+			fprintf(stderr, "\nspace %u offset %u"
+				" (%u records, index id %llu)\n"
+				"InnoDB: Submit a detailed bug report"
+				" to http://bugs.mysql.com\n",
+				(unsigned) buf_block_get_space(block),
+				(unsigned) buf_block_get_page_no(block),
+				(unsigned) page_get_n_recs(page),
+				(ulonglong) btr_page_get_index_id(page));
 
-		/* The record should have been marked for deletion. */
-		ut_ad(REC_INFO_DELETED_FLAG
-		      & rec_get_info_bits(rec, page_is_comp(page)));
+			ut_ad(0);
+			return;
+		}
 
 		lock_update_delete(block, rec);
 
@@ -4092,6 +4121,7 @@ ibuf_restore_pos(
 
 		fprintf(stderr, "InnoDB: ibuf tree ok\n");
 		fflush(stderr);
+		ut_ad(0);
 	}
 
 	return(FALSE);

=== modified file 'storage/innobase/include/btr0btr.h'
--- a/storage/innobase/include/btr0btr.h	2011-11-20 20:17:41 +0000
+++ b/storage/innobase/include/btr0btr.h	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -92,6 +92,26 @@ insert/delete buffer when the record is
 buffer when the record is not in the buffer pool. */
 #define BTR_DELETE		8192
 
+/**************************************************************//**
+Report that an index page is corrupted. */
+UNIV_INTERN
+void
+btr_corruption_report(
+/*==================*/
+	const buf_block_t*	block,	/*!< in: corrupted block */
+	const dict_index_t*	index)	/*!< in: index tree */
+	UNIV_COLD __attribute__((nonnull));
+
+/** Assert that a B-tree page is not corrupted.
+@param block buffer block containing a B-tree page
+@param index the B-tree index */
+#define btr_assert_not_corrupted(block, index)			\
+	if ((ibool) !!page_is_comp(buf_block_get_frame(block))	\
+	    != dict_table_is_comp((index)->table)) {		\
+		btr_corruption_report(block, index);		\
+		ut_error;					\
+	}
+
 #ifdef UNIV_BLOB_DEBUG
 # include "ut0rbt.h"
 /** An index->blobs entry for keeping track of off-page column references */

=== modified file 'storage/innobase/include/buf0flu.h'
--- a/storage/innobase/include/buf0flu.h	2011-11-08 10:32:23 +0000
+++ b/storage/innobase/include/buf0flu.h	2012-01-25 15:07:48 +0000
@@ -87,6 +87,13 @@ buf_flush_page_try(
 	buf_block_t*	block)		/*!< in/out: buffer control block */
 	__attribute__((nonnull, warn_unused_result));
 # endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
+/********************************************************************//**
+Flush a batch of writes to the datafiles that have already been
+written by the OS. */
+UNIV_INTERN
+void
+buf_flush_sync_datafiles(void);
+/*==========================*/
 /*******************************************************************//**
 This utility flushes dirty blocks from the end of the flush_list of
 all buffer pool instances.

=== modified file 'storage/innobase/include/data0data.h'
--- a/storage/innobase/include/data0data.h	2011-12-29 14:32:49 +0000
+++ b/storage/innobase/include/data0data.h	2012-01-24 10:04:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2009, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -153,6 +153,7 @@ dfield_dup(
 /*=======*/
 	dfield_t*	field,	/*!< in/out: data field */
 	mem_heap_t*	heap);	/*!< in: memory heap where allocated */
+#ifndef UNIV_HOTBACKUP
 /*********************************************************************//**
 Tests if two data fields are equal.
 If len==0, tests the data length and content for equality.
@@ -170,13 +171,15 @@ dfield_datas_are_binary_equal(
 /*********************************************************************//**
 Tests if dfield data length and content is equal to the given.
 @return	TRUE if equal */
-UNIV_INTERN
+UNIV_INLINE
 ibool
 dfield_data_is_binary_equal(
 /*========================*/
 	const dfield_t*	field,	/*!< in: field */
 	ulint		len,	/*!< in: data length or UNIV_SQL_NULL */
-	const byte*	data);	/*!< in: data */
+	const byte*	data)	/*!< in: data */
+	__attribute__((nonnull, warn_unused_result));
+#endif /* !UNIV_HOTBACKUP */
 /*********************************************************************//**
 Gets number of fields in a data tuple.
 @return	number of fields */

=== modified file 'storage/innobase/include/data0data.ic'
--- a/storage/innobase/include/data0data.ic	2011-12-29 14:32:49 +0000
+++ b/storage/innobase/include/data0data.ic	2012-01-24 10:04:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -228,6 +228,7 @@ dfield_dup(
 	}
 }
 
+#ifndef UNIV_HOTBACKUP
 /*********************************************************************//**
 Tests if two data fields are equal.
 If len==0, tests the data length and content for equality.
@@ -258,6 +259,23 @@ dfield_datas_are_binary_equal(
 }
 
 /*********************************************************************//**
+Tests if dfield data length and content is equal to the given.
+@return	TRUE if equal */
+UNIV_INLINE
+ibool
+dfield_data_is_binary_equal(
+/*========================*/
+	const dfield_t*	field,	/*!< in: field */
+	ulint		len,	/*!< in: data length or UNIV_SQL_NULL */
+	const byte*	data)	/*!< in: data */
+{
+	return(len == dfield_get_len(field)
+	       && (len == UNIV_SQL_NULL
+		   || !memcmp(dfield_get_data(field), data, len)));
+}
+#endif /* !UNIV_HOTBACKUP */
+
+/*********************************************************************//**
 Gets info bits in a data tuple.
 @return	info bits */
 UNIV_INLINE

=== modified file 'storage/innobase/include/mtr0log.ic'
--- a/storage/innobase/include/mtr0log.ic	2011-12-23 13:17:36 +0000
+++ b/storage/innobase/include/mtr0log.ic	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2009, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2012, 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
@@ -217,6 +217,7 @@ mlog_write_initial_log_record_fast(
 				"Please post a bug report to "
 				"bugs.mysql.com.\n",
 				type, offset, space);
+			ut_ad(0);
 		}
 	}
 

=== modified file 'storage/innobase/lock/lock0lock.cc'
--- a/storage/innobase/lock/lock0lock.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/lock/lock0lock.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2012, 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
@@ -1760,7 +1760,7 @@ lock_rec_create(
 	page_no	= buf_block_get_page_no(block);
 	page = block->frame;
 
-	ut_ad(!!page_is_comp(page) == dict_table_is_comp(index->table));
+	btr_assert_not_corrupted(block, index);
 
 	/* If rec is the supremum record, then we reset the gap and
 	LOCK_REC_NOT_GAP bits, as all locks on the supremum are
@@ -1885,6 +1885,7 @@ lock_rec_enqueue_waiting(
 		      "InnoDB: Submit a detailed bug report"
 		      " to http://bugs.mysql.com\n",
 		      stderr);
+		ut_ad(0);
 	}
 
 	/* Enqueue the lock request that will wait to be granted, note that
@@ -4238,6 +4239,7 @@ lock_table_enqueue_waiting(
 		      "InnoDB: Submit a detailed bug report"
 		      " to http://bugs.mysql.com\n",
 		      stderr);
+		ut_ad(0);
 	}
 
 	/* Enqueue the lock request that will wait to be granted */

=== modified file 'storage/innobase/os/os0file.cc'
--- a/storage/innobase/os/os0file.cc	2011-12-21 19:35:09 +0000
+++ b/storage/innobase/os/os0file.cc	2012-01-20 15:51:33 +0000
@@ -3200,6 +3200,90 @@ retry:
 		" setting innodb_native_aio = off in my.cnf\n");
 	return(FALSE);
 }
+
+/******************************************************************//**
+Checks if the system supports native linux aio. On some kernel
+versions where native aio is supported it won't work on tmpfs. In such
+cases we can't use native aio as it is not possible to mix simulated
+and native aio.
+@return: TRUE if supported, FALSE otherwise. */
+static
+ibool
+os_aio_native_aio_supported(void)
+/*=============================*/
+{
+	int			fd;
+	byte*			buf;
+	byte*			ptr;
+	struct io_event		io_event;
+	io_context_t		io_ctx;
+	struct iocb		iocb;
+	struct iocb*		p_iocb;
+	int			err;
+
+	if (!os_aio_linux_create_io_ctx(1, &io_ctx)) {
+		/* The platform does not support native aio. */
+		return(FALSE);
+	}
+
+	/* Now check if tmpdir supports native aio ops. */
+	fd = innobase_mysql_tmpfile();
+
+	if (fd < 0) {
+		ut_print_timestamp(stderr);
+		fprintf(stderr, " InnoDB: Error: unable to create "
+			"temp file to check native AIO support.\n");
+
+		return(FALSE);
+	}
+
+	memset(&io_event, 0x0, sizeof(io_event));
+
+	buf = static_cast<byte*>(ut_malloc(UNIV_PAGE_SIZE * 2));
+	ptr = static_cast<byte*>(ut_align(buf, UNIV_PAGE_SIZE));
+
+	/* Suppress valgrind warning. */
+	memset(buf, 0x00, UNIV_PAGE_SIZE * 2);
+
+	memset(&iocb, 0x0, sizeof(iocb));
+	p_iocb = &iocb;
+	io_prep_pwrite(p_iocb, fd, ptr, UNIV_PAGE_SIZE, 0);
+
+	err = io_submit(io_ctx, 1, &p_iocb);
+	if (err >= 1) {
+		/* Now collect the submitted IO request. */
+		err = io_getevents(io_ctx, 1, 1, &io_event, NULL);
+	}
+
+	ut_free(buf);
+	close(fd);
+
+	switch (err) {
+	case 1:
+		return(TRUE);
+
+	case -EINVAL:
+	case -ENOSYS:
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			" InnoDB: Error: Linux Native AIO is not"
+			" supported on tmpdir.\n"
+			"InnoDB: You can either move tmpdir to a"
+			" file system that supports native AIO\n"
+			"InnoDB: or you can set"
+			" innodb_use_native_aio to FALSE to avoid"
+			" this message.\n");
+
+		/* fall through. */
+	default:
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			" InnoDB: Error: Linux Native AIO check"
+			" on tmpdir returned error[%d]\n", -err);
+	}
+
+	return(FALSE);
+}
 #endif /* LINUX_NATIVE_AIO */
 
 /******************************************************************//**
@@ -3369,6 +3453,19 @@ os_aio_init(
 
 	os_io_init_simple();
 
+#if defined(LINUX_NATIVE_AIO)
+	/* Check if native aio is supported on this system and tmpfs */
+	if (srv_use_native_aio
+	    && !os_aio_native_aio_supported()) {
+
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			" InnoDB: Warning: Linux Native AIO"
+			" disabled.\n");
+		srv_use_native_aio = FALSE;
+	}
+#endif /* LINUX_NATIVE_AIO */
+
 	for (i = 0; i < n_segments; i++) {
 		srv_set_io_thread_op_info(i, "not started yet");
 	}

=== modified file 'storage/innobase/page/page0page.cc'
--- a/storage/innobase/page/page0page.cc	2011-12-12 12:03:34 +0000
+++ b/storage/innobase/page/page0page.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2012, 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
@@ -549,8 +549,7 @@ page_copy_rec_list_end_no_locks(
 		page_cur_move_to_next(&cur1);
 	}
 
-	ut_a((ibool)!!page_is_comp(new_page)
-	     == dict_table_is_comp(index->table));
+	btr_assert_not_corrupted(new_block, index);
 	ut_a(page_is_comp(new_page) == page_rec_is_comp(rec));
 	ut_a(mach_read_from_2(new_page + UNIV_PAGE_SIZE - 10) == (ulint)
 	     (page_is_comp(new_page) ? PAGE_NEW_INFIMUM : PAGE_OLD_INFIMUM));

=== modified file 'storage/innobase/row/row0ins.cc'
--- a/storage/innobase/row/row0ins.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/row/row0ins.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2012, 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
@@ -1070,7 +1070,7 @@ row_ins_foreign_check_on_constraint(
 			fputs("\n"
 			      "InnoDB: Submit a detailed bug report to"
 			      " http://bugs.mysql.com\n", stderr);
-
+			ut_ad(0);
 			err = DB_SUCCESS;
 
 			goto nonstandard_exit_func;

=== modified file 'storage/innobase/row/row0sel.cc'
--- a/storage/innobase/row/row0sel.cc	2011-12-29 14:32:49 +0000
+++ b/storage/innobase/row/row0sel.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1997, 2012, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -3123,6 +3123,7 @@ row_sel_get_clust_rec_for_mysql(
 			fputs("\n"
 			      "InnoDB: Submit a detailed bug report"
 			      " to http://bugs.mysql.com\n", stderr);
+			ut_ad(0);
 		}
 
 		clust_rec = NULL;

=== modified file 'storage/innobase/row/row0umod.cc'
--- a/storage/innobase/row/row0umod.cc	2011-11-16 15:31:08 +0000
+++ b/storage/innobase/row/row0umod.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1997, 2012, 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
@@ -509,6 +509,7 @@ row_undo_mod_del_unmark_sec_and_undo_upd
 		fputs("\n"
 		      "InnoDB: Submit a detailed bug report"
 		      " to http://bugs.mysql.com\n", stderr);
+		ut_ad(0);
 		break;
 	case ROW_FOUND:
 		btr_cur = btr_pcur_get_btr_cur(&pcur);

=== modified file 'storage/innobase/row/row0upd.cc'
--- a/storage/innobase/row/row0upd.cc	2011-11-20 20:17:41 +0000
+++ b/storage/innobase/row/row0upd.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2012, 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
@@ -1723,6 +1723,7 @@ row_upd_sec_index_entry(
 		fputs("\n"
 		      "InnoDB: Submit a detailed bug report"
 		      " to http://bugs.mysql.com\n", stderr);
+		ut_ad(0);
 		break;
 	case ROW_FOUND:
 		/* Delete mark the old index record; it can already be

=== modified file 'storage/innobase/srv/srv0srv.cc'
--- a/storage/innobase/srv/srv0srv.cc	2011-12-28 08:37:08 +0000
+++ b/storage/innobase/srv/srv0srv.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, 2009 Google Inc.
 Copyright (c) 2009, Percona Inc.
 
@@ -1594,6 +1594,7 @@ loop:
 			"InnoDB: Please submit a bug report"
 			" to http://bugs.mysql.com\n",
 			old_lsn, new_lsn);
+		ut_ad(0);
 	}
 
 	old_lsn = new_lsn;

=== modified file 'storage/innobase/trx/trx0purge.cc'
--- a/storage/innobase/trx/trx0purge.cc	2011-11-30 10:09:12 +0000
+++ b/storage/innobase/trx/trx0purge.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2012, 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
@@ -603,6 +603,7 @@ trx_purge_rseg_get_next_history_log(
 				"InnoDB: report, and submit it"
 				" to http://bugs.mysql.com\n",
 				(ulong) trx_sys->rseg_history_len);
+			ut_ad(0);
 		}
 
 		mutex_exit(&trx_sys->mutex);

=== modified file 'storage/innobase/trx/trx0rec.cc'
--- a/storage/innobase/trx/trx0rec.cc	2011-11-08 10:32:23 +0000
+++ b/storage/innobase/trx/trx0rec.cc	2012-01-26 11:57:53 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2012, 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
@@ -1009,6 +1009,7 @@ trx_undo_update_rec_get_update(
 			fprintf(stderr, "\n"
 				"InnoDB: n_fields = %lu, i = %lu, ptr %p\n",
 				(ulong) n_fields, (ulong) i, ptr);
+			ut_ad(0);
 			*upd = NULL;
 			return(NULL);
 		}

=== modified file 'storage/innobase/trx/trx0trx.cc'
--- a/storage/innobase/trx/trx0trx.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/trx/trx0trx.cc	2012-01-21 03:30:27 +0000
@@ -2055,5 +2055,4 @@ trx_start_if_not_started(
 	}
 
 	ut_error;
-
 }

=== modified file 'storage/innobase/ut/ut0crc32.cc'
--- a/storage/innobase/ut/ut0crc32.cc	2011-11-24 10:49:07 +0000
+++ b/storage/innobase/ut/ut0crc32.cc	2012-01-18 13:29:45 +0000
@@ -142,21 +142,10 @@ ut_cpuid(
 	ib_uint32_t*	features_edx)	/*!< out: CPU features edx */
 {
 	ib_uint32_t	sig;
-	asm volatile (
-		"mov %%ebx, %%edi;"	/* Save %ebx */
-		"cpuid;"
-		"mov %%ebx, %%esi;"
-		"mov %%edi, %%ebx;"
-		: "=S" (vend[0]), "=c" (vend[2]), "=d" (vend[1])
-		: "a" (0)
-		: "edi");
-	asm volatile (
-		"mov %%ebx, %%edi;"	/* Save %ebx */
-		"cpuid;"
-		"mov %%edi, %%ebx;"
-		: "=a" (sig), "=c" (*features_ecx), "=d" (*features_edx)
-		: "a" (1)
-		: "edi");
+	asm("cpuid" : "=b" (vend[0]), "=c" (vend[2]), "=d" (vend[1]) : "a" (0));
+	asm("cpuid" : "=a" (sig), "=c" (*features_ecx), "=d" (*features_edx)
+	    : "a" (1)
+	    : "ebx");
 
 	*model = ((sig >> 4) & 0xF);
 	*family = ((sig >> 8) & 0xF);

=== modified file 'storage/perfschema/ha_perfschema.cc'
--- a/storage/perfschema/ha_perfschema.cc	2011-09-21 11:01:41 +0000
+++ b/storage/perfschema/ha_perfschema.cc	2012-01-24 23:42:36 +0000
@@ -290,6 +290,9 @@ int ha_perfschema::rnd_init(bool scan)
   else
     m_table->reset_position();
 
+  if (m_table != NULL)
+    m_table->rnd_init(scan);
+
   result= m_table ? 0 : HA_ERR_OUT_OF_MEM;
   DBUG_RETURN(result);
 }

=== modified file 'storage/perfschema/pfs_engine_table.cc'
--- a/storage/perfschema/pfs_engine_table.cc	2011-09-02 20:03:36 +0000
+++ b/storage/perfschema/pfs_engine_table.cc	2012-01-24 23:42:36 +0000
@@ -70,6 +70,7 @@
 
 /* For show status */
 #include "pfs_column_values.h"
+#include "pfs_instr_class.h"
 #include "pfs_instr.h"
 #include "pfs_setup_actor.h"
 #include "pfs_setup_object.h"
@@ -446,6 +447,19 @@ void PFS_engine_table::set_position(cons
   memcpy(m_pos_ptr, ref, m_share_ptr->m_ref_length);
 }
 
+/**
+  Get the timer normalizer and class type for the current row.
+  @param [in] instr_class    class
+*/
+void PFS_engine_table::get_normalizer(PFS_instr_class *instr_class)
+{
+  if (instr_class->m_type != m_class_type)
+  {
+    m_normalizer= time_normalizer::get(*instr_class->m_timer);
+    m_class_type= instr_class->m_type;
+  }
+}
+
 void PFS_engine_table::set_field_ulong(Field *f, ulong value)
 {
   DBUG_ASSERT(f->real_type() == MYSQL_TYPE_LONG);

=== modified file 'storage/perfschema/pfs_engine_table.h'
--- a/storage/perfschema/pfs_engine_table.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/pfs_engine_table.h	2012-01-24 23:42:36 +0000
@@ -22,8 +22,10 @@
   Performance schema tables (declarations).
 */
 
+#include "pfs_instr_class.h"
 class Field;
 struct PFS_engine_table_share;
+struct time_normalizer;
 
 /**
   @addtogroup Performance_schema_engine
@@ -55,6 +57,9 @@ public:
   */
   int delete_row(TABLE *table, const unsigned char *buf, Field **fields);
 
+  /** Initialize table scan. */
+  virtual int rnd_init(bool scan){return 0;};
+
   /** Fetch the next row in this cursor. */
   virtual int rnd_next(void)= 0;
   /**
@@ -68,6 +73,9 @@ public:
   /** Reset the cursor position to the beginning of the table. */
   virtual void reset_position(void)= 0;
 
+  /** Get the normalizer and class type for the current row. */
+  void get_normalizer(PFS_instr_class *instr_class);
+
   /** Destructor. */
   virtual ~PFS_engine_table()
   {}
@@ -168,13 +176,18 @@ protected:
     @param pos              address of the m_pos position member
   */
   PFS_engine_table(const PFS_engine_table_share *share, void *pos)
-    : m_share_ptr(share), m_pos_ptr(pos)
+    : m_share_ptr(share), m_pos_ptr(pos),
+      m_normalizer(NULL), m_class_type(PFS_CLASS_NONE)
   {}
 
   /** Table share. */
   const PFS_engine_table_share *m_share_ptr;
   /** Opaque pointer to the m_pos position of this cursor. */
   void *m_pos_ptr;
+  /** Current normalizer */
+  time_normalizer *m_normalizer;
+  /** Current class type */
+  enum PFS_class_type m_class_type;
 };
 
 /** Callback to open a table. */

=== modified file 'storage/perfschema/pfs_instr_class.cc'
--- a/storage/perfschema/pfs_instr_class.cc	2012-01-06 09:03:53 +0000
+++ b/storage/perfschema/pfs_instr_class.cc	2012-01-24 23:42:36 +0000
@@ -25,6 +25,7 @@
 #include "pfs_instr_class.h"
 #include "pfs_instr.h"
 #include "pfs_global.h"
+#include "pfs_timer.h"
 #include "pfs_events_waits.h"
 #include "pfs_setup_object.h"
 #include "pfs_atomic.h"
@@ -49,6 +50,12 @@ my_bool pfs_enabled= TRUE;
 DYNAMIC_ARRAY pfs_instr_init_array;
 static void configure_instr_class(PFS_instr_class *entry);
 
+static void init_instr_class(PFS_instr_class *klass,
+                             const char *name,
+                             uint name_length,
+                             int flags,
+                             PFS_class_type class_type);
+
 /**
   Current number of elements in mutex_class_array.
   This global variable is written to during:
@@ -126,6 +133,22 @@ PFS_instr_class global_table_io_class;
 PFS_instr_class global_table_lock_class;
 PFS_instr_class global_idle_class;
 
+/** Class-timer map */
+enum_timer_name *class_timers[] =
+{&wait_timer,      /* PFS_CLASS_NONE */
+ &wait_timer,      /* PFS_CLASS_MUTEX */
+ &wait_timer,      /* PFS_CLASS_RWLOCK */
+ &wait_timer,      /* PFS_CLASS_COND */
+ &wait_timer,      /* PFS_CLASS_FILE */
+ &wait_timer,      /* PFS_CLASS_TABLE */
+ &stage_timer,     /* PFS_CLASS_STAGE */
+ &statement_timer, /* PFS_CLASS_STATEMENT */
+ &wait_timer,      /* PFS_CLASS_SOCKET */
+ &wait_timer,      /* PFS_CLASS_TABLE_IO */
+ &wait_timer,      /* PFS_CLASS_TABLE_LOCK */
+ &idle_timer       /* PFS_CLASS_IDLE */
+};
+
 /**
   Hash index for instrumented table shares.
   This index is searched by table fully qualified name (@c PFS_table_share_key),
@@ -177,32 +200,26 @@ void init_event_name_sizing(const PFS_gl
   socket_class_start= file_class_start + param->m_file_class_sizing;
   table_class_start= socket_class_start + param->m_socket_class_sizing;
   wait_class_max= table_class_start + 3; /* global table io, lock, idle */
+}
 
-  memcpy(global_table_io_class.m_name, "wait/io/table/sql/handler", 25);
-  global_table_io_class.m_name_length= 25;
-  global_table_io_class.m_flags= 0;
-  global_table_io_class.m_enabled= true;
-  global_table_io_class.m_timed= true;
+void register_global_classes()
+{
+  /* Table IO class */
+  init_instr_class(&global_table_io_class, "wait/io/table/sql/handler", 25,
+                   0, PFS_CLASS_TABLE_IO);
   global_table_io_class.m_event_name_index= table_class_start;
-  /* Set user-defined defaults. */
   configure_instr_class(&global_table_io_class);
 
-  memcpy(global_table_lock_class.m_name, "wait/lock/table/sql/handler", 27);
-  global_table_lock_class.m_name_length= 27;
-  global_table_lock_class.m_flags= 0;
-  global_table_lock_class.m_enabled= true;
-  global_table_lock_class.m_timed= true;
+  /* Table lock class */
+  init_instr_class(&global_table_lock_class, "wait/lock/table/sql/handler", 27,
+                   0, PFS_CLASS_TABLE_LOCK);
   global_table_lock_class.m_event_name_index= table_class_start + 1;
-  /* Set user-defined defaults. */
   configure_instr_class(&global_table_lock_class);
-
-  memcpy(global_idle_class.m_name, "idle", 4);
-  global_idle_class.m_name_length= 4;
-  global_idle_class.m_flags= 0;
-  global_idle_class.m_enabled= true;
-  global_idle_class.m_timed= true;
+  
+  /* Idle class */
+  init_instr_class(&global_idle_class, "idle", 4,
+                   0, PFS_CLASS_IDLE);
   global_idle_class.m_event_name_index= table_class_start + 2;
-  /* Set user-defined defaults. */
   configure_instr_class(&global_idle_class);
 }
 
@@ -592,6 +609,7 @@ static void init_instr_class(PFS_instr_c
   klass->m_enabled= true;
   klass->m_timed= true;
   klass->m_type= class_type;
+  klass->m_timer= class_timers[class_type];
 }
 
 /**

=== modified file 'storage/perfschema/pfs_instr_class.h'
--- a/storage/perfschema/pfs_instr_class.h	2011-11-17 21:44:20 +0000
+++ b/storage/perfschema/pfs_instr_class.h	2012-01-24 23:42:36 +0000
@@ -53,6 +53,7 @@ struct PFS_global_param;
 */
 
 extern my_bool pfs_enabled;
+extern enum_timer_name *class_timers[];
 
 /** Key, naming a synch instrument (mutex, rwlock, cond). */
 typedef unsigned int PFS_sync_key;
@@ -69,14 +70,20 @@ typedef unsigned int PFS_socket_key;
 
 enum PFS_class_type
 {
-  PFS_CLASS_MUTEX=  1,
-  PFS_CLASS_RWLOCK= 2,
-  PFS_CLASS_COND=   3,
-  PFS_CLASS_FILE=   4,
-  PFS_CLASS_TABLE=  5,
-  PFS_CLASS_STAGE=  6,
-  PFS_CLASS_STATEMENT= 7,
-  PFS_CLASS_SOCKET= 8
+  PFS_CLASS_NONE=        0,
+  PFS_CLASS_MUTEX=       1,
+  PFS_CLASS_RWLOCK=      2,
+  PFS_CLASS_COND=        3,
+  PFS_CLASS_FILE=        4,
+  PFS_CLASS_TABLE=       5,
+  PFS_CLASS_STAGE=       6,
+  PFS_CLASS_STATEMENT=   7,
+  PFS_CLASS_SOCKET=      8,
+  PFS_CLASS_TABLE_IO=    9,
+  PFS_CLASS_TABLE_LOCK= 10,
+  PFS_CLASS_IDLE=       11,
+  PFS_CLASS_LAST=       PFS_CLASS_IDLE,
+  PFS_CLASS_MAX=        PFS_CLASS_LAST + 1
 };
 
 /** User-defined instrument configuration. */
@@ -127,6 +134,8 @@ struct PFS_instr_class
   char m_name[PFS_MAX_INFO_NAME_LENGTH];
   /** Length in bytes of @c m_name. */
   uint m_name_length;
+  /** Timer associated with this class. */
+  enum_timer_name *m_timer;
 
   bool is_singleton() const
   {
@@ -362,6 +371,8 @@ struct PFS_socket_class : public PFS_ins
 
 void init_event_name_sizing(const PFS_global_param *param);
 
+void register_global_classes();
+
 int init_sync_class(uint mutex_class_sizing,
                     uint rwlock_class_sizing,
                     uint cond_class_sizing);

=== modified file 'storage/perfschema/pfs_server.cc'
--- a/storage/perfschema/pfs_server.cc	2012-01-06 09:03:53 +0000
+++ b/storage/perfschema/pfs_server.cc	2012-01-24 23:42:36 +0000
@@ -66,6 +66,7 @@ initialize_performance_schema(const PFS_
   init_timers();
   PFS_atomic::init();
   init_event_name_sizing(param);
+  register_global_classes();
 
   if (pthread_key_create(&THR_PFS, destroy_pfs_thread))
     return NULL;

=== modified file 'storage/perfschema/table_esgs_by_account_by_event_name.cc'
--- a/storage/perfschema/table_esgs_by_account_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_account_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -118,6 +118,12 @@ void table_esgs_by_account_by_event_name
   m_next_pos.reset();
 }
 
+int table_esgs_by_account_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_esgs_by_account_by_event_name::rnd_next(void)
 {
   PFS_account *account;
@@ -186,9 +192,7 @@ void table_esgs_by_account_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esgs_by_account_by_event_name

=== modified file 'storage/perfschema/table_esgs_by_account_by_event_name.h'
--- a/storage/perfschema/table_esgs_by_account_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_account_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -85,6 +85,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esgs_by_host_by_event_name.cc'
--- a/storage/perfschema/table_esgs_by_host_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_host_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -115,6 +115,12 @@ void table_esgs_by_host_by_event_name::r
   m_next_pos.reset();
 }
 
+int table_esgs_by_host_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_esgs_by_host_by_event_name::rnd_next(void)
 {
   PFS_host *host;
@@ -183,9 +189,7 @@ void table_esgs_by_host_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esgs_by_host_by_event_name

=== modified file 'storage/perfschema/table_esgs_by_host_by_event_name.h'
--- a/storage/perfschema/table_esgs_by_host_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_host_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -85,6 +85,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esgs_by_thread_by_event_name.cc'
--- a/storage/perfschema/table_esgs_by_thread_by_event_name.cc	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esgs_by_thread_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -112,6 +112,12 @@ void table_esgs_by_thread_by_event_name:
   m_next_pos.reset();
 }
 
+int table_esgs_by_thread_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_esgs_by_thread_by_event_name::rnd_next(void)
 {
   PFS_thread *thread;
@@ -184,8 +190,7 @@ void table_esgs_by_thread_by_event_name
   if (thread->m_lock.end_optimistic_lock(&lock))
     m_row_exists= true;
 
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esgs_by_thread_by_event_name

=== modified file 'storage/perfschema/table_esgs_by_thread_by_event_name.h'
--- a/storage/perfschema/table_esgs_by_thread_by_event_name.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esgs_by_thread_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -89,6 +89,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esgs_by_user_by_event_name.cc'
--- a/storage/perfschema/table_esgs_by_user_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_user_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -115,6 +115,12 @@ void table_esgs_by_user_by_event_name::r
   m_next_pos.reset();
 }
 
+int table_esgs_by_user_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_esgs_by_user_by_event_name::rnd_next(void)
 {
   PFS_user *user;
@@ -183,9 +189,7 @@ void table_esgs_by_user_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esgs_by_user_by_event_name

=== modified file 'storage/perfschema/table_esgs_by_user_by_event_name.h'
--- a/storage/perfschema/table_esgs_by_user_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esgs_by_user_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -90,6 +90,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esgs_global_by_event_name.cc'
--- a/storage/perfschema/table_esgs_global_by_event_name.cc	2011-07-07 19:06:44 +0000
+++ b/storage/perfschema/table_esgs_global_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -110,6 +110,12 @@ void table_esgs_global_by_event_name::re
   m_next_pos= 1;
 }
 
+int table_esgs_global_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_esgs_global_by_event_name::rnd_next(void)
 {
   PFS_stage_class *stage_class;
@@ -161,8 +167,7 @@ void table_esgs_global_by_event_name
                                         false, /* users */
                                         true, true, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 

=== modified file 'storage/perfschema/table_esgs_global_by_event_name.h'
--- a/storage/perfschema/table_esgs_global_by_event_name.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esgs_global_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -53,6 +53,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esms_by_account_by_event_name.cc'
--- a/storage/perfschema/table_esms_by_account_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_account_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -213,6 +213,12 @@ void table_esms_by_account_by_event_name
   m_next_pos.reset();
 }
 
+int table_esms_by_account_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_esms_by_account_by_event_name::rnd_next(void)
 {
   PFS_account *account;
@@ -281,9 +287,7 @@ void table_esms_by_account_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esms_by_account_by_event_name

=== modified file 'storage/perfschema/table_esms_by_account_by_event_name.h'
--- a/storage/perfschema/table_esms_by_account_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_account_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -85,6 +85,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esms_by_host_by_event_name.cc'
--- a/storage/perfschema/table_esms_by_host_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_host_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -210,6 +210,12 @@ void table_esms_by_host_by_event_name::r
   m_next_pos.reset();
 }
 
+int table_esms_by_host_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_esms_by_host_by_event_name::rnd_next(void)
 {
   PFS_host *host;
@@ -278,9 +284,7 @@ void table_esms_by_host_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esms_by_host_by_event_name

=== modified file 'storage/perfschema/table_esms_by_host_by_event_name.h'
--- a/storage/perfschema/table_esms_by_host_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_host_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -85,6 +85,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esms_by_thread_by_event_name.cc'
--- a/storage/perfschema/table_esms_by_thread_by_event_name.cc	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esms_by_thread_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -207,6 +207,12 @@ void table_esms_by_thread_by_event_name:
   m_next_pos.reset();
 }
 
+int table_esms_by_thread_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_esms_by_thread_by_event_name::rnd_next(void)
 {
   PFS_thread *thread;
@@ -280,9 +286,7 @@ void table_esms_by_thread_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esms_by_thread_by_event_name

=== modified file 'storage/perfschema/table_esms_by_thread_by_event_name.h'
--- a/storage/perfschema/table_esms_by_thread_by_event_name.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esms_by_thread_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -89,6 +89,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esms_by_user_by_event_name.cc'
--- a/storage/perfschema/table_esms_by_user_by_event_name.cc	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_user_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -210,6 +210,12 @@ void table_esms_by_user_by_event_name::r
   m_next_pos.reset();
 }
 
+int table_esms_by_user_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_esms_by_user_by_event_name::rnd_next(void)
 {
   PFS_user *user;
@@ -278,9 +284,7 @@ void table_esms_by_user_by_event_name
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_esms_by_user_by_event_name

=== modified file 'storage/perfschema/table_esms_by_user_by_event_name.h'
--- a/storage/perfschema/table_esms_by_user_by_event_name.h	2011-05-07 00:40:25 +0000
+++ b/storage/perfschema/table_esms_by_user_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -85,6 +85,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_esms_global_by_event_name.cc'
--- a/storage/perfschema/table_esms_global_by_event_name.cc	2011-07-07 19:06:44 +0000
+++ b/storage/perfschema/table_esms_global_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -205,6 +205,12 @@ void table_esms_global_by_event_name::re
   m_next_pos= 1;
 }
 
+int table_esms_global_by_event_name::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_esms_global_by_event_name::rnd_next(void)
 {
   PFS_statement_class *statement_class;
@@ -256,8 +262,7 @@ void table_esms_global_by_event_name
                                         false, /* users */
                                         true, true, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 

=== modified file 'storage/perfschema/table_esms_global_by_event_name.h'
--- a/storage/perfschema/table_esms_global_by_event_name.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_esms_global_by_event_name.h	2012-01-24 23:42:36 +0000
@@ -53,6 +53,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_events_stages.cc'
--- a/storage/perfschema/table_events_stages.cc	2011-08-26 08:42:40 +0000
+++ b/storage/perfschema/table_events_stages.cc	2012-01-24 23:42:36 +0000
@@ -166,8 +166,7 @@ void table_events_stages_common::make_ro
   m_row.m_nesting_event_id= stage->m_nesting_event_id;
   m_row.m_nesting_event_type= stage->m_nesting_event_type;
 
-  time_normalizer *normalizer= time_normalizer::get(stage_timer);
-  normalizer->to_pico(stage->m_timer_start, stage->m_timer_end,
+  m_normalizer->to_pico(stage->m_timer_start, stage->m_timer_end,
                       & m_row.m_timer_start, & m_row.m_timer_end, & m_row.m_timer_wait);
 
   m_row.m_name= klass->m_name;
@@ -279,6 +278,12 @@ void table_events_stages_current::reset_
   m_next_pos.m_index= 0;
 }
 
+int table_events_stages_current::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_events_stages_current::rnd_next(void)
 {
   PFS_thread *pfs_thread;
@@ -345,6 +350,12 @@ void table_events_stages_history::reset_
   m_next_pos.reset();
 }
 
+int table_events_stages_history::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_events_stages_history::rnd_next(void)
 {
   PFS_thread *pfs_thread;
@@ -442,6 +453,12 @@ void table_events_stages_history_long::r
   m_next_pos.m_index= 0;
 }
 
+int table_events_stages_history_long::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(stage_timer);
+  return 0;
+}
+
 int table_events_stages_history_long::rnd_next(void)
 {
   PFS_events_stages *stage;

=== modified file 'storage/perfschema/table_events_stages.h'
--- a/storage/perfschema/table_events_stages.h	2011-08-26 08:42:40 +0000
+++ b/storage/perfschema/table_events_stages.h	2012-01-24 23:42:36 +0000
@@ -115,6 +115,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);
@@ -154,6 +155,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);
@@ -184,6 +186,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_events_statements.cc'
--- a/storage/perfschema/table_events_statements.cc	2011-08-26 08:42:40 +0000
+++ b/storage/perfschema/table_events_statements.cc	2012-01-24 23:42:36 +0000
@@ -308,8 +308,7 @@ void table_events_statements_common::mak
   m_row.m_nesting_event_id= statement->m_nesting_event_id;
   m_row.m_nesting_event_type= statement->m_nesting_event_type;
 
-  time_normalizer *normalizer= time_normalizer::get(statement_timer);
-  normalizer->to_pico(statement->m_timer_start, statement->m_timer_end,
+  m_normalizer->to_pico(statement->m_timer_start, statement->m_timer_end,
                       & m_row.m_timer_start, & m_row.m_timer_end, & m_row.m_timer_wait);
   m_row.m_lock_time= statement->m_lock_time * MICROSEC_TO_PICOSEC;
 
@@ -555,6 +554,12 @@ void table_events_statements_current::re
   m_next_pos.reset();
 }
 
+int table_events_statements_current::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_events_statements_current::rnd_next(void)
 {
   PFS_thread *pfs_thread;
@@ -657,6 +662,12 @@ void table_events_statements_history::re
   m_next_pos.reset();
 }
 
+int table_events_statements_history::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_events_statements_history::rnd_next(void)
 {
   PFS_thread *pfs_thread;
@@ -754,6 +765,12 @@ void table_events_statements_history_lon
   m_next_pos.m_index= 0;
 }
 
+int table_events_statements_history_long::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(statement_timer);
+  return 0;
+}
+
 int table_events_statements_history_long::rnd_next(void)
 {
   PFS_events_statements *statement;

=== modified file 'storage/perfschema/table_events_statements.h'
--- a/storage/perfschema/table_events_statements.h	2011-08-26 08:42:40 +0000
+++ b/storage/perfschema/table_events_statements.h	2012-01-24 23:42:36 +0000
@@ -188,6 +188,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);
@@ -227,6 +228,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);
@@ -257,6 +259,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_events_waits.cc'
--- a/storage/perfschema/table_events_waits.cc	2012-01-06 09:03:53 +0000
+++ b/storage/perfschema/table_events_waits.cc	2012-01-24 23:42:36 +0000
@@ -442,8 +442,8 @@ void table_events_waits_common::make_row
   m_row.m_nesting_event_id= wait->m_nesting_event_id;
   m_row.m_nesting_event_type= wait->m_nesting_event_type;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  normalizer->to_pico(wait->m_timer_start, wait->m_timer_end,
+  get_normalizer(safe_class);
+  m_normalizer->to_pico(wait->m_timer_start, wait->m_timer_end,
                       & m_row.m_timer_start, & m_row.m_timer_end, & m_row.m_timer_wait);
 
   m_row.m_name= safe_class->m_name;

=== modified file 'storage/perfschema/table_events_waits_summary.cc'
--- a/storage/perfschema/table_events_waits_summary.cc	2011-04-01 22:04:26 +0000
+++ b/storage/perfschema/table_events_waits_summary.cc	2012-01-24 23:42:36 +0000
@@ -121,8 +121,8 @@ void table_events_waits_summary_by_insta
   m_row.m_name_length= klass->m_name_length;
   m_row.m_object_instance_addr= (intptr) object_instance_begin;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, pfs_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, pfs_stat);
 
   if (pfs->m_lock.end_optimistic_lock(&lock))
     m_row_exists= true;

=== modified file 'storage/perfschema/table_ews_by_account_by_event_name.cc'
--- a/storage/perfschema/table_ews_by_account_by_event_name.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/table_ews_by_account_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -246,8 +246,8 @@ void table_ews_by_account_by_event_name
 
   m_row_exists= true;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_ews_by_account_by_event_name

=== modified file 'storage/perfschema/table_ews_by_host_by_event_name.cc'
--- a/storage/perfschema/table_ews_by_host_by_event_name.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/table_ews_by_host_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -244,8 +244,8 @@ void table_ews_by_host_by_event_name
 
   m_row_exists= true;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
 }
 
 int table_ews_by_host_by_event_name

=== modified file 'storage/perfschema/table_ews_by_thread_by_event_name.cc'
--- a/storage/perfschema/table_ews_by_thread_by_event_name.cc	2011-10-06 17:15:47 +0000
+++ b/storage/perfschema/table_ews_by_thread_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -259,8 +259,8 @@ void table_ews_by_thread_by_event_name
 
   m_row_exists= true;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_ews_by_thread_by_event_name

=== modified file 'storage/perfschema/table_ews_by_user_by_event_name.cc'
--- a/storage/perfschema/table_ews_by_user_by_event_name.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/table_ews_by_user_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -244,8 +244,8 @@ void table_ews_by_user_by_event_name
 
   m_row_exists= true;
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
 }
 
 int table_ews_by_user_by_event_name

=== modified file 'storage/perfschema/table_ews_global_by_event_name.cc'
--- a/storage/perfschema/table_ews_global_by_event_name.cc	2011-08-11 03:11:58 +0000
+++ b/storage/perfschema/table_ews_global_by_event_name.cc	2012-01-24 23:42:36 +0000
@@ -292,8 +292,8 @@ void table_ews_global_by_event_name
   PFS_instance_wait_visitor visitor;
   PFS_instance_iterator::visit_mutex_instances(klass, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -305,8 +305,8 @@ void table_ews_global_by_event_name
   PFS_instance_wait_visitor visitor;
   PFS_instance_iterator::visit_rwlock_instances(klass, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -318,8 +318,8 @@ void table_ews_global_by_event_name
   PFS_instance_wait_visitor visitor;
   PFS_instance_iterator::visit_cond_instances(klass, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -331,8 +331,8 @@ void table_ews_global_by_event_name
   PFS_instance_wait_visitor visitor;
   PFS_instance_iterator::visit_file_instances(klass, & visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -344,8 +344,8 @@ void table_ews_global_by_event_name
   PFS_table_io_wait_visitor visitor;
   PFS_object_iterator::visit_all_tables(& visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -357,8 +357,8 @@ void table_ews_global_by_event_name
   PFS_table_lock_wait_visitor visitor;
   PFS_object_iterator::visit_all_tables(& visitor);
   
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -370,8 +370,8 @@ void table_ews_global_by_event_name
   PFS_instance_wait_visitor visitor;
   PFS_instance_iterator::visit_socket_instances(klass, &visitor);
 
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, &visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
   m_row_exists= true;
 }
 
@@ -385,8 +385,8 @@ void table_ews_global_by_event_name
                                         false, /* users */
                                         false, /* accts */
                                         true,  /* threads */ &visitor);
-  time_normalizer *normalizer= time_normalizer::get(idle_timer);
-  m_row.m_stat.set(normalizer, &visitor.m_stat);
+  get_normalizer(klass);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
   m_row_exists= true;
 }
 

=== modified file 'storage/perfschema/table_tiws_by_index_usage.cc'
--- a/storage/perfschema/table_tiws_by_index_usage.cc	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_tiws_by_index_usage.cc	2012-01-24 23:42:36 +0000
@@ -273,6 +273,12 @@ void table_tiws_by_index_usage::reset_po
   m_next_pos.reset();
 }
 
+int table_tiws_by_index_usage::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(wait_timer);
+  return 0;
+}
+
 int table_tiws_by_index_usage::rnd_next(void)
 {
   PFS_table_share *table_share;
@@ -346,9 +352,7 @@ void table_tiws_by_index_usage::make_row
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, & visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, & visitor.m_stat);
 }
 
 int table_tiws_by_index_usage::read_row_values(TABLE *table,

=== modified file 'storage/perfschema/table_tiws_by_index_usage.h'
--- a/storage/perfschema/table_tiws_by_index_usage.h	2011-06-30 15:50:45 +0000
+++ b/storage/perfschema/table_tiws_by_index_usage.h	2012-01-24 23:42:36 +0000
@@ -83,6 +83,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_tiws_by_table.cc'
--- a/storage/perfschema/table_tiws_by_table.cc	2011-01-07 16:20:19 +0000
+++ b/storage/perfschema/table_tiws_by_table.cc	2012-01-24 23:42:36 +0000
@@ -268,6 +268,12 @@ void table_tiws_by_table::reset_position
   m_next_pos.m_index= 0;
 }
 
+int table_tiws_by_table::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(wait_timer);
+  return 0;
+}
+
 int table_tiws_by_table::rnd_next(void)
 {
   PFS_table_share *table_share;
@@ -323,9 +329,7 @@ void table_tiws_by_table::make_row(PFS_t
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, &visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
 }
 
 int table_tiws_by_table::read_row_values(TABLE *table,

=== modified file 'storage/perfschema/table_tiws_by_table.h'
--- a/storage/perfschema/table_tiws_by_table.h	2011-01-07 16:20:19 +0000
+++ b/storage/perfschema/table_tiws_by_table.h	2012-01-24 23:42:36 +0000
@@ -53,6 +53,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'storage/perfschema/table_tlws_by_table.cc'
--- a/storage/perfschema/table_tlws_by_table.cc	2011-01-07 16:20:19 +0000
+++ b/storage/perfschema/table_tlws_by_table.cc	2012-01-24 23:42:36 +0000
@@ -443,6 +443,12 @@ void table_tlws_by_table::reset_position
   m_next_pos.m_index= 0;
 }
 
+int table_tlws_by_table::rnd_init(bool scan)
+{
+  m_normalizer= time_normalizer::get(wait_timer);
+  return 0;
+}
+
 int table_tlws_by_table::rnd_next(void)
 {
   PFS_table_share *table_share;
@@ -498,9 +504,7 @@ void table_tlws_by_table::make_row(PFS_t
     return;
 
   m_row_exists= true;
-
-  time_normalizer *normalizer= time_normalizer::get(wait_timer);
-  m_row.m_stat.set(normalizer, &visitor.m_stat);
+  m_row.m_stat.set(m_normalizer, &visitor.m_stat);
 }
 
 int table_tlws_by_table::read_row_values(TABLE *table,

=== modified file 'storage/perfschema/table_tlws_by_table.h'
--- a/storage/perfschema/table_tlws_by_table.h	2011-01-07 16:20:19 +0000
+++ b/storage/perfschema/table_tlws_by_table.h	2012-01-24 23:42:36 +0000
@@ -53,6 +53,7 @@ public:
   static PFS_engine_table* create();
   static int delete_all_rows();
 
+  virtual int rnd_init(bool scan);
   virtual int rnd_next();
   virtual int rnd_pos(const void *pos);
   virtual void reset_position(void);

=== modified file 'strings/ctype-ucs2.c'
--- a/strings/ctype-ucs2.c	2011-08-29 12:08:58 +0000
+++ b/strings/ctype-ucs2.c	2012-01-23 10:02:54 +0000
@@ -3410,6 +3410,41 @@ CHARSET_INFO my_charset_ucs2_general_ci=
     &my_collation_ucs2_general_ci_handler
 };
 
+
+CHARSET_INFO my_charset_ucs2_general_mysql500_ci=
+{
+  159, 0, 0,                                       /* number           */
+  MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE|MY_CS_NONASCII, /* state */
+  "ucs2",                                          /* cs name          */
+  "ucs2_general_mysql500_ci",                      /* name             */
+  "",                                              /* comment          */
+  NULL,                                            /* tailoring        */
+  ctype_ucs2,                                      /* ctype            */
+  to_lower_ucs2,                                   /* to_lower         */
+  to_upper_ucs2,                                   /* to_upper         */
+  to_upper_ucs2,                                   /* sort_order       */
+  NULL,                                            /* uca              */
+  NULL,                                            /* tab_to_uni       */
+  NULL,                                            /* tab_from_uni     */
+  &my_unicase_mysql500,                            /* caseinfo         */
+  NULL,                                            /* state_map        */
+  NULL,                                            /* ident_map        */
+  1,                                               /* strxfrm_multiply */
+  1,                                               /* caseup_multiply  */
+  1,                                               /* casedn_multiply  */
+  2,                                               /* mbminlen         */
+  2,                                               /* mbmaxlen         */
+  0,                                               /* min_sort_char    */
+  0xFFFF,                                          /* max_sort_char    */
+  ' ',                                             /* pad char         */
+  0,                          /* escape_with_backslash_is_dangerous    */
+  1,                                               /* levels_for_compare */
+  1,                                               /* levels_for_order   */
+  &my_charset_ucs2_handler,
+  &my_collation_ucs2_general_ci_handler
+};
+
+
 CHARSET_INFO my_charset_ucs2_bin=
 {
     90,0,0,		/* number       */

=== modified file 'strings/ctype-utf8.c'
--- a/strings/ctype-utf8.c	2011-08-29 12:08:58 +0000
+++ b/strings/ctype-utf8.c	2012-01-23 10:02:54 +0000
@@ -192,6 +192,141 @@ static MY_UNICASE_CHARACTER plane00[]={
 };
 
 
+/*
+  Almost similar to plane00, but maps sorting order
+  for U+00DF to 0x00DF instead of 0x0053.
+*/
+static MY_UNICASE_CHARACTER plane00_mysql500[]={
+  {0x0000,0x0000,0x0000},  {0x0001,0x0001,0x0001},
+  {0x0002,0x0002,0x0002},  {0x0003,0x0003,0x0003},
+  {0x0004,0x0004,0x0004},  {0x0005,0x0005,0x0005},
+  {0x0006,0x0006,0x0006},  {0x0007,0x0007,0x0007},
+  {0x0008,0x0008,0x0008},  {0x0009,0x0009,0x0009},
+  {0x000A,0x000A,0x000A},  {0x000B,0x000B,0x000B},
+  {0x000C,0x000C,0x000C},  {0x000D,0x000D,0x000D},
+  {0x000E,0x000E,0x000E},  {0x000F,0x000F,0x000F},
+  {0x0010,0x0010,0x0010},  {0x0011,0x0011,0x0011},
+  {0x0012,0x0012,0x0012},  {0x0013,0x0013,0x0013},
+  {0x0014,0x0014,0x0014},  {0x0015,0x0015,0x0015},
+  {0x0016,0x0016,0x0016},  {0x0017,0x0017,0x0017},
+  {0x0018,0x0018,0x0018},  {0x0019,0x0019,0x0019},
+  {0x001A,0x001A,0x001A},  {0x001B,0x001B,0x001B},
+  {0x001C,0x001C,0x001C},  {0x001D,0x001D,0x001D},
+  {0x001E,0x001E,0x001E},  {0x001F,0x001F,0x001F},
+  {0x0020,0x0020,0x0020},  {0x0021,0x0021,0x0021},
+  {0x0022,0x0022,0x0022},  {0x0023,0x0023,0x0023},
+  {0x0024,0x0024,0x0024},  {0x0025,0x0025,0x0025},
+  {0x0026,0x0026,0x0026},  {0x0027,0x0027,0x0027},
+  {0x0028,0x0028,0x0028},  {0x0029,0x0029,0x0029},
+  {0x002A,0x002A,0x002A},  {0x002B,0x002B,0x002B},
+  {0x002C,0x002C,0x002C},  {0x002D,0x002D,0x002D},
+  {0x002E,0x002E,0x002E},  {0x002F,0x002F,0x002F},
+  {0x0030,0x0030,0x0030},  {0x0031,0x0031,0x0031},
+  {0x0032,0x0032,0x0032},  {0x0033,0x0033,0x0033},
+  {0x0034,0x0034,0x0034},  {0x0035,0x0035,0x0035},
+  {0x0036,0x0036,0x0036},  {0x0037,0x0037,0x0037},
+  {0x0038,0x0038,0x0038},  {0x0039,0x0039,0x0039},
+  {0x003A,0x003A,0x003A},  {0x003B,0x003B,0x003B},
+  {0x003C,0x003C,0x003C},  {0x003D,0x003D,0x003D},
+  {0x003E,0x003E,0x003E},  {0x003F,0x003F,0x003F},
+  {0x0040,0x0040,0x0040},  {0x0041,0x0061,0x0041},
+  {0x0042,0x0062,0x0042},  {0x0043,0x0063,0x0043},
+  {0x0044,0x0064,0x0044},  {0x0045,0x0065,0x0045},
+  {0x0046,0x0066,0x0046},  {0x0047,0x0067,0x0047},
+  {0x0048,0x0068,0x0048},  {0x0049,0x0069,0x0049},
+  {0x004A,0x006A,0x004A},  {0x004B,0x006B,0x004B},
+  {0x004C,0x006C,0x004C},  {0x004D,0x006D,0x004D},
+  {0x004E,0x006E,0x004E},  {0x004F,0x006F,0x004F},
+  {0x0050,0x0070,0x0050},  {0x0051,0x0071,0x0051},
+  {0x0052,0x0072,0x0052},  {0x0053,0x0073,0x0053},
+  {0x0054,0x0074,0x0054},  {0x0055,0x0075,0x0055},
+  {0x0056,0x0076,0x0056},  {0x0057,0x0077,0x0057},
+  {0x0058,0x0078,0x0058},  {0x0059,0x0079,0x0059},
+  {0x005A,0x007A,0x005A},  {0x005B,0x005B,0x005B},
+  {0x005C,0x005C,0x005C},  {0x005D,0x005D,0x005D},
+  {0x005E,0x005E,0x005E},  {0x005F,0x005F,0x005F},
+  {0x0060,0x0060,0x0060},  {0x0041,0x0061,0x0041},
+  {0x0042,0x0062,0x0042},  {0x0043,0x0063,0x0043},
+  {0x0044,0x0064,0x0044},  {0x0045,0x0065,0x0045},
+  {0x0046,0x0066,0x0046},  {0x0047,0x0067,0x0047},
+  {0x0048,0x0068,0x0048},  {0x0049,0x0069,0x0049},
+  {0x004A,0x006A,0x004A},  {0x004B,0x006B,0x004B},
+  {0x004C,0x006C,0x004C},  {0x004D,0x006D,0x004D},
+  {0x004E,0x006E,0x004E},  {0x004F,0x006F,0x004F},
+  {0x0050,0x0070,0x0050},  {0x0051,0x0071,0x0051},
+  {0x0052,0x0072,0x0052},  {0x0053,0x0073,0x0053},
+  {0x0054,0x0074,0x0054},  {0x0055,0x0075,0x0055},
+  {0x0056,0x0076,0x0056},  {0x0057,0x0077,0x0057},
+  {0x0058,0x0078,0x0058},  {0x0059,0x0079,0x0059},
+  {0x005A,0x007A,0x005A},  {0x007B,0x007B,0x007B},
+  {0x007C,0x007C,0x007C},  {0x007D,0x007D,0x007D},
+  {0x007E,0x007E,0x007E},  {0x007F,0x007F,0x007F},
+  {0x0080,0x0080,0x0080},  {0x0081,0x0081,0x0081},
+  {0x0082,0x0082,0x0082},  {0x0083,0x0083,0x0083},
+  {0x0084,0x0084,0x0084},  {0x0085,0x0085,0x0085},
+  {0x0086,0x0086,0x0086},  {0x0087,0x0087,0x0087},
+  {0x0088,0x0088,0x0088},  {0x0089,0x0089,0x0089},
+  {0x008A,0x008A,0x008A},  {0x008B,0x008B,0x008B},
+  {0x008C,0x008C,0x008C},  {0x008D,0x008D,0x008D},
+  {0x008E,0x008E,0x008E},  {0x008F,0x008F,0x008F},
+  {0x0090,0x0090,0x0090},  {0x0091,0x0091,0x0091},
+  {0x0092,0x0092,0x0092},  {0x0093,0x0093,0x0093},
+  {0x0094,0x0094,0x0094},  {0x0095,0x0095,0x0095},
+  {0x0096,0x0096,0x0096},  {0x0097,0x0097,0x0097},
+  {0x0098,0x0098,0x0098},  {0x0099,0x0099,0x0099},
+  {0x009A,0x009A,0x009A},  {0x009B,0x009B,0x009B},
+  {0x009C,0x009C,0x009C},  {0x009D,0x009D,0x009D},
+  {0x009E,0x009E,0x009E},  {0x009F,0x009F,0x009F},
+  {0x00A0,0x00A0,0x00A0},  {0x00A1,0x00A1,0x00A1},
+  {0x00A2,0x00A2,0x00A2},  {0x00A3,0x00A3,0x00A3},
+  {0x00A4,0x00A4,0x00A4},  {0x00A5,0x00A5,0x00A5},
+  {0x00A6,0x00A6,0x00A6},  {0x00A7,0x00A7,0x00A7},
+  {0x00A8,0x00A8,0x00A8},  {0x00A9,0x00A9,0x00A9},
+  {0x00AA,0x00AA,0x00AA},  {0x00AB,0x00AB,0x00AB},
+  {0x00AC,0x00AC,0x00AC},  {0x00AD,0x00AD,0x00AD},
+  {0x00AE,0x00AE,0x00AE},  {0x00AF,0x00AF,0x00AF},
+  {0x00B0,0x00B0,0x00B0},  {0x00B1,0x00B1,0x00B1},
+  {0x00B2,0x00B2,0x00B2},  {0x00B3,0x00B3,0x00B3},
+  {0x00B4,0x00B4,0x00B4},  {0x039C,0x00B5,0x039C},
+  {0x00B6,0x00B6,0x00B6},  {0x00B7,0x00B7,0x00B7},
+  {0x00B8,0x00B8,0x00B8},  {0x00B9,0x00B9,0x00B9},
+  {0x00BA,0x00BA,0x00BA},  {0x00BB,0x00BB,0x00BB},
+  {0x00BC,0x00BC,0x00BC},  {0x00BD,0x00BD,0x00BD},
+  {0x00BE,0x00BE,0x00BE},  {0x00BF,0x00BF,0x00BF},
+  {0x00C0,0x00E0,0x0041},  {0x00C1,0x00E1,0x0041},
+  {0x00C2,0x00E2,0x0041},  {0x00C3,0x00E3,0x0041},
+  {0x00C4,0x00E4,0x0041},  {0x00C5,0x00E5,0x0041},
+  {0x00C6,0x00E6,0x00C6},  {0x00C7,0x00E7,0x0043},
+  {0x00C8,0x00E8,0x0045},  {0x00C9,0x00E9,0x0045},
+  {0x00CA,0x00EA,0x0045},  {0x00CB,0x00EB,0x0045},
+  {0x00CC,0x00EC,0x0049},  {0x00CD,0x00ED,0x0049},
+  {0x00CE,0x00EE,0x0049},  {0x00CF,0x00EF,0x0049},
+  {0x00D0,0x00F0,0x00D0},  {0x00D1,0x00F1,0x004E},
+  {0x00D2,0x00F2,0x004F},  {0x00D3,0x00F3,0x004F},
+  {0x00D4,0x00F4,0x004F},  {0x00D5,0x00F5,0x004F},
+  {0x00D6,0x00F6,0x004F},  {0x00D7,0x00D7,0x00D7},
+  {0x00D8,0x00F8,0x00D8},  {0x00D9,0x00F9,0x0055},
+  {0x00DA,0x00FA,0x0055},  {0x00DB,0x00FB,0x0055},
+  {0x00DC,0x00FC,0x0055},  {0x00DD,0x00FD,0x0059},
+  {0x00DE,0x00FE,0x00DE},  {0x00DF,0x00DF,0x00DF},
+  {0x00C0,0x00E0,0x0041},  {0x00C1,0x00E1,0x0041},
+  {0x00C2,0x00E2,0x0041},  {0x00C3,0x00E3,0x0041},
+  {0x00C4,0x00E4,0x0041},  {0x00C5,0x00E5,0x0041},
+  {0x00C6,0x00E6,0x00C6},  {0x00C7,0x00E7,0x0043},
+  {0x00C8,0x00E8,0x0045},  {0x00C9,0x00E9,0x0045},
+  {0x00CA,0x00EA,0x0045},  {0x00CB,0x00EB,0x0045},
+  {0x00CC,0x00EC,0x0049},  {0x00CD,0x00ED,0x0049},
+  {0x00CE,0x00EE,0x0049},  {0x00CF,0x00EF,0x0049},
+  {0x00D0,0x00F0,0x00D0},  {0x00D1,0x00F1,0x004E},
+  {0x00D2,0x00F2,0x004F},  {0x00D3,0x00F3,0x004F},
+  {0x00D4,0x00F4,0x004F},  {0x00D5,0x00F5,0x004F},
+  {0x00D6,0x00F6,0x004F},  {0x00F7,0x00F7,0x00F7},
+  {0x00D8,0x00F8,0x00D8},  {0x00D9,0x00F9,0x0055},
+  {0x00DA,0x00FA,0x0055},  {0x00DB,0x00FB,0x0055},
+  {0x00DC,0x00FC,0x0055},  {0x00DD,0x00FD,0x0059},
+  {0x00DE,0x00FE,0x00DE},  {0x0178,0x00FF,0x0059}
+};
+
 
 static MY_UNICASE_CHARACTER plane01[]={
   {0x0100,0x0101,0x0041},  {0x0100,0x0101,0x0041},
@@ -1549,6 +1684,54 @@ MY_UNICASE_INFO my_unicase_default=
 
 
 /*
+  Reproduce old utf8_general_ci behaviour before we fixed Bug#27877.
+*/
+MY_UNICASE_CHARACTER *my_unicase_pages_mysql500[256]={
+ plane00_mysql500,
+          plane01, plane02, plane03, plane04, plane05,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL, plane1E, plane1F,
+    NULL, plane21,    NULL,    NULL, plane24,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,
+    NULL,    NULL,    NULL,    NULL,    NULL,    NULL,    NULL, planeFF
+
+};
+
+
+MY_UNICASE_INFO my_unicase_mysql500=
+{
+  0xFFFF,
+  my_unicase_pages_mysql500
+};
+
+
+/*
   Turkish lower/upper mapping:
   1. LOWER(0x0049 LATIN CAPITAL LETTER I) -> 
            0x0131 LATIN SMALL   LETTER DOTLESS I
@@ -5895,6 +6078,40 @@ CHARSET_INFO my_charset_utf8_tolower_ci=
 };
 
 
+CHARSET_INFO my_charset_utf8_general_mysql500_ci=
+{
+  223,0,0,                                      /* number           */
+  MY_CS_COMPILED|MY_CS_STRNXFRM|MY_CS_UNICODE,  /* state            */
+  "utf8",                                       /* cs name          */
+  "utf8_general_mysql500_ci",                   /* name             */
+  "",                                           /* comment          */
+  NULL,                                         /* tailoring        */
+  ctype_utf8,                                   /* ctype            */
+  to_lower_utf8,                                /* to_lower         */
+  to_upper_utf8,                                /* to_upper         */
+  to_upper_utf8,                                /* sort_order       */
+  NULL,                                         /* uca              */
+  NULL,                                         /* tab_to_uni       */
+  NULL,                                         /* tab_from_uni     */
+  &my_unicase_mysql500,                         /* caseinfo         */
+  NULL,                                         /* state_map        */
+  NULL,                                         /* ident_map        */
+  1,                                            /* strxfrm_multiply */
+  1,                                            /* caseup_multiply  */
+  1,                                            /* casedn_multiply  */
+  1,                                            /* mbminlen         */
+  3,                                            /* mbmaxlen         */
+  0,                                            /* min_sort_char    */
+  0xFFFF,                                       /* max_sort_char    */
+  ' ',                                          /* pad char         */
+  0,                          /* escape_with_backslash_is_dangerous */
+  1,                                            /* levels_for_compare */
+  1,                                            /* levels_for_order   */
+  &my_charset_utf8_handler,
+  &my_collation_utf8_general_ci_handler
+};
+
+
 CHARSET_INFO my_charset_utf8_bin=
 {
     83,0,0,             /* number       */
@@ -7407,6 +7624,7 @@ CHARSET_INFO my_charset_filename=
     &my_collation_filename_handler
 };
 
+
 #ifdef MY_TEST_UTF8
 #include <stdio.h>
 

=== modified file 'strings/dtoa.c'
--- a/strings/dtoa.c	2012-01-19 07:41:28 +0000
+++ b/strings/dtoa.c	2012-01-25 15:49:57 +0000
@@ -783,7 +783,20 @@ static Bigint *multadd(Bigint *b, int m,
   return b;
 }
 
-
+/**
+  Converts a string to Bigint.
+  
+  Now we have nd0 digits, starting at s, followed by a
+  decimal point, followed by nd-nd0 digits.  
+  Unless nd0 == nd, in which case we have a number of the form:
+     ".xxxxxx"    or    "xxxxxx."
+
+  @param s     Input string, already partially parsed by my_strtod_int().
+  @param nd0   Number of digits before decimal point.
+  @param nd    Total number of digits.
+  @param y9    Pre-computed value of the first nine digits.
+  @param alloc Stack allocator for Bigints.
+ */
 static Bigint *s2b(const char *s, int nd0, int nd, ULong y9, Stack_alloc *alloc)
 {
   Bigint *b;
@@ -803,10 +816,11 @@ static Bigint *s2b(const char *s, int nd
     do
       b= multadd(b, 10, *s++ - '0', alloc);
     while (++i < nd0);
-    s++;
+    s++;                                        /* skip '.' */
   }
   else
     s+= 10;
+  /* now do the fractional part */
   for(; i < nd; i++)
     b= multadd(b, 10, *s++ - '0', alloc);
   return b;
@@ -1416,20 +1430,29 @@ static double my_strtod_int(const char *
     for (; s < end && c >= '0' && c <= '9'; c = *++s)
     {
  have_dig:
-      nz++;
-      if (c-= '0')
+      /*
+        Here we are parsing the fractional part.
+        We can stop counting digits after a while: the extra digits
+        will not contribute to the actual result produced by s2b().
+        We have to continue scanning, in case there is an exponent part.
+       */
+      if (nd < 2 * DBL_DIG)
       {
-        nf+= nz;
-        for (i= 1; i < nz; i++)
+        nz++;
+        if (c-= '0')
+        {
+          nf+= nz;
+          for (i= 1; i < nz; i++)
+            if (nd++ < 9)
+              y*= 10;
+            else if (nd <= DBL_DIG + 1)
+              z*= 10;
           if (nd++ < 9)
-            y*= 10;
+            y= 10*y + c;
           else if (nd <= DBL_DIG + 1)
-            z*= 10;
-        if (nd++ < 9)
-          y= 10*y + c;
-        else if (nd <= DBL_DIG + 1)
-          z= 10*z + c;
-        nz= 0;
+            z= 10*z + c;
+          nz= 0;
+        }
       }
     }
   }

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-wl5534 branch (jon.hauglid:3469 to 3470) Jon Olav Hauglid30 Jan