List:Commits« Previous MessageNext Message »
From:Marc Alff Date:January 26 2012 10:21am
Subject:bzr push into mysql-trunk-wl5259 branch (marc.alff:3360 to 3361)
View as plain text  
 3361 Marc Alff	2012-01-26 [merge]
      Merge mysql-trunk --> mysql-trunk-wl5259

    added:
      mysql-test/suite/sys_vars/r/stored_program_cache_basic.result
      mysql-test/suite/sys_vars/t/stored_program_cache_basic.test
    modified:
      mysql-test/include/order_by.inc
      mysql-test/include/wait_for_ndb_to_binlog.inc
      mysql-test/mysql-test-run.pl
      mysql-test/r/bigint.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/order_by_icp_mrr.result
      mysql-test/r/order_by_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/suite/rpl/r/rpl_heartbeat_basic.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/date_formats.test
      mysql-test/t/func_str.test
      mysql-test/t/func_time.test
      mysql-test/t/mysql_embedded.test
      mysql-test/t/temp_table.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/view.test
      sql/debug_sync.cc
      sql/item.cc
      sql/item_cmpfunc.cc
      sql/item_timefunc.cc
      sql/mysqld.cc
      sql/mysqld.h
      sql/opt_range.cc
      sql/records.cc
      sql/sp_cache.cc
      sql/sp_cache.h
      sql/sql_executor.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/innobase/btr/btr0cur.cc
      storage/innobase/buf/buf0dblwr.cc
      storage/innobase/buf/buf0flu.cc
      storage/innobase/data/data0data.cc
      storage/innobase/dict/dict0stats.cc
      storage/innobase/fts/fts0fts.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/include/buf0flu.h
      storage/innobase/include/data0data.h
      storage/innobase/include/data0data.ic
      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/dtoa.c
 3360 Marc Alff	2012-01-26
      Work in progress

    modified:
      mysql-test/suite/perfschema/include/hostcache_dump.inc
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_again_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_again_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_bad_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_bad_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_good_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_good_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_noname_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_addrinfo_noname_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_format.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_nameinfo_again_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_nameinfo_again_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_nameinfo_noname_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_nameinfo_noname_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv4_no_auth_plugin.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_addrinfo_again_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_addrinfo_bad_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_addrinfo_good_allow.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_addrinfo_good_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_addrinfo_noname_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_nameinfo_again_deny.result
      mysql-test/suite/perfschema/r/hostcache_ipv6_nameinfo_noname_deny.result
      mysql-test/suite/perfschema/r/hostcache_peer_addr.result
      mysql-test/suite/perfschema/r/pfs_upgrade.result
      mysql-test/suite/perfschema/r/schema.result
      mysql-test/suite/perfschema/r/table_schema.result
      scripts/mysql_system_tables.sql
      sql/hostname.cc
      sql/hostname.h
      sql/sql_acl.cc
      sql/sql_connect.cc
      storage/perfschema/table_host_cache.cc
      storage/perfschema/table_host_cache.h
=== 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/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/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 16:30:14 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result	2012-01-26 10:20:10 +0000
@@ -798,6 +798,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
@@ -1102,6 +1105,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 16:30:14 +0000
+++ b/mysql-test/r/mysqld--help-win.result	2012-01-26 10:20:10 +0000
@@ -806,6 +806,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
@@ -1113,6 +1116,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/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/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/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/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

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

=== 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/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/temp_table.test'
--- a/mysql-test/t/temp_table.test	2011-01-17 16:27:07 +0000
+++ b/mysql-test/t/temp_table.test	2012-01-25 11:42:57 +0000
@@ -294,3 +294,32 @@ INSERT INTO t3 VALUES (101), (102), (103
 REPAIR TABLE t1, t2, t3;
 
 DROP TABLES t1, t2, t3;
+
+# Test case temporarily deactivated until we can find a place to move it 
+# --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;
+# 
\ No newline at end of file

=== 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/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 '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/item.cc'
--- a/sql/item.cc	2012-01-17 15:43:31 +0000
+++ b/sql/item.cc	2012-01-25 15:06:20 +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)
@@ -8256,10 +8260,15 @@ int stored_field_cmp_to_item(THD *thd, F
     field_val= field->val_decimal(&field_buf);
     return my_decimal_cmp(item_val, field_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 14:44:32 +0000
+++ b/sql/mysqld.cc	2012-01-26 10:20:10 +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	2012-01-02 10:37:56 +0000
+++ b/sql/mysqld.h	2012-01-26 10:20:10 +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_range.cc'
--- a/sql/opt_range.cc	2012-01-12 13:22:52 +0000
+++ b/sql/opt_range.cc	2012-01-25 12:45:56 +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,

=== 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/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_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	2012-01-18 10:25:19 +0000
+++ b/sql/sys_vars.cc	2012-01-26 10:20:10 +0000
@@ -3784,3 +3784,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/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-25 08:25:07 +0000
@@ -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;

=== 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/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-23 09:38:29 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2012-01-25 19:31:50 +0000
@@ -691,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 */
@@ -2999,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);
 
@@ -4524,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);
@@ -13309,38 +13322,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
@@ -14691,7 +14672,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 */
@@ -14989,6 +14970,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 {
@@ -15219,4 +15215,3 @@ ha_innobase::idx_cond_push(
 	DBUG_RETURN(NULL);
 }
 
-

=== 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/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	2012-01-20 11:57:26 +0000
+++ b/storage/perfschema/pfs_engine_table.cc	2012-01-26 10:20:10 +0000
@@ -71,6 +71,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"
@@ -448,6 +449,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	2012-01-20 11:57:26 +0000
+++ b/storage/perfschema/pfs_engine_table.h	2012-01-26 10:20:10 +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()
   {}
@@ -174,13 +182,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/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-wl5259 branch (marc.alff:3360 to 3361) Marc Alff30 Jan