List:Commits« Previous MessageNext Message »
From:kevin.lewis Date:April 30 2012 6:33pm
Subject:bzr push into mysql-trunk branch (kevin.lewis:3745 to 3747)
View as plain text  
 3747 kevin.lewis@stripped	2012-04-30
      Fix PB2 failure of innodb_restart which was a problem in previous change to dict0load.cc.
      Improved innodb-restart.test by splitting mysql-test/include/restart_mysqld.inc into a shutdown and start files.
      Changed the way tablesapaces are opened so that if there are 2 or more possible locations, they are not opened at all except the case of recovery when innodb-strict-mode=OFF.
      Changes ha_innobase functions to used temporary tablename buffers on the stack instead of the heap.

    added:
      mysql-test/include/shutdown_mysqld.inc
      mysql-test/include/start_mysqld.inc
    modified:
      mysql-test/suite/innodb/r/innodb-restart.result
      mysql-test/suite/innodb/t/innodb-restart.test
      storage/innobase/dict/dict0load.cc
      storage/innobase/fil/fil0fil.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/ha_innodb.h
      storage/innobase/include/trx0trx.h
 3746 kevin.lewis@stripped	2012-04-30 [merge]
      merge with mysql-trunk

    added:
      mysql-test/lib/My/Memcache.pm
      mysql-test/r/func_group_innodb_16k.result
      mysql-test/suite/innodb/r/innodb_bug13867871.result
      mysql-test/suite/innodb/t/innodb_bug13867871.test
      mysql-test/suite/rpl/t/rpl_report_port-master.opt
      mysql-test/t/func_group_innodb_16k.test
    modified:
      .bzr-mysql/default.conf
      extra/comp_err.c
      libmysqld/lib_sql.cc
      mysql-test/include/order_by.inc
      mysql-test/include/subquery.inc
      mysql-test/lib/My/ConfigFactory.pm
      mysql-test/lib/mtr_cases.pm
      mysql-test/mysql-test-run.pl
      mysql-test/r/create.result
      mysql-test/r/ctype_create.result
      mysql-test/r/drop.result
      mysql-test/r/events_2.result
      mysql-test/r/func_group_innodb.result
      mysql-test/r/func_time.result
      mysql-test/r/mysql.result
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
      mysql-test/r/order_by_all.result
      mysql-test/r/order_by_icp_mrr.result
      mysql-test/r/order_by_none.result
      mysql-test/r/subquery_all.result
      mysql-test/r/subquery_all_bka.result
      mysql-test/r/subquery_all_bka_nixbnl.result
      mysql-test/r/subquery_nomat_nosj.result
      mysql-test/r/subquery_nomat_nosj_bka.result
      mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result
      mysql-test/r/subquery_none.result
      mysql-test/r/subquery_none_bka.result
      mysql-test/r/subquery_none_bka_nixbnl.result
      mysql-test/suite/innodb/r/innodb_corrupt_bit.result
      mysql-test/suite/innodb/t/innodb_corrupt_bit.test
      mysql-test/suite/opt_trace/r/bugs_no_prot_all.result
      mysql-test/suite/opt_trace/r/bugs_no_prot_none.result
      mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result
      mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result
      mysql-test/suite/opt_trace/r/range_no_prot.result
      mysql-test/suite/opt_trace/r/range_ps_prot.result
      mysql-test/suite/rpl/r/rpl_report_port.result
      mysql-test/suite/rpl/r/rpl_stm_relay_ign_space.result
      mysql-test/suite/rpl/t/rpl_report_port.test
      mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test
      mysql-test/suite/sys_vars/r/bind_address_basic.result
      mysql-test/suite/sys_vars/t/bind_address_basic.test
      mysql-test/t/create.test
      mysql-test/t/ctype_create.test
      mysql-test/t/drop.test
      mysql-test/t/events_2.test
      mysql-test/t/func_group_innodb.test
      mysql-test/t/func_time.test
      mysql-test/t/overflow.test
      sql-common/my_time.c
      sql/datadict.cc
      sql/derror.cc
      sql/event_db_repository.cc
      sql/field.cc
      sql/filesort.cc
      sql/ha_partition.cc
      sql/handler.cc
      sql/handler.h
      sql/item_buff.cc
      sql/item_cmpfunc.cc
      sql/item_cmpfunc.h
      sql/item_subselect.cc
      sql/item_timefunc.cc
      sql/log.cc
      sql/log_event.cc
      sql/log_event_old.cc
      sql/opt_range.cc
      sql/opt_sum.cc
      sql/partition_info.cc
      sql/rpl_slave.cc
      sql/sp.cc
      sql/sql_acl.cc
      sql/sql_bitmap.h
      sql/sql_db.cc
      sql/sql_executor.cc
      sql/sql_help.cc
      sql/sql_insert.cc
      sql/sql_join_buffer.cc
      sql/sql_optimizer.cc
      sql/sql_parse.cc
      sql/sql_planner.cc
      sql/sql_select.cc
      sql/sql_show.cc
      sql/sql_table.cc
      sql/sql_test.cc
      sql/sql_time.cc
      sql/sql_tmp_table.cc
      sql/sql_update.cc
      sql/sql_yacc.yy
      sql/sys_vars.cc
      sql/table.cc
      sql/table.h
      sql/tztime.cc
      storage/csv/ha_tina.cc
      storage/federated/ha_federated.cc
      storage/innobase/api/api0api.cc
      storage/innobase/dict/dict0dict.cc
      storage/innobase/dict/dict0load.cc
      storage/innobase/fil/fil0fil.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/handler0alter.cc
      storage/innobase/include/dict0dict.h
      storage/innobase/include/dict0dict.ic
      storage/innobase/include/dict0mem.h
      storage/innobase/include/fil0fil.h
      storage/innobase/include/fts0priv.ic
      storage/innobase/include/fts0types.ic
      storage/innobase/include/srv0srv.h
      storage/innobase/row/row0ins.cc
      storage/innobase/row/row0mysql.cc
      storage/innobase/row/row0sel.cc
      storage/innobase/row/row0upd.cc
      storage/innobase/sync/sync0arr.cc
      unittest/gunit/decimal-t.cc
      unittest/gunit/dynarray-t.cc
      unittest/gunit/stdcxx-t.cc
 3745 viswanatham.gudipati@strippedom	2012-04-27
      WL#5980 -  Portability testing

    added:
      mysql-test/suite/innodb/r/InnoDB-wl5980-Linux.result
      mysql-test/suite/innodb/r/InnoDB-wl5980-windows.result
      mysql-test/suite/innodb/t/InnoDB-wl5980-Linux.test
      mysql-test/suite/innodb/t/InnoDB-wl5980-windows.test
      mysql-test/suite/innodb/t/Portability-WL5980-Linux.zip
      mysql-test/suite/innodb/t/Portability-WL5980-Windows.tar
=== modified file '.bzr-mysql/default.conf'
--- a/.bzr-mysql/default.conf	revid:viswanatham.gudipati@stripped
+++ b/.bzr-mysql/default.conf	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -1,4 +1,4 @@
 [MYSQL]
 post_commit_to = "commits@stripped"
 post_push_to = "commits@stripped"
-tree_name = "mysql-trunk-wl5545"
+tree_name = "mysql-trunk"

=== modified file 'extra/comp_err.c'
--- a/extra/comp_err.c	revid:viswanatham.gudipati@stripped
+++ b/extra/comp_err.c	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -34,6 +34,7 @@
 
 #define MAX_ROWS  1000
 #define HEADER_LENGTH 32                /* Length of header in errmsg.sys */
+#define ERRMSG_VERSION 3                /* Version number of errmsg.sys */
 #define DEFAULT_CHARSET_DIR "../sql/share/charsets"
 #define ER_PREFIX "ER_"
 #define WARN_PREFIX "WARN_"
@@ -47,8 +48,14 @@ static char *DATADIRECTORY= (char*) "../
 static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace";
 #endif
 
-/* Header for errmsg.sys files */
-uchar file_head[]= { 254, 254, 2, 1 };
+/* 
+  Header for errmsg.sys files 
+  Byte 3 is treated as version number for errmsg.sys
+    With this version ERRMSG_VERSION = 3, number of bytes 
+    used for the length, count and offset are increased 
+    from 2 bytes to 4 bytes.
+*/
+uchar file_head[]= { 254, 254, ERRMSG_VERSION, 1 };
 /* Store positions to each error message row to store in errmsg.sys header */
 uint file_pos[MAX_ROWS];
 
@@ -329,8 +336,8 @@ static int create_sys_files(struct langu
     if (!(to= my_fopen(outfile, O_WRONLY | FILE_BINARY, MYF(MY_WME))))
       DBUG_RETURN(1);
 
-    /* 2 is for 2 bytes to store row position / error message */
-    start_pos= (long) (HEADER_LENGTH + row_count * 2);
+    /* 4 is for 4 bytes to store row position / error message */
+    start_pos= (long) (HEADER_LENGTH + row_count * 4);
     fseek(to, start_pos, 0);
     row_nr= 0;
     for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
@@ -354,12 +361,12 @@ static int create_sys_files(struct langu
     }
 
     /* continue with header of the errmsg.sys file */
-    length= ftell(to) - HEADER_LENGTH - row_count * 2;
+    length= ftell(to) - HEADER_LENGTH - row_count * 4;
     memset(head, 0, HEADER_LENGTH);
     bmove((uchar *) head, (uchar *) file_head, 4);
     head[4]= 1;
-    int2store(head + 6, length);
-    int2store(head + 8, row_count);
+    int4store(head + 6, length);
+    int4store(head + 10, row_count);
     head[30]= csnum;
 
     my_fseek(to, 0l, MY_SEEK_SET, MYF(0));
@@ -368,8 +375,8 @@ static int create_sys_files(struct langu
 
     for (i= 0; i < row_count; i++)
     {
-      int2store(head, file_pos[i]);
-      if (my_fwrite(to, (uchar*) head, 2, MYF(MY_WME | MY_FNABP)))
+      int4store(head, file_pos[i]);
+      if (my_fwrite(to, (uchar*) head, 4, MYF(MY_WME | MY_FNABP)))
 	goto err;
     }
     my_fclose(to, MYF(0));

=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	revid:viswanatham.gudipati@stripped10-uqcic6v5kvzls1lk
+++ b/libmysqld/lib_sql.cc	revid:kevin.lewis@stripped
@@ -448,7 +448,8 @@ static MYSQL_RES * emb_store_result(MYSQ
 int emb_read_change_user_result(MYSQL *mysql)
 {
   mysql->net.read_pos= (uchar*)""; // fake an OK packet
-  return mysql_errno(mysql) ? packet_error : 1 /* length of the OK packet */;
+  return mysql_errno(mysql) ? static_cast<int>packet_error :
+                              1 /* length of the OK packet */;
 }
 
 MYSQL_METHODS embedded_methods= 

=== modified file 'mysql-test/include/order_by.inc'
--- a/mysql-test/include/order_by.inc	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/include/order_by.inc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -1811,3 +1811,13 @@ SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.a
 
 DROP TABLE t1, t2;
 
+--echo #
+--echo # Bug #13949068 ASSERT TAB->REF.KEY == REF_KEY IN
+--echo # PLAN_CHANGE_WATCHDOG::~PLAN_CHANGE_WATCHDOG
+--echo #
+CREATE TABLE t1 (a INT, b INT, KEY(b), KEY(b,a)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0,0);
+let $query=SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+eval EXPLAIN $query;
+eval $query;
+DROP TABLE t1;

=== added file 'mysql-test/include/shutdown_mysqld.inc'
--- a/mysql-test/include/shutdown_mysqld.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/shutdown_mysqld.inc	revid:kevin.lewis@strippedyr7sxxgbhodbg4r
@@ -0,0 +1,19 @@
+
+if ($rpl_inited)
+{
+  if (!$allow_rpl_inited)
+  {
+    --die ERROR IN TEST: When using the replication test framework (master-slave.inc, rpl_init.inc etc), use rpl_restart_server.inc instead of restart_mysqld.inc. If you know what you are doing and you really have to use restart_mysqld.inc, set allow_rpl_inited=1 before you source restart_mysqld.inc
+  }
+}
+
+# Write file to make mysql-test-run.pl expect the "crash", but don't start
+# it until it's told to
+--let $_server_id= `SELECT @@server_id`
+--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
+--exec echo "wait" > $_expect_file_name
+
+# Send shutdown to the connected server and give
+# it 20 seconds to die before zapping it
+shutdown_server 20;
+

=== added file 'mysql-test/include/start_mysqld.inc'
--- a/mysql-test/include/start_mysqld.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/start_mysqld.inc	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -0,0 +1,12 @@
+# Write file to make mysql-test-run.pl start up the server again
+--exec echo "restart" > $_expect_file_name
+
+# Turn on reconnect
+--enable_reconnect
+
+# Call script that will poll the server waiting for it to be back online again
+--source include/wait_until_connected_again.inc
+
+# Turn off reconnect again
+--disable_reconnect
+

=== modified file 'mysql-test/include/subquery.inc'
--- a/mysql-test/include/subquery.inc	revid:viswanatham.gudipati@stripped-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/include/subquery.inc	revid:kevin.lewis@stripped-uyr7sxxgbhodbg4r
@@ -6067,3 +6067,25 @@ eval SELECT *
 );
 
 DROP TABLE t2,t1;
+
+--echo #
+--echo # Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+--echo # VARIABLES
+--echo #
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+
+DROP TABLE t1, t2, t3;

=== modified file 'mysql-test/lib/My/ConfigFactory.pm'
--- a/mysql-test/lib/My/ConfigFactory.pm	revid:viswanatham.gudipati@strippeds1lk
+++ b/mysql-test/lib/My/ConfigFactory.pm	revid:kevin.lewis@stripped
@@ -309,6 +309,16 @@ my @ndbd_rules=
 
 
 #
+# Rules to run for each memcached in the config
+#  - will be run in order listed here
+#
+my @memcached_rules=
+(
+ { '#host' => \&fix_host },
+ { 'port' => \&fix_port },
+);
+
+#
 # Rules to run for each cluster_config section
 #  - will be run in order listed here
 #
@@ -678,6 +688,10 @@ sub new_config {
 			   'mysqld.',
 			   @mysqld_rules);
 
+  $self->run_section_rules($config,
+			   'memcached.',
+			   @memcached_rules);
+               
   # [mysqlbinlog] need additional settings
   $self->run_rules_for_group($config,
 			     $config->insert('mysqlbinlog'),

=== added file 'mysql-test/lib/My/Memcache.pm'
--- a/mysql-test/lib/My/Memcache.pm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/lib/My/Memcache.pm	revid:kevin.lewis@stripped183156-uyr7sxxgbhodbg4r
@@ -0,0 +1,572 @@
+# -*- cperl -*-
+# Copyright (c) 2011, Oracle and/or its affiliates. 
+# All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+
+
+########## Memcache Client Library for Perl
+### 
+###  $mc = My::Memcache->new()          create an ascii-protocol client 
+###  $mc = My::Memcache::Binary->new()  create a binary-protocol client
+###
+###  $mc->connect(host, port)           returns 1 on success, 0 on failure
+### 
+###  $mc->{error}                       holds most recent error/status message
+### 
+###  $mc->set(key, value)               returns 1 on success, 0 on failure
+###  $mc->add(key, value)               set if record does not exist
+###  $mc->replace(key, value)           set if record exists
+###  $mc->append(key, value)            append value to existing data
+###  $mc->prepend(key, value)           prepend value to existing data
+###  $mc->get(key)                      returns value or undef
+###  $mc->delete(key)                   returns 1 on success, 0 on failure
+###  $mc->stats(stat_key)               get stats; returns a hash
+###  $mc->incr(key, amount)             returns the new value or undef
+###  $mc->decr(key, amount)             like incr
+###  $mc->flush()                       flush_all
+###
+###  $mc->set_expires(sec)              Set TTL for all store operations
+###  $mc->set_flags(int_flags)          Set numeric flags for store operations
+###
+###  $mc->note_config_version() 
+###    Store the generation number of the running config in the filesystem,
+###    for later use by wait_for_reconf()
+### 
+###  $mc->wait_for_reconf()
+###    Wait for NDB/Memcache to complete online reconfiguration.  
+###    Returns the generation number of the newly running configuration, 
+###    or zero on timeout/error. 
+
+use strict;
+use lib 'lib';
+use IO::Socket::INET;
+use IO::File;
+use Carp;
+use mtr_report;            # for main::mtr_verbose()
+
+require "mtr_process.pl";  # for mtr_ping_port() 
+require "mtr_misc.pl";     # for mtr_milli_sleep()
+
+package My::Memcache;
+
+sub new {
+  my $pkg = shift;
+  bless { "created" => 1 , "error" => "" , "cf_gen" => 0,
+          "exptime" => 0 , "flags" => 0
+        }, $pkg;
+}
+
+sub connect {
+  my $self = shift;
+  my $host = shift;
+  my $port = shift; 
+  
+  # Wait for memcached to be ready, up to ten seconds.
+  my $retries = 100;
+  while($retries && (::mtr_ping_port($port) == 0))
+  {
+     ::mtr_milli_sleep(100);
+     $retries--;
+  }
+
+  my $conn = IO::Socket::INET->new(PeerAddr => "$host:$port", Proto => "tcp");
+  if($conn) {
+    $self->{connection} = $conn;
+    $self->{connected} = 1;
+    $self->{server} = "$host:$port";
+    $self->{bin_req_id} = 0;
+    return 1;
+  }
+  $self->{error} = "CONNECTION_FAILED";
+  return 0;
+}
+
+sub DESTROY {
+  my $self = shift;
+  $self->{connection}->close();
+}
+
+sub note_config_version {
+  my $self = shift;
+
+  my $vardir = $ENV{MYSQLTEST_VARDIR};
+  # Fetch the memcached current config generation number and save it
+  my %stats = $self->stats("reconf");
+  my $F = IO::File->new("$vardir/tmp/memcache_cf_gen", "w") or die;
+  my $ver = $stats{"Running"};
+  print $F "$ver\n";
+  $F->close();
+
+  $self->{cf_gen} = $ver;
+}
+
+sub set_expires {
+  my $self = shift;
+  my $delta = shift;
+  
+  $self->{exptime} = $delta;
+}
+
+sub set_flags {
+  my $self = shift;
+  my $flags = shift;
+  
+  $self->{flags} = $flags;
+}
+
+sub wait_for_reconf {
+  my $self = shift;
+
+  if($self->{cf_gen} == 0) { 
+    my $cfgen = 0;
+    my $vardir = $ENV{MYSQLTEST_VARDIR};
+    my $F = IO::File->new("$vardir/tmp/memcache_cf_gen", "r");
+    if(defined $F) {
+      chomp($cfgen = <$F>);
+      undef $F;
+    }
+    $self->{cf_gen} = $cfgen;
+  }
+  
+  print STDERR "Config generation is : " . $self->{cf_gen} . "\n";
+  my $wait_for = $self->{cf_gen} + 1 ;
+  print STDERR "Waiting for: $wait_for \n";
+  
+  my $new_gen = $self->wait_for_config_generation($wait_for);
+  if($new_gen > 0) {
+    $self->{cf_gen} = $new_gen;
+  }
+  else {
+    print STDERR "Timed out.\n";
+  }
+  
+  return $new_gen;
+}
+  
+
+# wait_for_config_generation($cf_gen)
+# Wait until memcached is running config generation >= to $cf_gen
+# Returns 0 on error/timeout, or the actual running generation number
+#
+sub wait_for_config_generation {
+  my $self = shift;
+  my $cf_gen = shift;
+  my $ready = 0;
+  my $retries = 100;   # 100 retries x 100 ms = 10s
+  
+  while($retries && ! $ready) {
+    ::mtr_milli_sleep(100);     
+    my %stats = $self->stats("reconf");
+    if($stats{"Running"} >= $cf_gen) {
+      $ready = $stats{"Running"};
+    }
+    else {
+      $retries -= 1;
+    }
+  }
+  return $ready;
+}
+
+  
+sub delete {
+  my $self = shift;
+  my $key = shift;
+  my $sock = $self->{connection}; 
+  
+  $sock->print("delete $key\r\n") || Carp::confess "send error";
+  
+  $self->{error} = $sock->getline();
+  return $self->{error} =~ "^DELETED" ? 1 : $self->normalize_error();
+}
+
+
+sub _txt_store {
+  my $self = shift;
+  my $cmd = shift;
+  my $key = shift;
+  my $value = shift;
+  my $sock = $self->{connection};
+  
+  $sock->printf("%s %s %d %d %d\r\n%s\r\n",$cmd, $key, 
+                $self->{flags}, $self->{exptime}, length($value), $value);
+  return $sock->getline();
+}
+
+
+sub set {
+  my ($self, $key, $value) = @_;
+  
+  $self->{error} = $self->_txt_store("set", $key, $value);
+  return $self->{error} =~ "^STORED" ? 1 : $self->normalize_error();
+}
+
+
+sub add {
+  my ($self, $key, $value) = @_;
+  
+  $self->{error} = $self->_txt_store("add", $key, $value);
+  return $self->{error} =~ "^STORED" ? 1 : $self->normalize_error();
+}
+
+
+sub append {
+  my ($self, $key, $value) = @_;
+  
+  $self->{error} = $self->_txt_store("append", $key, $value);
+  return $self->{error} =~ "^STORED" ? 1 : $self->normalize_error();
+}
+
+
+sub prepend {    
+  my ($self, $key, $value) = @_;
+  
+  $self->{error} = $self->_txt_store("prepend", $key, $value);
+  return $self->{error} =~ "^STORED" ? 1 : $self->normalize_error();
+}
+
+
+sub replace {
+  my ($self, $key, $value) = @_;
+  
+  $self->{error} = $self->_txt_store("replace", $key, $value);
+  return $self->{error} =~ "^STORED" ? 1 : $self->normalize_error();
+}
+
+
+sub get {
+  my $self = shift;
+  my $key = shift;
+  my $sock = $self->{connection};
+  
+  $sock->print("get $key\r\n") || Carp::confess "send error";
+  my $response = $sock->getline();
+  my $val;
+  
+  if ($response =~ /^END/) 
+  {
+    $self->{error} = "NOT_FOUND";
+    return undef;
+  }
+  else
+  {
+    $response =~ /^VALUE (.*) (\d+) (\d+)/;
+    $self->{flags} = $2;
+    my $len = $3;
+    $sock->read($val, $len);
+    $sock->getline();  # \r\n after value
+    $sock->getline();  # END\r\n
+    
+    return $val;
+  }
+}
+
+
+sub _txt_math {
+  my ($self, $cmd, $key, $delta) = @_;
+  my $sock = $self->{connection};
+  
+  $sock->print("$cmd $key $delta \r\n") || Carp::confess "send error";
+  my $response = $sock->getline();
+  my $val;
+  
+  if ($response =~ "^NOT_FOUND")
+  {
+    $self->{error} = "NOT_FOUND";
+    return undef;
+  }
+  elsif ($response =~ "ERROR")
+  {
+    $self->{error} = $response;
+    $self->normalize_error();
+    return undef;
+  }
+  
+  $response =~ /(\d+)/;
+  return $1;
+}
+
+
+sub incr {
+  my ($self, $key, $delta) = @_;
+  return $self->_txt_math("incr", $key, $delta);
+}
+
+
+sub decr {
+  my ($self, $key, $delta) = @_;
+  return $self->_txt_math("decr", $key, $delta);
+}
+
+
+sub stats {
+  my $self = shift;
+  my $key = shift;
+  my $sock = $self->{connection};
+
+  $sock->print("stats $key\r\n") || Carp::confess "send error";
+  
+  $self->{error} = "OK";
+  my %response = ();
+  my $line = "";
+  while($line !~ "^END") {
+    if(($line) && ($line =~ /^STAT(\s+)(\S+)(\s+)(\S+)/)) {
+      $response{$2} = $4;
+    }
+    $line = $sock->getline();
+  }
+  
+  return %response;
+}
+
+sub flush {
+  my $self = shift;
+  my $key = shift;
+  my $sock = $self->{connection}; 
+  
+  $sock->print("flush_all\r\n") || Carp::confess "send error";
+  
+  $self->{error} = $sock->getline();
+  return $self->{error} =~ "^OK" ? 1 : $self->normalize_error();
+}
+
+
+# Try to provide consistent error messagees across ascii & binary protocols
+sub normalize_error {
+  my $self = shift;
+  my %error_message = (
+  "STORED\r\n"                         => "OK",
+  "EXISTS\r\n"                         => "KEY_EXISTS",
+  "CLIENT_ERROR value too big\r\n"     => "VALUE_TOO_LARGE",
+  "SERVER_ERROR object too large for cache\r\n"     => "VALUE_TOO_LARGE",
+  "CLIENT_ERROR invalid arguments\r\n" => "INVALID_ARGUMENTS",
+  "SERVER_ERROR not my vbucket\r\n"    => "NOT_MY_VBUCKET",
+  "SERVER_ERROR out of memory\r\n"     => "SERVER_OUT_OF_MEMORY",
+  "SERVER_ERROR not supported\r\n"     => "NOT_SUPPORTED",
+  "SERVER_ERROR internal\r\n"          => "INTERNAL_ERROR"
+  );  
+  my $norm_error = $error_message{$self->{error}};
+  $self->{error} = $norm_error if(defined($norm_error));
+  return 0;
+} 
+
+#  -----------------------------------------------------------------------
+#  ------------------         BINARY PROTOCOL         --------------------
+#  -----------------------------------------------------------------------
+
+package My::Memcache::Binary;
+@My::Memcache::Binary::ISA = "My::Memcache";
+
+use constant BINARY_HEADER_FMT  => "CCnCCnNNNN";
+use constant BINARY_REQUEST     => 0x80;
+use constant BINARY_RESPONSE    => 0x81;
+
+use constant BIN_CMD_GET        => 0x00;
+use constant BIN_CMD_SET        => 0x01;
+use constant BIN_CMD_ADD        => 0x02;
+use constant BIN_CMD_REPLACE    => 0x03;
+use constant BIN_CMD_DELETE     => 0x04;
+use constant BIN_CMD_INCR       => 0x05;
+use constant BIN_CMD_DECR       => 0x06;
+use constant BIN_CMD_QUIT       => 0x07;
+use constant BIN_CMD_FLUSH      => 0x08;
+use constant BIN_CMD_NOOP       => 0x0A;
+use constant BIN_CMD_APPEND     => 0x0E;
+use constant BIN_CMD_PREPEND    => 0x0F;
+use constant BIN_CMD_STAT       => 0x10;
+
+my %error_message = (
+ 0x00 => "OK",
+ 0x01 => "NOT_FOUND",
+ 0x02 => "KEY_EXISTS", 
+ 0x03 => "VALUE_TOO_LARGE",
+ 0x04 => "INVALID_ARGUMENTS",
+ 0x05 => "NOT_STORED",
+ 0x06 => "NON_NUMERIC_VALUE",
+ 0x07 => "NOT_MY_VBUCKET",
+ 0x81 => "UNKNOWN_COMMAND",
+ 0x82 => "SERVER_OUT_OF_MEMORY",
+ 0x83 => "NOT_SUPPORTED",
+ 0x84 => "INTERNAL_ERROR",
+ 0x85 => "SERVER_BUSY",
+ 0x86 => "SERVER_TEMPORARY_ERROR"
+);
+
+
+sub send_binary_request {
+  my $self = shift;
+  my ($cmd, $key, $val, $extra_header) = @_;
+  my $sock = $self->{connection};
+  my $key_len    = length($key);
+  my $val_len    = length($val);
+  my $extra_len  = length($extra_header);
+  my $total_len  = $key_len + $val_len + $extra_len;
+  my $cas_hi     = 0;
+  my $cas_lo     = 0;
+
+  $self->{bin_req_id}++;
+  
+  my $header = pack(BINARY_HEADER_FMT, BINARY_REQUEST, $cmd,
+                    $key_len, $extra_len, 0, 0, $total_len, 
+                    $self->{bin_req_id}, $cas_hi, $cas_lo);
+  my $packet = $header . $extra_header . $key . $val;
+
+  $sock->send($packet) || Carp::confess "send failed";
+}
+
+
+sub get_binary_response {
+  my $self = shift;
+  my $sock = $self->{connection};
+  my $header_len = length(pack(BINARY_HEADER_FMT));
+  my $expected = $self->{bin_req_id};
+  my $header;
+  my $body="";
+
+  $sock->recv($header, $header_len);
+
+  my ($magic, $cmd, $key_len, $extra_len, $datatype, $status, $body_len,
+      $opaque, $cas_hi, $cas_lo) = unpack(BINARY_HEADER_FMT, $header);
+  
+  ($magic == BINARY_RESPONSE) || Carp::confess "Bad magic number in response";
+  ($opaque == $expected) || Carp::confess "Response out of order ($expected/$opaque)";
+  
+  while($body_len - length($body) > 0) {
+    my $buf;
+    $sock->recv($buf, $body_len - length($body));
+    $body .= $buf;
+  }
+  $self->{error} = $error_message{$status};
+
+  # Packet structure is: header .. extras .. key .. value 
+  my $l = $extra_len + $key_len;
+  my $extras = substr $body, 0, $extra_len;
+  my $key    = substr $body, $extra_len, $key_len; 
+  my $value  = substr $body, $l, $body_len - $l;
+
+  return ($status, $value, $key, $extras);
+}  
+
+
+sub bin_math {
+  my $self = shift;
+  my ($cmd, $key, $delta, $initial, $expires) = @_;
+  
+  my $extra_header = pack "NNNNN", 
+  ($delta   / (2 ** 32)),   # delta hi
+  ($delta   % (2 ** 32)),   # delta lo
+  ($initial / (2 ** 32)),   # initial hi
+  ($initial % (2 ** 32)),   # initial lo
+  $expires;
+  $self->send_binary_request($cmd, $key, '', $extra_header);  
+  my ($status, $value) = $self->get_binary_response();
+  return ($status == 0) ? $value : undef;
+}
+
+
+sub bin_store {
+  my $self = shift;
+  my $cmd = shift;
+  my $key = shift;
+  my $value = shift;
+  
+  my $extra_header = pack "NN", $self->{flags}, $self->{exptime};
+  $self->send_binary_request($cmd, $key, $value, $extra_header);
+  
+  my ($status) = $self->get_binary_response();
+  return ($status == 0) ? 1 : 0;
+}
+
+
+sub get {
+  my $self = shift;
+  my $key = shift;
+  
+  $self->send_binary_request(BIN_CMD_GET, $key, '', '');  
+  my ($status, $value) = $self->get_binary_response();
+  return ($status == 0) ? $value : undef;
+}
+
+sub stats {
+  my $self = shift;
+  my $key = shift;
+  my %response, my $status, my $value, my $klen, my $tlen;
+
+  $self->send_binary_request(BIN_CMD_STAT, $key, '', '');
+  do {
+    ($status, $value, $key) = $self->get_binary_response();
+    if($status == 0) {
+      $response{$key} = $value;
+    } 
+  } while($status == 0 && $key);
+
+  return %response;
+}
+
+sub flush {
+  my ($self, $key, $value) = @_;
+  $self->send_binary_request(BIN_CMD_FLUSH, $key, '', ''); 
+  my ($status, $value) = $self->get_binary_response();
+  return ($status == 0) ? 1 : 0;
+}
+  
+sub set {
+  my ($self, $key, $value) = @_;
+  return $self->bin_store(BIN_CMD_SET, $key, $value);
+}
+
+sub add {
+  my ($self, $key, $value) = @_;
+  return $self->bin_store(BIN_CMD_ADD, $key, $value);
+}
+
+sub replace {
+  my ($self, $key, $value) = @_;
+  return $self->bin_store(BIN_CMD_REPLACE, $key, $value);
+}
+
+sub append {
+  my ($self, $key, $value) = @_;
+  $self->send_binary_request(BIN_CMD_APPEND, $key, $value, '');
+  my ($status) = $self->get_binary_response();
+  return ($status == 0) ? 1 : 0;
+}
+
+sub prepend {
+  my ($self, $key, $value) = @_;
+  $self->send_binary_request(BIN_CMD_PREPEND, $key, $value, '');
+  my ($status) = $self->get_binary_response();
+  return ($status == 0) ? 1 : 0;
+}
+
+sub delete { 
+  my ($self, $key) = @_;
+  $self->send_binary_request(BIN_CMD_DELETE, $key, '', '');
+  my ($status, $value) = $self->get_binary_response();
+  return ($status == 0) ? 1 : 0;
+}
+  
+sub incr {
+  my ($self, $key, $delta) = @_;
+  return $self->bin_math(BIN_CMD_INCR, $key, $delta, 0, 0xffffffff);
+}
+
+sub decr {
+  my ($self, $key, $delta) = @_;
+  return $self->bin_math(BIN_CMD_DECR, $key, $delta, 0, 0xffffffff);
+}
+
+
+1;
+

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	revid:viswanatham.gudipati@strippedls1lk
+++ b/mysql-test/lib/mtr_cases.pm	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -1090,6 +1090,13 @@ sub collect_one_test_case {
     }
   }
 
+  if ( $tinfo->{'not_windows'} && IS_WINDOWS )
+  {
+    $tinfo->{'skip'}= 1;
+    $tinfo->{'comment'}= "Test not supported on Windows";
+    return $tinfo;
+  }
+
   # ----------------------------------------------------------------------
   # Find config file to use if not already selected in <testname>.opt file
   # ----------------------------------------------------------------------
@@ -1172,6 +1179,7 @@ my @tags=
  ["include/not_embedded.inc", "not_embedded", 1],
  ["include/have_ssl.inc", "need_ssl", 1],
  ["include/have_ssl_communication.inc", "need_ssl", 1],
+ ["include/not_windows.inc", "not_windows", 1],
 );
 
 

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/mysql-test-run.pl	revid:kevin.lewis@stripped183156-uyr7sxxgbhodbg4r
@@ -411,7 +411,6 @@ sub main {
     unshift(@$tests, $tinfo);
   }
 
-  print "vardir: $opt_vardir\n";
   initialize_servers();
 
   #######################################################################
@@ -505,15 +504,17 @@ sub main {
   # Send Ctrl-C to any children still running
   kill("INT", keys(%children));
 
-  # Wait for childs to exit
-  foreach my $pid (keys %children)
-  {
-    my $ret_pid= waitpid($pid, 0);
-    if ($ret_pid != $pid){
-      mtr_report("Unknown process $ret_pid exited");
-    }
-    else {
-      delete $children{$ret_pid};
+  if (!IS_WINDOWS) {
+    # Wait for children to exit
+    foreach my $pid (keys %children)
+    {
+      my $ret_pid= waitpid($pid, 0);
+      if ($ret_pid != $pid){
+        mtr_report("Unknown process $ret_pid exited");
+      }
+      else {
+        delete $children{$ret_pid};
+      }
     }
   }
 
@@ -1734,6 +1735,10 @@ sub command_line_setup {
 
     mtr_report("Running valgrind with options \"",
 	       join(" ", @valgrind_args), "\"");
+    
+    # Turn off check testcases to save time
+    mtr_report("Turning off --check-testcases to save time when valgrinding");
+    $opt_check_testcases = 0; 
   }
 
   if ($opt_debug_common)
@@ -2817,7 +2822,7 @@ sub check_ndbcluster_support ($) {
     mtr_report(" - MySQL Cluster");
     # Enable ndb engine and add more test suites
     $opt_include_ndbcluster = 1;
-    $DEFAULT_SUITES.=",ndb,ndb_binlog,rpl_ndb,ndb_rpl";
+    $DEFAULT_SUITES.=",ndb,ndb_binlog,rpl_ndb,ndb_rpl,ndb_memcache";
   }
 
   if ($opt_include_ndbcluster)
@@ -3082,6 +3087,126 @@ sub ndbd_start {
 }
 
 
+sub memcached_start {
+  my ($cluster, $memcached) = @_;
+
+  my $name = $memcached->name();
+  mtr_verbose("memcached_start '$name'");
+
+  my $found_perl_source = my_find_file($basedir,
+     ["storage/ndb/memcache",        # source
+      "mysql-test/lib",              # install
+      "share/mysql-test/lib"],       # install
+      "memcached_path.pl", NOT_REQUIRED);
+
+  mtr_verbose("Found memcache script: '$found_perl_source'");
+  $found_perl_source ne "" or return;
+
+  my $found_so = my_find_file($bindir,
+    ["storage/ndb/memcache",        # source or build
+     "lib", "lib64"],               # install
+    "ndb_engine.so");
+  mtr_verbose("Found memcache plugin: '$found_so'");
+
+  require "$found_perl_source";
+  if(! memcached_is_available())
+  {
+    mtr_error("Memcached not available.");
+  }
+  my $exe = "";
+  if(memcached_is_bundled())
+  {
+    $exe = my_find_bin($bindir,
+    ["libexec", "sbin", "bin", "storage/ndb/memcache/extra/memcached"],
+    "memcached", NOT_REQUIRED);
+  }
+  else
+  {
+    $exe = get_memcached_exe_path();
+  }
+  $exe ne "" or mtr_error("Failed to find memcached.");
+
+  my $args;
+  mtr_init_args(\$args);
+  # TCP port number to listen on
+  mtr_add_arg($args, "-p %d", $memcached->value('port'));
+  # Max simultaneous connections
+  mtr_add_arg($args, "-c %d", $memcached->value('max_connections'));
+  # Load engine as storage engine, ie. /path/ndb_engine.so
+  mtr_add_arg($args, "-E");
+  mtr_add_arg($args, $found_so);
+  # Config options for loaded storage engine
+  {
+    my @opts;
+    push(@opts, "connectstring=" . $memcached->value('ndb_connectstring'));
+    push(@opts, $memcached->if_exist("options"));
+    mtr_add_arg($args, "-e");
+    mtr_add_arg($args, join(";", @opts));
+  }
+
+  if($opt_gdb)
+  {
+    gdb_arguments(\$args, \$exe, "memcached");
+  }
+
+  my $proc = My::SafeProcess->new
+  ( name     =>  $name,
+    path     =>  $exe,
+    args     => \$args,
+    output   =>  "$opt_vardir/log/$name.out",
+    error    =>  "$opt_vardir/log/$name.out",
+    append   =>  1,
+    verbose  => $opt_verbose,
+  );
+  mtr_verbose("Started $proc");
+
+  $memcached->{proc} = $proc;
+
+  return;
+}
+
+
+sub memcached_load_metadata($) {
+  my $cluster= shift;
+
+  foreach my $mysqld (mysqlds())
+  {
+    if(-d $mysqld->value('datadir') . "/" . "ndbmemcache")
+    {
+      mtr_verbose("skipping memcache metadata (already stored)");
+      return;
+    }
+  }
+
+  my $sql_script= my_find_file($bindir,
+                              ["share/mysql/memcache-api", # RPM install
+                               "share/memcache-api",       # Other installs
+                               "scripts"                   # Build tree
+                              ],
+                              "ndb_memcache_metadata.sql", NOT_REQUIRED);
+  mtr_verbose("memcached_load_metadata: '$sql_script'");
+  if (-f $sql_script )
+  {
+    my $args;
+    mtr_init_args(\$args);
+    mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
+    mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
+    mtr_add_arg($args, "--connect-timeout=20");
+    if ( My::SafeProcess->run(
+           name   => "ndbmemcache config loader",
+           path   => $exe_mysql,
+           args   => \$args,
+           input  => $sql_script,
+           output => "$opt_vardir/log/memcache_config.log",
+           error  => "$opt_vardir/log/memcache_config.log"
+       ) != 0)
+    {
+      mtr_error("Could not load ndb_memcache_metadata.sql file");
+    }
+  }
+}
+
+
 sub ndbcluster_start ($) {
   my $cluster= shift;
 
@@ -4254,7 +4379,7 @@ sub run_testcase ($) {
     }
 
     # Try to dump core for mysqltest and all servers
-    foreach my $proc ($test, started(all_servers())) 
+    foreach my $proc ($test, started(all_servers()))
     {
       mtr_print("Trying to dump core for $proc");
       if ($proc->dump_core())
@@ -5280,8 +5405,8 @@ sub mysqlds { return _like('mysqld.'); }
 sub ndbds   { return _like('cluster_config.ndbd.');}
 sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
 sub clusters  { return _like('mysql_cluster.'); }
-sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds() ); }
-
+sub memcacheds { return _like('memcached.'); }
+sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds(), memcacheds() ); }
 
 #
 # Filter a list of servers and return only those that are part
@@ -5353,7 +5478,7 @@ sub stop_servers($$) {
 
     # cluster processes
     My::SafeProcess::shutdown( $opt_shutdown_timeout,
-			       started(ndbds(), ndb_mgmds()) );
+			       started(ndbds(), ndb_mgmds(), memcacheds()) );
   }
   else
   {
@@ -5548,6 +5673,23 @@ sub start_servers($) {
       return 1;
     }
   }
+
+  # Start memcached(s) for each cluster
+  foreach my $cluster ( clusters() )
+  {
+    next if !in_cluster($cluster, memcacheds());
+
+    # Load the memcache metadata into this cluster
+    memcached_load_metadata($cluster);
+
+    # Start memcached(s)
+    foreach my $memcached ( in_cluster($cluster, memcacheds()))
+    {
+      next if started($memcached);
+      memcached_start($cluster, $memcached);
+    }
+  }
+
   return 0;
 }
 

=== modified file 'mysql-test/r/create.result'
--- a/mysql-test/r/create.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/r/create.result	revid:kevin.lewis@strippedom-20120430183156-uyr7sxxgbhodbg4r
@@ -51,7 +51,7 @@ create table t1 like `a/a`;
 drop table `a/a`;
 drop table `t1`;
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int);
-ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
 ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 create table t1 (a int default 100 auto_increment);
@@ -1616,13 +1616,13 @@ a	b
 1	1
 drop table t1,t2;
 CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 DROP DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 USE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 SHOW CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 set names utf8;
 create database имвке_утф8_длиной_больше_чем_45;
@@ -2456,3 +2456,11 @@ drop function f;
 #
 CREATE TABLE t1 (v varchar(65535));
 ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
+#
+# Bug#11746295 - 25168: "INCORRECT TABLE NAME" INSTEAD OF "IDENTIFIER TOO
+#                       LONG" IF TABLE NAME > 64 CHARACTERS
+#
+CREATE TABLE t01234567890123456789012345678901234567890123456789012345678901234567890123456789(a int);
+ERROR 42000: Identifier name 't01234567890123456789012345678901234567890123456789012345678901234567890123456789' is too long
+CREATE DATABASE t01234567890123456789012345678901234567890123456789012345678901234567890123456789;
+ERROR 42000: Identifier name 't01234567890123456789012345678901234567890123456789012345678901234567890123456789' is too long

=== modified file 'mysql-test/r/ctype_create.result'
--- a/mysql-test/r/ctype_create.result	revid:viswanatham.gudipati@stripped0-uqcic6v5kvzls1lk
+++ b/mysql-test/r/ctype_create.result	revid:kevin.lewis@strippedbg4r
@@ -73,6 +73,6 @@ drop database mysqltest2;
 ALTER DATABASE DEFAULT CHARACTER SET latin2;
 ERROR 3D000: No database selected
 ALTER DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa DEFAULT CHARACTER SET latin2;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 ALTER DATABASE `` DEFAULT CHARACTER SET latin2;
 ERROR 42000: Incorrect database name ''

=== modified file 'mysql-test/r/drop.result'
--- a/mysql-test/r/drop.result	revid:viswanatham.gudipati@strippedk
+++ b/mysql-test/r/drop.result	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -135,11 +135,11 @@ create database mysqltestbug26703;
 use mysqltestbug26703;
 create table `#mysql50#abc``def` ( id int );
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
-ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
 create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
 create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
-ERROR 42000: Incorrect table name '#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name '#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 use test;
 drop database mysqltestbug26703;
 End of 5.1 tests

=== modified file 'mysql-test/r/events_2.result'
--- a/mysql-test/r/events_2.result	revid:viswanatham.gudipati@stripped120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/r/events_2.result	revid:kevin.lewis@strippedxxgbhodbg4r
@@ -115,7 +115,7 @@ ERROR 0A000: Not allowed to return a res
 drop table t1;
 drop event e1;
 SHOW EVENTS FROM aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
-ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
+ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
 SHOW EVENTS FROM ``;
 ERROR 42000: Incorrect database name ''
 SHOW EVENTS FROM `events\\test`;

=== modified file 'mysql-test/r/func_group_innodb.result'
--- a/mysql-test/r/func_group_innodb.result	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/r/func_group_innodb.result	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -192,17 +192,3 @@ BIT_XOR(t1.b)
 0
 DROP TABLE t1, t2;
 End of 5.5 tests
-#
-# Bug#13723054 CRASH WITH MIN/MAX AFTER QUICK_GROUP_MIN_MAX_SELECT::NEXT_MIN
-#
-CREATE TABLE t1(a BLOB, b VARCHAR(255) CHARSET LATIN1, c INT,
-KEY(b, c, a(765))) ENGINE=INNODB;
-INSERT INTO t1(a, b, c) VALUES ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
-SELECT MIN(c) FROM t1 GROUP BY b;
-MIN(c)
-0
-EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
-id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	range	NULL	b	263	NULL	4	Using index for group-by
-DROP TABLE t1;
-End of 5.6 tests

=== added file 'mysql-test/r/func_group_innodb_16k.result'
--- a/mysql-test/r/func_group_innodb_16k.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/func_group_innodb_16k.result	revid:kevin.lewis@strippedodbg4r
@@ -0,0 +1,14 @@
+#
+# Bug#13723054 CRASH WITH MIN/MAX AFTER QUICK_GROUP_MIN_MAX_SELECT::NEXT_MIN
+#
+CREATE TABLE t1(a BLOB, b VARCHAR(255) CHARSET LATIN1, c INT,
+KEY(b, c, a(765))) ENGINE=INNODB;
+INSERT INTO t1(a, b, c) VALUES ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
+SELECT MIN(c) FROM t1 GROUP BY b;
+MIN(c)
+0
+EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	NULL	b	263	NULL	4	Using index for group-by
+DROP TABLE t1;
+End of 5.6 tests

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	revid:viswanatham.gudipati@strippedkvzls1lk
+++ b/mysql-test/r/func_time.result	revid:kevin.lewis@stripped
@@ -1769,6 +1769,18 @@ a	UNIX_TIMESTAMP(a)	UNIX_TIMESTAMP('5000
 5000-01-01 00:00:00	0.000000	0
 DROP TABLE t1;
 #
+# Bug#13988413 CRASH/ASSERTION AFTER INVALID MEMORY READ 
+#              IN MY_USECONDS_TO_STR
+#
+DO contains(1, if(0, coalesce(NULL), now()));
+CREATE TABLE t1 AS SELECT IF(0, coalesce(NULL), now(0)) + 0;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `IF(0, coalesce(NULL), now(0)) + 0` decimal(21,6) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
+#
 # Bug#13982125 BUFFER OVERFLOW OF VARIABLE BUF IN
 #              ITEM_FUNC_MAKETIME::GET_TIME
 #

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	revid:viswanatham.gudipati@strippedcic6v5kvzls1lk
+++ b/mysql-test/r/mysql.result	revid:kevin.lewis@stripped
@@ -167,7 +167,7 @@ ERROR 2005 (HY000) at line 1: Unknown My
 The commands reported in the bug report
 ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
 Too long dbname
-ERROR 1102 (42000) at line 1: Incorrect database name 'test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+ERROR 1059 (42000) at line 1: Identifier name 'test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' is too long
 Too long hostname
 ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
 1

=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/r/mysqld--help-notwin.result	revid:kevin.lewis@stripped
@@ -904,7 +904,7 @@ autocommit TRUE
 automatic-sp-privileges TRUE
 back-log 50
 big-tables FALSE
-bind-address (No default value)
+bind-address 0.0.0.0
 binlog-cache-size 32768
 binlog-checksum NONE
 binlog-direct-non-transactional-updates FALSE

=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result	revid:viswanatham.gudipati@stripped5kvzls1lk
+++ b/mysql-test/r/mysqld--help-win.result	revid:kevin.lewis@stripped
@@ -912,7 +912,7 @@ autocommit TRUE
 automatic-sp-privileges TRUE
 back-log 50
 big-tables FALSE
-bind-address (No default value)
+bind-address 0.0.0.0
 binlog-cache-size 32768
 binlog-checksum NONE
 binlog-direct-non-transactional-updates FALSE

=== modified file 'mysql-test/r/order_by_all.result'
--- a/mysql-test/r/order_by_all.result	revid:viswanatham.gudipati@stripped5kvzls1lk
+++ b/mysql-test/r/order_by_all.result	revid:kevin.lewis@stripped
@@ -2671,4 +2671,16 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	8	Using index
 1	SIMPLE	t2	ref	i_a	i_a	5	test.t1.a	2	Using index
 DROP TABLE t1, t2;
+#
+# Bug #13949068 ASSERT TAB->REF.KEY == REF_KEY IN
+# PLAN_CHANGE_WATCHDOG::~PLAN_CHANGE_WATCHDOG
+#
+CREATE TABLE t1 (a INT, b INT, KEY(b), KEY(b,a)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0,0);
+EXPLAIN SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	b,b_2	b_2	5	const	1	Using where
+SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+a
+DROP TABLE t1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/order_by_icp_mrr.result'
--- a/mysql-test/r/order_by_icp_mrr.result	revid:viswanatham.gudipati@stripped20427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/r/order_by_icp_mrr.result	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -2671,4 +2671,16 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	8	Using index
 1	SIMPLE	t2	ref	i_a	i_a	5	test.t1.a	2	Using index
 DROP TABLE t1, t2;
+#
+# Bug #13949068 ASSERT TAB->REF.KEY == REF_KEY IN
+# PLAN_CHANGE_WATCHDOG::~PLAN_CHANGE_WATCHDOG
+#
+CREATE TABLE t1 (a INT, b INT, KEY(b), KEY(b,a)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0,0);
+EXPLAIN SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	b,b_2	b_2	5	const	1	Using where
+SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+a
+DROP TABLE t1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/order_by_none.result'
--- a/mysql-test/r/order_by_none.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/r/order_by_none.result	revid:kevin.lewis@stripped-20120430183156-uyr7sxxgbhodbg4r
@@ -2670,4 +2670,16 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	8	Using index
 1	SIMPLE	t2	ref	i_a	i_a	5	test.t1.a	2	Using index
 DROP TABLE t1, t2;
+#
+# Bug #13949068 ASSERT TAB->REF.KEY == REF_KEY IN
+# PLAN_CHANGE_WATCHDOG::~PLAN_CHANGE_WATCHDOG
+#
+CREATE TABLE t1 (a INT, b INT, KEY(b), KEY(b,a)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0,0);
+EXPLAIN SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	b,b_2	b_2	5	const	1	Using where
+SELECT DISTINCT a FROM t1 WHERE b=1 ORDER BY 1;
+a
+DROP TABLE t1;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_all.result'
--- a/mysql-test/r/subquery_all.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/r/subquery_all.result	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -7375,4 +7375,26 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_all_bka.result'
--- a/mysql-test/r/subquery_all_bka.result	revid:viswanatham.gudipati@stripped5kvzls1lk
+++ b/mysql-test/r/subquery_all_bka.result	revid:kevin.lewis@stripped
@@ -7376,5 +7376,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_all_bka_nixbnl.result'
--- a/mysql-test/r/subquery_all_bka_nixbnl.result	revid:viswanatham.gudipati@strippedv5kvzls1lk
+++ b/mysql-test/r/subquery_all_bka_nixbnl.result	revid:kevin.lewis@strippedhodbg4r
@@ -7376,5 +7376,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_nomat_nosj.result'
--- a/mysql-test/r/subquery_nomat_nosj.result	revid:viswanatham.gudipati@strippedv5kvzls1lk
+++ b/mysql-test/r/subquery_nomat_nosj.result	revid:kevin.lewis@strippedg4r
@@ -7375,4 +7375,26 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_nomat_nosj_bka.result'
--- a/mysql-test/r/subquery_nomat_nosj_bka.result	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/r/subquery_nomat_nosj_bka.result	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -7376,5 +7376,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result'
--- a/mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result	revid:viswanatham.gudipati@strippedls1lk
+++ b/mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result	revid:kevin.lewis@strippedgbhodbg4r
@@ -7376,5 +7376,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_none.result'
--- a/mysql-test/r/subquery_none.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/r/subquery_none.result	revid:kevin.lewis@stripped
@@ -7374,4 +7374,26 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_none_bka.result'
--- a/mysql-test/r/subquery_none_bka.result	revid:viswanatham.gudipati@strippedc6v5kvzls1lk
+++ b/mysql-test/r/subquery_none_bka.result	revid:kevin.lewis@strippedg4r
@@ -7375,5 +7375,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_none_bka_nixbnl.result'
--- a/mysql-test/r/subquery_none_bka_nixbnl.result	revid:viswanatham.gudipati@strippeduqcic6v5kvzls1lk
+++ b/mysql-test/r/subquery_none_bka_nixbnl.result	revid:kevin.lewis@strippedr7sxxgbhodbg4r
@@ -7375,5 +7375,27 @@ AND ( table1.col_varchar_key LIKE '%a%' 
 );
 field1	field2	field3	field4	field5	field6
 DROP TABLE t2,t1;
+#
+# Bug #13735712 SELECT W/ SUBQUERY PRODUCES MORE ROWS WHEN USING
+# VARIABLES
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(9);
+CREATE TABLE t2(b INT);
+INSERT INTO t2 VALUES(8);
+CREATE TABLE t3(c INT);
+INSERT INTO t3 VALUES(3);
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= 7);
+b	c
+NULL	3
+SET @var = 7;
+SELECT *
+FROM t2 RIGHT JOIN t3 ON(c = b)
+WHERE b < ALL(SELECT a FROM t1 WHERE a <= @var);
+b	c
+NULL	3
+DROP TABLE t1, t2, t3;
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/suite/innodb/r/innodb-restart.result'
--- a/mysql-test/suite/innodb/r/innodb-restart.result	revid:viswanatham.gudipati@strippedm-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/innodb/r/innodb-restart.result	revid:kevin.lewis@strippedom-20120430183156-uyr7sxxgbhodbg4r
@@ -194,7 +194,7 @@ SELECT count(*) FROM t7;
 count(*)
 16
 #
-# Show these 7 tables in information_schema and list the OD files.
+# Show these 7 tables in information_schema.
 #
 SELECT name,n_cols,file_format,row_format
 FROM information_schema.innodb_sys_tables WHERE name like 'test%';
@@ -240,6 +240,9 @@ MYSQL_TMP_DIR/alt_dir/test/t7#p#p0#sp#s0
 MYSQL_TMP_DIR/alt_dir/test/t7#p#p0#sp#s1.ibd
 MYSQL_TMP_DIR/alt_dir/test/t7#p#p1#sp#s2.ibd
 MYSQL_TMP_DIR/alt_dir/test/t7#p#p1#sp#s3.ibd
+#
+# Shutdown the server and list the tablespace OS files
+#
 ---- MYSQLD_DATADIR/test
 t1.frm
 t1.ibd
@@ -274,7 +277,7 @@ t7#p#p0#sp#s1.ibd
 t7#p#p1#sp#s2.ibd
 t7#p#p1#sp#s3.ibd
 #
-# Restart the server and show that tables are still visible and accessible.
+# Start the server and show that tables are still visible and accessible.
 #
 SHOW VARIABLES LIKE 'innodb_file_per_table';
 Variable_name	Value
@@ -438,7 +441,7 @@ DROP TABLE t2;
 DROP TABLE t3;
 DROP TABLE t4;
 #
-# Truncate the remote tablespace and restart.
+# Truncate the remote tablespaces.
 #
 TRUNCATE TABLE t5;
 ALTER TABLE t6 TRUNCATE PARTITION p2;
@@ -576,7 +579,7 @@ SUBPARTITION BY HASH (c1)
  (SUBPARTITION s2 DATA DIRECTORY = 'MYSQL_TMP_DIR/alt_dir' ENGINE = InnoDB,
   SUBPARTITION s3 DATA DIRECTORY = 'MYSQL_TMP_DIR/alt_dir' ENGINE = InnoDB)) */
 #
-# Rename file table and tablespace, then restart
+# Rename file table and tablespace
 #
 ---- MYSQLD_DATADIR/test
 t5.frm
@@ -762,10 +765,10 @@ SUBPARTITION BY HASH (c1)
  (SUBPARTITION s2 DATA DIRECTORY = 'MYSQL_TMP_DIR/alt_dir' ENGINE = InnoDB,
   SUBPARTITION s3 DATA DIRECTORY = 'MYSQL_TMP_DIR/alt_dir' ENGINE = InnoDB)) */
 #
-# Restart the server
+# Shutdown the server
 #
 #
-# Move the remote tablespaces to a new location and change the ISL file
+# Move the remote tablespaces to a new location and change the ISL files
 #
 ---- MYSQLD_DATADIR/test
 t55.frm
@@ -790,9 +793,10 @@ t77#p#p0#sp#s0.ibd
 t77#p#p0#sp#s1.ibd
 t77#p#p1#sp#s2.ibd
 t77#p#p1#sp#s3.ibd
-FLUSH TABLE t55,t66,t77 WITH READ LOCK;
-# Moving tablespaces from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
-UNLOCK TABLES;
+---- MYSQL_TMP_DIR/new_dir/test
+# Moving tablespace 't55' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
+# Moving tablespace 't66' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
+# Moving tablespace 't77' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
 ---- MYSQLD_DATADIR/test
 t55.frm
 t55.isl
@@ -807,6 +811,7 @@ t77#p#p1#sp#s2.isl
 t77#p#p1#sp#s3.isl
 t77.frm
 t77.par
+---- MYSQL_TMP_DIR/alt_dir/test
 ---- MYSQL_TMP_DIR/new_dir/test
 t55.ibd
 t66#p#p0.ibd
@@ -817,9 +822,8 @@ t77#p#p0#sp#s1.ibd
 t77#p#p1#sp#s2.ibd
 t77#p#p1#sp#s3.ibd
 #
-# Restart the server, remove old tablespaces and check tablespaces.
+# Start the server and check tablespaces.
 #
----- MYSQL_TMP_DIR/alt_dir/test
 SELECT path FROM information_schema.innodb_sys_datafiles ORDER BY path;
 path
 MYSQL_TMP_DIR/new_dir/test/t55.ibd
@@ -885,10 +889,10 @@ SUBPARTITION BY HASH (c1)
  (SUBPARTITION s2 DATA DIRECTORY = 'MYSQL_TMP_DIR/new_dir' ENGINE = InnoDB,
   SUBPARTITION s3 DATA DIRECTORY = 'MYSQL_TMP_DIR/new_dir' ENGINE = InnoDB)) */
 #
-# Restart the server
+# Shutdown the server
 #
 #
-# Move the remote tablespace back to the default datadir and delete the ISL file.
+# Move the remote tablespaces back to the default datadir and delete the ISL file.
 #
 ---- MYSQLD_DATADIR/test
 t55.frm
@@ -913,9 +917,9 @@ t77#p#p0#sp#s0.ibd
 t77#p#p0#sp#s1.ibd
 t77#p#p1#sp#s2.ibd
 t77#p#p1#sp#s3.ibd
-FLUSH TABLE t55,t66,t77 WITH READ LOCK;
-# Moving tablespaces from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
-UNLOCK TABLES;
+# Moving 't55' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
+# Moving 't66' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
+# Moving 't77' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
 ---- MYSQLD_DATADIR/test
 t55.frm
 t55.ibd
@@ -931,18 +935,9 @@ t77#p#p1#sp#s3.ibd
 t77.frm
 t77.par
 ---- MYSQL_TMP_DIR/new_dir/test
-t55.ibd
-t66#p#p0.ibd
-t66#p#p1.ibd
-t66#p#p2.ibd
-t77#p#p0#sp#s0.ibd
-t77#p#p0#sp#s1.ibd
-t77#p#p1#sp#s2.ibd
-t77#p#p1#sp#s3.ibd
 # 
-# Restart the server, remove old tablespaces and check tablespaces.
+# Start the server and check tablespaces.
 # 
----- MYSQL_TMP_DIR/new_dir/test
 SELECT path FROM information_schema.innodb_sys_datafiles ORDER BY path;
 path
 MYSQLD_DATADIR/test/t55.ibd

=== added file 'mysql-test/suite/innodb/r/innodb_bug13867871.result'
--- a/mysql-test/suite/innodb/r/innodb_bug13867871.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_bug13867871.result	revid:kevin.lewis@stripped20430183156-uyr7sxxgbhodbg4r
@@ -0,0 +1,31 @@
+CREATE TABLE ibtest11a (A INT, D INT, B VARCHAR(20), C VARCHAR(75), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C)) ENGINE = INNODB;
+CREATE TABLE ibtest11c (A INT, D INT, B VARCHAR(20), C VARCHAR(75), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C), FOREIGN KEY (A, D) REFERENCES ibtest11a (A, D) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT kukkuu FOREIGN KEY (B, C) REFERENCES ibtest11a (B, C) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = INNODB;
+INSERT INTO ibtest11a VALUES (1, 5, 'khD','khD');
+SET DEBUG_SYNC='foreign_constraint_check_for_ins WAIT_FOR drop_done';
+INSERT INTO ibtest11c VALUES (1, 5, 'khD','khD');
+CREATE INDEX idx1 ON ibtest11a(B, C);
+DROP INDEX B ON ibtest11a;
+SET DEBUG_SYNC='now SIGNAL drop_done';
+SET DEBUG_SYNC='foreign_constraint_check_for_update WAIT_FOR drop_done';
+DELETE FROM ibtest11a WHERE A=1;
+CREATE INDEX idx ON ibtest11c(B, C);
+DROP INDEX B ON ibtest11c;
+SET DEBUG_SYNC='now SIGNAL drop_done';
+SELECT * FROM ibtest11c;
+A	D	B	C
+SELECT * FROM ibtest11a;
+A	D	B	C
+INSERT INTO ibtest11a VALUES (1, 5, 'khD','khD');
+INSERT INTO ibtest11c VALUES (1, 5, 'khD','khD');
+SET DEBUG_SYNC='foreign_constraint_check_for_update WAIT_FOR drop_done';
+UPDATE ibtest11a SET A=2;
+ALTER TABLE ibtest11c ADD INDEX idx_2(B, C), DROP INDEX idx, ALGORITHM=INPLACE;
+SET DEBUG_SYNC='now SIGNAL drop_done';
+SELECT * FROM ibtest11c;
+A	D	B	C
+2	5	khD	khD
+SELECT * FROM ibtest11a;
+A	D	B	C
+2	5	khD	khD
+DROP TABLE ibtest11c;
+DROP TABLE ibtest11a;

=== modified file 'mysql-test/suite/innodb/r/innodb_corrupt_bit.result'
--- a/mysql-test/suite/innodb/r/innodb_corrupt_bit.result	revid:viswanatham.gudipati@stripped910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/innodb/r/innodb_corrupt_bit.result	revid:kevin.lewis@stripped30183156-uyr7sxxgbhodbg4r
@@ -40,13 +40,13 @@ test.corrupt_bit_test_ā	check	Warning	I
 test.corrupt_bit_test_ā	check	Warning	InnoDB: The B-tree of index "idxē" is corrupted.
 test.corrupt_bit_test_ā	check	error	Corrupt
 select c from corrupt_bit_test_ā;
-ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+ERROR HY000: Index corrupt_bit_test_ā is corrupted
 select z from corrupt_bit_test_ā;
-ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+ERROR HY000: Index corrupt_bit_test_ā is corrupted
 show warnings;
 Level	Code	Message
 Warning	180	InnoDB: Index "idxē" for table "test"."corrupt_bit_test_ā" is marked as corrupted
-Error	1034	Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+Error	1712	Index corrupt_bit_test_ā is corrupted
 insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
 select * from corrupt_bit_test_ā use index(primary) where a = 10001;
 a	b	c	z
@@ -63,7 +63,7 @@ test.corrupt_bit_test_ā	check	Warning	I
 test.corrupt_bit_test_ā	check	error	Corrupt
 set names utf8;
 select z from corrupt_bit_test_ā;
-ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+ERROR HY000: Index corrupt_bit_test_ā is corrupted
 drop index idxē on corrupt_bit_test_ā;
 select z from corrupt_bit_test_ā limit 10;
 z

=== modified file 'mysql-test/suite/innodb/t/innodb-restart.test'
--- a/mysql-test/suite/innodb/t/innodb-restart.test	revid:viswanatham.gudipati@strippedic6v5kvzls1lk
+++ b/mysql-test/suite/innodb/t/innodb-restart.test	revid:kevin.lewis@strippedsxxgbhodbg4r
@@ -141,7 +141,7 @@ SHOW CREATE TABLE t7;
 SELECT count(*) FROM t7;
 
 --echo #
---echo # Show these 7 tables in information_schema and list the OD files.
+--echo # Show these 7 tables in information_schema.
 --echo #
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 SELECT name,n_cols,file_format,row_format
@@ -152,6 +152,12 @@ SELECT name,file_format,row_format
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --replace_result ./ MYSQLD_DATADIR/  $MYSQLD_DATADIR MYSQLD_DATADIR  $MYSQL_TMP_DIR MYSQL_TMP_DIR
 SELECT path FROM information_schema.innodb_sys_datafiles ORDER BY path;
+
+--echo #
+--echo # Shutdown the server and list the tablespace OS files
+--echo #
+--source include/shutdown_mysqld.inc
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
@@ -162,11 +168,11 @@ SELECT path FROM information_schema.inno
 --list_files $MYSQL_TMP_DIR/alt_dir/test
 
 --echo #
---echo # Restart the server and show that tables are still visible and accessible.
+--echo # Start the server and show that tables are still visible and accessible.
 --echo #
---source include/restart_mysqld.inc
-SHOW VARIABLES LIKE 'innodb_file_per_table';
+--source include/start_mysqld.inc
 
+SHOW VARIABLES LIKE 'innodb_file_per_table';
 SHOW CREATE TABLE t1;
 SHOW CREATE TABLE t2;
 SHOW CREATE TABLE t3;
@@ -210,7 +216,7 @@ DROP TABLE t3;
 DROP TABLE t4;
 
 --echo #
---echo # Truncate the remote tablespace and restart.
+--echo # Truncate the remote tablespaces.
 --echo #
 TRUNCATE TABLE t5;
 ALTER TABLE t6 TRUNCATE PARTITION p2;
@@ -224,6 +230,7 @@ INSERT INTO t5 VALUES (1000000000, 'MySQ
 INSERT INTO t5 (SELECT 0, c2, c3, c4, c5 FROM t5);
 INSERT INTO t5 (SELECT 0, c2, c3, c4, c5 FROM t5);
 INSERT INTO t5 (SELECT 0, c2, c3, c4, c5 FROM t5);
+
 SELECT count(*) FROM t5;
 --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
 SHOW CREATE TABLE t5;
@@ -260,17 +267,20 @@ SHOW CREATE TABLE t7;
 
 
 --echo #
---echo # Rename file table and tablespace, then restart
+--echo # Rename file table and tablespace
 --echo #
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
 --echo ---- MYSQL_TMP_DIR/alt_dir/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQL_TMP_DIR/alt_dir/test
+
 RENAME TABLE t5 TO t55;
 RENAME TABLE t6 TO t66;
 RENAME TABLE t7 TO t77;
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
@@ -324,70 +334,78 @@ SELECT count(*) FROM t77;
 SHOW CREATE TABLE t77;
 
 --echo #
---echo # Restart the server
+--echo # Shutdown the server
 --echo #
---source include/restart_mysqld.inc
+--source include/shutdown_mysqld.inc
 
 --echo #
---echo # Move the remote tablespaces to a new location and change the ISL file
+--echo # Move the remote tablespaces to a new location and change the ISL files
 --echo #
+--mkdir $MYSQL_TMP_DIR/new_dir
+--mkdir $MYSQL_TMP_DIR/new_dir/test
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
 --echo ---- MYSQL_TMP_DIR/alt_dir/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQL_TMP_DIR/alt_dir/test
-FLUSH TABLE t55,t66,t77 WITH READ LOCK;
---echo # Moving tablespaces from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
---mkdir $MYSQL_TMP_DIR/new_dir
---mkdir $MYSQL_TMP_DIR/new_dir/test
+--echo ---- MYSQL_TMP_DIR/new_dir/test
+--replace_regex  /#P#/#p#/  /#SP#/#sp#/
+--list_files $MYSQL_TMP_DIR/new_dir/test
+
+--echo # Moving tablespace 't55' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t55.ibd $MYSQL_TMP_DIR/new_dir/test/t55.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t55.ibd
+--remove_file $MYSQLD_DATADIR/test/t55.isl
+--exec echo $MYSQL_TMP_DIR/new_dir/test/t55.ibd > $MYSQLD_DATADIR/test/t55.isl
+
+--echo # Moving tablespace 't66' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p0.ibd $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p1.ibd $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p2.ibd $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p0.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p1.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p2.ibd
+--remove_file $MYSQLD_DATADIR/test/t66#P#p0.isl
+--remove_file $MYSQLD_DATADIR/test/t66#P#p1.isl
+--remove_file $MYSQLD_DATADIR/test/t66#P#p2.isl
+--exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd > $MYSQLD_DATADIR/test/t66#P#p0.isl
+--exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd > $MYSQLD_DATADIR/test/t66#P#p1.isl
+--exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd > $MYSQLD_DATADIR/test/t66#P#p2.isl
+
+--echo # Moving tablespace 't77' from MYSQL_TMP_DIR/alt_dir to MYSQL_TMP_DIR/new_dir
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s0.ibd $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s0.ibd
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s1.ibd $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s1.ibd
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s2.ibd $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s2.ibd
 --copy_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s3.ibd $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s3.ibd
---remove_file $MYSQLD_DATADIR/test/t55.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p0.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p1.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p2.isl
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s0.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s1.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s2.ibd
+--remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s3.ibd
 --remove_file $MYSQLD_DATADIR/test/t77#P#p0#SP#s0.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p0#SP#s1.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p1#SP#s2.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p1#SP#s3.isl
---exec echo $MYSQL_TMP_DIR/new_dir/test/t55.ibd > $MYSQLD_DATADIR/test/t55.isl
---exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd > $MYSQLD_DATADIR/test/t66#P#p0.isl
---exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd > $MYSQLD_DATADIR/test/t66#P#p1.isl
---exec echo $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd > $MYSQLD_DATADIR/test/t66#P#p2.isl
 --exec echo $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s0.ibd > $MYSQLD_DATADIR/test/t77#P#p0#SP#s0.isl
 --exec echo $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s1.ibd > $MYSQLD_DATADIR/test/t77#P#p0#SP#s1.isl
 --exec echo $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s2.ibd > $MYSQLD_DATADIR/test/t77#P#p1#SP#s2.isl
 --exec echo $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s3.ibd > $MYSQLD_DATADIR/test/t77#P#p1#SP#s3.isl
-UNLOCK TABLES;
+
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
+--echo ---- MYSQL_TMP_DIR/alt_dir/test
+--replace_regex  /#P#/#p#/  /#SP#/#sp#/
+--list_files $MYSQL_TMP_DIR/alt_dir/test
 --echo ---- MYSQL_TMP_DIR/new_dir/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQL_TMP_DIR/new_dir/test
 
 --echo #
---echo # Restart the server, remove old tablespaces and check tablespaces.
+--echo # Start the server and check tablespaces.
 --echo #
---source include/restart_mysqld.inc
-
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t55.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p0.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p1.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t66#P#p2.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s0.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p0#SP#s1.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s2.ibd
---remove_file $MYSQL_TMP_DIR/alt_dir/test/t77#P#p1#SP#s3.ibd
---echo ---- MYSQL_TMP_DIR/alt_dir/test
---list_files $MYSQL_TMP_DIR/alt_dir/test
+--source include/start_mysqld.inc
 
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
@@ -408,39 +426,53 @@ SELECT count(*) FROM t77;
 --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
 SHOW CREATE TABLE t77;
 
+
 --echo #
---echo # Restart the server
+--echo # Shutdown the server
 --echo #
---source include/restart_mysqld.inc
+--source include/shutdown_mysqld.inc
 
 --echo #
---echo # Move the remote tablespace back to the default datadir and delete the ISL file.
+--echo # Move the remote tablespaces back to the default datadir and delete the ISL file.
 --echo #
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
 --echo ---- MYSQL_TMP_DIR/new_dir/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQL_TMP_DIR/new_dir/test
-FLUSH TABLE t55,t66,t77 WITH READ LOCK;
---echo # Moving tablespaces from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
+
+--echo # Moving 't55' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t55.ibd $MYSQLD_DATADIR/test/t55.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t55.ibd
+--remove_file $MYSQLD_DATADIR/test/t55.isl
+
+--echo # Moving 't66' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd $MYSQLD_DATADIR/test/t66#P#p0.ibd
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd $MYSQLD_DATADIR/test/t66#P#p1.ibd
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd $MYSQLD_DATADIR/test/t66#P#p2.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd
+--remove_file $MYSQLD_DATADIR/test/t66#P#p0.isl
+--remove_file $MYSQLD_DATADIR/test/t66#P#p1.isl
+--remove_file $MYSQLD_DATADIR/test/t66#P#p2.isl
+
+--echo # Moving 't77' from MYSQL_TMP_DIR/new_dir to MYSQLD_DATADIR
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s0.ibd $MYSQLD_DATADIR/test/t77#P#p0#SP#s0.ibd
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s1.ibd $MYSQLD_DATADIR/test/t77#P#p0#SP#s1.ibd
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s2.ibd $MYSQLD_DATADIR/test/t77#P#p1#SP#s2.ibd
 --copy_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s3.ibd $MYSQLD_DATADIR/test/t77#P#p1#SP#s3.ibd
---remove_file $MYSQLD_DATADIR/test/t55.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p0.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p1.isl
---remove_file $MYSQLD_DATADIR/test/t66#P#p2.isl
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s0.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s1.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s2.ibd
+--remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s3.ibd
 --remove_file $MYSQLD_DATADIR/test/t77#P#p0#SP#s0.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p0#SP#s1.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p1#SP#s2.isl
 --remove_file $MYSQLD_DATADIR/test/t77#P#p1#SP#s3.isl
-UNLOCK TABLES;
+
 --echo ---- MYSQLD_DATADIR/test
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --list_files $MYSQLD_DATADIR/test
@@ -449,20 +481,9 @@ UNLOCK TABLES;
 --list_files $MYSQL_TMP_DIR/new_dir/test
 
 --echo # 
---echo # Restart the server, remove old tablespaces and check tablespaces.
+--echo # Start the server and check tablespaces.
 --echo # 
--- source include/restart_mysqld.inc
-
---remove_file $MYSQL_TMP_DIR/new_dir/test/t55.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p0.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p1.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t66#P#p2.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s0.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p0#SP#s1.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s2.ibd
---remove_file $MYSQL_TMP_DIR/new_dir/test/t77#P#p1#SP#s3.ibd
---echo ---- MYSQL_TMP_DIR/new_dir/test
---list_files $MYSQL_TMP_DIR/new_dir/test
+-- source include/start_mysqld.inc
 
 --replace_regex  /#P#/#p#/  /#SP#/#sp#/
 --replace_result $MYSQLD_DATADIR MYSQLD_DATADIR ./ MYSQLD_DATADIR/

=== added file 'mysql-test/suite/innodb/t/innodb_bug13867871.test'
--- a/mysql-test/suite/innodb/t/innodb_bug13867871.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug13867871.test	revid:kevin.lewis@strippedg4r
@@ -0,0 +1,79 @@
+# Test for Bug 13867871 - ROW_INS_CHECK_FOREIGN_CONSTRAINT() ACCESSES
+# FREED DICT_INDEX_T
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+
+
+CREATE TABLE ibtest11a (A INT, D INT, B VARCHAR(20), C VARCHAR(75), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C)) ENGINE = INNODB;
+
+CREATE TABLE ibtest11c (A INT, D INT, B VARCHAR(20), C VARCHAR(75), PRIMARY KEY (A, D, B), INDEX (B, C), INDEX (C), FOREIGN KEY (A, D) REFERENCES ibtest11a (A, D) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT kukkuu FOREIGN KEY (B, C) REFERENCES ibtest11a (B, C) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = INNODB;
+
+INSERT INTO ibtest11a VALUES (1, 5, 'khD','khD');
+
+connect (con1,localhost,root,,);
+
+connection con1;
+
+SET DEBUG_SYNC='foreign_constraint_check_for_ins WAIT_FOR drop_done';
+--send
+INSERT INTO ibtest11c VALUES (1, 5, 'khD','khD');
+
+# drop the original FK index "B" on table ibtest11a while above
+# insert blcoked in dict_foreign_replace_index()
+connection default;
+CREATE INDEX idx1 ON ibtest11a(B, C);
+DROP INDEX B ON ibtest11a;
+SET DEBUG_SYNC='now SIGNAL drop_done';
+
+
+# Now test deleting an index on ibtest11c
+
+connection con1;
+reap;
+SET DEBUG_SYNC='foreign_constraint_check_for_update WAIT_FOR drop_done';
+--send
+DELETE FROM ibtest11a WHERE A=1;
+
+# drop the original FK index "B" on table ibtest11a while above
+# insert blcoked in dict_foreign_replace_index()
+connection default;
+CREATE INDEX idx ON ibtest11c(B, C);
+DROP INDEX B ON ibtest11c;
+SET DEBUG_SYNC='now SIGNAL drop_done';
+
+SELECT * FROM ibtest11c;
+SELECT * FROM ibtest11a;
+
+connection con1;
+reap;
+
+# Test cascade update case
+
+INSERT INTO ibtest11a VALUES (1, 5, 'khD','khD');
+
+INSERT INTO ibtest11c VALUES (1, 5, 'khD','khD');
+
+SET DEBUG_SYNC='foreign_constraint_check_for_update WAIT_FOR drop_done';
+--send
+UPDATE ibtest11a SET A=2;
+
+# drop the original FK index "idx" on table ibtest11a while above
+# insert blocked in dict_foreign_replace_index()
+connection default;
+
+ALTER TABLE ibtest11c ADD INDEX idx_2(B, C), DROP INDEX idx, ALGORITHM=INPLACE;
+
+SET DEBUG_SYNC='now SIGNAL drop_done';
+
+connection con1;
+reap;
+disconnect con1;
+
+CONNECTION default;
+SELECT * FROM ibtest11c;
+SELECT * FROM ibtest11a;
+
+DROP TABLE ibtest11c;
+DROP TABLE ibtest11a;
+
+

=== modified file 'mysql-test/suite/innodb/t/innodb_corrupt_bit.test'
--- a/mysql-test/suite/innodb/t/innodb_corrupt_bit.test	revid:viswanatham.gudipati@stripped10-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/innodb/t/innodb_corrupt_bit.test	revid:kevin.lewis@stripped83156-uyr7sxxgbhodbg4r
@@ -80,10 +80,10 @@ CREATE INDEX idx4 ON corrupt_bit_test_ā
 check table corrupt_bit_test_ā;
 
 # This selection intend to use the corrupted index. Expect to fail
--- error ER_NOT_KEYFILE
+-- error ER_INDEX_CORRUPT
 select c from corrupt_bit_test_ā;
 
--- error ER_NOT_KEYFILE
+-- error ER_INDEX_CORRUPT
 select z from corrupt_bit_test_ā;
 
 show warnings;
@@ -109,7 +109,7 @@ check table corrupt_bit_test_ā;
 
 set names utf8;
 
--- error ER_NOT_KEYFILE
+-- error ER_INDEX_CORRUPT
 select z from corrupt_bit_test_ā;
 
 # Drop the corrupted index

=== modified file 'mysql-test/suite/opt_trace/r/bugs_no_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/bugs_no_prot_all.result	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/bugs_no_prot_all.result	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -2291,6 +2291,9 @@ SELECT 1 FROM t1 WHERE 1 LIKE
                         ] /* refine_plan */
                       },
                       {
+                        "added_back_ref_condition": "((`t1`.`a` <=> 1))"
+                      },
+                      {
                         "reconsidering_access_paths_for_index_ordering": {
                           "index_order_summary": {
                             "table": "`t1`",

=== modified file 'mysql-test/suite/opt_trace/r/bugs_no_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/bugs_no_prot_none.result	revid:viswanatham.gudipati@stripped6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/bugs_no_prot_none.result	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -1732,6 +1732,9 @@ SELECT 1 FROM t1 WHERE 1 LIKE
                         ] /* refine_plan */
                       },
                       {
+                        "added_back_ref_condition": "((`t1`.`a` <=> 1))"
+                      },
+                      {
                         "reconsidering_access_paths_for_index_ordering": {
                           "index_order_summary": {
                             "table": "`t1`",

=== modified file 'mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result	revid:kevin.lewis@stripped
@@ -2291,6 +2291,9 @@ SELECT 1 FROM t1 WHERE 1 LIKE
                         ] /* refine_plan */
                       },
                       {
+                        "added_back_ref_condition": "((`t1`.`a` <=> 1))"
+                      },
+                      {
                         "reconsidering_access_paths_for_index_ordering": {
                           "index_order_summary": {
                             "table": "`t1`",

=== modified file 'mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result	revid:viswanatham.gudipati@strippedqcic6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result	revid:kevin.lewis@stripped83156-uyr7sxxgbhodbg4r
@@ -1712,6 +1712,9 @@ SELECT 1 FROM t1 WHERE 1 LIKE
                         ] /* refine_plan */
                       },
                       {
+                        "added_back_ref_condition": "((`t1`.`a` <=> 1))"
+                      },
+                      {
                         "reconsidering_access_paths_for_index_ordering": {
                           "index_order_summary": {
                             "table": "`t1`",

=== modified file 'mysql-test/suite/opt_trace/r/range_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_no_prot.result	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/range_no_prot.result	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -6100,6 +6100,9 @@ EXPLAIN SELECT * FROM t1 WHERE c1 = '1' 
             ] /* refine_plan */
           },
           {
+            "added_back_ref_condition": "((`t1`.`c1` <=> '1'))"
+          },
+          {
             "reconsidering_access_paths_for_index_ordering": {
               "index_order_summary": {
                 "table": "`t1`",

=== modified file 'mysql-test/suite/opt_trace/r/range_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_ps_prot.result	revid:viswanatham.gudipati@stripped52910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/opt_trace/r/range_ps_prot.result	revid:kevin.lewis@stripped30183156-uyr7sxxgbhodbg4r
@@ -6100,6 +6100,9 @@ EXPLAIN SELECT * FROM t1 WHERE c1 = '1' 
             ] /* refine_plan */
           },
           {
+            "added_back_ref_condition": "((`t1`.`c1` <=> '1'))"
+          },
+          {
             "reconsidering_access_paths_for_index_ordering": {
               "index_order_summary": {
                 "table": "`t1`",

=== modified file 'mysql-test/suite/rpl/r/rpl_report_port.result'
--- a/mysql-test/suite/rpl/r/rpl_report_port.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/suite/rpl/r/rpl_report_port.result	revid:kevin.lewis@stripped
@@ -6,8 +6,8 @@ Note	####	Storing MySQL user name or pas
 include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000]
 include/start_slave.inc
 [Slave restarted with the report-port set to some value]
-include/assert.inc [The value shown for the slave's port number is 9000 which is the value set for report-port.]
-include/rpl_restart_server.inc [server_number=2 parameters: --report-port=]
+include/assert.inc [The value shown for the slave's port number is user specified port number which is the value set for report-port.]
+include/rpl_restart_server.inc [server_number=2]
 include/start_slave.inc
 [Slave restarted with the report-port set to the value of slave's port number]
 include/assert.inc [The default value shown for the slave's port number is the actual port number of the slave.]

=== modified file 'mysql-test/suite/rpl/r/rpl_stm_relay_ign_space.result'
--- a/mysql-test/suite/rpl/r/rpl_stm_relay_ign_space.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/suite/rpl/r/rpl_stm_relay_ign_space.result	revid:kevin.lewis@stripped
@@ -3,6 +3,24 @@ Warnings:
 Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
 Note	####	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.
 [connection master]
-include/assert.inc [Assert that relay log space is close to the limit]
+CREATE TABLE t1 (c1 TEXT) engine=InnoDB;
+INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
+UNLOCK TABLES;
+FLUSH LOGS;
 include/diff_tables.inc [master:test.t1,slave:test.t1]
+DROP TABLE t1;
 include/rpl_end.inc

=== added file 'mysql-test/suite/rpl/t/rpl_report_port-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_report_port-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_report_port-master.opt	revid:kevin.lewis@strippeduyr7sxxgbhodbg4r
@@ -0,0 +1 @@
+--force-restart

=== modified file 'mysql-test/suite/rpl/t/rpl_report_port.test'
--- a/mysql-test/suite/rpl/t/rpl_report_port.test	revid:viswanatham.gudipati@strippeds1lk
+++ b/mysql-test/suite/rpl/t/rpl_report_port.test	revid:kevin.lewis@strippedr
@@ -38,21 +38,23 @@ connection master;
 
 # 9000 is the value of the port we should get.
 --let $report_port= query_get_value(SHOW SLAVE HOSTS, Port, 1)
---let assert_text= The value shown for the slave's port number is 9000 which is the value set for report-port.
+--let assert_text= The value shown for the slave's port number is user specified port number which is the value set for report-port.
 --let assert_cond= $report_port = "9000"
 --source include/assert.inc
 
-
 # Start the server with the report-port being passed with no value. So on SHOW SLAVE HOSTS
 # on the master the value of slave's port should be the actual value of the slave port.
+connection master;
 
 --let $rpl_server_number= 2
---let $rpl_server_parameters= --report-port=
+--let $rpl_server_parameters= 
 --source include/rpl_restart_server.inc
 
 connection slave;
 --source include/start_slave.inc
 
+connection master;
+sync_slave_with_master;
 --echo [Slave restarted with the report-port set to the value of slave's port number]
 
 connection master;

=== modified file 'mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test'
--- a/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/rpl/t/rpl_stm_relay_ign_space.test	revid:kevin.lewis@stripped
@@ -14,15 +14,16 @@
 #
 # The purpose is to show that the IO thread will honor the limits
 # while the SQL thread is not able to purge the relay logs, which did
-# not happen before this patch. In addition we assert that while
-# ignoring the limit (SQL thread needs to rotate before purging), the
-# IO thread does not do it in an uncontrolled manner.
+# not happen before this patch. 
+# It is proved that when the blocking
+# condition are removed the occupied relay log space shrinks back to
+# below the limit.
+
 
 --source include/have_binlog_format_statement.inc
 --source include/master-slave.inc
 --source include/have_innodb.inc
 
---disable_query_log
 CREATE TABLE t1 (c1 TEXT) engine=InnoDB;
 
 INSERT INTO t1 VALUES ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 
---connection slave
+--let $space_total= query_get_value(SHOW MASTER STATUS, Position, 1)
 
-# ASSERT that the IO thread waits for the SQL thread to release some 
-# space before continuing
---let $show_statement= SHOW PROCESSLIST
---let $field= State
---let $condition= LIKE 'Waiting for %'
-# before the patch (IO would have transfered everything)
-#--let $condition= = 'Waiting for master to send event'
-# after the patch (now it waits for space to be freed)
-#--let $condition= = 'Waiting for the slave SQL thread to free enough relay log space'
---source include/wait_show_condition.inc
+--connection slave
 
-# without the patch we can uncomment the following two lines and
-# watch the IO thread synchronize with the master, thus writing 
-# relay logs way over the space limit
-#--connection master
-#--source include/sync_slave_io_with_master.inc
-
-## ASSERT that the IO thread has honored the limit+few bytes required to be able to purge
---let $relay_log_space_while_sql_is_executing = query_get_value(SHOW SLAVE STATUS, Relay_Log_Space, 1)
---let $relay_log_space_limit = query_get_value(SHOW VARIABLES LIKE "relay_log_space_limit", Value, 1)
---let $assert_text= Assert that relay log space is close to the limit
---let $assert_cond= $relay_log_space_while_sql_is_executing <= $relay_log_space_limit * 1.20
---source include/assert.inc
+--let $relay_log_space_limit= `select variable_value from information_schema.global_variables where variable_name like 'relay_log_space_limit'`
+if (`select $relay_log_space_limit >= $space_total`)
+{
+    --echo *** relay_log_space_limit on the slave must be less than size of unprocessed events. ***
+    --die
+}
 
 # unlock the table and let SQL thread continue applying events
 UNLOCK TABLES;
+# make the oldest logs removable
+
+--let $count= 14
+--let $table= t1
+--source include/wait_until_rows_count.inc
+FLUSH LOGS;
+
+--disable_query_log
+# Prove the total relay log space decreases below the limit
+--let $cnt=20 # 20 seconds
+--let $relay_log_space = query_get_value(SHOW SLAVE STATUS, Relay_Log_Space, 1)
+while (`select $relay_log_space > $relay_log_space_limit`)
+{
+    --sleep 1
+    FLUSH LOGS; # SQL thread gets awakened to proceed to purge task
+    --dec $cnt
+    --let $relay_log_space = query_get_value(SHOW SLAVE STATUS, Relay_Log_Space, 1)
+    if ($cnt < 0)
+    {
+	--echo *** Failed to wait for total relay log space freed below the limit. ***
+	--die
+    }
+}
+--enable_query_log
 
 --connection master
 --sync_slave_with_master
@@ -95,7 +105,6 @@ UNLOCK TABLES;
 
 --connection master
 DROP TABLE t1;
---enable_query_log
 --sync_slave_with_master
 
 --source include/rpl_end.inc

=== modified file 'mysql-test/suite/sys_vars/r/bind_address_basic.result'
--- a/mysql-test/suite/sys_vars/r/bind_address_basic.result	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/suite/sys_vars/r/bind_address_basic.result	revid:kevin.lewis@stripped
@@ -1,27 +1,27 @@
 '#---------------------BS_STVARS_001_01----------------------#'
 SELECT COUNT(@@GLOBAL.bind_address);
 COUNT(@@GLOBAL.bind_address)
-0
-0 Expected
+1
+1 Expected
 '#---------------------BS_STVARS_001_02----------------------#'
 SET @@GLOBAL.bind_address=1;
 ERROR HY000: Variable 'bind_address' is a read only variable
 Expected error 'Read only variable'
 SELECT COUNT(@@GLOBAL.bind_address);
 COUNT(@@GLOBAL.bind_address)
-0
-0 Expected
+1
+1 Expected
 '#---------------------BS_STVARS_001_03----------------------#'
 SELECT VARIABLE_VALUE = ''
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
 WHERE VARIABLE_NAME='bind_address';
 VARIABLE_VALUE = ''
-1
-1 Expected
-SELECT COUNT(@@GLOBAL.bind_address);
-COUNT(@@GLOBAL.bind_address)
 0
 0 Expected
+SELECT COUNT(@@GLOBAL.bind_address);
+COUNT(@@GLOBAL.bind_address)
+1
+1 Expected
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
 WHERE VARIABLE_NAME='bind_address';
@@ -31,13 +31,17 @@ COUNT(VARIABLE_VALUE)
 '#---------------------BS_STVARS_001_04----------------------#'
 SELECT @@bind_address is NULL AND @@GLOBAL.bind_address is NULL;
 @@bind_address is NULL AND @@GLOBAL.bind_address is NULL
+0
+0 Expected
+SELECT @@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL;
+@@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL
 1
 1 Expected
 '#---------------------BS_STVARS_001_05----------------------#'
 SELECT COUNT(@@bind_address);
 COUNT(@@bind_address)
-0
-0 Expected
+1
+1 Expected
 SELECT COUNT(@@local.bind_address);
 ERROR HY000: Variable 'bind_address' is a GLOBAL variable
 Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +50,8 @@ ERROR HY000: Variable 'bind_address' is 
 Expected error 'Variable is a GLOBAL variable'
 SELECT COUNT(@@GLOBAL.bind_address);
 COUNT(@@GLOBAL.bind_address)
-0
-0 Expected
+1
+1 Expected
 SELECT bind_address = @@SESSION.bind_address;
 ERROR 42S22: Unknown column 'bind_address' in 'field list'
 Expected error 'Readonly variable'

=== modified file 'mysql-test/suite/sys_vars/t/bind_address_basic.test'
--- a/mysql-test/suite/sys_vars/t/bind_address_basic.test	revid:viswanatham.gudipati@strippedom-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/suite/sys_vars/t/bind_address_basic.test	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -13,7 +13,7 @@
 #   Displaying default value                                       #
 ####################################################################
 SELECT COUNT(@@GLOBAL.bind_address);
---echo 0 Expected
+--echo 1 Expected
 
 
 --echo '#---------------------BS_STVARS_001_02----------------------#'
@@ -26,7 +26,7 @@ SET @@GLOBAL.bind_address=1;
 --echo Expected error 'Read only variable'
 
 SELECT COUNT(@@GLOBAL.bind_address);
---echo 0 Expected
+--echo 1 Expected
 
 
 
@@ -39,10 +39,10 @@ SELECT COUNT(@@GLOBAL.bind_address);
 SELECT VARIABLE_VALUE = ''
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
 WHERE VARIABLE_NAME='bind_address';
---echo 1 Expected
+--echo 0 Expected
 
 SELECT COUNT(@@GLOBAL.bind_address);
---echo 0 Expected
+--echo 1 Expected
 
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
@@ -56,6 +56,9 @@ WHERE VARIABLE_NAME='bind_address';
 #  Check if accessing variable with and without GLOBAL point to same variable  #
 ################################################################################
 SELECT @@bind_address is NULL AND @@GLOBAL.bind_address is NULL;
+--echo 0 Expected
+
+SELECT @@bind_address is NOT NULL AND @@GLOBAL.bind_address is NOT NULL;
 --echo 1 Expected
 
 
@@ -66,7 +69,7 @@ SELECT @@bind_address is NULL AND @@GLOB
 ################################################################################
 
 SELECT COUNT(@@bind_address);
---echo 0 Expected
+--echo 1 Expected
 
 --Error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SELECT COUNT(@@local.bind_address);
@@ -77,7 +80,7 @@ SELECT COUNT(@@SESSION.bind_address);
 --echo Expected error 'Variable is a GLOBAL variable'
 
 SELECT COUNT(@@GLOBAL.bind_address);
---echo 0 Expected
+--echo 1 Expected
 
 --Error ER_BAD_FIELD_ERROR
 SELECT bind_address = @@SESSION.bind_address;

=== modified file 'mysql-test/t/create.test'
--- a/mysql-test/t/create.test	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/t/create.test	revid:kevin.lewis@stripped0183156-uyr7sxxgbhodbg4r
@@ -47,7 +47,7 @@ show create table `a/a`;
 create table t1 like `a/a`;
 drop table `a/a`;
 drop table `t1`;
---error 1103
+--error ER_TOO_LONG_IDENT
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int);
 --error 1059
 create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
@@ -1276,9 +1276,9 @@ drop table t1,t2;
 # Test incorrect database names
 #
 
---error 1102
+--error ER_TOO_LONG_IDENT
 CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
---error 1102
+--error ER_TOO_LONG_IDENT
 DROP DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
 
 # TODO: enable these tests when RENAME DATABASE is implemented.
@@ -1291,9 +1291,9 @@ DROP DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaa
 # RENAME DATABASE mysqltest TO aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
 # drop database mysqltest;
 
---error 1102
+--error ER_TOO_LONG_IDENT
 USE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
---error 1102
+--error ER_TOO_LONG_IDENT
 SHOW CREATE DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
 
 #
@@ -2086,3 +2086,13 @@ drop function f;
 
 --error ER_TOO_BIG_ROWSIZE
 CREATE TABLE t1 (v varchar(65535));
+
+--echo #
+--echo # Bug#11746295 - 25168: "INCORRECT TABLE NAME" INSTEAD OF "IDENTIFIER TOO
+--echo #                       LONG" IF TABLE NAME > 64 CHARACTERS
+--echo #
+
+--error ER_TOO_LONG_IDENT
+CREATE TABLE t01234567890123456789012345678901234567890123456789012345678901234567890123456789(a int);
+--error ER_TOO_LONG_IDENT
+CREATE DATABASE t01234567890123456789012345678901234567890123456789012345678901234567890123456789;

=== modified file 'mysql-test/t/ctype_create.test'
--- a/mysql-test/t/ctype_create.test	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/t/ctype_create.test	revid:kevin.lewis@stripped56-uyr7sxxgbhodbg4r
@@ -101,7 +101,7 @@ ALTER DATABASE DEFAULT CHARACTER SET lat
 
 # End of 4.1 tests
 
---error 1102
+--error ER_TOO_LONG_IDENT
 ALTER DATABASE aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa DEFAULT CHARACTER SET latin2;
 --error 1102
 ALTER DATABASE `` DEFAULT CHARACTER SET latin2;

=== modified file 'mysql-test/t/drop.test'
--- a/mysql-test/t/drop.test	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/mysql-test/t/drop.test	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -225,11 +225,11 @@ DROP DATABASE mysql_test;
 create database mysqltestbug26703;
 use mysqltestbug26703;
 create table `#mysql50#abc``def` ( id int );
---error ER_WRONG_TABLE_NAME
+--error ER_TOO_LONG_IDENT
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
 create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
---error ER_WRONG_TABLE_NAME
+--error ER_TOO_LONG_IDENT
 create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
 use test;
 drop database mysqltestbug26703;

=== modified file 'mysql-test/t/events_2.test'
--- a/mysql-test/t/events_2.test	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/t/events_2.test	revid:kevin.lewis@stripped0183156-uyr7sxxgbhodbg4r
@@ -187,7 +187,7 @@ drop event e1;
 # Test wrong syntax
 #
 
---error ER_WRONG_DB_NAME 
+--error ER_TOO_LONG_IDENT 
 SHOW EVENTS FROM aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
 --error ER_WRONG_DB_NAME
 SHOW EVENTS FROM ``;

=== modified file 'mysql-test/t/func_group_innodb.test'
--- a/mysql-test/t/func_group_innodb.test	revid:viswanatham.gudipati@stripped2910-uqcic6v5kvzls1lk
+++ b/mysql-test/t/func_group_innodb.test	revid:kevin.lewis@strippedxgbhodbg4r
@@ -133,19 +133,3 @@ DROP TABLE t1, t2;
 
 
 --echo End of 5.5 tests
-
---echo #
---echo # Bug#13723054 CRASH WITH MIN/MAX AFTER QUICK_GROUP_MIN_MAX_SELECT::NEXT_MIN
---echo #
-
-CREATE TABLE t1(a BLOB, b VARCHAR(255) CHARSET LATIN1, c INT,
-                KEY(b, c, a(765))) ENGINE=INNODB;
-INSERT INTO t1(a, b, c) VALUES ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
-
-SELECT MIN(c) FROM t1 GROUP BY b;
-EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
-
-DROP TABLE t1;
-
-
---echo End of 5.6 tests

=== added file 'mysql-test/t/func_group_innodb_16k.test'
--- a/mysql-test/t/func_group_innodb_16k.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/func_group_innodb_16k.test	revid:kevin.lewis@stripped4r
@@ -0,0 +1,18 @@
+--source include/have_innodb.inc
+--source include/have_innodb_16k.inc
+
+--echo #
+--echo # Bug#13723054 CRASH WITH MIN/MAX AFTER QUICK_GROUP_MIN_MAX_SELECT::NEXT_MIN
+--echo #
+
+CREATE TABLE t1(a BLOB, b VARCHAR(255) CHARSET LATIN1, c INT,
+                KEY(b, c, a(765))) ENGINE=INNODB;
+INSERT INTO t1(a, b, c) VALUES ('', 'a', 0), ('', 'a', null), ('', 'a', 0);
+
+SELECT MIN(c) FROM t1 GROUP BY b;
+EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
+
+DROP TABLE t1;
+
+
+--echo End of 5.6 tests

=== modified file 'mysql-test/t/func_time.test'
--- a/mysql-test/t/func_time.test	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/t/func_time.test	revid:kevin.lewis@stripped30183156-uyr7sxxgbhodbg4r
@@ -1097,6 +1097,18 @@ SELECT a, UNIX_TIMESTAMP(a), UNIX_TIMEST
 DROP TABLE t1;
 
 --echo #
+--echo # Bug#13988413 CRASH/ASSERTION AFTER INVALID MEMORY READ 
+--echo #              IN MY_USECONDS_TO_STR
+--echo #
+
+DO contains(1, if(0, coalesce(NULL), now()));
+
+CREATE TABLE t1 AS SELECT IF(0, coalesce(NULL), now(0)) + 0;
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+--echo #
 --echo # Bug#13982125 BUFFER OVERFLOW OF VARIABLE BUF IN
 --echo #              ITEM_FUNC_MAKETIME::GET_TIME
 --echo #

=== modified file 'mysql-test/t/overflow.test'
--- a/mysql-test/t/overflow.test	revid:viswanatham.gudipati@stripped
+++ b/mysql-test/t/overflow.test	revid:kevin.lewis@stripped20430183156-uyr7sxxgbhodbg4r
@@ -3,7 +3,7 @@
 
 connect (con1,localhost,root,,);
 connection con1;
---error ER_PARSE_ERROR,ER_WRONG_DB_NAME,ER_WRONG_NAME_FOR_INDEX
+--error ER_PARSE_ERROR,ER_TOO_LONG_IDENT,ER_WRONG_NAME_FOR_INDEX
 drop database AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
 connection default;
 disconnect con1;

=== modified file 'sql-common/my_time.c'
--- a/sql-common/my_time.c	revid:viswanatham.gudipati@stripped
+++ b/sql-common/my_time.c	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -1200,8 +1200,8 @@ my_system_gmt_sec(const MYSQL_TIME *t_sr
 static inline int
 my_useconds_to_str(char *to, ulong useconds, uint dec)
 {
-  DBUG_ASSERT(dec > 0 && dec <= DATETIME_MAX_DECIMALS);
-  return sprintf(to, ".%0*lu", dec,
+  DBUG_ASSERT(dec <= DATETIME_MAX_DECIMALS);
+  return sprintf(to, ".%0*lu", (int) dec,
                  useconds / (ulong) log_10_int[DATETIME_MAX_DECIMALS - dec]);
 }
 

=== modified file 'sql/datadict.cc'
--- a/sql/datadict.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/datadict.cc	revid:kevin.lewis@strippedxxgbhodbg4r
@@ -90,17 +90,21 @@ bool dd_frm_storage_engine(THD *thd, con
   DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db,
                                              table_name, MDL_SHARED));
 
-  if (check_and_convert_db_name(&db_name, FALSE))
-  {
-    my_error(ER_WRONG_DB_NAME, MYF(0), db_name.str);
+  if (check_and_convert_db_name(&db_name, FALSE) != IDENT_NAME_OK)
     return TRUE;
-  }
 
-  if (check_table_name(table_name, strlen(table_name), FALSE))
+  enum_ident_name_check ident_check_status=
+    check_table_name(table_name, strlen(table_name), FALSE);
+  if (ident_check_status == IDENT_NAME_WRONG)
   {
     my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name);
     return TRUE;
   }
+  else if (ident_check_status == IDENT_NAME_TOO_LONG)
+  {
+    my_error(ER_TOO_LONG_IDENT, MYF(0), table_name);
+    return TRUE;
+  }
 
   (void) build_table_filename(path, sizeof(path) - 1, db,
                               table_name, reg_ext, 0);

=== modified file 'sql/derror.cc'
--- a/sql/derror.cc	revid:viswanatham.gudipati@strippedic6v5kvzls1lk
+++ b/sql/derror.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -138,12 +138,12 @@ bool read_texts(const char *file_name, c
   if (mysql_file_read(file, (uchar*) head, 32, MYF(MY_NABP)))
     goto err;
   if (head[0] != (uchar) 254 || head[1] != (uchar) 254 ||
-      head[2] != 2 || head[3] != 1)
+      head[2] != 3 || head[3] != 1)
     goto err; /* purecov: inspected */
   textcount=head[4];
 
   error_message_charset_info= system_charset_info;
-  length=uint2korr(head+6); count=uint2korr(head+8);
+  length=uint4korr(head+6); count=uint4korr(head+10);
 
   if (count < error_messages)
   {
@@ -166,12 +166,12 @@ Check that the above file is the right v
   }
   buff= (uchar*) (*point + count);
 
-  if (mysql_file_read(file, buff, (size_t) count*2, MYF(MY_NABP)))
+  if (mysql_file_read(file, buff, (size_t) count*4, MYF(MY_NABP)))
     goto err;
   for (i=0, pos= buff ; i< count ; i++)
   {
-    (*point)[i]= (char*) buff+uint2korr(pos);
-    pos+=2;
+    (*point)[i]= (char*) buff+uint4korr(pos);
+    pos+=4;
   }
   if (mysql_file_read(file, buff, length, MYF(MY_NABP)))
     goto err;

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	revid:viswanatham.gudipati@stripped120427152910-uqcic6v5kvzls1lk
+++ b/sql/event_db_repository.cc	revid:kevin.lewis@strippedgbhodbg4r
@@ -416,7 +416,11 @@ Event_db_repository::index_read_for_db_f
   DBUG_ENTER("Event_db_repository::index_read_for_db_for_i_s");
 
   DBUG_PRINT("info", ("Using prefix scanning on PK"));
-  event_table->file->ha_index_init(0, 1);
+  if ((ret= event_table->file->ha_index_init(0, 1)))
+  {
+    event_table->file->print_error(ret, MYF(0));
+    DBUG_RETURN(true);
+  }
   key_info= event_table->key_info;
 
   if (key_info->key_parts == 0 ||

=== modified file 'sql/field.cc'
--- a/sql/field.cc	revid:viswanatham.gudipati@strippedk
+++ b/sql/field.cc	revid:kevin.lewis@stripped0183156-uyr7sxxgbhodbg4r
@@ -5565,7 +5565,7 @@ Field_time_common::convert_number_to_TIM
     Both number_to_time() call and negative nanoseconds value
     affect ltime->neg, hence "|=" to combine them:
   */
-  if (ltime->neg|= (nanoseconds < 0))
+  if ((ltime->neg|= (nanoseconds < 0)))
     nanoseconds= -nanoseconds;
   ltime->second_part= 0;
   return time_add_nanoseconds_with_round(ltime, nanoseconds, warnings);

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/filesort.cc	revid:kevin.lewis@strippedbg4r
@@ -658,7 +658,8 @@ static ha_rows find_all_keys(Sort_param 
   if (!quick_select)
   {
     next_pos=(uchar*) 0;			/* Find records in sequence */
-    file->ha_rnd_init(1);
+    if (file->ha_rnd_init(1))
+      DBUG_RETURN(HA_POS_ERROR);
     file->extra_opt(HA_EXTRA_CACHE,
 		    current_thd->variables.read_buff_size);
   }

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	revid:viswanatham.gudipati@strippedic6v5kvzls1lk
+++ b/sql/ha_partition.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -4761,7 +4761,6 @@ int ha_partition::index_init(uint inx, b
   file= m_file;
   do
   {
-    /* TODO RONM: Change to index_init() when code is stable */
     if (bitmap_is_set(&(m_part_info->read_partitions), (file - m_file)))
       if ((error= (*file)->ha_index_init(inx, sorted)))
       {
@@ -4800,7 +4799,6 @@ int ha_partition::index_end()
   do
   {
     int tmp;
-    /* TODO RONM: Change to index_end() when code is stable */
     if (bitmap_is_set(&(m_part_info->read_partitions), (file - m_file)))
       if ((tmp= (*file)->ha_index_end()))
         error= tmp;
@@ -7711,7 +7709,7 @@ void ha_partition::get_auto_increment(ul
       /* Only nb_desired_values = 1 makes sense */
       (*file)->get_auto_increment(offset, increment, 1,
                                  &first_value_part, &nb_reserved_values_part);
-      if (first_value_part == ~(ulonglong)(0)) // error in one partition
+      if (first_value_part == ULONGLONG_MAX) // error in one partition
       {
         *first_value= first_value_part;
         /* log that the error was between table/partition handler */

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	revid:viswanatham.gudipati@stripped5kvzls1lk
+++ b/sql/handler.cc	revid:kevin.lewis@strippedom-20120430183156-uyr7sxxgbhodbg4r
@@ -2374,52 +2374,213 @@ int handler::ha_open(TABLE *table_arg, c
   DBUG_RETURN(error);
 }
 
+
+/**
+  Close handler.
+*/
+
 int handler::ha_close(void)
 {
+  DBUG_ENTER("handler::ha_close");
 #ifdef HAVE_PSI_TABLE_INTERFACE
   PSI_CALL(close_table)(m_psi);
   m_psi= NULL; /* instrumentation handle, invalid after close_table() */
 #endif
   DBUG_ASSERT(m_psi == NULL);
   DBUG_ASSERT(m_lock_type == F_UNLCK);
-  return close();
+  DBUG_ASSERT(inited == NONE);
+  DBUG_RETURN(close());
+}
+
+
+/**
+  Initialize use of index.
+
+  @param idx     Index to use
+  @param sorted  Use sorted order
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
+int handler::ha_index_init(uint idx, bool sorted)
+{
+  int result;
+  DBUG_ENTER("ha_index_init");
+  DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == NONE);
+  if (!(result= index_init(idx, sorted)))
+    inited= INDEX;
+  end_range= NULL;
+  DBUG_RETURN(result);
+}
+
+
+/**
+  End use of index.
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
+int handler::ha_index_end()
+{
+  DBUG_ENTER("ha_index_end");
+  /* SQL HANDLER function can call this without having it locked. */
+  DBUG_ASSERT(table->open_by_handler ||
+              table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
+  inited= NONE;
+  end_range= NULL;
+  DBUG_RETURN(index_end());
+}
+
+
+/**
+  Initialize table for random read or scan.
+
+  @param scan  if true: Initialize for random scans through rnd_next()
+               if false: Initialize for random reads through rnd_pos()
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
+int handler::ha_rnd_init(bool scan)
+{
+  int result;
+  DBUG_ENTER("ha_rnd_init");
+  DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == NONE || (inited == RND && scan));
+  inited= (result= rnd_init(scan)) ? NONE : RND;
+  end_range= NULL;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  End use of random access.
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
+int handler::ha_rnd_end()
+{
+  DBUG_ENTER("ha_rnd_end");
+  /* SQL HANDLER function can call this without having it locked. */
+  DBUG_ASSERT(table->open_by_handler ||
+              table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == RND);
+  inited= NONE;
+  end_range= NULL;
+  DBUG_RETURN(rnd_end());
+}
+
+
+/**
+  Read next row via random scan.
+
+  @param buf  Buffer to read the row into
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
 int handler::ha_rnd_next(uchar *buf)
 {
   int result;
+  DBUG_ENTER("handler::ha_rnd_next");
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == RND);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
     { result= rnd_next(buf); })
-  return result;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  Read row via random scan from position.
+
+  @param[out] buf  Buffer to read the row into
+  @param      pos  Position from position() call
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Error (error code returned)
+*/
+
 int handler::ha_rnd_pos(uchar *buf, uchar *pos)
 {
   int result;
+  DBUG_ENTER("handler::ha_rnd_pos");
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  /* TODO: Find out how to solve ha_rnd_pos when finding duplicate update. */
+  /* DBUG_ASSERT(inited == RND); */
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
     { result= rnd_pos(buf, pos); })
-  return result;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  Read [part of] row via [part of] index.
+  @param[out] buf          buffer where store the data
+  @param      key          Key to search for
+  @param      keypart_map  Which part of key to use
+  @param      find_flag    Direction/condition on key usage
+
+  @returns Operation status
+    @retval  0                   Success (found a record, and function has
+                                 set table->status to 0)
+    @retval  HA_ERR_END_OF_FILE  Row not found (function has set table->status
+                                 to STATUS_NOT_FOUND)
+    @retval  != 0                Error
+
+  @note Positions an index cursor to the index specified in the handle.
+  Fetches the row if available. If the key value is null,
+  begin at the first key of the index.
+  ha_index_read_map can be restarted without calling index_end on the previous
+  index scan and without calling ha_index_init. In this case the
+  ha_index_read_map is on the same index as the previous ha_index_scan.
+  This is particularly used in conjunction with multi read ranges.
+*/
+
 int handler::ha_index_read_map(uchar *buf, const uchar *key,
                                key_part_map keypart_map,
                                enum ha_rkey_function find_flag)
 {
   int result;
+  DBUG_ENTER("handler::ha_index_read_map");
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_read_map(buf, key, keypart_map, find_flag); })
-  return result;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  Initializes an index and read it.
+
+  @see handler::ha_index_read_map.
+*/
+
 int handler::ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
                                    key_part_map keypart_map,
                                    enum ha_rkey_function find_flag)
@@ -2434,84 +2595,186 @@ int handler::ha_index_read_idx_map(uchar
   return result;
 }
 
+
+/**
+  Reads the next row via index.
+
+  @param[out] buf  Row data
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_next(uchar * buf)
 {
   int result;
+  DBUG_ENTER("handler::ha_index_next");
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_next(buf); })
-  return result;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  Reads the previous row via index.
+
+  @param[out] buf  Row data
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_prev(uchar * buf)
 {
   int result;
+  DBUG_ENTER("handler::ha_index_prev");
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_prev(buf); })
-  return result;
+  DBUG_RETURN(result);
 }
 
+
+/**
+  Reads the first row via index.
+
+  @param[out] buf  Row data
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_first(uchar * buf)
 {
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_first(buf); })
   return result;
 }
 
+
+/**
+  Reads the last row via index.
+
+  @param[out] buf  Row data
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_last(uchar * buf)
 {
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_last(buf); })
   return result;
 }
 
+
+/**
+  Reads the next same row via index.
+
+  @param[out] buf     Row data
+  @param      key     Key to search for
+  @param      keylen  Length of key
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
 {
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_next_same(buf, key, keylen); })
   return result;
 }
 
+
+
+/**
+  Read one row via index.
+
+  @param[out] buf        Row data
+  @param      key        Key to search for
+  @param      keylen     Length of key
+  @param      find_flag  Direction/condition on key usage
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_read(uchar *buf, const uchar *key, uint key_len,
                            enum ha_rkey_function find_flag)
 {
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_read(buf, key, key_len, find_flag); })
   return result;
 }
 
+
+/**
+  Reads the last row via index.
+
+  @param[out] buf        Row data
+  @param      key        Key to search for
+  @param      keylen     Length of key
+
+  @return Operation status.
+    @retval  0                   Success
+    @retval  HA_ERR_END_OF_FILE  Row not found
+    @retval  != 0                Error
+*/
+
 int handler::ha_index_read_last(uchar *buf, const uchar *key, uint key_len)
 {
   int result;
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               m_lock_type != F_UNLCK);
+  DBUG_ASSERT(inited == INDEX);
 
   MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_FETCH_ROW, active_index, 0,
     { result= index_read_last(buf, key, key_len); })
   return result;
 }
 
+
 /**
   Read first row (only) from a table.
 
@@ -2533,16 +2796,27 @@ int handler::read_first_row(uchar * buf,
   if (stats.deleted < 10 || primary_key >= MAX_KEY ||
       !(index_flags(primary_key, 0, 0) & HA_READ_ORDER))
   {
-    (void) ha_rnd_init(1);
-    while ((error= ha_rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
-    (void) ha_rnd_end();
+    if (!(error= ha_rnd_init(1)))
+    {
+      int end_error;
+      while ((error= ha_rnd_next(buf)) == HA_ERR_RECORD_DELETED)
+        /* skip deleted row */;
+      end_error= ha_rnd_end();
+      if (!error)
+        error= end_error;
+    }
   }
   else
   {
     /* Find the first row through the primary key */
-    (void) ha_index_init(primary_key, 0);
-    error= ha_index_first(buf);
-    (void) ha_index_end();
+    if (!(error= ha_index_init(primary_key, 0)))
+    {
+      int end_error;
+      error= ha_index_first(buf);
+      end_error= ha_index_end();
+      if (!error)
+        error= end_error;
+    }
   }
   DBUG_RETURN(error);
 }
@@ -2899,23 +3173,22 @@ void handler::column_bitmaps_signal()
 }
 
 
-/** @brief
+/**
   Reserves an interval of auto_increment values from the handler.
 
-  SYNOPSIS
-    get_auto_increment()
-    offset              
-    increment
-    nb_desired_values   how many values we want
-    first_value         (OUT) the first value reserved by the handler
-    nb_reserved_values  (OUT) how many values the handler reserved
+  @param       offset              offset (modulus increment)
+  @param       increment           increment between calls
+  @param       nb_desired_values   how many values we want
+  @param[out]  first_value         the first value reserved by the handler
+  @param[out]  nb_reserved_values  how many values the handler reserved
 
   offset and increment means that we want values to be of the form
   offset + N * increment, where N>=0 is integer.
-  If the function sets *first_value to ~(ulonglong)0 it means an error.
+  If the function sets *first_value to ULONGLONG_MAX it means an error.
   If the function sets *nb_reserved_values to ULONGLONG_MAX it means it has
   reserved to "positive infinite".
 */
+
 void handler::get_auto_increment(ulonglong offset, ulonglong increment,
                                  ulonglong nb_desired_values,
                                  ulonglong *first_value,
@@ -2923,12 +3196,20 @@ void handler::get_auto_increment(ulonglo
 {
   ulonglong nr;
   int error;
+  DBUG_ENTER("handler::get_auto_increment");
 
   (void) extra(HA_EXTRA_KEYREAD);
   table->mark_columns_used_by_index_no_reset(table->s->next_number_index,
                                         table->read_set);
   column_bitmaps_signal();
-  index_init(table->s->next_number_index, 1);
+  if (ha_index_init(table->s->next_number_index, 1))
+  {
+    /* This should never happen, assert in debug, and fail in release build */
+    DBUG_ASSERT(0);
+    *first_value= ULONGLONG_MAX;
+    *nb_reserved_values= 0;
+    DBUG_VOID_RETURN;
+  }
   if (table->s->next_number_keypart == 0)
   {						// Autoincrement at key-start
     error= ha_index_last(table->record[1]);
@@ -2958,13 +3239,25 @@ void handler::get_auto_increment(ulonglo
   }
 
   if (error)
-    nr=1;
+  {
+    if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND)
+    {
+      /* No entry found, start with 1. */
+      nr= 1;
+    }
+    else
+    {
+      DBUG_ASSERT(0);
+      nr= ULONGLONG_MAX;
+    }
+  }
   else
     nr= ((ulonglong) table->next_number_field->
          val_int_offset(table->s->rec_buff_length)+1);
-  index_end();
+  ha_index_end();
   (void) extra(HA_EXTRA_NO_KEYREAD);
   *first_value= nr;
+  DBUG_VOID_RETURN;
 }
 
 
@@ -3604,6 +3897,43 @@ int handler::ha_repair(THD* thd, HA_CHEC
 
 
 /**
+  Start bulk insert.
+
+  Allow the handler to optimize for multiple row insert.
+
+  @param rows  Estimated rows to insert
+*/
+
+void handler::ha_start_bulk_insert(ha_rows rows)
+{
+  DBUG_ENTER("handler::ha_start_bulk_insert");
+  DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type == F_WRLCK);
+  estimation_rows_to_insert= rows;
+  start_bulk_insert(rows);
+  DBUG_VOID_RETURN;
+}
+
+
+/**
+  End bulk insert.
+
+  @return Operation status
+    @retval 0     Success
+    @retval != 0  Failure (error code returned)
+*/
+
+int handler::ha_end_bulk_insert()
+{
+  DBUG_ENTER("handler::ha_end_bulk_insert");
+  DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
+              m_lock_type == F_WRLCK);
+  estimation_rows_to_insert= 0;
+  DBUG_RETURN(end_bulk_insert());
+}
+
+
+/**
   Bulk update row: public interface.
 
   @sa handler::bulk_update_row()
@@ -6424,7 +6754,21 @@ int handler::ha_external_lock(THD *thd, 
   DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
               ((lock_type != F_UNLCK && m_lock_type == F_UNLCK) ||
                lock_type == F_UNLCK));
-              
+  /* SQL HANDLER call locks/unlock while scanning (RND/INDEX). */
+  DBUG_ASSERT(inited == NONE || table->open_by_handler);
+#ifndef DBUG_OFF
+  /*
+    If this handler is cloned, then table->file is not this handler!
+    TODO: have an indicator in the handler to show that it is clone,
+    since table->file may point to ha_partition too...
+  */
+  if (table->key_read != 0 && table->file == this)
+  {
+    DBUG_PRINT("error", ("key_read != 0 (%d)", table->key_read));
+    table->key_read= 0;
+    DBUG_ASSERT(0);
+  }
+#endif
 
   if (MYSQL_HANDLER_RDLOCK_START_ENABLED() ||
       MYSQL_HANDLER_WRLOCK_START_ENABLED() ||

=== modified file 'sql/handler.h'
--- a/sql/handler.h	revid:viswanatham.gudipati@stripped27152910-uqcic6v5kvzls1lk
+++ b/sql/handler.h	revid:kevin.lewis@stripped
@@ -96,7 +96,7 @@ enum enum_alter_inplace_result {
 */
 #define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
 #define HA_NULL_IN_KEY         (1 << 7) /* One can have keys with NULL */
-#define HA_DUPLICATE_POS       (1 << 8)    /* ha_position() gives dup row */
+#define HA_DUPLICATE_POS       (1 << 8)    /* position() gives dup row */
 #define HA_NO_BLOBS            (1 << 9) /* Doesn't support blobs */
 #define HA_CAN_INDEX_BLOBS     (1 << 10)
 #define HA_AUTO_PART_KEY       (1 << 11) /* auto-increment in multi-part key */
@@ -1772,41 +1772,10 @@ public:
 
   int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
   int ha_close(void);
-  int ha_index_init(uint idx, bool sorted)
-  {
-    int result;
-    DBUG_ENTER("ha_index_init");
-    DBUG_ASSERT(inited==NONE);
-    if (!(result= index_init(idx, sorted)))
-      inited=INDEX;
-    end_range= NULL;
-    DBUG_RETURN(result);
-  }
-  int ha_index_end()
-  {
-    DBUG_ENTER("ha_index_end");
-    DBUG_ASSERT(inited==INDEX);
-    inited=NONE;
-    end_range= NULL;
-    DBUG_RETURN(index_end());
-  }
-  int ha_rnd_init(bool scan)
-  {
-    int result;
-    DBUG_ENTER("ha_rnd_init");
-    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
-    inited= (result= rnd_init(scan)) ? NONE: RND;
-    end_range= NULL;
-    DBUG_RETURN(result);
-  }
-  int ha_rnd_end()
-  {
-    DBUG_ENTER("ha_rnd_end");
-    DBUG_ASSERT(inited==RND);
-    inited=NONE;
-    end_range= NULL;
-    DBUG_RETURN(rnd_end());
-  }
+  int ha_index_init(uint idx, bool sorted);
+  int ha_index_end();
+  int ha_rnd_init(bool scan);
+  int ha_rnd_end();
   int ha_rnd_next(uchar *buf);
   int ha_rnd_pos(uchar * buf, uchar *pos);
   int ha_index_read_map(uchar *buf, const uchar *key,
@@ -1850,16 +1819,8 @@ public:
   /** to be actually called to get 'check()' functionality*/
   int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
   int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
-  void ha_start_bulk_insert(ha_rows rows)
-  {
-    estimation_rows_to_insert= rows;
-    start_bulk_insert(rows);
-  }
-  int ha_end_bulk_insert()
-  {
-    estimation_rows_to_insert= 0;
-    return end_bulk_insert();
-  }
+  void ha_start_bulk_insert(ha_rows rows);
+  int ha_end_bulk_insert();
   int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
                          uint *dup_key_found);
   int ha_delete_all_rows();

=== modified file 'sql/item_buff.cc'
--- a/sql/item_buff.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/item_buff.cc	revid:kevin.lewis@stripped3156-uyr7sxxgbhodbg4r
@@ -129,7 +129,7 @@ bool Cached_item_int::cmp(void)
 {
   DBUG_ENTER("Cached_item_int::cmp");
   longlong nr=item->val_int();
-  DBUG_PRINT("info", ("old: %Ld, new: %Ld", value, nr));
+  DBUG_PRINT("info", ("old: %lld, new: %lld", value, nr));
   if (null_value != item->null_value || nr != value)
   {
     null_value= item->null_value;

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/item_cmpfunc.cc	revid:kevin.lewis@stripped7sxxgbhodbg4r
@@ -2972,20 +2972,20 @@ Item_func_if::fix_length_and_dec()
   }
 
   agg_result_type(&cached_result_type, args + 1, 2);
+  cached_field_type= agg_field_type(args + 1, 2);
   maybe_null= args[1]->maybe_null || args[2]->maybe_null;
   decimals= max(args[1]->decimals, args[2]->decimals);
   unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
 
   if (cached_result_type == STRING_RESULT)
   {
-    if (agg_arg_charsets_for_string_result(collation, args + 1, 2))
+    if (count_string_result_length(cached_field_type, args + 1, 2))
       return;
   }
   else
   {
     collation.set_numeric(); // Number
   }
-  cached_field_type= agg_field_type(args + 1, 2);
 
   uint32 char_length;
   if ((cached_result_type == DECIMAL_RESULT )

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/item_cmpfunc.h	revid:kevin.lewis@strippedbhodbg4r
@@ -546,6 +546,30 @@ public:
   void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
   void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
   void set_subselect(Item_subselect *item) { subselect= item; }
+  table_map not_null_tables() const
+  {
+    /*
+      See handling of not_null_tables_cache in
+      Item_in_optimizer::fix_fields().
+
+      This item is the result of a transformation from an ALL clause
+      such as
+          left-expr < ALL(subquery)
+      into
+          <not>(left-expr >= (subquery)
+
+      An inequality usually rejects NULLs from both operands, so the
+      not_null_tables() of the inequality is the union of the
+      null-rejecting tables of both operands. However, since this is a
+      transformed ALL clause that should return true if the subquery
+      is empty (even if left-expr is NULL), it is not null rejecting
+      for left-expr. The not null tables mask for left-expr should be
+      removed, leaving only the null-rejecting tables of the
+      subquery. Item_subselect::not_null_tables() always returns 0 (no
+      null-rejecting tables). Therefore, always return 0.
+    */
+    return 0;
+  }
   bool empty_underlying_subquery();
   Item *neg_transformer(THD *thd);
 };
@@ -558,6 +582,7 @@ public:
   Item_func_nop_all(Item *a) :Item_func_not_all(a) {}
   longlong val_int();
   const char *func_name() const { return "<nop>"; }
+  table_map not_null_tables() const { return not_null_tables_cache; }
   Item *neg_transformer(THD *thd);
 };
 

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/item_subselect.cc	revid:kevin.lewis@strippedr7sxxgbhodbg4r
@@ -2597,10 +2597,18 @@ bool subselect_indexsubquery_engine::sca
   // We never need to do a table scan of the materialized table.
   DBUG_ASSERT(engine_type() != HASH_SJ_ENGINE);
 
-  if (table->file->inited)
-    table->file->ha_index_end();
+  if (table->file->inited &&
+      (error= table->file->ha_index_end()))
+  {
+    (void) report_error(table, error);
+    DBUG_RETURN(true);
+  }
  
-  table->file->ha_rnd_init(1);
+  if ((error= table->file->ha_rnd_init(1)))
+  {
+    (void) report_error(table, error);
+    DBUG_RETURN(true);
+  }
   table->file->extra_opt(HA_EXTRA_CACHE,
                          current_thd->variables.read_buff_size);
   table->null_row= 0;
@@ -2841,8 +2849,12 @@ bool subselect_indexsubquery_engine::exe
     DBUG_RETURN(scan_result);
   }
 
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->ref.key, !unique /* sorted */);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->ref.key, !unique /* sorted */)))
+  {
+    (void) report_error(table, error);
+    DBUG_RETURN(true);
+  }
   error= table->file->ha_index_read_map(table->record[0],
                                         tab->ref.key_buff,
                                         make_prev_keypart_map(tab->ref.key_parts),

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/item_timefunc.cc	revid:kevin.lewis@stripped30183156-uyr7sxxgbhodbg4r
@@ -2792,7 +2792,7 @@ bool Item_func_timediff::get_time(MYSQL_
   if (l_time1.neg != l_time2.neg)
     l_sign= -l_sign;
 
-  memset(l_time3, 0, sizeof(l_time3));
+  memset(l_time3, 0, sizeof(*l_time3));
   
   l_time3->neg= calc_time_diff(&l_time1, &l_time2, l_sign,
                                &seconds, &microseconds);

=== modified file 'sql/log.cc'
--- a/sql/log.cc	revid:viswanatham.gudipati@strippedic6v5kvzls1lk
+++ b/sql/log.cc	revid:kevin.lewis@strippedom-20120430183156-uyr7sxxgbhodbg4r
@@ -1423,7 +1423,7 @@ static int find_uniq_filename(char *name
   my_dirend(dir_info);
 
   /* check if reached the maximum possible extension number */
-  if ((max_found == MAX_LOG_UNIQUE_FN_EXT))
+  if (max_found == MAX_LOG_UNIQUE_FN_EXT)
   {
     sql_print_error("Log filename extension number exhausted: %06lu. \
 Please fix this by archiving old logs and \

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	revid:viswanatham.gudipati@strippedqcic6v5kvzls1lk
+++ b/sql/log_event.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -1316,7 +1316,8 @@ Log_event* Log_event::read_log_event(IO_
   Log_event *res=  0;
 #ifndef max_allowed_packet
   THD *thd=current_thd;
-  uint max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
+  ulong max_allowed_packet= thd ? thd->variables.max_allowed_packet :
+                                  ~(ulong)0;
 #endif
 
   ulong const max_size=
@@ -10430,9 +10431,15 @@ Rows_log_event::write_row(const Relay_lo
       DBUG_PRINT("info",("Locating offending record using ha_rnd_pos()"));
 
       if (table->file->inited && (error= table->file->ha_index_end()))
-        DBUG_RETURN(error);
+      {
+        table->file->print_error(error, MYF(0));
+        goto error;
+      }
       if ((error= table->file->ha_rnd_init(FALSE)))
-        DBUG_RETURN(error);
+      {
+        table->file->print_error(error, MYF(0));
+        goto error;
+      }
 
       error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
 
@@ -11287,14 +11294,20 @@ TABLE_SCAN:
 
       case HA_ERR_END_OF_FILE:
         if (++restart_count < 2)
-          table->file->ha_rnd_init(1);
+        {
+          if ((error= table->file->ha_rnd_init(1)))
+          {
+            table->file->print_error(error, MYF(0));
+            goto err;
+          }
+        }
         break;
 
       default:
         DBUG_PRINT("info", ("Failed to get next record"
                             " (ha_rnd_next returns %d)",error));
         table->file->print_error(error, MYF(0));
-        table->file->ha_rnd_end();
+        (void) table->file->ha_rnd_end();
         goto err;
       }
     }

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	revid:viswanatham.gudipati@stripped10-uqcic6v5kvzls1lk
+++ b/sql/log_event_old.cc	revid:kevin.lewis@stripped
@@ -729,7 +729,10 @@ static int find_and_fetch_row(TABLE *tab
     int error;
     /* We have a key: search the table using the index */
     if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE)))
+    {
+      table->file->print_error(error, MYF(0));
       DBUG_RETURN(error);
+    }
 
   /*
     Don't print debug messages when running valgrind since they can
@@ -827,7 +830,10 @@ static int find_and_fetch_row(TABLE *tab
 
     /* We don't have a key: search the table using ha_rnd_next() */
     if ((error= table->file->ha_rnd_init(1)))
+    {
+      table->file->print_error(error, MYF(0));
       return error;
+    }
 
     /* Continue until we find the right record or have made a full loop */
     do
@@ -850,14 +856,20 @@ static int find_and_fetch_row(TABLE *tab
         goto restart_ha_rnd_next;
 
       case HA_ERR_END_OF_FILE:
-  if (++restart_count < 2)
-    table->file->ha_rnd_init(1);
-  break;
+        if (++restart_count < 2)
+        {
+          if ((error= table->file->ha_rnd_init(1)))
+          {
+            table->file->print_error(error, MYF(0));
+            DBUG_RETURN(error);
+          }
+        }
+       break;
 
       default:
   table->file->print_error(error, MYF(0));
         DBUG_PRINT("info", ("Record not found"));
-        table->file->ha_rnd_end();
+        (void) table->file->ha_rnd_end();
   DBUG_RETURN(error);
       }
     }
@@ -2400,7 +2412,7 @@ int Old_rows_log_event::find_row(const R
           continue;
         DBUG_PRINT("info",("no record matching the given row found"));
         table->file->print_error(error, MYF(0));
-        table->file->ha_index_end();
+        (void) table->file->ha_index_end();
         DBUG_RETURN(error);
       }
     }
@@ -2441,7 +2453,13 @@ int Old_rows_log_event::find_row(const R
 
       case HA_ERR_END_OF_FILE:
         if (++restart_count < 2)
-          table->file->ha_rnd_init(1);
+        {
+          if ((error= table->file->ha_rnd_init(1)))
+          {
+            table->file->print_error(error, MYF(0));
+            DBUG_RETURN(error);
+          }
+        }
         break;
 
       default:

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	revid:viswanatham.gudipati@strippedm-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/opt_range.cc	revid:kevin.lewis@strippedg4r
@@ -1326,7 +1326,7 @@ int QUICK_RANGE_SELECT::init()
 {
   DBUG_ENTER("QUICK_RANGE_SELECT::init");
 
-  if (file->inited != handler::NONE)
+  if (file->inited)
     file->ha_index_or_rnd_end();
   DBUG_RETURN(FALSE);
 }
@@ -1334,7 +1334,7 @@ int QUICK_RANGE_SELECT::init()
 
 void QUICK_RANGE_SELECT::range_end()
 {
-  if (file->inited != handler::NONE)
+  if (file->inited)
     file->ha_index_or_rnd_end();
 }
 
@@ -1585,6 +1585,7 @@ failure:
 */
 int QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan(bool reuse_handler)
 {
+  int error;
   List_iterator_fast<QUICK_RANGE_SELECT> quick_it(quick_selects);
   QUICK_RANGE_SELECT* quick;
   DBUG_ENTER("QUICK_ROR_INTERSECT_SELECT::init_ror_merged_scan");
@@ -1598,8 +1599,8 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror
       There is no use of this->file. Use it for the first of merged range
       selects.
     */
-    if (quick->init_ror_merged_scan(TRUE))
-      DBUG_RETURN(1);
+    if ((error= quick->init_ror_merged_scan(TRUE)))
+      DBUG_RETURN(error);
     quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS);
   }
   while ((quick= quick_it++))
@@ -1608,8 +1609,8 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror
     const MY_BITMAP * const save_read_set= quick->head->read_set;
     const MY_BITMAP * const save_write_set= quick->head->write_set;
 #endif
-    if (quick->init_ror_merged_scan(FALSE))
-      DBUG_RETURN(1);
+    if ((error= quick->init_ror_merged_scan(FALSE)))
+      DBUG_RETURN(error);
     quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS);
     // Sets are shared by all members of "quick_selects" so must not change
     DBUG_ASSERT(quick->head->read_set == save_read_set);
@@ -1618,10 +1619,10 @@ int QUICK_ROR_INTERSECT_SELECT::init_ror
     quick->record= head->record[0];
   }
 
-  if (need_to_fetch_row && head->file->ha_rnd_init(1))
+  if (need_to_fetch_row && (error= head->file->ha_rnd_init(1)))
   {
     DBUG_PRINT("error", ("ROR index_merge rnd_init call failed"));
-    DBUG_RETURN(1);
+    DBUG_RETURN(error);
   }
   DBUG_RETURN(0);
 }
@@ -1677,7 +1678,7 @@ QUICK_ROR_INTERSECT_SELECT::~QUICK_ROR_I
   quick_selects.delete_elements();
   delete cpk_quick;
   free_root(&alloc,MYF(0));
-  if (need_to_fetch_row && head->file->inited != handler::NONE)
+  if (need_to_fetch_row && head->file->inited)
     head->file->ha_rnd_end();
   DBUG_VOID_RETURN;
 }
@@ -1781,8 +1782,8 @@ int QUICK_ROR_UNION_SELECT::reset()
   List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
   while ((quick= it++))
   {
-    if (quick->reset())
-      DBUG_RETURN(1);
+    if ((error= quick->reset()))
+      DBUG_RETURN(error);
     if ((error= quick->get_next()))
     {
       if (error == HA_ERR_END_OF_FILE)
@@ -1793,10 +1794,10 @@ int QUICK_ROR_UNION_SELECT::reset()
     queue_insert(&queue, (uchar*)quick);
   }
 
-  if (head->file->ha_rnd_init(1))
+  if ((error= head->file->ha_rnd_init(1)))
   {
     DBUG_PRINT("error", ("ROR index_merge rnd_init call failed"));
-    DBUG_RETURN(1);
+    DBUG_RETURN(error);
   }
 
   DBUG_RETURN(0);
@@ -1814,7 +1815,7 @@ QUICK_ROR_UNION_SELECT::~QUICK_ROR_UNION
   DBUG_ENTER("QUICK_ROR_UNION_SELECT::~QUICK_ROR_UNION_SELECT");
   delete_queue(&queue);
   quick_selects.delete_elements();
-  if (head->file->inited != handler::NONE)
+  if (head->file->inited)
     head->file->ha_rnd_end();
   free_root(&alloc,MYF(0));
   DBUG_VOID_RETURN;
@@ -9603,7 +9604,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
       if (!cur_quick)
         break;
 
-      if (cur_quick->file->inited != handler::NONE) 
+      if (cur_quick->file->inited) 
         cur_quick->file->ha_index_end();
       if (cur_quick->init() || cur_quick->reset())
         DBUG_RETURN(1);
@@ -9852,7 +9853,7 @@ int QUICK_RANGE_SELECT::reset()
   last_range= NULL;
   cur_range= (QUICK_RANGE**) ranges.buffer;
 
-  if (file->inited == handler::NONE)
+  if (!file->inited)
   {
     if (in_ror_merged_scan)
       head->column_bitmaps_set_no_signal(&column_bitmap, &column_bitmap);
@@ -12054,7 +12055,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::init()
 QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT()
 {
   DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT");
-  if (head->file->inited != handler::NONE) 
+  if (head->file->inited) 
     head->file->ha_index_end();
   if (min_max_arg_part)
     delete_dynamic(&min_max_ranges);

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	revid:viswanatham.gudipati@stripped2910-uqcic6v5kvzls1lk
+++ b/sql/opt_sum.cc	revid:kevin.lewis@stripped
@@ -81,7 +81,7 @@ static ulonglong get_exact_record_count(
   for (TABLE_LIST *tl= tables; tl; tl= tl->next_leaf)
   {
     ha_rows tmp= tl->table->file->records();
-    if ((tmp == HA_POS_ERROR))
+    if (tmp == HA_POS_ERROR)
       return ULONGLONG_MAX;
     count*= tmp;
   }
@@ -415,7 +415,11 @@ int opt_sum_query(THD *thd,
             const_result= 0;
             break;
           }
-          table->file->ha_index_init((uint) ref.key, 1);
+          if ((error= table->file->ha_index_init((uint) ref.key, 1)))
+          {
+            table->file->print_error(error, MYF(0));
+            DBUG_RETURN(error);
+          }
 
           error= is_max ? 
                  get_index_max_value(table, &ref, range_fl) :

=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc	revid:viswanatham.gudipati@strippedk
+++ b/sql/partition_info.cc	revid:kevin.lewis@strippedm-20120430183156-uyr7sxxgbhodbg4r
@@ -1395,12 +1395,19 @@ bool partition_info::check_partition_inf
           num_parts_not_set++;
           part_elem->engine_type= default_engine_type;
         }
-        if (check_table_name(part_elem->partition_name,
-                             strlen(part_elem->partition_name), FALSE))
+        enum_ident_name_check ident_check_status=
+          check_table_name(part_elem->partition_name,
+                           strlen(part_elem->partition_name), FALSE);
+        if (ident_check_status == IDENT_NAME_WRONG)
         {
           my_error(ER_WRONG_PARTITION_NAME, MYF(0));
           goto end;
         }
+        else if (ident_check_status == IDENT_NAME_TOO_LONG)
+        {
+          my_error(ER_TOO_LONG_IDENT, MYF(0));
+          goto end;
+        }
         DBUG_PRINT("info", ("part = %d engine = %s",
                    i, ha_resolve_storage_engine_name(part_elem->engine_type)));
       }
@@ -1414,12 +1421,19 @@ bool partition_info::check_partition_inf
         {
           sub_elem= sub_it++;
           warn_if_dir_in_part_elem(thd, sub_elem);
-          if (check_table_name(sub_elem->partition_name,
-                               strlen(sub_elem->partition_name), FALSE))
+          enum_ident_name_check ident_check_status=
+            check_table_name(sub_elem->partition_name,
+                             strlen(sub_elem->partition_name), FALSE);
+          if (ident_check_status == IDENT_NAME_WRONG)
           {
             my_error(ER_WRONG_PARTITION_NAME, MYF(0));
             goto end;
           }
+          else if (ident_check_status == IDENT_NAME_TOO_LONG)
+          {
+            my_error(ER_TOO_LONG_IDENT, MYF(0));
+            goto end;
+          }
           if (sub_elem->engine_type == NULL)
           {
             if (part_elem->engine_type != NULL)

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/rpl_slave.cc	revid:kevin.lewis@strippedyr7sxxgbhodbg4r
@@ -6993,17 +6993,9 @@ static Log_event* next_event(Relay_log_i
           }
           else
           {
-            if (rli->mts_group_status != Relay_log_info::MTS_IN_GROUP)
-            {
-              /*
-                Before to let the current relay log be purged Workers
-                have to finish off their current assignments.
-              */
-              (void) wait_for_workers_to_finish(rli);
-              rli->sql_force_rotate_relay= true;
-            }
+            rli->sql_force_rotate_relay=
+              (rli->mts_group_status != Relay_log_info::MTS_IN_GROUP);
           }
-
           /* ask for one more event */
           rli->ignore_log_space_limit= true;
         }

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/sp.cc	revid:kevin.lewis@strippedodbg4r
@@ -1470,7 +1470,12 @@ bool lock_db_routines(THD *thd, char *db
 
   table->field[MYSQL_PROC_FIELD_DB]->store(db, strlen(db), system_charset_info);
   key_len= table->key_info->key_part[0].store_length;
-  table->file->ha_index_init(0, 1);
+  if ((nxtres= table->file->ha_index_init(0, 1)))
+  {
+    table->file->print_error(nxtres, MYF(0));
+    close_system_tables(thd, &open_tables_state_backup);
+    DBUG_RETURN(true);
+  }
 
   if (! table->file->index_read_map(table->record[0],
                                     table->field[MYSQL_PROC_FIELD_DB]->ptr,
@@ -1534,7 +1539,11 @@ sp_drop_db_routines(THD *thd, char *db)
   key_len= table->key_info->key_part[0].store_length;
 
   ret= SP_OK;
-  table->file->ha_index_init(0, 1);
+  if (table->file->ha_index_init(0, 1))
+  {
+    ret= SP_KEY_NOT_FOUND;
+    goto err_idx_init;
+  }
   if (! table->file->ha_index_read_map(table->record[0],
                                        (uchar *)table->field[MYSQL_PROC_FIELD_DB]->ptr,
                                        (key_part_map)1, HA_READ_KEY_EXACT))
@@ -1562,6 +1571,7 @@ sp_drop_db_routines(THD *thd, char *db)
   }
   table->file->ha_index_end();
 
+err_idx_init:
   close_thread_tables(thd);
   /*
     Make sure to only release the MDL lock on mysql.proc, not other

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/sql_acl.cc	revid:kevin.lewis@strippeduyr7sxxgbhodbg4r
@@ -2675,7 +2675,13 @@ replace_proxies_priv_table(THD *thd, TAB
 
   get_grantor(thd, grantor);
 
-  table->file->ha_index_init(0, 1);
+  if ((error= table->file->ha_index_init(0, 1)))
+  {
+    table->file->print_error(error, MYF(0));
+    DBUG_PRINT("info", ("ha_index_init error"));
+    DBUG_RETURN(-1);
+  }
+
   if (table->file->ha_index_read_map(table->record[0], user_key,
                                      HA_WHOLE_KEY,
                                      HA_READ_KEY_EXACT))
@@ -2915,7 +2921,12 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TA
     key_copy(key, col_privs->record[0], col_privs->key_info, key_prefix_len);
     col_privs->field[4]->store("",0, &my_charset_latin1);
 
-    col_privs->file->ha_index_init(0, 1);
+    if (col_privs->file->ha_index_init(0, 1))
+    {
+      cols= 0;
+      return;
+    }
+
     if (col_privs->file->ha_index_read_map(col_privs->record[0], (uchar*) key,
                                            (key_part_map)15, HA_READ_KEY_EXACT))
     {
@@ -3073,7 +3084,11 @@ static int replace_column_table(GRANT_TA
 
   List_iterator <LEX_COLUMN> iter(columns);
   class LEX_COLUMN *column;
-  table->file->ha_index_init(0, 1);
+  if ((error= table->file->ha_index_init(0, 1)))
+  {
+    table->file->print_error(error, MYF(0));
+    DBUG_RETURN(-1);
+  }
   while ((column= iter++))
   {
     ulong privileges= column->rights;
@@ -4238,7 +4253,8 @@ static my_bool grant_load_procs_priv(TAB
   (void) my_hash_init(&func_priv_hash, &my_charset_utf8_bin,
                       0,0,0, (my_hash_get_key) get_grant_table,
                       0,0);
-  p_table->file->ha_index_init(0, 1);
+  if (p_table->file->ha_index_init(0, 1))
+    DBUG_RETURN(TRUE);
   p_table->use_all_columns();
 
   if (!p_table->file->ha_index_first(p_table->record[0]))
@@ -4339,7 +4355,8 @@ static my_bool grant_load(THD *thd, TABL
 
   t_table = tables[0].table;
   c_table = tables[1].table;
-  t_table->file->ha_index_init(0, 1);
+  if (t_table->file->ha_index_init(0, 1))
+    goto end_index_init;
   t_table->use_all_columns();
   c_table->use_all_columns();
 
@@ -4384,9 +4401,10 @@ static my_bool grant_load(THD *thd, TABL
   return_val=0;					// Return ok
 
 end_unlock:
-  thd->variables.sql_mode= old_sql_mode;
   t_table->file->ha_index_end();
   my_pthread_setspecific_ptr(THR_MALLOC, save_mem_root_ptr);
+end_index_init:
+  thd->variables.sql_mode= old_sql_mode;
   DBUG_RETURN(return_val);
 }
 

=== modified file 'sql/sql_bitmap.h'
--- a/sql/sql_bitmap.h	revid:viswanatham.gudipati@stripped-uqcic6v5kvzls1lk
+++ b/sql/sql_bitmap.h	revid:kevin.lewis@stripped
@@ -47,7 +47,7 @@ public:
   void set_prefix(uint n) { bitmap_set_prefix(&map, n); }
   void set_all() { bitmap_set_all(&map); }
   void clear_all() { bitmap_clear_all(&map); }
-  void intersect(Bitmap& map2) { bitmap_intersect(&map, &map2.map); }
+  void intersect(const Bitmap& map2) { bitmap_intersect(&map, &map2.map); }
   void intersect(ulonglong map2buff)
   {
     MY_BITMAP map2;
@@ -62,8 +62,8 @@ public:
       bitmap_set_above(&map, sizeof(ulonglong),
                        test(map2buff & (LL(1) << (sizeof(ulonglong) * 8 - 1))));
   }
-  void subtract(Bitmap& map2) { bitmap_subtract(&map, &map2.map); }
-  void merge(Bitmap& map2) { bitmap_union(&map, &map2.map); }
+  void subtract(const Bitmap& map2) { bitmap_subtract(&map, &map2.map); }
+  void merge(const Bitmap& map2) { bitmap_union(&map, &map2.map); }
   my_bool is_set(uint n) const { return bitmap_is_set(&map, n); }
   my_bool is_prefix(uint n) const { return bitmap_is_prefix(&map, n); }
   my_bool is_clear_all() const { return bitmap_is_clear_all(&map); }
@@ -129,11 +129,11 @@ public:
   }
   void set_all() { map=~(ulonglong)0; }
   void clear_all() { map=(ulonglong)0; }
-  void intersect(Bitmap<64>& map2) { map&= map2.map; }
+  void intersect(const Bitmap<64>& map2) { map&= map2.map; }
   void intersect(ulonglong map2) { map&= map2; }
   void intersect_extended(ulonglong map2) { map&= map2; }
-  void subtract(Bitmap<64>& map2) { map&= ~map2.map; }
-  void merge(Bitmap<64>& map2) { map|= map2.map; }
+  void subtract(const Bitmap<64>& map2) { map&= ~map2.map; }
+  void merge(const Bitmap<64>& map2) { map|= map2.map; }
   my_bool is_set(uint n) const { return test(map & (((ulonglong)1) << n)); }
   my_bool is_prefix(uint n) const { return map == (((ulonglong)1) << n)-1; }
   my_bool is_clear_all() const { return map == (ulonglong)0; }

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	revid:viswanatham.gudipati@strippeds1lk
+++ b/sql/sql_db.cc	revid:kevin.lewis@stripped20430183156-uyr7sxxgbhodbg4r
@@ -1502,14 +1502,12 @@ bool mysql_change_db(THD *thd, const LEX
     in this case to be sure.
   */
 
-  if (check_and_convert_db_name(&new_db_file_name, FALSE))
+  if (check_and_convert_db_name(&new_db_file_name, FALSE) != IDENT_NAME_OK)
   {
-    my_error(ER_WRONG_DB_NAME, MYF(0), new_db_file_name.str);
     my_free(new_db_file_name.str);
 
     if (force_switch)
       mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);
-
     DBUG_RETURN(TRUE);
   }
 

=== modified file 'sql/sql_executor.cc'
--- a/sql/sql_executor.cc	revid:viswanatham.gudipati@strippeduqcic6v5kvzls1lk
+++ b/sql/sql_executor.cc	revid:kevin.lewis@stripped
@@ -1594,7 +1594,13 @@ do_select(JOIN *join,List<Item> *fields,
     empty_record(table);
     if (table->group && join->tmp_table_param.sum_func_count &&
         table->s->keys && !table->file->inited)
-      table->file->ha_index_init(0, 0);
+    {
+      if ((rc= table->file->ha_index_init(0, 0)))
+      {
+        table->file->print_error(rc, MYF(0));
+        DBUG_RETURN(-1);
+      }
+    }
   }
   /* Set up select_end */
   Next_select_func end_select= setup_end_select_func(join);
@@ -2899,7 +2905,11 @@ join_read_key2(JOIN_TAB *tab, TABLE *tab
   if (!table->file->inited)
   {
     DBUG_ASSERT(!tab->sorted);  // Don't expect sort req. for single row.
-    table->file->ha_index_init(table_ref->key, tab->sorted);
+    if ((error= table->file->ha_index_init(table_ref->key, tab->sorted)))
+    {
+      (void) report_error(table, error);
+      return 1;
+    }
   }
 
   /*
@@ -2988,8 +2998,12 @@ join_read_always_key(JOIN_TAB *tab)
   TABLE *table= tab->table;
 
   /* Initialize the index first */
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->ref.key, tab->sorted);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->ref.key, tab->sorted)))
+  {
+    (void) report_error(table, error);
+    return 1;
+  }
 
   /* Perform "Late NULLs Filtering" (see internals manual for explanations) */
   TABLE_REF *ref= &tab->ref;
@@ -3025,8 +3039,12 @@ join_read_last_key(JOIN_TAB *tab)
   int error;
   TABLE *table= tab->table;
 
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->ref.key, tab->sorted);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->ref.key, tab->sorted)))
+  {
+    (void) report_error(table, error);
+    return 1;
+  }
   if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref))
     return -1;
   if ((error=table->file->index_read_last_map(table->record[0],
@@ -3199,8 +3217,12 @@ join_read_first(JOIN_TAB *tab)
   tab->read_record.record=table->record[0];
   tab->read_record.read_record=join_read_next;
 
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->index, tab->sorted);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->index, tab->sorted)))
+  {
+    (void) report_error(table, error);
+    return 1;
+  }
   if ((error= tab->table->file->ha_index_first(tab->table->record[0])))
   {
     if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
@@ -3233,8 +3255,12 @@ join_read_last(JOIN_TAB *tab)
   tab->read_record.table=table;
   tab->read_record.index=tab->index;
   tab->read_record.record=table->record[0];
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->index, tab->sorted);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->index, tab->sorted)))
+  {
+    (void) report_error(table, error);
+    return 1;
+  }
   if ((error= tab->table->file->ha_index_last(tab->table->record[0])))
     return report_error(table, error);
   return 0;
@@ -3257,8 +3283,12 @@ join_ft_read_first(JOIN_TAB *tab)
   int error;
   TABLE *table= tab->table;
 
-  if (!table->file->inited)
-    table->file->ha_index_init(tab->ref.key, tab->sorted);
+  if (!table->file->inited &&
+      (error= table->file->ha_index_init(tab->ref.key, tab->sorted)))
+  {
+    (void) report_error(table, error);
+    return 1;
+  }
   table->file->ft_init();
 
   if ((error= table->file->ft_read(table->record[0])))
@@ -3749,7 +3779,11 @@ end_update(JOIN *join, JOIN_TAB *join_ta
 				error, FALSE, NULL))
       DBUG_RETURN(NESTED_LOOP_ERROR);            // Not a table_is_full error
     /* Change method to update rows */
-    table->file->ha_index_init(0, 0);
+    if ((error= table->file->ha_index_init(0, 0)))
+    {
+      table->file->print_error(error, MYF(0));
+      DBUG_RETURN(NESTED_LOOP_ERROR);
+    }
     join->join_tab[join->tables-1].next_select=end_unique_update;
   }
   join->send_records++;
@@ -4178,7 +4212,8 @@ static int remove_dup_with_compare(THD *
   org_record=(char*) (record=table->record[0])+offset;
   new_record=(char*) table->record[1]+offset;
 
-  file->ha_rnd_init(1);
+  if ((error= file->ha_rnd_init(1)))
+    goto err;
   error=file->ha_rnd_next(record);
   for (;;)
   {
@@ -4306,7 +4341,8 @@ static int remove_dup_with_hash_index(TH
     DBUG_RETURN(1);
   }
 
-  file->ha_rnd_init(1);
+  if ((error= file->ha_rnd_init(1)))
+    goto err;
   key_pos=key_buffer;
   for (;;)
   {
@@ -4364,7 +4400,8 @@ err:
   my_free(key_buffer);
   my_hash_free(&hash);
   file->extra(HA_EXTRA_NO_CACHE);
-  (void) file->ha_rnd_end();
+  if (file->inited)
+    (void) file->ha_rnd_end();
   if (error)
     file->print_error(error,MYF(0));
   DBUG_RETURN(1);

=== modified file 'sql/sql_help.cc'
--- a/sql/sql_help.cc	revid:viswanatham.gudipati@stripped152910-uqcic6v5kvzls1lk
+++ b/sql/sql_help.cc	revid:kevin.lewis@stripped
@@ -302,8 +302,17 @@ int get_topics_for_keyword(THD *thd, TAB
   rtopic_id= find_fields[help_relation_help_topic_id].field;
   rkey_id=   find_fields[help_relation_help_keyword_id].field;
 
-  topics->file->ha_index_init(iindex_topic,1);
-  relations->file->ha_index_init(iindex_relations,1);
+  if (topics->file->ha_index_init(iindex_topic, 1))
+  {
+    my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0));
+    DBUG_RETURN(-1);
+  }
+  if (relations->file->ha_index_init(iindex_relations, 1))
+  {
+    topics->file->ha_index_end();
+    my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0));
+    DBUG_RETURN(-1);
+  }
 
   rkey_id->store((longlong) key_id, TRUE);
   rkey_id->get_key_image(buff, rkey_id->pack_length(), Field::itRAW);

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	revid:viswanatham.gudipati@stripped0120427152910-uqcic6v5kvzls1lk
+++ b/sql/sql_insert.cc	revid:kevin.lewis@strippedr
@@ -3198,9 +3198,8 @@ bool Delayed_insert::handle_inserts(void
   DBUG_RETURN(0);
 
  err:
-#ifndef DBUG_OFF
-  max_rows= 0;                                  // For DBUG output
-#endif
+  max_rows= 0;
+  mysql_mutex_lock(&mutex);
   /* Remove all not used rows */
   while ((row=rows.get()))
   {
@@ -3210,13 +3209,13 @@ bool Delayed_insert::handle_inserts(void
       free_delayed_insert_blobs(table);
     }
     delete row;
-    thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
     stacked_inserts--;
-#ifndef DBUG_OFF
     max_rows++;
-#endif
   }
+  mysql_mutex_unlock(&mutex);
   DBUG_PRINT("error", ("dropped %lu rows after an error", max_rows));
+  for (; max_rows > 0; max_rows--)
+    thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
   thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
   mysql_mutex_lock(&mutex);
   DBUG_RETURN(1);

=== modified file 'sql/sql_join_buffer.cc'
--- a/sql/sql_join_buffer.cc	revid:viswanatham.gudipati@stripped10-uqcic6v5kvzls1lk
+++ b/sql/sql_join_buffer.cc	revid:kevin.lewis@stripped
@@ -2400,8 +2400,9 @@ JOIN_CACHE_BKA::init_join_matching_recor
     Prepare to iterate over keys from the join buffer and to get
     matching candidates obtained with MMR handler functions.
   */ 
-  if (!file->inited)
-    file->ha_index_init(join_tab->ref.key, 1);
+  if (!file->inited &&
+      (error= file->ha_index_init(join_tab->ref.key, 1)))
+    return NESTED_LOOP_ERROR;
   if ((error= file->multi_range_read_init(seq_funcs, (void*) this, ranges,
 					  mrr_mode, &mrr_buff)))
     rc= error < 0 ? NESTED_LOOP_NO_MORE_ROWS: NESTED_LOOP_ERROR;

=== modified file 'sql/sql_optimizer.cc'
--- a/sql/sql_optimizer.cc	revid:viswanatham.gudipati@strippedls1lk
+++ b/sql/sql_optimizer.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -8683,13 +8683,14 @@ static bool add_ref_to_table_cond(THD *t
   {
     if (join_tab->select->cond)
       error=(int) cond->add(join_tab->select->cond);
-    join_tab->select->cond= cond;
-    join_tab->set_condition(cond, __LINE__);
+    join_tab->set_jt_and_sel_condition(cond, __LINE__);
   }
   else if ((join_tab->select= make_select(join_tab->table, 0, 0, cond, 0,
                                           &error)))
     join_tab->set_condition(cond, __LINE__);
 
+  if (join_tab->select)
+    Opt_trace_object(&thd->opt_trace).add("added_back_ref_condition", cond);
   /*
     If we have pushed parts of the select condition down to the
     storage engine we also need to add the condition for the const

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	revid:viswanatham.gudipati@stripped0120427152910-uqcic6v5kvzls1lk
+++ b/sql/sql_parse.cc	revid:kevin.lewis@stripped
@@ -1382,12 +1382,19 @@ bool dispatch_command(enum enum_server_c
     }
     thd->convert_string(&table_name, system_charset_info,
 			packet, arg_length, thd->charset());
-    if (check_table_name(table_name.str, table_name.length, FALSE))
+    enum_ident_name_check ident_check_status=
+      check_table_name(table_name.str, table_name.length, FALSE);
+    if (ident_check_status == IDENT_NAME_WRONG)
     {
       /* this is OK due to convert_string() null-terminating the string */
       my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name.str);
       break;
     }
+    else if (ident_check_status == IDENT_NAME_TOO_LONG)
+    {
+      my_error(ER_TOO_LONG_IDENT, MYF(0), table_name.str);
+      break;
+    }
     packet= arg_end + 1;
     mysql_reset_thd_for_next_command(thd);
     lex_start(thd);
@@ -1859,11 +1866,8 @@ int prepare_schema_table(THD *thd, LEX *
       schema_select_lex->table_list.first= NULL;
       db.length= strlen(db.str);
 
-      if (check_and_convert_db_name(&db, FALSE))
-      {
-        my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
+      if (check_and_convert_db_name(&db, FALSE) != IDENT_NAME_OK)
         DBUG_RETURN(1);
-      }
       break;
     }
 #endif
@@ -3671,11 +3675,8 @@ end_with_restore_list:
     HA_CREATE_INFO create_info(lex->create_info);
     char *alias;
     if (!(alias=thd->strmake(lex->name.str, lex->name.length)) ||
-        check_and_convert_db_name(&lex->name, FALSE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
+        (check_and_convert_db_name(&lex->name, FALSE) != IDENT_NAME_OK))
       break;
-    }
     /*
       If in a slave thread :
       CREATE DATABASE DB was certainly not preceded by USE DB.
@@ -3698,11 +3699,8 @@ end_with_restore_list:
   }
   case SQLCOM_DROP_DB:
   {
-    if (check_and_convert_db_name(&lex->name, FALSE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
+    if (check_and_convert_db_name(&lex->name, FALSE) != IDENT_NAME_OK)
       break;
-    }
     /*
       If in a slave thread :
       DROP DATABASE DB may not be preceded by USE DB.
@@ -3733,11 +3731,8 @@ end_with_restore_list:
       break;
     }
 #endif
-    if (check_and_convert_db_name(db, FALSE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
+    if (check_and_convert_db_name(db, FALSE) != IDENT_NAME_OK)
       break;
-    }
     if (check_access(thd, ALTER_ACL, db->str, NULL, NULL, 1, 0) ||
         check_access(thd, DROP_ACL, db->str, NULL, NULL, 1, 0) ||
         check_access(thd, CREATE_ACL, db->str, NULL, NULL, 1, 0))
@@ -3754,11 +3749,8 @@ end_with_restore_list:
   {
     LEX_STRING *db= &lex->name;
     HA_CREATE_INFO create_info(lex->create_info);
-    if (check_and_convert_db_name(db, FALSE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
+    if (check_and_convert_db_name(db, FALSE) != IDENT_NAME_OK)
       break;
-    }
     /*
       If in a slave thread :
       ALTER DATABASE DB may not be preceded by USE DB.
@@ -3782,11 +3774,8 @@ end_with_restore_list:
   {
     DBUG_EXECUTE_IF("4x_server_emul",
                     my_error(ER_UNKNOWN_ERROR, MYF(0)); goto error;);
-    if (check_and_convert_db_name(&lex->name, TRUE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
+    if (check_and_convert_db_name(&lex->name, TRUE) != IDENT_NAME_OK)
       break;
-    }
     res= mysqld_show_create_db(thd, lex->name.str, &lex->create_info);
     break;
   }
@@ -4208,11 +4197,8 @@ end_with_restore_list:
       Verify that the database name is allowed, optionally
       lowercase it.
     */
-    if (check_and_convert_db_name(&lex->sphead->m_db, FALSE))
-    {
-      my_error(ER_WRONG_DB_NAME, MYF(0), lex->sphead->m_db.str);
+    if (check_and_convert_db_name(&lex->sphead->m_db, FALSE) != IDENT_NAME_OK)
       goto create_sp_error;
-    }
 
     if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str,
                      NULL, NULL, 0, 0))
@@ -6316,19 +6302,24 @@ TABLE_LIST *st_select_lex::add_table_to_
   if (!table)
     DBUG_RETURN(0);				// End of memory
   alias_str= alias ? alias->str : table->table.str;
-  if (!test(table_options & TL_OPTION_ALIAS) && 
-      check_table_name(table->table.str, table->table.length, FALSE))
+  if (!test(table_options & TL_OPTION_ALIAS))
   {
-    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
-    DBUG_RETURN(0);
+    enum_ident_name_check ident_check_status=
+      check_table_name(table->table.str, table->table.length, FALSE);
+    if (ident_check_status == IDENT_NAME_WRONG)
+    {
+      my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
+      DBUG_RETURN(0);
+    }
+    else if (ident_check_status == IDENT_NAME_TOO_LONG)
+    {
+      my_error(ER_TOO_LONG_IDENT, MYF(0), table->table.str);
+      DBUG_RETURN(0);
+    }
   }
-
   if (table->is_derived_table() == FALSE && table->db.str &&
-      check_and_convert_db_name(&table->db, FALSE))
-  {
-    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
+      (check_and_convert_db_name(&table->db, FALSE) != IDENT_NAME_OK))
     DBUG_RETURN(0);
-  }
 
   if (!alias)					/* Alias is case sensitive */
   {

=== modified file 'sql/sql_planner.cc'
--- a/sql/sql_planner.cc	revid:viswanatham.gudipati@stripped6v5kvzls1lk
+++ b/sql/sql_planner.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -415,13 +415,31 @@ void Optimize_table_order::best_access_p
 
   Opt_trace_object trace_wrapper(trace, "best_access_path");
   Opt_trace_array trace_paths(trace, "considered_access_paths");
-  
-  loose_scan_opt.init(s, remaining_tables,
-                      // in_dups_producing_range
-                      ((idx == join->const_tables) ? false :
-                       (pos[-1].dups_producing_tables != 0)),
-                      emb_sjm_nest != NULL);
-  
+
+  {
+    /*
+      Loose-scan specific-logic:
+      - we must decide whether this is within the dups_producing range.
+      - if 'pos' is within the JOIN::positions array, then decide this
+      by using the pos[-1] entry.
+      - if 'pos' is not in the JOIN::position array then
+      in_dups_producing_range must be false (this case may occur in
+      semijoin_*_access_paths() which calls best_access_path() with 'pos'
+      allocated on the stack).
+      @todo One day Loose-scan will be considered in advance_sj_state() only,
+      outside best_access_path(), so this complicated logic will not be
+      needed.
+    */
+    const bool in_dups_producing_range=
+      (idx == join->const_tables) ?
+      false :
+      (pos == (join->positions + idx) ?
+       (pos[-1].dups_producing_tables != 0) :
+       false);
+    loose_scan_opt.init(s, remaining_tables, in_dups_producing_range,
+                        emb_sjm_nest != NULL);
+  }
+
   /*
     This isn't unlikely at all, but unlikely() cuts 6% CPU time on a 20-table
     search when s->keyuse==0, and has no cost when s->keyuse!=0.

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/sql_select.cc	revid:kevin.lewis@strippedsxxgbhodbg4r
@@ -3713,7 +3713,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
   QUICK_SELECT_I *save_quick= select ? select->quick : NULL;
   int best_key= -1;
   Item *orig_cond;
-  bool orig_cond_saved= false, ret;
+  bool orig_cond_saved= false, ret, set_up_ref_access_to_key= false;
   int changed_key= -1;
   DBUG_ENTER("test_if_skip_sort_order");
   LINT_INIT(ref_key_parts);
@@ -3815,26 +3815,13 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
       {
 	/* Found key that can be used to retrieve data in sorted order */
 	if (tab->ref.key >= 0)
-	{
+        {
           /*
-            We'll use ref access method on key new_ref_key. In general case 
-            the index search tuple for new_ref_key will be different (e.g.
-            when one index is defined as (part1, part2, ...) and another as
-            (part1, part2(N), ...) and the WHERE clause contains 
-            "part1 = const1 AND part2=const2". 
-            So we build tab->ref from scratch here.
+            We'll use ref access method on key new_ref_key. The actual change
+            is done further down in this function where we update the plan.
           */
-          Key_use *keyuse= tab->keyuse;
-          while (keyuse->key != new_ref_key && keyuse->table == tab->table)
-            keyuse++;
-
-          if (create_ref_for_key(tab->join, tab, keyuse, 
-                                 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);
-	}
+          set_up_ref_access_to_key= true;
+        }
 	else
 	{
           /*
@@ -3934,6 +3921,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
       used_key_parts= (order_direction == -1) ?
         saved_best_key_parts :  best_key_parts;
       changed_key= best_key;
+      // We will use index scan or range scan:
+      set_up_ref_access_to_key= false;
     }
     else
       goto use_filesort; 
@@ -3969,7 +3958,28 @@ check_reverse_order:                  
   */
   if (!no_changes) // We are allowed to update QEP
   {
-    if (best_key >= 0)
+    if (set_up_ref_access_to_key)
+    {
+      /*
+        We'll use ref access method on key changed_key. In general case 
+        the index search tuple for changed_ref_key will be different (e.g.
+        when one index is defined as (part1, part2, ...) and another as
+        (part1, part2(N), ...) and the WHERE clause contains 
+        "part1 = const1 AND part2=const2". 
+        So we build tab->ref from scratch here.
+      */
+      Key_use *keyuse= tab->keyuse;
+      while (keyuse->key != (uint)changed_key && keyuse->table == tab->table)
+        keyuse++;
+
+      if (create_ref_for_key(tab->join, tab, keyuse, 
+                             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 if (best_key >= 0)
     {
       bool quick_created= 
         (select && select->quick && select->quick!=save_quick);
@@ -3993,6 +4003,10 @@ check_reverse_order:                  
         table->file->ha_index_or_rnd_end();
         if (tab->join->select_options & SELECT_DESCRIBE)
         {
+          /*
+            @todo this neutralizes add_ref_to_table_cond(); as a result
+            EXPLAIN shows no "using where" though real SELECT has one.
+          */
           tab->ref.key= -1;
           tab->ref.key_parts= 0;
           if (select_limit < table->file->stats.records) 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/sql_show.cc	revid:kevin.lewis@strippedodbg4r
@@ -5254,7 +5254,11 @@ int fill_schema_proc(THD *thd, TABLE_LIS
   {
     DBUG_RETURN(1);
   }
-  proc_table->file->ha_index_init(0, 1);
+  if (proc_table->file->ha_index_init(0, 1))
+  {
+    res= 1;
+    goto err;
+  }
   if ((res= proc_table->file->ha_index_first(proc_table->record[0])))
   {
     res= (res == HA_ERR_END_OF_FILE) ? 0 : 1;
@@ -5280,7 +5284,8 @@ int fill_schema_proc(THD *thd, TABLE_LIS
   }
 
 err:
-  proc_table->file->ha_index_end();
+  if (proc_table->file->inited)
+    (void) proc_table->file->ha_index_end();
   close_system_tables(thd, &open_tables_state_backup);
   DBUG_RETURN(res);
 }

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	revid:viswanatham.gudipati@strippedc6v5kvzls1lk
+++ b/sql/sql_table.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -495,7 +495,7 @@ uint tablename_to_filename(const char *f
       a lot of places don't check the return value and expect 
       a zero terminated string.
     */  
-    if (check_table_name(to, length, TRUE))
+    if (check_table_name(to, length, TRUE) != IDENT_NAME_OK)
     {
       to[0]= 0;
       length= 0;

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	revid:viswanatham.gudipati@stripped120427152910-uqcic6v5kvzls1lk
+++ b/sql/sql_test.cc	revid:kevin.lewis@stripped
@@ -233,6 +233,7 @@ void print_keyuse_array(Opt_trace_contex
 }
 
 #ifndef DBUG_OFF
+/* purecov: begin inspected */
 
 /* 
   Print the current state during query optimization.

=== modified file 'sql/sql_time.cc'
--- a/sql/sql_time.cc	revid:viswanatham.gudipati@stripped10-uqcic6v5kvzls1lk
+++ b/sql/sql_time.cc	revid:kevin.lewis@stripped
@@ -528,7 +528,7 @@ static bool lldiv_t_to_time(lldiv_t lld,
     Both lld.quot and lld.rem can give negative result value,
     thus combine them using "|=".
   */
-  if (ltime->neg|= (lld.rem < 0))
+  if ((ltime->neg|= (lld.rem < 0)))
     lld.rem= -lld.rem;
   ltime->second_part= lld.rem / 1000;
   return time_add_nanoseconds_with_round(ltime, lld.rem % 1000, warnings);

=== modified file 'sql/sql_tmp_table.cc'
--- a/sql/sql_tmp_table.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/sql_tmp_table.cc	revid:kevin.lewis@stripped3156-uyr7sxxgbhodbg4r
@@ -1918,7 +1918,7 @@ bool create_myisam_from_heap(THD *thd, T
   TABLE new_table;
   TABLE_SHARE share;
   const char *save_proc_info;
-  int write_err;
+  int write_err= 0;
   DBUG_ENTER("create_myisam_from_heap");
 
   if (table->s->db_type() != heap_hton || 
@@ -1974,7 +1974,12 @@ bool create_myisam_from_heap(THD *thd, T
   if (table->file->indexes_are_disabled())
     new_table.file->ha_disable_indexes(HA_KEY_SWITCH_ALL);
   table->file->ha_index_or_rnd_end();
-  table->file->ha_rnd_init(1);
+  if ((write_err= table->file->ha_rnd_init(1)))
+  {
+    table->file->print_error(write_err, MYF(ME_FATALERROR));
+    write_err= 0;
+    goto err;
+  }
   if (table->no_rows)
   {
     new_table.file->extra(HA_EXTRA_NO_ROWS);
@@ -2053,9 +2058,13 @@ bool create_myisam_from_heap(THD *thd, T
   DBUG_RETURN(0);
 
  err:
-  DBUG_PRINT("error",("Got error: %d",write_err));
-  table->file->print_error(write_err, MYF(0));
-  (void) table->file->ha_rnd_end();
+  if (write_err)
+  {
+    DBUG_PRINT("error",("Got error: %d",write_err));
+    new_table.file->print_error(write_err, MYF(0));
+  }
+  if (table->file->inited)
+    (void) table->file->ha_rnd_end();
   (void) new_table.file->ha_close();
  err1:
   new_table.file->ha_delete_table(new_table.s->table_name.str);

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	revid:viswanatham.gudipati@strippedlk
+++ b/sql/sql_update.cc	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -2165,7 +2165,8 @@ int multi_update::do_updates()
     org_updated= updated;
     tmp_table= tmp_tables[cur_table->shared];
     tmp_table->file->extra(HA_EXTRA_CACHE);	// Change to read cache
-    (void) table->file->ha_rnd_init(0);
+    if ((local_error= table->file->ha_rnd_init(0)))
+      goto err;
     table->file->extra(HA_EXTRA_NO_CACHE);
 
     check_opt_it.rewind();
@@ -2290,11 +2291,16 @@ err:
   }
 
 err2:
-  (void) table->file->ha_rnd_end();
-  (void) tmp_table->file->ha_rnd_end();
+  if (table->file->inited)
+    (void) table->file->ha_rnd_end();
+  if (tmp_table->file->inited)
+    (void) tmp_table->file->ha_rnd_end();
   check_opt_it.rewind();
   while (TABLE *tbl= check_opt_it++)
-      tbl->file->ha_rnd_end();
+  {
+    if (tbl->file->inited)
+      (void) tbl->file->ha_rnd_end();
+  }
 
   if (updated != org_updated)
   {

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	revid:viswanatham.gudipati@stripped
+++ b/sql/sql_yacc.yy	revid:kevin.lewis@strippedr7sxxgbhodbg4r
@@ -2705,11 +2705,9 @@ clear_privileges:
 sp_name:
           ident '.' ident
           {
-            if (!$1.str || check_and_convert_db_name(&$1, FALSE))
-            {
-              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
+            if (!$1.str ||
+                (check_and_convert_db_name(&$1, FALSE) != IDENT_NAME_OK))
               MYSQL_YYABORT;
-            }
             if (check_routine_name(&$3))
             {
               MYSQL_YYABORT;
@@ -7455,12 +7453,21 @@ alter_list_item:
             {
               MYSQL_YYABORT;
             }
-            if (check_table_name($3->table.str,$3->table.length, FALSE) ||
-                ($3->db.str && check_and_convert_db_name(&$3->db, FALSE)))
+            enum_ident_name_check ident_check_status=
+              check_table_name($3->table.str,$3->table.length, FALSE);
+            if (ident_check_status == IDENT_NAME_WRONG)
             {
               my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str);
               MYSQL_YYABORT;
             }
+            else if (ident_check_status == IDENT_NAME_TOO_LONG)
+            {
+              my_error(ER_TOO_LONG_IDENT, MYF(0), $3->table.str);
+              MYSQL_YYABORT;
+            }
+            if ($3->db.str &&
+                (check_and_convert_db_name(&$3->db, FALSE) != IDENT_NAME_OK))
+              MYSQL_YYABORT;
             lex->name= $3->table;
             lex->alter_info.flags|= Alter_info::ALTER_RENAME;
           }
@@ -9670,11 +9677,9 @@ function_call_generic:
               version() (a vendor can specify any schema).
             */
 
-            if (!$1.str || check_and_convert_db_name(&$1, FALSE))
-            {
-              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
+            if (!$1.str ||
+                (check_and_convert_db_name(&$1, FALSE) != IDENT_NAME_OK))
               MYSQL_YYABORT;
-            }
             if (check_routine_name(&$3))
             {
               MYSQL_YYABORT;
@@ -11235,11 +11240,9 @@ drop:
             THD *thd= YYTHD;
             LEX *lex= thd->lex;
             sp_name *spname;
-            if ($4.str && check_and_convert_db_name(&$4, FALSE))
-            {
-               my_error(ER_WRONG_DB_NAME, MYF(0), $4.str);
+            if ($4.str &&
+                (check_and_convert_db_name(&$4, FALSE) != IDENT_NAME_OK))
                MYSQL_YYABORT;
-            }
             if (lex->sphead)
             {
               my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION");

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	revid:viswanatham.gudipati@stripped0-uqcic6v5kvzls1lk
+++ b/sql/sys_vars.cc	revid:kevin.lewis@stripped
@@ -536,7 +536,7 @@ static Sys_var_charptr Sys_basedir(
 static Sys_var_charptr Sys_my_bind_addr(
        "bind_address", "IP address to bind to.",
        READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG),
-       IN_FS_CHARSET, DEFAULT(0));
+       IN_FS_CHARSET, DEFAULT("0.0.0.0"));
 
 static bool fix_binlog_cache_size(sys_var *self, THD *thd, enum_var_type type)
 {

=== modified file 'sql/table.cc'
--- a/sql/table.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/sql/table.cc	revid:kevin.lewis@strippeddbg4r
@@ -2922,31 +2922,37 @@ uint calculate_key_len(TABLE *table, uin
   return length;
 }
 
-/*
+/**
   Check if database name is valid
 
-  SYNPOSIS
-    check_db_name()
-    org_name		Name of database and length
-    preserve_lettercase Preserve lettercase if true
+  @param org_name             Name of database and length
+  @param preserve_lettercase  Preserve lettercase if true
 
-  NOTES
-    If lower_case_table_names is true and preserve_lettercase is false then
-    database is converted to lower case
+  @note If lower_case_table_names is true and preserve_lettercase
+  is false then database is converted to lower case
 
-  RETURN
-    0	ok
-    1   error
+  @retval  IDENT_NAME_OK        Identifier name is Ok (Success)
+  @retval  IDENT_NAME_WRONG     Identifier name is Wrong (ER_WRONG_TABLE_NAME)
+  @retval  IDENT_NAME_TOO_LONG  Identifier name is too long if it is greater
+                                than 64 characters (ER_TOO_LONG_IDENT)
+
+  @note In case of IDENT_NAME_WRONG and IDENT_NAME_TOO_LONG, this
+  function reports an error (my_error)
 */
 
-bool check_and_convert_db_name(LEX_STRING *org_name, bool preserve_lettercase)
+enum_ident_name_check check_and_convert_db_name(LEX_STRING *org_name,
+                                                bool preserve_lettercase)
 {
   char *name= org_name->str;
   uint name_length= org_name->length;
   bool check_for_path_chars;
+  enum_ident_name_check ident_check_status;
 
   if (!name_length || name_length > NAME_LEN)
-    return 1;
+  {
+    my_error(ER_WRONG_DB_NAME, MYF(0), org_name->str);
+    return IDENT_NAME_WRONG;
+  }
 
   if ((check_for_path_chars= check_mysql50_prefix(name)))
   {
@@ -2957,28 +2963,44 @@ bool check_and_convert_db_name(LEX_STRIN
   if (!preserve_lettercase && lower_case_table_names && name != any_db)
     my_casedn_str(files_charset_info, name);
 
-  return check_table_name(name, name_length, check_for_path_chars);
+  ident_check_status= check_table_name(name, name_length, check_for_path_chars);
+  if (ident_check_status == IDENT_NAME_WRONG)
+    my_error(ER_WRONG_DB_NAME, MYF(0), org_name->str);
+  else if (ident_check_status == IDENT_NAME_TOO_LONG)
+    my_error(ER_TOO_LONG_IDENT, MYF(0), org_name->str);
+  return ident_check_status;
 }
 
 
-/*
-  Allow anything as a table name, as long as it doesn't contain an
-  ' ' at the end
-  returns 1 on error
+/**
+  Function to check if table name is valid or not. If it is invalid,
+  return appropriate error in each case to the caller.
+
+  @param name                  Table name
+  @param length                Length of table name
+  @param check_for_path_chars  Check if the table name contains path chars
+
+  @retval  IDENT_NAME_OK        Identifier name is Ok (Success)
+  @retval  IDENT_NAME_WRONG     Identifier name is Wrong (ER_WRONG_TABLE_NAME)
+  @retval  IDENT_NAME_TOO_LONG  Identifier name is too long if it is greater
+                                than 64 characters (ER_TOO_LONG_IDENT)
+
+  @note Reporting error to the user is the responsiblity of the caller.
 */
 
-bool check_table_name(const char *name, size_t length, bool check_for_path_chars)
+enum_ident_name_check check_table_name(const char *name, size_t length,
+                                       bool check_for_path_chars)
 {
   // name length in symbols
   size_t name_length= 0;
   const char *end= name+length;
   if (!length || length > NAME_LEN)
-    return 1;
+    return IDENT_NAME_WRONG;
 #if defined(USE_MB) && defined(USE_MB_IDENT)
   bool last_char_is_space= FALSE;
 #else
   if (name[length-1]==' ')
-    return 1;
+    return IDENT_NAME_WRONG;
 #endif
 
   while (name != end)
@@ -2998,15 +3020,17 @@ bool check_table_name(const char *name, 
 #endif
     if (check_for_path_chars &&
         (*name == '/' || *name == '\\' || *name == '~' || *name == FN_EXTCHAR))
-      return 1;
+      return IDENT_NAME_WRONG;
     name++;
     name_length++;
   }
 #if defined(USE_MB) && defined(USE_MB_IDENT)
-  return last_char_is_space || (name_length > NAME_CHAR_LEN);
-#else
-  return FALSE;
+  if (last_char_is_space)
+   return IDENT_NAME_WRONG;
+  else if (name_length > NAME_CHAR_LEN)
+   return IDENT_NAME_TOO_LONG;
 #endif
+  return IDENT_NAME_OK;
 }
 
 

=== modified file 'sql/table.h'
--- a/sql/table.h	revid:viswanatham.gudipati@stripped910-uqcic6v5kvzls1lk
+++ b/sql/table.h	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -84,6 +84,16 @@ enum enum_table_ref_type
   TABLE_REF_TMP_TABLE
 };
 
+/**
+ Enumerate possible status of a identifier name while determining
+ its validity
+*/
+enum enum_ident_name_check
+{
+  IDENT_NAME_OK,
+  IDENT_NAME_WRONG,
+  IDENT_NAME_TOO_LONG
+};
 
 /*************************************************************************/
 
@@ -900,7 +910,11 @@ typedef Bitmap<MAX_FIELDS> Field_map;
 struct TABLE
 {
   TABLE() {}                               /* Remove gcc warning */
-  virtual ~TABLE() {}
+  /*
+    Since TABLE instances are often cleared using memset(), do not
+    add virtual members and do not inherit from TABLE.
+    Otherwise memset() will start overwriting the vtable pointer.
+  */
 
   TABLE_SHARE	*s;
   handler	*file;
@@ -2199,9 +2213,11 @@ void free_table_share(TABLE_SHARE *share
 int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
 void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
 void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
-bool check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase);
+enum_ident_name_check check_and_convert_db_name(LEX_STRING *db,
+                                                bool preserve_lettercase);
 bool check_column_name(const char *name);
-bool check_table_name(const char *name, size_t length, bool check_for_path_chars);
+enum_ident_name_check check_table_name(const char *name, size_t length,
+                                       bool check_for_path_chars);
 int rename_file_ext(const char * from,const char * to,const char * ext);
 char *get_field(MEM_ROOT *mem, Field *field);
 bool get_field(MEM_ROOT *mem, Field *field, class String *res);

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	revid:viswanatham.gudipati@stripped
+++ b/sql/tztime.cc	revid:kevin.lewis@strippedyr7sxxgbhodbg4r
@@ -1701,12 +1701,9 @@ my_tz_init(THD *org_thd, const char *def
   }
 
   table= tz_tables[0].table;
-  /*
-    It is OK to ignore ha_index_init()/ha_index_end() return values since
-    mysql.time_zone* tables are MyISAM and these operations always succeed
-    for MyISAM.
-  */
-  (void)table->file->ha_index_init(0, 1);
+
+  if (table->file->ha_index_init(0, 1))
+    goto end_with_close;
   table->use_all_columns();
 
   tz_leapcnt= 0;
@@ -1894,12 +1891,9 @@ tz_load_from_open_tables(const String *t
   tz_tables= tz_tables->next_local;
   table->field[0]->store(tz_name->ptr(), tz_name->length(),
                          &my_charset_latin1);
-  /*
-    It is OK to ignore ha_index_init()/ha_index_end() return values since
-    mysql.time_zone* tables are MyISAM and these operations always succeed
-    for MyISAM.
-  */
-  (void)table->file->ha_index_init(0, 1);
+
+  if (table->file->ha_index_init(0, 1))
+    goto end;
 
   if (table->file->ha_index_read_map(table->record[0], table->field[0]->ptr,
                                      HA_WHOLE_KEY, HA_READ_KEY_EXACT))
@@ -1927,7 +1921,8 @@ tz_load_from_open_tables(const String *t
   table= tz_tables->table;
   tz_tables= tz_tables->next_local;
   table->field[0]->store((longlong) tzid, TRUE);
-  (void)table->file->ha_index_init(0, 1);
+  if (table->file->ha_index_init(0, 1))
+    goto end;
 
   if (table->file->ha_index_read_map(table->record[0], table->field[0]->ptr,
                                      HA_WHOLE_KEY, HA_READ_KEY_EXACT))
@@ -1954,7 +1949,8 @@ tz_load_from_open_tables(const String *t
   table= tz_tables->table;
   tz_tables= tz_tables->next_local;
   table->field[0]->store((longlong) tzid, TRUE);
-  (void)table->file->ha_index_init(0, 1);
+  if (table->file->ha_index_init(0, 1))
+    goto end;
 
   res= table->file->ha_index_read_map(table->record[0], table->field[0]->ptr,
                                       (key_part_map)1, HA_READ_KEY_EXACT);
@@ -2025,7 +2021,8 @@ tz_load_from_open_tables(const String *t
   */
   table= tz_tables->table; 
   table->field[0]->store((longlong) tzid, TRUE);
-  (void)table->file->ha_index_init(0, 1);
+  if (table->file->ha_index_init(0, 1))
+    goto end;
 
   res= table->file->ha_index_read_map(table->record[0], table->field[0]->ptr,
                                       (key_part_map)1, HA_READ_KEY_EXACT);
@@ -2160,8 +2157,8 @@ tz_load_from_open_tables(const String *t
 
 end:
 
-  if (table)
-    (void)table->file->ha_index_end();
+  if (table && table->file->inited)
+    (void) table->file->ha_index_end();
 
   DBUG_RETURN(return_val);
 }

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	revid:viswanatham.gudipati@stripped6v5kvzls1lk
+++ b/storage/csv/ha_tina.cc	revid:kevin.lewis@stripped
@@ -1417,9 +1417,9 @@ int ha_tina::rnd_end()
       DBUG_RETURN(-1);
 
     /* Open the file again */
-    if (((data_file= mysql_file_open(csv_key_file_data,
-                                     share->data_file_name,
-                                     O_RDONLY, MYF(MY_WME))) == -1))
+    if ((data_file= mysql_file_open(csv_key_file_data,
+                                    share->data_file_name,
+                                    O_RDONLY, MYF(MY_WME))) == -1)
       DBUG_RETURN(my_errno ? my_errno : -1);
     /*
       As we reopened the data file, increase share->data_file_version 

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	revid:viswanatham.gudipati@stripped6v5kvzls1lk
+++ b/storage/federated/ha_federated.cc	revid:kevin.lewis@stripped
@@ -825,7 +825,7 @@ static int parse_url(MEM_ROOT *mem_root,
         user:@hostname:port/db/table
         Then password is a null string, so set to NULL
       */
-      if ((share->password[0] == '\0'))
+      if (share->password[0] == '\0')
         share->password= NULL;
     }
     else

=== modified file 'storage/innobase/api/api0api.cc'
--- a/storage/innobase/api/api0api.cc	revid:viswanatham.gudipati@stripped
+++ b/storage/innobase/api/api0api.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -1144,7 +1144,7 @@ ib_cursor_open_index_using_name(
 {
 	dict_table_t*	table;
 	dict_index_t*	index;
-	ib_id_u64_t	index_id = 0;
+	index_id_t	index_id = 0;
 	ib_err_t	err = DB_TABLE_NOT_FOUND;
 	ib_cursor_t*	cursor = (ib_cursor_t*) ib_open_crsr;
 
@@ -2000,7 +2000,7 @@ ib_cursor_delete_row(
 
 		if (rec && !rec_get_deleted_flag(rec, page_format)) {
 			err = ib_delete_row(cursor, pcur, rec);
-		} else{
+		} else {
 			err = DB_RECORD_NOT_FOUND;
 		}
 	} else {

=== modified file 'storage/innobase/dict/dict0dict.cc'
--- a/storage/innobase/dict/dict0dict.cc	revid:viswanatham.gudipati@stripped
+++ b/storage/innobase/dict/dict0dict.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -5004,14 +5004,14 @@ dict_table_print_low(
 	fprintf(stderr,
 		"--------------------------------------\n"
 		"TABLE: name %s, id %llu, flags %lx, columns %lu,"
-		" indexes %lu, appr.rows %lu\n"
+		" indexes %lu, appr.rows " UINT64PF "\n"
 		"  COLUMNS: ",
 		table->name,
 		(ullint) table->id,
 		(ulong) table->flags,
 		(ulong) table->n_cols,
 		(ulong) UT_LIST_GET_LEN(table->indexes),
-		(ulong) table->stat_n_rows);
+		table->stat_n_rows);
 
 	for (i = 0; i < (ulint) table->n_cols; i++) {
 		dict_col_print_low(table, dict_table_get_nth_col(table, i));
@@ -5645,6 +5645,13 @@ dict_foreign_replace_index(
 
 			foreign->foreign_index = new_index;
 		}
+	}
+
+	for (foreign = UT_LIST_GET_FIRST(table->referenced_list);
+	     foreign;
+	     foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) {
+
+		dict_index_t*	new_index;
 
 		if (foreign->referenced_index == index) {
 			ut_ad(foreign->referenced_table == index->table);

=== modified file 'storage/innobase/dict/dict0load.cc'
--- a/storage/innobase/dict/dict0load.cc	revid:viswanatham.gudipati@strippedk
+++ b/storage/innobase/dict/dict0load.cc	revid:kevin.lewis@stripped
@@ -188,7 +188,7 @@ dict_print(void)
 
 	os_increment_counter_by_amount(
 		server_mutex,
-		srv_fatal_semaphore_wait_threshold, 7200/*2 hours*/);
+		srv_fatal_semaphore_wait_threshold, SRV_SEMAPHORE_WAIT_EXTENSION);
 
 	heap = mem_heap_create(1000);
 	mutex_enter(&(dict_sys->mutex));
@@ -226,7 +226,7 @@ dict_print(void)
 	/* Restore the fatal semaphore wait timeout */
 	os_decrement_counter_by_amount(
 		server_mutex,
-		srv_fatal_semaphore_wait_threshold, 7200/*2 hours*/);
+		srv_fatal_semaphore_wait_threshold, SRV_SEMAPHORE_WAIT_EXTENSION);
 }
 
 /********************************************************************//**
@@ -2142,7 +2142,7 @@ dict_save_data_dir_path(
 
 	/* Be sure this filepath is not the default filepath. */
 	char*	default_filepath = fil_make_ibd_name(table->name, FALSE);
-	if (!strcmp(filepath, default_filepath)) {
+	if (strcmp(filepath, default_filepath)) {
 		ulint pathlen = strlen(filepath);
 		ut_a(pathlen < OS_FILE_MAX_PATH);
 		ut_a(0 == strcmp(filepath + pathlen - 4, ".ibd"));
@@ -2437,6 +2437,7 @@ dict_load_table_on_id(
 	sys_table_ids = dict_table_get_next_index(
 		dict_table_get_first_index(sys_tables));
 	ut_ad(!dict_table_is_comp(sys_tables));
+	ut_ad(!dict_index_is_clust(sys_table_ids));
 	heap = mem_heap_create(256);
 
 	tuple  = dtuple_create(heap, 1);
@@ -2832,6 +2833,7 @@ dict_load_foreigns(
 
 	sec_index = dict_table_get_next_index(
 		dict_table_get_first_index(sys_foreign));
+	ut_ad(!dict_index_is_clust(sec_index));
 start_load:
 
 	tuple = dtuple_create_from_mem(tuple_buf, sizeof(tuple_buf), 1);

=== modified file 'storage/innobase/fil/fil0fil.cc'
--- a/storage/innobase/fil/fil0fil.cc	revid:viswanatham.gudipati@strippedls1lk
+++ b/storage/innobase/fil/fil0fil.cc	revid:kevin.lewis@stripped
@@ -1497,6 +1497,8 @@ fil_space_get_space(
 	if (space->size == 0 && space->purpose == FIL_TABLESPACE) {
 		ut_a(id != 0);
 
+		/* The following code must change when InnoDB supports
+		multiple datafiles per tablespace. */
 		ut_a(1 == UT_LIST_GET_LEN(space->chain));
 
 		node = UT_LIST_GET_FIRST(space->chain);
@@ -1813,7 +1815,7 @@ fil_set_max_space_id_if_bigger(
 Writes the flushed lsn and the latest archived log number to the page header
 of the first page of a data file of the system tablespace (space 0),
 which is uncompressed. */
-static __attribute__((nonnull, warn_unused_result))
+static __attribute__((warn_unused_result))
 dberr_t
 fil_write_lsn_and_arch_no_to_file(
 /*==============================*/
@@ -1994,7 +1996,7 @@ fil_inc_pending_ops(
 
 	if (space == NULL) {
 		fprintf(stderr,
-			"InnoDB: Error: trying to do ibuf merge to a"
+			"InnoDB: Error: trying to do an operation on a"
 			" dropped tablespace %lu\n",
 			(ulong) id);
 	}
@@ -2230,7 +2232,6 @@ fil_op_log_parse_or_replay(
 	}
 	*/
 	if (!space_id) {
-
 		return(ptr);
 	}
 
@@ -2290,11 +2291,6 @@ fil_op_log_parse_or_replay(
 		} else {
 			const char*	path = NULL;
 
-			if (log_flags & MLOG_FILE_FLAG_TEMP) {
-				path = name;
-				/* TODO: name is not available. */
-			}
-
 			/* Create the database directory for name, if it does
 			not exist yet */
 			fil_create_directory_for_tablename(name);
@@ -2399,7 +2395,7 @@ try_again:
 
 	space->is_being_deleted = TRUE;
 
-	/* TODO: The following code must change when InnoDB supports
+	/* The following code must change when InnoDB supports
 	multiple datafiles per tablespace. */
 	ut_a(UT_LIST_GET_LEN(space->chain) == 1);
 
@@ -2744,6 +2740,8 @@ retry:
 
 	space->stop_ios = TRUE;
 
+	/* The following code must change when InnoDB supports
+	multiple datafiles per tablespace. */
 	ut_a(UT_LIST_GET_LEN(space->chain) == 1);
 	node = UT_LIST_GET_FIRST(space->chain);
 
@@ -2973,7 +2971,7 @@ fil_open_linked_file(
 
 	/* A link file existed, make sure it is not the file we are
 	already using. */
-	if (strcmp(filepath, *remote_filepath) == 0) {
+	if (filepath && strcmp(filepath, *remote_filepath) == 0) {
 		mem_free(*remote_filepath);
 		*remote_filepath = NULL;
 		return (FALSE);
@@ -3479,107 +3477,111 @@ fil_open_single_table_tablespace(
 					databasename/tablename format */
 	const char*	path_in)	/*!< in: tablespace filepath */
 {
-	os_file_t	file;
-	char*		filepath;
-	ibool		success;
 	ulint		err;
-	lsn_t		space_lsn;
-	ulint		space_id;
-	ulint		space_flags;
+	os_file_t	def_file;
+	char*		def_filepath;
+	ibool		def_success = FALSE;
+	lsn_t		def_lsn;
+	ulint		def_id;
+	ulint		def_flags;
+	os_file_t	dict_file;
+	char*		dict_filepath = NULL;
+	ibool		dict_success = FALSE;
+	lsn_t		dict_lsn;
+	ulint		dict_id;
+	ulint		dict_flags;
 	os_file_t	remote_file;
-	char*		remote_filepath;
+	char*		remote_filepath = NULL;
 	ibool		remote_success = FALSE;
 	lsn_t		remote_lsn;
 	ulint		remote_id;
 	ulint		remote_flags;
+	ulint		tablespaces_found = 0;
 #ifdef UNIV_LOG_ARCHIVE
 	ulint		space_arch_log_no;
 	ulint		remote_arch_log_no;
 #endif /* UNIV_LOG_ARCHIVE */
 
-	/* Discover the filepath. */
-	if (path_in) {
-		filepath = mem_strdup(path_in);
-	} else {
-		filepath = fil_make_ibd_name(tablename, FALSE);
-	}
-
 	fsp_flags_validate(flags);
 
-	/* check_space_id is FALSE when we know that the filepath
-	sent in is the right one.  If we need to check, look first
-	for a link file and a remote tablespace. If the filepath
-	is the same as the remote_filepath in the link file, then
-	this call returns false. */
-	if (check_space_id) {
-		remote_success = fil_open_linked_file(
-			tablename, filepath, &remote_filepath, &remote_file);
+	/* Discover the correct filepath.  We will always look for a ibd
+	in the default location. If it is remote, it should not also be
+	here. */
+	def_filepath = fil_make_ibd_name(tablename, FALSE);
+
+	/* The path_in was probably read from SYS_DATAFILES. */
+	if (path_in && strcmp(def_filepath, path_in)) {
+		dict_filepath = mem_strdup(path_in);
+		check_space_id = true;	/* possibility of multiple files. */
 	}
 
-	/* Attempt to open the tablespace at the filepath given.
-	If check_space_id is false, this could be the remote tablespace
-	as read from SYS_DATAFILES.  Most likely, it is the filepath to
-	the normal datadir. */
-	file = os_file_create_simple_no_error_handling(
-		innodb_file_data_key, filepath, OS_FILE_OPEN,
-		OS_FILE_READ_ONLY, &success);
-
-	if (!success && !remote_success) {
-		/* The following call prints an error message */
-		err = os_file_get_last_error(TRUE);
-
-		ut_print_timestamp(stderr);
-
-		fputs("  InnoDB: Error: trying to open a table,"
-		      " but could not\n"
-		      "InnoDB: open the tablespace file ", stderr);
-		ut_print_filename(stderr, filepath);
-		fputs("!\n"
-		      "InnoDB: Have you moved InnoDB .ibd files around"
-		      " without using the\n"
-		      "InnoDB: commands DISCARD TABLESPACE and"
-		      " IMPORT TABLESPACE?\n"
-		      "InnoDB: It is also possible that this is"
-		      " a temporary table #sql...,\n"
-		      "InnoDB: and MySQL removed the .ibd file for this.\n"
-		      "InnoDB: Please refer to\n"
-		      "InnoDB: " REFMAN
-		      "innodb-troubleshooting-datadict.html\n"
-		      "InnoDB: for how to resolve the issue.\n", stderr);
+	remote_success = fil_open_linked_file(
+		tablename, NULL, &remote_filepath, &remote_file);
+	if (remote_success) {
+		check_space_id = true;	/* possibility of multiple files. */
+		tablespaces_found++;
 
-		mem_free(filepath);
+		/* A link file was found. It should not be the same
+		as the default filepath. */
+		if (0 == strcmp(def_filepath, remote_filepath)) {
+			mem_free(def_filepath);
+			def_filepath = NULL;
+		}
 
-		return(FALSE);
+		/* If there was a filepath found in SYS_DATAFILES,
+		we hope it was the same as this remote_filepath found
+		in the ISL file. */
+		if (dict_filepath
+		    && (0 == strcmp(dict_filepath, remote_filepath))) {
+			mem_free(dict_filepath);
+			dict_filepath = NULL;
+		}
 	}
 
-	if (!check_space_id) {
-		space_id = id;
+	/* Attempt to open the tablespace at other possible filepaths. */
+	if (dict_filepath) {
+		dict_file = os_file_create_simple_no_error_handling(
+			innodb_file_data_key, dict_filepath, OS_FILE_OPEN,
+			OS_FILE_READ_ONLY, &dict_success);
+		if (dict_success) {
+			tablespaces_found++;
+		}
+	}
+	if (def_filepath) {
+		def_file = os_file_create_simple_no_error_handling(
+			innodb_file_data_key, def_filepath, OS_FILE_OPEN,
+			OS_FILE_READ_ONLY, &def_success);
+		if (def_success) {
+			tablespaces_found++;
+		}
+	}
 
+	/*  We have now checked alll possible tablesapce locations and
+	have a count of how many we found.  If things are normal, we
+	only found 1. */
+	if (!check_space_id && tablespaces_found == 1) {
 		goto skip_check;
 	}
 
-	/* Read the first page of the datadir tablespace */
-	if (success) {
+	/* Read the first page of the datadir tablespace, if found. */
+	if (def_success) {
 		fil_read_first_page(
-			file, FALSE, &space_flags, &space_id,
+			def_file, FALSE, &def_flags, &def_id,
 #ifdef UNIV_LOG_ARCHIVE
 			&space_arch_log_no, &space_arch_log_no,
 #endif /* UNIV_LOG_ARCHIVE */
-			&space_lsn, &space_lsn);
+			&def_lsn, &def_lsn);
 
 		/* Validate this single-table-tablespace with SYS_TABLES */
-		if (space_id != id || space_flags != flags) {
+		if (def_id != id || def_flags != flags) {
 			/* Do not use this tablespace. */
 			fil_report_bad_tablespace(
-				filepath, space_id,
-				space_flags, id, flags);
-			success = FALSE;
-			os_file_close(file);
-			mem_free(filepath);
-
-			if (!remote_success) {
-				goto func_exit;
-			}
+				def_filepath, def_id,
+				def_flags, id, flags);
+			def_success = FALSE;
+			os_file_close(def_file);
+			mem_free(def_filepath);
+			tablespaces_found--;
 		}
 	}
 
@@ -3601,58 +3603,127 @@ fil_open_single_table_tablespace(
 			remote_success = FALSE;
 			os_file_close(remote_file);
 			mem_free(remote_filepath);
-			if (success) {
-				goto skip_check;
-			} else {
-				goto func_exit;
-			}
+			tablespaces_found--;
 		}
+	}
 
-		if (success) {
-			/* Figure out which tablespace is newer. */
-			if (space_lsn > remote_lsn) {
-				/* Skip the remote tablespace */
-				remote_success = FALSE;
-				os_file_close(remote_file);
-				mem_free(remote_filepath);
-			} else {
-				/* Use the remote tablespace instead. */
-				success = FALSE;
-				os_file_close(file);
-				mem_free(filepath);
-			}
+	/* Read the first page of the datadir tablespace, if found. */
+	if (dict_success) {
+		fil_read_first_page(
+			dict_file, FALSE, &dict_flags, &dict_id,
+#ifdef UNIV_LOG_ARCHIVE
+			&space_arch_log_no, &space_arch_log_no,
+#endif /* UNIV_LOG_ARCHIVE */
+			&dict_lsn, &dict_lsn);
+
+		/* Validate this single-table-tablespace with SYS_TABLES */
+		if (dict_id != id || dict_flags != flags) {
+			/* Do not use this tablespace. */
+			fil_report_bad_tablespace(
+				dict_filepath, dict_id,
+				dict_flags, id, flags);
+			dict_success = FALSE;
+			os_file_close(dict_file);
+			mem_free(dict_filepath);
+			tablespaces_found--;
 		}
 	}
 
-skip_check:
-	/* At this point, there should be only one filepath. */
-	ut_a(success != remote_success);
+	/* Make sense of these three possible locations.
+	First, bail out if no tablespace files were found. */
+	if (tablespaces_found == 0) {
+		/* The following call prints an error message */
+		err = os_file_get_last_error(TRUE);
 
-	success = fil_space_create(
-		tablename, space_id, flags, FIL_TABLESPACE);
+		ut_print_timestamp(stderr);
 
-	if (!success) {
-		goto func_exit;
+		fputs("  InnoDB: Error: trying to open a table,"
+		      " but could not\n"
+		      "InnoDB: open the tablespace file ", stderr);
+		ut_print_filename(stderr, def_filepath);
+		fputs("!\n"
+		      "InnoDB: Have you moved InnoDB .ibd files around"
+		      " without using the\n"
+		      "InnoDB: commands DISCARD TABLESPACE and"
+		      " IMPORT TABLESPACE?\n"
+		      "InnoDB: It is also possible that this is"
+		      " a temporary table #sql...,\n"
+		      "InnoDB: and MySQL removed the .ibd file for this.\n"
+		      "InnoDB: Please refer to\n"
+		      "InnoDB: " REFMAN
+		      "innodb-troubleshooting-datadict.html\n"
+		      "InnoDB: for how to resolve the issue.\n", stderr);
+
+		mem_free(def_filepath);
+
+		return(FALSE);
 	}
 
-	/* We do not measure the size of the file, that is why we pass
-	the 0 below */
+	/* An bail out if more than one tablespace with the correct
+	space ID and flags were found. */
+	if (tablespaces_found > 1) {
+		fprintf(stderr,
+			"InnoDB: Error: A tablespace for %s "
+			"has been found in multiple places;\n",
+			tablename);
+		if (def_success) {
+			fprintf(stderr,
+				"InnoDB: %s, LSN=" LSN_PF "\n",
+				def_filepath, def_lsn);
+			os_file_close(def_file);
+			mem_free(def_filepath);
+		}
+		if (remote_success) {
+			fprintf(stderr,
+				"InnoDB: %s, LSN=" LSN_PF "\n",
+				remote_filepath, remote_lsn);
+			os_file_close(remote_file);
+			mem_free(remote_filepath);
+		}
+		if (dict_success) {
+			fprintf(stderr,
+				"InnoDB: %s, LSN=" LSN_PF "\n",
+				dict_filepath, dict_lsn);
+			os_file_close(dict_file);
+			mem_free(dict_filepath);
+		}
+		fprintf(stderr,
+			"InnoDB: Error: The tablespace for %s "
+			"will not be opened.\n",
+			tablename);
+
+		return(FALSE);
+	}
 
-	fil_node_create(remote_success ? remote_filepath : filepath,
-			0, space_id, FALSE);
+skip_check:
+	/* At this point, there should be only one filepath. */
+	ut_a(tablespaces_found == 1);
 
-func_exit:
+	ibool fil_space_success = fil_space_create(
+		tablename, id, flags, FIL_TABLESPACE);
 
-	if (success) {
-		os_file_close(file);
-		mem_free(filepath);
+	/* We do not measure the size of the file, that is why we pass
+	the 0 below */
+	if (fil_space_success) {
+		fil_node_create(remote_success ? remote_filepath :
+				dict_success ? dict_filepath :
+				def_filepath, 0, id, FALSE);
+	}
+
+	if (def_success) {
+		os_file_close(def_file);
+		mem_free(def_filepath);
 	}
 	if (remote_success) {
 		os_file_close(remote_file);
 		mem_free(remote_filepath);
 	}
+	if (dict_success) {
+		os_file_close(dict_file);
+		mem_free(dict_filepath);
+	}
 
-	return(success || remote_success);
+	return(fil_space_success);
 }
 #endif /* !UNIV_HOTBACKUP */
 
@@ -3691,26 +3762,23 @@ fil_load_single_table_tablespace(
 	const char*	filename)	/*!< in: file name (not a path),
 					including the .ibd or .isl extension */
 {
-	os_file_t	file;
-	os_file_t	remote_file;
-	char*		filepath;
-	char*		remote_filepath;
 	char*		tablename;
 	ulint		tablename_len;
 	ulint		dbname_len = strlen(dbname);
 	ulint		filename_len = strlen(filename);
-	ibool		success;
+	ibool		def_success;
+	os_file_t	def_file;
+	char*		def_filepath;
+	lsn_t		def_lsn;
+	ulint		def_id;
+	ulint		def_flags;
 	ibool		remote_success;
-	byte*		buf2;
-	byte*		page;
-	ulint		flags;
-	os_offset_t	size;
-	lsn_t		space_lsn;
+	os_file_t	remote_file;
+	char*		remote_filepath;
 	lsn_t		remote_lsn;
-	ulint		space_id;
 	ulint		remote_id;
-	ulint		space_flags;
 	ulint		remote_flags;
+	os_offset_t	size;
 #ifdef UNIV_LOG_ARCHIVE
 	ulint		space_arch_log_no;
 	ulint		remote_arch_log_no;
@@ -3743,12 +3811,13 @@ fil_load_single_table_tablespace(
 	mutex_exit(&fil_system->mutex);
 
 	/* Build up the filepath of the .ibd tablespace in the datadir */
-	filepath = static_cast<char*>(
+	def_filepath = fil_make_ibd_name(tablename, FALSE);
+	def_filepath = static_cast<char*>(
 		mem_alloc(strlen(fil_path_to_mysql_datadir)
 			  + tablename_len + sizeof "/.ibd"));
-	sprintf(filepath, "%s/%s.ibd",
+	sprintf(def_filepath, "%s/%s.ibd",
 		fil_path_to_mysql_datadir, tablename);
-	srv_normalize_path_for_win(filepath);
+	srv_normalize_path_for_win(def_filepath);
 
 #ifdef __WIN__
 # ifndef UNIV_HOTBACKUP
@@ -3758,23 +3827,23 @@ fil_load_single_table_tablespace(
 	file path to lower case, so that we are consistent with InnoDB's
 	internal data dictionary. */
 
-	dict_casedn_str(filepath);
+	dict_casedn_str(def_filepath);
 # endif /* !UNIV_HOTBACKUP */
 #endif
 
 	/* Check for a link file which locates a remote tablespace. */
 	remote_success = fil_open_linked_file(
-		tablename, filepath, &remote_filepath, &remote_file);
+		tablename, def_filepath, &remote_filepath, &remote_file);
 
 	/* Try to open the tablespace in the datadir. */
-	file = os_file_create_simple_no_error_handling(
-		innodb_file_data_key, filepath, OS_FILE_OPEN,
-		OS_FILE_READ_ONLY, &success);
+	def_file = os_file_create_simple_no_error_handling(
+		innodb_file_data_key, def_filepath, OS_FILE_OPEN,
+		OS_FILE_READ_ONLY, &def_success);
 
-	if (!success && !remote_success) {
+	if (!def_success && !remote_success) {
 		/* The following call prints an error message */
 		os_file_get_last_error(TRUE);
-
+no_good_file:
 		fprintf(stderr,
 			"InnoDB: Error: could not open single-table"
 			" tablespace file\n"
@@ -3798,10 +3867,11 @@ fil_load_single_table_tablespace(
 			"InnoDB: the .ibd file, you can set"
 			" innodb_force_recovery > 0 in my.cnf\n"
 			"InnoDB: and force InnoDB to continue crash"
-			" recovery here.\n", filepath);
+			" recovery here.\n", def_filepath);
 
+		mem_free(def_filepath);
+cannot_use_table:
 		mem_free(tablename);
-		mem_free(filepath);
 
 		if (srv_force_recovery > 0) {
 			fprintf(stderr,
@@ -3816,14 +3886,43 @@ fil_load_single_table_tablespace(
 		exit(1);
 	}
 
+	if (def_success && remote_success) {
+		fprintf(stderr,
+			"InnoDB: Tablespaces for %s "
+			"have been found in two places;\n"
+			"InnoDB: 1: %s\n"
+			"InnoDB: 2: %s\n",
+			tablename, def_filepath, remote_filepath);
+
+		if (global_mode_is_strict()) {
+			def_success = FALSE;
+			remote_success = FALSE;
+			os_file_close(def_file);
+			os_file_close(remote_file);
+			mem_free(def_filepath);
+			mem_free(remote_filepath);
+			goto cannot_use_table;
+		}
+	}
+
 	/* Read the first page of the datadir tablespace */
-	if (success) {
+	if (def_success) {
 		fil_read_first_page(
-			file, FALSE, &space_flags, &space_id,
+			def_file, FALSE, &def_flags, &def_id,
 #ifdef UNIV_LOG_ARCHIVE
 			&space_arch_log_no, &space_arch_log_no,
 #endif /* UNIV_LOG_ARCHIVE */
-			&space_lsn, &space_lsn);
+			&def_lsn, &def_lsn);
+
+		if (def_id == ULINT_UNDEFINED || def_id == 0) {
+			fprintf(stderr,
+			"InnoDB: Error: tablespace id %lu in file %s"
+			" is not sensible\n",
+			(ulong) def_id, def_filepath);
+			def_success = FALSE;
+			os_file_close(def_file);
+			mem_free(def_filepath);
+		}
 	}
 
 	/* Read the first page of the remote tablespace */
@@ -3834,33 +3933,53 @@ fil_load_single_table_tablespace(
 			&remote_arch_log_no, &remote_arch_log_no,
 #endif /* UNIV_LOG_ARCHIVE */
 			&remote_lsn, &remote_lsn);
+
+		if (remote_id == ULINT_UNDEFINED || remote_id == 0) {
+			fprintf(stderr,
+			"InnoDB: Error: tablespace id %lu in file %s"
+			" is not sensible\n",
+			(ulong) remote_id, remote_filepath);
+			remote_success = FALSE;
+			os_file_close(remote_file);
+			mem_free(remote_filepath);
+		}
+	}
+
+	if (!def_success && !remote_success) {
+		goto no_good_file;
 	}
 
-	if (success && remote_success) {
+	if (def_success && remote_success) {
+		fprintf(stderr,
+			"InnoDB: 1: LSN " LSN_PF "\n"
+			"InnoDB: 2: LSN " LSN_PF "\n",
+			def_lsn, remote_lsn);
+
 		/* Figure out which tablespace is newer. */
-		if (space_lsn > remote_lsn) {
+		if (def_lsn > remote_lsn) {
 			/* Skip the remote file */
+			fprintf(stderr, "InnoDB: Using tablespace 1\n");
 			remote_success = FALSE;
 			os_file_close(remote_file);
 			mem_free(remote_filepath);
+
 		} else {
 			/* Use the remote file instead. */
-			success = FALSE;
-			os_file_close(file);
-			mem_free(filepath);
+			fprintf(stderr, "InnoDB: Using tablespace 2\n");
+			def_success = FALSE;
+			os_file_close(def_file);
+			mem_free(def_filepath);
 		}
 	}
 
-	/* At this point, only one tablespace is still open */
-	ut_a((success && !remote_success) || (!success && remote_success));
-	if (remote_success) {
-		success = TRUE;
-		remote_success = FALSE;
-		file = remote_file;
-		filepath = remote_filepath;
-	}
-	/* TODO: What to do in other cases where we cannot access an .ibd
-	file during a crash recovery? */
+	/* At this point, only one tablespace is open */
+	ut_a((def_success && !remote_success) || (!def_success && remote_success));
+
+	os_file_t file	= def_success ? def_file : remote_file;
+	char* filepath	= def_success ? def_filepath : remote_filepath;
+	ulint space_id	= def_success ? def_id : remote_id;
+	ulint flags	= def_success ? def_flags : remote_flags;
+
 
 	/* Get and test the file size. */
 	size = os_file_get_size(file);
@@ -3895,69 +4014,31 @@ fil_load_single_table_tablespace(
 			" crash recovery here.\n", filepath);
 
 		os_file_close(file);
-		mem_free(tablename);
 		mem_free(filepath);
-
-		if (srv_force_recovery > 0) {
-			fprintf(stderr,
-				"InnoDB: innodb_force_recovery"
-				" was set to %lu. Continuing crash recovery\n"
-				"InnoDB: even though we cannot access"
-				" the .ibd file of this table.\n",
-				srv_force_recovery);
-			return;
-		}
-
-		exit(1);
+		goto cannot_use_table;
 	}
 
 	/* Every .ibd file is created >= 4 pages in size. Smaller files
 	cannot be ok. */
-
+	ulong minimum_size = FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE;
+	if (size < minimum_size) {
 #ifndef UNIV_HOTBACKUP
-	if (size < FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
 		fprintf(stderr,
 			"InnoDB: Error: the size of single-table"
 			" tablespace file %s\n"
 			"InnoDB: is only " UINT64PF
 			", should be at least %lu!\n",
-			filepath,
-			size, (ulong) (4 * UNIV_PAGE_SIZE));
+			filepath, size, minimum_size);
 		os_file_close(file);
-		mem_free(tablename);
 		mem_free(filepath);
-
-		return;
-	}
-#endif
-	/* Read the first page of the tablespace if the size is big enough */
-
-	buf2 = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));
-	/* Align the memory for file i/o if we might have O_DIRECT set */
-	page = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE));
-
-	if (size >= FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
-		success = os_file_read(file, page, 0, UNIV_PAGE_SIZE);
-
-		/* We have to read the tablespace id from the file */
-
-		space_id = fsp_header_get_space_id(page);
-		flags = fsp_header_get_flags(page);
-	} else {
+		goto cannot_use_table;
+#else
 		space_id = ULINT_UNDEFINED;
 		flags = 0;
+#endif
 	}
 
-#ifndef UNIV_HOTBACKUP
-	if (space_id == ULINT_UNDEFINED || space_id == 0) {
-		fprintf(stderr,
-			"InnoDB: Error: tablespace id %lu in file %s"
-			" is not sensible\n",
-			(ulong) space_id,
-			filepath);
-		goto func_exit;
-	}
-#else
+#ifdef UNIV_HOTBACKUP
 	if (space_id == ULINT_UNDEFINED || space_id == 0) {
 		char*	new_path;
 
@@ -3976,7 +4057,6 @@ fil_load_single_table_tablespace(
 		new_path = fil_make_ibbackup_old_name(filepath);
 		ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
 
-		ut_free(buf2);
 		mem_free(tablename);
 		mem_free(filepath);
 		mem_free(new_path);
@@ -4015,7 +4095,6 @@ fil_load_single_table_tablespace(
 
 		ut_a(os_file_rename(innodb_file_data_key, filepath, new_path));
 
-		ut_free(buf2);
 		mem_free(tablename);
 		mem_free(filepath);
 		mem_free(new_path);
@@ -4024,16 +4103,16 @@ fil_load_single_table_tablespace(
 	}
 	mutex_exit(&fil_system->mutex);
 #endif
-	success = fil_space_create(tablename, space_id, flags, FIL_TABLESPACE);
+	ibool success = fil_space_create(
+		tablename, space_id, flags, FIL_TABLESPACE);
 
 	if (!success) {
-
 		if (srv_force_recovery > 0) {
 			fprintf(stderr,
-				"InnoDB: innodb_force_recovery"
-				" was set to %lu. Continuing crash recovery\n"
-				"InnoDB: even though the tablespace creation"
-				" of this table failed.\n",
+				"InnoDB: innodb_force_recovery was set"
+				" to %lu. Continuing crash recovery\n"
+				"InnoDB: even though the tablespace"
+				" creation of this table failed.\n",
 				srv_force_recovery);
 			goto func_exit;
 		}
@@ -4049,7 +4128,6 @@ fil_load_single_table_tablespace(
 
 func_exit:
 	os_file_close(file);
-	ut_free(buf2);
 	mem_free(tablename);
 	mem_free(filepath);
 }

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	revid:viswanatham.gudipati@stripped
+++ b/storage/innobase/handler/ha_innodb.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -2546,6 +2546,28 @@ trx_is_strict(
 	       && THDVAR(static_cast<THD*>(trx->mysql_thd), strict_mode));
 }
 
+/**********************************************************************//**
+Determines if the current MySQL thread is running in strict mode.
+@return	TRUE if strict */
+UNIV_INTERN
+ibool
+thd_is_strict(
+/*==========*/
+	THD*	thd)	/*!< in: MySQL thread descriptor */
+{
+	return(thd && THDVAR(thd, strict_mode));
+}
+
+/**********************************************************************//**
+returns the global setting for innodb_strict_mode.
+@return	TRUE if strict */
+UNIV_INTERN
+ibool
+global_mode_is_strict()
+{
+	return(THDVAR(NULL, strict_mode));
+}
+
 /**************************************************************//**
 Resets some fields of a prebuilt struct. The template is used in fast
 retrieval of just those column values MySQL needs in its processing. */
@@ -3828,11 +3850,11 @@ ha_innobase::primary_key_is_clustered()
 
 /** Always normalize table name to lower case on Windows */
 #ifdef __WIN__
-#define normalize_table_name(name)		\
-	normalize_table_name_low(name, TRUE)
+#define normalize_table_name(norm_name, name)		\
+	normalize_table_name_low(norm_name, name, TRUE)
 #else
-#define normalize_table_name(name)           \
-	normalize_table_name_low(name, FALSE)
+#define normalize_table_name(norm_name, name)           \
+	normalize_table_name_low(norm_name, name, FALSE)
 #endif /* __WIN__ */
 
 /*****************************************************************//**
@@ -3846,11 +3868,12 @@ static
 char*
 normalize_table_name_low(
 /*=====================*/
+	char*		norm_name,	/*!< out: normalized name as a
+					null-terminated string */
 	const char*	name,		/*!< in: table name string */
 	ibool		set_lower_case)	/*!< in: TRUE if we want to set name
 					to lower case */
 {
-	char*	norm_name;
 	char*	name_ptr;
 	ulint	name_len;
 	char*	db_ptr;
@@ -3888,7 +3911,7 @@ normalize_table_name_low(
 	db_ptr = ptr + 1;
 
 	norm_len = db_len + name_len + sizeof "/";
-	norm_name = static_cast<char*>(mem_alloc(norm_len));
+	ut_a(norm_len < FN_REFLEN - 1);
 
 	memcpy(norm_name, db_ptr, db_len);
 
@@ -3912,7 +3935,7 @@ void
 test_normalize_table_name_low()
 /*===========================*/
 {
-	char*		norm_name;
+	char		norm_name[FN_REFLEN];
 	const char*	test_data[][2] = {
 		/* input, expected result */
 		{"./mysqltest/t1", "mysqltest/t1"},
@@ -3958,7 +3981,7 @@ test_normalize_table_name_low()
 		       "testing \"%s\", expected \"%s\"... ",
 		       test_data[i][0], test_data[i][1]);
 
-		norm_name = normalize_table_name_low(test_data[i][0], FALSE);
+		normalize_table_name_low(norm_name, test_data[i][0], FALSE);
 
 		if (strcmp(norm_name, test_data[i][1]) == 0) {
 			printf("ok\n");
@@ -3966,8 +3989,6 @@ test_normalize_table_name_low()
 			printf("got \"%s\"\n", norm_name);
 			ut_error;
 		}
-
-		mem_free(norm_name);
 	}
 }
 
@@ -4441,11 +4462,10 @@ ha_innobase::open(
 	uint		test_if_locked)	/*!< in: not used */
 {
 	dict_table_t*	ib_table;
-	char*		norm_name;
+	char		norm_name[FN_REFLEN];
 	THD*		thd;
 	ulint		retries = 0;
 	char*		is_part = NULL;
-	char*		par_case_name = NULL;
 
 	DBUG_ENTER("ha_innobase::open");
 
@@ -4468,7 +4488,7 @@ ha_innobase::open(
 		DBUG_RETURN(1);
 	}
 
-	norm_name = normalize_table_name(name);
+	normalize_table_name(norm_name, name);
 
 	/* Will be allocated if it is needed in ::update_row() */
 	upd_buf = NULL;
@@ -4502,33 +4522,29 @@ retry:
 
 			1) If boot against an installation from Windows
 			platform, then its partition table name could
-			be all be in lower case in system tables. So we
-			will need to check lower case name when load table.
+			be in lower case in system tables. So we will
+			need to check lower case name when load table.
 
-			2) If  we boot an installation from other case
+			2) If we boot an installation from other case
 			sensitive platform in Windows, we might need to
-			check the existence of table name without lowering
-			case them in the system table. */
+			check the existence of table name without lower
+			case in the system table. */
 			if (innobase_get_lower_case_table_names() == 1) {
-
-				if (par_case_name == NULL) {
+				char	par_case_name[FN_REFLEN];
 #ifndef __WIN__
-					/* Check for the table using lower
-					case name, including the partition
-					separator "P" */
-					par_case_name = mem_strdup(norm_name);
-					innobase_casedn_str(par_case_name);
+				/* Check for the table using lower
+				case name, including the partition
+				separator "P" */
+				strcpy(par_case_name, norm_name);
+				innobase_casedn_str(par_case_name);
 #else
-					/* On Windows platfrom, check
-					whether there exists table name in
-					system table whose name is
-					not being normalized to lower case */
-					par_case_name =
-						normalize_table_name_low(
-							name, FALSE);
+				/* On Windows platfrom, check
+				whether there exists table name in
+				system table whose name is
+				not being normalized to lower case */
+				normalize_table_name_low(
+					par_case_name, name, FALSE);
 #endif
-				}
-
 				ib_table = dict_table_open_on_name(
 					par_case_name, FALSE, TRUE,
 					DICT_ERR_IGNORE_NONE);
@@ -4585,20 +4601,12 @@ retry:
 				"how you can resolve the problem.\n",
 				norm_name);
 		my_errno = ENOENT;
-		mem_free(norm_name);
-		if (par_case_name) {
-			mem_free(par_case_name);
-		}
 
 		DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
 	}
 
 table_opened:
 
-	if (par_case_name) {
-		mem_free(par_case_name);
-	}
-
 	dict_stats_init(
 		ib_table,
 		table->s->db_create_options & HA_OPTION_STATS_PERSISTENT,
@@ -4619,7 +4627,6 @@ table_opened:
 		my_errno = ENOENT;
 
 		dict_table_close(ib_table, FALSE, FALSE);
-		mem_free(norm_name);
 
 		DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
 	}
@@ -4785,8 +4792,6 @@ table_opened:
 
 	info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
 
-	mem_free(norm_name);
-
 	DBUG_RETURN(0);
 }
 
@@ -5907,6 +5912,10 @@ ha_innobase::build_template(
 
 	prebuilt->need_to_access_clustered = (index == clust_index);
 
+	/* Either prebuilt->index should be a secondary index, or it
+	should be the clustered index. */
+	ut_ad(dict_index_is_clust(index) == (index == clust_index));
+
 	/* Below we check column by column if we need to access
 	the clustered index. */
 
@@ -7386,7 +7395,7 @@ ha_innobase::change_active_index(
 				"InnoDB: Index %s for table %s is"
 				" marked as corrupted",
 				index_name, table_name);
-			DBUG_RETURN(1);
+			DBUG_RETURN(HA_ERR_INDEX_CORRUPT);
 		} else {
 			push_warning_printf(
 				user_thd, Sql_condition::WARN_LEVEL_WARN,
@@ -7397,7 +7406,7 @@ ha_innobase::change_active_index(
 
 		/* The caller seems to ignore this.  Thus, we must check
 		this again in row_search_for_mysql(). */
-		DBUG_RETURN(2);
+		DBUG_RETURN(HA_ERR_TABLE_DEF_CHANGED);
 	}
 
 	ut_a(prebuilt->search_tuple != 0);
@@ -8177,12 +8186,12 @@ create_table_def(
 	}
 
 	if (flags2 & DICT_TF2_TEMPORARY) {
-		ut_a(temp_path);
+		ut_a(strlen(temp_path));
 		table->dir_path_of_temp_table =
 			mem_heap_strdup(table->heap, temp_path);
 	}
 
-	if (remote_path) {
+	if (strlen(remote_path)) {
 		table->data_dir_path =
 			mem_heap_strdup(table->heap, remote_path);
 	}
@@ -8555,7 +8564,7 @@ create_options_are_valid(
 	ut_ad(thd != NULL);
 
 	/* If innodb_strict_mode is not set don't do any validation. */
-	if (!(THDVAR(thd, strict_mode))) {
+	if (!thd_is_strict(thd)) {
 		return(TRUE);
 	}
 
@@ -8761,9 +8770,9 @@ ha_innobase::parse_table_name(
 					created table, contains also the
 					create statement string */
 	bool		use_tablespace,	/*!< in: srv_file_per_table */
-	char**		norm_name,	/*!< out: normalized table name */
-	char**		temp_path,	/*!< out: absolute path of table */
-	char**		remote_path)	/*!< out: remote path of table */
+	char*		norm_name,	/*!< out: normalized table name */
+	char*		temp_path,	/*!< out: absolute path of table */
+	char*		remote_path)	/*!< out: remote path of table */
 {
 	THD*		thd = ha_thd();
 	DBUG_ENTER("ha_innobase::parse_table_name");
@@ -8792,16 +8801,16 @@ ha_innobase::parse_table_name(
 	}
 #endif
 
-	*norm_name = normalize_table_name(name);
-	*temp_path = NULL;
-	*remote_path = NULL;
+	normalize_table_name(norm_name, name);
+	temp_path[0] = '\0';
+	remote_path[0] = '\0';
 
 	/* A full path is used for TEMPORARY TABLE and DATA DIRECTORY.
 	In the case of;
 	  CREATE TEMPORARY TABLE ... DATA DIRECTORY={path} ... ;
 	We ignore the DATA DIRECTORY. */
 	if (create_info->options & HA_LEX_CREATE_TMP_TABLE) {
-		*temp_path = mem_strdup(name);
+		strncpy(temp_path, name, FN_REFLEN - 1);
 	}
 
 	if (create_info->data_file_name) {
@@ -8834,7 +8843,8 @@ ha_innobase::parse_table_name(
 				ER_DEFAULT(WARN_OPTION_IGNORED),
 				"DATA DIRECTORY");
 		} else {
-			*remote_path = mem_strdup(create_info->data_file_name);
+			strncpy(remote_path, create_info->data_file_name,
+				FN_REFLEN - 1);
 		}
 	}
 
@@ -9090,9 +9100,9 @@ ha_innobase::create(
 	trx_t*		trx;
 	int		primary_key_no;
 	uint		i;
-	char*		remote_path = NULL;	/* absolute path of table */
-	char*		temp_path = NULL;	/* absolute path of temp frm */
-	char*		norm_name = NULL;	/* {database}/{tablename} */
+	char		norm_name[FN_REFLEN];	/* {database}/{tablename} */
+	char		temp_path[FN_REFLEN];	/* absolute path of temp frm */
+	char		remote_path[FN_REFLEN];	/* absolute path of table */
 	THD*		thd = ha_thd();
 	ib_int64_t	auto_inc_value;
 
@@ -9139,7 +9149,7 @@ ha_innobase::create(
 	}
 
 	error = parse_table_name(name, create_info, use_tablespace,
-				 &norm_name, &temp_path, &remote_path);
+				 norm_name, temp_path, remote_path);
 	if (error) {
 		DBUG_RETURN(error);
 	}
@@ -9157,13 +9167,11 @@ ha_innobase::create(
 	any user indices to be created. */
 	if (innobase_index_name_is_reserved(thd, form->key_info,
 					    form->s->keys)) {
-		error = -1;
-		goto cleanup3;
+		DBUG_RETURN(-1);
 	}
 
 	if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
-		error = HA_ERR_GENERIC;
-		goto cleanup3;
+		DBUG_RETURN(HA_ERR_GENERIC);
 	}
 
 	/* Get the transaction associated with the current thd, or create one
@@ -9366,7 +9374,7 @@ ha_innobase::create(
 			dict_table_close(innobase_table, FALSE, FALSE);
 			srv_active_wake_master_thread();
 			error = -1;
-			goto cleanup2;
+			goto cleanup;
 		}
 	}
 
@@ -9407,26 +9415,16 @@ ha_innobase::create(
 
 	srv_active_wake_master_thread();
 
-	error = 0;
-	goto cleanup2;
+	trx_free_for_mysql(trx);
+	DBUG_RETURN(0);
 
 cleanup:
 	innobase_commit_low(trx);
 
 	row_mysql_unlock_data_dictionary(trx);
 
-cleanup2:
 	trx_free_for_mysql(trx);
 
-cleanup3:
-	if (remote_path) {
-		mem_free(remote_path);
-	}
-	if (temp_path) {
-		mem_free(temp_path);
-	}
-	mem_free(norm_name);
-
 	DBUG_RETURN(error);
 }
 
@@ -9507,7 +9505,7 @@ ha_innobase::delete_table(
 	trx_t*	parent_trx;
 	trx_t*	trx;
 	THD	*thd = ha_thd();
-	char*	norm_name = NULL;
+	char	norm_name[FN_REFLEN];
 	char	errstr[1024];
 
 	DBUG_ENTER("ha_innobase::delete_table");
@@ -9523,10 +9521,9 @@ ha_innobase::delete_table(
 
 	/* Strangely, MySQL passes the table name without the '.frm'
 	extension, in contrast to ::create */
-	norm_name = normalize_table_name(name);
+	normalize_table_name(norm_name, name);
 
 	if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
-		mem_free(norm_name);
 		DBUG_RETURN(HA_ERR_GENERIC);
 	}
 
@@ -9580,26 +9577,25 @@ ha_innobase::delete_table(
 #endif /* __WIN__ */
 
 		if (is_part) {
-			char*	par_case_name;
+			char	par_case_name[FN_REFLEN];
 
 #ifndef __WIN__
 			/* Check for the table using lower
 			case name, including the partition
 			separator "P" */
-			par_case_name = mem_strdup(norm_name);
+			strcpy(par_case_name, norm_name);
 			innobase_casedn_str(par_case_name);
 #else
 			/* On Windows platfrom, check
 			whether there exists table name in
 			system table whose name is
 			not being normalized to lower case */
-			par_case_name = normalize_table_name_low(
-				name, FALSE);
+			normalize_table_name_low(
+				par_case_name, name, FALSE);
 #endif
 			err = row_drop_table_for_mysql(
 				par_case_name, trx,
 				thd_sql_command(thd) == SQLCOM_DROP_DB);
-			mem_free(par_case_name);
 		}
 	}
 
@@ -9618,8 +9614,6 @@ ha_innobase::delete_table(
 
 	trx_free_for_mysql(trx);
 
-	mem_free(norm_name);
-
 	DBUG_RETURN(convert_error_code_to_mysql(err, 0, NULL));
 }
 
@@ -9714,12 +9708,14 @@ innobase_rename_table(
 	const char*	to)	/*!< in: new name of the table */
 {
 	dberr_t	error;
+	char	norm_to[FN_REFLEN];
+	char	norm_from[FN_REFLEN];
 
 	DBUG_ENTER("innobase_rename_table");
 	DBUG_ASSERT(trx_get_dict_operation(trx) == TRX_DICT_OP_INDEX);
 
-	char* norm_to = normalize_table_name(to);
-	char* norm_from = normalize_table_name(from);
+	normalize_table_name(norm_to, to);
+	normalize_table_name(norm_from, from);
 
 	/* Serialize data dictionary operations with dictionary mutex:
 	no deadlocks can occur then in these operations */
@@ -9745,26 +9741,23 @@ innobase_rename_table(
 #endif /* __WIN__ */
 
 			if (is_part) {
-				char*	par_case_name;
-
+				char	par_case_name[FN_REFLEN];
 #ifndef __WIN__
 				/* Check for the table using lower
 				case name, including the partition
 				separator "P" */
-				par_case_name = mem_strdup(norm_from);
+				strcpy(par_case_name, norm_from);
 				innobase_casedn_str(par_case_name);
 #else
 				/* On Windows platfrom, check
 				whether there exists table name in
 				system table whose name is
 				not being normalized to lower case */
-				par_case_name = normalize_table_name_low(
-					from, FALSE);
+				normalize_table_name_low(
+					par_case_name, from, FALSE);
 #endif
 				error = row_rename_table_for_mysql(
 					par_case_name, norm_to, trx, TRUE);
-
-				mem_free(par_case_name);
 			}
 		}
 
@@ -9804,9 +9797,6 @@ innobase_rename_table(
 
 	log_buffer_flush_to_disk();
 
-	mem_free(norm_to);
-	mem_free(norm_from);
-
 	DBUG_RETURN(error);
 }
 
@@ -10007,10 +9997,10 @@ ha_rows
 ha_innobase::estimate_rows_upper_bound()
 /*====================================*/
 {
-	dict_index_t*	index;
-	ulonglong	estimate;
-	ulonglong	local_data_file_length;
-	ulint		stat_n_leaf_pages;
+	const dict_index_t*	index;
+	ulonglong		estimate;
+	ulonglong		local_data_file_length;
+	ulint			stat_n_leaf_pages;
 
 	DBUG_ENTER("estimate_rows_upper_bound");
 
@@ -10020,8 +10010,7 @@ ha_innobase::estimate_rows_upper_bound()
 
 	update_thd(ha_thd());
 
-	prebuilt->trx->op_info = (char*)
-				 "calculating upper bound for table rows";
+	prebuilt->trx->op_info = "calculating upper bound for table rows";
 
 	/* In case MySQL calls this in the middle of a SELECT query, release
 	possible adaptive hash latch to avoid deadlocks of threads */
@@ -10037,16 +10026,15 @@ ha_innobase::estimate_rows_upper_bound()
 	local_data_file_length =
 		((ulonglong) stat_n_leaf_pages) * UNIV_PAGE_SIZE;
 
-
 	/* Calculate a minimum length for a clustered index record and from
 	that an upper bound for the number of rows. Since we only calculate
 	new statistics in row0mysql.cc when a table has grown by a threshold
 	factor, we must add a safety factor 2 in front of the formula below. */
 
-	estimate = 2 * local_data_file_length /
-					 dict_index_calc_min_rec_len(index);
+	estimate = 2 * local_data_file_length
+		/ dict_index_calc_min_rec_len(index);
 
-	prebuilt->trx->op_info = (char*)"";
+	prebuilt->trx->op_info = "";
 
 	DBUG_RETURN((ha_rows) estimate);
 }
@@ -10299,7 +10287,7 @@ ha_innobase::info(
 {
 	dict_table_t*	ib_table;
 	ha_rows		rec_per_key;
-	ib_int64_t	n_rows;
+	ib_uint64_t	n_rows;
 	char		path[FN_REFLEN];
 	os_file_stat_t	stat_info;
 
@@ -10394,10 +10382,7 @@ ha_innobase::info(
 			dict_table_stats_unlock(ib_table, RW_S_LATCH);
 		}
 
-		/* Because we do not protect stat_n_rows by any mutex in a
-		delete, it is theoretically possible that the value can be
-		smaller than zero! TODO: fix this race.
-
+		/*
 		The MySQL optimizer seems to assume in a left join that n_rows
 		is an accurate estimate if it is zero. Of course, it is not,
 		since we do not have any locks on the rows yet at this phase.
@@ -10407,10 +10392,6 @@ ha_innobase::info(
 		set. That way SHOW TABLE STATUS will show the best estimate,
 		while the optimizer never sees the table empty. */
 
-		if (n_rows < 0) {
-			n_rows = 0;
-		}
-
 		if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
 			n_rows++;
 		}
@@ -10795,7 +10776,7 @@ ha_innobase::check(
 	/* Enlarge the fatal lock wait timeout during CHECK TABLE. */
 	os_increment_counter_by_amount(
 		server_mutex,
-		srv_fatal_semaphore_wait_threshold, 7200/*2 hours*/);
+		srv_fatal_semaphore_wait_threshold, SRV_SEMAPHORE_WAIT_EXTENSION);
 
 	for (index = dict_table_get_first_index(prebuilt->table);
 	     index != NULL;
@@ -10939,7 +10920,7 @@ ha_innobase::check(
 	/* Restore the fatal lock wait timeout after CHECK TABLE. */
 	os_decrement_counter_by_amount(
 		server_mutex,
-		srv_fatal_semaphore_wait_threshold, 7200/*2 hours*/);
+		srv_fatal_semaphore_wait_threshold, SRV_SEMAPHORE_WAIT_EXTENSION);
 
 	prebuilt->trx->op_info = "";
 	if (thd_killed(user_thd)) {

=== modified file 'storage/innobase/handler/ha_innodb.h'
--- a/storage/innobase/handler/ha_innodb.h	revid:viswanatham.gudipati@strippedic6v5kvzls1lk
+++ b/storage/innobase/handler/ha_innodb.h	revid:kevin.lewis@strippedg4r
@@ -192,9 +192,9 @@ class ha_innobase: public handler
 	int parse_table_name(const char*name,
 			     HA_CREATE_INFO*create_info,
 			     bool use_tablespace,
-			     char** norm_name,
-			     char** temp_path,
-			     char** remote_path);
+			     char* norm_name,
+			     char* temp_path,
+			     char* remote_path);
 	int create(const char *name, register TABLE *form,
 					HA_CREATE_INFO *create_info);
 	int truncate();

=== modified file 'storage/innobase/handler/handler0alter.cc'
--- a/storage/innobase/handler/handler0alter.cc	revid:viswanatham.gudipati@stripped
+++ b/storage/innobase/handler/handler0alter.cc	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -1215,7 +1215,18 @@ no_match:
 
 		for (uint j = 0; j < n_cols; j++) {
 			const KEY_PART_INFO&	key_part = key->key_part[j];
-			if (key_part.length < key_part.field->pack_length()) {
+			uint32			col_len
+				= key_part.field->pack_length();
+
+			/* The MySQL pack length contains 1 or 2 bytes
+			length field for a true VARCHAR. */
+
+			if (key_part.field->type() == MYSQL_TYPE_VARCHAR) {
+				col_len -= static_cast<const Field_varstring*>(
+					key_part.field)->length_bytes;
+			}
+
+			if (key_part.length < col_len) {
 
 				/* Column prefix indexes cannot be
 				used for FOREIGN KEY constraints. */

=== modified file 'storage/innobase/include/dict0dict.h'
--- a/storage/innobase/include/dict0dict.h	revid:viswanatham.gudipati@stripped20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/dict0dict.h	revid:kevin.lewis@stripped3156-uyr7sxxgbhodbg4r
@@ -715,7 +715,7 @@ dict_table_get_n_cols(
 Gets the approximately estimated number of rows in the table.
 @return	estimated number of rows */
 UNIV_INLINE
-ib_int64_t
+ib_uint64_t
 dict_table_get_n_rows(
 /*==================*/
 	const dict_table_t*	table)	/*!< in: table */
@@ -814,7 +814,7 @@ ulint
 dict_tf_get_format(
 /*===============*/
 	ulint		flags)		/*!< in: dict_table_t::flags */
-	__attribute__((nonnull, warn_unused_result));
+	__attribute__((warn_unused_result));
 /********************************************************************//**
 Set the various values in a dict_table_t::flags pointer. */
 UNIV_INLINE

=== modified file 'storage/innobase/include/dict0dict.ic'
--- a/storage/innobase/include/dict0dict.ic	revid:viswanatham.gudipati@stripped27152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/dict0dict.ic	revid:kevin.lewis@strippeduyr7sxxgbhodbg4r
@@ -370,18 +370,14 @@ dict_table_get_n_cols(
 Gets the approximately estimated number of rows in the table.
 @return	estimated number of rows */
 UNIV_INLINE
-ib_int64_t
+ib_uint64_t
 dict_table_get_n_rows(
 /*==================*/
 	const dict_table_t*	table)	/*!< in: table */
 {
-	ib_int64_t	n_rows;
-
 	ut_ad(table->stat_initialized);
 
-	n_rows = table->stat_n_rows;
-
-	return(n_rows);
+	return(table->stat_n_rows);
 }
 
 /********************************************************************//**
@@ -395,8 +391,8 @@ dict_table_n_rows_inc(
 	dict_table_t*	table)	/*!< in/out: table */
 {
 	if (table->stat_initialized) {
-		ib_int64_t      n_rows = table->stat_n_rows;
-		if (n_rows < 0x7FFFFFFFFFFFFFFFLL) {
+		ib_uint64_t	n_rows = table->stat_n_rows;
+		if (n_rows < 0xFFFFFFFFFFFFFFFFULL) {
 			table->stat_n_rows = n_rows + 1;
 		}
 	}
@@ -413,7 +409,7 @@ dict_table_n_rows_dec(
 	dict_table_t*	table)	/*!< in/out: table */
 {
 	if (table->stat_initialized) {
-		ib_int64_t      n_rows = table->stat_n_rows;
+		ib_uint64_t	n_rows = table->stat_n_rows;
 		if (n_rows > 0) {
 			table->stat_n_rows = n_rows - 1;
 		}

=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h	revid:viswanatham.gudipati@stripped
+++ b/storage/innobase/include/dict0mem.h	revid:kevin.lewis@oracle.com-20120430183156-uyr7sxxgbhodbg4r
@@ -763,7 +763,7 @@ struct dict_table_struct{
 				this ever happens. */
 #define DICT_STATS_PERSISTENT_ON	(1 << 1)
 #define DICT_STATS_PERSISTENT_OFF	(1 << 2)
-	ib_int64_t	stat_n_rows;
+	ib_uint64_t	stat_n_rows;
 				/*!< approximate number of rows in the table;
 				we periodically calculate new estimates */
 	ulint		stat_clustered_index_size;
@@ -771,14 +771,14 @@ struct dict_table_struct{
 				database pages */
 	ulint		stat_sum_of_other_index_sizes;
 				/*!< other indexes in database pages */
-	ulint		stat_modified_counter;
+	ib_uint64_t	stat_modified_counter;
 				/*!< when a row is inserted, updated,
 				or deleted,
 				we add 1 to this number; we calculate new
 				estimates for the stat_... values for the
-				table and the indexes at an interval of 2 GB
-				or when about 1 / 16 of table has been
-				modified; also when the estimate operation is
+				table and the indexes when about 1 / 16 of
+				table has been modified;
+				also when the estimate operation is
 				called for MySQL SHOW TABLE STATUS; the
 				counter is reset to zero at statistics
 				calculation; this counter is not protected by

=== modified file 'storage/innobase/include/fil0fil.h'
--- a/storage/innobase/include/fil0fil.h	revid:viswanatham.gudipati@stripped0120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/fil0fil.h	revid:kevin.lewis@stripped6-uyr7sxxgbhodbg4r
@@ -343,8 +343,7 @@ dberr_t
 fil_write_flushed_lsn_to_data_files(
 /*================================*/
 	lsn_t	lsn,		/*!< in: lsn to write */
-	ulint	arch_log_no)	/*!< in: latest archived log file number */
-	__attribute__((nonnull));
+	ulint	arch_log_no);	/*!< in: latest archived log file number */
 /*******************************************************************//**
 Reads the flushed lsn, arch no, and tablespace flag fields from a data
 file at database startup. */

=== modified file 'storage/innobase/include/fts0priv.ic'
--- a/storage/innobase/include/fts0priv.ic	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/fts0priv.ic	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -57,3 +57,42 @@ fts_read_object_id(
 	return(sscanf(str, IB_ID_FMT, id) == 2);
 }
 
+/******************************************************************//**
+Compare two fts_trx_table_t instances.
+@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2  */
+UNIV_INLINE
+int
+fts_trx_table_cmp(
+/*==============*/
+	const void*	p1,			/*!< in: id1 */
+	const void*	p2)			/*!< in: id2 */
+{
+	const dict_table_t* table1 = (*(const fts_trx_table_t**) p1)->table;
+	const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table;
+
+	return((table1->id > table2->id)
+	       ? 1
+	       : (table1->id == table2->id)
+		  ? 0
+		  : -1);
+}
+
+/******************************************************************//**
+Compare a table id with a fts_trx_table_t table id.
+@return < 0 if n1 < n2, 0 if n1 == n2,> 0 if n1 > n2 */
+UNIV_INLINE
+int
+fts_trx_table_id_cmp(
+/*=================*/
+	const void*	p1,			/*!< in: id1 */
+	const void*	p2)			/*!< in: id2 */
+{
+	const ullint* table_id = (const ullint*) p1;
+	const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table;
+
+	return((*table_id > table2->id)
+	       ? 1
+	       : (*table_id == table2->id)
+		  ? 0
+		  : -1);
+}

=== modified file 'storage/innobase/include/fts0types.ic'
--- a/storage/innobase/include/fts0types.ic	revid:viswanatham.gudipati@strippedm-20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/fts0types.ic	revid:kevin.lewis@stripped0183156-uyr7sxxgbhodbg4r
@@ -37,46 +37,6 @@ extern const ulint UTF8_ERROR;
 #define fts_utf8_is_valid(b) (((b) & 0xC0) == 0x80)
 
 /******************************************************************//**
-Compare two fts_trx_table_t instances.
-@return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2  */
-UNIV_INLINE
-int
-fts_trx_table_cmp(
-/*==============*/
-	const void*	p1,			/*!< in: id1 */
-	const void*	p2)			/*!< in: id2 */
-{
-	const dict_table_t* table1 = (*(const fts_trx_table_t**) p1)->table;
-	const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table;
-
-	return((table1->id > table2->id)
-	       ? 1
-	       : (table1->id == table2->id)
-		  ? 0
-		  : -1);
-}
-
-/******************************************************************//**
-Compare a table id with a fts_trx_table_t table id.
-@return < 0 if n1 < n2, 0 if n1 == n2,> 0 if n1 > n2 */
-UNIV_INLINE
-int
-fts_trx_table_id_cmp(
-/*=================*/
-	const void*	p1,			/*!< in: id1 */
-	const void*	p2)			/*!< in: id2 */
-{
-	const ullint* table_id = (const ullint*) p1;
-	const dict_table_t* table2 = (*(const fts_trx_table_t**) p2)->table;
-
-	return((*table_id > table2->id)
-	       ? 1
-	       : (*table_id == table2->id)
-		  ? 0
-		  : -1);
-}
-
-/******************************************************************//**
 Duplicate an UTF-8 string.
 @return < 0 if n1 < n2, 0 if n1 == n2, > 0 if n1 > n2 */
 UNIV_INLINE

=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/srv0srv.h	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -313,6 +313,7 @@ extern	ibool	srv_print_latch_waits;
 #endif /* UNIV_DEBUG */
 
 extern ulint	srv_fatal_semaphore_wait_threshold;
+#define SRV_SEMAPHORE_WAIT_EXTENSION	7200
 extern ulint	srv_dml_needed_delay;
 
 #ifndef HAVE_ATOMIC_BUILTINS

=== modified file 'storage/innobase/include/trx0trx.h'
--- a/storage/innobase/include/trx0trx.h	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/include/trx0trx.h	revid:kevin.lewis@stripped0120430183156-uyr7sxxgbhodbg4r
@@ -368,8 +368,16 @@ ibool
 trx_is_strict(
 /*==========*/
 	trx_t*	trx);	/*!< in: transaction */
+/**********************************************************************//**
+returns the global setting for innodb_strict_mode.
+@return	TRUE if strict */
+UNIV_INTERN
+ibool
+global_mode_is_strict();
+
 #else /* !UNIV_HOTBACKUP */
 #define trx_is_interrupted(trx) FALSE
+#define global_mode_is_strict() FALSE
 #endif /* !UNIV_HOTBACKUP */
 
 /*******************************************************************//**

=== modified file 'storage/innobase/row/row0ins.cc'
--- a/storage/innobase/row/row0ins.cc	revid:viswanatham.gudipati@stripped52910-uqcic6v5kvzls1lk
+++ b/storage/innobase/row/row0ins.cc	revid:kevin.lewis@strippedhodbg4r
@@ -1699,6 +1699,8 @@ row_ins_check_foreign_constraints(
 
 	foreign = UT_LIST_GET_FIRST(table->foreign_list);
 
+	DEBUG_SYNC_C("foreign_constraint_check_for_ins");
+
 	while (foreign) {
 		if (foreign->foreign_index == index) {
 			dict_table_t*	ref_table = NULL;

=== modified file 'storage/innobase/row/row0mysql.cc'
--- a/storage/innobase/row/row0mysql.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/row/row0mysql.cc	revid:kevin.lewis@stripped30183156-uyr7sxxgbhodbg4r
@@ -1003,7 +1003,7 @@ row_update_statistics_if_needed(
 /*============================*/
 	dict_table_t*	table)	/*!< in: table */
 {
-	ulint	counter;
+	ib_uint64_t	counter;
 
 	if (!table->stat_initialized) {
 		DBUG_EXECUTE_IF(
@@ -1024,13 +1024,11 @@ row_update_statistics_if_needed(
 	/* else */
 
 	/* Calculate new statistics if 1 / 16 of table has been modified
-	since the last time a statistics batch was run, or if
-	stat_modified_counter > 2 000 000 000 (to avoid wrap-around).
+	since the last time a statistics batch was run.
 	We calculate statistics at most every 16th round, since we may have
 	a counter table which is very small and updated very often. */
 
-	if (counter > 2000000000
-	    || ((ib_int64_t) counter > 16 + table->stat_n_rows / 16)) {
+	if (counter > 16 + table->stat_n_rows / 16) {
 
 		ut_ad(!mutex_own(&dict_sys->mutex));
 		/* this will reset table->stat_modified_counter to 0 */

=== modified file 'storage/innobase/row/row0sel.cc'
--- a/storage/innobase/row/row0sel.cc	revid:viswanatham.gudipati@stripped910-uqcic6v5kvzls1lk
+++ b/storage/innobase/row/row0sel.cc	revid:kevin.lewis@strippeddbg4r
@@ -3691,6 +3691,7 @@ row_search_for_mysql(
 	ulint		offsets_[REC_OFFS_NORMAL_SIZE];
 	ulint*		offsets				= offsets_;
 	ibool		table_lock_waited		= FALSE;
+	byte*		next_buf			= 0;
 
 	rec_offs_init(offsets_);
 
@@ -4168,12 +4169,12 @@ wait_table_again:
 
 			/* Try to place a gap lock on the next index record
 			to prevent phantoms in ORDER BY ... DESC queries */
-			const rec_t*	next = page_rec_get_next_const(rec);
+			const rec_t*	next_rec = page_rec_get_next_const(rec);
 
-			offsets = rec_get_offsets(next, index, offsets,
+			offsets = rec_get_offsets(next_rec, index, offsets,
 						  ULINT_UNDEFINED, &heap);
 			err = sel_set_rec_lock(btr_pcur_get_block(pcur),
-					       next, index, offsets,
+					       next_rec, index, offsets,
 					       prebuilt->select_lock_type,
 					       LOCK_GAP, thr);
 
@@ -4829,29 +4830,58 @@ requires_clust_rec:
 		/* We only convert from InnoDB row format to MySQL row
 		format when ICP is disabled. */
 
-		if (!prebuilt->idx_cond
-		    && !row_sel_store_mysql_rec(
-			    row_sel_fetch_last_buf(prebuilt),
-			    prebuilt, result_rec,
-			    result_rec != rec,
-			    result_rec != rec ? clust_index : index,
-			    offsets)) {
-
-			/* Only fresh inserts may contain incomplete
-			externally stored columns. Pretend that such
-			records do not exist. Such records may only be
-			accessed at the READ UNCOMMITTED isolation
-			level or when rolling back a recovered
-			transaction. Rollback happens at a lower
-			level, not here. */
-			goto next_rec;
-		}
+		if (!prebuilt->idx_cond) {
+
+			/* We use next_buf to track the allocation of buffers
+			where we store and enqueue the buffers for our
+			pre-fetch optimisation.
+
+			If next_buf == 0 then we store the converted record
+			directly into the MySQL record buffer (buf). If it is
+			!= 0 then we allocate a pre-fetch buffer and store the
+			converted record there.
+
+			If the conversion fails and the MySQL record buffer
+			was not written to then we reset next_buf so that
+			we can re-use the MySQL record buffer in the next
+			iteration. */
+
+			next_buf = next_buf
+				 ? row_sel_fetch_last_buf(prebuilt) : buf;
+
+			if (!row_sel_store_mysql_rec(
+				next_buf, prebuilt, result_rec,
+				result_rec != rec,
+				result_rec != rec ? clust_index : index,
+				offsets)) {
+
+				if (next_buf == buf) {
+					ut_a(prebuilt->n_fetch_cached == 0);
+					next_buf = 0;
+				}
 
-		row_sel_enqueue_cache_row_for_mysql(buf, prebuilt);
+				/* Only fresh inserts may contain incomplete
+				externally stored columns. Pretend that such
+				records do not exist. Such records may only be
+				accessed at the READ UNCOMMITTED isolation
+				level or when rolling back a recovered
+				transaction. Rollback happens at a lower
+				level, not here. */
+				goto next_rec;
+			}
+
+			if (next_buf != buf) {
+				row_sel_enqueue_cache_row_for_mysql(
+					next_buf, prebuilt);
+			}
+		} else {
+			row_sel_enqueue_cache_row_for_mysql(buf, prebuilt);
+		}
 
 		if (prebuilt->n_fetch_cached < MYSQL_FETCH_CACHE_SIZE) {
 			goto next_rec;
 		}
+
 	} else {
 		if (UNIV_UNLIKELY
 		    (prebuilt->template_type == ROW_MYSQL_DUMMY_TEMPLATE)) {
@@ -5086,8 +5116,23 @@ normal_return:
 
 	mtr_commit(&mtr);
 
-	if (prebuilt->n_fetch_cached > 0) {
-		row_sel_dequeue_cached_row_for_mysql(buf, prebuilt);
+	if (prebuilt->idx_cond != 0) {
+
+		/* When ICP is active we don't write to the MySQL buffer
+		directly, only to buffers that are enqueued in the pre-fetch
+		queue. We need to dequeue the first buffer and copy the contents
+		to the record buffer that was passed in by MySQL. */
+
+		if (prebuilt->n_fetch_cached > 0) {
+			row_sel_dequeue_cached_row_for_mysql(buf, prebuilt);
+			err = DB_SUCCESS;
+		}
+
+	} else if (next_buf != 0) {
+
+		/* We may or may not have enqueued some buffers to the
+		pre-fetch queue, but we definitely wrote to the record
+		buffer passed to use by MySQL. */
 
 		err = DB_SUCCESS;
 	}

=== modified file 'storage/innobase/row/row0upd.cc'
--- a/storage/innobase/row/row0upd.cc	revid:viswanatham.gudipati@strippedqcic6v5kvzls1lk
+++ b/storage/innobase/row/row0upd.cc	revid:kevin.lewis@stripped
@@ -218,6 +218,8 @@ row_upd_check_references_constraints(
 
 	mtr_commit(mtr);
 
+	DEBUG_SYNC_C("foreign_constraint_check_for_update");
+
 	mtr_start(mtr);
 
 	if (trx->dict_operation_lock_mode == 0) {

=== modified file 'storage/innobase/sync/sync0arr.cc'
--- a/storage/innobase/sync/sync0arr.cc	revid:viswanatham.gudipati@stripped27152910-uqcic6v5kvzls1lk
+++ b/storage/innobase/sync/sync0arr.cc	revid:kevin.lewis@strippedsxxgbhodbg4r
@@ -902,6 +902,11 @@ sync_array_print_long_waits_low(
 	ibool		fatal = FALSE;
 	double		longest_diff = 0;
 
+	/* For huge tables, skip the check during CHECK TABLE etc... */
+	if (fatal_timeout > SRV_SEMAPHORE_WAIT_EXTENSION) {
+		return(FALSE);
+	}
+
 #ifdef UNIV_DEBUG_VALGRIND
 	/* Increase the timeouts if running under valgrind because it executes
 	extremely slowly. UNIV_DEBUG_VALGRIND does not necessary mean that

=== modified file 'unittest/gunit/decimal-t.cc'
--- a/unittest/gunit/decimal-t.cc	revid:viswanatham.gudipati@stripped-uqcic6v5kvzls1lk
+++ b/unittest/gunit/decimal-t.cc	revid:kevin.lewis@stripped
@@ -420,8 +420,10 @@ void do_test_pr(const char *s1, int prec
   int slen= sizeof(s2);
   int res;
 
-  sprintf(s, filler ? "'%s', %d, %d, '%c'" : "'%s', %d, %d, '\\0'",
-          s1, prec, dec, filler);
+  if (filler)
+    sprintf(s, "'%s', %d, %d, '%c'", s1, prec, dec, filler);
+  else
+    sprintf(s, "'%s', %d, %d, '\\0'", s1, prec, dec);
   end= strend(s1);
   string2decimal(s1, &a, &end);
   res= decimal2string(&a, s2, &slen, prec, dec, filler);

=== modified file 'unittest/gunit/dynarray-t.cc'
--- a/unittest/gunit/dynarray-t.cc	revid:viswanatham.gudipati@oracle.com-20120427152910-uqcic6v5kvzls1lk
+++ b/unittest/gunit/dynarray-t.cc	revid:kevin.lewis@stripped3156-uyr7sxxgbhodbg4r
@@ -83,6 +83,19 @@ static inline bool operator==(const Key_
 }
 
 
+static inline std::ostream &operator<<(std::ostream &s, const Key_use &v)
+{
+  return s << "{"
+           << v.table->tablenr << ", "
+           << v.key            << ", "
+           << v.keypart        << ", "
+           << v.used_tables    << ", "
+           << v.optimize
+           << "}"
+    ;
+}
+
+
 namespace {
 
 /*
@@ -108,19 +121,6 @@ inline int sort_keyuse(Key_use *a, Key_u
 }
 
 
-std::ostream &operator<<(std::ostream &s, const Key_use &v)
-{
-  return s << "{"
-           << v.table->tablenr << ", "
-           << v.key            << ", "
-           << v.keypart        << ", "
-           << v.used_tables    << ", "
-           << v.optimize
-           << "}"
-    ;
-}
-
-
 // We generate some random data at startup, for testing of sorting.
 void generate_test_data(Key_use *keys, TABLE *tables, int n)
 {

=== modified file 'unittest/gunit/stdcxx-t.cc'
--- a/unittest/gunit/stdcxx-t.cc	revid:viswanatham.gudipati@stripped
+++ b/unittest/gunit/stdcxx-t.cc	revid:kevin.lewis@strippedm-20120430183156-uyr7sxxgbhodbg4r
@@ -53,52 +53,3 @@ TEST(STDfeatures, HashMap)
   EXPECT_TRUE(0 == intmap.count(42));
   EXPECT_TRUE(intmap.end() == intmap.find(42));
 }
-
-#if defined(TARGET_OS_LINUX)
-
-#include <malloc.h>
-
-namespace {
-
-void *nop_malloc_hook(size_t size, const void *caller)
-{
-  return NULL;
-}
-
-TEST(StdCxxNoThrow, NoThrow)
-{
-  typeof(__malloc_hook) old_malloc_hook= __malloc_hook;
-
-  __malloc_hook= nop_malloc_hook;
-
-  const int *pnull= NULL;
-  int *ptr= new (std::nothrow) int;
-  __malloc_hook= old_malloc_hook;
-
-  EXPECT_EQ(pnull, ptr);
-}
-
-TEST(StdCxxExceptionInNew, NewThrowsException)
-{
-  typeof(__malloc_hook) old_malloc_hook= __malloc_hook;
-
-  __malloc_hook= nop_malloc_hook;
-
-  bool thrown= false;
-  try
-  {
-    int *ptr= new int;
-    *ptr= 0;
-  }
-  catch (std::bad_alloc &e)
-  {
-    thrown= true;
-  }
-  __malloc_hook= old_malloc_hook;
-
-  EXPECT_TRUE(thrown);
-}
-
-}
-
-#endif // TARGET_OS_LINUX

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (kevin.lewis:3745 to 3747) kevin.lewis2 May