=== modified file 'BUILD/check-cpu'
--- a/BUILD/check-cpu	2007-05-29 10:25:51 +0000
+++ b/BUILD/check-cpu	2008-08-18 17:28:46 +0000
@@ -169,7 +169,7 @@
   fi
 
   cc_ver=`$cc --version | sed 1q`
-  cc_verno=`echo $cc_ver | sed -e 's/^.*gcc/gcc/g; s/[^0-9. ]//g;	 s/^ *//g; s/ .*//g'`
+  cc_verno=`echo $cc_ver | sed -e 's/^.*(GCC)//g; s/[^0-9. ]//g;	 s/^ *//g; s/ .*//g'`
   set -- `echo $cc_verno | tr '.' ' '`
   cc_major=$1
   cc_minor=$2

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2008-06-24 16:05:56 +0000
+++ b/client/mysql.cc	2008-07-18 10:24:59 +0000
@@ -2081,6 +2081,37 @@
 	continue;
       }
     }
+    else if (!*ml_comment && !*in_string &&
+             (end_of_line - pos) >= 10 &&
+             !my_strnncoll(charset_info, (uchar*) pos, 10,
+                           (const uchar*) "delimiter ", 10))
+    {
+      // Flush previously accepted characters
+      if (out != line)
+      {
+        buffer.append(line, (uint32) (out - line));
+        out= line;
+      }
+
+      // Flush possible comments in the buffer
+      if (!buffer.is_empty())
+      {
+        if (com_go(&buffer, 0) > 0) // < 0 is not fatal
+          DBUG_RETURN(1);
+        buffer.length(0);
+      }
+
+      /*
+        Delimiter wants the get rest of the given line as argument to
+        allow one to change ';' to ';;' and back
+      */
+      buffer.append(pos);
+      if (com_delimiter(&buffer, pos) > 0)
+        DBUG_RETURN(1);
+
+      buffer.length(0);
+      break;
+    }
     else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
     {
       // Found a statement. Continue parsing after the delimiter

=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2008-05-02 12:41:19 +0000
+++ b/client/mysql_upgrade.c	2008-08-11 17:56:54 +0000
@@ -259,6 +259,10 @@
 }
 
 
+/**
+  Run a command using the shell, storing its output in the supplied dynamic
+  string.
+*/
 static int run_command(char* cmd,
                        DYNAMIC_STRING *ds_res)
 {
@@ -331,36 +335,16 @@
 }
 
 
-/*
-  Try to get the full path to this exceutable
-
-  Return 0 if path found
-
-*/
-
-static my_bool get_full_path_to_executable(char* path)
-{
-  my_bool ret;
-  DBUG_ENTER("get_full_path_to_executable");
-#ifdef __WIN__
-  ret= (GetModuleFileName(NULL, path, FN_REFLEN) == 0);
-#else
-  /* my_readlink returns 0 if a symlink was read */
-  ret= (my_readlink(path, "/proc/self/exe", MYF(0)) != 0);
-  /* Might also want to try with /proc/$$/exe if the above fails */
-#endif
-  DBUG_PRINT("exit", ("path: %s", path));
-  DBUG_RETURN(ret);
-}
-
-
-/*
-  Look for the tool in the same directory as mysql_upgrade.
-*/
-
-static void find_tool(char *tool_path, const char *tool_name)
-{
-  char path[FN_REFLEN];
+/**
+  Look for the filename of given tool, with the presumption that it is in the
+  same directory as mysql_upgrade and that the same executable-searching 
+  mechanism will be used when we run our sub-shells with popen() later.
+*/
+static void find_tool(char *tool_executable_name, const char *tool_name, 
+                      const char *self_name)
+{
+  char *last_fn_libchar;
+
   DYNAMIC_STRING ds_tmp;
   DBUG_ENTER("find_tool");
   DBUG_PRINT("enter", ("progname: %s", my_progname));
@@ -368,77 +352,59 @@
   if (init_dynamic_string(&ds_tmp, "", 32, 32))
     die("Out of memory");
 
-  /* Initialize path with the full path to this program */
-  if (get_full_path_to_executable(path))
-  {
-    /*
-      Easy way to get full executable path failed, try
-      other methods
-    */
-    if (my_progname[0] == FN_LIBCHAR)
-    {
-      /* 1. my_progname contains full path */
-      strmake(path, my_progname, FN_REFLEN);
-    }
-    else if (my_progname[0] == '.')
-    {
-      /* 2. my_progname contains relative path, prepend wd */
-      char buf[FN_REFLEN];
-      my_getwd(buf, FN_REFLEN, MYF(0));
-      my_snprintf(path, FN_REFLEN, "%s%s", buf, my_progname);
-    }
-    else
-    {
-      /* 3. Just go for it and hope tool is in path */
-      path[0]= 0;
-    }
-  }
-
-  DBUG_PRINT("info", ("path: '%s'", path));
-
-  /* Chop off binary name (i.e mysql-upgrade) from path */
-  dirname_part(path, path);
-
-  /*
-    When running in a not yet installed build and using libtool,
-    the program(mysql_upgrade) will be in .libs/ and executed
-    through a libtool wrapper in order to use the dynamic libraries
-    from this build. The same must be done for the tools(mysql and
-    mysqlcheck). Thus if path ends in .libs/, step up one directory
-    and execute the tools from there
-  */
-  path[max((strlen(path)-1), 0)]= 0;   /* Chop off last / */
-  if (strncmp(path + dirname_length(path), ".libs", 5) == 0)
-  {
-    DBUG_PRINT("info", ("Chopping off .libs from '%s'", path));
-
-    /* Chop off .libs */
-    dirname_part(path, path);
-  }
-
-
-  DBUG_PRINT("info", ("path: '%s'", path));
-
-  /* Format name of the tool to search for */
-  fn_format(tool_path, tool_name,
-            path, "", MYF(MY_REPLACE_DIR));
-
-  verbose("Looking for '%s' in: %s", tool_name, tool_path);
-
-  /* Make sure the tool exists */
-  if (my_access(tool_path, F_OK) != 0)
-    die("Can't find '%s'", tool_path);
+  last_fn_libchar= strrchr(self_name, FN_LIBCHAR);
+
+  if (last_fn_libchar == NULL)
+  {
+    /*
+      mysql_upgrade was found by the shell searching the path.  A sibling
+      next to us should be found the same way.
+    */
+    strncpy(tool_executable_name, tool_name, FN_REFLEN);
+  }
+  else
+  {
+    int len;
+
+    /*
+      mysql_upgrade was run absolutely or relatively.  We can find a sibling
+      by replacing our name after the LIBCHAR with the new tool name.
+    */
+
+    /*
+      When running in a not yet installed build and using libtool,
+      the program(mysql_upgrade) will be in .libs/ and executed
+      through a libtool wrapper in order to use the dynamic libraries
+      from this build. The same must be done for the tools(mysql and
+      mysqlcheck). Thus if path ends in .libs/, step up one directory
+      and execute the tools from there
+    */
+    if (((last_fn_libchar - 6) >= self_name) &&
+        (strncmp(last_fn_libchar - 5, ".libs", 5) == 0) &&
+        (*(last_fn_libchar - 6) == FN_LIBCHAR))
+    {
+      DBUG_PRINT("info", ("Chopping off \".libs\" from end of path"));
+      last_fn_libchar -= 6;
+    }
+
+    len= last_fn_libchar - self_name;
+
+    my_snprintf(tool_executable_name, FN_REFLEN, "%.*s%c%s",
+                len, self_name, FN_LIBCHAR, tool_name);
+  }
+
+  verbose("Looking for '%s' as: %s", tool_name, tool_executable_name);
 
   /*
     Make sure it can be executed
   */
-  if (run_tool(tool_path,
+  if (run_tool(tool_executable_name,
                &ds_tmp, /* Get output from command, discard*/
                "--help",
                "2>&1",
                IF_WIN("> NUL", "> /dev/null"),
                NULL))
-    die("Can't execute '%s'", tool_path);
+    die("Can't execute '%s'", tool_executable_name);
 
   dynstr_free(&ds_tmp);
 
@@ -748,11 +714,20 @@
 
 int main(int argc, char **argv)
 {
+  char self_name[FN_REFLEN];
+
   MY_INIT(argv[0]);
 #ifdef __NETWARE__
   setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
 #endif
 
+#if __WIN__
+  if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
+#endif
+  {
+    strncpy(self_name, argv[0], FN_REFLEN);
+  }
+
   if (init_dynamic_string(&ds_args, "", 512, 256))
     die("Out of memory");
 
@@ -774,10 +749,10 @@
   dynstr_append(&ds_args, " ");
 
   /* Find mysql */
-  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"));
+  find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"), self_name);
 
   /* Find mysqlcheck */
-  find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"));
+  find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"), self_name);
 
   /*
     Read the mysql_upgrade_info file to check if mysql_upgrade

=== modified file 'configure.in'
--- a/configure.in	2008-06-10 12:25:21 +0000
+++ b/configure.in	2008-08-13 10:34:35 +0000
@@ -7,7 +7,7 @@
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.66)
+AM_INIT_AUTOMAKE(mysql, 5.0.70)
 AM_CONFIG_HEADER([include/config.h:config.h.in])
 
 PROTOCOL_VERSION=10
@@ -23,7 +23,7 @@
 # ndb version
 NDB_VERSION_MAJOR=5
 NDB_VERSION_MINOR=0
-NDB_VERSION_BUILD=66
+NDB_VERSION_BUILD=70
 NDB_VERSION_STATUS=""
 
 # Set all version vars based on $VERSION. How do we do this more elegant ?
@@ -2812,9 +2812,15 @@
 
 case $SYSTEM_TYPE-$MACHINE_TYPE-$ac_cv_prog_gcc-$have_ndbcluster in
   *solaris*-i?86-no-yes)
-  # ndb fail for whatever strange reason to link Sun Forte/x86
-  # unless using incremental linker
-  CXXFLAGS="$CXXFLAGS -xildon"
+  if $CC -xildon 2>&1 | grep "illegal option" >/dev/null
+  then
+    # This Solaris ld does not support -xildon
+    true
+  else
+    # ndb fail for whatever strange reason to link Sun Forte/x86
+    # unless using incremental linker
+    CXXFLAGS="$CXXFLAGS -xildon"
+  fi
   ;;
   *) ;;
 esac

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2008-01-31 15:15:46 +0000
+++ b/include/my_sys.h	2008-08-22 12:31:53 +0000
@@ -574,6 +574,7 @@
 extern File my_dup(File file, myf MyFlags);
 extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
 extern int my_readlink(char *to, const char *filename, myf MyFlags);
+extern int my_is_symlink(const char *filename);
 extern int my_realpath(char *to, const char *filename, myf MyFlags);
 extern File my_create_with_symlink(const char *linkname, const char *filename,
 				   int createflags, int access_flags,
@@ -681,6 +682,7 @@
 			   const char *form, uint flag);
 extern size_s strlength(const char *str);
 extern void pack_dirname(my_string to,const char *from);
+extern uint normalize_dirname(char * to, const char *from);
 extern uint unpack_dirname(my_string to,const char *from);
 extern uint cleanup_dirname(my_string to,const char *from);
 extern uint system_filename(my_string to,const char *from);

=== modified file 'include/myisam.h'
--- a/include/myisam.h	2006-12-23 19:17:15 +0000
+++ b/include/myisam.h	2008-08-22 12:31:53 +0000
@@ -267,6 +267,10 @@
 extern my_off_t myisam_max_temp_length;
 extern ulong myisam_bulk_insert_tree_size, myisam_data_pointer_size;
 
+/* usually used to check if a symlink points into the mysql data home */
+/* which is normally forbidden                                        */
+extern int (*myisam_test_invalid_symlink)(const char *filename);
+
 	/* Prototypes for myisam-functions */
 
 extern int mi_close(struct st_myisam_info *file);

=== modified file 'innobase/buf/buf0buf.c'
--- a/innobase/buf/buf0buf.c	2007-12-11 00:00:25 +0000
+++ b/innobase/buf/buf0buf.c	2008-07-31 21:47:57 +0000
@@ -2260,6 +2260,7 @@
 	ut_a(buf_validate());
 }	
 
+#ifdef UNIV_DEBUG
 /*************************************************************************
 Returns the number of latched pages in the buffer pool. */
 
@@ -2290,6 +2291,7 @@
         mutex_exit(&(buf_pool->mutex));
         return fixed_pages_number;
 }
+#endif /* UNIV_DEBUG */
 
 /*************************************************************************
 Returns the number of pending buf pool ios. */

=== modified file 'innobase/dict/dict0dict.c'
--- a/innobase/dict/dict0dict.c	2007-03-29 04:41:21 +0000
+++ b/innobase/dict/dict0dict.c	2008-08-08 00:25:24 +0000
@@ -3554,7 +3554,7 @@
 
 	ptr = dict_accept(ptr, "FOREIGN", &success);
 	
-	if (!success) {
+	if (!success || !ib_isspace(*ptr)) {
 
 	        goto loop;
 	}

=== modified file 'innobase/include/buf0buf.h'
--- a/innobase/include/buf0buf.h	2007-12-11 00:00:25 +0000
+++ b/innobase/include/buf0buf.h	2008-07-31 21:47:57 +0000
@@ -495,7 +495,15 @@
 void
 buf_print(void);
 /*============*/
+
+/*************************************************************************
+Returns the number of latched pages in the buffer pool. */
+
+ulint
+buf_get_latched_pages_number(void);
+/*==============================*/
 #endif /* UNIV_DEBUG */
+
 /************************************************************************
 Prints a page to stderr. */
 
@@ -503,12 +511,7 @@
 buf_page_print(
 /*===========*/
 	byte*	read_buf);	/* in: a database page */
-/*************************************************************************
-Returns the number of latched pages in the buffer pool. */
 
-ulint
-buf_get_latched_pages_number(void);
-/*==============================*/
 /*************************************************************************
 Returns the number of pending buf pool ios. */
 

=== modified file 'innobase/include/srv0srv.h'
--- a/innobase/include/srv0srv.h	2006-01-18 12:20:56 +0000
+++ b/innobase/include/srv0srv.h	2008-07-31 21:47:57 +0000
@@ -531,7 +531,9 @@
         ulint innodb_buffer_pool_pages_dirty;
         ulint innodb_buffer_pool_pages_misc;
         ulint innodb_buffer_pool_pages_free;
+#ifdef UNIV_DEBUG
         ulint innodb_buffer_pool_pages_latched;
+#endif /* UNIV_DEBUG */
         ulint innodb_buffer_pool_read_requests;
         ulint innodb_buffer_pool_reads;
         ulint innodb_buffer_pool_wait_free;

=== modified file 'innobase/include/trx0undo.h'
--- a/innobase/include/trx0undo.h	2005-02-25 20:35:33 +0000
+++ b/innobase/include/trx0undo.h	2008-07-31 21:47:57 +0000
@@ -237,6 +237,7 @@
 /*=========================*/
 				/* out: undo log segment header page,
 				x-latched */
+	trx_rseg_t*	rseg,	/* in: rollback segment memory object */
 	trx_t*		trx,	/* in: transaction */
 	trx_undo_t*	undo,	/* in: undo log memory copy */
 	mtr_t*		mtr);	/* in: mtr */

=== modified file 'innobase/srv/srv0srv.c'
--- a/innobase/srv/srv0srv.c	2007-11-20 17:53:19 +0000
+++ b/innobase/srv/srv0srv.c	2008-07-31 21:47:57 +0000
@@ -1803,7 +1803,9 @@
         export_vars.innodb_buffer_pool_pages_data= UT_LIST_GET_LEN(buf_pool->LRU);
         export_vars.innodb_buffer_pool_pages_dirty= UT_LIST_GET_LEN(buf_pool->flush_list);
         export_vars.innodb_buffer_pool_pages_free= UT_LIST_GET_LEN(buf_pool->free);
+#ifdef UNIV_DEBUG
         export_vars.innodb_buffer_pool_pages_latched= buf_get_latched_pages_number();
+#endif /* UNIV_DEBUG */
         export_vars.innodb_buffer_pool_pages_total= buf_pool->curr_size;
         export_vars.innodb_buffer_pool_pages_misc= buf_pool->max_size -
           UT_LIST_GET_LEN(buf_pool->LRU) - UT_LIST_GET_LEN(buf_pool->free);

=== modified file 'innobase/trx/trx0trx.c'
--- a/innobase/trx/trx0trx.c	2007-08-15 23:20:54 +0000
+++ b/innobase/trx/trx0trx.c	2008-07-31 21:47:57 +0000
@@ -761,8 +761,8 @@
 		mutex_enter(&(rseg->mutex));
 			
 		if (trx->insert_undo != NULL) {
-			trx_undo_set_state_at_finish(trx, trx->insert_undo,
-									&mtr);
+			trx_undo_set_state_at_finish(
+				rseg, trx, trx->insert_undo, &mtr);
 		}
 
 		undo = trx->update_undo;
@@ -777,8 +777,8 @@
 			because only a single OS thread is allowed to do the
 			transaction commit for this transaction. */
 					
-			update_hdr_page = trx_undo_set_state_at_finish(trx,
-								undo, &mtr);
+			update_hdr_page = trx_undo_set_state_at_finish(
+				rseg, trx, undo, &mtr);
 
 			/* We have to do the cleanup for the update log while
 			holding the rseg mutex because update log headers

=== modified file 'innobase/trx/trx0undo.c'
--- a/innobase/trx/trx0undo.c	2005-06-21 17:15:22 +0000
+++ b/innobase/trx/trx0undo.c	2008-07-31 21:47:57 +0000
@@ -1724,6 +1724,7 @@
 /*=========================*/
 				/* out: undo log segment header page,
 				x-latched */
+	trx_rseg_t*	rseg,	/* in: rollback segment memory object */
 	trx_t*		trx __attribute__((unused)), /* in: transaction */
 	trx_undo_t*	undo,	/* in: undo log memory copy */
 	mtr_t*		mtr)	/* in: mtr */
@@ -1732,8 +1733,10 @@
 	trx_upagef_t*	page_hdr;
 	page_t*		undo_page;
 	ulint		state;
-	
-	ut_ad(trx && undo && mtr);
+
+	ut_ad(trx);
+	ut_ad(undo);
+	ut_ad(mtr);
 
 	if (undo->id >= TRX_RSEG_N_SLOTS) {
 		fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
@@ -1747,9 +1750,23 @@
 	seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
 	page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
 
-	if (undo->size == 1 && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
-						< TRX_UNDO_PAGE_REUSE_LIMIT) {
-		state = TRX_UNDO_CACHED;
+	if (undo->size == 1
+	    && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
+	       < TRX_UNDO_PAGE_REUSE_LIMIT) {
+
+		/* This is a heuristic to avoid the problem of all UNDO
+		slots ending up in one of the UNDO lists. Previously if
+		the server crashed with all the slots in one of the lists,
+		transactions that required the slots of a different type
+		would fail for lack of slots. */
+
+		if (UT_LIST_GET_LEN(rseg->update_undo_list) < 500
+		    && UT_LIST_GET_LEN(rseg->insert_undo_list) < 500) {
+
+			state = TRX_UNDO_CACHED;
+		} else {
+			state = TRX_UNDO_TO_FREE;
+		}
 
 	} else if (undo->type == TRX_UNDO_INSERT) {
 
@@ -1759,7 +1776,7 @@
 	}
 
 	undo->state = state;
-		   
+
 	mlog_write_ulint(seg_hdr + TRX_UNDO_STATE, state, MLOG_2BYTES, mtr);
 
 	return(undo_page);

=== modified file 'myisam/mi_check.c'
--- a/myisam/mi_check.c	2008-03-29 15:50:46 +0000
+++ b/myisam/mi_check.c	2008-08-22 12:31:53 +0000
@@ -1732,7 +1732,7 @@
 			    DATA_TMP_EXT, share->base.raid_chunks,
 			    (param->testflag & T_BACKUP_DATA ?
 			     MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) ||
-	  mi_open_datafile(info,share,-1))
+	  mi_open_datafile(info,share,name,-1))
 	got_error=1;
     }
   }
@@ -2519,7 +2519,7 @@
 			    DATA_TMP_EXT, share->base.raid_chunks,
 			    (param->testflag & T_BACKUP_DATA ?
 			     MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) ||
-	  mi_open_datafile(info,share,-1))
+	  mi_open_datafile(info,share,name,-1))
 	got_error=1;
     }
   }
@@ -3050,7 +3050,7 @@
 			    DATA_TMP_EXT, share->base.raid_chunks,
 			    (param->testflag & T_BACKUP_DATA ?
 			     MYF(MY_REDEL_MAKE_BACKUP): MYF(0))) ||
-	  mi_open_datafile(info,share,-1))
+	  mi_open_datafile(info,share,name,-1))
 	got_error=1;
     }
   }

=== modified file 'myisam/mi_create.c'
--- a/myisam/mi_create.c	2007-07-11 09:37:47 +0000
+++ b/myisam/mi_create.c	2008-08-26 13:48:50 +0000
@@ -192,7 +192,7 @@
   packed=(packed+7)/8;
   if (pack_reclength != INT_MAX32)
     pack_reclength+= reclength+packed +
-      test(test_all_bits(options, HA_OPTION_CHECKSUM | HA_PACK_RECORD));
+      test(test_all_bits(options, HA_OPTION_CHECKSUM | HA_OPTION_PACK_RECORD));
   min_pack_length+=packed;
 
   if (!ci->data_file_length && ci->max_rows)

=== modified file 'myisam/mi_open.c'
--- a/myisam/mi_open.c	2008-03-29 07:52:16 +0000
+++ b/myisam/mi_open.c	2008-08-22 12:31:53 +0000
@@ -74,7 +74,7 @@
 
 MI_INFO *mi_open(const char *name, int mode, uint open_flags)
 {
-  int lock_error,kfile,open_mode,save_errno,have_rtree=0;
+  int lock_error,kfile,open_mode,save_errno,have_rtree=0, realpath_err;
   uint i,j,len,errpos,head_length,base_pos,offset,info_length,keys,
     key_parts,unique_key_parts,fulltext_keys,uniques;
   char name_buff[FN_REFLEN], org_name[FN_REFLEN], index_name[FN_REFLEN],
@@ -94,7 +94,16 @@
   head_length=sizeof(share_buff.state.header);
   bzero((byte*) &info,sizeof(info));
 
-  my_realpath(name_buff, fn_format(org_name,name,"",MI_NAME_IEXT,4),MYF(0));
+  realpath_err= my_realpath(name_buff,
+                  fn_format(org_name,name,"",MI_NAME_IEXT,4),MYF(0));
+  if (my_is_symlink(org_name) &&
+      (realpath_err || (*myisam_test_invalid_symlink)(name_buff)))
+  {
+    my_errno= HA_WRONG_CREATE_OPTION;
+    DBUG_RETURN (NULL);
+  }
+
+
   pthread_mutex_lock(&THR_LOCK_myisam);
   if (!(old_info=test_if_reopen(name_buff)))
   {
@@ -463,7 +472,7 @@
       lock_error=1;			/* Database unlocked */
     }
 
-    if (mi_open_datafile(&info, share, -1))
+    if (mi_open_datafile(&info, share, name, -1))
       goto err;
     errpos=5;
 
@@ -534,7 +543,7 @@
       my_errno=EACCES;				/* Can't open in write mode */
       goto err;
     }
-    if (mi_open_datafile(&info, share, old_info->dfile))
+    if (mi_open_datafile(&info, share, name, old_info->dfile))
       goto err;
     errpos=5;
     have_rtree= old_info->rtree_recursion_state != NULL;
@@ -1191,12 +1200,30 @@
 exist a dup()-like call that would give us two different file descriptors.
 *************************************************************************/
 
-int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup __attribute__((unused)))
+int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name,
+                     File file_to_dup __attribute__((unused)))
 {
+  char *data_name= share->data_file_name;
+  char real_data_name[FN_REFLEN];
+
+  if (org_name)
+  {
+    fn_format(real_data_name,org_name,"",MI_NAME_DEXT,4);
+    if (my_is_symlink(real_data_name))
+    {
+      if (my_realpath(real_data_name, real_data_name, MYF(0)) ||
+          (*myisam_test_invalid_symlink)(real_data_name))
+      {
+        my_errno= HA_WRONG_CREATE_OPTION;
+        return 1;
+      }
+      data_name= real_data_name;
+    }
+  }
 #ifdef USE_RAID
   if (share->base.raid_type)
   {
-    info->dfile=my_raid_open(share->data_file_name,
+    info->dfile=my_raid_open(data_name,
 			     share->mode | O_SHARE,
 			     share->base.raid_type,
 			     share->base.raid_chunks,
@@ -1205,8 +1232,7 @@
   }
   else
 #endif
-    info->dfile=my_open(share->data_file_name, share->mode | O_SHARE,
-			MYF(MY_WME));
+    info->dfile=my_open(data_name, share->mode | O_SHARE, MYF(MY_WME));
   return info->dfile >= 0 ? 0 : 1;
 }
 

=== modified file 'myisam/mi_static.c'
--- a/myisam/mi_static.c	2006-12-31 00:02:27 +0000
+++ b/myisam/mi_static.c	2008-08-26 08:32:43 +0000
@@ -41,6 +41,15 @@
 ulong    myisam_bulk_insert_tree_size=8192*1024;
 ulong    myisam_data_pointer_size=4;
 
+
+static int always_valid(const char *filename __attribute__((unused)))
+{
+  return 0;
+}
+
+int (*myisam_test_invalid_symlink)(const char *filename)= always_valid;
+
+
 /*
   read_vec[] is used for converting between P_READ_KEY.. and SEARCH_
   Position is , == , >= , <= , > , <

=== modified file 'myisam/myisamchk.c'
--- a/myisam/myisamchk.c	2007-11-14 10:38:26 +0000
+++ b/myisam/myisamchk.c	2008-08-22 12:31:53 +0000
@@ -1039,7 +1039,7 @@
 	  error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT,
 				   raid_chunks,
 				   MYF(0));
-	  if (mi_open_datafile(info,info->s, -1))
+	  if (mi_open_datafile(info,info->s, NULL, -1))
 	    error=1;
 	  param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
 	  param->read_cache.file=info->dfile;

=== modified file 'myisam/myisamdef.h'
--- a/myisam/myisamdef.h	2007-04-18 11:22:23 +0000
+++ b/myisam/myisamdef.h	2008-08-22 12:31:53 +0000
@@ -739,7 +739,9 @@
 
 extern MI_INFO *test_if_reopen(char *filename);
 my_bool check_table_is_closed(const char *name, const char *where);
-int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup);
+int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *orn_name,
+                     File file_to_dup);
+
 int mi_open_keyfile(MYISAM_SHARE *share);
 void mi_setup_functions(register MYISAM_SHARE *share);
 

=== modified file 'myisam/rt_index.c'
--- a/myisam/rt_index.c	2007-10-05 10:41:56 +0000
+++ b/myisam/rt_index.c	2008-08-26 13:51:06 +0000
@@ -389,7 +389,7 @@
   info->rtree_recursion_depth = -1;
   info->buff_used = 1;
   
-  return rtree_get_req(info, &keyinfo[keynr], key_length, root, 0);
+  return rtree_get_req(info, keyinfo, key_length, root, 0);
 }
 
 
@@ -436,7 +436,7 @@
       return -1;
     }
   
-    return rtree_get_req(info, &keyinfo[keynr], key_length, root, 0);
+    return rtree_get_req(info, keyinfo, key_length, root, 0);
   }
 }
 

=== modified file 'mysql-test/include/have_archive.inc'
--- a/mysql-test/include/have_archive.inc	2005-10-27 19:45:18 +0000
+++ b/mysql-test/include/have_archive.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 --require r/have_archive.require
 --disable_query_log
-show variables like "have_archive";
+show variables like 'have_archive';
 --enable_query_log

=== modified file 'mysql-test/include/have_bdb.inc'
--- a/mysql-test/include/have_bdb.inc	2001-10-04 21:42:25 +0000
+++ b/mysql-test/include/have_bdb.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_bdb.require
 disable_query_log;
-show variables like "have_bdb";
+show variables like 'have_bdb';
 enable_query_log;

=== modified file 'mysql-test/include/have_big5.inc'
--- a/mysql-test/include/have_big5.inc	2003-12-24 12:59:48 +0000
+++ b/mysql-test/include/have_big5.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_big5.require
 disable_query_log;
-show collation like "big5_chinese_ci";
+show collation like 'big5_chinese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_blackhole.inc'
--- a/mysql-test/include/have_blackhole.inc	2005-03-23 00:10:39 +0000
+++ b/mysql-test/include/have_blackhole.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_blackhole.require
 disable_query_log;
-show variables like "have_blackhole_engine";
+show variables like 'have_blackhole_engine';
 enable_query_log;

=== modified file 'mysql-test/include/have_case_sensitive_file_system.inc'
--- a/mysql-test/include/have_case_sensitive_file_system.inc	2006-05-04 06:55:09 +0000
+++ b/mysql-test/include/have_case_sensitive_file_system.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 --require r/case_sensitive_file_system.require
 --disable_query_log
-show variables like "lower_case_file_system";
+show variables like 'lower_case_file_system';
 --enable_query_log

=== modified file 'mysql-test/include/have_compress.inc'
--- a/mysql-test/include/have_compress.inc	2003-04-10 00:50:30 +0000
+++ b/mysql-test/include/have_compress.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_compress.require
 disable_query_log;
-show variables like "have_compress";
+show variables like 'have_compress';
 enable_query_log;

=== modified file 'mysql-test/include/have_cp1250_ch.inc'
--- a/mysql-test/include/have_cp1250_ch.inc	2005-03-03 10:15:37 +0000
+++ b/mysql-test/include/have_cp1250_ch.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_cp1250_ch.require
 disable_query_log;
-show collation like "cp1250_czech_cs";
+show collation like 'cp1250_czech_cs';
 enable_query_log;

=== modified file 'mysql-test/include/have_cp932.inc'
--- a/mysql-test/include/have_cp932.inc	2005-02-01 10:37:51 +0000
+++ b/mysql-test/include/have_cp932.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_cp932.require
 disable_query_log;
-show collation like "cp932_japanese_ci";
+show collation like 'cp932_japanese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_crypt.inc'
--- a/mysql-test/include/have_crypt.inc	2003-01-28 06:38:28 +0000
+++ b/mysql-test/include/have_crypt.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_crypt.require
 disable_query_log;
-show variables like "have_crypt";
+show variables like 'have_crypt';
 enable_query_log;

=== modified file 'mysql-test/include/have_csv.inc'
--- a/mysql-test/include/have_csv.inc	2004-08-13 03:57:18 +0000
+++ b/mysql-test/include/have_csv.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_csv.require
 disable_query_log;
-show variables like "have_csv";
+show variables like 'have_csv';
 enable_query_log;

=== modified file 'mysql-test/include/have_eucjpms.inc'
--- a/mysql-test/include/have_eucjpms.inc	2005-02-01 10:37:51 +0000
+++ b/mysql-test/include/have_eucjpms.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_eucjpms.require
 disable_query_log;
-show collation like "eucjpms_japanese_ci";
+show collation like 'eucjpms_japanese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_euckr.inc'
--- a/mysql-test/include/have_euckr.inc	2005-12-09 12:37:58 +0000
+++ b/mysql-test/include/have_euckr.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_euckr.require
 disable_query_log;
-show collation like "euckr_korean_ci";
+show collation like 'euckr_korean_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_exampledb.inc'
--- a/mysql-test/include/have_exampledb.inc	2004-08-14 00:14:36 +0000
+++ b/mysql-test/include/have_exampledb.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_exampledb.require
 disable_query_log;
-show variables like "have_example_engine";
+show variables like 'have_example_engine';
 enable_query_log;

=== modified file 'mysql-test/include/have_federated_db.inc'
--- a/mysql-test/include/have_federated_db.inc	2005-01-21 02:36:40 +0000
+++ b/mysql-test/include/have_federated_db.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_federated_db.require
 disable_query_log;
-show variables like "have_federated_engine";
+show variables like 'have_federated_engine';
 enable_query_log;

=== modified file 'mysql-test/include/have_gb2312.inc'
--- a/mysql-test/include/have_gb2312.inc	2005-12-09 12:37:58 +0000
+++ b/mysql-test/include/have_gb2312.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_gb2312.require
 disable_query_log;
-show collation like "gb2312_chinese_ci";
+show collation like 'gb2312_chinese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_gbk.inc'
--- a/mysql-test/include/have_gbk.inc	2005-07-22 16:06:02 +0000
+++ b/mysql-test/include/have_gbk.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_gbk.require
 disable_query_log;
-show collation like "gbk_chinese_ci";
+show collation like 'gbk_chinese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_geometry.inc'
--- a/mysql-test/include/have_geometry.inc	2005-10-27 19:45:18 +0000
+++ b/mysql-test/include/have_geometry.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 --require r/have_geometry.require
 --disable_query_log
-show variables like "have_geometry";
+show variables like 'have_geometry';
 --enable_query_log

=== modified file 'mysql-test/include/have_innodb.inc'
--- a/mysql-test/include/have_innodb.inc	2001-10-04 21:42:25 +0000
+++ b/mysql-test/include/have_innodb.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_innodb.require
 disable_query_log;
-show variables like "have_innodb";
+show variables like 'have_innodb';
 enable_query_log;

=== modified file 'mysql-test/include/have_latin2_ch.inc'
--- a/mysql-test/include/have_latin2_ch.inc	2006-03-20 12:28:25 +0000
+++ b/mysql-test/include/have_latin2_ch.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_latin2_ch.require
 disable_query_log;
-show collation like "latin2_czech_cs";
+show collation like 'latin2_czech_cs';
 enable_query_log;

=== modified file 'mysql-test/include/have_log_bin.inc'
--- a/mysql-test/include/have_log_bin.inc	2007-05-14 12:38:50 +0000
+++ b/mysql-test/include/have_log_bin.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_log_bin.require
 disable_query_log;
-show variables like "log_bin";
+show variables like 'log_bin';
 enable_query_log;

=== modified file 'mysql-test/include/have_lowercase0.inc'
--- a/mysql-test/include/have_lowercase0.inc	2006-10-19 09:35:10 +0000
+++ b/mysql-test/include/have_lowercase0.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 --require r/lowercase0.require
 --disable_query_log
-show variables like "lower_case_%";
+show variables like 'lower_case_%';
 --enable_query_log

=== modified file 'mysql-test/include/have_multi_ndb.inc'
--- a/mysql-test/include/have_multi_ndb.inc	2006-10-03 14:14:23 +0000
+++ b/mysql-test/include/have_multi_ndb.inc	2008-07-04 16:41:27 +0000
@@ -10,7 +10,7 @@
 --enable_warnings
 flush tables;
 --require r/have_ndb.require
-show variables like "have_ndbcluster";
+show variables like 'have_ndbcluster';
 enable_query_log;
 
 # Check that server2 has NDB support
@@ -21,7 +21,7 @@
 --enable_warnings
 flush tables;
 --require r/have_ndb.require
-show variables like "have_ndbcluster";
+show variables like 'have_ndbcluster';
 enable_query_log;
 
 # Set the default connection to 'server1'

=== modified file 'mysql-test/include/have_ndb.inc'
--- a/mysql-test/include/have_ndb.inc	2006-10-05 10:42:39 +0000
+++ b/mysql-test/include/have_ndb.inc	2008-07-04 16:41:27 +0000
@@ -1,7 +1,7 @@
 # Check that server is compiled and started with support for NDB
 -- require r/have_ndb.require
 disable_query_log;
-show variables like "have_ndbcluster";
+show variables like 'have_ndbcluster';
 enable_query_log;
 
 # Check that NDB is installed and known to be working

=== modified file 'mysql-test/include/have_query_cache.inc'
--- a/mysql-test/include/have_query_cache.inc	2004-10-26 16:30:01 +0000
+++ b/mysql-test/include/have_query_cache.inc	2008-07-04 16:41:27 +0000
@@ -3,5 +3,5 @@
 # of query cache hits
 -- disable_ps_protocol
 disable_query_log;
-show variables like "have_query_cache";
+show variables like 'have_query_cache';
 enable_query_log;

=== modified file 'mysql-test/include/have_sjis.inc'
--- a/mysql-test/include/have_sjis.inc	2004-03-25 10:29:56 +0000
+++ b/mysql-test/include/have_sjis.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_sjis.require
 disable_query_log;
-show collation like "sjis_japanese_ci";
+show collation like 'sjis_japanese_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_ssl.inc'
--- a/mysql-test/include/have_ssl.inc	2007-03-05 09:03:42 +0000
+++ b/mysql-test/include/have_ssl.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_ssl.require
 disable_query_log;
-show variables like "have_ssl";
+show variables like 'have_ssl';
 enable_query_log;

=== modified file 'mysql-test/include/have_tis620.inc'
--- a/mysql-test/include/have_tis620.inc	2003-12-25 16:11:01 +0000
+++ b/mysql-test/include/have_tis620.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_tis620.require
 disable_query_log;
-show collation like "tis620_thai_ci";
+show collation like 'tis620_thai_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_ucs2.inc'
--- a/mysql-test/include/have_ucs2.inc	2003-05-23 10:10:05 +0000
+++ b/mysql-test/include/have_ucs2.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_ucs2.require
 disable_query_log;
-show collation like "ucs2_general_ci";
+show collation like 'ucs2_general_ci';
 enable_query_log;

=== modified file 'mysql-test/include/have_udf.inc'
--- a/mysql-test/include/have_udf.inc	2006-04-27 14:32:40 +0000
+++ b/mysql-test/include/have_udf.inc	2008-07-04 16:41:27 +0000
@@ -4,7 +4,7 @@
 #
 --require r/have_udf.require
 disable_query_log;
-show variables like "have_dynamic_loading";
+show variables like 'have_dynamic_loading';
 enable_query_log;
 
 #

=== modified file 'mysql-test/include/have_ujis.inc'
--- a/mysql-test/include/have_ujis.inc	2003-05-23 10:10:05 +0000
+++ b/mysql-test/include/have_ujis.inc	2008-07-04 16:41:27 +0000
@@ -1,4 +1,4 @@
 -- require r/have_ujis.require
 disable_query_log;
-show collation like "ujis_japanese_ci";
+show collation like 'ujis_japanese_ci';
 enable_query_log;

=== modified file 'mysql-test/r/client_xml.result'
--- a/mysql-test/r/client_xml.result	2007-04-09 12:53:10 +0000
+++ b/mysql-test/r/client_xml.result	2008-07-18 09:07:16 +0000
@@ -1,3 +1,4 @@
+drop table if exists t1;
 create table t1 (
 `a&b` int,
 `a<b` int,

=== modified file 'mysql-test/r/comments.result'
--- a/mysql-test/r/comments.result	2007-08-29 20:50:32 +0000
+++ b/mysql-test/r/comments.result	2008-07-07 16:00:08 +0000
@@ -35,7 +35,7 @@
 prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;";
 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
 prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;*";
-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
+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
 prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';";
 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 '/*!98765' AND b = 'bar'' at line 1
 prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';*";

=== modified file 'mysql-test/r/federated.result'
--- a/mysql-test/r/federated.result	2008-03-20 15:07:17 +0000
+++ b/mysql-test/r/federated.result	2008-08-15 06:40:05 +0000
@@ -2071,7 +2071,18 @@
 DROP TABLE t1;
 CREATE TABLE t1 (a INT) ENGINE=federated CONNECTION='mysql://@:://';
 DROP TABLE t1;
-DROP TABLE IF EXISTS federated.t1;
-DROP DATABASE IF EXISTS federated;
-DROP TABLE IF EXISTS federated.t1;
-DROP DATABASE IF EXISTS federated;
+CREATE TABLE t1 (a LONGBLOB, b LONGBLOB);
+INSERT INTO t1 VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaa', NULL);
+CREATE TABLE t1
+(a LONGBLOB, b LONGBLOB) ENGINE=FEDERATED
+CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
+CHECKSUM TABLE t1;
+Table	Checksum
+test.t1	2465757603
+DROP TABLE t1;
+DROP TABLE t1;
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE IF EXISTS federated;
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE IF EXISTS federated;
+End of 5.0 tests

=== modified file 'mysql-test/r/func_if.result'
--- a/mysql-test/r/func_if.result	2007-02-12 20:59:29 +0000
+++ b/mysql-test/r/func_if.result	2008-07-30 11:07:37 +0000
@@ -131,3 +131,49 @@
 select if(0, 18446744073709551610, 18446744073709551610);
 if(0, 18446744073709551610, 18446744073709551610)
 18446744073709551610
+CREATE TABLE t1(a DECIMAL(10,3));
+SELECT t1.a,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,0)))))))))))))))))))))))))))))) + 1
+FROM t1;
+a	IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((ROUND(t1.a,2)=1), 2,
+IF((R
+DROP TABLE t1;
+End of 5.0 tests

=== modified file 'mysql-test/r/func_misc.result'
--- a/mysql-test/r/func_misc.result	2008-06-02 19:57:11 +0000
+++ b/mysql-test/r/func_misc.result	2008-07-10 01:58:30 +0000
@@ -305,4 +305,18 @@
 SELECT NAME_CONST('var', 'value') COLLATE latin1_general_cs;
 NAME_CONST('var', 'value') COLLATE latin1_general_cs
 value
+select @@session.time_zone into @save_tz;
+set @@session.time_zone='UTC';
+select uuid() into @my_uuid;
+select mid(@my_uuid,15,1);
+mid(@my_uuid,15,1)
+1
+select 24 * 60 * 60 * 1000 * 1000 * 10 into @my_uuid_one_day;
+select concat('0',mid(@my_uuid,16,3),mid(@my_uuid,10,4),left(@my_uuid,8)) into @my_uuidate;
+select floor(conv(@my_uuidate,16,10)/@my_uuid_one_day) into @my_uuid_date;
+select 141427 + datediff(curdate(),'1970-01-01') into @my_uuid_synthetic;
+select @my_uuid_date - @my_uuid_synthetic;
+@my_uuid_date - @my_uuid_synthetic
+0
+set @@session.time_zone=@save_tz;
 End of 5.0 tests

=== modified file 'mysql-test/r/group_min_max.result'
--- a/mysql-test/r/group_min_max.result	2007-11-20 14:07:24 +0000
+++ b/mysql-test/r/group_min_max.result	2008-08-27 13:03:17 +0000
@@ -2353,3 +2353,79 @@
 2	1	3	2.0000
 1	1	3	2.0000
 DROP TABLE t1;
+create table t1 (a int, b int, primary key (a,b), key `index` (a,b)) engine=MyISAM;
+insert into  t1 (a,b) values 
+(0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),
+(0,7),(0,8),(0,9),(0,10),(0,11),(0,12),(0,13),
+(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),
+(1,7),(1,8),(1,9),(1,10),(1,11),(1,12),(1,13),
+(2,0),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),
+(2,7),(2,8),(2,9),(2,10),(2,11),(2,12),(2,13),
+(3,0),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),
+(3,7),(3,8),(3,9),(3,10),(3,11),(3,12),(3,13);
+insert into t1 (a,b) select a, max(b)+1 from t1 where a = 0 group by a;
+select * from t1;
+a	b
+0	0
+0	1
+0	2
+0	3
+0	4
+0	5
+0	6
+0	7
+0	8
+0	9
+0	10
+0	11
+0	12
+0	13
+0	14
+1	0
+1	1
+1	2
+1	3
+1	4
+1	5
+1	6
+1	7
+1	8
+1	9
+1	10
+1	11
+1	12
+1	13
+2	0
+2	1
+2	2
+2	3
+2	4
+2	5
+2	6
+2	7
+2	8
+2	9
+2	10
+2	11
+2	12
+2	13
+3	0
+3	1
+3	2
+3	3
+3	4
+3	5
+3	6
+3	7
+3	8
+3	9
+3	10
+3	11
+3	12
+3	13
+explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,index	PRIMARY	4	NULL	3	Using where; Using index for group-by; Using temporary
+Warnings:
+Note	1003	select sql_buffer_result `test`.`t1`.`a` AS `a`,(max(`test`.`t1`.`b`) + 1) AS `max(b)+1` from `test`.`t1` where (`test`.`t1`.`a` = 0) group by `test`.`t1`.`a`
+drop table t1;

=== added file 'mysql-test/r/innodb-autoinc-optimize.result'
--- a/mysql-test/r/innodb-autoinc-optimize.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb-autoinc-optimize.result	2008-07-31 21:47:57 +0000
@@ -0,0 +1,6 @@
+drop table if exists t1;
+create table t1(a int not null auto_increment primary key) engine=innodb;
+insert into t1 set a = -1;
+optimize table t1;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	OK

=== added file 'mysql-test/r/innodb_bug35220.result'
--- a/mysql-test/r/innodb_bug35220.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug35220.result	2008-08-08 00:25:24 +0000
@@ -0,0 +1,1 @@
+SET storage_engine=InnoDB;

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2008-02-07 07:12:49 +0000
+++ b/mysql-test/r/innodb_mysql.result	2008-07-23 11:25:00 +0000
@@ -1246,4 +1246,19 @@
 set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
 set global innodb_commit_concurrency=0;
 set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
+CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
+ENGINE=InnoDB;
+INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
+INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
+EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	t1_b	t1_b	5	NULL	4	Using where
+SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+a	b	c
+8	1	1
+7	1	1
+6	1	1
+5	1	1
+4	1	1
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/metadata.result'
--- a/mysql-test/r/metadata.result	2007-06-20 09:21:48 +0000
+++ b/mysql-test/r/metadata.result	2008-08-20 09:49:28 +0000
@@ -108,11 +108,11 @@
 1
 select * from v1 group by id limit 0;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def	test	t1	v1	id	id	3	10	0	Y	32768	0	63
+def	test	v1	v1	id	id	3	10	0	Y	32768	0	63
 id
 select * from v1 where id=1000 group by id;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def	test	t1	v1	id	id	3	10	0	Y	32768	0	63
+def	test	v1	v1	id	id	3	10	0	Y	32768	0	63
 id
 select * from v1 where id=1 group by id;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
@@ -126,7 +126,7 @@
 1
 select * from v3 where renamed=1 group by renamed;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def			v3		renamed	8	12	0	Y	32896	0	63
+def		v3	v3	renamed	renamed	8	12	0	Y	32896	0	63
 renamed
 drop table t1;
 drop view v1,v2,v3;
@@ -156,8 +156,8 @@
 3
 SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def	test	t1	v1	c1	c1	254	1	1	Y	0	0	8
-def	test	t2	v2	c2	c2	254	1	1	Y	0	0	8
+def	test	v1	v1	c1	c1	254	1	1	Y	0	0	8
+def	test	v2	v2	c2	c2	254	1	1	Y	0	0	8
 c1	c2
 1	1
 2	2

=== modified file 'mysql-test/r/myisam.result'
--- a/mysql-test/r/myisam.result	2008-05-06 16:43:46 +0000
+++ b/mysql-test/r/myisam.result	2008-08-26 13:48:50 +0000
@@ -1861,4 +1861,26 @@
 3	2
 4	5
 DROP TABLE t1, t2;
+CREATE TABLE t1 (a INT) ENGINE=MyISAM CHECKSUM=1 ROW_FORMAT=DYNAMIC;
+INSERT INTO t1 VALUES (0);
+UPDATE t1 SET a=1;
+SELECT a FROM t1;
+a
+1
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+INSERT INTO t1 VALUES (0), (5), (4), (2);
+UPDATE t1 SET a=2;
+SELECT a FROM t1;
+a
+2
+2
+2
+2
+2
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2008-06-24 16:03:17 +0000
+++ b/mysql-test/r/mysql.result	2008-07-18 10:24:59 +0000
@@ -38,8 +38,6 @@
 t3
 Tables_in_test
 t1
-delimiter
-1
 _
 Test delimiter : from command line
 a

=== added file 'mysql-test/r/parser.result'
--- a/mysql-test/r/parser.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/parser.result	2008-07-07 16:00:08 +0000
@@ -0,0 +1,68 @@
+DROP PROCEDURE IF EXISTS p26030;
+select "non terminated"$$
+non terminated
+non terminated
+select "terminated";$$
+terminated
+terminated
+select "non terminated, space"      $$
+non terminated, space
+non terminated, space
+select "terminated, space";      $$
+terminated, space
+terminated, space
+select "non terminated, comment" /* comment */$$
+non terminated, comment
+non terminated, comment
+select "terminated, comment"; /* comment */$$
+terminated, comment
+terminated, comment
+select "stmt 1";select "stmt 2 non terminated"$$
+stmt 1
+stmt 1
+stmt 2 non terminated
+stmt 2 non terminated
+select "stmt 1";select "stmt 2 terminated";$$
+stmt 1
+stmt 1
+stmt 2 terminated
+stmt 2 terminated
+select "stmt 1";select "stmt 2 non terminated, space"      $$
+stmt 1
+stmt 1
+stmt 2 non terminated, space
+stmt 2 non terminated, space
+select "stmt 1";select "stmt 2 terminated, space";      $$
+stmt 1
+stmt 1
+stmt 2 terminated, space
+stmt 2 terminated, space
+select "stmt 1";select "stmt 2 non terminated, comment" /* comment */$$
+stmt 1
+stmt 1
+stmt 2 non terminated, comment
+stmt 2 non terminated, comment
+select "stmt 1";select "stmt 2 terminated, comment"; /* comment */$$
+stmt 1
+stmt 1
+stmt 2 terminated, comment
+stmt 2 terminated, comment
+select "stmt 1";             select "space, stmt 2"$$
+stmt 1
+stmt 1
+space, stmt 2
+space, stmt 2
+select "stmt 1";/* comment */select "comment, stmt 2"$$
+stmt 1
+stmt 1
+comment, stmt 2
+comment, stmt 2
+DROP PROCEDURE IF EXISTS p26030; CREATE PROCEDURE p26030() BEGIN SELECT 1; END; CALL p26030()
+$$
+1
+1
+DROP PROCEDURE IF EXISTS p26030; CREATE PROCEDURE p26030() SELECT 1; CALL p26030()
+$$
+1
+1
+DROP PROCEDURE p26030;

=== added file 'mysql-test/r/parser_stack.result'
--- a/mysql-test/r/parser_stack.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/parser_stack.result	2008-07-14 21:41:30 +0000
@@ -0,0 +1,306 @@
+use test;
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+;
+1
+1
+prepare stmt from
+"
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+"
+;
+execute stmt;
+1
+1
+drop view if exists view_overflow;
+CREATE VIEW view_overflow AS
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+;
+SELECT * from view_overflow;
+1
+1
+drop view view_overflow;
+drop procedure if exists proc_overflow;
+CREATE PROCEDURE proc_overflow()
+BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+select 1;
+select 2;
+select 3;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END $$
+call proc_overflow();
+1
+1
+2
+2
+3
+3
+drop procedure proc_overflow;
+drop function if exists func_overflow;
+create function func_overflow() returns int
+BEGIN
+DECLARE x int default 0;
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+SET x=x+1;
+SET x=x+2;
+SET x=x+3;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+return x;
+END $$
+select func_overflow();
+func_overflow()
+6
+drop function func_overflow;
+drop table if exists table_overflow;
+create table table_overflow(a int, b int);
+create trigger trigger_overflow before insert on table_overflow
+for each row
+BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+SET NEW.b := NEW.a;
+SET NEW.b := NEW.b + 1;
+SET NEW.b := NEW.b + 2;
+SET NEW.b := NEW.b + 3;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+END $$
+insert into table_overflow set a=10;
+insert into table_overflow set a=20;
+select * from table_overflow;
+a	b
+10	16
+20	26
+drop table table_overflow;
+drop procedure if exists proc_35577;
+CREATE PROCEDURE proc_35577()
+BEGIN
+DECLARE z_done INT DEFAULT 0;
+DECLARE t_done VARCHAR(5000);
+outer_loop: LOOP
+IF t_done=1  THEN
+LEAVE outer_loop;
+END IF;
+inner_block:BEGIN
+DECLARE z_done INT DEFAULT  0;
+SET z_done = 0;
+inner_loop: LOOP
+IF z_done=1  THEN
+LEAVE inner_loop;
+END IF;
+IF (t_done = 'a') THEN
+IF (t_done <> 0) THEN
+IF ( t_done > 0) THEN
+IF (t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF (t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+ELSEIF(t_done = 'a') THEN
+SET t_done = 'a';
+END IF;
+END IF;
+END IF;
+END IF;
+END LOOP inner_loop;
+END inner_block;
+END LOOP outer_loop;
+END $$
+drop procedure proc_35577;
+drop procedure if exists p_37269;
+create procedure p_37269()
+begin
+declare done int default 0;
+declare varb int default 0;
+declare vara int default 0;
+repeat
+select now();
+until done end repeat;
+while varb do
+select now();
+begin
+select now();
+repeat
+select now();
+until done end repeat;
+if vara then 
+select now();
+repeat
+select now();
+loop
+select now();
+end loop;
+repeat
+select now();
+label1: while varb do
+select now();
+end while label1;
+if vara then 
+select now();
+repeat
+select now();
+until done end repeat;
+begin
+select now();
+while varb do
+select now();
+label1: while varb do
+select now();
+end while label1;
+if vara then 
+select now();
+while varb do
+select now();
+loop
+select now();
+end loop;
+repeat
+select now();
+loop
+select now();
+while varb do
+select now();
+end while;
+repeat
+select now();
+label1: loop
+select now();
+if vara then 
+select now();
+end if;
+end loop label1;
+until done end repeat;
+end loop;
+until done end repeat;
+end while;
+end if;
+end while;
+end;
+end if;
+until done end repeat;
+until done end repeat;
+end if;
+end;
+end while;
+end $$
+drop procedure p_37269;
+drop procedure if exists p_37228;
+create procedure p_37228 ()
+BEGIN
+DECLARE v INT DEFAULT 123;
+IF (v > 1) THEN SET v = 1; 
+ELSEIF (v < 10) THEN SET v = 10;
+ELSEIF (v < 11) THEN SET v = 11;
+ELSEIF (v < 12) THEN SET v = 12;
+ELSEIF (v < 13) THEN SET v = 13;
+ELSEIF (v < 14) THEN SET v = 14;
+ELSEIF (v < 15) THEN SET v = 15;
+ELSEIF (v < 16) THEN SET v = 16;
+ELSEIF (v < 17) THEN SET v = 17;
+ELSEIF (v < 18) THEN SET v = 18;
+ELSEIF (v < 19) THEN SET v = 19;
+ELSEIF (v < 20) THEN SET v = 20;
+ELSEIF (v < 21) THEN SET v = 21;
+ELSEIF (v < 22) THEN SET v = 22;
+ELSEIF (v < 23) THEN SET v = 23;
+ELSEIF (v < 24) THEN SET v = 24;
+ELSEIF (v < 25) THEN SET v = 25;
+ELSEIF (v < 26) THEN SET v = 26;
+ELSEIF (v < 27) THEN SET v = 27;
+ELSEIF (v < 28) THEN SET v = 28;
+ELSEIF (v < 29) THEN SET v = 29;
+ELSEIF (v < 30) THEN SET v = 30;
+ELSEIF (v < 31) THEN SET v = 31;
+ELSEIF (v < 32) THEN SET v = 32;
+ELSEIF (v < 33) THEN SET v = 33;
+ELSEIF (v < 34) THEN SET v = 34;
+ELSEIF (v < 35) THEN SET v = 35;
+ELSEIF (v < 36) THEN SET v = 36;
+ELSEIF (v < 37) THEN SET v = 37;
+ELSEIF (v < 38) THEN SET v = 38;
+ELSEIF (v < 39) THEN SET v = 39;
+END IF;
+END $$
+drop procedure p_37228;

=== modified file 'mysql-test/r/ps.result'
--- a/mysql-test/r/ps.result	2008-02-28 14:34:08 +0000
+++ b/mysql-test/r/ps.result	2008-07-07 16:00:08 +0000
@@ -85,9 +85,9 @@
 NULL
 NULL
 prepare stmt6 from 'select 1; select2';
-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 '; select2' at line 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 'select2' at line 1
 prepare stmt6 from 'insert into t1 values (5,"five"); select2';
-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 '; select2' at line 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 'select2' at line 1
 explain prepare stmt6 from 'insert into t1 values (5,"five"); select2';
 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 'from 'insert into t1 values (5,"five"); select2'' at line 1
 create table t2

=== modified file 'mysql-test/r/ps_1general.result'
--- a/mysql-test/r/ps_1general.result	2007-09-20 08:54:46 +0000
+++ b/mysql-test/r/ps_1general.result	2008-08-15 20:13:27 +0000
@@ -468,7 +468,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	14	N	1	31	8
@@ -484,7 +484,7 @@
 def					type	253	10	5	Y	0	31	8
 def					possible_keys	253	4096	7	Y	0	31	8
 def					key	253	64	7	Y	0	31	8
-def					key_len	253	1365	1	Y	0	31	8
+def					key_len	253	4096	1	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	27	N	1	31	8

=== modified file 'mysql-test/r/ps_2myisam.result'
--- a/mysql-test/r/ps_2myisam.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_2myisam.result	2008-08-15 20:13:27 +0000
@@ -1158,7 +1158,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/ps_3innodb.result'
--- a/mysql-test/r/ps_3innodb.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_3innodb.result	2008-08-15 20:13:27 +0000
@@ -1158,7 +1158,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/ps_4heap.result'
--- a/mysql-test/r/ps_4heap.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_4heap.result	2008-08-15 20:13:27 +0000
@@ -1159,7 +1159,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/ps_5merge.result'
--- a/mysql-test/r/ps_5merge.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_5merge.result	2008-08-15 20:13:27 +0000
@@ -1201,7 +1201,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8
@@ -4223,7 +4223,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/ps_6bdb.result'
--- a/mysql-test/r/ps_6bdb.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_6bdb.result	2008-08-15 20:13:27 +0000
@@ -1158,7 +1158,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/ps_7ndb.result'
--- a/mysql-test/r/ps_7ndb.result	2007-12-06 07:46:01 +0000
+++ b/mysql-test/r/ps_7ndb.result	2008-08-15 20:13:27 +0000
@@ -1158,7 +1158,7 @@
 def					type	253	10	3	Y	0	31	8
 def					possible_keys	253	4096	0	Y	0	31	8
 def					key	253	64	0	Y	0	31	8
-def					key_len	253	1365	0	Y	0	31	8
+def					key_len	253	4096	0	Y	0	31	8
 def					ref	253	1024	0	Y	0	31	8
 def					rows	8	10	1	Y	32928	0	63
 def					Extra	253	255	0	N	1	31	8

=== modified file 'mysql-test/r/query_cache_merge.result'
--- a/mysql-test/r/query_cache_merge.result	2003-08-22 01:07:40 +0000
+++ b/mysql-test/r/query_cache_merge.result	2008-07-24 14:14:34 +0000
@@ -18,3 +18,1675 @@
 Qcache_queries_in_cache	0
 drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40,t41,t42,t43,t44,t45,t46,t47,t48,t49,t50,t51,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79,t80,t81,t82,t83,t84,t85,t86,t87,t88,t89,t90,t91,t92,t93,t94,t95,t96,t97,t98,t99,t100,t101,t102,t103,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t114,t115,t116,t117,t118,t119,t120,t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t137,t138,t139,t140,t141,t142,t143,t144,t145,t146,t147,t148,t149,t150,t151,t152,t153,t154,t155,t156,t157,t158,t159,t160,t161,t162,t163,t164,t165,t166,t167,t168,t169,t170,t171,t172,t173,t174,t175,t176,t177,t178,t179,t180,t181,t182,t183,t184,t185,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t196,t197,t198,t199,t200,t201,t202,t203,t204,t205,t206,t207,t208,t209,t210,t211,t212,t213,t214,t215,t216,t217,t218,t219,t220,t221,t222,t223,t224,t225,t226,t227,t228,t229,t230,t231,t232,t233,t234,t235,t236,t237,t238,t239,t240,t241,t242,t243,t244,t245,t246,t247,t248,t249,t250,t251,t252,t253,t254,t255,t256,t257,t00;
 SET @@global.query_cache_size=0;
+CREATE TABLE t255 (a INT);
+INSERT INTO t255 VALUES (255);
+CREATE TABLE t254 (a INT);
+INSERT INTO t254 VALUES (254);
+CREATE TABLE t253 (a INT);
+INSERT INTO t253 VALUES (253);
+CREATE TABLE t252 (a INT);
+INSERT INTO t252 VALUES (252);
+CREATE TABLE t251 (a INT);
+INSERT INTO t251 VALUES (251);
+CREATE TABLE t250 (a INT);
+INSERT INTO t250 VALUES (250);
+CREATE TABLE t249 (a INT);
+INSERT INTO t249 VALUES (249);
+CREATE TABLE t248 (a INT);
+INSERT INTO t248 VALUES (248);
+CREATE TABLE t247 (a INT);
+INSERT INTO t247 VALUES (247);
+CREATE TABLE t246 (a INT);
+INSERT INTO t246 VALUES (246);
+CREATE TABLE t245 (a INT);
+INSERT INTO t245 VALUES (245);
+CREATE TABLE t244 (a INT);
+INSERT INTO t244 VALUES (244);
+CREATE TABLE t243 (a INT);
+INSERT INTO t243 VALUES (243);
+CREATE TABLE t242 (a INT);
+INSERT INTO t242 VALUES (242);
+CREATE TABLE t241 (a INT);
+INSERT INTO t241 VALUES (241);
+CREATE TABLE t240 (a INT);
+INSERT INTO t240 VALUES (240);
+CREATE TABLE t239 (a INT);
+INSERT INTO t239 VALUES (239);
+CREATE TABLE t238 (a INT);
+INSERT INTO t238 VALUES (238);
+CREATE TABLE t237 (a INT);
+INSERT INTO t237 VALUES (237);
+CREATE TABLE t236 (a INT);
+INSERT INTO t236 VALUES (236);
+CREATE TABLE t235 (a INT);
+INSERT INTO t235 VALUES (235);
+CREATE TABLE t234 (a INT);
+INSERT INTO t234 VALUES (234);
+CREATE TABLE t233 (a INT);
+INSERT INTO t233 VALUES (233);
+CREATE TABLE t232 (a INT);
+INSERT INTO t232 VALUES (232);
+CREATE TABLE t231 (a INT);
+INSERT INTO t231 VALUES (231);
+CREATE TABLE t230 (a INT);
+INSERT INTO t230 VALUES (230);
+CREATE TABLE t229 (a INT);
+INSERT INTO t229 VALUES (229);
+CREATE TABLE t228 (a INT);
+INSERT INTO t228 VALUES (228);
+CREATE TABLE t227 (a INT);
+INSERT INTO t227 VALUES (227);
+CREATE TABLE t226 (a INT);
+INSERT INTO t226 VALUES (226);
+CREATE TABLE t225 (a INT);
+INSERT INTO t225 VALUES (225);
+CREATE TABLE t224 (a INT);
+INSERT INTO t224 VALUES (224);
+CREATE TABLE t223 (a INT);
+INSERT INTO t223 VALUES (223);
+CREATE TABLE t222 (a INT);
+INSERT INTO t222 VALUES (222);
+CREATE TABLE t221 (a INT);
+INSERT INTO t221 VALUES (221);
+CREATE TABLE t220 (a INT);
+INSERT INTO t220 VALUES (220);
+CREATE TABLE t219 (a INT);
+INSERT INTO t219 VALUES (219);
+CREATE TABLE t218 (a INT);
+INSERT INTO t218 VALUES (218);
+CREATE TABLE t217 (a INT);
+INSERT INTO t217 VALUES (217);
+CREATE TABLE t216 (a INT);
+INSERT INTO t216 VALUES (216);
+CREATE TABLE t215 (a INT);
+INSERT INTO t215 VALUES (215);
+CREATE TABLE t214 (a INT);
+INSERT INTO t214 VALUES (214);
+CREATE TABLE t213 (a INT);
+INSERT INTO t213 VALUES (213);
+CREATE TABLE t212 (a INT);
+INSERT INTO t212 VALUES (212);
+CREATE TABLE t211 (a INT);
+INSERT INTO t211 VALUES (211);
+CREATE TABLE t210 (a INT);
+INSERT INTO t210 VALUES (210);
+CREATE TABLE t209 (a INT);
+INSERT INTO t209 VALUES (209);
+CREATE TABLE t208 (a INT);
+INSERT INTO t208 VALUES (208);
+CREATE TABLE t207 (a INT);
+INSERT INTO t207 VALUES (207);
+CREATE TABLE t206 (a INT);
+INSERT INTO t206 VALUES (206);
+CREATE TABLE t205 (a INT);
+INSERT INTO t205 VALUES (205);
+CREATE TABLE t204 (a INT);
+INSERT INTO t204 VALUES (204);
+CREATE TABLE t203 (a INT);
+INSERT INTO t203 VALUES (203);
+CREATE TABLE t202 (a INT);
+INSERT INTO t202 VALUES (202);
+CREATE TABLE t201 (a INT);
+INSERT INTO t201 VALUES (201);
+CREATE TABLE t200 (a INT);
+INSERT INTO t200 VALUES (200);
+CREATE TABLE t199 (a INT);
+INSERT INTO t199 VALUES (199);
+CREATE TABLE t198 (a INT);
+INSERT INTO t198 VALUES (198);
+CREATE TABLE t197 (a INT);
+INSERT INTO t197 VALUES (197);
+CREATE TABLE t196 (a INT);
+INSERT INTO t196 VALUES (196);
+CREATE TABLE t195 (a INT);
+INSERT INTO t195 VALUES (195);
+CREATE TABLE t194 (a INT);
+INSERT INTO t194 VALUES (194);
+CREATE TABLE t193 (a INT);
+INSERT INTO t193 VALUES (193);
+CREATE TABLE t192 (a INT);
+INSERT INTO t192 VALUES (192);
+CREATE TABLE t191 (a INT);
+INSERT INTO t191 VALUES (191);
+CREATE TABLE t190 (a INT);
+INSERT INTO t190 VALUES (190);
+CREATE TABLE t189 (a INT);
+INSERT INTO t189 VALUES (189);
+CREATE TABLE t188 (a INT);
+INSERT INTO t188 VALUES (188);
+CREATE TABLE t187 (a INT);
+INSERT INTO t187 VALUES (187);
+CREATE TABLE t186 (a INT);
+INSERT INTO t186 VALUES (186);
+CREATE TABLE t185 (a INT);
+INSERT INTO t185 VALUES (185);
+CREATE TABLE t184 (a INT);
+INSERT INTO t184 VALUES (184);
+CREATE TABLE t183 (a INT);
+INSERT INTO t183 VALUES (183);
+CREATE TABLE t182 (a INT);
+INSERT INTO t182 VALUES (182);
+CREATE TABLE t181 (a INT);
+INSERT INTO t181 VALUES (181);
+CREATE TABLE t180 (a INT);
+INSERT INTO t180 VALUES (180);
+CREATE TABLE t179 (a INT);
+INSERT INTO t179 VALUES (179);
+CREATE TABLE t178 (a INT);
+INSERT INTO t178 VALUES (178);
+CREATE TABLE t177 (a INT);
+INSERT INTO t177 VALUES (177);
+CREATE TABLE t176 (a INT);
+INSERT INTO t176 VALUES (176);
+CREATE TABLE t175 (a INT);
+INSERT INTO t175 VALUES (175);
+CREATE TABLE t174 (a INT);
+INSERT INTO t174 VALUES (174);
+CREATE TABLE t173 (a INT);
+INSERT INTO t173 VALUES (173);
+CREATE TABLE t172 (a INT);
+INSERT INTO t172 VALUES (172);
+CREATE TABLE t171 (a INT);
+INSERT INTO t171 VALUES (171);
+CREATE TABLE t170 (a INT);
+INSERT INTO t170 VALUES (170);
+CREATE TABLE t169 (a INT);
+INSERT INTO t169 VALUES (169);
+CREATE TABLE t168 (a INT);
+INSERT INTO t168 VALUES (168);
+CREATE TABLE t167 (a INT);
+INSERT INTO t167 VALUES (167);
+CREATE TABLE t166 (a INT);
+INSERT INTO t166 VALUES (166);
+CREATE TABLE t165 (a INT);
+INSERT INTO t165 VALUES (165);
+CREATE TABLE t164 (a INT);
+INSERT INTO t164 VALUES (164);
+CREATE TABLE t163 (a INT);
+INSERT INTO t163 VALUES (163);
+CREATE TABLE t162 (a INT);
+INSERT INTO t162 VALUES (162);
+CREATE TABLE t161 (a INT);
+INSERT INTO t161 VALUES (161);
+CREATE TABLE t160 (a INT);
+INSERT INTO t160 VALUES (160);
+CREATE TABLE t159 (a INT);
+INSERT INTO t159 VALUES (159);
+CREATE TABLE t158 (a INT);
+INSERT INTO t158 VALUES (158);
+CREATE TABLE t157 (a INT);
+INSERT INTO t157 VALUES (157);
+CREATE TABLE t156 (a INT);
+INSERT INTO t156 VALUES (156);
+CREATE TABLE t155 (a INT);
+INSERT INTO t155 VALUES (155);
+CREATE TABLE t154 (a INT);
+INSERT INTO t154 VALUES (154);
+CREATE TABLE t153 (a INT);
+INSERT INTO t153 VALUES (153);
+CREATE TABLE t152 (a INT);
+INSERT INTO t152 VALUES (152);
+CREATE TABLE t151 (a INT);
+INSERT INTO t151 VALUES (151);
+CREATE TABLE t150 (a INT);
+INSERT INTO t150 VALUES (150);
+CREATE TABLE t149 (a INT);
+INSERT INTO t149 VALUES (149);
+CREATE TABLE t148 (a INT);
+INSERT INTO t148 VALUES (148);
+CREATE TABLE t147 (a INT);
+INSERT INTO t147 VALUES (147);
+CREATE TABLE t146 (a INT);
+INSERT INTO t146 VALUES (146);
+CREATE TABLE t145 (a INT);
+INSERT INTO t145 VALUES (145);
+CREATE TABLE t144 (a INT);
+INSERT INTO t144 VALUES (144);
+CREATE TABLE t143 (a INT);
+INSERT INTO t143 VALUES (143);
+CREATE TABLE t142 (a INT);
+INSERT INTO t142 VALUES (142);
+CREATE TABLE t141 (a INT);
+INSERT INTO t141 VALUES (141);
+CREATE TABLE t140 (a INT);
+INSERT INTO t140 VALUES (140);
+CREATE TABLE t139 (a INT);
+INSERT INTO t139 VALUES (139);
+CREATE TABLE t138 (a INT);
+INSERT INTO t138 VALUES (138);
+CREATE TABLE t137 (a INT);
+INSERT INTO t137 VALUES (137);
+CREATE TABLE t136 (a INT);
+INSERT INTO t136 VALUES (136);
+CREATE TABLE t135 (a INT);
+INSERT INTO t135 VALUES (135);
+CREATE TABLE t134 (a INT);
+INSERT INTO t134 VALUES (134);
+CREATE TABLE t133 (a INT);
+INSERT INTO t133 VALUES (133);
+CREATE TABLE t132 (a INT);
+INSERT INTO t132 VALUES (132);
+CREATE TABLE t131 (a INT);
+INSERT INTO t131 VALUES (131);
+CREATE TABLE t130 (a INT);
+INSERT INTO t130 VALUES (130);
+CREATE TABLE t129 (a INT);
+INSERT INTO t129 VALUES (129);
+CREATE TABLE t128 (a INT);
+INSERT INTO t128 VALUES (128);
+CREATE TABLE t127 (a INT);
+INSERT INTO t127 VALUES (127);
+CREATE TABLE t126 (a INT);
+INSERT INTO t126 VALUES (126);
+CREATE TABLE t125 (a INT);
+INSERT INTO t125 VALUES (125);
+CREATE TABLE t124 (a INT);
+INSERT INTO t124 VALUES (124);
+CREATE TABLE t123 (a INT);
+INSERT INTO t123 VALUES (123);
+CREATE TABLE t122 (a INT);
+INSERT INTO t122 VALUES (122);
+CREATE TABLE t121 (a INT);
+INSERT INTO t121 VALUES (121);
+CREATE TABLE t120 (a INT);
+INSERT INTO t120 VALUES (120);
+CREATE TABLE t119 (a INT);
+INSERT INTO t119 VALUES (119);
+CREATE TABLE t118 (a INT);
+INSERT INTO t118 VALUES (118);
+CREATE TABLE t117 (a INT);
+INSERT INTO t117 VALUES (117);
+CREATE TABLE t116 (a INT);
+INSERT INTO t116 VALUES (116);
+CREATE TABLE t115 (a INT);
+INSERT INTO t115 VALUES (115);
+CREATE TABLE t114 (a INT);
+INSERT INTO t114 VALUES (114);
+CREATE TABLE t113 (a INT);
+INSERT INTO t113 VALUES (113);
+CREATE TABLE t112 (a INT);
+INSERT INTO t112 VALUES (112);
+CREATE TABLE t111 (a INT);
+INSERT INTO t111 VALUES (111);
+CREATE TABLE t110 (a INT);
+INSERT INTO t110 VALUES (110);
+CREATE TABLE t109 (a INT);
+INSERT INTO t109 VALUES (109);
+CREATE TABLE t108 (a INT);
+INSERT INTO t108 VALUES (108);
+CREATE TABLE t107 (a INT);
+INSERT INTO t107 VALUES (107);
+CREATE TABLE t106 (a INT);
+INSERT INTO t106 VALUES (106);
+CREATE TABLE t105 (a INT);
+INSERT INTO t105 VALUES (105);
+CREATE TABLE t104 (a INT);
+INSERT INTO t104 VALUES (104);
+CREATE TABLE t103 (a INT);
+INSERT INTO t103 VALUES (103);
+CREATE TABLE t102 (a INT);
+INSERT INTO t102 VALUES (102);
+CREATE TABLE t101 (a INT);
+INSERT INTO t101 VALUES (101);
+CREATE TABLE t100 (a INT);
+INSERT INTO t100 VALUES (100);
+CREATE TABLE t99 (a INT);
+INSERT INTO t99 VALUES (99);
+CREATE TABLE t98 (a INT);
+INSERT INTO t98 VALUES (98);
+CREATE TABLE t97 (a INT);
+INSERT INTO t97 VALUES (97);
+CREATE TABLE t96 (a INT);
+INSERT INTO t96 VALUES (96);
+CREATE TABLE t95 (a INT);
+INSERT INTO t95 VALUES (95);
+CREATE TABLE t94 (a INT);
+INSERT INTO t94 VALUES (94);
+CREATE TABLE t93 (a INT);
+INSERT INTO t93 VALUES (93);
+CREATE TABLE t92 (a INT);
+INSERT INTO t92 VALUES (92);
+CREATE TABLE t91 (a INT);
+INSERT INTO t91 VALUES (91);
+CREATE TABLE t90 (a INT);
+INSERT INTO t90 VALUES (90);
+CREATE TABLE t89 (a INT);
+INSERT INTO t89 VALUES (89);
+CREATE TABLE t88 (a INT);
+INSERT INTO t88 VALUES (88);
+CREATE TABLE t87 (a INT);
+INSERT INTO t87 VALUES (87);
+CREATE TABLE t86 (a INT);
+INSERT INTO t86 VALUES (86);
+CREATE TABLE t85 (a INT);
+INSERT INTO t85 VALUES (85);
+CREATE TABLE t84 (a INT);
+INSERT INTO t84 VALUES (84);
+CREATE TABLE t83 (a INT);
+INSERT INTO t83 VALUES (83);
+CREATE TABLE t82 (a INT);
+INSERT INTO t82 VALUES (82);
+CREATE TABLE t81 (a INT);
+INSERT INTO t81 VALUES (81);
+CREATE TABLE t80 (a INT);
+INSERT INTO t80 VALUES (80);
+CREATE TABLE t79 (a INT);
+INSERT INTO t79 VALUES (79);
+CREATE TABLE t78 (a INT);
+INSERT INTO t78 VALUES (78);
+CREATE TABLE t77 (a INT);
+INSERT INTO t77 VALUES (77);
+CREATE TABLE t76 (a INT);
+INSERT INTO t76 VALUES (76);
+CREATE TABLE t75 (a INT);
+INSERT INTO t75 VALUES (75);
+CREATE TABLE t74 (a INT);
+INSERT INTO t74 VALUES (74);
+CREATE TABLE t73 (a INT);
+INSERT INTO t73 VALUES (73);
+CREATE TABLE t72 (a INT);
+INSERT INTO t72 VALUES (72);
+CREATE TABLE t71 (a INT);
+INSERT INTO t71 VALUES (71);
+CREATE TABLE t70 (a INT);
+INSERT INTO t70 VALUES (70);
+CREATE TABLE t69 (a INT);
+INSERT INTO t69 VALUES (69);
+CREATE TABLE t68 (a INT);
+INSERT INTO t68 VALUES (68);
+CREATE TABLE t67 (a INT);
+INSERT INTO t67 VALUES (67);
+CREATE TABLE t66 (a INT);
+INSERT INTO t66 VALUES (66);
+CREATE TABLE t65 (a INT);
+INSERT INTO t65 VALUES (65);
+CREATE TABLE t64 (a INT);
+INSERT INTO t64 VALUES (64);
+CREATE TABLE t63 (a INT);
+INSERT INTO t63 VALUES (63);
+CREATE TABLE t62 (a INT);
+INSERT INTO t62 VALUES (62);
+CREATE TABLE t61 (a INT);
+INSERT INTO t61 VALUES (61);
+CREATE TABLE t60 (a INT);
+INSERT INTO t60 VALUES (60);
+CREATE TABLE t59 (a INT);
+INSERT INTO t59 VALUES (59);
+CREATE TABLE t58 (a INT);
+INSERT INTO t58 VALUES (58);
+CREATE TABLE t57 (a INT);
+INSERT INTO t57 VALUES (57);
+CREATE TABLE t56 (a INT);
+INSERT INTO t56 VALUES (56);
+CREATE TABLE t55 (a INT);
+INSERT INTO t55 VALUES (55);
+CREATE TABLE t54 (a INT);
+INSERT INTO t54 VALUES (54);
+CREATE TABLE t53 (a INT);
+INSERT INTO t53 VALUES (53);
+CREATE TABLE t52 (a INT);
+INSERT INTO t52 VALUES (52);
+CREATE TABLE t51 (a INT);
+INSERT INTO t51 VALUES (51);
+CREATE TABLE t50 (a INT);
+INSERT INTO t50 VALUES (50);
+CREATE TABLE t49 (a INT);
+INSERT INTO t49 VALUES (49);
+CREATE TABLE t48 (a INT);
+INSERT INTO t48 VALUES (48);
+CREATE TABLE t47 (a INT);
+INSERT INTO t47 VALUES (47);
+CREATE TABLE t46 (a INT);
+INSERT INTO t46 VALUES (46);
+CREATE TABLE t45 (a INT);
+INSERT INTO t45 VALUES (45);
+CREATE TABLE t44 (a INT);
+INSERT INTO t44 VALUES (44);
+CREATE TABLE t43 (a INT);
+INSERT INTO t43 VALUES (43);
+CREATE TABLE t42 (a INT);
+INSERT INTO t42 VALUES (42);
+CREATE TABLE t41 (a INT);
+INSERT INTO t41 VALUES (41);
+CREATE TABLE t40 (a INT);
+INSERT INTO t40 VALUES (40);
+CREATE TABLE t39 (a INT);
+INSERT INTO t39 VALUES (39);
+CREATE TABLE t38 (a INT);
+INSERT INTO t38 VALUES (38);
+CREATE TABLE t37 (a INT);
+INSERT INTO t37 VALUES (37);
+CREATE TABLE t36 (a INT);
+INSERT INTO t36 VALUES (36);
+CREATE TABLE t35 (a INT);
+INSERT INTO t35 VALUES (35);
+CREATE TABLE t34 (a INT);
+INSERT INTO t34 VALUES (34);
+CREATE TABLE t33 (a INT);
+INSERT INTO t33 VALUES (33);
+CREATE TABLE t32 (a INT);
+INSERT INTO t32 VALUES (32);
+CREATE TABLE t31 (a INT);
+INSERT INTO t31 VALUES (31);
+CREATE TABLE t30 (a INT);
+INSERT INTO t30 VALUES (30);
+CREATE TABLE t29 (a INT);
+INSERT INTO t29 VALUES (29);
+CREATE TABLE t28 (a INT);
+INSERT INTO t28 VALUES (28);
+CREATE TABLE t27 (a INT);
+INSERT INTO t27 VALUES (27);
+CREATE TABLE t26 (a INT);
+INSERT INTO t26 VALUES (26);
+CREATE TABLE t25 (a INT);
+INSERT INTO t25 VALUES (25);
+CREATE TABLE t24 (a INT);
+INSERT INTO t24 VALUES (24);
+CREATE TABLE t23 (a INT);
+INSERT INTO t23 VALUES (23);
+CREATE TABLE t22 (a INT);
+INSERT INTO t22 VALUES (22);
+CREATE TABLE t21 (a INT);
+INSERT INTO t21 VALUES (21);
+CREATE TABLE t20 (a INT);
+INSERT INTO t20 VALUES (20);
+CREATE TABLE t19 (a INT);
+INSERT INTO t19 VALUES (19);
+CREATE TABLE t18 (a INT);
+INSERT INTO t18 VALUES (18);
+CREATE TABLE t17 (a INT);
+INSERT INTO t17 VALUES (17);
+CREATE TABLE t16 (a INT);
+INSERT INTO t16 VALUES (16);
+CREATE TABLE t15 (a INT);
+INSERT INTO t15 VALUES (15);
+CREATE TABLE t14 (a INT);
+INSERT INTO t14 VALUES (14);
+CREATE TABLE t13 (a INT);
+INSERT INTO t13 VALUES (13);
+CREATE TABLE t12 (a INT);
+INSERT INTO t12 VALUES (12);
+CREATE TABLE t11 (a INT);
+INSERT INTO t11 VALUES (11);
+CREATE TABLE t10 (a INT);
+INSERT INTO t10 VALUES (10);
+CREATE TABLE t9 (a INT);
+INSERT INTO t9 VALUES (9);
+CREATE TABLE t8 (a INT);
+INSERT INTO t8 VALUES (8);
+CREATE TABLE t7 (a INT);
+INSERT INTO t7 VALUES (7);
+CREATE TABLE t6 (a INT);
+INSERT INTO t6 VALUES (6);
+CREATE TABLE t5 (a INT);
+INSERT INTO t5 VALUES (5);
+CREATE TABLE t4 (a INT);
+INSERT INTO t4 VALUES (4);
+CREATE TABLE t3 (a INT);
+INSERT INTO t3 VALUES (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (2);
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+CREATE TABLE t0 (a INT) ENGINE=MERGE UNION(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40,t41,t42,t43,t44,t45,t46,t47,t48,t49,t50,t51,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79,t80,t81,t82,t83,t84,t85,t86,t87,t88,t89,t90,t91,t92,t93,t94,t95,t96,t97,t98,t99,t100,t101,t102,t103,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t114,t115,t116,t117,t118,t119,t120,t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t137,t138,t139,t140,t141,t142,t143,t144,t145,t146,t147,t148,t149,t150,t151,t152,t153,t154,t155,t156,t157,t158,t159,t160,t161,t162,t163,t164,t165,t166,t167,t168,t169,t170,t171,t172,t173,t174,t175,t176,t177,t178,t179,t180,t181,t182,t183,t184,t185,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t196,t197,t198,t199,t200,t201,t202,t203,t204,t205,t206,t207,t208,t209,t210,t211,t212,t213,t214,t215,t216,t217,t218,t219,t220,t221,t222,t223,t224,t225,t226,t227,t228,t229,t230,t231,t232,t233,t234,t235,t236,t237,t238,t239,t240,t241,t242,t243,t244,t245,t246,t247,t248,t249,t250,t251,t252,t253,t254,t255);
+SET GLOBAL query_cache_size = 1048576;
+FLUSH STATUS;
+SELECT a FROM t0 WHERE a = 1;
+a
+1
+SHOW STATUS LIKE "Qcache_queries_in_cache";
+Variable_name	Value
+Qcache_queries_in_cache	1
+FLUSH TABLES;
+TRUNCATE TABLE t255;
+SELECT a FROM t1;
+a
+1
+TRUNCATE TABLE t254;
+SELECT a FROM t2;
+a
+2
+TRUNCATE TABLE t253;
+SELECT a FROM t3;
+a
+3
+TRUNCATE TABLE t252;
+SELECT a FROM t4;
+a
+4
+TRUNCATE TABLE t251;
+SELECT a FROM t5;
+a
+5
+TRUNCATE TABLE t250;
+SELECT a FROM t6;
+a
+6
+TRUNCATE TABLE t249;
+SELECT a FROM t7;
+a
+7
+TRUNCATE TABLE t248;
+SELECT a FROM t8;
+a
+8
+TRUNCATE TABLE t247;
+SELECT a FROM t9;
+a
+9
+TRUNCATE TABLE t246;
+SELECT a FROM t10;
+a
+10
+TRUNCATE TABLE t245;
+SELECT a FROM t11;
+a
+11
+TRUNCATE TABLE t244;
+SELECT a FROM t12;
+a
+12
+TRUNCATE TABLE t243;
+SELECT a FROM t13;
+a
+13
+TRUNCATE TABLE t242;
+SELECT a FROM t14;
+a
+14
+TRUNCATE TABLE t241;
+SELECT a FROM t15;
+a
+15
+TRUNCATE TABLE t240;
+SELECT a FROM t16;
+a
+16
+TRUNCATE TABLE t239;
+SELECT a FROM t17;
+a
+17
+TRUNCATE TABLE t238;
+SELECT a FROM t18;
+a
+18
+TRUNCATE TABLE t237;
+SELECT a FROM t19;
+a
+19
+TRUNCATE TABLE t236;
+SELECT a FROM t20;
+a
+20
+TRUNCATE TABLE t235;
+SELECT a FROM t21;
+a
+21
+TRUNCATE TABLE t234;
+SELECT a FROM t22;
+a
+22
+TRUNCATE TABLE t233;
+SELECT a FROM t23;
+a
+23
+TRUNCATE TABLE t232;
+SELECT a FROM t24;
+a
+24
+TRUNCATE TABLE t231;
+SELECT a FROM t25;
+a
+25
+TRUNCATE TABLE t230;
+SELECT a FROM t26;
+a
+26
+TRUNCATE TABLE t229;
+SELECT a FROM t27;
+a
+27
+TRUNCATE TABLE t228;
+SELECT a FROM t28;
+a
+28
+TRUNCATE TABLE t227;
+SELECT a FROM t29;
+a
+29
+TRUNCATE TABLE t226;
+SELECT a FROM t30;
+a
+30
+TRUNCATE TABLE t225;
+SELECT a FROM t31;
+a
+31
+TRUNCATE TABLE t224;
+SELECT a FROM t32;
+a
+32
+TRUNCATE TABLE t223;
+SELECT a FROM t33;
+a
+33
+TRUNCATE TABLE t222;
+SELECT a FROM t34;
+a
+34
+TRUNCATE TABLE t221;
+SELECT a FROM t35;
+a
+35
+TRUNCATE TABLE t220;
+SELECT a FROM t36;
+a
+36
+TRUNCATE TABLE t219;
+SELECT a FROM t37;
+a
+37
+TRUNCATE TABLE t218;
+SELECT a FROM t38;
+a
+38
+TRUNCATE TABLE t217;
+SELECT a FROM t39;
+a
+39
+TRUNCATE TABLE t216;
+SELECT a FROM t40;
+a
+40
+TRUNCATE TABLE t215;
+SELECT a FROM t41;
+a
+41
+TRUNCATE TABLE t214;
+SELECT a FROM t42;
+a
+42
+TRUNCATE TABLE t213;
+SELECT a FROM t43;
+a
+43
+TRUNCATE TABLE t212;
+SELECT a FROM t44;
+a
+44
+TRUNCATE TABLE t211;
+SELECT a FROM t45;
+a
+45
+TRUNCATE TABLE t210;
+SELECT a FROM t46;
+a
+46
+TRUNCATE TABLE t209;
+SELECT a FROM t47;
+a
+47
+TRUNCATE TABLE t208;
+SELECT a FROM t48;
+a
+48
+TRUNCATE TABLE t207;
+SELECT a FROM t49;
+a
+49
+TRUNCATE TABLE t206;
+SELECT a FROM t50;
+a
+50
+TRUNCATE TABLE t205;
+SELECT a FROM t51;
+a
+51
+TRUNCATE TABLE t204;
+SELECT a FROM t52;
+a
+52
+TRUNCATE TABLE t203;
+SELECT a FROM t53;
+a
+53
+TRUNCATE TABLE t202;
+SELECT a FROM t54;
+a
+54
+TRUNCATE TABLE t201;
+SELECT a FROM t55;
+a
+55
+TRUNCATE TABLE t200;
+SELECT a FROM t56;
+a
+56
+TRUNCATE TABLE t199;
+SELECT a FROM t57;
+a
+57
+TRUNCATE TABLE t198;
+SELECT a FROM t58;
+a
+58
+TRUNCATE TABLE t197;
+SELECT a FROM t59;
+a
+59
+TRUNCATE TABLE t196;
+SELECT a FROM t60;
+a
+60
+TRUNCATE TABLE t195;
+SELECT a FROM t61;
+a
+61
+TRUNCATE TABLE t194;
+SELECT a FROM t62;
+a
+62
+TRUNCATE TABLE t193;
+SELECT a FROM t63;
+a
+63
+TRUNCATE TABLE t192;
+SELECT a FROM t64;
+a
+64
+TRUNCATE TABLE t191;
+SELECT a FROM t65;
+a
+65
+TRUNCATE TABLE t190;
+SELECT a FROM t66;
+a
+66
+TRUNCATE TABLE t189;
+SELECT a FROM t67;
+a
+67
+TRUNCATE TABLE t188;
+SELECT a FROM t68;
+a
+68
+TRUNCATE TABLE t187;
+SELECT a FROM t69;
+a
+69
+TRUNCATE TABLE t186;
+SELECT a FROM t70;
+a
+70
+TRUNCATE TABLE t185;
+SELECT a FROM t71;
+a
+71
+TRUNCATE TABLE t184;
+SELECT a FROM t72;
+a
+72
+TRUNCATE TABLE t183;
+SELECT a FROM t73;
+a
+73
+TRUNCATE TABLE t182;
+SELECT a FROM t74;
+a
+74
+TRUNCATE TABLE t181;
+SELECT a FROM t75;
+a
+75
+TRUNCATE TABLE t180;
+SELECT a FROM t76;
+a
+76
+TRUNCATE TABLE t179;
+SELECT a FROM t77;
+a
+77
+TRUNCATE TABLE t178;
+SELECT a FROM t78;
+a
+78
+TRUNCATE TABLE t177;
+SELECT a FROM t79;
+a
+79
+TRUNCATE TABLE t176;
+SELECT a FROM t80;
+a
+80
+TRUNCATE TABLE t175;
+SELECT a FROM t81;
+a
+81
+TRUNCATE TABLE t174;
+SELECT a FROM t82;
+a
+82
+TRUNCATE TABLE t173;
+SELECT a FROM t83;
+a
+83
+TRUNCATE TABLE t172;
+SELECT a FROM t84;
+a
+84
+TRUNCATE TABLE t171;
+SELECT a FROM t85;
+a
+85
+TRUNCATE TABLE t170;
+SELECT a FROM t86;
+a
+86
+TRUNCATE TABLE t169;
+SELECT a FROM t87;
+a
+87
+TRUNCATE TABLE t168;
+SELECT a FROM t88;
+a
+88
+TRUNCATE TABLE t167;
+SELECT a FROM t89;
+a
+89
+TRUNCATE TABLE t166;
+SELECT a FROM t90;
+a
+90
+TRUNCATE TABLE t165;
+SELECT a FROM t91;
+a
+91
+TRUNCATE TABLE t164;
+SELECT a FROM t92;
+a
+92
+TRUNCATE TABLE t163;
+SELECT a FROM t93;
+a
+93
+TRUNCATE TABLE t162;
+SELECT a FROM t94;
+a
+94
+TRUNCATE TABLE t161;
+SELECT a FROM t95;
+a
+95
+TRUNCATE TABLE t160;
+SELECT a FROM t96;
+a
+96
+TRUNCATE TABLE t159;
+SELECT a FROM t97;
+a
+97
+TRUNCATE TABLE t158;
+SELECT a FROM t98;
+a
+98
+TRUNCATE TABLE t157;
+SELECT a FROM t99;
+a
+99
+TRUNCATE TABLE t156;
+SELECT a FROM t100;
+a
+100
+TRUNCATE TABLE t155;
+SELECT a FROM t101;
+a
+101
+TRUNCATE TABLE t154;
+SELECT a FROM t102;
+a
+102
+TRUNCATE TABLE t153;
+SELECT a FROM t103;
+a
+103
+TRUNCATE TABLE t152;
+SELECT a FROM t104;
+a
+104
+TRUNCATE TABLE t151;
+SELECT a FROM t105;
+a
+105
+TRUNCATE TABLE t150;
+SELECT a FROM t106;
+a
+106
+TRUNCATE TABLE t149;
+SELECT a FROM t107;
+a
+107
+TRUNCATE TABLE t148;
+SELECT a FROM t108;
+a
+108
+TRUNCATE TABLE t147;
+SELECT a FROM t109;
+a
+109
+TRUNCATE TABLE t146;
+SELECT a FROM t110;
+a
+110
+TRUNCATE TABLE t145;
+SELECT a FROM t111;
+a
+111
+TRUNCATE TABLE t144;
+SELECT a FROM t112;
+a
+112
+TRUNCATE TABLE t143;
+SELECT a FROM t113;
+a
+113
+TRUNCATE TABLE t142;
+SELECT a FROM t114;
+a
+114
+TRUNCATE TABLE t141;
+SELECT a FROM t115;
+a
+115
+TRUNCATE TABLE t140;
+SELECT a FROM t116;
+a
+116
+TRUNCATE TABLE t139;
+SELECT a FROM t117;
+a
+117
+TRUNCATE TABLE t138;
+SELECT a FROM t118;
+a
+118
+TRUNCATE TABLE t137;
+SELECT a FROM t119;
+a
+119
+TRUNCATE TABLE t136;
+SELECT a FROM t120;
+a
+120
+TRUNCATE TABLE t135;
+SELECT a FROM t121;
+a
+121
+TRUNCATE TABLE t134;
+SELECT a FROM t122;
+a
+122
+TRUNCATE TABLE t133;
+SELECT a FROM t123;
+a
+123
+TRUNCATE TABLE t132;
+SELECT a FROM t124;
+a
+124
+TRUNCATE TABLE t131;
+SELECT a FROM t125;
+a
+125
+TRUNCATE TABLE t130;
+SELECT a FROM t126;
+a
+126
+TRUNCATE TABLE t129;
+SELECT a FROM t127;
+a
+127
+TRUNCATE TABLE t128;
+SELECT a FROM t128;
+a
+TRUNCATE TABLE t127;
+SELECT a FROM t129;
+a
+TRUNCATE TABLE t126;
+SELECT a FROM t130;
+a
+TRUNCATE TABLE t125;
+SELECT a FROM t131;
+a
+TRUNCATE TABLE t124;
+SELECT a FROM t132;
+a
+TRUNCATE TABLE t123;
+SELECT a FROM t133;
+a
+TRUNCATE TABLE t122;
+SELECT a FROM t134;
+a
+TRUNCATE TABLE t121;
+SELECT a FROM t135;
+a
+TRUNCATE TABLE t120;
+SELECT a FROM t136;
+a
+TRUNCATE TABLE t119;
+SELECT a FROM t137;
+a
+TRUNCATE TABLE t118;
+SELECT a FROM t138;
+a
+TRUNCATE TABLE t117;
+SELECT a FROM t139;
+a
+TRUNCATE TABLE t116;
+SELECT a FROM t140;
+a
+TRUNCATE TABLE t115;
+SELECT a FROM t141;
+a
+TRUNCATE TABLE t114;
+SELECT a FROM t142;
+a
+TRUNCATE TABLE t113;
+SELECT a FROM t143;
+a
+TRUNCATE TABLE t112;
+SELECT a FROM t144;
+a
+TRUNCATE TABLE t111;
+SELECT a FROM t145;
+a
+TRUNCATE TABLE t110;
+SELECT a FROM t146;
+a
+TRUNCATE TABLE t109;
+SELECT a FROM t147;
+a
+TRUNCATE TABLE t108;
+SELECT a FROM t148;
+a
+TRUNCATE TABLE t107;
+SELECT a FROM t149;
+a
+TRUNCATE TABLE t106;
+SELECT a FROM t150;
+a
+TRUNCATE TABLE t105;
+SELECT a FROM t151;
+a
+TRUNCATE TABLE t104;
+SELECT a FROM t152;
+a
+TRUNCATE TABLE t103;
+SELECT a FROM t153;
+a
+TRUNCATE TABLE t102;
+SELECT a FROM t154;
+a
+TRUNCATE TABLE t101;
+SELECT a FROM t155;
+a
+TRUNCATE TABLE t100;
+SELECT a FROM t156;
+a
+TRUNCATE TABLE t99;
+SELECT a FROM t157;
+a
+TRUNCATE TABLE t98;
+SELECT a FROM t158;
+a
+TRUNCATE TABLE t97;
+SELECT a FROM t159;
+a
+TRUNCATE TABLE t96;
+SELECT a FROM t160;
+a
+TRUNCATE TABLE t95;
+SELECT a FROM t161;
+a
+TRUNCATE TABLE t94;
+SELECT a FROM t162;
+a
+TRUNCATE TABLE t93;
+SELECT a FROM t163;
+a
+TRUNCATE TABLE t92;
+SELECT a FROM t164;
+a
+TRUNCATE TABLE t91;
+SELECT a FROM t165;
+a
+TRUNCATE TABLE t90;
+SELECT a FROM t166;
+a
+TRUNCATE TABLE t89;
+SELECT a FROM t167;
+a
+TRUNCATE TABLE t88;
+SELECT a FROM t168;
+a
+TRUNCATE TABLE t87;
+SELECT a FROM t169;
+a
+TRUNCATE TABLE t86;
+SELECT a FROM t170;
+a
+TRUNCATE TABLE t85;
+SELECT a FROM t171;
+a
+TRUNCATE TABLE t84;
+SELECT a FROM t172;
+a
+TRUNCATE TABLE t83;
+SELECT a FROM t173;
+a
+TRUNCATE TABLE t82;
+SELECT a FROM t174;
+a
+TRUNCATE TABLE t81;
+SELECT a FROM t175;
+a
+TRUNCATE TABLE t80;
+SELECT a FROM t176;
+a
+TRUNCATE TABLE t79;
+SELECT a FROM t177;
+a
+TRUNCATE TABLE t78;
+SELECT a FROM t178;
+a
+TRUNCATE TABLE t77;
+SELECT a FROM t179;
+a
+TRUNCATE TABLE t76;
+SELECT a FROM t180;
+a
+TRUNCATE TABLE t75;
+SELECT a FROM t181;
+a
+TRUNCATE TABLE t74;
+SELECT a FROM t182;
+a
+TRUNCATE TABLE t73;
+SELECT a FROM t183;
+a
+TRUNCATE TABLE t72;
+SELECT a FROM t184;
+a
+TRUNCATE TABLE t71;
+SELECT a FROM t185;
+a
+TRUNCATE TABLE t70;
+SELECT a FROM t186;
+a
+TRUNCATE TABLE t69;
+SELECT a FROM t187;
+a
+TRUNCATE TABLE t68;
+SELECT a FROM t188;
+a
+TRUNCATE TABLE t67;
+SELECT a FROM t189;
+a
+TRUNCATE TABLE t66;
+SELECT a FROM t190;
+a
+TRUNCATE TABLE t65;
+SELECT a FROM t191;
+a
+TRUNCATE TABLE t64;
+SELECT a FROM t192;
+a
+TRUNCATE TABLE t63;
+SELECT a FROM t193;
+a
+TRUNCATE TABLE t62;
+SELECT a FROM t194;
+a
+TRUNCATE TABLE t61;
+SELECT a FROM t195;
+a
+TRUNCATE TABLE t60;
+SELECT a FROM t196;
+a
+TRUNCATE TABLE t59;
+SELECT a FROM t197;
+a
+TRUNCATE TABLE t58;
+SELECT a FROM t198;
+a
+TRUNCATE TABLE t57;
+SELECT a FROM t199;
+a
+TRUNCATE TABLE t56;
+SELECT a FROM t200;
+a
+TRUNCATE TABLE t55;
+SELECT a FROM t201;
+a
+TRUNCATE TABLE t54;
+SELECT a FROM t202;
+a
+TRUNCATE TABLE t53;
+SELECT a FROM t203;
+a
+TRUNCATE TABLE t52;
+SELECT a FROM t204;
+a
+TRUNCATE TABLE t51;
+SELECT a FROM t205;
+a
+TRUNCATE TABLE t50;
+SELECT a FROM t206;
+a
+TRUNCATE TABLE t49;
+SELECT a FROM t207;
+a
+TRUNCATE TABLE t48;
+SELECT a FROM t208;
+a
+TRUNCATE TABLE t47;
+SELECT a FROM t209;
+a
+TRUNCATE TABLE t46;
+SELECT a FROM t210;
+a
+TRUNCATE TABLE t45;
+SELECT a FROM t211;
+a
+TRUNCATE TABLE t44;
+SELECT a FROM t212;
+a
+TRUNCATE TABLE t43;
+SELECT a FROM t213;
+a
+TRUNCATE TABLE t42;
+SELECT a FROM t214;
+a
+TRUNCATE TABLE t41;
+SELECT a FROM t215;
+a
+TRUNCATE TABLE t40;
+SELECT a FROM t216;
+a
+TRUNCATE TABLE t39;
+SELECT a FROM t217;
+a
+TRUNCATE TABLE t38;
+SELECT a FROM t218;
+a
+TRUNCATE TABLE t37;
+SELECT a FROM t219;
+a
+TRUNCATE TABLE t36;
+SELECT a FROM t220;
+a
+TRUNCATE TABLE t35;
+SELECT a FROM t221;
+a
+TRUNCATE TABLE t34;
+SELECT a FROM t222;
+a
+TRUNCATE TABLE t33;
+SELECT a FROM t223;
+a
+TRUNCATE TABLE t32;
+SELECT a FROM t224;
+a
+TRUNCATE TABLE t31;
+SELECT a FROM t225;
+a
+TRUNCATE TABLE t30;
+SELECT a FROM t226;
+a
+TRUNCATE TABLE t29;
+SELECT a FROM t227;
+a
+TRUNCATE TABLE t28;
+SELECT a FROM t228;
+a
+TRUNCATE TABLE t27;
+SELECT a FROM t229;
+a
+TRUNCATE TABLE t26;
+SELECT a FROM t230;
+a
+TRUNCATE TABLE t25;
+SELECT a FROM t231;
+a
+TRUNCATE TABLE t24;
+SELECT a FROM t232;
+a
+TRUNCATE TABLE t23;
+SELECT a FROM t233;
+a
+TRUNCATE TABLE t22;
+SELECT a FROM t234;
+a
+TRUNCATE TABLE t21;
+SELECT a FROM t235;
+a
+TRUNCATE TABLE t20;
+SELECT a FROM t236;
+a
+TRUNCATE TABLE t19;
+SELECT a FROM t237;
+a
+TRUNCATE TABLE t18;
+SELECT a FROM t238;
+a
+TRUNCATE TABLE t17;
+SELECT a FROM t239;
+a
+TRUNCATE TABLE t16;
+SELECT a FROM t240;
+a
+TRUNCATE TABLE t15;
+SELECT a FROM t241;
+a
+TRUNCATE TABLE t14;
+SELECT a FROM t242;
+a
+TRUNCATE TABLE t13;
+SELECT a FROM t243;
+a
+TRUNCATE TABLE t12;
+SELECT a FROM t244;
+a
+TRUNCATE TABLE t11;
+SELECT a FROM t245;
+a
+TRUNCATE TABLE t10;
+SELECT a FROM t246;
+a
+TRUNCATE TABLE t9;
+SELECT a FROM t247;
+a
+TRUNCATE TABLE t8;
+SELECT a FROM t248;
+a
+TRUNCATE TABLE t7;
+SELECT a FROM t249;
+a
+TRUNCATE TABLE t6;
+SELECT a FROM t250;
+a
+TRUNCATE TABLE t5;
+SELECT a FROM t251;
+a
+TRUNCATE TABLE t4;
+SELECT a FROM t252;
+a
+TRUNCATE TABLE t3;
+SELECT a FROM t253;
+a
+TRUNCATE TABLE t2;
+SELECT a FROM t254;
+a
+TRUNCATE TABLE t1;
+SELECT a FROM t255;
+a
+SELECT a FROM t0;
+a
+DROP TABLE t0;
+DROP TABLE t255;
+DROP TABLE t254;
+DROP TABLE t253;
+DROP TABLE t252;
+DROP TABLE t251;
+DROP TABLE t250;
+DROP TABLE t249;
+DROP TABLE t248;
+DROP TABLE t247;
+DROP TABLE t246;
+DROP TABLE t245;
+DROP TABLE t244;
+DROP TABLE t243;
+DROP TABLE t242;
+DROP TABLE t241;
+DROP TABLE t240;
+DROP TABLE t239;
+DROP TABLE t238;
+DROP TABLE t237;
+DROP TABLE t236;
+DROP TABLE t235;
+DROP TABLE t234;
+DROP TABLE t233;
+DROP TABLE t232;
+DROP TABLE t231;
+DROP TABLE t230;
+DROP TABLE t229;
+DROP TABLE t228;
+DROP TABLE t227;
+DROP TABLE t226;
+DROP TABLE t225;
+DROP TABLE t224;
+DROP TABLE t223;
+DROP TABLE t222;
+DROP TABLE t221;
+DROP TABLE t220;
+DROP TABLE t219;
+DROP TABLE t218;
+DROP TABLE t217;
+DROP TABLE t216;
+DROP TABLE t215;
+DROP TABLE t214;
+DROP TABLE t213;
+DROP TABLE t212;
+DROP TABLE t211;
+DROP TABLE t210;
+DROP TABLE t209;
+DROP TABLE t208;
+DROP TABLE t207;
+DROP TABLE t206;
+DROP TABLE t205;
+DROP TABLE t204;
+DROP TABLE t203;
+DROP TABLE t202;
+DROP TABLE t201;
+DROP TABLE t200;
+DROP TABLE t199;
+DROP TABLE t198;
+DROP TABLE t197;
+DROP TABLE t196;
+DROP TABLE t195;
+DROP TABLE t194;
+DROP TABLE t193;
+DROP TABLE t192;
+DROP TABLE t191;
+DROP TABLE t190;
+DROP TABLE t189;
+DROP TABLE t188;
+DROP TABLE t187;
+DROP TABLE t186;
+DROP TABLE t185;
+DROP TABLE t184;
+DROP TABLE t183;
+DROP TABLE t182;
+DROP TABLE t181;
+DROP TABLE t180;
+DROP TABLE t179;
+DROP TABLE t178;
+DROP TABLE t177;
+DROP TABLE t176;
+DROP TABLE t175;
+DROP TABLE t174;
+DROP TABLE t173;
+DROP TABLE t172;
+DROP TABLE t171;
+DROP TABLE t170;
+DROP TABLE t169;
+DROP TABLE t168;
+DROP TABLE t167;
+DROP TABLE t166;
+DROP TABLE t165;
+DROP TABLE t164;
+DROP TABLE t163;
+DROP TABLE t162;
+DROP TABLE t161;
+DROP TABLE t160;
+DROP TABLE t159;
+DROP TABLE t158;
+DROP TABLE t157;
+DROP TABLE t156;
+DROP TABLE t155;
+DROP TABLE t154;
+DROP TABLE t153;
+DROP TABLE t152;
+DROP TABLE t151;
+DROP TABLE t150;
+DROP TABLE t149;
+DROP TABLE t148;
+DROP TABLE t147;
+DROP TABLE t146;
+DROP TABLE t145;
+DROP TABLE t144;
+DROP TABLE t143;
+DROP TABLE t142;
+DROP TABLE t141;
+DROP TABLE t140;
+DROP TABLE t139;
+DROP TABLE t138;
+DROP TABLE t137;
+DROP TABLE t136;
+DROP TABLE t135;
+DROP TABLE t134;
+DROP TABLE t133;
+DROP TABLE t132;
+DROP TABLE t131;
+DROP TABLE t130;
+DROP TABLE t129;
+DROP TABLE t128;
+DROP TABLE t127;
+DROP TABLE t126;
+DROP TABLE t125;
+DROP TABLE t124;
+DROP TABLE t123;
+DROP TABLE t122;
+DROP TABLE t121;
+DROP TABLE t120;
+DROP TABLE t119;
+DROP TABLE t118;
+DROP TABLE t117;
+DROP TABLE t116;
+DROP TABLE t115;
+DROP TABLE t114;
+DROP TABLE t113;
+DROP TABLE t112;
+DROP TABLE t111;
+DROP TABLE t110;
+DROP TABLE t109;
+DROP TABLE t108;
+DROP TABLE t107;
+DROP TABLE t106;
+DROP TABLE t105;
+DROP TABLE t104;
+DROP TABLE t103;
+DROP TABLE t102;
+DROP TABLE t101;
+DROP TABLE t100;
+DROP TABLE t99;
+DROP TABLE t98;
+DROP TABLE t97;
+DROP TABLE t96;
+DROP TABLE t95;
+DROP TABLE t94;
+DROP TABLE t93;
+DROP TABLE t92;
+DROP TABLE t91;
+DROP TABLE t90;
+DROP TABLE t89;
+DROP TABLE t88;
+DROP TABLE t87;
+DROP TABLE t86;
+DROP TABLE t85;
+DROP TABLE t84;
+DROP TABLE t83;
+DROP TABLE t82;
+DROP TABLE t81;
+DROP TABLE t80;
+DROP TABLE t79;
+DROP TABLE t78;
+DROP TABLE t77;
+DROP TABLE t76;
+DROP TABLE t75;
+DROP TABLE t74;
+DROP TABLE t73;
+DROP TABLE t72;
+DROP TABLE t71;
+DROP TABLE t70;
+DROP TABLE t69;
+DROP TABLE t68;
+DROP TABLE t67;
+DROP TABLE t66;
+DROP TABLE t65;
+DROP TABLE t64;
+DROP TABLE t63;
+DROP TABLE t62;
+DROP TABLE t61;
+DROP TABLE t60;
+DROP TABLE t59;
+DROP TABLE t58;
+DROP TABLE t57;
+DROP TABLE t56;
+DROP TABLE t55;
+DROP TABLE t54;
+DROP TABLE t53;
+DROP TABLE t52;
+DROP TABLE t51;
+DROP TABLE t50;
+DROP TABLE t49;
+DROP TABLE t48;
+DROP TABLE t47;
+DROP TABLE t46;
+DROP TABLE t45;
+DROP TABLE t44;
+DROP TABLE t43;
+DROP TABLE t42;
+DROP TABLE t41;
+DROP TABLE t40;
+DROP TABLE t39;
+DROP TABLE t38;
+DROP TABLE t37;
+DROP TABLE t36;
+DROP TABLE t35;
+DROP TABLE t34;
+DROP TABLE t33;
+DROP TABLE t32;
+DROP TABLE t31;
+DROP TABLE t30;
+DROP TABLE t29;
+DROP TABLE t28;
+DROP TABLE t27;
+DROP TABLE t26;
+DROP TABLE t25;
+DROP TABLE t24;
+DROP TABLE t23;
+DROP TABLE t22;
+DROP TABLE t21;
+DROP TABLE t20;
+DROP TABLE t19;
+DROP TABLE t18;
+DROP TABLE t17;
+DROP TABLE t16;
+DROP TABLE t15;
+DROP TABLE t14;
+DROP TABLE t13;
+DROP TABLE t12;
+DROP TABLE t11;
+DROP TABLE t10;
+DROP TABLE t9;
+DROP TABLE t8;
+DROP TABLE t7;
+DROP TABLE t6;
+DROP TABLE t5;
+DROP TABLE t4;
+DROP TABLE t3;
+DROP TABLE t2;
+DROP TABLE t1;
+SET @@global.query_cache_size = 0;
+End of 5.1 tests

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2007-09-20 08:54:46 +0000
+++ b/mysql-test/r/show_check.result	2008-08-15 20:13:27 +0000
@@ -12,51 +12,51 @@
 -- after Bug#29394 is implemented.
 check table t1 fast;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	27	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	27	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	Table is already up to date
 check table t1 fast;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	27	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	27	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	Table is already up to date
 check table t1 changed;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 insert into t1 values (5,5,5);
 check table t1 changed;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 check table t1 medium;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 check table t1 extended;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	5	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	5	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 show index from t1;
@@ -84,10 +84,10 @@
 -- after Bug#29394 is implemented.
 optimize table t1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	8	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	8	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	optimize	status	OK
 optimize table t1;
@@ -154,10 +154,10 @@
 -- after Bug#29394 is implemented.
 analyze table t1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	7	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	7	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	analyze	status	OK
 show index from t1;
@@ -171,10 +171,10 @@
 -- after Bug#29394 is implemented.
 repair table t1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	42	7	Y	0	31	8
-def					Op	253	3	6	Y	0	31	8
-def					Msg_type	253	3	6	Y	0	31	8
-def					Msg_text	253	85	2	Y	0	31	8
+def					Table	253	128	7	Y	0	31	8
+def					Op	253	10	6	Y	0	31	8
+def					Msg_type	253	10	6	Y	0	31	8
+def					Msg_text	253	255	2	Y	0	31	8
 Table	Op	Msg_type	Msg_text
 test.t1	repair	status	OK
 show index from t1;
@@ -788,8 +788,8 @@
 ----------------------------------------------------------------
 SHOW CREATE DATABASE mysqltest1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Database	253	63	10	N	1	31	33
-def					Create Database	253	1023	69	N	1	31	33
+def					Database	253	192	10	N	1	31	33
+def					Create Database	253	3072	69	N	1	31	33
 Database	Create Database
 mysqltest1	CREATE DATABASE `mysqltest1` /*!40100 DEFAULT CHARACTER SET latin1 */
 ----------------------------------------------------------------
@@ -801,8 +801,8 @@
 ----------------------------------------------------------------
 SHOW CREATE TABLE t1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Table	253	63	2	N	1	31	33
-def					Create Table	253	1023	103	N	1	31	33
+def					Table	253	192	2	N	1	31	33
+def					Create Table	253	3072	103	N	1	31	33
 Table	Create Table
 t1	CREATE TABLE `t1` (
   `c` int(11) NOT NULL,
@@ -959,8 +959,8 @@
 ----------------------------------------------------------------
 SHOW CREATE VIEW v1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					View	253	63	2	N	1	31	33
-def					Create View	253	1023	103	N	1	31	33
+def					View	253	192	2	N	1	31	33
+def					Create View	253	3072	103	N	1	31	33
 View	Create View
 v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1`
 ----------------------------------------------------------------
@@ -981,9 +981,9 @@
 ----------------------------------------------------------------
 SHOW CREATE PROCEDURE p1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Procedure	253	63	2	N	1	31	33
+def					Procedure	253	192	2	N	1	31	33
 def					sql_mode	253	0	0	N	1	31	33
-def					Create Procedure	253	2046	59	Y	0	31	33
+def					Create Procedure	253	6144	59	Y	0	31	33
 Procedure	sql_mode	Create Procedure
 p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
 SELECT 1
@@ -1033,9 +1033,9 @@
 ----------------------------------------------------------------
 SHOW CREATE FUNCTION f1;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					Function	253	63	2	N	1	31	33
+def					Function	253	192	2	N	1	31	33
 def					sql_mode	253	0	0	N	1	31	33
-def					Create Function	253	2046	74	Y	0	31	33
+def					Create Function	253	6144	74	Y	0	31	33
 Function	sql_mode	Create Function
 f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
 RETURN 1
@@ -1141,4 +1141,34 @@
 show variables like 'myisam_recover_options';
 Variable_name	Value
 myisam_recover_options	OFF
+CREATE TABLE t1 (
+Codigo int(10) unsigned NOT NULL auto_increment,
+Nombre varchar(255) default NULL,
+Telefono varchar(255) default NULL,
+Observaciones longtext,
+Direccion varchar(255) default NULL,
+Dni varchar(255) default NULL,
+CP int(11) default NULL,
+Provincia varchar(255) default NULL,
+Poblacion varchar(255) default NULL,
+PRIMARY KEY  (Codigo)
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
+show create table t1;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					Table	253	64	2	N	1	31	7
+def					Create Table	253	1024	446	N	1	31	7
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `Codigo` int(10) unsigned NOT NULL auto_increment,
+  `Nombre` varchar(255) default NULL,
+  `Telefono` varchar(255) default NULL,
+  `Observaciones` longtext,
+  `Direccion` varchar(255) default NULL,
+  `Dni` varchar(255) default NULL,
+  `CP` int(11) default NULL,
+  `Provincia` varchar(255) default NULL,
+  `Poblacion` varchar(255) default NULL,
+  PRIMARY KEY  (`Codigo`)
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
+drop table t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/sp.result'
--- a/mysql-test/r/sp.result	2008-02-17 11:37:39 +0000
+++ b/mysql-test/r/sp.result	2008-08-20 09:49:28 +0000
@@ -6646,6 +6646,22 @@
 2
 drop function func30787;
 drop table t1;
+create table t1(c1 INT);
+create function f1(p1 int) returns varchar(32)
+return 'aaa';
+create view v1 as select f1(c1) as parent_control_name from t1;
+create procedure p1()
+begin
+select parent_control_name as c1 from v1;
+end //
+call p1();
+c1
+call p1();
+c1
+drop procedure p1;
+drop function f1;
+drop view v1;
+drop table t1;
 # ------------------------------------------------------------------
 # -- End of 5.0 tests
 # ------------------------------------------------------------------

=== modified file 'mysql-test/r/subselect.result'
--- a/mysql-test/r/subselect.result	2008-05-16 14:05:55 +0000
+++ b/mysql-test/r/subselect.result	2008-07-26 20:44:07 +0000
@@ -4396,4 +4396,15 @@
 Warnings:
 Note	1003	select 1 AS `1` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 AS `1` from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a` having (<cache>(1) = <ref_null_helper>(1))))
 DROP TABLE t1;
+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.0 tests.

=== modified file 'mysql-test/r/symlink.result'
--- a/mysql-test/r/symlink.result	2008-03-03 11:02:34 +0000
+++ b/mysql-test/r/symlink.result	2008-08-26 09:21:07 +0000
@@ -57,8 +57,6 @@
 Got one of the listed errors
 Got one of the listed errors
 Got one of the listed errors
-Got one of the listed errors
-Got one of the listed errors
 alter table t9 rename mysqltest.t9;
 select count(*) from mysqltest.t9;
 count(*)

=== modified file 'mysql-test/r/type_bit.result'
--- a/mysql-test/r/type_bit.result	2007-12-02 00:48:43 +0000
+++ b/mysql-test/r/type_bit.result	2008-08-27 21:10:37 +0000
@@ -684,4 +684,28 @@
 1
 1
 DROP TABLE t1;
+CREATE TABLE t1 (b BIT NOT NULL, i2 INTEGER NOT NULL, s VARCHAR(255) NOT NULL);
+INSERT INTO t1 VALUES(0x01,100,''), (0x00,300,''), (0x01,200,''), (0x00,100,'');
+SELECT HEX(b), i2 FROM t1 WHERE (i2>=100 AND i2<201) AND b=TRUE;
+HEX(b)	i2
+1	100
+1	200
+CREATE TABLE t2 (b1 BIT NOT NULL, b2 BIT NOT NULL, i2 INTEGER NOT NULL,
+s VARCHAR(255) NOT NULL);
+INSERT INTO t2 VALUES (0x01,0x00,100,''), (0x00,0x01,300,''),
+(0x01,0x00,200,''), (0x00,0x01,100,'');
+SELECT HEX(b1), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b1=TRUE;
+HEX(b1)	i2
+1	100
+1	200
+SELECT HEX(b2), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b2=FALSE;
+HEX(b2)	i2
+0	100
+0	200
+SELECT HEX(b1), HEX(b2), i2 FROM t2
+WHERE (i2>=100 AND i2<201) AND b1=TRUE AND b2=FALSE;
+HEX(b1)	HEX(b2)	i2
+1	0	100
+1	0	200
+DROP TABLE t1, t2;
 End of 5.0 tests

=== modified file 'mysql-test/r/type_newdecimal.result'
--- a/mysql-test/r/type_newdecimal.result	2007-11-17 18:05:31 +0000
+++ b/mysql-test/r/type_newdecimal.result	2008-08-15 19:46:21 +0000
@@ -1519,4 +1519,9 @@
 f1
 99999999999999999999999999999.999999999999999999999999999999
 DROP TABLE t1;
+select (1.20396873 * 0.89550000 * 0.68000000 * 1.08721696 * 0.99500000 *
+1.01500000 * 1.01500000 * 0.99500000);
+(1.20396873 * 0.89550000 * 0.68000000 * 1.08721696 * 0.99500000 *
+1.01500000 * 1.01500000 * 0.99500000)
+0.812988073953673124592306939480
 End of 5.0 tests

=== modified file 'mysql-test/r/udf.result'
--- a/mysql-test/r/udf.result	2007-11-27 15:16:52 +0000
+++ b/mysql-test/r/udf.result	2008-08-25 12:11:59 +0000
@@ -1,5 +1,7 @@
 drop table if exists t1;
 CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
+Warnings:
+Warning	1105	plugin_dir was not specified
 CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
 CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 ERROR HY000: Can't find function 'myfunc_nonexist' in library
@@ -197,6 +199,8 @@
 select * from mysql.func;
 name	ret	dl	type
 CREATE FUNCTION is_const RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
+Warnings:
+Warning	1105	plugin_dir was not specified
 select IS_const(3);
 IS_const(3)
 const
@@ -206,6 +210,8 @@
 select is_const(3);
 ERROR 42000: FUNCTION test.is_const does not exist
 CREATE FUNCTION is_const RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
+Warnings:
+Warning	1105	plugin_dir was not specified
 select
 is_const(3) as const,
 is_const(3.14) as const,

=== modified file 'mysql-test/r/varbinary.result'
--- a/mysql-test/r/varbinary.result	2007-03-09 21:29:02 +0000
+++ b/mysql-test/r/varbinary.result	2008-06-27 15:56:41 +0000
@@ -78,3 +78,34 @@
 select length(a) from t1;
 length(a)
 6
+select 0b01000001;
+0b01000001
+A
+select 0x41;
+0x41
+A
+select b'01000001';
+b'01000001'
+A
+select x'41', 0+x'41';
+x'41'	0+x'41'
+A	65
+select N'abc', length(N'abc');
+abc	length(N'abc')
+abc	3
+select N'', length(N'');
+	length(N'')
+	0
+select '', length('');
+	length('')
+	0
+select b'', 0+b'';
+b''	0+b''
+	0
+select x'', 0+x'';
+x''	0+x''
+	0
+select 0x;
+ERROR 42S22: Unknown column '0x' in 'field list'
+select 0b;
+ERROR 42S22: Unknown column '0b' in 'field list'

=== modified file 'mysql-test/suite/funcs_1/t/is_columns_myisam_embedded.test'
--- a/mysql-test/suite/funcs_1/t/is_columns_myisam_embedded.test	2008-06-16 18:39:58 +0000
+++ b/mysql-test/suite/funcs_1/t/is_columns_myisam_embedded.test	2008-07-01 18:44:47 +0000
@@ -10,11 +10,6 @@
 # 2008-06-06 mleich Create this this variant for the embedded server.
 #
 
-let $value= query_get_value(SHOW VARIABLES LIKE 'version_compile_os',Value,1);
-if (`SELECT '$value' LIKE 'apple-darwin%'`)
-{
-   skip Bug#37380 Test funcs_1.is_columns_myisam_embedded fails on OS X;
-}
 if (`SELECT VERSION() NOT LIKE '%embedded%'`)
 {
    --skip Test requires: embedded server

=== modified file 'mysql-test/suite/funcs_2/charset/charset_master.test'
--- a/mysql-test/suite/funcs_2/charset/charset_master.test	2007-02-06 18:07:48 +0000
+++ b/mysql-test/suite/funcs_2/charset/charset_master.test	2008-07-09 11:22:07 +0000
@@ -1,14 +1,96 @@
 #################################################################################
-# Author:  Serge Kozlov								#
-# Date:    09/21/2005								#
-# Purpose: used by ../t/*_charset.test						#
-# Require: set $engine_type= [NDB,MyISAM,InnoDB,etc] before calling		#
+# Author:  Serge Kozlov                                                         #
+# Date:    2005-09-21                                                           #
+# Purpose: used by ../t/*_charset.test                                          #
+# Require: set $engine_type= [NDB,MyISAM,InnoDB,etc] before calling             #
+#                                                                               #
+# Last modification:  Matthias Leich                                            #
+# Date:    2008-07-02                                                           #
+# Purpose: Fix Bug#37160 funcs_2: The tests do not check if optional character  #
+#                                 sets exist.                                   #
+#          Add checking of prerequisites + minor cleanup                        #
 #################################################################################
 
 #
 #
 #
 
+# Check that all character sets needed are available
+# Note(mleich):
+#    It is intentional that the common solution with
+#    "--source include/have_<character set>.inc"
+#    is not applied.
+#    - We currently do not have such a prerequisite test for every character set
+#      /collation needed.
+#    - There is also no real value in mentioning the first missing character set
+#      /collation within the "skip message" because it is most probably only
+#      one of many.
+#      
+# Hint: 5 character_set_names per source line if possible
+if (`SELECT COUNT(*) <> 36 FROM information_schema.character_sets
+    WHERE CHARACTER_SET_NAME IN (
+    'armscii8', 'ascii'  , 'big5'   , 'binary' , 'cp1250',
+    'cp1251'  , 'cp1256' , 'cp1257' , 'cp850'  , 'cp852' ,
+    'cp866'   , 'cp932'  , 'dec8'   , 'eucjpms', 'euckr' ,
+    'gb2312'  , 'gbk'    , 'geostd8', 'greek'  , 'hebrew',
+    'hp8'     , 'keybcs2', 'koi8r'  , 'koi8u'  , 'latin1',
+    'latin2'  , 'latin5' , 'latin7' , 'macce'  , 'macroman',
+    'sjis'    , 'swe7'   , 'tis620' , 'ucs2'   , 'ujis',
+    'utf8'
+    )`)
+{
+   --skip Not all character sets required for this test are present
+}
+# Check that all collations needed are available
+# Hint: 4 collation_names per source line if possible
+if (`SELECT COUNT(*) <> 123 FROM information_schema.collations
+WHERE collation_name IN (
+'armscii8_bin', 'armscii8_general_ci', 'ascii_bin', 'ascii_general_ci',
+'big5_bin', 'big5_chinese_ci', 'cp1250_bin', 'cp1250_croatian_ci',
+'cp1250_czech_cs', 'cp1250_general_ci', 'cp1251_bin', 'cp1251_bulgarian_ci',
+'cp1251_general_ci', 'cp1251_general_cs', 'cp1251_ukrainian_ci', 'cp1256_bin',
+'cp1256_general_ci', 'cp1257_bin', 'cp1257_general_ci', 'cp1257_lithuanian_ci',
+'cp850_bin', 'cp850_general_ci', 'cp852_bin', 'cp852_general_ci',
+'cp866_bin', 'cp866_general_ci', 'cp932_bin', 'cp932_japanese_ci',
+'dec8_bin', 'dec8_swedish_ci', 'eucjpms_bin', 'eucjpms_japanese_ci',
+'euckr_bin', 'euckr_korean_ci', 'gb2312_bin', 'gb2312_chinese_ci',
+'gbk_bin', 'gbk_chinese_ci', 'geostd8_bin', 'geostd8_general_ci',
+'greek_bin', 'greek_general_ci', 'hebrew_bin', 'hebrew_general_ci',
+'hp8_bin', 'hp8_english_ci', 'keybcs2_bin', 'keybcs2_general_ci',
+'koi8r_bin', 'koi8r_general_ci', 'koi8u_bin', 'koi8u_general_ci',
+'latin1_bin', 'latin1_danish_ci', 'latin1_general_ci', 'latin1_general_cs',
+'latin1_german1_ci', 'latin1_german2_ci', 'latin1_spanish_ci', 'latin1_swedish_ci',
+'latin2_bin', 'latin2_croatian_ci', 'latin2_czech_cs', 'latin2_general_ci',
+'latin2_hungarian_ci', 'latin5_bin', 'latin5_turkish_ci', 'latin7_bin',
+'latin7_estonian_cs', 'latin7_general_ci', 'latin7_general_cs', 'macce_bin',
+'macce_general_ci', 'macroman_bin', 'macroman_general_ci', 'sjis_bin',
+'sjis_japanese_ci', 'swe7_bin', 'swe7_swedish_ci', 'tis620_bin',
+'tis620_thai_ci', 'ucs2_bin', 'ucs2_czech_ci', 'ucs2_danish_ci',
+'ucs2_estonian_ci', 'ucs2_general_ci', 'ucs2_hungarian_ci', 'ucs2_icelandic_ci',
+'ucs2_latvian_ci', 'ucs2_lithuanian_ci', 'ucs2_persian_ci', 'ucs2_polish_ci',
+'ucs2_roman_ci', 'ucs2_romanian_ci', 'ucs2_slovak_ci', 'ucs2_slovenian_ci',
+'ucs2_spanish2_ci', 'ucs2_spanish_ci', 'ucs2_swedish_ci', 'ucs2_turkish_ci',
+'ucs2_unicode_ci', 'ujis_bin', 'ujis_japanese_ci', 'utf8_bin',
+'utf8_czech_ci', 'utf8_danish_ci', 'utf8_estonian_ci', 'utf8_general_ci',
+'utf8_hungarian_ci', 'utf8_icelandic_ci', 'utf8_latvian_ci', 'utf8_lithuanian_ci',
+'utf8_persian_ci', 'utf8_polish_ci', 'utf8_roman_ci', 'utf8_romanian_ci',
+'utf8_slovak_ci', 'utf8_slovenian_ci', 'utf8_spanish2_ci', 'utf8_spanish_ci',
+'utf8_swedish_ci', 'utf8_turkish_ci', 'utf8_unicode_ci'
+)`)
+{
+   --skip Not all collations required for this test are present
+}
+
+################################
+let $check_std_csets= 1;
+let $check_ucs2_csets= 1;
+let $check_utf8_csets= 1;
+
+#
+# Check all charsets/collation combinations
+#
+
+################################
 let $check_std_csets= 1;
 let $check_ucs2_csets= 1;
 let $check_utf8_csets= 1;

=== modified file 'mysql-test/suite/funcs_2/t/innodb_charset.test'
--- a/mysql-test/suite/funcs_2/t/innodb_charset.test	2007-02-06 18:07:48 +0000
+++ b/mysql-test/suite/funcs_2/t/innodb_charset.test	2008-07-09 11:22:07 +0000
@@ -1,8 +1,10 @@
-#################################################################################
-# Author:  Serge Kozlov								#
-# Date:    09/21/2005								#
-# Purpose: Testing the charsets for InnoDB engine				#
-#################################################################################
+################################################################################
+# Author:  Serge Kozlov                                                        #
+# Date:    2005-09-21                                                          #
+# Purpose: Testing the charsets for InnoDB engine                              #
+#                                                                              #
+# Checking of other prerequisites is in charset_master.test                    #
+################################################################################
 
 --source include/have_innodb.inc
 

=== modified file 'mysql-test/suite/funcs_2/t/memory_charset.test'
--- a/mysql-test/suite/funcs_2/t/memory_charset.test	2007-02-06 18:07:48 +0000
+++ b/mysql-test/suite/funcs_2/t/memory_charset.test	2008-07-09 11:22:07 +0000
@@ -1,8 +1,10 @@
-#################################################################################
-# Author:  Serge Kozlov								#
-# Date:    09/21/2005								#
-# Purpose: Testing the charsets for Memory engine				#
-#################################################################################
+################################################################################
+# Author:  Serge Kozlov                                                        #
+# Date:    2005-09-21                                                          #
+# Purpose: Testing the charsets for Memory engine                              #
+#                                                                              #
+# Checking of other prerequisites is in charset_master.test                    #
+################################################################################
 
 let $engine_type= Memory;
 --source suite/funcs_2/charset/charset_master.test

=== modified file 'mysql-test/suite/funcs_2/t/myisam_charset.test'
--- a/mysql-test/suite/funcs_2/t/myisam_charset.test	2007-02-06 18:07:48 +0000
+++ b/mysql-test/suite/funcs_2/t/myisam_charset.test	2008-07-09 11:22:07 +0000
@@ -1,8 +1,10 @@
-#################################################################################
-# Author:  Serge Kozlov								#
-# Date:    09/21/2005								#
-# Purpose: Testing the charsets for MyISAM engine				#
-#################################################################################
+################################################################################
+# Author:  Serge Kozlov                                                        #
+# Date:    2005-09-21                                                          #
+# Purpose: Testing the charsets for MyISAM engine                              #
+#                                                                              #
+# Checking of other prerequisites is in charset_master.test                    #
+################################################################################
 
 let $engine_type= MyISAM;
 --source suite/funcs_2/charset/charset_master.test

=== modified file 'mysql-test/suite/funcs_2/t/ndb_charset.test'
--- a/mysql-test/suite/funcs_2/t/ndb_charset.test	2007-02-06 18:07:48 +0000
+++ b/mysql-test/suite/funcs_2/t/ndb_charset.test	2008-07-09 11:22:07 +0000
@@ -1,8 +1,10 @@
-#################################################################################
-# Author:  Serge Kozlov								#
-# Date:    09/21/2005								#
-# Purpose: Testing the charsets for NDB engine					#
-#################################################################################
+################################################################################
+# Author:  Serge Kozlov                                                        #
+# Date:    09/21/2005                                                          #
+# Purpose: Testing the charsets for NDB engine                                 #
+#                                                                              #
+# Checking of other prerequisites is in charset_master.test                    #
+################################################################################
 
 --source include/have_ndb.inc
 --source include/not_embedded.inc

=== modified file 'mysql-test/t/client_xml.test'
--- a/mysql-test/t/client_xml.test	2007-04-09 12:53:10 +0000
+++ b/mysql-test/t/client_xml.test	2008-07-18 09:07:16 +0000
@@ -1,6 +1,10 @@
 # Can't run with embedded server
 -- source include/not_embedded.inc
 
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
 # Test of the xml output of the 'mysql' and 'mysqldump' clients -- makes
 # sure that basic encoding issues are handled properly
 create table t1 (

=== modified file 'mysql-test/t/federated.test'
--- a/mysql-test/t/federated.test	2008-03-25 08:47:57 +0000
+++ b/mysql-test/t/federated.test	2008-08-15 06:40:05 +0000
@@ -1750,4 +1750,26 @@
 CREATE TABLE t1 (a INT) ENGINE=federated CONNECTION='mysql://@:://';
 DROP TABLE t1;
 
+
+#
+# Bug #34779: crash in checksum table on federated tables with blobs 
+# containing nulls
+#
+connection slave;
+CREATE TABLE t1 (a LONGBLOB, b LONGBLOB);
+INSERT INTO t1 VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaa', NULL);
+connection master;
+--replace_result $SLAVE_MYPORT SLAVE_PORT
+eval CREATE TABLE t1
+  (a LONGBLOB, b LONGBLOB) ENGINE=FEDERATED
+  CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/t1';
+CHECKSUM TABLE t1;
+connection slave;
+DROP TABLE t1;
+connection master;
+DROP TABLE t1;
+
+
 source include/federated_cleanup.inc;
+
+--echo End of 5.0 tests

=== modified file 'mysql-test/t/func_if.test'
--- a/mysql-test/t/func_if.test	2007-02-12 20:59:29 +0000
+++ b/mysql-test/t/func_if.test	2008-07-30 11:07:37 +0000
@@ -108,3 +108,46 @@
 select if(0, 18446744073709551610, 18446744073709551610);
 
 
+#
+# Bug #37662: nested if() inside sum() is parsed in exponential time
+#
+
+CREATE TABLE t1(a DECIMAL(10,3));
+
+# check : should be fast. more than few secs means failure.
+SELECT t1.a,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,
+ IF((ROUND(t1.a,2)=1), 2,0)))))))))))))))))))))))))))))) + 1
+FROM t1;
+
+DROP TABLE t1;
+
+--echo End of 5.0 tests

=== modified file 'mysql-test/t/func_misc.test'
--- a/mysql-test/t/func_misc.test	2008-06-02 19:57:11 +0000
+++ b/mysql-test/t/func_misc.test	2008-07-10 01:58:30 +0000
@@ -417,5 +417,24 @@
 #
 SELECT NAME_CONST('var', 'value') COLLATE latin1_general_cs;
 
+#
+# Bug #35848: UUID() returns UUIDs with the wrong time
+#
+select @@session.time_zone into @save_tz;
+
+# make sure all times are UTC so the DayNr won't differ
+set @@session.time_zone='UTC';
+select uuid() into @my_uuid;
+# if version nibble isn't 1, the following calculations will be rubbish
+select mid(@my_uuid,15,1);
+select 24 * 60 * 60 * 1000 * 1000 * 10 into @my_uuid_one_day;
+select concat('0',mid(@my_uuid,16,3),mid(@my_uuid,10,4),left(@my_uuid,8)) into @my_uuidate;
+select floor(conv(@my_uuidate,16,10)/@my_uuid_one_day) into @my_uuid_date;
+select 141427 + datediff(curdate(),'1970-01-01') into @my_uuid_synthetic;
+# these should be identical; date part of UUID should be current date
+select @my_uuid_date - @my_uuid_synthetic;
+
+set @@session.time_zone=@save_tz;
+
 --echo End of 5.0 tests
 

=== modified file 'mysql-test/t/group_min_max.test'
--- a/mysql-test/t/group_min_max.test	2007-11-20 14:07:24 +0000
+++ b/mysql-test/t/group_min_max.test	2008-08-27 13:03:17 +0000
@@ -916,3 +916,22 @@
 SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC;
 
 DROP TABLE t1;
+
+#
+# Bug#38195: Incorrect handling of aggregate functions when loose index scan is
+#            used causes server crash.
+#
+create table t1 (a int, b int, primary key (a,b), key `index` (a,b)) engine=MyISAM;
+insert into  t1 (a,b) values 
+(0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),
+  (0,7),(0,8),(0,9),(0,10),(0,11),(0,12),(0,13),
+(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),
+  (1,7),(1,8),(1,9),(1,10),(1,11),(1,12),(1,13),
+(2,0),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),
+  (2,7),(2,8),(2,9),(2,10),(2,11),(2,12),(2,13),
+(3,0),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),
+  (3,7),(3,8),(3,9),(3,10),(3,11),(3,12),(3,13);
+insert into t1 (a,b) select a, max(b)+1 from t1 where a = 0 group by a;
+select * from t1;
+explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a;
+drop table t1;

=== added file 'mysql-test/t/innodb-autoinc-optimize.test'
--- a/mysql-test/t/innodb-autoinc-optimize.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb-autoinc-optimize.test	2008-07-31 21:47:57 +0000
@@ -0,0 +1,16 @@
+-- source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug 34286
+#
+create table t1(a int not null auto_increment primary key) engine=innodb;
+insert into t1 set a = -1;
+# NOTE: The database needs to be shutdown and restarted (here) for
+# the test to work. It's included for reference only.
+optimize table t1;

=== added file 'mysql-test/t/innodb_bug35220.test'
--- a/mysql-test/t/innodb_bug35220.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug35220.test	2008-08-08 00:25:24 +0000
@@ -0,0 +1,16 @@
+#
+# Bug#35220 ALTER TABLE too picky on reserved word "foreign"
+# http://bugs.mysql.com/35220
+#
+
+-- source include/have_innodb.inc
+
+SET storage_engine=InnoDB;
+
+# we care only that the following SQL commands do not produce errors
+-- disable_query_log
+-- disable_result_log
+
+CREATE TABLE bug35220 (foreign_col INT, dummy_cant_delete_all_columns INT);
+ALTER TABLE bug35220 DROP foreign_col;
+DROP TABLE bug35220;

=== modified file 'mysql-test/t/innodb_mysql.test'
--- a/mysql-test/t/innodb_mysql.test	2008-02-07 07:12:49 +0000
+++ b/mysql-test/t/innodb_mysql.test	2008-07-23 11:25:00 +0000
@@ -996,4 +996,22 @@
 set global innodb_commit_concurrency=0;
 set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
 
+#
+# Bug #37830: ORDER BY ASC/DESC - no difference
+#
+
+CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
+ ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
+INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
+
+# should be range access
+EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+# should produce '8 7 6 5 4' for a
+SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+DROP TABLE t1;
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/myisam.test'
--- a/mysql-test/t/myisam.test	2008-01-16 11:15:57 +0000
+++ b/mysql-test/t/myisam.test	2008-08-26 13:48:50 +0000
@@ -1210,4 +1210,19 @@
 
 DROP TABLE t1, t2;
 
+
+#
+# Bug#37310: 'on update CURRENT_TIMESTAMP' option crashes the table
+#
+CREATE TABLE t1 (a INT) ENGINE=MyISAM CHECKSUM=1 ROW_FORMAT=DYNAMIC;
+INSERT INTO t1 VALUES (0);
+UPDATE t1 SET a=1;
+SELECT a FROM t1;
+CHECK TABLE t1;
+INSERT INTO t1 VALUES (0), (5), (4), (2);
+UPDATE t1 SET a=2;
+SELECT a FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1; 
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/mysql_delimiter.sql'
--- a/mysql-test/t/mysql_delimiter.sql	2008-06-24 16:03:17 +0000
+++ b/mysql-test/t/mysql_delimiter.sql	2008-07-18 10:24:59 +0000
@@ -61,12 +61,6 @@
 delimiter ; # Reset delimiter
 
 #
-# Bug #33812: mysql client incorrectly parsing DELIMITER
-#
-select a as delimiter from t1
-delimiter ; # Reset delimiter
-
-#
 # Bug #36244: MySQL CLI doesn't recognize standalone -- as comment
 #             before DELIMITER statement
 #

=== added file 'mysql-test/t/parser.test'
--- a/mysql-test/t/parser.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/parser.test	2008-07-07 16:00:08 +0000
@@ -0,0 +1,59 @@
+#
+# This file contains tests covering the parser
+#
+
+#=============================================================================
+# LEXICAL PARSER (lex)
+#=============================================================================
+
+#
+# Maintainer: these tests are for the lexical parser, so every character,
+# even whitespace or comments, is significant here.
+#
+
+#
+# Bug#26030 (Parsing fails for stored routine w/multi-statement execution
+# enabled)
+#
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p26030;
+--enable_warnings
+
+delimiter $$;
+
+select "non terminated"$$
+select "terminated";$$
+select "non terminated, space"      $$
+select "terminated, space";      $$
+select "non terminated, comment" /* comment */$$
+select "terminated, comment"; /* comment */$$
+
+# Multi queries can not be used in --ps-protocol test mode
+--disable_ps_protocol
+
+select "stmt 1";select "stmt 2 non terminated"$$
+select "stmt 1";select "stmt 2 terminated";$$
+select "stmt 1";select "stmt 2 non terminated, space"      $$
+select "stmt 1";select "stmt 2 terminated, space";      $$
+select "stmt 1";select "stmt 2 non terminated, comment" /* comment */$$
+select "stmt 1";select "stmt 2 terminated, comment"; /* comment */$$
+
+select "stmt 1";             select "space, stmt 2"$$
+select "stmt 1";/* comment */select "comment, stmt 2"$$
+
+DROP PROCEDURE IF EXISTS p26030; CREATE PROCEDURE p26030() BEGIN SELECT 1; END; CALL p26030()
+$$
+
+DROP PROCEDURE IF EXISTS p26030; CREATE PROCEDURE p26030() SELECT 1; CALL p26030()
+$$
+
+--enable_ps_protocol
+
+delimiter ;$$
+DROP PROCEDURE p26030;
+
+#============================================================================r
+# SYNTACTIC PARSER (bison)
+#=============================================================================
+

=== added file 'mysql-test/t/parser_stack.test'
--- a/mysql-test/t/parser_stack.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/parser_stack.test	2008-07-14 21:41:30 +0000
@@ -0,0 +1,402 @@
+# Copyright (C) 2008 Sun Microsystems, Inc
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+#
+# These tests are designed to cause an internal parser stack overflow,
+# and trigger my_yyoverflow().
+#
+
+use test;
+
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+;
+
+prepare stmt from
+"
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+"
+;
+
+execute stmt;
+
+--disable_warnings
+drop view if exists view_overflow;
+--enable_warnings
+
+CREATE VIEW view_overflow AS
+SELECT
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+1
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+;
+
+SELECT * from view_overflow;
+
+drop view view_overflow;
+
+--disable_warnings
+drop procedure if exists proc_overflow;
+--enable_warnings
+
+delimiter $$;
+
+CREATE PROCEDURE proc_overflow()
+BEGIN
+
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+
+  select 1;
+  select 2;
+  select 3;
+
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+
+END $$
+
+delimiter ;$$
+
+call proc_overflow();
+
+drop procedure proc_overflow;
+
+--disable_warnings
+drop function if exists func_overflow;
+--enable_warnings
+
+delimiter $$;
+
+create function func_overflow() returns int
+BEGIN
+  DECLARE x int default 0;
+
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+
+  SET x=x+1;
+  SET x=x+2;
+  SET x=x+3;
+
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+
+  return x;
+END $$
+
+delimiter ;$$
+
+select func_overflow();
+
+drop function func_overflow;
+
+--disable_warnings
+drop table if exists table_overflow;
+--enable_warnings
+
+create table table_overflow(a int, b int);
+
+delimiter $$;
+
+create trigger trigger_overflow before insert on table_overflow
+for each row
+BEGIN
+
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+  BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN BEGIN
+
+  SET NEW.b := NEW.a;
+  SET NEW.b := NEW.b + 1;
+  SET NEW.b := NEW.b + 2;
+  SET NEW.b := NEW.b + 3;
+
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;  END;
+
+END $$
+
+delimiter ;$$
+
+insert into table_overflow set a=10;
+insert into table_overflow set a=20;
+select * from table_overflow;
+
+drop table table_overflow;
+
+--disable_warnings
+drop procedure if exists proc_35577;
+--enable_warnings
+
+delimiter $$;
+
+CREATE PROCEDURE proc_35577()
+BEGIN
+  DECLARE z_done INT DEFAULT 0;
+  DECLARE t_done VARCHAR(5000);
+  outer_loop: LOOP
+    IF t_done=1  THEN
+      LEAVE outer_loop;
+    END IF;
+
+    inner_block:BEGIN
+      DECLARE z_done INT DEFAULT  0;
+      SET z_done = 0;
+      inner_loop: LOOP
+        IF z_done=1  THEN
+          LEAVE inner_loop;
+        END IF;
+        IF (t_done = 'a') THEN
+          IF (t_done <> 0) THEN
+            IF ( t_done > 0) THEN
+              IF (t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF (t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              ELSEIF(t_done = 'a') THEN
+                SET t_done = 'a';
+              END IF;
+            END IF;
+          END IF;
+        END IF;
+      END LOOP inner_loop;
+    END inner_block;
+  END LOOP outer_loop;
+END $$
+
+delimiter ;$$
+
+drop procedure proc_35577;
+
+#
+# Bug#37269 (parser crash when creating stored procedure)
+#
+
+--disable_warnings
+drop procedure if exists p_37269;
+--enable_warnings
+
+delimiter $$;
+
+create procedure p_37269()
+begin
+  declare done int default 0;
+  declare varb int default 0;
+  declare vara int default 0;
+
+  repeat
+    select now();
+  until done end repeat;
+  while varb do
+    select now();
+    begin
+      select now();
+      repeat
+        select now();
+      until done end repeat;
+      if vara then 
+        select now();
+        repeat
+          select now();
+          loop
+            select now();
+          end loop;
+          repeat
+            select now();
+            label1: while varb do
+              select now();
+            end while label1;
+            if vara then 
+              select now();
+              repeat
+                select now();
+              until done end repeat;
+              begin
+                select now();
+                while varb do
+                  select now();
+                  label1: while varb do
+                    select now();
+                  end while label1;
+                  if vara then 
+                    select now();
+                    while varb do
+                      select now();
+                      loop
+                        select now();
+                      end loop;
+                      repeat
+                        select now();
+                        loop
+                          select now();
+                          while varb do
+                            select now();
+                          end while;
+                          repeat
+                            select now();
+                            label1: loop
+                              select now();
+                              if vara then 
+                                select now();
+                              end if;
+                            end loop label1;
+                          until done end repeat;
+                        end loop;
+                      until done end repeat;
+                    end while;
+                  end if;
+                end while;
+              end;
+            end if;
+          until done end repeat;
+        until done end repeat;
+      end if;
+    end;
+  end while;
+end $$
+
+delimiter ;$$
+
+drop procedure p_37269;
+
+#
+# Bug#37228 (Sever crashes when creating stored procedure with more than
+#            10 IF/ELSEIF)
+#
+
+--disable_warnings
+drop procedure if exists p_37228;
+--enable_warnings
+
+delimiter $$;
+
+create procedure p_37228 ()
+BEGIN
+  DECLARE v INT DEFAULT 123;
+
+  IF (v > 1) THEN SET v = 1; 
+  ELSEIF (v < 10) THEN SET v = 10;
+  ELSEIF (v < 11) THEN SET v = 11;
+  ELSEIF (v < 12) THEN SET v = 12;
+  ELSEIF (v < 13) THEN SET v = 13;
+  ELSEIF (v < 14) THEN SET v = 14;
+  ELSEIF (v < 15) THEN SET v = 15;
+  ELSEIF (v < 16) THEN SET v = 16;
+  ELSEIF (v < 17) THEN SET v = 17;
+  ELSEIF (v < 18) THEN SET v = 18;
+  ELSEIF (v < 19) THEN SET v = 19;
+  ELSEIF (v < 20) THEN SET v = 20;
+  ELSEIF (v < 21) THEN SET v = 21;
+  ELSEIF (v < 22) THEN SET v = 22;
+  ELSEIF (v < 23) THEN SET v = 23;
+  ELSEIF (v < 24) THEN SET v = 24;
+  ELSEIF (v < 25) THEN SET v = 25;
+  ELSEIF (v < 26) THEN SET v = 26;
+  ELSEIF (v < 27) THEN SET v = 27;
+  ELSEIF (v < 28) THEN SET v = 28;
+  ELSEIF (v < 29) THEN SET v = 29;
+  ELSEIF (v < 30) THEN SET v = 30;
+  ELSEIF (v < 31) THEN SET v = 31;
+  ELSEIF (v < 32) THEN SET v = 32;
+  ELSEIF (v < 33) THEN SET v = 33;
+  ELSEIF (v < 34) THEN SET v = 34;
+  ELSEIF (v < 35) THEN SET v = 35;
+  ELSEIF (v < 36) THEN SET v = 36;
+  ELSEIF (v < 37) THEN SET v = 37;
+  ELSEIF (v < 38) THEN SET v = 38;
+  ELSEIF (v < 39) THEN SET v = 39;
+  END IF;
+END $$
+
+delimiter ;$$
+
+drop procedure p_37228;
+
+

=== modified file 'mysql-test/t/query_cache_merge.test'
--- a/mysql-test/t/query_cache_merge.test	2005-07-28 00:22:47 +0000
+++ b/mysql-test/t/query_cache_merge.test	2008-07-24 14:14:34 +0000
@@ -38,3 +38,59 @@
 SET @@global.query_cache_size=0;
 
 # End of 4.1 tests
+
+#
+# Bug#33362: Query cache invalidation (truncate) may hang if cached query uses many tables
+#
+
+let $c= 255;
+
+while ($c)
+{
+  eval CREATE TABLE t$c (a INT);
+  eval INSERT INTO t$c VALUES ($c);
+  dec $c;
+}
+
+let $c= 254;
+let $str= t255;
+
+while ($c)
+{
+  let $str= t$c,$str;
+  dec $c;
+}
+
+eval CREATE TABLE t0 (a INT) ENGINE=MERGE UNION($str);
+SET GLOBAL query_cache_size = 1048576;
+FLUSH STATUS;
+SELECT a FROM t0 WHERE a = 1;
+SHOW STATUS LIKE "Qcache_queries_in_cache";
+
+let $c= 255;
+let $i= 1;
+
+FLUSH TABLES;
+
+while ($c)
+{
+  eval TRUNCATE TABLE t$c;
+  eval SELECT a FROM t$i;
+  dec $c;
+  inc $i;
+}
+
+SELECT a FROM t0;
+DROP TABLE t0;
+
+let $c= 255;
+
+while ($c)
+{
+  eval DROP TABLE t$c;
+  dec $c;
+}
+
+SET @@global.query_cache_size = 0;
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/show_check.test'
--- a/mysql-test/t/show_check.test	2007-08-02 13:23:23 +0000
+++ b/mysql-test/t/show_check.test	2008-08-15 20:13:27 +0000
@@ -844,4 +844,24 @@
 #
 show variables like 'myisam_recover_options';
 
+#
+# Bug#37301 Length and Max_length differ with no obvious reason
+#
+CREATE TABLE t1 (
+ Codigo int(10) unsigned NOT NULL auto_increment,
+ Nombre varchar(255) default NULL,
+ Telefono varchar(255) default NULL,
+ Observaciones longtext,
+ Direccion varchar(255) default NULL,
+ Dni varchar(255) default NULL,
+ CP int(11) default NULL,
+ Provincia varchar(255) default NULL,
+ Poblacion varchar(255) default NULL,
+ PRIMARY KEY  (Codigo)
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
+--enable_metadata
+show create table t1;
+--disable_metadata
+drop table t1;
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/sp.test'
--- a/mysql-test/t/sp.test	2008-02-17 11:37:39 +0000
+++ b/mysql-test/t/sp.test	2008-08-20 09:49:28 +0000
@@ -7794,6 +7794,30 @@
 drop table t1;
 
 
+#
+# Bug#38291 memory corruption and server crash with view/sp/function
+#
+
+create table t1(c1 INT);
+create function f1(p1 int) returns varchar(32)
+  return 'aaa';
+create view v1 as select f1(c1) as parent_control_name from t1;
+
+delimiter //;
+create procedure p1()
+begin
+    select parent_control_name as c1 from v1;
+end //
+delimiter ;//
+
+call p1();
+call p1();
+
+drop procedure p1;
+drop function f1;
+drop view v1;
+drop table t1;
+
 --echo # ------------------------------------------------------------------
 --echo # -- End of 5.0 tests
 --echo # ------------------------------------------------------------------

=== modified file 'mysql-test/t/subselect.test'
--- a/mysql-test/t/subselect.test	2008-06-25 14:59:38 +0000
+++ b/mysql-test/t/subselect.test	2008-07-26 20:44:07 +0000
@@ -3295,5 +3295,17 @@
 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT 1 FROM t1 WHERE a > 3 GROUP BY a);
 DROP TABLE t1;
 
+#
+# 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.0 tests.
 

=== modified file 'mysql-test/t/symlink.test'
--- a/mysql-test/t/symlink.test	2008-03-03 11:02:34 +0000
+++ b/mysql-test/t/symlink.test	2008-08-26 09:21:07 +0000
@@ -71,8 +71,6 @@
 SHOW CREATE TABLE t9;
 
 disable_query_log;
---error 1103,1103
-create table t1 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam data directory="tmp";
 
 # Check that we cannot link over a table from another database.
 
@@ -81,8 +79,9 @@
 --error 1,1
 create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="/this-dir-does-not-exist";
 
---error 1103,1103
-create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="not-hard-path";
+# temporarily disabled as it returns different result in the embedded server
+# --error 1210, 1210
+# create table mysqltest.t9 (a int not null auto_increment, b char(16) not null, primary key (a)) engine=myisam index directory="not-hard-path";
 
 # Should fail becasue the file t9.MYI already exist in 'run'
 --error 1,1,1105
@@ -230,6 +229,7 @@
 EOF
 --disable_abort_on_error
 --error 1
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
 CREATE TABLE t1 (a INT) ENGINE MYISAM;
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/test/t1.MYD;

=== modified file 'mysql-test/t/type_bit.test'
--- a/mysql-test/t/type_bit.test	2007-11-21 18:56:42 +0000
+++ b/mysql-test/t/type_bit.test	2008-08-27 21:10:37 +0000
@@ -333,4 +333,23 @@
 
 DROP TABLE t1;
 
+#
+# Bug#37799 SELECT with a BIT column in WHERE clause returns unexpected result
+#
+
+CREATE TABLE t1 (b BIT NOT NULL, i2 INTEGER NOT NULL, s VARCHAR(255) NOT NULL);
+INSERT INTO t1 VALUES(0x01,100,''), (0x00,300,''), (0x01,200,''), (0x00,100,'');
+SELECT HEX(b), i2 FROM t1 WHERE (i2>=100 AND i2<201) AND b=TRUE;
+
+CREATE TABLE t2 (b1 BIT NOT NULL, b2 BIT NOT NULL, i2 INTEGER NOT NULL,
+                 s VARCHAR(255) NOT NULL);
+INSERT INTO t2 VALUES (0x01,0x00,100,''), (0x00,0x01,300,''),
+                      (0x01,0x00,200,''), (0x00,0x01,100,'');
+SELECT HEX(b1), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b1=TRUE;
+SELECT HEX(b2), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b2=FALSE;
+SELECT HEX(b1), HEX(b2), i2 FROM t2
+       WHERE (i2>=100 AND i2<201) AND b1=TRUE AND b2=FALSE;
+
+DROP TABLE t1, t2;
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/type_newdecimal.test'
--- a/mysql-test/t/type_newdecimal.test	2007-11-17 18:05:31 +0000
+++ b/mysql-test/t/type_newdecimal.test	2008-08-15 19:46:21 +0000
@@ -1216,4 +1216,13 @@
 SELECT f1 FROM t1;
 DROP TABLE t1;
 
+#
+# Bug #36270: incorrect calculation result - works in 4.1 but not in 5.0 or 5.1
+#
+
+# show that if we need to truncate the scale of an operand, we pick the
+# right one (that is, we discard the least significant decimal places)
+select (1.20396873 * 0.89550000 * 0.68000000 * 1.08721696 * 0.99500000 *
+        1.01500000 * 1.01500000 * 0.99500000);
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/varbinary.test'
--- a/mysql-test/t/varbinary.test	2006-12-21 23:38:34 +0000
+++ b/mysql-test/t/varbinary.test	2008-06-27 15:56:41 +0000
@@ -84,3 +84,31 @@
 alter table t1 modify a varchar(255);
 select length(a) from t1;
 
+#
+# Bug#35658 (An empty binary value leads to mysqld crash)
+#
+
+select 0b01000001;
+
+select 0x41;
+
+select b'01000001';
+
+select x'41', 0+x'41';
+
+select N'abc', length(N'abc');
+
+select N'', length(N'');
+
+select '', length('');
+
+select b'', 0+b'';
+
+select x'', 0+x'';
+
+--error ER_BAD_FIELD_ERROR
+select 0x;
+
+--error ER_BAD_FIELD_ERROR
+select 0b;
+

=== modified file 'mysys/default.c'
--- a/mysys/default.c	2007-11-16 21:56:37 +0000
+++ b/mysys/default.c	2008-07-22 10:55:15 +0000
@@ -48,13 +48,12 @@
 /* Which directories are searched for options (and in which order) */
 
 #define MAX_DEFAULT_DIRS 6
-const char *default_directories[MAX_DEFAULT_DIRS + 1];
+#define DEFAULT_DIRS_SIZE (MAX_DEFAULT_DIRS + 1)  /* Terminate with NULL */
+static const char **default_directories = NULL;
 
 #ifdef __WIN__
 static const char *f_extensions[]= { ".ini", ".cnf", 0 };
 #define NEWLINE "\r\n"
-static char system_dir[FN_REFLEN], shared_system_dir[FN_REFLEN],
-            config_dir[FN_REFLEN];
 #else
 static const char *f_extensions[]= { ".cnf", 0 };
 #define NEWLINE "\n"
@@ -85,19 +84,34 @@
 					const char *config_file, int recursion_level);
 
 
-
 /**
   Create the list of default directories.
 
+  @param alloc  MEM_ROOT where the list of directories is stored
+
   @details
+  The directories searched, in order, are:
+  - Windows:     GetSystemWindowsDirectory()
+  - Windows:     GetWindowsDirectory()
+  - Windows:     C:/
+  - Windows:     Directory above where the executable is located
+  - Netware:     sys:/etc/
+  - Unix & OS/2: /etc/
+  - Unix:        --sysconfdir=<path> (compile-time option)
+  - OS/2:        getenv(ETC)
+  - ALL:         getenv(DEFAULT_HOME_ENV)
+  - ALL:         --defaults-extra-file=<path> (run-time option)
+  - Unix:        ~/
+
   On all systems, if a directory is already in the list, it will be moved
   to the end of the list.  This avoids reading defaults files multiple times,
   while ensuring the correct precedence.
 
-  @return void
+  @retval NULL  Failure (out of memory, probably)
+  @retval other Pointer to NULL-terminated array of default directories
 */
 
-static void (*init_default_directories)();
+static const char **init_default_directories(MEM_ROOT *alloc);
 
 
 static char *remove_end_comment(char *ptr);
@@ -386,8 +400,9 @@
   struct handle_option_ctx ctx;
   DBUG_ENTER("load_defaults");
 
-  init_default_directories();
   init_alloc_root(&alloc,512,0);
+  if ((default_directories= init_default_directories(&alloc)) == NULL)
+    goto err;
   /*
     Check if the user doesn't want any default option processing
     --no-defaults is always the first option
@@ -864,34 +879,49 @@
   my_bool have_ext= fn_ext(conf_file)[0] != 0;
   const char **exts_to_use= have_ext ? empty_list : f_extensions;
   char name[FN_REFLEN], **ext;
-  const char **dirs;
 
-  init_default_directories();
   puts("\nDefault options are read from the following files in the given order:");
 
   if (dirname_length(conf_file))
     fputs(conf_file,stdout);
   else
   {
-    for (dirs=default_directories ; *dirs; dirs++)
-    {
-      for (ext= (char**) exts_to_use; *ext; ext++)
+    /*
+      If default_directories is already initialized, use it.  Otherwise,
+      use a private MEM_ROOT.
+    */
+    const char **dirs = default_directories;
+    MEM_ROOT alloc;
+    init_alloc_root(&alloc,512,0);
+
+    if (!dirs && (dirs= init_default_directories(&alloc)) == NULL)
+    {
+      fputs("Internal error initializing default directories list", stdout);
+    }
+    else
+    {
+      for ( ; *dirs; dirs++)
       {
-	const char *pos;
-	char *end;
-	if (**dirs)
-	  pos= *dirs;
-	else if (my_defaults_extra_file)
-	  pos= my_defaults_extra_file;
-	else
-	  continue;
-	end= convert_dirname(name, pos, NullS);
-	if (name[0] == FN_HOMELIB)	/* Add . to filenames in home */
-	  *end++='.';
-	strxmov(end, conf_file, *ext, " ", NullS);
-	fputs(name,stdout);
+        for (ext= (char**) exts_to_use; *ext; ext++)
+        {
+          const char *pos;
+          char *end;
+          if (**dirs)
+            pos= *dirs;
+          else if (my_defaults_extra_file)
+            pos= my_defaults_extra_file;
+          else
+            continue;
+          end= convert_dirname(name, pos, NullS);
+          if (name[0] == FN_HOMELIB)	/* Add . to filenames in home */
+            *end++= '.';
+          strxmov(end, conf_file, *ext, " ", NullS);
+          fputs(name, stdout);
+        }
       }
     }
+
+    free_root(&alloc, MYF(0));
   }
   puts("");
 }
@@ -928,32 +958,22 @@
 #include <help_end.h>
 
 
-/*
-  This extra complexity is to avoid declaring 'rc' if it won't be
-  used.
-*/
-#define ADD_DIRECTORY_INTERNAL(DIR) \
-  array_append_string_unique((DIR), default_directories, \
-                             array_elements(default_directories))
-#ifdef DBUG_OFF
-#  define ADD_DIRECTORY(DIR)  (void) ADD_DIRECTORY_INTERNAL(DIR)
-#else
-#define ADD_DIRECTORY(DIR) \
-  do { \
-    my_bool rc= ADD_DIRECTORY_INTERNAL(DIR); \
-    DBUG_ASSERT(rc == FALSE);                   /* Success */ \
-  } while (0)
-#endif
-
-
-#define ADD_COMMON_DIRECTORIES() \
-  do { \
-    char *env; \
-    if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV)))) \
-      ADD_DIRECTORY(env); \
-    /* Placeholder for --defaults-extra-file=<path> */ \
-    ADD_DIRECTORY(""); \
-  } while (0)
+static int add_directory(MEM_ROOT *alloc, const char *dir, const char **dirs)
+{
+  char buf[FN_REFLEN];
+  uint len;
+  char *p;
+  my_bool err __attribute__((unused));
+
+  len= normalize_dirname(buf, dir);
+  if (!(p= strmake_root(alloc, buf, len)))
+    return 1;  /* Failure */
+  /* Should never fail if DEFAULT_DIRS_SIZE is correct size */
+  err= array_append_string_unique(p, dirs, DEFAULT_DIRS_SIZE);
+  DBUG_ASSERT(err == FALSE);
+
+  return 0;
+}
 
 
 #ifdef __WIN__
@@ -992,138 +1012,93 @@
 }
 
 
-/**
-  Initialize default directories for Microsoft Windows
-
-  @details
-    1. GetSystemWindowsDirectory()
-    2. GetWindowsDirectory()
-    3. C:/
-    4. Directory above where the executable is located
-    5. getenv(DEFAULT_HOME_ENV)
-    6. --defaults-extra-file=<path> (run-time option)
-*/
-
-static void init_default_directories_win()
+static const char *my_get_module_parent(char *buf, size_t size)
 {
-  bzero((char *) default_directories, sizeof(default_directories));
-
-  if (my_get_system_windows_directory(shared_system_dir,
-                                      sizeof(shared_system_dir)))
-    ADD_DIRECTORY(shared_system_dir);
-
-  if (GetWindowsDirectory(system_dir,sizeof(system_dir)))
-    ADD_DIRECTORY(system_dir);
-
-  ADD_DIRECTORY("C:/");
-
-  if (GetModuleFileName(NULL, config_dir, sizeof(config_dir)))
+  char *last= NULL;
+  char *end;
+  if (!GetModuleFileName(NULL, buf, (DWORD) size))
+    return NULL;
+  end= strend(buf);
+
+  /*
+    Look for the second-to-last \ in the filename, but hang on
+    to a pointer after the last \ in case we're in the root of
+    a drive.
+  */
+  for ( ; end > buf; end--)
   {
-    char *last= NULL, *end= strend(config_dir);
-    /*
-      Look for the second-to-last \ in the filename, but hang on
-      to a pointer after the last \ in case we're in the root of
-      a drive.
-    */
-    for ( ; end > config_dir; end--)
+    if (*end == FN_LIBCHAR)
     {
-      if (*end == FN_LIBCHAR)
+      if (last)
       {
-        if (last)
-        {
-          if (end != config_dir)
-          {
-            /* Keep the last '\' as this works both with D:\ and a directory */
-            end[1]= 0;
-          }
-          else
-          {
-            /* No parent directory (strange). Use current dir + '\' */
-            last[1]= 0;
-          }
-          break;
-        }
-        last= end;
+        /* Keep the last '\' as this works both with D:\ and a directory */
+        end[1]= 0;
+        break;
       }
+      last= end;
     }
-    ADD_DIRECTORY(config_dir);
   }
 
-  ADD_COMMON_DIRECTORIES();
+  return buf;
 }
-
-static void (*init_default_directories)()= init_default_directories_win;
+#endif /* __WIN__ */
+
+
+static const char **init_default_directories(MEM_ROOT *alloc)
+{
+  const char **dirs;
+  char *env;
+  int errors= 0;
+
+  dirs= (const char **)alloc_root(alloc, DEFAULT_DIRS_SIZE * sizeof(char *));
+  if (dirs == NULL)
+    return NULL;
+  bzero((char *) dirs, DEFAULT_DIRS_SIZE * sizeof(char *));
+
+#ifdef __WIN__
+
+  {
+    char fname_buffer[FN_REFLEN];
+    if (my_get_system_windows_directory(fname_buffer, sizeof(fname_buffer)))
+      errors += add_directory(alloc, fname_buffer, dirs);
+
+    if (GetWindowsDirectory(fname_buffer, sizeof(fname_buffer)))
+      errors += add_directory(alloc, fname_buffer, dirs);
+
+    errors += add_directory(alloc, "C:/", dirs);
+
+    if (my_get_module_parent(fname_buffer, sizeof(fname_buffer)) != NULL)
+      errors += add_directory(alloc, fname_buffer, dirs);
+  }
 
 #elif defined(__NETWARE__)
 
-/**
-  Initialize default directories for Novell Netware
-
-  @details
-    1. sys:/etc/
-    2. getenv(DEFAULT_HOME_ENV)
-    3. --defaults-extra-file=<path> (run-time option)
-*/
-
-static void init_default_directories_netware()
-{
-  bzero((char *) default_directories, sizeof(default_directories));
-  ADD_DIRECTORY("sys:/etc/");
-  ADD_COMMON_DIRECTORIES();
-}
-
-static void (*init_default_directories)()= init_default_directories_netware;
-
-#elif defined(__EMX__) || defined(OS2)
-
-/**
-  Initialize default directories for OS/2
-
-  @details
-    1. /etc/
-    2. getenv(ETC)
-    3. getenv(DEFAULT_HOME_ENV)
-    4. --defaults-extra-file=<path> (run-time option)
-*/
-
-static void init_default_directories_os2()
-{
-  const char *env;
-
-  bzero((char *) default_directories, sizeof(default_directories));
-  ADD_DIRECTORY("/etc/");
+  errors += add_directory(alloc, "sys:/etc/", dirs);
+
+#else
+
+  errors += add_directory(alloc, "/etc/", dirs);
+
+#if defined(__EMX__) || defined(OS2)
   if ((env= getenv("ETC")))
-    ADD_DIRECTORY(env);
-  ADD_COMMON_DIRECTORIES();
-}
-
-static void (*init_default_directories)()= init_default_directories_os2;
-
-#else
-
-/**
-  Initialize default directories for Unix
-
-  @details
-    1. /etc/
-    2. --sysconfdir=<path> (compile-time option)
-    3. getenv(DEFAULT_HOME_ENV)
-    4. --defaults-extra-file=<path> (run-time option)
-    5. "~/"
-*/
-
-static void init_default_directories_unix()
-{
-  bzero((char *) default_directories, sizeof(default_directories));
-  ADD_DIRECTORY("/etc/");
-#ifdef DEFAULT_SYSCONFDIR
+    errors += add_directory(alloc, env, dirs);
+#elif defined(DEFAULT_SYSCONFDIR)
   if (DEFAULT_SYSCONFDIR != "")
-    ADD_DIRECTORY(DEFAULT_SYSCONFDIR);
-#endif
-  ADD_COMMON_DIRECTORIES();
-  ADD_DIRECTORY("~/");
+    errors += add_directory(alloc, DEFAULT_SYSCONFDIR, dirs);
+#endif /* __EMX__ || __OS2__ */
+
+#endif
+
+  if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV))))
+    errors += add_directory(alloc, env, dirs);
+
+  /* Placeholder for --defaults-extra-file=<path> */
+  errors += add_directory(alloc, "", dirs);
+
+#if !defined(__WIN__) && !defined(__NETWARE__) && \
+    !defined(__EMX__) && !defined(OS2)
+  errors += add_directory(alloc, "~/", dirs);
+#endif
+
+  return (errors > 0 ? NULL : dirs);
 }
-
-static void (*init_default_directories)()= init_default_directories_unix;
-
-#endif

=== modified file 'mysys/mf_keycache.c'
--- a/mysys/mf_keycache.c	2008-03-29 15:50:46 +0000
+++ b/mysys/mf_keycache.c	2008-08-11 21:08:12 +0000
@@ -1382,7 +1382,7 @@
       /* We don't need the page in the cache: we are going to write on disk */
       hash_link->requests--;
       unlink_hash(keycache, hash_link);
-      return 0;
+      DBUG_RETURN(0);
     }
     if (!(block->status & BLOCK_IN_FLUSH))
     {
@@ -1399,7 +1399,7 @@
         flag (see the code below that handles reading requests).
       */
       free_block(keycache, block);
-      return 0;
+      DBUG_RETURN(0);
     }
     /* Wait intil the page is flushed on disk */
     hash_link->requests--;
@@ -1429,7 +1429,7 @@
     /* Invalidate page in the block if it has not been done yet */
     if (block->status)
       free_block(keycache, block);
-    return 0;
+    DBUG_RETURN(0);
   }
 
   if (page_status == PAGE_READ &&

=== modified file 'mysys/mf_pack.c'
--- a/mysys/mf_pack.c	2007-12-17 08:13:38 +0000
+++ b/mysys/mf_pack.c	2008-08-18 17:06:27 +0000
@@ -266,22 +266,64 @@
 #endif /* USE_SYMDIR */
 
 
-/*
-  Fixes a directroy name so that can be used by open()
-
-  SYNOPSIS
-    unpack_dirname()
-    to			result-buffer, FN_REFLEN characters. may be == from
-    from		'Packed' directory name (may contain ~)
-
- IMPLEMENTATION
-  Make that last char of to is '/' if from not empty and
-  from doesn't end in FN_DEVCHAR
-  Uses cleanup_dirname and changes ~/.. to home_dir/..
-
-  Changes a UNIX filename to system filename (replaces / with \ on windows)
-
-  RETURN
+/**
+  Convert a directory name to a format which can be compared as strings
+
+  @param to     result buffer, FN_REFLEN chars in length; may be == from
+  @param from   'packed' directory name, in whatever format
+  @returns      size of the normalized name
+
+  @details
+  - Ensures that last char is FN_LIBCHAR, unless it is FN_DEVCHAR
+  - Uses cleanup_dirname
+
+  It does *not* expand ~/ (although, see cleanup_dirname).  Nor does it do
+  any case folding.  All case-insensitive normalization should be done by
+  the caller.
+*/
+
+uint normalize_dirname(char *to, const char *from)
+{
+  uint length;
+  char buff[FN_REFLEN];
+  DBUG_ENTER("normalize_dirname");
+
+  /*
+    Despite the name, this actually converts the name to the system's
+    format (TODO: rip out the non-working VMS stuff and name this
+    properly).
+  */
+  (void) intern_filename(buff, from);
+  length= (uint) strlen(buff);			/* Fix that '/' is last */
+  if (length &&
+#ifdef FN_DEVCHAR
+      buff[length - 1] != FN_DEVCHAR &&
+#endif
+      buff[length - 1] != FN_LIBCHAR && buff[length - 1] != '/')
+  {
+    buff[length]= FN_LIBCHAR;
+    buff[length + 1]= '\0';
+  }
+
+  length=cleanup_dirname(to, buff);
+
+  DBUG_RETURN(length);
+}
+
+
+/**
+  Fixes a directory name so that can be used by open()
+
+  @param to     Result buffer, FN_REFLEN characters. May be == from
+  @param from   'Packed' directory name (may contain ~)
+
+  @details
+  - Uses normalize_dirname()
+  - Expands ~/... to home_dir/...
+  - Resolves MySQL's fake "foo.sym" symbolic directory names (if USE_SYMDIR)
+  - Changes a UNIX filename to system filename (replaces / with \ on windows)
+
+  @returns
    Length of new directory name (= length of to)
 */
 
@@ -291,19 +333,8 @@
   char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
   DBUG_ENTER("unpack_dirname");
 
-  (void) intern_filename(buff,from);		/* Change to intern name */
-  length= (uint) strlen(buff);			/* Fix that '/' is last */
-  if (length &&
-#ifdef FN_DEVCHAR
-      buff[length-1] != FN_DEVCHAR &&
-#endif
-      buff[length-1] != FN_LIBCHAR && buff[length-1] != '/')
-  {
-    buff[length]=FN_LIBCHAR;
-    buff[length+1]= '\0';
-  }
+  length= normalize_dirname(buff, from);
 
-  length=cleanup_dirname(buff,buff);
   if (buff[0] == FN_HOMELIB)
   {
     suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
@@ -312,7 +343,7 @@
       length-=(uint) (suffix-buff)-1;
       if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN)
       {
-	if (tilde_expansion[h_length-1] == FN_LIBCHAR)
+	if ((h_length > 0) && (tilde_expansion[h_length-1] == FN_LIBCHAR))
 	  h_length--;
 	if (buff+h_length < suffix)
 	  bmove(buff+h_length,suffix,length);

=== modified file 'mysys/my_alloc.c'
--- a/mysys/my_alloc.c	2007-04-18 20:50:32 +0000
+++ b/mysys/my_alloc.c	2008-08-11 16:10:00 +0000
@@ -202,7 +202,7 @@
     {
       if (mem_root->error_handler)
 	(*mem_root->error_handler)();
-      return((gptr) 0);				/* purecov: inspected */
+      DBUG_RETURN((gptr) 0);			/* purecov: inspected */
     }
     mem_root->block_num++;
     next->next= *prev;

=== modified file 'mysys/my_symlink.c'
--- a/mysys/my_symlink.c	2006-12-23 19:17:15 +0000
+++ b/mysys/my_symlink.c	2008-08-26 08:32:43 +0000
@@ -106,38 +106,47 @@
 #define BUFF_LEN FN_LEN
 #endif
 
+
+int my_is_symlink(const char *filename __attribute__((unused)))
+{
+#if defined (HAVE_LSTAT) && defined (S_ISLNK)
+  struct stat stat_buff;
+  return !lstat(filename, &stat_buff) && S_ISLNK(stat_buff.st_mode);
+#elif defined (_WIN32)
+  DWORD dwAttr = GetFileAttributes(filename);
+  return (dwAttr != INVALID_FILE_ATTRIBUTES) &&
+    (dwAttr & FILE_ATTRIBUTE_REPARSE_POINT);
+#else  /* No symlinks */
+  return 0;
+#endif
+}
+
+
 int my_realpath(char *to, const char *filename,
 		myf MyFlags __attribute__((unused)))
 {
 #if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH)
   int result=0;
   char buff[BUFF_LEN];
-  struct stat stat_buff;
+  char *ptr;
   DBUG_ENTER("my_realpath");
 
-  if (!(MyFlags & MY_RESOLVE_LINK) ||
-      (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
-  {
-    char *ptr;
-    DBUG_PRINT("info",("executing realpath"));
-    if ((ptr=realpath(filename,buff)))
-    {
+  DBUG_PRINT("info",("executing realpath"));
+  if ((ptr=realpath(filename,buff)))
       strmake(to,ptr,FN_REFLEN-1);
-    }
-    else
-    {
-      /*
-	Realpath didn't work;  Use my_load_path() which is a poor substitute
-	original name but will at least be able to resolve paths that starts
-	with '.'.
-      */
-      DBUG_PRINT("error",("realpath failed with errno: %d", errno));
-      my_errno=errno;
-      if (MyFlags & MY_WME)
-	my_error(EE_REALPATH, MYF(0), filename, my_errno);
-      my_load_path(to, filename, NullS);
-      result= -1;
-    }
+  else
+  {
+    /*
+      Realpath didn't work;  Use my_load_path() which is a poor substitute
+      original name but will at least be able to resolve paths that starts
+      with '.'.
+    */
+    DBUG_PRINT("error",("realpath failed with errno: %d", errno));
+    my_errno=errno;
+    if (MyFlags & MY_WME)
+      my_error(EE_REALPATH, MYF(0), filename, my_errno);
+    my_load_path(to, filename, NullS);
+    result= -1;
   }
   DBUG_RETURN(result);
 #else

=== modified file 'mysys/thr_lock.c'
--- a/mysys/thr_lock.c	2007-08-05 09:17:07 +0000
+++ b/mysys/thr_lock.c	2008-08-25 13:18:52 +0000
@@ -333,10 +333,10 @@
 void thr_lock_delete(THR_LOCK *lock)
 {
   DBUG_ENTER("thr_lock_delete");
-  VOID(pthread_mutex_destroy(&lock->mutex));
   pthread_mutex_lock(&THR_LOCK_lock);
   thr_lock_thread_list=list_delete(thr_lock_thread_list,&lock->list);
   pthread_mutex_unlock(&THR_LOCK_lock);
+  pthread_mutex_destroy(&lock->mutex);
   DBUG_VOID_RETURN;
 }
 

=== modified file 'netware/BUILD/compile-linux-tools'
--- a/netware/BUILD/compile-linux-tools	2006-04-03 15:54:09 +0000
+++ b/netware/BUILD/compile-linux-tools	2008-08-06 13:25:03 +0000
@@ -53,6 +53,9 @@
 # so the file will be linked
 (cd sql; make sql_yacc.cc)
 
+# we need initilizing SQL files.
+(cd netware; make test_db.sql init_db.sql)
+
 # copying required linux tools
 cp extra/comp_err extra/comp_err.linux
 cp libmysql/conf_to_src libmysql/conf_to_src.linux

=== modified file 'netware/BUILD/nwbootstrap'
--- a/netware/BUILD/nwbootstrap	2006-11-28 17:36:53 +0000
+++ b/netware/BUILD/nwbootstrap	2008-08-06 13:25:03 +0000
@@ -91,8 +91,8 @@
 echo "starting build..."
 
 # check for bk and repo_dir
-bk help > /dev/null
-repo_dir=`bk root $repo_dir`
+bzr help > /dev/null
+repo_dir=`bzr root $repo_dir`
 cd $repo_dir
 doc_dir="$repo_dir/../mysqldoc"
 
@@ -100,7 +100,7 @@
 temp_dir="$build_dir/mysql-$$.tmp"
 
 # export the bk tree
-command="bk export";
+command="bzr export";
 if test $revision; then command="$command -r$revision"; fi
 command="$command $temp_dir"
 echo "exporting $repo_dir..."
@@ -178,6 +178,8 @@
 # build linux tools
 echo "compiling linux tools..."
 ./netware/BUILD/compile-linux-tools
+test -f ./netware/init_db.sql  # this must exist
+test -f ./netware/test_db.sql  # this must exist
 
 # compile
 if test $build

=== modified file 'netware/Makefile.am'
--- a/netware/Makefile.am	2007-08-24 21:40:36 +0000
+++ b/netware/Makefile.am	2008-08-06 13:25:03 +0000
@@ -103,8 +103,7 @@
 	@echo "CREATE DATABASE mysql;" > $@;
 	@echo "CREATE DATABASE test;" >> $@;
 	@echo "use mysql;" >> $@;
-	@cat $(top_srcdir)/scripts/mysql_system_tables.sql \
-	     $(top_srcdir)/scripts/mysql_system_tables_fix.sql >> $@;
+	@cat $(top_srcdir)/scripts/mysql_system_tables.sql >> $@;
 
 # Build test_db.sql from init_db.sql plus
 # some test data

=== modified file 'netware/mysql_install_db.c'
--- a/netware/mysql_install_db.c	2006-04-03 01:37:43 +0000
+++ b/netware/mysql_install_db.c	2008-08-06 13:25:03 +0000
@@ -324,9 +324,10 @@
 ******************************************************************************/
 int mysql_install_db(int argc, char *argv[])
 {
-	arg_list_t al;
-	int i, j, err;
-	char skip;
+  arg_list_t al;
+  int i, j, err;
+  char skip;
+  struct stat info;
   
   // private options
   static char *private_options[] =
@@ -363,6 +364,15 @@
 	add_arg(&al, "--skip-innodb");
 	add_arg(&al, "--skip-bdb");
 
+  if ((err = stat(sql_file, &info)) != 0)
+  {
+    printf("ERROR - %s:\n", strerror(errno));
+    printf("\t%s\n\n", sql_file);
+    // free args
+    free_args(&al);
+    exit(-1);
+  }
+
   // spawn mysqld
   err = spawn(mysqld, &al, TRUE, sql_file, out_log, err_log);
 
@@ -395,9 +405,9 @@
 	// install the database
   if (mysql_install_db(argc, argv))
   {
-    printf("ERROR - The database creation failed!\n");
+    printf("ERROR - Failed to create the database!\n");
     printf("        %s\n", strerror(errno));
-    printf("See the following log for more infomration:\n");
+    printf("See the following log for more information:\n");
     printf("\t%s\n\n", err_log);
     exit(-1);
   }

=== modified file 'scripts/make_binary_distribution.sh'
--- a/scripts/make_binary_distribution.sh	2008-04-28 19:53:52 +0000
+++ b/scripts/make_binary_distribution.sh	2008-06-27 17:12:42 +0000
@@ -61,6 +61,7 @@
 system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'`
 system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'`
 system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'`
+system=`echo $system | sed -e 's/darwin9.*/osx10.5/g'`
 system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'`
 system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'`
 system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'`

=== modified file 'scripts/mysql_system_tables.sql'
--- a/scripts/mysql_system_tables.sql	2007-04-26 14:48:53 +0000
+++ b/scripts/mysql_system_tables.sql	2008-07-31 09:28:04 +0000
@@ -2,6 +2,7 @@
 -- The system tables of MySQL Server
 --
 
+set sql_mode='';
 set storage_engine=myisam;
 
 CREATE TABLE IF NOT EXISTS db (   Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';

=== modified file 'sql/field.h'
--- a/sql/field.h	2008-05-06 16:43:46 +0000
+++ b/sql/field.h	2008-08-27 21:10:37 +0000
@@ -48,7 +48,8 @@
   Field(const Item &);				/* Prevent use of these */
   void operator=(Field &);
 public:
-  static void *operator new(size_t size) {return (void*) sql_alloc((uint) size); }
+  static void *operator new(size_t size) throw ()
+  { return (void*) sql_alloc((uint) size); }
   static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
 
   char		*ptr;			// Position to field in record
@@ -137,7 +138,7 @@
   virtual bool eq(Field *field)
   {
     return (ptr == field->ptr && null_ptr == field->null_ptr &&
-            null_bit == field->null_bit);
+            null_bit == field->null_bit && field->type() == type());
   }
   virtual bool eq_def(Field *field);
   
@@ -1488,7 +1489,6 @@
   bool eq(Field *field)
   {
     return (Field::eq(field) &&
-            field->type() == type() &&
             bit_ptr == ((Field_bit *)field)->bit_ptr &&
             bit_ofs == ((Field_bit *)field)->bit_ofs);
   }

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2008-03-12 07:59:15 +0000
+++ b/sql/filesort.cc	2008-07-15 14:13:21 +0000
@@ -402,6 +402,56 @@
   DBUG_RETURN(tmp);
 }
 
+#ifndef DBUG_OFF
+/*
+  Print a text, SQL-like record representation into dbug trace.
+
+  Note: this function is a work in progress: at the moment
+   - column read bitmap is ignored (can print garbage for unused columns)
+   - there is no quoting
+*/
+static void dbug_print_record(TABLE *table, bool print_rowid)
+{
+  char buff[1024];
+  Field **pfield;
+  String tmp(buff,sizeof(buff),&my_charset_bin);
+  DBUG_LOCK_FILE;
+  
+  fprintf(DBUG_FILE, "record (");
+  for (pfield= table->field; *pfield ; pfield++)
+    fprintf(DBUG_FILE, "%s%s", (*pfield)->field_name, (pfield[1])? ", ":"");
+  fprintf(DBUG_FILE, ") = ");
+
+  fprintf(DBUG_FILE, "(");
+  for (pfield= table->field; *pfield ; pfield++)
+  {
+    Field *field=  *pfield;
+
+    if (field->is_null())
+      fwrite("NULL", sizeof(char), 4, DBUG_FILE);
+   
+    if (field->type() == MYSQL_TYPE_BIT)
+      (void) field->val_int_as_str(&tmp, 1);
+    else
+      field->val_str(&tmp);
+
+    fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);
+    if (pfield[1])
+      fwrite(", ", sizeof(char), 2, DBUG_FILE);
+  }
+  fprintf(DBUG_FILE, ")");
+  if (print_rowid)
+  {
+    fprintf(DBUG_FILE, " rowid ");
+    for (uint i=0; i < table->file->ref_length; i++)
+    {
+      fprintf(DBUG_FILE, "%x", (uchar)table->file->ref[i]);
+    }
+  }
+  fprintf(DBUG_FILE, "\n");
+  DBUG_UNLOCK_FILE;
+}
+#endif 
 
 /* 
   Search after sort_keys and write them into tempfile.
@@ -475,25 +525,23 @@
 		    current_thd->variables.read_buff_size);
   }
 
-  READ_RECORD read_record_info;
   if (quick_select)
   {
     if (select->quick->reset())
       DBUG_RETURN(HA_POS_ERROR);
-    init_read_record(&read_record_info, current_thd, select->quick->head,
-                     select, 1, 1);
   }
 
   for (;;)
   {
     if (quick_select)
     {
-      if ((error= read_record_info.read_record(&read_record_info)))
+      if ((error= select->quick->get_next()))
       {
         error= HA_ERR_END_OF_FILE;
         break;
       }
       file->position(sort_form->record[0]);
+      DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
     }
     else					/* Not quick-select */
     {
@@ -550,15 +598,7 @@
     if (thd->net.report_error)
       break;
   }
-  if (quick_select)
-  {
-    /*
-      index_merge quick select uses table->sort when retrieving rows, so free
-      resoures it has allocated.
-    */
-    end_read_record(&read_record_info);
-  }
-  else
+  if (!quick_select)
   {
     (void) file->extra(HA_EXTRA_NO_CACHE);	/* End cacheing of records */
     if (!next_pos)

=== modified file 'sql/ha_federated.cc'
--- a/sql/ha_federated.cc	2008-03-29 07:52:16 +0000
+++ b/sql/ha_federated.cc	2008-08-15 06:40:05 +0000
@@ -405,6 +405,9 @@
 bool federated_db_init()
 {
   DBUG_ENTER("federated_db_init");
+  /* the federated engine can be disabled by a command line option */
+  if (have_federated_db == SHOW_OPTION_DISABLED)
+    DBUG_RETURN(TRUE);
   if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
     goto error;
   if (hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
@@ -728,7 +731,10 @@
     old_ptr= (my_ptrdiff_t) (record - table->record[0]);
     (*field)->move_field(old_ptr);
     if (!row[x])
+    {
       (*field)->set_null();
+      (*field)->reset();
+    }
     else
     {
       (*field)->set_notnull();

=== modified file 'sql/ha_innodb.cc'
--- a/sql/ha_innodb.cc	2008-03-29 07:52:16 +0000
+++ b/sql/ha_innodb.cc	2008-07-31 21:47:57 +0000
@@ -244,8 +244,10 @@
   (char*) &export_vars.innodb_buffer_pool_pages_flushed,  SHOW_LONG},
   {"buffer_pool_pages_free",
   (char*) &export_vars.innodb_buffer_pool_pages_free,     SHOW_LONG},
+#ifdef UNIV_DEBUG
   {"buffer_pool_pages_latched",
   (char*) &export_vars.innodb_buffer_pool_pages_latched,  SHOW_LONG},
+#endif /* UNIV_DEBUG */
   {"buffer_pool_pages_misc",
   (char*) &export_vars.innodb_buffer_pool_pages_misc,     SHOW_LONG},
   {"buffer_pool_pages_total",
@@ -4250,7 +4252,7 @@
 	int		error;
 	uint		keynr	= active_index;
 	DBUG_ENTER("rnd_pos");
-	DBUG_DUMP("key", (uchar *)pos, ref_length);
+	DBUG_DUMP("key", (uchar*) pos, ref_length);
 
 	statistic_increment(current_thd->status_var.ha_read_rnd_count,
 			    &LOCK_status);
@@ -6882,6 +6884,12 @@
 	from a table when no table has been locked in ::external_lock(). */
 	prebuilt->trx->n_mysql_tables_in_use++;
 
+	/* Since we will perform a MySQL SELECT query to determine the
+	auto-inc value, set prebuilt->sql_stat_start = TRUE so that it
+	is performed like any normal SELECT, regardless of the context
+	we come here. */
+        prebuilt->sql_stat_start = TRUE;
+
 	error = index_last(table->record[1]);
 
 	prebuilt->trx->n_mysql_tables_in_use--;

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2008-04-21 22:53:12 +0000
+++ b/sql/item.cc	2008-08-20 09:49:28 +0000
@@ -429,8 +429,11 @@
   Item_result restype= result_type();
 
   if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
-    return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag),
-               DECIMAL_MAX_PRECISION);
+  {
+    uint prec= 
+      my_decimal_length_to_precision(max_length, decimals, unsigned_flag);
+    return min(prec, DECIMAL_MAX_PRECISION);
+  }
   return min(max_length, DECIMAL_MAX_PRECISION);
 }
 
@@ -5013,21 +5016,28 @@
   if (!ptr)
     return;
   str_value.set(ptr, max_length, &my_charset_bin);
-  ptr+= max_length - 1;
-  ptr[1]= 0;                     // Set end null for string
-  for (; end >= str; end--)
+
+  if (max_length > 0)
   {
-    if (power == 256)
+    ptr+= max_length - 1;
+    ptr[1]= 0;                     // Set end null for string
+    for (; end >= str; end--)
     {
-      power= 1;
-      *ptr--= bits;
-      bits= 0;     
+      if (power == 256)
+      {
+        power= 1;
+        *ptr--= bits;
+        bits= 0;
+      }
+      if (*end == '1')
+        bits|= power;
+      power<<= 1;
     }
-    if (*end == '1')
-      bits|= power; 
-    power<<= 1;
+    *ptr= (char) bits;
   }
-  *ptr= (char) bits;
+  else
+    ptr[0]= 0;
+
   collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
   fixed= 1;
 }
@@ -5754,6 +5764,10 @@
     field->table_name= table_name;
   if (db_name)
     field->db_name= db_name;
+  if (orig_field_name)
+    field->org_col_name= orig_field_name;
+  if (orig_table_name)
+    field->org_table_name= orig_table_name;
 }
 
 
@@ -6831,8 +6845,9 @@
   if (Field::result_merge_type(fld_type) == DECIMAL_RESULT)
   {
     decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
-    int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
-                       + decimals, DECIMAL_MAX_PRECISION);
+    int item_int_part= item->decimal_int_part();
+    int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
+    int precision= min(item_prec, DECIMAL_MAX_PRECISION);
     unsigned_flag&= item->unsigned_flag;
     max_length= my_decimal_precision_to_length(precision, decimals,
                                                unsigned_flag);

=== modified file 'sql/item.h'
--- a/sql/item.h	2008-03-12 07:59:15 +0000
+++ b/sql/item.h	2008-08-15 20:13:27 +0000
@@ -439,9 +439,9 @@
   Item(const Item &);			/* Prevent use of these */
   void operator=(Item &);
 public:
-  static void *operator new(size_t size)
+  static void *operator new(size_t size) throw ()
   { return (void*) sql_alloc((uint) size); }
-  static void *operator new(size_t size, MEM_ROOT *mem_root)
+  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
   { return (void*) alloc_root(mem_root, (uint) size); }
   static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
   static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
@@ -1817,7 +1817,7 @@
 public:
   Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
     Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
-    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
+    { name=(char*) header; max_length= length * collation.collation->mbmaxlen; }
   void make_field(Send_field *field);
 };
 

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2008-03-28 18:02:27 +0000
+++ b/sql/item_cmpfunc.cc	2008-07-30 11:07:37 +0000
@@ -2098,8 +2098,11 @@
 
 uint Item_func_ifnull::decimal_precision() const
 {
-  int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
-  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
+  int arg0_int_part= args[0]->decimal_int_part();
+  int arg1_int_part= args[1]->decimal_int_part();
+  int max_int_part= max(arg0_int_part, arg1_int_part);
+  int precision= max_int_part + decimals;
+  return min(precision, DECIMAL_MAX_PRECISION);
 }
 
 
@@ -2281,8 +2284,9 @@
 
 uint Item_func_if::decimal_precision() const
 {
-  int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
-                 decimals);
+  int arg1_prec= args[1]->decimal_int_part();
+  int arg2_prec= args[2]->decimal_int_part();
+  int precision=max(arg1_prec,arg2_prec) + decimals;
   return min(precision, DECIMAL_MAX_PRECISION);
 }
 

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2008-03-29 15:50:46 +0000
+++ b/sql/item_func.cc	2008-07-30 11:07:37 +0000
@@ -1156,9 +1156,10 @@
 void Item_func_additive_op::result_precision()
 {
   decimals= max(args[0]->decimals, args[1]->decimals);
-  int max_int_part= max(args[0]->decimal_precision() - args[0]->decimals,
-                        args[1]->decimal_precision() - args[1]->decimals);
-  int precision= min(max_int_part + 1 + decimals, DECIMAL_MAX_PRECISION);
+  int arg1_int= args[0]->decimal_precision() - args[0]->decimals;
+  int arg2_int= args[1]->decimal_precision() - args[1]->decimals;
+  int est_prec= max(arg1_int, arg2_int) + 1 + decimals;
+  int precision= min(est_prec, DECIMAL_MAX_PRECISION);
 
   /* Integer operations keep unsigned_flag if one of arguments is unsigned */
   if (result_type() == INT_RESULT)
@@ -1267,8 +1268,8 @@
   else
     unsigned_flag= args[0]->unsigned_flag & args[1]->unsigned_flag;
   decimals= min(args[0]->decimals + args[1]->decimals, DECIMAL_MAX_SCALE);
-  int precision= min(args[0]->decimal_precision() + args[1]->decimal_precision(),
-                     DECIMAL_MAX_PRECISION);
+  uint est_prec = args[0]->decimal_precision() + args[1]->decimal_precision();
+  uint precision= min(est_prec, DECIMAL_MAX_PRECISION);
   max_length= my_decimal_precision_to_length(precision, decimals,unsigned_flag);
 }
 
@@ -1315,8 +1316,8 @@
 
 void Item_func_div::result_precision()
 {
-  uint precision=min(args[0]->decimal_precision() + prec_increment,
-                     DECIMAL_MAX_PRECISION);
+  uint arg_prec= args[0]->decimal_precision() + prec_increment;
+  uint precision=min(arg_prec, DECIMAL_MAX_PRECISION);
   /* Integer operations keep unsigned_flag if one of arguments is unsigned */
   if (result_type() == INT_RESULT)
     unsigned_flag= args[0]->unsigned_flag | args[1]->unsigned_flag;

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2008-05-13 15:27:46 +0000
+++ b/sql/item_strfunc.cc	2008-07-10 23:51:58 +0000
@@ -3258,7 +3258,8 @@
 
 /* number of 100-nanosecond intervals between
    1582-10-15 00:00:00.00 and 1970-01-01 00:00:00.00 */
-#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * 1000 * 10 )
+#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * \
+                          1000 * 1000 * 10)
 
 #define UUID_VERSION      0x1000
 #define UUID_VARIANT      0x8000
@@ -3317,24 +3318,64 @@
     set_clock_seq_str();
   }
 
-  ulonglong tv=my_getsystime() + UUID_TIME_OFFSET + nanoseq;
-  if (unlikely(tv < uuid_time))
-    set_clock_seq_str();
-  else if (unlikely(tv == uuid_time))
-  {
-    /* special protection from low-res system clocks */
-    nanoseq++;
-    tv++;
-  }
-  else
-  {
+  ulonglong tv= my_getsystime() + UUID_TIME_OFFSET + nanoseq;
+
+  if (likely(tv > uuid_time))
+  {
+    /*
+      Current time is ahead of last timestamp, as it should be.
+      If we "borrowed time", give it back, just as long as we
+      stay ahead of the previous timestamp.
+    */
     if (nanoseq)
     {
-      tv-=nanoseq;
-      nanoseq=0;
-    }
-    DBUG_ASSERT(tv > uuid_time);
-  }
+      DBUG_ASSERT((tv > uuid_time) && (nanoseq > 0));
+      /*
+        -1 so we won't make tv= uuid_time for nanoseq >= (tv - uuid_time)
+      */
+      ulong delta= min(nanoseq, (ulong) (tv - uuid_time -1));
+      tv-= delta;
+      nanoseq-= delta;
+    }
+  }
+  else
+  {
+    if (unlikely(tv == uuid_time))
+    {
+      /*
+        For low-res system clocks. If several requests for UUIDs
+        end up on the same tick, we add a nano-second to make them
+        different.
+        ( current_timestamp + nanoseq * calls_in_this_period )
+        may end up > next_timestamp; this is OK. Nonetheless, we'll
+        try to unwind nanoseq when we get a chance to.
+        If nanoseq overflows, we'll start over with a new numberspace
+        (so the if() below is needed so we can avoid the ++tv and thus
+        match the follow-up if() if nanoseq overflows!).
+      */
+      if (likely(++nanoseq))
+        ++tv;
+    }
+
+    if (unlikely(tv <= uuid_time))
+    {
+      /*
+        If the admin changes the system clock (or due to Daylight
+        Saving Time), the system clock may be turned *back* so we
+        go through a period once more for which we already gave out
+        UUIDs.  To avoid duplicate UUIDs despite potentially identical
+        times, we make a new random component.
+        We also come here if the nanoseq "borrowing" overflows.
+        In either case, we throw away any nanoseq borrowing since it's
+        irrelevant in the new numberspace.
+      */
+      set_clock_seq_str();
+      tv= my_getsystime() + UUID_TIME_OFFSET;
+      nanoseq= 0;
+      DBUG_PRINT("uuid",("making new numberspace"));
+    }
+  }
+
   uuid_time=tv;
   pthread_mutex_unlock(&LOCK_uuid_generator);
 

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2008-03-21 14:10:15 +0000
+++ b/sql/log.cc	2008-07-24 12:28:21 +0000
@@ -1193,6 +1193,7 @@
   int error;
   bool exit_loop= 0;
   LOG_INFO log_info;
+  THD *thd= current_thd;
   DBUG_ENTER("purge_logs");
   DBUG_PRINT("info",("to_log= %s",to_log));
 
@@ -1218,10 +1219,13 @@
         /*
           It's not fatal if we can't stat a log file that does not exist;
           If we could not stat, we won't delete.
-        */     
-        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
-                            log_info.log_file_name);
+        */
+        if (thd)
+        {
+          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+                              log_info.log_file_name);
+        }
         sql_print_information("Failed to execute my_stat on file '%s'",
 			      log_info.log_file_name);
         my_errno= 0;
@@ -1231,13 +1235,24 @@
         /*
           Other than ENOENT are fatal
         */
-        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
-                            ER_BINLOG_PURGE_FATAL_ERR,
-                            "a problem with getting info on being purged %s; "
-                            "consider examining correspondence "
-                            "of your binlog index file "
-                            "to the actual binlog files",
-                            log_info.log_file_name);
+        if (thd)
+        {
+          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                              ER_BINLOG_PURGE_FATAL_ERR,
+                              "a problem with getting info on being purged %s; "
+                              "consider examining correspondence "
+                              "of your binlog index file "
+                              "to the actual binlog files",
+                              log_info.log_file_name);
+        }
+        else
+        {
+            sql_print_information("Failed to delete log file '%s'; "
+                                  "consider examining correspondence "
+                                  "of your binlog index file "
+                                  "to the actual binlog files",
+                                  log_info.log_file_name);
+        }
         error= LOG_INFO_FATAL;
         goto err;
       }
@@ -1254,22 +1269,36 @@
       {
         if (my_errno == ENOENT) 
         {
-          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
-                              log_info.log_file_name);
+          if (thd)
+          {
+            push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                                ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+                                log_info.log_file_name);
+          }
           sql_print_information("Failed to delete file '%s'",
                                 log_info.log_file_name);
           my_errno= 0;
         }
         else
         {
-          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
-                              ER_BINLOG_PURGE_FATAL_ERR,
-                              "a problem with deleting %s; "
-                              "consider examining correspondence "
-                              "of your binlog index file "
-                              "to the actual binlog files",
-                              log_info.log_file_name);
+          if (thd)
+          {
+            push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                                ER_BINLOG_PURGE_FATAL_ERR,
+                                "a problem with deleting %s; "
+                                "consider examining correspondence "
+                                "of your binlog index file "
+                                "to the actual binlog files",
+                                log_info.log_file_name);
+          }
+          else
+          {
+            sql_print_information("Failed to delete file '%s'; "
+                                  "consider examining correspondence "
+                                  "of your binlog index file "
+                                  "to the actual binlog files",
+                                  log_info.log_file_name);
+          }
           error= LOG_INFO_FATAL;
           goto err;
         }
@@ -1316,7 +1345,8 @@
   int error;
   LOG_INFO log_info;
   MY_STAT stat_area;
-
+  THD *thd= current_thd;
+  
   DBUG_ENTER("purge_logs_before_date");
 
   pthread_mutex_lock(&LOCK_index);
@@ -1338,12 +1368,15 @@
       {
         /*
           It's not fatal if we can't stat a log file that does not exist.
-        */     
-        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                            ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
-                            log_info.log_file_name);
-	sql_print_information("Failed to execute my_stat on file '%s'",
-			      log_info.log_file_name);
+        */ 
+        if (thd)
+        {
+          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+                              log_info.log_file_name);
+        }
+        sql_print_information("Failed to execute my_stat on file '%s'",
+                              log_info.log_file_name);
         my_errno= 0;
       }
       else
@@ -1351,13 +1384,21 @@
         /*
           Other than ENOENT are fatal
         */
-        push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
-                            ER_BINLOG_PURGE_FATAL_ERR,
-                            "a problem with getting info on being purged %s; "
-                            "consider examining correspondence "
-                            "of your binlog index file "
-                            "to the actual binlog files",
-                            log_info.log_file_name);
+        if (thd)
+        {
+          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                              ER_BINLOG_PURGE_FATAL_ERR,
+                              "a problem with getting info on being purged %s; "
+                              "consider examining correspondence "
+                              "of your binlog index file "
+                              "to the actual binlog files",
+                              log_info.log_file_name);
+        }
+        else
+        {
+          sql_print_information("Failed to delete log file '%s'",
+                                log_info.log_file_name);
+        }
         error= LOG_INFO_FATAL;
         goto err;
       }
@@ -1371,22 +1412,33 @@
         if (my_errno == ENOENT) 
         {
           /* It's not fatal even if we can't delete a log file */
-          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                              ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
-                              log_info.log_file_name);
+          if (thd)
+          {
+              push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                                  ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
+                                  log_info.log_file_name);
+          }
           sql_print_information("Failed to delete file '%s'",
                                 log_info.log_file_name);
           my_errno= 0;
         }
         else
         {
-          push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
-                              ER_BINLOG_PURGE_FATAL_ERR,
-                              "a problem with deleting %s; "
-                              "consider examining correspondence "
-                              "of your binlog index file "
-                              "to the actual binlog files",
-                              log_info.log_file_name);
+          if (thd)
+          {
+            push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                                ER_BINLOG_PURGE_FATAL_ERR,
+                                "a problem with deleting %s; "
+                                "consider examining correspondence "
+                                "of your binlog index file "
+                                "to the actual binlog files",
+                                log_info.log_file_name);
+          }
+          else
+          {
+            sql_print_information("Failed to delete log file '%s'",
+                                  log_info.log_file_name); 
+          }
           error= LOG_INFO_FATAL;
           goto err;
         }

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2008-03-18 12:38:12 +0000
+++ b/sql/log_event.cc	2008-07-07 07:58:27 +0000
@@ -4154,8 +4154,14 @@
   /*
     Item_func_set_user_var can't substitute something else on its place =>
     0 can be passed as last argument (reference on item)
+
+    Fix_fields() can fail, in which case a call of update_hash() might
+    crash the server, so if fix fields fails, we just return with an
+    error.
   */
-  e.fix_fields(thd, 0);
+  if (e.fix_fields(thd, 0))
+    return 1;
+
   /*
     A variable can just be considered as a table with
     a single record and with a single column. Thus, like

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2008-03-28 11:31:52 +0000
+++ b/sql/mysql_priv.h	2008-08-26 08:32:43 +0000
@@ -1264,6 +1264,7 @@
 	    mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[],
 	    mysql_unpacked_real_data_home[],
             def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
+extern int mysql_unpacked_real_data_home_len;
 #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
 extern MY_TMPDIR mysql_tmpdir_list;
 extern const char *command_name[];
@@ -1342,6 +1343,9 @@
 extern my_bool opt_large_pages;
 extern uint opt_large_page_size;
 
+extern char *opt_plugin_dir_ptr;
+extern char opt_plugin_dir[FN_REFLEN];
+
 extern MYSQL_LOG mysql_log,mysql_slow_log,mysql_bin_log;
 extern FILE *bootstrap_file;
 extern int bootstrap_error;
@@ -1557,8 +1561,8 @@
 int test_if_number(char *str,int *res,bool allow_wildcards);
 void change_byte(byte *,uint,char,char);
 void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
-		      SQL_SELECT *select,
-		      int use_record_cache, bool print_errors);
+		      SQL_SELECT *select, int use_record_cache, 
+                      bool print_errors, bool disable_rr_cache);
 void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 
                           bool print_error, uint idx);
 void end_read_record(READ_RECORD *info);
@@ -1764,6 +1768,8 @@
 #define check_stack_overrun(A, B, C) 0
 #endif
 
+extern "C" int test_if_data_home_dir(const char *dir);
+
 #endif /* MYSQL_CLIENT */
 
 #endif

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2008-06-03 10:12:37 +0000
+++ b/sql/mysqld.cc	2008-08-26 08:32:43 +0000
@@ -324,6 +324,9 @@
 
 /* static variables */
 
+char opt_plugin_dir[FN_REFLEN];
+char *opt_plugin_dir_ptr;
+
 static bool lower_case_table_names_used= 0;
 static bool volatile select_thread_in_use, signal_thread_in_use;
 static bool volatile ready_to_exit;
@@ -477,6 +480,7 @@
      *opt_init_file, *opt_tc_log_file,
      mysql_unpacked_real_data_home[FN_REFLEN],
      def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
+int mysql_unpacked_real_data_home_len;
 char *mysql_data_home= mysql_real_data_home;
 const key_map key_map_empty(0);
 key_map key_map_full(0);                        // Will be initialized later
@@ -4984,6 +4988,7 @@
   OPT_OLD_STYLE_USER_LIMITS,
   OPT_LOG_SLOW_ADMIN_STATEMENTS,
   OPT_TABLE_LOCK_WAIT_TIMEOUT,
+  OPT_PLUGIN_DIR,
   OPT_PORT_OPEN_TIMEOUT,
   OPT_MERGE,
   OPT_INNODB_ROLLBACK_ON_TIMEOUT,
@@ -6216,6 +6221,10 @@
    (gptr*) &global_system_variables.optimizer_search_depth,
    (gptr*) &max_system_variables.optimizer_search_depth,
    0, GET_ULONG, OPT_ARG, MAX_TABLES+1, 0, MAX_TABLES+2, 0, 1, 0},
+  {"plugin_dir", OPT_PLUGIN_DIR,
+   "Directory for plugins.",
+   (gptr*) &opt_plugin_dir_ptr, (gptr*) &opt_plugin_dir_ptr, 0,
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
    {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
     "The size of the buffer that is allocated when preloading indexes",
     (gptr*) &global_system_variables.preload_buff_size,
@@ -6696,6 +6705,7 @@
   /* Things reset to zero */
   opt_skip_slave_start= opt_reckless_slave = 0;
   mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
+  myisam_test_invalid_symlink= test_if_data_home_dir;
   opt_log= opt_slow_log= 0;
   opt_update_log= 0;
   opt_bin_log= 0;
@@ -7746,13 +7756,19 @@
     pos[1]= 0;
   }
   convert_dirname(mysql_real_data_home,mysql_real_data_home,NullS);
-  (void) fn_format(buff, mysql_real_data_home, "", "",
-                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
-  (void) unpack_dirname(mysql_unpacked_real_data_home, buff);
+  my_realpath(mysql_unpacked_real_data_home, mysql_real_data_home, MYF(0));
+  mysql_unpacked_real_data_home_len= strlen(mysql_unpacked_real_data_home);
+  if (mysql_unpacked_real_data_home[mysql_unpacked_real_data_home_len-1] == FN_LIBCHAR)
+    --mysql_unpacked_real_data_home_len;
+
+
   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);
   (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 :
+                                      "", "");
+  opt_plugin_dir_ptr= opt_plugin_dir;
 
   char *sharedir=get_relative_path(SHAREDIR);
   if (test_if_hard_path(sharedir))

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2008-03-28 18:02:27 +0000
+++ b/sql/opt_range.cc	2008-08-25 17:02:54 +0000
@@ -6494,7 +6494,7 @@
   QUICK_RANGE_SELECT* cur_quick;
   int result;
   Unique *unique;
-  DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::prepare_unique");
+  DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge");
 
   /* We're going to just read rowids. */
   if (head->file->extra(HA_EXTRA_KEYREAD))
@@ -6565,13 +6565,17 @@
 
   }
 
-  /* ok, all row ids are in Unique */
+  /*
+    Ok all rowids are in the Unique now. The next call will initialize
+    head->sort structure so it can be used to iterate through the rowids
+    sequence.
+  */
   result= unique->get(head);
   delete unique;
   doing_pk_scan= FALSE;
-  /* start table scan */
-  init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1, 1);
-  /* index_merge currently doesn't support "using index" at all */
+
+  /* Start the rnd_pos() scan. */
+  init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE);
   head->file->extra(HA_EXTRA_NO_KEYREAD);
 
   DBUG_RETURN(result);
@@ -6601,6 +6605,7 @@
   {
     result= HA_ERR_END_OF_FILE;
     end_read_record(&read_record);
+    free_io_cache(head);
     /* All rows from Unique have been retrieved, do a clustered PK scan */
     if (pk_quick_select)
     {
@@ -7094,9 +7099,17 @@
 
 QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q,
                                      uint used_key_parts_arg)
- : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges)
+ : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges), 
+  used_key_parts (used_key_parts_arg)
 {
   QUICK_RANGE *r;
+  /* 
+    Use default MRR implementation for reverse scans. No table engine
+    currently can do an MRR scan with output in reverse index order.
+  */
+  multi_range_length= 0;
+  multi_range= NULL;
+  multi_range_buff= NULL;
 
   QUICK_RANGE **pr= (QUICK_RANGE**)ranges.buffer;
   QUICK_RANGE **end_range= pr + ranges.elements;
@@ -7136,10 +7149,11 @@
     int result;
     if (last_range)
     {						// Already read through key
-      result = ((last_range->flag & EQ_RANGE)
-		? file->index_next_same(record, (byte*) last_range->min_key,
-					last_range->min_length) :
-		file->index_prev(record));
+      result = ((last_range->flag & EQ_RANGE && 
+                 used_key_parts <= head->key_info[index].key_parts) ? 
+                file->index_next_same(record, (byte*) last_range->min_key,
+                                      last_range->min_length) :
+                file->index_prev(record));
       if (!result)
       {
 	if (cmp_prev(*rev_it.ref()) == 0)
@@ -7163,7 +7177,9 @@
       continue;
     }
 
-    if (last_range->flag & EQ_RANGE)
+    if (last_range->flag & EQ_RANGE &&
+        used_key_parts <= head->key_info[index].key_parts)
+
     {
       result= file->index_read(record, (byte*) last_range->max_key,
                                last_range->max_length, HA_READ_KEY_EXACT);
@@ -7171,6 +7187,8 @@
     else
     {
       DBUG_ASSERT(last_range->flag & NEAR_MAX ||
+                  (last_range->flag & EQ_RANGE && 
+                   used_key_parts > head->key_info[index].key_parts) ||
                   range_reads_after_key(last_range));
       result=file->index_read(record, (byte*) last_range->max_key,
 			      last_range->max_length,
@@ -7268,54 +7286,6 @@
 }
 
 
-/* TRUE if we are reading over a key that may have a NULL value */
-
-#ifdef NOT_USED
-bool QUICK_SELECT_DESC::test_if_null_range(QUICK_RANGE *range_arg,
-					   uint used_key_parts)
-{
-  uint offset, end;
-  KEY_PART *key_part = key_parts,
-           *key_part_end= key_part+used_key_parts;
-
-  for (offset= 0,  end = min(range_arg->min_length, range_arg->max_length) ;
-       offset < end && key_part != key_part_end ;
-       offset+= key_part++->store_length)
-  {
-    if (!memcmp((char*) range_arg->min_key+offset,
-		(char*) range_arg->max_key+offset,
-		key_part->store_length))
-      continue;
-
-    if (key_part->null_bit && range_arg->min_key[offset])
-      return 1;				// min_key is null and max_key isn't
-    // Range doesn't cover NULL. This is ok if there is no more null parts
-    break;
-  }
-  /*
-    If the next min_range is > NULL, then we can use this, even if
-    it's a NULL key
-    Example:  SELECT * FROM t1 WHERE a = 2 AND b >0 ORDER BY a DESC,b DESC;
-
-  */
-  if (key_part != key_part_end && key_part->null_bit)
-  {
-    if (offset >= range_arg->min_length || range_arg->min_key[offset])
-      return 1;					// Could be null
-    key_part++;
-  }
-  /*
-    If any of the key parts used in the ORDER BY could be NULL, we can't
-    use the key to sort the data.
-  */
-  for (; key_part != key_part_end ; key_part++)
-    if (key_part->null_bit)
-      return 1;					// Covers null part
-  return 0;
-}
-#endif
-
-
 void QUICK_RANGE_SELECT::add_info_string(String *str)
 {
   KEY *key_info= head->key_info + index;

=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h	2007-02-21 12:07:08 +0000
+++ b/sql/opt_range.h	2008-08-25 17:02:54 +0000
@@ -329,14 +329,7 @@
   void dbug_dump(int indent, bool verbose);
 #endif
 private:
-  /* Used only by QUICK_SELECT_DESC */
-  QUICK_RANGE_SELECT(const QUICK_RANGE_SELECT& org) : QUICK_SELECT_I()
-  {
-    bcopy(&org, this, sizeof(*this));
-    multi_range_length= 0;
-    multi_range= NULL;
-    multi_range_buff= NULL;
-  }
+  /* Default copy ctor used by QUICK_SELECT_DESC */
 };
 
 
@@ -667,12 +660,10 @@
   int get_type() { return QS_TYPE_RANGE_DESC; }
 private:
   bool range_reads_after_key(QUICK_RANGE *range);
-#ifdef NOT_USED
-  bool test_if_null_range(QUICK_RANGE *range, uint used_key_parts);
-#endif
   int reset(void) { rev_it.rewind(); return QUICK_RANGE_SELECT::reset(); }
   List<QUICK_RANGE> rev_ranges;
   List_iterator<QUICK_RANGE> rev_it;
+  uint used_key_parts;
 };
 
 

=== modified file 'sql/records.cc'
--- a/sql/records.cc	2007-10-17 16:08:58 +0000
+++ b/sql/records.cc	2008-07-15 14:13:21 +0000
@@ -72,11 +72,47 @@
 }
 
 
-/* init struct for read with info->read_record */
+/*
+  init struct for read with info->read_record 
+
+  SYNOPSIS
+    init_read_record()
+      info              OUT read structure
+      thd               Thread handle
+      table             Table the data [originally] comes from.
+      select            SQL_SELECT structure. We may select->quick or 
+                        select->file as data source
+      use_record_cache  Call file->extra_opt(HA_EXTRA_CACHE,...)
+                        if we're going to do sequential read and some
+                        additional conditions are satisfied.
+      print_error       Copy this to info->print_error
+      disable_rr_cache  Don't use rr_from_cache (used by sort-union
+                        index-merge which produces rowid sequences that 
+                        are already ordered)
+
+  DESCRIPTION
+    This function sets up reading data via one of the methods:
+
+    rr_unpack_from_tempfile  Unpack full records from sequential file
+    rr_unpack_from_buffer    ... or from buffer
+    
+    rr_from_tempfile         Read rowids from tempfile and get full records
+                             with handler->rnd_pos() calls.
+    rr_from_pointers         ... or get rowids from buffer
+    
+    rr_from_cache            Read a bunch of rowids from file, sort them, 
+                             get records in rowid order, return, repeat.
+
+    rr_quick                 Get data from QUICK_*_SELECT
+    
+    rr_sequential            Sequentially scan the table using
+                             handler->rnd_next() calls
+*/
 
 void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
 		      SQL_SELECT *select,
-		      int use_record_cache, bool print_error)
+		      int use_record_cache, bool print_error, 
+                      bool disable_rr_cache)
 {
   IO_CACHE *tempfile;
   DBUG_ENTER("init_read_record");
@@ -121,7 +157,8 @@
       it doesn't make sense to use cache - we don't read from the table
       and table->sort.io_cache is read sequentially
     */
-    if (!table->sort.addon_field &&
+    if (!disable_rr_cache &&
+        !table->sort.addon_field &&
         ! (specialflag & SPECIAL_SAFE_MODE) &&
 	thd->variables.read_rnd_buff_size &&
 	!(table->file->table_flags() & HA_FAST_KEY_READ) &&

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2008-03-28 18:02:27 +0000
+++ b/sql/set_var.cc	2008-08-25 12:11:59 +0000
@@ -1026,6 +1026,7 @@
   {sys_optimizer_search_depth.name,(char*) &sys_optimizer_search_depth,
    SHOW_SYS},
   {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
+  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
   {"port",                    (char*) &mysqld_port,                  SHOW_INT},
   {sys_preload_buff_size.name, (char*) &sys_preload_buff_size,      SHOW_SYS},
   {"protocol_version",        (char*) &protocol_version,            SHOW_INT},

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-04-10 00:34:38 +0000
+++ b/sql/share/errmsg.txt	2008-07-29 13:58:15 +0000
@@ -4737,7 +4737,7 @@
 	swe "Slav SQL tråden ignorerade frågan pga en replicate-*-table regel"
 ER_INCORRECT_GLOBAL_LOCAL_VAR  
 	eng "Variable '%-.64s' is a %s variable"
-	serbian "Incorrect foreign key definition for '%-.64s': %s"
+	serbian "Promenljiva '%-.64s' je %s promenljiva"
 	ger "Variable '%-.64s' ist eine %s-Variable"
 	spa "Variable '%-.64s' es una %s variable"
 	swe "Variabel '%-.64s' är av typ %s"

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2008-05-15 23:13:24 +0000
+++ b/sql/sp.cc	2008-07-14 21:41:30 +0000
@@ -443,11 +443,12 @@
     goto end;
 
   {
-    Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length());
-    thd->m_lip= &lip;
+    Parser_state parser_state(thd, defstr.c_ptr(), defstr.length());
+    thd->m_parser_state= &parser_state;
     lex_start(thd);
     thd->spcont= NULL;
     ret= MYSQLparse(thd);
+    thd->m_parser_state= NULL;
 
     if (ret == 0)
     {

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2008-05-15 23:13:24 +0000
+++ b/sql/sp_head.cc	2008-08-11 16:10:00 +0000
@@ -446,7 +446,7 @@
   init_sql_alloc(&own_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC);
   sp= (sp_head *) alloc_root(&own_root, size);
   if (sp == NULL)
-    return NULL;
+    DBUG_RETURN(NULL);
   sp->main_mem_root= own_root;
   DBUG_PRINT("info", ("mem_root 0x%lx", (ulong) &sp->mem_root));
   DBUG_RETURN(sp);
@@ -591,7 +591,7 @@
   const char *endp;                  /* Used to trim the end */
   /* During parsing, we must use thd->mem_root */
   MEM_ROOT *root= thd->mem_root;
-  Lex_input_stream *lip=thd->m_lip;
+  Lex_input_stream *lip= & thd->m_parser_state->m_lip;
 
   if (m_param_begin && m_param_end)
   {

=== modified file 'sql/sp_head.h'
--- a/sql/sp_head.h	2008-05-15 23:13:24 +0000
+++ b/sql/sp_head.h	2008-07-07 16:00:08 +0000
@@ -117,7 +117,6 @@
   create_field m_return_field_def; /* This is used for FUNCTIONs only. */
 
   const char *m_tmp_query;	// Temporary pointer to sub query string
-  uint m_old_cmq;		// Old CLIENT_MULTI_QUERIES value
   st_sp_chistics *m_chistics;
   ulong m_sql_mode;		// For SHOW CREATE and execution
   LEX_STRING m_qname;		// db.name

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2008-03-28 09:26:40 +0000
+++ b/sql/sql_acl.cc	2008-07-29 13:37:09 +0000
@@ -205,7 +205,8 @@
   acl_cache->clear(1);				// Clear locked hostname cache
 
   init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
-  init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0);
+  init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0, 
+                   FALSE);
   VOID(my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50));
   while (!(read_record_info.read_record(&read_record_info)))
   {
@@ -253,7 +254,7 @@
   end_read_record(&read_record_info);
   freeze_size(&acl_hosts);
 
-  init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0);
+  init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0,FALSE);
   VOID(my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100));
   password_length= table->field[2]->field_length /
     table->field[2]->charset()->mbmaxlen;
@@ -426,7 +427,7 @@
   end_read_record(&read_record_info);
   freeze_size(&acl_users);
 
-  init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0);
+  init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0,FALSE);
   VOID(my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100));
   while (!(read_record_info.read_record(&read_record_info)))
   {
@@ -5429,7 +5430,6 @@
 
   while ((tmp_user_name= user_list++))
   {
-    user_name= get_current_user(thd, tmp_user_name);
     if (!(user_name= get_current_user(thd, tmp_user_name)))
     {
       result= TRUE;

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2008-03-28 18:02:27 +0000
+++ b/sql/sql_cache.cc	2008-07-24 14:14:34 +0000
@@ -2516,7 +2516,7 @@
 	 tmp++)
       unlink_table(tmp);
   }
-  return (n);
+  return test(n);
 }
 
 /*

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2008-03-14 02:03:01 +0000
+++ b/sql/sql_class.cc	2008-07-14 21:41:30 +0000
@@ -177,7 +177,8 @@
    rand_used(0), time_zone_used(0),
    last_insert_id_used(0), last_insert_id_used_bin_log(0), insert_id_used(0),
    clear_next_insert_id(0), in_lock_tables(0), bootstrap(0),
-   derived_tables_processing(FALSE), spcont(NULL), m_lip(NULL)
+   derived_tables_processing(FALSE), spcont(NULL),
+   m_parser_state(NULL)
 {
   ulong tmp;
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2008-02-28 14:34:08 +0000
+++ b/sql/sql_class.h	2008-07-14 21:41:30 +0000
@@ -28,7 +28,7 @@
 class Format_description_log_event;
 class sp_rcontext;
 class sp_cache;
-class Lex_input_stream;
+class Parser_state;
 
 enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
 enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
@@ -1575,13 +1575,11 @@
   } binlog_evt_union;
 
   /**
-    Character input stream consumed by the lexical analyser,
-    used during parsing.
-    Note that since the parser is not re-entrant, we keep only one input
-    stream here. This member is valid only when executing code during parsing,
-    and may point to invalid memory after that.
+    Internal parser state.
+    Note that since the parser is not re-entrant, we keep only one parser
+    state here. This member is valid only when executing code during parsing.
   */
-  Lex_input_stream *m_lip;
+  Parser_state *m_parser_state;
 
   THD();
   ~THD();

=== modified file 'sql/sql_cursor.cc'
--- a/sql/sql_cursor.cc	2008-02-20 19:45:24 +0000
+++ b/sql/sql_cursor.cc	2008-08-11 09:40:54 +0000
@@ -111,7 +111,8 @@
   select_result *result; /* the result object of the caller (PS or SP) */
 public:
   Materialized_cursor *materialized_cursor;
-  Select_materialize(select_result *result_arg) :result(result_arg) {}
+  Select_materialize(select_result *result_arg) :result(result_arg),
+    materialized_cursor(0) {}
   virtual bool send_fields(List<Item> &list, uint flags);
 };
 
@@ -155,6 +156,7 @@
   if (! (sensitive_cursor= new (thd->mem_root) Sensitive_cursor(thd, result)))
   {
     delete result_materialize;
+    result_materialize= NULL;
     return 1;
   }
 
@@ -212,6 +214,7 @@
     if ((rc= materialized_cursor->open(0)))
     {
       delete materialized_cursor;
+      materialized_cursor= NULL;
       goto err_open;
     }
 

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2008-03-27 11:52:55 +0000
+++ b/sql/sql_delete.cc	2008-07-15 14:13:21 +0000
@@ -214,7 +214,7 @@
     DBUG_RETURN(TRUE);
   }
   if (usable_index==MAX_KEY)
-    init_read_record(&info,thd,table,select,1,1);
+    init_read_record(&info, thd, table, select, 1, 1, FALSE);
   else
     init_read_record_idx(&info, thd, table, 1, usable_index);
 
@@ -772,7 +772,7 @@
     }
 
     READ_RECORD	info;
-    init_read_record(&info,thd,table,NULL,0,1);
+    init_read_record(&info, thd, table, NULL, 0, 1, FALSE);
     /*
       Ignore any rows not found in reference tables as they may already have
       been deleted by foreign key handling

=== modified file 'sql/sql_help.cc'
--- a/sql/sql_help.cc	2007-10-17 16:08:58 +0000
+++ b/sql/sql_help.cc	2008-07-15 14:13:21 +0000
@@ -181,7 +181,7 @@
   int count= 0;
 
   READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, topics, select,1,0);
+  init_read_record(&read_record_info, thd, topics, select, 1, 0, FALSE);
   while (!read_record_info.read_record(&read_record_info))
   {
     if (!select->cond->val_int())		// Doesn't match like
@@ -221,7 +221,7 @@
   int count= 0;
 
   READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, keywords, select,1,0);
+  init_read_record(&read_record_info, thd, keywords, select, 1, 0, FALSE);
   while (!read_record_info.read_record(&read_record_info) && count<2)
   {
     if (!select->cond->val_int())		// Dosn't match like
@@ -346,7 +346,7 @@
 
   DBUG_ENTER("search_categories");
 
-  init_read_record(&read_record_info, thd, categories, select,1,0);
+  init_read_record(&read_record_info, thd, categories, select,1,0,FALSE);
   while (!read_record_info.read_record(&read_record_info))
   {
     if (select && !select->cond->val_int())
@@ -380,7 +380,7 @@
   DBUG_ENTER("get_all_items_for_category");
 
   READ_RECORD read_record_info;
-  init_read_record(&read_record_info, thd, items, select,1,0);
+  init_read_record(&read_record_info, thd, items, select,1,0,FALSE);
   while (!read_record_info.read_record(&read_record_info))
   {
     if (!select->cond->val_int())

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2008-03-27 16:49:32 +0000
+++ b/sql/sql_lex.cc	2008-07-14 21:41:30 +0000
@@ -192,7 +192,6 @@
   lex->select_lex.order_list.empty();
   lex->select_lex.udf_list.empty();
   lex->current_select= &lex->select_lex;
-  lex->yacc_yyss=lex->yacc_yyvs=0;
   lex->sql_command= lex->orig_sql_command= SQLCOM_END;
   lex->duplicates= DUP_ERROR;
   lex->ignore= 0;
@@ -210,11 +209,16 @@
 
 void lex_end(LEX *lex)
 {
-  DBUG_ENTER("lex_end");
-  DBUG_PRINT("enter", ("lex: 0x%lx", (long) lex));
-  x_free(lex->yacc_yyss);
-  x_free(lex->yacc_yyvs);
-  DBUG_VOID_RETURN;
+  /* Empty in 5.0, non empty in 5.1 */
+}
+
+Yacc_state::~Yacc_state()
+{
+  if (yacc_yyss)
+  {
+    x_free(yacc_yyss);
+    x_free(yacc_yyvs);
+  }
 }
 
 
@@ -531,7 +535,7 @@
   uint length;
   enum my_lex_states state;
   THD *thd= (THD *)yythd;
-  Lex_input_stream *lip= thd->m_lip;
+  Lex_input_stream *lip= & thd->m_parser_state->m_lip;
   LEX *lex= thd->lex;
   YYSTYPE *yylval=(YYSTYPE*) arg;
   CHARSET_INFO *cs= thd->charset();
@@ -1010,21 +1014,8 @@
       yySkip();
       return (SET_VAR);
     case MY_LEX_SEMICOLON:			// optional line terminator
-      if (yyPeek())
-      {
-        if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS) && 
-            !lip->stmt_prepare_mode)
-        {
-	  lex->safe_to_cache_query= 0;
-          lip->found_semicolon= lip->ptr;
-          thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
-          lip->next_state=     MY_LEX_END;
-          return (END_OF_INPUT);
-        }
-        state= MY_LEX_CHAR;		// Return ';'
-	break;
-      }
-      /* fall true */
+      state= MY_LEX_CHAR;               // Return ';'
+      break;
     case MY_LEX_EOL:
       if (lip->ptr >= lip->end_of_query)
       {
@@ -1039,7 +1030,7 @@
     case MY_LEX_END:
       lip->next_state=MY_LEX_END;
       return(0);			// We found end of input last time
-      
+
       /* Actually real shouldn't start with . but allow them anyhow */
     case MY_LEX_REAL_OR_POINT:
       if (my_isdigit(cs,yyPeek()))
@@ -1794,7 +1785,7 @@
 */
 
 st_lex::st_lex()
-  :result(0), yacc_yyss(0), yacc_yyvs(0),
+  :result(0),
    sql_command(SQLCOM_END)
 {
   reset_query_tables_list(TRUE);

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2008-03-27 16:49:32 +0000
+++ b/sql/sql_lex.h	2008-08-11 16:10:00 +0000
@@ -331,11 +331,11 @@
   bool no_table_names_allowed; /* used for global order by */
   bool no_error; /* suppress error message (convert it to warnings) */
 
-  static void *operator new(size_t size)
+  static void *operator new(size_t size) throw ()
   {
     return (void*) sql_alloc((uint) size);
   }
-  static void *operator new(size_t size, MEM_ROOT *mem_root)
+  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
   { return (void*) alloc_root(mem_root, (uint) size); }
   static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
   static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
@@ -1004,7 +1004,6 @@
   LEX_STRING comment, ident;
   LEX_USER *grant_user;
   XID *xid;
-  gptr yacc_yyss,yacc_yyvs;
   THD *thd;
   CHARSET_INFO *charset, *underscore_charset;
   bool text_string_is_7bit;
@@ -1290,6 +1289,59 @@
   }
 } LEX;
 
+
+/**
+  The internal state of the syntax parser.
+  This object is only available during parsing,
+  and is private to the syntax parser implementation (sql_yacc.yy).
+*/
+class Yacc_state
+{
+public:
+  Yacc_state()
+    : yacc_yyss(NULL), yacc_yyvs(NULL)
+  {}
+
+  ~Yacc_state();
+
+  /**
+    Bison internal state stack, yyss, when dynamically allocated using
+    my_yyoverflow().
+  */
+  gptr yacc_yyss;
+
+  /**
+    Bison internal semantic value stack, yyvs, when dynamically allocated using
+    my_yyoverflow().
+  */
+  gptr yacc_yyvs;
+
+  /*
+    TODO: move more attributes from the LEX structure here.
+  */
+};
+
+/**
+  Internal state of the parser.
+  The complete state consist of:
+  - state data used during lexical parsing,
+  - state data used during syntactic parsing.
+*/
+class Parser_state
+{
+public:
+  Parser_state(THD *thd, const char* buff, unsigned int length)
+    : m_lip(thd, buff, length), m_yacc()
+  {}
+
+  ~Parser_state()
+  {}
+
+  Lex_input_stream m_lip;
+  Yacc_state m_yacc;
+};
+
+
 struct st_lex_local: public st_lex
 {
   static void *operator new(size_t size) throw()

=== modified file 'sql/sql_list.h'
--- a/sql/sql_list.h	2007-03-29 06:35:28 +0000
+++ b/sql/sql_list.h	2008-08-11 16:10:00 +0000
@@ -27,7 +27,7 @@
   {
     return (void*) sql_alloc((uint) size);
   }
-  static void *operator new[](size_t size)
+  static void *operator new[](size_t size) throw ()
   {
     return (void*) sql_alloc((uint) size);
   }
@@ -466,7 +466,7 @@
 struct ilink
 {
   struct ilink **prev,*next;
-  static void *operator new(size_t size)
+  static void *operator new(size_t size) throw ()
   {
     return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE));
   }

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-03-21 15:23:17 +0000
+++ b/sql/sql_parse.cc	2008-08-26 08:32:43 +0000
@@ -76,7 +76,6 @@
 static bool append_file_to_dir(THD *thd, const char **filename_ptr,
 			       const char *table_name);
 static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
-static bool test_if_data_home_dir(const char *dir);
 
 const char *any_db="*any*";	// Special symbol for check_access
 
@@ -3044,13 +3043,13 @@
 
     if (test_if_data_home_dir(lex->create_info.data_file_name))
     {
-      my_error(ER_WRONG_ARGUMENTS,MYF(0),"DATA DIRECORY");
+      my_error(ER_WRONG_ARGUMENTS,MYF(0),"DATA DIRECTORY");
       res= -1;
       break;
     }
     if (test_if_data_home_dir(lex->create_info.index_file_name))
     {
-      my_error(ER_WRONG_ARGUMENTS,MYF(0),"INDEX DIRECORY");
+      my_error(ER_WRONG_ARGUMENTS,MYF(0),"INDEX DIRECTORY");
       res= -1;
       break;
     }
@@ -5875,29 +5874,35 @@
 
 bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
 {
-  LEX	*lex= current_thd->lex;
+  Yacc_state *state= & current_thd->m_parser_state->m_yacc;
   ulong old_info=0;
+  DBUG_ASSERT(state);
   if ((uint) *yystacksize >= MY_YACC_MAX)
     return 1;
-  if (!lex->yacc_yyvs)
+  if (!state->yacc_yyvs)
     old_info= *yystacksize;
   *yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
-  if (!(lex->yacc_yyvs= (char*)
-	my_realloc((gptr) lex->yacc_yyvs,
+  if (!(state->yacc_yyvs= (char*)
+        my_realloc(state->yacc_yyvs,
 		   *yystacksize*sizeof(**yyvs),
 		   MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) ||
-      !(lex->yacc_yyss= (char*)
-	my_realloc((gptr) lex->yacc_yyss,
+      !(state->yacc_yyss= (char*)
+        my_realloc(state->yacc_yyss,
 		   *yystacksize*sizeof(**yyss),
 		   MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))))
     return 1;
   if (old_info)
-  {						// Copy old info from stack
-    memcpy(lex->yacc_yyss, (gptr) *yyss, old_info*sizeof(**yyss));
-    memcpy(lex->yacc_yyvs, (gptr) *yyvs, old_info*sizeof(**yyvs));
+  {
+    /*
+      Only copy the old stack on the first call to my_yyoverflow(),
+      when replacing a static stack (YYINITDEPTH) by a dynamic stack.
+      For subsequent calls, my_realloc already did preserve the old stack.
+    */
+    memcpy(state->yacc_yyss, *yyss, old_info*sizeof(**yyss));
+    memcpy(state->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
   }
-  *yyss=(short*) lex->yacc_yyss;
-  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
+  *yyss= (short*) state->yacc_yyss;
+  *yyvs= (YYSTYPE*) state->yacc_yyvs;
   return 0;
 }
 
@@ -6136,11 +6141,12 @@
     sp_cache_flush_obsolete(&thd->sp_proc_cache);
     sp_cache_flush_obsolete(&thd->sp_func_cache);
 
-    Lex_input_stream lip(thd, inBuf, length);
-    thd->m_lip= &lip;
+    Parser_state parser_state(thd, inBuf, length);
+    thd->m_parser_state= &parser_state;
 
     int err= MYSQLparse(thd);
-    *found_semicolon= lip.found_semicolon;
+    *found_semicolon= parser_state.m_lip.found_semicolon;
+    thd->m_parser_state= NULL;
 
     if (!err && ! thd->is_fatal_error)
     {
@@ -6165,10 +6171,16 @@
             PROCESSLIST.
             Note that we don't need LOCK_thread_count to modify query_length.
           */
-          if (lip.found_semicolon &&
-              (thd->query_length= (ulong)(lip.found_semicolon - thd->query)))
+          if (parser_state.m_lip.found_semicolon &&
+              (thd->query_length= (ulong)(parser_state.m_lip.found_semicolon
+                                          - thd->query)))
             thd->query_length--;
           /* Actually execute the query */
+          if (*found_semicolon)
+          {
+            lex->safe_to_cache_query= 0;
+            thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
+          }
           lex->set_trg_event_type_for_tables();
           mysql_execute_command(thd);
           query_cache_end_of_result(thd);
@@ -6220,11 +6232,13 @@
   bool error= 0;
   DBUG_ENTER("mysql_test_parse_for_slave");
 
-  Lex_input_stream lip(thd, inBuf, length);
-  thd->m_lip= &lip;
+  Parser_state parser_state(thd, inBuf, length);
+  thd->m_parser_state= &parser_state;
+
   lex_start(thd);
   mysql_reset_thd_for_next_command(thd);
   int err= MYSQLparse((void*) thd);
+  thd->m_parser_state= NULL;
 
   if (!err && ! thd->is_fatal_error &&
       all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
@@ -7054,11 +7068,23 @@
       thd->thread_stack= (char*) &tmp_thd;
       thd->store_globals();
     }
+    
     if (thd)
     {
-      (void)acl_reload(thd);
-      (void)grant_reload(thd);
+      bool reload_acl_failed= acl_reload(thd);
+      bool reload_grants_failed= grant_reload(thd);
+
+      if (reload_acl_failed || reload_grants_failed)
+      {
+        result= 1;
+        /*
+          When an error is returned, my_message may have not been called and
+          the client will hang waiting for a response.
+        */
+        my_error(ER_UNKNOWN_ERROR, MYF(0), "FLUSH PRIVILEGES failed");
+      }
     }
+
     if (tmp_thd)
     {
       delete tmp_thd;
@@ -7144,8 +7170,10 @@
       tmp_write_to_binlog= 0;
       if (lock_global_read_lock(thd))
 	return 1;                               // Killed
-      result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1,
-                                 tables);
+      if (close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1,
+                                 tables))
+          result= 1;
+      
       if (make_global_read_lock_block_commit(thd)) // Killed
       {
         /* Don't leave things in a half-locked state */
@@ -7154,7 +7182,10 @@
       }
     }
     else
-      result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables);
+    {
+      if (close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables))
+        result= 1;
+    }
     my_dbopt_cleanup();
   }
   if (options & REFRESH_HOSTS)
@@ -7178,8 +7209,8 @@
 #ifdef OPENSSL
    if (options & REFRESH_DES_KEY_FILE)
    {
-     if (des_key_file)
-       result=load_des_key_file(des_key_file);
+     if (des_key_file && load_des_key_file(des_key_file))
+         result= 1;
    }
 #endif
 #ifdef HAVE_REPLICATION
@@ -7290,7 +7321,7 @@
   if (lex->current_select != &lex->select_lex)
   {
     char command[80];
-    Lex_input_stream *lip= thd->m_lip;
+    Lex_input_stream *lip= & thd->m_parser_state->m_lip;
     strmake(command, lip->yylval->symbol.str,
 	    min(lip->yylval->symbol.length, sizeof(command)-1));
     my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
@@ -7914,10 +7945,12 @@
     1	error  
 */
 
-static bool test_if_data_home_dir(const char *dir)
+C_MODE_START
+
+int test_if_data_home_dir(const char *dir)
 {
-  char path[FN_REFLEN], conv_path[FN_REFLEN];
-  uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
+  char path[FN_REFLEN];
+  int dir_len;
   DBUG_ENTER("test_if_data_home_dir");
 
   if (!dir)
@@ -7925,21 +7958,27 @@
 
   (void) fn_format(path, dir, "", "",
                    (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
-  dir_len= unpack_dirname(conv_path, dir);
+  dir_len= strlen(path);
+  if (mysql_unpacked_real_data_home_len<= dir_len)
+  {
+    if (dir_len > mysql_unpacked_real_data_home_len &&
+        path[mysql_unpacked_real_data_home_len] != FN_LIBCHAR)
+      DBUG_RETURN(0);
 
-  if (home_dir_len <= dir_len)
-  {
     if (lower_case_file_system)
     {
-      if (!my_strnncoll(default_charset_info, (const uchar*) conv_path,
-                        home_dir_len,
+      if (!my_strnncoll(default_charset_info, (const uchar*) path,
+                        mysql_unpacked_real_data_home_len,
                         (const uchar*) mysql_unpacked_real_data_home,
-                        home_dir_len))
+                        mysql_unpacked_real_data_home_len))
         DBUG_RETURN(1);
     }
-    else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
+    else if (!memcmp(path, mysql_unpacked_real_data_home,
+                     mysql_unpacked_real_data_home_len))
       DBUG_RETURN(1);
   }
   DBUG_RETURN(0);
 }
 
+C_MODE_END
+

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2008-03-27 11:52:55 +0000
+++ b/sql/sql_prepare.cc	2008-07-14 21:41:30 +0000
@@ -2849,12 +2849,13 @@
   old_stmt_arena= thd->stmt_arena;
   thd->stmt_arena= this;
 
-  Lex_input_stream lip(thd, thd->query, thd->query_length);
-  lip.stmt_prepare_mode= TRUE;
-  thd->m_lip= &lip;
+  Parser_state parser_state(thd, thd->query, thd->query_length);
+  parser_state.m_lip.stmt_prepare_mode= TRUE;
+  thd->m_parser_state= &parser_state;
   lex_start(thd);
   lex->safe_to_cache_query= FALSE;
   int err= MYSQLparse((void *)thd);
+  thd->m_parser_state= NULL;
   lex->set_trg_event_type_for_tables();
 
   error= err || thd->is_fatal_error ||

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2008-05-16 14:05:55 +0000
+++ b/sql/sql_select.cc	2008-08-27 13:03:17 +0000
@@ -1724,7 +1724,8 @@
     if (!items1)
     {
       items1= items0 + all_fields.elements;
-      if (sort_and_group || curr_tmp_table->group)
+      if (sort_and_group || curr_tmp_table->group ||
+          tmp_table_param.precomputed_group_by)
       {
 	if (change_to_use_tmp_fields(thd, items1,
 				     tmp_fields_list1, tmp_all_fields1,
@@ -6469,6 +6470,12 @@
     if (tmp_join)
       tmp_table_param.copy_field= 0;
     group_fields.delete_elements();
+    /* 
+      Ensure that the above delete_elements() would not be called
+      twice for the same list.
+    */
+    if (tmp_join && tmp_join != this)
+      tmp_join->group_fields= group_fields;
     /*
       We can't call delete_elements() on copy_funcs as this will cause
       problems in free_elements() as some of the elements are then deleted.
@@ -9253,6 +9260,8 @@
   MI_COLUMNDEF *recinfo;
   uint total_uneven_bit_length= 0;
   bool force_copy_fields= param->force_copy_fields;
+  /* Treat sum functions as normal ones when loose index scan is used. */
+  save_sum_fields|= param->precomputed_group_by;
   DBUG_ENTER("create_tmp_table");
   DBUG_PRINT("enter",("distinct: %d  save_sum_fields: %d  rows_limit: %lu  group: %d",
 		      (int) distinct, (int) save_sum_fields,
@@ -11309,7 +11318,7 @@
   if (tab->select && tab->select->quick && tab->select->quick->reset())
     return 1;
   init_read_record(&tab->read_record, tab->join->thd, tab->table,
-		   tab->select,1,1);
+		   tab->select,1,1, FALSE);
   return (*tab->read_record.read_record)(&tab->read_record);
 }
 
@@ -12088,26 +12097,25 @@
 }
 
 
-/*****************************************************************************
-  Test if one can use the key to resolve ORDER BY
-
-  SYNOPSIS
-    test_if_order_by_key()
-    order		Sort order
-    table		Table to sort
-    idx			Index to check
-    used_key_parts	Return value for used key parts.
-
-
-  NOTES
-    used_key_parts is set to correct key parts used if return value != 0
-    (On other cases, used_key_part may be changed)
-
-  RETURN
-    1   key is ok.
-    0   Key can't be used
-    -1  Reverse key can be used
-*****************************************************************************/
+/**
+  Test if a key can be used to resolve ORDER BY
+
+  used_key_parts is set to correct key parts used if return value != 0
+  (On other cases, used_key_part may be changed).
+  Note that the value may actually be greater than the number of index 
+  key parts. This can happen for storage engines that have the primary 
+  key parts as a suffix for every secondary key.
+
+  @param      order		Sort order
+  @param      table		Table to sort
+  @param      idx		Index to check
+  @param[out] used_key_parts	Return value for used key parts.
+
+  @return indication if the key can be used for sorting
+    @retval 1   key can be used for reading data in order.
+    @retval 0   Key can't be used
+    @retval -1  Reverse read on the key can be used
+*/
 
 static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
 				uint *used_key_parts)
@@ -12172,11 +12180,27 @@
     reverse=flag;				// Remember if reverse
     key_part++;
   }
-  *used_key_parts= on_primary_key ? table->key_info[idx].key_parts :
-    (uint) (key_part - table->key_info[idx].key_part);
-  if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) &
-                         HA_READ_PREV))
-    reverse= 0;                                 // Index can't be used
+  if (on_primary_key)
+  {
+    uint used_key_parts_secondary= table->key_info[idx].key_parts;
+    uint used_key_parts_pk=
+      (uint) (key_part - table->key_info[table->s->primary_key].key_part);
+    *used_key_parts= used_key_parts_pk + used_key_parts_secondary;
+
+    if (reverse == -1 &&
+        (!(table->file->index_flags(idx, used_key_parts_secondary - 1, 1) &
+           HA_READ_PREV) ||
+         !(table->file->index_flags(table->s->primary_key,
+                                    used_key_parts_pk - 1, 1) & HA_READ_PREV)))
+      reverse= 0;                               // Index can't be used
+  }
+  else
+  {
+    *used_key_parts= (uint) (key_part - table->key_info[idx].key_part);
+    if (reverse == -1 && 
+        !(table->file->index_flags(idx, *used_key_parts-1, 1) & HA_READ_PREV))
+      reverse= 0;                               // Index can't be used
+  }
   DBUG_RETURN(reverse);
 }
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2008-03-19 13:32:28 +0000
+++ b/sql/sql_show.cc	2008-08-15 20:13:27 +0000
@@ -3666,12 +3666,10 @@
       /* Don't let unimplemented types pass through. Could be a grave error. */
       DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
 
-      /* this should be changed when Item_empty_string is fixed(in 4.1) */
-      if (!(item= new Item_empty_string("", 0, cs)))
+      if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
       {
         DBUG_RETURN(0);
       }
-      item->max_length= fields_info->field_length * cs->mbmaxlen;
       item->set_name(fields_info->field_name,
                      strlen(fields_info->field_name), cs);
       break;

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2007-01-22 12:10:46 +0000
+++ b/sql/sql_string.h	2008-08-11 16:10:00 +0000
@@ -78,7 +78,7 @@
     Alloced_length=str.Alloced_length; alloced=0; 
     str_charset=str.str_charset;
   }
-  static void *operator new(size_t size, MEM_ROOT *mem_root)
+  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
   { return (void*) alloc_root(mem_root, (uint) size); }
   static void operator delete(void *ptr_arg,size_t size)
   { TRASH(ptr_arg, size); }

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2008-05-12 16:01:13 +0000
+++ b/sql/sql_table.cc	2008-07-15 14:13:21 +0000
@@ -4177,7 +4177,7 @@
     current query id
   */
   from->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
-  init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1,1);
+  init_read_record(&info, thd, from, (SQL_SELECT *) 0, 1, 1, FALSE);
   if (ignore)
     to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
   thd->row_count= 0;

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2007-09-04 22:40:27 +0000
+++ b/sql/sql_trigger.cc	2008-07-14 21:41:30 +0000
@@ -968,11 +968,13 @@
 
         thd->variables.sql_mode= (ulong)*trg_sql_mode;
 
-        Lex_input_stream lip(thd, trg_create_str->str, trg_create_str->length);
-        thd->m_lip= &lip;
+        Parser_state parser_state(thd, trg_create_str->str,
+                                  trg_create_str->length);
+        thd->m_parser_state= &parser_state;
         lex_start(thd);
         thd->spcont= NULL;
         int err= MYSQLparse((void *)thd);
+        thd->m_parser_state= NULL;
 
         if (err || thd->is_fatal_error)
         {

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2007-11-09 10:41:50 +0000
+++ b/sql/sql_udf.cc	2008-08-25 12:11:59 +0000
@@ -176,7 +176,7 @@
   }
 
   table= tables.table;
-  init_read_record(&read_record_info, new_thd, table, NULL,1,0);
+  init_read_record(&read_record_info, new_thd, table, NULL,1,0,FALSE);
   while (!(error = read_record_info.read_record(&read_record_info)))
   {
     DBUG_PRINT("info",("init udf record"));
@@ -214,7 +214,17 @@
     void *dl = find_udf_dl(tmp->dl);
     if (dl == NULL)
     {
-      if (!(dl = dlopen(tmp->dl, RTLD_NOW)))
+      char dlpath[FN_REFLEN];
+      if (*opt_plugin_dir)
+        strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl,
+                 NullS);
+      else
+      {
+        strxnmov(dlpath, sizeof(dlpath)-1, tmp->dl, NullS);
+        push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
+                     "plugin_dir was not specified");
+      }
+      if (!(dl = dlopen(dlpath, RTLD_NOW)))
       {
 	/* Print warning to log */
 	sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl,errno,dlerror());
@@ -443,8 +453,18 @@
   }
   if (!(dl = find_udf_dl(udf->dl)))
   {
-    DBUG_PRINT("info", ("Calling dlopen, udf->dl: %s", udf->dl));
-    if (!(dl = dlopen(udf->dl, RTLD_NOW)))
+    char dlpath[FN_REFLEN];
+    if (*opt_plugin_dir)
+      strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", udf->dl,
+               NullS);
+    else
+    {
+      strxnmov(dlpath, sizeof(dlpath)-1, udf->dl, NullS);
+      push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
+                   "plugin_dir was not specified");
+    }
+    DBUG_PRINT("info", ("Calling dlopen, udf->dl: %s", dlpath));
+    if (!(dl = dlopen(dlpath, RTLD_NOW)))
     {
       DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
 			  udf->dl,errno,dlerror()));

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2008-05-18 09:21:25 +0000
+++ b/sql/sql_update.cc	2008-07-15 14:13:21 +0000
@@ -358,7 +358,7 @@
                Full index scan must be started with init_read_record_idx
       */
       if (used_index == MAX_KEY || (select && select->quick))
-        init_read_record(&info,thd,table,select,0,1);
+        init_read_record(&info, thd, table, select, 0, 1, FALSE);
       else
         init_read_record_idx(&info, thd, table, 1, used_index);
 
@@ -422,7 +422,7 @@
   
   if (select && select->quick && select->quick->reset())
         goto err;
-  init_read_record(&info,thd,table,select,0,1);
+  init_read_record(&info, thd, table, select, 0, 1, FALSE);
 
   updated= found= 0;
   thd->count_cuted_fields= CHECK_FIELD_WARN;		/* calc cuted fields */

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2008-05-08 07:41:22 +0000
+++ b/sql/sql_view.cc	2008-07-14 21:41:30 +0000
@@ -1081,8 +1081,7 @@
     char old_db_buf[NAME_LEN+1];
     LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
     bool dbchanged;
-    Lex_input_stream lip(thd, table->query.str, table->query.length);
-    thd->m_lip= &lip;
+    Parser_state parser_state(thd, table->query.str, table->query.length);
 
     /* 
       Use view db name as thread default database, in order to ensure
@@ -1091,6 +1090,7 @@
     if ((result= sp_use_new_db(thd, table->view_db, &old_db, 1, &dbchanged)))
       goto end;
 
+    thd->m_parser_state= &parser_state;
     lex_start(thd);
     view_select= &lex->select_lex;
     view_select->select_number= ++thd->select_number;
@@ -1125,6 +1125,7 @@
     CHARSET_INFO *save_cs= thd->variables.character_set_client;
     thd->variables.character_set_client= system_charset_info;
     res= MYSQLparse((void *)thd);
+    thd->m_parser_state= NULL;
 
     if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) ||
         (old_lex->sql_command == SQLCOM_SHOW_CREATE))

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-04-10 00:34:38 +0000
+++ b/sql/sql_yacc.yy	2008-08-11 16:10:00 +0000
@@ -23,6 +23,7 @@
 #define YYPARSE_PARAM yythd
 #define YYLEX_PARAM yythd
 #define YYTHD ((THD *)yythd)
+#define YYLIP (& YYTHD->m_parser_state->m_lip)
 
 #define MYSQL_YACC
 #define YYINITDEPTH 100
@@ -86,7 +87,7 @@
 void my_parse_error(const char *s)
 {
   THD *thd= current_thd;
-  Lex_input_stream *lip= thd->m_lip;
+  Lex_input_stream *lip= & thd->m_parser_state->m_lip;
 
   const char *yytext= lip->tok_start;
   /* Push an error into the error stack */
@@ -1203,21 +1204,54 @@
 
 
 query:
-	END_OF_INPUT
-	{
-	   THD *thd= YYTHD;
-	   if (!thd->bootstrap &&
-	      (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
-	   {
-	     my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
-	     MYSQL_YYABORT;
-	   }
-	   else
-	   {
-	     thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
-	   }
-	}
-	| verb_clause END_OF_INPUT {};
+          END_OF_INPUT
+          {
+            THD *thd= YYTHD;
+            if (!thd->bootstrap &&
+              (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT)))
+            {
+              my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0));
+              MYSQL_YYABORT;
+            }
+            thd->lex->sql_command= SQLCOM_EMPTY_QUERY;
+            YYLIP->found_semicolon= NULL;
+          }
+        | verb_clause
+          {
+            Lex_input_stream *lip = YYLIP;
+
+            if ((YYTHD->client_capabilities & CLIENT_MULTI_QUERIES) &&
+                ! lip->stmt_prepare_mode &&
+                ! (lip->ptr >= lip->end_of_query))
+            {
+              /*
+                We found a well formed query, and multi queries are allowed:
+                - force the parser to stop after the ';'
+                - mark the start of the next query for the next invocation
+                  of the parser.
+              */
+              lip->next_state= MY_LEX_END;
+              lip->found_semicolon= lip->ptr;
+            }
+            else
+            {
+              /* Single query, terminated. */
+              lip->found_semicolon= NULL;
+            }
+          }
+          ';'
+          opt_end_of_input
+        | verb_clause END_OF_INPUT
+          {
+            /* Single query, not terminated. */
+            YYLIP->found_semicolon= NULL;
+          }
+        ;
+
+opt_end_of_input:
+          /* empty */
+        | END_OF_INPUT
+        ;
 
 verb_clause:
 	  statement
@@ -1506,6 +1540,8 @@
 	  {
 	    LEX *lex=Lex;
             Key *key= new Key($2, $4.str, $5, 0, lex->col_list);
+            if (key == NULL)
+              MYSQL_YYABORT;
 
             lex->alter_info.key_list.push_back(key);
 	    lex->col_list.empty();
@@ -1565,6 +1601,8 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= new sp_name($1, $3, true);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    $$->init_qname(YYTHD);
 	  }
 	| ident
@@ -1580,8 +1618,9 @@
             if (lex->copy_db_to(&db.str, &db.length))
               MYSQL_YYABORT;
 	    $$= new sp_name(db, $1, false);
-            if ($$)
-	      $$->init_qname(YYTHD);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+	    $$->init_qname(YYTHD);
 	  }
 	;              
                
@@ -1832,6 +1871,8 @@
             if (!dflt_value_item)
             {
               dflt_value_item= new Item_null();
+              if (dflt_value_item == NULL)
+                MYSQL_YYABORT;
               /* QQ Set to the var_type with null_value? */
             }
             
@@ -1857,10 +1898,17 @@
             
               /* 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);
@@ -1894,6 +1942,8 @@
 	    sp_instr_hpush_jump *i=
               new sp_instr_hpush_jump(sp->instructions(), ctx, $2,
 	                              ctx->current_var_count());
+            if (i == NULL)
+              MYSQL_YYABORT;
 
 	    sp->add_instr(i);
 	    sp->push_backpatch(i, ctx->push_label((char *)"", 0));
@@ -1946,7 +1996,7 @@
 	    }
             i= new sp_instr_cpush(sp->instructions(), ctx, $5,
                                   ctx->current_cursor_count());
-	    if ( i==NULL )
+	    if (i == NULL)
               MYSQL_YYABORT;
             sp->add_instr(i);
 	    ctx->push_cursor(&$2);
@@ -2027,6 +2077,8 @@
 	  ulong_num
 	  {			/* mysql errno */
 	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              YYABORT;
 	    $$->type= sp_cond_type_t::number;
 	    $$->mysqlerr= $1;
 	  }
@@ -2038,6 +2090,8 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              YYABORT;
 	    $$->type= sp_cond_type_t::state;
 	    memcpy($$->sqlstate, $3.str, 5);
 	    $$->sqlstate[5]= '\0';
@@ -2066,16 +2120,22 @@
 	| SQLWARNING_SYM	/* SQLSTATEs 01??? */
 	  {
 	    $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t));
+            if ($$ == NULL)
+              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)
+              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)
+              YYABORT;
 	    $$->type= sp_cond_type_t::exception;
 	  }
 	;
@@ -2122,7 +2182,7 @@
 	  {
             THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
-            Lex_input_stream *lip= thd->m_lip;
+            Lex_input_stream *lip= YYLIP;
 
 	    if (lex->sphead->reset_lex(thd))
               MYSQL_YYABORT;
@@ -2132,7 +2192,7 @@
 	  {
             THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
-            Lex_input_stream *lip= thd->m_lip;
+            Lex_input_stream *lip= YYLIP;
 	    sp_head *sp= lex->sphead;
 
             sp->m_flags|= sp_get_flags_for_command(lex);
@@ -3051,6 +3111,8 @@
 	  {
 	    LEX *lex=Lex;
             Key *key= new Key($1, $2, $7 ? $7 : $3, 0, lex->col_list);
+            if (key == NULL)
+              MYSQL_YYABORT;
             lex->alter_info.key_list.push_back(key);
 
 	    lex->col_list.empty();		/* Alloced by sql_alloc */
@@ -3060,6 +3122,8 @@
 	    LEX *lex=Lex;
 	    const char *key_name= $3 ? $3:$1;
             Key *key= new Key($2, key_name, $4, 0, lex->col_list);
+            if (key == NULL)
+              MYSQL_YYABORT;
             lex->alter_info.key_list.push_back(key);
 	    lex->col_list.empty();		/* Alloced by sql_alloc */
 	  }
@@ -3073,10 +3137,14 @@
                                       lex->fk_delete_opt,
                                       lex->fk_update_opt,
                                       lex->fk_match_option);
+            if (key == NULL)
+              MYSQL_YYABORT;
             lex->alter_info.key_list.push_back(key);
             key= new Key(Key::MULTIPLE, key_name,
                          HA_KEY_ALG_UNDEF, 1,
                          lex->col_list);
+            if (key == NULL)
+              MYSQL_YYABORT;
             lex->alter_info.key_list.push_back(key);
 	    lex->col_list.empty();		/* Alloced by sql_alloc */
 	  }
@@ -3366,7 +3434,12 @@
 	;
 
 now_or_signed_literal:
-        NOW_SYM optional_braces { $$= new Item_func_now_local(); }
+        NOW_SYM optional_braces
+          {
+            $$= new Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | signed_literal { $$=$1; }
         ;
 
@@ -3492,8 +3565,21 @@
 	| '(' ref_list ')' opt_on_delete {};
 
 ref_list:
-	ref_list ',' ident	{ Lex->ref_list.push_back(new key_part_spec($3.str)); }
-	| ident			{ Lex->ref_list.push_back(new key_part_spec($1.str)); };
+          ref_list ',' ident
+          {
+            key_part_spec *key= new key_part_spec($3.str);
+            if (key == NULL)
+              MYSQL_YYABORT;
+            Lex->ref_list.push_back(key);
+          }
+        | ident
+          {
+            key_part_spec *key= new key_part_spec($1.str);
+            if (key == NULL)
+              MYSQL_YYABORT;
+            Lex->ref_list.push_back(key);
+          }
+        ;
 
 
 opt_on_delete:
@@ -3584,16 +3670,24 @@
 	| key_part order_dir		{ Lex->col_list.push_back($1); };
 
 key_part:
-	ident			{ $$=new key_part_spec($1.str); }
-	| ident '(' NUM ')'	
-        {
-          int key_part_len= atoi($3.str);
-          if (!key_part_len)
-          {
-            my_error(ER_KEY_PART_0, MYF(0), $1.str);
-          }
-          $$=new key_part_spec($1.str,(uint) key_part_len);
-        };
+          ident
+          {
+            $$= new key_part_spec($1.str);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| ident '(' NUM ')'
+          {
+            int key_part_len= atoi($3.str);
+            if (!key_part_len)
+            {
+              my_error(ER_KEY_PART_0, MYF(0), $1.str);
+            }
+            $$=new key_part_spec($1.str,(uint) key_part_len);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        ;
 
 opt_ident:
 	/* empty */	{ $$=(char*) 0; }	/* Defaultlength */
@@ -3763,8 +3857,10 @@
 	| 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
@@ -3774,15 +3870,19 @@
 	| 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
@@ -3800,14 +3900,19 @@
 	| 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_CHANGE_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_CHANGE_COLUMN_DEFAULT;
 	  }
 	| RENAME opt_to table_ident
@@ -4433,10 +4538,11 @@
 	| '*'
 	  {
 	    THD *thd= YYTHD;
-	    if (add_item_to_list(thd,
-                                 new Item_field(&thd->lex->current_select->
-                                                context,
-                                                NULL, NULL, "*")))
+            Item *item= new 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)++;
 	  };
@@ -4470,16 +4576,12 @@
 
 remember_name:
 	{
-          THD *thd= YYTHD;
-          Lex_input_stream *lip= thd->m_lip;
-          $$= (char*) lip->tok_start;
+          $$= (char*) YYLIP->tok_start;
         };
 
 remember_end:
 	{
-          THD *thd= YYTHD;
-          Lex_input_stream *lip= thd->m_lip;
-          $$=(char*) lip->tok_end;
+          $$=(char*) YYLIP->tok_end;
         };
 
 select_item2:
@@ -4547,12 +4649,16 @@
             {
               /* X OR Y */
               $$ = new (YYTHD->mem_root) Item_cond_or($1, $3);
+              if ($$ == NULL)
+                MYSQL_YYABORT;
             }
           }
         | expr XOR expr %prec XOR
           {
             /* XOR is a proprietary extension */
             $$ = new (YYTHD->mem_root) Item_cond_xor($1, $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         | expr and expr %prec AND_SYM
           {
@@ -4593,62 +4699,124 @@
             {
               /* 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 Item_func_isnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bool_pri IS not UNKNOWN_SYM %prec IS
-          { $$= new Item_func_isnotnull($1); }
+          {
+            $$= new 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 Item_func_isnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| bool_pri IS not NULL_SYM %prec IS
-          { $$= new Item_func_isnotnull($1); }
+          {
+            $$= new Item_func_isnotnull($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| bool_pri EQUAL_SYM predicate %prec EQUAL_SYM
-          { $$= new Item_func_equal($1,$3); }
+          {
+            $$= new 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 ;
 
 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 ')'
           {
@@ -4661,54 +4829,146 @@
             $$= item;
           }
 	| bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
-	  { $$= new Item_func_between($1,$3,$5); }
+	  {
+            $$= new 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);
+            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 Item_func_soundex($1);
+            Item *item4= new Item_func_soundex($4);
+            if ((item1 == NULL) || (item4 == NULL))
+              MYSQL_YYABORT;
+            $$= new 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 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 Item_func_like($1,$4,$5, Lex->escape_used);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new Item_func_not(item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| bit_expr REGEXP bit_expr
+          {
+            $$= new 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 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 Item_func_bit_or($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '&' bit_expr %prec '&'
-          { $$= new Item_func_bit_and($1,$3); }
+          {
+            $$= new 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 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 Item_func_shift_right($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '+' bit_expr %prec '+'
-          { $$= new Item_func_plus($1,$3); }
+          {
+            $$= new Item_func_plus($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '-' bit_expr %prec '-'
-          { $$= new Item_func_minus($1,$3); }
+          {
+            $$= new Item_func_minus($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '+' interval_expr interval %prec '+'
-          { $$= new Item_date_add_interval($1,$3,$4,0); }
+          {
+            $$= new Item_date_add_interval($1,$3,$4,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '-' interval_expr interval %prec '-'
-          { $$= new Item_date_add_interval($1,$3,$4,1); }
+          {
+            $$= new Item_date_add_interval($1,$3,$4,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '*' bit_expr %prec '*'
-          { $$= new Item_func_mul($1,$3); }
+          {
+            $$= new Item_func_mul($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '/' bit_expr %prec '/'
-          { $$= new Item_func_div($1,$3); }
+          {
+            $$= new Item_func_div($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '%' bit_expr %prec '%'
-          { $$= new Item_func_mod($1,$3); }
+          {
+            $$= new 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 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 Item_func_mod($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | bit_expr '^' bit_expr
-          { $$= new Item_func_bit_xor($1,$3); }
+          {
+            $$= new Item_func_bit_xor($1,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         | simple_expr
         ;
 
@@ -4738,67 +4998,118 @@
 	simple_ident
  	| simple_expr COLLATE_SYM ident_or_text %prec NEG
 	  {
-	    $$= new Item_func_set_collation($1,
-					    new Item_string($3.str,
-							    $3.length,
-                                                            YYTHD->charset()));
+            Item *item= new Item_string($3.str, $3.length, YYTHD->charset());
+            if (item == NULL)
+              MYSQL_YYABORT;
+	    $$= new Item_func_set_collation($1, item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| literal
 	| param_marker
 	| variable
 	| sum_expr
 	| simple_expr OR_OR_SYM simple_expr
-	  { $$= new Item_func_concat($1, $3); }
-	| '+' simple_expr %prec NEG	{ $$= $2; }
-	| '-' simple_expr %prec NEG	{ $$= new Item_func_neg($2); }
-	| '~' simple_expr %prec NEG	{ $$= new Item_func_bit_neg($2); }
-	| not2 simple_expr %prec NEG	{ $$= negate_expression(YYTHD, $2); }
+	  {
+            $$= new Item_func_concat($1, $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| '+' simple_expr %prec NEG
+          { $$= $2; }
+	| '-' simple_expr %prec NEG
+          {
+            $$= new Item_func_neg($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| '~' simple_expr %prec NEG
+          {
+            $$= new Item_func_bit_neg($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| not2 simple_expr %prec NEG
+          {
+            $$= negate_expression(YYTHD, $2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| '(' subselect ')'   
           { 
             $$= new Item_singlerow_subselect($2); 
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
 	| '(' expr ')'		{ $$= $2; }
 	| '(' expr ',' expr_list ')'
 	  {
 	    $4->push_front($2);
 	    $$= new Item_row(*$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| ROW_SYM '(' expr ',' expr_list ')'
 	  {
 	    $5->push_front($3);
 	    $$= new Item_row(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| EXISTS '(' subselect ')' 
           {
             $$= new 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);
-            Select->add_ftfunc_to_list((Item_func_match*)
-                                        ($$=new Item_func_match(*$2,$6))); }
-	| ASCII_SYM '(' expr ')' { $$= new Item_func_ascii($3); }
+          {
+            $2->push_front($5);
+            Item_func_match *item= new Item_func_match(*$2,$6);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            Select->add_ftfunc_to_list(item);
+            $$= item;
+          }
+	| ASCII_SYM '(' expr ')'
+          {
+            $$= new Item_func_ascii($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| BINARY simple_expr %prec NEG
 	  {
             $$= create_func_cast($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($3, $5, lex->length, lex->dec, lex->charset);
-            if (!$$)
+            if ($$ == NULL)
               MYSQL_YYABORT;
 	  }
 	| CASE_SYM opt_expr when_list opt_else END
-	  { $$= new Item_func_case(* $3, $2, $4 ); }
+	  {
+            $$= new Item_func_case(* $3, $2, $4 );
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CONVERT_SYM '(' expr ',' cast_type ')'
 	  {
 	    $$= create_func_cast($3, $5, Lex->length, Lex->dec, Lex->charset);
-            if (!$$)
+            if ($$ == NULL)
               MYSQL_YYABORT;
 	  }
 	| CONVERT_SYM '(' expr USING charset_name ')'
-	  { $$= new Item_func_conv_charset($3,$5); }
+	  {
+            $$= new Item_func_conv_charset($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DEFAULT '(' simple_ident ')'
 	  {
 	    if ($3->is_splocal())
@@ -4809,9 +5120,15 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= new Item_default_value(Lex->current_context(), $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| VALUES '(' simple_ident_nospvar ')'
-	  { $$= new Item_insert_value(Lex->current_context(), $3); }
+	  {
+            $$= new Item_insert_value(Lex->current_context(), $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| FUNC_ARG0 '(' ')'
 	  {
 	    if (!$1.symbol->create_func)
@@ -4822,6 +5139,8 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(void))($1.symbol->create_func))();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| FUNC_ARG1 '(' expr ')'
 	  {
@@ -4833,6 +5152,8 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*))($1.symbol->create_func))($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| FUNC_ARG2 '(' expr ',' expr ')'
 	  {
@@ -4844,6 +5165,8 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| FUNC_ARG3 '(' expr ',' expr ',' expr ')'
 	  {
@@ -4855,106 +5178,264 @@
 	      MYSQL_YYABORT;
 	    }
 	    $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| ADDDATE_SYM '(' expr ',' expr ')'
-	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);}
+	  {
+            $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
-	  { $$= new Item_date_add_interval($3, $6, $7, 0); }
+	  {
+            $$= new Item_date_add_interval($3, $6, $7, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| REPEAT_SYM '(' expr ',' expr ')'
-	  { $$= new Item_func_repeat($3,$5); }
+	  {
+            $$= new Item_func_repeat($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ATAN	'(' expr ')'
-	  { $$= new Item_func_atan($3); }
+	  {
+            $$= new Item_func_atan($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ATAN	'(' expr ',' expr ')'
-	  { $$= new Item_func_atan($3,$5); }
+	  {
+            $$= new Item_func_atan($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CHAR_SYM '(' expr_list ')'
-	  { $$= new Item_func_char(*$3); }
+	  {
+            $$= new Item_func_char(*$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CHAR_SYM '(' expr_list USING charset_name ')'
-	  { $$= new Item_func_char(*$3, $5); }
+	  {
+            $$= new Item_func_char(*$3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CHARSET '(' expr ')'
-	  { $$= new Item_func_charset($3); }
+	  {
+            $$= new Item_func_charset($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| COALESCE '(' expr_list ')'
-	  { $$= new Item_func_coalesce(* $3); }
+	  {
+            $$= new Item_func_coalesce(* $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| COLLATION_SYM '(' expr ')'
-	  { $$= new Item_func_collation($3); }
+	  {
+            $$= new Item_func_collation($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CONCAT '(' expr_list ')'
-	  { $$= new Item_func_concat(* $3); }
+	  {
+            $$= new Item_func_concat(* $3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CONCAT_WS '(' expr ',' expr_list ')'
-	  { $5->push_front($3); $$= new Item_func_concat_ws(*$5); }
+	  {
+            $5->push_front($3);
+            $$= new Item_func_concat_ws(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| CONVERT_TZ_SYM '(' expr ',' expr ',' expr ')'
 	  {
             if (Lex->add_time_zone_tables_to_query_tables(YYTHD))
               MYSQL_YYABORT;
 	    $$= new Item_func_convert_tz($3, $5, $7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| CURDATE optional_braces
-	  { $$= new Item_func_curdate_local(); Lex->safe_to_cache_query=0; }
+	  {
+            $$= new Item_func_curdate_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| CURTIME optional_braces
-	  { $$= new Item_func_curtime_local(); Lex->safe_to_cache_query=0; }
+	  {
+            $$= new Item_func_curtime_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| CURTIME '(' expr ')'
 	  {
 	    $$= new Item_func_curtime_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query=0;
 	  }
 	| CURRENT_USER optional_braces
           {
             $$= new Item_func_current_user(Lex->current_context());
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query= 0;
           }
 	| DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')'
-	  { $$= new Item_date_add_interval($3,$5,$6,0); }
+	  {
+            $$= new Item_date_add_interval($3,$5,$6,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')'
-	  { $$= new Item_date_add_interval($3,$5,$6,1); }
+	  {
+            $$= new Item_date_add_interval($3,$5,$6,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DATABASE '(' ')'
 	  {
 	    $$= new Item_func_database();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
 	  }
 	| DATE_SYM '(' expr ')'
-	  { $$= new Item_date_typecast($3); }
+	  {
+            $$= new Item_date_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DAY_SYM '(' expr ')'
-	  { $$= new Item_func_dayofmonth($3); }
+	  {
+            $$= new Item_func_dayofmonth($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ELT_FUNC '(' expr ',' expr_list ')'
-	  { $5->push_front($3); $$= new Item_func_elt(*$5); }
+	  {
+            $5->push_front($3);
+            $$= new Item_func_elt(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MAKE_SET_SYM '(' expr ',' expr_list ')'
-	  { $$= new Item_func_make_set($3, *$5); }
+	  {
+            $$= new Item_func_make_set($3, *$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ENCRYPT '(' expr ')'
 	  {
 	    $$= new Item_func_encrypt($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->uncacheable(UNCACHEABLE_RAND);
 	  }
-	| ENCRYPT '(' expr ',' expr ')'   { $$= new Item_func_encrypt($3,$5); }
+	| ENCRYPT '(' expr ',' expr ')'
+          {
+            $$= new Item_func_encrypt($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
-	  { $$= new Item_func_decode($3,$5.str); }
+	  {
+            $$= new Item_func_decode($3,$5.str);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ENCODE_SYM '(' expr ',' TEXT_STRING_literal ')'
-	 { $$= new Item_func_encode($3,$5.str); }
+	  {
+            $$= new Item_func_encode($3,$5.str);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DES_DECRYPT_SYM '(' expr ')'
-        { $$= new Item_func_des_decrypt($3); }
+          {
+            $$= new Item_func_des_decrypt($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DES_DECRYPT_SYM '(' expr ',' expr ')'
-        { $$= new Item_func_des_decrypt($3,$5); }
+          {
+            $$= new Item_func_des_decrypt($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DES_ENCRYPT_SYM '(' expr ')'
-        { $$= new Item_func_des_encrypt($3); }
+          {
+            $$= new Item_func_des_encrypt($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| DES_ENCRYPT_SYM '(' expr ',' expr ')'
-        { $$= new Item_func_des_encrypt($3,$5); }
+          {
+            $$= new Item_func_des_encrypt($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| EXPORT_SET '(' expr ',' expr ',' expr ')'
-		{ $$= new Item_func_export_set($3, $5, $7); }
+          {
+            $$= new Item_func_export_set($3, $5, $7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ')'
-		{ $$= new Item_func_export_set($3, $5, $7, $9); }
+          {
+            $$= new Item_func_export_set($3, $5, $7, $9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| EXPORT_SET '(' expr ',' expr ',' expr ',' expr ',' expr ')'
-		{ $$= new Item_func_export_set($3, $5, $7, $9, $11); }
+          {
+            $$= new Item_func_export_set($3, $5, $7, $9, $11);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| FORMAT_SYM '(' expr ',' NUM ')'
-	  { $$= new Item_func_format($3,atoi($5.str)); }
+	  {
+            $$= new Item_func_format($3,atoi($5.str));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| FROM_UNIXTIME '(' expr ')'
-	  { $$= new Item_func_from_unixtime($3); }
+	  {
+            $$= new Item_func_from_unixtime($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| FROM_UNIXTIME '(' expr ',' expr ')'
 	  {
-	    $$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
+            Item *item= new Item_func_from_unixtime($3);
+            if (item == NULL)
+              MYSQL_YYABORT;
+	    $$= new Item_func_date_format (item, $5, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| FIELD_FUNC '(' expr ',' expr_list ')'
-	  { $5->push_front($3); $$= new Item_func_field(*$5); }
+	  {
+            $5->push_front($3);
+            $$= new Item_func_field(*$5);
+            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);
@@ -4962,16 +5443,36 @@
 #endif
 	  }
 	| GET_FORMAT '(' date_time_type  ',' expr ')'
-	  { $$= new Item_func_get_format($3, $5); }
+	  {
+            $$= new Item_func_get_format($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| HOUR_SYM '(' expr ')'
-	  { $$= new Item_func_hour($3); }
+	  {
+            $$= new Item_func_hour($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| IF '(' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_if($3,$5,$7); }
+	  {
+            $$= new Item_func_if($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| INSERT '(' expr ',' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_insert($3,$5,$7,$9); }
+	  {
+            $$= new Item_func_insert($3,$5,$7,$9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| interval_expr interval '+' expr
 	  /* we cannot put interval before - */
-	  { $$= new Item_date_add_interval($4,$1,$2,0); }
+	  {
+            $$= new Item_date_add_interval($4,$1,$2,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| interval_expr
 	  {
             if ($1->type() != Item::ROW_ITEM)
@@ -4980,102 +5481,248 @@
               MYSQL_YYABORT;
             }
             $$= new Item_func_interval((Item_row *)$1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
 	| LAST_INSERT_ID '(' ')'
 	  {
 	    $$= new Item_func_last_insert_id();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query= 0;
 	  }
 	| LAST_INSERT_ID '(' expr ')'
 	  {
 	    $$= new Item_func_last_insert_id($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query= 0;
 	  }
 	| LEFT '(' expr ',' expr ')'
-	  { $$= new Item_func_left($3,$5); }
+	  {
+            $$= new Item_func_left($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| LOCATE '(' expr ',' expr ')'
-	  { $$= new Item_func_locate($5,$3); }
+	  {
+            $$= new Item_func_locate($5,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| LOCATE '(' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_locate($5,$3,$7); }
+	  {
+            $$= new Item_func_locate($5,$3,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| GREATEST_SYM '(' expr ',' expr_list ')'
-	  { $5->push_front($3); $$= new Item_func_max(*$5); }
+	  {
+            $5->push_front($3);
+            $$= new Item_func_max(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| LEAST_SYM '(' expr ',' expr_list ')'
-	  { $5->push_front($3); $$= new Item_func_min(*$5); }
+	  {
+            $5->push_front($3);
+            $$= new Item_func_min(*$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| LOG_SYM '(' expr ')'
-	  { $$= new Item_func_log($3); }
+	  {
+            $$= new Item_func_log($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| LOG_SYM '(' expr ',' expr ')'
-	  { $$= new Item_func_log($3, $5); }
+	  {
+            $$= new Item_func_log($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MASTER_POS_WAIT '(' expr ',' expr ')'
 	  {
 	    $$= new Item_master_pos_wait($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query=0;
-		  }
+          }
 	| MASTER_POS_WAIT '(' expr ',' expr ',' expr ')'
 	  {
 	    $$= new Item_master_pos_wait($3, $5, $7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query=0;
 	  }
 	| MICROSECOND_SYM '(' expr ')'
-	  { $$= new Item_func_microsecond($3); }
+	  {
+            $$= new Item_func_microsecond($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MINUTE_SYM '(' expr ')'
-	  { $$= new Item_func_minute($3); }
+	  {
+            $$= new Item_func_minute($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MOD_SYM '(' expr ',' expr ')'
-	  { $$ = new Item_func_mod( $3, $5); }
+	  {
+            $$= new Item_func_mod( $3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MONTH_SYM '(' expr ')'
-	  { $$= new Item_func_month($3); }
+	  {
+            $$= new Item_func_month($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| NOW_SYM optional_braces
-	  { $$= new Item_func_now_local(); Lex->safe_to_cache_query=0;}
+	  {
+            $$= new Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| NOW_SYM '(' expr ')'
-	  { $$= new Item_func_now_local($3); Lex->safe_to_cache_query=0;}
+	  {
+            $$= new Item_func_now_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| PASSWORD '(' expr ')'
 	  {
 	    $$= YYTHD->variables.old_passwords ?
               (Item *) new Item_func_old_password($3) :
 	      (Item *) new Item_func_password($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| OLD_PASSWORD '(' expr ')'
-	  { $$=  new Item_func_old_password($3); }
+	  {
+            $$= new Item_func_old_password($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| POSITION_SYM '(' bit_expr IN_SYM expr ')'
-	  { $$ = new Item_func_locate($5,$3); }
+	  {
+            $$= new Item_func_locate($5,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| QUARTER_SYM '(' expr ')'
-	  { $$ = new Item_func_quarter($3); }
+	  {
+            $$= new Item_func_quarter($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| RAND '(' expr ')'
-	  { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
+	  {
+            $$= new Item_func_rand($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->uncacheable(UNCACHEABLE_RAND);
+          }
 	| RAND '(' ')'
-	  { $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
+	  {
+            $$= new Item_func_rand();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->uncacheable(UNCACHEABLE_RAND);
+          }
 	| REPLACE '(' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_replace($3,$5,$7); }
+	  {
+            $$= new Item_func_replace($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| RIGHT '(' expr ',' expr ')'
-	  { $$= new Item_func_right($3,$5); }
+	  {
+            $$= new Item_func_right($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ROUND '(' expr ')'
-	  { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
-	| ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
+	  {
+            Item *item= new Item_int((char*)"0",0,1);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new Item_func_round($3, item, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| ROUND '(' expr ',' expr ')'
+          {
+            $$= new Item_func_round($3,$5,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ROW_COUNT_SYM '(' ')'
 	  {
 	    $$= new Item_func_row_count();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query= 0;
 	  }
 	| SUBDATE_SYM '(' expr ',' expr ')'
-	  { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
+	  {
+            $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
-	  { $$= new Item_date_add_interval($3, $6, $7, 1); }
+	  {
+            $$= new Item_date_add_interval($3, $6, $7, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SECOND_SYM '(' expr ')'
-	  { $$= new Item_func_second($3); }
+	  {
+            $$= new Item_func_second($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBSTRING '(' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_substr($3,$5,$7); }
+	  {
+            $$= new Item_func_substr($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBSTRING '(' expr ',' expr ')'
-	  { $$= new Item_func_substr($3,$5); }
+	  {
+            $$= new Item_func_substr($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBSTRING '(' expr FROM expr FOR_SYM expr ')'
-	  { $$= new Item_func_substr($3,$5,$7); }
+	  {
+            $$= new Item_func_substr($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBSTRING '(' expr FROM expr ')'
-	  { $$= new Item_func_substr($3,$5); }
+	  {
+            $$= new Item_func_substr($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
-	  { $$= new Item_func_substr_index($3,$5,$7); }
+	  {
+            $$= new Item_func_substr_index($3,$5,$7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SYSDATE optional_braces
           {
             if (global_system_variables.sysdate_is_now == 0)
               $$= new Item_func_sysdate_local();
             else $$= new Item_func_now_local();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
 	| SYSDATE '(' expr ')'
@@ -5083,36 +5730,94 @@
             if (global_system_variables.sysdate_is_now == 0)
               $$= new Item_func_sysdate_local($3);
             else $$= new Item_func_now_local($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             Lex->safe_to_cache_query=0;
           }
 	| TIME_SYM '(' expr ')'
-	  { $$= new Item_time_typecast($3); }
+	  {
+            $$= new Item_time_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TIMESTAMP '(' expr ')'
-	  { $$= new Item_datetime_typecast($3); }
+	  {
+            $$= new Item_datetime_typecast($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TIMESTAMP '(' expr ',' expr ')'
-	  { $$= new Item_func_add_time($3, $5, 1, 0); }
+	  {
+            $$= new Item_func_add_time($3, $5, 1, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TIMESTAMP_ADD '(' interval_time_stamp ',' expr ',' expr ')'
-	  { $$= new Item_date_add_interval($7,$5,$3,0); }
+	  {
+            $$= new Item_date_add_interval($7,$5,$3,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TIMESTAMP_DIFF '(' interval_time_stamp ',' expr ',' expr ')'
-	  { $$= new Item_func_timestamp_diff($5,$7,$3); }
+	  {
+            $$= new Item_func_timestamp_diff($5,$7,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' expr ')'
-	  { $$= new Item_func_trim($3); }
+	  {
+            $$= new Item_func_trim($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' LEADING expr FROM expr ')'
-	  { $$= new Item_func_ltrim($6,$4); }
+	  {
+            $$= new Item_func_ltrim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' TRAILING expr FROM expr ')'
-	  { $$= new Item_func_rtrim($6,$4); }
+	  {
+            $$= new Item_func_rtrim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' BOTH expr FROM expr ')'
-	  { $$= new Item_func_trim($6,$4); }
+	  {
+            $$= new Item_func_trim($6,$4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' LEADING FROM expr ')'
-	 { $$= new Item_func_ltrim($5); }
+	  {
+            $$= new Item_func_ltrim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' TRAILING FROM expr ')'
-	  { $$= new Item_func_rtrim($5); }
+	  {
+            $$= new Item_func_rtrim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' BOTH FROM expr ')'
-	  { $$= new Item_func_trim($5); }
+	  {
+            $$= new Item_func_trim($5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRIM '(' expr FROM expr ')'
-	  { $$= new Item_func_trim($5,$3); }
+	  {
+            $$= new Item_func_trim($5,$3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| TRUNCATE_SYM '(' expr ',' expr ')'
-	  { $$= new Item_func_round($3,$5,1); }
+	  {
+            $$= new Item_func_round($3,$5,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| ident '.' ident '(' opt_expr_list ')'
 	  {
 	    LEX *lex= Lex;
@@ -5125,6 +5830,8 @@
 	      $$= new Item_func_sp(Lex->current_context(), name, *$5);
 	    else
 	      $$= new Item_func_sp(Lex->current_context(), name);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    lex->safe_to_cache_query=0;
 	  }
 	| IDENT_sys '(' 
@@ -5265,47 +5972,110 @@
               else
                 $$= new Item_func_sp(Lex->current_context(), name);
             }          
-          lex->safe_to_cache_query=0;
+            lex->safe_to_cache_query=0;
+
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
 	| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
 	  {
             $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| UNIX_TIMESTAMP '(' ')'
 	  {
 	    $$= new Item_func_unix_timestamp();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->safe_to_cache_query=0;
 	  }
 	| UNIX_TIMESTAMP '(' expr ')'
-	  { $$= new Item_func_unix_timestamp($3); }
+	  {
+            $$= new Item_func_unix_timestamp($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| USER '(' ')'
-	  { $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
+	  {
+            $$= new Item_func_user();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| UTC_DATE_SYM optional_braces
-	  { $$= new Item_func_curdate_utc(); Lex->safe_to_cache_query=0;}
+	  {
+            $$= new Item_func_curdate_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| UTC_TIME_SYM optional_braces
-	  { $$= new Item_func_curtime_utc(); Lex->safe_to_cache_query=0;}
+	  {
+            $$= new Item_func_curtime_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| UTC_TIMESTAMP_SYM optional_braces
-	  { $$= new Item_func_now_utc(); Lex->safe_to_cache_query=0;}
+	  {
+            $$= new Item_func_now_utc();
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            Lex->safe_to_cache_query=0;
+          }
 	| WEEK_SYM '(' expr ')'
 	  {
-            $$= new Item_func_week($3,new Item_int((char*) "0",
-				   YYTHD->variables.default_week_format,1));
+            Item *item= new Item_int((char*) "0",
+                                     YYTHD->variables.default_week_format,
+                                     1);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new Item_func_week($3, item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
 	| WEEK_SYM '(' expr ',' expr ')'
-	  { $$= new Item_func_week($3,$5); }
+	  {
+            $$= new Item_func_week($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| YEAR_SYM '(' expr ')'
-	  { $$= new Item_func_year($3); }
+	  {
+            $$= new Item_func_year($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| YEARWEEK '(' expr ')'
-	  { $$= new Item_func_yearweek($3,new Item_int((char*) "0",0,1)); }
+	  {
+            Item *item= new Item_int((char*) "0",0,1);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$= new Item_func_yearweek($3, item);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| YEARWEEK '(' expr ',' expr ')'
-	  { $$= new Item_func_yearweek($3, $5); }
+	  {
+            $$= new Item_func_yearweek($3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| BENCHMARK_SYM '(' ulong_num ',' expr ')'
 	  {
 	    $$=new Item_func_benchmark($3,$5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
 	  }
 	| EXTRACT_SYM '(' interval FROM expr ')'
-	{ $$=new Item_extract( $3, $5); };
+          {
+            $$=new Item_extract( $3, $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        ;
 
 geometry_function:
 	  CONTAINS_SYM '(' expr ',' expr ')'
@@ -5381,7 +6151,12 @@
 	;
 
 udf_expr_list2:
-	{ Select->expr_list.push_front(new List<Item>); }
+	  {
+            List<Item> *list= new List<Item>;
+            if (list == NULL)
+              MYSQL_YYABORT;
+            Select->expr_list.push_front(list);
+          }
 	udf_expr_list3
 	{ $$= Select->expr_list.pop(); }
 	;
@@ -5429,53 +6204,132 @@
 	;
 
 sum_expr:
-	AVG_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_avg($3); }
+	  AVG_SYM '(' in_sum_expr ')'
+	  {
+            $$=new Item_sum_avg($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| AVG_SYM '(' DISTINCT in_sum_expr ')'
-	  { $$=new Item_sum_avg_distinct($4); }
+	  {
+            $$=new Item_sum_avg_distinct($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| BIT_AND  '(' in_sum_expr ')'
-	  { $$=new Item_sum_and($3); }
+	  {
+            $$=new Item_sum_and($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| BIT_OR  '(' in_sum_expr ')'
-	  { $$=new Item_sum_or($3); }
+	  {
+            $$=new Item_sum_or($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| BIT_XOR  '(' in_sum_expr ')'
-	  { $$=new Item_sum_xor($3); }
+	  {
+            $$=new 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 Item_int((int32) 0L,1);
+            if (item == NULL)
+              MYSQL_YYABORT;
+            $$=new Item_sum_count(new Item_int((int32) 0L,1));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| COUNT_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_count($3); }
+	  {
+            $$=new 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 Item_sum_count_distinct(* $5);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| GROUP_UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' in_sum_expr ')'
-	  { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); }
+	  {
+            $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MIN_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_min($3); }
+	  {
+            $$=new Item_sum_min($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 /*
    According to ANSI SQL, DISTINCT is allowed and has
    no sence 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 Item_sum_min($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MAX_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_max($3); }
+	  {
+            $$=new Item_sum_max($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| MAX_SYM '(' DISTINCT in_sum_expr ')'
-	  { $$=new Item_sum_max($4); }
+	  {
+            $$=new Item_sum_max($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| STD_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_std($3, 0); }
+	  {
+            $$=new Item_sum_std($3, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| VARIANCE_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_variance($3, 0); }
+	  {
+            $$=new Item_sum_variance($3, 0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| STDDEV_SAMP_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_std($3, 1); }
+	  {
+            $$=new Item_sum_std($3, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| VAR_SAMP_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_variance($3, 1); }
+	  {
+            $$=new Item_sum_variance($3, 1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUM_SYM '(' in_sum_expr ')'
-	  { $$=new Item_sum_sum($3); }
+	  {
+            $$=new Item_sum_sum($3);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| SUM_SYM '(' DISTINCT in_sum_expr ')'
-	  { $$=new Item_sum_sum_distinct($4); }
+	  {
+            $$=new Item_sum_sum_distinct($4);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	| GROUP_CONCAT_SYM '(' opt_distinct
 	  { Select->in_sum_expr++; }
 	  expr_list opt_gorder_clause
@@ -5486,6 +6340,8 @@
 	    sel->in_sum_expr--;
 	    $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
                                           sel->gorder_list, $7);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	    $5->empty();
 	  };
 
@@ -5508,12 +6364,16 @@
           ident_or_text SET_VAR expr
           {
             $$= new 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);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             LEX *lex= Lex;
             lex->uncacheable(UNCACHEABLE_RAND);
           }
@@ -5534,11 +6394,14 @@
     |DISTINCT   { $$ = 1; };
 
 opt_gconcat_separator:
-    /* empty */
-      {
-        $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
-      }
-    | SEPARATOR_SYM text_string { $$ = $2; };
+          /* empty */
+          {
+            $$= new (YYTHD->mem_root) String(",", 1, &my_charset_latin1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | SEPARATOR_SYM text_string { $$ = $2; }
+        ;
 
 
 opt_gorder_clause:
@@ -5552,6 +6415,8 @@
             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();
 	  };
 
@@ -5592,7 +6457,12 @@
 	;
 
 expr_list:
-	{ Select->expr_list.push_front(new List<Item>); }
+	{
+          List<Item> *list= new List<Item>;
+          if (list == NULL)
+            MYSQL_YYABORT;
+          Select->expr_list.push_front(list);
+        }
 	expr_list2
 	{ $$= Select->expr_list.pop(); };
 
@@ -5605,7 +6475,12 @@
         | '(' ident_list ')'  { $$= $2; };
 
 ident_list:
-        { Select->expr_list.push_front(new List<Item>); }
+        {
+          List<Item> *list= new List<Item>;
+          if (list == NULL)
+            MYSQL_YYABORT;
+          Select->expr_list.push_front(new List<Item>);
+        }
         ident_list2
         { $$= Select->expr_list.pop(); };
 
@@ -5625,6 +6500,8 @@
           WHEN_SYM expr THEN_SYM expr
           {
             $$= new List<Item>;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             $$->push_back($2);
             $$->push_back($4);
           }
@@ -6031,32 +6908,53 @@
 
 key_usage_list2:
 	key_usage_list2 ',' ident
-        { Select->
-	    interval_list.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;
+          Select->interval_list.push_back(s);
+        }
 	| ident
-        { Select->
-	    interval_list.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;
+          Select->interval_list.push_back(s);
+        }
 	| PRIMARY_SYM
-        { Select->
-	    interval_list.push_back(new (YYTHD->mem_root) String("PRIMARY", 7,
-				    system_charset_info)); };
+        {
+          String *s= new (YYTHD->mem_root) String("PRIMARY", 7,
+                                                  system_charset_info);
+          if (s == NULL)
+            MYSQL_YYABORT;
+          Select->interval_list.push_back(s);
+        }
+        ;
 
 using_list:
 	ident
 	  {
             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;
 	  };
 
@@ -6121,7 +7019,12 @@
 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:
 	/* empty */
@@ -6172,6 +7075,8 @@
             $$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ?
 		 new Item_string("", 0, &my_charset_latin1) :
                  new Item_string("\\", 1, &my_charset_latin1));
+            if ($$ == NULL)
+              MYSQL_YYABORT;
           }
         ;
 
@@ -6342,9 +7247,24 @@
         {
           ((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); }
+        | ULONGLONG_NUM
+          {
+            $$= new Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | LONG_NUM
+          {
+            $$= new Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | NUM
+          {
+            $$= new Item_uint($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 delete_limit_clause:
@@ -6397,10 +7317,11 @@
 	    lex->proc_list.elements=0;
 	    lex->proc_list.first=0;
 	    lex->proc_list.next= (byte**) &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 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);
 	  }
@@ -6419,7 +7340,7 @@
 	  remember_name expr
 	  {
             THD *thd= YYTHD;
-            Lex_input_stream *lip= thd->m_lip;
+            Lex_input_stream *lip= YYLIP;
 
 	    if (add_proc_to_list(thd, $2))
 	      MYSQL_YYABORT;
@@ -6451,13 +7372,20 @@
            {
              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
            {
@@ -6471,12 +7399,12 @@
 	     }
 	     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
@@ -6561,11 +7489,13 @@
 	| DROP INDEX_SYM ident ON table_ident {}
 	  {
 	     LEX *lex=Lex;
+             Alter_drop *ad= new Alter_drop(Alter_drop::KEY, $3.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.drop_list.push_back(new Alter_drop(Alter_drop::KEY,
-                                                                $3.str));
+	     lex->alter_info.drop_list.push_back(ad);
 	     if (!lex->current_select->add_table_to_list(lex->thd, $5, NULL,
 							TL_OPTION_UPDATING))
 	      MYSQL_YYABORT;
@@ -6590,6 +7520,8 @@
 	    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;
 	  }
@@ -6609,6 +7541,8 @@
 	    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;
 	  }
@@ -6823,7 +7757,12 @@
 
 expr_or_default:
 	expr	  { $$= $1;}
-	| DEFAULT {$$= new Item_default_value(Lex->current_context()); }
+	| DEFAULT
+          {
+            $$= new Item_default_value(Lex->current_context());
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	;
 
 opt_insert_update:
@@ -6941,15 +7880,21 @@
 table_wild_one:
 	ident opt_wild opt_table_alias
 	{
-	  if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3,
+          Table_ident *ti= new Table_ident($1);
+          if (ti == NULL)
+            MYSQL_YYABORT;
+	  if (!Select->add_table_to_list(YYTHD, ti, $3,
 					 TL_OPTION_UPDATING | 
                                          TL_OPTION_ALIAS, Lex->lock_option))
 	    MYSQL_YYABORT;
         }
 	| ident '.' ident opt_wild opt_table_alias
 	  {
+            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,
 					   $5, 
                                            TL_OPTION_UPDATING | 
                                            TL_OPTION_ALIAS,
@@ -7327,8 +8272,12 @@
 wild_and_where:
       /* empty */
       | LIKE TEXT_STRING_sys
-	{ Lex->wild=  new (YYTHD->mem_root) String($2.str, $2.length,
-                                                   system_charset_info); }
+	{
+          Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length,
+                                                  system_charset_info);
+          if (Lex->wild == NULL)
+            MYSQL_YYABORT;
+        }
       | WHERE expr
         {
           Select->where= $2;
@@ -7376,7 +8325,14 @@
 	/* empty */	{}
 	| text_string	{ Lex->wild= $1; }
 	| ident
-	  { Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info); };
+	  {
+            Lex->wild= new (YYTHD->mem_root) String((const char*) $1.str,
+                                                    $1.length,
+                                                    system_charset_info);
+            if (Lex->wild == NULL)
+              MYSQL_YYABORT;
+          }
+        ;
 
 
 /* flush things */
@@ -7491,7 +8447,7 @@
         {
           THD *thd= YYTHD;
           LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 
 	  if (lex->sphead)
 	  {
@@ -7533,10 +8489,7 @@
         }
         opt_duplicate INTO
         {
-          THD *thd= YYTHD;
-	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
-	  lex->fname_end= lip->ptr;
+	  Lex->fname_end= YYLIP->ptr;
 	}
         TABLE_SYM table_ident
         {
@@ -7663,7 +8616,11 @@
 field_or_var:
         simple_ident_nospvar {$$= $1;}
         | '@' ident_or_text
-          { $$= new Item_user_var_as_out_param($2); }
+          {
+            $$= new Item_user_var_as_out_param($2);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 opt_load_data_set_spec:
@@ -7688,9 +8645,14 @@
                my_charset_is_ascii_based(cs_con)))
             tmp= $1;
           else
-            thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli);
+          {
+            if (thd->convert_string(&tmp, cs_con, $1.str, $1.length, cs_cli))
+              MYSQL_YYABORT;
+          }
           $$= new Item_string(tmp.str, tmp.length, cs_con,
                               DERIVATION_COERCIBLE, repertoire);
+          if ($$ == NULL)
+            MYSQL_YYABORT;
         }
         | NCHAR_STRING
         {
@@ -7699,10 +8661,14 @@
           DBUG_ASSERT(my_charset_is_ascii_based(national_charset_info));
           $$= new Item_string($1.str, $1.length, national_charset_info,
                               DERIVATION_COERCIBLE, repertoire);
+          if ($$ == NULL)
+            MYSQL_YYABORT;
         }
         | UNDERSCORE_CHARSET TEXT_STRING
           {
             $$= new Item_string($2.str, $2.length, Lex->underscore_charset);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
             ((Item_string*) $$)->set_repertoire_from_value();
           }
         | text_literal TEXT_STRING_literal
@@ -7724,28 +8690,37 @@
         ;
 
 text_string:
-	TEXT_STRING_literal
-	{ $$=  new (YYTHD->mem_root) String($1.str,$1.length,YYTHD->variables.collation_connection); }
+	  TEXT_STRING_literal
+          {
+            $$= 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);
+            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);
+            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);
           }
 	;
 
@@ -7754,7 +8729,7 @@
         {
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
           Item_param *item;
           if (! lex->parsing_options.allows_variable)
           {
@@ -7787,76 +8762,121 @@
 	| NULL_SYM
           {
             $$ = new Item_null();
-            YYTHD->m_lip->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); }
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+            YYLIP->next_state= MY_LEX_OPERATOR_OR_IDENT;
+          }
+	| FALSE_SYM
+          {
+            $$= new Item_int((char*) "FALSE",0,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| TRUE_SYM
+          {
+            $$= new Item_int((char*) "TRUE",1,1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| HEX_NUM
+          {
+            $$=	new Item_hex_string($1.str, $1.length);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| BIN_NUM
+          {
+            $$= new 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);
+            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;
-            $$= new Item_string(NULL, /* name will be set in select_item */
-                                str ? str->ptr() : "",
-                                str ? str->length() : 0,
-                                Lex->underscore_charset);
-            if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+            tmp->quick_fix_field();
+            String *str= tmp->val_str((String*) 0);
+            Item_string *item_str;
+            item_str= new Item_string(NULL, /* name will be set in select_item */
+                                      str ? str->ptr() : "",
+                                      str ? str->length() : 0,
+                                      Lex->underscore_charset);
+            if (!item_str ||
+                !item_str->check_well_formed_result(&item_str->str_value, TRUE))
             {
               MYSQL_YYABORT;
             }
-            ((Item_string *) $$)->set_repertoire_from_value();
+            item_str->set_repertoire_from_value();
+            $$= item_str;
           }
 	| UNDERSCORE_CHARSET BIN_NUM
           {
 	    Item *tmp= new 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;
-            $$= new Item_string(NULL, /* name will be set in select_item */
-                                str ? str->ptr() : "",
-                                str ? str->length() : 0,
-                                Lex->underscore_charset);
-            if (!$$ || !$$->check_well_formed_result(&$$->str_value, TRUE))
+            tmp->quick_fix_field();
+	    String *str= tmp->val_str((String*) 0);
+            Item_string *item_str;
+            item_str= new Item_string(NULL, /* name will be set in select_item */
+                                      str ? str->ptr() : "",
+                                      str ? str->length() : 0,
+                                      Lex->underscore_charset);
+            if (!item_str ||
+                !item_str->check_well_formed_result(&item_str->str_value, TRUE))
             {
               MYSQL_YYABORT;
             }
+            $$= item_str;
           }
 	| DATE_SYM text_literal { $$ = $2; }
 	| TIME_SYM text_literal { $$ = $2; }
 	| TIMESTAMP text_literal { $$ = $2; };
 
 NUM_literal:
-	NUM		{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
-	| LONG_NUM	{ int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); }
-	| ULONGLONG_NUM	{ $$ =	new Item_uint($1.str, $1.length); }
+	  NUM
+          {
+            int error;
+            $$ = new Item_int($1.str,
+                              (longlong) my_strtoll10($1.str, NULL, &error),
+                              $1.length);
+          }
+	| LONG_NUM
+          {
+            int error;
+            $$ = new Item_int($1.str,
+                              (longlong) my_strtoll10($1.str, NULL, &error),
+                              $1.length);
+          }
+	| ULONGLONG_NUM
+          {
+            $$=	new Item_uint($1.str, $1.length);
+          }
         | DECIMAL_NUM
-	{
-           $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
-	   if (YYTHD->net.report_error)
-	   {
-	     MYSQL_YYABORT;
-	   }
-	}
+	  {
+            $$= new Item_decimal($1.str, $1.length, YYTHD->charset());
+            if (($$ == NULL) || (YYTHD->net.report_error))
+            {
+              MYSQL_YYABORT;
+            }
+          }
 	| FLOAT_NUM
-	{
-	   $$ =	new Item_float($1.str, $1.length);
-	   if (YYTHD->net.report_error)
-	   {
-	     MYSQL_YYABORT;
-	   }
-	}
-	;
+          {
+            $$= new Item_float($1.str, $1.length);
+            if (($$ == NULL) || (YYTHD->net.report_error))
+            {
+              MYSQL_YYABORT;
+            }
+          }
+        ;
 
 /**********************************************************************
 ** Creating different items.
@@ -7871,6 +8891,8 @@
 	{
           SELECT_LEX *sel= Select;
 	  $$ = new Item_field(Lex->current_context(), NullS, $1.str, "*");
+          if ($$ == NULL)
+            MYSQL_YYABORT;
 	  sel->with_wild++;
 	}
 	| ident '.' ident '.' '*'
@@ -7879,6 +8901,8 @@
 	  $$ = new Item_field(Lex->current_context(), (YYTHD->client_capabilities &
                              CLIENT_NO_SCHEMA ? NullS : $1.str),
                              $3.str,"*");
+          if ($$ == NULL)
+            MYSQL_YYABORT;
 	  sel->with_wild++;
 	}
 	;
@@ -7891,7 +8915,7 @@
 	{
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 	  sp_variable_t *spv;
           sp_pcontext *spc = lex->spcont;
 	  if (spc && (spv = spc->find_variable(&$1)))
@@ -7908,11 +8932,12 @@
                                       lip->tok_start_prev - 
                                       lex->sphead->m_tmp_query,
                                       lip->tok_end - lip->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
@@ -7922,6 +8947,8 @@
 	         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);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
         }
         | simple_ident_q { $$= $1; }
@@ -7935,6 +8962,8 @@
 	       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);
+          if ($$ == NULL)
+            MYSQL_YYABORT;
 	}
 	| simple_ident_q { $$= $1; }
 	;
@@ -8006,6 +9035,8 @@
 	         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 ($$ == NULL)
+              MYSQL_YYABORT;
           }
         }
 	| '.' ident '.' ident
@@ -8022,6 +9053,8 @@
 	       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 ($$ == NULL)
+            MYSQL_YYABORT;
 	}
 	| ident '.' ident '.' ident
 	{
@@ -8043,6 +9076,8 @@
                                    (YYTHD->client_capabilities &
 				    CLIENT_NO_SCHEMA ? NullS : $1.str),
                                    $3.str, $5.str);
+          if ($$ == NULL)
+            MYSQL_YYABORT;
 	};
 
 
@@ -8077,13 +9112,34 @@
 	| '.' ident		{ $$=$2;}	/* For Delphi */;
 
 table_ident:
-	ident			{ $$=new Table_ident($1); }
-	| ident '.' ident	{ $$=new Table_ident(YYTHD, $1,$3,0);}
-	| '.' ident		{ $$=new Table_ident($2);} /* For Delphi */
+	  ident
+          {
+            $$=new Table_ident($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| ident '.' ident
+          {
+            $$=new Table_ident(YYTHD, $1,$3,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| '.' ident
+          {
+            $$=new Table_ident($2); /* For Delphi */
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 table_ident_nodb:
-	ident			{ LEX_STRING db={(char*) any_db,3}; $$=new Table_ident(YYTHD, db,$1,0); }
+	ident
+          {
+            LEX_STRING db={(char*) any_db,3};
+            $$=new Table_ident(YYTHD, db,$1,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 IDENT_sys:
@@ -8107,8 +9163,11 @@
 	      $$= $1;
             }
 	    else
-	      thd->convert_string(&$$, system_charset_info,
-				  $1.str, $1.length, thd->charset());
+            {
+	      if (thd->convert_string(&$$, system_charset_info,
+				  $1.str, $1.length, thd->charset()))
+                MYSQL_YYABORT;
+            }
 	  }
 	;
 
@@ -8119,8 +9178,11 @@
 	  if (thd->charset_is_system_charset)
 	    $$= $1;
 	  else
-	    thd->convert_string(&$$, system_charset_info,
-				$1.str, $1.length, thd->charset());
+          {
+	    if (thd->convert_string(&$$, system_charset_info,
+				$1.str, $1.length, thd->charset()))
+              MYSQL_YYABORT;
+          }
 	}
 	;
 
@@ -8131,8 +9193,11 @@
 	  if (thd->charset_is_collation_connection)
 	    $$= $1;
 	  else
-	    thd->convert_string(&$$, thd->variables.collation_connection,
-				$1.str, $1.length, thd->charset());
+          {
+	    if (thd->convert_string(&$$, thd->variables.collation_connection,
+				$1.str, $1.length, thd->charset()))
+              MYSQL_YYABORT;
+          }
 	}
 	;
 
@@ -8144,8 +9209,11 @@
 	  if (thd->charset_is_character_set_filesystem)
 	    $$= $1;
 	  else
-	    thd->convert_string(&$$, thd->variables.character_set_filesystem,
-				$1.str, $1.length, thd->charset());
+          {
+	    if (thd->convert_string(&$$, thd->variables.character_set_filesystem,
+				$1.str, $1.length, thd->charset()))
+              MYSQL_YYABORT;
+          }
 	}
 	;
 
@@ -8155,6 +9223,8 @@
 	{
 	  THD *thd= YYTHD;
 	  $$.str=    thd->strmake($1.str, $1.length);
+          if ($$.str == NULL)
+            MYSQL_YYABORT;
 	  $$.length= $1.length;
 	}
 	;
@@ -8165,6 +9235,8 @@
 	{
 	  THD *thd= YYTHD;
 	  $$.str=    thd->strmake($1.str, $1.length);
+          if ($$.str == NULL)
+            MYSQL_YYABORT;
 	  $$.length= $1.length;
 	}
 	;
@@ -8504,7 +9576,7 @@
         {
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 
           if (lex->sphead)
           {
@@ -8535,7 +9607,7 @@
         {
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 
           if (lex->sphead)
           {
@@ -8696,29 +9768,50 @@
 	  LEX *lex=Lex;
           if ($1)
             lex->option_type= $1;
-	  lex->var_list.push_back(new set_var(lex->option_type,
-                                              find_sys_var("tx_isolation"),
-                                              &null_lex_str,
-                                              new Item_int((int32) $5)));
+          Item *item= new Item_int((int32) $5);
+          if (item == NULL)
+            MYSQL_YYABORT;
+          set_var *var= new set_var(lex->option_type,
+                                    find_sys_var("tx_isolation"),
+                                    &null_lex_str,
+                                    item);
+          if (var == NULL)
+            MYSQL_YYABORT;
+	  lex->var_list.push_back(var);
 	}
         ;
 
 option_value:
 	'@' ident_or_text equal expr
 	{
-          Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4)));
+          Item_func_set_user_var *item= new Item_func_set_user_var($2,$4);
+          if (item == NULL)
+            MYSQL_YYABORT;
+          set_var_user *var= new set_var_user(item);
+          if (var == NULL)
+            MYSQL_YYABORT;
+          Lex->var_list.push_back(var);
 	}
 	| '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default
 	  {
 	    LEX *lex=Lex;
-	    lex->var_list.push_back(new set_var($3, $4.var, &$4.base_name, $6));
+            set_var *var= new set_var($3, $4.var, &$4.base_name, $6);
+            if (var == NULL)
+              MYSQL_YYABORT;
+	    lex->var_list.push_back(var);
 	  }
 	| charset old_or_new_charset_name_or_default
 	{
 	  THD *thd= YYTHD;
 	  LEX *lex= Lex;
 	  $2= $2 ? $2: global_system_variables.character_set_client;
-	  lex->var_list.push_back(new set_var_collation_client($2,thd->variables.collation_database,$2));
+          set_var_collation_client *var;
+          var= new set_var_collation_client($2,
+                                            thd->variables.collation_database,
+                                            $2);
+          if (var == NULL)
+            MYSQL_YYABORT;
+	  lex->var_list.push_back(var);
 	}
         | NAMES_SYM equal expr
 	  {
@@ -8746,7 +9839,11 @@
                      $3->name, $2->csname);
 	    MYSQL_YYABORT;
 	  }
-	  lex->var_list.push_back(new set_var_collation_client($3,$3,$3));
+          set_var_collation_client *var;
+          var= new set_var_collation_client($3,$3,$3);
+          if (var == NULL)
+            MYSQL_YYABORT;
+	  lex->var_list.push_back(var);
 	}
 	| PASSWORD equal text_or_password
 	  {
@@ -8767,11 +9864,17 @@
 	      MYSQL_YYABORT;
 	    user->host=null_lex_str;
 	    user->user.str=thd->security_ctx->priv_user;
-	    thd->lex->var_list.push_back(new set_var_password(user, $3));
+            set_var_password *var= new set_var_password(user, $3);
+            if (var == NULL)
+              MYSQL_YYABORT;
+	    thd->lex->var_list.push_back(var);
 	  }
 	| PASSWORD FOR_SYM user equal text_or_password
 	  {
-	    Lex->var_list.push_back(new set_var_password($3,$5));
+            set_var_password *var= new set_var_password($3,$5);
+            if (var == NULL)
+              MYSQL_YYABORT;
+	    Lex->var_list.push_back(var);
 	  }
 	;
 
@@ -8885,11 +9988,15 @@
 	        Item_func_old_password::alloc(YYTHD, $3.str) :
 	        Item_func_password::alloc(YYTHD, $3.str) :
 	      $3.str;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
 	| OLD_PASSWORD '(' TEXT_STRING ')'
 	  {
 	    $$= $3.length ? Item_func_old_password::alloc(YYTHD, $3.str) :
 	      $3.str;
+            if ($$ == NULL)
+              MYSQL_YYABORT;
 	  }
           ;
 
@@ -8897,9 +10004,24 @@
 set_expr_or_default:
 	expr      { $$=$1; }
 	| DEFAULT { $$=0; }
-	| ON	  { $$=new Item_string("ON",  2, system_charset_info); }
-	| ALL	  { $$=new Item_string("ALL", 3, system_charset_info); }
-	| BINARY  { $$=new Item_string("binary", 6, system_charset_info); }
+	| ON
+          {
+            $$=new Item_string("ON",  2, system_charset_info);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| ALL
+          {
+            $$=new Item_string("ALL", 3, system_charset_info);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+	| BINARY
+          {
+            $$=new Item_string("binary", 6, system_charset_info);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
 	;
 
 
@@ -9000,7 +10122,10 @@
 	  }
 	  lex->sql_command = SQLCOM_HA_READ;
 	  lex->ha_rkey_mode= HA_READ_KEY_EXACT;	/* Avoid purify warnings */
-	  lex->current_select->select_limit= new Item_int((int32) 1);
+          Item *one= new Item_int((int32) 1);
+          if (one == NULL)
+            MYSQL_YYABORT;
+	  lex->current_select->select_limit= one;
 	  lex->current_select->offset_limit= 0;
 	  if (!lex->current_select->add_table_to_list(lex->thd, $2, 0, 0))
 	    MYSQL_YYABORT;
@@ -9307,8 +10432,9 @@
              {
                char *buff= 
                  (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
-               if (buff)
-                 make_scrambled_password_323(buff, $4.str);
+               if (buff == NULL)
+                 MYSQL_YYABORT;
+               make_scrambled_password_323(buff, $4.str);
                $1->password.str= buff;
                $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323;
              }
@@ -9316,8 +10442,9 @@
              {
                char *buff= 
                  (char *) YYTHD->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
-               if (buff)
-                 make_scrambled_password(buff, $4.str);
+               if (buff == NULL)
+                 MYSQL_YYABORT;
+               make_scrambled_password(buff, $4.str);
                $1->password.str= buff;
                $1->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
              }
@@ -9346,6 +10473,8 @@
 	ident
 	{
 	  String *new_str = new (YYTHD->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
+          if (new_str == NULL)
+            MYSQL_YYABORT;
 	  List_iterator <LEX_COLUMN> iter(Lex->columns);
 	  class LEX_COLUMN *point;
 	  LEX *lex=Lex;
@@ -9359,7 +10488,12 @@
 	  if (point)
 	    point->rights |= lex->which_columns;
 	  else
-	    lex->columns.push_back(new LEX_COLUMN (*new_str,lex->which_columns));
+          {
+            LEX_COLUMN *col= new LEX_COLUMN (*new_str,lex->which_columns);
+            if (col == NULL)
+              MYSQL_YYABORT;
+	    lex->columns.push_back(col);
+          }
 	}
         ;
 
@@ -9773,13 +10907,17 @@
 view_list:
 	ident 
 	  {
-	    Lex->view_list.push_back((LEX_STRING*)
-				     sql_memdup(&$1, sizeof(LEX_STRING)));
+            LEX_STRING *ls= (LEX_STRING*) sql_memdup(&$1, sizeof(LEX_STRING));
+            if (ls == NULL)
+              MYSQL_YYABORT;
+	    Lex->view_list.push_back(ls);
 	  }
 	| view_list ',' ident
 	  {
-	    Lex->view_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;
+	    Lex->view_list.push_back(ls);
 	  }
 	;
 
@@ -9845,7 +10983,7 @@
 	{
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 	  sp_head *sp;
 	 
 	  if (lex->sphead)
@@ -9867,13 +11005,6 @@
 
 	  lex->sphead= sp;
 	  lex->spname= $3;
-	  /*
-	    We have to turn of CLIENT_MULTI_QUERIES while parsing a
-	    stored procedure, otherwise yylex will chop it into pieces
-	    at each ';'.
-	  */
-	  sp->m_old_cmq= thd->client_capabilities & CLIENT_MULTI_QUERIES;
-	  thd->client_capabilities &= ~CLIENT_MULTI_QUERIES;
 	  
 	  bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
 	  lex->sphead->m_chistics= &lex->sp_chistics;
@@ -9888,9 +11019,6 @@
 	  
 	  lex->sql_command= SQLCOM_CREATE_TRIGGER;
 	  sp->init_strings(YYTHD, lex);
-	  /* Restore flag if it was cleared above */
-	  if (sp->m_old_cmq)
-	    YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
 	  sp->restore_thd_mem_root(YYTHD);
 	
 	  if (sp->is_not_allowed_in_function("trigger"))
@@ -9948,7 +11076,7 @@
           { /* $5 */
             THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
-            Lex_input_stream *lip= thd->m_lip;
+            Lex_input_stream *lip= YYLIP;
 	    sp_head *sp;
 
 	    lex->stmt_definition_begin= $1;
@@ -9962,29 +11090,20 @@
 
 	    /* Order is important here: new - reset - init */
 	    sp= new sp_head();
+            if (sp == NULL)
+              MYSQL_YYABORT;
 	    sp->reset_thd_mem_root(thd);
 	    sp->init(lex);
             sp->init_sp_name(thd, lex->spname);
 
 	    sp->m_type= TYPE_ENUM_FUNCTION;
 	    lex->sphead= sp;
-	    /*
-	     * We have to turn of CLIENT_MULTI_QUERIES while parsing a
-	     * stored procedure, otherwise yylex will chop it into pieces
-	     * at each ';'.
-	     */
-	    sp->m_old_cmq= thd->client_capabilities & CLIENT_MULTI_QUERIES;
-	    thd->client_capabilities &= ~CLIENT_MULTI_QUERIES;
 	    lex->sphead->m_param_begin= lip->tok_start+1;
 	  }
           sp_fdparam_list /* $6 */
           ')' /* $7 */
           { /* $8 */
-            THD *thd= YYTHD;
-	    LEX *lex= thd->lex;
-            Lex_input_stream *lip= thd->m_lip;
-
-	    lex->sphead->m_param_end= lip->tok_start;
+	    Lex->sphead->m_param_end= YYLIP->tok_start;
 	  }
           RETURNS_SYM /* $9 */
 	  { /* $10 */
@@ -10010,7 +11129,7 @@
           { /* $14 */
             THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
-            Lex_input_stream *lip= thd->m_lip;
+            Lex_input_stream *lip= YYLIP;
 
 	    lex->sphead->m_chistics= &lex->sp_chistics;
 	    lex->sphead->m_body_begin= lip->tok_start;
@@ -10030,9 +11149,6 @@
               my_error(ER_SP_NORETURN, MYF(0), sp->m_qname.str);
               MYSQL_YYABORT;
             }
-	    /* Restore flag if it was cleared above */
-	    if (sp->m_old_cmq)
-	      YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
 	    sp->restore_thd_mem_root(YYTHD);
 	  }
 	;
@@ -10062,28 +11178,17 @@
           sp->init_sp_name(YYTHD, $3);
 
 	  lex->sphead= sp;
-	  /*
-	   * We have to turn of CLIENT_MULTI_QUERIES while parsing a
-	   * stored procedure, otherwise yylex will chop it into pieces
-	   * at each ';'.
-	   */
-	  sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
-	  YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
 	}
         '('
 	{
-          THD *thd= YYTHD;
-	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
-
-	  lex->sphead->m_param_begin= lip->tok_start+1;
+	  Lex->sphead->m_param_begin= YYLIP->tok_start+1;
 	}
 	sp_pdparam_list
 	')'
 	{
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 
 	  lex->sphead->m_param_end= lip->tok_start;
 	  bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
@@ -10092,7 +11197,7 @@
 	{
           THD *thd= YYTHD;
 	  LEX *lex= thd->lex;
-          Lex_input_stream *lip= thd->m_lip;
+          Lex_input_stream *lip= YYLIP;
 
 	  lex->sphead->m_chistics= &lex->sp_chistics;
 	  lex->sphead->m_body_begin= lip->tok_start;
@@ -10104,9 +11209,6 @@
 
 	  sp->init_strings(YYTHD, lex);
 	  lex->sql_command= SQLCOM_CREATE_PROCEDURE;
-	  /* Restore flag if it was cleared above */
-	  if (sp->m_old_cmq)
-	    YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
 	  sp->restore_thd_mem_root(YYTHD);
 	}
 	;

=== modified file 'sql/thr_malloc.cc'
--- a/sql/thr_malloc.cc	2006-12-31 00:02:27 +0000
+++ b/sql/thr_malloc.cc	2008-08-11 16:10:00 +0000
@@ -21,10 +21,35 @@
 extern "C" {
   void sql_alloc_error_handler(void)
   {
+    sql_print_error(ER(ER_OUT_OF_RESOURCES));
+
     THD *thd=current_thd;
-    if (thd)					// QQ;  To be removed
-      thd->fatal_error();			/* purecov: inspected */
-    sql_print_error(ER(ER_OUT_OF_RESOURCES));
+    if (thd)
+    {
+      /*
+        This thread is Out Of Memory.
+        An OOM condition is a fatal error.
+        It should not be caught by error handlers in stored procedures.
+        Also, recording that SQL condition in the condition area could
+        cause more memory allocations, which in turn could raise more
+        OOM conditions, causing recursion in the error handling code itself.
+        As a result, my_error() should not be invoked, and the
+        thread diagnostics area is set to an error status directly.
+        The visible result for a client application will be:
+        - a query fails with an ER_OUT_OF_RESOURCES error,
+        returned in the error packet.
+        - SHOW ERROR/SHOW WARNINGS may be empty.
+      */
+
+      NET *net= &thd->net;
+      thd->fatal_error();
+      if (!net->last_error[0])                  // Return only first message
+      {
+        strmake(net->last_error, ER(ER_OUT_OF_RESOURCES),
+                sizeof(net->last_error)-1);
+        net->last_errno= ER_OUT_OF_RESOURCES;
+      }
+    }
   }
 }
 

=== modified file 'sql/unireg.h'
--- a/sql/unireg.h	2008-04-10 00:34:38 +0000
+++ b/sql/unireg.h	2008-08-25 12:11:59 +0000
@@ -35,6 +35,9 @@
 #ifndef SHAREDIR
 #define SHAREDIR	"share/"
 #endif
+#ifndef PLUGINDIR
+#define PLUGINDIR	"lib/plugin"
+#endif
 
 #define ER(X) errmesg[(X) - ER_ERROR_FIRST]
 #define ER_SAFE(X) (((X) >= ER_ERROR_FIRST && (X) <= ER_ERROR_LAST) ? ER(X) : "Invalid error code")

=== modified file 'strings/decimal.c'
--- a/strings/decimal.c	2008-01-14 15:16:36 +0000
+++ b/strings/decimal.c	2008-08-15 19:46:21 +0000
@@ -1999,18 +1999,18 @@
 
   sanity(to);
 
-  i=intg0;
+  i=intg0;                                       /* save 'ideal' values */
   j=frac0;
-  FIX_INTG_FRAC_ERROR(to->len, intg0, frac0, error);
+  FIX_INTG_FRAC_ERROR(to->len, intg0, frac0, error);  /* bound size */
   to->sign=from1->sign != from2->sign;
-  to->frac=from1->frac+from2->frac;
+  to->frac=from1->frac+from2->frac;              /* store size in digits */
   to->intg=intg0*DIG_PER_DEC1;
 
   if (unlikely(error))
   {
     set_if_smaller(to->frac, frac0*DIG_PER_DEC1);
     set_if_smaller(to->intg, intg0*DIG_PER_DEC1);
-    if (unlikely(i > intg0))
+    if (unlikely(i > intg0))                     /* bounded integer-part */
     {
       i-=intg0;
       j=i >> 1;
@@ -2018,12 +2018,20 @@
       intg2-=i-j;
       frac1=frac2=0; /* frac0 is already 0 here */
     }
-    else
+    else                                         /* bounded fract part */
     {
       j-=frac0;
       i=j >> 1;
-      frac1-= i;
-      frac2-=j-i;
+      if (frac1 <= frac2)
+      {
+        frac1-= i;
+        frac2-=j-i;
+      }
+      else
+      {
+        frac2-= i;
+        frac1-=j-i;
+      }
     }
   }
   start0=to->buf+intg0+frac0-1;

=== modified file 'support-files/build-tags'
--- a/support-files/build-tags	2002-01-20 02:16:52 +0000
+++ b/support-files/build-tags	2008-08-06 20:25:25 +0000
@@ -2,8 +2,11 @@
 
 rm -f TAGS
 filter='\.cc$\|\.c$\|\.h$\|\.yy$'
-files=`bk -r sfiles -gU | grep $filter `
-for f in $files ;
+
+list="find . -type f"
+bzr root >/dev/null 2>/dev/null && list="bzr ls --kind=file --versioned"
+
+$list |grep $filter |while read f; 
 do
 	 etags -o TAGS --append $f
 done

=== modified file 'support-files/my-huge.cnf.sh'
--- a/support-files/my-huge.cnf.sh	2005-10-31 09:54:36 +0000
+++ b/support-files/my-huge.cnf.sh	2008-06-10 19:10:56 +0000
@@ -46,6 +46,9 @@
 # 
 #skip-networking
 
+# Disable Federated by default
+skip-federated
+
 # Replication Master Server (default)
 # binary logging is required for replication
 log-bin=mysql-bin

=== modified file 'support-files/my-innodb-heavy-4G.cnf.sh'
--- a/support-files/my-innodb-heavy-4G.cnf.sh	2005-10-31 09:54:36 +0000
+++ b/support-files/my-innodb-heavy-4G.cnf.sh	2008-06-10 19:10:56 +0000
@@ -357,6 +357,9 @@
 myisam_recover
 
 
+# Disable Federated by default
+skip-federated
+
 # *** BDB Specific options ***
 
 # Use this option if you run a MySQL server with BDB support enabled but

=== modified file 'support-files/my-large.cnf.sh'
--- a/support-files/my-large.cnf.sh	2005-10-31 09:54:36 +0000
+++ b/support-files/my-large.cnf.sh	2008-06-10 19:10:56 +0000
@@ -46,6 +46,9 @@
 # 
 #skip-networking
 
+# Disable Federated by default
+skip-federated
+
 # Replication Master Server (default)
 # binary logging is required for replication
 log-bin=mysql-bin

=== modified file 'support-files/my-medium.cnf.sh'
--- a/support-files/my-medium.cnf.sh	2005-01-10 23:16:07 +0000
+++ b/support-files/my-medium.cnf.sh	2008-06-10 19:10:56 +0000
@@ -44,6 +44,9 @@
 # 
 #skip-networking
 
+# Disable Federated by default
+skip-federated
+
 # Replication Master Server (default)
 # binary logging is required for replication
 log-bin=mysql-bin

=== modified file 'support-files/my-small.cnf.sh'
--- a/support-files/my-small.cnf.sh	2005-01-10 23:16:07 +0000
+++ b/support-files/my-small.cnf.sh	2008-06-10 19:10:56 +0000
@@ -48,6 +48,9 @@
 # Uncomment the following if you want to log updates
 #log-bin=mysql-bin
 
+# Disable Federated by default
+skip-federated
+
 # Uncomment the following if you are NOT using BDB tables
 #skip-bdb
 

=== modified file 'tests/mysql_client_test.c'
--- a/tests/mysql_client_test.c	2008-05-27 11:33:08 +0000
+++ b/tests/mysql_client_test.c	2008-08-20 09:49:28 +0000
@@ -7578,9 +7578,7 @@
   else
   {
     verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", 
-                         "", "",
-                         NAME_LEN*MAX_KEY / my_charset_utf8_general_ci.mbmaxlen,
-                         0);
+                         "", "", NAME_LEN*MAX_KEY, 0);
   }
 
   verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING,
@@ -16164,7 +16162,7 @@
   metadata= mysql_stmt_result_metadata(stmt);
   field= mysql_fetch_field(metadata);
   DIE_UNLESS(strcmp(field->table, "v1") == 0);
-  DIE_UNLESS(strcmp(field->org_table, "t1") == 0);
+  DIE_UNLESS(strcmp(field->org_table, "v1") == 0);
   DIE_UNLESS(strcmp(field->db, "client_test_db") == 0);
   mysql_free_result(metadata);
   mysql_stmt_close(stmt);
@@ -16176,7 +16174,7 @@
   metadata= mysql_stmt_result_metadata(stmt);
   field= mysql_fetch_field(metadata);
   DIE_UNLESS(strcmp(field->table, "v1") == 0);
-  DIE_UNLESS(strcmp(field->org_table, "t1") == 0);
+  DIE_UNLESS(strcmp(field->org_table, "v1") == 0);
   DIE_UNLESS(strcmp(field->db, "client_test_db") == 0);
   mysql_free_result(metadata);
   mysql_stmt_close(stmt);
@@ -16189,6 +16187,38 @@
   DBUG_VOID_RETURN;
 }
 
+
+/**
+  Bug#38486 Crash when using cursor protocol
+*/
+
+static void test_bug38486(void)
+{
+  MYSQL_STMT *stmt;
+  const char *stmt_text;
+  unsigned long type= CURSOR_TYPE_READ_ONLY;
+
+  DBUG_ENTER("test_bug38486");
+  myheader("test_bug38486");
+
+  stmt= mysql_stmt_init(mysql);
+  mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type);
+  stmt_text= "CREATE TABLE t1 (a INT)";
+  mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+  mysql_stmt_execute(stmt);
+  mysql_stmt_close(stmt);
+
+  stmt= mysql_stmt_init(mysql);
+  mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type);
+  stmt_text= "INSERT INTO t1 VALUES (1)";
+  mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+  mysql_stmt_execute(stmt);
+  mysql_stmt_close(stmt);
+
+  DBUG_VOID_RETURN;
+}
+
+
 /*
   Read and parse arguments and MySQL options from my.cnf
 */
@@ -16483,6 +16513,7 @@
   { "test_bug29306", test_bug29306 },
   { "test_bug31669", test_bug31669 },
   { "test_bug32265", test_bug32265 },
+  { "test_bug38486", test_bug38486 },
   { 0, 0 }
 };
 


