List:Commits« Previous MessageNext Message »
From:Konstantin Osipov Date:September 27 2010 5:56am
Subject:bzr commit into mysql-trunk-merge branch (kostja:3197)
View as plain text  
#At file:///opt/local/work/trunk-merge/ based on revid:kostja@stripped

 3197 Konstantin Osipov	2010-09-27 [merge]
      Merge 5.5-merge -> trunk-merge.

    modified:
      BUILD/build_mccge.sh
      BUILD/check-cpu
      CMakeLists.txt
      config/ac-macros/maintainer.m4
      mysql-test/include/index_merge_ror_cpk.inc
      mysql-test/r/index_merge_innodb.result
      mysql-test/r/index_merge_myisam.result
      mysql-test/r/order_by.result
      mysql-test/r/partition.result
      mysql-test/r/partition_column.result
      mysql-test/r/partition_column_prune.result
      mysql-test/r/partition_hash.result
      mysql-test/r/partition_innodb.result
      mysql-test/r/partition_pruning.result
      mysql-test/r/partition_range.result
      mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result
      mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result
      mysql-test/suite/innodb/r/innodb_mysql.result
      mysql-test/suite/innodb/t/innodb_mysql.test
      mysql-test/suite/parts/r/partition_alter3_innodb.result
      mysql-test/suite/parts/r/partition_alter3_myisam.result
      mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result
      mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result
      mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result
      mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result
      mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result
      mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result
      mysql-test/suite/rpl/r/rpl_row_mixing_engines.result
      mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result
      mysql-test/t/order_by.test
      mysql-test/t/partition.test
      mysql-test/t/partition_pruning.test
      sql/ha_partition.cc
      sql/ha_partition.h
      sql/log.cc
      sql/net_serv.cc
      sql/opt_range.cc
      sql/sql_cache.cc
      sql/sql_select.cc
      sql/sql_table.cc
=== modified file 'BUILD/build_mccge.sh'
--- a/BUILD/build_mccge.sh	2010-08-06 13:17:51 +0000
+++ b/BUILD/build_mccge.sh	2010-09-27 05:55:33 +0000
@@ -71,9 +71,10 @@ cat <<EOF
   same type as that on which you intend to run MySQL/MySQL Cluster.
 
   The simplest possible way to run this script is to allow it to use the 
-  built-in defaults everywhere, invoking it simply as:
+  built-in defaults everywhere, invoking it simply as (from top-level
+  MySQL directory):
 
-  shell> ./build_mccge.sh
+  shell> BUILD/build_mccge.sh
 
   This performs the following operations:
     1) Detects the operating system. Currently, Linux, FreeBSD, Solaris 
@@ -128,7 +129,7 @@ cat <<EOF
   information in the binary then use --debug.
 
   If your aim is not to build MySQL Cluster Carrier Grade Edition, you 
-  can also use this script to build MySQL Classic and MySQL Pro 
+  can also use this script to build MySQL Classic and MySQL Enterprise Pro 
   versions; see the --extended-help for descriptions of these packages.
 EOF
 }
@@ -147,7 +148,13 @@ Usage: $0 [options]
                           configure
   --extended-help         Show extended help message
   --without-debug         Build non-debug version
+  --use-comment           Set the comment in the build
+  --with-fast-mutexes     Use try/retry method of acquiring mutex
   --with-debug            Build debug version
+  --with-link-time-optimizer
+                          Link time optimizations enabled (Requires GCC 4.5
+                          if GCC used), available for icc as well. This flag
+                          is only considered if also fast is set.
   --configure-only        Stop after running configure.
   --use-autotools         Start by running autoconf, automake,.. tools
   --no-autotools          Start from configure
@@ -297,6 +304,7 @@ extended_usage()
     by MySQL (cannot be overridden).
 
   --with-ssl: Enable use of yaSSL library included in the MySQL source
+    if possible (GCC and same CC and CXX).
     (cannot be overridden).
 
   --with-pic: Build all binaries using position independent assembler
@@ -377,17 +385,17 @@ extended_usage()
   Compiler options:
   -----------------
 
-  This section describes the compiler options for each of the different
-  platforms supported by this script.
+    This section describes the compiler options for each of the different
+    platforms supported by this script.
 
-  The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides
-  support for Nocona, K8, and other processors).
+    The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides
+    support for Nocona, K8, and other processors).
 
-  Use of the --debug option adds -g to the C/C++ flags.
+    Use of the --debug option adds -g to the C/C++ flags.
 
-  In all cases it is possible to override the definition of CC and CXX
-  by calling the script as follows:
-  CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh
+    In all cases it is possible to override the definition of CC and CXX
+    by calling the script as follows:
+    CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh
 
   FreeBSD/x86/gcc
   ---------------
@@ -411,15 +419,19 @@ extended_usage()
 
     On Itanium we also add -no-ftz and to CC and C++ flags.
 
-  The non-debug versions also add the following:
-    C/C++ flags += -O3 unroll2 -ip
-
-  The fast version adds:
-    C/C++ flags += -ipo
-
-  On discovery of a Core 2 Duo architecture while using icc, -xT is also 
-  added to the C/C++ flags; this provides optimisations specific to Core 
-  2 Duo. This is added only when the --fast flag is set.
+    Note that if the user of this script sets CC or CXX explicitly then
+    also -static-libgcc and -static-intel needs to be set in the CC and
+    CXX.
+
+    The non-debug versions also add the following:
+      C/C++ flags += -O3 unroll2 -ip
+
+    The fast version adds (if --with-link-time-optimizer is used):
+      C/C++ flags += -ipo
+
+    On discovery of a Core 2 Duo architecture while using icc, -xT is also 
+    added to the C/C++ flags; this provides optimisations specific to Core 
+    2 Duo. This is added only when the --fast flag is set.
 
   Solaris/x86/gcc
   ---------------
@@ -445,7 +457,7 @@ extended_usage()
     Sparc v9 binaries, also -mt is set in all those since we're always
     building a multithreaded program.
 
-    C flags   = -xstrconst
+    C flags   = -xstrconst    This flag is set only on SPARC
     C++ flags = -noex
 
     Set the following C/C++ flags:
@@ -458,8 +470,10 @@ extended_usage()
 
     Set the C++ flag:
     -noex
+    -features=no%except    This flag is set only on x86
 
-    When compiling with fast we set:
+    When compiling with fast we set (-ipo only used if we have
+    set --with-link-time-optimizer):
     C/C++ flags: -xtarget=native -xunroll=3 -xipo
     LDFLAGS: -xipo
 
@@ -471,6 +485,11 @@ extended_usage()
 
     When compiling with fast on x86 we also set:
     C/C++ flags: -xregs=frameptr
+    When not compiling with fast we set on x86
+    C/C++ flags: -xregs=no%frameptr
+
+    On SPARC we set
+    ASFLAGS = LDFLAGS = C/C++ flags = -xarch=sparc
 
     The optimisation level is
     -xO         Debug builds
@@ -480,17 +499,19 @@ extended_usage()
 
   MacOSX/x86/gcc
   --------------
-  C/C++ flags include -fno-common -arch i386.
+    C/C++ flags include -fno-common -arch i386.
+    When 64-bits builds then i386 is replaced by x86_64.
 
-  Non-debug versions also add -Os -felide-constructors, where "-Os"
-  means the build is space-optimised as long as the space optimisations
-  do not negatively affect performance. Debug versions use -O.
+    Non-debug versions also add -Os -felide-constructors, where "-Os"
+    means the build is space-optimised as long as the space optimisations
+    do not negatively affect performance. Debug versions use -O.
   
-  Mac OS X builds will always be 32-bit by default, when --64 is added
-  the build will be 64 bit instead. Thus the flag --m64 is added only
-  when specifically given as an option.
+    Mac OS X builds will always be 32-bit by default, when --64 is added
+    the build will be 64 bit instead. Thus the flag --m64 is added only
+    when specifically given as an option.
 EOF
 }
+
 with_usage()
 {
   cat <<EOF
@@ -593,13 +614,13 @@ parse_cpu_type()
   case "$cpu_type" in
     x86 )
       cpu_type="x86"
-      if test "x$m64" != "x" ; then
+      if test "x$m64" = "x" ; then
         m64="no"
       fi
       ;;
     x86_64 )
       cpu_type="x86"
-      if test "x$m64" != "x" ; then
+      if test "x$m64" = "x" ; then
         m64="yes"
       fi
       ;;
@@ -629,10 +650,7 @@ parse_compiler()
     icc )
       compiler="icc"
       ;;
-    forte )
-      compiler="forte"
-      ;;
-    SunStudio | sunstudio )
+    forte | SunStudio | sunstudio )
       compiler="forte"
       ;;
     *)
@@ -653,12 +671,21 @@ parse_options()
     --datadir=*)
       datadir=`get_key_value "$1"`
       ;;
+    --with-link-time-optimizer)
+      with_link_time_optimizer="yes"
+      ;;
     --without-debug)
       with_debug_flag="no"
       if test "x$fast_flag" != "xyes" ; then
         fast_flag="generic"
       fi
       ;;
+    --use-comment)
+      without_comment="no"
+      ;;
+    --with-fast-mutexes)
+      with_fast_mutexes="yes"
+      ;;
     --use-tcmalloc)
       use_tcmalloc="yes"
       ;;
@@ -817,9 +844,11 @@ set_cpu_base()
     fi
     case "$cpu_arg" in
       core2 | nocona | prescott | pentium* | i*86 )
+        # Intel CPU
         cpu_base_type="x86"
         ;;
-      athlon* | opteron* )
+      athlon* | opteron* | k6 | k8 )
+        # AMD CPU
         cpu_base_type="x86"
         ;;
       sparc )
@@ -871,15 +900,15 @@ init_configure_commands()
   cxxflags="$cxx_warnings $base_cxxflags $compiler_flags"
   configure="./configure $base_configs $with_flags"
 
-  flags="CC=\"$CC\" CFLAGS=\"$cflags\" CXX=\"$CXX\" CXXFLAGS=\"$cxxflags\""
+  env_flags="CC=\"$CC\" CFLAGS=\"$cflags\" CXX=\"$CXX\" CXXFLAGS=\"$cxxflags\""
   if test "x$LDFLAGS" != "x" ; then
-    flags="$flags LDFLAGS=\"$LDFLAGS\""
+    env_flags="$env_flags LDFLAGS=\"$LDFLAGS\""
   fi
   if test "x$ASFLAGS" != "x" ; then
-    flags="$flags ASFLAGS=\"$ASFLAGS\""
+    env_flags="$env_flags ASFLAGS=\"$ASFLAGS\""
   fi
   commands="$commands
-    $flags $configure"
+    $env_flags $configure"
 } 
 
 #
@@ -1082,6 +1111,18 @@ set_debug_flag()
 }
 
 #
+# We compile in SSL support if we can, this isn't possible if CXX
+# and CC aren't the same and we're not using GCC.
+# 
+set_ssl()
+{
+  if test "x$compiler" = "xgcc" && \
+     test "x$CC" = "x$CXX" ; then
+    base_configs="$base_configs --with-ssl"
+  fi
+}
+
+#
 # Base options used by all packages
 #
 # SSL library to use. --with-ssl selects the bundled yaSSL
@@ -1105,10 +1146,13 @@ set_base_configs()
   base_configs="$base_configs --enable-local-infile"
   base_configs="$base_configs --enable-thread-safe-client"
   base_configs="$base_configs --with-big-tables"
-  base_configs="$base_configs --with-extra-charsets=complex"
-  base_configs="$base_configs --with-ssl"
+  base_configs="$base_configs --with-extra-charsets=all"
+  if test "x$with_fast_mutexes" = "xyes" ; then
+    base_configs="$base_configs --with-fast-mutexes"
+  fi
   base_configs="$base_configs --with-pic"
   base_configs="$base_configs --with-csv-storage-engine"
+  base_configs="$base_configs --with-perfschema"
 }
 
 #
@@ -1139,7 +1183,9 @@ set_ndb_engine()
 
 set_pro_package()
 {
-  base_configs="$base_configs --with-comment=\"MySQL Pro $version_text built from source\""
+  if test "x$without_comment" != "xyes" ; then
+    base_configs="$base_configs --with-comment=\"MySQL Enterprise Pro $version_text built from source\""
+  fi
   if test "x$with_debug_flag" = "xyes" ; then
     base_configs="$base_configs --with-server-suffix=\"-debug\""
   fi
@@ -1147,33 +1193,37 @@ set_pro_package()
 
 set_cge_extended_package()
 {
-  if test "x$gpl" = "xno" ; then
-    echo "Cannot build Extended Carrier Grade Edition as Commercial version"
+  if test "x$without_comment" != "xyes" ; then
+    base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Extended Edition $version_text built from source\""
   fi
-  base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Extended Edition $version_text built from source\""
   if test "x$with_debug_flag" = "xyes" ; then
     base_configs="$base_configs --with-server-suffix=\"-cge-extended-debug\""
   else
-    base_configs="$base_configs --with-server-suffix=\"-cge-extended"\"
+    base_configs="$base_configs --with-server-suffix=\"-cge-extended\""
   fi
 }
 
 set_cge_package()
 {
-  base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Edition $version_text built from source\""
+  if test "x$without_comment" != "xyes" ; then
+    base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Edition $version_text built from source\""
+  fi
   if test "x$with_debug_flag" = "xyes" ; then
     base_configs="$base_configs --with-server-suffix=\"-cge-debug\""
   else
-    base_configs="$base_configs --with-server-suffix=\"-cge"\"
+    base_configs="$base_configs --with-server-suffix=\"-cge\""
   fi
 }
 
 set_classic_package()
 {
-  base_configs="$base_configs --with-comment=\"MySQL Classic $version_text built from source\""
+  if test "x$without_comment" != "xyes" ; then
+    base_configs="$base_configs --with-comment=\"MySQL Classic $version_text built from source\""
+  fi
   if test "x$with_debug_flag" = "xyes" ; then
     base_configs="$base_configs --with-server-suffix=\"-debug\""
   fi
+  base_configs="$base_configs --without-example-storage-engine"
 }
 
 #
@@ -1204,10 +1254,10 @@ set_gcc_special_options()
 set_cc_and_cxx_for_gcc()
 {
   if test "x$CC" = "x" ; then
-    CC="gcc -static-libgcc"
+    CC="gcc -static-libgcc -fno-exceptions"
   fi
   if test "x$CXX" = "x" ; then
-    CXX="gcc -static-libgcc"
+    CXX="gcc -static-libgcc -fno-exceptions"
   fi
 }
 
@@ -1266,6 +1316,61 @@ set_bsd_configs()
   set_cc_and_cxx_for_gcc
 }
 
+check_64_bits()
+{
+  echo "Checking for 32/64-bits compilation"
+  echo "int main() { return 0; }" > temp_test.c
+  if test "x$m64" = "xyes" ; then
+    cmd="$CC $compile_flags -m64 temp_test.c"
+    if ! $cmd 2>1 ; then
+      m64="no"
+      echo "Changing to 32-bits since 64-bits didn't work"
+    else
+      echo "Will use 64-bits"
+    fi
+  else
+    cmd="$CC $compile_flags -m32 temp_test.c"
+    if ! $cmd 2>1 ; then
+      m64="yes"
+      echo "Changing to 64-bits since 32-bits didn't work"
+    else
+      echo "Will use 32-bits"
+    fi
+  fi
+  rm temp_test.c
+}
+
+#
+# Get GCC version
+#
+get_gcc_version()
+{
+  # check if compiler is gcc and dump its version
+  cc_verno=`$cc -dumpversion 2>/dev/null`
+  if test "x$?" = "x0" ; then
+    set -- `echo $cc_verno | tr '.' ' '`
+    cc_ver="GCC"
+    cc_major=$1
+    cc_minor=$2
+    cc_patch=$3
+    gcc_version=`expr $cc_major '*' 100 '+' $cc_minor`
+  fi
+}
+
+#
+# Link Time Optimizer in GCC (LTO) uses a parameter -flto
+# which was added to GCC 4.5, if --with-link-time-optimizer
+# is set then use this feature
+#
+check_for_link_time_optimizer()
+{
+  get_gcc_version
+  if test "$gcc_version" -ge 405 && \
+     test "x$with_link_time_optimizer" = "xyes" ; then
+    compiler_flags="$compiler_flags -flto"
+    LDFLAGS="$LDFLAGS -flto"
+  fi
+}
 #
 # Linux Section
 #
@@ -1284,20 +1389,22 @@ set_linux_configs()
   fi
   if test "x$compiler" = "xgcc" ; then
     set_cc_and_cxx_for_gcc
-    if test "x$m64" = "xyes" ; then
-      compiler_flags="$compiler_flags -m64"
-    else
-      compiler_flags="$compiler_flags -m32"
-    fi
     if test "x$fast_flag" != "xno" ; then
       if test "x$fast_flag" = "xyes" ; then
         compiler_flags="$compiler_flags -O3"
+        check_for_link_time_optimizer
       else
         compiler_flags="$compiler_flags -O2"
       fi
     else
       compiler_flags="$compiler_flags -O0"
     fi
+    check_64_bits
+    if test "x$m64" = "xyes" ; then
+      compiler_flags="$compiler_flags -m64"
+    else
+      compiler_flags="$compiler_flags -m32"
+    fi
 # configure will set proper compiler flags for gcc on Linux
   elif test "x$compiler" = "xicc" ; then
     compiler_flags="$compiler_flags -mp -restrict"
@@ -1307,8 +1414,10 @@ set_linux_configs()
     fi
     if test "x$fast_flag" != "xno" ; then
       compiler_flags="$compiler_flags -O3 -unroll2 -ip"
-      if test "x$fast_flag" = "xyes" ; then
+      if test "x$fast_flag" = "xyes" && \
+         test "x$with_link_time_optimizer" = "xyes" ; then
         compiler_flags="$compiler_flags -ipo"
+        LDFLAGS="$LDFLAGS -ipo"
       fi
     fi
   else
@@ -1323,11 +1432,16 @@ set_linux_configs()
 set_solaris_configs()
 {
 # Use mtmalloc as malloc, see Tim Cook blog
-  base_configs="$base_configs --with-mysqld-libs=-lmtmalloc"
+# For information on optimal compiler settings, see article at
+# http://developers.sun.com/solaris/articles/mysql_perf_tune.html
+# by Luojia Chen at Sun.
   base_configs="$base_configs --with-named-curses=-lcurses"
   case "`uname -a`" in
-    *5.8* | *5.9* | *5.10* | *5.11*)
+    *5.8* | *5.9* )
+      ;;
 
+    *5.10* | *5.11*)
+      base_configs="$base_configs --with-mysqld-libs=-lmtmalloc"
       ;;
     *)
       usage "Only versions 8,9, 10 and 11 supported for Solaris"
@@ -1361,6 +1475,7 @@ set_solaris_configs()
     if test "x$fast_flag" = "xyes" ; then
       LDFLAGS="$LDFLAGS -O3"
       compiler_flags="$compiler_flags -O3"
+      check_for_link_time_optimizer
     else
       if test "x$fast_flag" = "xgeneric" ; then
         LDFLAGS="$LDFLAGS -O2"
@@ -1373,44 +1488,50 @@ set_solaris_configs()
   else
 #Using Forte compiler (SunStudio)
     set_cc_and_cxx_for_forte
-    base_cflags="$base_cflags -xstrconst"
     compiler_flags="$compiler_flags -mt"
-    LD_FLAGS="$LD_FLAGS -mt"
+    LDFLAGS="$LDFLAGS -mt"
     compiler_flags="$compiler_flags -fsimple=1"
     compiler_flags="$compiler_flags -ftrap=%none"
     compiler_flags="$compiler_flags -xbuiltin=%all"
     compiler_flags="$compiler_flags -xlibmil"
     compiler_flags="$compiler_flags -xlibmopt"
-    base_cxxflags="$base_cxxflags -noex"
     if test "x$fast_flag" = "xyes" ; then
       compiler_flags="$compiler_flags -xtarget=native"
-      compiler_flags="$compiler_flags -xipo"
       compiler_flags="$compiler_flags -xunroll=3"
-      LD_FLAGS="$LD_FLAGS -xipo"
+      if test "x$with_link_time_optimizer" = "xyes" ; then
+        compiler_flags="$compiler_flags -xipo"
+        LDFLAGS="$LDFLAGS -xipo"
+      fi
     else
       compiler_flags="$compiler_flags -xtarget=generic"
     fi
     if test "x$cpu_base_type" = "xx86" ; then
       compiler_flags="$compiler_flags -nofstore"
+      base_cxx_flags="$base_cxx_flags -features=no%except"
       if test "x$fast_flag" = "xyes" ; then
         compiler_flags="$compiler_flags -xregs=frameptr"
         compiler_flags="$compiler_flags -xO4"
-      elif test "x$fast_flag" = "xgeneric" ; then
-        compiler_flags="$compiler_flags -xO2"
       else
-        compiler_flags="$compiler_flags -xO0"
+        compiler_flags="$compiler_flags -xregs=no%frameptr"
+        if test "x$fast_flag" = "xgeneric" ; then
+          compiler_flags="$compiler_flags -xO2"
+        else
+          compiler_flags="$compiler_flags -xO0"
+        fi
       fi
     else
 #Using SPARC cpu with SunStudio (Forte) compiler
       ASFLAGS="$ASFLAGS -xarch=sparc"
       LDFLAGS="$LDFLAGS -xarch=sparc"
+      base_cxxflags="$base_cxxflags -noex"
+      base_cflags="$base_cflags -xstrconst"
       compiler_flags="$compiler_flags -xarch=sparc"
       if test "x$fast_flag" = "xyes" ; then
         compiler_flags="$compiler_flags -xbinopt=prepare"
         LDFLAGS="$LDFLAGS -xbinopt=prepare"
         compiler_flags="$compiler_flags -xO4"
       elif test "x$fast_flag" = "xgeneric" ; then
-        compiler_flags="$compiler_flags -xO2"
+        compiler_flags="$compiler_flags -xO3"
       else
         compiler_flags="$compiler_flags -xO0"
       fi
@@ -1432,7 +1553,7 @@ set_macosx_configs()
 # optimisations also when not in fast mode.
 #
   base_cxxflags="$base_cxxflags -felide-constructors"
-  base_cxxflags="$base_cxxflags -fno-common"
+  compiler_flags="$compiler_flags -fno-common"
   if test "x$m64" = "xyes" ; then
     compiler_flags="$compiler_flags -m64"
     compiler_flags="$compiler_flags -arch x86_64"
@@ -1526,7 +1647,7 @@ fi
 cpu_type=
 package=
 prefix="/usr/local/mysql"
-parallelism="4"
+parallelism="8"
 fast_flag="generic"
 compiler="gcc"
 gpl="yes"
@@ -1562,6 +1683,10 @@ engine_configs=
 ASFLAGS=
 LDFLAGS=
 use_tcmalloc=
+without_comment="yes"
+with_fast_mutexes=
+with_link_time_optimizer=
+gcc_version="0"
 
 set_defaults_based_on_environment
 
@@ -1656,7 +1781,7 @@ elif test "x$os" = "xbsd" ; then
 else
   die "Operating system not supported by this script"
 fi
-
+set_ssl
 #
 # Final step before setting up commands is to set up proper make and
 # proper libtoolize versions, and to determine whether to use ccache.

=== modified file 'BUILD/check-cpu'
--- a/BUILD/check-cpu	2010-08-05 12:32:23 +0000
+++ b/BUILD/check-cpu	2010-09-16 08:04:10 +0000
@@ -4,6 +4,7 @@
 # best compiler optimization flags for gcc
 # Will return result in:
 # cpu_arg        : Type of CPU
+# low_cpu_arg    : Type of CPU used up until GCC v3.3
 # check_cpu_args : Arguments for GCC compiler settings
 #
 
@@ -33,7 +34,7 @@ check_compiler_cpu_flags () {
         case `gcc -dumpmachine` in
           i?86-* | x86_64-*)
 	    if test "$cc_comp" -lt 304 ; then
-              check_cpu_cflags="-mcpu=${cpu_arg}"
+              check_cpu_cflags="-mcpu=${low_cpu_arg}"
             elif test "$cc_comp" -ge 402 ; then
               check_cpu_cflags="-mtune=native"
             else
@@ -141,9 +142,10 @@ check_cpu () {
   # detect CPU shortname as used by gcc options 
   # this list is not complete, feel free to add further entries
   cpu_arg=""
-  case "$cpu_family--$model_name--$spu_arch" in
+  low_cpu_arg=""
+  case "$cpu_vendor--$cpu_family--$model_name--$spu_arch" in
     # DEC Alpha
-    Alpha*EV6*)
+    *Alpha*EV6*)
       cpu_arg="ev6";
       ;;
     #Core 2 Duo  
@@ -172,6 +174,13 @@ check_cpu () {
     *Pentium*4*Mobile*)
       cpu_arg="pentium4m"
       ;;
+    *Pentium\(R\)*\ M*)
+      cpu_arg="pentium-m"
+      low_cpu_arg="pentium3"
+      ;;
+    *Pentium\(R\)*\ D*)
+      cpu_arg="prescott"
+      ;;
     *Pentium*4*)
       cpu_arg="pentium4"
       ;;
@@ -196,6 +205,12 @@ check_cpu () {
     *Celeron*)
       cpu_arg="pentium2"
       ;;
+    *Atom*)
+      cpu_arg="prescott"
+      ;;
+    *GenuineIntel*)
+      cpu_arg="pentium"
+      ;;
     *Turion*)
       cpu_arg="athlon64"
       ;;
@@ -205,9 +220,30 @@ check_cpu () {
     *Athlon*)
       cpu_arg="athlon"
       ;;
+    *AMD-K7*)
+      cpu_arg="athlon"
+      ;;
+    *Athlon*XP\ *)
+      cpu_arg="athlon-xp"
+      ;;
+    *AMD*Sempron\(tm\)*)
+      cpu_arg="athlon-mp"
+      ;;
+    *AMD*Athlon\(tm\)\ 64*)
+      cpu_arg="k8"
+      ;;
     *Opteron*)
       cpu_arg="opteron"
       ;;
+    *Phenom*)
+      cpu_arg="k8"
+      ;;
+    *AuthenticAMD*)
+      cpu_arg="k6"
+      ;;
+    *VIA\ *)
+      cpu_arg="i686"
+      ;;
     # MacOSX / Intel  
     *i386*i486*)
       cpu_arg="pentium-m"
@@ -239,6 +275,10 @@ check_cpu () {
       ;;
   esac
 
+  if test "x$low_cpu_arg" = "x" ; then
+    low_cpu_arg="$cpu_arg"
+  fi
+
   if test -z "$cpu_arg" ; then
     if test "$CPUINFO" != " " ; then
       # fallback to uname if necessary

=== modified file 'CMakeLists.txt'
--- a/CMakeLists.txt	2010-08-12 15:27:53 +0000
+++ b/CMakeLists.txt	2010-09-27 05:55:33 +0000
@@ -112,7 +112,8 @@ OPTION(MYSQL_MAINTAINER_MODE "MySQL main
 # Whether the maintainer mode should be enabled.
 IF(MYSQL_MAINTAINER_MODE)
   IF(CMAKE_COMPILER_IS_GNUCC)
-    SET(MY_MAINTAINER_C_WARNINGS "-Wall -Wextra -Wunused -Wwrite-strings -Werror"
+    SET(MY_MAINTAINER_C_WARNINGS
+        "-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror"
         CACHE STRING "C warning options used in maintainer builds.")
   ENDIF()
   IF(CMAKE_COMPILER_IS_GNUCXX)

=== modified file 'config/ac-macros/maintainer.m4'
--- a/config/ac-macros/maintainer.m4	2010-07-09 12:51:21 +0000
+++ b/config/ac-macros/maintainer.m4	2010-09-24 12:36:31 +0000
@@ -16,7 +16,7 @@ AC_DEFUN([MY_MAINTAINER_MODE], [
 AC_DEFUN([MY_MAINTAINER_MODE_WARNINGS], [
   # Setup GCC warning options.
   AS_IF([test "$GCC" = "yes"], [
-    C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Werror"
+    C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror"
     CXX_WARNINGS="${C_WARNINGS} -Wno-unused-parameter"
   ])
 

=== modified file 'mysql-test/include/index_merge_ror_cpk.inc'
--- a/mysql-test/include/index_merge_ror_cpk.inc	2006-08-16 12:58:49 +0000
+++ b/mysql-test/include/index_merge_ror_cpk.inc	2010-09-16 12:13:53 +0000
@@ -126,3 +126,19 @@ WHERE
 
 drop table t1;
 
+--echo #
+--echo # Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB
+--echo #
+CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1));
+INSERT INTO t1 VALUES (2);
+CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1),
+                 PRIMARY KEY (f1), KEY (f2), KEY (f3) );
+INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, '');
+
+SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+
+EXPLAIN SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+
+DROP TABLE t1,t2;

=== modified file 'mysql-test/r/index_merge_innodb.result'
--- a/mysql-test/r/index_merge_innodb.result	2009-10-08 09:27:45 +0000
+++ b/mysql-test/r/index_merge_innodb.result	2010-09-16 12:20:35 +0000
@@ -255,3 +255,21 @@ WHERE
 `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND
 `TESTID`='' AND `UCCHECK`='';
 drop table t1;
+#
+# Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB
+#
+CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1));
+INSERT INTO t1 VALUES (2);
+CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1),
+PRIMARY KEY (f1), KEY (f2), KEY (f3) );
+INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, '');
+SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+f1
+2
+EXPLAIN SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
+2	DEPENDENT SUBQUERY	t2	index_merge	f2,f3	f3,f2	2,5	NULL	1	Using intersect(f3,f2); Using where; Using index
+DROP TABLE t1,t2;

=== modified file 'mysql-test/r/index_merge_myisam.result'
--- a/mysql-test/r/index_merge_myisam.result	2010-01-06 10:54:45 +0000
+++ b/mysql-test/r/index_merge_myisam.result	2010-09-16 12:20:35 +0000
@@ -1414,6 +1414,24 @@ WHERE
 `TESTID`='' AND `UCCHECK`='';
 drop table t1;
 #
+# Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB
+#
+CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1));
+INSERT INTO t1 VALUES (2);
+CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1),
+PRIMARY KEY (f1), KEY (f2), KEY (f3) );
+INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, '');
+SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+f1
+2
+EXPLAIN SELECT t1.f1 FROM t1
+WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	system	PRIMARY	NULL	NULL	NULL	1	
+2	DEPENDENT SUBQUERY	t2	ref	f2,f3	f2	5		1	Using where
+DROP TABLE t1,t2;
+#
 # Generic @@optimizer_switch tests (move those into a separate file if
 #  we get another @@optimizer_switch user)
 #

=== modified file 'mysql-test/r/order_by.result'
--- a/mysql-test/r/order_by.result	2010-05-31 12:52:19 +0000
+++ b/mysql-test/r/order_by.result	2010-09-13 12:46:55 +0000
@@ -1617,6 +1617,27 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	t1	range	a	a	5	NULL	2	Using where; Using temporary; Using filesort
 1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	10	Using join buffer
 DROP TABLE t1, t2;
+#
+# Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and
+# ORDER BY computed col
+#
+CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, KEY( a, b ) );
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
+CREATE TABLE t2( a INT PRIMARY KEY, b INT );
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t2 SELECT a + 5, b + 5 FROM t2;
+EXPLAIN
+SELECT count(*) AS c, t1.a
+FROM t1 JOIN t2 ON t1.b = t2.a
+WHERE t2.b = 1
+GROUP BY t1.a
+ORDER by c
+LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	index	NULL	a	8	NULL	10	Using index; Using temporary; Using filesort
+1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.b	1	Using where
+DROP TABLE t1, t2;
 End of 5.1 tests
 #
 # Bug #38745: MySQL 5.1 optimizer uses filesort for ORDER BY

=== modified file 'mysql-test/r/partition.result'
--- a/mysql-test/r/partition.result	2010-08-26 21:26:02 +0000
+++ b/mysql-test/r/partition.result	2010-09-27 05:55:33 +0000
@@ -1,4 +1,29 @@
 drop table if exists t1, t2;
+#
+# Bug#55458: Partitioned MyISAM table gets crashed by multi-table update 
+#
+CREATE TABLE t1 (
+`id` int NOT NULL,
+`user_num` int DEFAULT NULL,
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM CHARSET=latin1;
+INSERT INTO t1 VALUES (1,8601);
+INSERT INTO t1 VALUES (2,8601);
+INSERT INTO t1 VALUES (3,8601);
+INSERT INTO t1 VALUES (4,8601);
+CREATE TABLE t2 (
+`id` int(11) NOT NULL,
+`user_num` int DEFAULT NULL,
+`name` varchar(64) NOT NULL,
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM CHARSET=latin1
+PARTITION BY HASH (id)
+PARTITIONS 2;
+INSERT INTO t2 VALUES (1,8601,'John');
+INSERT INTO t2 VALUES (2,8601,'JS');
+INSERT INTO t2 VALUES (3,8601,'John S');
+UPDATE t1, t2 SET t2.name = 'John Smith' WHERE t1.user_num = t2.user_num;
+DROP TABLE t1, t2;
 # Bug#39338: Fieldnames in
 #   INFORMATIONSCHEMA.PARTITIONS.PARTITION_EXPRESSION become unescaped
 # NOTE: the partition expression is saved as a string, so changing from
@@ -1472,7 +1497,7 @@ NULL
 2
 explain partitions select * from t1 where a is null or a < 0 or a > 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pn,p2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	pn,p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 drop table t1;
 CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, name VARCHAR(20)) 
 ENGINE=MyISAM DEFAULT CHARSET=latin1

=== modified file 'mysql-test/r/partition_column.result'
--- a/mysql-test/r/partition_column.result	2010-05-26 07:56:55 +0000
+++ b/mysql-test/r/partition_column.result	2010-09-14 08:56:11 +0000
@@ -611,7 +611,7 @@ partition p1 values less than (3,3),
 partition p2 values less than (9,5));
 explain partitions select * from t1 where b < 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	5	Using where
 select * from t1 where b < 2;
 a	b
 0	1
@@ -647,7 +647,7 @@ alter table t1 reorganize partition p2 i
 partition p22 values less than (9,5));
 explain partitions select * from t1 where b < 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p11,p12,p21	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0,p11,p12,p21	ALL	NULL	NULL	NULL	NULL	6	Using where
 select * from t1 where b < 4;
 a	b
 0	1

=== modified file 'mysql-test/r/partition_column_prune.result'
--- a/mysql-test/r/partition_column_prune.result	2009-11-30 15:55:03 +0000
+++ b/mysql-test/r/partition_column_prune.result	2010-09-14 08:56:11 +0000
@@ -59,8 +59,8 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p01,p02,p03,p11	ALL	NULL	NULL	NULL	NULL	8	Using where
 explain partitions select * from t1 where a=4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p11,p12,p13,p21	ALL	NULL	NULL	NULL	NULL	14	Using where
+1	SIMPLE	t1	p11,p12,p13,p21	ALL	NULL	NULL	NULL	NULL	8	Using where
 explain partitions select * from t1 where a=2 and b < 22;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p01,p02,p03	ALL	NULL	NULL	NULL	NULL	14	Using where
+1	SIMPLE	t1	p01,p02,p03	ALL	NULL	NULL	NULL	NULL	6	Using where
 drop table t1;

=== modified file 'mysql-test/r/partition_hash.result'
--- a/mysql-test/r/partition_hash.result	2009-10-05 20:59:19 +0000
+++ b/mysql-test/r/partition_hash.result	2010-09-13 13:56:56 +0000
@@ -69,31 +69,31 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0,p1,p2,p3	ALL	NULL	NULL	NULL	NULL	9	Using where
 explain partitions select * from t1 where a is null or (a >= 5 and a <= 7);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p2,p3	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p0,p2,p3	ALL	NULL	NULL	NULL	NULL	7	Using where
 explain partitions select * from t1 where a is null;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
 explain partitions select * from t1 where a is not null;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p0,p1,p2,p3	ALL	NULL	NULL	NULL	NULL	9	Using where
 explain partitions select * from t1 where a >= 1 and a < 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	5	Using where
 explain partitions select * from t1 where a >= 3 and a <= 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p1,p2	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p1,p2	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t1 where a > 2 and a < 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p1	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a > 3 and a <= 6;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p2,p3	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t1 where a > 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p0,p1,p2,p3	ALL	NULL	NULL	NULL	NULL	9	Using where
 explain partitions select * from t1 where a >= 1 and a <= 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2	ALL	NULL	NULL	NULL	NULL	9	Using where
+1	SIMPLE	t1	p0,p1,p2	ALL	NULL	NULL	NULL	NULL	7	Using where
 drop table t1;
 CREATE TABLE t1 (
 a int not null,

=== modified file 'mysql-test/r/partition_innodb.result'
--- a/mysql-test/r/partition_innodb.result	2010-08-20 17:15:48 +0000
+++ b/mysql-test/r/partition_innodb.result	2010-09-13 13:56:56 +0000
@@ -120,31 +120,31 @@ insert INTO t1 VALUES (110);
 ERROR HY000: Table has no partition for value 110
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 90;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	5	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 90;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	5	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 90;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	5	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 89;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p90	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p90	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 89;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p90	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p90	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 89;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 100;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 100;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 100;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1		ALL	NULL	NULL	NULL	NULL	0	Using where
 DROP TABLE t1;
 #
 # Bug#50104: Partitioned table with just 1 partion works with fk

=== modified file 'mysql-test/r/partition_pruning.result'
--- a/mysql-test/r/partition_pruning.result	2010-03-24 15:03:44 +0000
+++ b/mysql-test/r/partition_pruning.result	2010-09-13 13:56:56 +0000
@@ -1,5 +1,29 @@
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
 #
+# Bug#53806: Wrong estimates for range query in partitioned MyISAM table
+# Bug#46754: 'rows' field doesn't reflect partition pruning
+#
+CREATE TABLE t1 (a INT PRIMARY KEY)
+PARTITION BY RANGE (a) (
+PARTITION p0 VALUES LESS THAN (1),
+PARTITION p1 VALUES LESS THAN (2),
+PARTITION p2 VALUES LESS THAN (3),
+PARTITION p3 VALUES LESS THAN (4),
+PARTITION p4 VALUES LESS THAN (5),
+PARTITION p5 VALUES LESS THAN (6),
+PARTITION max VALUES LESS THAN MAXVALUE);
+INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+#	#	#	#	#	#	#	#	#	3	#
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+#	#	#	#	#	#	#	#	#	9	#
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+#	#	#	#	#	#	#	#	#	3	#
+DROP TABLE t1;
+#
 # Bug#49742: Partition Pruning not working correctly for RANGE
 #
 CREATE TABLE t1 (a INT PRIMARY KEY)
@@ -89,7 +113,7 @@ a
 1
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a <= 2;
 a
 -1
@@ -98,7 +122,7 @@ a
 2
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a <= 3;
 a
 -1
@@ -108,7 +132,7 @@ a
 3
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a <= 4;
 a
 -1
@@ -119,7 +143,7 @@ a
 4
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a <= 5;
 a
 -1
@@ -131,7 +155,7 @@ a
 5
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3,p4,p5	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2,p3,p4,p5	index	PRIMARY	PRIMARY	4	NULL	7	Using where; Using index
 SELECT * FROM t1 WHERE a <= 6;
 a
 -1
@@ -213,7 +237,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p1,p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p1,p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	8	Using where; Using index
 SELECT * FROM t1 WHERE a >= 2;
 a
 2
@@ -225,7 +249,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	7	Using where; Using index
 SELECT * FROM t1 WHERE a >= 3;
 a
 3
@@ -236,7 +260,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a >= 4;
 a
 4
@@ -246,7 +270,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a >= 5;
 a
 5
@@ -255,7 +279,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a >= 6;
 a
 6
@@ -263,14 +287,14 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a >= 7;
 a
 7
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 7;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 1;
 a
 2
@@ -282,7 +306,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	7	Using where; Using index
 SELECT * FROM t1 WHERE a > 2;
 a
 3
@@ -293,7 +317,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a > 3;
 a
 4
@@ -303,7 +327,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a > 4;
 a
 5
@@ -312,7 +336,7 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a > 5;
 a
 6
@@ -320,20 +344,20 @@ a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 6;
 a
 7
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 7;
 a
 8
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 7;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 DROP TABLE t1;
 CREATE TABLE t1 (a INT PRIMARY KEY)
 PARTITION BY RANGE (a) (
@@ -408,7 +432,7 @@ a
 1
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a <= 2;
 a
 -1
@@ -417,7 +441,7 @@ a
 2
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a <= 3;
 a
 -1
@@ -427,7 +451,7 @@ a
 3
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a <= 4;
 a
 -1
@@ -438,7 +462,7 @@ a
 4
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a <= 5;
 a
 -1
@@ -511,7 +535,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p1,p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p1,p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	7	Using where; Using index
 SELECT * FROM t1 WHERE a >= 2;
 a
 2
@@ -522,7 +546,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a >= 3;
 a
 3
@@ -532,7 +556,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a >= 4;
 a
 4
@@ -541,7 +565,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a >= 5;
 a
 5
@@ -549,14 +573,14 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a >= 6;
 a
 6
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 1;
 a
 2
@@ -567,7 +591,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
 SELECT * FROM t1 WHERE a > 2;
 a
 3
@@ -577,7 +601,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
 SELECT * FROM t1 WHERE a > 3;
 a
 4
@@ -586,7 +610,7 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
 SELECT * FROM t1 WHERE a > 4;
 a
 5
@@ -594,20 +618,20 @@ a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 5;
 a
 6
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 SELECT * FROM t1 WHERE a > 6;
 a
 7
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
+1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
 DROP TABLE t1;
 # test of RANGE and index
 CREATE TABLE t1 (a DATE, KEY(a))
@@ -757,10 +781,10 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	range	a	a	4	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
@@ -880,34 +904,34 @@ a
 1001-01-01
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p1001-01-01	system	NULL	NULL	NULL	NULL	1	
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 # Disabling warnings for the invalid date
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -917,25 +941,25 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 DROP TABLE t1;
 # test of LIST and index
 CREATE TABLE t1 (a DATE, KEY(a))
@@ -1086,10 +1110,10 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
@@ -1101,7 +1125,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	pNULL,p1001-01-01	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
@@ -1209,62 +1233,62 @@ a
 1001-01-01
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p1001-01-01	system	NULL	NULL	NULL	NULL	1	
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 # Disabling warnings for the invalid date
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 DROP TABLE t1;
 # TO_SECONDS, test of LIST and index
 CREATE TABLE t1 (a DATE, KEY(a))
@@ -1415,10 +1439,10 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
@@ -1430,7 +1454,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01	index	a	a	4	NULL	7	Using where; Using index
+1	SIMPLE	t1	pNULL,p1001-01-01	index	a	a	4	NULL	4	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
@@ -1538,62 +1562,62 @@ a
 1001-01-01
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p1001-01-01	system	NULL	NULL	NULL	NULL	1	
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 # Disabling warnings for the invalid date
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	4	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	5	Using where
 DROP TABLE t1;
 # Test with DATETIME column NOT NULL
 CREATE TABLE t1 (
@@ -1618,25 +1642,25 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	3	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1644,99 +1668,99 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	3	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
+1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	3	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1769,21 +1793,21 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1791,79 +1815,79 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	2	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1871,19 +1895,19 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	8	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1891,11 +1915,11 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	10	Using where; Using index
 DROP TABLE t1;
 # Test with DATETIME column NULL
 CREATE TABLE t1 (
@@ -1919,25 +1943,25 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1945,99 +1969,99 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
+1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	3	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2069,21 +2093,21 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2091,79 +2115,79 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	2	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2171,19 +2195,19 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	8	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2191,11 +2215,11 @@ id	select_type	table	partitions	type	pos
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 EXPLAIN PARTITIONS SELECT * FROM t1
 WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
+1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	10	Using where
 DROP TABLE t1;
 # For better code coverage of the patch
 CREATE TABLE t1 (
@@ -2259,7 +2283,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	3	Using where
 explain partitions select * from t2 where a=1 and b=1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 create table t3 (
 a int
 )
@@ -2317,25 +2341,25 @@ id	select_type	table	partitions	type	pos
 explain partitions select * from t5
 where (a=10 and b=1) or (a=10 and b=2) or (a=10 and b = 3);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t5	p0_p0sp0,p0_p0sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t5	p0_p0sp0,p0_p0sp1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t5 where (a=10 and b=2) or (a=10 and b=3)
 or (a=10 and b = 4);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t5 where (c=1 and d=1);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t5	p0_p0sp0,p1_p1sp0	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t5	p0_p0sp0,p1_p1sp0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t5 where (c=2 and d=1);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t5	p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t5	p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or 
 (c=2 and d=1);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	3	Using where
 explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or 
 (b=2 and c=2 and d=1);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	3	Using where
 create table t6 (a int not null) partition by LIST(a) (
 partition p1 values in (1),
 partition p3 values in (3),
@@ -2373,7 +2397,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t6	p5,p7,p9	system	NULL	NULL	NULL	NULL	1	
 explain partitions select * from t6 where a >= 3 and a <= 8;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t6 where a > 3 and a < 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
@@ -2415,7 +2439,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t6	p5,p7,p9	system	NULL	NULL	NULL	NULL	1	
 explain partitions select * from t6 where a >= 3 and a <= 8;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t6 where a > 3 and a < 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
@@ -2667,7 +2691,7 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p1,p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a >  1 and a <= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2,p3	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t1	p2,p3	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a >= 1 and a <= 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	p1,p2,p3	ALL	NULL	NULL	NULL	NULL	3	Using where
@@ -2757,22 +2781,22 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	
 explain partitions select * from t2 where a < 801 and a > 200;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	800	Using where
 explain partitions select * from t2 where a < 801 and a > 800;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	200	Using where
 explain partitions select * from t2 where a > 600;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where b = 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
@@ -2827,19 +2851,19 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	910	
 explain partitions select * from t2 where a = 101;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	910	Using where
+1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	110	Using where
 explain partitions select * from t2 where a = 550;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	910	Using where
+1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	200	Using where
 explain partitions select * from t2 where a = 833;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	910	Using where
+1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	200	Using where
 explain partitions select * from t2 where (a = 100 OR a = 900);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0,p4	ALL	NULL	NULL	NULL	NULL	910	Using where
+1	SIMPLE	t2	p0,p4	ALL	NULL	NULL	NULL	NULL	310	Using where
 explain partitions select * from t2 where (a > 100 AND a < 600);
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0,p1,p2	ALL	NULL	NULL	NULL	NULL	910	Using where
+1	SIMPLE	t2	p0,p1,p2	ALL	NULL	NULL	NULL	NULL	510	Using where
 explain partitions select * from t2 where b = 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ref	b	b	5	const	76	Using where
@@ -3125,17 +3149,17 @@ id	select_type	table	partitions	type	pos
 explain partitions select * from t1 
 where a >= 18446744073709551000-1 and a <= 18446744073709551000+1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p3,p4	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p3,p4	ALL	NULL	NULL	NULL	NULL	3	Using where
 explain partitions select * from t1 
 where a between 18446744073709551001 and 18446744073709551002;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a = 18446744073709551000;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a = 18446744073709551613;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a = 18446744073709551614;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
@@ -3162,10 +3186,10 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a=0xFE;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t2 where a=0xFE;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a > 0xFE AND a <= 0xFF;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
@@ -3174,22 +3198,22 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 explain partitions select * from t1 where a >= 0xFE AND a <= 0xFF;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t2 where a >= 0xFE AND a <= 0xFF;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a < 64 AND a >= 63;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t2 where a < 64 AND a >= 63;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a <= 64 AND a >= 63;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t2 where a <= 64 AND a >= 63;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	4	Using where
 drop table t1;
 drop table t2;
 create table t1(a bigint unsigned not null) partition by range(a+0) (

=== modified file 'mysql-test/r/partition_range.result'
--- a/mysql-test/r/partition_range.result	2010-08-11 15:55:07 +0000
+++ b/mysql-test/r/partition_range.result	2010-09-13 13:56:56 +0000
@@ -53,10 +53,10 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t1 where a <= '2007-03-07 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a < '2007-03-07 23:59:59';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
@@ -203,13 +203,13 @@ id	select_type	table	partitions	type	pos
 1	SIMPLE	t1	pnull	system	NULL	NULL	NULL	NULL	1	
 explain partitions select * from t1 where a >= 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a < 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 explain partitions select * from t1 where a <= 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pnull,p0	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t1	pnull,p0	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a > 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
@@ -242,16 +242,16 @@ select * from t1 where a > 1;
 a	b
 explain partitions select * from t1 where a is null;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a >= 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t1	p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t1 where a < 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1	ALL	NULL	NULL	NULL	NULL	2	Using where
 explain partitions select * from t1 where a <= 0;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1	ALL	NULL	NULL	NULL	NULL	6	Using where
+1	SIMPLE	t1	pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
 explain partitions select * from t1 where a > 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables

=== modified file 'mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result'
--- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result	2010-09-27 05:55:33 +0000
@@ -53,10 +53,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT my_savepoint
+master-bin.000001	#	Query	#	#	SAVEPOINT `my_savepoint`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO my_savepoint
+master-bin.000001	#	Query	#	#	ROLLBACK TO `my_savepoint`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 delete from t1;
 delete from t2;
@@ -84,10 +84,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT my_savepoint
+master-bin.000001	#	Query	#	#	SAVEPOINT `my_savepoint`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO my_savepoint
+master-bin.000001	#	Query	#	#	ROLLBACK TO `my_savepoint`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result	2010-09-27 05:55:33 +0000
@@ -51,10 +51,10 @@ show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values(3)
-master-bin.000001	#	Query	#	#	SAVEPOINT my_savepoint
+master-bin.000001	#	Query	#	#	SAVEPOINT `my_savepoint`
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values(4)
 master-bin.000001	#	Query	#	#	use `test`; insert into t2 select * from t1
-master-bin.000001	#	Query	#	#	ROLLBACK TO my_savepoint
+master-bin.000001	#	Query	#	#	ROLLBACK TO `my_savepoint`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 delete from t1;
 delete from t2;
@@ -79,10 +79,10 @@ show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values(5)
-master-bin.000001	#	Query	#	#	SAVEPOINT my_savepoint
+master-bin.000001	#	Query	#	#	SAVEPOINT `my_savepoint`
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values(6)
 master-bin.000001	#	Query	#	#	use `test`; insert into t2 select * from t1
-master-bin.000001	#	Query	#	#	ROLLBACK TO my_savepoint
+master-bin.000001	#	Query	#	#	ROLLBACK TO `my_savepoint`
 master-bin.000001	#	Query	#	#	use `test`; insert into t1 values(7)
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 delete from t1;

=== modified file 'mysql-test/suite/innodb/r/innodb_mysql.result'
--- a/mysql-test/suite/innodb/r/innodb_mysql.result	2010-09-10 08:06:58 +0000
+++ b/mysql-test/suite/innodb/r/innodb_mysql.result	2010-09-27 05:55:33 +0000
@@ -2653,3 +2653,13 @@ COMMIT;
 COMMIT;
 DROP TABLE t1;
 DROP FUNCTION f1;
+#
+# Bug#54606 innodb fast alter table + pack_keys=0 
+#           prevents adding new indexes
+#
+CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b)) 
+ENGINE=InnoDB 
+PACK_KEYS=0;
+CREATE INDEX a ON t1 (a);
+CREATE INDEX c on t1 (c);
+DROP TABLE t1;

=== modified file 'mysql-test/suite/innodb/t/innodb_mysql.test'
--- a/mysql-test/suite/innodb/t/innodb_mysql.test	2010-09-10 08:06:58 +0000
+++ b/mysql-test/suite/innodb/t/innodb_mysql.test	2010-09-27 05:55:33 +0000
@@ -830,3 +830,16 @@ connection default;
 COMMIT;
 DROP TABLE t1;
 DROP FUNCTION f1;
+
+--echo #
+--echo # Bug#54606 innodb fast alter table + pack_keys=0 
+--echo #           prevents adding new indexes
+--echo #
+
+CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b)) 
+  ENGINE=InnoDB 
+  PACK_KEYS=0;
+CREATE INDEX a ON t1 (a);
+CREATE INDEX c on t1 (c);
+
+DROP TABLE t1;

=== modified file 'mysql-test/suite/parts/r/partition_alter3_innodb.result'
--- a/mysql-test/suite/parts/r/partition_alter3_innodb.result	2010-06-17 20:51:35 +0000
+++ b/mysql-test/suite/parts/r/partition_alter3_innodb.result	2010-09-13 13:56:56 +0000
@@ -148,7 +148,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -176,7 +176,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -209,7 +209,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -252,7 +252,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -280,7 +280,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -306,7 +306,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -330,7 +330,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -352,7 +352,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -372,7 +372,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -505,7 +505,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -533,7 +533,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -569,7 +569,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -610,7 +610,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -641,7 +641,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -670,7 +670,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	23	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -697,7 +697,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -722,7 +722,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -745,7 +745,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1

=== modified file 'mysql-test/suite/parts/r/partition_alter3_myisam.result'
--- a/mysql-test/suite/parts/r/partition_alter3_myisam.result	2008-11-12 17:51:47 +0000
+++ b/mysql-test/suite/parts/r/partition_alter3_myisam.result	2010-08-27 08:43:51 +0000
@@ -155,7 +155,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -187,7 +187,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -228,7 +228,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -278,7 +278,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -312,7 +312,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -343,7 +343,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -371,7 +371,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -396,7 +396,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part1	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -418,7 +418,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10';
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -552,7 +552,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -584,7 +584,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -628,7 +628,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p6	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -676,7 +676,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -713,7 +713,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	3	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -747,7 +747,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -778,7 +778,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	5	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -806,7 +806,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	part7	ALL	NULL	NULL	NULL	NULL	7	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1
@@ -831,7 +831,7 @@ t1.frm
 t1.par
 EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	20	Using where
+1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	10	Using where
 # check read single success: 1
 # check read all success: 1
 # check read row by row success: 1

=== modified file 'mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result'
--- a/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result	2010-08-10 11:58:46 +0000
+++ b/mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result	2010-09-27 05:55:33 +0000
@@ -150,14 +150,14 @@ show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO db1.t1 VALUES(20)
-master-bin.000001	#	Query	#	#	SAVEPOINT has_comment
+master-bin.000001	#	Query	#	#	SAVEPOINT `has_comment`
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(30)
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("in savepoint has_comment")
-master-bin.000001	#	Query	#	#	SAVEPOINT mixed_cases
+master-bin.000001	#	Query	#	#	SAVEPOINT `mixed_cases`
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("in savepoint mixed_cases")
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(40)
-master-bin.000001	#	Query	#	#	ROLLBACK TO mixed_cases
-master-bin.000001	#	Query	#	#	ROLLBACK TO has_comment
+master-bin.000001	#	Query	#	#	ROLLBACK TO `mixed_cases`
+master-bin.000001	#	Query	#	#	ROLLBACK TO `has_comment`
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("after rollback to")
 master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(50)
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */

=== modified file 'mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result'
--- a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result	2010-08-04 08:10:38 +0000
+++ b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result	2010-09-27 05:55:33 +0000
@@ -995,7 +995,7 @@ master-bin.000001	#	Query	#	#	use `test_
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test_rpl`; INSERT INTO t1 VALUES (5, 'before savepoint s2')
-master-bin.000001	#	Query	#	#	SAVEPOINT s2
+master-bin.000001	#	Query	#	#	SAVEPOINT `s2`
 master-bin.000001	#	Query	#	#	use `test_rpl`; INSERT INTO t1 VALUES (6, 'after savepoint s2')
 master-bin.000001	#	Table_map	#	#	table_id: # (test_rpl.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F

=== modified file 'mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_mixed_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -10260,9 +10260,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10272,9 +10272,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10312,9 +10312,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10324,9 +10324,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10364,9 +10364,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10376,9 +10376,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -11346,20 +11346,20 @@ ROLLBACK;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -10628,9 +10628,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10640,9 +10640,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10681,9 +10681,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10694,9 +10694,9 @@ master-bin.000001	#	Write_rows	#	#	table
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10735,9 +10735,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10748,9 +10748,9 @@ master-bin.000001	#	Write_rows	#	#	table
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -11718,20 +11718,20 @@ ROLLBACK;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_non_direct_row_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -12240,10 +12240,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12255,10 +12255,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -12298,10 +12298,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12313,10 +12313,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -12356,10 +12356,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12371,10 +12371,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -13579,10 +13579,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
@@ -13590,10 +13590,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -9878,9 +9878,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -9890,9 +9890,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -9930,9 +9930,9 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO nt_1(trans_id, stmt_id) VALUES (319, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -9940,9 +9940,9 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO nt_1(trans_id, stmt_id) VALUES (319, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -9979,20 +9979,20 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO nt_1(trans_id, stmt_id) VALUES (320, 5)
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO nt_1(trans_id, stmt_id) VALUES (320, 5)
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10908,20 +10908,20 @@ ROLLBACK;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/suite/rpl/r/rpl_row_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_row_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -12240,10 +12240,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12255,10 +12255,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -12298,10 +12298,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12313,10 +12313,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -12356,10 +12356,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -12371,10 +12371,10 @@ master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -13579,10 +13579,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
@@ -13590,10 +13590,10 @@ Log_name	Pos	Event_type	Server_id	End_lo
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Table_map	#	#	table_id: # (test.tt_1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result'
--- a/mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result	2010-08-20 03:37:42 +0000
+++ b/mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result	2010-09-27 05:55:33 +0000
@@ -10010,9 +10010,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B N T S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10022,9 +10022,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 4)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (318, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B N T S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10062,9 +10062,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T N S1 T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10074,9 +10074,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (319, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T N S1 T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -10114,9 +10114,9 @@ COMMIT;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> C << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 N T R1 C << -b-b-b-b-b-b-b-b-b-b-b-
@@ -10126,9 +10126,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	COMMIT
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (320, 7)
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 N T R1 C << -e-e-e-e-e-e-e-e-e-e-e-
 
@@ -11051,20 +11051,20 @@ ROLLBACK;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
 -b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 2)
-master-bin.000001	#	Query	#	#	SAVEPOINT s1
+master-bin.000001	#	Query	#	#	SAVEPOINT `s1`
 master-bin.000001	#	Query	#	#	use `test`; INSERT INTO tt_1(trans_id, stmt_id) VALUES (353, 5)
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
-master-bin.000001	#	Query	#	#	ROLLBACK TO s1
+master-bin.000001	#	Query	#	#	ROLLBACK TO `s1`
 master-bin.000001	#	Query	#	#	ROLLBACK
 -e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
 

=== modified file 'mysql-test/t/order_by.test'
--- a/mysql-test/t/order_by.test	2010-05-31 12:52:19 +0000
+++ b/mysql-test/t/order_by.test	2010-09-13 12:46:55 +0000
@@ -1467,6 +1467,31 @@ SELECT * FROM t1 FORCE INDEX FOR JOIN (a
 
 DROP TABLE t1, t2;
 
+--echo #
+--echo # Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and
+--echo # ORDER BY computed col
+--echo #
+CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, KEY( a, b ) );
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
+
+CREATE TABLE t2( a INT PRIMARY KEY, b INT );
+
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t2 SELECT a + 5, b + 5 FROM t2;
+
+EXPLAIN
+SELECT count(*) AS c, t1.a
+FROM t1 JOIN t2 ON t1.b = t2.a
+WHERE t2.b = 1
+GROUP BY t1.a
+ORDER by c
+LIMIT 2;
+
+DROP TABLE t1, t2;
+
+
 --echo End of 5.1 tests
 
 

=== modified file 'mysql-test/t/partition.test'
--- a/mysql-test/t/partition.test	2010-05-28 05:49:57 +0000
+++ b/mysql-test/t/partition.test	2010-09-27 05:55:33 +0000
@@ -14,6 +14,34 @@
 drop table if exists t1, t2;
 --enable_warnings
 
+--echo #
+--echo # Bug#55458: Partitioned MyISAM table gets crashed by multi-table update 
+--echo #
+CREATE TABLE t1 (
+  `id` int NOT NULL,
+  `user_num` int DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM CHARSET=latin1;
+INSERT INTO t1 VALUES (1,8601);
+INSERT INTO t1 VALUES (2,8601);
+INSERT INTO t1 VALUES (3,8601);
+INSERT INTO t1 VALUES (4,8601);
+CREATE TABLE t2 (
+  `id` int(11) NOT NULL,
+  `user_num` int DEFAULT NULL,
+  `name` varchar(64) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM CHARSET=latin1
+PARTITION BY HASH (id)
+PARTITIONS 2;
+INSERT INTO t2 VALUES (1,8601,'John');
+INSERT INTO t2 VALUES (2,8601,'JS');
+INSERT INTO t2 VALUES (3,8601,'John S');
+
+UPDATE t1, t2 SET t2.name = 'John Smith' WHERE t1.user_num = t2.user_num;
+
+DROP TABLE t1, t2;
+
 --echo # Bug#39338: Fieldnames in
 --echo #   INFORMATIONSCHEMA.PARTITIONS.PARTITION_EXPRESSION become unescaped
 --echo # NOTE: the partition expression is saved as a string, so changing from

=== modified file 'mysql-test/t/partition_pruning.test'
--- a/mysql-test/t/partition_pruning.test	2010-03-24 15:03:44 +0000
+++ b/mysql-test/t/partition_pruning.test	2010-09-13 13:56:56 +0000
@@ -9,6 +9,30 @@ drop table if exists t1,t2,t3,t4,t5,t6,t
 --enable_warnings
 
 --echo #
+--echo # Bug#53806: Wrong estimates for range query in partitioned MyISAM table
+--echo # Bug#46754: 'rows' field doesn't reflect partition pruning
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY)
+PARTITION BY RANGE (a) (
+PARTITION p0 VALUES LESS THAN (1),
+PARTITION p1 VALUES LESS THAN (2),
+PARTITION p2 VALUES LESS THAN (3),
+PARTITION p3 VALUES LESS THAN (4),
+PARTITION p4 VALUES LESS THAN (5),
+PARTITION p5 VALUES LESS THAN (6),
+PARTITION max VALUES LESS THAN MAXVALUE);
+
+INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
+
+--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
+--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
+--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
+DROP TABLE t1;
+
+--echo #
 --echo # Bug#49742: Partition Pruning not working correctly for RANGE
 --echo #
 CREATE TABLE t1 (a INT PRIMARY KEY)

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2010-08-26 14:29:22 +0000
+++ b/sql/ha_partition.cc	2010-09-27 05:55:33 +0000
@@ -232,6 +232,8 @@ void ha_partition::init_handler_variable
   m_innodb= FALSE;
   m_extra_cache= FALSE;
   m_extra_cache_size= 0;
+  m_extra_prepare_for_update= FALSE;
+  m_extra_cache_part_id= NO_CURRENT_PART_ID;
   m_handler_status= handler_not_initialized;
   m_low_byte_first= 1;
   m_part_field_array= NULL;
@@ -5516,9 +5518,6 @@ void ha_partition::get_dynamic_partition
     when performing the sequential scan we will check this recorded value
     and call extra_opt whenever we start scanning a new partition.
 
-    monty: Neads to be fixed so that it's passed to all handlers when we
-    move to another partition during table scan.
-
   HA_EXTRA_NO_CACHE:
     When performing a UNION SELECT HA_EXTRA_NO_CACHE is called from the
     flush method in the select_union class.
@@ -5530,7 +5529,7 @@ void ha_partition::get_dynamic_partition
     for. If no cache is in use they will quickly return after finding
     this out. And we also ensure that all caches are disabled and no one
     is left by mistake.
-    In the future this call will probably be deleted an we will instead call
+    In the future this call will probably be deleted and we will instead call
     ::reset();
 
   HA_EXTRA_WRITE_CACHE:
@@ -5542,8 +5541,9 @@ void ha_partition::get_dynamic_partition
     This is called as part of a multi-table update. When the table to be
     updated is also scanned then this informs MyISAM handler to drop any
     caches if dynamic records are used (fixed size records do not care
-    about this call). We pass this along to all underlying MyISAM handlers
-    and ignore it for the rest.
+    about this call). We pass this along to the first partition to scan, and
+    flag that it is to be called after HA_EXTRA_CACHE when moving to the next
+    partition to scan.
 
   HA_EXTRA_PREPARE_FOR_DROP:
     Only used by MyISAM, called in preparation for a DROP TABLE.
@@ -5698,9 +5698,21 @@ int ha_partition::extra(enum ha_extra_fu
   case HA_EXTRA_PREPARE_FOR_RENAME:
     DBUG_RETURN(prepare_for_rename());
     break;
+  case HA_EXTRA_PREPARE_FOR_UPDATE:
+    DBUG_ASSERT(m_extra_cache);
+    /*
+      Needs to be run on the first partition in the range now, and 
+      later in late_extra_cache, when switching to a new partition to scan.
+    */
+    m_extra_prepare_for_update= TRUE;
+    if (m_part_spec.start_part != NO_CURRENT_PART_ID)
+    {
+      DBUG_ASSERT(m_extra_cache_part_id == m_part_spec.start_part);
+      (void) m_file[m_part_spec.start_part]->extra(HA_EXTRA_PREPARE_FOR_UPDATE);
+    }
+    break;
   case HA_EXTRA_NORMAL:
   case HA_EXTRA_QUICK:
-  case HA_EXTRA_PREPARE_FOR_UPDATE:
   case HA_EXTRA_FORCE_REOPEN:
   case HA_EXTRA_PREPARE_FOR_DROP:
   case HA_EXTRA_FLUSH_CACHE:
@@ -5723,10 +5735,22 @@ int ha_partition::extra(enum ha_extra_fu
     break;
   }
   case HA_EXTRA_NO_CACHE:
+  {
+    int ret= 0;
+    if (m_extra_cache_part_id != NO_CURRENT_PART_ID)
+      ret= m_file[m_extra_cache_part_id]->extra(HA_EXTRA_NO_CACHE);
+    m_extra_cache= FALSE;
+    m_extra_cache_size= 0;
+    m_extra_prepare_for_update= FALSE;
+    m_extra_cache_part_id= NO_CURRENT_PART_ID;
+    DBUG_RETURN(ret);
+  }
   case HA_EXTRA_WRITE_CACHE:
   {
     m_extra_cache= FALSE;
     m_extra_cache_size= 0;
+    m_extra_prepare_for_update= FALSE;
+    m_extra_cache_part_id= NO_CURRENT_PART_ID;
     DBUG_RETURN(loop_extra(operation));
   }
   case HA_EXTRA_IGNORE_NO_KEY:
@@ -5863,6 +5887,7 @@ int ha_partition::extra_opt(enum ha_extr
 void ha_partition::prepare_extra_cache(uint cachesize)
 {
   DBUG_ENTER("ha_partition::prepare_extra_cache()");
+  DBUG_PRINT("info", ("cachesize %u", cachesize));
 
   m_extra_cache= TRUE;
   m_extra_cache_size= cachesize;
@@ -5921,16 +5946,18 @@ int ha_partition::loop_extra(enum ha_ext
 {
   int result= 0, tmp;
   handler **file;
+  bool is_select;
   DBUG_ENTER("ha_partition::loop_extra()");
   
-  /* 
-    TODO, 5.2: this is where you could possibly add optimisations to add the bitmap
-    _if_ a SELECT.
-  */
+  is_select= (thd_sql_command(ha_thd()) == SQLCOM_SELECT);
   for (file= m_file; *file; file++)
   {
-    if ((tmp= (*file)->extra(operation)))
-      result= tmp;
+    if (!is_select ||
+        bitmap_is_set(&(m_part_info->used_partitions), file - m_file))
+    {
+      if ((tmp= (*file)->extra(operation)))
+        result= tmp;
+    }
   }
   DBUG_RETURN(result);
 }
@@ -5951,14 +5978,22 @@ void ha_partition::late_extra_cache(uint
 {
   handler *file;
   DBUG_ENTER("ha_partition::late_extra_cache");
+  DBUG_PRINT("info", ("extra_cache %u partid %u size %u", m_extra_cache,
+                      partition_id, m_extra_cache_size));
 
-  if (!m_extra_cache)
+  if (!m_extra_cache && !m_extra_prepare_for_update)
     DBUG_VOID_RETURN;
   file= m_file[partition_id];
   if (m_extra_cache_size == 0)
     (void) file->extra(HA_EXTRA_CACHE);
   else
     (void) file->extra_opt(HA_EXTRA_CACHE, m_extra_cache_size);
+  if (m_extra_prepare_for_update)
+  {
+    DBUG_ASSERT(m_extra_cache);
+    (void) file->extra(HA_EXTRA_PREPARE_FOR_UPDATE);
+  }
+  m_extra_cache_part_id= partition_id;
   DBUG_VOID_RETURN;
 }
 
@@ -5979,10 +6014,12 @@ void ha_partition::late_extra_no_cache(u
   handler *file;
   DBUG_ENTER("ha_partition::late_extra_no_cache");
 
-  if (!m_extra_cache)
+  if (!m_extra_cache && !m_extra_prepare_for_update)
     DBUG_VOID_RETURN;
   file= m_file[partition_id];
   (void) file->extra(HA_EXTRA_NO_CACHE);
+  DBUG_ASSERT(partition_id == m_extra_cache_part_id);
+  m_extra_cache_part_id= NO_CURRENT_PART_ID;
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/ha_partition.h'
--- a/sql/ha_partition.h	2010-07-23 20:59:42 +0000
+++ b/sql/ha_partition.h	2010-09-27 05:55:33 +0000
@@ -137,6 +137,10 @@ private:
   */
   bool m_extra_cache;
   uint m_extra_cache_size;
+  /* The same goes for HA_EXTRA_PREPARE_FOR_UPDATE */
+  bool m_extra_prepare_for_update;
+  /* Which partition has active cache */
+  uint m_extra_cache_part_id;
 
   void init_handler_variables();
   /*

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-08-30 08:38:30 +0000
+++ b/sql/log.cc	2010-09-27 05:55:33 +0000
@@ -1998,10 +1998,32 @@ extern "C" my_bool reopen_fstreams(const
                                    FILE *outstream, FILE *errstream)
 {
   int handle_fd;
-  int stream_fd;
+  int err_fd, out_fd;
   HANDLE osfh;
 
-  DBUG_ASSERT(filename && (outstream || errstream));
+  DBUG_ASSERT(filename && errstream);
+
+  // Services don't have stdout/stderr on Windows, so _fileno returns -1.
+  err_fd= _fileno(errstream);
+  if (err_fd < 0)
+  {
+    if (!freopen(filename, "a+", errstream))
+      return TRUE;
+
+    setbuf(errstream, NULL);
+    err_fd= _fileno(errstream);
+  }
+
+  if (outstream)
+  {
+    out_fd= _fileno(outstream);
+    if (out_fd < 0)
+    {
+      if (!freopen(filename, "a+", outstream))
+        return TRUE;
+      out_fd= _fileno(outstream);
+    }
+  }
 
   if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
                         FILE_SHARE_READ | FILE_SHARE_WRITE |
@@ -2017,24 +2039,16 @@ extern "C" my_bool reopen_fstreams(const
     return TRUE;
   }
 
-  if (outstream)
+  if (_dup2(handle_fd, err_fd) < 0)
   {
-    stream_fd= _fileno(outstream);
-    if (_dup2(handle_fd, stream_fd) < 0)
-    {
-      CloseHandle(osfh);
-      return TRUE;
-    }
+    CloseHandle(osfh);
+    return TRUE;
   }
 
-  if (errstream)
+  if (outstream && _dup2(handle_fd, out_fd) < 0)
   {
-    stream_fd= _fileno(errstream);
-    if (_dup2(handle_fd, stream_fd) < 0)
-    {
-      CloseHandle(osfh);
-      return TRUE;
-    }
+    CloseHandle(osfh);
+    return TRUE;
   }
 
   _close(handle_fd);

=== modified file 'sql/net_serv.cc'
--- a/sql/net_serv.cc	2010-08-05 13:10:22 +0000
+++ b/sql/net_serv.cc	2010-09-27 05:55:33 +0000
@@ -164,7 +164,17 @@ my_bool net_realloc(NET *net, size_t len
   DBUG_ENTER("net_realloc");
   DBUG_PRINT("enter",("length: %lu", (ulong) length));
 
-  if (length >= net->max_packet_size)
+  /*
+    When compression is off, net->where_b is always 0.
+    With compression turned on, net->where_b may indicate
+    that we still have a piece of the previous logical
+    packet in the buffer, unprocessed. Take it into account
+    when checking that max_allowed_packet is not exceeded.
+    This ensures that the client treats max_allowed_packet
+    limit identically, regardless of compression being on
+    or off.
+  */
+  if (length >= (net->max_packet_size + net->where_b))
   {
     DBUG_PRINT("error", ("Packet too large. Max size: %lu",
                          net->max_packet_size));

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-08-26 14:29:22 +0000
+++ b/sql/opt_range.cc	2010-09-27 05:55:33 +0000
@@ -8550,9 +8550,14 @@ int QUICK_RANGE_SELECT::reset()
   in_range= FALSE;
   cur_range= (QUICK_RANGE**) ranges.buffer;
 
-  if (file->inited == handler::NONE && (error= file->ha_index_init(index,1)))
-    DBUG_RETURN(error);
- 
+  if (file->inited == handler::NONE)
+  {
+    if (in_ror_merged_scan)
+      head->column_bitmaps_set_no_signal(&column_bitmap, &column_bitmap);
+    if ((error= file->ha_index_init(index,1)))
+        DBUG_RETURN(error);
+  }
+
   /* Do not allocate the buffers twice. */
   if (multi_range_length)
   {

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2010-07-26 09:01:42 +0000
+++ b/sql/sql_cache.cc	2010-09-27 05:55:33 +0000
@@ -1346,6 +1346,57 @@ end:
 }
 
 
+#ifndef EMBEDDED_LIBRARY
+/**
+  Send a single memory block from the query cache.
+
+  Respects the client/server protocol limits for the
+  size of the network packet, and splits a large block
+  in pieces to ensure that individual piece doesn't exceed
+  the maximal allowed size of the network packet (16M).
+
+  @param[in] net NET handler
+  @param[in] packet packet to send
+  @param[in] len packet length
+
+  @return Operation status
+    @retval FALSE On success
+    @retval TRUE On error
+*/
+static bool
+send_data_in_chunks(NET *net, const uchar *packet, ulong len)
+{
+  /*
+    On the client we may require more memory than max_allowed_packet
+    to keep, both, the truncated last logical packet, and the
+    compressed next packet.  This never (or in practice never)
+    happens without compression, since without compression it's very
+    unlikely that a) a truncated logical packet would remain on the
+    client when it's time to read the next packet b) a subsequent
+    logical packet that is being read would be so large that
+    size-of-new-packet + size-of-old-packet-tail >
+    max_allowed_packet.  To remedy this issue, we send data in 1MB
+    sized packets, that's below the current client default of 16MB
+    for max_allowed_packet, but large enough to ensure there is no
+    unnecessary overhead from too many syscalls per result set.
+  */
+  static const ulong MAX_CHUNK_LENGTH= 1024*1024;
+
+  while (len > MAX_CHUNK_LENGTH)
+  {
+    if (net_real_write(net, packet, MAX_CHUNK_LENGTH))
+      return TRUE;
+    packet+= MAX_CHUNK_LENGTH;
+    len-= MAX_CHUNK_LENGTH;
+  }
+  if (len && net_real_write(net, packet, len))
+    return TRUE;
+
+  return FALSE;
+}
+#endif
+
+
 /*
   Check if the query is in the cache. If it was cached, send it
   to the user.
@@ -1655,11 +1706,11 @@ def_week_frmt: %lu, in_trans: %d, autoco
                                    ALIGN_SIZE(sizeof(Query_cache_result)))));
     
     Query_cache_result *result = result_block->result();
-    if (net_real_write(&thd->net, result->data(),
-		       result_block->used -
-		       result_block->headers_len() -
-		       ALIGN_SIZE(sizeof(Query_cache_result))))
-      break;					// Client aborted
+    if (send_data_in_chunks(&thd->net, result->data(),
+                            result_block->used -
+                            result_block->headers_len() -
+                            ALIGN_SIZE(sizeof(Query_cache_result))))
+      break;                                    // Client aborted
     result_block = result_block->next;
     thd->net.pkt_nr= query->last_pkt_nr; // Keep packet number updated
   } while (result_block != first_result_block);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-09-10 08:06:58 +0000
+++ b/sql/sql_select.cc	2010-09-27 05:55:33 +0000
@@ -1512,6 +1512,15 @@ JOIN::optimize()
     if (order)
     {
       /*
+        Do we need a temporary table due to the ORDER BY not being equal to
+        the GROUP BY? The call to test_if_skip_sort_order above tests for the
+        GROUP BY clause only and hence is not valid in this case. So the
+        estimated number of rows to be read from the first table is not valid.
+        We clear it here so that it doesn't show up in EXPLAIN.
+       */
+      if (need_tmp && (select_options & SELECT_DESCRIBE) != 0)
+        join_tab[const_tables].limit= 0;
+      /*
         Force using of tmp table if sorting by a SP or UDF function due to
         their expensive and probably non-deterministic nature.
       */
@@ -16642,7 +16651,15 @@ static void select_describe(JOIN *join, 
         if (tab->select && tab->select->quick)
           examined_rows= tab->select->quick->records;
         else if (tab->type == JT_NEXT || tab->type == JT_ALL)
-          examined_rows= tab->limit ? tab->limit : tab->table->file->records();
+        {
+          if (tab->limit)
+            examined_rows= tab->limit;
+          else
+          {
+            tab->table->file->info(HA_STATUS_VARIABLE);
+            examined_rows= tab->table->file->stats.records;
+          }
+        }
         else
           examined_rows=(ha_rows)join->best_positions[i].records_read; 
  

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-08-30 08:38:30 +0000
+++ b/sql/sql_table.cc	2010-09-27 05:55:33 +0000
@@ -3712,6 +3712,7 @@ mysql_prepare_create_table(THD *thd, HA_
       key_part_info->length=(uint16) length;
       /* Use packed keys for long strings on the first column */
       if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) &&
+          !((create_info->table_options & HA_OPTION_NO_PACK_KEYS)) &&
 	  (length >= KEY_DEFAULT_PACK_LENGTH &&
 	   (sql_field->sql_type == MYSQL_TYPE_STRING ||
 	    sql_field->sql_type == MYSQL_TYPE_VARCHAR ||


Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100927055533-9yprk8kkxzdfswsd.bundle
Thread
bzr commit into mysql-trunk-merge branch (kostja:3197)Konstantin Osipov27 Sep