List:Commits« Previous MessageNext Message »
From:Georgi Kodinov Date:May 9 2012 4:58pm
Subject:bzr push into mysql-trunk branch (Georgi.Kodinov:3809)
View as plain text  
 3809 Georgi Kodinov	2012-05-09 [merge]
      merge

    modified:
      mysql-test/t/ds_mrr-big.test
=== added file 'BUILD/SETUP.sh'
--- a/BUILD/SETUP.sh	1970-01-01 00:00:00 +0000
+++ b/BUILD/SETUP.sh	2012-05-09 16:47:39 +0000
@@ -0,0 +1,258 @@
+#!/bin/sh
+
+# Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+# MA 02111-1307, USA
+
+########################################################################
+
+get_key_value()
+{
+  echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
+}
+
+usage()
+{
+cat <<EOF 
+Usage: $0 [-h|-n] [configure-options]
+  -h, --help              Show this help message.
+  -n, --just-print        Don't actually run any commands; just print them.
+  -c, --just-configure    Stop after running configure.
+  --with-debug=full       Build with full debug(no optimizations, keep call stack).
+  --warning-mode=[old|pedantic|maintainer]
+                          Influences the debug flags. Old is default.
+  --prefix=path           Build with prefix 'path'.
+
+Note: this script is intended for internal use by MySQL developers.
+EOF
+}
+
+parse_options()
+{
+  while test $# -gt 0
+  do
+    case "$1" in
+    --prefix=*)
+      prefix=`get_key_value "$1"`;;
+    --with-debug=full)
+      full_debug="=full";;
+    --warning-mode=*)
+      warning_mode=`get_key_value "$1"`;;
+    -c | --just-configure)
+      just_configure=1;;
+    -n | --just-print | --print)
+      just_print=1;;
+    -h | --help)
+      usage
+      exit 0;;
+    *)
+      echo "Unknown option '$1'"
+      exit 1;;
+    esac
+    shift
+  done
+}
+
+########################################################################
+
+if test ! -f sql/mysqld.cc
+then
+  echo "You must run this script from the MySQL top-level directory"
+  exit 1
+fi
+
+prefix="/usr/local/mysql"
+just_print=
+just_configure=
+warning_mode=
+maintainer_mode=
+full_debug=
+
+parse_options "$@"
+
+if test -n "$MYSQL_BUILD_PREFIX"
+then
+  prefix="$MYSQL_BUILD_PREFIX"
+fi
+
+set -e
+
+#
+# Check for the CPU and set up CPU specific flags. We may reset them
+# later.
+# 
+path=`dirname $0`
+. "$path/check-cpu"
+
+export AM_MAKEFLAGS
+AM_MAKEFLAGS="-j 6"
+
+# SSL library to use.--with-ssl will select our bundled yaSSL
+# implementation of SSL. To use openSSl you will nee too point out
+# the location of openSSL headers and lbs on your system.
+# Ex --with-ssl=/usr
+SSL_LIBRARY=--with-ssl
+
+if [ "x$warning_mode" = "xpedantic" ]; then
+  warnings="-W -Wall -ansi -pedantic -Wno-long-long -Wno-unused -D_POSIX_SOURCE"
+  c_warnings="$warnings"
+  cxx_warnings="$warnings -std=c++98"
+# NOTE: warning mode should not influence optimize/debug mode.
+# Please feel free to add a separate option if you don't feel it's an overkill.
+  debug_extra_cflags="-O0"
+# Reset CPU flags (-mtune), they don't work in -pedantic mode
+  check_cpu_cflags=""
+elif [ "x$warning_mode" = "xmaintainer" ]; then
+  c_warnings="-Wall -Wextra"
+  cxx_warnings="$c_warnings -Wno-unused-parameter"
+  maintainer_mode="--enable-mysql-maintainer-mode"
+  debug_extra_cflags="-g3"
+else
+# Both C and C++ warnings
+  warnings="-Wall -Wextra -Wunused -Wwrite-strings"
+
+# For more warnings, uncomment the following line
+# warnings="$warnings -Wshadow"
+
+# C warnings
+  c_warnings="$warnings"
+# C++ warnings
+  cxx_warnings="$warnings -Wno-unused-parameter"
+# cxx_warnings="$cxx_warnings -Woverloaded-virtual -Wsign-promo"
+  cxx_warnings="$cxx_warnings -Wnon-virtual-dtor"
+  debug_extra_cflags="-O0 -g3 -gdwarf-2"
+fi
+
+# Set flags for various build configurations.
+# Used in -valgrind builds
+# Override -DFORCE_INIT_OF_VARS from debug_cflags. It enables the macro
+# LINT_INIT(), which is only useful for silencing spurious warnings
+# of static analysis tools. We want LINT_INIT() to be a no-op in Valgrind.
+valgrind_flags="-UFORCE_INIT_OF_VARS -DHAVE_purify "
+valgrind_flags="$valgrind_flags -DMYSQL_SERVER_SUFFIX=-valgrind-max"
+valgrind_configs="--with-valgrind"
+#
+# Used in -debug builds
+debug_cflags="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS "
+debug_cflags="$debug_cflags -DSAFE_MUTEX"
+error_inject="--with-error-inject "
+#
+# Base C++ flags for all builds
+base_cxxflags="-felide-constructors"
+#
+# Flags for optimizing builds.
+# Be as fast as we can be without losing our ability to backtrace.
+fast_cflags="-O3 -fno-omit-frame-pointer"
+
+debug_configs="--with-debug"
+if [ -z "$full_debug" ]
+then
+  debug_cflags="$debug_cflags $debug_extra_cflags"
+fi
+
+
+#
+# Configuration options.
+#
+base_configs="--prefix=$prefix --enable-assembler "
+base_configs="$base_configs --with-extra-charsets=complex "
+base_configs="$base_configs --enable-thread-safe-client "
+base_configs="$base_configs --with-big-tables $maintainer_mode"
+
+
+if test -d "$path/../cmd-line-utils/libedit"
+then
+    base_configs="$base_configs --with-libedit"
+fi
+
+static_link="--with-mysqld-ldflags=-all-static "
+static_link="$static_link --with-client-ldflags=-all-static"
+# we need local-infile in all binaries for rpl000001
+# if you need to disable local-infile in the client, write a build script
+# and unset local_infile_configs
+local_infile_configs="--enable-local-infile"
+
+
+max_no_embedded_configs="$SSL_LIBRARY --with-plugins=max"
+max_no_ndb_configs="$SSL_LIBRARY --with-plugins=max-no-ndb --with-embedded-server"
+max_configs="$SSL_LIBRARY --with-plugins=max --with-embedded-server"
+
+#
+# CPU and platform specific compilation flags.
+#
+alpha_cflags="$check_cpu_cflags -Wa,-m$cpu_flag"
+amd64_cflags="$check_cpu_cflags"
+amd64_cxxflags=""  # If dropping '--with-big-tables', add here  "-DBIG_TABLES"
+pentium_cflags="$check_cpu_cflags"
+pentium64_cflags="$check_cpu_cflags -m64"
+ppc_cflags="$check_cpu_cflags"
+sparc_cflags=""
+
+if gmake --version > /dev/null 2>&1
+then
+  make=gmake
+else
+  make=make
+fi
+
+if test -z "$CC" ; then
+  CC=gcc
+fi
+
+if test -z "$CXX" ; then
+  CXX=g++
+fi
+
+# If ccache (a compiler cache which reduces build time)
+# (http://samba.org/ccache) is installed, use it.
+# We use 'grep' and hope 'grep' will work as expected
+# (returns 0 if finds lines)
+if test "$USING_GCOV" != "1"
+then
+  # Not using gcov; Safe to use ccache
+  CCACHE_GCOV_VERSION_ENABLED=1
+fi
+
+if ccache -V > /dev/null 2>&1 && test "$CCACHE_GCOV_VERSION_ENABLED" = "1"
+then
+  echo "$CC" | grep "ccache" > /dev/null || CC="ccache $CC"
+  echo "$CXX" | grep "ccache" > /dev/null || CXX="ccache $CXX"
+fi
+
+# gcov
+
+# The  -fprofile-arcs and -ftest-coverage options cause GCC to instrument the
+# code with profiling information used by gcov.
+# The -DDISABLE_TAO_ASM is needed to avoid build failures in Yassl.
+# The -DHAVE_gcov enables code to write out coverage info even when crashing.
+
+gcov_compile_flags="-fprofile-arcs -ftest-coverage"
+gcov_compile_flags="$gcov_compile_flags -DDISABLE_TAO_ASM"
+gcov_compile_flags="$gcov_compile_flags -DMYSQL_SERVER_SUFFIX=-gcov -DHAVE_gcov"
+
+# GCC4 needs -fprofile-arcs -ftest-coverage on the linker command line (as well
+# as on the compiler command line), and this requires setting LDFLAGS for BDB.
+
+gcov_link_flags="-fprofile-arcs -ftest-coverage"
+
+gcov_configs="--with-gcov"
+
+# gprof
+
+gprof_compile_flags="-O2 -pg -g"
+
+gprof_link_flags="--disable-shared $static_link"
+

=== added file 'BUILD/build_mccge.sh'
--- a/BUILD/build_mccge.sh	1970-01-01 00:00:00 +0000
+++ b/BUILD/build_mccge.sh	2012-05-09 16:47:39 +0000
@@ -0,0 +1,1980 @@
+#!/bin/sh
+
+# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA
+
+die()
+{
+  echo "ERROR: $@"; exit 1;
+}
+
+get_key_value()
+{
+  echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
+}
+
+developer_usage()
+{
+cat <<EOF
+
+  This script can be used by developers of MySQL, early adopters wanting 
+  to try out early versions of MySQL before binary versions are 
+  available, anyone needing a version with a special patch included that 
+  needs to be built from source code, or anyone else wanting to exercise 
+  full control over the MySQL build process.
+
+  This help text is targeted towards those that want to debug and test 
+  MySQL using source code releases. If you have downloaded a source code 
+  release and simply want to build a usable binary, you should read the 
+  --sysadmin-help instead.
+
+  The script is also designed to be used by anyone receiving a source 
+  code release of MySQL Cluster Carrier Grade Edition. The default
+  behaviour is to build the standard MySQL Cluster Carrier Grade Edition
+  package. Three environment variables can be used to change the 
+  default behaviour:
+
+  MYSQL_DEVELOPER
+    Defining this variable is similar to setting the --developer flag
+  MYSQL_DEVELOPER_PACKAGE=package
+    Defining this variable is similar to setting the --package=* 
+    variable
+  MYSQL_DEVELOPER_DEBUG
+    Defining this variable sets the --with-debug flag
+
+  Options used with this script always override any default behaviour. 
+  The default package is MySQL Cluster Carrier Grade (standard) Edition. 
+  For developers, the default package is MySQL Cluster Carrier Grade 
+  Extended Edition.
+
+  More information for developers can be found in --help, 
+  --sysadmin-help, and --extended-help.
+
+  The most common usage for developers is to set the three variables 
+  mentioned previously and then simply to run the script without any 
+  additional parameters, using them only when needing to change some 
+  things like not requiring debug build. If some of these environment 
+  variables have already been set, you can use the corresponding options 
+  to unset them and reverse their effects.
+EOF
+}
+
+sysadmin_usage()
+{
+cat <<EOF
+
+  This script can be used to build MySQL Cluster Carrier Grade Edition
+  based on a source code release you received from MySQL. It can also
+  be used to build many variants other variants of MySQL, in particular
+  various performance-optimised versions of MySQL.
+
+  It is assumed that you are building on a computer which is of the 
+  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 (from top-level
+  MySQL directory):
+
+  shell> BUILD/build_mccge.sh
+
+  This performs the following operations:
+    1) Detects the operating system. Currently, Linux, FreeBSD, Solaris 
+      8/9/10/11, and Mac OS X are supported by this script.
+    2) Detect the type of CPU being used. Currently supported processors 
+      are: x86 for all supported operating systems, Itanium for Linux 
+      with GCC, and x86 + SPARC for Solaris using the Forte compiler and
+      finally x86 on Linux using the Intel compiler.
+    3) Invokes the GCC compiler.
+    4) Builds a set of MySQL/MySQL Cluster binaries; for
+      more information about these, see --extended-help.
+    5) Default compiler is always gcc.
+  
+  The default version assumes that you have a source code tarball from 
+  which you are building, and thus autoconf and automake do not need to 
+  be run. If you have downloaded a BitKeeper tree then you should read 
+  --developer-help.
+
+  If you are building MySQL/MySQL Cluster for commercial 
+  use then you need to set the --commercial flag to ensure that the 
+  commercial libraries are compiled in, rather than the GPL-only 
+  libraries. The default is to build a GPL version of MySQL Cluster 
+  Carrier Grade Edition.
+
+  If your building on a Solaris SPARC machine and you want to compile
+  using SunStudio you must set 
+  --compiler=forte; if you want to build using the Intel compiler on 
+  Linux, you need to set --compiler=icc. If you want to use the AMD
+  compiler Open64 set --compiler=open64.
+
+  A synonym for forte is SunStudio, so one can also use
+  --compiler=SunStudio.
+
+  If you want to make sure that a 64-bit version is built then you 
+  should add the flag --64. This is always set on Solaris machines and 
+  when check-cpu is able to discover that a 64-bit CPU is being used. If 
+  you want to ensure that a 32-bit binary is produced, use --32 instead.
+
+  If you need the binaries to be installed in a different location from 
+  /usr/local/mysql, then you should set --prefix to point to where you
+  want the binaries installed.
+
+  Using a data directory other than the default (PREFIX/data) can be 
+  done when starting the MySQL Server, or by invoking this script with 
+  the --datadir option.
+
+  If you want your binaries stripped of surplus debug or other 
+  information, use the --strip option.
+
+  If you want debug information in the binary (for example, to be
+  able to send gdb core dumps to MySQL Support), then you should add the 
+  flag --with-debug; if you want a production build with only debugging 
+  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 Enterprise Pro 
+  versions; see the --extended-help for descriptions of these packages.
+EOF
+}
+
+usage()
+{
+cat <<EOF
+
+Usage: $0 [options]
+  --help                  Show this help message.
+  --sysadmin-help         Show help for system administrators wishing 
+                          to build MySQL Cluster Carrier Grade Edition
+                          or other MySQL versions.
+  --developer-help        Show help for developers trying to build MySQL
+  --with-help             Show extended help on --with-xxx options to 
+                          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
+  --without-fast-mutexes  Don't use try/retry method of acquiring mutex
+  --without-perfschema    Don't build with performance schema
+  --generate-feedback path Compile with feedback using the specified directory
+                          to store the feedback files
+  --use-feedback path     Compile using feedback information from the specified
+                          directory
+  --with-debug            Build debug version
+  --extra-debug-flag flag Add -Dflag to compiler flags
+                          InnoDB supports the following debug flags,
+                          UNIV_DEBUG, UNIV_SYNC_DEBUG, UNIV_MEM_DEBUG,
+                          UNIV_DEBUG_THREAD_CREATION, UNIV_DEBUG_LOCK_VALIDATE,
+                          UNIV_DEBUG_PRINT, UNIV_DEBUG_FILE_ACCESS,
+                          UNIV_LIGHT_MEM_DEBUG, UNIV_LOG_DEBUG,
+                          UNIV_IBUF_COUNT_DEBUG, UNIV_SEARCH_DEBUG,
+                          UNIV_LOG_LSN_DEBUG, UNIV_ZIP_DEBUG, UNIV_AHI_DEBUG,
+                          UNIV_DEBUG_VALGRIND, UNIV_SQL_DEBUG, UNIV_AIO_DEBUG,
+                          UNIV_BTR_DEBUG, UNIV_LRU_DEBUG, UNIV_BUF_DEBUG,
+                          UNIV_HASH_DEBUG, UNIV_LIST_DEBUG, UNIV_IBUF_DEBUG
+  --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.
+  --with-mso              Special flag used by Open64 compiler (requres at
+                          least version 4.2.3) that enables optimisations
+                          for multi-core scalability.
+  --configure-only        Stop after running configure.
+  --print-only            Print commands that the script will execute, 
+                          but do not actually execute
+  --prefix=path           Build with prefix 'path'
+  --datadir=path          Build with data directory set to non-standard 
+                          'path'
+  --debug                 Build normal version, but add debug 
+                          information to binary
+  --developer             Use extensions that most MySQL developers use
+  --no-developer          Do not use extensions that most developers of 
+                          MySQL use
+  --commercial            Use commercial libraries
+  --gpl                   Use gpl libraries
+  --compiler=[gcc|icc|forte|SunStudio|open64] Select compiler
+  --cpu=[x86|x86_64|sparc|itanium]            Select CPU type
+                          x86 => x86 and 32-bit binary
+                          x86_64 => x86 and 64 bit binary
+  --warning-mode=[extra|pedantic|normal|no]   Set warning mode level
+  --warnings              Set warning mode to normal
+  --32                    Build a 32-bit binary even if CPU is 64-bit
+  --64                    Build a 64-bit binary even if not sure a
+                          64-bit CPU is being used
+  --package=[cge|extended|pro|classic]        Select package to build
+  --parallelism=number    Define parallelism in make
+  --strip                 Strip binaries
+  --error-inject          Enable error injection into MySQL Server and 
+                          data nodes
+  --valgrind              Build with valgrind
+  --fast                  Optimise for CPU architecture built on
+  --static-linking        Statically link system libraries into binaries
+  --use-tcmalloc          Link with tcmalloc instead of standard malloc (Linux only)
+  --with-flags *          Pass extra --with-xxx options to configure
+EOF
+  if test "x$1" != "x" ; then
+    echo "Failure Message: $1"
+  fi
+}
+
+extended_usage()
+{
+  cat <<EOF
+
+  Extended help text for this script:
+  -----------------------------------
+  This script is intended to make it easier for customers using MySQL
+  Cluster Carrier Grade Edition, customers using performance-optimised
+  MySQL versions and developers to build the product from source on 
+  these platforms/compilers: Linux/x86 (32-bit and 64-bit) (either using
+  gcc or icc), Linux Itanium, Solaris 8,9,10 and 11 x86 and SPARC using
+  gcc or SunStudio and MacOSX/x86/gcc.
+
+  The script automatically detects CPU type and operating system; The
+  default compiler is always gcc.
+
+  To build on other platforms you can use the --print-only option on a
+  supported platform and edit the output for a proper set of commands on
+  the specific platform you are using. MySQL also provides custom builds
+  for any type of platform that is officially supported for MySQL
+  Cluster. For a list of supported platforms, see
+  http://www.mysql.com/support/supportedplatforms/cluster.html.
+
+  Using the --package option, it is also possible to build a "classic"
+  version of MySQL having only the MyISAM storage engine, a "Pro"
+  package including all storage engines and other features except MySQL
+  Cluster, and an "extended" package including these features plus MySQL
+  Cluster (this is the default if the --developer option is used).
+
+  Different MySQL storage engines are included in the build, depending
+  on which --package option is used. The comment and version strong
+  suffix are also set according to the package selected.
+
+  --package=cge
+    storage engines:
+      ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, NDB
+      (All storage engines except InnoDB)
+    comment: MySQL Cluster Carrier Grade Edition GPL/Commercial version 
+             built from source
+    version string suffix: -cge
+
+  --package=extended
+    storage engines:
+      ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, INNODB, NDB
+      (All storage engines)
+    comment: MySQL Cluster Carrier Grade Extended Edition GPL/Commercial 
+             version built from source
+    version string suffix: -cge-extended
+
+  --package=pro
+    storage engines:
+      ARCHIVE, BLACKHOLE, CSV, FEDERATED, INNODB, MYISAM
+      (All storage engines except NDB)
+    comment: MySQL Pro GPL/Commercial version built from 
+             source
+    version string suffix: [none]
+
+  --package=classic
+    storage engines: CSV, MYISAM
+    comment: MySQL Classic GPL/Commercial version built 
+             from source
+    version string suffix: [none]
+
+  All packages except Classic include support for user-defined
+  partitioning. All packages include support for Performance
+  Schema.
+
+  If --with-debug is used, an additional "-debug" is appended to the
+  version string.
+
+  --commercial
+    This flag prevents the use of GPL libraries which cannot be used
+    under a commercial license, such as the readline library.
+
+  --developer
+    This option changes a number of things to make the version built
+    more appropriate to the debugging and testing needs of developers. 
+    It changes the default package to "extended". It also changes the 
+    default warning mode from "none" to "normal", which allows an 
+    extensive list of warnings to be generated.
+
+  --error-inject
+    This flag is used only when the --developer option is also used, and
+    enables error injection in both the MySQL Server and in MySQL
+    Cluster data nodes.
+
+  The following is a list of the default configure options used for all
+  packages:
+
+  --prefix: /usr/local/mysql (can be overridden)
+
+  --libexecdir: <prefix>/bin (can be overridden)
+
+  --localstatedir: <prefix>/data, unless --datadir is used, in which
+    case it defaults to <datadir>/data (can be overridden by setting
+    --localstatedir explicitly).
+
+  --enable-local-infile: Enable use of the LOAD DATA FROM  LOCAL INFILE
+    command (cannot be overridden).
+
+  --enable-thread-safe-client: Enable the multi-threaded mysql client
+    library (cannot be overridden).
+
+  --with-big-tables: Enable use of tables with more than 4G rows (cannot
+    be overridden).
+
+  --with-extra-charsets=all: Enable use of all character sets supported
+    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
+    to avoid problems with dynamic linkers (cannot be overridden).
+
+  --without-example-engine: Ensure that the example engine isn't built,
+    it cannot do any useful things, it's merely intended as documentation.
+    (cannot be overridden)
+
+  --with-csv-storage-engine: Ensure that the CSV storage engine is
+    included in all builds. Since CSV is required for log tables in
+    MySQL 5.1, this option cannot be overridden.
+
+    (Note that MyISAM support is always built into the MySQL Server; the
+    server *cannot* be built without MyISAM.)
+
+  --with-mysqld-ldflags=-static
+  --with-client-ldflags=-static
+    Ensures that binaries for, respectively, the MySQL server and client
+    are built with static libraries except for the system libraries,
+    which use dynamically loaded libraries provided by the operating
+    system. Building with --developer sets these to all-static instead, 
+    to build everything statically.
+
+  In addition there are some configure options that are specific to
+  Linux operating systems:
+
+  --enable-assembler
+    Include assembler code optimisations for a number of mostly string
+    methods. Used for x86 processors only.
+
+  Neither of the preceding options can be disabled.
+
+  MySQL Cluster Carrier Grade edition also adds the following options
+  (also used by the extended package):
+
+  --with-ndbcluster
+    Include the NDB Cluster storage engine, its kernel, management
+    server, and client, as well as support for the NDB and MGM APIs.
+
+  --without-ndb-debug
+    Do not include specific NDB debug code, not even in debug versions
+    (cannot be overridden).
+
+  Package-specific options:
+  -------------------------
+  --with-innodb
+    Specifically included in the "pro" and "extended" packages, and not 
+    in any of the others.
+
+  --with-comment
+    Sets the comment for the MySQL version, by package, as described
+    above.
+
+  --with-server-suffix
+    Sets the server suffix on the MySQL version, by package, as
+    described above.
+
+  Other options used:
+  -------------------
+  --with-readline
+    Use the GPL readline library for command editing functions; not
+    available with commercial packages.
+
+  --with-libedit
+    Use the BSD licensed library for command editing functions; used for
+    commercial packages.
+
+  --with-zlib-dir=bundled
+    Use the zlib package bundled with MySQL.
+
+  --with-mysqld-libs=-lmtmalloc
+    Used on Solaris to ensure that the proper malloc library is used.
+    Investigations have shown mtmalloc to be the best choice on Solaris,
+    also umem has good performance on Solaris but better debugging
+    capabilities.
+
+  Compiler options:
+  -----------------
+
+    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), this option is valid
+    when gcc is the compiler.
+
+    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/g++" BUILD/build_mccge.sh
+
+  Feedback profiler on gcc
+  ------------------------
+  Using gcc --generate-feedback=path causes the following flags to be added
+  to the compiler flags.
+
+  --fprofile-generate
+  --fprofile-dir=path
+
+  Using gcc with --use-feedback=path causes the following flags to be added
+  to the compiler flags. --fprofile-correction indicates MySQL is a multi-
+  threaded application and thus counters can be inconsistent with each other
+  and the compiler should take this into account.
+
+  --fprofile-use
+  --fprofile-dir=path
+  --fprofile-correction
+
+  Feedback compilation using Open64
+  ---------------------------------
+
+  Using Open64 with --generate-feedback=path causes the following flags to
+  be added to the compiler flags.
+
+  -fb-create path/feedback
+
+  Using Open64 with --use-feedback=path causes the following flags to be
+  added to the compiler flags.
+
+  --fb-opt path/feedback
+
+  Linux/x86+Itanium/gcc
+  -------------
+    For debug builds -O is used and otherwise -O3 is used.Discovery of a
+    Nocona or Core 2 Duo CPU causes a 64-bit binary to be built;
+    otherwise, the binary is 32-bit. To build a 64-bit binary, -m64 is
+    added to the C/C++ flags. (To build a 32-bit binary on a 64-bit CPU,
+    use the --32 option as described previously.)
+
+    When gcc 4.5 is used and the user set --with-link-time-optimizer then
+    also --flto is added to compiler flags and linker flags.
+
+  Linux/x86+Itanium/icc
+  -------------
+    Flags used:
+    CC  = icc -static-libgcc -static-intel
+    C++ = icpc -static-libgcc -static-intel
+    C/C++ flags = -mp -restrict
+
+    On Itanium we also add -no-ftz and to CC and C++ flags.
+
+    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.
+
+  Linux/x86/Open64
+  ----------------
+    For normal builds use -O3, when fast flag is set one also adds
+    --march=auto to generate optimized builds for the CPU used. If
+    --with-link-time-optimizer is set also -ipa is set. There is also
+    a special flag --with-mso which can be set to get --mso set which
+    activates optimisation for multi-core scalability.
+
+  FreeBSD/x86/gcc
+  ---------------
+    No flags are used. Instead, configure determines the proper flags to 
+    use.
+
+  Solaris/x86/gcc
+  ---------------
+    All builds on Solaris are by default 64-bit, so -m64 is always used in
+    the C/C++ flags. LDFLAGS is set to -m64 -O/-O2/-O3. If for
+    some reason a 32-bit Solaris is used it is necessary to add the flag
+    --32 to the script invocation. Due to bugs in compiling with -O3 on
+    Solaris only -O2 is used by default, when --fast flag is used -O3 will
+    be used instead.
+
+    Sets -m64 (default) or -m32 (if specifically set) in LDFLAGS and
+    C/C++ flags.
+
+  Solaris/Sparc/Forte
+  -------------------
+    Uses cc as CC and CC as CXX
+    Note that SunStudio uses different binaries for C and C++ compilers.
+
+    Set -m64 (default) or -m32 (if specifically set) in ASFLAGS,
+    LDFLAGS and C/C++ flags.
+
+    Sets ASFLAGS=LDFLAGS=compiler flags=xarch=sparc, so that we compile
+    Sparc v9 binaries, also -mt is set in all those since we're always
+    building a multithreaded program.
+
+    C flags   = -xstrconst    This flag is set only on SPARC
+    C++ flags = -noex
+
+    Set the following C/C++ flags:
+    -fsimple=1
+    -ftrap=%none
+    -nofstore          This flag is set only on x86
+    -xbuiltin=%all
+    -xlibmil
+    -xlibmopt
+
+    Set the C++ flag:
+    -noex
+    -features=no%except    This flag is set only on x86
+
+    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
+
+    When not compiling with fast we always set -xtarget=generic
+
+    When compiling with fast on SPARC we also set:
+    C/C++ flags: -xbinopt=prepare
+    LDFLAGS: -xbinopt=prepare
+
+    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
+    -xO2        Production build on SPARC
+    -xO3        Production build on x86
+    -xO4        Fast builds on SPARC/x86
+
+  MacOSX/x86/gcc
+  --------------
+    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.
+  
+    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
+
+  To obtain extended help on the --with-* options available, run this
+  script with --configure-only to create a configuration file. Then
+  issue the command ./configure --help to get an extensive list of
+  possible configure options.
+
+  The remainder of this text focuses on those options which are useful
+  in building binaries for MySQL Cluster Carrier Grade Edition.
+
+  --with-ndb-sci=/opt/DIS
+    Used to build a MySQL Cluster Carrier Grade Edition that can use the
+    SCI Transporter. The Dolphin SCI installation must be completed
+    first (see 
+    http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-interconnects.html
+    for more information).
+
+  --with-ndb-test
+    Compile the MySQL Cluster test programs.
+
+  --with-ndb-port=PORT
+    Change the default port for the MySQL Cluster management server.
+
+  --with-ndb-port-base=PORT
+    Change the default port base for MySQL Cluster data nodes.
+
+  --without-query-cache
+    Build the MySQL Server without the query cache, which is often not
+    of value in MySQL Cluster applications.
+
+  --with-atomic-ops=rwlocks|smp|up
+                          Implement atomic operations using pthread
+                          rwlocks or atomic CPU instructions for
+                          multi-processor (default) or single-processor
+                          configurations.
+
+  --without-geometry      Do not build geometry-related portions of the
+                          MySQL Server. Seldom used in MySQL Cluster
+                          applications.
+
+  --with-ndb-cc-flags=FLAGS
+    This option can be used to build MySQL Cluster with error injection
+    on the data nodes. It can be used to pass special options to
+    programs in the NDB kernel for special test builds.
+    The option for enabling data node error injection is -DERROR_INSERT.
+EOF
+}
+
+parse_package()
+{
+  case "$package" in
+    classic )
+      package="classic"
+      ;;
+    pro )
+      package="pro"
+      ;;
+    extended )
+      package="extended"
+      ;;
+    cge )
+      package="cge"
+      ;;
+    *)
+      echo "Unknown package '$package'"
+      exit 1
+      ;;
+  esac
+}
+
+parse_warning_mode()
+{
+  case "$warning_mode" in
+    pedantic )
+      warning_mode="pedantic"
+      ;;
+    extra_warnings | extra-warnings | extra )
+      warning_mode="extra"
+      ;;
+    no )
+      warning_mode=
+      ;;
+    normal )
+      warning_mode="normal"
+      ;;
+    *)
+      echo "Unknown warning mode '$warning_mode'"
+      exit 1
+      ;;
+  esac
+}
+
+#
+# We currently only support x86, Itanium and UltraSparc processors.
+#
+parse_cpu_type()
+{
+  case "$cpu_type" in
+    x86 )
+      cpu_type="x86"
+      if test "x$m64" = "x" ; then
+        m64="no"
+      fi
+      ;;
+    x86_64 )
+      cpu_type="x86"
+      if test "x$m64" = "x" ; then
+        m64="yes"
+      fi
+      ;;
+    itanium )
+      cpu_type="itanium"
+      ;;
+    sparc )
+      cpu_type="sparc"
+      ;;
+    * )
+      echo "Unknown CPU type $cpu_type"
+      exit 1
+      ;;
+  esac
+  return
+}
+
+#
+# We currently only support gcc, icc and Forte.
+#
+parse_compiler()
+{
+  case "$compiler" in
+    gcc )
+      compiler="gcc"
+      ;;
+    icc )
+      compiler="icc"
+      ;;
+    forte | SunStudio | sunstudio )
+      compiler="forte"
+      ;;
+    open64 | Open64 )
+      compiler="open64"
+      ;;
+    *)
+      echo "Unknown compiler '$compiler'"
+      exit 1
+      ;;
+  esac
+}
+
+parse_options()
+{
+  while test $# -gt 0
+  do
+    case "$1" in
+    --prefix=*)
+      prefix=`get_key_value "$1"`
+      ;;
+    --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"
+      ;;
+    --without-fast-mutexes)
+      with_fast_mutexes="no"
+      ;;
+    --without-perfschema)
+      with_perfschema="no"
+      ;;
+    --with-mso)
+      with_mso="yes"
+      ;;
+    --use-tcmalloc)
+      use_tcmalloc="yes"
+      ;;
+    --with-debug)
+      with_debug_flag="yes"
+      fast_flag="no"
+      ;;
+    --extra-debug-flag)
+      shift
+      extra_debug_flags="$extra_debug_flags -D$1"
+      ;;
+    --debug)
+      compile_debug_flag="yes"
+      ;;
+    --no-developer)
+      developer_flag="no"
+      ;;
+    --developer)
+      developer_flag="yes"
+      ;;
+    --commercial)
+      gpl="no"
+      ;;
+    --gpl)
+      gpl="yes"
+      ;;
+    --compiler=*)
+      compiler=`get_key_value "$1"`
+      parse_compiler
+      ;;
+    --generate-feedback)
+      shift
+      GENERATE_FEEDBACK_PATH="$1"
+      ;;
+    --use-feedback)
+      shift
+      USE_FEEDBACK_PATH="$1"
+      ;;
+    --cpu=*)
+      cpu_type=`get_key_value "$1"`
+      parse_cpu_type
+      ;;
+    --warning-mode=*)
+      warning_mode=`get_key_value "$1"`
+      parse_warning_mode
+      ;;
+    --warnings)
+      warning_mode="normal"
+      ;;
+    --32)
+      if test "x$explicit_size_set" != "x" ; then
+        echo "Cannot set both --32 and --64"
+        exit 1
+      fi
+      explicit_size_set="yes"
+      m64="no"
+      ;;
+    --64)
+      if test "x$explicit_size_set" != "x" ; then
+        echo "Cannot set both --32 and --64"
+        exit 1
+      fi
+      explicit_size_set="yes"
+      m64="yes"
+      ;;
+    --package=*)
+      package=`get_key_value "$1"`
+      parse_package
+      ;;
+    --parallelism=*)
+      parallelism=`get_key_value "$1"`
+      ;;
+    --configure-only)
+      just_configure="yes"
+      ;;
+    --print-only)
+      just_print="yes"
+      ;;
+    --static-linking)
+      static_linking_flag="yes"
+      ;;
+    --strip)
+      strip_flag="yes"
+      ;;
+    --error-inject)
+      error_inject_flag="yes"
+      ;;
+    --valgrind)
+      valgrind="yes"
+      ;;
+    --fast)
+      fast_flag="yes"
+      ;;
+    --with-flags)
+      shift
+      break
+      ;;
+    --with-help)
+      with_usage
+      exit 0
+      ;;
+    --sysadmin-help)
+      sysadmin_usage
+      exit 0
+      ;;
+    --developer-help)
+      developer_usage
+      exit 0
+      ;;
+    --extended-help)
+      extended_usage
+      exit 0
+      ;;
+    --help)
+      usage
+      exit 0
+      ;;
+    *)
+      echo "Unknown option '$1'"
+      exit 1
+      ;;
+    esac
+    shift
+  done
+  for flag in $@
+  do
+    with_flags="$with_flags $flag"
+  done
+}
+
+#
+# We currently only support Linux, FreeBSD/OpenBSD, Mac OS X and Solaris
+#
+check_os()
+{
+  case "`uname -s`" in
+    Linux)
+      os="linux"
+      ;;
+    FreeBSD|OpenBSD)
+      os="bsd"
+      ;;
+    Darwin)
+      os="MacOSX"
+      ;;
+    SunOS)
+      os="Solaris"
+      ;;
+    *)
+      os="Unknown"
+      ;;
+  esac
+
+}
+
+set_cpu_base()
+{
+  if test "x$cpu_type" = "x" ; then
+    if test "x$cpu_arg" = "x" ; then
+      usage "CPU type not discovered, cannot proceed"
+      exit 1
+    fi
+    case "$cpu_arg" in
+      core2 | nocona | prescott | pentium* | i*86 )
+        # Intel CPU
+        cpu_base_type="x86"
+        ;;
+      athlon* | opteron* | k6 | k8 )
+        # AMD CPU
+        cpu_base_type="x86"
+        ;;
+      sparc )
+        cpu_base_type="sparc"
+        ;;
+      itanium )
+        cpu_base_type="itanium"
+        ;;
+      * )
+        usage "CPU type $cpu_arg not handled by this script"
+        exit 1
+        ;;
+    esac
+  else
+    cpu_base_type="$cpu_type"
+    check_cpu_cflags=""
+  fi
+  if test "x$os" = "xMacOSX" ; then
+    if test "x$m64" = "x" ; then
+      m64="no"
+    fi
+  elif test "x$os" = "xSolaris" ; then
+    if test "x$m64" = "x" ; then
+      m64="yes"
+    fi
+  elif test "x$m64" = "x" ; then
+    if test "x$cpu_arg" = "xnocona" || test "x$cpu_arg" = "xcore2" || \
+       test "x$cpu_arg" = "xathlon64" || test "x$cpu_arg" = "xopteron" ; then
+      m64="yes"
+    else
+      m64="no"
+    fi
+  fi
+  echo "Discovered CPU of type $cpu_base_type ($cpu_arg) on $os"
+  if test "x$m64" = "xyes" ; then
+    echo "Will compile 64-bit binaries"
+  else
+    echo "Will compile 32-bit binaries"
+  fi
+  return 0
+}
+
+#
+# Add to the variable commands with the configure command
+# 
+init_configure_commands()
+{
+  path=`dirname $0`
+  cp $path/cmake_configure.sh $path/../configure
+  chmod +x $path/../configure
+  cflags="$c_warnings $base_cflags $compiler_flags"
+  cxxflags="$cxx_warnings $base_cxxflags $compiler_flags"
+  configure="./configure $base_configs $with_flags"
+
+  env_flags="CC=\"$CC\" CFLAGS=\"$cflags\" CXX=\"$CXX\" CXXFLAGS=\"$cxxflags\""
+  if test "x$LDFLAGS" != "x" ; then
+    env_flags="$env_flags LDFLAGS=\"$LDFLAGS\""
+  fi
+  if test "x$ASFLAGS" != "x" ; then
+    env_flags="$env_flags ASFLAGS=\"$ASFLAGS\""
+  fi
+  commands="$commands
+    $env_flags $configure"
+} 
+
+#
+# Initialise the variable commands with the commands needed to generate
+# the configure script.
+#
+init_auto_commands()
+{
+  set_libtoolize_version
+  commands="\
+  $make -k maintainer-clean || true
+  /bin/rm -rf */.deps/*.P configure config.cache
+  /bin/rm -rf  storage/*/configure storage/*/config.cache autom4te.cache
+  /bin/rm -rf storage/*/autom4te.cache;"
+#
+# --add-missing instructs automake to install missing auxiliary files
+# and --force to overwrite them if they already exist
+#
+  commands="$commands
+  aclocal || die \"Can't execute aclocal\"
+  autoheader || die \"Can't execute autoheader\"
+  $LIBTOOLIZE --automake --copy --force || die \"Can't execute libtoolize\"
+  automake --add-missing --copy --force || die \"Can't execute automake\"
+  autoconf || die \"Can't execute autoconf\""
+}
+
+#
+# Add to the variable commands the make command and possibly also
+# strip commands
+#
+add_make_commands()
+{
+  AM_MAKEFLAGS="-j $parallelism"
+  commands="$commands
+  $make $AM_MAKEFLAGS"
+
+  if test "x$strip_flag" = "xyes" ; then
+    commands="$commands
+    mkdir -p tmp
+    nm --numeric-sort sql/mysqld  > tmp/mysqld.sym
+    objdump -d sql/mysqld > tmp/mysqld.S
+    strip sql/mysqld
+    strip storage/ndb/src/kernel/ndbd
+    strip storage/ndb/src/mgmsrv/ndb_mgmd
+    strip storage/ndb/src/mgmclient/ndb_mgm"
+  fi
+}
+
+#
+# Set make version, but only gmake is supported :)
+#
+set_make_version()
+{
+  if gmake --version > /dev/null 2>&1
+  then
+    make=gmake
+  else
+    make=make
+  fi
+  if test "x`$make --version | grep GNU`" = "x" ; then
+    die "Only gmake is supported"
+  fi
+}
+
+#
+# Find a libtoolize binary, both libtoolize and glibtoolize are
+# ok, use first found.
+#
+set_libtoolize_version()
+{
+  LIBTOOLIZE=not_found
+  save_ifs="$IFS"; IFS=':'
+  for dir in $PATH
+  do
+    if test -x $dir/libtoolize
+    then
+      LIBTOOLIZE=libtoolize
+      echo "Found libtoolize in $dir"
+      break
+    fi
+    if test -x $dir/glibtoolize
+    then
+      LIBTOOLIZE=glibtoolize
+      echo "Found glibtoolize in $dir"
+      break
+    fi
+  done
+  IFS="$save_ifs"
+  if test "x$LIBTOOLIZE" = "xnot_found" ; then
+    die "Found no libtoolize version, quitting here"
+  fi
+  return
+}
+
+#
+# If ccache (a compiler cache which reduces build time)
+# (http://samba.org/ccache) is installed, use it.
+# We use 'grep' and hope that 'grep' works as expected
+# (returns 0 if finds lines)
+# We do not use ccache when gcov is used. Also only when
+# gcc is used.
+#
+set_ccache_usage()
+{
+  if test "x$compiler" = "xgcc" ; then
+    if ccache -V > /dev/null 2>&1 && test "$USING_GCOV" != "1"
+    then
+      echo "$CC" | grep "ccache" > /dev/null || CC="ccache $CC"
+      echo "$CXX" | grep "ccache" > /dev/null || CXX="ccache $CXX"
+    fi
+  fi
+}
+
+#
+# Set flags for various build configurations.
+# Used in -valgrind builds
+#
+set_valgrind_flags()
+{
+  if test "x$valgrind_flag" = "xyes" ; then
+    loc_valgrind_flags="-UFORCE_INIT_OF_VARS -DHAVE_purify "
+    loc_valgrind_flags="$loc_valgrind_flags -DMYSQL_SERVER_SUFFIX=-valgrind-max"
+    compiler_flags="$compiler_flags $loc_valgrind_flags"
+    with_flags="$with_flags --with-valgrind"
+  fi
+}
+
+#
+# Set up warnings; default is to use no warnings, but if warning_mode
+# is used a lot of warning flags are set up. These flags are valid only
+# for gcc, so for other compilers we ignore the warning_mode.
+#
+set_warning_flags()
+{
+  if test "x$developer_flag" = "xyes" && test "x$warning_mode" = "x" ; then
+    warning_mode="normal"
+  fi
+  if test "x$compiler" = "xgcc" ; then
+    if test "x$warning_mode" = "normal" || test "x$warning_mode" = "extra" ; then
+# Both C and C++ warnings
+      warnings="$warnings -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs"
+      warnings="$warnings -Wcomment -W"
+      warnings="$warnings -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare"
+      warnings="$warnings -Wwrite-strings -Wunused-function -Wunused-label"
+      warnings="$warnings -Wunused-value -Wunused-variable"
+
+      if test "x$warning_mode" = "extra" ; then
+        warnings="$warnings -Wshadow"
+      fi
+# C warnings
+      c_warnings="$warnings -Wunused-parameter"
+# C++ warnings
+      cxx_warnings="$warnings -Woverloaded-virtual -Wsign-promo -Wreorder"
+      cxx_warnings="$warnings -Wctor-dtor-privacy -Wnon-virtual-dtor"
+      compiler_flags="$compiler_flags -Wuninitialized"
+    elif test "x$warning_mode" = "xpedantic" ; then
+      warnings="-W -Wall -ansi -pedantic -Wno-long-long -D_POSIX_SOURCE"
+      c_warnings="$warnings"
+      cxx_warnings="$warnings -std=c++98"
+# Reset CPU flags (-mtune), they don't work in -pedantic mode
+     check_cpu_cflags=""
+    fi
+  fi
+}
+
+#
+# Used in -debug builds
+#
+set_with_debug_flags()
+{
+  if test "x$with_debug_flag" = "xyes" ; then
+    if test "x$developer_flag" = "xyes" ; then
+      loc_debug_flags="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS "
+      compiler_flags="$compiler_flags $loc_debug_flags"
+    fi
+    compiler_flags="$compiler_flags $extra_debug_flags"
+  fi
+}
+
+#
+# Flag for optimizing builds for developers.
+#
+set_no_omit_frame_pointer_for_developers()
+{
+  if test "x$fast_flag" != "xno" ; then
+    if test "x$developer_flag" = "xyes" && test "x$compiler" = "xgcc" ; then
+# Be as fast as we can be without losing our ability to backtrace.
+      compiler_flags="$compiler_flags -fno-omit-frame-pointer"
+    fi
+  fi
+}
+
+#
+# Add -g to all builds that requested debug information in build
+#
+set_debug_flag()
+{
+  if test "x$compile_debug_flag" = "xyes" ; then
+    compiler_flags="$compiler_flags -g"
+  fi
+}
+
+#
+# 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
+# implementation of SSL. To use openSSL, you must point out the location
+# of the openSSL headers and libs on your system.
+# For example: --with-ssl=/usr
+#
+set_base_configs()
+{
+  base_configs="$base_configs --prefix=$prefix"
+  base_configs="$base_configs --libexecdir=$prefix/bin"
+  base_configs="$base_configs --with-zlib-dir=bundled"
+  if test "x$datadir" = "x" ; then
+    base_configs="$base_configs --localstatedir=$prefix/data"
+  else
+    base_configs="$base_configs --localstatedir=$datadir"
+  fi
+  if test "x$with_debug_flag" = "xyes" ; then
+    base_configs="$base_configs --with-debug"
+  fi
+  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=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"
+  if test "x$with_perfschema" != "xno" ; then
+    base_configs="$base_configs --with-perfschema"
+  fi
+}
+
+#
+# Add all standard engines and partitioning (included as part of MySQL
+# Cluster storage engine as well) as part of MySQL Server. These are 
+# added in all packages except the classic package.
+#
+set_base_engines()
+{
+  engine_configs="--with-archive-storage-engine"
+  engine_configs="$engine_configs --with-blackhole-storage-engine"
+  engine_configs="$engine_configs --without-example-storage-engine"
+  engine_configs="$engine_configs --with-federated-storage-engine"
+  engine_configs="$engine_configs --with-partition"
+  base_configs="$base_configs $engine_configs"
+}
+
+set_innodb_engine()
+{
+  base_configs="$base_configs --with-innodb"
+}
+
+set_ndb_engine()
+{
+  base_configs="$base_configs --with-ndbcluster"
+  base_configs="$base_configs --without-ndb-debug"
+}
+
+set_pro_package()
+{
+  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
+}
+
+set_cge_extended_package()
+{
+  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
+  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\""
+  fi
+}
+
+set_cge_package()
+{
+  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\""
+  fi
+}
+
+set_classic_package()
+{
+  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"
+}
+
+#
+# Special handling of readline; use readline from the MySQL
+# distribution if building a GPL version, otherwise use libedit.
+#
+set_readline_package()
+{
+   if test -d "$path/../cmd-line-utils/libedit" ; then
+    base_configs="$base_configs --with-libedit"
+  fi
+}
+
+#
+# If fast flag set by user we also add architecture as discovered to 
+# compiler flags to make binary optimised for architecture at hand. 
+# We use this feature on gcc compilers.
+#
+set_gcc_special_options()
+{
+  if test "x$fast_flag" = "xyes" && test "x$compiler" = "xgcc" ; then
+    compiler_flags="$compiler_flags $check_cpu_cflags"
+  fi
+}
+
+#
+# If we discover a Core 2 Duo architecture and we have enabled the fast
+# flag, we enable a compile especially optimised for Core 2 Duo. This
+# feature is currently available on Intel's icc compiler only.
+#
+set_icc_special_options()
+{
+  if test "x$fast_flag" = "xyes" && test "x$cpu_arg" = "xcore2" && \
+     test "x$compiler" = "xicc" ; then
+    compiler_flags="$compiler_flags -xT"
+  fi
+}
+
+set_cc_and_cxx_for_gcc()
+{
+  if test "x$CC" = "x" ; then
+    CC="gcc -static-libgcc"
+  fi
+  if test "x$CXX" = "x" ; then
+    CXX="g++ -static-libgcc"
+  fi
+}
+
+set_cc_and_cxx_for_icc()
+{
+  if test "x$CC" = "x" ; then
+    CC="icc -static-intel -static-libgcc"
+  fi
+  if test "x$CXX" = "x" ; then
+    CXX="icpc -static-intel -static-libgcc"
+  fi
+}
+
+set_cc_and_cxx_for_open64()
+{
+  if test "x$CC" = "x" ; then
+    CC="opencc -static-libgcc"
+  fi
+  if test "x$CXX" = "x" ; then
+    CXX="openCC -static-libgcc"
+  fi
+}
+
+set_cc_and_cxx_for_forte()
+{
+  if test "x$CC" = "x" ; then
+    CC="cc"
+  fi
+  if test "x$CXX" = "x" ; then
+    CXX="CC"
+  fi
+}
+
+#
+# FreeBSD Section
+#
+set_bsd_configs()
+{
+  if test "x$cpu_base_type" != "xx86" ; then
+    usage "Only x86 CPUs supported for FreeBSD"
+    exit 1
+  fi
+  if test "x$compiler" != "xgcc" ; then
+    usage "Only gcc supported for FreeBSD"
+    exit 1
+  fi
+  base_configs="$base_configs --enable-assembler"
+  if test "x$fast_flag" != "xno" ; then
+    compiler_flags="$compiler_flags -O3"
+  else
+    compiler_flags="$compiler_flags -O0"
+  fi
+  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 (interprocedural optimizations) for Open64
+#
+check_for_open64_link_time_optimizer()
+{
+  if test "x$with_link_time_optimizer" = "xyes" ; then
+    compiler_flags="$compiler_flags -ipa"
+    LDFLAGS="$LDFLAGS -ipa"
+  fi
+}
+
+#
+# Link time optimizer (interprocedural optimizations) for icc
+#
+check_for_icc_link_time_optimizer()
+{
+  if test "x$with_link_time_optimizer" = "xyes" ; then
+    compiler_flags="$compiler_flags -ipo"
+    LDFLAGS="$LDFLAGS -ipo"
+  fi
+}
+
+#
+# Link time optimizer (interprocedural optimizations) for forte
+#
+check_for_forte_link_time_optimizer()
+{
+  if test "x$with_link_time_optimizer" = "xyes" ; then
+    compiler_flags="$compiler_flags -ipo"
+    LDFLAGS="$LDFLAGS -ipo"
+  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_gcc_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
+}
+
+set_feedback_for_gcc()
+{
+  if test "x$GENERATE_FEEDBACK_PATH" != "x" ; then
+    compiler_flags="$compiler_flags -fprofile-generate"
+    compiler_flags="$compiler_flags -fprofile-dir=$GENERATE_FEEDBACK_PATH"
+  elif test "x$USE_FEEDBACK_PATH" != "x" ; then
+    compiler_flags="$compiler_flags -fprofile-use"
+    compiler_flags="$compiler_flags -fprofile-correction"
+    compiler_flags="$compiler_flags -fprofile-dir=$USE_FEEDBACK_PATH"
+  fi
+}
+
+set_feedback_for_open64()
+{
+  if test "x$GENERATE_FEEDBACK_PATH" != "x" ; then
+    compiler_flags="$compiler_flags --fb-create=$GENERATE_FEEDBACK_PATH/feedback"
+  elif test "x$USE_FEEDBACK_PATH" != "x" ; then
+    compiler_flags="$compiler_flags --fb-opt=$USE_FEEDBACK_PATH/feedback"
+  fi
+}
+
+#
+# Linux Section
+#
+set_linux_configs()
+{
+# Default to use --with-fast-mutexes on Linux
+  if test "x$with_fast_mutexes" = "x" ; then
+    base_configs="$base_configs --with-fast-mutexes"
+  fi
+  if test "x$cpu_base_type" != "xx86" && \
+     test "x$cpu_base_type" != "xitanium" ; then
+    usage "Only x86 and Itanium CPUs supported for Linux"
+    exit 1
+  fi
+  if test "x$use_tcmalloc" = "xyes" ; then
+    base_configs="$base_configs --with-mysqld-libs=-ltcmalloc_minimal"
+  fi
+  if test "x$cpu_base_type" = "xx86" ; then
+    base_configs="$base_configs --enable-assembler"
+  fi
+  if test "x$compiler" = "xgcc" ; then
+    set_cc_and_cxx_for_gcc
+    if test "x$fast_flag" != "xno" ; then
+      if test "x$fast_flag" = "xyes" ; then
+        compiler_flags="$compiler_flags -O3"
+        check_for_gcc_link_time_optimizer
+      else
+        compiler_flags="$compiler_flags -O3"
+      fi
+    else
+      compiler_flags="$compiler_flags -O0"
+    fi
+    set_feedback_for_gcc
+# configure will set proper compiler flags for gcc on Linux
+  elif test "x$compiler" = "xicc" ; then
+    compiler_flags="$compiler_flags -mp -restrict"
+    set_cc_and_cxx_for_icc
+    if test "x$cpu_base_type" = "xitanium" ; then
+      compiler_flags="$compiler_flags -no-ftz"
+    fi
+    if test "x$fast_flag" != "xno" ; then
+      compiler_flags="$compiler_flags -O3 -unroll2 -ip"
+      if test "x$fast_flag" = "xyes" ; then
+        check_for_icc_link_time_optimizer
+      fi
+    fi
+  elif test "x$compiler" = "xopen64" ; then
+    set_cc_and_cxx_for_open64
+    if test "x$fast_flag" != "xno" ; then
+      if test "x$fast_flag" = "xyes" ; then
+        compiler_flags="$compiler_flags -O3"
+#       Generate code specific for the machine you run on
+        compiler_flags="$compiler_flags -march=auto"
+        check_for_open64_link_time_optimizer
+        if test "x$with_mso" = "xyes" ; then
+          compiler_flags="$compiler_flags -mso"
+        fi
+      else
+        compiler_flags="$compiler_flags -O3"
+      fi
+    fi
+    set_feedback_for_open64
+  else
+    usage "Only gcc,icc and Open64 compilers supported for Linux"
+    exit 1
+  fi
+  check_64_bits
+  if test "x$m64" = "xyes" ; then
+    compiler_flags="$compiler_flags -m64"
+  else
+    compiler_flags="$compiler_flags -m32"
+  fi
+}
+
+#
+# Solaris Section
+#
+set_solaris_configs()
+{
+# Use mtmalloc as malloc, see Tim Cook blog
+# 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*)
+      base_configs="$base_configs --with-mysqld-libs=-lmtmalloc"
+      ;;
+    *)
+      usage "Only versions 8,9, 10 and 11 supported for Solaris"
+      exit 1
+  esac
+  if test "x$cpu_base_type" != "xx86" && \
+     test "x$cpu_base_type" != "xsparc" ; then
+    usage "Only x86 and Sparc CPUs supported for Solaris"
+    exit 1
+  fi
+  if test "x$compiler" != "xgcc" && \
+     test "x$compiler" != "xforte" ; then
+    usage "Only gcc and Forte compilers supported for Solaris"
+    exit 1
+  fi
+  if test "x$m64" = "xyes" ; then
+    compiler_flags="$compiler_flags -m64"
+    LDFLAGS="-m64"
+    ASFLAGS="$ASFLAGS -m64"
+  else
+    compiler_flags="$compiler_flags -m32"
+    LDFLAGS="-m32"
+    ASFLAGS="$ASFLAGS -m32"
+  fi
+  if test "x$compiler" = "xgcc" ; then
+    set_cc_and_cxx_for_gcc
+    if test "x$cpu_base_type" != "xx86" ; then
+      usage "gcc currently not supported for Solaris on SPARC"
+      exit 1
+    fi
+    if test "x$fast_flag" = "xyes" ; then
+      LDFLAGS="$LDFLAGS -O3"
+      compiler_flags="$compiler_flags -O3"
+      check_for_gcc_link_time_optimizer
+    else
+      if test "x$fast_flag" = "xgeneric" ; then
+        LDFLAGS="$LDFLAGS -O2"
+        compiler_flags="$compiler_flags -O2"
+      else
+        LDFLAGS="$LDFLAGS -O0"
+        compiler_flags="$compiler_flags -O0"
+      fi
+    fi
+  else
+#Using Forte compiler (SunStudio)
+    set_cc_and_cxx_for_forte
+    compiler_flags="$compiler_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"
+    if test "x$fast_flag" = "xyes" ; then
+      compiler_flags="$compiler_flags -xtarget=native"
+      compiler_flags="$compiler_flags -xunroll=3"
+      check_for_forte_link_time_optimizer
+    else
+      compiler_flags="$compiler_flags -xtarget=generic"
+    fi
+    if test "x$cpu_base_type" = "xx86" ; then
+      compiler_flags="$compiler_flags -nofstore"
+      if test "x$fast_flag" = "xyes" ; then
+        compiler_flags="$compiler_flags -xregs=frameptr"
+        compiler_flags="$compiler_flags -xO4"
+      else
+        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_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 -xO3"
+      else
+        compiler_flags="$compiler_flags -xO0"
+      fi
+    fi
+  fi
+}
+
+#
+# Mac OS X Section
+#
+set_macosx_configs()
+{
+  if test "x$cpu_base_type" != "xx86" || test "x$compiler" != "xgcc" ; then
+    usage "Only gcc/x86 supported for Mac OS X"
+    exit 1
+  fi
+#
+# Optimize for space as long as it doesn't affect performance, use some
+# optimisations also when not in fast mode.
+#
+  base_cxxflags="$base_cxxflags -felide-constructors"
+  compiler_flags="$compiler_flags -fno-common"
+  if test "x$m64" = "xyes" ; then
+    compiler_flags="$compiler_flags -m64"
+    compiler_flags="$compiler_flags -arch x86_64"
+  else
+    compiler_flags="$compiler_flags -m32"
+    compiler_flags="$compiler_flags -arch i386"
+  fi
+  if test "x$fast_flag" != "xno" ; then
+    compiler_flags="$compiler_flags -Os"
+  else
+    compiler_flags="$compiler_flags -O0"
+  fi
+  set_cc_and_cxx_for_gcc
+}
+
+#
+# Use static linking for own modules and dynamic linking for system
+# modules unless specifically requested to do everything statically.
+# Should normally not be used; static_linking_flag kept in case someone 
+# really needs it. Available only if developer flag is also set.
+#
+set_static_link_configs()
+{
+  if test "x$static_linking_flag" = "xyes" && test "x$developer_flag" = "xyes" ; then
+    loc_static_link="--with-mysqld-ldflags=\"-all-static\""
+    loc_static_link="$loc_static_link --with-client-ldflags=\"-all-static\""
+  else
+    loc_static_link="--with-mysqld-ldflags=\"-static\""
+    loc_static_link="$loc_static_link --with-client-ldflags=\"-static\""
+  fi
+  base_configs="$base_configs $loc_static_link"
+}
+
+#
+# Enable error injection in MySQL Server (for developer build only -
+# extra check for developer flag required).
+#
+set_error_inject_configs()
+{
+  if test "x$error_inject_flag" = "xyes" && test "x$developer_flag" = "xyes" ; then
+    base_configs="$base_configs --with-error-inject"
+    if test "x$package" = "xndb" || test "x$package" = "xextended" ; then
+      base_configs="$base_configs --with-ndb-ccflags='-DERROR_INSERT'"
+    fi
+  fi
+}
+
+set_default_package()
+{
+  if test "x$package" = "x" ; then
+    if test "x$developer_flag" = "xyes" ; then
+      package="extended"
+    else
+      package="cge"
+    fi
+  fi
+}
+
+set_defaults_based_on_environment()
+{
+  if test ! -z "$MYSQL_DEVELOPER" ; then
+    developer_flag="yes"
+  fi
+  if test ! -z "$MYSQL_DEVELOPER_DEBUG" ; then
+    with_debug_flag="yes"
+    fast_flag="no"
+  fi
+  if test ! -z "$MYSQL_DEVELOPER_PACKAGE" ; then
+    package="$MYSQL_DEVELOPER_PACKAGE"
+    parse_package
+  fi
+}
+
+########################################################################
+
+if test ! -f sql/mysqld.cc ; then
+  die "You must run this script from the MySQL top-level directory"
+fi
+
+cpu_type=
+package=
+prefix="/usr/local/mysql"
+parallelism="8"
+fast_flag="generic"
+compiler="gcc"
+gpl="yes"
+version_text=
+developer_flag="no"
+just_configure=
+warning_mode=
+with_flags=
+error_inject_flag=
+with_debug_flag=
+compile_debug_flag=
+strip_flag=
+valgrind_flag=
+static_linking_flag=
+compiler_flags=
+os=
+cpu_base_type=
+warnings=
+c_warnings=
+cflags=
+base_cflags=
+cxx_warnings=
+base_cxxflags=
+base_configs=
+debug_flags=
+cxxflags=
+extra_debug_flags=
+m64=
+explicit_size_set=
+datadir=
+commands=
+engine_configs=
+ASFLAGS=
+LDFLAGS=
+use_tcmalloc=
+without_comment="yes"
+with_fast_mutexes=
+with_perfschema="yes"
+with_link_time_optimizer=
+with_mso=
+gcc_version="0"
+generate_feedback_path=
+use_feedback_path=
+
+set_defaults_based_on_environment
+
+parse_options "$@"
+
+set_default_package
+
+set -e
+
+#
+# Check for the CPU and set up CPU specific flags. We may reset them
+# later.
+# This call sets the cpu_arg and check_cpu_args parameters
+#
+path=`dirname $0`
+if test "x$compiler" = "xgcc" ; then
+  compiler=
+fi
+. "$path/check-cpu"
+if test "x$compiler" = "x" ; then
+  compiler="gcc"
+fi
+check_os
+set_cpu_base
+if test "x$?" = "x1" ; then
+  exit 1
+fi
+
+#
+# Set up c_warnings and cxx_warnings; add to compiler_flags.
+# Possibly reset check_cpu_flags.
+#
+set_warning_flags
+
+#
+# Add to compiler_flags.
+#
+set_valgrind_flags
+set_with_debug_flags
+set_no_omit_frame_pointer_for_developers
+set_debug_flag
+set_gcc_special_options
+set_icc_special_options
+
+#
+# Definitions of various packages possible to compile. The default is to
+# build a source variant of MySQL Cluster Carrier Grade Edition 
+# including all storage engines except InnoDB, and to use GPL libraries.
+#
+set_base_configs
+if test "x$gpl" = "xyes" ; then
+  version_text="GPL version"
+else
+  version_text="Commercial version"
+fi
+if test "x$package" = "xpro" ; then
+  set_base_engines
+  set_innodb_engine
+  set_pro_package
+elif test "x$package" = "xextended" ; then
+  set_base_engines
+  set_ndb_engine
+  set_innodb_engine
+  set_cge_extended_package
+elif test "x$package" = "xcge" ; then
+  set_base_engines
+  set_ndb_engine
+  set_cge_package
+elif test "x$package" = "xclassic" ; then
+  set_classic_package
+else
+  die "No supported package was used, internal error"
+fi
+set_readline_package
+set_static_link_configs
+set_error_inject_configs
+
+#
+# This section handles flags for specific combinations of compilers,
+# operating systems, and processors.
+#
+
+if test "x$os" = "xlinux" ; then
+  set_linux_configs
+elif test "x$os" = "xSolaris" ; then
+  set_solaris_configs
+elif test "x$os" = "xMacOSX" ; then
+  set_macosx_configs
+elif test "x$os" = "xbsd" ; then
+  set_bsd_configs
+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.
+#
+set_make_version
+set_ccache_usage
+
+#
+# Set up commands variable from variables prepared for base 
+# configurations, compiler flags, and warnings flags.
+# 
+init_configure_commands
+
+if test "x$just_configure" != "xyes" ; then
+  add_make_commands
+fi
+
+#
+# The commands variable now contains the entire command to be run for
+# the build; we either execute it, or merely print it out.
+#
+echo "Running command:"
+echo "$commands"
+if test "x$just_print" != "xyes" ; then
+  eval "set -x; $commands"
+fi

=== modified file 'include/my_base.h'
--- a/include/my_base.h	2012-04-24 06:21:11 +0000
+++ b/include/my_base.h	2012-05-09 16:47:39 +0000
@@ -10,8 +10,9 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
 
 /* This file includes constants used with all databases */
 
@@ -463,7 +464,8 @@ is the global server default. */
 #define HA_ERR_INDEX_CORRUPT      180	 /* InnoDB index corrupted */
 #define HA_ERR_UNDO_REC_TOO_BIG   181    /* Undo log record too big */
 #define HA_FTS_INVALID_DOCID      182	/* Invalid InnoDB Doc ID */
-#define HA_ERR_LAST               182    /* Copy of last error nr */
+#define HA_ERR_TABLE_IN_FK_CHECK  183    /* Table being used in foreign key check */
+#define HA_ERR_LAST               183    /* Copy of last error nr */
 
 /* Number of different errors */
 #define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)

=== modified file 'include/mysql/psi/mysql_socket.h'
--- a/include/mysql/psi/mysql_socket.h	2012-03-07 08:31:23 +0000
+++ b/include/mysql/psi/mysql_socket.h	2012-03-08 15:34:34 +0000
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth 
 #ifdef __WIN__
   #include <ws2def.h>
   #include <winsock2.h>
+  #include <MSWSock.h>
   #define SOCKBUF_T char
 #else
   #include <netinet/in.h>
@@ -1105,7 +1106,20 @@ inline_mysql_socket_shutdown
 {
   int result;
 
-  /* Instrumentation start */
+#ifdef __WIN__
+  static LPFN_DISCONNECTEX DisconnectEx = NULL;
+  if (DisconnectEx == NULL)
+  {
+    DWORD dwBytesReturned;
+    GUID guidDisconnectEx = WSAID_DISCONNECTEX;
+    WSAIoctl(mysql_socket.fd, SIO_GET_EXTENSION_FUNCTION_POINTER,
+             &guidDisconnectEx, sizeof(GUID),
+             &DisconnectEx, sizeof(DisconnectEx), 
+             &dwBytesReturned, NULL, NULL);
+  }
+#endif
+
+/* Instrumentation start */
 #ifdef HAVE_PSI_SOCKET_INTERFACE
   if (mysql_socket.m_psi != NULL)
   {
@@ -1115,7 +1129,13 @@ inline_mysql_socket_shutdown
                                         PSI_SOCKET_SHUTDOWN, (size_t)0, src_file, src_line);
 
     /* Instrumented code */
-    result= shutdown(mysql_socket.fd, how);
+#ifdef __WIN__
+    if (DisconnectEx)
+      result= (DisconnectEx(mysql_socket.fd, (LPOVERLAPPED) NULL,
+                            (DWORD) 0, (DWORD) 0) == TRUE) ? 0 : -1;
+    else
+#endif
+      result= shutdown(mysql_socket.fd, how);
 
     /* Instrumentation end */
     if (locker != NULL)
@@ -1126,7 +1146,13 @@ inline_mysql_socket_shutdown
 #endif
 
   /* Non instrumented code */
-  result= shutdown(mysql_socket.fd, how);
+#ifdef __WIN__
+  if (DisconnectEx)
+    result= (DisconnectEx(mysql_socket.fd, (LPOVERLAPPED) NULL,
+                          (DWORD) 0, (DWORD) 0) == TRUE) ? 0 : -1;
+  else
+#endif
+    result= shutdown(mysql_socket.fd, how);
 
   return result;
 }

=== modified file 'mysql-test/include/subquery.inc'
--- a/mysql-test/include/subquery.inc	2012-05-02 07:44:09 +0000
+++ b/mysql-test/include/subquery.inc	2012-05-09 16:47:39 +0000
@@ -5869,6 +5869,18 @@ DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 
 --echo #
+--echo # Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+--echo #
+
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+
+DROP TABLE t1;
+
+--echo #
 --echo # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 --echo # SELECT * SUBQ FOR TABLES
 --echo #
@@ -5989,6 +6001,38 @@ eval $query;
 
 DROP TABLE t0, t1, t2;
 
+
+--echo #
+--echo # Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+--echo # INDEX
+--echo #
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+
+let $query=SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+
+eval EXPLAIN $query;
+eval $query;
+
+DROP TABLE t1,t2;
+
+
 --echo #
 --echo # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 --echo # COMPOSITE INDEX ON SUBQUERY'S TABLE

=== added file 'mysql-test/r/blackhole.result'
--- a/mysql-test/r/blackhole.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/blackhole.result	2012-03-28 08:22:31 +0000
@@ -0,0 +1,11 @@
+#
+# Bug #11880012: INDEX_SUBQUERY, BLACKHOLE,
+#                HANG IN PREPARING WITH 100% CPU USAGE
+#
+CREATE TABLE t1(a INT NOT NULL);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT UNSIGNED, b INT, UNIQUE KEY (a, b)) ENGINE=BLACKHOLE;
+SELECT 1 FROM t1 WHERE a = ANY (SELECT a FROM t2);
+1
+DROP TABLE t1, t2;
+End of 5.5 tests 

=== modified file 'mysql-test/r/cast.result'
--- a/mysql-test/r/cast.result	2012-04-24 07:35:13 +0000
+++ b/mysql-test/r/cast.result	2012-05-09 16:47:39 +0000
@@ -468,6 +468,15 @@ NULL
 Warnings:
 Warning	1301	Result of cast_as_char() was larger than max_allowed_packet (2048) - truncated
 SET @@GLOBAL.max_allowed_packet=default;
+#
+# Bug#13519724 63793: CRASH IN DTCOLLATION::SET(DTCOLLATION &SET)
+#
+CREATE TABLE t1 (a VARCHAR(50));
+SELECT a FROM t1 
+WHERE CAST(a as BINARY)=x'62736D697468' 
+AND CAST(a AS BINARY)=x'65736D697468';
+a
+DROP TABLE t1;
 End of 5.1 tests
 #
 # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH LONGTEXT, UNION, USER VARIABLE

=== modified file 'mysql-test/r/errors.result'
--- a/mysql-test/r/errors.result	2010-11-04 12:36:36 +0000
+++ b/mysql-test/r/errors.result	2012-03-12 08:24:59 +0000
@@ -146,3 +146,17 @@ ERROR 22003: BIGINT value is out of rang
 #
 # End Bug#57882
 #
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2(a INT PRIMARY KEY, b INT);
+SELECT '' AS b FROM t1 GROUP BY VALUES(b);
+ERROR 42S22: Unknown column '' in 'VALUES() function'
+REPLACE t2(b) SELECT '' AS b FROM t1 GROUP BY VALUES(b);
+ERROR 42S22: Unknown column '' in 'VALUES() function'
+UPDATE t2 SET a=(SELECT '' AS b FROM t1 GROUP BY VALUES(b));
+ERROR 42S22: Unknown column '' in 'VALUES() function'
+INSERT INTO t2 VALUES (1,0) ON DUPLICATE KEY UPDATE
+b=(SELECT '' AS b FROM t1 GROUP BY VALUES(b));
+ERROR 42S22: Unknown column '' in 'VALUES() function'
+INSERT INTO t2(a,b) VALUES (1,0) ON DUPLICATE KEY UPDATE
+b=(SELECT VALUES(a)+2 FROM t1);
+DROP TABLE t1, t2;

=== modified file 'mysql-test/r/gis.result'
--- a/mysql-test/r/gis.result	2012-03-09 08:50:17 +0000
+++ b/mysql-test/r/gis.result	2012-03-09 13:54:12 +0000
@@ -1077,6 +1077,19 @@ SPATIAL INDEX i1 (col1, col2)
 ERROR HY000: Incorrect arguments to SPATIAL INDEX
 DROP TABLE t0, t1, t2;
 #
+# BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS
+#
+SELECT ISCLOSED(CONVERT(CONCAT('     ', 0x2), BINARY(20)));
+ISCLOSED(CONVERT(CONCAT('     ', 0x2), BINARY(20)))
+NULL
+#
+# BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN 
+# GEOMETRY FUNCTION ARGUMENTS
+#
+SELECT GEOMETRYCOLLECTION((SELECT @@OLD));
+ERROR 22007: Illegal non geometric '' value found during parsing
+End of 5.1 tests
+#
 # Bug#11908153: CRASH AND/OR VALGRIND ERRORS IN FIELD_BLOB::GET_KEY_IMAGE
 #
 CREATE TABLE g1

=== modified file 'mysql-test/r/sp-bugs.result'
--- a/mysql-test/r/sp-bugs.result	2012-03-28 08:27:26 +0000
+++ b/mysql-test/r/sp-bugs.result	2012-04-10 12:20:51 +0000
@@ -109,6 +109,26 @@ DROP FUNCTION db1.f1;
 DROP TABLE db1.t1;
 DROP DATABASE db1;
 DROP DATABASE db2;
+#
+# Bug#13105873:valgrind warning:possible crash in foreign 
+# key handling on subsequent create table if not exists 
+#
+DROP DATABASE IF EXISTS testdb;
+CREATE DATABASE testdb;
+USE testdb;
+CREATE TABLE t1 (id1 INT PRIMARY KEY);
+CREATE PROCEDURE `p1`()
+BEGIN
+CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY,
+CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 ));
+END$
+CALL p1();
+# below stmt should not return valgrind warnings
+CALL p1();
+Warnings:
+Note	1050	Table 't2' already exists
+DROP DATABASE testdb;
+USE test;
 End of 5.1 tests
 #
 # BUG#13489996 valgrind:conditional jump or move depends on

=== modified file 'mysql-test/r/sp-destruct.result'
--- a/mysql-test/r/sp-destruct.result	2012-04-23 08:14:28 +0000
+++ b/mysql-test/r/sp-destruct.result	2012-05-09 16:47:39 +0000
@@ -148,7 +148,7 @@ alter table mysql.proc drop column type;
 # The below statement should not cause assertion failure.
 drop database mysqltest;
 Warnings:
-Error	1727	Column count of mysql.proc is wrong. Expected 20, found 19. The table is probably corrupted
+Error	1805	Column count of mysql.proc is wrong. Expected 20, found 19. The table is probably corrupted
 # Restore mysql.proc.
 drop table mysql.proc;
 #

=== modified file 'mysql-test/r/subquery_all.result'
--- a/mysql-test/r/subquery_all.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_all.result	2012-05-09 16:47:39 +0000
@@ -7153,6 +7153,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7276,6 +7285,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_all_bka.result'
--- a/mysql-test/r/subquery_all_bka.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_all_bka.result	2012-05-09 16:47:39 +0000
@@ -7154,6 +7154,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7277,6 +7286,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_all_bka_nixbnl.result'
--- a/mysql-test/r/subquery_all_bka_nixbnl.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_all_bka_nixbnl.result	2012-05-09 16:47:39 +0000
@@ -7154,6 +7154,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7277,6 +7286,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_nomat_nosj.result'
--- a/mysql-test/r/subquery_nomat_nosj.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_nomat_nosj.result	2012-05-09 16:47:39 +0000
@@ -7153,6 +7153,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7276,6 +7285,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_nomat_nosj_bka.result'
--- a/mysql-test/r/subquery_nomat_nosj_bka.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_nomat_nosj_bka.result	2012-05-09 16:47:39 +0000
@@ -7154,6 +7154,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7277,6 +7286,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result'
--- a/mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_nomat_nosj_bka_nixbnl.result	2012-05-09 16:47:39 +0000
@@ -7154,6 +7154,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7277,6 +7286,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_none.result'
--- a/mysql-test/r/subquery_none.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_none.result	2012-05-09 16:47:39 +0000
@@ -7152,6 +7152,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7275,6 +7284,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_none_bka.result'
--- a/mysql-test/r/subquery_none_bka.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_none_bka.result	2012-05-09 16:47:39 +0000
@@ -7153,6 +7153,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7276,6 +7285,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subquery_none_bka_nixbnl.result'
--- a/mysql-test/r/subquery_none_bka_nixbnl.result	2012-05-02 07:44:09 +0000
+++ b/mysql-test/r/subquery_none_bka_nixbnl.result	2012-05-09 16:47:39 +0000
@@ -7153,6 +7153,15 @@ NULL
 DROP VIEW v1, v2;
 DROP TABLE m, o, integers;
 #
+# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY
+#
+CREATE TABLE t1(a TIME NOT NULL);
+INSERT INTO t1 VALUES ('00:00:32');
+SELECT 1 FROM t1 WHERE a >
+(SELECT timestamp(a) AS a FROM t1);
+1
+DROP TABLE t1;
+#
 # Bug #13736664 RIGHT JOIN+WHERE QUERY GIVES DIFF RESULTS WHEN USING
 # SELECT * SUBQ FOR TABLES
 #
@@ -7276,6 +7285,42 @@ WHERE ((SELECT i1 FROM t0 WHERE i1 = 7),
 col_varchar_key
 DROP TABLE t0, t1, t2;
 #
+# Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
+# INDEX
+#
+CREATE TABLE t1 (
+id int
+) ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (11);
+CREATE TABLE t2 (
+t1_id int,
+position int,
+KEY t1_id (t1_id),
+KEY t1_id_position (t1_id,position)
+) ENGINE=InnoDB;
+EXPLAIN SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	t1_id,t1_id_position	t1_id_position	5	test.t1.id	1	Using where
+SELECT
+(SELECT position FROM t2
+WHERE t2.t1_id = t1.id
+ORDER BY t2.t1_id , t2.position
+LIMIT 10,1
+) AS maxkey
+FROM t1
+LIMIT 1;
+maxkey
+NULL
+DROP TABLE t1,t2;
+#
 # Bug#13731417 WRONG RESULT WITH NOT IN (SUBQUERY) AND
 # COMPOSITE INDEX ON SUBQUERY'S TABLE
 #

=== modified file 'mysql-test/r/subselect_innodb.result'
--- a/mysql-test/r/subselect_innodb.result	2012-02-29 11:17:52 +0000
+++ b/mysql-test/r/subselect_innodb.result	2012-04-04 11:06:05 +0000
@@ -442,3 +442,26 @@ SELECT * FROM t1 WHERE b < (SELECT CAST(
 a	b
 2011-05-13	0
 DROP TABLE t1;
+#
+# Bug #11766300  59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE
+#
+CREATE TABLE t1 (a INT) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0);
+CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d)) ENGINE=INNODB;
+SELECT 1 FROM t1 WHERE NOT EXISTS
+(SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
+1
+1
+EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS
+(SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
+2	DEPENDENT SUBQUERY	t2	eq_ref	PRIMARY,d	PRIMARY	1	func	1	Using where
+3	DEPENDENT SUBQUERY	t2	index	NULL	d	2	NULL	1	Using where; Using index
+DROP TABLE t2;
+CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB;
+INSERT INTO t2 VALUES (1, 1);
+SELECT 1 FROM t1
+WHERE a != (SELECT 1 FROM t2 WHERE a <=> b OR a > '' AND 6 = 7 ORDER BY b, c);
+1
+DROP TABLE t1, t2;

=== modified file 'mysql-test/r/user_var.result'
--- a/mysql-test/r/user_var.result	2012-03-06 14:29:42 +0000
+++ b/mysql-test/r/user_var.result	2012-03-09 14:40:39 +0000
@@ -485,6 +485,12 @@ f1	f2
 1	4
 DROP TRIGGER trg1;
 DROP TABLE t1;
+#
+# Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT
+#   SAME USER VARIABLE = CRASH
+#
+SET @bug12408412=1;
+SELECT GROUP_CONCAT(@bug12408412 ORDER BY 1) INTO @bug12408412;
 End of 5.5 tests
 CREATE TABLE t1(a int);
 INSERT INTO t1 VALUES (1), (2);

=== added file 'mysql-test/suite/innodb/r/innodb_bug13635833.result'
--- a/mysql-test/suite/innodb/r/innodb_bug13635833.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_bug13635833.result	2012-03-09 13:40:32 +0000
@@ -0,0 +1,45 @@
+SET DEBUG_SYNC='reset';
+create table t1 (f1 integer, key k1 (f1)) engine=innodb;
+create table t2 (f1 int, f2 int, key(f1), key(f2)) engine=innodb;
+create table t3 (f2 int, key(f2)) engine=innodb;
+insert into t1 values (10);
+insert into t2 values (10, 20);
+insert into t3 values (20);
+alter table t2 add constraint c1 foreign key (f1)
+references t1(f1) on update cascade;
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `f1` int(11) DEFAULT NULL,
+  KEY `k1` (`f1`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+show create table t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `f1` int(11) DEFAULT NULL,
+  `f2` int(11) DEFAULT NULL,
+  KEY `f1` (`f1`),
+  KEY `f2` (`f2`),
+  CONSTRAINT `c1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `f2` int(11) DEFAULT NULL,
+  KEY `f2` (`f2`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL update_can_proceed
+                   WAIT_FOR dict_unfreeze';
+alter table t2 add constraint z1 foreign key (f2)
+references t3(f2) on update cascade;
+SET DEBUG_SYNC='innodb_row_update_for_mysql_begin
+                            WAIT_FOR update_can_proceed';
+SET DEBUG_SYNC='innodb_dml_cascade_dict_unfreeze SIGNAL dict_unfreeze
+                            WAIT_FOR  foreign_free_cache';
+update ignore t1 set f1 = 20;
+ERROR HY000: Error on rename of './test/t2' to '#sql2-temporary' (errno: 183 - Table is being used in foreign key check)
+SET DEBUG_SYNC='now SIGNAL foreign_free_cache';
+drop table t2;
+drop table t1;
+drop table t3;
+SET DEBUG_SYNC='reset';

=== added file 'mysql-test/suite/innodb/t/innodb_bug13635833.test'
--- a/mysql-test/suite/innodb/t/innodb_bug13635833.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug13635833.test	2012-02-27 11:53:56 +0000
@@ -0,0 +1,64 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+SET DEBUG_SYNC='reset';
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+create table t1 (f1 integer, key k1 (f1)) engine=innodb;
+create table t2 (f1 int, f2 int, key(f1), key(f2)) engine=innodb;
+create table t3 (f2 int, key(f2)) engine=innodb;
+
+insert into t1 values (10);
+insert into t2 values (10, 20);
+insert into t3 values (20);
+
+alter table t2 add constraint c1 foreign key (f1)
+    references t1(f1) on update cascade;
+
+show create table t1;
+show create table t2;
+show create table t3;
+
+SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL update_can_proceed
+                   WAIT_FOR dict_unfreeze';
+
+--send
+alter table t2 add constraint z1 foreign key (f2)
+    references t3(f2) on update cascade;
+
+connect (thr2,localhost,root,,);
+connection thr2;
+
+SET DEBUG_SYNC='innodb_row_update_for_mysql_begin
+                            WAIT_FOR update_can_proceed';
+SET DEBUG_SYNC='innodb_dml_cascade_dict_unfreeze SIGNAL dict_unfreeze
+                            WAIT_FOR  foreign_free_cache';
+
+--send
+update ignore t1 set f1 = 20;
+
+connection default;
+--replace_regex /'[^']*test\/#sql2-[0-9a-f-]*'/'#sql2-temporary'/
+--error ER_ERROR_ON_RENAME
+reap;
+
+SET DEBUG_SYNC='now SIGNAL foreign_free_cache';
+
+connection thr2;
+reap;
+disconnect thr2;
+--source include/wait_until_disconnected.inc
+
+connection default;
+
+drop table t2;
+drop table t1;
+drop table t3;
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc
+
+SET DEBUG_SYNC='reset';

=== modified file 'mysql-test/suite/rpl/r/rpl_alter_repository.result'
--- a/mysql-test/suite/rpl/r/rpl_alter_repository.result	2012-05-04 07:51:46 +0000
+++ b/mysql-test/suite/rpl/r/rpl_alter_repository.result	2012-05-09 16:47:39 +0000
@@ -46,7 +46,7 @@ call mtr.add_suppression(" Error while c
 INSERT INTO t_innodb VALUES (1), (2), (3);
 ALTER TABLE mysql.slave_relay_log_info DROP COLUMN Number_of_workers;
 INSERT INTO t_innodb VALUES (1), (2), (3);
-include/wait_for_slave_sql_error.inc [errno=1727]
+include/wait_for_slave_sql_error.inc [errno=1805]
 Last_SQL_Error = 'Column count of mysql.slave_relay_log_info is wrong. Expected 8, found 7. The table is probably corrupted'
 include/stop_slave_io.inc
 include/rpl_restart_server.inc [server_number=2 parameters: --sync-master-info=1 --master-info-repository=TABLE --relay-log-info-repository=TABLE]
@@ -59,7 +59,7 @@ include/start_slave.inc
 INSERT INTO t_innodb VALUES (1), (2), (3);
 ALTER TABLE mysql.slave_relay_log_info DROP COLUMN Number_of_workers;
 INSERT INTO t_innodb VALUES (1), (2), (3);
-include/wait_for_slave_sql_error.inc [errno=1727]
+include/wait_for_slave_sql_error.inc [errno=1805]
 Last_SQL_Error = 'Column count of mysql.slave_relay_log_info is wrong. Expected 8, found 7. The table is probably corrupted'
 include/stop_slave_io.inc
 START SLAVE SQL_THREAD;

=== added file 'mysql-test/suite/rpl/r/rpl_row_merge_engine.result'
--- a/mysql-test/suite/rpl/r/rpl_row_merge_engine.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_merge_engine.result	2012-04-12 12:44:00 +0000
@@ -0,0 +1,19 @@
+include/master-slave.inc
+Warnings:
+Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
+Note	####	Storing MySQL user name or password information in the master.info repository is not secure and is therefore not recommended. Please see the MySQL Manual for more about this issue and possible alternatives.
+[connection master]
+CREATE TABLE t1 (a int) ENGINE=MyISAM;
+CREATE TABLE t2 (a int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (4), (5), (6);
+CREATE TABLE IF NOT EXISTS t1_merge LIKE t1;
+ALTER TABLE t1_merge ENGINE=MERGE UNION (t2, t1);
+include/diff_tables.inc [master:test.t1, slave:test.t1]
+include/diff_tables.inc [master:test.t2, slave:test.t2]
+UPDATE t1_merge SET a=10 WHERE a=1;
+DELETE FROM t1_merge WHERE a=10;
+include/diff_tables.inc [master:test.t1, slave:test.t1]
+include/diff_tables.inc [master:test.t2, slave:test.t2]
+DROP TABLE t1_merge, t1, t2;
+include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/t/rpl_alter_repository.test'
--- a/mysql-test/suite/rpl/t/rpl_alter_repository.test	2012-05-04 07:51:46 +0000
+++ b/mysql-test/suite/rpl/t/rpl_alter_repository.test	2012-05-09 16:47:39 +0000
@@ -59,8 +59,8 @@ ALTER TABLE mysql.slave_relay_log_info D
 --connection master
 INSERT INTO t_innodb VALUES (1), (2), (3);
 --connection slave
-# ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2 1726
---let $slave_sql_errno= 1727
+# ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2 1805
+--let $slave_sql_errno= 1805
 --let $show_slave_sql_error= 1
 --source include/wait_for_slave_sql_error.inc
 --source include/stop_slave_io.inc
@@ -99,8 +99,8 @@ ALTER TABLE mysql.slave_relay_log_info D
 --connection master
 INSERT INTO t_innodb VALUES (1), (2), (3);
 --connection slave
-# ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2 1726
---let $slave_sql_errno= 1727
+# ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2 1805
+--let $slave_sql_errno= 1805
 --let $show_slave_sql_error= 1
 --source include/wait_for_slave_sql_error.inc
 --source include/stop_slave_io.inc

=== added file 'mysql-test/suite/rpl/t/rpl_row_merge_engine.test'
--- a/mysql-test/suite/rpl/t/rpl_row_merge_engine.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_merge_engine.test	2012-02-24 16:07:43 +0000
@@ -0,0 +1,50 @@
+#
+# BUG#47103
+# 
+# This test case checks whether the slave crashes or not when there is
+# a merge table in use.
+#
+# Description
+# ===========
+#
+# The test case creates two regular MyISAM tables on the master and
+# one MERGE table. Then it populates the MyISAM tables, updates and 
+# deletes their contents through the merge table. Finally, the slave
+# is synchronized with the master and (after the fix) it won't crash.
+# 
+--source include/master-slave.inc
+--source include/have_binlog_format_row.inc
+--connection master
+
+CREATE TABLE t1 (a int) ENGINE=MyISAM;
+CREATE TABLE t2 (a int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1), (2), (3);
+INSERT INTO t2 VALUES (4), (5), (6);
+CREATE TABLE IF NOT EXISTS t1_merge LIKE t1;
+ALTER TABLE t1_merge ENGINE=MERGE UNION (t2, t1);
+
+--sync_slave_with_master
+
+--let diff_tables=master:test.t1, slave:test.t1
+--source include/diff_tables.inc
+
+--let diff_tables=master:test.t2, slave:test.t2
+--source include/diff_tables.inc
+
+--connection master
+UPDATE t1_merge SET a=10 WHERE a=1;
+DELETE FROM t1_merge WHERE a=10;
+
+--sync_slave_with_master
+--connection master
+
+--let diff_tables=master:test.t1, slave:test.t1
+--source include/diff_tables.inc
+
+--let diff_tables=master:test.t2, slave:test.t2
+--source include/diff_tables.inc
+
+DROP TABLE t1_merge, t1, t2;
+--sync_slave_with_master
+
+--source include/rpl_end.inc

=== added file 'mysql-test/t/blackhole.test'
--- a/mysql-test/t/blackhole.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/blackhole.test	2012-03-28 08:22:31 +0000
@@ -0,0 +1,21 @@
+#
+# Tests for the BLACKHOLE storage engine
+#
+
+--source include/have_blackhole.inc
+
+--echo #
+--echo # Bug #11880012: INDEX_SUBQUERY, BLACKHOLE,
+--echo #                HANG IN PREPARING WITH 100% CPU USAGE
+--echo #
+
+CREATE TABLE t1(a INT NOT NULL);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT UNSIGNED, b INT, UNIQUE KEY (a, b)) ENGINE=BLACKHOLE;
+
+SELECT 1 FROM t1 WHERE a = ANY (SELECT a FROM t2);
+
+DROP TABLE t1, t2;
+
+--echo End of 5.5 tests 
+

=== modified file 'mysql-test/t/cast.test'
--- a/mysql-test/t/cast.test	2012-04-24 07:35:13 +0000
+++ b/mysql-test/t/cast.test	2012-05-09 16:47:39 +0000
@@ -295,6 +295,18 @@ connection default;
 disconnect newconn;
 SET @@GLOBAL.max_allowed_packet=default;
 
+--echo #
+--echo # Bug#13519724 63793: CRASH IN DTCOLLATION::SET(DTCOLLATION &SET)
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(50));
+
+SELECT a FROM t1 
+WHERE CAST(a as BINARY)=x'62736D697468' 
+  AND CAST(a AS BINARY)=x'65736D697468';
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests
 
 --echo #

=== modified file 'mysql-test/t/errors.test'
--- a/mysql-test/t/errors.test	2010-11-04 12:36:36 +0000
+++ b/mysql-test/t/errors.test	2012-03-12 08:24:59 +0000
@@ -171,3 +171,21 @@ SELECT UPDATEXML(-73 * -2465717823867977
 --echo #
 --echo # End Bug#57882
 --echo #
+
+#
+# Bug #13031606 VALUES() IN A SELECT STATEMENT CRASHES SERVER
+#
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2(a INT PRIMARY KEY, b INT);
+--error ER_BAD_FIELD_ERROR
+SELECT '' AS b FROM t1 GROUP BY VALUES(b);
+--error ER_BAD_FIELD_ERROR
+REPLACE t2(b) SELECT '' AS b FROM t1 GROUP BY VALUES(b);
+--error ER_BAD_FIELD_ERROR
+UPDATE t2 SET a=(SELECT '' AS b FROM t1 GROUP BY VALUES(b));
+--error ER_BAD_FIELD_ERROR
+INSERT INTO t2 VALUES (1,0) ON DUPLICATE KEY UPDATE
+  b=(SELECT '' AS b FROM t1 GROUP BY VALUES(b));
+INSERT INTO t2(a,b) VALUES (1,0) ON DUPLICATE KEY UPDATE
+  b=(SELECT VALUES(a)+2 FROM t1);
+DROP TABLE t1, t2;

=== modified file 'mysql-test/t/gis.test'
--- a/mysql-test/t/gis.test	2011-12-09 21:08:37 +0000
+++ b/mysql-test/t/gis.test	2012-03-08 15:34:34 +0000
@@ -820,6 +820,24 @@ CREATE TABLE t3 (
 # cleanup
 DROP TABLE t0, t1, t2;
 
+
+--echo #
+--echo # BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS
+--echo #
+SELECT ISCLOSED(CONVERT(CONCAT('     ', 0x2), BINARY(20)));
+
+--echo #
+--echo # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN 
+--echo # GEOMETRY FUNCTION ARGUMENTS
+--echo #
+--replace_regex /non geometric .* value/non geometric '' value/
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+SELECT GEOMETRYCOLLECTION((SELECT @@OLD));
+
+
+--echo End of 5.1 tests
+
+
 --echo #
 --echo # Bug#11908153: CRASH AND/OR VALGRIND ERRORS IN FIELD_BLOB::GET_KEY_IMAGE
 --echo #

=== modified file 'mysql-test/t/sp-bugs.test'
--- a/mysql-test/t/sp-bugs.test	2012-03-28 08:27:26 +0000
+++ b/mysql-test/t/sp-bugs.test	2012-04-10 12:20:51 +0000
@@ -138,6 +138,31 @@ DROP FUNCTION db1.f1;
 DROP TABLE db1.t1;
 DROP DATABASE db1;
 DROP DATABASE db2;
+
+--echo #
+--echo # Bug#13105873:valgrind warning:possible crash in foreign 
+--echo # key handling on subsequent create table if not exists 
+--echo #
+
+--disable_warnings
+DROP DATABASE IF EXISTS testdb;
+--enable_warnings
+CREATE DATABASE testdb;
+USE testdb;
+CREATE TABLE t1 (id1 INT PRIMARY KEY);
+DELIMITER $;
+CREATE PROCEDURE `p1`()
+BEGIN
+    CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY,
+    CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 ));
+END$
+DELIMITER ;$
+CALL p1();
+--echo # below stmt should not return valgrind warnings
+CALL p1(); 
+DROP DATABASE testdb;
+USE test;
+
 --echo End of 5.1 tests
 
 --echo #

=== modified file 'mysql-test/t/subselect_innodb.test'
--- a/mysql-test/t/subselect_innodb.test	2011-02-17 13:59:06 +0000
+++ b/mysql-test/t/subselect_innodb.test	2012-04-04 11:06:05 +0000
@@ -458,3 +458,28 @@ CREATE TABLE t1(a date, b int, unique(b)
 INSERT INTO t1 VALUES ('2011-05-13', 0);
 SELECT * FROM t1 WHERE b < (SELECT CAST(a as date) FROM t1 GROUP BY a); 
 DROP TABLE t1;
+
+
+--echo #
+--echo # Bug #11766300  59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE
+--echo #
+
+CREATE TABLE t1 (a INT) ENGINE=INNODB;
+INSERT INTO t1 VALUES (0);
+CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d)) ENGINE=INNODB;
+
+SELECT 1 FROM t1 WHERE NOT EXISTS
+(SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
+
+EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS
+(SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
+
+DROP TABLE t2;
+
+CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB;
+INSERT INTO t2 VALUES (1, 1);
+
+SELECT 1 FROM t1
+WHERE a != (SELECT 1 FROM t2 WHERE a <=> b OR a > '' AND 6 = 7 ORDER BY b, c);
+
+DROP TABLE t1, t2;

=== modified file 'mysql-test/t/user_var.test'
--- a/mysql-test/t/user_var.test	2012-03-06 14:29:42 +0000
+++ b/mysql-test/t/user_var.test	2012-03-09 14:40:39 +0000
@@ -404,6 +404,15 @@ SELECT f1, f2 FROM t1 ORDER BY f2;
 DROP TRIGGER trg1;
 DROP TABLE t1;
 
+
+--echo #
+--echo # Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT
+--echo #   SAME USER VARIABLE = CRASH
+--echo #
+
+SET @bug12408412=1;
+SELECT GROUP_CONCAT(@bug12408412 ORDER BY 1) INTO @bug12408412;
+
 --echo End of 5.5 tests
 
 #

=== modified file 'mysys/my_handler_errors.h'
--- a/mysys/my_handler_errors.h	2011-12-09 21:08:37 +0000
+++ b/mysys/my_handler_errors.h	2012-03-09 13:40:32 +0000
@@ -1,7 +1,7 @@
 #ifndef MYSYS_MY_HANDLER_ERRORS_INCLUDED
 #define MYSYS_MY_HANDLER_ERRORS_INCLUDED
 
-/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,8 +13,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
 
 /*
   Errors a handler can give you
@@ -85,7 +85,8 @@ static const char *handler_error_message
   "Index column length exceeds limit",
   "Index corrupted",
   "Undo record too big",
-  "Invalid InnoDB FTS Doc ID"
+  "Invalid InnoDB FTS Doc ID",
+  "Table is being used in foreign key check"
 };
 
 extern void my_handler_error_register(void);

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2012-04-26 10:33:24 +0000
+++ b/sql/handler.cc	2012-05-09 16:47:39 +0000
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
 
 /** @file handler.cc
 
@@ -485,6 +485,7 @@ int ha_init_errors(void)
   SETMSG(HA_ERR_INDEX_COL_TOO_LONG,	ER_DEFAULT(ER_INDEX_COLUMN_TOO_LONG));
   SETMSG(HA_ERR_INDEX_CORRUPT,		ER_DEFAULT(ER_INDEX_CORRUPT));
   SETMSG(HA_FTS_INVALID_DOCID,		"Invalid InnoDB FTS Doc ID");
+  SETMSG(HA_ERR_TABLE_IN_FK_CHECK,	ER_DEFAULT(ER_TABLE_IN_FK_CHECK));
 
   /* Register the error messages for use with my_error(). */
   return my_error_register(get_handler_errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -3519,6 +3520,9 @@ void handler::print_error(int error, myf
   case HA_ERR_UNDO_REC_TOO_BIG:
     textno= ER_UNDO_RECORD_TOO_BIG;
     break;
+  case HA_ERR_TABLE_IN_FK_CHECK:
+    textno= ER_TABLE_IN_FK_CHECK;
+    break;
   default:
     {
       /* The error was "unknown" to this function.

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2012-05-07 08:29:18 +0000
+++ b/sql/item.cc	2012-05-09 16:47:39 +0000
@@ -8002,20 +8002,12 @@ bool Item_insert_value::fix_fields(THD *
   }
 
   if (arg->type() == REF_ITEM)
+    arg= static_cast<Item_ref *>(arg)->ref[0];
+  if (arg->type() != FIELD_ITEM)
   {
-    Item_ref *ref= (Item_ref *)arg;
-    if (ref->ref[0]->type() != FIELD_ITEM)
-    {
-      my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
-      return TRUE;
-    }
-    arg= ref->ref[0];
+    my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
+    return TRUE;
   }
-  /*
-    According to our SQL grammar, VALUES() function can reference
-    only to a column.
-  */
-  DBUG_ASSERT(arg->type() == FIELD_ITEM);
 
   Item_field *field_arg= (Item_field *)arg;
 

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2012-05-02 07:44:09 +0000
+++ b/sql/item_subselect.cc	2012-05-09 16:53:03 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2012-05-03 09:41:32 +0000
+++ b/sql/log_event.cc	2012-05-09 16:53:03 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -10548,9 +10548,24 @@ int Rows_log_event::do_apply_event(Relay
     {
       DBUG_PRINT("debug", ("Checking compability of tables to lock - tables_to_lock: %p",
                            rli->tables_to_lock));
+
+      /**
+        When using RBR and MyISAM MERGE tables the base tables that make
+        up the MERGE table can be appended to the list of tables to lock.
+  
+        Thus, we just check compatibility for those that tables that have
+        a correspondent table map event (ie, those that are actually going
+        to be accessed while applying the event). That's why the loop stops
+        at rli->tables_to_lock_count .
+
+        NOTE: The base tables are added here are removed when 
+              close_thread_tables is called.
+       */
       RPL_TABLE_LIST *ptr= rli->tables_to_lock;
-      for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))
+      for (uint i= 0 ; ptr && (i < rli->tables_to_lock_count);
+           ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++)
       {
+        DBUG_ASSERT(ptr->m_tabledef_valid);
         TABLE *conv_table;
         if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli),
                                              ptr->table, &conv_table))
@@ -10588,10 +10603,10 @@ int Rows_log_event::do_apply_event(Relay
       Rows_log_event, we can invalidate the query cache for the
       associated table.
      */
-    for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
-    {
+    TABLE_LIST *ptr= rli->tables_to_lock;
+    for (uint i=0 ;  ptr && (i < rli->tables_to_lock_count); ptr= ptr->next_global, i++)
       const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table);
-    }
+
 #ifdef HAVE_QUERY_CACHE
     query_cache.invalidate_locked_for_write(rli->tables_to_lock);
 #endif
@@ -11443,9 +11458,9 @@ check_table_map(Relay_log_info const *rl
     res= FILTERED_OUT;
   else
   {
-    for(RPL_TABLE_LIST *ptr= static_cast<RPL_TABLE_LIST*>(rli->tables_to_lock);
-        ptr; 
-        ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_local))
+    RPL_TABLE_LIST *ptr= static_cast<RPL_TABLE_LIST*>(rli->tables_to_lock);
+    for(uint i=0 ; ptr && (i< rli->tables_to_lock_count); 
+        ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_local), i++)
     {
       if (ptr->table_id == table_list->table_id)
       {

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2012-04-26 10:33:24 +0000
+++ b/sql/log_event_old.cc	2012-05-09 16:53:03 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -131,8 +131,10 @@ Old_rows_log_event::do_apply_event(Old_r
 
     {
       RPL_TABLE_LIST *ptr= rli->tables_to_lock;
-      for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))
+      for (uint i= 0 ; ptr&& (i< rli->tables_to_lock_count); 
+           ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++)
       {
+        DBUG_ASSERT(ptr->m_tabledef_valid);
         TABLE *conv_table;
         if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli),
                                              ptr->table, &conv_table))
@@ -163,10 +165,9 @@ Old_rows_log_event::do_apply_event(Old_r
       Old_rows_log_event, we can invalidate the query cache for the
       associated table.
      */
-    for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
-    {
+    TABLE_LIST *ptr= rli->tables_to_lock;
+    for (uint i=0; ptr && (i < rli->tables_to_lock_count); ptr= ptr->next_global, i++)
       const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table);
-    }
 #ifdef HAVE_QUERY_CACHE
     query_cache.invalidate_locked_for_write(rli->tables_to_lock);
 #endif
@@ -1541,7 +1542,8 @@ int Old_rows_log_event::do_apply_event(R
 
     {
       RPL_TABLE_LIST *ptr= rli->tables_to_lock;
-      for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global))
+      for (uint i= 0 ; ptr&& (i< rli->tables_to_lock_count);
+           ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++)
       {
         TABLE *conv_table;
         if (ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli),

=== modified file 'sql/password.c'
--- a/sql/password.c	2012-03-06 14:29:42 +0000
+++ b/sql/password.c	2012-05-09 16:53:03 +0000
@@ -537,7 +537,7 @@ check_scramble(const uchar *scramble_arg
   /* now buf supposedly contains hash_stage1: so we can get hash_stage2 */
   compute_sha1_hash(hash_stage2_reassured, (const char *) buf, SHA1_HASH_SIZE);
 
-  return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE);
+  return test(memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE));
 }
 
 

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2012-04-21 12:11:15 +0000
+++ b/sql/rpl_rli.cc	2012-05-09 16:53:03 +0000
@@ -1456,6 +1456,23 @@ void Relay_log_info::cleanup_context(THD
 
 void Relay_log_info::clear_tables_to_lock()
 {
+  DBUG_ENTER("Relay_log_info::clear_tables_to_lock()");
+#ifndef DBUG_OFF
+  /**
+    When replicating in RBR and MyISAM Merge tables are involved
+    open_and_lock_tables (called in do_apply_event) appends the 
+    base tables to the list of tables_to_lock. Then these are 
+    removed from the list in close_thread_tables (which is called 
+    before we reach this point).
+
+    This assertion just confirms that we get no surprises at this
+    point.
+   */
+  uint i=0;
+  for (TABLE_LIST *ptr= tables_to_lock ; ptr ; ptr= ptr->next_global, i++) ;
+  DBUG_ASSERT(i == tables_to_lock_count);
+#endif  
+
   while (tables_to_lock)
   {
     uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
@@ -1480,11 +1497,13 @@ void Relay_log_info::clear_tables_to_loc
     my_free(to_free);
   }
   DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0);
+  DBUG_VOID_RETURN;
 }
 
 void Relay_log_info::slave_close_thread_tables(THD *thd)
 {
   thd->get_stmt_da()->set_overwrite_status(true);
+  DBUG_ENTER("Relay_log_info::slave_close_thread_tables(THD *thd)");
   thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
   thd->get_stmt_da()->set_overwrite_status(false);
 
@@ -1505,6 +1524,7 @@ void Relay_log_info::slave_close_thread_
     thd->mdl_context.release_statement_locks();
 
   clear_tables_to_lock();
+  DBUG_VOID_RETURN;
 }
 /**
   Execute a SHOW RELAYLOG EVENTS statement.

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2012-05-03 08:11:43 +0000
+++ b/sql/share/errmsg-utf8.txt	2012-05-09 16:53:03 +0000
@@ -6499,6 +6499,9 @@ ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC
 ER_BINLOG_UNSAFE_INSERT_TWO_KEYS
   eng "INSERT... ON DUPLICATE KEY UPDATE  on a table with more than one UNIQUE KEY is unsafe"
 
+ER_TABLE_IN_FK_CHECK
+  eng "Table is being used in foreign key check."
+
 ER_UNSUPPORTED_ENGINE
   eng "Storage engine '%s' does not support system tables. [%s.%s]"
 
@@ -6509,10 +6512,6 @@ ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST
 #  End of 5.5 error messages.
 #
 
-ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
-  eng "Column count of %s.%s is wrong. Expected %d, found %d. The table is probably corrupted"
-  ger "Spaltenanzahl von %s.%s falsch. %d erwartet, aber %d gefunden. Tabelle ist wahrscheinlich besch��digt"
-
 ER_CANNOT_LOAD_FROM_TABLE_V2
   eng "Cannot load from %s.%s. The table is probably corrupted"
   ger "Kann %s.%s nicht einlesen. Tabelle ist wahrscheinlich besch��digt"
@@ -6751,10 +6750,16 @@ ER_UNKNOWN_ALTER_LOCK
 
 ER_MTS_CHANGE_MASTER_CANT_RUN_WITH_GAPS
   eng "CHANGE MASTER cannot be executed when the slave was stopped with an error or killed in MTS mode. Consider using RESET SLAVE or START SLAVE UNTIL."
+
 ER_MTS_RECOVERY_FAILURE
   eng "Cannot recover after SLAVE errored out in parallel execution mode. Additional error messages can be found in the MySQL error log."
 ER_MTS_RESET_WORKERS
   eng "Cannot clean up worker info tables. Additional error messages can be found in the MySQL error log."
+
+ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2
+  eng "Column count of %s.%s is wrong. Expected %d, found %d. The table is probably corrupted"
+  ger "Spaltenanzahl von %s.%s falsch. %d erwartet, aber %d gefunden. Tabelle ist wahrscheinlich besch��digt"
+
 #
 #  End of 5.6 error messages.
 #

=== modified file 'sql/spatial.cc'
--- a/sql/spatial.cc	2012-03-06 14:29:42 +0000
+++ b/sql/spatial.cc	2012-05-09 16:53:03 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -654,7 +654,8 @@ int Gis_line_string::is_closed(int *clos
     return 0;
   }
   data+= 4;
-  if (no_data(data, POINT_DATA_SIZE * n_points))
+  if (n_points == 0 ||
+      no_data(data, POINT_DATA_SIZE * n_points))
     return 1;
 
   /* Get first point */

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2012-05-03 09:41:32 +0000
+++ b/sql/sql_class.cc	2012-05-09 16:53:03 +0000
@@ -3055,13 +3055,42 @@ bool select_exists_subselect::send_data(
 int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
 {
   unit= u;
+  List_iterator_fast<my_var> var_li(var_list);
+  List_iterator_fast<Item> it(list);
+  Item *item;
+  my_var *mv;
+  Item_func_set_user_var **suv;
   
   if (var_list.elements != list.elements)
   {
     my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
                ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
     return 1;
-  }               
+  }
+
+  /*
+    Iterate over the destination variables and mark them as being
+    updated in this query.
+    We need to do this at JOIN::prepare time to ensure proper
+    const detection of Item_func_get_user_var that is determined
+    by the presence of Item_func_set_user_vars
+  */
+
+  suv= set_var_items= (Item_func_set_user_var **) 
+    sql_alloc(sizeof(Item_func_set_user_var *) * list.elements);
+
+  while ((mv= var_li++) && (item= it++))
+  {
+    if (!mv->local)
+    {
+      *suv= new Item_func_set_user_var(mv->s, item);
+      (*suv)->fix_fields(thd, 0);
+    }
+    else
+      *suv= NULL;
+    suv++;
+  }
+
   return 0;
 }
 
@@ -3378,6 +3407,7 @@ bool select_dumpvar::send_data(List<Item
   List_iterator<Item> it(items);
   Item *item;
   my_var *mv;
+  Item_func_set_user_var **suv;
   DBUG_ENTER("select_dumpvar::send_data");
 
   if (unit->offset_limit_cnt)
@@ -3390,20 +3420,19 @@ bool select_dumpvar::send_data(List<Item
     my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
     DBUG_RETURN(1);
   }
-  while ((mv= var_li++) && (item= it++))
+  for (suv= set_var_items; ((mv= var_li++) && (item= it++)); suv++)
   {
     if (mv->local)
     {
+      DBUG_ASSERT(!*suv);
       if (thd->sp_runtime_ctx->set_variable(thd, mv->offset, &item))
 	    DBUG_RETURN(1);
     }
     else
     {
-      Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
-      if (suv->fix_fields(thd, 0))
-        DBUG_RETURN (1);
-      suv->save_item_result(item);
-      if (suv->update())
+      DBUG_ASSERT(*suv);
+      (*suv)->save_item_result(item);
+      if ((*suv)->update())
         DBUG_RETURN (1);
     }
   }

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2012-05-03 09:41:32 +0000
+++ b/sql/sql_class.h	2012-05-09 16:53:03 +0000
@@ -4835,6 +4835,7 @@ public:
 
 class select_dumpvar :public select_result_interceptor {
   ha_rows row_count;
+  Item_func_set_user_var **set_var_items;
 public:
   List<my_var> var_list;
   select_dumpvar()  { var_list.empty(); row_count= 0;}

=== modified file 'sql/sql_planner.h'
--- a/sql/sql_planner.h	2012-03-22 08:17:51 +0000
+++ b/sql/sql_planner.h	2012-04-10 11:47:39 +0000
@@ -51,9 +51,7 @@ public:
     thd(thd), join(join),
     cur_embedding_map(0), emb_sjm_nest(sjm_nest),
     excluded_tables(sjm_nest ?
-                    (join->all_table_map & ~sjm_nest->sj_inner_tables) |
-                    OUTER_REF_TABLE_BIT :
-                    0)
+                    (join->all_table_map & ~sjm_nest->sj_inner_tables) : 0)
   {}
   ~Optimize_table_order()
   {}

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2012-04-30 10:06:23 +0000
+++ b/sql/sql_select.cc	2012-05-09 16:53:03 +0000
@@ -1268,7 +1268,8 @@ bool JOIN::set_access_methods()
       */
       const table_map available_tables=
         sj_is_materialize_strategy(tab->get_sj_strategy()) ?
-          used_tables & tab->emb_sj_nest->sj_inner_tables : used_tables;
+        (used_tables & tab->emb_sj_nest->sj_inner_tables) |
+        OUTER_REF_TABLE_BIT : used_tables;
       if (create_ref_for_key(this, tab, keyuse, available_tables))
         DBUG_RETURN(true);
     }
@@ -1396,6 +1397,7 @@ bool create_ref_for_key(JOIN *join, JOIN
       }
       keyuse++;
     } while (keyuse->table == table && keyuse->key == key);
+    DBUG_ASSERT(length > 0 && keyparts != 0);
   } /* not ftkey */
 
   /* set up fieldref */
@@ -3719,6 +3721,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
   LINT_INIT(ref_key_parts);
   LINT_INIT(orig_cond);
 
+  /* Check that we are always called with first non-const table */
+  DBUG_ASSERT(tab == tab->join->join_tab + tab->join->const_tables); 
+
   Plan_change_watchdog watchdog(tab, no_changes);
 
   /* Sorting a single row can always be skipped */
@@ -3973,7 +3978,8 @@ check_reverse_order:                  
         keyuse++;
 
       if (create_ref_for_key(tab->join, tab, keyuse, 
-                             tab->join->const_table_map))
+                             tab->join->const_table_map |
+                             OUTER_REF_TABLE_BIT))
         goto use_filesort;
 
       DBUG_ASSERT(tab->type != JT_REF_OR_NULL && tab->type != JT_FT);

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2012-03-06 14:29:42 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2012-05-09 16:53:03 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -153,6 +153,7 @@ int ha_blackhole::rnd_next(uchar *buf)
   else
     rc= HA_ERR_END_OF_FILE;
   MYSQL_READ_ROW_DONE(rc);
+  table->status= rc ? STATUS_NOT_FOUND : 0;
   DBUG_RETURN(rc);
 }
 
@@ -243,6 +244,7 @@ int ha_blackhole::index_read_map(uchar *
   else
     rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= rc ? STATUS_NOT_FOUND : 0;
   DBUG_RETURN(rc);
 }
 
@@ -260,6 +262,7 @@ int ha_blackhole::index_read_idx_map(uch
   else
     rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= rc ? STATUS_NOT_FOUND : 0;
   DBUG_RETURN(rc);
 }
 
@@ -276,6 +279,7 @@ int ha_blackhole::index_read_last_map(uc
   else
     rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= rc ? STATUS_NOT_FOUND : 0;
   DBUG_RETURN(rc);
 }
 
@@ -287,6 +291,7 @@ int ha_blackhole::index_next(uchar * buf
   MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
   rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= STATUS_NOT_FOUND;
   DBUG_RETURN(rc);
 }
 
@@ -298,6 +303,7 @@ int ha_blackhole::index_prev(uchar * buf
   MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
   rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= STATUS_NOT_FOUND;
   DBUG_RETURN(rc);
 }
 
@@ -309,8 +315,8 @@ int ha_blackhole::index_first(uchar * bu
   MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
   rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= STATUS_NOT_FOUND;
   DBUG_RETURN(rc);
-  DBUG_RETURN(HA_ERR_END_OF_FILE);
 }
 
 
@@ -321,6 +327,7 @@ int ha_blackhole::index_last(uchar * buf
   MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
   rc= HA_ERR_END_OF_FILE;
   MYSQL_INDEX_READ_ROW_DONE(rc);
+  table->status= STATUS_NOT_FOUND;
   DBUG_RETURN(rc);
 }
 

=== modified file 'storage/innobase/dict/dict0dict.cc'
--- a/storage/innobase/dict/dict0dict.cc	2012-04-27 16:39:02 +0000
+++ b/storage/innobase/dict/dict0dict.cc	2012-05-09 16:47:39 +0000
@@ -67,6 +67,10 @@ UNIV_INTERN dict_index_t*	dict_ind_compa
 #include "row0merge.h"
 #include "row0log.h"
 #include "ut0ut.h" /* ut_format_name() */
+#include "m_string.h"
+#include "my_sys.h"
+
+#include <ctype.h>
 
 /** the dictionary system */
 UNIV_INTERN dict_sys_t*	dict_sys	= NULL;
@@ -2949,6 +2953,8 @@ dict_foreign_free(
 /*==============*/
 	dict_foreign_t*	foreign)	/*!< in, own: foreign key struct */
 {
+	ut_a(foreign->foreign_table->n_foreign_key_checks_running == 0);
+
 	mem_heap_free(foreign->heap);
 }
 

=== modified file 'storage/innobase/dict/dict0stats.cc'
--- a/storage/innobase/dict/dict0stats.cc	2012-05-04 16:41:23 +0000
+++ b/storage/innobase/dict/dict0stats.cc	2012-05-09 16:47:39 +0000
@@ -322,10 +322,10 @@ dict_stats_persistent_storage_check(
 	/* definition for the table TABLE_STATS_NAME */
 	dict_col_meta_t	table_stats_columns[] = {
 		{"database_name", DATA_VARMYSQL,
-			DATA_NOT_NULL, MAX_DATABASE_NAME_LEN},
+			DATA_NOT_NULL, 192},
 
 		{"table_name", DATA_VARMYSQL,
-			DATA_NOT_NULL, MAX_TABLE_NAME_LEN},
+			DATA_NOT_NULL, 192},
 
 		{"last_update", DATA_FIXBINARY,
 			DATA_NOT_NULL, 4},
@@ -348,13 +348,13 @@ dict_stats_persistent_storage_check(
 	/* definition for the table INDEX_STATS_NAME */
 	dict_col_meta_t	index_stats_columns[] = {
 		{"database_name", DATA_VARMYSQL,
-			DATA_NOT_NULL, MAX_DATABASE_NAME_LEN},
+			DATA_NOT_NULL, 192},
 
 		{"table_name", DATA_VARMYSQL,
-			DATA_NOT_NULL, MAX_TABLE_NAME_LEN},
+			DATA_NOT_NULL, 192},
 
 		{"index_name", DATA_VARMYSQL,
-			DATA_NOT_NULL, MAX_TABLE_NAME_LEN},
+			DATA_NOT_NULL, 192},
 
 		{"last_update", DATA_FIXBINARY,
 			DATA_NOT_NULL, 4},

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2012-05-04 00:07:22 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2012-05-09 16:53:03 +0000
@@ -1345,6 +1345,9 @@ convert_error_code_to_mysql(
 	case DB_OUT_OF_FILE_SPACE:
 		return(HA_ERR_RECORD_FILE_FULL);
 
+	case DB_TABLE_IN_FK_CHECK:
+		return(HA_ERR_TABLE_IN_FK_CHECK);
+
 	case DB_TABLE_IS_BEING_USED:
 		return(HA_ERR_WRONG_COMMAND);
 
@@ -7148,6 +7151,7 @@ ha_innobase::index_read(
 	DBUG_ENTER("index_read");
 
 	ut_a(prebuilt->trx == thd_to_trx(user_thd));
+	ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT);
 
 	ha_statistic_increment(&SSV::ha_read_key_count);
 
@@ -9539,6 +9543,8 @@ innobase_rename_table(
 	normalize_table_name(norm_to, to);
 	normalize_table_name(norm_from, from);
 
+	DEBUG_SYNC_C("innodb_rename_table_ready");
+
 	/* Serialize data dictionary operations with dictionary mutex:
 	no deadlocks can occur then in these operations */
 

=== modified file 'storage/innobase/include/db0err.h'
--- a/storage/innobase/include/db0err.h	2012-04-11 10:25:07 +0000
+++ b/storage/innobase/include/db0err.h	2012-04-12 11:13:43 +0000
@@ -114,7 +114,9 @@ enum dberr_t {
 	DB_UNDO_RECORD_TOO_BIG,		/*!< the undo log record is too big */
 	DB_READ_ONLY,			/*!< Update operation attempted in
 					a read-only transaction */
-	DB_FTS_INVALID_DOCID,		/*!< FTS Doc ID cannot be zero */
+	DB_FTS_INVALID_DOCID,		/* FTS Doc ID cannot be zero */
+	DB_TABLE_IN_FK_CHECK,		/* table is being used in foreign
+					key check */
 	DB_ONLINE_LOG_TOO_BIG,		/*!< Modification log grew too big
 					during online index creation */
 

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	2012-05-04 00:07:22 +0000
+++ b/storage/innobase/include/univ.i	2012-05-09 16:47:39 +0000
@@ -380,11 +380,16 @@ This number varies depending on UNIV_PAG
 /** Maximum number of parallel threads in a parallelized operation */
 #define UNIV_MAX_PARALLELISM	32
 
-/** The maximum length of a table name. This is the MySQL limit and is
-defined in mysql_com.h like NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN, the
-number does not include a terminating '\0'. InnoDB probably can handle
-longer names internally */
-#define MAX_TABLE_NAME_LEN	192
+/** This is the "mbmaxlen" for my_charset_filename (defined in
+strings/ctype-utf8.c), which is used to encode File and Database names. */
+#define FILENAME_CHARSET_MAXNAMLEN	5
+
+/** The maximum length of an encode table name in bytes.  The max
+table and database names are NAME_CHAR_LEN (64) characters. After the
+encoding, the max length would be NAME_CHAR_LEN (64) *
+FILENAME_CHARSET_MAXNAMLEN (5) = 320 bytes. The number does not include a
+terminating '\0'. InnoDB can handle longer names internally */
+#define MAX_TABLE_NAME_LEN	320
 
 /** The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is
 the MySQL's NAME_LEN, see check_and_convert_db_name(). */

=== modified file 'storage/innobase/row/row0ins.cc'
--- a/storage/innobase/row/row0ins.cc	2012-04-26 10:13:37 +0000
+++ b/storage/innobase/row/row0ins.cc	2012-05-09 16:47:39 +0000
@@ -51,6 +51,8 @@ Created 4/20/1996 Heikki Tuuri
 #include "buf0lru.h"
 #include "fts0fts.h"
 #include "fts0types.h"
+#include "m_string.h"
+#include "my_sys.h"
 
 /*************************************************************************
 IMPORTANT NOTE: Any operation that generates redo MUST check that there
@@ -1256,6 +1258,9 @@ row_ins_foreign_check_on_constraint(
 	release the latch. */
 
 	row_mysql_unfreeze_data_dictionary(thr_get_trx(thr));
+
+	DEBUG_SYNC_C("innodb_dml_cascade_dict_unfreeze");
+
 	row_mysql_freeze_data_dictionary(thr_get_trx(thr));
 
 	mtr_start(mtr);

=== modified file 'storage/innobase/row/row0mysql.cc'
--- a/storage/innobase/row/row0mysql.cc	2012-05-04 00:07:22 +0000
+++ b/storage/innobase/row/row0mysql.cc	2012-05-09 16:47:39 +0000
@@ -57,6 +57,8 @@ Created 9/17/2000 Heikki Tuuri
 #include "ibuf0ibuf.h"
 #include "fts0fts.h"
 #include "fts0types.h"
+#include "m_string.h"
+#include "my_sys.h"
 
 /** Provide optional 4.x backwards compatibility for 5.0 and above */
 UNIV_INTERN ibool	row_rollback_on_timeout	= FALSE;
@@ -1644,6 +1646,8 @@ row_update_for_mysql(
 		return(DB_ERROR);
 	}
 
+	DEBUG_SYNC_C("innodb_row_update_for_mysql_begin");
+
 	trx->op_info = "updating or deleting";
 
 	row_mysql_delay_if_needed();
@@ -4296,6 +4300,7 @@ row_rename_table_for_mysql(
 	ulint		n_constraints_to_drop	= 0;
 	ibool		old_is_tmp, new_is_tmp;
 	pars_info_t*	info			= NULL;
+	int		retry;
 
 	ut_a(old_name != NULL);
 	ut_a(new_name != NULL);
@@ -4380,6 +4385,25 @@ row_rename_table_for_mysql(
 		}
 	}
 
+	/* Is a foreign key check running on this table? */
+	for (retry = 0; retry < 100
+	     && table->n_foreign_key_checks_running > 0; ++retry) {
+		row_mysql_unlock_data_dictionary(trx);
+		os_thread_yield();
+		row_mysql_lock_data_dictionary(trx);
+	}
+
+	if (table->n_foreign_key_checks_running > 0) {
+		ut_print_timestamp(stderr);
+		fputs(" InnoDB: Error: in ALTER TABLE ", stderr);
+		ut_print_name(stderr, trx, TRUE, old_name);
+		fprintf(stderr, "\n"
+			"InnoDB: a FOREIGN KEY check is running.\n"
+			"InnoDB: Cannot rename table.\n");
+		err = DB_TABLE_IN_FK_CHECK;
+		goto funct_exit;
+	}
+
 	/* We use the private SQL parser of Innobase to generate the query
 	graphs needed in updating the dictionary data from system tables. */
 

=== modified file 'storage/innobase/ut/ut0ut.cc'
--- a/storage/innobase/ut/ut0ut.cc	2012-04-24 06:21:11 +0000
+++ b/storage/innobase/ut/ut0ut.cc	2012-05-09 16:47:39 +0000
@@ -789,6 +789,8 @@ ut_strerr(
 		return("Undo record too big");
 	case DB_END_OF_INDEX:
 		return("End of index");
+	case DB_TABLE_IN_FK_CHECK:
+		return("Table is being used in foreign key check");
 	case DB_DATA_MISMATCH:
 		return("data mismatch");
 	case DB_SCHEMA_NOT_LOCKED:

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (Georgi.Kodinov:3809) Georgi Kodinov11 Jun