List:Commits« Previous MessageNext Message »
From:Sven Sandberg Date:August 27 2008 1:43pm
Subject:bzr push into mysql-6.0 branch (sven:2677) Bug#33337 Bug#39011
View as plain text  
 2677 Sven Sandberg	2008-08-27 [merge]
      merge of 6.0-rpl into (local merge of 6.0-rpl into 6.0)
      all changes automerged, no conflicts
modified:
  client/mysqltest.cc
  mysql-test/mysql-test-run.pl
  sql/sql_class.h

=== modified file '.bzr-mysql/default.conf'
--- a/.bzr-mysql/default.conf	2008-07-28 17:44:14 +0000
+++ b/.bzr-mysql/default.conf	2008-08-21 08:18:48 +0000
@@ -1,5 +1,5 @@
-[MYSQL]
-tree_location = bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-6.0
-post_commit_to = commits@lists.mysql.com
-post_push_to = commits@stripped
-tree_name = mysql-6.0
+[MYSQL]
+tree_location = bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-6.0
+post_commit_to = commits@stripped
+post_push_to = commits@lists.mysql.com
+tree_name = mysql-6.0

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2008-08-26 12:42:44 +0000
+++ b/client/mysqltest.cc	2008-08-27 13:42:29 +0000
@@ -4167,12 +4167,13 @@ typedef struct
 {
   const char *name;
   uint        code;
+  const char *text;
 } st_error;
 
 static st_error global_error_names[] =
 {
 #include <mysqld_ername.h>
-  { 0, 0 }
+  { 0, 0, 0 }
 };
 
 uint get_errcode_from_name(char *error_name, char *error_end)

=== modified file 'config/ac-macros/character_sets.m4'
--- a/config/ac-macros/character_sets.m4	2008-08-22 17:03:15 +0000
+++ b/config/ac-macros/character_sets.m4	2008-08-27 12:49:58 +0000
@@ -376,8 +376,8 @@ case $default_charset in 
       default_charset_default_collation="utf8_general_ci"
       define(UTFC1, utf8_general_ci utf8_bin)
       define(UTFC2, utf8_czech_ci utf8_danish_ci)
-      define(UTFC3, utf8_esperanto_ci utf8_estonian_ci utf8_icelandic_ci)
-      define(UTFC4, utf8_latvian_ci utf8_lithuanian_ci)
+      define(UTFC3, utf8_esperanto_ci utf8_estonian_ci utf8_hungarian_ci)
+      define(UTFC4, utf8_icelandic_ci utf8_latvian_ci utf8_lithuanian_ci)
       define(UTFC5, utf8_persian_ci utf8_polish_ci utf8_romanian_ci)
       define(UTFC6, utf8_sinhala_ci utf8_slovak_ci utf8_slovenian_ci)
       define(UTFC7, utf8_spanish2_ci utf8_spanish_ci)
@@ -411,8 +411,8 @@ case $default_charset in 
       default_charset_default_collation="utf16_general_ci"
       define(UTFC1, utf16_general_ci utf16_bin)
       define(UTFC2, utf16_czech_ci utf16_danish_ci)
-      define(UTFC3, utf16_esperanto_ci utf16_estonian_ci utf16_icelandic_ci)
-      define(UTFC4, utf16_latvian_ci utf16_lithuanian_ci)
+      define(UTFC3, utf16_esperanto_ci utf16_estonian_ci utf16_hungarian_ci)
+      define(UTFC4, utf16_icelandic_ci utf16_latvian_ci utf16_lithuanian_ci)
       define(UTFC5, utf16_persian_ci utf16_polish_ci utf16_romanian_ci)
       define(UTFC6, utf16_sinhala_ci utf16_slovak_ci utf16_slovenian_ci)
       define(UTFC7, utf16_spanish2_ci utf16_spanish_ci)
@@ -425,8 +425,8 @@ case $default_charset in 
       default_charset_default_collation="utf32_general_ci"
       define(UTFC1, utf32_general_ci utf32_bin)
       define(UTFC2, utf32_czech_ci utf32_danish_ci)
-      define(UTFC3, utf32_esperanto_ci utf32_estonian_ci utf32_icelandic_ci)
-      define(UTFC4, utf32_latvian_ci utf32_lithuanian_ci)
+      define(UTFC3, utf32_esperanto_ci utf32_estonian_ci utf32_hungarian_ci)
+      define(UTFC4, utf32_icelandic_ci utf32_latvian_ci utf32_lithuanian_ci)
       define(UTFC5, utf32_persian_ci utf32_polish_ci utf32_romanian_ci)
       define(UTFC6, utf32_sinhala_ci utf32_slovak_ci utf32_slovenian_ci)
       define(UTFC7, utf32_spanish2_ci utf32_spanish_ci)

=== modified file 'configure.in'
--- a/configure.in	2008-08-07 20:51:09 +0000
+++ b/configure.in	2008-08-27 12:49:58 +0000
@@ -835,7 +835,7 @@ AC_TYPE_SIZE_T
 AC_HEADER_DIRENT
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(fcntl.h fenv.h float.h floatingpoint.h fpu_control.h \
+AC_CHECK_HEADERS(fcntl.h fenv.h float.h floatingpoint.h fpu_control.h ieeefp.h \
  limits.h memory.h pwd.h select.h \
  stdlib.h stddef.h sys/fpu.h sys/stat.h \
  strings.h string.h synch.h sys/mman.h sys/socket.h netinet/in.h arpa/inet.h \
@@ -846,6 +846,7 @@ AC_CHECK_HEADERS(fcntl.h fenv.h float.h 
  execinfo.h)
 
 AC_CHECK_HEADERS([xfs/xfs.h])
+AC_CHECK_HEADERS([valgrind/memcheck.h])
 
 #--------------------------------------------------------------------
 # Check for system libraries. Adds the library to $LIBS

=== modified file 'extra/comp_err.c'
--- a/extra/comp_err.c	2008-04-09 00:56:49 +0000
+++ b/extra/comp_err.c	2008-08-06 19:20:57 +0000
@@ -199,11 +199,33 @@ int main(int argc, char *argv[])
 }
 
 
+static void print_escaped_string(FILE *f, const char *str)
+{
+  const char *tmp = str;
+
+  while (tmp[0] != 0)
+  {
+    switch (tmp[0])
+    {
+      case '\\': fprintf(f, "\\\\"); break;
+      case '\'': fprintf(f, "\\\'"); break;
+      case '\"': fprintf(f, "\\\""); break;
+      case '\n': fprintf(f, "\\n"); break;
+      case '\r': fprintf(f, "\\r"); break;
+      default: fprintf(f, "%c", tmp[0]);
+    }
+    tmp++;
+  }
+}
+
+
 static int create_header_files(struct errors *error_head)
 {
   uint er_last;
   FILE *er_definef, *sql_statef, *er_namef;
   struct errors *tmp_error;
+  struct message *er_msg;
+  const char *er_text;
   DBUG_ENTER("create_header_files");
   LINT_INIT(er_last);
 
@@ -245,8 +267,12 @@ static int create_header_files(struct er
 	      "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
 	      tmp_error->sql_code1, tmp_error->sql_code2);
     /*generating er_name file */
-    fprintf(er_namef, "{ \"%s\", %d },\n", tmp_error->er_name,
+    er_msg= find_message(tmp_error, default_language, FALSE);
+    er_text = (er_msg ? er_msg->text : "");
+    fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
 	    tmp_error->d_code);
+    print_escaped_string(er_namef, er_text);
+    fprintf(er_namef, "\" },\n");
 
   }
   /* finishing off with mysqld_error.h */

=== modified file 'extra/perror.c'
--- a/extra/perror.c	2008-03-28 19:59:20 +0000
+++ b/extra/perror.c	2008-08-05 23:26:18 +0000
@@ -184,11 +184,51 @@ static const char *get_ha_error_msg(int 
   return NullS;
 }
 
+typedef struct
+{
+  const char *name;
+  uint        code;
+  const char *text;
+} st_error;
+
+static st_error global_error_names[] =
+{
+#include <mysqld_ername.h>
+  { 0, 0, 0 }
+};
+
+/**
+  Lookup an error by code in the global_error_names array.
+  @param code the code to lookup
+  @param [out] name_ptr the error name, when found
+  @param [out] msg_ptr the error text, when found
+  @return 1 when found, otherwise 0
+*/
+int get_ER_error_msg(uint code, const char **name_ptr, const char **msg_ptr)
+{
+  st_error *tmp_error;
+
+  tmp_error= & global_error_names[0];
+
+  while (tmp_error->name != NULL)
+  {
+    if (tmp_error->code == code)
+    {
+      *name_ptr= tmp_error->name;
+      *msg_ptr= tmp_error->text;
+      return 1;
+    }
+    tmp_error++;
+  }
+
+  return 0;
+}
 
 int main(int argc,char *argv[])
 {
   int error,code,found;
   const char *msg;
+  const char *name;
   char *unknown_error = 0;
   MY_INIT(argv[0]);
 
@@ -291,6 +331,14 @@ int main(int argc,char *argv[])
         else
           puts(msg);
       }
+      if (get_ER_error_msg(code, & name, & msg))
+      {
+        found= 1;
+        if (verbose)
+          printf("MySQL error code %3d (%s): %s\n", code, name, msg);
+        else
+          puts(msg);
+      }
       if (!found)
       {
         fprintf(stderr,"Illegal error code: %d\n", code);

=== modified file 'include/my_handler.h'
--- a/include/my_handler.h	2008-07-22 14:16:22 +0000
+++ b/include/my_handler.h	2008-08-27 12:49:58 +0000
@@ -54,8 +54,8 @@ typedef struct st_HA_KEYSEG		/* Key-port
   uint16 bit_pos;                       /* Position to bit part */
   uint16 flag;
   uint16 length;			/* Keylength */
+  uint16 language;
   uint8  type;				/* Type of key (for sort) */
-  uint8  language;
   uint8  null_bit;			/* bitmask to test for NULL */
   uint8  bit_start,bit_end;		/* if bit field */
   uint8  bit_length;                    /* Length of bit part */

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2008-08-05 11:20:20 +0000
+++ b/include/my_sys.h	2008-08-27 12:49:58 +0000
@@ -233,8 +233,9 @@ extern uint    my_large_page_size;
 #endif
 
 /* charsets */
+#define MY_ALL_CHARSETS_SIZE 512
 extern CHARSET_INFO *default_charset_info;
-extern CHARSET_INFO *all_charsets[256];
+extern CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
 extern CHARSET_INFO compiled_charsets[];
 
 /* statistics */

=== modified file 'include/myisam.h'
--- a/include/myisam.h	2008-07-22 14:16:22 +0000
+++ b/include/myisam.h	2008-08-27 12:49:58 +0000
@@ -170,7 +170,7 @@ typedef struct st_mi_create_info
   ulonglong data_file_length;
   ulonglong key_file_length;
   uint old_options;
-  uint8 language;
+  uint16 language;
   my_bool with_auto_increment;
 } MI_CREATE_INFO;
 

=== modified file 'include/myisamchk.h'
--- a/include/myisamchk.h	2008-04-10 02:26:36 +0000
+++ b/include/myisamchk.h	2008-07-24 11:33:35 +0000
@@ -148,7 +148,7 @@ typedef struct st_handler_check_param
   uint key_cache_block_size, pagecache_block_size;
   int tmpfile_createflag, err_count;
   myf myf_rw;
-  uint8 language;
+  uint16 language;
   my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
   my_bool retry_repair, force_sort, calc_checksum, static_row_size;
   char temp_filename[FN_REFLEN];

=== added file 'mysql-test/include/have_nodebug.inc'
--- a/mysql-test/include/have_nodebug.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/have_nodebug.inc	2008-07-24 16:50:18 +0000
@@ -0,0 +1,4 @@
+-- require r/have_nodebug.require
+disable_query_log;
+select (version() like '%debug%') as debug;
+enable_query_log;

=== added file 'mysql-test/install_test_db.sh'
--- a/mysql-test/install_test_db.sh	1970-01-01 00:00:00 +0000
+++ b/mysql-test/install_test_db.sh	2008-05-29 15:33:33 +0000
@@ -0,0 +1,115 @@
+#!/bin/sh
+# Copyright (C) 1997-2006 MySQL AB
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+# This scripts creates the privilege tables db, host, user, tables_priv,
+# columns_priv in the mysql database, as well as the func table.
+
+if [ x$1 = x"--bin" ]; then
+  shift 1
+  BINARY_DIST=1
+
+  bindir=../bin
+  scriptdir=bin
+  libexecdir=../libexec
+
+  # Check if it's a binary distribution or a 'make install'
+  if test -x ../libexec/mysqld
+  then
+    execdir=../libexec
+  elif test -x ../../sbin/mysqld  # RPM installation
+  then
+    execdir=../../sbin
+    bindir=../../bin
+    scriptdir=../bin
+    libexecdir=../../libexec
+  else
+    execdir=../bin
+  fi
+  fix_bin=mysql-test
+else
+  execdir=../sql
+  bindir=../client
+  fix_bin=.
+  scriptdir=scripts
+  libexecdir=../libexec
+fi
+
+vardir=var
+logdir=$vardir/log
+if [ x$1 = x"-slave" ] 
+then
+ shift 1
+ data=var/slave-data
+else
+ if [ x$1 = x"-1" ] 
+ then
+   data=var/master-data1
+ else
+   data=var/master-data
+ fi
+fi
+ldata=$fix_bin/$data
+
+mdata=$data/mysql
+EXTRA_ARG=""
+
+mysqld=
+if test -x $execdir/mysqld
+then
+  mysqld=$execdir/mysqld
+else
+  if test ! -x $libexecdir/mysqld
+  then
+    echo "mysqld is missing - looked in $execdir and in $libexecdir"
+    exit 1
+  else
+    mysqld=$libexecdir/mysqld
+  fi
+fi
+
+# On IRIX hostname is in /usr/bsd so add this to the path
+PATH=$PATH:/usr/bsd
+hostname=`hostname`		# Install this too in the user table
+hostname="$hostname%"		# Fix if not fully qualified hostname
+
+
+#create the directories
+[ -d $vardir ] || mkdir $vardir
+[ -d $logdir ] || mkdir $logdir
+
+# Create database directories mysql & test
+if [ -d $data ] ; then rm -rf $data ; fi
+mkdir $data $data/mysql $data/test 
+
+#for error messages
+if [ x$BINARY_DIST = x1 ] ; then
+basedir=..
+else
+basedir=.
+EXTRA_ARG="--windows"
+fi
+
+INSTALL_CMD="$scriptdir/mysql_install_db --no-defaults $EXTRA_ARG --datadir=mysql-test/$ldata --srcdir=."
+echo "running $INSTALL_CMD"
+
+cd ..
+if $INSTALL_CMD
+then
+    exit 0
+else
+    echo "Error executing mysqld --bootstrap"
+    exit 1
+fi

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2008-08-08 17:55:07 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2008-08-27 12:49:58 +0000
@@ -569,6 +569,37 @@ sub optimize_cases {
 	  if ( $default_engine =~ /^innodb/i );
       }
     }
+
+      # =======================================================
+      # Check that engine selected by
+      # --default-storage-engine=<engine> is supported
+      # =======================================================
+      my %builtin_engines = ('myisam' => 1, 'memory' => 1);
+
+      foreach my $opt ( @{$tinfo->{master_opt}} ) {
+      my $default_engine=
+        mtr_match_prefix($opt, "--default-storage-engine=");
+
+      if (defined $default_engine){
+
+
+        my $engine_value= $::mysqld_variables{$default_engine};
+
+        if ( ! exists $::mysqld_variables{$default_engine} and
+             ! exists $builtin_engines{$default_engine} )
+        {
+          $tinfo->{'skip'}= 1;
+          $tinfo->{'comment'}=
+            "'$default_engine' not supported";
+        }
+
+        $tinfo->{'ndb_test'}= 1
+          if ( $default_engine =~ /^ndb/i );
+        $tinfo->{'innodb_test'}= 1
+          if ( $default_engine =~ /^innodb/i );
+      }
+    }
+
   }
 }
 

=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm	2008-08-08 17:55:07 +0000
+++ b/mysql-test/lib/mtr_report.pm	2008-08-27 12:49:58 +0000
@@ -254,8 +254,281 @@ sub mtr_report_stats ($) {
   my $warnlog= "$::opt_vardir/log/warnings";
   if ( -f $warnlog )
   {
-    mtr_warning("Got errors/warnings while running tests, please examine",
-		"'$warnlog' for details.");
+    # Save and report if there was any fatal warnings/errors in err logs
+
+    my $warnlog= "$::opt_vardir/log/warnings";
+
+    unless ( open(WARN, ">$warnlog") )
+    {
+      mtr_warning("can't write to the file \"$warnlog\": $!");
+    }
+    else
+    {
+      # We report different types of problems in order
+      foreach my $pattern ( "^Warning:",
+			    "\\[Warning\\]",
+			    "\\[ERROR\\]",
+			    "^Error:", "^==.* at 0x",
+			    "InnoDB: Warning",
+			    "InnoDB: Error",
+			    "^safe_mutex:",
+			    "missing DBUG_RETURN",
+			    "mysqld: Warning",
+			    "allocated at line",
+			    "Attempting backtrace", "Assertion .* failed" )
+      {
+        foreach my $errlog ( sort glob("$::opt_vardir/log/*.err") )
+        {
+	  my $testname= "";
+          unless ( open(ERR, $errlog) )
+          {
+            mtr_warning("can't read $errlog");
+            next;
+          }
+          my $leak_reports_expected= undef;
+          while ( <ERR> )
+          {
+            # There is a test case that purposely provokes a
+            # SAFEMALLOC leak report, even though there is no actual
+            # leak. We need to detect this, and ignore the warning in
+            # that case.
+            if (/Begin safemalloc memory dump:/) {
+              $leak_reports_expected= 1;
+            } elsif (/End safemalloc memory dump./) {
+              $leak_reports_expected= undef;
+            }
+
+            # Skip some non fatal warnings from the log files
+            if (
+		/\"SELECT UNIX_TIMESTAMP\(\)\" failed on master/ or
+		/Aborted connection/ or
+		/Client requested master to start replication from impossible position/ or
+		/Could not find first log file name in binary log/ or
+		/Enabling keys got errno/ or
+		/Error reading master configuration/ or
+		/Error reading packet/ or
+		/Event Scheduler/ or
+		/Failed to open log/ or
+		/Failed to open the existing master info file/ or
+		/Forcing shutdown of [0-9]* plugins/ or
+                /Can't open shared library .*\bha_example\b/ or
+                /Couldn't load plugin .*\bha_example\b/ or
+
+		# Due to timing issues, it might be that this warning
+		# is printed when the server shuts down and the
+		# computer is loaded.
+		/Forcing close of thread \d+  user: '.*?'/ or
+
+		/Got error [0-9]* when reading table/ or
+		/Incorrect definition of table/ or
+		/Incorrect information in file/ or
+		/InnoDB: Warning: we did not need to do crash recovery/ or
+		/Invalid \(old\?\) table or database name/ or
+		/Lock wait timeout exceeded/ or
+		/Log entry on master is longer than max_allowed_packet/ or
+                /unknown option '--loose-/ or
+                /unknown variable 'loose-/ or
+		/You have forced lower_case_table_names to 0 through a command-line option/ or
+		/Setting lower_case_table_names=2/ or
+		/NDB Binlog:/ or
+		/NDB: failed to setup table/ or
+		/NDB: only row based binary logging/ or
+		/Neither --relay-log nor --relay-log-index were used/ or
+		/Query partially completed/ or
+		/Slave I.O thread aborted while waiting for relay log/ or
+		/Slave SQL thread is stopped because UNTIL condition/ or
+		/Slave SQL thread retried transaction/ or
+		/Slave \(additional info\)/ or
+		/Slave: .*Duplicate column name/ or
+		/Slave: .*master may suffer from/ or
+		/Slave: According to the master's version/ or
+		/Slave: Column [0-9]* type mismatch/ or
+                /Slave: Can't DROP 'c7'; check that column.key exists Error_code: 1091/ or
+                /Slave: Unknown column 'c7' in 't15' Error_code: 1054/ or
+                /Slave: Key column 'c6' doesn't exist in table Error_code: 1072/ or
+		/Slave: Error .* doesn't exist/ or
+		/Slave: Error .*Deadlock found/ or
+		/Slave: Error .*Unknown table/ or
+		/Slave: Error in Write_rows event: / or
+		/Slave: Field .* of table .* has no default value/ or
+                /Slave: Field .* doesn't have a default value/ or
+		/Slave: Query caused different errors on master and slave/ or
+		/Slave: Table .* doesn't exist/ or
+		/Slave: Table width mismatch/ or
+		/Slave: The incident LOST_EVENTS occured on the master/ or
+		/Slave: Unknown error.* 1105/ or
+		/Slave: Can't drop database.* database doesn't exist/ or
+                /Slave SQL:.*(?:Error_code: \d+|Query:.*)/ or
+		
+		# backup_errors test is supposed to trigger lots of backup related errors
+		($testname eq 'main.backup_errors') and
+		(
+		  /Backup:/ or /Restore:/ or /Can't open the online backup progress tables/
+		) or
+
+		# backup_backupdir test is supposed to trigger backup related errors
+		($testname eq 'main.backup_backupdir') and
+		(
+		  /Backup:/ or /Can't write to backup location/
+		) or
+                
+		# backup_concurrent performs a backup that should fail
+		($testname eq 'main.backup_concurrent') and
+		(
+		  /Can't execute this command because another BACKUP\/RESTORE operation is in progress/
+		) or
+                
+		# The tablespace test triggers error below on purpose
+		($testname eq 'main.backup_tablespace') and
+		(
+		  /Restore: Tablespace .* needed by tables being restored has changed on the server/
+		) or
+		
+		# The views test triggers errors below on purpose
+		($testname eq 'main.backup_views') and
+		(
+		  /Backup: Failed to add view/ or
+		  /Backup: Failed to obtain meta-data for view/ or
+		  /Restore: Could not restore view/
+		) or
+ 	 
+		# ignore warning generated when backup engine selection algorithm is tested
+		($testname eq 'main.backup_no_be') and /Backup: Cannot create backup engine/ or
+		# ignore warnings generated when backup privilege is tested
+		($testname eq 'main.backup_security') and /(Backup|Restore): Access denied; you need the SUPER/ or
+		
+                ($testname eq 'main.backup_myisam1') and
+                (/Backup: Can't initialize MyISAM backup driver/) or
+		/Sort aborted/ or
+		/Time-out in NDB/ or
+		/One can only use the --user.*root/ or
+		/Setting lower_case_table_names=2/ or
+		/Table:.* on (delete|rename)/ or
+		/You have an error in your SQL syntax/ or
+		/deprecated/ or
+		/description of time zone/ or
+		/equal MySQL server ids/ or
+		/error .*connecting to master/ or
+		/error reading log entry/ or
+		/lower_case_table_names is set/ or
+		/skip-name-resolve mode/ or
+		/slave SQL thread aborted/ or
+		/Slave: .*Duplicate entry/ or
+		# Special case for Bug #26402 in show_check.test
+		# Question marks are not valid file name parts
+		# on Windows platforms. Ignore this error message. 
+		/\QCan't find file: '.\test\????????.frm'\E/ or
+		# Special case, made as specific as possible, for:
+		# Bug #28436: Incorrect position in SHOW BINLOG EVENTS causes
+		#             server coredump
+		/\QError in Log_event::read_log_event(): 'Sanity check failed', data_len: 258, event_type: 49\E/ or
+                /Statement is not safe to log in statement format/ or
+
+                # test case for Bug#bug29807 copies a stray frm into database
+                /InnoDB: Error: table `test`.`bug29807` does not exist in the InnoDB internal/ or
+                /Cannot find or open table test\/bug29807 from/ or
+
+                # innodb foreign key tests that fail in ALTER or RENAME produce this
+                /InnoDB: Error: in ALTER TABLE `test`.`t[12]`/ or
+                /InnoDB: Error: in RENAME TABLE table `test`.`t1`/ or
+                /InnoDB: Error: table `test`.`t[12]` does not exist in the InnoDB internal/ or
+
+                # Test case for Bug#14233 produces the following warnings:
+                /Stored routine 'test'.'bug14233_1': invalid value in column mysql.proc/ or
+                /Stored routine 'test'.'bug14233_2': invalid value in column mysql.proc/ or
+                /Stored routine 'test'.'bug14233_3': invalid value in column mysql.proc/ or
+
+                # BUG#29839 - lowercase_table3.test: Cannot find table test/T1
+                #             from the internal data dictiona
+                /Cannot find table test\/BUG29839 from the internal data dictionary/ or
+                # BUG#32080 - Excessive warnings on Solaris: setrlimit could not
+                #             change the size of core files
+                /setrlimit could not change the size of core files to 'infinity'/ or
+
+                # rpl_ndb_basic expects this error
+                /Slave: Got error 146 during COMMIT Error_code: 1180/ or
+
+		# rpl_extrColmaster_*.test, the slave thread produces warnings
+		# when it get updates to a table that has more columns on the
+		# master
+		/Slave: Unknown column 'c7' in 't15' Error_code: 1054/ or
+		/Slave: Can't DROP 'c7'.* 1091/ or
+		/Slave: Key column 'c6'.* 1072/ or
+
+                # BUG#32080 - Excessive warnings on Solaris: setrlimit could not
+                #             change the size of core files
+                /setrlimit could not change the size of core files to 'infinity'/ or
+                # rpl_idempotency.test produces warnings for the slave.
+                ($testname eq 'rpl.rpl_idempotency' and
+                 (/Slave: Can\'t find record in \'t1\' Error_code: 1032/ or
+                   /Slave: Cannot add or update a child row: a foreign key constraint fails .* Error_code: 1452/
+                 )) or
+ 
+                # These tests does "kill" on queries, causing sporadic errors when writing to logs
+                (($testname eq 'rpl.rpl_skip_error' or
+                  $testname eq 'rpl.rpl_err_ignoredtable' or
+                  $testname eq 'binlog.binlog_killed_simulate' or
+                  $testname eq 'binlog.binlog_killed') and
+                 (/Failed to write to mysql\.\w+_log/
+                 )) or
+
+		# rpl_bug33931 has deliberate failures
+		($testname eq 'rpl.rpl_bug33931' and
+		 (/Failed during slave.*thread initialization/
+		  )) or
+
+                # rpl_temporary has an error on slave that can be ignored
+                ($testname eq 'rpl.rpl_temporary' and
+                 (/Slave: Can\'t find record in \'user\' Error_code: 1032/
+                 )) or
+                # Test case for Bug#31590 produces the following error:
+                /Out of sort memory; increase server sort buffer size/ or
+                # maria-recovery.test has warning about missing log file
+                /File '.*maria_log.000.*' not found \(Errcode: 2\)/ or
+                # and about marked-corrupted table
+                /Table '.\/mysqltest\/t_corrupted1' is crashed, skipping it. Please repair it with maria_chk -r/ or
+                # maria-recover.test corrupts tables on purpose
+                /Checking table:   '.\/mysqltest\/t_corrupted2'/ or
+                /Recovering table: '.\/mysqltest\/t_corrupted2'/ or
+                /Table '.\/mysqltest\/t_corrupted2' is marked as crashed and should be repaired/ or
+                /Incorrect key file for table '.\/mysqltest\/t_corrupted2.MAI'; try to repair it/
+	       )
+            {
+              next;                       # Skip these lines
+            }
+	    if ( /CURRENT_TEST: (.*)/ )
+	    {
+	      $testname= $1;
+	    }
+            if ( /$pattern/ )
+            {
+              if ($leak_reports_expected) {
+                next;
+              }
+              $found_problems= 1;
+              print WARN basename($errlog) . ": $testname: $_";
+            }
+          }
+        }
+      }
+
+      if ( $::opt_check_testcases )
+      {
+        # Look for warnings produced by mysqltest in testname.warnings
+        foreach my $test_warning_file
+	  ( glob("$::glob_mysql_test_dir/r/*.warnings") )
+        {
+          $found_problems= 1;
+	  print WARN "Check myqltest warnings in $test_warning_file\n";
+        }
+      }
+
+      if ( $found_problems )
+      {
+	mtr_warning("Got errors/warnings while running tests, please examine",
+                    "'$warnlog' for details.");
+      }
+    }
   }
 
   print "\n";

=== added file 'mysql-test/r/backup_backupdir.result'
--- a/mysql-test/r/backup_backupdir.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_backupdir.result	2008-08-08 17:21:31 +0000
@@ -0,0 +1,56 @@
+Reset backupdir 
+SET @@global.backupdir = @@global.datadir;
+DROP DATABASE IF EXISTS bup_backupdir;
+Create a database
+CREATE DATABASE bup_backupdir;
+CREATE TABLE bup_backupdir.t1(a INT);
+INSERT INTO bup_backupdir.t1 VALUES (1), (2), (3);
+Create a directory for backup images
+Reset backupdir 
+SET @@global.backupdir = '../tmp/backup';
+Perform backup
+BACKUP DATABASE bup_backupdir TO 'bup_backupdir1.bak';
+backup_id
+#
+Ensure backup image file went to the correct location
+/backup/bup_backupdir.bak
+Perform restore
+RESTORE FROM 'bup_backupdir1.bak';
+backup_id
+#
+Now do the backup and restore by specifying a path.
+Perform backup
+BACKUP DATABASE bup_backupdir TO '../bup_backupdir2.bak';
+backup_id
+#
+Ensure backup image file went to the correct location
+Perform restore
+RESTORE FROM '../bup_backupdir2.bak';
+backup_id
+#
+Perform backup
+BACKUP DATABASE bup_backupdir TO '../../bup_backupdir3.bak';
+backup_id
+#
+Ensure backup image file went to the correct location
+Reset backupdir with ending /
+SET @@global.backupdir = '../tmp/backup/';
+Perform backup
+BACKUP DATABASE bup_backupdir TO '../../bup_backupdir4.bak';
+backup_id
+#
+Ensure backup image file went to the correct location
+Try a backup to an invalid relative path.
+BACKUP DATABASE bup_backupdir TO '../../../../../../../../../../../../../../../../../../bup_backupdir5.bak';
+ERROR HY000: Can't write to backup location '../../../../../../../../../../../../../../../../../../bup_backup' (file already exists?)
+Try a backup to an invalid hard path.
+BACKUP DATABASE bup_backupdir TO '/dev/not/there/either/bup_backupdir6.bak';
+ERROR HY000: Can't write to backup location '/dev/not/there/either/bup_backupdir6.bak' (file already exists?)
+SET @@global.backupdir = 'This_is_really_stupid/not/there/at/all';
+Warnings:
+Warning	1725	The path specified for the system variable backupdir cannot be accessed or is invalid. ref: This_is_really_stupid/not/there/at/all
+Warning	1725	The path specified for the system variable backupdir cannot be accessed or is invalid. ref: This_is_really_stupid/not/there/at/all
+Cleanup
+Reset backupdir 
+SET @@global.backupdir = @@global.datadir;
+DROP DATABASE bup_backupdir;

=== added file 'mysql-test/r/backup_concurrent.result'
--- a/mysql-test/r/backup_concurrent.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_concurrent.result	2008-08-08 11:17:37 +0000
@@ -0,0 +1,75 @@
+SET DEBUG_SYNC= 'reset';
+DROP DATABASE IF EXISTS backup_concurrent;
+CREATE DATABASE backup_concurrent;
+USE backup_concurrent;
+Creating Table
+CREATE TABLE t (
+t1 INTEGER NOT NULL,
+t2 CHAR(36),
+PRIMARY KEY (t1)
+);
+---------------------------------------------------
+Testing starting new backup while backup is ongoing
+---------------------------------------------------
+Starting first backup
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR backup';
+BACKUP DATABASE backup_concurrent TO 'backup1';
+Waiting for first backup to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+Starting second backup in another connection.  
+(Should fail because another backup is running.)
+BACKUP DATABASE backup_concurrent TO 'backup2';
+ERROR HY000: Can't execute this command because another BACKUP/RESTORE operation is in progress
+Insert Data
+INSERT INTO t VALUES (1, 'test');
+Wait for first backup to complete
+SET DEBUG_SYNC= 'now SIGNAL backup';
+backup_id
+#
+---------------------------------------------------
+Testing starting restore while backup is ongoing
+---------------------------------------------------
+Starting backup
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR backup';
+BACKUP DATABASE backup_concurrent TO 'backup3';
+Waiting for backup to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+Starting restore in another connection.  
+(Should fail because another backup is running.)
+RESTORE FROM 'backup1';
+ERROR HY000: Can't execute this command because another BACKUP/RESTORE operation is in progress
+Insert Data
+INSERT INTO t VALUES (2, 'test');
+Wait for backup to complete
+SET DEBUG_SYNC= 'now SIGNAL backup';
+backup_id
+#
+---------------------------------------------------
+Testing starting backup/restore restore is ongoing
+---------------------------------------------------
+Starting restore
+SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR restore';
+RESTORE FROM 'backup1';
+Waiting for restore to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+Starting backup in another connection.  
+(Should fail because restore is running.)
+BACKUP DATABASE backup_concurrent TO 'backup4';
+ERROR HY000: Can't execute this command because another BACKUP/RESTORE operation is in progress
+Insert Data
+INSERT INTO t VALUES (3, 'test');
+Starting a new restore in another connection.  
+(Should fail because another restore is running.)
+RESTORE FROM 'backup3';
+ERROR HY000: Can't execute this command because another BACKUP/RESTORE operation is in progress
+Insert Data
+INSERT INTO t VALUES (4, 'test');
+Wait for backup to complete
+SET DEBUG_SYNC= 'now SIGNAL restore';
+backup_id
+#
+
+Test completed. Cleaning up.
+
+DROP DATABASE backup_concurrent;
+SET DEBUG_SYNC= 'reset';

=== modified file 'mysql-test/r/backup_progress.result'
--- a/mysql-test/r/backup_progress.result	2008-07-09 18:37:42 +0000
+++ b/mysql-test/r/backup_progress.result	2008-08-08 17:21:31 +0000
@@ -1,3 +1,33 @@
+
+Checking character set for backup tables 
+
+SELECT column_name, character_set_name 
+FROM information_schema.columns 
+WHERE table_name LIKE 'online_backup' 
+AND character_set_name LIKE 'utf8' 
+ORDER BY column_name;
+column_name	character_set_name
+backup_file	utf8
+backup_state	utf8
+binlog_file	utf8
+command	utf8
+drivers	utf8
+host_or_server_name	utf8
+operation	utf8
+username	utf8
+user_comment	utf8
+
+SELECT column_name, character_set_name 
+FROM information_schema.columns 
+WHERE table_name LIKE 'online_backup_progress' 
+AND character_set_name LIKE 'utf8' 
+ORDER BY column_name;
+column_name	character_set_name
+notes	utf8
+object	utf8
+
+Now starting real tests
+
 SET DEBUG_SYNC= 'reset';
 DROP DATABASE IF EXISTS backup_progress;
 DROP TABLE IF EXISTS backup_progress.t1_res;
@@ -78,7 +108,7 @@ start_time	#
 stop_time	#
 host_or_server_name	localhost
 username	root
-backup_file	backup_progress_orig.bak
+backup_file	#
 user_comment	
 command	BACKUP DATABASE backup_progress to 'backup_progress_orig.bak'
 drivers	MyISAM, Default, Snapshot
@@ -135,7 +165,7 @@ start_time	#
 stop_time	#
 host_or_server_name	localhost
 username	root
-backup_file	backup_progress_orig.bak
+backup_file	#
 user_comment	
 command	RESTORE FROM 'backup_progress_orig.bak'
 drivers	MyISAM, Default, Snapshot

=== modified file 'mysql-test/r/backup_views.result'
--- a/mysql-test/r/backup_views.result	2008-06-12 09:55:35 +0000
+++ b/mysql-test/r/backup_views.result	2008-08-11 10:41:41 +0000
@@ -6,11 +6,16 @@ DROP DATABASE IF EXISTS bup_db2;
 CREATE DATABASE bup_db1;
 USE bup_db1;
 Creating Table t1
-CREATE TABLE t1(id int not null primary key, name char(10),city varchar(10));
+CREATE TABLE bup_db1.t1(
+id INT NOT NULL PRIMARY KEY, 
+name CHAR(10),
+city VARCHAR(10)
+)ENGINE=INNODB;
 loading data
-INSERT INTO t1 VALUES 
-(1,'aa1','RR1'),(2,'aa2','RR2'),(3,'aa3','RR3'),(4,'aa4','RR4'),(5,'aa5','RR5'),(6,'aa6','RR6'),(7,'aa7','RR7'),(8,'aa8','RR8');
-SELECT * FROM t1;
+INSERT INTO bup_db1.t1 VALUES
+(1,'aa1','RR1'),(2,'aa2','RR2'),(3,'aa3','RR3'),(4,'aa4','RR4'),
+(5,'aa5','RR5'),(6,'aa6','RR6'),(7,'aa7','RR7'),(8,'aa8','RR8');
+SELECT * FROM bup_db1.t1 ORDER BY id;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -21,66 +26,85 @@ id	name	city
 7	aa7	RR7
 8	aa8	RR8
 Creating Table t3
-CREATE TABLE t3(ccode int, District char(20) not null primary key, scode int, foreign key (scode) references t1(id));
+CREATE TABLE bup_db1.t3(
+ccode INT, 
+District CHAR(20) NOT NULL PRIMARY KEY, 
+scode INT, 
+FOREIGN KEY (scode) REFERENCES bup_db1.t1(id)
+)ENGINE=INNODB;
 Loading Data
 INSERT INTO t3 VALUES
-(234, 'zuloa',1),(321,'yyy',2),(765,'iug',3),(124,'LKJ',4),(235,'uth',6);
-SELECT * FROM t3;
+(234, 'zuloa',1),(321,'yyy',2),(765,'iug',3),
+(124,'LKJ',4),(235,'uth',6);
+SELECT * FROM bup_db1.t3 ORDER BY scode;
 ccode	District	scode
 234	zuloa	1
 321	yyy	2
 765	iug	3
 124	LKJ	4
 235	uth	6
+*****Create view from the table bup_db1.t1*******
+CREATE VIEW bup_db1.v1 AS SELECT * FROM bup_db1.t1;
+***Create views from 2 tables(t1 and t3) within same DB bup_db1****
+CREATE VIEW bup_db1.vcomb AS 
+SELECT name, city, ccode FROM bup_db1.t1, bup_db1.t3 WHERE id=scode;
+CREATE DATABASE bup_db2;
+CREATE TABLE bup_db2.t2(
+idno INT, 
+age INT PRIMARY KEY, 
+education CHAR(20) ,
+FOREIGN KEY (idno) REFERENCES bup_db1.t1(id)
+)ENGINE=INNODB;
+INSERT INTO bup_db2.t2 VALUES
+(1,23,'BS'),(2,24,'BE'),(3,19,'School'),(4,28,'MS'),
+(5,43,'PHD'),(6,30,'Doctor'),(7,31,'Lawyer'),(8,27,'Undergrad');
+SELECT * FROM bup_db2.t2 ORDER BY age;
+idno	age	education
+3	19	School
+1	23	BS
+2	24	BE
+8	27	Undergrad
+4	28	MS
+6	30	Doctor
+7	31	Lawyer
+5	43	PHD
+****Create view in bup_db2****
+CREATE VIEW bup_db2.v2 AS SELECT age, education FROM bup_db2.t2;
+******Create views from combination of 2 databases*******
+CREATE VIEW bup_db2.v3 AS SELECT name, age, education 
+FROM bup_db1.t1 , bup_db2.t2 WHERE id=idno;
+*********Create view from another view in bup_db2***********.
+CREATE VIEW bup_db2.vv (N, A, E) AS SELECT * FROM bup_db2.v3;
+*****Create view from other Database********
+CREATE VIEW bup_db2.v4 AS SELECT * FROM bup_db1.t3;
+Rename the view name
+RENAME TABLE bup_db2.v4 to bup_db2.student_details;
+*******Create view from database bup_db2**********
+CREATE VIEW bup_db1.v5 AS SELECT * FROM bup_db2.t2;
 Creating Table t5
-CREATE TABLE t5(Gender char(5), cand_age int,foreign key(cand_age) references 
-bup_db2.t2(age));
+CREATE TABLE bup_db1.t5(
+Gender CHAR(5),
+cand_age INT,
+FOREIGN KEY(cand_age) REFERENCES bup_db2.t2(age)
+)ENGINE=INNODB;
 Loading data into table t5
-INSERT INTO t5 VALUES
-('F',23),('F',24),('M',19),('F',28),('M',43),('F',30),('M',31),('M',27);
-SELECT * FROM t5;
+INSERT INTO bup_db1.t5 VALUES
+('F',23),('F',24),('M',19),('F',28),
+('M',43),('F',30),('M',31),('M',27);
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
 Gender	cand_age
 F	23
 F	24
-M	19
 F	28
-M	43
 F	30
+M	19
+M	43
 M	31
 M	27
-*****Create views from the table t1 of bup_db1*******
-CREATE VIEW v1  AS SELECT * FROM t1;
-*****Creating views from 2 tables(t1 and t3) within same database******
-CREATE VIEW vcomb AS SELECT name, city, ccode FROM t1, t3 WHERE id=scode;
-CREATE DATABASE bup_db2;
-USE bup_db2;
-CREATE TABLE t2(idno int, age int primary key, education char(20) ,foreign key (idno) references bup_db1.t1(id));
-INSERT INTO t2 VALUES(1,23,'BS'),(2,24,'BE'),(3,19,'school'),(4,28,'MS'),(5,43,'PHD'),(6,30,'Doctor'),(7,31,'Lawyer'),(8,27,'undergrad');
-SELECT * FROM t2;
-idno	age	education
-1	23	BS
-2	24	BE
-3	19	school
-4	28	MS
-5	43	PHD
-6	30	Doctor
-7	31	Lawyer
-8	27	undergrad
-****Creating View****
-CREATE VIEW v2 AS SELECT age, education FROM t2;
-******Creating Views from combination of 2 databases*******
-CREATE VIEW v3 AS SELECT name, age, education FROM bup_db1.t1 , bup_db2.t2 WHERE id=idno;
-*********Creating View from another view ***********.
-*****Creating View from other Database********
-CREATE VIEW v4 AS SELECT * FROM bup_db1.t3;
-Rename the view name
-RENAME TABLE v4 to student_details;
-USE bup_db1;
-*******Creating View from database bup_db2**********
-CREATE VIEW v5 AS SELECT * FROM bup_db2.t2;
-******Creating View v6********
-USE bup_db1;
-SELECT * FROM t1;
+******Create view v6********
+CREATE VIEW bup_db1.v6 AS SELECT education,gender 
+FROM bup_db2.v2, bup_db1.t5  WHERE cand_age=age;
+SELECT * FROM bup_db1.t1 ORDER BY id;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -90,24 +114,24 @@ id	name	city
 6	aa6	RR6
 7	aa7	RR7
 8	aa8	RR8
-SELECT * FROM t3;
+SELECT * FROM bup_db1.t3 ORDER BY scode;
 ccode	District	scode
 234	zuloa	1
 321	yyy	2
 765	iug	3
 124	LKJ	4
 235	uth	6
-SELECT * FROM t5;
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
 Gender	cand_age
 F	23
 F	24
-M	19
 F	28
-M	43
 F	30
+M	19
+M	43
 M	31
 M	27
-SELECT * FROM v1;
+SELECT * FROM bup_db1.v1;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -117,62 +141,81 @@ id	name	city
 6	aa6	RR6
 7	aa7	RR7
 8	aa8	RR8
-SELECT * FROM vcomb;
+SELECT * FROM bup_db1.vcomb ORDER BY name;
 name	city	ccode
 aa1	RR1	234
 aa2	RR2	321
 aa3	RR3	765
 aa4	RR4	124
 aa6	RR6	235
-SELECT * FROM v5;
+SELECT * FROM bup_db1.v5 ORDER BY age;
 idno	age	education
+3	19	School
 1	23	BS
 2	24	BE
-3	19	school
+8	27	Undergrad
 4	28	MS
-5	43	PHD
 6	30	Doctor
 7	31	Lawyer
-8	27	undergrad
+5	43	PHD
+SELECT * FROM bup_db1.v6 ORDER BY education, gender;
+education	gender
+BE	F
+BS	F
+Doctor	F
+Lawyer	M
+MS	F
+PHD	M
+School	M
+Undergrad	M
 excercise objects of bup_db2
-USE bup_db2;
-SELECT * FROM t2;
+SELECT * FROM bup_db2.t2 ORDER BY age;
 idno	age	education
+3	19	School
 1	23	BS
 2	24	BE
-3	19	school
+8	27	Undergrad
 4	28	MS
-5	43	PHD
 6	30	Doctor
 7	31	Lawyer
-8	27	undergrad
-SELECT * FROM v2;
+5	43	PHD
+SELECT * FROM bup_db2.v2 ORDER BY age;
 age	education
+19	School
 23	BS
 24	BE
-19	school
+27	Undergrad
 28	MS
-43	PHD
 30	Doctor
 31	Lawyer
-27	undergrad
-SELECT * FROM v3;
+43	PHD
+SELECT * FROM bup_db2.v3 ORDER BY age;
 name	age	education
+aa3	19	School
 aa1	23	BS
 aa2	24	BE
-aa3	19	school
+aa8	27	Undergrad
+aa4	28	MS
+aa6	30	Doctor
+aa7	31	Lawyer
+aa5	43	PHD
+SELECT * FROM bup_db2.vv;
+N	A	E
+aa1	23	BS
+aa2	24	BE
+aa3	19	School
 aa4	28	MS
 aa5	43	PHD
 aa6	30	Doctor
 aa7	31	Lawyer
-aa8	27	undergrad
-SELECT * FROM student_details;
+aa8	27	Undergrad
+SELECT * FROM bup_db2.student_details;
 ccode	District	scode
-234	zuloa	1
-321	yyy	2
 765	iug	3
 124	LKJ	4
 235	uth	6
+321	yyy	2
+234	zuloa	1
 showing objects and create statements.
 SHOW FULL TABLES FROM bup_db1;;
 Tables_in_bup_db1	t1
@@ -185,6 +228,8 @@ Tables_in_bup_db1	v1
 Table_type	VIEW
 Tables_in_bup_db1	v5
 Table_type	VIEW
+Tables_in_bup_db1	v6
+Table_type	VIEW
 Tables_in_bup_db1	vcomb
 Table_type	VIEW
 SHOW FULL TABLES FROM bup_db2;;
@@ -196,14 +241,16 @@ Tables_in_bup_db2	v2
 Table_type	VIEW
 Tables_in_bup_db2	v3
 Table_type	VIEW
+Tables_in_bup_db2	vv
+Table_type	VIEW
 SHOW CREATE VIEW bup_db1.v1;;
 View	v1
-Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bup_db1`.`v1` AS select `bup_db1`.`t1`.`id` AS `id`,`bup_db1`.`t1`.`name` AS `name`,`bup_db1`.`t1`.`city` AS `city` from `bup_db1`.`t1`
+Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`id` AS `id`,`t1`.`name` AS `name`,`t1`.`city` AS `city` from `t1`
 character_set_client	latin1
 collation_connection	latin1_swedish_ci
 SHOW CREATE VIEW bup_db1.vcomb;;
 View	vcomb
-Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bup_db1`.`vcomb` AS select `bup_db1`.`t1`.`name` AS `name`,`bup_db1`.`t1`.`city` AS `city`,`bup_db1`.`t3`.`ccode` AS `ccode` from (`bup_db1`.`t1` join `bup_db1`.`t3`) where (`bup_db1`.`t1`.`id` = `bup_db1`.`t3`.`scode`)
+Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vcomb` AS select `t1`.`name` AS `name`,`t1`.`city` AS `city`,`t3`.`ccode` AS `ccode` from (`t1` join `t3`) where (`t1`.`id` = `t3`.`scode`)
 character_set_client	latin1
 collation_connection	latin1_swedish_ci
 SHOW CREATE VIEW bup_db2.v3;;
@@ -211,7 +258,7 @@ View	v3
 Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bup_db2`.`v3` AS select `bup_db1`.`t1`.`name` AS `name`,`bup_db2`.`t2`.`age` AS `age`,`bup_db2`.`t2`.`education` AS `education` from (`bup_db1`.`t1` join `bup_db2`.`t2`) where (`bup_db1`.`t1`.`id` = `bup_db2`.`t2`.`idno`)
 character_set_client	latin1
 collation_connection	latin1_swedish_ci
-backup data
+backup database
 BACKUP DATABASE bup_db1, bup_db2 TO 'bup_objectview.bak';
 backup_id
 #
@@ -222,8 +269,19 @@ BACKUP DATABASE bup_db2 TO 'bup_objectvi
 backup_id
 #
 dropping  database.
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
+Restore database.
+restore database with view dependency to other, non-existing db
+RESTORE FROM 'bup_objectview1.bak';
+ERROR 42S02: Table 'bup_db2.t2' doesn't exist
+DROP DATABASE bup_db1;
+RESTORE FROM 'bup_objectview2.bak';
+ERROR 42S02: Table 'bup_db1.t3' doesn't exist
+DROP DATABASE bup_db2;
 RESTORE FROM 'bup_objectview.bak';
 backup_id
 #
@@ -242,6 +300,8 @@ Tables_in_bup_db1	v1
 Table_type	VIEW
 Tables_in_bup_db1	v5
 Table_type	VIEW
+Tables_in_bup_db1	v6
+Table_type	VIEW
 Tables_in_bup_db1	vcomb
 Table_type	VIEW
 SHOW FULL TABLES FROM bup_db2;;
@@ -253,6 +313,8 @@ Tables_in_bup_db2	v2
 Table_type	VIEW
 Tables_in_bup_db2	v3
 Table_type	VIEW
+Tables_in_bup_db2	vv
+Table_type	VIEW
 SHOW CREATE VIEW bup_db1.v1;;
 View	v1
 Create View	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bup_db1`.`v1` AS select `bup_db1`.`t1`.`id` AS `id`,`bup_db1`.`t1`.`name` AS `name`,`bup_db1`.`t1`.`city` AS `city` from `bup_db1`.`t1`
@@ -269,8 +331,7 @@ Create View	CREATE ALGORITHM=UNDEFINED D
 character_set_client	latin1
 collation_connection	latin1_swedish_ci
 ****check for view contents after Restore*****
-USE bup_db1;
-SELECT * FROM t1;
+SELECT * FROM bup_db1.t1 ORDER BY id;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -280,24 +341,24 @@ id	name	city
 6	aa6	RR6
 7	aa7	RR7
 8	aa8	RR8
-SELECT * FROM t3;
+SELECT * FROM bup_db1.t3 ORDER BY scode;
 ccode	District	scode
 234	zuloa	1
 321	yyy	2
 765	iug	3
 124	LKJ	4
 235	uth	6
-SELECT * FROM t5;
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
 Gender	cand_age
 F	23
 F	24
-M	19
 F	28
-M	43
 F	30
+M	19
+M	43
 M	31
 M	27
-SELECT * FROM v1;
+SELECT * FROM bup_db1.v1;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -307,79 +368,88 @@ id	name	city
 6	aa6	RR6
 7	aa7	RR7
 8	aa8	RR8
-SELECT * FROM vcomb;
+SELECT * FROM bup_db1.vcomb ORDER BY name;
 name	city	ccode
 aa1	RR1	234
 aa2	RR2	321
 aa3	RR3	765
 aa4	RR4	124
 aa6	RR6	235
-SELECT * FROM v5;
+SELECT * FROM bup_db1.v5 ORDER BY age;
 idno	age	education
+3	19	School
 1	23	BS
 2	24	BE
-3	19	school
+8	27	Undergrad
 4	28	MS
-5	43	PHD
 6	30	Doctor
 7	31	Lawyer
-8	27	undergrad
+5	43	PHD
+SELECT * FROM bup_db1.v6 ORDER BY education, gender;
+education	gender
+BE	F
+BS	F
+Doctor	F
+Lawyer	M
+MS	F
+PHD	M
+School	M
+Undergrad	M
 excercise objects of bup_db2
-use bup_db2;
-SELECT * FROM t2;
+SELECT * FROM bup_db2.t2 ORDER BY age;
 idno	age	education
+3	19	School
 1	23	BS
 2	24	BE
-3	19	school
+8	27	Undergrad
 4	28	MS
-5	43	PHD
 6	30	Doctor
 7	31	Lawyer
-8	27	undergrad
-SELECT * FROM v2;
+5	43	PHD
+SELECT * FROM bup_db2.v2 ORDER BY age;
 age	education
+19	School
 23	BS
 24	BE
-19	school
+27	Undergrad
 28	MS
-43	PHD
 30	Doctor
 31	Lawyer
-27	undergrad
-SELECT * FROM v3;
+43	PHD
+SELECT * FROM bup_db2.v3 ORDER BY age;
 name	age	education
+aa3	19	School
+aa1	23	BS
+aa2	24	BE
+aa8	27	Undergrad
+aa4	28	MS
+aa6	30	Doctor
+aa7	31	Lawyer
+aa5	43	PHD
+SELECT * FROM bup_db2.vv;
+N	A	E
 aa1	23	BS
 aa2	24	BE
-aa3	19	school
+aa3	19	School
 aa4	28	MS
 aa5	43	PHD
 aa6	30	Doctor
 aa7	31	Lawyer
-aa8	27	undergrad
-SELECT * FROM student_details;
+aa8	27	Undergrad
+SELECT * FROM bup_db2.student_details;
 ccode	District	scode
-234	zuloa	1
-321	yyy	2
 765	iug	3
 124	LKJ	4
 235	uth	6
-DROP DATABASE bup_db1;
-DROP DATABASE bup_db2;
-Restoring Database
-RESTORE FROM 'bup_objectview.bak';
-backup_id
-#
-USE bup_db1;
-ALTER TABLE t1 CHANGE id id tinyint not null;
-SHOW CREATE TABLE t1;;
-Table	t1
-Create Table	CREATE TABLE `t1` (
-  `id` tinyint(4) NOT NULL,
-  `name` char(10) DEFAULT NULL,
-  `city` varchar(10) DEFAULT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1
-SELECT * FROM t1;
+321	yyy	2
+234	zuloa	1
+ALTER TABLE bup_db1.t1 CHANGE name name VARCHAR(10);
+DESCRIBE bup_db1.t1;
+Field	Type	Null	Key	Default	Extra
+id	int(11)	NO	PRI	NULL	
+name	varchar(10)	YES		NULL	
+city	varchar(10)	YES		NULL	
+SELECT * FROM bup_db1.t1 ORDER BY id;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -389,17 +459,7 @@ id	name	city
 6	aa6	RR6
 7	aa7	RR7
 8	aa8	RR8
-DELETE FROM t1 WHERE id=7;
-SELECT * FROM t1;
-id	name	city
-1	aa1	RR1
-2	aa2	RR2
-3	aa3	RR3
-4	aa4	RR4
-5	aa5	RR5
-6	aa6	RR6
-8	aa8	RR8
-SELECT * FROM v1;
+SELECT * FROM bup_db1.v1;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -407,37 +467,40 @@ id	name	city
 4	aa4	RR4
 5	aa5	RR5
 6	aa6	RR6
+7	aa7	RR7
 8	aa8	RR8
-USE bup_db2;
-SELECT * FROM v3;
+SELECT * FROM bup_db2.v3 ORDER BY age;
 name	age	education
+aa3	19	School
 aa1	23	BS
 aa2	24	BE
-aa3	19	school
+aa8	27	Undergrad
 aa4	28	MS
-aa5	43	PHD
 aa6	30	Doctor
-aa8	27	undergrad
+aa7	31	Lawyer
+aa5	43	PHD
 BACKUP DATABASE bup_db1, bup_db2 TO 'bup_objectview3.bak';
 backup_id
 #
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
 RESTORE FROM 'bup_objectview3.bak';
 backup_id
 #
-USE bup_db2;
-SELECT * FROM v3;
+SELECT * FROM bup_db2.v3 ORDER BY age;
 name	age	education
+aa3	19	School
 aa1	23	BS
 aa2	24	BE
-aa3	19	school
+aa8	27	Undergrad
 aa4	28	MS
-aa5	43	PHD
 aa6	30	Doctor
-aa8	27	undergrad
-USE bup_db1;
-SELECT * FROM t1;
+aa7	31	Lawyer
+aa5	43	PHD
+SELECT * FROM bup_db1.t1 ORDER BY id;
 id	name	city
 1	aa1	RR1
 2	aa2	RR2
@@ -445,9 +508,91 @@ id	name	city
 4	aa4	RR4
 5	aa5	RR5
 6	aa6	RR6
+7	aa7	RR7
 8	aa8	RR8
 
+*** ENTER Backup of database with missing view dependency 
+*** should fail but not crash server 
+*** Test for bug#34902 ***
+initializing test
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
+DROP DATABASE bup_db1;
+DROP DATABASE bup_db2;
+RESTORE FROM 'bup_objectview.bak';
+backup_id
+#
+SELECT * FROM bup_db1.t1;
+id	name	city
+1	aa1	RR1
+2	aa2	RR2
+3	aa3	RR3
+4	aa4	RR4
+5	aa5	RR5
+6	aa6	RR6
+7	aa7	RR7
+8	aa8	RR8
+SELECT * FROM bup_db1.v1;
+id	name	city
+1	aa1	RR1
+2	aa2	RR2
+3	aa3	RR3
+4	aa4	RR4
+5	aa5	RR5
+6	aa6	RR6
+7	aa7	RR7
+8	aa8	RR8
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
+DROP TABLE bup_db1.t1;
+
+Testing backup with missing view dependency in same db
+
+SELECT * FROM bup_db1.v1;
+ERROR HY000: View 'bup_db1.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+BACKUP DATABASE bup_db1 TO 'bup_shouldfail1.bak';
+ERROR HY000: Failed to add view `bup_db1`.`v1` to the catalog
+
+Testing backup with missing view dependency in other db
+
+USE bup_db2;
+SELECT * from bup_db2.v3;
+ERROR HY000: View 'bup_db2.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+BACKUP DATABASE bup_db2 TO 'bup_shouldfail2.bak';
+ERROR HY000: Failed to add view `bup_db2`.`student_details` to the catalog
+
+*** EXIT Backup of database with missing view dependency
+
+
+*** ENTER Backup of database with altered view should report error, not crash server
+Test for bug#34867
+initializing test
+DROP DATABASE bup_db1;
+DROP DATABASE bup_db2;
+RESTORE FROM 'bup_objectview.bak';
+backup_id
+#
+USE bup_db1;
+CREATE VIEW alter1 AS SELECT 5;
+CREATE VIEW alter2 AS SELECT * FROM alter1;
+ALTER VIEW alter1 AS SELECT 6;
+
+Testing view selecting from altered view
+
+SELECT * FROM alter2;
+ERROR HY000: View 'bup_db1.alter2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+BACKUP DATABASE bup_db1 TO 'bup_alterview.bak';
+ERROR HY000: View 'bup_db1.alter2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+
+*** EXIT Backup of database with altered view
+
+
 ***  DROP bup_db1, bup_db2 DATABASE ****
 
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;

=== modified file 'mysql-test/r/constraints.result'
--- a/mysql-test/r/constraints.result	2006-02-22 09:09:59 +0000
+++ b/mysql-test/r/constraints.result	2008-06-12 15:21:49 +0000
@@ -3,7 +3,7 @@ create table t1 (a int check (a>0));
 insert into t1 values (1);
 insert into t1 values (0);
 drop table t1;
-create table t1 (a int ,b int, check a>b);
+create table t1 (a int, b int, check (a>b));
 insert into t1 values (1,0);
 insert into t1 values (0,1);
 drop table t1;
@@ -27,3 +27,10 @@ t1	CREATE TABLE `t1` (
   UNIQUE KEY `key_2` (`a`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
+drop table if exists t_illegal;
+create table t_illegal (a int, b int, check a>b);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a>b)' at line 1
+create table t_illegal (a int, b int, constraint abc check a>b);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a>b)' at line 1
+create table t_illegal (a int, b int, constraint abc);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

=== modified file 'mysql-test/r/ctype_ldml.result'
--- a/mysql-test/r/ctype_ldml.result	2007-10-22 11:43:32 +0000
+++ b/mysql-test/r/ctype_ldml.result	2008-07-24 11:33:35 +0000
@@ -8,7 +8,7 @@ Variable_name	Value
 character_sets_dir	MYSQL_TEST_DIR/std_data/
 show collation like 'utf8_test_ci';
 Collation	Charset	Id	Default	Compiled	Sortlen
-utf8_test_ci	utf8	253			8
+utf8_test_ci	utf8	353			8
 create table t1 (c1 char(1) character set utf8 collate utf8_test_ci);
 insert into t1 values ('a');
 select * from t1 where c1='b';
@@ -17,7 +17,7 @@ a
 drop table t1;
 show collation like 'ucs2_test_ci';
 Collation	Charset	Id	Default	Compiled	Sortlen
-ucs2_test_ci	ucs2	158			8
+ucs2_test_ci	ucs2	358			8
 create table t1 (c1 char(1) character set ucs2 collate ucs2_test_ci);
 insert into t1 values ('a');
 select * from t1 where c1='b';
@@ -26,7 +26,7 @@ a
 drop table t1;
 show collation like 'utf16_test_ci';
 Collation	Charset	Id	Default	Compiled	Sortlen
-utf16_test_ci	utf16	127			8
+utf16_test_ci	utf16	327			8
 create table t1 (c1 char(1) character set utf16 collate utf16_test_ci);
 insert into t1 values ('a');
 select * from t1 where c1='b';
@@ -35,7 +35,7 @@ a
 drop table t1;
 show collation like 'utf32_test_ci';
 Collation	Charset	Id	Default	Compiled	Sortlen
-utf32_test_ci	utf32	191			8
+utf32_test_ci	utf32	391			8
 create table t1 (c1 char(1) character set utf32 collate utf32_test_ci);
 insert into t1 values ('a');
 select * from t1 where c1='b';
@@ -45,7 +45,7 @@ drop table t1;
 Vietnamese experimental collation
 show collation like 'ucs2_vn_ci';
 Collation	Charset	Id	Default	Compiled	Sortlen
-ucs2_vn_ci	ucs2	159			8
+ucs2_vn_ci	ucs2	359			8
 create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
 insert into t1 values (0x0061),(0x0041),(0x00E0),(0x00C0),(0x1EA3),(0x1EA2),
 (0x00E3),(0x00C3),(0x00E1),(0x00C1),(0x1EA1),(0x1EA0);
@@ -316,3 +316,29 @@ Vv
 Xx
 YyÝýỲỳỴỵỶỷỸỹ
 drop table t1;
+The following tests check that two-byte collation IDs work
+select * from information_schema.collations where id>256 order by id;
+COLLATION_NAME	CHARACTER_SET_NAME	ID	IS_DEFAULT	IS_COMPILED	SORTLEN
+utf16_test_ci	utf16	327			8
+utf8_test_ci	utf8	353			8
+ucs2_test_ci	ucs2	358			8
+ucs2_vn_ci	ucs2	359			8
+utf32_test_ci	utf32	391			8
+show collation like '%test%';
+Collation	Charset	Id	Default	Compiled	Sortlen
+ucs2_test_ci	ucs2	358			8
+utf8_test_ci	utf8	353			8
+utf16_test_ci	utf16	327			8
+utf32_test_ci	utf32	391			8
+show collation like 'ucs2_vn_ci';
+Collation	Charset	Id	Default	Compiled	Sortlen
+ucs2_vn_ci	ucs2	359			8
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+insert into t1 values (0x0061);
+set @@character_set_results=NULL;
+select * from t1;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def	test	t1	t1	c1	c1	254	2	2	Y	0	0	359
+c1
+a
+drop table t1;

=== added file 'mysql-test/r/have_nodebug.require'
--- a/mysql-test/r/have_nodebug.require	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/have_nodebug.require	2008-07-24 16:50:18 +0000
@@ -0,0 +1,2 @@
+debug
+0

=== modified file 'mysql-test/r/perror.result'
--- a/mysql-test/r/perror.result	2006-08-01 09:29:10 +0000
+++ b/mysql-test/r/perror.result	2008-08-05 23:26:18 +0000
@@ -1 +1,6 @@
 Illegal error code: 10000
+MySQL error code 1062 (ER_DUP_ENTRY): Duplicate entry '%-.192s' for key %d
+MySQL error code 1076 (ER_READY): %s: ready for connections.
+Version: '%s'  socket: '%s'  port: %d
+MySQL error code 1459 (ER_TABLE_NEEDS_UPGRADE): Table upgrade required. Please do "REPAIR TABLE `%-.32s`" to fix it!
+MySQL error code 1461 (ER_MAX_PREPARED_STMT_COUNT_REACHED): Can't create more than max_prepared_stmt_count statements (current value: %lu)

=== modified file 'mysql-test/r/sp-error.result'
--- a/mysql-test/r/sp-error.result	2008-08-07 20:51:09 +0000
+++ b/mysql-test/r/sp-error.result	2008-08-27 12:49:58 +0000
@@ -1625,6 +1625,29 @@ begin
 declare continue handler for sqlstate '00000' set @x=0;
 end$$
 ERROR 42000: Bad SQLSTATE: '00000'
+drop procedure if exists proc_36510;
+create procedure proc_36510()
+begin
+declare should_be_illegal condition for sqlstate '00123';
+declare continue handler for should_be_illegal set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00123'
+create procedure proc_36510()
+begin
+declare continue handler for sqlstate '00123' set @x=0;
+end$$
+ERROR 42000: Bad SQLSTATE: '00123'
+create procedure proc_36510()
+begin
+declare should_be_illegal condition for 0;
+declare continue handler for should_be_illegal set @x=0;
+end$$
+ERROR HY000: Incorrect CONDITION value: '0'
+create procedure proc_36510()
+begin
+declare continue handler for 0 set @x=0;
+end$$
+ERROR HY000: Incorrect CONDITION value: '0'
 drop procedure if exists p1;
 set @old_recursion_depth = @@max_sp_recursion_depth;
 set @@max_sp_recursion_depth = 255;

=== added file 'mysql-test/r/sp-no-code.result'
--- a/mysql-test/r/sp-no-code.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/sp-no-code.result	2008-07-24 16:50:18 +0000
@@ -0,0 +1,4 @@
+show procedure code foo;
+ERROR HY000: The 'SHOW PROCEDURE|FUNCTION CODE' feature is disabled; you need MySQL built with '--with-debug' to have it working
+show function code foo;
+ERROR HY000: The 'SHOW PROCEDURE|FUNCTION CODE' feature is disabled; you need MySQL built with '--with-debug' to have it working

=== modified file 'mysql-test/r/subselect.result'
--- a/mysql-test/r/subselect.result	2008-08-22 17:03:15 +0000
+++ b/mysql-test/r/subselect.result	2008-08-27 12:49:58 +0000
@@ -1323,6 +1323,10 @@ create table t1 (a int, b int, index a (
 create table t2 (a int, index a (a));
 create table t3 (a int, b int, index a (a));
 insert into t1 values (1,10), (2,20), (3,30), (4,40);
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+insert into t1
+select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
 insert into t2 values (2), (3), (4), (5);
 insert into t3 values (10,3), (20,4), (30,5);
 select * from t2 where t2.a in (select a from t1);
@@ -1373,7 +1377,7 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using where; Using index; FirstMatch(t2)
 Warnings:
 Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
-drop table t1, t2, t3;
+drop table t0, t1, t2, t3;
 create table t1 (a int, b int);
 create table t2 (a int, b int);
 create table t3 (a int, b int);
@@ -4296,15 +4300,20 @@ Note	1276	Field or reference 'test.t1.a'
 Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
 Note	1003	select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
 DROP TABLE t1,t2;
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 create table t1(f11 int, f12 int);
 create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
 insert into t1 values(1,1),(2,2), (3, 3);
+insert into t2 
+select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a 
+from t0 A, t0 B, t0 C, t0 D;
 set session sort_buffer_size= 33*1024;
 select count(*) from t1 where f12 = 
 (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
 count(*)
 3
-drop table t1,t2;
+drop table t0,t1,t2;
 CREATE TABLE t4 (
 f7 varchar(32) collate utf8_bin NOT NULL default '',
 f10 varchar(32) collate utf8_bin default NULL,
@@ -4610,6 +4619,17 @@ SELECT * FROM t2 WHERE b NOT IN (SELECT 
 a	b
 DROP TABLE t1,t2;
 End of 5.0 tests.
+CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
+INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
+CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
+INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
+SELECT * FROM t1
+WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
+pk	a
+1	10
+3	30
+2	20
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );
@@ -4871,15 +4891,4 @@ ERROR 42000: You have an error in your S
 SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO @v )' at line 1
 DROP TABLE t1, t2;
-CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
-INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
-CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
-INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
-SELECT * FROM t1
-WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
-pk	a
-1	10
-3	30
-2	20
-DROP TABLE t1,t2;
 End of 5.1 tests.

=== modified file 'mysql-test/r/subselect_no_mat.result'
--- a/mysql-test/r/subselect_no_mat.result	2008-08-22 17:03:15 +0000
+++ b/mysql-test/r/subselect_no_mat.result	2008-08-27 12:49:58 +0000
@@ -1327,6 +1327,10 @@ create table t1 (a int, b int, index a (
 create table t2 (a int, index a (a));
 create table t3 (a int, b int, index a (a));
 insert into t1 values (1,10), (2,20), (3,30), (4,40);
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+insert into t1
+select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
 insert into t2 values (2), (3), (4), (5);
 insert into t3 values (10,3), (20,4), (30,5);
 select * from t2 where t2.a in (select a from t1);
@@ -1377,7 +1381,7 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using where; Using index; FirstMatch(t2)
 Warnings:
 Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
-drop table t1, t2, t3;
+drop table t0, t1, t2, t3;
 create table t1 (a int, b int);
 create table t2 (a int, b int);
 create table t3 (a int, b int);
@@ -4300,15 +4304,20 @@ Note	1276	Field or reference 'test.t1.a'
 Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
 Note	1003	select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
 DROP TABLE t1,t2;
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 create table t1(f11 int, f12 int);
 create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
 insert into t1 values(1,1),(2,2), (3, 3);
+insert into t2 
+select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a 
+from t0 A, t0 B, t0 C, t0 D;
 set session sort_buffer_size= 33*1024;
 select count(*) from t1 where f12 = 
 (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
 count(*)
 3
-drop table t1,t2;
+drop table t0,t1,t2;
 CREATE TABLE t4 (
 f7 varchar(32) collate utf8_bin NOT NULL default '',
 f10 varchar(32) collate utf8_bin default NULL,
@@ -4614,6 +4623,17 @@ SELECT * FROM t2 WHERE b NOT IN (SELECT 
 a	b
 DROP TABLE t1,t2;
 End of 5.0 tests.
+CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
+INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
+CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
+INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
+SELECT * FROM t1
+WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
+pk	a
+1	10
+3	30
+2	20
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );
@@ -4875,17 +4895,6 @@ ERROR 42000: You have an error in your S
 SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO @v )' at line 1
 DROP TABLE t1, t2;
-CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
-INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
-CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
-INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
-SELECT * FROM t1
-WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
-pk	a
-1	10
-3	30
-2	20
-DROP TABLE t1,t2;
 End of 5.1 tests.
 set optimizer_switch='';
 show variables like 'optimizer_switch';

=== modified file 'mysql-test/r/subselect_no_opts.result'
--- a/mysql-test/r/subselect_no_opts.result	2008-08-22 17:03:15 +0000
+++ b/mysql-test/r/subselect_no_opts.result	2008-08-27 12:49:58 +0000
@@ -1327,6 +1327,10 @@ create table t1 (a int, b int, index a (
 create table t2 (a int, index a (a));
 create table t3 (a int, b int, index a (a));
 insert into t1 values (1,10), (2,20), (3,30), (4,40);
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+insert into t1
+select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
 insert into t2 values (2), (3), (4), (5);
 insert into t3 values (10,3), (20,4), (30,5);
 select * from t2 where t2.a in (select a from t1);
@@ -1377,7 +1381,7 @@ id	select_type	table	type	possible_keys	
 2	DEPENDENT SUBQUERY	t1	index_subquery	a	a	5	func	1001	100.00	Using index; Using where
 Warnings:
 Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a where ((`test`.`t1`.`b` <> 30) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`)))))
-drop table t1, t2, t3;
+drop table t0, t1, t2, t3;
 create table t1 (a int, b int);
 create table t2 (a int, b int);
 create table t3 (a int, b int);
@@ -4300,15 +4304,20 @@ Note	1276	Field or reference 'test.t1.a'
 Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
 Note	1003	select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
 DROP TABLE t1,t2;
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 create table t1(f11 int, f12 int);
 create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
 insert into t1 values(1,1),(2,2), (3, 3);
+insert into t2 
+select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a 
+from t0 A, t0 B, t0 C, t0 D;
 set session sort_buffer_size= 33*1024;
 select count(*) from t1 where f12 = 
 (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
 count(*)
 3
-drop table t1,t2;
+drop table t0,t1,t2;
 CREATE TABLE t4 (
 f7 varchar(32) collate utf8_bin NOT NULL default '',
 f10 varchar(32) collate utf8_bin default NULL,
@@ -4614,6 +4623,17 @@ SELECT * FROM t2 WHERE b NOT IN (SELECT 
 a	b
 DROP TABLE t1,t2;
 End of 5.0 tests.
+CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
+INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
+CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
+INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
+SELECT * FROM t1
+WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
+pk	a
+1	10
+3	30
+2	20
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );
@@ -4875,17 +4895,6 @@ ERROR 42000: You have an error in your S
 SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO @v )' at line 1
 DROP TABLE t1, t2;
-CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
-INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
-CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
-INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
-SELECT * FROM t1
-WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
-pk	a
-1	10
-3	30
-2	20
-DROP TABLE t1,t2;
 End of 5.1 tests.
 set optimizer_switch='';
 show variables like 'optimizer_switch';

=== modified file 'mysql-test/r/subselect_no_semijoin.result'
--- a/mysql-test/r/subselect_no_semijoin.result	2008-08-22 17:03:15 +0000
+++ b/mysql-test/r/subselect_no_semijoin.result	2008-08-27 12:49:58 +0000
@@ -1327,6 +1327,10 @@ create table t1 (a int, b int, index a (
 create table t2 (a int, index a (a));
 create table t3 (a int, b int, index a (a));
 insert into t1 values (1,10), (2,20), (3,30), (4,40);
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+insert into t1
+select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
 insert into t2 values (2), (3), (4), (5);
 insert into t3 values (10,3), (20,4), (30,5);
 select * from t2 where t2.a in (select a from t1);
@@ -1377,7 +1381,7 @@ id	select_type	table	type	possible_keys	
 2	SUBQUERY	t1	index	NULL	a	10	NULL	10005	100.00	Using where; Using index
 Warnings:
 Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`b` <> 30) ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key)))
-drop table t1, t2, t3;
+drop table t0, t1, t2, t3;
 create table t1 (a int, b int);
 create table t2 (a int, b int);
 create table t3 (a int, b int);
@@ -4300,15 +4304,20 @@ Note	1276	Field or reference 'test.t1.a'
 Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
 Note	1003	select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
 DROP TABLE t1,t2;
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 create table t1(f11 int, f12 int);
 create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
 insert into t1 values(1,1),(2,2), (3, 3);
+insert into t2 
+select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a 
+from t0 A, t0 B, t0 C, t0 D;
 set session sort_buffer_size= 33*1024;
 select count(*) from t1 where f12 = 
 (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
 count(*)
 3
-drop table t1,t2;
+drop table t0,t1,t2;
 CREATE TABLE t4 (
 f7 varchar(32) collate utf8_bin NOT NULL default '',
 f10 varchar(32) collate utf8_bin default NULL,
@@ -4614,6 +4623,17 @@ SELECT * FROM t2 WHERE b NOT IN (SELECT 
 a	b
 DROP TABLE t1,t2;
 End of 5.0 tests.
+CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
+INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
+CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
+INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
+SELECT * FROM t1
+WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
+pk	a
+1	10
+3	30
+2	20
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );
@@ -4875,17 +4895,6 @@ ERROR 42000: You have an error in your S
 SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO @v )' at line 1
 DROP TABLE t1, t2;
-CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
-INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
-CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
-INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
-SELECT * FROM t1
-WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
-pk	a
-1	10
-3	30
-2	20
-DROP TABLE t1,t2;
 End of 5.1 tests.
 set optimizer_switch='';
 show variables like 'optimizer_switch';

=== added file 'mysql-test/r/subselect_nulls.result'
--- a/mysql-test/r/subselect_nulls.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/subselect_nulls.result	2008-08-18 12:45:37 +0000
@@ -0,0 +1,114 @@
+drop table if exists x1;
+drop table if exists x2;
+create table x1(k int primary key, d1 int, d2 int);
+create table x2(k int primary key, d1 int, d2 int);
+insert into x1 values
+(10,   10,   10),
+(20,   20,   20),
+(21,   20,   null),
+(30,   null, 30),
+(40,   40,   40);
+insert into x2 values
+(10,   10,   10),
+(20,   20,   20),
+(21,   20,   null),
+(30,   null, 30);
+select *
+from x1
+where (d1, d2) in (select d1, d2
+from x2);
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where (d1, d2) in (select d1, d2
+from x2) is true;
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where (d1, d2) in (select d1, d2
+from x2) is false;
+k	d1	d2
+40	40	40
+select *
+from x1
+where (d1, d2) in (select d1, d2
+from x2) is unknown;
+k	d1	d2
+21	20	NULL
+30	NULL	30
+select *
+from x1
+where d1 in (select d1
+from x2
+where x1.d2=x2.d2);
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where d1 in (select d1
+from x2
+where x1.d2=x2.d2) is true;
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where d1 in (select d1
+from x2
+where x1.d2=x2.d2) is false;
+k	d1	d2
+21	20	NULL
+40	40	40
+select *
+from x1
+where d1 in (select d1
+from x2
+where x1.d2=x2.d2) is unknown;
+k	d1	d2
+30	NULL	30
+select *
+from x1
+where 1 in (select 1
+from x2
+where x1.d1=x2.d1 and x1.d2=x2.d2);
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where 1 in (select 1
+from x2
+where x1.d1=x2.d1 and x1.d2=x2.d2) is true;
+k	d1	d2
+10	10	10
+20	20	20
+select *
+from x1
+where 1 in (select 1
+from x2
+where x1.d1=x2.d1 and x1.d2=x2.d2) is false;
+k	d1	d2
+21	20	NULL
+30	NULL	30
+40	40	40
+select *
+from x1
+where 1 in (select 1
+from x2
+where x1.d1=x2.d1 and x1.d2=x2.d2) is unknown;
+k	d1	d2
+select *
+from x1
+where exists (select *
+from x2
+where x1.d1=x2.d1 and x1.d2=x2.d2);
+k	d1	d2
+10	10	10
+20	20	20
+drop table x1;
+drop table x2;

=== modified file 'mysql-test/r/subselect_sj.result'
--- a/mysql-test/r/subselect_sj.result	2008-05-01 03:53:36 +0000
+++ b/mysql-test/r/subselect_sj.result	2008-06-11 23:16:53 +0000
@@ -197,5 +197,44 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	103	100.00	Using where; Using join buffer
 Warnings:
 Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where ((`test`.`t1`.`a` = `test`.`t10`.`pk`) and (`test`.`t10`.`pk` < 3))
+
+BUG#37120 optimizer_switch allowable values not according to specification
+
+select @@optimizer_switch;
+@@optimizer_switch
+
+set optimizer_switch='no_materialization';
+select @@optimizer_switch;
+@@optimizer_switch
+no_materialization
+set optimizer_switch='no_semijoin';
+select @@optimizer_switch;
+@@optimizer_switch
+no_semijoin
+set optimizer_switch='no_loosescan';
+select @@optimizer_switch;
+@@optimizer_switch
+no_loosescan
+set optimizer_switch='no_semijoin,no_materialization';
+select @@optimizer_switch;
+@@optimizer_switch
+no_materialization,no_semijoin
+set optimizer_switch='no_materialization,no_semijoin';
+select @@optimizer_switch;
+@@optimizer_switch
+no_materialization,no_semijoin
+set optimizer_switch='no_semijoin,no_materialization,no_loosescan';
+select @@optimizer_switch;
+@@optimizer_switch
+no_materialization,no_semijoin,no_loosescan
+set optimizer_switch='no_semijoin,no_loosescan';
+select @@optimizer_switch;
+@@optimizer_switch
+no_semijoin,no_loosescan
+set optimizer_switch='no_materialization,no_loosescan';
+select @@optimizer_switch;
+@@optimizer_switch
+no_materialization,no_loosescan
+set optimizer_switch='';
 drop table t0, t1;
 drop table t10, t11, t12;

=== modified file 'mysql-test/r/subselect_sj2.result'
--- a/mysql-test/r/subselect_sj2.result	2008-05-03 08:27:47 +0000
+++ b/mysql-test/r/subselect_sj2.result	2008-05-31 07:14:57 +0000
@@ -654,3 +654,30 @@ call p1();
 a
 drop procedure p1;
 drop table t1;
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int) as select A.a + 10 *(B.a + 10*C.a) as a  from t0 A, t0 B, t0 C;
+create table t2 (id int, a int, primary key(id), key(a)) as select a as id, a as a  from t1;
+show create table t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `id` int(11) NOT NULL DEFAULT '0',
+  `a` int(11) DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  KEY `a` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+set @a=0;
+create table t3 as select * from t2 limit 0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+alter table t3 add primary key(id), add key(a);
+The following must use loose index scan over t3, key a:
+explain select count(a) from t2 where a in ( SELECT  a FROM t3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t3	index	a	a	5	NULL	30000	Using index; LooseScan
+1	PRIMARY	t2	ref	a	a	5	test.t3.a	1	Using index
+select count(a) from t2 where a in ( SELECT  a FROM t3);
+count(a)
+1000
+drop table t0,t1,t2,t3;

=== modified file 'mysql-test/std_data/Index.xml'
--- a/mysql-test/std_data/Index.xml	2007-10-22 11:43:32 +0000
+++ b/mysql-test/std_data/Index.xml	2008-07-24 11:33:35 +0000
@@ -1,7 +1,7 @@
 <charsets>
 
   <charset name="utf8">
-    <collation name="utf8_test_ci" id="253">
+    <collation name="utf8_test_ci" id="353">
       <rules>
         <reset>a</reset>
         <s>b</s>
@@ -11,7 +11,7 @@
   </charset>
 
   <charset name="utf16">
-    <collation name="utf16_test_ci" id="127">
+    <collation name="utf16_test_ci" id="327">
       <rules>
         <reset>a</reset>
         <s>b</s>
@@ -20,7 +20,7 @@
   </charset>
 
   <charset name="utf32">
-    <collation name="utf32_test_ci" id="191">
+    <collation name="utf32_test_ci" id="391">
       <rules>
         <reset>a</reset>
         <s>b</s>
@@ -31,13 +31,13 @@
 
 
   <charset name="ucs2">
-    <collation name="ucs2_test_ci" id="158">
+    <collation name="ucs2_test_ci" id="358">
       <rules>
         <reset>a</reset>
         <s>b</s>
       </rules>
     </collation>
-    <collation name="ucs2_vn_ci" id="159">
+    <collation name="ucs2_vn_ci" id="359">
       <!-- Vietnamese experimental collation -->
       <rules>
         <reset>A</reset>

=== added file 'mysql-test/suite/backup/combinations'
--- a/mysql-test/suite/backup/combinations	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/combinations	2008-08-12 03:22:05 +0000
@@ -0,0 +1,11 @@
+[myisam]
+--default-storage-engine=myisam
+
+[falcon]
+--default-storage-engine=falcon
+
+[memory]
+--default-storage-engine=memory
+
+[innodb]
+--default-storage-engine=innodb

=== added directory 'mysql-test/suite/backup/include'
=== added file 'mysql-test/suite/backup/include/backup_engine.inc'
--- a/mysql-test/suite/backup/include/backup_engine.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/include/backup_engine.inc	2008-08-12 03:22:05 +0000
@@ -0,0 +1,9 @@
+###############################################################################
+# Author: Hema
+# Date: 2008-04-01
+# Purpose:To define the engine variable.
+###############################################################################
+--replace_column 2 #
+SHOW VARIABLES LIKE 'storage_engine';
+let $ENGINE= query_get_value(SHOW VARIABLES LIKE 'storage_engine', Value, 1);
+

=== added file 'mysql-test/suite/backup/r/backup_functions.result'
--- a/mysql-test/suite/backup/r/backup_functions.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_functions.result	2008-08-12 03:22:05 +0000
@@ -0,0 +1,601 @@
+SHOW VARIABLES LIKE 'storage_engine';
+Variable_name	Value
+storage_engine	#
+
+starting the test for backup
+
+DROP DATABASE IF EXISTS bup_sfs;
+CREATE DATABASE bup_sfs;
+USE bup_sfs;
+SET SQL_MODE=TRADITIONAL;
+Creating table
+CREATE TABLE bup_sfs.players(
+playerno INT not null PRIMARY KEY,
+name CHAR(10),
+Bdate DATE,
+sex CHAR(2),
+joined YEAR
+);
+CREATE TABLE bup_sfs.teams(
+teamno INT NOT NULL PRIMARY KEY,
+playerno INT,
+division CHAR(10),
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+CREATE TABLE bup_sfs.matches(
+Matchno INT NOT NULL PRIMARY KEY,
+teamno INT ,
+playerno INT,
+won INT,
+lost INT,
+FOREIGN KEY(teamno) REFERENCES teams(teamno),
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+CREATE TABLE bup_sfs.penalties(
+paymentno INT not null PRIMARY KEY,
+playerno INT,
+paymentdate DATE,
+amount FLOAT,
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+Load Data in tables
+INSERT INTO bup_sfs.players VALUES
+(1,'aa1','1948-10-09','M','1960'),(2,'aa2','1950-05-09','M','1965'),
+(3,'aa3','1953-10-10','F','1970'),(4,'aa4','1970-10-19','M','1985'),
+(5,'aa5','1972-04-28','F','1994'),(6,'aa6','1945-01-26','M','1960');
+INSERT INTO bup_sfs.teams VALUES(1,3,'first'),(2,4,'division');
+INSERT INTO bup_sfs.matches VALUES
+(1,1,2,3,1),(2,2,1,4,2),(3,1,5,0,1),(4,2,4,3,0),(5,2,5,2,2),
+(6,1,3,3,1),(7,2,1,4,2),(8,1,5,0,1),(9,2,2,3,0),(10,2,2,2,2);
+INSERT INTO bup_sfs.penalties VALUES
+(1,5,'1980-10-10',100.23),(2,3,'1967-12-10',123.23),
+(3,3,'1983-05-25',25.25), (4,4,'1981-11-10',210.23) ,
+(5,5,'1980-12-12',300), (6,1,'1984-07-02',10),
+(7,1,'1985-10-10',23.90);
+CREATE FUNCTION number_of_players() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END;
+||
+CREATE FUNCTION number_of_players1() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM players WHERE playerno > 2);
+END;
+||
+CREATE FUNCTION fcount() RETURNS INTEGER
+BEGIN
+DECLARE v_out INT;
+SELECT count(*) FROM matches INTO v_out;
+RETURN v_out;
+END;
+||
+CREATE FUNCTION dollars(amount FLOAT(7,2)) RETURNS FLOAT(7,2)
+BEGIN
+RETURN amount * (1/0.8);
+END;
+||
+SELECT number_of_players();
+number_of_players()
+6
+SELECT number_of_players1();
+number_of_players1()
+4
+SELECT fcount();
+fcount()
+10
+SELECT paymentno,amount, dollars(amount) FROM penalties;
+paymentno	amount	dollars(amount)
+1	100.23	125.29
+2	123.23	154.04
+3	25.25	31.56
+4	210.23	262.79
+5	300	375.00
+6	10	12.50
+7	23.9	29.87
+creating stored functions which is not dependent on table
+CREATE FUNCTION square_area(side tinyINT)
+RETURNS FLOAT
+RETURN side * side;
+SELECT square_area(11);
+square_area(11)
+121
+showing objects and create statements.
+SHOW CREATE FUNCTION number_of_players;;
+Function	number_of_players
+sql_mode	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+Create Function	CREATE DEFINER=`root`@`localhost` FUNCTION `number_of_players`() RETURNS int(11)
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE players;;
+Table	players
+Create Table	CREATE TABLE `players` (
+  `playerno` int(11) NOT NULL,
+  `name` char(10) DEFAULT NULL,
+  `Bdate` date DEFAULT NULL,
+  `sex` char(2) DEFAULT NULL,
+  `joined` year(4) DEFAULT NULL,
+  PRIMARY KEY (`playerno`)
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+describe penalties;
+Field	Type	Null	Key	Default	Extra
+paymentno	int(11)	NO	PRI	NULL	
+playerno	int(11)	YES	MUL	NULL	
+paymentdate	date	YES		NULL	
+amount	float	YES		NULL	
+SHOW FUNCTION STATUS;;
+Db	bup_sfs
+Name	dollars
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	fcount
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players1
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	square_area
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+backup data
+BACKUP DATABASE bup_sfs TO 'bup_sfs.bak';
+backup_id
+#
+dropping  database.
+DROP DATABASE bup_sfs;
+Restoring Database
+RESTORE FROM 'bup_sfs.bak';
+backup_id
+#
+SELECT @@SQL_MODE;
+@@SQL_MODE
+STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+showing objects and create statements
+SHOW CREATE DATABASE bup_sfs;;
+Database	bup_sfs
+Create Database	CREATE DATABASE `bup_sfs` /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE FUNCTION number_of_players;;
+Function	number_of_players
+sql_mode	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+Create Function	CREATE DEFINER=`root`@`localhost` FUNCTION `number_of_players`() RETURNS int(11)
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+describe penalties;
+Field	Type	Null	Key	Default	Extra
+paymentno	int(11)	NO	PRI	NULL	
+playerno	int(11)	YES	MUL	NULL	
+paymentdate	date	YES		NULL	
+amount	float	YES		NULL	
+describe matches;
+Field	Type	Null	Key	Default	Extra
+Matchno	int(11)	NO	PRI	NULL	
+teamno	int(11)	YES	MUL	NULL	
+playerno	int(11)	YES	MUL	NULL	
+won	int(11)	YES		NULL	
+lost	int(11)	YES		NULL	
+SHOW FUNCTION STATUS;;
+Db	bup_sfs
+Name	dollars
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	fcount
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players1
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	square_area
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+INSERT INTO bup_sfs.players VALUES
+(57,'brown','1971-08-17','M','1985'),(95,'Miller','1963-05-14','M','1972');
+INSERT INTO bup_sfs.matches VALUES(11,2,6,0,3);
+SELECT square_area(12);
+square_area(12)
+144
+SELECT number_of_players();
+number_of_players()
+8
+SELECT number_of_players1();
+number_of_players1()
+6
+SELECT fcount();
+fcount()
+11
+SELECT paymentno,amount, dollars(amount) FROM penalties WHERE paymentno<=3;
+paymentno	amount	dollars(amount)
+1	100.23	125.29
+2	123.23	154.04
+3	25.25	31.56
+DROP DATABASE bup_sfs;
+change SQL_MODE and then perform RESTORE operation
+SET SQL_MODE=ANSI;
+RESTORE FROM 'bup_sfs.bak';
+backup_id
+#
+SELECT @@SQL_MODE;
+@@SQL_MODE
+REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI
+showing objects and create statements
+SHOW CREATE DATABASE bup_sfs;;
+Database	bup_sfs
+Create Database	CREATE DATABASE "bup_sfs" /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE FUNCTION number_of_players;;
+Function	number_of_players
+sql_mode	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+Create Function	CREATE DEFINER=`root`@`localhost` FUNCTION `number_of_players`() RETURNS int(11)
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW FUNCTION STATUS;;
+Db	bup_sfs
+Name	dollars
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	fcount
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players1
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	square_area
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SELECT square_area(13);
+square_area(13)
+169
+SELECT number_of_players();
+number_of_players()
+6
+SELECT fcount();
+fcount()
+10
+DROP DATABASE bup_sfs;
+change SQL_MODE and then perform RESTORE
+SET SQL_MODE=MAXDB;
+RESTORE FROM 'bup_sfs.bak';
+backup_id
+#
+SELECT @@SQL_MODE;
+@@SQL_MODE
+PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,MAXDB,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,NO_AUTO_CREATE_USER
+showing objects and create statements
+SHOW CREATE DATABASE bup_sfs;;
+Database	bup_sfs
+Create Database	CREATE DATABASE "bup_sfs" /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE FUNCTION number_of_players;;
+Function	number_of_players
+sql_mode	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+Create Function	CREATE DEFINER=`root`@`localhost` FUNCTION `number_of_players`() RETURNS int(11)
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW FUNCTION STATUS;;
+Db	bup_sfs
+Name	dollars
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	fcount
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players1
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	square_area
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SELECT square_area(14);
+square_area(14)
+196
+SELECT number_of_players();
+number_of_players()
+6
+SELECT fcount();
+fcount()
+10
+SELECT paymentno,amount, dollars(amount) FROM penalties WHERE paymentno >=3;
+paymentno	amount	dollars(amount)
+3	25.25	31.56
+4	210.23	262.79
+5	300	375.00
+6	10	12.50
+7	23.9	29.87
+DROP DATABASE bup_sfs;
+change SQL_MODE and then perform RESTORE
+SET SQL_MODE=' ';
+RESTORE FROM 'bup_sfs.bak';
+backup_id
+#
+SELECT @@SQL_MODE;
+@@SQL_MODE
+
+showing objects and create statements
+SHOW CREATE DATABASE bup_sfs;;
+Database	bup_sfs
+Create Database	CREATE DATABASE `bup_sfs` /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE FUNCTION number_of_players;;
+Function	number_of_players
+sql_mode	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
+Create Function	CREATE DEFINER=`root`@`localhost` FUNCTION `number_of_players`() RETURNS int(11)
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE players;;
+Table	players
+Create Table	CREATE TABLE `players` (
+  `playerno` int(11) NOT NULL,
+  `name` char(10) DEFAULT NULL,
+  `Bdate` date DEFAULT NULL,
+  `sex` char(2) DEFAULT NULL,
+  `joined` year(4) DEFAULT NULL,
+  PRIMARY KEY (`playerno`)
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+describe matches;
+Field	Type	Null	Key	Default	Extra
+Matchno	int(11)	NO	PRI	NULL	
+teamno	int(11)	YES	MUL	NULL	
+playerno	int(11)	YES	MUL	NULL	
+won	int(11)	YES		NULL	
+lost	int(11)	YES		NULL	
+SHOW FUNCTION STATUS;;
+Db	bup_sfs
+Name	dollars
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	fcount
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	number_of_players1
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sfs
+Name	square_area
+Type	FUNCTION
+Definer	#
+Modified	#
+Created	#
+Security_type	DEFINER
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SELECT square_area(20);
+square_area(20)
+400
+SELECT number_of_players();
+number_of_players()
+6
+SELECT fcount();
+fcount()
+10
+SELECT paymentno,amount, dollars(amount) FROM penalties;
+paymentno	amount	dollars(amount)
+1	100.23	125.29
+2	123.23	154.04
+3	25.25	31.56
+4	210.23	262.79
+5	300	375.00
+6	10	12.50
+7	23.9	29.87
+
+***  DROP bup_sfs DATABASE ****
+
+DROP DATABASE bup_sfs;

=== added file 'mysql-test/suite/backup/r/backup_procedures.result'
--- a/mysql-test/suite/backup/r/backup_procedures.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_procedures.result	2008-08-12 03:22:05 +0000
@@ -0,0 +1,175 @@
+SHOW VARIABLES LIKE 'storage_engine';
+Variable_name	Value
+storage_engine	#
+
+starting the test for backup
+
+DROP DATABASE IF EXISTS bup_sp;
+CREATE DATABASE bup_sp;
+USE bup_sp;
+*******Creating table******
+CREATE TABLE bup_sp.country(
+ccode CHAR(10),
+city VARCHAR(10)
+);
+*********loading data*********
+INSERT INTO bup_sp.country VALUES
+('IND','chennai'),('US','sfo'),('US','austin'),
+('IND','Bomb'),('US','Richmond'),('IND','hyd');
+SELECT * FROM bup_sp.country ORDER BY ccode, city;
+ccode	city
+IND	Bomb
+IND	chennai
+IND	hyd
+US	austin
+US	Richmond
+US	sfo
+CREATE PROCEDURE countryinfo (IN loc CHAR(5))
+BEGIN
+SELECT * FROM country WHERE ccode=loc;
+END;
+||
+CREATE PROCEDURE dorepeat(p1 INT)
+BEGIN
+SET @x = 0;
+REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
+END ;||
+CALL countryinfo('US');
+ccode	city
+US	sfo
+US	austin
+US	Richmond
+CALL countryinfo('IND');
+ccode	city
+IND	chennai
+IND	Bomb
+IND	hyd
+CALL dorepeat(1000);
+SELECT @x;
+@x
+1001
+showing objects and create statements.
+SHOW CREATE PROCEDURE countryinfo;;
+Procedure	countryinfo
+sql_mode	
+Create Procedure	CREATE DEFINER=`root`@`localhost` PROCEDURE `countryinfo`(IN loc CHAR(5))
+BEGIN
+SELECT * FROM country WHERE ccode=loc;
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE country;;
+Table	country
+Create Table	CREATE TABLE `country` (
+  `ccode` char(10) DEFAULT NULL,
+  `city` varchar(10) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+SHOW PROCEDURE STATUS;;
+Db	bup_sp
+Name	countryinfo
+Type	PROCEDURE
+Definer	#
+Modified	#
+Created	#
+Security_type	#
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sp
+Name	dorepeat
+Type	PROCEDURE
+Definer	#
+Modified	#
+Created	#
+Security_type	#
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+backup data
+
+BACKUP DATABASE bup_sp TO 'bup_sp.bak';
+backup_id
+#
+dropping  database.
+DROP DATABASE bup_sp;
+
+RESTORE FROM 'bup_sp.bak';
+backup_id
+#
+showing objects and create statements
+SHOW CREATE PROCEDURE countryinfo;;
+Procedure	countryinfo
+sql_mode	
+Create Procedure	CREATE DEFINER=`root`@`localhost` PROCEDURE `countryinfo`(IN loc CHAR(5))
+BEGIN
+SELECT * FROM country WHERE ccode=loc;
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE country;;
+Table	country
+Create Table	CREATE TABLE `country` (
+  `ccode` char(10) DEFAULT NULL,
+  `city` varchar(10) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+SHOW PROCEDURE STATUS;;
+Db	bup_sp
+Name	countryinfo
+Type	PROCEDURE
+Definer	#
+Modified	#
+Created	#
+Security_type	#
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Db	bup_sp
+Name	dorepeat
+Type	PROCEDURE
+Definer	#
+Modified	#
+Created	#
+Security_type	#
+Comment	
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+INSERT INTO bup_sp.country VALUES
+('US','boston'),('IND','jaipur'),('US','natick');
+SELECT * FROM bup_sp.country ORDER BY  ccode, city;
+ccode	city
+IND	Bomb
+IND	chennai
+IND	hyd
+IND	jaipur
+US	austin
+US	boston
+US	natick
+US	Richmond
+US	sfo
+CALL countryinfo('IND');
+ccode	city
+IND	chennai
+IND	Bomb
+IND	hyd
+IND	jaipur
+CALL countryinfo('US');
+ccode	city
+US	sfo
+US	austin
+US	Richmond
+US	boston
+US	natick
+CALL dorepeat(99);
+SELECT @x;
+@x
+100
+
+***  DROP bup_sp DATABASE ****
+
+DROP DATABASE bup_sp;

=== added file 'mysql-test/suite/backup/r/backup_triggers.result'
--- a/mysql-test/suite/backup/r/backup_triggers.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_triggers.result	2008-08-12 03:22:05 +0000
@@ -0,0 +1,775 @@
+SHOW VARIABLES LIKE 'storage_engine';
+Variable_name	Value
+storage_engine	#
+
+starting the test for backup
+
+DROP DATABASE IF EXISTS bup_ts;
+CREATE DATABASE bup_ts;
+USE bup_ts;
+SELECT @@SQL_MODE;
+@@SQL_MODE
+
+*****Creating table cap ******
+CREATE TABLE bup_ts.cap(
+id SMALLINT,
+country CHAR(20),
+city VARCHAR(20),
+population BIGINT,
+capital CHAR(20)
+);
+******* Creating table city*****.
+CREATE TABLE bup_ts.city(
+id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+name VARCHAR(20),
+ccode CHAR(10),
+population bigint
+);
+*******Creating table dropcity *****
+CREATE TABLE bup_ts.dropcity(
+id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+name VARCHAR(20)
+);
+******Create Trigger for the table*******
+*******creating trigger with event before insert**********
+CREATE TRIGGER cap_tri BEFORE INSERT ON cap FOR EACH ROW
+SET new.population= if(new.population<0,0,truncate(new.population,-3));||
+********creating trigger with event before Update******
+CREATE  TRIGGER capu_tri BEFORE UPDATE ON cap FOR EACH ROW
+BEGIN
+SET @country=old.country;
+SET @capital_old=old.capital;
+SET @capital_new=new.capital;
+END;
+||
+*****creating trigger with event after delete********
+CREATE TRIGGER cityin_d AFTER
+DELETE ON city FOR EACH ROW
+INSERT INTO dropcity(id, name) VALUES(old.id, old.name);||
+Creating Tables
+CREATE TABLE bup_ts.t2(a CHAR(4));
+CREATE TABLE bup_ts.t3(a CHAR(4));
+CREATE TABLE bup_ts.t4(a CHAR(4));
+Creating Triggers
+Creating trigger with event after insert
+CREATE TRIGGER trai AFTER INSERT ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END;
+||
+Creating trigger with event after Update
+CREATE TRIGGER trau AFTER UPDATE ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END;
+||
+Load data in to table
+********Inserting Values in tables*********
+INSERT INTO bup_ts.cap VALUES
+(1,'IND','chn',87874646468,'deli'),(2,'US','Austin',-6466547,'DC'),
+(3,'Russia','moscow',76487623235682,'moscow'),(4,'IND','bang',-83875477,'deli'),
+(5,'US','sacramento',-388348,'DC'),(6,'IND','jammu',3848488,'deli'),
+(7,'Russia','xx',-373788,'moscow'),(8,'IND','hyd',647747,'deli');
+INSERT INTO bup_ts.city VALUES
+(1,'aa','AD',263768),(2,'bb','PO',8839898),(3,'cc','KL',898778),
+(4,'dd','IK',73287328),(5,'ee','YU',89399),(6,'ff','IL',90880),
+(7,'gg','TY',345),(8,'hh','WE',9239084);
+Updating the table to fire trigger with event update
+UPDATE cap SET capital='Delhi' WHERE country='Ind';
+UPDATE cap SET capital='Washington DC' WHERE country='US';
+SELECT @country as country, @capital_old as 'old capital',
+@capital_new as 'new capital';
+country	old capital	new capital
+US	DC	Washington DC
+showing the tables to check the trigger is fired  with event insert
+SELECT * FROM bup_ts.cap ORDER BY city;
+id	country	city	population	capital
+2	US	Austin	0	Washington DC
+4	IND	bang	0	Delhi
+1	IND	chn	87874646000	Delhi
+8	IND	hyd	647000	Delhi
+6	IND	jammu	3848000	Delhi
+3	Russia	moscow	76487623235000	moscow
+5	US	sacramento	0	Washington DC
+7	Russia	xx	0	moscow
+selecting data from table city
+SELECT * FROM bup_ts.city ORDER BY name;
+id	name	ccode	population
+1	aa	AD	263768
+2	bb	PO	8839898
+3	cc	KL	898778
+4	dd	IK	73287328
+5	ee	YU	89399
+6	ff	IL	90880
+7	gg	TY	345
+8	hh	WE	9239084
+deleting few rows from table city to fire trigger with event delete.
+DELETE FROM bup_ts.city WHERE name='dd';
+DELETE FROM bup_ts.city WHERE name='bb';
+
+Checking table contents of city and dropcity to verify if trigger is
+fired for event delete.
+SELECT * FROM city ORDER BY name;
+id	name	ccode	population
+1	aa	AD	263768
+3	cc	KL	898778
+5	ee	YU	89399
+6	ff	IL	90880
+7	gg	TY	345
+8	hh	WE	9239084
+SELECT * FROM dropcity ORDER BY id;
+id	name
+2	bb
+4	dd
+******Firing Trigger after insert and after update *********
+INSERT INTO bup_ts.t2 values('a'),('k'),('*'),('i');
+SELECT * FROM bup_ts.t3;
+a
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+UPDATE t2 SET a='*' WHERE a='k';
+SELECT * FROM bup_ts.t4;
+a
+J
+O
+B
+Show the data and Create statements
+showing objects and create statements.
+SHOW TRIGGERS;;
+Trigger	cap_tri
+Event	INSERT
+Table	cap
+Statement	SET new.population= if(new.population<0,0,truncate(new.population,-3))
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	capu_tri
+Event	UPDATE
+Table	cap
+Statement	BEGIN
+SET @country=old.country;
+SET @capital_old=old.capital;
+SET @capital_new=new.capital;
+END
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	cityin_d
+Event	DELETE
+Table	city
+Statement	INSERT INTO dropcity(id, name) VALUES(old.id, old.name)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trai
+Event	INSERT
+Table	t2
+Statement	BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trau
+Event	UPDATE
+Table	t2
+Statement	BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER cap_tri;;
+Trigger	cap_tri
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER cap_tri BEFORE INSERT ON cap FOR EACH ROW
+SET new.population= if(new.population<0,0,truncate(new.population,-3))
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER capu_tri;;
+Trigger	capu_tri
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER capu_tri BEFORE UPDATE ON cap FOR EACH ROW
+BEGIN
+SET @country=old.country;
+SET @capital_old=old.capital;
+SET @capital_new=new.capital;
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER cityin_d;;
+Trigger	cityin_d
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER cityin_d AFTER
+DELETE ON city FOR EACH ROW
+INSERT INTO dropcity(id, name) VALUES(old.id, old.name)
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER trai;;
+Trigger	trai
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER trai AFTER INSERT ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER trau;;
+Trigger	trau
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER trau AFTER UPDATE ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE city;;
+Table	city
+Create Table	CREATE TABLE `city` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(20) DEFAULT NULL,
+  `ccode` char(10) DEFAULT NULL,
+  `population` bigint(20) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=ENGINE AUTO_INCREMENT=9 DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;;
+Table	t2
+Create Table	CREATE TABLE `t2` (
+  `a` char(4) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+backup data
+BACKUP DATABASE bup_ts TO 'bup_ts.bak';
+backup_id
+#
+dropping  database.
+DROP DATABASE bup_ts;
+perform restore
+RESTORE FROM 'bup_ts.bak';
+backup_id
+#
+show data and create statements after Restore
+showing objects and create statements
+SHOW CREATE DATABASE bup_ts;;
+Database	bup_ts
+Create Database	CREATE DATABASE `bup_ts` /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE TRIGGER cap_tri;;
+Trigger	cap_tri
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER cap_tri BEFORE INSERT ON cap FOR EACH ROW
+SET new.population= if(new.population<0,0,truncate(new.population,-3))
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER cityin_d;;
+Trigger	cityin_d
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER cityin_d AFTER
+DELETE ON city FOR EACH ROW
+INSERT INTO dropcity(id, name) VALUES(old.id, old.name)
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER trai;;
+Trigger	trai
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER trai AFTER INSERT ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TRIGGER trau;;
+Trigger	trau
+sql_mode	
+SQL Original Statement	CREATE DEFINER=`root`@`localhost` TRIGGER trau AFTER UPDATE ON t2 FOR EACH ROW
+BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW TRIGGERS;;
+Trigger	cap_tri
+Event	INSERT
+Table	cap
+Statement	SET new.population= if(new.population<0,0,truncate(new.population,-3))
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	capu_tri
+Event	UPDATE
+Table	cap
+Statement	BEGIN
+SET @country=old.country;
+SET @capital_old=old.capital;
+SET @capital_new=new.capital;
+END
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	cityin_d
+Event	DELETE
+Table	city
+Statement	INSERT INTO dropcity(id, name) VALUES(old.id, old.name)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trai
+Event	INSERT
+Table	t2
+Statement	BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trau
+Event	UPDATE
+Table	t2
+Statement	BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Inserting some more values in the table to check the trigger with event insert
+INSERT INTO bup_ts.cap VALUES
+(9,'US','houston',-33399587677866656555655555655,'texas');
+Warnings:
+Warning	1264	Out of range value for column 'population' at row 1
+SELECT * FROM bup_ts.cap ORDER BY city;
+id	country	city	population	capital
+2	US	Austin	0	Washington DC
+4	IND	bang	0	Delhi
+1	IND	chn	87874646000	Delhi
+9	US	houston	0	texas
+8	IND	hyd	647000	Delhi
+6	IND	jammu	3848000	Delhi
+3	Russia	moscow	76487623235000	moscow
+5	US	sacramento	0	Washington DC
+7	Russia	xx	0	moscow
+Deleting some rows from city to check the trigger with event delete
+DELETE FROM city WHERE name='aa';
+Checking table city and drop city
+SELECT * FROM bup_ts.city ORDER BY name;
+id	name	ccode	population
+3	cc	KL	898778
+5	ee	YU	89399
+6	ff	IL	90880
+7	gg	TY	345
+8	hh	WE	9239084
+SELECT * FROM bup_ts.dropcity ORDER BY id;
+id	name
+1	aa
+2	bb
+4	dd
+INSERT INTO bup_ts.t2 VALUES('m'),('s1'),('s'),('q'),('l');
+SELECT * FROM bup_ts.t3;
+a
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+UPDATE t2 SET a='y' WHERE a='s1';
+SELECT * FROM bup_ts.t4;
+a
+J
+O
+B
+J
+O
+B
+DROP DATABASE bup_ts;
+Change sql mode and perform Restore and check the table contents.
+SET SQL_MODE=TRADITIONAL;
+RESTORE FROM 'bup_ts.bak';
+backup_id
+#
+SHOW TRIGGERS;;
+Trigger	cap_tri
+Event	INSERT
+Table	cap
+Statement	SET new.population= if(new.population<0,0,truncate(new.population,-3))
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	capu_tri
+Event	UPDATE
+Table	cap
+Statement	BEGIN
+SET @country=old.country;
+SET @capital_old=old.capital;
+SET @capital_new=new.capital;
+END
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	cityin_d
+Event	DELETE
+Table	city
+Statement	INSERT INTO dropcity(id, name) VALUES(old.id, old.name)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trai
+Event	INSERT
+Table	t2
+Statement	BEGIN
+INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	trau
+Event	UPDATE
+Table	t2
+Statement	BEGIN
+INSERT INTO t4 VALUES('J'),('O'),('B');
+END
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW CREATE TABLE t2;;
+Table	t2
+Create Table	CREATE TABLE `t2` (
+  `a` char(4) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+SHOW CREATE TABLE city;;
+Table	city
+Create Table	CREATE TABLE `city` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(20) DEFAULT NULL,
+  `ccode` char(10) DEFAULT NULL,
+  `population` bigint(20) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=ENGINE AUTO_INCREMENT=9 DEFAULT CHARSET=latin1
+SHOW CREATE TABLE cap;;
+Table	cap
+Create Table	CREATE TABLE `cap` (
+  `id` smallint(6) DEFAULT NULL,
+  `country` char(20) DEFAULT NULL,
+  `city` varchar(20) DEFAULT NULL,
+  `population` bigint(20) DEFAULT NULL,
+  `capital` char(20) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+Check contents after Restore and change of SQL mode
+INSERT INTO bup_ts.cap VALUES(10,'India','Daund',36637782899,'maharashtra');
+SELECT * FROM bup_ts.cap ORDER BY city;
+id	country	city	population	capital
+2	US	Austin	0	Washington DC
+4	IND	bang	0	Delhi
+1	IND	chn	87874646000	Delhi
+10	India	Daund	36637782000	maharashtra
+8	IND	hyd	647000	Delhi
+6	IND	jammu	3848000	Delhi
+3	Russia	moscow	76487623235000	moscow
+5	US	sacramento	0	Washington DC
+7	Russia	xx	0	moscow
+INSERT INTO bup_ts.t2 VALUES('i'),('w');
+SELECT * FROM t3;
+a
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+UPDATE t2 SET a='^' WHERE a='w';
+SELECT * FROM t4;
+a
+J
+O
+B
+J
+O
+B
+DROP DATABASE bup_ts;
+change of SQL mode
+SET SQL_MODE=MAXDB;
+RESTORE FROM 'bup_ts.bak';
+backup_id
+#
+Check contents after Restore and change of SQL mode
+INSERT INTO bup_ts.cap VALUES(11,'UK','Edenburg',-36637782899,'london');
+SELECT * FROM bup_ts.cap ORDER BY city;
+id	country	city	population	capital
+2	US	Austin	0	Washington DC
+4	IND	bang	0	Delhi
+1	IND	chn	87874646000	Delhi
+11	UK	Edenburg	0	london
+8	IND	hyd	647000	Delhi
+6	IND	jammu	3848000	Delhi
+3	Russia	moscow	76487623235000	moscow
+5	US	sacramento	0	Washington DC
+7	Russia	xx	0	moscow
+INSERT INTO bup_ts.t2 VALUES('i'),('w'),('h');
+SELECT * FROM bup_ts.t3;
+a
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+UPDATE t2 SET a='p' WHERE a='h';
+SELECT * FROM bup_ts.t4;
+a
+J
+O
+B
+J
+O
+B
+DROP DATABASE bup_ts;
+Chnage SQL mode and then perform Restore.
+SET SQL_MODE=ANSI;
+RESTORE FROM 'bup_ts.bak';
+backup_id
+#
+Check contents after Restore and change of SQL mode
+INSERT INTO bup_ts.cap VALUES(12,'India','vooty',789,'Tamilnadu');
+SELECT * FROM bup_ts.cap ORDER BY city;
+id	country	city	population	capital
+2	US	Austin	0	Washington DC
+4	IND	bang	0	Delhi
+1	IND	chn	87874646000	Delhi
+8	IND	hyd	647000	Delhi
+6	IND	jammu	3848000	Delhi
+3	Russia	moscow	76487623235000	moscow
+5	US	sacramento	0	Washington DC
+12	India	vooty	0	Tamilnadu
+7	Russia	xx	0	moscow
+INSERT INTO bup_ts.t2 VALUES('i'),('w'),('h'),('b');
+SELECT * FROM bup_ts.t3;
+a
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+H
+E
+L
+L
+O
+UPDATE bup_ts.t2 SET a='#' WHERE a='w';
+SELECT * FROM bup_ts.t4;
+a
+J
+O
+B
+J
+O
+B
+
+***  DROP bup_ts DATABASE ****
+
+DROP DATABASE bup_ts;

=== added file 'mysql-test/suite/backup/t/backup_functions.test'
--- a/mysql-test/suite/backup/t/backup_functions.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_functions.test	2008-08-27 12:49:58 +0000
@@ -0,0 +1,273 @@
+###########################################################################
+# Author: Hema
+# Date: 2008-03-11
+# Purpose: To test the metadata consistency of  object (stored functions)
+# after backup and Restore.
+###############################################################################
+--source include/not_embedded.inc
+--source suite/backup/include/backup_engine.inc
+--source include/have_debug.inc
+
+connect (backup,localhost,root,,);
+connect (breakpoints,localhost,root,,);
+
+##############################################################
+--echo
+--echo starting the test for backup
+--echo
+##############################################################
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--error 0,1
+remove_file $MYSQLD_DATADIR/bup_sfs.bak;
+
+#Create Database and object stored function for this test.
+
+--disable_warnings
+DROP DATABASE IF EXISTS bup_sfs;
+--enable_warnings
+
+CREATE DATABASE bup_sfs;
+USE bup_sfs;
+
+SET SQL_MODE=TRADITIONAL;
+
+#Create table and load with data.
+
+--echo Creating table
+
+CREATE TABLE bup_sfs.players(
+playerno INT not null PRIMARY KEY,
+name CHAR(10),
+Bdate DATE,
+sex CHAR(2),
+joined YEAR
+);
+
+CREATE TABLE bup_sfs.teams(
+teamno INT NOT NULL PRIMARY KEY,
+playerno INT,
+division CHAR(10),
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+
+CREATE TABLE bup_sfs.matches(
+Matchno INT NOT NULL PRIMARY KEY,
+teamno INT ,
+playerno INT,
+won INT,
+lost INT,
+FOREIGN KEY(teamno) REFERENCES teams(teamno),
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+
+CREATE TABLE bup_sfs.penalties(
+paymentno INT not null PRIMARY KEY,
+playerno INT,
+paymentdate DATE,
+amount FLOAT,
+FOREIGN KEY(playerno) REFERENCES players(playerno)
+);
+
+--echo Load Data in tables
+
+INSERT INTO bup_sfs.players VALUES
+(1,'aa1','1948-10-09','M','1960'),(2,'aa2','1950-05-09','M','1965'),
+(3,'aa3','1953-10-10','F','1970'),(4,'aa4','1970-10-19','M','1985'),
+(5,'aa5','1972-04-28','F','1994'),(6,'aa6','1945-01-26','M','1960');
+
+INSERT INTO bup_sfs.teams VALUES(1,3,'first'),(2,4,'division');
+
+INSERT INTO bup_sfs.matches VALUES
+(1,1,2,3,1),(2,2,1,4,2),(3,1,5,0,1),(4,2,4,3,0),(5,2,5,2,2),
+(6,1,3,3,1),(7,2,1,4,2),(8,1,5,0,1),(9,2,2,3,0),(10,2,2,2,2);
+
+INSERT INTO bup_sfs.penalties VALUES
+(1,5,'1980-10-10',100.23),(2,3,'1967-12-10',123.23),
+(3,3,'1983-05-25',25.25), (4,4,'1981-11-10',210.23) ,
+(5,5,'1980-12-12',300), (6,1,'1984-07-02',10),
+(7,1,'1985-10-10',23.90);
+
+#Create stored functions for the table
+
+delimiter ||;
+CREATE FUNCTION number_of_players() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM players);
+END;
+||
+
+CREATE FUNCTION number_of_players1() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM players WHERE playerno > 2);
+END;
+||
+
+CREATE FUNCTION fcount() RETURNS INTEGER
+BEGIN
+  DECLARE v_out INT;
+  SELECT count(*) FROM matches INTO v_out;
+  RETURN v_out;
+END;
+||
+
+CREATE FUNCTION dollars(amount FLOAT(7,2)) RETURNS FLOAT(7,2)
+BEGIN
+  RETURN amount * (1/0.8);
+END;
+||
+
+delimiter ;||
+
+#Excercise the objects
+
+SELECT number_of_players();
+SELECT number_of_players1();
+SELECT fcount();
+SELECT paymentno,amount, dollars(amount) FROM penalties;
+--echo creating stored functions which is not dependent on table
+#BUG#34868 Backup: restore failure if two procedures but this doesn't happen for
+#  procedures in database, which has atleast one table
+
+
+CREATE FUNCTION square_area(side tinyINT)
+RETURNS FLOAT
+RETURN side * side;
+
+#excercise function
+
+SELECT square_area(11);
+
+#Show data and create statements.
+--echo showing objects and create statements.
+--query_vertical SHOW CREATE FUNCTION number_of_players;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE players;
+describe penalties;
+--replace_column  4 # 5 # 6 #
+--query_vertical SHOW FUNCTION STATUS;
+
+#Backup and restore data.
+--echo backup data
+--replace_column 1 #
+BACKUP DATABASE bup_sfs TO 'bup_sfs.bak';
+
+--echo dropping  database.
+DROP DATABASE bup_sfs;
+
+--echo Restoring Database
+
+# BUG#35118 Backup:Restore fails if previous create Procedure/Function/Trigger
+# command fails
+
+--replace_column 1 #
+RESTORE FROM 'bup_sfs.bak';
+SELECT @@SQL_MODE;
+
+#show data and create statements
+--echo showing objects and create statements
+--query_vertical SHOW CREATE DATABASE bup_sfs;
+--query_vertical SHOW CREATE FUNCTION number_of_players;
+describe penalties;
+describe matches;
+--replace_column  4 # 5 # 6 #
+
+--query_vertical SHOW FUNCTION STATUS;
+
+#Again calling function to check if Sf are backed up and restored properly or
+# not.
+
+INSERT INTO bup_sfs.players VALUES
+(57,'brown','1971-08-17','M','1985'),(95,'Miller','1963-05-14','M','1972');
+INSERT INTO bup_sfs.matches VALUES(11,2,6,0,3);
+
+SELECT square_area(12);
+SELECT number_of_players();
+SELECT number_of_players1();
+SELECT fcount();
+SELECT paymentno,amount, dollars(amount) FROM penalties WHERE paymentno<=3;
+
+#dropping Database again.
+DROP DATABASE bup_sfs;
+
+--echo change SQL_MODE and then perform RESTORE operation
+
+SET SQL_MODE=ANSI;
+--replace_column 1 #
+RESTORE FROM 'bup_sfs.bak';
+
+SELECT @@SQL_MODE;
+
+#show data and create statements
+--echo showing objects and create statements
+--query_vertical SHOW CREATE DATABASE bup_sfs;
+--query_vertical SHOW CREATE FUNCTION number_of_players;
+--replace_column  4 # 5 # 6 #
+
+--query_vertical SHOW FUNCTION STATUS;
+
+#Again calling function to check if Sf are backed up and restored
+#properly or not.
+
+SELECT square_area(13);
+SELECT number_of_players();
+SELECT fcount();
+DROP DATABASE bup_sfs;
+
+--echo change SQL_MODE and then perform RESTORE
+
+SET SQL_MODE=MAXDB;
+--replace_column 1 #
+RESTORE FROM 'bup_sfs.bak';
+
+SELECT @@SQL_MODE;
+
+#show data and create statements
+--echo showing objects and create statements
+--query_vertical SHOW CREATE DATABASE bup_sfs;
+--query_vertical SHOW CREATE FUNCTION number_of_players;
+--replace_column  4 # 5 # 6 #
+--query_vertical SHOW FUNCTION STATUS;
+
+#Again calling function to check if Sf are backed up and restored properly
+#or not.
+
+SELECT square_area(14);
+SELECT number_of_players();
+SELECT fcount();
+SELECT paymentno,amount, dollars(amount) FROM penalties WHERE paymentno >=3;
+DROP DATABASE bup_sfs;
+--echo change SQL_MODE and then perform RESTORE
+
+SET SQL_MODE=' ';
+--replace_column 1 #
+RESTORE FROM 'bup_sfs.bak';
+
+SELECT @@SQL_MODE;
+#show data and create statements
+--echo showing objects and create statements
+--query_vertical SHOW CREATE DATABASE bup_sfs;
+--query_vertical SHOW CREATE FUNCTION number_of_players;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE players;
+describe matches;
+--replace_column  4 # 5 # 6 #
+--query_vertical SHOW FUNCTION STATUS;
+
+#Again calling function to check if Sf are backed up and restored properly
+# ornot
+
+SELECT square_area(20);
+SELECT number_of_players();
+SELECT fcount();
+SELECT paymentno,amount, dollars(amount) FROM penalties;
+
+# Test cleanup section
+
+--echo
+--echo ***  DROP bup_sfs DATABASE ****
+--echo
+
+DROP DATABASE bup_sfs;
+
+remove_file $MYSQLD_DATADIR/bup_sfs.bak;

=== modified file 'mysql-test/suite/backup/t/backup_online_testing.test'
--- a/mysql-test/suite/backup/t/backup_online_testing.test	2008-07-22 18:08:06 +0000
+++ b/mysql-test/suite/backup/t/backup_online_testing.test	2008-08-27 12:49:58 +0000
@@ -47,11 +47,13 @@
 # Initialize the debug sync facility.
 SET DEBUG_SYNC= 'RESET';
 DROP DATABASE IF EXISTS bup_online;
+--enable_warnings
 
 let $MYSQLD_DATADIR= `select @@datadir`;
 --error 0,1
 remove_file $MYSQLD_DATADIR/bup_online.bak;
---enable_warnings
+--error 0,1
+remove_file $MYSQLD_DATADIR/bup_online1.bak;
 
 ##############################################################
 --echo

=== added file 'mysql-test/suite/backup/t/backup_procedures.test'
--- a/mysql-test/suite/backup/t/backup_procedures.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_procedures.test	2008-08-27 12:49:58 +0000
@@ -0,0 +1,124 @@
+###########################################################################
+# Author: Hema
+# Date: 2008-03-11
+# Purpose: To test the metadata consistency object stored procedures  for all
+#  storage engines.
+###############################################################################
+--source include/not_embedded.inc
+--source suite/backup/include/backup_engine.inc
+--source include/have_debug.inc
+
+connect (backup,localhost,root,,);
+connect (breakpoints,localhost,root,,);
+
+##############################################################
+--echo
+--echo starting the test for backup
+--echo
+##############################################################
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--error 0,1
+remove_file $MYSQLD_DATADIR/bup_sp.bak;
+
+# Multiple instances of stored routines without atleast one table in
+# database results in failure.
+# BUG#34868
+
+--disable_warnings
+DROP DATABASE IF EXISTS bup_sp;
+--enable_warnings
+
+CREATE DATABASE bup_sp;
+USE bup_sp;
+
+#Create table with all storage engines and load with data.
+
+--echo *******Creating table******
+
+CREATE TABLE bup_sp.country(
+ccode CHAR(10),
+city VARCHAR(10)
+);
+
+--echo *********loading data*********
+INSERT INTO bup_sp.country VALUES
+('IND','chennai'),('US','sfo'),('US','austin'),
+('IND','Bomb'),('US','Richmond'),('IND','hyd');
+
+SELECT * FROM bup_sp.country ORDER BY ccode, city;
+
+#Create stored procedures for the table
+
+delimiter ||;
+CREATE PROCEDURE countryinfo (IN loc CHAR(5))
+BEGIN
+  SELECT * FROM country WHERE ccode=loc;
+END;
+||
+
+CREATE PROCEDURE dorepeat(p1 INT)
+ BEGIN
+ SET @x = 0;
+ REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
+ END ;||
+delimiter ;||
+
+#Excercise the objects
+
+CALL countryinfo('US');
+CALL countryinfo('IND');
+CALL dorepeat(1000);
+SELECT @x;
+#Show the data and Create statements
+
+--echo showing objects and create statements.
+--query_vertical SHOW CREATE PROCEDURE countryinfo;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE country;
+--replace_column 4 # 5 # 6 # 7 #
+--query_vertical SHOW PROCEDURE STATUS;
+
+#Backup and restore data.
+
+--echo backup data
+--echo
+--replace_column 1 #
+BACKUP DATABASE bup_sp TO 'bup_sp.bak';
+--echo dropping  database.
+DROP DATABASE bup_sp;
+
+#RESTORE FROM bup_sp.bak;
+--echo
+--replace_column 1 #
+RESTORE FROM 'bup_sp.bak';
+
+#show data and create statements
+--echo showing objects and create statements
+--query_vertical SHOW CREATE PROCEDURE countryinfo;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE country;
+--replace_column 4 # 5 # 6 # 7 #
+--query_vertical SHOW PROCEDURE STATUS;
+
+
+#Excercise the objects after restore to make sure if objects are backedup and
+#restored properly.
+
+INSERT INTO bup_sp.country VALUES
+('US','boston'),('IND','jaipur'),('US','natick');
+SELECT * FROM bup_sp.country ORDER BY  ccode, city;
+CALL countryinfo('IND');
+CALL countryinfo('US');
+CALL dorepeat(99);
+SELECT @x;
+
+# Test cleanup section
+
+--echo
+--echo ***  DROP bup_sp DATABASE ****
+--echo
+
+DROP DATABASE bup_sp;
+
+remove_file $MYSQLD_DATADIR/bup_sp.bak;

=== added file 'mysql-test/suite/backup/t/backup_triggers.test'
--- a/mysql-test/suite/backup/t/backup_triggers.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_triggers.test	2008-08-27 12:49:58 +0000
@@ -0,0 +1,299 @@
+
+##################################################################
+# Author: Hema
+# Date: 2008-05-28
+# Purpose: To test the metadata consistency of object trigger for all
+#  storage engines
+###################################################################
+
+--source include/not_embedded.inc
+--source suite/backup/include/backup_engine.inc
+--source include/have_debug.inc
+
+connect (backup,localhost,root,,);
+connect (breakpoints,localhost,root,,);
+
+##############################################################
+--echo
+--echo starting the test for backup
+--echo
+##############################################################
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--error 0,1
+remove_file $MYSQLD_DATADIR/bup_ts.bak;
+
+--error 0,1
+--disable_warnings
+#Create Database and object trigger for this test.
+
+DROP DATABASE IF EXISTS bup_ts;
+--enable_warnings
+
+CREATE DATABASE bup_ts;
+USE bup_ts;
+
+#Create table and load with data.
+SELECT @@SQL_MODE;
+--echo *****Creating table cap ******
+
+CREATE TABLE bup_ts.cap(
+id SMALLINT,
+country CHAR(20),
+city VARCHAR(20),
+population BIGINT,
+capital CHAR(20)
+);
+
+--echo ******* Creating table city*****.
+
+CREATE TABLE bup_ts.city(
+id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+name VARCHAR(20),
+ccode CHAR(10),
+population bigint
+);
+
+--echo *******Creating table dropcity *****
+
+CREATE TABLE bup_ts.dropcity(
+id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
+name VARCHAR(20)
+);
+
+--echo ******Create Trigger for the table*******
+# BUG#35118 Restore fails if previous create Procedure/Function/Trigger
+# command fails
+
+delimiter ||;
+
+--echo *******creating trigger with event before insert**********
+#BUG#34759 Server crash when backing-up database with after insert
+# trigger with event delete.
+
+CREATE TRIGGER cap_tri BEFORE INSERT ON cap FOR EACH ROW
+SET new.population= if(new.population<0,0,truncate(new.population,-3));||
+
+--echo ********creating trigger with event before Update******
+CREATE  TRIGGER capu_tri BEFORE UPDATE ON cap FOR EACH ROW
+BEGIN
+ SET @country=old.country;
+ SET @capital_old=old.capital;
+ SET @capital_new=new.capital;
+END;
+||
+
+--echo *****creating trigger with event after delete********
+
+CREATE TRIGGER cityin_d AFTER
+DELETE ON city FOR EACH ROW
+INSERT INTO dropcity(id, name) VALUES(old.id, old.name);||
+
+--echo Creating Tables
+delimiter ;||
+
+CREATE TABLE bup_ts.t2(a CHAR(4));
+CREATE TABLE bup_ts.t3(a CHAR(4));
+CREATE TABLE bup_ts.t4(a CHAR(4));
+
+--echo Creating Triggers
+
+--echo Creating trigger with event after insert
+#BUG#34759 Server crash when backing-up database with after insert trigger with
+# event delete.
+
+delimiter ||;
+
+CREATE TRIGGER trai AFTER INSERT ON t2 FOR EACH ROW
+BEGIN
+ INSERT INTO t3 VALUES('H'),('E'),('L'),('L'),('O');
+END;
+||
+
+--echo Creating trigger with event after Update
+
+CREATE TRIGGER trau AFTER UPDATE ON t2 FOR EACH ROW
+BEGIN
+ INSERT INTO t4 VALUES('J'),('O'),('B');
+END;
+||
+
+delimiter ;||
+
+--echo Load data in to table
+--echo ********Inserting Values in tables*********
+
+INSERT INTO bup_ts.cap VALUES
+(1,'IND','chn',87874646468,'deli'),(2,'US','Austin',-6466547,'DC'),
+(3,'Russia','moscow',76487623235682,'moscow'),(4,'IND','bang',-83875477,'deli'),
+(5,'US','sacramento',-388348,'DC'),(6,'IND','jammu',3848488,'deli'),
+(7,'Russia','xx',-373788,'moscow'),(8,'IND','hyd',647747,'deli');
+
+INSERT INTO bup_ts.city VALUES
+(1,'aa','AD',263768),(2,'bb','PO',8839898),(3,'cc','KL',898778),
+(4,'dd','IK',73287328),(5,'ee','YU',89399),(6,'ff','IL',90880),
+(7,'gg','TY',345),(8,'hh','WE',9239084);
+
+--echo  Updating the table to fire trigger with event update
+
+UPDATE cap SET capital='Delhi' WHERE country='Ind';
+UPDATE cap SET capital='Washington DC' WHERE country='US';
+SELECT @country as country, @capital_old as 'old capital',
+@capital_new as 'new capital';
+
+--echo showing the tables to check the trigger is fired  with event insert
+
+SELECT * FROM bup_ts.cap ORDER BY city;
+
+--echo selecting data from table city
+
+SELECT * FROM bup_ts.city ORDER BY name;
+
+--echo deleting few rows from table city to fire trigger with event delete.
+#*****Bug#35249******
+#Here memory storage engine crashes if trigger is created
+# with event delete and executed.
+
+DELETE FROM bup_ts.city WHERE name='dd';
+DELETE FROM bup_ts.city WHERE name='bb';
+
+--echo
+--echo Checking table contents of city and dropcity to verify if trigger is
+--echo fired for event delete.
+SELECT * FROM city ORDER BY name;
+SELECT * FROM dropcity ORDER BY id;
+
+--echo ******Firing Trigger after insert and after update *********
+
+INSERT INTO bup_ts.t2 values('a'),('k'),('*'),('i');
+SELECT * FROM bup_ts.t3;
+UPDATE t2 SET a='*' WHERE a='k';
+SELECT * FROM bup_ts.t4;
+
+--echo Show the data and Create statements
+
+--echo showing objects and create statements.
+--query_vertical SHOW TRIGGERS;
+--query_vertical SHOW CREATE TRIGGER cap_tri;
+--query_vertical SHOW CREATE TRIGGER capu_tri;
+--query_vertical SHOW CREATE TRIGGER cityin_d;
+--query_vertical SHOW CREATE TRIGGER trai;
+--query_vertical SHOW CREATE TRIGGER trau;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE city;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE t2;
+
+
+#Backup and restore data.
+--echo backup data
+--replace_column 1 #
+
+BACKUP DATABASE bup_ts TO 'bup_ts.bak';
+
+--echo dropping  database.
+DROP DATABASE bup_ts;
+
+--echo perform restore
+--replace_column 1 #
+
+RESTORE FROM 'bup_ts.bak';
+
+--echo show data and create statements after Restore
+--echo showing objects and create statements
+--query_vertical SHOW CREATE DATABASE bup_ts;
+--query_vertical SHOW CREATE TRIGGER cap_tri;
+--query_vertical SHOW CREATE TRIGGER cityin_d;
+--query_vertical SHOW CREATE TRIGGER trai;
+--query_vertical SHOW CREATE TRIGGER trau;
+--query_vertical SHOW TRIGGERS;
+--echo  Inserting some more values in the table to check the trigger with event insert
+
+INSERT INTO bup_ts.cap VALUES
+(9,'US','houston',-33399587677866656555655555655,'texas');
+
+SELECT * FROM bup_ts.cap ORDER BY city;
+
+--echo Deleting some rows from city to check the trigger with event delete
+
+DELETE FROM city WHERE name='aa';
+
+--echo Checking table city and drop city
+
+SELECT * FROM bup_ts.city ORDER BY name;
+SELECT * FROM bup_ts.dropcity ORDER BY id;
+INSERT INTO bup_ts.t2 VALUES('m'),('s1'),('s'),('q'),('l');
+SELECT * FROM bup_ts.t3;
+UPDATE t2 SET a='y' WHERE a='s1';
+SELECT * FROM bup_ts.t4;
+DROP DATABASE bup_ts;
+
+--echo Change sql mode and perform Restore and check the table contents.
+
+SET SQL_MODE=TRADITIONAL;
+--replace_column 1 #
+RESTORE FROM 'bup_ts.bak';
+
+--query_vertical SHOW TRIGGERS;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE t2;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE city;
+--replace_result $ENGINE ENGINE
+--query_vertical SHOW CREATE TABLE cap;
+--echo Check contents after Restore and change of SQL mode
+
+INSERT INTO bup_ts.cap VALUES(10,'India','Daund',36637782899,'maharashtra');
+SELECT * FROM bup_ts.cap ORDER BY city;
+INSERT INTO bup_ts.t2 VALUES('i'),('w');
+SELECT * FROM t3;
+UPDATE t2 SET a='^' WHERE a='w';
+SELECT * FROM t4;
+
+DROP DATABASE bup_ts;
+
+--echo change of SQL mode
+
+SET SQL_MODE=MAXDB;
+--replace_column 1 #
+RESTORE FROM 'bup_ts.bak';
+
+--echo Check contents after Restore and change of SQL mode
+
+INSERT INTO bup_ts.cap VALUES(11,'UK','Edenburg',-36637782899,'london');
+SELECT * FROM bup_ts.cap ORDER BY city;
+INSERT INTO bup_ts.t2 VALUES('i'),('w'),('h');
+SELECT * FROM bup_ts.t3;
+UPDATE t2 SET a='p' WHERE a='h';
+SELECT * FROM bup_ts.t4;
+
+DROP DATABASE bup_ts;
+--echo Chnage SQL mode and then perform Restore.
+
+SET SQL_MODE=ANSI;
+--replace_column 1 #
+
+RESTORE FROM 'bup_ts.bak';
+
+--echo Check contents after Restore and change of SQL mode
+
+INSERT INTO bup_ts.cap VALUES(12,'India','vooty',789,'Tamilnadu');
+
+SELECT * FROM bup_ts.cap ORDER BY city;
+INSERT INTO bup_ts.t2 VALUES('i'),('w'),('h'),('b');
+
+SELECT * FROM bup_ts.t3;
+UPDATE bup_ts.t2 SET a='#' WHERE a='w';
+
+SELECT * FROM bup_ts.t4;
+
+# Test cleanup section
+--echo
+--echo ***  DROP bup_ts DATABASE ****
+--echo
+
+DROP DATABASE bup_ts;
+
+remove_file $MYSQLD_DATADIR/bup_ts.bak;
+
+

=== modified file 'mysql-test/suite/falcon/r/falcon_bug_22161.result'
--- a/mysql-test/suite/falcon/r/falcon_bug_22161.result	2008-07-14 05:32:03 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bug_22161.result	2008-07-31 10:37:43 +0000
@@ -9,10 +9,6 @@ CREATE INDEX i1 ON t1 (a);
 ERROR 42000: BLOB column 'a' can't be used in key specification with the used table type
 ALTER TABLE t1 MODIFY COLUMN a varchar(30000);
 CREATE INDEX i1 ON t1 (a);
-Warnings:
-Warning	1071	Specified key was too long; max key length is 1100 bytes
-Warning	1071	Specified key was too long; max key length is 1100 bytes
-Warning	1071	Specified key was too long; max key length is 1100 bytes
 SELECT count(*) FROM t1;
 count(*)
 1

=== modified file 'mysql-test/suite/falcon/r/falcon_bug_31295.result'
--- a/mysql-test/suite/falcon/r/falcon_bug_31295.result	2008-04-15 17:29:36 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bug_31295.result	2008-07-29 10:45:39 +0000
@@ -1,22 +1,28 @@
 *** Bug #31295 ***
-SET @@storage_engine = 'Falcon';
+SET @@storage_engine = Falcon;
 DROP TABLE IF EXISTS t1;
-DROP TABLESPACE ts1 ENGINE 'Falcon';
-CREATE TABLESPACE ts1 ADD DATAFILE 'ts1.fts' ENGINE 'Falcon';
+DROP TABLESPACE ts1 ENGINE Falcon;
+CREATE TABLESPACE ts1 ADD DATAFILE 'ts1.fts' ENGINE Falcon;
 CREATE TABLE t1(a int);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1		FALCON_USER	T1
-ALTER TABLE t1 TABLESPACE ts1 ENGINE 'Falcon';
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1		ts1	T1
-ALTER TABLE t1 ENGINE 'Falcon';
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1		ts1	T1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=ENGINE DEFAULT CHARSET=latin1
+ALTER TABLE t1 TABLESPACE ts1 ENGINE Falcon;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=ENGINE DEFAULT CHARSET=latin1
+ALTER TABLE t1 ENGINE Falcon;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=ENGINE DEFAULT CHARSET=latin1
 SELECT count(*) FROM t1;
 count(*)
 0
 DROP TABLE t1;
-DROP TABLESPACE ts1 ENGINE 'Falcon';
+DROP TABLESPACE ts1 ENGINE Falcon;

=== modified file 'mysql-test/suite/falcon/r/falcon_bug_33404.result'
--- a/mysql-test/suite/falcon/r/falcon_bug_33404.result	2008-04-23 06:54:13 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bug_33404.result	2008-07-29 10:45:39 +0000
@@ -12,23 +12,17 @@ SUBPARTITION p2s1,
 SUBPARTITION p2s2
 )
 );
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P1S1	ts3	T1#P#P1#SP#P1S1
-TEST	T1	P1S2	ts2	T1#P#P1#SP#P1S2
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
   `a` int(11) DEFAULT NULL
 ) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1s1 TABLESPACE = ts3 ENGINE = Falcon, SUBPARTITION p1s2 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN MAXVALUE (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon)) */
 ALTER TABLE t1 REMOVE PARTITIONING;
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1		ts1	T1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1
 ALTER TABLE t1 TABLESPACE ts1
 PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (
 PARTITION p1 VALUES LESS THAN (100) TABLESPACE ts2 (
@@ -40,56 +34,38 @@ SUBPARTITION p2s1,
 SUBPARTITION p2s2
 )
 );
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P1S1	ts3	T1#P#P1#SP#P1S1
-TEST	T1	P1S2	ts2	T1#P#P1#SP#P1S2
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1s1 TABLESPACE = ts3 ENGINE = Falcon, SUBPARTITION p1s2 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN (200) (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon)) */
 ALTER TABLE t1 ADD PARTITION (PARTITION p3 VALUES LESS THAN MAXVALUE);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P1S1	ts3	T1#P#P1#SP#P1S1
-TEST	T1	P1S2	ts2	T1#P#P1#SP#P1S2
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
-TEST	T1	P3SP0	ts1	T1#P#P3#SP#P3SP0
-TEST	T1	P3SP1	ts1	T1#P#P3#SP#P3SP1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1s1 TABLESPACE = ts3 ENGINE = Falcon, SUBPARTITION p1s2 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN (200) (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon), PARTITION p3 VALUES LESS THAN MAXVALUE (SUBPARTITION p3sp0 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p3sp1 TABLESPACE = ts1 ENGINE = Falcon)) */
 ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
 MAXVALUE TABLESPACE ts1);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P1S1	ts3	T1#P#P1#SP#P1S1
-TEST	T1	P1S2	ts2	T1#P#P1#SP#P1S2
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
-TEST	T1	P3SP0	ts1	T1#P#P3#SP#P3SP0
-TEST	T1	P3SP1	ts1	T1#P#P3#SP#P3SP1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1s1 TABLESPACE = ts3 ENGINE = Falcon, SUBPARTITION p1s2 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN (200) (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon), PARTITION p3 VALUES LESS THAN MAXVALUE (SUBPARTITION p3sp0 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p3sp1 TABLESPACE = ts1 ENGINE = Falcon)) */
 ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
 MAXVALUE TABLESPACE ts2);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P1S1	ts3	T1#P#P1#SP#P1S1
-TEST	T1	P1S2	ts2	T1#P#P1#SP#P1S2
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
-TEST	T1	P3SP0	ts2	T1#P#P3#SP#P3SP0
-TEST	T1	P3SP1	ts2	T1#P#P3#SP#P3SP1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1s1 TABLESPACE = ts3 ENGINE = Falcon, SUBPARTITION p1s2 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN (200) (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon), PARTITION p3 VALUES LESS THAN MAXVALUE (SUBPARTITION p3sp0 TABLESPACE = ts2 ENGINE = Falcon, SUBPARTITION p3sp1 TABLESPACE = ts2 ENGINE = Falcon)) */
 ALTER TABLE t1 REORGANIZE PARTITION p1 INTO (PARTITION p1 VALUES LESS THAN
 (100) TABLESPACE ts2);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-TABLE_NAME = 't1' AND SCHEMA_NAME='test';
-SCHEMA_NAME	TABLE_NAME	PARTITION	TABLESPACE	INTERNAL_NAME
-TEST	T1	P2S1	ts1	T1#P#P2#SP#P2S1
-TEST	T1	P2S2	ts1	T1#P#P2#SP#P2S2
-TEST	T1	P3SP0	ts2	T1#P#P3#SP#P3SP0
-TEST	T1	P3SP1	ts2	T1#P#P3#SP#P3SP1
-TEST	T1	P1SP0	ts2	T1#P#P1#SP#P1SP0
-TEST	T1	P1SP1	ts2	T1#P#P1#SP#P1SP1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) /*!50100 TABLESPACE `ts1` */ ENGINE=Falcon DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p1 VALUES LESS THAN (100) (SUBPARTITION p1sp0 TABLESPACE = ts2 ENGINE = Falcon, SUBPARTITION p1sp1 TABLESPACE = ts2 ENGINE = Falcon), PARTITION p2 VALUES LESS THAN (200) (SUBPARTITION p2s1 TABLESPACE = ts1 ENGINE = Falcon, SUBPARTITION p2s2 TABLESPACE = ts1 ENGINE = Falcon), PARTITION p3 VALUES LESS THAN MAXVALUE (SUBPARTITION p3sp0 TABLESPACE = ts2 ENGINE = Falcon, SUBPARTITION p3sp1 TABLESPACE = ts2 ENGINE = Falcon)) */
 DROP TABLE t1;
 DROP TABLESPACE ts1 ENGINE=Falcon;
 DROP TABLESPACE ts2 ENGINE=Falcon;

=== added file 'mysql-test/suite/falcon/r/falcon_bug_35939.result'
--- a/mysql-test/suite/falcon/r/falcon_bug_35939.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bug_35939.result	2008-07-31 10:04:30 +0000
@@ -0,0 +1,61 @@
+*** Bug #35939 ***
+SET @@storage_engine = 'Falcon';
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(i int);
+INSERT INTO t1(i) VALUES (1),(2),(3),(4);
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+4
+UPDATE t1 set i=i+1;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+4
+DELETE FROM t1 WHERE i=2;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+SET AUTOCOMMIT=OFF;
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+DELETE FROM t1 WHERE i=42;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+BEGIN;
+DELETE FROM t1 WHERE i=4;
+INSERT INTO t1(i) VALUES(4);
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+UPDATE t1 SET i=43 WHERE i=42;
+DELETE FROM t1 WHERE i=43;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+BEGIN;
+DELETE FROM t1 WHERE i=4;
+INSERT INTO t1(i) VALUES(4);
+UPDATE t1 SET i=42 WHERE i=4;
+UPDATE t1 SET i=4 WHERE i=42;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+UPDATE t1 SET i=43 WHERE i=42;
+DELETE FROM t1 WHERE i=43;
+ROLLBACK;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_ROWS
+3
+SET AUTOCOMMIT=ON;
+SELECT count(*) FROM t1;
+count(*)
+3
+DROP TABLE t1;

=== added file 'mysql-test/suite/falcon/r/falcon_bug_38039.result'
--- a/mysql-test/suite/falcon/r/falcon_bug_38039.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/falcon/r/falcon_bug_38039.result	2008-07-16 12:40:47 +0000
@@ -0,0 +1,18 @@
+*** Bug #38039 ***
+SET @@storage_engine = 'Falcon';
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a_int INT) Engine = Falcon;
+ALTER TABLE t1 ADD KEY (a_int);
+SHOW INDEXES FROM t1;
+Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
+t1	1	a_int	1	a_int	NULL	1	NULL	NULL	YES	BTREE		
+ALTER TABLE t1 ADD KEY (a_int);
+SHOW INDEXES FROM t1;
+Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
+t1	1	a_int	1	a_int	NULL	1	NULL	NULL	YES	BTREE		
+t1	1	a_int_2	1	a_int	NULL	1	NULL	NULL	YES	BTREE		
+ALTER TABLE t1 DROP KEY a_int;
+SHOW INDEXES FROM t1;
+Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
+t1	1	a_int_2	1	a_int	NULL	1	NULL	NULL	YES	BTREE		
+DROP TABLE t1;

=== modified file 'mysql-test/suite/falcon/r/falcon_options.result'
--- a/mysql-test/suite/falcon/r/falcon_options.result	2008-07-10 19:00:14 +0000
+++ b/mysql-test/suite/falcon/r/falcon_options.result	2008-08-14 11:24:18 +0000
@@ -1,4 +1,4 @@
-SHOW VARIABLES LIKE 'falcon_%';
+SHOW VARIABLES where variable_name LIKE 'falcon_%' and variable_name <>'falcon_serial_log_dir';
 Variable_name	Value
 falcon_checkpoint_schedule	7 * * * * *
 falcon_checksums	ON
@@ -9,7 +9,6 @@ falcon_debug_trace	0
 falcon_direct_io	1
 falcon_gopher_threads	5
 falcon_index_chill_threshold	4194304
-falcon_initial_allocation	0
 falcon_io_threads	2
 falcon_large_blob_threshold	160000
 falcon_lock_wait_timeout	50
@@ -22,7 +21,6 @@ falcon_record_scavenge_threshold	67
 falcon_scavenge_schedule	15,45 * * * * *
 falcon_serial_log_block_size	0
 falcon_serial_log_buffers	20
-falcon_serial_log_dir	
 falcon_serial_log_file_size	10485760
 falcon_serial_log_priority	1
 falcon_support_xa	OFF
@@ -34,9 +32,6 @@ SELECT @@GLOBAL.falcon_debug_server;
 0
 SET GLOBAL falcon_debug_server = TRUE;
 ERROR HY000: Variable 'falcon_debug_server' is a read only variable
-SELECT @@GLOBAL.falcon_serial_log_dir;
-@@GLOBAL.falcon_serial_log_dir
-NULL
 SET GLOBAL falcon_serial_log_dir = '/foo';
 ERROR HY000: Variable 'falcon_serial_log_dir' is a read only variable
 SELECT @@GLOBAL.falcon_page_cache_size;
@@ -81,7 +76,7 @@ SELECT @@GLOBAL.falcon_record_chill_thre
 @@GLOBAL.falcon_record_chill_threshold
 1073741824
 SELECT * FROM INFORMATION_SCHEMA.global_variables
-WHERE variable_name LIKE 'falcon%';
+WHERE variable_name LIKE 'falcon%' and variable_name <> 'falcon_serial_log_dir';
 VARIABLE_NAME	VARIABLE_VALUE
 FALCON_CHECKPOINT_SCHEDULE	7 * * * * *
 FALCON_CHECKSUMS	ON
@@ -92,7 +87,6 @@ FALCON_DEBUG_TRACE	0
 FALCON_DIRECT_IO	1
 FALCON_GOPHER_THREADS	5
 FALCON_INDEX_CHILL_THRESHOLD	1073741824
-FALCON_INITIAL_ALLOCATION	0
 FALCON_IO_THREADS	2
 FALCON_LARGE_BLOB_THRESHOLD	160000
 FALCON_LOCK_WAIT_TIMEOUT	50
@@ -105,7 +99,6 @@ FALCON_RECORD_SCAVENGE_THRESHOLD	67
 FALCON_SCAVENGE_SCHEDULE	15,45 * * * * *
 FALCON_SERIAL_LOG_BLOCK_SIZE	0
 FALCON_SERIAL_LOG_BUFFERS	20
-FALCON_SERIAL_LOG_DIR	
 FALCON_SERIAL_LOG_FILE_SIZE	10485760
 FALCON_SERIAL_LOG_PRIORITY	1
 FALCON_SUPPORT_XA	OFF

=== modified file 'mysql-test/suite/falcon/r/falcon_options2.result'
--- a/mysql-test/suite/falcon/r/falcon_options2.result	2008-07-10 19:00:14 +0000
+++ b/mysql-test/suite/falcon/r/falcon_options2.result	2008-08-14 11:24:18 +0000
@@ -1,5 +1,5 @@
 SELECT * FROM INFORMATION_SCHEMA.global_variables
-WHERE variable_name LiKE 'falcon_%';
+WHERE variable_name LiKE 'falcon_%' AND variable_name <> 'falcon_serial_log_dir';
 VARIABLE_NAME	VARIABLE_VALUE
 FALCON_CHECKPOINT_SCHEDULE	7 * * * * *
 FALCON_CHECKSUMS	ON
@@ -10,7 +10,6 @@ FALCON_DEBUG_TRACE	0
 FALCON_DIRECT_IO	1
 FALCON_GOPHER_THREADS	5
 FALCON_INDEX_CHILL_THRESHOLD	4194304
-FALCON_INITIAL_ALLOCATION	0
 FALCON_IO_THREADS	2
 FALCON_LARGE_BLOB_THRESHOLD	160000
 FALCON_LOCK_WAIT_TIMEOUT	50
@@ -23,7 +22,6 @@ FALCON_RECORD_SCAVENGE_THRESHOLD	67
 FALCON_SCAVENGE_SCHEDULE	15,45 * * * * *
 FALCON_SERIAL_LOG_BLOCK_SIZE	0
 FALCON_SERIAL_LOG_BUFFERS	20
-FALCON_SERIAL_LOG_DIR	
 FALCON_SERIAL_LOG_FILE_SIZE	10485760
 FALCON_SERIAL_LOG_PRIORITY	1
 FALCON_SUPPORT_XA	OFF
@@ -54,9 +52,6 @@ SELECT @@falcon_gopher_threads;
 SELECT @@falcon_index_chill_threshold;
 @@falcon_index_chill_threshold
 4194304
-SELECT @@falcon_initial_allocation;
-@@falcon_initial_allocation
-0
 SELECT @@falcon_io_threads;
 @@falcon_io_threads
 2
@@ -93,9 +88,6 @@ SELECT @@falcon_serial_log_block_size;
 SELECT @@falcon_serial_log_buffers;
 @@falcon_serial_log_buffers
 20
-SELECT @@falcon_serial_log_dir;
-@@falcon_serial_log_dir
-NULL
 SELECT @@falcon_serial_log_priority;
 @@falcon_serial_log_priority
 1

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_22161.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_22161.test	2008-02-06 15:21:13 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_22161.test	2008-07-31 10:37:43 +0000
@@ -25,7 +25,9 @@ ALTER TABLE t1 MODIFY COLUMN a text;
 --error ER_BLOB_USED_AS_KEY
 CREATE INDEX i1 ON t1 (a);
 ALTER TABLE t1 MODIFY COLUMN a varchar(30000);
+--disable_warnings
 CREATE INDEX i1 ON t1 (a);
+--enable_warnings
 
 # ----------------------------------------------------- #
 # --- Check                                         --- #

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_22179.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_22179.test	2007-09-29 04:30:42 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_22179.test	2008-08-12 08:46:11 +0000
@@ -1,4 +1,5 @@
 --source include/have_falcon.inc
+--source include/have_ucs2.inc
 #
 # Bug #22179: UCS2 searches fail if index exists	
 #

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_22845.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_22845.test	2008-01-31 00:07:54 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_22845.test	2008-08-12 08:46:11 +0000
@@ -1,4 +1,5 @@
 --source include/have_falcon.inc
+--source include/have_partition.inc
 #
 # Bug #22845: Falcon: hang on partition drop
 #

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_23818_I.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_23818_I.test	2007-09-29 04:30:42 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_23818_I.test	2008-08-12 08:46:11 +0000
@@ -1,4 +1,5 @@
 --source include/have_falcon.inc
+--source include/have_ucs2.inc
 SET @@storage_engine = Falcon;
 #
 # Bug #23818 Falcon: crash with random updates of long varchar columns

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_24858.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_24858.test	2007-09-29 04:30:42 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_24858.test	2008-08-12 08:46:11 +0000
@@ -1,4 +1,5 @@
 --source include/have_falcon.inc
+--source include/have_ucs2.inc
 SET storage_engine = Falcon;
 #
 # Bug #24858: Falcon: searches fail if partial index on utf8 column

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_31295.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_31295.test	2008-04-15 17:29:36 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_31295.test	2008-07-29 10:45:39 +0000
@@ -8,7 +8,7 @@
 # ----------------------------------------------------- #
 # --- Initialisation                                --- #
 # ----------------------------------------------------- #
-let $engine = 'Falcon';
+let $engine = Falcon;
 eval SET @@storage_engine = $engine;
 
 --disable_warnings
@@ -23,12 +23,14 @@ CREATE TABLE t1(a int);
 # ----------------------------------------------------- #
 # --- Test                                          --- #
 # ----------------------------------------------------- #
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
+--replace_result $engine ENGINE
+SHOW CREATE TABLE t1;
 eval ALTER TABLE t1 TABLESPACE ts1 ENGINE $engine;
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
+--replace_result $engine ENGINE
+SHOW CREATE TABLE t1;
 eval ALTER TABLE t1 ENGINE $engine;
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE TABLE_NAME='t1';
-
+--replace_result $engine ENGINE
+SHOW CREATE TABLE t1;
 
 # ----------------------------------------------------- #
 # --- Check                                         --- #

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_33081.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_33081.test	2007-12-10 10:58:37 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_33081.test	2008-08-12 08:46:11 +0000
@@ -1,4 +1,5 @@
 --source include/have_falcon.inc
+--source include/have_ucs2.inc
 #
 # Bug #33081: Falcon: crash and database corruption when altering indexed ucs2 column
 #

=== modified file 'mysql-test/suite/falcon/t/falcon_bug_33404.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_33404.test	2008-04-23 06:54:13 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_33404.test	2008-07-29 10:45:39 +0000
@@ -19,13 +19,10 @@ PARTITION BY RANGE(a) SUBPARTITION BY HA
     SUBPARTITION p2s2
   )
 );
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
 SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 REMOVE PARTITIONING;
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 TABLESPACE ts1
 PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (
@@ -38,27 +35,22 @@ PARTITION BY RANGE(a) SUBPARTITION BY HA
     SUBPARTITION p2s2
   )
 );
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 ADD PARTITION (PARTITION p3 VALUES LESS THAN MAXVALUE);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
 MAXVALUE TABLESPACE ts1);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
 MAXVALUE TABLESPACE ts2);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 ALTER TABLE t1 REORGANIZE PARTITION p1 INTO (PARTITION p1 VALUES LESS THAN
 (100) TABLESPACE ts2);
-SELECT * FROM INFORMATION_SCHEMA.FALCON_TABLES WHERE
-  TABLE_NAME = 't1' AND SCHEMA_NAME='test';
+SHOW CREATE TABLE t1;
 
 DROP TABLE t1;
 DROP TABLESPACE ts1 ENGINE=Falcon;

=== added file 'mysql-test/suite/falcon/t/falcon_bug_35939.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_35939.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_35939.test	2008-07-31 10:04:30 +0000
@@ -0,0 +1,86 @@
+--source include/have_falcon.inc
+
+#
+# Bug #35939: Drift in Falcon row count reported by SHOW TABLE STATUS
+#
+--echo *** Bug #35939 ***
+
+# ----------------------------------------------------- #
+# --- Initialisation                                --- #
+# ----------------------------------------------------- #
+let $engine = 'Falcon';
+eval SET @@storage_engine = $engine;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+# ----------------------------------------------------- #
+# --- Test                                          --- #
+# ----------------------------------------------------- #
+CREATE TABLE t1(i int);
+INSERT INTO t1(i) VALUES (1),(2),(3),(4);
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Expect 4 rows
+UPDATE t1 set i=i+1;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Expect 4 rows, nothing added or deleted
+DELETE FROM t1 WHERE i=2;
+# One row deleted, expect count=3
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+
+# insert/delete on the same row, count does not change
+SET AUTOCOMMIT=OFF;
+# Next tests are transactional
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+DELETE FROM t1 WHERE i=42;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Count should not be changed,count=3
+
+#delete/insert, count does not change
+BEGIN;
+DELETE FROM t1 WHERE i=4;
+INSERT INTO t1(i) VALUES(4);
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Count should not be changed,count=3
+
+# insert/update/delete on the same row, count does not change
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+UPDATE t1 SET i=43 WHERE i=42;
+DELETE FROM t1 WHERE i=43;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Count should not be changed,count=3
+
+#delete/insert/update/update, count does not change
+BEGIN;
+DELETE FROM t1 WHERE i=4;
+INSERT INTO t1(i) VALUES(4);
+UPDATE t1 SET i=42 WHERE i=4;
+UPDATE t1 SET i=4 WHERE i=42;
+COMMIT;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+# Count should not be changed,count=3
+
+# same as before, but with rollback
+BEGIN;
+INSERT INTO t1(i) VALUES(42);
+UPDATE t1 SET i=43 WHERE i=42;
+DELETE FROM t1 WHERE i=43;
+ROLLBACK;
+SELECT TABLE_ROWS  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+SET AUTOCOMMIT=ON;
+
+# ----------------------------------------------------- #
+# --- Check                                         --- #
+# ----------------------------------------------------- #
+SELECT count(*) FROM t1;
+
+# ----------------------------------------------------- #
+# --- Final cleanup                                 --- #
+# ----------------------------------------------------- #
+DROP TABLE t1;

=== added file 'mysql-test/suite/falcon/t/falcon_bug_38039.test'
--- a/mysql-test/suite/falcon/t/falcon_bug_38039.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bug_38039.test	2008-07-16 12:40:47 +0000
@@ -0,0 +1,43 @@
+--source include/have_falcon.inc
+
+#
+# Bug #38039: Assertion lockState == 0 failed in StorageTableShare::deleteTable SyncObject
+#
+
+--echo *** Bug #38039 ***
+
+# ----------------------------------------------------- #
+# --- Initialisation                                --- #
+# ----------------------------------------------------- #
+let $engine = 'Falcon';
+eval SET @@storage_engine = $engine;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (a_int INT) Engine = Falcon;
+
+# ----------------------------------------------------- #
+# --- Test                                          --- #
+# ----------------------------------------------------- #
+
+## SHOW INDEXES is not required to reproduce the bug, but
+## is included here to verify correct behavior.
+
+ALTER TABLE t1 ADD KEY (a_int);
+SHOW INDEXES FROM t1;
+
+ALTER TABLE t1 ADD KEY (a_int);
+SHOW INDEXES FROM t1;
+
+ALTER TABLE t1 DROP KEY a_int;
+SHOW INDEXES FROM t1;
+
+DROP TABLE t1;
+
+# ----------------------------------------------------- #
+# --- Final cleanup                                 --- #
+# ----------------------------------------------------- #
+
+## None, DROP TABLE is part of the test.

=== modified file 'mysql-test/suite/falcon/t/falcon_bugs2.test'
--- a/mysql-test/suite/falcon/t/falcon_bugs2.test	2007-10-05 12:21:31 +0000
+++ b/mysql-test/suite/falcon/t/falcon_bugs2.test	2008-08-12 08:46:11 +0000
@@ -4,6 +4,7 @@ DROP TABLE IF EXISTS t2;
 --enable_warnings
 
 --source include/have_falcon.inc
+--source include/have_ucs2.inc
 SET storage_engine=falcon;
 
 # Verify that setting storage engine worked

=== modified file 'mysql-test/suite/falcon/t/falcon_options.test'
--- a/mysql-test/suite/falcon/t/falcon_options.test	2008-07-03 11:24:12 +0000
+++ b/mysql-test/suite/falcon/t/falcon_options.test	2008-08-14 11:24:18 +0000
@@ -1,8 +1,6 @@
 --source include/have_falcon.inc
 
-SHOW VARIABLES LIKE 'falcon_%';
-
---real_sleep 1
+SHOW VARIABLES where variable_name LIKE 'falcon_%' and variable_name <>'falcon_serial_log_dir';
 
 # Test that these server variables are READ ONLY.
 
@@ -10,7 +8,6 @@ SELECT @@GLOBAL.falcon_debug_server;
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SET GLOBAL falcon_debug_server = TRUE;
 
-SELECT @@GLOBAL.falcon_serial_log_dir;
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SET GLOBAL falcon_serial_log_dir = '/foo';
 
@@ -49,7 +46,7 @@ SELECT @@GLOBAL.falcon_record_chill_thre
 # Test INFORMATION_SCHEMA access to variables.
 --sorted_result
 SELECT * FROM INFORMATION_SCHEMA.global_variables
-  WHERE variable_name LIKE 'falcon%';
+  WHERE variable_name LIKE 'falcon%' and variable_name <> 'falcon_serial_log_dir';
 
 # Final cleanup.
 SET GLOBAL falcon_debug_mask = @previous_falcon_debug_mask;

=== modified file 'mysql-test/suite/falcon/t/falcon_options2.test'
--- a/mysql-test/suite/falcon/t/falcon_options2.test	2008-07-10 19:00:14 +0000
+++ b/mysql-test/suite/falcon/t/falcon_options2.test	2008-08-14 11:24:18 +0000
@@ -4,7 +4,7 @@
 
 --sorted_result
 SELECT * FROM INFORMATION_SCHEMA.global_variables
-         WHERE variable_name LiKE 'falcon_%';
+         WHERE variable_name LiKE 'falcon_%' AND variable_name <> 'falcon_serial_log_dir';
 
 SELECT @@falcon_checkpoint_schedule;
 SELECT @@falcon_consistent_read;
@@ -14,7 +14,6 @@ SELECT @@falcon_debug_trace;
 SELECT @@falcon_direct_io;
 SELECT @@falcon_gopher_threads;
 SELECT @@falcon_index_chill_threshold;
-SELECT @@falcon_initial_allocation;
 SELECT @@falcon_io_threads;
 SELECT @@falcon_large_blob_threshold;
 SELECT @@falcon_lock_wait_timeout;
@@ -27,7 +26,6 @@ SELECT @@falcon_record_scavenge_threshol
 SELECT @@falcon_scavenge_schedule;
 SELECT @@falcon_serial_log_block_size;
 SELECT @@falcon_serial_log_buffers;
-SELECT @@falcon_serial_log_dir;
 SELECT @@falcon_serial_log_priority;
 SELECT @@falcon_use_deferred_index_hash;
 SELECT @@falcon_use_sectorcache;

=== modified file 'mysql-test/suite/falcon_team/r/falcon_bug_22165.result'
--- a/mysql-test/suite/falcon_team/r/falcon_bug_22165.result	2008-04-20 00:05:17 +0000
+++ b/mysql-test/suite/falcon_team/r/falcon_bug_22165.result	2008-08-27 12:49:58 +0000
@@ -1,11 +1,8 @@
 *** Bug #22165 ***
 SET @@storage_engine = 'Falcon';
-DROP PROCEDURE IF EXISTS db1.p1;
-DROP EVENT IF EXISTS db1.e1;
-DROP EVENT IF EXISTS db1.e2;
-DROP DATABASE IF EXISTS db1;
-CREATE DATABASE db1;
-USE db1;
+DROP TABLE IF EXISTS t1;
+DROP PROCEDURE IF EXISTS p1;
+CREATE TABLE t1 (a bigint, b varchar(1000), c timestamp);
 CREATE PROCEDURE p1 ()
 begin
 declare v int default 0;
@@ -23,13 +20,5 @@ COMMIT;
 SET v = v + 1;
 end while;
 end//
-CREATE TABLE t1 (a bigint, b varchar(1000), c timestamp);
-CREATE EVENT e1 ON SCHEDULE EVERY 1 second DO CALL db1.p1();
-CREATE EVENT e2 ON SCHEDULE EVERY 1 second DO CALL db1.p1();
-SET GLOBAL event_scheduler = 1;
-SET GLOBAL event_scheduler = 0;
-USE test;
-DROP EVENT db1.e1;
-DROP EVENT db1.e2;
-DROP PROCEDURE db1.p1;
-DROP DATABASE db1;
+DROP PROCEDURE p1;
+DROP TABLE t1;

=== modified file 'mysql-test/suite/falcon_team/r/falcon_bug_22173a.result'
--- a/mysql-test/suite/falcon_team/r/falcon_bug_22173a.result	2008-07-22 14:16:22 +0000
+++ b/mysql-test/suite/falcon_team/r/falcon_bug_22173a.result	2008-08-27 12:49:58 +0000
@@ -12,6 +12,7 @@ begin declare v1 int default 0;
 declare v2 int;
 declare continue handler for 1020 begin end;
 declare continue handler for 1213 begin end;
+declare continue handler for 1015 begin end;
 while v1 < 2500 do
 /* SELECT 'insert', v1; */
 INSERT INTO t1 VALUES (v1);

=== modified file 'mysql-test/suite/falcon_team/r/falcon_bug_23962.result'
--- a/mysql-test/suite/falcon_team/r/falcon_bug_23962.result	2008-04-20 00:05:17 +0000
+++ b/mysql-test/suite/falcon_team/r/falcon_bug_23962.result	2008-08-27 12:49:58 +0000
@@ -1,5 +1,5 @@
-SET STORAGE_ENGINE = Falcon;
 *** Bug #23962 ***
+SET @@storage_engine = 'Falcon';
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (a char(5), KEY (a));
 INSERT INTO t1 VALUES ('a'), ('aa'), ('aaa'), ('abc'), ('bbb');
@@ -14,4 +14,7 @@ a
 aaa
 abc
 bbb
+SELECT count(*) FROM t1;
+count(*)
+5
 DROP TABLE t1;

=== modified file 'mysql-test/suite/falcon_team/r/falcon_bug_37080.result'
--- a/mysql-test/suite/falcon_team/r/falcon_bug_37080.result	2008-07-03 08:46:37 +0000
+++ b/mysql-test/suite/falcon_team/r/falcon_bug_37080.result	2008-08-27 12:49:58 +0000
@@ -1,5 +1,5 @@
 *** Bug #37080 ***
 SET @@storage_engine = 'Falcon';
-DROP TABLE IF EXISTS t;
-CREATE TABLE t(i int);
-DROP TABLE t;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(a int);
+DROP TABLE t1;

=== modified file 'mysql-test/suite/falcon_team/t/falcon_bug_22165.test'
--- a/mysql-test/suite/falcon_team/t/falcon_bug_22165.test	2008-04-20 00:05:17 +0000
+++ b/mysql-test/suite/falcon_team/t/falcon_bug_22165.test	2008-08-27 12:49:58 +0000
@@ -11,14 +11,11 @@ let $engine = 'Falcon';
 eval SET @@storage_engine = $engine;
 
 --disable_warnings
-DROP PROCEDURE IF EXISTS db1.p1;
-DROP EVENT IF EXISTS db1.e1;
-DROP EVENT IF EXISTS db1.e2;
-DROP DATABASE IF EXISTS db1;
+DROP TABLE IF EXISTS t1;
+DROP PROCEDURE IF EXISTS p1;
 --enable_warnings
+CREATE TABLE t1 (a bigint, b varchar(1000), c timestamp);
 
-CREATE DATABASE db1;
-USE db1;
 delimiter //;
 CREATE PROCEDURE p1 ()
 begin
@@ -39,18 +36,31 @@ begin
 end//
 delimiter ;//
 
-CREATE TABLE t1 (a bigint, b varchar(1000), c timestamp);
+connect (conn1,localhost,root,,);
+connect (conn2,localhost,root,,);
+
 
-CREATE EVENT e1 ON SCHEDULE EVERY 1 second DO CALL db1.p1();
-CREATE EVENT e2 ON SCHEDULE EVERY 1 second DO CALL db1.p1();
 
 # ----------------------------------------------------- #
 # --- Test                                          --- #
 # ----------------------------------------------------- #
-SET GLOBAL event_scheduler = 1;
---sleep 60
-SET GLOBAL event_scheduler = 0;
-
+--disable_query_log
+let $i=150;
+while ($i)
+{
+  connection conn1;
+  --send call p1();
+  connection conn2;
+  --send call p1();
+  
+  connection conn1;
+  --reap
+  connection conn2;
+  --reap
+  
+  dec $i;
+}
+--enable_query_log
 # ----------------------------------------------------- #
 # --- Check                                         --- #
 # ----------------------------------------------------- #
@@ -60,8 +70,9 @@ SET GLOBAL event_scheduler = 0;
 # ----------------------------------------------------- #
 # --- Final cleanup                                 --- #
 # ----------------------------------------------------- #
-USE test;
-DROP EVENT db1.e1;
-DROP EVENT db1.e2;
-DROP PROCEDURE db1.p1;
-DROP DATABASE db1;
+connection default;
+disconnect conn1;
+disconnect conn2;
+DROP PROCEDURE p1;
+DROP TABLE t1;
+

=== modified file 'mysql-test/suite/falcon_team/t/falcon_bug_22173a.test'
--- a/mysql-test/suite/falcon_team/t/falcon_bug_22173a.test	2008-07-22 14:16:22 +0000
+++ b/mysql-test/suite/falcon_team/t/falcon_bug_22173a.test	2008-08-27 12:49:58 +0000
@@ -31,6 +31,7 @@ begin declare v1 int default 0;
 declare v2 int;
 declare continue handler for 1020 begin end;
 declare continue handler for 1213 begin end;
+declare continue handler for 1015 begin end;
 while v1 < 2500 do
   /* SELECT 'insert', v1; */
   INSERT INTO t1 VALUES (v1);
@@ -52,7 +53,6 @@ delimiter ;//
 
 --echo # Switch to connection conn1
 connection conn1;
---real_sleep 1
 call p1();
 
 --echo # Switch to connection default

=== modified file 'mysql-test/suite/falcon_team/t/falcon_bug_23962.test'
--- a/mysql-test/suite/falcon_team/t/falcon_bug_23962.test	2008-04-20 00:05:17 +0000
+++ b/mysql-test/suite/falcon_team/t/falcon_bug_23962.test	2008-08-27 12:49:58 +0000
@@ -1,9 +1,16 @@
 --source include/have_falcon.inc
-SET STORAGE_ENGINE = Falcon;
+
 #
 # Bug #23962: Wrong results with > search
 #
 --echo *** Bug #23962 ***
+
+# ----------------------------------------------------- #
+# --- Initialisation                                --- #
+# ----------------------------------------------------- #
+let $engine = 'Falcon';
+eval SET @@storage_engine = $engine;
+
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings
@@ -11,8 +18,18 @@ DROP TABLE IF EXISTS t1;
 CREATE TABLE t1 (a char(5), KEY (a));
 INSERT INTO t1 VALUES ('a'), ('aa'), ('aaa'), ('abc'), ('bbb');
 
+# ----------------------------------------------------- #
+# --- Test                                          --- #
+# ----------------------------------------------------- #
 SELECT * FROM t1 WHERE a > 'a'  ORDER BY a;
 SELECT * FROM t1 WHERE a > 'aa' ORDER BY a;
 
-# Final cleanup.
+# ----------------------------------------------------- #
+# --- Check                                         --- #
+# ----------------------------------------------------- #
+SELECT count(*) FROM t1;
+
+# ----------------------------------------------------- #
+# --- Final cleanup                                 --- #
+# ----------------------------------------------------- #
 DROP TABLE t1;

=== modified file 'mysql-test/suite/falcon_team/t/falcon_bug_37080.test'
--- a/mysql-test/suite/falcon_team/t/falcon_bug_37080.test	2008-07-03 08:46:37 +0000
+++ b/mysql-test/suite/falcon_team/t/falcon_bug_37080.test	2008-08-27 12:49:58 +0000
@@ -1,48 +1,50 @@
---source include/have_falcon.inc
-#
-# Bug#37080: Falcon deadlock on parallel TRUNCATE  and INSERT
-# 
---echo *** Bug #37080 ***
-
-# ----------------------------------------------------- #
-# --- Initialisation                                --- #
-# ----------------------------------------------------- #
-let $engine = 'Falcon';
-eval SET @@storage_engine = $engine;
-
---disable_warnings
-DROP TABLE IF EXISTS t;
---enable_warnings
-
-
-CREATE TABLE t(i int);
-connect (conn1,localhost,root,,);
-# ----------------------------------------------------- #
-# --- Test                                          --- #
-# ----------------------------------------------------- #
-
-
-let $num=10000;
---disable_query_log
-while ($num)
-{
-   connection conn1;
-   --send insert into t values(1);
-   connection default;
-   --send truncate table t;
-   connection conn1;
-   --reap
-   connection default;
-   --reap 
-   dec $num;
-}
---enable_query_log
-
-# ----------------------------------------------------- #
-# --- Check                                         --- #
-# ----------------------------------------------------- #
-
-# ----------------------------------------------------- #
-# --- Final cleanup                                 --- #
-# ----------------------------------------------------- #
-DROP TABLE t;
+--source include/have_falcon.inc
+
+#
+# Bug#37080: Falcon deadlock on parallel TRUNCATE  and INSERT
+#
+--echo *** Bug #37080 ***
+
+# ----------------------------------------------------- #
+# --- Initialisation                                --- #
+# ----------------------------------------------------- #
+let $engine = 'Falcon';
+eval SET @@storage_engine = $engine;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a int);
+connect (conn1,localhost,root,,);
+
+# ----------------------------------------------------- #
+# --- Test                                          --- #
+# ----------------------------------------------------- #
+
+let $num=1000;
+--disable_query_log
+while ($num)
+{
+   connection conn1;
+   --send insert into t1 values(1), (3), (5), (7) , (11);
+   connection default;
+   --send truncate table t1;
+   connection conn1;
+   --error 0,ER_CANT_LOCK
+   --reap
+   connection default;
+   --error 0,ER_CANT_LOCK
+   --reap 
+   dec $num;
+}
+--enable_query_log
+
+# ----------------------------------------------------- #
+# --- Check                                         --- #
+# ----------------------------------------------------- #
+
+# ----------------------------------------------------- #
+# --- Final cleanup                                 --- #
+# ----------------------------------------------------- #
+DROP TABLE t1;

=== modified file 'mysql-test/suite/funcs_1/r/falcon_storedproc.result'
--- a/mysql-test/suite/funcs_1/r/falcon_storedproc.result	2008-07-08 18:40:32 +0000
+++ b/mysql-test/suite/funcs_1/r/falcon_storedproc.result	2008-08-07 13:38:29 +0000
@@ -21942,9 +21942,9 @@ END	latin1	latin1_swedish_ci	latin1_swed
 set @@sql_mode='';
 CALL sp4();
 Level	Code	Message
-Error	1365	Division by 0
+Warning	1365	Division by 0
 Warnings:
-Error	1365	Division by 0
+Warning	1365	Division by 0
 DROP PROCEDURE sp4;
 set @@sql_mode='';
 

=== modified file 'mysql-test/suite/funcs_1/r/falcon_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/falcon_trig_03.result	2008-06-03 12:10:33 +0000
+++ b/mysql-test/suite/funcs_1/r/falcon_trig_03.result	2008-08-07 13:38:29 +0000
@@ -77,7 +77,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke TRIGGER on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER on *.* to test_yesprivs@localhost;
 grant SELECT on priv_db.t1 to test_yesprivs@localhost;
@@ -155,7 +155,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke UPDATE  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -169,7 +169,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 select f1 from t1 order by f1;
 f1
 insert 3.5.3.2-no
@@ -401,7 +401,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke SELECT  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -415,7 +415,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 create trigger trg5a_1 before INSERT on t1 for each row
 set @test_var = new.f1;
 set @test_var = 'before trig 3.5.3.8-1a';

=== modified file 'mysql-test/suite/funcs_1/r/falcon_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/falcon_trig_03e.result	2008-04-01 21:01:02 +0000
+++ b/mysql-test/suite/funcs_1/r/falcon_trig_03e.result	2008-08-07 13:38:29 +0000
@@ -562,7 +562,7 @@ trig 1_1-yes
 revoke TRIGGER on *.* from test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
@@ -609,7 +609,7 @@ root@localhost
 grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
 trigger privilege on db level for create:

=== modified file 'mysql-test/suite/funcs_1/r/innodb_storedproc.result'
--- a/mysql-test/suite/funcs_1/r/innodb_storedproc.result	2008-07-08 18:40:32 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_storedproc.result	2008-08-07 13:38:29 +0000
@@ -21942,9 +21942,9 @@ END	latin1	latin1_swedish_ci	latin1_swed
 set @@sql_mode='';
 CALL sp4();
 Level	Code	Message
-Error	1365	Division by 0
+Warning	1365	Division by 0
 Warnings:
-Error	1365	Division by 0
+Warning	1365	Division by 0
 DROP PROCEDURE sp4;
 set @@sql_mode='';
 

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_03.result	2008-06-03 10:21:48 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_03.result	2008-08-07 13:38:29 +0000
@@ -77,7 +77,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke TRIGGER on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER on *.* to test_yesprivs@localhost;
 grant SELECT on priv_db.t1 to test_yesprivs@localhost;
@@ -155,7 +155,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke UPDATE  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -169,7 +169,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 select f1 from t1 order by f1;
 f1
 insert 3.5.3.2-no
@@ -401,7 +401,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke SELECT  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -415,7 +415,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 create trigger trg5a_1 before INSERT on t1 for each row
 set @test_var = new.f1;
 set @test_var = 'before trig 3.5.3.8-1a';

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_03e.result	2008-04-30 16:16:45 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_03e.result	2008-08-07 13:38:29 +0000
@@ -562,7 +562,7 @@ trig 1_1-yes
 revoke TRIGGER on *.* from test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
@@ -609,7 +609,7 @@ root@localhost
 grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
 trigger privilege on db level for create:

=== modified file 'mysql-test/suite/funcs_1/r/is_columns_is_falcon.result'
--- a/mysql-test/suite/funcs_1/r/is_columns_is_falcon.result	2008-04-28 20:09:51 +0000
+++ b/mysql-test/suite/funcs_1/r/is_columns_is_falcon.result	2008-07-29 10:45:39 +0000
@@ -36,11 +36,6 @@ NULL	information_schema	FALCON_SYSTEM_ME
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	SMALL_HUNKS	5	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(4)			select		Default	Default
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	TOTAL_SPACE	1	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(4)			select		Default	Default
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	UNIQUE_SIZES	6	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(4)			select		Default	Default
-NULL	information_schema	FALCON_TABLES	INTERNAL_NAME	5		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
-NULL	information_schema	FALCON_TABLES	PARTITION	3		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
-NULL	information_schema	FALCON_TABLES	SCHEMA_NAME	1		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
-NULL	information_schema	FALCON_TABLES	TABLESPACE	4		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
-NULL	information_schema	FALCON_TABLES	TABLE_NAME	2		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
 NULL	information_schema	FALCON_TABLESPACES	COMMENT	3		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
 NULL	information_schema	FALCON_TABLESPACES	TABLESPACE_NAME	1		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
 NULL	information_schema	FALCON_TABLESPACES	TYPE	2		NO	varchar	127	508	NULL	NULL	utf8	utf8_general_ci	varchar(127)			select		Default	Default
@@ -161,11 +156,6 @@ NULL	information_schema	FALCON_SYSTEM_ME
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	BIG_HUNKS	int	NULL	NULL	NULL	NULL	int(4)
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	SMALL_HUNKS	int	NULL	NULL	NULL	NULL	int(4)
 NULL	information_schema	FALCON_SYSTEM_MEMORY_SUMMARY	UNIQUE_SIZES	int	NULL	NULL	NULL	NULL	int(4)
-4.0000	information_schema	FALCON_TABLES	SCHEMA_NAME	varchar	127	508	utf8	utf8_general_ci	varchar(127)
-4.0000	information_schema	FALCON_TABLES	TABLE_NAME	varchar	127	508	utf8	utf8_general_ci	varchar(127)
-4.0000	information_schema	FALCON_TABLES	PARTITION	varchar	127	508	utf8	utf8_general_ci	varchar(127)
-4.0000	information_schema	FALCON_TABLES	TABLESPACE	varchar	127	508	utf8	utf8_general_ci	varchar(127)
-4.0000	information_schema	FALCON_TABLES	INTERNAL_NAME	varchar	127	508	utf8	utf8_general_ci	varchar(127)
 4.0000	information_schema	FALCON_TABLESPACES	TABLESPACE_NAME	varchar	127	508	utf8	utf8_general_ci	varchar(127)
 4.0000	information_schema	FALCON_TABLESPACES	TYPE	varchar	127	508	utf8	utf8_general_ci	varchar(127)
 4.0000	information_schema	FALCON_TABLESPACES	COMMENT	varchar	127	508	utf8	utf8_general_ci	varchar(127)

=== modified file 'mysql-test/suite/funcs_1/r/is_columns_mysql.result'
--- a/mysql-test/suite/funcs_1/r/is_columns_mysql.result	2008-07-10 09:49:53 +0000
+++ b/mysql-test/suite/funcs_1/r/is_columns_mysql.result	2008-08-22 13:21:31 +0000
@@ -107,28 +107,28 @@ NULL	mysql	ndb_binlog_index	orig_server_
 NULL	mysql	ndb_binlog_index	Position	1	NULL	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(20) unsigned			select,insert,update,references		Default	Default
 NULL	mysql	ndb_binlog_index	schemaops	7	NULL	NO	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references		Default	Default
 NULL	mysql	ndb_binlog_index	updates	5	NULL	NO	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references		Default	Default
-NULL	mysql	online_backup	backup_file	15	NULL	YES	char	100	100	NULL	NULL	latin1	latin1_swedish_ci	char(100)			select,insert,update,references	The name of the file	Default	Default
+NULL	mysql	online_backup	backup_file	15	NULL	YES	char	100	400	NULL	NULL	utf8	utf8_general_ci	char(100)			select,insert,update,references	The name of the file	Default	Default
 NULL	mysql	online_backup	backup_id	1	NULL	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(20) unsigned	PRI	auto_increment	select,insert,update,references	Surrogate key for (near) duplicate entries	Default	Default
-NULL	mysql	online_backup	backup_state	5	NULL	NO	enum	14	14	NULL	NULL	latin1	latin1_swedish_ci	enum('complete','starting','validity point','running','error','cancel')			select,insert,update,references	Status of current operation	Default	Default
-NULL	mysql	online_backup	binlog_file	4	NULL	YES	char	64	64	NULL	NULL	latin1	latin1_swedish_ci	char(64)			select,insert,update,references	The recorded binlog filename at time of backup/restore	Default	Default
+NULL	mysql	online_backup	backup_state	5	NULL	NO	enum	14	56	NULL	NULL	utf8	utf8_general_ci	enum('complete','starting','validity point','running','error','cancel')			select,insert,update,references	Status of current operation	Default	Default
+NULL	mysql	online_backup	binlog_file	4	NULL	YES	char	64	256	NULL	NULL	utf8	utf8_general_ci	char(64)			select,insert,update,references	The recorded binlog filename at time of backup/restore	Default	Default
 NULL	mysql	online_backup	binlog_pos	3	0	YES	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references	The recorded binlog position of backup/restore	Default	Default
-NULL	mysql	online_backup	command	17	NULL	YES	varchar	512	512	NULL	NULL	latin1	latin1_swedish_ci	varchar(512)			select,insert,update,references	The command used to issue operation	Default	Default
-NULL	mysql	online_backup	drivers	18	NULL	YES	varchar	100	100	NULL	NULL	latin1	latin1_swedish_ci	varchar(100)			select,insert,update,references	The name of the storage engine backup drivers used in the operation	Default	Default
+NULL	mysql	online_backup	command	17	NULL	YES	varchar	512	2048	NULL	NULL	utf8	utf8_general_ci	varchar(512)			select,insert,update,references	The command used to issue operation	Default	Default
+NULL	mysql	online_backup	drivers	18	NULL	YES	varchar	100	400	NULL	NULL	utf8	utf8_general_ci	varchar(100)			select,insert,update,references	The name of the storage engine backup drivers used in the operation	Default	Default
 NULL	mysql	online_backup	error_num	7	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11)			select,insert,update,references	The error from this run 0 == none	Default	Default
-NULL	mysql	online_backup	host_or_server_name	13	NULL	YES	char	30	30	NULL	NULL	latin1	latin1_swedish_ci	char(30)			select,insert,update,references	The server name where operation ran	Default	Default
+NULL	mysql	online_backup	host_or_server_name	13	NULL	YES	char	30	120	NULL	NULL	utf8	utf8_general_ci	char(30)			select,insert,update,references	The server name where operation ran	Default	Default
 NULL	mysql	online_backup	num_objects	8	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references	The number of objects in the backup	Default	Default
-NULL	mysql	online_backup	operation	6	NULL	NO	enum	7	7	NULL	NULL	latin1	latin1_swedish_ci	enum('backup','restore')			select,insert,update,references	Type of operation	Default	Default
+NULL	mysql	online_backup	operation	6	NULL	NO	enum	7	28	NULL	NULL	utf8	utf8_general_ci	enum('backup','restore')			select,insert,update,references	Type of operation	Default	Default
 NULL	mysql	online_backup	process_id	2	NULL	NO	int	NULL	NULL	10	0	NULL	NULL	int(10) unsigned			select,insert,update,references	The process id that operation ran as	Default	Default
 NULL	mysql	online_backup	start_time	11	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select,insert,update,references	The date/time of start of operation	Default	Default
 NULL	mysql	online_backup	stop_time	12	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select,insert,update,references	The date/time of end of operation	Default	Default
 NULL	mysql	online_backup	total_bytes	9	NULL	YES	bigint	NULL	NULL	19	0	NULL	NULL	bigint(20) unsigned			select,insert,update,references	The size of the backup repository in bytes	Default	Default
-NULL	mysql	online_backup	username	14	NULL	YES	char	30	30	NULL	NULL	latin1	latin1_swedish_ci	char(30)			select,insert,update,references	The user name who ran the operation	Default	Default
-NULL	mysql	online_backup	user_comment	16	NULL	YES	varchar	200	200	NULL	NULL	latin1	latin1_swedish_ci	varchar(200)			select,insert,update,references	The comment from user entered at command line	Default	Default
+NULL	mysql	online_backup	username	14	NULL	YES	char	30	120	NULL	NULL	utf8	utf8_general_ci	char(30)			select,insert,update,references	The user name who ran the operation	Default	Default
+NULL	mysql	online_backup	user_comment	16	NULL	YES	varchar	200	800	NULL	NULL	utf8	utf8_general_ci	varchar(200)			select,insert,update,references	The comment from user entered at command line	Default	Default
 NULL	mysql	online_backup	validity_point_time	10	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select,insert,update,references	The time of the validity point.	Default	Default
 NULL	mysql	online_backup_progress	backup_id	1	NULL	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(20) unsigned			select,insert,update,references	Key for online_backup table entries	Default	Default
 NULL	mysql	online_backup_progress	error_num	7	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11)			select,insert,update,references	The error from this run 0 == none	Default	Default
-NULL	mysql	online_backup_progress	notes	8	NULL	YES	char	100	100	NULL	NULL	latin1	latin1_swedish_ci	char(100)			select,insert,update,references	Commentary from the backup engine	Default	Default
-NULL	mysql	online_backup_progress	object	2	NULL	NO	char	30	30	NULL	NULL	latin1	latin1_swedish_ci	char(30)			select,insert,update,references	The object being operated on	Default	Default
+NULL	mysql	online_backup_progress	notes	8	NULL	YES	char	100	400	NULL	NULL	utf8	utf8_general_ci	char(100)			select,insert,update,references	Commentary from the backup engine	Default	Default
+NULL	mysql	online_backup_progress	object	2	NULL	NO	char	30	120	NULL	NULL	utf8	utf8_general_ci	char(30)			select,insert,update,references	The object being operated on	Default	Default
 NULL	mysql	online_backup_progress	progress	6	NULL	YES	bigint	NULL	NULL	19	0	NULL	NULL	bigint(20) unsigned			select,insert,update,references	The number of bytes processed	Default	Default
 NULL	mysql	online_backup_progress	start_time	3	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select,insert,update,references	The date/time of start of operation	Default	Default
 NULL	mysql	online_backup_progress	stop_time	4	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select,insert,update,references	The date/time of end of operation	Default	Default
@@ -209,6 +209,7 @@ NULL	mysql	user	Alter_priv	17	N	NO	enum	
 NULL	mysql	user	Alter_routine_priv	28	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Create_priv	8	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Create_routine_priv	27	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
+NULL	mysql	user	Create_tablespace_priv	32	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Create_tmp_table_priv	20	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Create_user_priv	29	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Create_view_priv	25	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
@@ -222,10 +223,10 @@ NULL	mysql	user	Host	1		NO	char	60	240	N
 NULL	mysql	user	Index_priv	16	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Insert_priv	5	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Lock_tables_priv	21	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
-NULL	mysql	user	max_connections	38	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
-NULL	mysql	user	max_questions	36	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
-NULL	mysql	user	max_updates	37	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
-NULL	mysql	user	max_user_connections	39	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
+NULL	mysql	user	max_connections	39	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
+NULL	mysql	user	max_questions	37	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
+NULL	mysql	user	max_updates	38	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
+NULL	mysql	user	max_user_connections	40	0	NO	int	NULL	NULL	10	0	NULL	NULL	int(11) unsigned			select,insert,update,references		Default	Default
 NULL	mysql	user	Password	3		NO	char	41	41	NULL	NULL	latin1	latin1_bin	char(41)			select,insert,update,references		Default	Default
 NULL	mysql	user	Process_priv	12	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	References_priv	15	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
@@ -236,14 +237,14 @@ NULL	mysql	user	Select_priv	4	N	NO	enum	
 NULL	mysql	user	Show_db_priv	18	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Show_view_priv	26	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Shutdown_priv	11	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
-NULL	mysql	user	ssl_cipher	33	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
-NULL	mysql	user	ssl_type	32		NO	enum	9	36	NULL	NULL	utf8	utf8_general_ci	enum('','ANY','X509','SPECIFIED')			select,insert,update,references		Default	Default
+NULL	mysql	user	ssl_cipher	34	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
+NULL	mysql	user	ssl_type	33		NO	enum	9	36	NULL	NULL	utf8	utf8_general_ci	enum('','ANY','X509','SPECIFIED')			select,insert,update,references		Default	Default
 NULL	mysql	user	Super_priv	19	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Trigger_priv	31	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	Update_priv	6	N	NO	enum	1	4	NULL	NULL	utf8	utf8_general_ci	enum('N','Y')			select,insert,update,references		Default	Default
 NULL	mysql	user	User	2		NO	char	16	64	NULL	NULL	utf8	utf8_bin	char(16)	PRI		select,insert,update,references		Default	Default
-NULL	mysql	user	x509_issuer	34	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
-NULL	mysql	user	x509_subject	35	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
+NULL	mysql	user	x509_issuer	35	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
+NULL	mysql	user	x509_subject	36	NULL	NO	blob	65535	65535	NULL	NULL	NULL	NULL	blob			select,insert,update,references		Default	Default
 ##########################################################################
 # Show the quotient of CHARACTER_OCTET_LENGTH and CHARACTER_MAXIMUM_LENGTH
 ##########################################################################
@@ -261,7 +262,6 @@ COL_CML	DATA_TYPE	CHARACTER_SET_NAME	COL
 1.0000	longblob	NULL	NULL
 1.0000	char	latin1	latin1_bin
 1.0000	char	latin1	latin1_swedish_ci
-1.0000	enum	latin1	latin1_swedish_ci
 1.0000	varchar	latin1	latin1_swedish_ci
 1.0000	mediumtext	utf8	utf8_general_ci
 1.0000	text	utf8	utf8_general_ci
@@ -422,29 +422,29 @@ NULL	mysql	ndb_binlog_index	gci	int	NULL
 NULL	mysql	online_backup	backup_id	bigint	NULL	NULL	NULL	NULL	bigint(20) unsigned
 NULL	mysql	online_backup	process_id	int	NULL	NULL	NULL	NULL	int(10) unsigned
 NULL	mysql	online_backup	binlog_pos	int	NULL	NULL	NULL	NULL	int(10) unsigned
-1.0000	mysql	online_backup	binlog_file	char	64	64	latin1	latin1_swedish_ci	char(64)
-1.0000	mysql	online_backup	backup_state	enum	14	14	latin1	latin1_swedish_ci	enum('complete','starting','validity point','running','error','cancel')
-1.0000	mysql	online_backup	operation	enum	7	7	latin1	latin1_swedish_ci	enum('backup','restore')
+4.0000	mysql	online_backup	binlog_file	char	64	256	utf8	utf8_general_ci	char(64)
+4.0000	mysql	online_backup	backup_state	enum	14	56	utf8	utf8_general_ci	enum('complete','starting','validity point','running','error','cancel')
+4.0000	mysql	online_backup	operation	enum	7	28	utf8	utf8_general_ci	enum('backup','restore')
 NULL	mysql	online_backup	error_num	int	NULL	NULL	NULL	NULL	int(11)
 NULL	mysql	online_backup	num_objects	int	NULL	NULL	NULL	NULL	int(10) unsigned
 NULL	mysql	online_backup	total_bytes	bigint	NULL	NULL	NULL	NULL	bigint(20) unsigned
 NULL	mysql	online_backup	validity_point_time	datetime	NULL	NULL	NULL	NULL	datetime
 NULL	mysql	online_backup	start_time	datetime	NULL	NULL	NULL	NULL	datetime
 NULL	mysql	online_backup	stop_time	datetime	NULL	NULL	NULL	NULL	datetime
-1.0000	mysql	online_backup	host_or_server_name	char	30	30	latin1	latin1_swedish_ci	char(30)
-1.0000	mysql	online_backup	username	char	30	30	latin1	latin1_swedish_ci	char(30)
-1.0000	mysql	online_backup	backup_file	char	100	100	latin1	latin1_swedish_ci	char(100)
-1.0000	mysql	online_backup	user_comment	varchar	200	200	latin1	latin1_swedish_ci	varchar(200)
-1.0000	mysql	online_backup	command	varchar	512	512	latin1	latin1_swedish_ci	varchar(512)
-1.0000	mysql	online_backup	drivers	varchar	100	100	latin1	latin1_swedish_ci	varchar(100)
+4.0000	mysql	online_backup	host_or_server_name	char	30	120	utf8	utf8_general_ci	char(30)
+4.0000	mysql	online_backup	username	char	30	120	utf8	utf8_general_ci	char(30)
+4.0000	mysql	online_backup	backup_file	char	100	400	utf8	utf8_general_ci	char(100)
+4.0000	mysql	online_backup	user_comment	varchar	200	800	utf8	utf8_general_ci	varchar(200)
+4.0000	mysql	online_backup	command	varchar	512	2048	utf8	utf8_general_ci	varchar(512)
+4.0000	mysql	online_backup	drivers	varchar	100	400	utf8	utf8_general_ci	varchar(100)
 NULL	mysql	online_backup_progress	backup_id	bigint	NULL	NULL	NULL	NULL	bigint(20) unsigned
-1.0000	mysql	online_backup_progress	object	char	30	30	latin1	latin1_swedish_ci	char(30)
+4.0000	mysql	online_backup_progress	object	char	30	120	utf8	utf8_general_ci	char(30)
 NULL	mysql	online_backup_progress	start_time	datetime	NULL	NULL	NULL	NULL	datetime
 NULL	mysql	online_backup_progress	stop_time	datetime	NULL	NULL	NULL	NULL	datetime
 NULL	mysql	online_backup_progress	total_bytes	bigint	NULL	NULL	NULL	NULL	bigint(20)
 NULL	mysql	online_backup_progress	progress	bigint	NULL	NULL	NULL	NULL	bigint(20) unsigned
 NULL	mysql	online_backup_progress	error_num	int	NULL	NULL	NULL	NULL	int(11)
-1.0000	mysql	online_backup_progress	notes	char	100	100	latin1	latin1_swedish_ci	char(100)
+4.0000	mysql	online_backup_progress	notes	char	100	400	utf8	utf8_general_ci	char(100)
 4.0000	mysql	plugin	name	char	64	256	utf8	utf8_bin	char(64)
 4.0000	mysql	plugin	dl	char	128	512	utf8	utf8_bin	char(128)
 4.0000	mysql	proc	db	char	64	256	utf8	utf8_bin	char(64)
@@ -548,6 +548,7 @@ NULL	mysql	time_zone_transition_type	Is_
 4.0000	mysql	user	Create_user_priv	enum	1	4	utf8	utf8_general_ci	enum('N','Y')
 4.0000	mysql	user	Event_priv	enum	1	4	utf8	utf8_general_ci	enum('N','Y')
 4.0000	mysql	user	Trigger_priv	enum	1	4	utf8	utf8_general_ci	enum('N','Y')
+4.0000	mysql	user	Create_tablespace_priv	enum	1	4	utf8	utf8_general_ci	enum('N','Y')
 4.0000	mysql	user	ssl_type	enum	9	36	utf8	utf8_general_ci	enum('','ANY','X509','SPECIFIED')
 1.0000	mysql	user	ssl_cipher	blob	65535	65535	NULL	NULL	blob
 1.0000	mysql	user	x509_issuer	blob	65535	65535	NULL	NULL	blob

=== modified file 'mysql-test/suite/funcs_1/r/is_tables_is_falcon.result'
--- a/mysql-test/suite/funcs_1/r/is_tables_is_falcon.result	2008-06-19 18:56:48 +0000
+++ b/mysql-test/suite/funcs_1/r/is_tables_is_falcon.result	2008-07-29 10:45:39 +0000
@@ -153,29 +153,6 @@ user_comment	
 Separator	-----------------------------------------------------
 TABLE_CATALOG	NULL
 TABLE_SCHEMA	information_schema
-TABLE_NAME	FALCON_TABLES
-TABLE_TYPE	SYSTEM VIEW
-ENGINE	MEMORY
-VERSION	10
-ROW_FORMAT	Fixed
-TABLE_ROWS	#TBLR#
-AVG_ROW_LENGTH	#ARL#
-DATA_LENGTH	#DL#
-MAX_DATA_LENGTH	#MDL#
-INDEX_LENGTH	#IL#
-DATA_FREE	#DF#
-AUTO_INCREMENT	NULL
-CREATE_TIME	#CRT#
-UPDATE_TIME	#UT#
-CHECK_TIME	#CT#
-TABLE_COLLATION	utf8_general_ci
-CHECKSUM	NULL
-CREATE_OPTIONS	#CO#
-TABLE_COMMENT	#TC#
-user_comment	
-Separator	-----------------------------------------------------
-TABLE_CATALOG	NULL
-TABLE_SCHEMA	information_schema
 TABLE_NAME	FALCON_TABLESPACES
 TABLE_TYPE	SYSTEM VIEW
 ENGINE	MEMORY
@@ -469,29 +446,6 @@ user_comment	
 Separator	-----------------------------------------------------
 TABLE_CATALOG	NULL
 TABLE_SCHEMA	information_schema
-TABLE_NAME	FALCON_TABLES
-TABLE_TYPE	SYSTEM VIEW
-ENGINE	MEMORY
-VERSION	10
-ROW_FORMAT	Fixed
-TABLE_ROWS	#TBLR#
-AVG_ROW_LENGTH	#ARL#
-DATA_LENGTH	#DL#
-MAX_DATA_LENGTH	#MDL#
-INDEX_LENGTH	#IL#
-DATA_FREE	#DF#
-AUTO_INCREMENT	NULL
-CREATE_TIME	#CRT#
-UPDATE_TIME	#UT#
-CHECK_TIME	#CT#
-TABLE_COLLATION	utf8_general_ci
-CHECKSUM	NULL
-CREATE_OPTIONS	#CO#
-TABLE_COMMENT	#TC#
-user_comment	
-Separator	-----------------------------------------------------
-TABLE_CATALOG	NULL
-TABLE_SCHEMA	information_schema
 TABLE_NAME	FALCON_TABLESPACES
 TABLE_TYPE	SYSTEM VIEW
 ENGINE	MEMORY

=== modified file 'mysql-test/suite/funcs_1/r/is_tables_mysql.result'
--- a/mysql-test/suite/funcs_1/r/is_tables_mysql.result	2008-07-04 08:28:36 +0000
+++ b/mysql-test/suite/funcs_1/r/is_tables_mysql.result	2008-08-14 14:07:27 +0000
@@ -282,7 +282,7 @@ AUTO_INCREMENT	1
 CREATE_TIME	#CRT#
 UPDATE_TIME	#UT#
 CHECK_TIME	#CT#
-TABLE_COLLATION	latin1_swedish_ci
+TABLE_COLLATION	utf8_general_ci
 CHECKSUM	NULL
 CREATE_OPTIONS	#CO#
 TABLE_COMMENT	#TC#
@@ -305,7 +305,7 @@ AUTO_INCREMENT	NULL
 CREATE_TIME	#CRT#
 UPDATE_TIME	#UT#
 CHECK_TIME	#CT#
-TABLE_COLLATION	latin1_swedish_ci
+TABLE_COLLATION	utf8_general_ci
 CHECKSUM	NULL
 CREATE_OPTIONS	#CO#
 TABLE_COMMENT	#TC#

=== modified file 'mysql-test/suite/funcs_1/r/is_user_privileges.result'
--- a/mysql-test/suite/funcs_1/r/is_user_privileges.result	2008-03-07 19:18:14 +0000
+++ b/mysql-test/suite/funcs_1/r/is_user_privileges.result	2008-08-07 13:38:29 +0000
@@ -76,10 +76,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 #
 # Add GRANT OPTION db_datadict.* to testuser1;
 GRANT UPDATE ON db_datadict.* TO 'testuser1'@'localhost' WITH GRANT OPTION;
@@ -93,10 +93,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 # Establish connection testuser1 (user=testuser1)
 SELECT * FROM information_schema.user_privileges
 WHERE grantee LIKE '''testuser%'''
@@ -105,10 +105,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser1'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 SHOW GRANTS;
 Grants for testuser1@localhost
 GRANT USAGE ON *.* TO 'testuser1'@'localhost'
@@ -130,10 +130,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 GRANT SELECT ON *.* TO 'testuser1'@'localhost' WITH GRANT OPTION;
 #
 # Here <SELECT YES> is shown correctly for testuser1;
@@ -147,10 +147,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 # Switch to connection testuser1
 SELECT * FROM information_schema.user_privileges
 WHERE grantee LIKE '''testuser%'''
@@ -159,10 +159,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser1'@'localhost'	NULL	SELECT	YES
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		Y	N	N	N	N	N	N	N	N	N	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 SHOW GRANTS;
 Grants for testuser1@localhost
 GRANT SELECT ON *.* TO 'testuser1'@'localhost' WITH GRANT OPTION
@@ -207,10 +207,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 # Switch to connection testuser1
 SELECT * FROM information_schema.user_privileges
 WHERE grantee LIKE '''testuser%'''
@@ -253,10 +253,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 # Switch to connection testuser1
 SELECT * FROM information_schema.user_privileges
 WHERE grantee LIKE '''testuser%'''
@@ -265,10 +265,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser1'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 SHOW GRANTS;
 Grants for testuser1@localhost
 GRANT USAGE ON *.* TO 'testuser1'@'localhost'
@@ -284,10 +284,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser1'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 SHOW GRANTS;
 Grants for testuser1@localhost
 GRANT USAGE ON *.* TO 'testuser1'@'localhost'
@@ -309,10 +309,10 @@ GRANTEE	TABLE_CATALOG	PRIVILEGE_TYPE	IS_
 'testuser3'@'localhost'	NULL	USAGE	NO
 SELECT * FROM mysql.user
 WHERE user LIKE 'testuser%' ORDER BY host, user;
-Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
-localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
-localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+Host	User	Password	Select_priv	Insert_priv	Update_priv	Delete_priv	Create_priv	Drop_priv	Reload_priv	Shutdown_priv	Process_priv	File_priv	Grant_priv	References_priv	Index_priv	Alter_priv	Show_db_priv	Super_priv	Create_tmp_table_priv	Lock_tables_priv	Execute_priv	Repl_slave_priv	Repl_client_priv	Create_view_priv	Show_view_priv	Create_routine_priv	Alter_routine_priv	Create_user_priv	Event_priv	Trigger_priv	Create_tablespace_priv	ssl_type	ssl_cipher	x509_issuer	x509_subject	max_questions	max_updates	max_connections	max_user_connections
+localhost	testuser1		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser2		N	Y	Y	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
+localhost	testuser3		N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N	N					0	0	0	0
 # Switch to connection testuser1
 SELECT * FROM information_schema.user_privileges
 WHERE grantee LIKE '''testuser%'''

=== modified file 'mysql-test/suite/funcs_1/r/memory_storedproc.result'
--- a/mysql-test/suite/funcs_1/r/memory_storedproc.result	2008-07-08 18:40:32 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_storedproc.result	2008-08-07 13:38:29 +0000
@@ -21943,9 +21943,9 @@ END	latin1	latin1_swedish_ci	latin1_swed
 set @@sql_mode='';
 CALL sp4();
 Level	Code	Message
-Error	1365	Division by 0
+Warning	1365	Division by 0
 Warnings:
-Error	1365	Division by 0
+Warning	1365	Division by 0
 DROP PROCEDURE sp4;
 set @@sql_mode='';
 

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_03.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_03.result	2008-08-07 13:38:29 +0000
@@ -78,7 +78,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke TRIGGER on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER on *.* to test_yesprivs@localhost;
 grant SELECT on priv_db.t1 to test_yesprivs@localhost;
@@ -156,7 +156,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke UPDATE  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -170,7 +170,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 select f1 from t1 order by f1;
 f1
 insert 3.5.3.2-no
@@ -402,7 +402,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke SELECT  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -416,7 +416,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 create trigger trg5a_1 before INSERT on t1 for each row
 set @test_var = new.f1;
 set @test_var = 'before trig 3.5.3.8-1a';

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_03e.result	2008-06-19 18:56:48 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_03e.result	2008-08-07 13:38:29 +0000
@@ -563,7 +563,7 @@ trig 1_1-yes
 revoke TRIGGER on *.* from test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
@@ -610,7 +610,7 @@ root@localhost
 grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
 trigger privilege on db level for create:

=== modified file 'mysql-test/suite/funcs_1/r/myisam_storedproc.result'
--- a/mysql-test/suite/funcs_1/r/myisam_storedproc.result	2008-07-08 18:40:32 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_storedproc.result	2008-08-07 13:38:29 +0000
@@ -21943,9 +21943,9 @@ END	latin1	latin1_swedish_ci	latin1_swed
 set @@sql_mode='';
 CALL sp4();
 Level	Code	Message
-Error	1365	Division by 0
+Warning	1365	Division by 0
 Warnings:
-Error	1365	Division by 0
+Warning	1365	Division by 0
 DROP PROCEDURE sp4;
 set @@sql_mode='';
 

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_03.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_03.result	2008-08-07 13:38:29 +0000
@@ -78,7 +78,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke TRIGGER on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER on *.* to test_yesprivs@localhost;
 grant SELECT on priv_db.t1 to test_yesprivs@localhost;
@@ -156,7 +156,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke UPDATE  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -170,7 +170,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 select f1 from t1 order by f1;
 f1
 insert 3.5.3.2-no
@@ -402,7 +402,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke SELECT  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -416,7 +416,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 create trigger trg5a_1 before INSERT on t1 for each row
 set @test_var = new.f1;
 set @test_var = 'before trig 3.5.3.8-1a';

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_03e.result	2008-06-19 18:56:48 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_03e.result	2008-08-07 13:38:29 +0000
@@ -563,7 +563,7 @@ trig 1_1-yes
 revoke TRIGGER on *.* from test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
@@ -610,7 +610,7 @@ root@localhost
 grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
 trigger privilege on db level for create:

=== modified file 'mysql-test/suite/funcs_1/r/ndb_storedproc.result'
--- a/mysql-test/suite/funcs_1/r/ndb_storedproc.result	2008-07-08 21:10:26 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_storedproc.result	2008-08-11 13:45:45 +0000
@@ -21942,9 +21942,9 @@ END	latin1	latin1_swedish_ci	latin1_swed
 set @@sql_mode='';
 CALL sp4();
 Level	Code	Message
-Error	1365	Division by 0
+Warning	1365	Division by 0
 Warnings:
-Error	1365	Division by 0
+Warning	1365	Division by 0
 DROP PROCEDURE sp4;
 set @@sql_mode='';
 

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_03.result	2008-06-03 10:21:48 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_03.result	2008-08-11 13:45:45 +0000
@@ -77,7 +77,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke TRIGGER on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER on *.* to test_yesprivs@localhost;
 grant SELECT on priv_db.t1 to test_yesprivs@localhost;
@@ -155,7 +155,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke UPDATE  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -169,7 +169,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 select f1 from t1 order by f1;
 f1
 insert 3.5.3.2-no
@@ -401,7 +401,7 @@ grant ALL  on *.* to test_noprivs@localh
 revoke SELECT  on *.* from test_noprivs@localhost;
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
@@ -415,7 +415,7 @@ test_noprivs@localhost
 use priv_db;
 show grants;
 Grants for test_noprivs@localhost
-GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 create trigger trg5a_1 before INSERT on t1 for each row
 set @test_var = new.f1;
 set @test_var = 'before trig 3.5.3.8-1a';

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_03e.result	2008-04-30 16:16:45 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_03e.result	2008-08-11 13:45:45 +0000
@@ -562,7 +562,7 @@ trig 1_1-yes
 revoke TRIGGER on *.* from test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
@@ -609,7 +609,7 @@ root@localhost
 grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, CREATE TABLESPACE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
 trigger privilege on db level for create:

=== modified file 'mysql-test/suite/ndb/r/ndb_basic.result'
--- a/mysql-test/suite/ndb/r/ndb_basic.result	2007-11-12 12:25:34 +0000
+++ b/mysql-test/suite/ndb/r/ndb_basic.result	2008-08-06 22:16:07 +0000
@@ -783,6 +783,7 @@ f1	f2	f3
 222222	bbbbbb	2
 drop table t1;
 Illegal ndb error code: 1186
+MySQL error code 1186 (ER_FLUSH_MASTER_BINLOG_CLOSED): Binlog closed, cannot RESET MASTER
 CREATE TABLE t1 (
 a VARBINARY(40) NOT NULL,
 b VARCHAR (256) CHARACTER SET UTF8 NOT NULL,

=== removed file 'mysql-test/suite/sys_vars/r/rpl_sync_binlog_basic_64.result'
--- a/mysql-test/suite/sys_vars/r/rpl_sync_binlog_basic_64.result	2008-08-22 17:03:15 +0000
+++ b/mysql-test/suite/sys_vars/r/rpl_sync_binlog_basic_64.result	1970-01-01 00:00:00 +0000
@@ -1,105 +0,0 @@
-SET @start_value = @@global.sync_binlog;
-SELECT @start_value;
-@start_value
-0
-'#--------------------FN_DYNVARS_168_01------------------------#'
-SET @@global.sync_binlog = 99;
-SET @@global.sync_binlog = DEFAULT;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0
-'#---------------------FN_DYNVARS_168_02-------------------------#'
-SET @@global.sync_binlog = @start_value;
-SELECT @@global.sync_binlog = 0;
-@@global.sync_binlog = 0
-1
-'#--------------------FN_DYNVARS_168_03------------------------#'
-SET @@global.sync_binlog = 0;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0
-SET @@global.sync_binlog = 1;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-1
-SET @@global.sync_binlog = 4294967295;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-4294967295
-SET @@global.sync_binlog = 4294967294;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-4294967294
-SET @@global.sync_binlog = 65536;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-65536
-'#--------------------FN_DYNVARS_168_04-------------------------#'
-SET @@global.sync_binlog = -1;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0
-SET @@global.sync_binlog = 4294967296;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0
-SET @@global.sync_binlog = 10240022115;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-1650087523
-SET @@global.sync_binlog = 10000.01;
-ERROR 42000: Incorrect argument type to variable 'sync_binlog'
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-1650087523
-SET @@global.sync_binlog = -1024;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0
-SET @@global.sync_binlog = 42949672950;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-4294967286
-'Bug # 34837: Errors are not coming on assigning invalid values to variable';
-SET @@global.sync_binlog = ON;
-ERROR 42000: Incorrect argument type to variable 'sync_binlog'
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-4294967286
-SET @@global.sync_binlog = 'test';
-ERROR 42000: Incorrect argument type to variable 'sync_binlog'
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-4294967286
-'#-------------------FN_DYNVARS_168_05----------------------------#'
-SET @@session.sync_binlog = 0;
-ERROR HY000: Variable 'sync_binlog' is a GLOBAL variable and should be set with SET GLOBAL
-SELECT @@sync_binlog;
-@@sync_binlog
-4294967286
-'#----------------------FN_DYNVARS_168_06------------------------#'
-SELECT @@global.sync_binlog = VARIABLE_VALUE
-FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
-WHERE VARIABLE_NAME='sync_binlog';
-@@global.sync_binlog = VARIABLE_VALUE
-1
-'#---------------------FN_DYNVARS_168_07----------------------#'
-SET sync_binlog = 1;
-ERROR HY000: Variable 'sync_binlog' is a GLOBAL variable and should be set with SET GLOBAL
-SELECT @@sync_binlog;
-@@sync_binlog
-4294967286
-SET local.sync_binlog = 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sync_binlog = 1' at line 1
-SELECT local.sync_binlog;
-ERROR 42S02: Unknown table 'local' in field list
-SET global.sync_binlog = 1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sync_binlog = 1' at line 1
-SELECT global.sync_binlog;
-ERROR 42S02: Unknown table 'global' in field list
-SELECT sync_binlog = @@session.sync_binlog;
-ERROR 42S22: Unknown column 'sync_binlog' in 'field list'
-SET @@global.sync_binlog = @start_value;
-SELECT @@global.sync_binlog;
-@@global.sync_binlog
-0

=== removed file 'mysql-test/suite/sys_vars/t/rpl_sync_binlog_basic_64.test'
--- a/mysql-test/suite/sys_vars/t/rpl_sync_binlog_basic_64.test	2008-08-05 11:20:20 +0000
+++ b/mysql-test/suite/sys_vars/t/rpl_sync_binlog_basic_64.test	1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-################################################################################
-# Created by Horst Hunger      2008-05-07                                      #
-#                                                                              #
-# Wrapper for 64 bit machines                                                  #
-################################################################################
-
---source include/have_64bit.inc
---source include/sync_binlog_basic.inc

=== added file 'mysql-test/t/backup_backupdir.test'
--- a/mysql-test/t/backup_backupdir.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_backupdir.test	2008-08-27 12:49:58 +0000
@@ -0,0 +1,104 @@
+#
+# This test is designed to test the new backupdir variable.
+#
+
+--source include/not_embedded.inc
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--echo Reset backupdir 
+SET @@global.backupdir = @@global.datadir;
+
+--disable_warnings
+DROP DATABASE IF EXISTS bup_backupdir;
+--enable_warnings
+
+--echo Create a database
+CREATE DATABASE bup_backupdir;
+CREATE TABLE bup_backupdir.t1(a INT);
+INSERT INTO bup_backupdir.t1 VALUES (1), (2), (3);
+
+#
+# The following tests the backupdir variable by changing it to
+# redirect the output of the backup command/input of the restore
+# command.
+#
+
+--error 0,1,2
+rmdir $MYSQLTEST_VARDIR/tmp/backup;
+
+--echo Create a directory for backup images
+mkdir $MYSQLTEST_VARDIR/tmp/backup;
+
+--echo Reset backupdir 
+SET @@global.backupdir = '../../tmp/backup';
+
+--echo Perform backup
+--replace_column 1 #
+BACKUP DATABASE bup_backupdir TO 'bup_backupdir1.bak';
+
+--echo Ensure backup image file went to the correct location
+--echo $MYSQLTEST_DIR/backup/bup_backupdir.bak
+--file_exists $MYSQLTEST_VARDIR/tmp/backup/bup_backupdir1.bak
+
+--echo Perform restore
+--replace_column 1 #
+RESTORE FROM 'bup_backupdir1.bak';
+
+--echo Now do the backup and restore by specifying a path.
+
+--echo Perform backup
+--replace_column 1 #
+BACKUP DATABASE bup_backupdir TO '../bup_backupdir2.bak';
+
+--echo Ensure backup image file went to the correct location
+--file_exists $MYSQLTEST_VARDIR/tmp/bup_backupdir2.bak
+
+--echo Perform restore
+--replace_column 1 #
+RESTORE FROM '../bup_backupdir2.bak';
+
+--echo Perform backup
+--replace_column 1 #
+BACKUP DATABASE bup_backupdir TO '../../bup_backupdir3.bak';
+
+--echo Ensure backup image file went to the correct location
+--file_exists $MYSQLTEST_VARDIR/bup_backupdir3.bak
+
+--echo Reset backupdir with ending /
+SET @@global.backupdir = '../../tmp/backup/';
+
+--echo Perform backup
+--replace_column 1 #
+BACKUP DATABASE bup_backupdir TO '../../bup_backupdir4.bak';
+
+--echo Ensure backup image file went to the correct location
+--file_exists $MYSQLTEST_VARDIR/bup_backupdir4.bak
+
+--echo Try a backup to an invalid relative path.
+--error ER_BACKUP_WRITE_LOC
+BACKUP DATABASE bup_backupdir TO '../../../../../../../../../../../../../../../../../../bup_backupdir5.bak';
+
+--echo Try a backup to an invalid hard path.
+--error ER_BACKUP_WRITE_LOC
+BACKUP DATABASE bup_backupdir TO '/dev/not/there/either/bup_backupdir6.bak';
+
+#
+# Attempt to set the backupdir to something invalid.
+#
+SET @@global.backupdir = 'This_is_really_stupid/not/there/at/all';
+
+--echo Cleanup
+
+--echo Reset backupdir 
+SET @@global.backupdir = @@global.datadir;
+
+DROP DATABASE bup_backupdir;
+
+remove_file $MYSQLTEST_VARDIR/tmp/bup_backupdir1.bak;
+remove_file $MYSQLTEST_VARDIR/tmp/backup/bup_backupdir2.bak;
+remove_file $MYSQLD_DATADIR/bup_backupdir3.bak;
+remove_file $MYSQLD_DATADIR/bup_backupdir4.bak;
+
+--error 0,1
+rmdir $MYSQLTEST_VARDIR/tmp/backup;

=== added file 'mysql-test/t/backup_concurrent.test'
--- a/mysql-test/t/backup_concurrent.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_concurrent.test	2008-08-27 12:49:58 +0000
@@ -0,0 +1,130 @@
+###########################################################################
+# Author: Oystein Grovlen
+# Date: 2008-07-31
+# Purpose: To test starting backups/retore in parallel
+###############################################################################
+--source include/not_embedded.inc
+--source include/have_debug_sync.inc
+
+#Create Database and object view for this test.
+
+--disable_warnings
+SET DEBUG_SYNC= 'reset';
+DROP DATABASE IF EXISTS backup_concurrent;
+--enable_warnings
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+--error 0,1
+remove_file $MYSQLD_DATADIR/backup1;
+--error 0,1
+remove_file $MYSQLD_DATADIR/backup2;
+--error 0,1
+remove_file $MYSQLD_DATADIR/backup3;
+
+CREATE DATABASE backup_concurrent;
+USE backup_concurrent;
+
+#Create table
+
+--echo Creating Table
+CREATE TABLE t (
+t1 INTEGER NOT NULL,
+t2 CHAR(36),
+PRIMARY KEY (t1)
+);
+
+--echo ---------------------------------------------------
+--echo Testing starting new backup while backup is ongoing
+--echo ---------------------------------------------------
+--echo Starting first backup
+connect (backup,localhost,root,,);
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR backup';
+send BACKUP DATABASE backup_concurrent TO 'backup1';
+
+connection default;
+--echo Waiting for first backup to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+--echo Starting second backup in another connection.  
+--echo (Should fail because another backup is running.)
+--error ER_BACKUP_RUNNING
+BACKUP DATABASE backup_concurrent TO 'backup2';
+
+--echo Insert Data
+INSERT INTO t VALUES (1, 'test');
+
+--echo Wait for first backup to complete
+SET DEBUG_SYNC= 'now SIGNAL backup';
+connection backup;
+replace_column 1 #;
+reap;
+
+--echo ---------------------------------------------------
+--echo Testing starting restore while backup is ongoing
+--echo ---------------------------------------------------
+--echo Starting backup
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR backup';
+send BACKUP DATABASE backup_concurrent TO 'backup3';
+
+connection default;
+--echo Waiting for backup to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+--echo Starting restore in another connection.  
+--echo (Should fail because another backup is running.)
+--error ER_BACKUP_RUNNING
+RESTORE FROM 'backup1';
+
+--echo Insert Data
+INSERT INTO t VALUES (2, 'test');
+
+--echo Wait for backup to complete
+SET DEBUG_SYNC= 'now SIGNAL backup';
+connection backup;
+replace_column 1 #;
+reap;
+
+--echo ---------------------------------------------------
+--echo Testing starting backup/restore restore is ongoing
+--echo ---------------------------------------------------
+--echo Starting restore
+SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR restore';
+send RESTORE FROM 'backup1';
+
+connection default;
+--echo Waiting for restore to get going
+SET DEBUG_SYNC= 'now WAIT_FOR running';
+
+--echo Starting backup in another connection.  
+--echo (Should fail because restore is running.)
+--error ER_BACKUP_RUNNING
+BACKUP DATABASE backup_concurrent TO 'backup4';
+
+--echo Insert Data
+INSERT INTO t VALUES (3, 'test');
+
+--echo Starting a new restore in another connection.  
+--echo (Should fail because another restore is running.)
+--error ER_BACKUP_RUNNING
+RESTORE FROM 'backup3';
+
+--echo Insert Data
+INSERT INTO t VALUES (4, 'test');
+
+--echo Wait for backup to complete
+SET DEBUG_SYNC= 'now SIGNAL restore';
+connection backup;
+replace_column 1 #;
+reap;
+
+
+# Test cleanup section
+
+--echo
+--echo Test completed. Cleaning up.
+--echo
+
+DROP DATABASE backup_concurrent;
+SET DEBUG_SYNC= 'reset';
+
+remove_file $MYSQLTEST_DATADIR/backup1;
+remove_file $MYSQLTEST_DATADIR/backup3;
+

=== modified file 'mysql-test/t/backup_progress.test'
--- a/mysql-test/t/backup_progress.test	2008-07-22 18:08:06 +0000
+++ b/mysql-test/t/backup_progress.test	2008-08-27 12:49:58 +0000
@@ -8,6 +8,30 @@
 --source include/have_innodb.inc
 --source include/not_embedded.inc
 
+# bug#33836 backup tables should have charset utf8
+
+--echo 
+--echo Checking character set for backup tables 
+--echo 
+
+SELECT column_name, character_set_name 
+FROM information_schema.columns 
+WHERE table_name LIKE 'online_backup' 
+  AND character_set_name LIKE 'utf8' 
+ORDER BY column_name;
+
+--echo 
+
+SELECT column_name, character_set_name 
+FROM information_schema.columns 
+WHERE table_name LIKE 'online_backup_progress' 
+  AND character_set_name LIKE 'utf8' 
+ORDER BY column_name;
+
+--echo 
+--echo Now starting real tests
+--echo 
+
 #
 # Preparative cleanup.
 #
@@ -109,7 +133,7 @@ connection con2;
 reap;
 
 #Show results
---replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 #
+--replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 # 15 #
 --query_vertical SELECT ob.* FROM mysql.online_backup AS ob JOIN backup_progress.t1_res AS t1 ON ob.backup_id = t1.id;
 --replace_column 1 # 3 # 4 #
 SELECT obp.* FROM mysql.online_backup_progress AS obp JOIN backup_progress.t1_res AS t1 ON obp.backup_id = t1.id;
@@ -158,7 +182,7 @@ reap;
 DELETE FROM backup_progress.t1_res;
 SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
 INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
---replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 #
+--replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 # 15 #
 --query_vertical SELECT ob.* FROM mysql.online_backup AS ob JOIN backup_progress.t1_res AS t1 ON ob.backup_id = t1.id;
 --replace_column 1 # 3 # 4 #
 SELECT obp.* FROM mysql.online_backup_progress AS obp JOIN backup_progress.t1_res AS t1 ON obp.backup_id = t1.id;

=== modified file 'mysql-test/t/backup_views.test'
--- a/mysql-test/t/backup_views.test	2008-07-23 17:58:12 +0000
+++ b/mysql-test/t/backup_views.test	2008-08-27 12:49:58 +0000
@@ -27,140 +27,148 @@ remove_file $MYSQLD_DATADIR/bup_objectvi
 DROP DATABASE IF EXISTS bup_db1;
 DROP DATABASE IF EXISTS bup_db2;
 
-
-#We are creating 2 databases bup_db1 and bup_db2 to accomplish wide testing of  views in order to check their consistency    #  after BACKUP AND RESTORE.
+#
+# We are creating 2 databases bup_db1 and bup_db2 to accomplish wide testing
+# of views in order to check their consistency after BACKUP AND RESTORE.
 # In bup_db1 DATABASE consists of tables :t1 t3 t5
-# and views v1(based on t1 alone), vcomb(based on t1 and t3), v5( based on bup_db2.t2), v6(based on bup_db2.v2,bup_db1.t5)
+# and views v1(based on t1 alone), vcomb(based on t1 and t3), 
+# v5( based on bup_db2.t2), v6(based on bup_db2.v2,bup_db1.t5)
 #
 # In bup_db2,it consists table t2
-# views v2(based on t2), v3( based on combination of bup_db1 and bup_db2),v4( based on  bup_db1.t3), vv( based on v3)
+# views v2(based on t2), v3( based on combination of bup_db1 and bup_db2),
+# v4( based on  bup_db1.t3), vv( based on v3)
 #
 
 --enable_warnings
-
 CREATE DATABASE bup_db1;
 USE bup_db1;
 
 #Create table and load with data.
 
 --echo Creating Table t1
-CREATE TABLE t1(id int not null primary key, name char(10),city varchar(10));
+CREATE TABLE bup_db1.t1(
+id INT NOT NULL PRIMARY KEY, 
+name CHAR(10),
+city VARCHAR(10)
+)ENGINE=INNODB;
 
 --echo loading data
-INSERT INTO t1 VALUES 
-(1,'aa1','RR1'),(2,'aa2','RR2'),(3,'aa3','RR3'),(4,'aa4','RR4'),(5,'aa5','RR5'),(6,'aa6','RR6'),(7,'aa7','RR7'),(8,'aa8','RR8');
+INSERT INTO bup_db1.t1 VALUES
+(1,'aa1','RR1'),(2,'aa2','RR2'),(3,'aa3','RR3'),(4,'aa4','RR4'),
+(5,'aa5','RR5'),(6,'aa6','RR6'),(7,'aa7','RR7'),(8,'aa8','RR8');
 
-SELECT * FROM t1;
+SELECT * FROM bup_db1.t1 ORDER BY id;
 
 --echo Creating Table t3
 
-CREATE TABLE t3(ccode int, District char(20) not null primary key, scode int, foreign key (scode) references t1(id));
+CREATE TABLE bup_db1.t3(
+ccode INT, 
+District CHAR(20) NOT NULL PRIMARY KEY, 
+scode INT, 
+FOREIGN KEY (scode) REFERENCES bup_db1.t1(id)
+)ENGINE=INNODB;
 
 --echo Loading Data
 
 INSERT INTO t3 VALUES
-(234, 'zuloa',1),(321,'yyy',2),(765,'iug',3),(124,'LKJ',4),(235,'uth',6);
-
-SELECT * FROM t3;
-
---echo Creating Table t5
-
-CREATE TABLE t5(Gender char(5), cand_age int,foreign key(cand_age) references 
-bup_db2.t2(age));
-
---echo Loading data into table t5
-
-INSERT INTO t5 VALUES
-('F',23),('F',24),('M',19),('F',28),('M',43),('F',30),('M',31),('M',27);
+(234, 'zuloa',1),(321,'yyy',2),(765,'iug',3),
+(124,'LKJ',4),(235,'uth',6);
 
-SELECT * FROM t5;
+SELECT * FROM bup_db1.t3 ORDER BY scode;
 
---echo *****Create views from the table t1 of bup_db1*******
+--echo *****Create view from the table bup_db1.t1*******
 
-CREATE VIEW v1  AS SELECT * FROM t1;
+CREATE VIEW bup_db1.v1 AS SELECT * FROM bup_db1.t1;
 
---echo *****Creating views from 2 tables(t1 and t3) within same database******
-
-CREATE VIEW vcomb AS SELECT name, city, ccode FROM t1, t3 WHERE id=scode;
+--echo ***Create views from 2 tables(t1 and t3) within same DB bup_db1****
 
+CREATE VIEW bup_db1.vcomb AS 
+SELECT name, city, ccode FROM bup_db1.t1, bup_db1.t3 WHERE id=scode;
 
 CREATE DATABASE bup_db2;
-USE bup_db2;
-
-CREATE TABLE t2(idno int, age int primary key, education char(20) ,foreign key (idno) references bup_db1.t1(id));
 
-INSERT INTO t2 VALUES(1,23,'BS'),(2,24,'BE'),(3,19,'school'),(4,28,'MS'),(5,43,'PHD'),(6,30,'Doctor'),(7,31,'Lawyer'),(8,27,'undergrad');
+CREATE TABLE bup_db2.t2(
+idno INT, 
+age INT PRIMARY KEY, 
+education CHAR(20) ,
+FOREIGN KEY (idno) REFERENCES bup_db1.t1(id)
+)ENGINE=INNODB;
 
+INSERT INTO bup_db2.t2 VALUES
+(1,23,'BS'),(2,24,'BE'),(3,19,'School'),(4,28,'MS'),
+(5,43,'PHD'),(6,30,'Doctor'),(7,31,'Lawyer'),(8,27,'Undergrad');
 
-SELECT * FROM t2;
+SELECT * FROM bup_db2.t2 ORDER BY age;
 
---echo ****Creating View****
+--echo ****Create view in bup_db2****
 
-CREATE VIEW v2 AS SELECT age, education FROM t2;
+CREATE VIEW bup_db2.v2 AS SELECT age, education FROM bup_db2.t2;
 
---echo ******Creating Views from combination of 2 databases*******
+--echo ******Create views from combination of 2 databases*******
 
-CREATE VIEW v3 AS SELECT name, age, education FROM bup_db1.t1 , bup_db2.t2 WHERE id=idno;
+CREATE VIEW bup_db2.v3 AS SELECT name, age, education 
+FROM bup_db1.t1 , bup_db2.t2 WHERE id=idno;
 
---echo *********Creating View from another view ***********.
+--echo *********Create view from another view in bup_db2***********.
 
-#Bug#35347 Mysql Server crash while doing restore with views for default  driver
+# Bug#35347 Mysql Server crash while doing restore with views for default driver
 # BUG#34758 Server crashes if database with views backed up using CS driver
-#Creatig view from another view is possible if bug#35347 and bug#34758 is fixed.
+#Creating view from another view is possible if bug#35347 and bug#34758is fixed.
 
-#CREATE VIEW vv (N, A, E) AS SELECT * FROM v3;
+CREATE VIEW bup_db2.vv (N, A, E) AS SELECT * FROM bup_db2.v3;
 
---echo *****Creating View from other Database********
+--echo *****Create view from other Database********
 
-CREATE VIEW v4 AS SELECT * FROM bup_db1.t3;
+CREATE VIEW bup_db2.v4 AS SELECT * FROM bup_db1.t3;
 
 --echo Rename the view name
 
-RENAME TABLE v4 to student_details;
+RENAME TABLE bup_db2.v4 to bup_db2.student_details;
 
-USE bup_db1;
+--echo *******Create view from database bup_db2**********
 
---echo *******Creating View from database bup_db2**********
+CREATE VIEW bup_db1.v5 AS SELECT * FROM bup_db2.t2;
 
-CREATE VIEW v5 AS SELECT * FROM bup_db2.t2;
+--echo Creating Table t5
 
---echo ******Creating View v6********
+CREATE TABLE bup_db1.t5(
+Gender CHAR(5),
+cand_age INT,
+FOREIGN KEY(cand_age) REFERENCES bup_db2.t2(age)
+)ENGINE=INNODB;
 
-#Bug#36213 Restore fails for a database that has views created using another database .
+--echo Loading data into table t5
 
-#CREATE VIEW v6 AS SELECT education,gender FROM bup_db2.v2, t5  WHERE cand_age=age;
+INSERT INTO bup_db1.t5 VALUES
+('F',23),('F',24),('M',19),('F',28),
+('M',43),('F',30),('M',31),('M',27);
+
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
+
+#Bug#36213 Restore fails for a database that has views created using 
+#another database .
+
+--echo ******Create view v6********
+CREATE VIEW bup_db1.v6 AS SELECT education,gender 
+FROM bup_db2.v2, bup_db1.t5  WHERE cand_age=age;
 
 #Excercise the objects of bup_db1
 
-USE bup_db1;
-
-SELECT * FROM t1;
-
-SELECT * FROM t3;
-
-SELECT * FROM t5;
-
-SELECT * FROM v1;
-
-SELECT * FROM vcomb;
-
-SELECT * FROM v5;
-
-#SELECT * FROM v6;
+SELECT * FROM bup_db1.t1 ORDER BY id;
+SELECT * FROM bup_db1.t3 ORDER BY scode;
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
+SELECT * FROM bup_db1.v1;
+SELECT * FROM bup_db1.vcomb ORDER BY name;
+SELECT * FROM bup_db1.v5 ORDER BY age;
+SELECT * FROM bup_db1.v6 ORDER BY education, gender;
 
 --echo excercise objects of bup_db2
 
-USE bup_db2;
-
-SELECT * FROM t2;
-
-SELECT * FROM v2;
-
-SELECT * FROM v3;
-
-#SELECT * FROM vv;
-
-SELECT * FROM student_details; #view v4 is renamed as student_details
+SELECT * FROM bup_db2.t2 ORDER BY age;
+SELECT * FROM bup_db2.v2 ORDER BY age;
+SELECT * FROM bup_db2.v3 ORDER BY age;
+SELECT * FROM bup_db2.vv;
+SELECT * FROM bup_db2.student_details; #view v4 is renamed as student_details
 
 #Show the data and Create statements
 
@@ -172,7 +180,8 @@ SELECT * FROM student_details; #view v4 
 --query_vertical SHOW CREATE VIEW bup_db2.v3;
 
 #Backup and restore data.
---echo backup data
+--echo backup database
+
 replace_column 1 #;
 BACKUP DATABASE bup_db1, bup_db2 TO 'bup_objectview.bak';
 
@@ -183,18 +192,34 @@ replace_column 1 #;
 BACKUP DATABASE bup_db2 TO 'bup_objectview2.bak';
 
 --echo dropping  database.
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
-
 DROP DATABASE bup_db2;
 
-#RESTORE FROM bup_objectview.bak;
+--echo Restore database.
+
+# Individual databases cannot be restored because of VIEW DEPENDENCY
+# For restoring we need base tables in the database, otherwise the 
+# Restore will fail. Once this bug is fixed, we can remove the '#'
+# for the restore below.
+
+--echo restore database with view dependency to other, non-existing db
+
+--error ER_NO_SUCH_TABLE
+RESTORE FROM 'bup_objectview1.bak';
+
+# An incomplete bup_db1 was created by the failing restore operation.
+# Remove it before trying restore of bup_db2.
+DROP DATABASE bup_db1;
 
-#Individual databases cannot be restored because of VIEW DEPENDENCY
+--error ER_NO_SUCH_TABLE
+RESTORE FROM 'bup_objectview2.bak';
 
-#--error 1146
-#RESTORE FROM 'bup_objectview1.bak';
-#--error 1146
-#RESTORE FROM 'bup_objectview2.bak';
+# An incomplete bup_db2 was created by the failing restore operation.
+# Remove it before reverting to the working backup image
+DROP DATABASE bup_db2;
 
 replace_column 1 #;
 RESTORE FROM 'bup_objectview.bak';
@@ -211,77 +236,132 @@ RESTORE FROM 'bup_objectview.bak';
 --echo ****check for view contents after Restore*****
 
 #Excercise the objects of bup_db1
-USE bup_db1;
-SELECT * FROM t1;
-
-SELECT * FROM t3;
 
-SELECT * FROM t5;
+SELECT * FROM bup_db1.t1 ORDER BY id;
+SELECT * FROM bup_db1.t3 ORDER BY scode;
+SELECT * FROM bup_db1.t5 ORDER BY Gender;
+SELECT * FROM bup_db1.v1;
+SELECT * FROM bup_db1.vcomb ORDER BY name;
+SELECT * FROM bup_db1.v5 ORDER BY age;
+SELECT * FROM bup_db1.v6 ORDER BY education, gender;
 
-SELECT * FROM v1;
+--echo excercise objects of bup_db2
 
-SELECT * FROM vcomb;
+SELECT * FROM bup_db2.t2 ORDER BY age;
+SELECT * FROM bup_db2.v2 ORDER BY age;
+SELECT * FROM bup_db2.v3 ORDER BY age;
+SELECT * FROM bup_db2.vv;
+SELECT * FROM bup_db2.student_details;
 
-SELECT * FROM v5;
+#Alter table t1 and take BACKUP to see if view is not affected.
 
-#SELECT * FROM v6;
---echo excercise objects of bup_db2
-use bup_db2;
-SELECT * FROM t2;
+ALTER TABLE bup_db1.t1 CHANGE name name VARCHAR(10);
+DESCRIBE bup_db1.t1;
+SELECT * FROM bup_db1.t1 ORDER BY id;
+SELECT * FROM bup_db1.v1;
+SELECT * FROM bup_db2.v3 ORDER BY age;
 
-SELECT * FROM v2;
+replace_column 1 #;
+BACKUP DATABASE bup_db1, bup_db2 TO 'bup_objectview3.bak';
 
-SELECT * FROM v3;
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
+DROP DATABASE bup_db1;
+DROP DATABASE bup_db2;
 
-#SELECT * FROM vv;
+replace_column 1 #;
+RESTORE FROM 'bup_objectview3.bak';
 
-SELECT * FROM student_details;
+SELECT * FROM bup_db2.v3 ORDER BY age;
+SELECT * FROM bup_db1.t1 ORDER BY id;
 
+--echo
+--echo *** ENTER Backup of database with missing view dependency 
+--echo *** should fail but not crash server 
+--echo *** Test for bug#34902 ***
+
+--echo initializing test
+
+# start with the backed up database
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
 
---echo Restoring Database
-
 replace_column 1 #;
 RESTORE FROM 'bup_objectview.bak';
 
-USE bup_db1;
+# check that table t1 and v1 are initially correct
+SELECT * FROM bup_db1.t1;
+SELECT * FROM bup_db1.v1;
+
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
+DROP TABLE bup_db1.t1;
 
-#Alter table t1 and take BACKUP to see if view is not affected.
-
-ALTER TABLE t1 CHANGE id id tinyint not null;
---query_vertical SHOW CREATE TABLE t1;
-
-SELECT * FROM t1;
+--echo
+--echo Testing backup with missing view dependency in same db
+--echo
 
-DELETE FROM t1 WHERE id=7;
-SELECT * FROM t1;
+# v1 selects from t1, and select now reports error
+--error ER_VIEW_INVALID
+SELECT * FROM bup_db1.v1;
+
+# try to backup - v1 selects from t1 and backup should now fail
+--error ER_BACKUP_CATALOG_ADD_VIEW
+BACKUP DATABASE bup_db1 TO 'bup_shouldfail1.bak';
 
-SELECT * FROM v1;
+--echo
+--echo Testing backup with missing view dependency in other db
+--echo
 
 USE bup_db2;
-SELECT * FROM v3;
+--error ER_VIEW_INVALID
+SELECT * from bup_db2.v3;
+# try to backup - v3 selects from bup_db1.t1 and backup should now fail
+--error ER_BACKUP_CATALOG_ADD_VIEW
+BACKUP DATABASE bup_db2 TO 'bup_shouldfail2.bak';
 
-#BUG#35249 Mysql server crash for delete operation followed by backup for Default Drivers.
+--echo
+--echo *** EXIT Backup of database with missing view dependency
+--echo
 
-#DELETE FROM t2 WHERE age=24;
-#SELECT * FROM t2;
-#SELECT * FROM v3;
+--echo 
+--echo *** ENTER Backup of database with altered view should report error, not crash server
+--echo Test for bug#34867
 
-replace_column 1 #;
-BACKUP DATABASE bup_db1, bup_db2 TO 'bup_objectview3.bak';
+--echo initializing test
 
+# start with the backed up database
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
 
 replace_column 1 #;
-RESTORE FROM 'bup_objectview3.bak';
-
-USE bup_db2;
-SELECT * FROM v3;
+RESTORE FROM 'bup_objectview.bak';
 
 USE bup_db1;
-SELECT * FROM t1;
+CREATE VIEW alter1 AS SELECT 5;
+CREATE VIEW alter2 AS SELECT * FROM alter1;
+ALTER VIEW alter1 AS SELECT 6;
+
+--echo
+--echo Testing view selecting from altered view
+--echo 
+
+--error ER_VIEW_INVALID
+SELECT * FROM alter2;
+
+#fails
+--error ER_VIEW_INVALID
+BACKUP DATABASE bup_db1 TO 'bup_alterview.bak';
+
+--echo 
+--echo *** EXIT Backup of database with altered view
+--echo 
+
 
 # Test cleanup section
 
@@ -289,13 +369,18 @@ SELECT * FROM t1;
 --echo ***  DROP bup_db1, bup_db2 DATABASE ****
 --echo
 
-DROP DATABASE bup_db1;
 
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
+DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
 
 remove_file $MYSQLD_DATADIR/bup_objectview.bak;
 remove_file $MYSQLD_DATADIR/bup_objectview1.bak;
 remove_file $MYSQLD_DATADIR/bup_objectview2.bak;
 remove_file $MYSQLD_DATADIR/bup_objectview3.bak;
+remove_file $MYSQLD_DATADIR/bup_shouldfail1.bak;
+remove_file $MYSQLD_DATADIR/bup_shouldfail2.bak;
+remove_file $MYSQLD_DATADIR/bup_alterview.bak;
 
-#BUG#35249 Mysql server crash for delete operation followed by backup for Default Drivers.

=== modified file 'mysql-test/t/constraints.test'
--- a/mysql-test/t/constraints.test	2005-07-28 00:22:47 +0000
+++ b/mysql-test/t/constraints.test	2008-06-12 15:21:49 +0000
@@ -10,7 +10,7 @@ create table t1 (a int check (a>0));
 insert into t1 values (1);
 insert into t1 values (0);
 drop table t1;
-create table t1 (a int ,b int, check a>b);
+create table t1 (a int, b int, check (a>b));
 insert into t1 values (1,0);
 insert into t1 values (0,1);
 drop table t1;
@@ -29,3 +29,21 @@ show create table t1;
 drop table t1;
 
 # End of 4.1 tests
+
+#
+# Bug#35578 (Parser allows useless/illegal CREATE TABLE syntax)
+#
+
+--disable_warnings
+drop table if exists t_illegal;
+--enable_warnings
+
+--error ER_PARSE_ERROR
+create table t_illegal (a int, b int, check a>b);
+
+--error ER_PARSE_ERROR
+create table t_illegal (a int, b int, constraint abc check a>b);
+
+--error ER_PARSE_ERROR
+create table t_illegal (a int, b int, constraint abc);
+

=== modified file 'mysql-test/t/ctype_ldml.test'
--- a/mysql-test/t/ctype_ldml.test	2007-10-22 11:43:32 +0000
+++ b/mysql-test/t/ctype_ldml.test	2008-08-27 12:49:58 +0000
@@ -77,3 +77,21 @@ select hex(c1) as h, c1 from t1 order by
 select group_concat(hex(c1) order by hex(c1)) from t1 group by c1;
 select group_concat(c1 order by hex(c1) SEPARATOR '') from t1 group by c1;
 drop table t1;
+
+
+-- echo The following tests check that two-byte collation IDs work
+# The file ../std-data/Index.xml has a number of collations with high IDs.
+
+# Test that the "ID" column in I_S and SHOW queries can handle two bytes
+select * from information_schema.collations where id>256 order by id;
+show collation like '%test%';
+
+# Test that two-byte collation ID is correctly transfered to the client side.
+show collation like 'ucs2_vn_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+insert into t1 values (0x0061);
+--enable_metadata
+set @@character_set_results=NULL;
+select * from t1;
+--disable_metadata
+drop table t1;

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2008-08-22 17:03:15 +0000
+++ b/mysql-test/t/disabled.def	2008-08-27 12:49:58 +0000
@@ -22,7 +22,6 @@ csv_alter_table      : Bug#33696 2008-01
 query_cache_wlock_invalidate_func: Bug#35390 causes not deterministic results.
 thread_cache_size_func: BUG#35988, BUG#36733 Due to not deterministic results
 cast                 : Bug#35594 2008-03-27 main.cast fails on Windows2003-64
-subselect_notembedded  : Bug#35803, Bug#33506 2008-Apr-03 subselect_notembedded crashes the server
 status          : Bug#37481 status.test fails randomly
 maria-preload        : Bug#35107 crashes
 key_buffer_size_basic_64    : Bug #36522: Some tests of system variables have diffs on 64bit platorms

=== modified file 'mysql-test/t/implicit_commit.test'
--- a/mysql-test/t/implicit_commit.test	2008-07-27 13:14:46 +0000
+++ b/mysql-test/t/implicit_commit.test	2008-08-27 12:49:58 +0000
@@ -156,7 +156,7 @@ source include/implicit_commit_helper.in
 create table t4 (a varchar(100));
 
 let $statement=
-  load data infile '../std_data_ln/words.dat' into table t4;
+  load data infile '../../std_data/words.dat' into table t4;
 source include/implicit_commit_helper.inc;
 
 drop table t4;

=== modified file 'mysql-test/t/information_schema-master.opt'
--- a/mysql-test/t/information_schema-master.opt	2007-11-30 03:26:57 +0000
+++ b/mysql-test/t/information_schema-master.opt	2008-07-29 10:45:39 +0000
@@ -6,7 +6,6 @@
 --loose-skip-plugin-falcon_syncobjects
 --loose-skip-plugin-falcon_system_memory_detail
 --loose-skip-plugin-falcon_system_memory_summary
---loose-skip-plugin-falcon_tables
 --loose-skip-plugin-falcon_transaction_summary
 --loose-skip-plugin-falcon_transactions
 --loose-skip-plugin-falcon_version

=== modified file 'mysql-test/t/information_schema_db-master.opt'
--- a/mysql-test/t/information_schema_db-master.opt	2007-11-30 03:26:57 +0000
+++ b/mysql-test/t/information_schema_db-master.opt	2008-07-29 10:45:39 +0000
@@ -6,7 +6,6 @@
 --loose-skip-plugin-falcon_syncobjects
 --loose-skip-plugin-falcon_system_memory_detail
 --loose-skip-plugin-falcon_system_memory_summary
---loose-skip-plugin-falcon_tables
 --loose-skip-plugin-falcon_transaction_summary
 --loose-skip-plugin-falcon_transactions
 --loose-skip-plugin-falcon_version

=== modified file 'mysql-test/t/mysqlshow-master.opt'
--- a/mysql-test/t/mysqlshow-master.opt	2007-11-30 03:26:57 +0000
+++ b/mysql-test/t/mysqlshow-master.opt	2008-07-29 10:45:39 +0000
@@ -6,7 +6,6 @@
 --loose-skip-plugin-falcon_syncobjects
 --loose-skip-plugin-falcon_system_memory_detail
 --loose-skip-plugin-falcon_system_memory_summary
---loose-skip-plugin-falcon_tables
 --loose-skip-plugin-falcon_transaction_summary
 --loose-skip-plugin-falcon_transactions
 --loose-skip-plugin-falcon_version

=== modified file 'mysql-test/t/perror.test'
--- a/mysql-test/t/perror.test	2006-08-01 09:29:10 +0000
+++ b/mysql-test/t/perror.test	2008-08-05 23:26:18 +0000
@@ -17,3 +17,17 @@ enable_query_log;
 # As there is no error code defined for 10000, expect error
 --error 1
 --exec $MY_PERROR 10000 2>&1
+
+#
+# Bug#10143 (Perror not showing error description)
+#
+
+# test reported case
+--exec $MY_PERROR 1062 2>&1
+
+# test errors that contain characters to escape in the text.
+--exec $MY_PERROR 1076 2>&1
+--exec $MY_PERROR 1459 2>&1
+--exec $MY_PERROR 1461 2>&1
+
+

=== modified file 'mysql-test/t/sp-error.test'
--- a/mysql-test/t/sp-error.test	2008-08-07 20:51:09 +0000
+++ b/mysql-test/t/sp-error.test	2008-08-27 12:49:58 +0000
@@ -2396,6 +2396,42 @@ end$$
 
 delimiter ;$$
 
+#
+# Bug#36510 (Stored Procedures: mysql_error_code 0 should be illegal)
+#
+
+--disable_warnings
+drop procedure if exists proc_36510;
+--enable_warnings
+
+delimiter $$;
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_36510()
+begin
+  declare should_be_illegal condition for sqlstate '00123';
+  declare continue handler for should_be_illegal set @x=0;
+end$$
+
+--error ER_SP_BAD_SQLSTATE
+create procedure proc_36510()
+begin
+  declare continue handler for sqlstate '00123' set @x=0;
+end$$
+
+--error ER_WRONG_VALUE
+create procedure proc_36510()
+begin
+  declare should_be_illegal condition for 0;
+  declare continue handler for should_be_illegal set @x=0;
+end$$
+
+--error ER_WRONG_VALUE
+create procedure proc_36510()
+begin
+  declare continue handler for 0 set @x=0;
+end$$
+delimiter ;$$
 
 #
 # Bug#15192: "fatal errors" are caught by handlers in stored procedures

=== added file 'mysql-test/t/sp-no-code.test'
--- a/mysql-test/t/sp-no-code.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/sp-no-code.test	2008-07-24 16:50:18 +0000
@@ -0,0 +1,12 @@
+#
+# Test the debugging feature "show procedure/function code <name>" 
+#
+
+-- source include/have_nodebug.inc
+
+--error ER_FEATURE_DISABLED
+show procedure code foo;
+
+--error ER_FEATURE_DISABLED
+show function code foo;
+

=== modified file 'mysql-test/t/subselect.test'
--- a/mysql-test/t/subselect.test	2008-08-22 17:03:15 +0000
+++ b/mysql-test/t/subselect.test	2008-08-27 12:49:58 +0000
@@ -810,15 +810,12 @@ create table t1 (a int, b int, index a (
 create table t2 (a int, index a (a));
 create table t3 (a int, b int, index a (a));
 insert into t1 values (1,10), (2,20), (3,30), (4,40);
-disable_query_log;
 # making table large enough
-let $1 = 10000;
-while ($1)
- {
-  eval insert into t1 values (rand()*100000+200,rand()*100000); 
-  dec $1;
- }
-enable_query_log;
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+insert into t1
+select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D;
+
 insert into t2 values (2), (3), (4), (5);
 insert into t3 values (10,3), (20,4), (30,5);
 select * from t2 where t2.a in (select a from t1);
@@ -831,7 +828,7 @@ insert into t1 values (3,31);
 select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
 select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
-drop table t1, t2, t3;
+drop table t0, t1, t2, t3;
 
 #
 # alloc_group_fields() working
@@ -3184,24 +3181,21 @@ DROP TABLE t1,t2;
 # Bug#33675: Usage of an uninitialized memory by filesort in a subquery
 #            caused server crash.
 #
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
 create table t1(f11 int, f12 int);
 create table t2(f21 int unsigned not null, f22 int, f23 varchar(10));
 insert into t1 values(1,1),(2,2), (3, 3);
-let $i=10000;
---disable_query_log
 --disable_warnings
-while ($i)
-{
-  eval insert into t2 values (-1 , $i/5000 + 1, '$i');
-  dec $i;
-}
+insert into t2 
+select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a 
+from t0 A, t0 B, t0 C, t0 D;
 --enable_warnings
---enable_query_log
 set session sort_buffer_size= 33*1024;
 select count(*) from t1 where f12 = 
 (select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1);
 
-drop table t1,t2;
+drop table t0,t1,t2;
 
 #
 # BUG#33794 "MySQL crashes executing specific query on specific dump"
@@ -3510,6 +3504,19 @@ DROP TABLE t1,t2;
 --echo End of 5.0 tests.
 
 #
+# Bug #38191: Server crash with subquery containing DISTINCT and ORDER BY
+#
+
+CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
+INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
+CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
+INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
+SELECT * FROM t1
+   WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
+DROP TABLE t1,t2;
+
+
+#
 # Bug#33204: INTO is allowed in subselect, causing inconsistent results
 #
 CREATE TABLE t1( a INT );
@@ -3735,16 +3742,5 @@ SELECT * FROM t1 WHERE EXISTS ( SELECT 1
 SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
 
 DROP TABLE t1, t2;
-#
-# Bug #38191: Server crash with subquery containing DISTINCT and ORDER BY
-#
-
-CREATE TABLE t1(pk int PRIMARY KEY, a int, INDEX idx(a));
-INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20);
-CREATE TABLE t2(pk int PRIMARY KEY, a int, b int, INDEX idxa(a));
-INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100);
-SELECT * FROM t1
-   WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b);
-DROP TABLE t1,t2;
 
 --echo End of 5.1 tests.

=== added file 'mysql-test/t/subselect_nulls.test'
--- a/mysql-test/t/subselect_nulls.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/subselect_nulls.test	2008-08-18 12:45:37 +0000
@@ -0,0 +1,94 @@
+-- Initialize tables for the test
+
+--disable_warnings
+drop table if exists x1;
+drop table if exists x2;
+--enable_warnings
+
+create table x1(k int primary key, d1 int, d2 int);
+create table x2(k int primary key, d1 int, d2 int);
+
+insert into x1 values
+    (10,   10,   10),
+    (20,   20,   20),
+    (21,   20,   null),
+    (30,   null, 30),
+    (40,   40,   40);
+insert into x2 values
+    (10,   10,   10),
+    (20,   20,   20),
+    (21,   20,   null),
+    (30,   null, 30);
+
+-- Test various IN and EXISTS queries with NULL values and UNKNOWN
+-- Q1 T=(10, 20) U=(21,30) F=(40)
+select *
+from x1
+where (d1, d2) in (select d1, d2
+                   from x2);
+select *
+from x1
+where (d1, d2) in (select d1, d2
+                   from x2) is true;
+select *
+from x1
+where (d1, d2) in (select d1, d2
+                   from x2) is false;
+select *
+from x1
+where (d1, d2) in (select d1, d2
+                   from x2) is unknown;
+
+-- Q2 T=(10, 20) U=(30) F=(21, 40)
+select *
+from x1
+where d1 in (select d1
+             from x2
+             where x1.d2=x2.d2);
+select *
+from x1
+where d1 in (select d1
+             from x2
+             where x1.d2=x2.d2) is true;
+select *
+from x1
+where d1 in (select d1
+             from x2
+             where x1.d2=x2.d2) is false;
+select *
+from x1
+where d1 in (select d1
+             from x2
+             where x1.d2=x2.d2) is unknown;
+
+-- Q3 T=(10, 20) U=() F=(21, 30, 40)
+select *
+from x1
+where 1 in (select 1
+            from x2
+            where x1.d1=x2.d1 and x1.d2=x2.d2);
+select *
+from x1
+where 1 in (select 1
+            from x2
+            where x1.d1=x2.d1 and x1.d2=x2.d2) is true;
+select *
+from x1
+where 1 in (select 1
+            from x2
+            where x1.d1=x2.d1 and x1.d2=x2.d2) is false;
+select *
+from x1
+where 1 in (select 1
+            from x2
+            where x1.d1=x2.d1 and x1.d2=x2.d2) is unknown;
+
+-- Q4 T=(10, 20) F=(21, 30, 40)
+select *
+from x1
+where exists (select *
+              from x2
+              where x1.d1=x2.d1 and x1.d2=x2.d2);
+
+drop table x1;
+drop table x2;

=== modified file 'mysql-test/t/subselect_sj.test'
--- a/mysql-test/t/subselect_sj.test	2008-05-01 03:53:36 +0000
+++ b/mysql-test/t/subselect_sj.test	2008-06-11 23:16:53 +0000
@@ -92,5 +92,36 @@ execute s1;
 insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
 explain extended select * from t1 where a in (select pk from t10 where pk<3);
 
+--echo
+--echo BUG#37120 optimizer_switch allowable values not according to specification
+--echo
+
+select @@optimizer_switch; 
+
+set optimizer_switch='no_materialization';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_semijoin';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_loosescan';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_semijoin,no_materialization';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_materialization,no_semijoin';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_semijoin,no_materialization,no_loosescan';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_semijoin,no_loosescan';
+select @@optimizer_switch; 
+
+set optimizer_switch='no_materialization,no_loosescan';
+select @@optimizer_switch; 
+set optimizer_switch='';
+
 drop table t0, t1;
 drop table t10, t11, t12;

=== modified file 'mysql-test/t/subselect_sj2.test'
--- a/mysql-test/t/subselect_sj2.test	2008-05-03 08:27:47 +0000
+++ b/mysql-test/t/subselect_sj2.test	2008-07-10 16:02:38 +0000
@@ -271,11 +271,11 @@ insert into t2 (ID, Name, CountryCode, P
 (1,'Kabul','AFG',1780000), (2,'Qandahar','AFG',237500), (3,'Herat','AFG',186800),
 (4,'Mazar-e-Sharif','AFG',127800), (33,'Willemstad','ANT',2345), (34,'Tirana','ALB',270000),
 (55,'Andorra la Vella','AND',21189), (61,'South Hill','AIA',961), (62,'The Valley','AIA',595),
-(63,'Saint John�s','ATG',24000), (64,'Dubai','ARE',669181), (65,'Abu Dhabi','ARE',398695),
+(63,'Saint John�s','ATG',24000), (64,'Dubai','ARE',669181), (65,'Abu Dhabi','ARE',398695),
 (66,'Sharja','ARE',320095), (67,'al-Ayn','ARE',225970), (68,'Ajman','ARE',114395),
 (126,'Yerevan','ARM',1248700), (127,'Gjumri','ARM',211700), (128,'Vanadzor','ARM',172700),
-(129,'Oranjestad','ABW',29034), (144,'Baku','AZE',1787800), (145,'G��'AZE',299300),
-(146,'Sumqayit','AZE',283000), (147,'Ming�vir','AZE',93900), (148,'Nassau','BHS',172000),
+(129,'Oranjestad','ABW',29034), (144,'Baku','AZE',1787800), (145,'G�nc�','AZE',299300),
+(146,'Sumqayit','AZE',283000), (147,'Ming��evir','AZE',93900), (148,'Nassau','BHS',172000),
 (149,'al-Manama','BHR',148000), (150,'Dhaka','BGD',3612850), (151,'Chittagong','BGD',1392860),
 (152,'Khulna','BGD',663340), (153,'Rajshahi','BGD',294056), (154,'Narayanganj','BGD',202134),
 (155,'Rangpur','BGD',191398), (156,'Mymensingh','BGD',188713), (157,'Barisal','BGD',170232),
@@ -285,7 +285,7 @@ insert into t2 (ID, Name, CountryCode, P
 (167,'Jamalpur','BGD',103556), (168,'Pabna','BGD',103277), (169,'Naogaon','BGD',101266),
 (170,'Sirajganj','BGD',99669), (171,'Narsinghdi','BGD',98342), (172,'Saidpur','BGD',96777),
 (173,'Gazipur','BGD',96717), (174,'Bridgetown','BRB',6070), (175,'Antwerpen','BEL',446525),
-(176,'Gent','BEL',224180), (177,'Charleroi','BEL',200827), (178,'Li�','BEL',185639),
+(176,'Gent','BEL',224180), (177,'Charleroi','BEL',200827), (178,'Li�ge','BEL',185639),
 (179,'Bruxelles [Brussel]','BEL',133859), (180,'Brugge','BEL',116246), (181,'Schaerbeek','BEL',105692),
 (182,'Namur','BEL',105419), (183,'Mons','BEL',90935), (184,'Belize City','BLZ',55810),
 (185,'Belmopan','BLZ',7105), (190,'Saint George','BMU',1800), (191,'Hamilton','BMU',1200),
@@ -293,10 +293,10 @@ insert into t2 (ID, Name, CountryCode, P
 (203,'Zenica','BIH',96027), (538,'Bandar Seri Begawan','BRN',21484), (539,'Sofija','BGR',1122302),
 (540,'Plovdiv','BGR',342584), (541,'Varna','BGR',299801), (542,'Burgas','BGR',195255),
 (543,'Ruse','BGR',166467), (544,'Stara Zagora','BGR',147939), (545,'Pleven','BGR',121952),
-(546,'Sliven','BGR',105530), (547,'Dobric','BGR',100399), (548,'�umen','BGR',94686),
-(553,'George Town','CYM',19600), (584,'San Jos�'CRI',339131), (1523,'Wien','AUT',1608144),
+(546,'Sliven','BGR',105530), (547,'Dobric','BGR',100399), (548,'�umen','BGR',94686),
+(553,'George Town','CYM',19600), (584,'San Jos�','CRI',339131), (1523,'Wien','AUT',1608144),
 (1524,'Graz','AUT',240967), (1525,'Linz','AUT',188022), (1526,'Salzburg','AUT',144247),
-(1527,'Innsbruck','AUT',111752), (1528,'Klagenfurt','AUT',91141), (1810,'Montr�','CAN',1016376),
+(1527,'Innsbruck','AUT',111752), (1528,'Klagenfurt','AUT',91141), (1810,'Montr�al','CAN',1016376),
 (1811,'Calgary','CAN',768082), (1812,'Toronto','CAN',688275), (1813,'North York','CAN',622632),
 (1814,'Winnipeg','CAN',618477), (1815,'Edmonton','CAN',616306), (1816,'Mississauga','CAN',608072),
 (1817,'Scarborough','CAN',594501), (1818,'Vancouver','CAN',514008), (1819,'Etobicoke','CAN',348845),
@@ -304,25 +304,25 @@ insert into t2 (ID, Name, CountryCode, P
 (1823,'Laval','CAN',330393), (1824,'Surrey','CAN',304477), (1825,'Brampton','CAN',296711),
 (1826,'Windsor','CAN',207588), (1827,'Saskatoon','CAN',193647), (1828,'Kitchener','CAN',189959),
 (1829,'Markham','CAN',189098), (1830,'Regina','CAN',180400), (1831,'Burnaby','CAN',179209),
-(1832,'Qu�c','CAN',167264), (1833,'York','CAN',154980), (1834,'Richmond','CAN',148867),
+(1832,'Qu�bec','CAN',167264), (1833,'York','CAN',154980), (1834,'Richmond','CAN',148867),
 (1835,'Vaughan','CAN',147889), (1836,'Burlington','CAN',145150), (1837,'Oshawa','CAN',140173),
 (1838,'Oakville','CAN',139192), (1839,'Saint Catharines','CAN',136216), (1840,'Longueuil','CAN',127977),
 (1841,'Richmond Hill','CAN',116428), (1842,'Thunder Bay','CAN',115913), (1843,'Nepean','CAN',115100),
 (1844,'Cape Breton','CAN',114733), (1845,'East York','CAN',114034), (1846,'Halifax','CAN',113910),
 (1847,'Cambridge','CAN',109186), (1848,'Gloucester','CAN',107314), (1849,'Abbotsford','CAN',105403),
-(1850,'Guelph','CAN',103593), (1851,'Saint John�s','CAN',101936), (1852,'Coquitlam','CAN',101820),
+(1850,'Guelph','CAN',103593), (1851,'Saint John�s','CAN',101936), (1852,'Coquitlam','CAN',101820),
 (1853,'Saanich','CAN',101388), (1854,'Gatineau','CAN',100702), (1855,'Delta','CAN',95411),
 (1856,'Sudbury','CAN',92686), (1857,'Kelowna','CAN',89442), (1858,'Barrie','CAN',89269),
 (1890,'Shanghai','CHN',9696300), (1891,'Peking','CHN',7472000), (1892,'Chongqing','CHN',6351600),
 (1893,'Tianjin','CHN',5286800), (1894,'Wuhan','CHN',4344600), (1895,'Harbin','CHN',4289800),
 (1896,'Shenyang','CHN',4265200), (1897,'Kanton [Guangzhou]','CHN',4256300), (1898,'Chengdu','CHN',3361500),
-(1899,'Nanking [Nanjing]','CHN',2870300), (1900,'Changchun','CHN',2812000), (1901,'Xi�an','CHN',2761400),
+(1899,'Nanking [Nanjing]','CHN',2870300), (1900,'Changchun','CHN',2812000), (1901,'Xi�an','CHN',2761400),
 (1902,'Dalian','CHN',2697000), (1903,'Qingdao','CHN',2596000), (1904,'Jinan','CHN',2278100),
 (1905,'Hangzhou','CHN',2190500), (1906,'Zhengzhou','CHN',2107200), (1907,'Shijiazhuang','CHN',2041500),
 (1908,'Taiyuan','CHN',1968400), (1909,'Kunming','CHN',1829500), (1910,'Changsha','CHN',1809800),
 (1911,'Nanchang','CHN',1691600), (1912,'Fuzhou','CHN',1593800), (1913,'Lanzhou','CHN',1565800),
 (1914,'Guiyang','CHN',1465200), (1915,'Ningbo','CHN',1371200), (1916,'Hefei','CHN',1369100),
-(1917,'Urumt�i [��,'CHN',1310100), (1918,'Anshan','CHN',1200000), (1919,'Fushun','CHN',1200000),
+(1917,'Urumt�i [�r�mqi]','CHN',1310100), (1918,'Anshan','CHN',1200000), (1919,'Fushun','CHN',1200000),
 (1920,'Nanning','CHN',1161800), (1921,'Zibo','CHN',1140000), (1922,'Qiqihar','CHN',1070000),
 (1923,'Jilin','CHN',1040000), (1924,'Tangshan','CHN',1040000), (1925,'Baotou','CHN',980000),
 (1926,'Shenzhen','CHN',950500), (1927,'Hohhot','CHN',916700), (1928,'Handan','CHN',840000),
@@ -346,12 +346,12 @@ insert into t2 (ID, Name, CountryCode, P
 (1980,'Zhenjiang','CHN',368316), (1981,'Huaibei','CHN',366549), (1982,'Qinhuangdao','CHN',364972),
 (1983,'Guilin','CHN',364130), (1984,'Liupanshui','CHN',363954), (1985,'Panjin','CHN',362773),
 (1986,'Yangquan','CHN',362268), (1987,'Jinxi','CHN',357052), (1988,'Liaoyuan','CHN',354141),
-(1989,'Lianyungang','CHN',354139), (1990,'Xianyang','CHN',352125), (1991,'Tai�an','CHN',350696),
+(1989,'Lianyungang','CHN',354139), (1990,'Xianyang','CHN',352125), (1991,'Tai�an','CHN',350696),
 (1992,'Chifeng','CHN',350077), (1993,'Shaoguan','CHN',350043), (1994,'Nantong','CHN',343341),
 (1995,'Leshan','CHN',341128), (1996,'Baoji','CHN',337765), (1997,'Linyi','CHN',324720),
 (1998,'Tonghua','CHN',324600), (1999,'Siping','CHN',317223), (2000,'Changzhi','CHN',317144),
 (2001,'Tengzhou','CHN',315083), (2002,'Chaozhou','CHN',313469), (2003,'Yangzhou','CHN',312892),
-(2004,'Dongwan','CHN',308669), (2005,'Ma�anshan','CHN',305421), (2006,'Foshan','CHN',303160),
+(2004,'Dongwan','CHN',308669), (2005,'Ma�anshan','CHN',305421), (2006,'Foshan','CHN',303160),
 (2007,'Yueyang','CHN',302800), (2008,'Xingtai','CHN',302789), (2009,'Changde','CHN',301276),
 (2010,'Shihezi','CHN',299676), (2011,'Yancheng','CHN',296831), (2012,'Jiujiang','CHN',291187),
 (2013,'Dongying','CHN',281728), (2014,'Shashi','CHN',281352), (2015,'Xintai','CHN',281248),
@@ -371,7 +371,7 @@ insert into t2 (ID, Name, CountryCode, P
 (2055,'Jiangyin','CHN',213659), (2056,'Hebi','CHN',212976), (2057,'Jiaxing','CHN',211526),
 (2058,'Wuzhou','CHN',210452), (2059,'Meihekou','CHN',209038), (2060,'Xuchang','CHN',208815),
 (2061,'Liaocheng','CHN',207844), (2062,'Haicheng','CHN',205560), (2063,'Qianjiang','CHN',205504),
-(2064,'Baiyin','CHN',204970), (2065,'Bei�an','CHN',204899), (2066,'Yixing','CHN',200824),
+(2064,'Baiyin','CHN',204970), (2065,'Bei�an','CHN',204899), (2066,'Yixing','CHN',200824),
 (2067,'Laizhou','CHN',198664), (2068,'Qaramay','CHN',197602), (2069,'Acheng','CHN',197595),
 (2070,'Dezhou','CHN',195485), (2071,'Nanping','CHN',195064), (2072,'Zhaoqing','CHN',194784),
 (2073,'Beipiao','CHN',194301), (2074,'Fengcheng','CHN',193784), (2075,'Fuyu','CHN',192981),
@@ -392,21 +392,21 @@ insert into t2 (ID, Name, CountryCode, P
 (2118,'Xiaoshan','CHN',162930), (2119,'Zaoyang','CHN',162198), (2120,'Xinghua','CHN',161910),
 (2121,'Hami','CHN',161315), (2122,'Huizhou','CHN',161023), (2123,'Jinmen','CHN',160794),
 (2124,'Sanming','CHN',160691), (2125,'Ulanhot','CHN',159538), (2126,'Korla','CHN',159344),
-(2127,'Wanxian','CHN',156823), (2128,'Rui�an','CHN',156468), (2129,'Zhoushan','CHN',156317),
+(2127,'Wanxian','CHN',156823), (2128,'Rui�an','CHN',156468), (2129,'Zhoushan','CHN',156317),
 (2130,'Liangcheng','CHN',156307), (2131,'Jiaozhou','CHN',153364), (2132,'Taizhou','CHN',152442),
 (2133,'Suzhou','CHN',151862), (2134,'Yichun','CHN',151585), (2135,'Taonan','CHN',150168),
-(2136,'Pingdu','CHN',150123), (2137,'Ji�an','CHN',148583), (2138,'Longkou','CHN',148362),
+(2136,'Pingdu','CHN',150123), (2137,'Ji�an','CHN',148583), (2138,'Longkou','CHN',148362),
 (2139,'Langfang','CHN',148105), (2140,'Zhoukou','CHN',146288), (2141,'Suining','CHN',146086),
-(2142,'Yulin','CHN',144467), (2143,'Jinhua','CHN',144280), (2144,'Liu�an','CHN',144248),
+(2142,'Yulin','CHN',144467), (2143,'Jinhua','CHN',144280), (2144,'Liu�an','CHN',144248),
 (2145,'Shuangcheng','CHN',142659), (2146,'Suizhou','CHN',142302), (2147,'Ankang','CHN',142170),
-(2148,'Weinan','CHN',140169), (2149,'Longjing','CHN',139417), (2150,'Da�an','CHN',138963),
+(2148,'Weinan','CHN',140169), (2149,'Longjing','CHN',139417), (2150,'Da�an','CHN',138963),
 (2151,'Lengshuijiang','CHN',137994), (2152,'Laiyang','CHN',137080), (2153,'Xianning','CHN',136811),
 (2154,'Dali','CHN',136554), (2155,'Anda','CHN',136446), (2156,'Jincheng','CHN',136396),
 (2157,'Longyan','CHN',134481), (2158,'Xichang','CHN',134419), (2159,'Wendeng','CHN',133910),
 (2160,'Hailun','CHN',133565), (2161,'Binzhou','CHN',133555), (2162,'Linhe','CHN',133183),
 (2163,'Wuwei','CHN',133101), (2164,'Duyun','CHN',132971), (2165,'Mishan','CHN',132744),
 (2166,'Shangrao','CHN',132455), (2167,'Changji','CHN',132260), (2168,'Meixian','CHN',132156),
-(2169,'Yushu','CHN',131861), (2170,'Tiefa','CHN',131807), (2171,'Huai�an','CHN',131149),
+(2169,'Yushu','CHN',131861), (2170,'Tiefa','CHN',131807), (2171,'Huai�an','CHN',131149),
 (2172,'Leiyang','CHN',130115), (2173,'Zalantun','CHN',130031), (2174,'Weihai','CHN',128888),
 (2175,'Loudi','CHN',128418), (2176,'Qingzhou','CHN',128258), (2177,'Qidong','CHN',126872),
 (2178,'Huaihua','CHN',126785), (2179,'Luohe','CHN',126438), (2180,'Chuzhou','CHN',125341),
@@ -417,39 +417,39 @@ insert into t2 (ID, Name, CountryCode, P
 (2193,'Lianyuan','CHN',118858), (2194,'Kuytun','CHN',118553), (2195,'Puqi','CHN',117264),
 (2196,'Hongjiang','CHN',116188), (2197,'Qinzhou','CHN',114586), (2198,'Renqiu','CHN',114256),
 (2199,'Yuyao','CHN',114065), (2200,'Guigang','CHN',114025), (2201,'Kaili','CHN',113958),
-(2202,'Yan�an','CHN',113277), (2203,'Beihai','CHN',112673), (2204,'Xuangzhou','CHN',112673),
-(2205,'Quzhou','CHN',112373), (2206,'Yong�an','CHN',111762), (2207,'Zixing','CHN',110048),
+(2202,'Yan�an','CHN',113277), (2203,'Beihai','CHN',112673), (2204,'Xuangzhou','CHN',112673),
+(2205,'Quzhou','CHN',112373), (2206,'Yong�an','CHN',111762), (2207,'Zixing','CHN',110048),
 (2208,'Liyang','CHN',109520), (2209,'Yizheng','CHN',109268), (2210,'Yumen','CHN',109234),
 (2211,'Liling','CHN',108504), (2212,'Yuncheng','CHN',108359), (2213,'Shanwei','CHN',107847),
 (2214,'Cixi','CHN',107329), (2215,'Yuanjiang','CHN',107004), (2216,'Bozhou','CHN',106346),
-(2217,'Jinchang','CHN',105287), (2218,'Fu�an','CHN',105265), (2219,'Suqian','CHN',105021),
+(2217,'Jinchang','CHN',105287), (2218,'Fu�an','CHN',105265), (2219,'Suqian','CHN',105021),
 (2220,'Shishou','CHN',104571), (2221,'Hengshui','CHN',104269), (2222,'Danjiangkou','CHN',103211),
 (2223,'Fujin','CHN',103104), (2224,'Sanya','CHN',102820), (2225,'Guangshui','CHN',102770),
 (2226,'Huangshan','CHN',102628), (2227,'Xingcheng','CHN',102384), (2228,'Zhucheng','CHN',102134),
 (2229,'Kunshan','CHN',102052), (2230,'Haining','CHN',100478), (2231,'Pingliang','CHN',99265),
 (2232,'Fuqing','CHN',99193), (2233,'Xinzhou','CHN',98667), (2234,'Jieyang','CHN',98531),
-(2235,'Zhangjiagang','CHN',97994), (2236,'Tong Xian','CHN',97168), (2237,'Ya�an','CHN',95900),
+(2235,'Zhangjiagang','CHN',97994), (2236,'Tong Xian','CHN',97168), (2237,'Ya�an','CHN',95900),
 (2238,'Jinzhou','CHN',95761), (2239,'Emeishan','CHN',94000), (2240,'Enshi','CHN',93056),
 (2241,'Bose','CHN',93009), (2242,'Yuzhou','CHN',92889), (2243,'Kaiyuan','CHN',91999),
 (2244,'Tumen','CHN',91471), (2245,'Putian','CHN',91030), (2246,'Linhai','CHN',90870),
 (2247,'Xilin Hot','CHN',90646), (2248,'Shaowu','CHN',90286), (2249,'Junan','CHN',90222),
 (2250,'Huaying','CHN',89400), (2251,'Pingyi','CHN',89373), (2252,'Huangyan','CHN',89288),
-(2413,'La Habana','CUB',2256000), (2414,'Santiago de Cuba','CUB',433180), (2415,'Camag�CUB',298726),
-(2416,'Holgu�,'CUB',249492), (2417,'Santa Clara','CUB',207350), (2418,'Guant, (2420,'Bayamo','CUB',141000), (2421,'Cienfuegos','CUB',132770),
+(2413,'La Habana','CUB',2256000), (2414,'Santiago de Cuba','CUB',433180), (2415,'Camag�ey','CUB',298726),
+(2416,'Holgu�n','CUB',249492), (2417,'Santa Clara','CUB',207350), (2418,'Guant�namo','CUB',205078),
+(2419,'Pinar del R�o','CUB',142100), (2420,'Bayamo','CUB',141000), (2421,'Cienfuegos','CUB',132770),
 (2422,'Victoria de las Tunas','CUB',132350), (2423,'Matanzas','CUB',123273), (2424,'Manzanillo','CUB',109350),
-(2425,'Sancti-Sp�tus','CUB',100751), (2426,'Ciego de �ila','CUB',98505), (2430,'Nicosia','CYP',195000),
-(2431,'Limassol','CYP',154400), (3245,'Z�,'CHE',336800), (3246,'Geneve','CHE',173500),
+(2425,'Sancti-Sp�ritus','CUB',100751), (2426,'Ciego de �vila','CUB',98505), (2430,'Nicosia','CYP',195000),
+(2431,'Limassol','CYP',154400), (3245,'Z�rich','CHE',336800), (3246,'Geneve','CHE',173500),
 (3247,'Basel','CHE',166700), (3248,'Bern','CHE',122700), (3249,'Lausanne','CHE',114500),
 (3339,'Praha','CZE',1181126), (3340,'Brno','CZE',381862), (3341,'Ostrava','CZE',320041),
 (3342,'Plzen','CZE',166759), (3343,'Olomouc','CZE',102702), (3344,'Liberec','CZE',99155),
-(3345,'Cesk�udejovice','CZE',98186), (3346,'Hradec Kr�v�'CZE',98080), (3347,'�t�ad Labem','CZE',95491),
+(3345,'Cesk� Budejovice','CZE',98186), (3346,'Hradec Kr�lov�','CZE',98080), (3347,'�st� nad Labem','CZE',95491),
 (3348,'Pardubice','CZE',91309), (3520,'Minsk','BLR',1674000), (3521,'Gomel','BLR',475000),
 (3522,'Mogiljov','BLR',356000), (3523,'Vitebsk','BLR',340000), (3524,'Grodno','BLR',302000),
-(3525,'Brest','BLR',286000), (3526,'Bobruisk','BLR',221000), (3527,'Baranovit�i','BLR',167000),
-(3528,'Borisov','BLR',151000), (3529,'Pinsk','BLR',130000), (3530,'Or�a','BLR',124000),
+(3525,'Brest','BLR',286000), (3526,'Bobruisk','BLR',221000), (3527,'Baranovit�i','BLR',167000),
+(3528,'Borisov','BLR',151000), (3529,'Pinsk','BLR',130000), (3530,'Or�a','BLR',124000),
 (3531,'Mozyr','BLR',110000), (3532,'Novopolotsk','BLR',106000), (3533,'Lida','BLR',101000),
-(3534,'Soligorsk','BLR',101000), (3535,'Molodet�no','BLR',97000);
+(3534,'Soligorsk','BLR',101000), (3535,'Molodet�no','BLR',97000);
 
 insert into t1 (Code, Name, Continent) values 
 ('AFG','Afghanistan','Asia'), ('ANT','Netherlands Antilles','North America'),
@@ -837,3 +837,25 @@ delimiter ;|
 call p1();
 drop procedure p1;
 drop table t1;
+
+#
+# BUG#35468 "Slowdown and wrong result for uncorrelated subquery w/o where"
+#
+
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int) as select A.a + 10 *(B.a + 10*C.a) as a  from t0 A, t0 B, t0 C;
+create table t2 (id int, a int, primary key(id), key(a)) as select a as id, a as a  from t1;
+show create table t2;
+set @a=0;
+create table t3 as select * from t2 limit 0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+insert into t3 select @a:=@a+1, t2.a from t2, t0;
+
+alter table t3 add primary key(id), add key(a);
+--echo The following must use loose index scan over t3, key a:
+explain select count(a) from t2 where a in ( SELECT  a FROM t3);
+select count(a) from t2 where a in ( SELECT  a FROM t3);
+
+drop table t0,t1,t2,t3;

=== modified file 'mysql-test/t/variables-master.opt'
--- a/mysql-test/t/variables-master.opt	2007-09-28 19:51:23 +0000
+++ b/mysql-test/t/variables-master.opt	2008-07-29 10:45:39 +0000
@@ -6,6 +6,5 @@
 --loose-skip-plugin-falcon_syncobjects
 --loose-skip-plugin-falcon_system_memory_detail
 --loose-skip-plugin-falcon_system_memory_summary
---loose-skip-plugin-falcon_tables
 --loose-skip-plugin-falcon_transaction_summary
 --loose-skip-plugin-falcon_transactions

=== modified file 'mysys/charset.c'
--- a/mysys/charset.c	2008-02-19 21:53:33 +0000
+++ b/mysys/charset.c	2008-07-24 11:33:35 +0000
@@ -410,7 +410,7 @@ char *get_charsets_dir(char *buf)
   DBUG_RETURN(res);
 }
 
-CHARSET_INFO *all_charsets[256];
+CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
 CHARSET_INFO *default_charset_info = &my_charset_latin1;
 
 void add_compiled_collation(CHARSET_INFO *cs)

=== modified file 'scripts/mysql_system_tables.sql'
--- a/scripts/mysql_system_tables.sql	2008-08-22 17:03:15 +0000
+++ b/scripts/mysql_system_tables.sql	2008-08-27 12:49:58 +0000
@@ -83,10 +83,10 @@ DROP PREPARE stmt;
 CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode  set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator int(10) NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
 
 
-CREATE TABLE IF NOT EXISTS online_backup ( backup_id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT COMMENT 'Surrogate key for (near) duplicate entries', process_id INT UNSIGNED NOT NULL COMMENT 'The process id that operation ran as', binlog_pos INT UNSIGNED DEFAULT 0 COMMENT 'The recorded binlog position of backup/restore', binlog_file CHAR(64) COMMENT 'The recorded binlog filename at time of backup/restore', backup_state ENUM('complete', 'starting', 'validity point', 'running', 'error', 'cancel') NOT NULL COMMENT 'Status of current operation', operation ENUM('backup', 'restore') NOT NULL COMMENT 'Type of operation', error_num INT NOT NULL DEFAULT 0 COMMENT 'The error from this run 0 == none', num_objects INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'The number of objects in the backup', total_bytes BIGINT UNSIGNED COMMENT 'The size of the backup repository in bytes', validity_point_time datetime COMMENT 'The time of the validity point.', start_time datetime COMMENT 'The date/time of start of operation', stop_time datetime COMMENT 'The date/time of end of operation', host_or_server_name CHAR (30) COMMENT 'The server name where operation ran', username CHAR (30) COMMENT 'The user name who ran the operation', backup_file CHAR (100) COMMENT 'The name of the file', user_comment VARCHAR (200) DEFAULT NULL COMMENT 'The comment from user entered at command line', command VARCHAR (512) COMMENT 'The command used to issue operation', drivers VARCHAR (100) COMMENT 'The name of the storage engine backup drivers used in the operation') ENGINE=MYISAM;
+CREATE TABLE IF NOT EXISTS online_backup ( backup_id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT COMMENT 'Surrogate key for (near) duplicate entries', process_id INT UNSIGNED NOT NULL COMMENT 'The process id that operation ran as', binlog_pos INT UNSIGNED DEFAULT 0 COMMENT 'The recorded binlog position of backup/restore', binlog_file CHAR(64) COMMENT 'The recorded binlog filename at time of backup/restore', backup_state ENUM('complete', 'starting', 'validity point', 'running', 'error', 'cancel') NOT NULL COMMENT 'Status of current operation', operation ENUM('backup', 'restore') NOT NULL COMMENT 'Type of operation', error_num INT NOT NULL DEFAULT 0 COMMENT 'The error from this run 0 == none', num_objects INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'The number of objects in the backup', total_bytes BIGINT UNSIGNED COMMENT 'The size of the backup repository in bytes', validity_point_time datetime COMMENT 'The time of the validity point.', start_time datetime COMMENT 'The date/time of start of operation', stop_time datetime COMMENT 'The date/time of end of operation', host_or_server_name CHAR (30) COMMENT 'The server name where operation ran', username CHAR (30) COMMENT 'The user name who ran the operation', backup_file CHAR (100) COMMENT 'The name of the file', user_comment VARCHAR (200) DEFAULT NULL COMMENT 'The comment from user entered at command line', command VARCHAR (512) COMMENT 'The command used to issue operation', drivers VARCHAR (100) COMMENT 'The name of the storage engine backup drivers used in the operation') ENGINE=MYISAM DEFAULT CHARACTER SET utf8;
 
 
-CREATE TABLE IF NOT EXISTS online_backup_progress ( backup_id BIGINT UNSIGNED NOT NULL COMMENT 'Key for online_backup table entries', object CHAR (30) NOT NULL COMMENT 'The object being operated on', start_time datetime COMMENT 'The date/time of start of operation', stop_time datetime COMMENT 'The date/time of end of operation', total_bytes BIGINT COMMENT 'The size of the object in bytes', progress BIGINT UNSIGNED COMMENT 'The number of bytes processed', error_num INT NOT NULL DEFAULT 0 COMMENT 'The error from this run 0 == none', notes CHAR(100) COMMENT 'Commentary from the backup engine') ENGINE=MYISAM;
+CREATE TABLE IF NOT EXISTS online_backup_progress ( backup_id BIGINT UNSIGNED NOT NULL COMMENT 'Key for online_backup table entries', object CHAR (30) NOT NULL COMMENT 'The object being operated on', start_time datetime COMMENT 'The date/time of start of operation', stop_time datetime COMMENT 'The date/time of end of operation', total_bytes BIGINT COMMENT 'The size of the object in bytes', progress BIGINT UNSIGNED COMMENT 'The number of bytes processed', error_num INT NOT NULL DEFAULT 0 COMMENT 'The error from this run 0 == none', notes CHAR(100) COMMENT 'Commentary from the backup engine') ENGINE=MYISAM DEFAULT CHARACTER SET utf8;
 
 
 CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts INT UNSIGNED NOT NULL, updates INT UNSIGNED NOT NULL, deletes INT UNSIGNED NOT NULL, schemaops INT UNSIGNED NOT NULL, orig_server_id INT UNSIGNED NOT NULL, orig_epoch BIGINT UNSIGNED NOT NULL, gci INT UNSIGNED NOT NULL, PRIMARY KEY(epoch, orig_server_id, orig_epoch)) ENGINE=MYISAM;

=== modified file 'scripts/mysql_system_tables_fix.sql'
--- a/scripts/mysql_system_tables_fix.sql	2008-07-24 07:44:21 +0000
+++ b/scripts/mysql_system_tables_fix.sql	2008-08-07 03:05:33 +0000
@@ -216,6 +216,52 @@ ALTER TABLE func
   MODIFY type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL;
 
 #
+# Convert miscellaneous tables to UTF-8.
+#
+# Tables coming from a old version might have the 3-byte Unicode
+# character set formerly known as utf8.
+#
+
+ALTER TABLE help_category CONVERT TO CHARACTER SET utf8;
+ALTER TABLE help_keyword CONVERT TO CHARACTER SET utf8;
+ALTER TABLE help_relation CONVERT TO CHARACTER SET utf8;
+ALTER TABLE servers CONVERT TO CHARACTER SET utf8;
+ALTER TABLE time_zone CONVERT TO CHARACTER SET utf8;
+ALTER TABLE time_zone_leap_second CONVERT TO CHARACTER SET utf8;
+ALTER TABLE time_zone_name CONVERT TO CHARACTER SET utf8;
+ALTER TABLE time_zone_transition CONVERT TO CHARACTER SET utf8;
+ALTER TABLE time_zone_transition_type CONVERT TO CHARACTER SET utf8;
+
+# Bug#31291: Avoid conversion from text to mediumtext
+ALTER TABLE help_topic
+  MODIFY description text NOT NULL,
+  MODIFY example text NOT NULL,
+CONVERT TO CHARACTER SET utf8;
+
+#
+# Convert log tables to UTF-8.
+#
+
+SET @old_log_state = @@global.general_log;
+SET GLOBAL general_log = 'OFF';
+ALTER TABLE general_log CONVERT TO CHARACTER SET utf8;
+SET GLOBAL general_log = @old_log_state;
+
+SET @old_log_state = @@global.slow_query_log;
+SET GLOBAL slow_query_log = 'OFF';
+ALTER TABLE slow_log CONVERT TO CHARACTER SET utf8;
+SET GLOBAL slow_query_log = @old_log_state;
+
+#
+# Convert plugin table to UTF-8 with binary collation.
+#
+
+ALTER TABLE plugin
+  MODIFY name char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
+  MODIFY dl char(128) COLLATE utf8_bin NOT NULL DEFAULT '',
+  CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
+
+#
 # Detect whether we had Create_view_priv
 #
 SET @hadCreateViewPriv:=0;
@@ -431,6 +477,13 @@ ALTER TABLE db MODIFY Event_priv enum('N
 #
 # EVENT table
 #
+
+#
+# WARNING: Beware that some columns are added and modified multiple
+# times. Whether adding or modifying the column, it's specification
+# should always be the same.
+#
+
 ALTER TABLE event DROP PRIMARY KEY;
 ALTER TABLE event ADD PRIMARY KEY(db, name);
 # Add sql_mode column just in case.
@@ -499,6 +552,20 @@ ALTER TABLE event ADD body_utf8 longblob
                       AFTER db_collation;
 ALTER TABLE event MODIFY body_utf8 longblob DEFAULT NULL;
 
+#
+# Convert event table to UTF-8 with binary collation.
+#
+
+ALTER TABLE event
+  CONVERT TO CHARACTER SET utf8;
+ALTER TABLE event
+  MODIFY time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM',
+  MODIFY db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
+  MODIFY definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
+  MODIFY comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
+  MODIFY character_set_client char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
+  MODIFY collation_connection char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
+  MODIFY db_collation char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL;
 
 #
 # TRIGGER privilege

=== modified file 'sql/backup/backup_aux.h'
--- a/sql/backup/backup_aux.h	2008-07-09 07:12:43 +0000
+++ b/sql/backup/backup_aux.h	2008-07-31 10:45:02 +0000
@@ -1,6 +1,18 @@
 #ifndef _BACKUP_AUX_H
 #define _BACKUP_AUX_H
 
+/** 
+  @file
+ 
+  @brief Auxiliary declarations used in online backup code.
+
+  @todo Fix error detection in places marked with "FIXME: detect errors...". 
+  These are places where functions or methods are called and if they can 
+  report errors it should be detected and appropriate action taken. If callee 
+  never reports errors or we want to ignore errors, a comment explaining this
+  should be added.
+*/ 
+
 typedef st_plugin_int* storage_engine_ref;
 
 // Macro which transforms plugin_ref to storage_engine_ref
@@ -131,6 +143,7 @@ void set_table_list(TABLE_LIST &tl, cons
   tl.db= const_cast<char*>(tbl.db().name().ptr());
   tl.lock_type= lock_type;
 
+  // FIXME: detect errors (if NULL returned).
   tl.mdl_lock_data= mdl_alloc_lock(0, tl.db, tl.table_name, mem); 
 }
 

=== modified file 'sql/backup/backup_info.cc'
--- a/sql/backup/backup_info.cc	2008-07-09 07:12:43 +0000
+++ b/sql/backup/backup_info.cc	2008-08-05 08:04:30 +0000
@@ -4,7 +4,18 @@
   Implementation of @c Backup_info class. Method @c find_backup_engine()
   implements algorithm for selecting backup engine used to backup
   given table.
- */
+  
+  @todo Fix error detection in places marked with "FIXME: detect errors...". 
+  These are places where functions or methods are called and if they can 
+  report errors it should be detected and appropriate action taken. If callee 
+  never reports errors or we want to ignore errors, a comment explaining this
+  should be added.
+
+  @todo Fix error logging in places marked with "FIXME: error logging...". In 
+  these places it should be decided if and how the error should be shown to the
+  user. If an error message should be logged, it can happen either in the place
+  where error was detected or somewhere up the call stack.
+*/
 
 #include "../mysql_priv.h"
 
@@ -306,8 +317,12 @@ Backup_info::Backup_info(Backup_restore_
 
   bzero(m_snap, sizeof(m_snap));
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   hash_init(&ts_hash, &::my_charset_bin, 16, 0, 0,
             Ts_hash_node::get_key, Ts_hash_node::free, MYF(0));
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   hash_init(&dep_hash, &::my_charset_bin, 16, 0, 0,
             Dep_node::get_key, Dep_node::free, MYF(0));
 
@@ -319,23 +334,32 @@ Backup_info::Backup_info(Backup_restore_
 
   snap= new Nodata_snapshot(m_ctx);  // reports errors
 
+  // FIXME: error logging (in case snap could not be allocated).
   if (!snap || !snap->is_valid())
     return;
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   snapshots.push_back(snap);
 
   snap= new CS_snapshot(m_ctx); // reports errors
 
+  // FIXME: error logging (in case snap could not be allocated).
   if (!snap || !snap->is_valid())
     return;
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   snapshots.push_back(snap);
 
   snap= new Default_snapshot(m_ctx);  // reports errors
 
+  // FIXME: error logging (in case snap could not be allocated).
   if (!snap || !snap->is_valid())
     return;
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   snapshots.push_back(snap);
 
   m_state= CREATED;
@@ -964,9 +988,9 @@ error:
   @param[in] type type of the object
   @param[in] obj  the object
 
-  The object is also added to the dependency list with @c add_to_dep_list() 
-  method. If it is a view, its dependencies are handled first using 
-  @c add_view_deps().
+  The object is added both to the dependency list with @c
+  add_to_dep_list() method and to the catalogue. If it is a view, its
+  dependencies are handled first using @c add_view_deps().
 
   @returns Pointer to @c Image_info::Dbobj instance storing information 
   about the object or NULL in case of error.  
@@ -998,16 +1022,6 @@ Backup_info::add_db_object(Db &db, const
 
   }
 
-  Dbobj *o= Image_info::add_db_object(db, type, *name, pos);
-  
-  if (!o)
-  {
-    m_ctx.fatal_error(error, db.name().ptr(), name->ptr());
-    return NULL;
-  }
-
-  o->m_obj_ptr= obj;
-
   /* 
     Add new object to the dependency list. If it is a view, add its
     dependencies first.
@@ -1026,15 +1040,6 @@ Backup_info::add_db_object(Db &db, const
     return NULL;
   }
 
-  /* 
-    Store a pointer to the catalogue item in the dep. list node. If this node
-    was a placeholder inserted into the list before, now it will be filled with
-    the object we are adding to the catalogue.
-   */
-
-  DBUG_ASSERT(n);
-  n->obj= o;  
-
   /*
     If a new node was created, it must be added to the dependency list with
     add_to_dep_list(). However, if the object is a view, we must first add 
@@ -1053,6 +1058,36 @@ Backup_info::add_db_object(Db &db, const
     add_to_dep_list(type, n);
   } 
 
+  /*
+    The object has now been added to the dependancy list. If it is a
+    view, all dependant objects have also been successfully added to
+    the dependency list. The object can now be added to the cataloge
+    and then be linked to from the node in the dep list. Adding to dep
+    list before adding to catalogue ensures that an object will not be
+    added to catalogue if there are problems with it's dependant
+    objects.
+   */
+
+  // Add object to catalogue
+  Dbobj *o= Image_info::add_db_object(db, type, *name, pos);
+  
+  if (!o)
+  {
+    m_ctx.fatal_error(error, db.name().ptr(), name->ptr());
+    return NULL;
+  }
+
+  o->m_obj_ptr= obj;
+
+  /* 
+    Store a pointer to the catalogue item in the dep. list node. If this node
+    was a placeholder inserted into the list before, now it will be filled with
+    the object we are adding to the catalogue.
+   */
+
+  DBUG_ASSERT(n);
+  n->obj= o;  
+
   DBUG_PRINT("backup",("Added object %s of type %d from database %s (pos=%lu)",
                        name->ptr(), type, db.name().ptr(), pos));
   return o;
@@ -1240,8 +1275,9 @@ inline
 Backup_info::Global_iterator::Global_iterator(const Image_info &info)
  :Iterator(info), mode(TABLESPACES), m_it(NULL), m_obj(NULL)
 {
+  // FIXME: detect errors (if NULL returned).
   m_it= m_info.get_tablespaces();
-  next();
+  next();       // Note: next() doesn't report errors.
 }
 
 

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2008-07-07 12:51:56 +0000
+++ b/sql/backup/backup_kernel.h	2008-08-08 17:21:31 +0000
@@ -30,7 +30,7 @@ void backup_shutdown();
   Called from the big switch in mysql_execute_command() to execute
   backup related statement
 */
-int execute_backup_command(THD*, LEX*);
+int execute_backup_command(THD*, LEX*, String*);
 
 // forward declarations
 
@@ -66,8 +66,12 @@ class Backup_restore_ctx: public backup:
   bool is_valid() const;
   ulonglong op_id() const;
 
-  Backup_info*  prepare_for_backup(LEX_STRING location, const char*, bool);
-  Restore_info* prepare_for_restore(LEX_STRING location, const char*);  
+  Backup_info*  prepare_for_backup(String *location, 
+                                   LEX_STRING orig_loc, 
+                                   const char*, bool);
+  Restore_info* prepare_for_restore(String *location, 
+                                   LEX_STRING orig_loc,
+                                   const char*);  
 
   int do_backup();
   int do_restore();
@@ -79,9 +83,11 @@ class Backup_restore_ctx: public backup:
 
  private:
 
-  /** Indicates if a backup/restore operation is in progress. */
-  static bool is_running;
-  static pthread_mutex_t  run_lock; ///< To guard @c is_running flag.
+  /** @c current_op points to the @c Backup_restore_ctx for the
+      ongoing backup/restore operation.  If pointer is null, no
+      operation is currently running. */
+  static Backup_restore_ctx *current_op;
+  static pthread_mutex_t  run_lock; ///< To guard @c current_op.
 
   /** 
     @brief State of a context object. 
@@ -109,7 +115,7 @@ class Backup_restore_ctx: public backup:
   backup::Image_info *m_catalog;  ///< Pointer to the image catalogue object.
 
   /** Memory allocator for backup stream library. */
-  static backup::Mem_allocator *mem_alloc;
+  backup::Mem_allocator *mem_alloc;
 
   int prepare(LEX_STRING location);
   void disable_fkey_constraints();

=== modified file 'sql/backup/data_backup.cc'
--- a/sql/backup/data_backup.cc	2008-07-19 03:03:39 +0000
+++ b/sql/backup/data_backup.cc	2008-08-11 16:06:30 +0000
@@ -7,6 +7,17 @@
   drivers and protocols to create snapshot of the data stored in the tables being
   backed up.
 
+  @todo Fix error detection in places marked with "FIXME: detect errors...". 
+  These are places where functions or methods are called and if they can 
+  report errors it should be detected and appropriate action taken. If callee 
+  never reports errors or we want to ignore errors, a comment explaining this
+  should be added.
+
+  @todo Fix error logging in places marked with "FIXME: error logging...". In 
+  these places it should be decided if and how the error should be shown to the
+  user. If an error message should be logged, it can happen either in the place
+  where error was detected or somewhere up the call stack.
+
   @todo Implement better scheduling strategy in Scheduler::step
   @todo Add error reporting in the scheduler and elsewhere
   @todo If an error from driver is ignored (and operation retried) leave trace
@@ -467,6 +478,8 @@ int write_table_data(THD* thd, Backup_in
       if (init_size > max_init_size)
         max_init_size= init_size;
 
+      // FIXME: detect errors if reported.
+      // FIXME: error logging.
       inactive.push_back(p);
     }
   }
@@ -587,6 +600,8 @@ int write_table_data(THD* thd, Backup_in
       Save binlog information for point in time recovery on restore.
     */
     if (mysql_bin_log.is_open())
+      // FIXME: detect errors if reported.
+      // FIXME: error logging.
       mysql_bin_log.get_current_log(&binlog_pos);
 
     /*
@@ -774,12 +789,14 @@ int Scheduler::step()
       break;
 
     case backup_state::DONE:
+      // FIXME: detect errors if reported.
       p->end();
 
     case backup_state::ERROR:
-      remove_pump(p);
+      remove_pump(p);   // Note: never errors.
       if (res)
         cancel_backup(); // we hit an error - bail out
+                         // Note: cancel_backup() never errors.
       break;
 
     default: break;
@@ -911,8 +928,8 @@ void Scheduler::cancel_backup()
   while (m_count && m_pumps)
   {
     Pump_iterator p(*this);
-    p->cancel();
-    remove_pump(p);
+    p->cancel();        // Note: even if cancel() errors, we ignore it.
+    remove_pump(p);     // Note: never errors.
   }
 
   cancelled= TRUE;
@@ -931,7 +948,7 @@ int Scheduler::prepare()
   {
     if (it->prepare())
     {
-      cancel_backup();
+      cancel_backup();  // Note: never errors.
       return ERROR;
     }
     if (it->state == backup_state::PREPARING)
@@ -954,7 +971,7 @@ int Scheduler::lock()
   for (Pump_iterator it(*this); it; ++it)
    if (it->lock())
    {
-     cancel_backup();
+     cancel_backup();  // Note: never errors.
      return ERROR;
    }
 
@@ -973,7 +990,7 @@ int Scheduler::unlock()
   {
     if (it->unlock())
     {
-      cancel_backup();
+      cancel_backup();  // Note: never errors.
       return ERROR;
     }
     if (it->state == backup_state::FINISHING)
@@ -998,6 +1015,7 @@ Backup_pump::Backup_pump(Snapshot_info &
 {
   DBUG_ASSERT(snap.m_num > 0);
   m_buf.data= NULL;
+  // FIXME: detect errors if reported.
   bitmap_init(&m_closed_streams,
               NULL,
               1 + snap.table_count(),
@@ -1237,6 +1255,8 @@ int Backup_pump::pump(size_t *howmuch)
         if (m_buf.size > 0)
           mode= WRITING;
         else
+          // FIXME: detect errors (perhaps ensure that drop_buf never errors).
+          // FIXME: error logging.
           m_bw.drop_buf(m_buf);
 
         break;
@@ -1255,6 +1275,8 @@ int Backup_pump::pump(size_t *howmuch)
         state= backup_state::DONE;
 
       case BUSY:
+        // FIXME: detect errors (perhaps ensure that drop_buf never errors).
+        // FIXME: error logging.
         m_bw.drop_buf(m_buf);
         m_buf_head=NULL;  // thus a new request will be made
       }
@@ -1510,6 +1532,8 @@ int restore_table_data(THD *thd, Restore
           bad_drivers.append(",");
         bad_drivers.append(info.m_snap[n]->name());
       }
+      // FIXME: detect errors.
+      // FIXME: error logging.
       drv[n]->free();
     }
 
@@ -1528,6 +1552,8 @@ int restore_table_data(THD *thd, Restore
     if (!drv[n])
       continue;
 
+    // FIXME: detect errors.
+    // FIXME: error logging (perhaps we don't want to report errors here).
     drv[n]->free();
   }
 

=== modified file 'sql/backup/image_info.cc'
--- a/sql/backup/image_info.cc	2008-06-18 14:09:34 +0000
+++ b/sql/backup/image_info.cc	2008-07-31 10:45:02 +0000
@@ -8,6 +8,16 @@
 
   @brief Implements @c Image_info class and friends.
 
+  @todo Fix error detection in places marked with "FIXME: detect errors...". 
+  These are places where functions or methods are called and if they can 
+  report errors it should be detected and appropriate action taken. If callee 
+  never reports errors or we want to ignore errors, a comment explaining this
+  should be added.
+
+  @todo Fix error logging in places marked with "FIXME: error logging...". In 
+  these places it should be decided if and how the error should be shown to the
+  user. If an error message should be logged, it can happen either in the place
+  where error was detected or somewhere up the call stack.
 */
 
 namespace backup {
@@ -15,6 +25,7 @@ namespace backup {
 Image_info::Image_info()
   :data_size(0), m_table_count(0), m_dbs(16, 16), m_ts_map(16,16)
 {
+  // FIXME: detect errors if reported.
   init_alloc_root(&mem_root, 4 * 1024, 0);
 
   /* initialize st_bstream_image_header members */
@@ -295,14 +306,15 @@ Image_info::add_table(Db &db, const ::St
   if (!t)
     return NULL;
 
-  if (snap.add_table(*t, pos))
+  if (snap.add_table(*t, pos))  // reports errors
     return NULL;
   
+  // FIXME: error logging.
   if (db.add_table(*t))
     return NULL;
 
   if (!snap.m_num)
-    snap.m_num= add_snapshot(snap);
+    snap.m_num= add_snapshot(snap); // reports errors
 
   if (!snap.m_num)
    return NULL;

=== modified file 'sql/backup/image_info.h'
--- a/sql/backup/image_info.h	2008-07-19 03:03:39 +0000
+++ b/sql/backup/image_info.h	2008-08-11 16:06:30 +0000
@@ -1,6 +1,15 @@
 #ifndef CATALOG_H_
 #define CATALOG_H_
 
+/**
+  @file
+  
+  @todo Fix error logging in places marked with "FIXME: error logging...". In 
+  these places it should be decided if and how the error should be shown to the
+  user. If an error message should be logged, it can happen either in the place
+  where error was detected or somewhere up the call stack.
+*/ 
+
 #include <si_objects.h>
 #include <backup_stream.h> // for st_bstream_* types
 #include <backup/backup_aux.h>  // for Map template
@@ -802,6 +811,7 @@ void Image_info::save_binlog_pos(const :
 inline
 Image_info::Db_iterator* Image_info::get_dbs() const
 {
+  // FIXME: error logging (in case allocation fails).
   return new Db_iterator(*this);
 }
 
@@ -809,6 +819,7 @@ Image_info::Db_iterator* Image_info::get
 inline
 Image_info::Ts_iterator* Image_info::get_tablespaces() const
 {
+  // FIXME: error logging (in case allocation fails).
   return new Ts_iterator(*this);
 }
 
@@ -816,6 +827,7 @@ Image_info::Ts_iterator* Image_info::get
 inline
 Image_info::Dbobj_iterator* Image_info::get_db_objects(const Db &db) const
 {
+  // FIXME: error logging (in case allocation fails).
   return new Dbobj_iterator(*this, db);
 }
 

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2008-07-19 03:03:39 +0000
+++ b/sql/backup/kernel.cc	2008-08-11 16:06:30 +0000
@@ -19,7 +19,8 @@
   {
   
    Backup_restore_ctx context(thd); // create context instance
-   Backup_info *info= context.prepare_for_backup(location); // prepare for backup
+   Backup_info *info= context.prepare_for_backup(location, 
+                                                 orig_loc); // prepare for backup
   
    // select objects to backup
    info->add_all_dbs();
@@ -41,7 +42,8 @@
   {
   
    Backup_restore_ctx context(thd); // create context instance
-   Restore_info *info= context.prepare_for_restore(location); // prepare for restore
+   Restore_info *info= context.prepare_for_restore(location,
+                                                   orig_loc); // prepare for restore
   
    context.do_restore(); // perform restore
    
@@ -50,15 +52,22 @@
   } // if code jumps here, context destructor will do the clean-up automatically
   @endcode
 
+  @todo Fix error detection in places marked with "FIXME: detect errors...". 
+  These are places where functions or methods are called and if they can 
+  report errors it should be detected and appropriate action taken. If callee 
+  never reports errors or we want to ignore errors, a comment explaining this
+  should be added.
+
+  @todo Fix error logging in places marked with "FIXME: error logging...". In 
+  these places it should be decided if and how the error should be shown to the
+  user. If an error message should be logged, it can happen either in the place
+  where error was detected or somewhere up the call stack.
+
   @todo Use internal table name representation when passing tables to
         backup/restore drivers.
   @todo Handle other types of meta-data in Backup_info methods.
   @todo Handle item dependencies when adding new items.
   @todo Handle other kinds of backup locations (far future).
-
-  @note This comment was added to show Jorgen and Oystein how to push patches 
-  into the team tree - please remove it if you see it. Second version of the 
-  patch, to show how to collapse/re-edit csets.
 */
 
 #include "../mysql_priv.h"
@@ -111,7 +120,9 @@ static int send_reply(Backup_restore_ctx
 /**
   Call backup kernel API to execute backup related SQL statement.
 
-  @param lex  results of parsing the statement.
+  @param[IN] thd        current thread object reference.
+  @param[IN] lex        results of parsing the statement.
+  @param[IN] backupdir  value of the backupdir variable from server.
 
   @note This function sends response to the client (ok, result set or error).
 
@@ -119,7 +130,7 @@ static int send_reply(Backup_restore_ctx
  */
 
 int
-execute_backup_command(THD *thd, LEX *lex)
+execute_backup_command(THD *thd, LEX *lex, String *backupdir)
 {
   int res= 0;
   
@@ -127,6 +138,7 @@ execute_backup_command(THD *thd, LEX *le
   DBUG_ASSERT(thd && lex);
   DEBUG_SYNC(thd, "before_backup_command");
 
+    
   using namespace backup;
 
   Backup_restore_ctx context(thd); // reports errors
@@ -134,13 +146,25 @@ execute_backup_command(THD *thd, LEX *le
   if (!context.is_valid())
     DBUG_RETURN(send_error(context, ER_BACKUP_CONTEXT_CREATE));
 
+  /*
+    Check backupdir for validity. This is needed since we cannot trust
+    that the path is still valid. Access could have changed or the
+    folders in the path could have been moved, deleted, etc.
+  */
+  if (backupdir->length() && my_access(backupdir->c_ptr(), (F_OK|W_OK)))
+  {
+    context.fatal_error(ER_BACKUP_BACKUPDIR, backupdir->c_ptr());
+    DBUG_RETURN(send_error(context, ER_BACKUP_BACKUPDIR, backupdir->c_ptr()));
+  }
+
   switch (lex->sql_command) {
 
   case SQLCOM_BACKUP:
   {
     // prepare for backup operation
     
-    Backup_info *info= context.prepare_for_backup(lex->backup_dir, thd->query,
+    Backup_info *info= context.prepare_for_backup(backupdir, lex->backup_dir, 
+                                                  thd->query,
                                                   lex->backup_compression);
                                                               // reports errors
 
@@ -185,7 +209,8 @@ execute_backup_command(THD *thd, LEX *le
 
   case SQLCOM_RESTORE:
   {
-    Restore_info *info= context.prepare_for_restore(lex->backup_dir, thd->query);
+    Restore_info *info= context.prepare_for_restore(backupdir, lex->backup_dir, 
+                                                    thd->query);
     
     if (!info || !info->is_valid())
       DBUG_RETURN(send_error(context, ER_BACKUP_RESTORE_PREPARE));
@@ -271,17 +296,31 @@ int send_reply(Backup_restore_ctx &conte
   /*
     Send field list.
   */
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   field_list.push_back(new Item_empty_string(STRING_WITH_LEN("backup_id")));
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
 
   /*
     Send field data.
   */
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   protocol->prepare_for_resend();
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   llstr(context.op_id(), buf);
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   protocol->store(buf, system_charset_info);
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   protocol->write();
 
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   my_eof(context.thd());
   DBUG_RETURN(0);
 }
@@ -323,15 +362,14 @@ class Mem_allocator
 
 // static members
 
-bool Backup_restore_ctx::is_running= FALSE;
+Backup_restore_ctx *Backup_restore_ctx::current_op= NULL;
 pthread_mutex_t Backup_restore_ctx::run_lock;
-backup::Mem_allocator *Backup_restore_ctx::mem_alloc= NULL;
 
 
 Backup_restore_ctx::Backup_restore_ctx(THD *thd)
  :Logger(thd), m_state(CREATED), m_thd_options(thd->options),
   m_error(0), m_path(NULL), m_remove_loc(FALSE), m_stream(NULL),
-  m_catalog(NULL), m_tables_locked(FALSE)
+  m_catalog(NULL), mem_alloc(NULL), m_tables_locked(FALSE)
 {
   /*
     Check for progress tables.
@@ -344,6 +382,7 @@ Backup_restore_ctx::~Backup_restore_ctx(
 {
   close();
   
+  delete mem_alloc;
   delete m_catalog;  
   delete m_stream;
 }
@@ -366,8 +405,12 @@ int Backup_restore_ctx::prepare(LEX_STRI
   
   // Prepare error reporting context.
   
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   mysql_reset_errors(m_thd, 0);
   m_thd->no_warnings_for_error= FALSE;
+  // FIXME: detect errors if  reported.
+  // FIXME: error logging.
   save_errors();  
 
 
@@ -387,8 +430,8 @@ int Backup_restore_ctx::prepare(LEX_STRI
 
   pthread_mutex_lock(&run_lock);
 
-  if (!is_running)
-    is_running= TRUE;
+  if (!current_op)
+    current_op= this;
   else
     fatal_error(ER_BACKUP_RUNNING);
 
@@ -399,6 +442,11 @@ int Backup_restore_ctx::prepare(LEX_STRI
 
   // check if location is valid (we assume it is a file path)
 
+  /*
+    For this error to work correctly, we need to check original
+    file specified by the user rather than the path formed
+    using the backupdir.
+  */
   bool bad_filename= (location.length == 0);
   
   /*
@@ -408,7 +456,7 @@ int Backup_restore_ctx::prepare(LEX_STRI
 #if defined(__WIN__) || defined(__EMX__)  
 
   bad_filename = bad_filename || check_if_legal_filename(location.str);
-  
+
 #endif
 
   if (bad_filename)
@@ -446,7 +494,8 @@ int Backup_restore_ctx::prepare(LEX_STRI
 /**
   Prepare for backup operation.
   
-  @param[in] location   path to the file where backup image should be stored
+  @param[in] backupdir  path to the file where backup image should be stored
+  @param[in] orig_loc   path as specified on command line for backup image
   @param[in] query      BACKUP query starting the operation
   @param[in] with_compression  backup image compression switch
   
@@ -461,7 +510,9 @@ int Backup_restore_ctx::prepare(LEX_STRI
   is performed using @c do_backup() method.
  */ 
 Backup_info* 
-Backup_restore_ctx::prepare_for_backup(LEX_STRING location, const char *query,
+Backup_restore_ctx::prepare_for_backup(String *backupdir, 
+                                       LEX_STRING orig_loc, 
+                                       const char *query,
                                        bool with_compression)
 {
   using namespace backup;
@@ -469,7 +520,7 @@ Backup_restore_ctx::prepare_for_backup(L
   if (m_error)
     return NULL;
   
-  if (Logger::init(BACKUP, location, query))
+  if (Logger::init(BACKUP, orig_loc, query))
   {
     fatal_error(ER_BACKUP_LOGGER_INIT);
     return NULL;
@@ -482,16 +533,16 @@ Backup_restore_ctx::prepare_for_backup(L
     Do preparations common to backup and restore operations. After call
     to prepare() all meta-data changes are blocked.
    */ 
-  if (prepare(location))
+  if (prepare(orig_loc))
     return NULL;
 
-  backup::String path(location);
-  
   /*
     Open output stream.
    */
-
-  Output_stream *s= new Output_stream(*this, path, with_compression);
+  Output_stream *s= new Output_stream(*this, 
+                                      backupdir, 
+                                      orig_loc,
+                                      with_compression);
   m_stream= s;
   
   if (!s)
@@ -502,7 +553,11 @@ Backup_restore_ctx::prepare_for_backup(L
   
   if (!s->open())
   {
-    fatal_error(ER_BACKUP_WRITE_LOC, path.ptr());
+    /*
+      For this error, use the actual value returned instead of the
+      path complimented with backupdir.
+    */
+    fatal_error(ER_BACKUP_WRITE_LOC, orig_loc.str);
     return NULL;
   }
 
@@ -531,7 +586,8 @@ Backup_restore_ctx::prepare_for_backup(L
 /**
   Prepare for restore operation.
   
-  @param[in] location   path to the file where backup image is stored
+  @param[in] backupdir  path to the file where backup image is stored
+  @param[in] orig_loc   path as specified on command line for backup image
   @param[in] query      RESTORE query starting the operation
   
   @returns Pointer to a @c Restore_info instance containing catalogue of the
@@ -540,14 +596,16 @@ Backup_restore_ctx::prepare_for_backup(L
   @note This function reports errors.
  */ 
 Restore_info* 
-Backup_restore_ctx::prepare_for_restore(LEX_STRING location, const char *query)
+Backup_restore_ctx::prepare_for_restore(String *backupdir,
+                                        LEX_STRING orig_loc, 
+                                        const char *query)
 {
   using namespace backup;  
 
   if (m_error)
     return NULL;
   
-  if (Logger::init(RESTORE, location, query))
+  if (Logger::init(RESTORE, orig_loc, query))
   {
     fatal_error(ER_BACKUP_LOGGER_INIT);
     return NULL;
@@ -560,15 +618,14 @@ Backup_restore_ctx::prepare_for_restore(
     Do preparations common to backup and restore operations. After this call
     changes of meta-data are blocked.
    */ 
-  if (prepare(location))
+  if (prepare(orig_loc))
     return NULL;
   
   /*
     Open input stream.
    */
 
-  backup::String path(location);
-  Input_stream *s= new Input_stream(*this, path);
+  Input_stream *s= new Input_stream(*this, backupdir, orig_loc);
   m_stream= s;
   
   if (!s)
@@ -579,7 +636,11 @@ Backup_restore_ctx::prepare_for_restore(
   
   if (!s->open())
   {
-    fatal_error(ER_BACKUP_READ_LOC, path.ptr());
+    /*
+      For this error, use the actual value returned instead of the
+      path complimented with backupdir.
+    */
+    fatal_error(ER_BACKUP_READ_LOC, orig_loc.str);
     return NULL;
   }
 
@@ -669,9 +730,13 @@ int Backup_restore_ctx::lock_tables_for_
       backup::Image_info::Table *tbl= snap->get_table(t);
       DBUG_ASSERT(tbl); // All tables should be present in the catalogue.
 
+      // FIXME: detect errors. Don't assert here but report error instead.
+      // FIXME: error logging.
       TABLE_LIST *ptr= backup::mk_table_list(*tbl, TL_WRITE, m_thd->mem_root);
-      DBUG_ASSERT(ptr);  // FIXME: report error instead
+      DBUG_ASSERT(ptr);
 
+      // FIXME: detect errors if reported.
+      // FIXME: error logging.
       tables= backup::link_table_list(*ptr, tables);      
       tbl->m_table= ptr;
     }
@@ -733,8 +798,10 @@ int Backup_restore_ctx::close()
   time_t when= my_time(0);
 
   // If auto commit is turned off, be sure to commit the transaction
-  // TODO: move it to the big switch, case: MYSQLCOM_BACKUP?
-
+  /* 
+    Note: this code needs to be refactored (see BUG#38261). When refactoring
+    make sure that errors are detected and reported.
+  */
   if (m_thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
   {
     ha_autocommit_or_rollback(m_thd, 0);
@@ -743,10 +810,13 @@ int Backup_restore_ctx::close()
 
   // unlock tables if they are still locked
 
+  // FIXME: detect errors if reported.
   unlock_tables();
 
   // unfreeze meta-data
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   obs::ddl_blocker_disable();
 
   // restore thread options
@@ -756,20 +826,23 @@ int Backup_restore_ctx::close()
   // close stream
 
   if (m_stream)
+    // FIXME: detect errors if reported.
+    // FIXME: error logging.
     m_stream->close();
 
   if (m_catalog)
-    m_catalog->save_end_time(when);
+    m_catalog->save_end_time(when); // Note: no errors.
 
   // destroy backup stream's memory allocator (this frees memory)
 
   delete mem_alloc;
   mem_alloc= NULL;
   
-  // deregister this operation
-
+  // deregister this operation if it was running
   pthread_mutex_lock(&run_lock);
-  is_running= FALSE;
+  if (current_op == this) {
+    current_op= NULL;
+  }
   pthread_mutex_unlock(&run_lock);
 
   /* 
@@ -827,6 +900,8 @@ int Backup_restore_ctx::do_backup()
 
   DEBUG_SYNC(m_thd, "before_backup_meta");
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   report_stats_pre(info);
 
   DBUG_PRINT("backup",("Writing preamble"));
@@ -852,6 +927,8 @@ int Backup_restore_ctx::do_backup()
     DBUG_RETURN(m_error);
   }
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   report_stats_post(info);
 
   DBUG_PRINT("backup",("Backup done."));
@@ -880,6 +957,7 @@ int Backup_restore_ctx::restore_triggers
 
   DBUG_ASSERT(m_catalog);
 
+  // FIXME: detect errors (when dbit==NULL). Perhaps just assert.
   Image_info::Iterator *dbit= m_catalog->get_dbs();
   Image_info::Obj *obj;
   List<Image_info::Obj> events;
@@ -891,6 +969,7 @@ int Backup_restore_ctx::restore_triggers
   
   while ((obj= (*dbit)++)) 
   {
+    // FIXME: detect errors (when it==NULL). Perhaps just assert.
     Image_info::Iterator *it= 
                     m_catalog->get_db_objects(*static_cast<Image_info::Db*>(obj));
 
@@ -899,6 +978,8 @@ int Backup_restore_ctx::restore_triggers
       
       case BSTREAM_IT_EVENT:
         DBUG_ASSERT(obj->m_obj_ptr);
+        // FIXME: detect errors if reported.
+        // FIXME: error logging.
         events.push_back(obj);
         break;
       
@@ -961,11 +1042,14 @@ int Backup_restore_ctx::do_restore()
   Input_stream &s= *static_cast<Input_stream*>(m_stream);
   Restore_info &info= *static_cast<Restore_info*>(m_catalog);
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   report_stats_pre(info);
 
   DBUG_PRINT("restore", ("Restoring meta-data"));
 
-  disable_fkey_constraints();
+  // FIXME: detect errors if reported.
+  disable_fkey_constraints();  // reports errors
 
   if (read_meta_data(info, s))
   {
@@ -973,6 +1057,7 @@ int Backup_restore_ctx::do_restore()
     DBUG_RETURN(m_error);
   }
 
+  // FIXME: detect errors.
   s.next_chunk();
 
   DBUG_PRINT("restore",("Restoring table data"));
@@ -983,7 +1068,11 @@ int Backup_restore_ctx::do_restore()
     It should be fixed inside object services implementation and then the
     following line should be removed.
    */
+  // FIXME: detect errors.
+  // FIXME: error logging.
   close_thread_tables(m_thd);
+  // FIXME: detect errors.
+  // FIXME: error logging.
   m_thd->main_da.reset_diagnostics_area();
 
   if (lock_tables_for_restore()) // reports errors
@@ -992,6 +1081,7 @@ int Backup_restore_ctx::do_restore()
   // Here restore drivers are created to restore table data
   err= restore_table_data(m_thd, info, s); // reports errors
 
+  // FIXME: detect errors if reported.
   unlock_tables();
 
   if (err)
@@ -1004,7 +1094,7 @@ int Backup_restore_ctx::do_restore()
    creation of these objects will fail.
   */
 
-  if (restore_triggers_and_events())
+  if (restore_triggers_and_events())    // reports errors
      DBUG_RETURN(ER_BACKUP_RESTORE);
 
   DBUG_PRINT("restore",("Done."));
@@ -1021,9 +1111,15 @@ int Backup_restore_ctx::do_restore()
     It should be fixed inside object services implementation and then the
     following line should be removed.
    */
+  // FIXME: detect errors.
+  // FIXME: error logging.
   close_thread_tables(m_thd);
+  // FIXME: detect errors.
+  // FIXME: error logging.
   m_thd->main_da.reset_diagnostics_area();
 
+  // FIXME: detect errors if reported.
+  // FIXME: error logging.
   report_stats_post(info);
 
   DBUG_RETURN(0);
@@ -1135,9 +1231,10 @@ bstream_byte* bstream_alloc(unsigned lon
 {
   using namespace backup;
 
-  DBUG_ASSERT(Backup_restore_ctx::mem_alloc);
+  DBUG_ASSERT(Backup_restore_ctx::current_op 
+              && Backup_restore_ctx::current_op->mem_alloc);
 
-  return (bstream_byte*)Backup_restore_ctx::mem_alloc->alloc(size);
+  return (bstream_byte*)Backup_restore_ctx::current_op->mem_alloc->alloc(size);
 }
 
 /**
@@ -1147,8 +1244,9 @@ extern "C"
 void bstream_free(bstream_byte *ptr)
 {
   using namespace backup;
-  if (Backup_restore_ctx::mem_alloc)
-    Backup_restore_ctx::mem_alloc->free(ptr);
+  if (Backup_restore_ctx::current_op 
+      && Backup_restore_ctx::current_op->mem_alloc)
+    Backup_restore_ctx::current_op->mem_alloc->free(ptr);
 }
 
 /**

=== modified file 'sql/backup/stream.cc'
--- a/sql/backup/stream.cc	2008-07-02 11:27:17 +0000
+++ b/sql/backup/stream.cc	2008-08-08 17:21:31 +0000
@@ -190,9 +190,11 @@ extern "C" int stream_read(void *instanc
 }
 
 
-Stream::Stream(Logger &log, const ::String &name, int flags)
-  :m_path(name), m_flags(flags), m_block_size(0), m_log(log)
+Stream::Stream(Logger &log, ::String *backupdir, 
+               LEX_STRING orig_loc, int flags)
+  :m_flags(flags), m_block_size(0), m_log(log)
 {
+  prepare_path(backupdir, orig_loc);
   bzero(&stream, sizeof(stream));
   bzero(&buf, sizeof(buf));
   bzero(&mem, sizeof(mem));
@@ -201,6 +203,150 @@ Stream::Stream(Logger &log, const ::Stri
   state= CLOSED;
 }
 
+/**
+  Make a relative path.
+
+  This method takes the backupdir and the path specified on the backup command
+  (orig_loc) and forms a combined path. It walks the backupdir from the right
+  and the orig_loc from the left to position the paths for concatenation. Output
+  is written to new_path.
+
+  @param[OUT] new_path   The newly combined path + file name.
+  @param[IN]  orig_loc   The path + file name specified in the backup command.
+  @param[IN]  backupdir  The backupdir system variable value.
+
+  For example, if backupdir = '/dev/tmp' and orig_log = '../backup.bak', the 
+  combined path is = '/dev/backup.bak'.
+
+  @returns 
+    0 if success
+    1 if cannot be combined. Note: m_path is set to '' when this occurs to
+      trigger error in call stack.
+*/
+int Stream::make_relative_path(char *new_path, 
+                               char *orig_loc, 
+                               ::String *backupdir)
+{
+  char fixed_base[FN_LEN];
+  char fixed_rel[FN_LEN];
+  cleanup_dirname(fixed_base, backupdir->c_ptr());
+  cleanup_dirname(fixed_rel, orig_loc);
+  char *rel;
+  char *base= fixed_base;
+  bool done= FALSE;
+  char *found= fixed_rel;
+  int j= backupdir->length() - 1;
+  new_path[0]= 0;  // initialize the new path to an empty string
+
+  /*
+    For each '../' in orig_loc, move the pointer to the right for rel.
+    For each '../' in orig_loc, move pointer to the left for base.
+  */
+  while (!done)
+  {
+    rel= found; // save last known position
+    // find location of next level in relative path
+    found= strstr(found, FN_PARENTDIR);
+    if (found)
+    {
+      found+= 2;   // move past '..\'
+      if (base[j] == FN_LIBCHAR)
+        j--;       // move past last '\'
+      if (j == 0)  // We are trying to move too far down the path
+        return 1;
+      /*
+        Look for the next level down.
+      */
+      while ((base[j] != FN_LIBCHAR) && j)
+        j--;       
+    }
+    else
+      done= TRUE;
+  }
+  strcpy (new_path, base);
+  strcpy (new_path + j, rel);
+  return 0;
+}
+
+/**
+  Prepare path for access.
+
+  This method takes the backupdir and the file name specified on the backup
+  command (orig_loc) and forms a combined path + file name as follows:
+
+    1. If orig_loc has a relative path, make it relative to backupdir
+    2. If orig_loc has a hard path, use it.
+    3. If orig_loc has no path, append to backupdir
+
+  @param[IN]  backupdir  The backupdir system variable value.
+  @param[IN]  orig_loc   The path + file name specified in the backup command.
+
+  @returns 0
+*/
+int Stream::prepare_path(::String *backupdir, 
+                         LEX_STRING orig_loc)
+{
+  int path_len= 0;
+
+  /*
+    Prepare the path using the backupdir iff no relative path
+    or no hard path included.
+
+    Relative paths are formed from the backupdir system variable.
+  */
+  if (is_prefix(orig_loc.str, FN_PARENTDIR))
+  {
+    /* 
+      Case 1: Backup image file name has relative path. 
+              Make relative to backupdir.
+
+      Example BACKUP DATATBASE ... TO '../monthly/dec.bak'
+              If backupdir = '/dev/daily/backup' then the
+              calculated path becomes
+              '/dev/monthly/backup/dec.bak'
+    */
+    char new_path[FN_LEN];
+    if (make_relative_path(new_path, orig_loc.str, backupdir))
+      m_path.length(0);
+    path_len= strlen(new_path) + 1;
+    m_path.alloc(path_len);
+    m_path.length(0);
+    m_path.append(new_path);
+  }
+  else if (!test_if_hard_path(orig_loc.str))
+  {
+    /* 
+      Case 2: Backup image file name has hard path. 
+
+      Example BACKUP DATATBASE ... TO '/dev/dec.bak'
+              If backupdir = '/dev/daily/backup' then the
+              calculated path becomes
+              '/dev/dec.bak'
+    */
+    path_len=backupdir->length() + orig_loc.length + 1;
+    m_path.alloc(path_len);
+    fn_format(m_path.c_ptr(), orig_loc.str, backupdir->c_ptr(), "",
+              MY_UNPACK_FILENAME);
+  }
+  else 
+  {
+    /* 
+      Case 3: Backup image file name has no path. 
+
+      Example BACKUP DATATBASE ... TO 'week2.bak'
+              If backupdir = '/dev/weekly/backup' then the
+              calculated path becomes
+              '/dev/weekly/week2.bak'
+    */
+    path_len= orig_loc.length + 1;
+    m_path.alloc(path_len);
+    m_path.length(0);
+    m_path.append(orig_loc.str);
+  }
+  m_path.length(path_len);
+  return 0;
+}
+
 bool Stream::open()
 {
   close();
@@ -228,9 +374,10 @@ bool Stream::rewind()
 }
 
 
-Output_stream::Output_stream(Logger &log, const ::String &name,
+Output_stream::Output_stream(Logger &log, ::String *backupdir,
+                             LEX_STRING orig_loc,
                              bool with_compression)
-  :Stream(log, name, 0)
+  :Stream(log, backupdir, orig_loc, 0)
 {
   m_with_compression= with_compression;
   stream.write= stream_write;
@@ -414,8 +561,9 @@ bool Output_stream::rewind()
 }
 
 
-Input_stream::Input_stream(Logger &log, const ::String &name)
-  :Stream(log, name, O_RDONLY)
+Input_stream::Input_stream(Logger &log, ::String *backupdir, 
+                           LEX_STRING orig_loc)
+  :Stream(log, backupdir, orig_loc, O_RDONLY)
 {
   m_with_compression= false;
   stream.read= stream_read;

=== modified file 'sql/backup/stream.h'
--- a/sql/backup/stream.h	2008-06-26 16:20:30 +0000
+++ b/sql/backup/stream.h	2008-08-08 17:21:31 +0000
@@ -92,7 +92,7 @@ class Stream: public fd_stream
 
  protected:
 
-  Stream(Logger&, const ::String&, int);
+  Stream(Logger&, ::String *, LEX_STRING, int);
 
   String  m_path;
   int     m_flags;  ///< flags used when opening the file
@@ -101,6 +101,15 @@ class Stream: public fd_stream
 
   friend int stream_write(void*, bstream_blob*, bstream_blob);
   friend int stream_read(void*, bstream_blob*, bstream_blob);
+
+private:
+
+  int make_relative_path(char *new_path, 
+                         char *orig_loc, 
+                         ::String *backupdir);
+  int prepare_path(::String *backupdir, 
+                   LEX_STRING orig_loc);
+
 };
 
 /// Used to write to backup stream.
@@ -109,7 +118,7 @@ class Output_stream:
 {
  public:
 
-  Output_stream(Logger&, const ::String&, bool);
+  Output_stream(Logger&, ::String *, LEX_STRING, bool);
 
   bool open();
   void close();
@@ -127,7 +136,7 @@ class Input_stream:
 {
  public:
 
-  Input_stream(Logger&, const ::String &name);
+  Input_stream(Logger&, ::String *, LEX_STRING);
 
   bool open();
   void close();

=== modified file 'sql/backup/stream_v1.c'
--- a/sql/backup/stream_v1.c	2008-07-19 03:03:39 +0000
+++ b/sql/backup/stream_v1.c	2008-08-13 12:41:33 +0000
@@ -1555,14 +1555,30 @@ int bstream_wr_item_def(backup_stream *s
   blob data;
   int ret=BSTREAM_OK;
 
-  if (bcat_get_item_create_query(cat,item,&query) == BSTREAM_OK)
+  /* initialize variables */
+  data.begin= 0;
+  data.end= 0;
+  query.begin= 0;
+  query.end= 0;
+  ret= bcat_get_item_create_query(cat,item,&query);
+  if (ret == BSTREAM_OK) 
     flags |= BSTREAM_FLAG_HAS_CREATE_STMT;
+  else if (ret == BSTREAM_ERROR) 
+    goto wr_error;
 
-  if (bcat_get_item_create_data(cat,item,&data) == BSTREAM_OK)
+  /* bcat_get_item_create_data not in use yet. */
+  /*
+  ret= bcat_get_item_create_data(cat,item,&data);
+  if (ret == BSTREAM_OK)
     flags |= BSTREAM_FLAG_HAS_EXTRA_DATA;
-
+  else if (ret == BSTREAM_ERROR) 
+    goto wr_error;
+  */
+  
   ret= bstream_wr_meta_item(s,kind,flags,item);
-
+  if (ret == BSTREAM_ERROR) 
+    goto wr_error;
+  
   /* save create query and/or create data */
 
   if (flags & BSTREAM_FLAG_HAS_EXTRA_DATA)

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2008-08-25 10:16:09 +0000
+++ b/sql/handler.cc	2008-08-27 12:49:58 +0000
@@ -4596,7 +4596,7 @@ ha_rows DsMrr_impl::dsmrr_info_const(uin
   @retval FALSE  No
 */
 
-bool DsMrr_impl::key_uses_partial_cols(uint keyno)
+bool key_uses_partial_cols(TABLE *table, uint keyno)
 {
   KEY_PART_INFO *kp= table->key_info[keyno].key_part;
   KEY_PART_INFO *kp_end= kp + table->key_info[keyno].key_parts;
@@ -4608,7 +4608,6 @@ bool DsMrr_impl::key_uses_partial_cols(u
   return FALSE;
 }
 
-
 /**
   DS-MRR Internals: Choose between Default MRR implementation and DS-MRR
 
@@ -4642,7 +4641,7 @@ bool DsMrr_impl::choose_mrr_impl(uint ke
       (*flags & HA_MRR_INDEX_ONLY) || (*flags & HA_MRR_SORTED) ||
       (keyno == table->s->primary_key && 
        h->primary_key_is_clustered()) || 
-       key_uses_partial_cols(keyno))
+       key_uses_partial_cols(table, keyno))
   {
     /* Use the default implementation */
     *flags |= HA_MRR_USE_DEFAULT_IMPL;

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2008-08-05 11:20:20 +0000
+++ b/sql/handler.h	2008-08-27 12:49:58 +0000
@@ -2329,6 +2329,7 @@ private:
 };
 
 
+bool key_uses_partial_cols(TABLE *table, uint keyno);
 
 /**
   A Disk-Sweep MRR interface implementation
@@ -2389,7 +2390,6 @@ public:
                             void *seq_init_param, uint n_ranges, uint *bufsz,
                             uint *flags, COST_VECT *cost);
 private:
-  bool key_uses_partial_cols(uint keyno);
   bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, 
                        COST_VECT *cost);
   bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, 

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2008-08-22 17:03:15 +0000
+++ b/sql/mysql_priv.h	2008-08-27 12:49:58 +0000
@@ -570,6 +570,7 @@ enum open_table_mode
 /* @@optimizer_switch flags */
 #define OPTIMIZER_SWITCH_NO_MATERIALIZATION 1
 #define OPTIMIZER_SWITCH_NO_SEMIJOIN 2
+#define OPTIMIZER_SWITCH_NO_LOOSE_SCAN 4
 
 
 /*

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2008-07-22 18:30:36 +0000
+++ b/sql/mysqld.cc	2008-08-27 12:49:58 +0000
@@ -332,15 +332,16 @@ TYPELIB sql_mode_typelib= { array_elemen
 
 static const char *optimizer_switch_names[]=
 {
-  "no_materialization", "no_semijoin",
+  "no_materialization", "no_semijoin", "no_loosescan",
   NullS
 };
 
 /* Corresponding defines are named OPTIMIZER_SWITCH_XXX */
 static const unsigned int optimizer_switch_names_len[]=
 {
-  /*no_materialization*/          19,
-  /*no_semijoin*/                 11
+  /*no_materialization*/          18,
+  /*no_semijoin*/                 11,
+  /*no_loosescan*/                12,
 };
 
 TYPELIB optimizer_switch_typelib= { array_elements(optimizer_switch_names)-1,"",
@@ -1370,6 +1371,7 @@ void clean_up(bool print_message)
   my_free(sys_init_slave.value, MYF(MY_ALLOW_ZERO_PTR));
   my_free(sys_var_general_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
   my_free(sys_var_slow_log_path.value, MYF(MY_ALLOW_ZERO_PTR));
+  my_free(sys_var_backupdir.value, MYF(MY_ALLOW_ZERO_PTR));
   free_tmpdir(&mysql_tmpdir_list);
 #ifdef HAVE_REPLICATION
   my_free(slave_load_tmpdir,MYF(MY_ALLOW_ZERO_PTR));
@@ -5810,6 +5812,8 @@ struct my_option my_long_options[] =
    "Creating and dropping stored procedures alters ACLs. Disable with --skip-automatic-sp-privileges.",
    (uchar**) &sp_automatic_privileges, (uchar**) &sp_automatic_privileges,
    0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
+  {"backupdir", 'B', "Path used to store backup data.", (uchar**) &sys_var_backupdir.value,
+   (uchar**) &sys_var_backupdir.value, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"basedir", 'b',
    "Path to installation directory. All paths are usually resolved relative to this.",
    (uchar**) &mysql_home_ptr, (uchar**) &mysql_home_ptr, 0, GET_STR, REQUIRED_ARG,
@@ -7938,6 +7942,21 @@ mysqld_get_one_option(int optid,
   case 'l':
     opt_log=1;
     break;
+  case 'B':
+  {
+    /*
+      Check if directory exists and we have permission to create file and
+      write to file.
+    */
+    if (my_access(argument, (F_OK|W_OK)))
+    {
+      sql_print_warning("The path specified for the variable backupdir cannot"
+        " be accessed or is invalid. ref:'%s'\n", argument);
+    }
+    sys_var_backupdir.value= my_strdup(argument, MYF(0));
+    sys_var_backupdir.value_length= strlen(sys_var_backupdir.value);
+    break;
+  }
   case 'h':
     strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1);
     /* Correct pointer set by my_getopt (for embedded library) */
@@ -8647,6 +8666,16 @@ static void fix_paths(void)
   convert_dirname(language,language,NullS);
   (void) my_load_path(mysql_home,mysql_home,""); // Resolve current dir
   (void) my_load_path(mysql_real_data_home,mysql_real_data_home,mysql_home);
+ 
+  /*
+    Set backupdir if datadir set on command line but not otherwise set.
+  */
+  if (!sys_var_backupdir.value)
+  {
+    sys_var_backupdir.value= my_strdup(mysql_real_data_home, MYF(0));
+    sys_var_backupdir.value_length= strlen(mysql_real_data_home);
+  }
+
   (void) my_load_path(pidfile_name,pidfile_name,mysql_real_data_home);
   (void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
                                       get_relative_path(PLUGINDIR), mysql_home);

=== modified file 'sql/probes.h'
--- a/sql/probes.h	2007-09-21 07:09:31 +0000
+++ b/sql/probes.h	2008-07-08 13:49:57 +0000
@@ -11,7 +11,7 @@
 extern "C" {
 #endif
 
-#if _DTRACE_VERSION
+#if _DTRACE_VERSION && defined(HAVE_DTRACE)
 
 #define	MYSQL_DELETE_END() \
 	__dtrace_mysql___delete_end()

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2008-08-05 11:20:20 +0000
+++ b/sql/set_var.cc	2008-08-27 12:49:58 +0000
@@ -149,6 +149,9 @@ static bool sys_update_general_log_path(
 static void sys_default_general_log_path(THD *thd, enum_var_type type);
 static bool sys_update_slow_log_path(THD *thd, set_var * var);
 static void sys_default_slow_log_path(THD *thd, enum_var_type type);
+static int sys_check_backupdir(THD *thd, set_var *var);
+static bool sys_update_backupdir(THD *thd, set_var * var);
+static void sys_default_backupdir(THD *thd, enum_var_type type);
 
 /*
   Variable definition list
@@ -779,6 +782,15 @@ sys_var_str sys_var_slow_log_path(&vars,
 static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 					    &log_output_typelib, 0);
 
+/*
+  Create the backupdir dynamic variable.
+*/
+sys_var_str sys_var_backupdir(&vars, "backupdir",
+                              sys_check_backupdir,
+                              sys_update_backupdir,
+                              sys_default_backupdir,
+                               0);
+
 
 /*
   Additional variables (not derived from sys_var class, not accessible as
@@ -2627,6 +2639,140 @@ uchar *sys_var_log_output::value_ptr(THD
   return (uchar*) thd->strmake(tmp.ptr(), length);
 }
 
+/*
+  Functions for backupdir variable.
+*/
+
+/**
+  Set the default for the backupdir
+
+  @param[IN] buff Buffer to use for making string.
+
+  @returns pointer to string (buff)
+*/
+char *make_default_backupdir(char *buff)
+{
+  strmake(buff, mysql_data_home, FN_REFLEN-5);
+  return buff;
+}
+
+/**
+  Check the backupdir value for validity.
+
+  This method ensures the users is specifying a valid path
+  for the backupdir. Validity in this case means the path
+  is accessible to the user.
+
+  @param[IN] thd   Current thread context.
+  @param[IN] var   The new value set in set_var structure.
+
+  @returns 0 
+*/
+static int sys_check_backupdir(THD *thd, set_var *var)
+{
+  char path[FN_REFLEN], buff[FN_REFLEN];
+  MY_STAT f_stat;
+  String str(buff, sizeof(buff), system_charset_info), *res;
+  const char *log_file_str;
+  size_t path_length;
+
+  if (!(res= var->value->val_str(&str)))
+    goto err;
+
+  log_file_str= res->c_ptr();
+  bzero(&f_stat, sizeof(MY_STAT));
+
+  /* Get dirname of the file path. */
+  (void) dirname_part(path, log_file_str, &path_length);
+
+  /* Dirname is empty if file path is relative. */
+  if (!path_length)
+    return 0;
+
+  /*
+    Check if directory exists and we have permission to create file and
+    write to file.
+  */
+  if (my_access(path, (F_OK|W_OK)))
+    goto err;
+
+  return 0;
+
+err:
+  /*
+    We print a warning if backupdir is invalid but set it anyway.
+  */
+  push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                      ER_BACKUP_BACKUPDIR, ER(ER_BACKUP_BACKUPDIR),
+                      var->value->str_value.c_ptr());
+  return 0;
+}
+
+/**
+  Update the backupdir variable 
+  
+  This method is used to change the backupdir variable.
+
+  @param[IN] thd   Current thread context.
+  @param[IN] var   The new value set in set_var structure.
+
+  @returns 0 valid, 1 invalid.
+*/
+static bool sys_update_backupdir(THD *thd, set_var * var)
+{
+  char buff[FN_REFLEN];
+  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
+  bool result= 0;
+  uint str_length= (var ? var->value->str_value.length() : 0);
+
+  if (!old_value)
+  {
+    old_value= make_default_backupdir(buff);
+    str_length= strlen(old_value);
+  }
+  if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
+  {
+    result= 1;
+    goto err;
+  }
+
+  pthread_mutex_lock(&LOCK_global_system_variables);
+  logger.lock_exclusive();
+  old_value= sys_var_backupdir.value;
+  sys_var_backupdir.value= res;
+  sys_var_backupdir.value_length= str_length;
+  logger.unlock();
+  pthread_mutex_unlock(&LOCK_global_system_variables);
+
+  if (my_access(sys_var_backupdir.value, (F_OK|W_OK)))
+    goto err;
+
+  return result;
+
+err:
+  /*
+    We print a warning if backupdir is invalid but set it anyway.
+  */
+  push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                      ER_BACKUP_BACKUPDIR, ER(ER_BACKUP_BACKUPDIR),
+                      var->value->str_value.c_ptr());
+  return result;
+}
+
+/**
+  Set the default value for the backupdir variable 
+  
+  This method is used to reset the backupdir variable to the
+  default by calling the update method without a path.
+
+  @param[IN] thd   Current thread context.
+  @param[IN] type  Ignored (needed for api).
+*/
+static void sys_default_backupdir(THD *thd, enum_var_type type)
+{
+  sys_update_backupdir(thd, 0);
+}
+
 
 /*****************************************************************************
   Functions to handle SET NAMES and SET CHARACTER SET

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2008-07-22 18:30:36 +0000
+++ b/sql/set_var.h	2008-08-27 12:49:58 +0000
@@ -1366,7 +1366,8 @@ CHARSET_INFO *get_old_charset_by_name(co
 uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
 		NAMED_LIST **found);
 
-extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path;
+extern sys_var_str sys_var_general_log_path, sys_var_slow_log_path,
+       sys_var_backupdir;
 
 /* key_cache functions */
 KEY_CACHE *get_key_cache(LEX_STRING *cache_name);

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-08-22 17:03:15 +0000
+++ b/sql/share/errmsg.txt	2008-08-27 12:49:58 +0000
@@ -6374,3 +6374,5 @@ ER_BACKUP_OBTAIN_NAME_LOCK_FAILED
   eng "Restore failed to obtain the name locks on the tables."
 ER_BACKUP_RELEASE_NAME_LOCK_FAILED
   eng "Restore failed to release the name locks on the tables."
+ER_BACKUP_BACKUPDIR
+  eng "The path specified for the system variable backupdir cannot be accessed or is invalid. ref: %-.64s"

=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc	2008-08-25 10:16:09 +0000
+++ b/sql/si_objects.cc	2008-08-27 12:49:58 +0000
@@ -1776,8 +1776,11 @@ bool TableObj::do_serialize(THD *thd, St
   /*
     Open the view and its base tables or views
   */
-  if (open_normal_and_derived_tables(thd, table_list, 0))
-    DBUG_RETURN(FALSE);
+  if (open_normal_and_derived_tables(thd, table_list, 0)) {
+    close_thread_tables(thd);
+    thd->lex->select_lex.table_list.empty();
+    DBUG_RETURN(TRUE);
+  }
 
   /*
     Setup view specific variables and settings

=== modified file 'sql/sp_pcontext.cc'
--- a/sql/sp_pcontext.cc	2008-04-09 00:56:49 +0000
+++ b/sql/sp_pcontext.cc	2008-06-12 20:20:47 +0000
@@ -51,7 +51,8 @@ sp_cond_check(LEX_STRING *sqlstate)
 	(c < 'A' || 'Z' < c))
       return FALSE;
   }
-  if (strcmp(sqlstate->str, "00000") == 0)
+  /* SQLSTATE class '00' : completion condition */
+  if (strncmp(sqlstate->str, "00", 2) == 0)
     return FALSE;
   return TRUE;
 }

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2008-02-19 12:59:19 +0000
+++ b/sql/sql_error.cc	2008-07-29 22:03:57 +0000
@@ -97,12 +97,9 @@ void mysql_reset_errors(THD *thd, bool f
     level		Severity of warning (note, warning, error ...)
     code		Error number
     msg			Clear error message
-    
-  RETURN
-    pointer on MYSQL_ERROR object
 */
 
-MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, 
+void push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, 
                           uint code, const char *msg)
 {
   MYSQL_ERROR *err= 0;
@@ -111,7 +108,7 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQ
 
   if (level == MYSQL_ERROR::WARN_LEVEL_NOTE &&
       !(thd->options & OPTION_SQL_NOTES))
-    DBUG_RETURN(0);
+    DBUG_VOID_RETURN;
 
   if (thd->query_id != thd->warn_id && !thd->spcont)
     mysql_reset_errors(thd, 0);
@@ -138,12 +135,12 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQ
   }
 
   if (thd->handle_error(code, msg, level))
-    DBUG_RETURN(NULL);
+    DBUG_VOID_RETURN;
 
   if (thd->spcont &&
       thd->spcont->handle_error(code, level, thd))
   {
-    DBUG_RETURN(NULL);
+    DBUG_VOID_RETURN;
   }
   query_cache_abort(&thd->query_cache_tls);
 
@@ -156,7 +153,7 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQ
   }
   thd->warn_count[(uint) level]++;
   thd->total_warn_count++;
-  DBUG_RETURN(err);
+  DBUG_VOID_RETURN;
 }
 
 /*

=== modified file 'sql/sql_error.h'
--- a/sql/sql_error.h	2008-07-22 14:16:22 +0000
+++ b/sql/sql_error.h	2008-08-27 12:49:58 +0000
@@ -41,8 +41,8 @@ private:
   void set_msg(THD *thd, const char *msg_arg);
 };
 
-MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
-                          uint code, const char *msg);
+void push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
+                  uint code, const char *msg);
 void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
 			 uint code, const char *format, ...);
 void mysql_reset_errors(THD *thd, bool force);

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-08-25 10:16:09 +0000
+++ b/sql/sql_parse.cc	2008-08-27 12:49:58 +0000
@@ -42,7 +42,7 @@
   @defgroup Runtime_Environment Runtime Environment
   @{
 */
-int execute_backup_command(THD*,LEX*);
+int execute_backup_command(THD*, LEX*, String*);
 
 /* Used in error handling only */
 #define SP_TYPE_STRING(LP) \
@@ -2308,10 +2308,21 @@ mysql_execute_command(THD *thd)
 #else
   {
     /*
+      Create a string from the backupdir system variable and pass
+      to backup system.
+    */
+    String backupdir;
+
+    backupdir.alloc(sys_var_backupdir.value_length);
+    backupdir.set_ascii(sys_var_backupdir.value, 
+                        sys_var_backupdir.value_length);
+    backupdir.length(sys_var_backupdir.value_length);
+
+    /*
       Note: execute_backup_command() sends a correct response to the client
       (either ok, result set or error message).
-     */  
-    if (execute_backup_command(thd,lex))
+     */ 
+    if (execute_backup_command(thd, lex, &backupdir))
       goto error;
     break;
   }
@@ -4488,10 +4499,10 @@ create_sp_error:
       }
       break;
     }
-#ifndef DBUG_OFF
   case SQLCOM_SHOW_PROC_CODE:
   case SQLCOM_SHOW_FUNC_CODE:
     {
+#ifndef DBUG_OFF
       sp_head *sp;
 
       if (lex->sql_command == SQLCOM_SHOW_PROC_CODE)
@@ -4508,8 +4519,12 @@ create_sp_error:
         goto error;
       }
       break;
-    }
+#else
+      my_error(ER_FEATURE_DISABLED, MYF(0),
+               "SHOW PROCEDURE|FUNCTION CODE", "--with-debug");
+      goto error;
 #endif // ifndef DBUG_OFF
+    }
   case SQLCOM_SHOW_CREATE_TRIGGER:
     {
       if (lex->spname->m_name.length > NAME_LEN)
@@ -6817,8 +6832,8 @@ bool reload_acl_and_cache(THD *thd, ulon
       tmp_write_to_binlog= 0;
       if (lock_global_read_lock(thd))
 	return 1;                               // Killed
-      if (close_cached_tables(thd, tables, FALSE, (options & REFRESH_FAST) ?
-                              FALSE : TRUE))
+      if (close_cached_tables(thd, tables, FALSE,
+                              (options & REFRESH_FAST) ? FALSE : TRUE))
           result= 1;
       
       if (make_global_read_lock_block_commit(thd)) // Killed

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2008-08-22 17:03:15 +0000
+++ b/sql/sql_select.cc	2008-08-27 12:49:58 +0000
@@ -169,13 +169,11 @@ static int join_read_always_key(JOIN_TAB
 static int join_read_last_key(JOIN_TAB *tab);
 static int join_no_more_records(READ_RECORD *info);
 static int join_read_next(READ_RECORD *info);
-static int join_read_next_different(READ_RECORD *info);
 static int join_init_quick_read_record(JOIN_TAB *tab);
 static int test_if_quick_select(JOIN_TAB *tab);
 static int join_init_read_record(JOIN_TAB *tab);
 static int join_read_first(JOIN_TAB *tab);
 static int join_read_next_same(READ_RECORD *info);
-static int join_read_next_same_diff(READ_RECORD *info);
 static int join_read_last(JOIN_TAB *tab);
 static int join_read_prev_same(READ_RECORD *info);
 static int join_read_prev(READ_RECORD *info);
@@ -1055,6 +1053,12 @@ static
 int setup_semijoin_dups_elimination(JOIN *join, ulonglong options, uint no_jbuf_after)
 {
   table_map cur_map= join->const_table_map | PSEUDO_TABLE_BITS;
+  enum sj_strategy_enum { 
+    SJ_STRATEGY_INVALID,
+    SJ_STRATEGY_INSIDEOUT,
+    SJ_STRATEGY_DUPS_WEEDOUT,
+    SJ_STRATEGY_DUPS_WEEDOUT_JBUF
+  };
   struct {
     /* 
       0 - invalid (EOF marker), 
@@ -1062,7 +1066,7 @@ int setup_semijoin_dups_elimination(JOIN
       2 - Temptable (maybe confluent),
       3 - Temptable with join buffering
     */
-    uint strategy;
+    enum sj_strategy_enum strategy;
     uint start_idx; /* Left range bound */
     uint end_idx;   /* Right range bound */
     /* 
@@ -1086,7 +1090,7 @@ int setup_semijoin_dups_elimination(JOIN
   /*
     First pass: locate the duplicate-generating ranges and pick the strategies.
   */
-  for (i=join->const_tables ; i < join->tables ; i++)
+  for (i= join->const_tables ; i < join->tables ; i++)
   {
     JOIN_TAB *tab=join->join_tab+i;
     TABLE *table=tab->table;
@@ -1104,7 +1108,7 @@ int setup_semijoin_dups_elimination(JOIN
           be that it overlaps with anther semi-join's range. we don't
           support InsideOut for joined ranges)
         */
-        if (join->best_positions[i].use_insideout_scan)
+        if (join->best_positions[i].insideout_key != MAX_KEY)
           emb_insideout_nest= tab->emb_sj_nest;
       }
 
@@ -1174,7 +1178,7 @@ int setup_semijoin_dups_elimination(JOIN
           bitmap_covers(cur_map, emb_insideout_nest->sj_inner_tables))
       {
         /* Save that this range is handled with InsideOut: */
-        dups_ranges[cur_range].strategy= 1;
+        dups_ranges[cur_range].strategy= SJ_STRATEGY_INSIDEOUT;
         end_of_range= TRUE;
       }
       else if (bitmap_covers(cur_map, emb_outer_tables | emb_sj_map))
@@ -1183,7 +1187,9 @@ int setup_semijoin_dups_elimination(JOIN
           This is a complete range to be handled with either DuplicateWeedout 
           or FirstMatch
         */
-        dups_ranges[cur_range].strategy= dealing_with_jbuf? 3 : 2;
+        dups_ranges[cur_range].strategy= 
+          dealing_with_jbuf? SJ_STRATEGY_DUPS_WEEDOUT_JBUF: 
+                             SJ_STRATEGY_DUPS_WEEDOUT;
         /* 
           This will hold tables from within the range that need to be put 
           into the join buffer before we can use the FirstMatch on its tail.
@@ -1199,7 +1205,7 @@ int setup_semijoin_dups_elimination(JOIN
         emb_sj_map= emb_outer_tables= 0;
         emb_insideout_nest= NULL;
         dealing_with_jbuf= FALSE;
-        dups_ranges[++cur_range].strategy= 0;
+        dups_ranges[++cur_range].strategy= SJ_STRATEGY_INVALID;
       }
       else
       {
@@ -1213,18 +1219,27 @@ int setup_semijoin_dups_elimination(JOIN
   THD *thd= join->thd;
   SJ_TMP_TABLE **next_sjtbl_ptr= &join->sj_tmp_tables;
   /*
-    Second pass: setup the chosen strategies    
+    The second pass: setup the chosen strategies    
   */
   for (int j= 0; j < cur_range; j++)
   {
     JOIN_TAB *tab=join->join_tab + dups_ranges[j].start_idx;
     JOIN_TAB *jump_to;
-    if (dups_ranges[j].strategy == 1)  // InsideOut strategy
+    if (dups_ranges[j].strategy == SJ_STRATEGY_INSIDEOUT)
     {
+      /* We jump from the last table to the first one */
       tab->insideout_match_tab= join->join_tab + dups_ranges[j].end_idx - 1;
+      
+      /* Calculate key length */
+      uint nparts= join->best_positions[dups_ranges[j].start_idx].insideout_parts;
+      uint keyno= join->best_positions[dups_ranges[j].start_idx].insideout_key;
+      uint keylen= 0;
+      for (uint kp=0; kp < nparts; kp++)
+        keylen += tab->table->key_info[keyno].key_part[kp].store_length;
+      tab->insideout_key_len= keylen;
       jump_to= tab++;
     }
-    else // DuplicateWeedout strategy
+    else // DuplicateWeedout or FirstMatch
     {
       SJ_TMP_TABLE::TAB sjtabs[MAX_TABLES];
       table_map cur_map= join->const_table_map | PSEUDO_TABLE_BITS;
@@ -5417,9 +5432,16 @@ best_access_path(JOIN      *join,
   table_map best_ref_depends_map= 0;
   double tmp;
   ha_rows rec;
-  uint best_is_sj_inside_out=    0;
+  uint best_is_sj_inside_out= MAX_KEY;
+  uint best_sj_keyparts;
+  bool try_sj_inside_out= FALSE;
+  uint sj_insideout_quick_select= FALSE;
+  uint sj_insideout_quick_max_sj_keypart;
+  uint sj_inside_out_scan= MAX_KEY;
   DBUG_ENTER("best_access_path");
-
+  
+  LINT_INIT(best_sj_keyparts); // Protected by sj_inside_out_scan
+  LINT_INIT(sj_insideout_quick_max_sj_keypart); // Protected by sj_insideout_quick_*
   if (s->keyuse)
   {                                            /* Use key if possible */
     TABLE *table= s->table;
@@ -5427,14 +5449,13 @@ best_access_path(JOIN      *join,
     double best_records= DBL_MAX;
     uint max_key_part=0;
     ulonglong bound_sj_equalities= 0;
-    bool try_sj_inside_out= FALSE;
     /*
       Discover the bound equalites. We need to do this, if
         1. The next table is an SJ-inner table, and
         2. It is the first table from that semijoin, and
         3. We're not within a semi-join range (i.e. all semi-joins either have
            all or none of their tables in join_table_map), except
-           s->emb_sj_nest (which we've just entered).
+           s->emb_sj_nest (which we've just entered, see #2).
         4. All non-IN-equality correlation references from this sj-nest are 
            bound
         5. But some of the IN-equalities aren't (so this can't be handled by 
@@ -5447,12 +5468,15 @@ best_access_path(JOIN      *join,
         join->cur_emb_sj_nests == s->emb_sj_nest->sj_inner_tables &&    // (3)
         !(remaining_tables & 
           s->emb_sj_nest->nested_join->sj_corr_tables) &&               // (4)
-        remaining_tables & s->emb_sj_nest->nested_join->sj_depends_on)  // (5)
+        remaining_tables & s->emb_sj_nest->nested_join->sj_depends_on &&// (5)
+        !test(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_NO_LOOSE_SCAN))
     {
       /* This table is an InsideOut scan candidate */
       bound_sj_equalities= get_bound_sj_equalities(s->emb_sj_nest, 
                                                    remaining_tables);
       try_sj_inside_out= TRUE;
+      DBUG_PRINT("info", ("Will try InsideOut scan, bound_map=%llx",
+                          (longlong)bound_sj_equalities));
     }
 
     /* Test how we can use keys */
@@ -5473,6 +5497,9 @@ best_access_path(JOIN      *join,
       start_key= keyuse;
       ulonglong handled_sj_equalities=0;
       key_part_map sj_insideout_map= 0;
+      uint max_sj_keypart= 0;
+      DBUG_PRINT("info", ("Considering ref access on key %s",
+                          keyuse->table->key_info[keyuse->key].name));
 
       do /* For each keypart */
       {
@@ -5520,6 +5547,7 @@ best_access_path(JOIN      *join,
             {
               handled_sj_equalities |= 1ULL << keyuse->sj_pred_no;
               sj_insideout_map |= ((key_part_map)1) << keyuse->keypart;
+              set_if_bigger(max_sj_keypart, keyuse->keypart);
             }
           }
 
@@ -5538,7 +5566,7 @@ best_access_path(JOIN      *join,
       if (rec < MATCHING_ROWS_IN_OTHER_TABLE)
         rec= MATCHING_ROWS_IN_OTHER_TABLE;      // Fix for small tables
 
-      bool sj_inside_out_scan= FALSE;
+      sj_inside_out_scan= MAX_KEY;
       /*
         ft-keys require special treatment
       */
@@ -5555,49 +5583,66 @@ best_access_path(JOIN      *join,
       {
         found_constraint= test(found_part);
         /*
-          Check if InsideOut scan is applicable:
-          1. All IN-equalities are either "bound" or "handled"
-          2. Index keyparts are 
-             ...
+          Check if we can use InsideOut semi-join strategy. We can if
+          1. This is the right table at right location
+          2. All IN-equalities are either
+             - "bound", ie. the outer_expr part refers to the preceding tables
+             - "handled", ie. covered by the index we're considering
+          3. Index order allows to enumerate subquery's duplicate groups in
+             order. This happens when the index definition matches this
+             pattern:
+
+               (handled_col|bound_col)* (other_col|bound_col)
+
         */
-        if (try_sj_inside_out && 
-            table->covering_keys.is_set(key) &&
-            (handled_sj_equalities | bound_sj_equalities) ==     // (1)
-            PREV_BITS(ulonglong, s->emb_sj_nest->sj_in_exprs)) // (1)
+        if (try_sj_inside_out &&                                    // (1)
+            (handled_sj_equalities | bound_sj_equalities) ==      // (2)
+            PREV_BITS(ulonglong, s->emb_sj_nest->sj_in_exprs) &&  // (2)
+            (PREV_BITS(key_part_map, max_sj_keypart+1) &           // (3)
+             (found_part | sj_insideout_map)) ==                     // (3)
+             (found_part | sj_insideout_map) &&                     // (3)
+            !key_uses_partial_cols(s->table, key))
         {
-          uint n_fixed_parts= max_part_bit(found_part);
-          if (n_fixed_parts != keyinfo->key_parts &&
-              (PREV_BITS(uint, n_fixed_parts) | sj_insideout_map) ==
-               PREV_BITS(uint, keyinfo->key_parts))
+          /* Ok, can use the strategy */
+          sj_inside_out_scan= key;
+          if (s->quick && s->quick->index == key && 
+              s->quick->get_type() == QUICK_SELECT_I::QS_TYPE_RANGE)
           {
-            /*
-              Not all parts are fixed. Produce bitmap of remaining bits and
-              check if all of them are covered.
-            */
-            sj_inside_out_scan= TRUE;
-            DBUG_PRINT("info", ("Using sj InsideOut scan"));
-            if (!n_fixed_parts)
-            {
-              /*
-                It's a confluent ref scan.
+            sj_insideout_quick_select= TRUE;
+            sj_insideout_quick_max_sj_keypart= max_sj_keypart;
+          }
+          DBUG_PRINT("info", ("Can use InsideOut scan"));
 
-                That is, all found KEYUSE elements refer to IN-equalities,
-                and there is really no ref access because there is no
-                  t.keypart0 = {bound expression}
+          /* 
+            Check if this is a confluent where there are no usable bound
+            IN-equalities, e.g. we have
 
-                Calculate the cost of complete loose index scan.
-              */
-              records= (double)s->table->file->stats.records;
+              outer_expr IN (SELECT innertbl.key FROM ...) 
+            
+            and outer_expr cannot be evaluated yet, so it's actually full
+            index scan and not a ref access
+          */
+          if (!(found_part & 1 ) && /* no usable ref access for 1st key part */
+              table->covering_keys.is_set(key))
+          {
+            DBUG_PRINT("info", ("Can use full index scan for InsideOut"));
+            /* Calculate the cost of complete loose index scan.  */
+            records= rows2double(s->table->file->stats.records);
 
-              /* The cost is entire index scan cost (divided by 2) */
-              best_time= s->table->file->index_only_read_time(key, records);
+            /* The cost is entire index scan cost (divided by 2) */
+            best_time= s->table->file->index_only_read_time(key, records);
 
-              /* Now figure how many different keys we will get */
-              ulong rpc;
-              if ((rpc= keyinfo->rec_per_key[keyinfo->key_parts-1]))
-                records= records / rpc;
-              start_key= NULL;
-            }
+            /*
+              Now find out how many different keys we will get (for now we
+              ignore the fact that we have "keypart_i=const" restriction for
+              some key components, that may make us think think that loose
+              scan will produce more distinct records than it actually will)
+            */
+            ulong rpc;
+            if ((rpc= keyinfo->rec_per_key[max_sj_keypart]))
+              records= records / rpc;
+            start_key= NULL;
+            /* Fall through */
           }
         }
 
@@ -5852,7 +5897,7 @@ best_access_path(JOIN      *join,
             tmp= best_time;                    // Do nothing
         }
 
-        if (sj_inside_out_scan && !start_key)
+        if ((sj_inside_out_scan != MAX_KEY) && !start_key)
         {
           tmp= tmp/2;
           if (records)
@@ -5869,8 +5914,9 @@ best_access_path(JOIN      *join,
         best_max_key_part= max_key_part;
         best_ref_depends_map= found_ref;
         best_is_sj_inside_out= sj_inside_out_scan;
+        best_sj_keyparts= max_sj_keypart;
       }
-    }
+    } /* for each key */
     records= best_records;
   }
 
@@ -5909,6 +5955,7 @@ best_access_path(JOIN      *join,
         ! s->table->covering_keys.is_clear_all() && best_key && !s->quick) &&// (3)
       !(s->table->force_index && best_key && !s->quick))                 // (4)
   {                                             // Check full join
+    sj_inside_out_scan= MAX_KEY;
     ha_rows rnd_records= s->found_records;
     /*
       If there is a filtering condition on the table (i.e. ref analyzer found
@@ -5948,6 +5995,11 @@ best_access_path(JOIN      *join,
       tmp= record_count *
         (s->quick->read_time +
          (s->found_records - rnd_records)/(double) TIME_FOR_COMPARE);
+      
+      if (sj_insideout_quick_select && idx == join->const_tables)
+      {
+        sj_inside_out_scan= s->quick->index;
+      }
     }
     else
     {
@@ -5999,7 +6051,8 @@ best_access_path(JOIN      *join,
       best_key= 0;
       /* range/index_merge/ALL/index access method are "independent", so: */
       best_ref_depends_map= 0;
-      best_is_sj_inside_out= FALSE;
+      best_is_sj_inside_out= sj_inside_out_scan;
+      best_sj_keyparts= sj_insideout_quick_max_sj_keypart;
     }
   }
 
@@ -6009,7 +6062,8 @@ best_access_path(JOIN      *join,
   join->positions[idx].key=          best_key;
   join->positions[idx].table=        s;
   join->positions[idx].ref_depend_map= best_ref_depends_map;
-  join->positions[idx].use_insideout_scan= best_is_sj_inside_out;
+  join->positions[idx].insideout_key= best_is_sj_inside_out;
+  join->positions[idx].insideout_parts= best_sj_keyparts + 1;
 
   if (!best_key &&
       idx == join->const_tables &&
@@ -6579,13 +6633,6 @@ best_extension_by_limited_search(JOIN   
       double current_record_count, current_read_time;
       advance_sj_state(remaining_tables, s);
 
-      /*
-        psergey-insideout-todo: 
-          when best_access_path() detects it could do an InsideOut scan or 
-          some other scan, have it return an insideout scan and a flag that 
-          requests to "fork" this loop iteration. (Q: how does that behave 
-          when the depth is insufficient??)
-      */
       /* Find the best access method from 's' to the current partial plan */
       best_access_path(join, s, thd, remaining_tables, idx,
                        record_count, read_time);
@@ -6952,7 +6999,7 @@ get_best_combination(JOIN *join)
     DBUG_PRINT("info",("type: %d", j->type));
     if (j->type == JT_CONST)
       continue;					// Handled in make_join_stat..
-
+    j->insideout_match_tab= NULL;
     j->ref.key = -1;
     j->ref.key_parts=0;
 
@@ -6961,6 +7008,7 @@ get_best_combination(JOIN *join)
     if (j->keys.is_clear_all() || !(keyuse= join->best_positions[tablenr].key))
     {
       j->type=JT_ALL;
+      j->index= join->best_positions[tablenr].insideout_key;
       if (tablenr != join->const_tables)
 	join->full_join=1;
     }
@@ -7255,6 +7303,7 @@ make_simple_join(JOIN *join,TABLE *tmp_t
   join_tab->ref.key_parts= 0;
   join_tab->flush_weedout_table= join_tab->check_weed_out_table= NULL;
   join_tab->do_firstmatch= NULL;
+  join_tab->insideout_match_tab= NULL;
   bzero((char*) &join_tab->read_record,sizeof(join_tab->read_record));
   tmp_table->status=0;
   tmp_table->null_row=0;
@@ -7523,7 +7572,15 @@ make_join_select(JOIN *join,SQL_SELECT *
 	  thd->lex->current_select->master_unit() ==
 	  &thd->lex->unit)		// not upper level SELECT
         join->const_table_map|=RAND_TABLE_BIT;
-      {						// Check const tables
+
+      /*
+        Extract expressions that depend on constant tables
+        1. Const part of the join's WHERE clause can be checked immediately
+           and if it is not satisfied then the join has empty result
+        2. Constant parts of outer joins' ON expressions must be attached 
+           there inside the triggers.
+      */
+      {
         COND *const_cond=
 	  make_cond_for_table(cond,
                               join->const_table_map,
@@ -7770,9 +7827,9 @@ make_join_select(JOIN *join,SQL_SELECT *
 	    tab->keys=sel->quick_keys;
             tab->keys.merge(sel->needed_reg);
 	    tab->use_quick= (!sel->needed_reg.is_clear_all() &&
-			     (select->quick_keys.is_clear_all() ||
-			      (select->quick &&
-			       (select->quick->records >= 100L)))) ?
+			     (sel->quick_keys.is_clear_all() ||
+			      (sel->quick &&
+			       (sel->quick->records >= 100L)))) ?
 	      2 : 1;
 	    sel->read_tables= used_tables & ~current_map;
 	  }
@@ -8288,9 +8345,8 @@ make_join_readinfo(JOIN *join, ulonglong
     sorted= 0;                                  // only first must be sorted
     if (tab->insideout_match_tab)
     {
-      if (!(tab->insideout_buf= (uchar*)join->thd->alloc(tab->table->key_info
-                                                         [tab->index].
-                                                         key_length)))
+      if (!(tab->insideout_buf= 
+            (uchar*)join->thd->alloc(tab->insideout_key_len)))
         return TRUE;
     }
     switch (tab->type) {
@@ -8351,8 +8407,7 @@ make_join_readinfo(JOIN *join, ulonglong
       if (tab->type == JT_REF)
       {
 	tab->read_first_record= join_read_always_key;
-	tab->read_record.read_record= tab->insideout_match_tab? 
-           join_read_next_same_diff : join_read_next_same;
+        tab->read_record.read_record= join_read_next_same;
       }
       else
       {
@@ -12326,9 +12381,11 @@ err:
   SYNOPSIS
 
     create_duplicate_weedout_tmp_table()
-      thd
-      uniq_tuple_length_arg
-      SJ_TMP_TABLE 
+      thd                    Thread handle
+      uniq_tuple_length_arg  Length of the table's column
+      sjtbl                  Update sjtbl->[start_]recinfo values which 
+                             will be needed if we'll need to convert the 
+                             created temptable from HEAP to MyISAM/Maria.
 
   DESCRIPTION
     Create a temporary table to weed out duplicate rowid combinations. The
@@ -13650,9 +13707,25 @@ sub_select(JOIN *join,JOIN_TAB *join_tab
     Note: psergey has added the 2nd part of the following condition; the 
     change should probably be made in 5.1, too.
   */
+  bool skip_over= FALSE;
   while (rc == NESTED_LOOP_OK && join->return_tab >= join_tab)
   {
+    if (join_tab->insideout_match_tab && join_tab->insideout_match_tab->found_match)
+    {
+      KEY *key= join_tab->table->key_info + join_tab->index;
+      key_copy(join_tab->insideout_buf, info->record, key, 
+               join_tab->insideout_key_len);
+      skip_over= TRUE;
+    }
     error= info->read_record(info);
+
+    if (skip_over && !error && 
+        !key_cmp(join_tab->table->key_info[join_tab->index].key_part,
+                 join_tab->insideout_buf, join_tab->insideout_key_len))
+    {
+      continue;
+    }
+
     rc= evaluate_join_record(join, join_tab, error);
   }
 
@@ -13673,7 +13746,14 @@ sub_select(JOIN *join,JOIN_TAB *join_tab
 
   SYNPOSIS
     do_sj_dups_weedout()
-      
+      thd    Thread handle
+      sjtbl  Duplicate weedout table
+
+  DESCRIPTION
+    Try storing current record combination of outer tables (i.e. their
+    rowids) in the temporary table. This records the fact that we've seen 
+    this record combination and also tells us if we've seen it before.
+
   RETURN
     -1  Error
     1   The row combination is a duplicate (discard it)
@@ -13737,7 +13817,6 @@ int do_sj_dups_weedout(THD *thd, SJ_TMP_
                                             sjtbl->start_recinfo,
                                             &sjtbl->recinfo, error, 1))
       return -1;
-    //return (error == HA_ERR_FOUND_DUPP_KEY || error== HA_ERR_FOUND_DUPP_UNIQUE) ? 1: -1;
     return 1;
   }
   return 0;
@@ -14380,37 +14459,6 @@ join_no_more_records(READ_RECORD *info _
   return -1;
 }
 
-static int
-join_read_next_same_diff(READ_RECORD *info)
-{
-  TABLE *table= info->table;
-  JOIN_TAB *tab=table->reginfo.join_tab;
-  if (tab->insideout_match_tab->found_match)
-  {
-    KEY *key= tab->table->key_info + tab->index;
-    do 
-    {
-      int error;
-      /* Save index tuple from record to the buffer */
-      key_copy(tab->insideout_buf, info->record, key, 0);
-
-      if ((error=table->file->index_next_same(table->record[0],
-                                              tab->ref.key_buff,
-                                              tab->ref.key_length)))
-      {
-        if (error != HA_ERR_END_OF_FILE)
-          return report_error(table, error);
-        table->status= STATUS_GARBAGE;
-        return -1;
-      }
-    } while (!key_cmp(tab->table->key_info[tab->index].key_part, 
-                      tab->insideout_buf, key->key_length));
-    tab->insideout_match_tab->found_match= 0;
-    return 0;
-  }
-  else
-    return join_read_next_same(info);
-}
 
 static int
 join_read_next_same(READ_RECORD *info)
@@ -14505,17 +14553,7 @@ join_read_first(JOIN_TAB *tab)
   tab->read_record.file=table->file;
   tab->read_record.index=tab->index;
   tab->read_record.record=table->record[0];
-  if (tab->insideout_match_tab)
-  {
-    tab->read_record.do_insideout_scan= tab;
-    tab->read_record.read_record=join_read_next_different;
-    tab->insideout_match_tab->found_match= 0;
-  }
-  else
-  {
-    tab->read_record.read_record=join_read_next;
-    tab->read_record.do_insideout_scan= 0;
-  }
+  tab->read_record.read_record=join_read_next;
 
   if (!table->file->inited)
     table->file->ha_index_init(tab->index, tab->sorted);
@@ -14530,32 +14568,6 @@ join_read_first(JOIN_TAB *tab)
 
 
 static int
-join_read_next_different(READ_RECORD *info)
-{
-  JOIN_TAB *tab= info->do_insideout_scan;
-  if (tab->insideout_match_tab->found_match)
-  {
-    KEY *key= tab->table->key_info + tab->index;
-    do 
-    {
-      int error;
-      /* Save index tuple from record to the buffer */
-      key_copy(tab->insideout_buf, info->record, key, 0);
-
-      if ((error=info->file->index_next(info->record)))
-        return report_error(info->table, error);
-      
-    } while (!key_cmp(tab->table->key_info[tab->index].key_part, 
-                      tab->insideout_buf, key->key_length));
-    tab->insideout_match_tab->found_match= 0;
-    return 0;
-  }
-  else
-    return join_read_next(info);
-}
-
-
-static int
 join_read_next(READ_RECORD *info)
 {
   int error;

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2008-07-11 16:22:44 +0000
+++ b/sql/sql_select.h	2008-08-16 15:22:47 +0000
@@ -272,15 +272,20 @@ typedef struct st_join_table {
   struct st_join_table  *do_firstmatch;
  
   /* 
-     ptr  - this join tab should do an InsideOut scan. Points 
-            to the tab for which we'll need to check tab->found_match.
-
+     ptr  - We're doing and InsideOut scan, and this is the first (aka
+            "driving" join tab). ptr to the last tab, for which we'll need 
+            to check tab->found_match to see if the current value group had
+            a match.
      NULL - Not an insideout scan.
   */
   struct st_join_table *insideout_match_tab;
-  uchar *insideout_buf; // Buffer to save index tuple to be able to skip dups
+  /* Buffer to save index tuple to be able to skip duplicates */
+  uchar *insideout_buf;
+  
+  /* Length of key tuple (depends on #keyparts used) to store in the above */
+  uint insideout_key_len;
 
-  /* Used by InsideOut scan. Just set to true when have found a row. */
+  /* Used by LooseScan. TRUE<=> there has been a matching record combination */
   bool found_match;
 
   enum { 
@@ -348,8 +353,16 @@ typedef struct st_position
 
   /* If ref-based access is used: bitmap of tables this table depends on  */
   table_map ref_depend_map;
-
-  bool use_insideout_scan;
+  
+  /* 
+    keyno  - This is an insideout scan on this key. If keyuse is NULL then
+              this is a full index scan, otherwise this is a ref + insideout
+              scan (and keyno matches the KEUSE's)
+    MAX_KEY - This is not an InsideOut scan
+  */
+  uint insideout_key;
+  /* Number of key parts to be used by insideout */
+  uint insideout_parts;
 } POSITION;
 
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2008-08-25 10:16:09 +0000
+++ b/sql/sql_show.cc	2008-08-27 12:49:58 +0000
@@ -4051,7 +4051,9 @@ int fill_schema_charsets(THD *thd, TABLE
   TABLE *table= tables->table;
   CHARSET_INFO *scs= system_charset_info;
 
-  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
+  for (cs= all_charsets ;
+       cs < all_charsets + array_elements(all_charsets) ;
+       cs++)
   {
     CHARSET_INFO *tmp_cs= cs[0];
     if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
@@ -4130,7 +4132,9 @@ int fill_schema_collation(THD *thd, TABL
   const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
   TABLE *table= tables->table;
   CHARSET_INFO *scs= system_charset_info;
-  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
+  for (cs= all_charsets ;
+       cs < all_charsets + array_elements(all_charsets)  ;
+       cs++ )
   {
     CHARSET_INFO **cl;
     CHARSET_INFO *tmp_cs= cs[0];
@@ -4138,7 +4142,9 @@ int fill_schema_collation(THD *thd, TABL
          (tmp_cs->state & MY_CS_HIDDEN) ||
         !(tmp_cs->state & MY_CS_PRIMARY))
       continue;
-    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
+    for (cl= all_charsets;
+         cl < all_charsets + array_elements(all_charsets)  ;
+         cl ++)
     {
       CHARSET_INFO *tmp_cl= cl[0];
       if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
@@ -4171,14 +4177,18 @@ int fill_schema_coll_charset_app(THD *th
   CHARSET_INFO **cs;
   TABLE *table= tables->table;
   CHARSET_INFO *scs= system_charset_info;
-  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
+  for (cs= all_charsets ;
+       cs < all_charsets + array_elements(all_charsets) ;
+       cs++ )
   {
     CHARSET_INFO **cl;
     CHARSET_INFO *tmp_cs= cs[0];
     if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
         !(tmp_cs->state & MY_CS_PRIMARY))
       continue;
-    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
+    for (cl= all_charsets;
+         cl < all_charsets + array_elements(all_charsets) ;
+         cl ++)
     {
       CHARSET_INFO *tmp_cl= cl[0];
       if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-08-22 17:03:15 +0000
+++ b/sql/sql_yacc.yy	2008-08-27 12:49:58 +0000
@@ -590,10 +590,10 @@ bool my_yyoverflow(short **a, YYSTYPE **
 
 %pure_parser                                    /* We have threads */
 /*
-  Currently there are 172 shift/reduce conflicts.
+  Currently there are 169 shift/reduce conflicts.
   We should not introduce new conflicts any more.
 */
-%expect 172
+%expect 169
 
 /*
    Comments for TOKENS.
@@ -2049,7 +2049,10 @@ opt_ev_status:
 ev_starts:
           /* empty */
           {
-            Lex->event_parse_data->item_starts= new Item_func_now_local();
+            Item *item= new (YYTHD->mem_root) Item_func_now_local();
+            if (item == NULL)
+              MYSQL_YYABORT;
+            Lex->event_parse_data->item_starts= item;
           }
         | STARTS_SYM expr
           {
@@ -2196,6 +2199,8 @@ sp_name:
               MYSQL_YYABORT;
             }
             $$= new sp_name($1, $3, true);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->init_qname(YYTHD);
           }
         | ident
@@ -2210,8 +2215,9 @@ sp_name:
             if (lex->copy_db_to(&db.str, &db.length))
               MYSQL_YYABORT;
             $$= new sp_name(db, $1, false);
-            if ($$)
-              $$->init_qname(thd);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            $$->init_qname(thd);
           }
         ;
 
@@ -2448,6 +2454,7 @@ sp_decl:
           type
           sp_opt_default
           {
+            THD *thd= YYTHD;
             LEX *lex= Lex;
             sp_pcontext *pctx= lex->spcont;
             uint num_vars= pctx->context_var_count();
@@ -2456,7 +2463,9 @@ sp_decl:
             
             if (!dflt_value_item)
             {
-              dflt_value_item= new Item_null();
+              dflt_value_item= new (thd->mem_root) Item_null();
+              if (dflt_value_item == NULL)
+                MYSQL_YYABORT;
               /* QQ Set to the var_type with null_value? */
             }
             
@@ -2482,10 +2491,17 @@ sp_decl:
             
               /* The last instruction is responsible for freeing LEX. */
 
-              lex->sphead->add_instr(
-                new sp_instr_set(lex->sphead->instructions(), pctx, var_idx,
-                                 dflt_value_item, var_type, lex,
-                                 (i == num_vars - 1)));
+              sp_instr_set *is= new sp_instr_set(lex->sphead->instructions(),
+                                                 pctx,
+                                                 var_idx,
+                                                 dflt_value_item,
+                                                 var_type,
+                                                 lex,
+                                                 (i == num_vars - 1));
+              if (is == NULL)
+                MYSQL_YYABORT;
+
+              lex->sphead->add_instr(is);
             }
 
             pctx->declare_var_boundary(0);
@@ -2636,7 +2652,14 @@ sp_hcond_element:
 sp_cond:
           ulong_num
           { /* mysql errno */
+            if ($1 == 0)
+            {
+              my_error(ER_WRONG_VALUE, MYF(0), "CONDITION", "0");
+              MYSQL_YYABORT;
+            }
             $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->type= sp_cond_type_t::number;
             $$->mysqlerr= $1;
           }
@@ -2648,6 +2671,8 @@ sp_cond:
               MYSQL_YYABORT;
             }
             $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->type= sp_cond_type_t::state;
             memcpy($$->sqlstate, $3.str, 5);
             $$->sqlstate[5]= '\0';
@@ -2676,16 +2701,22 @@ sp_hcond:
         | SQLWARNING_SYM /* SQLSTATEs 01??? */
           {
             $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->type= sp_cond_type_t::warning;
           }
         | not FOUND_SYM /* SQLSTATEs 02??? */
           {
             $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->type= sp_cond_type_t::notfound;
           }
         | SQLEXCEPTION_SYM /* All other SQLSTATEs */
           {
             $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->type= sp_cond_type_t::exception;
           }
         ;
@@ -4799,10 +4830,6 @@ key_def:
             /* Only used for ALTER TABLE. Ignored otherwise. */
             lex->alter_info.flags|= ALTER_FOREIGN_KEY;
           }
-        | constraint opt_check_constraint
-          {
-            Lex->col_list.empty(); /* Alloced by sql_alloc */
-          }
         | opt_constraint check_constraint
           {
             Lex->col_list.empty(); /* Alloced by sql_alloc */
@@ -4815,7 +4842,7 @@ opt_check_constraint:
         ;
 
 check_constraint:
-          CHECK_SYM expr
+          CHECK_SYM '(' expr ')'
         ;
 
 opt_constraint:
@@ -5158,7 +5185,12 @@ attribute:
             Lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
           }
         | ON UPDATE_SYM NOW_SYM optional_braces 
-          { Lex->on_update_value= new Item_func_now_local(); }
+          {
+            Item *item= new (YYTHD->mem_root) Item_func_now_local();
+            if (item == NULL)
+              MYSQL_YYABORT;
+            Lex->on_update_value= item;
+          }
         | AUTO_INC { Lex->type|= AUTO_INCREMENT_FLAG | NOT_NULL_FLAG; }
         | SERIAL_SYM DEFAULT VALUE_SYM
           { 
@@ -5202,7 +5234,11 @@ attribute:
 
 now_or_signed_literal:
           NOW_SYM optional_braces
-          { $$= new Item_func_now_local(); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | signed_literal
           { $$=$1; }
         ;
@@ -5584,7 +5620,12 @@ key_list:
         ;
 
 key_part:
-          ident { $$=new Key_part_spec($1, 0); }
+          ident
+          {
+            $$= new Key_part_spec($1, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | ident '(' NUM ')'
           {
             int key_part_len= atoi($3.str);
@@ -5592,7 +5633,9 @@ key_part:
             {
               my_error(ER_KEY_PART_0, MYF(0), $1.str);
             }
-            $$=new Key_part_spec($1, (uint) key_part_len);
+            $$= new Key_part_spec($1, (uint) key_part_len);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         ;
 
@@ -5971,7 +6014,7 @@ reorg_partition_rule:
             lex->part_info= new partition_info();
             if (!lex->part_info)
             {
-            mem_alloc_error(sizeof(partition_info));
+              mem_alloc_error(sizeof(partition_info));
               MYSQL_YYABORT;
             }
             lex->no_write_to_binlog= $3;
@@ -6074,8 +6117,10 @@ alter_list_item:
         | DROP opt_column field_ident opt_restrict
           {
             LEX *lex=Lex;
-            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN,
-                                                               $3.str));
+            Alter_drop *ad= new Alter_drop(Alter_drop::COLUMN, $3.str);
+            if (ad == NULL)
+              MYSQL_YYABORT;
+            lex->alter_info.drop_list.push_back(ad);
             lex->alter_info.flags|= ALTER_DROP_COLUMN;
           }
         | DROP FOREIGN KEY_SYM opt_ident
@@ -6085,15 +6130,19 @@ alter_list_item:
         | DROP PRIMARY_SYM KEY_SYM
           {
             LEX *lex=Lex;
-            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
-                                                               primary_key_name));
+            Alter_drop *ad= new Alter_drop(Alter_drop::KEY, primary_key_name);
+            if (ad == NULL)
+              MYSQL_YYABORT;
+            lex->alter_info.drop_list.push_back(ad);
             lex->alter_info.flags|= ALTER_DROP_INDEX;
           }
         | DROP key_or_index field_ident
           {
             LEX *lex=Lex;
-            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
-                                                               $3.str));
+            Alter_drop *ad= new Alter_drop(Alter_drop::KEY, $3.str);
+            if (ad == NULL)
+              MYSQL_YYABORT;
+            lex->alter_info.drop_list.push_back(ad);
             lex->alter_info.flags|= ALTER_DROP_INDEX;
           }
         | DISABLE_SYM KEYS
@@ -6111,14 +6160,19 @@ alter_list_item:
         | ALTER opt_column field_ident SET DEFAULT signed_literal
           {
             LEX *lex=Lex;
-            lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6));
+            Alter_column *ac= new Alter_column($3.str,$6);
+            if (ac == NULL)
+              MYSQL_YYABORT;
+            lex->alter_info.alter_list.push_back(ac);
             lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
           }
         | ALTER opt_column field_ident DROP DEFAULT
           {
             LEX *lex=Lex;
-            lex->alter_info.alter_list.push_back(new Alter_column($3.str,
-                                                                  (Item*) 0));
+            Alter_column *ac= new Alter_column($3.str, (Item*) 0);
+            if (ac == NULL)
+              MYSQL_YYABORT;
+            lex->alter_info.alter_list.push_back(ac);
             lex->alter_info.flags|= ALTER_COLUMN_DEFAULT;
           }
         | RENAME opt_to table_ident
@@ -6386,15 +6440,19 @@ database_ident_list:
           ident
           {
             LEX *lex= Lex;
+            LEX_STRING* ls= (LEX_STRING*) sql_memdup(&$1, sizeof(LEX_STRING));
+            if (ls == NULL)
+              MYSQL_YYABORT;
             lex->db_list.empty();
-            if (lex->db_list.push_back((LEX_STRING*)
-                sql_memdup(&$1, sizeof(LEX_STRING))))
+            if (lex->db_list.push_back(ls))
               YYABORT;
           }
         | database_ident_list ',' ident
           {
-            if (Lex->db_list.push_back((LEX_STRING*)
-                sql_memdup(&$3, sizeof(LEX_STRING))))
+            LEX_STRING *ls= (LEX_STRING*) sql_memdup(&$3, sizeof(LEX_STRING));
+            if (ls == NULL)
+              MYSQL_YYABORT;
+            if (Lex->db_list.push_back(ls))
               YYABORT;
           }
         ;
@@ -6831,10 +6889,12 @@ select_item_list:
         | '*'
           {
             THD *thd= YYTHD;
-            if (add_item_to_list(thd,
-                                 new Item_field(&thd->lex->current_select->
-                                                context,
-                                                NULL, NULL, "*")))
+            Item *item= new (thd->mem_root)
+                          Item_field(&thd->lex->current_select->context,
+                                     NULL, NULL, "*");
+            if (item == NULL)
+              MYSQL_YYABORT;
+            if (add_item_to_list(thd, item))
               MYSQL_YYABORT;
             (thd->lex->current_select->with_wild)++;
           }
@@ -6947,6 +7007,8 @@ expr:
             {
               /* X OR Y */
               $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
+              if ($$ == NULL)
+                MYSQL_YYABORT;
             }
           }
         | expr XOR expr %prec XOR
@@ -6993,36 +7055,86 @@ expr:
             {
               /* X AND Y */
               $$ = new (YYTHD->mem_root) Item_cond_and($1, $3);
+              if ($$ == NULL)
+                MYSQL_YYABORT;
             }
           }
         | NOT_SYM expr %prec NOT_SYM
-          { $$= negate_expression(YYTHD, $2); }
+          {
+            $$= negate_expression(YYTHD, $2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS TRUE_SYM %prec IS
-          { $$= new (YYTHD->mem_root) Item_func_istrue($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_istrue($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS not TRUE_SYM %prec IS
-          { $$= new (YYTHD->mem_root) Item_func_isnottrue($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnottrue($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS FALSE_SYM %prec IS
-          { $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isfalse($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS not FALSE_SYM %prec IS
-          { $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnotfalse($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS UNKNOWN_SYM %prec IS
-          { $$= new Item_func_isnull($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS not UNKNOWN_SYM %prec IS
-          { $$= new Item_func_isnotnull($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnotnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri
         ;
 
 bool_pri:
           bool_pri IS NULL_SYM %prec IS
-          { $$= new Item_func_isnull($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS not NULL_SYM %prec IS
-          { $$= new Item_func_isnotnull($1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_isnotnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
-          { $$= new Item_func_equal($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_equal($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri comp_op predicate %prec EQ
-          { $$= (*$2)(0)->create($1,$3); }
+          {
+            $$= (*$2)(0)->create($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
-          { $$= all_any_subquery_creator($1, $2, $3, $5); }
+          {
+            $$= all_any_subquery_creator($1, $2, $3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | predicate
         ;
 
@@ -7030,87 +7142,193 @@ predicate:
           bit_expr IN_SYM '(' subselect ')'
           {
             $$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr not IN_SYM '(' subselect ')'
           {
             THD *thd= YYTHD;
             Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
+            if (item == NULL)
+              MYSQL_YYABORT;
             $$= negate_expression(thd, item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr IN_SYM '(' expr ')'
           {
             $$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr IN_SYM '(' expr ',' expr_list ')'
           { 
             $6->push_front($4);
             $6->push_front($1);
             $$= new (YYTHD->mem_root) Item_func_in(*$6);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr not IN_SYM '(' expr ')'
           {
             $$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr not IN_SYM '(' expr ',' expr_list ')'
           {
             $7->push_front($5);
             $7->push_front($1);
             Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
+            if (item == NULL)
+              MYSQL_YYABORT;
             item->negate();
             $$= item;
           }
         | bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
-          { $$= new Item_func_between($1,$3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_between($1,$3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr not BETWEEN_SYM bit_expr AND_SYM predicate
           {
-            Item_func_between *item= new Item_func_between($1,$4,$6);
+            Item_func_between *item;
+            item= new (YYTHD->mem_root) Item_func_between($1,$4,$6);
+            if (item == NULL)
+              MYSQL_YYABORT;
             item->negate();
             $$= item;
           }
         | bit_expr SOUNDS_SYM LIKE bit_expr
           {
-            $$= new Item_func_eq(new Item_func_soundex($1),
-                                 new Item_func_soundex($4));
+            Item *item1= new (YYTHD->mem_root) Item_func_soundex($1);
+            Item *item4= new (YYTHD->mem_root) Item_func_soundex($4);
+            if ((item1 == NULL) || (item4 == NULL))
+              MYSQL_YYABORT;
+            $$= new (YYTHD->mem_root) Item_func_eq(item1, item4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | bit_expr LIKE simple_expr opt_escape
-          { $$= new Item_func_like($1,$3,$4,Lex->escape_used); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_like($1,$3,$4,Lex->escape_used);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr not LIKE simple_expr opt_escape
-          { $$= new Item_func_not(new Item_func_like($1,$4,$5, Lex->escape_used)); }
-        | bit_expr REGEXP bit_expr { $$= new Item_func_regex($1,$3); }
+          {
+            Item *item= new (YYTHD->mem_root) Item_func_like($1,$4,$5,
+                                                             Lex->escape_used);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new (YYTHD->mem_root) Item_func_not(item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | bit_expr REGEXP bit_expr
+          {
+            $$= new (YYTHD->mem_root) Item_func_regex($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr not REGEXP bit_expr
-          { $$= negate_expression(YYTHD, new Item_func_regex($1,$4)); }
+          {
+            Item *item= new (YYTHD->mem_root) Item_func_regex($1,$4);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= negate_expression(YYTHD, item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr
         ;
 
 bit_expr:
           bit_expr '|' bit_expr %prec '|'
-          { $$= new Item_func_bit_or($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_bit_or($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '&' bit_expr %prec '&'
-          { $$= new Item_func_bit_and($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_bit_and($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr SHIFT_LEFT bit_expr %prec SHIFT_LEFT
-          { $$= new Item_func_shift_left($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_shift_left($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr SHIFT_RIGHT bit_expr %prec SHIFT_RIGHT
-          { $$= new Item_func_shift_right($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_shift_right($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '+' bit_expr %prec '+'
-          { $$= new Item_func_plus($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_plus($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '-' bit_expr %prec '-'
-          { $$= new Item_func_minus($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_minus($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '+' INTERVAL_SYM expr interval %prec '+'
-          { $$= new Item_date_add_interval($1,$4,$5,0); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($1,$4,$5,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '-' INTERVAL_SYM expr interval %prec '-'
-          { $$= new Item_date_add_interval($1,$4,$5,1); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($1,$4,$5,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '*' bit_expr %prec '*'
-          { $$= new Item_func_mul($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_mul($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '/' bit_expr %prec '/'
-          { $$= new Item_func_div($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_div($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '%' bit_expr %prec '%'
-          { $$= new Item_func_mod($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_mod($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr DIV_SYM bit_expr %prec DIV_SYM
-          { $$= new Item_func_int_div($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_int_div($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr MOD_SYM bit_expr %prec MOD_SYM
-          { $$= new Item_func_mod($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_mod($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '^' bit_expr
-          { $$= new Item_func_bit_xor($1,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_bit_xor($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | simple_expr
         ;
 
@@ -7160,45 +7378,80 @@ simple_expr:
             Item *i1= new (thd->mem_root) Item_string($3.str,
                                                       $3.length,
                                                       thd->charset());
+            if (i1 == NULL)
+              MYSQL_YYABORT;
             $$= new (thd->mem_root) Item_func_set_collation($1, i1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | literal
         | param_marker
         | variable
         | sum_expr
         | simple_expr OR_OR_SYM simple_expr
-          { $$= new (YYTHD->mem_root) Item_func_concat($1, $3); }
-        | '+' simple_expr %prec NEG { $$= $2; }
+          {
+            $$= new (YYTHD->mem_root) Item_func_concat($1, $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | '+' simple_expr %prec NEG
+          {
+            $$= $2;
+          }
         | '-' simple_expr %prec NEG
-          { $$= new (YYTHD->mem_root) Item_func_neg($2); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_neg($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | '~' simple_expr %prec NEG
-          { $$= new (YYTHD->mem_root) Item_func_bit_neg($2); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_bit_neg($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | not2 simple_expr %prec NEG
-          { $$= negate_expression(YYTHD, $2); }
+          {
+            $$= negate_expression(YYTHD, $2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | '(' subselect ')'
           { 
             $$= new (YYTHD->mem_root) Item_singlerow_subselect($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
-        | '(' expr ')' { $$= $2; }
+        | '(' expr ')'
+          { $$= $2; }
         | '(' expr ',' expr_list ')'
           {
             $4->push_front($2);
             $$= new (YYTHD->mem_root) Item_row(*$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | ROW_SYM '(' expr ',' expr_list ')'
           {
             $5->push_front($3);
             $$= new (YYTHD->mem_root) Item_row(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | EXISTS '(' subselect ')'
           {
             $$= new (YYTHD->mem_root) Item_exists_subselect($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
-        | '{' ident expr '}' { $$= $3; }
+        | '{' ident expr '}'
+          { $$= $3; }
         | MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')'
           {
             $2->push_front($5);
             Item_func_match *i1= new (YYTHD->mem_root) Item_func_match(*$2, $6);
+            if (i1 == NULL)
+              MYSQL_YYABORT;
             Select->add_ftfunc_to_list(i1);
             $$= i1;
           }
@@ -7206,26 +7459,36 @@ simple_expr:
           {
             $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
                                  &my_charset_bin);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | CAST_SYM '(' expr AS cast_type ')'
           {
             LEX *lex= Lex;
             $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
                                  lex->charset);
-            if (!$$)
+            if ($$ == NULL)
               MYSQL_YYABORT;
           }
         | CASE_SYM opt_expr when_list opt_else END
-          { $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 );
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | CONVERT_SYM '(' expr ',' cast_type ')'
           {
             $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
                                  Lex->charset);
-            if (!$$)
+            if ($$ == NULL)
               MYSQL_YYABORT;
           }
         | CONVERT_SYM '(' expr USING charset_name ')'
-          { $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_conv_charset($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | DEFAULT '(' simple_ident ')'
           {
             if ($3->is_splocal())
@@ -7237,15 +7500,23 @@ simple_expr:
             }
             $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context(),
                                                          $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | VALUES '(' simple_ident_nospvar ')'
           {
             $$= new (YYTHD->mem_root) Item_insert_value(Lex->current_context(),
                                                         $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
           /* we cannot put interval before - */
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($5,$2,$3,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 /*
@@ -7256,31 +7527,63 @@ simple_expr:
 */
 function_call_keyword:
           CHAR_SYM '(' expr_list ')'
-          { $$= new (YYTHD->mem_root) Item_func_char(*$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_char(*$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | CHAR_SYM '(' expr_list USING charset_name ')'
-          { $$= new (YYTHD->mem_root) Item_func_char(*$3, $5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_char(*$3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | CURRENT_USER optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->set_stmt_unsafe();
             Lex->safe_to_cache_query= 0;
           }
         | DATE_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_date_typecast($3); }
-        | DAY_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_dayofmonth($3); }
-        | HOUR_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_hour($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | DAY_SYM '(' expr ')'
+          {
+            $$= new (YYTHD->mem_root) Item_func_dayofmonth($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | HOUR_SYM '(' expr ')'
+          {
+            $$= new (YYTHD->mem_root) Item_func_hour($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | INSERT '(' expr ',' expr ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_insert($3,$5,$7,$9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | INTERVAL_SYM '(' expr ',' expr ')' %prec INTERVAL_SYM
           {
             THD *thd= YYTHD;
             List<Item> *list= new (thd->mem_root) List<Item>;
+            if (list == NULL)
+              MYSQL_YYABORT;
             list->push_front($5);
             list->push_front($3);
             Item_row *item= new (thd->mem_root) Item_row(*list);
+            if (item == NULL)
+              MYSQL_YYABORT;
             $$= new (thd->mem_root) Item_func_interval(item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | INTERVAL_SYM '(' expr ',' expr ',' expr_list ')' %prec INTERVAL_SYM
           {
@@ -7288,48 +7591,120 @@ function_call_keyword:
             $7->push_front($5);
             $7->push_front($3);
             Item_row *item= new (thd->mem_root) Item_row(*$7);
+            if (item == NULL)
+              MYSQL_YYABORT;
             $$= new (thd->mem_root) Item_func_interval(item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | LEFT '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_left($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_left($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MINUTE_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_minute($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_minute($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MONTH_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_month($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_month($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | RIGHT '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_right($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_right($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SECOND_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_second($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_second($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TIME_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_time_typecast($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_time_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TIMESTAMP '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_datetime_typecast($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_datetime_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TIMESTAMP '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_add_time($3, $5, 1, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_trim($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_trim($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' LEADING expr FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_ltrim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' TRAILING expr FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_rtrim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' BOTH expr FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_trim($6,$4); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_trim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' LEADING FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_ltrim($5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_ltrim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' TRAILING FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_rtrim($5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_rtrim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' BOTH FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_trim($5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_trim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRIM '(' expr FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_trim($5,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_trim($5,$3);
+          }
         | USER '(' ')'
           {
             $$= new (YYTHD->mem_root) Item_func_user();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->set_stmt_unsafe();
             Lex->safe_to_cache_query=0;
           }
         | YEAR_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_year($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_year($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 /*
@@ -7349,65 +7724,127 @@ function_call_nonkeyword:
           {
             $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
                                                              INTERVAL_DAY, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | CURDATE optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_curdate_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | CURTIME optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_curtime_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | CURTIME '(' expr ')'
           {
             $$= new (YYTHD->mem_root) Item_func_curtime_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
-        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0); }
-        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' %prec INTERVAL_SYM
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1); }
+        | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
+          %prec INTERVAL_SYM
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
+          %prec INTERVAL_SYM
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($3,$6,$7,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | EXTRACT_SYM '(' interval FROM expr ')'
-          { $$=new (YYTHD->mem_root) Item_extract( $3, $5); }
+          {
+            $$=new (YYTHD->mem_root) Item_extract( $3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | GET_FORMAT '(' date_time_type  ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_get_format($3, $5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_get_format($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | NOW_SYM optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | NOW_SYM '(' expr ')'
           {
             $$= new (YYTHD->mem_root) Item_func_now_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | POSITION_SYM '(' bit_expr IN_SYM expr ')'
-          { $$ = new (YYTHD->mem_root) Item_func_locate($5,$3); }
+          {
+            $$ = new (YYTHD->mem_root) Item_func_locate($5,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUBDATE_SYM '(' expr ',' expr ')'
           {
             $$= new (YYTHD->mem_root) Item_date_add_interval($3, $5,
                                                              INTERVAL_DAY, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($3, $6, $7, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUBSTRING '(' expr ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUBSTRING '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_substr($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_substr($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUBSTRING '(' expr FROM expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_substr($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_substr($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SYSDATE optional_braces
           {
             if (global_system_variables.sysdate_is_now == 0)
               $$= new (YYTHD->mem_root) Item_func_sysdate_local();
             else
               $$= new (YYTHD->mem_root) Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | SYSDATE '(' expr ')'
@@ -7416,25 +7853,41 @@ function_call_nonkeyword:
               $$= new (YYTHD->mem_root) Item_func_sysdate_local($3);
             else
               $$= new (YYTHD->mem_root) Item_func_now_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0); }
+          {
+            $$= new (YYTHD->mem_root) Item_date_add_interval($7,$5,$3,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_timestamp_diff($5,$7,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | UTC_DATE_SYM optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_curdate_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | UTC_TIME_SYM optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_curtime_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | UTC_TIMESTAMP_SYM optional_braces
           {
             $$= new (YYTHD->mem_root) Item_func_now_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         ;
@@ -7446,26 +7899,60 @@ function_call_nonkeyword:
 */
 function_call_conflict:
           ASCII_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_ascii($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_ascii($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | CHARSET '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_charset($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_charset($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | COALESCE '(' expr_list ')'
-          { $$= new (YYTHD->mem_root) Item_func_coalesce(* $3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_coalesce(* $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | COLLATION_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_collation($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_collation($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | DATABASE '(' ')'
           {
             $$= new (YYTHD->mem_root) Item_func_database();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
         | IF '(' expr ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_if($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MICROSECOND_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_microsecond($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_microsecond($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MOD_SYM '(' expr ',' expr ')'
-          { $$ = new (YYTHD->mem_root) Item_func_mod( $3, $5); }
+          {
+            $$ = new (YYTHD->mem_root) Item_func_mod($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | OLD_PASSWORD '(' expr ')'
-          { $$=  new (YYTHD->mem_root) Item_func_old_password($3); }
+          {
+            $$=  new (YYTHD->mem_root) Item_func_old_password($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | PASSWORD '(' expr ')'
           {
             THD *thd= YYTHD;
@@ -7474,51 +7961,95 @@ function_call_conflict:
               i1= new (thd->mem_root) Item_func_old_password($3);
             else
               i1= new (thd->mem_root) Item_func_password($3);
+            if (i1 == NULL)
+              MYSQL_YYABORT;
             $$= i1;
           }
         | QUARTER_SYM '(' expr ')'
-          { $$ = new (YYTHD->mem_root) Item_func_quarter($3); }
+          {
+            $$ = new (YYTHD->mem_root) Item_func_quarter($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | REPEAT_SYM '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_repeat($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_repeat($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | REPLACE '(' expr ',' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_replace($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | REVERSE_SYM '(' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_reverse($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_reverse($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | TRUNCATE_SYM '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_round($3,$5,1); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_round($3,$5,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | WEEK_SYM '(' expr ')'
           {
             THD *thd= YYTHD;
             Item *i1= new (thd->mem_root) Item_int((char*) "0",
                                            thd->variables.default_week_format,
                                                    1);
-
+            if (i1 == NULL)
+              MYSQL_YYABORT;
             $$= new (thd->mem_root) Item_func_week($3, i1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | WEEK_SYM '(' expr ',' expr ')'
-          { $$= new (YYTHD->mem_root) Item_func_week($3,$5); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_week($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
-          { $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, 0, $4); }
+          {
+            $$= new (YYTHD->mem_root) Item_func_weight_string($3, 0, 0, $4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
           {
             $$= new (YYTHD->mem_root)
                 Item_func_weight_string($3, 0, $6,
                                         $7 | MY_STRXFRM_PAD_WITH_SPACE);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
           {
-            $3= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
+            Item *item= create_func_char_cast(YYTHD, $3, $6, &my_charset_bin);
+            if (item == NULL)
+              MYSQL_YYABORT;
             $$= new (YYTHD->mem_root)
-                Item_func_weight_string($3, 0, $6, MY_STRXFRM_PAD_WITH_SPACE);
+                Item_func_weight_string(item, 0, $6, MY_STRXFRM_PAD_WITH_SPACE);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | WEIGHT_STRING_SYM '(' expr ',' ulong_num ',' ulong_num ',' ulong_num ')'
           {
             $$= new (YYTHD->mem_root) Item_func_weight_string($3, $5, $7, $9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | geometry_function
           {
 #ifdef HAVE_SPATIAL
             $$= $1;
+            /* $1 may be NULL, GEOM_NEW not tested for out of memory */
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 #else
             my_error(ER_FEATURE_DISABLED, MYF(0),
                      sym_group_geom.name, sym_group_geom.needed_define);
@@ -7527,6 +8058,7 @@ function_call_conflict:
           }
         ;
 
+/* may return NULL */
 geometry_function:
           CONTAINS_SYM '(' expr ',' expr ')'
           {
@@ -7570,7 +8102,9 @@ geometry_function:
                            Geometry::wkb_polygon));
           }
         | POINT_SYM '(' expr ',' expr ')'
-          { $$= GEOM_NEW(YYTHD, Item_func_point($3,$5)); }
+          {
+            $$= GEOM_NEW(YYTHD, Item_func_point($3,$5));
+          }
         | POLYGON '(' expr_list ')'
           {
             $$= GEOM_NEW(YYTHD,
@@ -7715,6 +8249,8 @@ udf_expr_list:
           udf_expr
           {
             $$= new (YYTHD->mem_root) List<Item>;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->push_back($1);
           }
         | udf_expr_list ',' udf_expr
@@ -7746,50 +8282,125 @@ udf_expr:
 
 sum_expr:
           AVG_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_avg($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_avg($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | AVG_SYM '(' DISTINCT in_sum_expr ')'
-          { $$=new Item_sum_avg_distinct($4); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_avg_distinct($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | BIT_AND  '(' in_sum_expr ')'
-          { $$=new Item_sum_and($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_and($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | BIT_OR  '(' in_sum_expr ')'
-          { $$=new Item_sum_or($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_or($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | BIT_XOR  '(' in_sum_expr ')'
-          { $$=new Item_sum_xor($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_xor($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | COUNT_SYM '(' opt_all '*' ')'
-          { $$=new Item_sum_count(new Item_int((int32) 0L,1)); }
+          {
+            Item *item= new (YYTHD->mem_root) Item_int((int32) 0L,1);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new (YYTHD->mem_root) Item_sum_count(item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | COUNT_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_count($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_count($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | COUNT_SYM '(' DISTINCT
           { Select->in_sum_expr++; }
           expr_list
           { Select->in_sum_expr--; }
           ')'
-          { $$=new Item_sum_count_distinct(* $5); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_count_distinct(* $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MIN_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_min($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_min($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         /*
           According to ANSI SQL, DISTINCT is allowed and has
           no sense inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...)
           is processed like an ordinary MIN | MAX()
         */
         | MIN_SYM '(' DISTINCT in_sum_expr ')'
-          { $$=new Item_sum_min($4); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_min($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MAX_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_max($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_max($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | MAX_SYM '(' DISTINCT in_sum_expr ')'
-          { $$=new Item_sum_max($4); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_max($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | STD_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_std($3, 0); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_std($3, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | VARIANCE_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_variance($3, 0); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_variance($3, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | STDDEV_SAMP_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_std($3, 1); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_std($3, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | VAR_SAMP_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_variance($3, 1); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_variance($3, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUM_SYM '(' in_sum_expr ')'
-          { $$=new Item_sum_sum($3); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_sum($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SUM_SYM '(' DISTINCT in_sum_expr ')'
-          { $$=new Item_sum_sum_distinct($4); }
+          {
+            $$= new (YYTHD->mem_root) Item_sum_sum_distinct($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | GROUP_CONCAT_SYM '(' opt_distinct
           { Select->in_sum_expr++; }
           expr_list opt_gorder_clause
@@ -7798,8 +8409,11 @@ sum_expr:
           {
             SELECT_LEX *sel= Select;
             sel->in_sum_expr--;
-            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
-                                          sel->gorder_list, $7);
+            $$= new (YYTHD->mem_root)
+                  Item_func_group_concat(Lex->current_context(), $3, $5,
+                                         sel->gorder_list, $7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $5->empty();
           }
         ;
@@ -7822,13 +8436,17 @@ variable:
 variable_aux:
           ident_or_text SET_VAR expr
           {
-            $$= new Item_func_set_user_var($1, $3);
+            $$= new (YYTHD->mem_root) Item_func_set_user_var($1, $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             LEX *lex= Lex;
             lex->uncacheable(UNCACHEABLE_RAND);
           }
         | ident_or_text
           {
-            $$= new Item_func_get_user_var($1);
+            $$= new (YYTHD->mem_root) Item_func_get_user_var($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             LEX *lex= Lex;
             lex->uncacheable(UNCACHEABLE_RAND);
           }
@@ -7854,9 +8472,11 @@ opt_distinct:
 
 opt_gconcat_separator:
           /* empty */
-            {
-              $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
-            }
+          {
+            $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | SEPARATOR_SYM text_string { $$ = $2; }
         ;
 
@@ -7871,6 +8491,8 @@ opt_gorder_clause:
             select->gorder_list=
               (SQL_LIST*) sql_memdup((char*) &select->order_list,
                                      sizeof(st_sql_list));
+            if (select->gorder_list == NULL)
+              MYSQL_YYABORT;
             select->order_list.empty();
           }
         ;
@@ -7926,6 +8548,8 @@ expr_list:
           expr
           {
             $$= new (YYTHD->mem_root) List<Item>;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->push_back($1);
           }
         | expr_list ',' expr
@@ -7944,6 +8568,8 @@ ident_list:
           simple_ident
           {
             $$= new (YYTHD->mem_root) List<Item>;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->push_back($1);
           }
         | ident_list ',' simple_ident
@@ -7967,6 +8593,8 @@ when_list:
           WHEN_SYM expr THEN_SYM expr
           {
             $$= new List<Item>;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->push_back($2);
             $$->push_back($4);
           }
@@ -8469,15 +9097,21 @@ using_list:
           {
             if (!($$= new List<String>))
               MYSQL_YYABORT;
-            $$->push_back(new (YYTHD->mem_root)
-                              String((const char *) $1.str, $1.length,
-                                      system_charset_info));
+            String *s= new (YYTHD->mem_root) String((const char *) $1.str,
+                                                    $1.length,
+                                                    system_charset_info);
+            if (s == NULL)
+              MYSQL_YYABORT;
+            $$->push_back(s);
           }
         | using_list ',' ident
           {
-            $1->push_back(new (YYTHD->mem_root)
-                              String((const char *) $3.str, $3.length,
-                                      system_charset_info));
+            String *s= new (YYTHD->mem_root) String((const char *) $3.str,
+                                                    $3.length,
+                                                    system_charset_info);
+            if (s == NULL)
+              MYSQL_YYABORT;
+            $1->push_back(s);
             $$= $1;
           }
         ;
@@ -8545,7 +9179,11 @@ table_alias:
 opt_table_alias:
           /* empty */ { $$=0; }
         | table_alias ident
-          { $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)); }
+          {
+            $$= (LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 opt_all:
@@ -8593,10 +9231,13 @@ opt_escape:
           }
         | /* empty */
           {
+            THD *thd= YYTHD;
             Lex->escape_used= FALSE;
-            $$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
-                 new Item_string("", 0, &my_charset_latin1) :
-                 new Item_string("\\", 1, &my_charset_latin1));
+            $$= ((thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
+                 new (thd->mem_root) Item_string("", 0, &my_charset_latin1) :
+                 new (thd->mem_root) Item_string("\\", 1, &my_charset_latin1));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         ;
 
@@ -8783,13 +9424,28 @@ limit_options:
         ;
 
 limit_option:
-        param_marker
-        {
-          ((Item_param *) $1)->limit_clause_param= TRUE;
-        }
-        | ULONGLONG_NUM { $$= new Item_uint($1.str, $1.length); }
-        | LONG_NUM      { $$= new Item_uint($1.str, $1.length); }
-        | NUM           { $$= new Item_uint($1.str, $1.length); }
+          param_marker
+          {
+            ((Item_param *) $1)->limit_clause_param= TRUE;
+          }
+        | ULONGLONG_NUM
+          {
+            $$= new (YYTHD->mem_root) Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | LONG_NUM
+          {
+            $$= new (YYTHD->mem_root) Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | NUM
+          {
+            $$= new (YYTHD->mem_root) Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 delete_limit_clause:
@@ -8873,10 +9529,12 @@ procedure_clause:
             lex->proc_list.elements=0;
             lex->proc_list.first=0;
             lex->proc_list.next= (uchar**) &lex->proc_list.first;
-            if (add_proc_to_list(lex->thd, new Item_field(&lex->
-                                                          current_select->
-                                                          context,
-                                                          NULL,NULL,$2.str)))
+            Item_field *item= new (YYTHD->mem_root)
+                                Item_field(&lex->current_select->context,
+                                           NULL, NULL, $2.str);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            if (add_proc_to_list(lex->thd, item))
               MYSQL_YYABORT;
             Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
           }
@@ -8925,13 +9583,20 @@ select_var_ident:  
           {
             LEX *lex=Lex;
             if (lex->result) 
-              ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0));
+            {
+              my_var *var= new my_var($2,0,0,(enum_field_types)0);
+              if (var == NULL)
+                MYSQL_YYABORT;
+              ((select_dumpvar *)lex->result)->var_list.push_back(var);
+            }
             else
+            {
               /*
                 The parser won't create select_result instance only
                 if it's an EXPLAIN.
               */
               DBUG_ASSERT(lex->describe);
+            }
           }
         | ident_or_text
           {
@@ -8945,12 +9610,12 @@ select_var_ident:  
             }
             if (lex->result)
             {
-              my_var *var;
-              ((select_dumpvar *)lex->result)->
-                var_list.push_back(var= new my_var($1,1,t->offset,t->type));
+              my_var *var= new my_var($1,1,t->offset,t->type);
+              if (var == NULL)
+                MYSQL_YYABORT;
+              ((select_dumpvar *)lex->result)->var_list.push_back(var);
 #ifndef DBUG_OFF
-              if (var)
-                var->sp= lex->sphead;
+              var->sp= lex->sphead;
 #endif
             }
             else
@@ -9036,12 +9701,14 @@ drop:
         | DROP build_method INDEX_SYM ident ON table_ident {}
           {
             LEX *lex=Lex;
+            Alter_drop *ad= new Alter_drop(Alter_drop::KEY, $4.str);
+            if (ad == NULL)
+              MYSQL_YYABORT;
             lex->sql_command= SQLCOM_DROP_INDEX;
             lex->alter_info.reset();
             lex->alter_info.flags= ALTER_DROP_INDEX;
             lex->alter_info.build_method= $2;
-            lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
-                                                               $4.str));
+            lex->alter_info.drop_list.push_back(ad);
             if (!lex->current_select->add_table_to_list(lex->thd, $6, NULL,
                                                         TL_OPTION_UPDATING))
               MYSQL_YYABORT;
@@ -9066,6 +9733,8 @@ drop:
             lex->sql_command = SQLCOM_DROP_FUNCTION;
             lex->drop_if_exists= $3;
             spname= new sp_name($4, $6, true);
+            if (spname == NULL)
+              MYSQL_YYABORT;
             spname->init_qname(thd);
             lex->spname= spname;
           }
@@ -9085,6 +9754,8 @@ drop:
             lex->sql_command = SQLCOM_DROP_FUNCTION;
             lex->drop_if_exists= $3;
             spname= new sp_name(db, $4, false);
+            if (spname == NULL)
+              MYSQL_YYABORT;
             spname->init_qname(thd);
             lex->spname= spname;
           }
@@ -9352,7 +10023,12 @@ values:
 
 expr_or_default:
           expr { $$= $1;}
-        | DEFAULT {$$= new Item_default_value(Lex->current_context()); }
+        | DEFAULT
+          {
+            $$= new (YYTHD->mem_root) Item_default_value(Lex->current_context());
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 opt_insert_update:
@@ -9476,7 +10152,11 @@ table_wild_list:
 table_wild_one:
           ident opt_wild
           {
-            if (!Select->add_table_to_list(YYTHD, new Table_ident($1),
+            Table_ident *ti= new Table_ident($1);
+            if (ti == NULL)
+              MYSQL_YYABORT;
+            if (!Select->add_table_to_list(YYTHD,
+                                           ti,
                                            NULL,
                                            TL_OPTION_UPDATING | TL_OPTION_ALIAS,
                                            Lex->lock_option))
@@ -9484,8 +10164,11 @@ table_wild_one:
           }
         | ident '.' ident opt_wild
           {
+            Table_ident *ti= new Table_ident(YYTHD, $1, $3, 0);
+            if (ti == NULL)
+              MYSQL_YYABORT;
             if (!Select->add_table_to_list(YYTHD,
-                                           new Table_ident(YYTHD, $1, $3, 0),
+                                           ti,
                                            NULL,
                                            TL_OPTION_UPDATING | TL_OPTION_ALIAS,
                                            Lex->lock_option))
@@ -9857,23 +10540,13 @@ show_param:
           }
         | PROCEDURE CODE_SYM sp_name
           {
-#ifdef DBUG_OFF
-            my_parse_error(ER(ER_SYNTAX_ERROR));
-            MYSQL_YYABORT;
-#else
             Lex->sql_command= SQLCOM_SHOW_PROC_CODE;
             Lex->spname= $3;
-#endif
           }
         | FUNCTION_SYM CODE_SYM sp_name
           {
-#ifdef DBUG_OFF
-            my_parse_error(ER(ER_SYNTAX_ERROR));
-            MYSQL_YYABORT;
-#else
             Lex->sql_command= SQLCOM_SHOW_FUNC_CODE;
             Lex->spname= $3;
-#endif
           }
         | CREATE EVENT_SYM sp_name
           {
@@ -9932,6 +10605,8 @@ wild_and_where:
           {
             Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
                                                     system_charset_info);
+            if (Lex->wild == NULL)
+              MYSQL_YYABORT;
           }
         | WHERE expr
           {
@@ -9984,6 +10659,8 @@ opt_describe_column:
             Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
                                                     $1.length,
                                                     system_charset_info);
+            if (Lex->wild == NULL)
+              MYSQL_YYABORT;
           }
         ;
 
@@ -10293,7 +10970,11 @@ fields_or_vars:
 field_or_var:
           simple_ident_nospvar {$$= $1;}
         | '@' ident_or_text
-          { $$= new Item_user_var_as_out_param($2); }
+          {
+            $$= new (YYTHD->mem_root) Item_user_var_as_out_param($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 opt_load_data_set_spec:
@@ -10319,20 +11000,30 @@ text_literal:
               tmp= $1;
             else
               thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
-            $$= new Item_string(tmp.str, tmp.length, cs_con,
-                                DERIVATION_COERCIBLE, repertoire);
+            $$= new (thd->mem_root) Item_string(tmp.str, tmp.length, cs_con,
+                                                DERIVATION_COERCIBLE,
+                                                repertoire);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | NCHAR_STRING
           {
             uint repertoire= Lex->text_string_is_7bit ?
                              MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
             DBUG_ASSERT(my_charset_is_ascii_based(national_charset_info));
-            $$= new Item_string($1.str, $1.length, national_charset_info,
-                                DERIVATION_COERCIBLE, repertoire);
+            $$= new (YYTHD->mem_root) Item_string($1.str, $1.length,
+                                                  national_charset_info,
+                                                  DERIVATION_COERCIBLE,
+                                                  repertoire);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | UNDERSCORE_CHARSET TEXT_STRING
           {
-            Item_string *str= new Item_string($2.str, $2.length, $1);
+            Item_string *str= new (YYTHD->mem_root) Item_string($2.str,
+                                                                $2.length, $1);
+            if (str == NULL)
+              MYSQL_YYABORT;
             str->set_repertoire_from_value();
             str->set_cs_specified(TRUE);
 
@@ -10362,27 +11053,30 @@ text_string:
             $$= new (YYTHD->mem_root) String($1.str,
                                              $1.length,
                                              YYTHD->variables.collation_connection);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | HEX_NUM
           {
-            Item *tmp= new Item_hex_string($1.str, $1.length);
+            Item *tmp= new (YYTHD->mem_root) Item_hex_string($1.str, $1.length);
+            if (tmp == NULL)
+              MYSQL_YYABORT;
             /*
               it is OK only emulate fix_fields, because we need only
               value of constant
             */
-            $$= tmp ?
-              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
-              (String*) 0;
+            tmp->quick_fix_field();
+            $$= tmp->val_str((String*) 0);
           }
         | BIN_NUM
           {
-            Item *tmp= new Item_bin_string($1.str, $1.length);
+            Item *tmp= new (YYTHD->mem_root) Item_bin_string($1.str, $1.length);
             /*
               it is OK only emulate fix_fields, because we need only
               value of constant
             */
-            $$= tmp ? tmp->quick_fix_field(), tmp->val_str((String*) 0) :
-              (String*) 0;
+            tmp->quick_fix_field();
+            $$= tmp->val_str((String*) 0);
           }
         ;
 
@@ -10398,7 +11092,7 @@ param_marker:
               my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
               MYSQL_YYABORT;
             }
-            item= new Item_param((uint) (lip->get_tok_start() - thd->query));
+            item= new (thd->mem_root) Item_param((uint) (lip->get_tok_start() - thd->query));
             if (!($$= item) || lex->param_list.push_back(item))
             {
               my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
@@ -10422,29 +11116,53 @@ literal:
         | NUM_literal { $$ = $1; }
         | NULL_SYM
           {
-            $$ = new Item_null();
+            $$ = new (YYTHD->mem_root) Item_null();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             YYLIP->next_state= MY_LEX_OPERATOR_OR_IDENT;
           }
-        | FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
-        | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
-        | HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
-        | BIN_NUM { $$= new Item_bin_string($1.str, $1.length); }
+        | FALSE_SYM
+          {
+            $$= new (YYTHD->mem_root) Item_int((char*) "FALSE",0,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | TRUE_SYM
+          {
+            $$= new (YYTHD->mem_root) Item_int((char*) "TRUE",1,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | HEX_NUM
+          {
+            $$ = new (YYTHD->mem_root) Item_hex_string($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | BIN_NUM
+          {
+            $$= new (YYTHD->mem_root) Item_bin_string($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | UNDERSCORE_CHARSET HEX_NUM
           {
-            Item *tmp= new Item_hex_string($2.str, $2.length);
+            Item *tmp= new (YYTHD->mem_root) Item_hex_string($2.str, $2.length);
+            if (tmp == NULL)
+              MYSQL_YYABORT;
             /*
               it is OK only emulate fix_fieds, because we need only
               value of constant
             */
-            String *str= tmp ?
-              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
-              (String*) 0;
-
-            Item_string *item_str=
-              new Item_string(NULL, /* name will be set in select_item */
-                              str ? str->ptr() : "",
-                              str ? str->length() : 0,
-                              $1);
+            tmp->quick_fix_field();
+            String *str= tmp->val_str((String*) 0);
+
+            Item_string *item_str;
+            item_str= new (YYTHD->mem_root)
+                        Item_string(NULL, /* name will be set in select_item */
+                                    str ? str->ptr() : "",
+                                    str ? str->length() : 0,
+                                    $1);
             if (!item_str ||
                 !item_str->check_well_formed_result(&item_str->str_value, TRUE))
             {
@@ -10458,20 +11176,22 @@ literal:
           }
         | UNDERSCORE_CHARSET BIN_NUM
           {
-            Item *tmp= new Item_bin_string($2.str, $2.length);
+            Item *tmp= new (YYTHD->mem_root) Item_bin_string($2.str, $2.length);
+            if (tmp == NULL)
+              MYSQL_YYABORT;
             /*
               it is OK only emulate fix_fieds, because we need only
               value of constant
             */
-            String *str= tmp ?
-              tmp->quick_fix_field(), tmp->val_str((String*) 0) :
-              (String*) 0;
-
-            Item_string *item_str=
-              new Item_string(NULL, /* name will be set in select_item */
-                              str ? str->ptr() : "",
-                              str ? str->length() : 0,
-                              $1);
+            tmp->quick_fix_field();
+            String *str= tmp->val_str((String*) 0);
+
+            Item_string *item_str;
+            item_str= new (YYTHD->mem_root)
+                        Item_string(NULL, /* name will be set in select_item */
+                                    str ? str->ptr() : "",
+                                    str ? str->length() : 0,
+                                    $1);
             if (!item_str ||
                 !item_str->check_well_formed_result(&item_str->str_value, TRUE))
             {
@@ -10491,27 +11211,42 @@ NUM_literal:
           NUM
           {
             int error;
-            $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
+            $$= new (YYTHD->mem_root)
+                  Item_int($1.str,
+                           (longlong) my_strtoll10($1.str, NULL, &error),
+                           $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | LONG_NUM
           {
             int error;
-            $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length);
+            $$= new (YYTHD->mem_root)
+                  Item_int($1.str,
+                           (longlong) my_strtoll10($1.str, NULL, &error),
+                           $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | ULONGLONG_NUM
-          { $$ = new Item_uint($1.str, $1.length); }
+          {
+            $$= new (YYTHD->mem_root) Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | DECIMAL_NUM
           {
-            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
-            if (YYTHD->is_error())
+            $$= new (YYTHD->mem_root) Item_decimal($1.str, $1.length,
+                                                   YYTHD->charset());
+            if (($$ == NULL) || (YYTHD->is_error()))
             {
               MYSQL_YYABORT;
             }
           }
         | FLOAT_NUM
           {
-            $$ = new Item_float($1.str, $1.length);
-            if (YYTHD->is_error())
+            $$ = new (YYTHD->mem_root) Item_float($1.str, $1.length);
+            if (($$ == NULL) || (YYTHD->is_error()))
             {
               MYSQL_YYABORT;
             }
@@ -10531,15 +11266,23 @@ table_wild:
           ident '.' '*'
           {
             SELECT_LEX *sel= Select;
-            $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
+            $$ = new (YYTHD->mem_root) Item_field(Lex->current_context(),
+                                                  NullS, $1.str, "*");
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             sel->with_wild++;
           }
         | ident '.' ident '.' '*'
           {
+            THD *thd= YYTHD;
             SELECT_LEX *sel= Select;
-            $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
-                                CLIENT_NO_SCHEMA ? NullS : $1.str),
-                                $3.str,"*");
+            const char* schema= thd->client_capabilities & CLIENT_NO_SCHEMA ?
+                                  NullS : $1.str;
+            $$ = new (thd->mem_root) Item_field(Lex->current_context(),
+                                                schema,
+                                                $3.str,"*");
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             sel->with_wild++;
           }
         ;
@@ -10566,24 +11309,35 @@ simple_ident:
               }
 
               Item_splocal *splocal;
-              splocal= new Item_splocal($1, spv->offset, spv->type,
-                                        lip->get_tok_start_prev() -
-                                        lex->sphead->m_tmp_query,
-                                        lip->get_tok_end() - lip->get_tok_start_prev());
+              splocal= new (thd->mem_root)
+                         Item_splocal($1,
+                                      spv->offset, spv->type,
+                                      lip->get_tok_start_prev() - lex->sphead->m_tmp_query,
+                                      lip->get_tok_end() - lip->get_tok_start_prev());
+              if (splocal == NULL)
+                MYSQL_YYABORT;
 #ifndef DBUG_OFF
-              if (splocal)
-                splocal->m_sp= lex->sphead;
+              splocal->m_sp= lex->sphead;
 #endif
-              $$ = (Item*) splocal;
+              $$= splocal;
               lex->safe_to_cache_query=0;
             }
             else
             {
-              SELECT_LEX *sel=Select;
-              $$= (sel->parsing_place != IN_HAVING ||
-                  sel->get_in_sum_expr() > 0) ?
-                  (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
-                  (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
+              SELECT_LEX *sel= Select;
+              if ((sel->parsing_place != IN_HAVING) ||
+                  (sel->get_in_sum_expr() > 0))
+              {
+                $$= new (thd->mem_root) Item_field(Lex->current_context(),
+                                                   NullS, NullS, $1.str);
+              }
+              else
+              {
+                $$= new (thd->mem_root) Item_ref(Lex->current_context(),
+                                                 NullS, NullS, $1.str);
+              }
+              if ($$ == NULL)
+                MYSQL_YYABORT;
             }
           }
         | simple_ident_q { $$= $1; }
@@ -10592,11 +11346,21 @@ simple_ident:
 simple_ident_nospvar:
           ident
           {
-            SELECT_LEX *sel=Select;
-            $$= (sel->parsing_place != IN_HAVING ||
-                sel->get_in_sum_expr() > 0) ?
-                (Item*) new Item_field(Lex->current_context(), NullS, NullS, $1.str) :
-                (Item*) new Item_ref(Lex->current_context(), NullS, NullS, $1.str);
+            THD *thd= YYTHD;
+            SELECT_LEX *sel= Select;
+            if ((sel->parsing_place != IN_HAVING) ||
+                (sel->get_in_sum_expr() > 0))
+            {
+              $$= new (thd->mem_root) Item_field(Lex->current_context(),
+                                                 NullS, NullS, $1.str);
+            }
+            else
+            {
+              $$= new (thd->mem_root) Item_ref(Lex->current_context(),
+                                               NullS, NullS, $1.str);
+            }
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | simple_ident_q { $$= $1; }
         ;
@@ -10638,13 +11402,16 @@ simple_ident_q:
                            lex->trg_chistics.event == TRG_EVENT_UPDATE));
               const bool read_only=
                 !(new_row && lex->trg_chistics.action_time == TRG_ACTION_BEFORE);
-              if (!(trg_fld= new Item_trigger_field(Lex->current_context(),
-                                                    new_row ?
-                                                    Item_trigger_field::NEW_ROW:
-                                                    Item_trigger_field::OLD_ROW,
-                                                    $3.str,
-                                                    SELECT_ACL,
-                                                    read_only)))
+
+              trg_fld= new (thd->mem_root)
+                         Item_trigger_field(Lex->current_context(),
+                                            new_row ?
+                                              Item_trigger_field::NEW_ROW:
+                                              Item_trigger_field::OLD_ROW,
+                                            $3.str,
+                                            SELECT_ACL,
+                                            read_only);
+              if (trg_fld == NULL)
                 MYSQL_YYABORT;
 
               /*
@@ -10654,7 +11421,7 @@ simple_ident_q:
               lex->trg_table_fields.link_in_list((uchar*) trg_fld,
                                                  (uchar**) &trg_fld->next_trg_field);
 
-              $$= (Item *)trg_fld;
+              $$= trg_fld;
             }
             else
             {
@@ -10664,10 +11431,19 @@ simple_ident_q:
                 my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
                          MYF(0), $1.str, thd->where);
               }
-              $$= (sel->parsing_place != IN_HAVING ||
-                  sel->get_in_sum_expr() > 0) ?
-                  (Item*) new Item_field(Lex->current_context(), NullS, $1.str, $3.str) :
-                  (Item*) new Item_ref(Lex->current_context(), NullS, $1.str, $3.str);
+              if ((sel->parsing_place != IN_HAVING) ||
+                  (sel->get_in_sum_expr() > 0))
+              {
+                $$= new (thd->mem_root) Item_field(Lex->current_context(),
+                                                   NullS, $1.str, $3.str);
+              }
+              else
+              {
+                $$= new (thd->mem_root) Item_ref(Lex->current_context(),
+                                                 NullS, $1.str, $3.str);
+              }
+              if ($$ == NULL)
+                MYSQL_YYABORT;
             }
           }
         | '.' ident '.' ident
@@ -10680,31 +11456,45 @@ simple_ident_q:
               my_error(ER_TABLENAME_NOT_ALLOWED_HERE,
                        MYF(0), $2.str, thd->where);
             }
-            $$= (sel->parsing_place != IN_HAVING ||
-                sel->get_in_sum_expr() > 0) ?
-                (Item*) new Item_field(Lex->current_context(), NullS, $2.str, $4.str) :
-                (Item*) new Item_ref(Lex->current_context(), NullS, $2.str, $4.str);
+            if ((sel->parsing_place != IN_HAVING) ||
+                (sel->get_in_sum_expr() > 0))
+            {
+              $$= new (thd->mem_root) Item_field(Lex->current_context(),
+                                                 NullS, $2.str, $4.str);
+            }
+            else
+            {
+              $$= new (thd->mem_root) Item_ref(Lex->current_context(),
+                                               NullS, $2.str, $4.str);
+            }
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | ident '.' ident '.' ident
           {
             THD *thd= YYTHD;
             LEX *lex= thd->lex;
             SELECT_LEX *sel= lex->current_select;
+