List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:December 2 2010 8:09am
Subject:bzr push into mysql-trunk-bugfixing branch (Dmitry.Lenev:3394 to 3395)
View as plain text  
 3395 Dmitry Lenev	2010-12-02 [merge]
      Merged recent changes from mysql-trunk-bugfixing
      into work-in-progress tree.

    added:
      mysql-test/suite/federated/federated_bug_35333.result
      mysql-test/suite/federated/federated_bug_35333.test
      mysql-test/suite/perfschema/r/dml_threads.result
      mysql-test/suite/perfschema/r/thread_cache.result
      mysql-test/suite/perfschema/t/dml_threads.test
      mysql-test/suite/perfschema/t/thread_cache.test
      mysql-test/suite/rpl/r/rpl_slave_start.result
      mysql-test/suite/rpl/t/rpl_slave_start.test
    modified:
      BUILD/build_mccge.sh
      CMakeLists.txt
      client/mysqltest.cc
      config.h.cmake
      include/atomic/x86-gcc.h
      include/my_stacktrace.h
      mysql-test/r/lock_multi.result
      mysql-test/r/mdl_sync.result
      mysql-test/r/merge.result
      mysql-test/r/mysql.result
      mysql-test/r/show_check.result
      mysql-test/r/variables.result
      mysql-test/r/view.result
      mysql-test/suite/perfschema/include/privilege.inc
      mysql-test/suite/perfschema/r/dml_cond_instances.result
      mysql-test/suite/perfschema/r/dml_ews_by_instance.result
      mysql-test/suite/perfschema/r/dml_ews_by_thread_by_event_name.result
      mysql-test/suite/perfschema/r/dml_ews_global_by_event_name.result
      mysql-test/suite/perfschema/r/dml_file_instances.result
      mysql-test/suite/perfschema/r/dml_file_summary_by_event_name.result
      mysql-test/suite/perfschema/r/dml_file_summary_by_instance.result
      mysql-test/suite/perfschema/r/dml_mutex_instances.result
      mysql-test/suite/perfschema/r/dml_rwlock_instances.result
      mysql-test/suite/perfschema/r/misc.result
      mysql-test/suite/perfschema/r/myisam_file_io.result
      mysql-test/suite/perfschema/r/privilege.result
      mysql-test/suite/perfschema/t/dml_cond_instances.test
      mysql-test/suite/perfschema/t/dml_ews_by_instance.test
      mysql-test/suite/perfschema/t/dml_ews_by_thread_by_event_name.test
      mysql-test/suite/perfschema/t/dml_ews_global_by_event_name.test
      mysql-test/suite/perfschema/t/dml_file_instances.test
      mysql-test/suite/perfschema/t/dml_file_summary_by_event_name.test
      mysql-test/suite/perfschema/t/dml_file_summary_by_instance.test
      mysql-test/suite/perfschema/t/dml_mutex_instances.test
      mysql-test/suite/perfschema/t/dml_rwlock_instances.test
      mysql-test/suite/perfschema/t/misc.test
      mysql-test/suite/perfschema/t/myisam_file_io.test
      mysql-test/suite/rpl/r/rpl_slave_status.result
      mysql-test/suite/rpl/t/rpl_checksum.test
      mysql-test/suite/rpl/t/rpl_slave_status.test
      mysql-test/t/mysql.test
      mysql-test/t/mysqld--defaults-file.test
      mysql-test/t/variables.test
      mysys/stacktrace.c
      sql/CMakeLists.txt
      sql/binlog.cc
      sql/event_data_objects.cc
      sql/event_data_objects.h
      sql/event_db_repository.cc
      sql/ha_partition.cc
      sql/item.cc
      sql/item_cmpfunc.cc
      sql/item_timefunc.h
      sql/log_event.cc
      sql/log_event.h
      sql/mysqld.cc
      sql/opt_range.cc
      sql/partition_info.cc
      sql/rpl_mi.cc
      sql/rpl_mi.h
      sql/rpl_slave.cc
      sql/set_var.h
      sql/sp.cc
      sql/sp.h
      sql/sp_head.cc
      sql/sp_head.h
      sql/sql_acl.cc
      sql/sql_cache.cc
      sql/sql_cache.h
      sql/sql_class.h
      sql/sql_insert.cc
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_show.cc
      sql/sql_table.cc
      sql/sql_trigger.cc
      sql/sql_trigger.h
      sql/sql_view.cc
      sql/sys_vars.cc
      storage/perfschema/ha_perfschema.cc
      storage/perfschema/ha_perfschema.h
      storage/perfschema/pfs_engine_table.cc
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr_class.cc
      storage/perfschema/pfs_instr_class.h
      storage/perfschema/table_setup_actors.cc
      storage/perfschema/table_setup_consumers.cc
      storage/perfschema/table_setup_instruments.cc
      storage/perfschema/table_setup_timers.cc
      storage/perfschema/table_threads.cc
 3394 Dmitry Lenev	2010-12-02
      Prerequisite patch for Bug#27480 (Extend CREATE TEMPORARY TABLES
      privilege to allow temp table operations).
      
      Review fixes in progress. Streamline handling of temporary tables
      for prelocking list elements.

    modified:
      sql/sp_head.cc
      sql/sql_base.cc
      sql/sql_prepare.cc
      sql/sql_view.cc
=== modified file 'BUILD/build_mccge.sh'
--- a/BUILD/build_mccge.sh	2010-09-27 11:37:21 +0000
+++ b/BUILD/build_mccge.sh	2010-12-01 12:44:00 +0000
@@ -42,9 +42,7 @@ cat <<EOF
   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, and the default build behaviour is to build with
-  autotools. If you want to skip autotools and start from a source code
-  release you can use the --no-autotools flag.
+  Extended Edition.
 
   More information for developers can be found in --help, 
   --sysadmin-help, and --extended-help.
@@ -102,7 +100,8 @@ cat <<EOF
   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.
+  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.
@@ -150,14 +149,32 @@ Usage: $0 [options]
   --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.
-  --use-autotools         Start by running autoconf, automake,.. tools
-  --no-autotools          Start from configure
   --print-only            Print commands that the script will execute, 
                           but do not actually execute
   --prefix=path           Build with prefix 'path'
@@ -170,7 +187,7 @@ Usage: $0 [options]
                           MySQL use
   --commercial            Use commercial libraries
   --gpl                   Use gpl libraries
-  --compiler=[gcc|icc|forte|SunStudio]        Select compiler
+  --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
@@ -389,7 +406,8 @@ extended_usage()
     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).
+    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.
 
@@ -397,10 +415,35 @@ extended_usage()
     by calling the script as follows:
     CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh
 
-  FreeBSD/x86/gcc
-  ---------------
-    No flags are used. Instead, configure determines the proper flags to 
-    use.
+  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
   -------------
@@ -410,6 +453,9 @@ extended_usage()
     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:
@@ -433,6 +479,19 @@ extended_usage()
     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
@@ -653,6 +712,9 @@ parse_compiler()
     forte | SunStudio | sunstudio )
       compiler="forte"
       ;;
+    open64 | Open64 )
+      compiler="open64"
+      ;;
     *)
       echo "Unknown compiler '$compiler'"
       exit 1
@@ -686,6 +748,15 @@ parse_options()
     --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"
       ;;
@@ -693,6 +764,10 @@ parse_options()
       with_debug_flag="yes"
       fast_flag="no"
       ;;
+    --extra-debug-flag)
+      shift
+      extra_debug_flags="$extra_debug_flags -D$1"
+      ;;
     --debug)
       compile_debug_flag="yes"
       ;;
@@ -712,6 +787,14 @@ parse_options()
       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
@@ -746,12 +829,6 @@ parse_options()
     --parallelism=*)
       parallelism=`get_key_value "$1"`
       ;;
-    --use-autotools)
-      use_autotools="yes"
-      ;;
-    --no-autotools)
-      use_autotools="no"
-      ;;
     --configure-only)
       just_configure="yes"
       ;;
@@ -896,6 +973,9 @@ set_cpu_base()
 # 
 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"
@@ -1084,6 +1164,7 @@ set_with_debug_flags()
       loc_debug_flags="-DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS "
       compiler_flags="$compiler_flags $loc_debug_flags"
     fi
+    compiler_flags="$compiler_flags $extra_debug_flags"
   fi
 }
 
@@ -1105,7 +1186,7 @@ set_no_omit_frame_pointer_for_developers
 #
 set_debug_flag()
 {
-  if test "x$compile_debug_flags" = "xyes" ; then
+  if test "x$compile_debug_flag" = "xyes" ; then
     compiler_flags="$compiler_flags -g"
   fi
 }
@@ -1152,7 +1233,9 @@ set_base_configs()
   fi
   base_configs="$base_configs --with-pic"
   base_configs="$base_configs --with-csv-storage-engine"
-  base_configs="$base_configs --with-perfschema"
+  if test "x$with_perfschema" != "xno" ; then
+    base_configs="$base_configs --with-perfschema"
+  fi
 }
 
 #
@@ -1251,6 +1334,19 @@ set_gcc_special_options()
   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
@@ -1271,26 +1367,23 @@ set_cc_and_cxx_for_icc()
   fi
 }
 
-set_cc_and_cxx_for_forte()
+set_cc_and_cxx_for_open64()
 {
   if test "x$CC" = "x" ; then
-    CC="cc"
+    CC="opencc -static-libgcc -fno-exceptions"
   fi
   if test "x$CXX" = "x" ; then
-    CXX="CC"
+    CXX="openCC -static-libgcc -fno-exceptions"
   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()
+set_cc_and_cxx_for_forte()
 {
-  if test "x$fast_flag" = "xyes" && test "x$cpu_arg" = "xcore2" && \
-     test "x$compiler" = "xicc" ; then
-    compiler_flags="$compiler_flags -xT"
+  if test "x$CC" = "x" ; then
+    CC="cc"
+  fi
+  if test "x$CXX" = "x" ; then
+    CXX="CC"
   fi
 }
 
@@ -1358,11 +1451,44 @@ get_gcc_version()
 }
 
 #
+# 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_link_time_optimizer()
+check_for_gcc_link_time_optimizer()
 {
   get_gcc_version
   if test "$gcc_version" -ge 405 && \
@@ -1371,11 +1497,37 @@ check_for_link_time_optimizer()
     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"
@@ -1392,19 +1544,14 @@ set_linux_configs()
     if test "x$fast_flag" != "xno" ; then
       if test "x$fast_flag" = "xyes" ; then
         compiler_flags="$compiler_flags -O3"
-        check_for_link_time_optimizer
+        check_for_gcc_link_time_optimizer
       else
-        compiler_flags="$compiler_flags -O2"
+        compiler_flags="$compiler_flags -O3"
       fi
     else
       compiler_flags="$compiler_flags -O0"
     fi
-    check_64_bits
-    if test "x$m64" = "xyes" ; then
-      compiler_flags="$compiler_flags -m64"
-    else
-      compiler_flags="$compiler_flags -m32"
-    fi
+    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"
@@ -1414,16 +1561,36 @@ set_linux_configs()
     fi
     if test "x$fast_flag" != "xno" ; then
       compiler_flags="$compiler_flags -O3 -unroll2 -ip"
-      if test "x$fast_flag" = "xyes" && \
-         test "x$with_link_time_optimizer" = "xyes" ; then
-        compiler_flags="$compiler_flags -ipo"
-        LDFLAGS="$LDFLAGS -ipo"
+      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 and icc compilers supported for Linux"
+    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
 }
 
 #
@@ -1475,7 +1642,7 @@ set_solaris_configs()
     if test "x$fast_flag" = "xyes" ; then
       LDFLAGS="$LDFLAGS -O3"
       compiler_flags="$compiler_flags -O3"
-      check_for_link_time_optimizer
+      check_for_gcc_link_time_optimizer
     else
       if test "x$fast_flag" = "xgeneric" ; then
         LDFLAGS="$LDFLAGS -O2"
@@ -1498,10 +1665,7 @@ set_solaris_configs()
     if test "x$fast_flag" = "xyes" ; then
       compiler_flags="$compiler_flags -xtarget=native"
       compiler_flags="$compiler_flags -xunroll=3"
-      if test "x$with_link_time_optimizer" = "xyes" ; then
-        compiler_flags="$compiler_flags -xipo"
-        LDFLAGS="$LDFLAGS -xipo"
-      fi
+      check_for_forte_link_time_optimizer
     else
       compiler_flags="$compiler_flags -xtarget=generic"
     fi
@@ -1612,17 +1776,6 @@ set_default_package()
   fi
 }
 
-set_autotool_flags()
-{
-  if test "x$use_autotools" = "x" ; then
-    if test "x$developer_flag" = "xno" ; then
-      use_autotools="no"
-    else
-      use_autotools="yes"
-    fi
-  fi
-}
-
 set_defaults_based_on_environment()
 {
   if test ! -z "$MYSQL_DEVELOPER" ; then
@@ -1674,25 +1827,28 @@ base_cxxflags=
 base_configs=
 debug_flags=
 cxxflags=
+extra_debug_flags=
 m64=
 explicit_size_set=
 datadir=
 commands=
-use_autotools=
 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_autotool_flags
 set_default_package
 
 set -e
@@ -1793,9 +1949,6 @@ set_ccache_usage
 # Set up commands variable from variables prepared for base 
 # configurations, compiler flags, and warnings flags.
 # 
-if test "x$use_autotools" = "xyes" ; then
-  init_auto_commands
-fi
 init_configure_commands
 
 if test "x$just_configure" != "xyes" ; then
@@ -1806,8 +1959,8 @@ fi
 # The commands variable now contains the entire command to be run for
 # the build; we either execute it, or merely print it out.
 #
-if test "x$just_print" = "xyes" ; then
-  echo "$commands"
-else
+echo "Running command:"
+echo "$commands"
+if test "x$just_print" != "xyes" ; then
   eval "set -x; $commands"
 fi

=== modified file 'CMakeLists.txt'
--- a/CMakeLists.txt	2010-11-24 10:35:06 +0000
+++ b/CMakeLists.txt	2010-11-30 09:59:23 +0000
@@ -268,6 +268,14 @@ IF(MYSQL_MAINTAINER_MODE)
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_MAINTAINER_CXX_WARNINGS}")
 ENDIF()
 
+IF(CMAKE_COMPILER_IS_GNUCXX)
+  STRING(REGEX MATCH "-Werror"
+    BUILD_WITH_WERROR ${CMAKE_CXX_FLAGS})
+  IF(BUILD_WITH_WERROR)
+    SET("COMPILE_FLAG_WERROR" 1)
+  ENDIF()
+ENDIF()
+
 IF(WITH_UNIT_TESTS)
  ENABLE_TESTING()
 ENDIF()

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2010-11-27 12:22:17 +0000
+++ b/client/mysqltest.cc	2010-11-30 19:09:11 +0000
@@ -8110,13 +8110,16 @@ static void dump_backtrace(void)
 {
   struct st_connection *conn= cur_con;
 
-  my_safe_print_str("read_command_buf", read_command_buf,
-                    sizeof(read_command_buf));
+  fprintf(stderr, "read_command_buf (%p): ", read_command_buf);
+  my_safe_print_str(read_command_buf, sizeof(read_command_buf));
+
   if (conn)
   {
-    my_safe_print_str("conn->name", conn->name, conn->name_len);
+    fprintf(stderr, "conn->name (%p): ", conn->name);
+    my_safe_print_str(conn->name, conn->name_len);
 #ifdef EMBEDDED_LIBRARY
-    my_safe_print_str("conn->cur_query", conn->cur_query, conn->cur_query_len);
+    fprintf(stderr, "conn->cur_query (%p): ", conn->cur_query);
+    my_safe_print_str(conn->cur_query, conn->cur_query_len);
 #endif
   }
   fputs("Attempting backtrace...\n", stderr);

=== modified file 'config.h.cmake'
--- a/config.h.cmake	2010-10-04 15:25:10 +0000
+++ b/config.h.cmake	2010-11-30 09:59:23 +0000
@@ -569,7 +569,7 @@
 #cmakedefine HAVE_CHARSET_utf32 1
 #cmakedefine HAVE_UCA_COLLATIONS 1
 #cmakedefine HAVE_COMPRESS 1
-
+#cmakedefine COMPILE_FLAG_WERROR 1
 
 /*
   Stuff that always need to be defined (compile breaks without it)

=== modified file 'include/atomic/x86-gcc.h'
--- a/include/atomic/x86-gcc.h	2010-09-17 20:34:15 +0000
+++ b/include/atomic/x86-gcc.h	2010-11-30 23:19:49 +0000
@@ -78,15 +78,15 @@
                 : "memory")
 
 /*
-  Actually 32-bit reads/writes are always atomic on x86
-  But we add LOCK_prefix here anyway to force memory barriers
+  Actually 32/64-bit reads/writes are always atomic on x86_64,
+  nonetheless issue memory barriers as appropriate.
 */
 #define make_atomic_load_body(S)                                \
-  ret=0;                                                        \
-  asm volatile (LOCK_prefix "; cmpxchg %2, %0"                  \
-                : "=m" (*a), "=a" (ret)                         \
-                : "r" (ret), "m" (*a)                           \
-                : "memory")
+  /* Serialize prior load and store operations. */              \
+  asm volatile ("mfence" ::: "memory");                         \
+  ret= *a;                                                      \
+  /* Prevent compiler from reordering instructions. */          \
+  asm volatile ("" ::: "memory")
 #define make_atomic_store_body(S)                               \
   asm volatile ("; xchg %0, %1;"                                \
                 : "=m" (*a), "+r" (v)                           \

=== modified file 'include/my_stacktrace.h'
--- a/include/my_stacktrace.h	2010-07-15 11:13:30 +0000
+++ b/include/my_stacktrace.h	2010-11-30 19:06:53 +0000
@@ -45,7 +45,7 @@ C_MODE_START
 #if defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)
 void my_init_stacktrace();
 void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack);
-void my_safe_print_str(const char* name, const char* val, int max_len);
+void my_safe_print_str(const char* val, int max_len);
 void my_write_core(int sig);
 #if BACKTRACE_DEMANGLE
 char *my_demangle(const char *mangled_name, int *status);

=== modified file 'mysql-test/r/lock_multi.result'
--- a/mysql-test/r/lock_multi.result	2010-02-26 12:40:25 +0000
+++ b/mysql-test/r/lock_multi.result	2010-11-30 17:55:36 +0000
@@ -430,6 +430,8 @@ SELECT table_name, table_comment FROM in
 WHERE table_schema= 'test' AND table_name= 't1';
 table_name	table_comment
 t1	Lock wait timeout exceeded; try restarting transaction
+Warnings:
+Warning	1205	Lock wait timeout exceeded; try restarting transaction
 # Connection default
 UNLOCK TABLES;
 # Connection con3

=== modified file 'mysql-test/r/mdl_sync.result'
--- a/mysql-test/r/mdl_sync.result	2010-11-18 16:34:56 +0000
+++ b/mysql-test/r/mdl_sync.result	2010-11-30 17:55:36 +0000
@@ -2322,6 +2322,8 @@ select table_name, table_type, auto_incr
 from information_schema.tables where table_schema='test' and table_name='t2';
 table_name	table_type	auto_increment	table_comment
 t2	BASE TABLE	NULL	Table 'test'.'t2' was skipped since its definition is being modified by concurrent DDL statement
+Warnings:
+Warning	1684	Table 'test'.'t2' was skipped since its definition is being modified by concurrent DDL statement
 # Switching to connection 'default'.
 unlock tables;
 # Switching to connection 'con46044'.

=== modified file 'mysql-test/r/merge.result'
--- a/mysql-test/r/merge.result	2010-11-29 14:13:07 +0000
+++ b/mysql-test/r/merge.result	2010-12-02 08:07:11 +0000
@@ -2084,6 +2084,8 @@ SELECT * FROM INFORMATION_SCHEMA.TABLES 
 TABLE_SCHEMA = 'test' and TABLE_NAME='tm1';
 TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	VERSION	ROW_FORMAT	TABLE_ROWS	AVG_ROW_LENGTH	DATA_LENGTH	MAX_DATA_LENGTH	INDEX_LENGTH	DATA_FREE	AUTO_INCREMENT	CREATE_TIME	UPDATE_TIME	CHECK_TIME	TABLE_COLLATION	CHECKSUM	CREATE_OPTIONS	TABLE_COMMENT
 def	test	tm1	BASE TABLE	NULL	NULL	NULL	#	#	#	#	#	#	#	#	#	#	NULL	#	#	Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+Warnings:
+Warning	1168	Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
 DROP TABLE tm1;
 CREATE TABLE t1(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM;
 CREATE TABLE t2(C1 INT, C2 INT, KEY C1(C1), KEY C2(C2)) ENGINE=MYISAM;

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2010-11-26 14:37:59 +0000
+++ b/mysql-test/r/mysql.result	2010-12-01 07:01:44 +0000
@@ -492,17 +492,15 @@ Tables_in_test
 # Checking --one-database option with non_existent_db 
 # specified with USE command
 #
-SHOW TABLES IN test;
-Tables_in_test
-table_in_test
-DROP DATABASE test;
+CREATE DATABASE connected_db;
+SHOW TABLES IN connected_db;
+Tables_in_connected_db
+table_in_connected_db
 
-CREATE DATABASE test;
-SHOW TABLES IN test;
-Tables_in_test
-table_in_test
-DROP DATABASE test;
-CREATE DATABASE test;
+SHOW TABLES IN connected_db;
+Tables_in_connected_db
+table_in_connected_db
+DROP DATABASE connected_db;
 
 End of tests
 Connected

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2010-11-19 05:47:50 +0000
+++ b/mysql-test/r/show_check.result	2010-11-30 17:55:36 +0000
@@ -663,6 +663,8 @@ flush tables;
 SHOW TABLE STATUS like 't1';
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
 t1	NULL	NULL	NULL	NULL	#	#	#	#	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Incorrect information in file: './test/t1.frm'
+Warnings:
+Warning	1033	Incorrect information in file: './test/t1.frm'
 show create table t1;
 ERROR HY000: Incorrect information in file: './test/t1.frm'
 drop table if exists t1;

=== modified file 'mysql-test/r/variables.result'
--- a/mysql-test/r/variables.result	2010-11-25 04:41:58 +0000
+++ b/mysql-test/r/variables.result	2010-11-29 16:27:58 +0000
@@ -1722,3 +1722,9 @@ set @@session.autocommit=t1_min(), @@ses
 drop table t1;
 drop function t1_min;
 drop function t1_max;
+#
+# Bug#57035 'ulonglong sql_mode' stored into ulong, is risky and causes
+#           compiler warning
+#
+SET @@sql_mode= 4294967296;
+ERROR 42000: Variable 'sql_mode' can't be set to the value of '4294967296'

=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2010-08-30 06:38:09 +0000
+++ b/mysql-test/r/view.result	2010-11-30 17:55:36 +0000
@@ -840,6 +840,8 @@ show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
 t1	MyISAM	10	Fixed	0	0	0	#	1024	0	NULL	#	#	NULL	latin1_swedish_ci	NULL		
 v1	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+Warnings:
+Warning	1356	View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
 drop view v1;
 drop table t1;
 create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;

=== added file 'mysql-test/suite/federated/federated_bug_35333.result'
--- a/mysql-test/suite/federated/federated_bug_35333.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/federated/federated_bug_35333.result	2010-11-30 16:58:48 +0000
@@ -0,0 +1,67 @@
+#
+# Bug 35333 "If a Federated table can't connect to the remote hose, can't retrieve metadata"
+#
+# Queries such as SHOW TABLE STATUS and SELECT * FROM INFORMATION_SCHEMA.TABLES fail
+# when encountering a federated table that cannot connect to its remote table.
+#
+# The fix is to store the error text in the TABLE COMMENTS column of I_S.TABLES, clear
+# the remote connection error and push a warning instead. This allows the SELECT operation
+# to complete while still indicating a problem. This fix applies to any non-fatal system
+# error that occurs during a query against I_S.TABLES.de
+CREATE DATABASE federated;
+CREATE DATABASE federated;
+CREATE DATABASE IF NOT EXISTS realdb;
+DROP TABLE IF EXISTS realdb.t0;
+DROP TABLE IF EXISTS federated.t0;
+#
+# Create the base table to be referenced
+#
+CREATE TABLE realdb.t0 (a text, b text) ENGINE=MYISAM;
+#
+# Create a federated table with a bogus port number
+#
+CREATE TABLE federated.t0 (a text, b text) ENGINE=FEDERATED
+CONNECTION='mysql://root@stripped:63333/realdb/t0';
+#
+# Trigger a federated system error during a INFORMATION_SCHEMA.TABLES query
+#
+SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
+FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'realdb' or TABLE_SCHEMA = 'federated';
+TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	ROW_FORMAT	TABLE_ROWS	DATA_LENGTH	TABLE_COMMENT
+federated	t0	BASE TABLE	FEDERATED		NULL	0	Unable to connect to foreign data source: Can't connect to MySQL server on '127.0.0.1' (socket errno)
+realdb	t0	BASE TABLE	MyISAM	Dynamic	0	0	
+Warnings:
+Warning	1429	Unable to connect to foreign data source: Can't connect to MySQL server on '127.0.0.1' (socket errno)
+SHOW WARNINGS;
+Level	Code	Message
+Warning	1429	Unable to connect to foreign data source: Can't connect to MySQL server on '127.0.0.1' (socket errno)
+#
+# Create a MyISAM table then corrupt the file
+#
+USE realdb;
+CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
+#
+# Corrupt the MyISAM table by deleting the base file
+#
+#
+# Trigger a MyISAM system error during an INFORMATION_SCHEMA.TABLES query
+#
+SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
+FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	ROW_FORMAT	TABLE_ROWS	DATA_LENGTH	TABLE_COMMENT
+realdb	t1	BASE TABLE	NULL	NULL	NULL	NULL	Can't find file: 't1' (errno: 2)
+Warnings:
+Warning	1017	Can't find file: 't1' (errno: 2)
+SHOW WARNINGS;
+Level	Code	Message
+Warning	1017	Can't find file: 't1' (errno: 2)
+#
+# Cleanup
+#
+DROP TABLE IF EXISTS realdb.t0;
+DROP TABLE IF EXISTS federated.t0;
+DROP DATABASE realdb;
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE federated;
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE federated;

=== added file 'mysql-test/suite/federated/federated_bug_35333.test'
--- a/mysql-test/suite/federated/federated_bug_35333.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/federated/federated_bug_35333.test	2010-11-30 16:58:48 +0000
@@ -0,0 +1,74 @@
+--echo #
+--echo # Bug 35333 "If a Federated table can't connect to the remote hose, can't retrieve metadata"
+--echo #
+--echo # Queries such as SHOW TABLE STATUS and SELECT * FROM INFORMATION_SCHEMA.TABLES fail
+--echo # when encountering a federated table that cannot connect to its remote table.
+--echo #
+--echo # The fix is to store the error text in the TABLE COMMENTS column of I_S.TABLES, clear
+--echo # the remote connection error and push a warning instead. This allows the SELECT operation
+--echo # to complete while still indicating a problem. This fix applies to any non-fatal system
+--echo # error that occurs during a query against I_S.TABLES.de
+
+--source federated.inc
+
+--disable_warnings
+CREATE DATABASE IF NOT EXISTS realdb;
+# Federated database exists
+DROP TABLE IF EXISTS realdb.t0;
+DROP TABLE IF EXISTS federated.t0;
+--enable_warnings
+
+--echo #
+--echo # Create the base table to be referenced
+--echo #
+CREATE TABLE realdb.t0 (a text, b text) ENGINE=MYISAM;
+
+--echo #
+--echo # Create a federated table with a bogus port number
+--echo #
+CREATE TABLE federated.t0 (a text, b text) ENGINE=FEDERATED
+    CONNECTION='mysql://root@stripped:63333/realdb/t0';
+
+#--warning ER_CONNECT_TO_FOREIGN_DATA_SOURCE
+
+--echo #
+--echo # Trigger a federated system error during a INFORMATION_SCHEMA.TABLES query
+--echo #
+# Remove O/S-specific socket error
+--replace_regex /\(.*\)/(socket errno)/
+SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
+       FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'realdb' or TABLE_SCHEMA = 'federated';
+
+# Remove O/S-specific socket error
+--replace_regex /\(.*\)/(socket errno)/
+SHOW WARNINGS;
+
+--echo #
+--echo # Create a MyISAM table then corrupt the file
+--echo #
+USE realdb;
+CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
+--echo #
+--echo # Corrupt the MyISAM table by deleting the base file
+--echo #
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+--remove_file $MYSQLD_DATADIR/realdb/t1.MYD
+--remove_file $MYSQLD_DATADIR/realdb/t1.MYI
+
+--echo #
+--echo # Trigger a MyISAM system error during an INFORMATION_SCHEMA.TABLES query
+--echo #
+SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
+       FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
+
+SHOW WARNINGS;
+--echo #
+--echo # Cleanup
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS realdb.t0;
+DROP TABLE IF EXISTS federated.t0;
+DROP DATABASE realdb;
+--enable_warnings
+
+--source federated_cleanup.inc

=== modified file 'mysql-test/suite/perfschema/include/privilege.inc'
--- a/mysql-test/suite/perfschema/include/privilege.inc	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/include/privilege.inc	2010-12-01 18:46:51 +0000
@@ -100,16 +100,16 @@ create trigger performance_schema.bi_fil
   before insert on performance_schema.file_instances
   for each row begin end;
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1(a int) engine=PERFORMANCE_SCHEMA;
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1 like performance_schema.setup_instruments;
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1 like performance_schema.events_waits_current;
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1 like performance_schema.file_instances;
 
 --error ER_TABLEACCESS_DENIED_ERROR

=== modified file 'mysql-test/suite/perfschema/r/dml_cond_instances.result'
--- a/mysql-test/suite/perfschema/r/dml_cond_instances.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_cond_instances.result	2010-12-01 18:46:51 +0000
@@ -1,9 +1,6 @@
 select * from performance_schema.cond_instances limit 1;
-NAME	OBJECT_INSTANCE_BEGIN
-#	#
 select * from performance_schema.cond_instances
 where name='FOO';
-NAME	OBJECT_INSTANCE_BEGIN
 insert into performance_schema.cond_instances
 set name='FOO', object_instance_begin=12;
 ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'cond_instances'

=== modified file 'mysql-test/suite/perfschema/r/dml_ews_by_instance.result'
--- a/mysql-test/suite/perfschema/r/dml_ews_by_instance.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_ews_by_instance.result	2010-12-01 18:46:51 +0000
@@ -1,26 +1,15 @@
 select * from performance_schema.events_waits_summary_by_instance
 where event_name like 'Wait/Synch/%' limit 1;
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_by_instance
 where event_name='FOO';
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
 select * from performance_schema.events_waits_summary_by_instance
 order by count_star limit 1;
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_by_instance
 order by count_star desc limit 1;
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_by_instance
 where min_timer_wait > 0 order by count_star limit 1;
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_by_instance
 where min_timer_wait > 0 order by count_star desc limit 1;
-EVENT_NAME	OBJECT_INSTANCE_BEGIN	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 insert into performance_schema.events_waits_summary_by_instance
 set event_name='FOO', object_instance_begin=0,
 count_star=1, sum_timer_wait=2, min_timer_wait=3,

=== modified file 'mysql-test/suite/perfschema/r/dml_ews_by_thread_by_event_name.result'
--- a/mysql-test/suite/perfschema/r/dml_ews_by_thread_by_event_name.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_ews_by_thread_by_event_name.result	2010-12-01 18:46:51 +0000
@@ -1,10 +1,7 @@
 select * from performance_schema.events_waits_summary_by_thread_by_event_name
 where event_name like 'Wait/Synch/%' limit 1;
-THREAD_ID	EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_by_thread_by_event_name
 where event_name='FOO';
-THREAD_ID	EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
 insert into performance_schema.events_waits_summary_by_thread_by_event_name
 set event_name='FOO', thread_id=1,
 count_star=1, sum_timer_wait=2, min_timer_wait=3,

=== modified file 'mysql-test/suite/perfschema/r/dml_ews_global_by_event_name.result'
--- a/mysql-test/suite/perfschema/r/dml_ews_global_by_event_name.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_ews_global_by_event_name.result	2010-12-01 18:46:51 +0000
@@ -1,10 +1,7 @@
 select * from performance_schema.events_waits_summary_global_by_event_name
 where event_name like 'Wait/Synch/%' limit 1;
-EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
-#	#	#	#	#	#
 select * from performance_schema.events_waits_summary_global_by_event_name
 where event_name='FOO';
-EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT
 insert into performance_schema.events_waits_summary_global_by_event_name
 set event_name='FOO', count_star=1, sum_timer_wait=2, min_timer_wait=3,
 avg_timer_wait=4, max_timer_wait=5;

=== modified file 'mysql-test/suite/perfschema/r/dml_file_instances.result'
--- a/mysql-test/suite/perfschema/r/dml_file_instances.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_file_instances.result	2010-12-01 18:46:51 +0000
@@ -1,9 +1,6 @@
 select * from performance_schema.file_instances limit 1;
-FILE_NAME	EVENT_NAME	OPEN_COUNT
-#	#	#
 select * from performance_schema.file_instances
 where file_name='FOO';
-FILE_NAME	EVENT_NAME	OPEN_COUNT
 insert into performance_schema.file_instances
 set file_name='FOO', event_name='BAR', open_count=12;
 ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'file_instances'

=== modified file 'mysql-test/suite/perfschema/r/dml_file_summary_by_event_name.result'
--- a/mysql-test/suite/perfschema/r/dml_file_summary_by_event_name.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_file_summary_by_event_name.result	2010-12-01 18:46:51 +0000
@@ -1,10 +1,7 @@
 select * from performance_schema.file_summary_by_event_name
 where event_name like 'Wait/io/%' limit 1;
-EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-#	#	#	#	#
 select * from performance_schema.file_summary_by_event_name
 where event_name='FOO';
-EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
 insert into performance_schema.file_summary_by_event_name
 set event_name='FOO', count_read=1, count_write=2,
 sum_number_of_bytes_read=4, sum_number_of_bytes_write=5;

=== modified file 'mysql-test/suite/perfschema/r/dml_file_summary_by_instance.result'
--- a/mysql-test/suite/perfschema/r/dml_file_summary_by_instance.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_file_summary_by_instance.result	2010-12-01 18:46:51 +0000
@@ -1,10 +1,7 @@
 select * from performance_schema.file_summary_by_instance
 where event_name like 'Wait/io/%' limit 1;
-FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
-#	#	#	#	#	#
 select * from performance_schema.file_summary_by_instance
 where event_name='FOO';
-FILE_NAME	EVENT_NAME	COUNT_READ	COUNT_WRITE	SUM_NUMBER_OF_BYTES_READ	SUM_NUMBER_OF_BYTES_WRITE
 insert into performance_schema.file_summary_by_instance
 set event_name='FOO', count_read=1, count_write=2,
 sum_number_of_bytes_read=4, sum_number_of_bytes_write=5;

=== modified file 'mysql-test/suite/perfschema/r/dml_mutex_instances.result'
--- a/mysql-test/suite/perfschema/r/dml_mutex_instances.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_mutex_instances.result	2010-12-01 18:46:51 +0000
@@ -1,9 +1,6 @@
 select * from performance_schema.mutex_instances limit 1;
-NAME	OBJECT_INSTANCE_BEGIN	LOCKED_BY_THREAD_ID
-#	#	#
 select * from performance_schema.mutex_instances
 where name='FOO';
-NAME	OBJECT_INSTANCE_BEGIN	LOCKED_BY_THREAD_ID
 insert into performance_schema.mutex_instances
 set name='FOO', object_instance_begin=12;
 ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'mutex_instances'

=== modified file 'mysql-test/suite/perfschema/r/dml_rwlock_instances.result'
--- a/mysql-test/suite/perfschema/r/dml_rwlock_instances.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/dml_rwlock_instances.result	2010-12-01 18:46:51 +0000
@@ -1,9 +1,6 @@
 select * from performance_schema.rwlock_instances limit 1;
-NAME	OBJECT_INSTANCE_BEGIN	WRITE_LOCKED_BY_THREAD_ID	READ_LOCKED_BY_COUNT
-#	#	#	#
 select * from performance_schema.rwlock_instances
 where name='FOO';
-NAME	OBJECT_INSTANCE_BEGIN	WRITE_LOCKED_BY_THREAD_ID	READ_LOCKED_BY_COUNT
 insert into performance_schema.rwlock_instances
 set name='FOO', object_instance_begin=12;
 ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'rwlock_instances'

=== added file 'mysql-test/suite/perfschema/r/dml_threads.result'
--- a/mysql-test/suite/perfschema/r/dml_threads.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/r/dml_threads.result	2010-12-01 18:46:51 +0000
@@ -0,0 +1,34 @@
+select * from performance_schema.threads
+where name like 'Thread/%' limit 1;
+select * from performance_schema.threads
+where name='FOO';
+insert into performance_schema.threads
+set name='FOO', thread_id=1, processlist_id=2;
+ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'threads'
+update performance_schema.threads
+set thread_id=12;
+ERROR HY000: Invalid performance_schema usage.
+update performance_schema.threads
+set thread_id=12 where PROCESSLIST_ID=connection_id();
+ERROR HY000: Invalid performance_schema usage.
+update performance_schema.threads
+set instrumented= 'NO' where PROCESSLIST_ID=connection_id();
+select instrumented from performance_schema.threads
+where PROCESSLIST_ID=connection_id();
+instrumented
+NO
+update performance_schema.threads
+set instrumented= 'YES' where PROCESSLIST_ID=connection_id();
+select instrumented from performance_schema.threads
+where PROCESSLIST_ID=connection_id();
+instrumented
+YES
+delete from performance_schema.threads
+where id=1;
+ERROR 42000: DELETE command denied to user 'root'@'localhost' for table 'threads'
+delete from performance_schema.threads;
+ERROR 42000: DELETE command denied to user 'root'@'localhost' for table 'threads'
+LOCK TABLES performance_schema.threads READ;
+UNLOCK TABLES;
+LOCK TABLES performance_schema.threads WRITE;
+UNLOCK TABLES;

=== modified file 'mysql-test/suite/perfschema/r/misc.result'
--- a/mysql-test/suite/perfschema/r/misc.result	2010-11-09 08:16:50 +0000
+++ b/mysql-test/suite/perfschema/r/misc.result	2010-12-01 18:46:51 +0000
@@ -6,9 +6,9 @@ AND EVENT_NAME IN
 WHERE NAME LIKE "wait/synch/%")
 LIMIT 1;
 create table test.t1(a int) engine=performance_schema;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.events_waits_current;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table performance_schema.t1(a int);
 ERROR 42000: CREATE command denied to user 'root'@'localhost' for table 't1'
 drop table if exists test.ghost;

=== modified file 'mysql-test/suite/perfschema/r/myisam_file_io.result'
--- a/mysql-test/suite/perfschema/r/myisam_file_io.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/myisam_file_io.result	2010-12-01 18:46:51 +0000
@@ -15,8 +15,8 @@ left(source, locate(":", source)) as sho
 operation, number_of_bytes,
 substring(object_name, locate("no_index_tab", object_name)) as short_name
 from performance_schema.events_waits_history_long
-where event_name like 'wait/io/file/%'
-  and operation not like "tell"
+where operation not like "tell"
+  and event_name like "wait/io/file/myisam/%"
   order by thread_id, event_id;
 event_name	short_source	operation	number_of_bytes	short_name
 wait/io/file/myisam/kfile	mi_create.c:	create	NULL	no_index_tab.MYI

=== modified file 'mysql-test/suite/perfschema/r/privilege.result'
--- a/mysql-test/suite/perfschema/r/privilege.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/privilege.result	2010-12-01 18:46:51 +0000
@@ -152,13 +152,13 @@ before insert on performance_schema.file
 for each row begin end;
 ERROR 42000: Access denied for user 'root'@'localhost' to database 'performance_schema'
 create table test.t1(a int) engine=PERFORMANCE_SCHEMA;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.setup_instruments;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.events_waits_current;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.file_instances;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 insert into performance_schema.setup_instruments
 set name="foo";
 ERROR 42000: INSERT command denied to user 'root'@'localhost' for table 'setup_instruments'
@@ -250,13 +250,13 @@ before insert on performance_schema.file
 for each row begin end;
 ERROR 42000: Access denied for user 'pfs_user_1'@'localhost' to database 'performance_schema'
 create table test.t1(a int) engine=PERFORMANCE_SCHEMA;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.setup_instruments;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.events_waits_current;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.file_instances;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 insert into performance_schema.setup_instruments
 set name="foo";
 ERROR 42000: INSERT command denied to user 'pfs_user_1'@'localhost' for table 'setup_instruments'
@@ -348,13 +348,13 @@ before insert on performance_schema.file
 for each row begin end;
 ERROR 42000: Access denied for user 'pfs_user_2'@'localhost' to database 'performance_schema'
 create table test.t1(a int) engine=PERFORMANCE_SCHEMA;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.setup_instruments;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.events_waits_current;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.file_instances;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 insert into performance_schema.setup_instruments
 set name="foo";
 ERROR 42000: INSERT command denied to user 'pfs_user_2'@'localhost' for table 'setup_instruments'
@@ -446,13 +446,13 @@ before insert on performance_schema.file
 for each row begin end;
 ERROR 42000: Access denied for user 'pfs_user_3'@'localhost' to database 'performance_schema'
 create table test.t1(a int) engine=PERFORMANCE_SCHEMA;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.setup_instruments;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.events_waits_current;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 create table test.t1 like performance_schema.file_instances;
-ERROR HY000: Invalid performance_schema usage.
+ERROR HY000: Can't create table 'test.t1' (errno: 131)
 insert into performance_schema.setup_instruments
 set name="foo";
 ERROR 42000: INSERT command denied to user 'pfs_user_3'@'localhost' for table 'setup_instruments'

=== added file 'mysql-test/suite/perfschema/r/thread_cache.result'
--- a/mysql-test/suite/perfschema/r/thread_cache.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/r/thread_cache.result	2010-12-01 18:46:51 +0000
@@ -0,0 +1,39 @@
+flush status;
+SET @saved_thread_cache_size = @@global.thread_cache_size;
+set global thread_cache_size = 0;
+show variables like "thread_cache_size";
+Variable_name	Value
+thread_cache_size	0
+select @id_increment;
+@id_increment
+1
+select @thread_id_increment;
+@thread_id_increment
+1
+select @id_increment;
+@id_increment
+1
+select @thread_id_increment;
+@thread_id_increment
+1
+set global thread_cache_size = 100;
+show variables like "thread_cache_size";
+Variable_name	Value
+thread_cache_size	100
+select @id_increment;
+@id_increment
+1
+select @thread_id_increment;
+@thread_id_increment
+1
+select @id_increment;
+@id_increment
+1
+select @thread_id_increment;
+@thread_id_increment
+1
+set global thread_cache_size = @saved_thread_cache_size;
+show status like "performance_schema_thread%";
+Variable_name	Value
+Performance_schema_thread_classes_lost	0
+Performance_schema_thread_instances_lost	0

=== modified file 'mysql-test/suite/perfschema/t/dml_cond_instances.test'
--- a/mysql-test/suite/perfschema/t/dml_cond_instances.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_cond_instances.test	2010-12-01 18:46:51 +0000
@@ -18,11 +18,12 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 #
+--disable_result_log
 select * from performance_schema.cond_instances limit 1;
 
 select * from performance_schema.cond_instances
   where name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.cond_instances

=== modified file 'mysql-test/suite/perfschema/t/dml_ews_by_instance.test'
--- a/mysql-test/suite/perfschema/t/dml_ews_by_instance.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_ews_by_instance.test	2010-12-01 18:46:51 +0000
@@ -18,28 +18,25 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
+--disable_result_log
 select * from performance_schema.events_waits_summary_by_instance
   where event_name like 'Wait/Synch/%' limit 1;
 
 select * from performance_schema.events_waits_summary_by_instance
   where event_name='FOO';
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
 select * from performance_schema.events_waits_summary_by_instance
   order by count_star limit 1;
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
 select * from performance_schema.events_waits_summary_by_instance
   order by count_star desc limit 1;
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
 select * from performance_schema.events_waits_summary_by_instance
   where min_timer_wait > 0 order by count_star limit 1;
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
 select * from performance_schema.events_waits_summary_by_instance
   where min_timer_wait > 0 order by count_star desc limit 1;
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.events_waits_summary_by_instance

=== modified file 'mysql-test/suite/perfschema/t/dml_ews_by_thread_by_event_name.test'
--- a/mysql-test/suite/perfschema/t/dml_ews_by_thread_by_event_name.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_ews_by_thread_by_event_name.test	2010-12-01 18:46:51 +0000
@@ -18,12 +18,13 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 #
+--disable_result_log
 select * from performance_schema.events_waits_summary_by_thread_by_event_name
   where event_name like 'Wait/Synch/%' limit 1;
 
 select * from performance_schema.events_waits_summary_by_thread_by_event_name
   where event_name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.events_waits_summary_by_thread_by_event_name

=== modified file 'mysql-test/suite/perfschema/t/dml_ews_global_by_event_name.test'
--- a/mysql-test/suite/perfschema/t/dml_ews_global_by_event_name.test	2010-11-03 15:42:33 +0000
+++ b/mysql-test/suite/perfschema/t/dml_ews_global_by_event_name.test	2010-12-01 08:01:04 +0000
@@ -18,12 +18,13 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 #
+--disable_result_log
 select * from performance_schema.events_waits_summary_global_by_event_name
   where event_name like 'Wait/Synch/%' limit 1;
 
 select * from performance_schema.events_waits_summary_global_by_event_name
   where event_name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.events_waits_summary_global_by_event_name

=== modified file 'mysql-test/suite/perfschema/t/dml_file_instances.test'
--- a/mysql-test/suite/perfschema/t/dml_file_instances.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_file_instances.test	2010-12-01 18:46:51 +0000
@@ -18,11 +18,12 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 #
+--disable_result_log
 select * from performance_schema.file_instances limit 1;
 
 select * from performance_schema.file_instances
   where file_name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.file_instances

=== modified file 'mysql-test/suite/perfschema/t/dml_file_summary_by_event_name.test'
--- a/mysql-test/suite/perfschema/t/dml_file_summary_by_event_name.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_file_summary_by_event_name.test	2010-12-01 18:46:51 +0000
@@ -18,12 +18,13 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 # 5 #
+--disable_result_log
 select * from performance_schema.file_summary_by_event_name
   where event_name like 'Wait/io/%' limit 1;
 
 select * from performance_schema.file_summary_by_event_name
   where event_name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.file_summary_by_event_name

=== modified file 'mysql-test/suite/perfschema/t/dml_file_summary_by_instance.test'
--- a/mysql-test/suite/perfschema/t/dml_file_summary_by_instance.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_file_summary_by_instance.test	2010-12-01 18:46:51 +0000
@@ -18,12 +18,13 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 # 5 # 6 #
+--disable_result_log
 select * from performance_schema.file_summary_by_instance
   where event_name like 'Wait/io/%' limit 1;
 
 select * from performance_schema.file_summary_by_instance
   where event_name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.file_summary_by_instance

=== modified file 'mysql-test/suite/perfschema/t/dml_mutex_instances.test'
--- a/mysql-test/suite/perfschema/t/dml_mutex_instances.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_mutex_instances.test	2010-12-01 18:46:51 +0000
@@ -18,11 +18,12 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 #
+--disable_result_log
 select * from performance_schema.mutex_instances limit 1;
 
 select * from performance_schema.mutex_instances
   where name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.mutex_instances

=== modified file 'mysql-test/suite/perfschema/t/dml_rwlock_instances.test'
--- a/mysql-test/suite/perfschema/t/dml_rwlock_instances.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/dml_rwlock_instances.test	2010-12-01 18:46:51 +0000
@@ -18,11 +18,12 @@
 --source include/not_embedded.inc
 --source include/have_perfschema.inc
 
---replace_column 1 # 2 # 3 # 4 #
+--disable_result_log
 select * from performance_schema.rwlock_instances limit 1;
 
 select * from performance_schema.rwlock_instances
   where name='FOO';
+--enable_result_log
 
 --error ER_TABLEACCESS_DENIED_ERROR
 insert into performance_schema.rwlock_instances

=== added file 'mysql-test/suite/perfschema/t/dml_threads.test'
--- a/mysql-test/suite/perfschema/t/dml_threads.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/dml_threads.test	2010-12-01 18:46:51 +0000
@@ -0,0 +1,65 @@
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
+
+# Tests for PERFORMANCE_SCHEMA
+
+--source include/not_embedded.inc
+--source include/have_perfschema.inc
+
+--disable_result_log
+select * from performance_schema.threads
+  where name like 'Thread/%' limit 1;
+
+select * from performance_schema.threads
+  where name='FOO';
+--enable_result_log
+
+--error ER_TABLEACCESS_DENIED_ERROR
+insert into performance_schema.threads
+  set name='FOO', thread_id=1, processlist_id=2;
+
+--error ER_WRONG_PERFSCHEMA_USAGE
+update performance_schema.threads
+  set thread_id=12;
+
+--error ER_WRONG_PERFSCHEMA_USAGE
+update performance_schema.threads
+  set thread_id=12 where PROCESSLIST_ID=connection_id();
+
+update performance_schema.threads
+  set instrumented= 'NO' where PROCESSLIST_ID=connection_id();
+
+select instrumented from performance_schema.threads
+  where PROCESSLIST_ID=connection_id();
+
+update performance_schema.threads
+  set instrumented= 'YES' where PROCESSLIST_ID=connection_id();
+
+select instrumented from performance_schema.threads
+  where PROCESSLIST_ID=connection_id();
+
+--error ER_TABLEACCESS_DENIED_ERROR
+delete from performance_schema.threads
+  where id=1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+delete from performance_schema.threads;
+
+LOCK TABLES performance_schema.threads READ;
+UNLOCK TABLES;
+
+LOCK TABLES performance_schema.threads WRITE;
+UNLOCK TABLES;
+

=== modified file 'mysql-test/suite/perfschema/t/misc.test'
--- a/mysql-test/suite/perfschema/t/misc.test	2010-11-09 08:16:50 +0000
+++ b/mysql-test/suite/perfschema/t/misc.test	2010-12-01 18:46:51 +0000
@@ -38,14 +38,14 @@ LIMIT 1;
 # Bug#45088 Should not be able to create tables of engine PERFORMANCE_SCHEMA
 #
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1(a int) engine=performance_schema;
 
 #
 # Bug#44897 Performance Schema: can create a ghost table in another database
 #
 
---error ER_WRONG_PERFSCHEMA_USAGE
+--error ER_CANT_CREATE_TABLE
 create table test.t1 like performance_schema.events_waits_current;
 
 #

=== modified file 'mysql-test/suite/perfschema/t/myisam_file_io.test'
--- a/mysql-test/suite/perfschema/t/myisam_file_io.test	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/t/myisam_file_io.test	2010-12-01 18:46:51 +0000
@@ -46,14 +46,21 @@ insert into no_index_tab set a = 'foo', 
 # Verification
 # Note that mi_create.c contains mysql_file_tell() calls in debug only,
 # so the result are filtered to remove 'tell'.
+# Note that even after setting other instruments to enabled='NO'
+# and truncating the events_waits_history_long table,
+# some events -- that were already started but not completed --
+# for other instruments could still be added in the history.
+# To protect against that, an extra where clause
+# "and event_name like "wait/io/file/myisam/%"
+# is added to the select to filter out the result.
 
 select event_name,
   left(source, locate(":", source)) as short_source,
   operation, number_of_bytes,
   substring(object_name, locate("no_index_tab", object_name)) as short_name
   from performance_schema.events_waits_history_long
-  where event_name like 'wait/io/file/%'
-  and operation not like "tell"
+  where operation not like "tell"
+  and event_name like "wait/io/file/myisam/%"
   order by thread_id, event_id;
 
 # In case of failures, this will tell if file io are lost.

=== added file 'mysql-test/suite/perfschema/t/thread_cache.test'
--- a/mysql-test/suite/perfschema/t/thread_cache.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/thread_cache.test	2010-12-01 18:46:51 +0000
@@ -0,0 +1,166 @@
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
+
+# Tests for PERFORMANCE_SCHEMA
+
+--source include/not_embedded.inc
+--source include/have_perfschema.inc
+
+# Setup
+
+flush status;
+
+SET @saved_thread_cache_size = @@global.thread_cache_size;
+
+set global thread_cache_size = 0;
+
+show variables like "thread_cache_size";
+
+connect (con1, localhost, root, , );
+
+let $con1_ID=`select connection_id()`;
+
+let $con1_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+connect (con2, localhost, root, , );
+
+let $con2_ID=`select connection_id()`;
+
+let $con2_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+--connection default
+
+--disable_query_log
+eval select ($con2_ID - $con1_ID) into @id_increment;
+eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment;
+--enable_query_log
+
+# Expect 1, connection_id() is incremented for each new connection
+select @id_increment;
+# Expect 1, THREAD_ID is incremented for each new connection
+select @thread_id_increment;
+
+--disconnect con2
+
+--connection default
+
+# Wait for the disconnect con2 to complete
+let $wait_condition=
+  select count(*) = 2 from performance_schema.threads
+  where name like "thread/sql/one_connection";
+--source include/wait_condition.inc
+
+connect (con3, localhost, root, , );
+
+let $con3_ID=`select connection_id()`;
+
+let $con3_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+--disconnect con3
+--disconnect con1
+
+--connection default
+
+# Wait for the disconnect con1 and con3 to complete
+let $wait_condition=
+  select count(*) = 1 from performance_schema.threads
+  where name like "thread/sql/one_connection";
+--source include/wait_condition.inc
+
+--disable_query_log
+eval select ($con3_ID - $con2_ID) into @id_increment;
+eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment;
+--enable_query_log
+
+select @id_increment;
+select @thread_id_increment;
+
+set global thread_cache_size = 100;
+
+show variables like "thread_cache_size";
+
+connect (con1, localhost, root, , );
+
+let $con1_ID=`select connection_id()`;
+
+let $con1_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+connect (con2, localhost, root, , );
+
+let $con2_ID=`select connection_id()`;
+
+let $con2_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+--connection default
+
+--disable_query_log
+eval select ($con2_ID - $con1_ID) into @id_increment;
+eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment;
+--enable_query_log
+
+select @id_increment;
+select @thread_id_increment;
+
+--disconnect con2
+
+--connection default
+
+# Wait for the disconnect con2 to complete
+let $wait_condition=
+  select count(*) = 2 from performance_schema.threads
+  where name like "thread/sql/one_connection";
+--source include/wait_condition.inc
+
+connect (con3, localhost, root, , );
+
+let $con3_ID=`select connection_id()`;
+
+let $con3_THREAD_ID=`select thread_id from performance_schema.threads
+  where PROCESSLIST_ID = connection_id()`;
+
+--disconnect con3
+--disconnect con1
+
+--connection default
+
+# Wait for the disconnect con1 and con3 to complete
+let $wait_condition=
+  select count(*) = 1 from performance_schema.threads
+  where name like "thread/sql/one_connection";
+--source include/wait_condition.inc
+
+--disable_query_log
+eval select ($con3_ID - $con2_ID) into @id_increment;
+eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment;
+--enable_query_log
+
+# When caching threads, the pthread that executed con2 was parked in the
+# cache on disconnect, and then picked up con3.
+
+# Still expect a new connection_id()
+select @id_increment;
+
+# And expect a new instrumentation: the THREAD_ID of old connections should not be reused.
+select @thread_id_increment;
+
+set global thread_cache_size = @saved_thread_cache_size;
+
+show status like "performance_schema_thread%";
+

=== added file 'mysql-test/suite/rpl/r/rpl_slave_start.result'
--- a/mysql-test/suite/rpl/r/rpl_slave_start.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_slave_start.result	2010-11-30 09:19:33 +0000
@@ -0,0 +1,26 @@
+# Bug#47699 rpl.rpl_backup_block fails sporadically
+#
+# START SLAVE released the lock and returned before it cleared the error,
+# so there is a possibility that Slave_SQL_Error is not 0.
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+[on slave]
+CALL mtr.add_suppression("Slave: Table 't1' already exists Error_code: 1050");
+# The statement makes SQL thread to fail.
+CREATE TABLE t1(c1 INT);
+[on master]
+CREATE TABLE t1(c1 INT);
+[on slave]
+DROP TABLE t1;
+# Block SQL thread immediately after it starts.
+SET DEBUG_SYNC='after_start_slave WAIT_FOR signal.continue';
+START SLAVE SQL_THREAD;
+# Check Slave_SQL_Error, there should not be an error.
+# Resume SQL thread
+SET DEBUG_SYNC="now SIGNAL signal.continue";
+[on master]
+DROP TABLE t1;

=== modified file 'mysql-test/suite/rpl/r/rpl_slave_status.result'
--- a/mysql-test/suite/rpl/r/rpl_slave_status.result	2010-11-28 09:11:02 +0000
+++ b/mysql-test/suite/rpl/r/rpl_slave_status.result	2010-11-30 09:19:33 +0000
@@ -36,24 +36,3 @@ DROP TABLE t1;
 include/stop_slave.inc
 CHANGE MASTER TO master_user='root', master_password='';
 include/start_slave.inc
-
-# Bug#47699 rpl.rpl_backup_block fails sporadically
-#
-# START SLAVE released the lock and returned before it cleared the error,
-# so there is a possibility that Slave_SQL_Error is not 0.
-[on slave]
-CALL mtr.add_suppression("Slave: Table 't1' already exists Error_code: 1050");
-# The statement makes SQL thread to fail.
-CREATE TABLE t1(c1 INT);
-[on master]
-CREATE TABLE t1(c1 INT);
-[on slave]
-DROP TABLE t1;
-# Block SQL thread immediately after it starts.
-SET DEBUG_SYNC='after_start_slave WAIT_FOR signal.continue';
-START SLAVE SQL_THREAD;
-# Check Slave_SQL_Error, there should not be an error.
-# Resume SQL thread
-SET DEBUG_SYNC="now SIGNAL signal.continue";
-[on master]
-DROP TABLE t1;

=== modified file 'mysql-test/suite/rpl/t/rpl_checksum.test'
--- a/mysql-test/suite/rpl/t/rpl_checksum.test	2010-09-28 15:42:48 +0000
+++ b/mysql-test/suite/rpl/t/rpl_checksum.test	2010-11-29 16:07:06 +0000
@@ -239,6 +239,25 @@ drop table t1, t2, t3;
 set @@global.binlog_checksum = @master_save_binlog_checksum;
 set @@global.master_verify_checksum = @save_master_verify_checksum;
 
+#
+# BUG#58564: flush_read_lock fails in mysql-trunk-bugfixing after merging with WL#2540
+#
+# Sanity check that verifies that no assertions are triggered because
+# of old FD events (generated by versions prior to server released with 
+# checksums feature)
+#
+# There is no need for query log, if something wrong this should trigger
+# an assertion
+
+--disable_query_log
+
+BINLOG '
+MfmqTA8BAAAAZwAAAGsAAAABAAQANS41LjctbTMtZGVidWctbG9nAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAx+apMEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
+';
+
+--enable_query_log
+
 #connection slave;
 sync_slave_with_master;
 set @@global.binlog_checksum = @slave_save_binlog_checksum;

=== added file 'mysql-test/suite/rpl/t/rpl_slave_start.test'
--- a/mysql-test/suite/rpl/t/rpl_slave_start.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slave_start.test	2010-11-30 09:19:33 +0000
@@ -0,0 +1,39 @@
+--echo # Bug#47699 rpl.rpl_backup_block fails sporadically
+--echo #
+--echo # START SLAVE released the lock and returned before it cleared the error,
+--echo # so there is a possibility that Slave_SQL_Error is not 0.
+source include/master-slave.inc;
+source include/have_debug_sync.inc;
+
+--echo [on slave]
+connection slave;
+CALL mtr.add_suppression("Slave: Table 't1' already exists Error_code: 1050");
+--echo # The statement makes SQL thread to fail.
+CREATE TABLE t1(c1 INT);
+
+--echo [on master]
+connection master;
+CREATE TABLE t1(c1 INT);
+
+--echo [on slave]
+connection slave;
+# ERROR: Table already exists.
+let $slave_sql_errno= 1050;
+source include/wait_for_slave_sql_error.inc;
+
+DROP TABLE t1;
+
+--echo # Block SQL thread immediately after it starts.
+SET DEBUG_SYNC='after_start_slave WAIT_FOR signal.continue';
+START SLAVE SQL_THREAD;
+source include/wait_for_slave_sql_to_start.inc;
+--echo # Check Slave_SQL_Error, there should not be an error.
+source include/check_slave_no_error.inc;
+
+--echo # Resume SQL thread
+SET DEBUG_SYNC="now SIGNAL signal.continue";
+
+--echo [on master]
+connection master;
+DROP TABLE t1;
+source include/master-slave-end.inc;
\ No newline at end of file

=== modified file 'mysql-test/suite/rpl/t/rpl_slave_status.test'
--- a/mysql-test/suite/rpl/t/rpl_slave_status.test	2010-11-28 09:11:02 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slave_status.test	2010-11-30 09:19:33 +0000
@@ -71,40 +71,4 @@ source include/stop_slave.inc;
 CHANGE MASTER TO master_user='root', master_password='';
 source include/start_slave.inc;
 connection master;
-sync_slave_with_master;
-
---echo 
---echo # Bug#47699 rpl.rpl_backup_block fails sporadically
---echo #
---echo # START SLAVE released the lock and returned before it cleared the error,
---echo # so there is a possibility that Slave_SQL_Error is not 0.
-
---echo [on slave]
-CALL mtr.add_suppression("Slave: Table 't1' already exists Error_code: 1050");
---echo # The statement makes SQL thread to fail.
-CREATE TABLE t1(c1 INT);
-
---echo [on master]
-connection master;
-CREATE TABLE t1(c1 INT);
-
---echo [on slave]
-connection slave;
-source include/wait_for_slave_sql_to_stop.inc;
-
-DROP TABLE t1;
-
---echo # Block SQL thread immediately after it starts.
-SET DEBUG_SYNC='after_start_slave WAIT_FOR signal.continue';
-START SLAVE SQL_THREAD;
-source include/wait_for_slave_sql_to_start.inc;
---echo # Check Slave_SQL_Error, there should not be an error.
-source include/check_slave_no_error.inc;
-
---echo # Resume SQL thread
-SET DEBUG_SYNC="now SIGNAL signal.continue";
-
---echo [on master]
-connection master;
-DROP TABLE t1;
 source include/master-slave-end.inc;
\ No newline at end of file

=== modified file 'mysql-test/t/mysql.test'
--- a/mysql-test/t/mysql.test	2010-11-26 14:37:59 +0000
+++ b/mysql-test/t/mysql.test	2010-12-01 07:01:44 +0000
@@ -536,35 +536,34 @@ SHOW TABLES IN test;
 --echo # specified with USE command
 --echo #
 
-# CASE 1 : When 'test' database exists and passed at commandline.
+# CASE 1 : When 'connected_db' database exists and passed at commandline.
 --write_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql
-CREATE TABLE `table_in_test`(i INT);
+CREATE TABLE `table_in_connected_db`(i INT);
 USE non_existent_db;
 # Following statement should be filtered out.
 CREATE TABLE `table_in_non_existent_db`(i INT);
 EOF
 
-# CASE 2 : When 'test' database exists but dropped and recreated in load file.
+# CASE 2 : When 'connected_db' database exists but dropped and recreated in
+# load file.
 --write_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql
-DROP DATABASE test;
-CREATE DATABASE test;
+DROP DATABASE connected_db;
+CREATE DATABASE connected_db;
 USE non_existent_db;
 # Following statements should be filtered out.
 CREATE TABLE `table_in_non_existent_db`(i INT);
-USE test;
+USE connected_db;
 # Following statements should not be filtered out.
-CREATE TABLE `table_in_test`(i INT);
+CREATE TABLE `table_in_connected_db`(i INT);
 EOF
 
---exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_1.sql
-SHOW TABLES IN test;
-DROP DATABASE test;
+CREATE DATABASE connected_db;
+--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_1.sql
+SHOW TABLES IN connected_db;
 --echo
-CREATE DATABASE test;
---exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db_2.sql
-SHOW TABLES IN test;
-DROP DATABASE test;
-CREATE DATABASE test;
+--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_2.sql
+SHOW TABLES IN connected_db;
+DROP DATABASE connected_db;
 
 --remove_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql
 --remove_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql

=== modified file 'mysql-test/t/mysqld--defaults-file.test'
--- a/mysql-test/t/mysqld--defaults-file.test	2010-11-27 20:21:16 +0000
+++ b/mysql-test/t/mysqld--defaults-file.test	2010-11-29 22:16:48 +0000
@@ -3,6 +3,7 @@
 # segmentation fault
 
 source include/not_embedded.inc;
+source include/not_windows.inc;
 
 # We need to use a plain "mysqld" without any other options to trigger
 # the bug. In particular, it seems that passing --bootstrap does not

=== modified file 'mysql-test/t/variables.test'
--- a/mysql-test/t/variables.test	2010-11-25 04:41:58 +0000
+++ b/mysql-test/t/variables.test	2010-11-29 16:27:58 +0000
@@ -1464,3 +1464,23 @@ drop function t1_max;
 
 
 ###########################################################################
+
+
+--echo #
+--echo # Bug#57035 'ulonglong sql_mode' stored into ulong, is risky and causes
+--echo #           compiler warning
+--echo #
+
+# Several tests currently use "@@sql_mode= cast(pow(2,32)-1"
+# to activate all SQL modes. This will stop working once
+# someone adds a new flag. The test below is designed to break
+# once this happens to indicate that other tests will have to
+# be updated.
+#
+# The test does this by trying to set sql_mode to the next 
+# currently unused flag value and check that this currently fails.
+# Once a new flag is added, this value will become valid and
+# the statement below will succeed.
+
+--error ER_WRONG_VALUE_FOR_VAR
+SET @@sql_mode= 4294967296;

=== modified file 'mysys/stacktrace.c'
--- a/mysys/stacktrace.c	2010-11-08 11:53:04 +0000
+++ b/mysys/stacktrace.c	2010-11-30 23:20:32 +0000
@@ -24,6 +24,11 @@
 #include <unistd.h>
 #include <strings.h>
 
+#ifdef __linux__
+#include <ctype.h>          /* isprint */
+#include <sys/syscall.h>    /* SYS_gettid */
+#endif
+
 #if HAVE_EXECINFO_H
 #include <execinfo.h>
 #endif
@@ -43,10 +48,99 @@ void my_init_stacktrace()
 #endif
 }
 
-void my_safe_print_str(const char* name, const char* val, int max_len)
+#ifdef __linux__
+
+static void print_buffer(char *buffer, size_t count)
+{
+  for (; count && *buffer; --count)
+  {
+    int c= (int) *buffer++;
+    fputc(isprint(c) ? c : ' ', stderr);
+  }
+}
+
+/**
+  Access the pages of this process through /proc/self/task/<tid>/mem
+  in order to safely print the contents of a memory address range.
+
+  @param  addr      The address at the start of the memory region.
+  @param  max_len   The length of the memory region.
+
+  @return Zero on success.
+*/
+static int safe_print_str(const char *addr, int max_len)
 {
-  char *heap_end= (char*) sbrk(0);
-  fprintf(stderr, "%s at %p ", name, val);
+  int fd;
+  pid_t tid;
+  off_t offset;
+  ssize_t nbytes= 0;
+  size_t total, count;
+  char buf[256];
+
+  tid= (pid_t) syscall(SYS_gettid);
+
+  sprintf(buf, "/proc/self/task/%d/mem", tid);
+
+  if ((fd= open(buf, O_RDONLY)) < 0)
+    return -1;
+
+  /* Ensure that off_t can hold a pointer. */
+  compile_time_assert(sizeof(off_t) >= sizeof(intptr));
+
+  total= max_len;
+  offset= (intptr) addr;
+
+  /* Read up to the maximum number of bytes. */
+  while (total)
+  {
+    count= min(sizeof(buf), total);
+
+    if ((nbytes= pread(fd, buf, count, offset)) < 0)
+    {
+      /* Just in case... */
+      if (errno == EINTR)
+        continue;
+      else
+        break;
+    }
+
+    /* Advance offset into memory. */
+    total-= nbytes;
+    offset+= nbytes;
+    addr+= nbytes;
+
+    /* Output the printable characters. */
+    print_buffer(buf, nbytes);
+
+    /* Break if less than requested... */
+    if ((count - nbytes))
+      break;
+  }
+
+  /* Output a new line if something was printed. */
+  if (total != (size_t) max_len)
+    fputc('\n', stderr);
+
+  if (nbytes == -1)
+    fprintf(stderr, "Can't read from address %p: %m.\n", addr);
+
+  close(fd);
+
+  return 0;
+}
+
+#endif
+
+void my_safe_print_str(const char* val, int max_len)
+{
+  char *heap_end;
+
+#ifdef __linux__
+  if (!safe_print_str(val, max_len))
+    return;
+#endif
+
+  heap_end= (char*) sbrk(0);
 
   if (!PTR_SANE(val))
   {
@@ -54,7 +148,6 @@ void my_safe_print_str(const char* name,
     return;
   }
 
-  fprintf(stderr, "= ");
   for (; max_len && PTR_SANE(val) && *val; --max_len)
     fputc(*val++, stderr);
   fputc('\n', stderr);
@@ -607,10 +700,9 @@ void my_write_core(int unused)
 }
 
 
-void my_safe_print_str(const char *name, const char *val, int len)
+void my_safe_print_str(const char *val, int len)
 {
-  fprintf(stderr,"%s at %p", name, val);
-  __try 
+  __try
   {
     fprintf(stderr,"=%.*s\n", len, val);
   }

=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2010-11-23 22:37:59 +0000
+++ b/sql/CMakeLists.txt	2010-11-29 13:21:04 +0000
@@ -154,7 +154,7 @@ IF(NOT WITHOUT_DYNAMIC_PLUGINS)
 ENDIF()
 
 SET_TARGET_PROPERTIES(mysqld PROPERTIES ENABLE_EXPORTS TRUE) 
-TARGET_LINK_LIBRARIES(mysqld sql binlog rpl master slave sql)
+TARGET_LINK_LIBRARIES(mysqld sql binlog rpl master slave sql mysys)
 
 # Provide plugins with minimal set of libraries
 SET(INTERFACE_LIBS ${LIBRT})

=== modified file 'sql/binlog.cc'
--- a/sql/binlog.cc	2010-11-29 11:28:55 +0000
+++ b/sql/binlog.cc	2010-11-30 18:20:57 +0000
@@ -2042,7 +2042,7 @@ bool MYSQL_BIN_LOG::reset_logs(THD* thd)
   }
 
   /* Start logging with a new file */
-  close(LOG_CLOSE_INDEX);
+  close(LOG_CLOSE_INDEX | LOG_CLOSE_TO_BE_OPENED);
   if ((error= my_delete_allow_opened(index_file_name, MYF(0))))	// Reset (open will update)
   {
     if (my_errno == ENOENT) 

=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2010-11-18 16:34:56 +0000
+++ b/sql/event_data_objects.cc	2010-11-29 16:27:58 +0000
@@ -430,7 +430,7 @@ Event_job_data::load_from_row(THD *thd, 
   definer_host.str= strmake_root(&mem_root, ptr + 1, len);
   definer_host.length= len;
 
-  sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
+  sql_mode= (sql_mode_t) table->field[ET_FIELD_SQL_MODE]->val_int();
 
   DBUG_RETURN(FALSE);
 }
@@ -636,7 +636,7 @@ Event_timed::load_from_row(THD *thd, TAB
   else
     comment.length= 0;
 
-  sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
+  sql_mode= (sql_mode_t) table->field[ET_FIELD_SQL_MODE]->val_int();
 
   DBUG_RETURN(FALSE);
 }

=== modified file 'sql/event_data_objects.h'
--- a/sql/event_data_objects.h	2010-11-18 16:34:56 +0000
+++ b/sql/event_data_objects.h	2010-11-29 16:27:58 +0000
@@ -132,7 +132,7 @@ public:
   ulonglong created;
   ulonglong modified;
 
-  ulong sql_mode;
+  sql_mode_t sql_mode;
 
   class Stored_program_creation_ctx *creation_ctx;
   LEX_STRING body_utf8;
@@ -158,7 +158,7 @@ public:
   LEX_STRING definer_user;
   LEX_STRING definer_host;
 
-  ulong sql_mode;
+  sql_mode_t sql_mode;
 
   class Stored_program_creation_ctx *creation_ctx;
 

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	2010-11-18 16:34:56 +0000
+++ b/sql/event_db_repository.cc	2010-11-29 16:27:58 +0000
@@ -199,7 +199,7 @@ mysql_event_fill_row(THD *thd,
                      TABLE *table,
                      Event_parse_data *et,
                      sp_head *sp,
-                     ulong sql_mode,
+                     sql_mode_t sql_mode,
                      my_bool is_update)
 {
   CHARSET_INFO *scs= system_charset_info;
@@ -622,7 +622,7 @@ Event_db_repository::create_event(THD *t
   int ret= 1;
   TABLE *table= NULL;
   sp_head *sp= thd->lex->sphead;
-  ulong saved_mode= thd->variables.sql_mode;
+  sql_mode_t saved_mode= thd->variables.sql_mode;
   /*
     Take a savepoint to release only the lock on mysql.event
     table at the end but keep the global read lock and
@@ -740,7 +740,7 @@ Event_db_repository::update_event(THD *t
   CHARSET_INFO *scs= system_charset_info;
   TABLE *table= NULL;
   sp_head *sp= thd->lex->sphead;
-  ulong saved_mode= thd->variables.sql_mode;
+  sql_mode_t saved_mode= thd->variables.sql_mode;
   /*
     Take a savepoint to release only the lock on mysql.event
     table at the end but keep the global read lock and
@@ -1015,7 +1015,7 @@ Event_db_repository::load_named_event(TH
                                       LEX_STRING name, Event_basic *etn)
 {
   bool ret;
-  ulong saved_mode= thd->variables.sql_mode;
+  sql_mode_t saved_mode= thd->variables.sql_mode;
   Open_tables_backup open_tables_backup;
   TABLE_LIST event_table;
 

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2010-11-26 15:20:05 +0000
+++ b/sql/ha_partition.cc	2010-11-29 16:27:58 +0000
@@ -3095,7 +3095,7 @@ int ha_partition::write_row(uchar * buf)
   my_bitmap_map *old_map;
   THD *thd= ha_thd();
   timestamp_auto_set_type saved_timestamp_type= table->timestamp_field_type;
-  ulong saved_sql_mode= thd->variables.sql_mode;
+  sql_mode_t saved_sql_mode= thd->variables.sql_mode;
   bool saved_auto_inc_field_not_null= table->auto_increment_field_not_null;
 #ifdef NOT_NEEDED
   uchar *rec0= m_rec0;

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-11-19 15:49:46 +0000
+++ b/sql/item.cc	2010-11-29 16:27:58 +0000
@@ -1068,7 +1068,7 @@ int Item::save_in_field_no_warnings(Fiel
   THD *thd= table->in_use;
   enum_check_fields tmp= thd->count_cuted_fields;
   my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
-  ulonglong sql_mode= thd->variables.sql_mode;
+  sql_mode_t sql_mode= thd->variables.sql_mode;
   thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
   thd->count_cuted_fields= CHECK_FIELD_IGNORE;
   res= save_in_field(field, no_conversions);

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2010-11-05 16:23:32 +0000
+++ b/sql/item_cmpfunc.cc	2010-11-29 16:27:58 +0000
@@ -406,7 +406,7 @@ static bool convert_constant_item(THD *t
   if (!(*item)->with_subselect && (*item)->const_item())
   {
     TABLE *table= field->table;
-    ulonglong orig_sql_mode= thd->variables.sql_mode;
+    sql_mode_t orig_sql_mode= thd->variables.sql_mode;
     enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
     my_bitmap_map *old_maps[2];
     ulonglong UNINIT_VAR(orig_field_val); /* original field value if valid */

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2010-10-31 23:37:14 +0000
+++ b/sql/item_timefunc.h	2010-11-29 16:27:58 +0000
@@ -1041,7 +1041,7 @@ class Item_func_str_to_date :public Item
   date_time_format_types cached_format_type;
   timestamp_type cached_timestamp_type;
   bool const_item;
-  ulonglong sql_mode;
+  sql_mode_t sql_mode;
 public:
   Item_func_str_to_date(Item *a, Item *b)
     :Item_str_func(a, b), const_item(false)

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-11-29 11:28:55 +0000
+++ b/sql/log_event.cc	2010-11-29 16:55:45 +0000
@@ -93,11 +93,8 @@ TYPELIB binlog_checksum_typelib=
    replication event checksum is introduced in the following "checksum-home" version.
    The checksum-aware servers extract FD's version to decide whether the FD event
    carries checksum info.
-
-   TODO: correct the constant when it has been determined 
-   (which main tree to push and when) 
 */
-const uchar checksum_version_split[3]= {5, 1, 46};
+const uchar checksum_version_split[3]= {5, 6, 1};
 const ulong checksum_version_product=
   (checksum_version_split[0] * 256 + checksum_version_split[1]) * 256 +
   checksum_version_split[2];
@@ -2498,7 +2495,7 @@ bool Query_log_event::write(IO_CACHE* fi
   if (sql_mode_inited)
   {
     *start++= Q_SQL_MODE_CODE;
-    int8store(start, (ulonglong)sql_mode);
+    int8store(start, sql_mode);
     start+= 8;
   }
   if (catalog_len) // i.e. this var is inited (false for 4.0 events)
@@ -2827,7 +2824,7 @@ Query_log_event::Query_log_event(THD* th
   else
     cache_type= Log_event::EVENT_STMT_CACHE;
   DBUG_ASSERT(cache_type != Log_event::EVENT_INVALID_CACHE);
-  DBUG_PRINT("info",("Query_log_event has flags2: %lu  sql_mode: %lu",
+  DBUG_PRINT("info",("Query_log_event has flags2: %lu  sql_mode: %llu",
                      (ulong) flags2, sql_mode));
 }
 #endif /* MYSQL_CLIENT */
@@ -3042,7 +3039,7 @@ Query_log_event::Query_log_event(const c
 #endif
       CHECK_SPACE(pos, end, 8);
       sql_mode_inited= 1;
-      sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong
+      sql_mode= uint8korr(pos);
       DBUG_PRINT("info",("In Query_log_event, read sql_mode: %s",
 			 llstr(sql_mode, buff)));
       pos+= 8;
@@ -3515,8 +3512,8 @@ int Query_log_event::do_apply_event(Rela
       */
       if (sql_mode_inited)
         thd->variables.sql_mode=
-          (ulong) ((thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) |
-                   (sql_mode & ~(ulong) MODE_NO_DIR_IN_CREATE));
+          (sql_mode_t) ((thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) |
+                       (sql_mode & ~(ulonglong) MODE_NO_DIR_IN_CREATE));
       if (charset_inited)
       {
         if (rli->cached_charset_compare(charset))

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2010-11-16 12:14:06 +0000
+++ b/sql/log_event.h	2010-11-29 16:27:58 +0000
@@ -51,6 +51,7 @@
 
 /* Forward declarations */
 class String;
+typedef ulonglong sql_mode_t;
 
 #define PREFIX_SQL_LOAD "SQL_LOAD-"
 
@@ -695,7 +696,7 @@ typedef struct st_print_event_info
   bool flags2_inited;
   uint32 flags2;
   bool sql_mode_inited;
-  ulong sql_mode;		/* must be same as THD.variables.sql_mode */
+  sql_mode_t sql_mode;		/* must be same as THD.variables.sql_mode */
   ulong auto_increment_increment, auto_increment_offset;
   bool charset_inited;
   char charset[6]; // 3 variables, each of them storable in 2 bytes
@@ -1740,7 +1741,7 @@ public:
 
   uint32 flags2;
   /* In connections sql_mode is 32 bits now but will be 64 bits soon */
-  ulong sql_mode;
+  sql_mode_t sql_mode;
   ulong auto_increment_increment, auto_increment_offset;
   char charset[6];
   uint time_zone_len; /* 0 means uninited */

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-11-29 11:28:55 +0000
+++ b/sql/mysqld.cc	2010-11-30 19:09:11 +0000
@@ -2428,7 +2428,7 @@ the thread stack. Please read http://dev
 
   if (!(test_flags & TEST_NO_STACKTRACE))
   {
-    fprintf(stderr, "thd: 0x%lx\n",(long) thd);
+    fprintf(stderr, "Thread pointer: 0x%lx\n", (long) thd);
     fprintf(stderr, "Attempting backtrace. You can use the following "
                     "information to find out\nwhere mysqld died. If "
                     "you see no messages after this, something went\n"
@@ -2456,11 +2456,13 @@ the thread stack. Please read http://dev
       kreason= "KILLED_NO_VALUE";
       break;
     }
-    fprintf(stderr, "Trying to get some variables.\n\
-Some pointers may be invalid and cause the dump to abort...\n");
-    my_safe_print_str("thd->query", thd->query(), 1024);
-    fprintf(stderr, "thd->thread_id=%lu\n", (ulong) thd->thread_id);
-    fprintf(stderr, "thd->killed=%s\n", kreason);
+    fprintf(stderr, "\nTrying to get some variables.\n"
+                    "Some pointers may be invalid and cause the dump to abort.\n");
+    fprintf(stderr, "Query (%p): ", thd->query());
+    my_safe_print_str(thd->query(), min(1024, thd->query_length()));
+    fprintf(stderr, "Connection ID (thread ID): %lu\n", (ulong) thd->thread_id);
+    fprintf(stderr, "Status: %s\n", kreason);
+    fputc('\n', stderr);
   }
   fprintf(stderr, "\
 The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains\n\
@@ -6309,6 +6311,24 @@ static int show_slave_received_heartbeat
   return 0;
 }
 
+static int show_slave_last_heartbeat(THD *thd, SHOW_VAR *var, char *buff)
+{
+  MYSQL_TIME received_heartbeat_time;
+  mysql_mutex_lock(&LOCK_active_mi);
+  if (active_mi)
+  {
+    var->type= SHOW_CHAR;
+    var->value= buff;
+    thd->variables.time_zone->gmt_sec_to_TIME(&received_heartbeat_time, 
+      active_mi->last_heartbeat);
+    my_datetime_to_str(&received_heartbeat_time, buff);
+  }
+  else
+    var->type= SHOW_UNDEF;
+  mysql_mutex_unlock(&LOCK_active_mi);
+  return 0;
+}
+
 static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff)
 {
   mysql_mutex_lock(&LOCK_active_mi);
@@ -6690,6 +6710,7 @@ SHOW_VAR status_vars[]= {
   {"Slave_retried_transactions",(char*) &show_slave_retried_trans, SHOW_FUNC},
   {"Slave_heartbeat_period",   (char*) &show_heartbeat_period, SHOW_FUNC},
   {"Slave_received_heartbeats",(char*) &show_slave_received_heartbeats, SHOW_FUNC},
+  {"Slave_last_heartbeat",     (char*) &show_slave_last_heartbeat, SHOW_FUNC},
   {"Slave_running",            (char*) &show_slave_running,     SHOW_FUNC},
 #endif
   {"Slow_launch_threads",      (char*) &slow_launch_threads,    SHOW_LONG},

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-11-26 13:46:21 +0000
+++ b/sql/opt_range.cc	2010-11-29 16:27:58 +0000
@@ -5721,7 +5721,7 @@ get_mm_leaf(RANGE_OPT_PARAM *param, Item
   SEL_ARG *tree= 0;
   MEM_ROOT *alloc= param->mem_root;
   uchar *str;
-  ulonglong orig_sql_mode;
+  sql_mode_t orig_sql_mode;
   int err;
   DBUG_ENTER("get_mm_leaf");
 

=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc	2010-10-01 16:11:50 +0000
+++ b/sql/partition_info.cc	2010-11-29 16:27:58 +0000
@@ -2156,7 +2156,7 @@ bool partition_info::fix_column_value_fu
       {
         uchar *val_ptr;
         uint len= field->pack_length();
-        ulong save_sql_mode;
+        sql_mode_t save_sql_mode;
         bool save_got_warning;
 
         if (!(column_item= get_column_item(column_item,

=== modified file 'sql/rpl_mi.cc'
--- a/sql/rpl_mi.cc	2010-11-29 11:28:55 +0000
+++ b/sql/rpl_mi.cc	2010-11-29 18:35:56 +0000
@@ -87,7 +87,7 @@ Master_info::Master_info(PSI_mutex_key *
    ssl(0), ssl_verify_server_cert(0),
    port(MYSQL_PORT), connect_retry(DEFAULT_CONNECT_RETRY),
    clock_diff_with_master(0), heartbeat_period(0),
-   received_heartbeats(0), master_id(0),
+   received_heartbeats(0), last_heartbeat(0), master_id(0),
    checksum_alg_before_fd(BINLOG_CHECKSUM_ALG_UNDEF),
    retry_count(master_retry_count)
 {

=== modified file 'sql/rpl_mi.h'
--- a/sql/rpl_mi.h	2010-11-29 11:28:55 +0000
+++ b/sql/rpl_mi.h	2010-11-29 18:35:56 +0000
@@ -96,6 +96,7 @@ class Master_info : public Rpl_info
   long clock_diff_with_master;
   float heartbeat_period;         // interface with CHANGE MASTER or master.info
   ulonglong received_heartbeats;  // counter of received heartbeat events
+  time_t last_heartbeat;
   Server_ids *ignore_server_ids;
   ulong master_id;
   /*

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2010-11-29 11:28:55 +0000
+++ b/sql/rpl_slave.cc	2010-11-29 18:35:56 +0000
@@ -4558,6 +4558,7 @@ static int queue_event(Master_info* mi,c
       goto err;
     }
     mi->received_heartbeats++;
+    mi->last_heartbeat= my_time(0);
     /* 
        compare local and event's versions of log_file, log_pos.
        

=== modified file 'sql/set_var.h'
--- a/sql/set_var.h	2010-11-29 11:28:55 +0000
+++ b/sql/set_var.h	2010-11-29 18:48:29 +0000
@@ -309,8 +309,8 @@ int sql_set_variables(THD *thd, List<set
 
 bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type);
 
-ulong expand_sql_mode(ulonglong sql_mode);
-bool sql_mode_string_representation(THD *thd, ulong sql_mode, LEX_STRING *ls);
+sql_mode_t expand_sql_mode(sql_mode_t sql_mode);
+bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls);
 
 extern sys_var *Sys_autocommit_ptr;
 

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2010-11-18 16:34:56 +0000
+++ b/sql/sp.cc	2010-11-29 16:27:58 +0000
@@ -42,11 +42,11 @@ create_string(THD *thd, String *buf,
 	      st_sp_chistics *chistics,
               const LEX_STRING *definer_user,
               const LEX_STRING *definer_host,
-              ulong sql_mode);
+              sql_mode_t sql_mode);
 
 static int
 db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
-                ulong sql_mode, const char *params, const char *returns,
+                sql_mode_t sql_mode, const char *params, const char *returns,
                 const char *body, st_sp_chistics &chistics,
                 const char *definer, longlong created, longlong modified,
                 Stored_program_creation_ctx *creation_ctx);
@@ -539,7 +539,7 @@ db_find_routine(THD *thd, int type, sp_n
   char buff[65];
   String str(buff, sizeof(buff), &my_charset_bin);
   bool saved_time_zone_used= thd->time_zone_used;
-  ulong sql_mode, saved_mode= thd->variables.sql_mode;
+  sql_mode_t sql_mode, saved_mode= thd->variables.sql_mode;
   Open_tables_backup open_tables_state_backup;
   Stored_program_creation_ctx *creation_ctx;
 
@@ -636,7 +636,7 @@ db_find_routine(THD *thd, int type, sp_n
   modified= table->field[MYSQL_PROC_FIELD_MODIFIED]->val_int();
   created= table->field[MYSQL_PROC_FIELD_CREATED]->val_int();
 
-  sql_mode= (ulong) table->field[MYSQL_PROC_FIELD_SQL_MODE]->val_int();
+  sql_mode= (sql_mode_t) table->field[MYSQL_PROC_FIELD_SQL_MODE]->val_int();
 
   table->field[MYSQL_PROC_FIELD_COMMENT]->val_str(&str, &str);
 
@@ -713,11 +713,11 @@ Silence_deprecated_warning::handle_condi
     @retval   0                     error
 */
 
-static sp_head *sp_compile(THD *thd, String *defstr, ulong sql_mode,
+static sp_head *sp_compile(THD *thd, String *defstr, sql_mode_t sql_mode,
                            Stored_program_creation_ctx *creation_ctx)
 {
   sp_head *sp;
-  ulong old_sql_mode= thd->variables.sql_mode;
+  sql_mode_t old_sql_mode= thd->variables.sql_mode;
   ha_rows old_select_limit= thd->variables.select_limit;
   sp_rcontext *old_spcont= thd->spcont;
   Silence_deprecated_warning warning_handler;
@@ -758,7 +758,7 @@ static sp_head *sp_compile(THD *thd, Str
 
 static int
 db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
-                ulong sql_mode, const char *params, const char *returns,
+                sql_mode_t sql_mode, const char *params, const char *returns,
                 const char *body, st_sp_chistics &chistics,
                 const char *definer, longlong created, longlong modified,
                 Stored_program_creation_ctx *creation_ctx)
@@ -924,7 +924,7 @@ sp_create_routine(THD *thd, int type, sp
   int ret;
   TABLE *table;
   char definer[USER_HOST_BUFF_SIZE];
-  ulong saved_mode= thd->variables.sql_mode;
+  sql_mode_t saved_mode= thd->variables.sql_mode;
   MDL_key::enum_mdl_namespace mdl_type= type == TYPE_ENUM_FUNCTION ?
                                         MDL_key::FUNCTION : MDL_key::PROCEDURE;
 
@@ -2093,9 +2093,9 @@ create_string(THD *thd, String *buf,
               st_sp_chistics *chistics,
               const LEX_STRING *definer_user,
               const LEX_STRING *definer_host,
-              ulong sql_mode)
+              sql_mode_t sql_mode)
 {
-  ulong old_sql_mode= thd->variables.sql_mode;
+  sql_mode_t old_sql_mode= thd->variables.sql_mode;
   /* Make some room to begin with */
   if (buf->alloc(100 + dblen + 1 + namelen + paramslen + returnslen + bodylen +
 		 chistics->comment.length + 10 /* length of " DEFINER= "*/ +
@@ -2177,7 +2177,7 @@ create_string(THD *thd, String *buf,
 
 sp_head *
 sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
-                               String *name, ulong sql_mode, int type,
+                               String *name, sql_mode_t sql_mode, int type,
                                const char *returns, const char *params,
                                bool *free_sp_head)
 {

=== modified file 'sql/sp.h'
--- a/sql/sp.h	2010-11-18 16:34:56 +0000
+++ b/sql/sp.h	2010-11-29 16:27:58 +0000
@@ -188,7 +188,7 @@ TABLE *open_proc_table_for_read(THD *thd
 
 sp_head *
 sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
-                               String *name, ulong sql_mode, int type,
+                               String *name, sql_mode_t sql_mode, int type,
                                const char *returns, const char *params,
                                bool *free_sp_head);
 

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2010-12-02 06:57:30 +0000
+++ b/sql/sp_head.cc	2010-12-02 08:07:11 +0000
@@ -1204,7 +1204,7 @@ sp_head::execute(THD *thd, bool merge_da
   sp_rcontext *ctx= thd->spcont;
   bool err_status= FALSE;
   uint ip= 0;
-  ulong save_sql_mode;
+  sql_mode_t save_sql_mode;
   bool save_abort_on_warning;
   Query_arena *old_arena;
   /* per-instruction arena */
@@ -2479,7 +2479,7 @@ sp_head::do_cont_backpatch()
 
 void
 sp_head::set_info(longlong created, longlong modified,
-                  st_sp_chistics *chistics, ulong sql_mode)
+                  st_sp_chistics *chistics, sql_mode_t sql_mode)
 {
   m_created= created;
   m_modified= modified;

=== modified file 'sql/sp_head.h'
--- a/sql/sp_head.h	2010-11-16 12:14:06 +0000
+++ b/sql/sp_head.h	2010-11-29 16:27:58 +0000
@@ -172,7 +172,7 @@ public:
 
   const char *m_tmp_query;	///< Temporary pointer to sub query string
   st_sp_chistics *m_chistics;
-  ulong m_sql_mode;		///< For SHOW CREATE and execution
+  sql_mode_t m_sql_mode;        ///< For SHOW CREATE and execution
   LEX_STRING m_qname;		///< db.name
   bool m_explicit_name;         ///< Prepend the db name? */
   LEX_STRING m_db;
@@ -394,7 +394,7 @@ public:
                              Create_field *field_def);
 
   void set_info(longlong created, longlong modified,
-		st_sp_chistics *chistics, ulong sql_mode);
+		st_sp_chistics *chistics, sql_mode_t sql_mode);
 
   void set_definer(const char *definer, uint definerlen);
   void set_definer(const LEX_STRING *user_name, const LEX_STRING *host_name);

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2010-11-26 15:45:26 +0000
+++ b/sql/sql_acl.cc	2010-11-29 16:27:58 +0000
@@ -703,7 +703,7 @@ static my_bool acl_load(THD *thd, TABLE_
   bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
   char tmp_name[NAME_LEN+1];
   int password_length;
-  ulong old_sql_mode= thd->variables.sql_mode;
+  sql_mode_t old_sql_mode= thd->variables.sql_mode;
   DBUG_ENTER("acl_load");
 
   thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
@@ -4290,7 +4290,7 @@ static my_bool grant_load(THD *thd, TABL
   bool check_no_resolve= specialflag & SPECIAL_NO_RESOLVE;
   MEM_ROOT **save_mem_root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**,
                                                            THR_MALLOC);
-  ulong old_sql_mode= thd->variables.sql_mode;
+  sql_mode_t old_sql_mode= thd->variables.sql_mode;
   DBUG_ENTER("grant_load");
 
   thd->variables.sql_mode&= ~MODE_PAD_CHAR_TO_FULL_LENGTH;
@@ -6497,7 +6497,7 @@ bool mysql_drop_user(THD *thd, List <LEX
   List_iterator <LEX_USER> user_list(list);
   TABLE_LIST tables[GRANT_TABLES];
   bool some_users_deleted= FALSE;
-  ulong old_sql_mode= thd->variables.sql_mode;
+  sql_mode_t old_sql_mode= thd->variables.sql_mode;
   bool save_binlog_row_based;
   DBUG_ENTER("mysql_drop_user");
 

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2010-10-12 10:15:42 +0000
+++ b/sql/sql_cache.cc	2010-11-29 16:27:58 +0000
@@ -1222,7 +1222,7 @@ void Query_cache::store_query(THD *thd, 
     DBUG_PRINT("qcache", ("\
 long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
 CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
-sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
+sql mode: 0x%llx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
 def_week_frmt: %lu, in_trans: %d, autocommit: %d",
                           (int)flags.client_long_flag,
                           (int)flags.client_protocol_41,
@@ -1564,7 +1564,7 @@ Query_cache::send_result_to_client(THD *
   DBUG_PRINT("qcache", ("\
 long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
 CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
-sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
+sql mode: 0x%llx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
 def_week_frmt: %lu, in_trans: %d, autocommit: %d",
                           (int)flags.client_long_flag,
                           (int)flags.client_protocol_41,

=== modified file 'sql/sql_cache.h'
--- a/sql/sql_cache.h	2010-07-02 02:58:51 +0000
+++ b/sql/sql_cache.h	2010-11-29 16:27:58 +0000
@@ -25,6 +25,7 @@ class Time_zone;
 struct LEX;
 struct TABLE;
 typedef struct st_changed_table_list CHANGED_TABLE_LIST;
+typedef ulonglong sql_mode_t;
 
 /* Query cache */
 
@@ -532,7 +533,7 @@ struct Query_cache_query_flags
   uint collation_connection_num;
   ha_rows limit;
   Time_zone *time_zone;
-  ulong sql_mode;
+  sql_mode_t sql_mode;
   ulong max_sort_length;
   ulong group_concat_max_len;
   ulong default_week_format;

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-11-29 14:13:07 +0000
+++ b/sql/sql_class.h	2010-12-02 08:07:11 +0000
@@ -399,6 +399,8 @@ class Time_zone;
 
 #define THD_CHECK_SENTRY(thd) DBUG_ASSERT(thd->dbug_sentry == THD_SENTRY_MAGIC)
 
+typedef ulonglong sql_mode_t;
+
 typedef struct system_variables
 {
   /*
@@ -420,7 +422,7 @@ typedef struct system_variables
   ulonglong long_query_time;
   /* A bitmap for switching optimizations on/off */
   ulonglong optimizer_switch;
-  ulonglong sql_mode; ///< which non-standard SQL behaviour should be enabled
+  sql_mode_t sql_mode; ///< which non-standard SQL behaviour should be enabled
   ulonglong option_bits; ///< OPTION_xxx constants, e.g. OPTION_PROFILING
   ha_rows select_limit;
   ha_rows max_join_size;

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2010-11-29 14:13:07 +0000
+++ b/sql/sql_insert.cc	2010-12-02 08:07:11 +0000
@@ -1825,7 +1825,7 @@ public:
   char *record;
   enum_duplicates dup;
   time_t start_time;
-  ulong sql_mode;
+  sql_mode_t sql_mode;
   bool auto_increment_field_not_null;
   bool query_start_used, ignore, log_query, binlog_rows_query_log_events;
   bool stmt_depends_on_first_successful_insert_id_in_prev_stmt;

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-11-29 11:28:55 +0000
+++ b/sql/sql_select.cc	2010-11-30 10:35:29 +0000
@@ -6586,11 +6586,18 @@ public:
       best_loose_scan_records - same
       best_max_loose_keypart - same
       best_loose_scan_start_key - same
-      Not initializing them causes compiler warnings, but using UNINIT_VAR()
-      would cause a 2% CPU time loss in a 20-table plan search.
-      So, until UNINIT_VAR(x) doesn't do x=0 for any C++ code, it's not used
-      here.
-    */
+      Not initializing them causes compiler warnings with g++ at -O1 or higher,
+      but initializing them would cause a 2% CPU time loss in a 20-table plan
+      search. So we initialize only if warnings would stop the build.
+    */
+#ifdef COMPILE_FLAG_WERROR
+    bound_sj_equalities=       0;
+    quick_max_loose_keypart=   0;
+    best_loose_scan_key=       0;
+    best_loose_scan_records=   0;
+    best_max_loose_keypart=    0;
+    best_loose_scan_start_key= NULL;
+#endif
   }
 
   void init(JOIN *join, JOIN_TAB *s, table_map remaining_tables)

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2010-11-05 22:19:41 +0000
+++ b/sql/sql_select.h	2010-11-29 16:27:58 +0000
@@ -2070,7 +2070,7 @@ public:
     enum store_key_result result;
     THD *thd= to_field->table->in_use;
     enum_check_fields saved_count_cuted_fields= thd->count_cuted_fields;
-    ulonglong sql_mode= thd->variables.sql_mode;
+    sql_mode_t sql_mode= thd->variables.sql_mode;
     thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
 
     thd->count_cuted_fields= CHECK_FIELD_IGNORE;

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2010-11-29 14:13:07 +0000
+++ b/sql/sql_show.cc	2010-12-02 08:07:11 +0000
@@ -3795,6 +3795,7 @@ static int get_schema_tables_record(THD 
 {
   const char *tmp_buff;
   MYSQL_TIME time;
+  int info_error= 0;
   CHARSET_INFO *cs= system_charset_info;
   DBUG_ENTER("get_schema_tables_record");
 
@@ -3802,22 +3803,21 @@ static int get_schema_tables_record(THD 
   table->field[0]->store(STRING_WITH_LEN("def"), cs);
   table->field[1]->store(db_name->str, db_name->length, cs);
   table->field[2]->store(table_name->str, table_name->length, cs);
+
   if (res)
   {
-    /*
-      there was errors during opening tables
-    */
-    const char *error= thd->is_error() ? thd->stmt_da->message() : "";
+    /* There was a table open error, so set the table type and return */
     if (tables->view)
       table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
     else if (tables->schema_table)
       table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
     else
       table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
-    table->field[20]->store(error, strlen(error), cs);
-    thd->clear_error();
+
+    goto err;
   }
-  else if (tables->view)
+
+  if (tables->view)
   {
     table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
     table->field[20]->store(STRING_WITH_LEN("VIEW"), cs);
@@ -3832,6 +3832,7 @@ static int get_schema_tables_record(THD 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
     bool is_partitioned= FALSE;
 #endif
+
     if (share->tmp_table == SYSTEM_TMP_TABLE)
       table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
     else if (share->tmp_table)
@@ -3845,6 +3846,9 @@ static int get_schema_tables_record(THD 
         continue;
       table->field[i]->set_notnull();
     }
+
+    /* Collect table info from the table share */
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
     if (share->db_type() == partition_hton &&
         share->partition_info_str_len)
@@ -3853,62 +3857,82 @@ static int get_schema_tables_record(THD 
       is_partitioned= TRUE;
     }
 #endif
+
     tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
     table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
     table->field[5]->store((longlong) share->frm_version, TRUE);
 
     ptr=option_buff;
+
     if (share->min_rows)
     {
       ptr=strmov(ptr," min_rows=");
       ptr=longlong10_to_str(share->min_rows,ptr,10);
     }
+
     if (share->max_rows)
     {
       ptr=strmov(ptr," max_rows=");
       ptr=longlong10_to_str(share->max_rows,ptr,10);
     }
+
     if (share->avg_row_length)
     {
       ptr=strmov(ptr," avg_row_length=");
       ptr=longlong10_to_str(share->avg_row_length,ptr,10);
     }
+
     if (share->db_create_options & HA_OPTION_PACK_KEYS)
       ptr=strmov(ptr," pack_keys=1");
+
     if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
       ptr=strmov(ptr," pack_keys=0");
+
     /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
     if (share->db_create_options & HA_OPTION_CHECKSUM)
       ptr=strmov(ptr," checksum=1");
+
     if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
       ptr=strmov(ptr," delay_key_write=1");
+
     if (share->row_type != ROW_TYPE_DEFAULT)
       ptr=strxmov(ptr, " row_format=", 
                   ha_row_type[(uint) share->row_type],
                   NullS);
+
     if (share->key_block_size)
     {
       ptr= strmov(ptr, " KEY_BLOCK_SIZE=");
       ptr= longlong10_to_str(share->key_block_size, ptr, 10);
     }
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
     if (is_partitioned)
       ptr= strmov(ptr, " partitioned");
 #endif
+
     table->field[19]->store(option_buff+1,
                             (ptr == option_buff ? 0 : 
                              (uint) (ptr-option_buff)-1), cs);
 
     tmp_buff= (share->table_charset ?
                share->table_charset->name : "default");
+
     table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
 
     if (share->comment.str)
       table->field[20]->store(share->comment.str, share->comment.length, cs);
 
+    /* Collect table info from the storage engine  */
+
     if(file)
     {
-      file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO);
+      /* If info() fails, then there's nothing else to do */
+      if ((info_error= file->info(HA_STATUS_VARIABLE |
+                                  HA_STATUS_TIME |
+                                  HA_STATUS_AUTO)) != 0)
+        goto err;
+
       enum row_type row_type = file->get_row_type();
       switch (row_type) {
       case ROW_TYPE_NOT_USED:
@@ -3937,7 +3961,9 @@ static int get_schema_tables_record(THD 
         tmp_buff= "Paged";
         break;
       }
+
       table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
+
       if (!tables->schema_table)
       {
         table->field[7]->store((longlong) file->stats.records, TRUE);
@@ -3986,6 +4012,26 @@ static int get_schema_tables_record(THD 
       }
     }
   }
+
+err:
+  if (res || info_error)
+  {
+    /*
+      If an error was encountered, push a warning, set the TABLE COMMENT
+      column with the error text, and clear the error so that the operation
+      can continue.
+    */
+    const char *error= thd->is_error() ? thd->stmt_da->message() : "";
+    table->field[20]->store(error, strlen(error), cs);
+
+    if (thd->is_error())
+    {
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                   thd->stmt_da->sql_errno(), thd->stmt_da->message());
+      thd->clear_error();
+    }
+  }
+
   DBUG_RETURN(schema_table_store_record(thd, table));
 }
 
@@ -4487,7 +4533,7 @@ bool store_schema_params(THD *thd, TABLE
               &returns);
 
   sp= sp_load_for_information_schema(thd, proc_table, &sp_db, &sp_name,
-                                     (ulong) proc_table->
+                                     (sql_mode_t) proc_table->
                                      field[MYSQL_PROC_FIELD_SQL_MODE]->val_int(),
                                      routine_type,
                                      returns.c_ptr_safe(),
@@ -4643,7 +4689,7 @@ bool store_schema_proc(THD *thd, TABLE *
         bool free_sp_head;
         proc_table->field[MYSQL_PROC_FIELD_RETURNS]->val_str(&returns);
         sp= sp_load_for_information_schema(thd, proc_table, &sp_db, &sp_name,
-                                           (ulong) proc_table->
+                                           (sql_mode_t) proc_table->
                                            field[MYSQL_PROC_FIELD_SQL_MODE]->
                                            val_int(),
                                            TYPE_ENUM_FUNCTION,
@@ -5104,7 +5150,7 @@ static bool store_trigger(THD *thd, TABL
                           enum trg_event_type event,
                           enum trg_action_time_type timing,
                           LEX_STRING *trigger_stmt,
-                          ulong sql_mode,
+                          sql_mode_t sql_mode,
                           LEX_STRING *definer_buffer,
                           LEX_STRING *client_cs_name,
                           LEX_STRING *connection_cl_name,
@@ -5173,7 +5219,7 @@ static int get_schema_triggers_record(TH
       {
         LEX_STRING trigger_name;
         LEX_STRING trigger_stmt;
-        ulong sql_mode;
+        sql_mode_t sql_mode;
         char definer_holder[USER_HOST_BUFF_SIZE];
         LEX_STRING definer_buffer;
         LEX_STRING client_cs_name;
@@ -7552,7 +7598,7 @@ static bool show_create_trigger_impl(THD
   List<Item> fields;
 
   LEX_STRING trg_name;
-  ulonglong trg_sql_mode;
+  sql_mode_t trg_sql_mode;
   LEX_STRING trg_sql_mode_str;
   LEX_STRING trg_sql_original_stmt;
   LEX_STRING trg_client_cs_name;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-11-29 14:13:07 +0000
+++ b/sql/sql_table.cc	2010-12-02 08:07:11 +0000
@@ -7071,7 +7071,7 @@ copy_data_between_tables(TABLE *from,TAB
   List<Item>   all_fields;
   ha_rows examined_rows;
   bool auto_increment_field_copied= 0;
-  ulong save_sql_mode;
+  sql_mode_t save_sql_mode;
   ulonglong prev_insert_id;
   DBUG_ENTER("copy_data_between_tables");
 

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2010-11-18 16:34:56 +0000
+++ b/sql/sql_trigger.cc	2010-11-29 16:27:58 +0000
@@ -576,7 +576,7 @@ bool Table_triggers_list::create_trigger
   LEX_STRING *trg_def;
   LEX_STRING definer_user;
   LEX_STRING definer_host;
-  ulonglong *trg_sql_mode;
+  sql_mode_t *trg_sql_mode;
   char trg_definer_holder[USER_HOST_BUFF_SIZE];
   LEX_STRING *trg_definer;
   Item_trigger_field *trg_field;
@@ -717,7 +717,7 @@ bool Table_triggers_list::create_trigger
   if (!(trg_def= alloc_lex_string(&table->mem_root)) ||
       definitions_list.push_back(trg_def, &table->mem_root) ||
 
-      !(trg_sql_mode= alloc_type<ulonglong>(&table->mem_root)) ||
+      !(trg_sql_mode= alloc_type<sql_mode_t>(&table->mem_root)) ||
       definition_modes_list.push_back(trg_sql_mode, &table->mem_root) ||
 
       !(trg_definer= alloc_lex_string(&table->mem_root)) ||
@@ -932,7 +932,7 @@ bool Table_triggers_list::drop_trigger(T
 
   List_iterator_fast<LEX_STRING> it_name(names_list);
 
-  List_iterator<ulonglong> it_mod(definition_modes_list);
+  List_iterator<sql_mode_t> it_mod(definition_modes_list);
   List_iterator<LEX_STRING> it_def(definitions_list);
   List_iterator<LEX_STRING> it_definer(definers_list);
   List_iterator<LEX_STRING> it_client_cs_name(client_cs_names);
@@ -1138,7 +1138,7 @@ bool Table_triggers_list::check_n_load(T
 
       List_iterator_fast<LEX_STRING> it(triggers->definitions_list);
       LEX_STRING *trg_create_str;
-      ulonglong *trg_sql_mode;
+      sql_mode_t *trg_sql_mode;
 
       if (triggers->definition_modes_list.is_empty() &&
           !triggers->definitions_list.is_empty())
@@ -1149,7 +1149,7 @@ bool Table_triggers_list::check_n_load(T
           We use one mode (current) for all triggers, because we have not
           information about mode in old format.
         */
-        if (!(trg_sql_mode= alloc_type<ulonglong>(&table->mem_root)))
+        if (!(trg_sql_mode= alloc_type<sql_mode_t>(&table->mem_root)))
         {
           DBUG_RETURN(1); // EOM
         }
@@ -1286,14 +1286,14 @@ bool Table_triggers_list::check_n_load(T
       if (!names_only && triggers->prepare_record1_accessors(table))
         DBUG_RETURN(1);
 
-      List_iterator_fast<ulonglong> itm(triggers->definition_modes_list);
+      List_iterator_fast<sql_mode_t> itm(triggers->definition_modes_list);
       List_iterator_fast<LEX_STRING> it_definer(triggers->definers_list);
       List_iterator_fast<LEX_STRING> it_client_cs_name(triggers->client_cs_names);
       List_iterator_fast<LEX_STRING> it_connection_cl_name(triggers->connection_cl_names);
       List_iterator_fast<LEX_STRING> it_db_cl_name(triggers->db_cl_names);
       LEX *old_lex= thd->lex, lex;
       sp_rcontext *save_spcont= thd->spcont;
-      ulong save_sql_mode= thd->variables.sql_mode;
+      sql_mode_t save_sql_mode= thd->variables.sql_mode;
       LEX_STRING *on_table_name;
 
       thd->lex= &lex;
@@ -1307,7 +1307,7 @@ bool Table_triggers_list::check_n_load(T
         trg_sql_mode= itm++;
         LEX_STRING *trg_definer= it_definer++;
 
-        thd->variables.sql_mode= (ulong)*trg_sql_mode;
+        thd->variables.sql_mode= *trg_sql_mode;
 
         Parser_state parser_state;
         if (parser_state.init(thd, trg_create_str->str, trg_create_str->length))
@@ -1346,7 +1346,7 @@ bool Table_triggers_list::check_n_load(T
         sp= triggers->bodies[event][action_time]= lex.sphead;
         lex.sphead= NULL; /* Prevent double cleanup. */
 
-        sp->set_info(0, 0, &lex.sp_chistics, (ulong) *trg_sql_mode);
+        sp->set_info(0, 0, &lex.sp_chistics, *trg_sql_mode);
         sp->set_creation_ctx(creation_ctx);
 
         if (!trg_definer->length)
@@ -1499,7 +1499,7 @@ bool Table_triggers_list::get_trigger_in
                                            trg_action_time_type time_type,
                                            LEX_STRING *trigger_name,
                                            LEX_STRING *trigger_stmt,
-                                           ulong *sql_mode,
+                                           sql_mode_t *sql_mode,
                                            LEX_STRING *definer,
                                            LEX_STRING *client_cs_name,
                                            LEX_STRING *connection_cl_name,
@@ -1545,14 +1545,14 @@ bool Table_triggers_list::get_trigger_in
 void Table_triggers_list::get_trigger_info(THD *thd,
                                            int trigger_idx,
                                            LEX_STRING *trigger_name,
-                                           ulonglong *sql_mode,
+                                           sql_mode_t *sql_mode,
                                            LEX_STRING *sql_original_stmt,
                                            LEX_STRING *client_cs_name,
                                            LEX_STRING *connection_cl_name,
                                            LEX_STRING *db_cl_name)
 {
   List_iterator_fast<LEX_STRING> it_trigger_name(names_list);
-  List_iterator_fast<ulonglong> it_sql_mode(definition_modes_list);
+  List_iterator_fast<sql_mode_t> it_sql_mode(definition_modes_list);
   List_iterator_fast<LEX_STRING> it_sql_orig_stmt(definitions_list);
   List_iterator_fast<LEX_STRING> it_client_cs_name(client_cs_names);
   List_iterator_fast<LEX_STRING> it_connection_cl_name(connection_cl_names);
@@ -1740,7 +1740,7 @@ Table_triggers_list::change_table_name_i
 {
   char path_buff[FN_REFLEN];
   LEX_STRING *def, *on_table_name, new_def;
-  ulong save_sql_mode= thd->variables.sql_mode;
+  sql_mode_t save_sql_mode= thd->variables.sql_mode;
   List_iterator_fast<LEX_STRING> it_def(definitions_list);
   List_iterator_fast<LEX_STRING> it_on_table_name(on_table_names_list);
   List_iterator_fast<ulonglong> it_mode(definition_modes_list);
@@ -1753,7 +1753,7 @@ Table_triggers_list::change_table_name_i
   while ((def= it_def++))
   {
     on_table_name= it_on_table_name++;
-    thd->variables.sql_mode= (ulong) *(it_mode++);
+    thd->variables.sql_mode= *(it_mode++);
 
     /* Construct CREATE TRIGGER statement with new table name. */
     buff.length(0);

=== modified file 'sql/sql_trigger.h'
--- a/sql/sql_trigger.h	2010-10-01 10:23:16 +0000
+++ b/sql/sql_trigger.h	2010-11-29 16:27:58 +0000
@@ -136,7 +136,7 @@ public:
   bool get_trigger_info(THD *thd, trg_event_type event,
                         trg_action_time_type time_type,
                         LEX_STRING *trigger_name, LEX_STRING *trigger_stmt,
-                        ulong *sql_mode,
+                        sql_mode_t *sql_mode,
                         LEX_STRING *definer,
                         LEX_STRING *client_cs_name,
                         LEX_STRING *connection_cl_name,
@@ -145,7 +145,7 @@ public:
   void get_trigger_info(THD *thd,
                         int trigger_idx,
                         LEX_STRING *trigger_name,
-                        ulonglong *sql_mode,
+                        sql_mode_t *sql_mode,
                         LEX_STRING *sql_original_stmt,
                         LEX_STRING *client_cs_name,
                         LEX_STRING *connection_cl_name,

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2010-12-02 06:57:30 +0000
+++ b/sql/sql_view.cc	2010-12-02 08:07:11 +0000
@@ -836,7 +836,7 @@ static int mysql_register_view(THD *thd,
   view_query.length(0);
   is_query.length(0);
   {
-    ulong sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
+    sql_mode_t sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
     thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
 
     lex->unit.print(&view_query, QT_ORDINARY);
@@ -1221,7 +1221,7 @@ bool mysql_make_view(THD *thd, File_pars
     view_select= &lex->select_lex;
     view_select->select_number= ++thd->select_number;
 
-    ulong saved_mode= thd->variables.sql_mode;
+    sql_mode_t saved_mode= thd->variables.sql_mode;
     /* switch off modes which can prevent normal parsing of VIEW
       - MODE_REAL_AS_FLOAT            affect only CREATE TABLE parsing
       + MODE_PIPES_AS_CONCAT          affect expression parsing

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2010-11-29 11:28:55 +0000
+++ b/sql/sys_vars.cc	2010-11-29 16:27:58 +0000
@@ -1939,7 +1939,7 @@ static Sys_var_ulong Sys_sort_buffer(
        VALID_RANGE(MIN_SORT_MEMORY, ULONG_MAX), DEFAULT(MAX_SORT_MEMORY),
        BLOCK_SIZE(1));
 
-export ulong expand_sql_mode(ulonglong sql_mode)
+export sql_mode_t expand_sql_mode(sql_mode_t sql_mode)
 {
   if (sql_mode & MODE_ANSI)
   {
@@ -2025,7 +2025,7 @@ static const char *sql_mode_names[]=
   "PAD_CHAR_TO_FULL_LENGTH",
   0
 };
-export bool sql_mode_string_representation(THD *thd, ulong sql_mode,
+export bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode,
                                            LEX_STRING *ls)
 {
   set_to_string(thd, ls, sql_mode, sql_mode_names);

=== modified file 'storage/perfschema/ha_perfschema.cc'
--- a/storage/perfschema/ha_perfschema.cc	2010-10-21 12:18:25 +0000
+++ b/storage/perfschema/ha_perfschema.cc	2010-12-01 18:46:51 +0000
@@ -339,7 +339,6 @@ int ha_perfschema::delete_all_rows(void)
     result= m_table_share->m_delete_all_rows();
   else
   {
-    my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
     result= HA_ERR_WRONG_COMMAND;
   }
   DBUG_RETURN(result);
@@ -370,7 +369,6 @@ int ha_perfschema::delete_table(const ch
 int ha_perfschema::rename_table(const char * from, const char * to)
 {
   DBUG_ENTER("ha_perfschema::rename_table ");
-  my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
   DBUG_RETURN(HA_ERR_WRONG_COMMAND);
 }
 
@@ -395,7 +393,37 @@ int ha_perfschema::create(const char *na
     This is not a general purpose engine.
     Failure to CREATE TABLE is the expected result.
   */
-  my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
   DBUG_RETURN(HA_ERR_WRONG_COMMAND);
 }
 
+void ha_perfschema::print_error(int error, myf errflag)
+{
+  switch (error)
+  {
+    case HA_ERR_TABLE_NEEDS_UPGRADE:
+      /*
+        The error message for ER_TABLE_NEEDS_UPGRADE refers to REPAIR table,
+        which does not apply to performance schema tables.
+      */
+      my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
+               table_share->db.str, table_share->table_name.str);
+      break;
+    case HA_ERR_WRONG_COMMAND:
+      /*
+        The performance schema is not a general purpose storage engine,
+        some operations are not supported, by design.
+        We do not want to print "Command not supported",
+        which gives the impression that a command implementation is missing,
+        and that the failure should be considered a bug.
+        We print "Invalid performance_schema usage." instead,
+        to emphasise that the operation attempted is not meant to be legal,
+        and that the failure returned is indeed the expected result.
+      */
+      my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
+      break;
+    default:
+     handler::print_error(error, errflag);
+     break;
+  }
+}
+

=== modified file 'storage/perfschema/ha_perfschema.h'
--- a/storage/perfschema/ha_perfschema.h	2010-10-21 11:34:17 +0000
+++ b/storage/perfschema/ha_perfschema.h	2010-12-01 18:46:51 +0000
@@ -101,9 +101,6 @@ public:
   double scan_time(void)
   { return 1.0; }
 
-  double read_time(ha_rows)
-  { return 1.0; }
-
   int open(const char *name, int mode, uint test_if_locked);
 
   int close(void);
@@ -152,6 +149,8 @@ public:
     return FALSE;
   }
 
+  virtual void print_error(int error, myf errflags);
+
 private:
   /** MySQL lock */
   THR_LOCK_DATA m_thr_lock;

=== modified file 'storage/perfschema/pfs_engine_table.cc'
--- a/storage/perfschema/pfs_engine_table.cc	2010-09-28 15:17:29 +0000
+++ b/storage/perfschema/pfs_engine_table.cc	2010-12-01 18:46:51 +0000
@@ -193,14 +193,11 @@ int PFS_engine_table_share::write_row(TA
   */
   if (! m_checked)
   {
-    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
-             PERFORMANCE_SCHEMA_str.str, m_name);
     return HA_ERR_TABLE_NEEDS_UPGRADE;
   }
 
   if (m_write_row == NULL)
   {
-    my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
     return HA_ERR_WRONG_COMMAND;
   }
 
@@ -275,8 +272,6 @@ int PFS_engine_table::read_row(TABLE *ta
   */
   if (! m_share_ptr->m_checked)
   {
-    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
-             PERFORMANCE_SCHEMA_str.str, m_share_ptr->m_name.str);
     return HA_ERR_TABLE_NEEDS_UPGRADE;
   }
 
@@ -322,8 +317,6 @@ int PFS_engine_table::update_row(TABLE *
   */
   if (! m_share_ptr->m_checked)
   {
-    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
-             PERFORMANCE_SCHEMA_str.str, m_share_ptr->m_name.str);
     return HA_ERR_TABLE_NEEDS_UPGRADE;
   }
 
@@ -347,8 +340,6 @@ int PFS_engine_table::delete_row(TABLE *
   */
   if (! m_share_ptr->m_checked)
   {
-    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
-             PERFORMANCE_SCHEMA_str.str, m_share_ptr->m_name.str);
     return HA_ERR_TABLE_NEEDS_UPGRADE;
   }
 
@@ -364,7 +355,6 @@ int PFS_engine_table::delete_row_values(
                                         const unsigned char *,
                                         Field **)
 {
-  my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
   return HA_ERR_WRONG_COMMAND;
 }
 
@@ -461,7 +451,6 @@ int PFS_engine_table::update_row_values(
                                         unsigned char *,
                                         Field **)
 {
-  my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
   return HA_ERR_WRONG_COMMAND;
 }
 

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2010-11-16 06:27:18 +0000
+++ b/storage/perfschema/pfs_instr.cc	2010-12-01 08:33:53 +0000
@@ -1057,7 +1057,7 @@ PFS_table* create_table(PFS_table_share 
         {
           pfs->m_identity= identity;
           pfs->m_share= share;
-          share->m_refcount++;
+          share->inc_refcount();
           pfs->m_wait_stat.m_control_flag=
             &flag_events_waits_summary_by_instance;
           pfs->m_wait_stat.m_parent= &share->m_wait_stat;

=== modified file 'storage/perfschema/pfs_instr_class.cc'
--- a/storage/perfschema/pfs_instr_class.cc	2010-11-16 06:27:18 +0000
+++ b/storage/perfschema/pfs_instr_class.cc	2010-12-01 08:33:53 +0000
@@ -788,7 +788,7 @@ search:
   {
     PFS_table_share *pfs;
     pfs= *entry;
-    pfs->m_refcount++ ;
+    pfs->inc_refcount() ;
     lf_hash_search_unpin(pins);
     return pfs;
   }
@@ -835,7 +835,7 @@ search:
           reset_single_stat_link(&pfs->m_wait_stat);
           pfs->m_enabled= enabled;
           pfs->m_timed= timed;
-          pfs->m_refcount= 1;
+          pfs->init_refcount();
 
           int res;
           res= lf_hash_insert(&table_share_hash, pins, &pfs);
@@ -879,7 +879,7 @@ search:
 */
 void purge_table_share(PFS_thread *thread, PFS_table_share *pfs)
 {
-  if (pfs->m_refcount == 1)
+  if (pfs->get_refcount() == 1)
   {
     LF_PINS* pins= get_table_share_hash_pins(thread);
     if (likely(pins != NULL))

=== modified file 'storage/perfschema/pfs_instr_class.h'
--- a/storage/perfschema/pfs_instr_class.h	2010-11-16 06:27:18 +0000
+++ b/storage/perfschema/pfs_instr_class.h	2010-12-01 08:33:53 +0000
@@ -146,11 +146,32 @@ struct PFS_table_share_key
 /** Instrumentation metadata for a table share. */
 struct PFS_table_share
 {
+public:
   enum_object_type get_object_type()
   {
     return (enum_object_type) m_key.m_hash_key[0];
   }
 
+  inline void init_refcount(void)
+  {
+    PFS_atomic::store_32(& m_refcount, 1);
+  }
+
+  inline int get_refcount(void)
+  {
+    return PFS_atomic::load_32(& m_refcount);
+  }
+
+  inline void inc_refcount(void)
+  {
+    PFS_atomic::add_32(& m_refcount, 1);
+  }
+
+  inline void dec_refcount(void)
+  {
+    PFS_atomic::add_32(& m_refcount, -1);
+  }
+
   /** Internal lock. */
   pfs_lock m_lock;
   /** Search key. */
@@ -170,8 +191,10 @@ struct PFS_table_share
   /** True if this table instrument is timed. */
   bool m_timed;
   bool m_purge;
+
+private:
   /** Number of opened table handles. */
-  uint m_refcount;
+  int m_refcount;
 };
 
 /**

=== modified file 'storage/perfschema/table_setup_actors.cc'
--- a/storage/perfschema/table_setup_actors.cc	2010-11-09 08:16:50 +0000
+++ b/storage/perfschema/table_setup_actors.cc	2010-12-01 18:46:51 +0000
@@ -249,7 +249,6 @@ int table_setup_actors::update_row_value
       case 0: /* HOST */
       case 1: /* USER */
       case 2: /* ROLE */
-        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
         return HA_ERR_WRONG_COMMAND;
         break;
       default:

=== modified file 'storage/perfschema/table_setup_consumers.cc'
--- a/storage/perfschema/table_setup_consumers.cc	2010-11-09 08:16:50 +0000
+++ b/storage/perfschema/table_setup_consumers.cc	2010-12-01 18:46:51 +0000
@@ -193,7 +193,6 @@ int table_setup_consumers::update_row_va
       switch(f->field_index)
       {
       case 0: /* NAME */
-        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
         return HA_ERR_WRONG_COMMAND;
       case 1: /* ENABLED */
       {

=== modified file 'storage/perfschema/table_setup_instruments.cc'
--- a/storage/perfschema/table_setup_instruments.cc	2010-11-09 08:16:50 +0000
+++ b/storage/perfschema/table_setup_instruments.cc	2010-12-01 18:46:51 +0000
@@ -269,7 +269,6 @@ int table_setup_instruments::update_row_
       switch(f->field_index)
       {
       case 0: /* NAME */
-        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
         return HA_ERR_WRONG_COMMAND;
       case 1: /* ENABLED */
         value= (enum_yes_no) get_field_enum(f);

=== modified file 'storage/perfschema/table_setup_timers.cc'
--- a/storage/perfschema/table_setup_timers.cc	2010-11-09 08:16:50 +0000
+++ b/storage/perfschema/table_setup_timers.cc	2010-12-01 18:46:51 +0000
@@ -165,7 +165,6 @@ int table_setup_timers::update_row_value
       switch(f->field_index)
       {
       case 0: /* NAME */
-        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
         return HA_ERR_WRONG_COMMAND;
       case 1: /* TIMER_NAME */
         value= get_field_enum(f);

=== modified file 'storage/perfschema/table_threads.cc'
--- a/storage/perfschema/table_threads.cc	2010-11-09 10:36:41 +0000
+++ b/storage/perfschema/table_threads.cc	2010-12-01 18:46:51 +0000
@@ -354,7 +354,6 @@ int table_threads::update_row_values(TAB
       case 10: /* PROCESSLIST_INFO */
       case 11: /* PARENT_THREAD_ID */
       case 12: /* ROLE */
-        my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
         return HA_ERR_WRONG_COMMAND;
       case 13: /* INSTRUMENTED */
         value= (enum_yes_no) get_field_enum(f);

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-bugfixing branch (Dmitry.Lenev:3394 to 3395) Dmitry Lenev2 Dec