List:Commits« Previous MessageNext Message »
From:Martin Skold Date:June 9 2010 2:09pm
Subject:bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:3103) Bug#23300
Bug#31602 Bug#33717 Bug#35250 Bug#35543 Bug#38901 Bug#39022 Bug#39774
Bug#4...
View as plain text  
#At file:///home/marty/MySQL/mysql-5.1-telco-6.2/

 3103 Martin Skold	2010-06-09 [merge]
      Merged in 5.1.45
      added:
        mysql-test/include/not_binlog_format_row.inc
        mysql-test/r/bug39022.result
        mysql-test/r/no_binlog.result
        mysql-test/r/partition_debug_sync.result
        mysql-test/std_data/bug48449.frm
        mysql-test/suite/rpl/r/rpl_slow_query_log.result
        mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt
        mysql-test/suite/rpl/t/rpl_slow_query_log.test
        mysql-test/t/bug39022.test
        mysql-test/t/no_binlog.test
        mysql-test/t/partition_debug_sync.test
      renamed:
        mysql-test/r/variables+c.result => mysql-test/r/variables_community.result
        mysql-test/t/variables+c.test => mysql-test/t/variables_community.test
      modified:
        client/mysql.cc
        client/mysql_upgrade.c
        client/mysqladmin.cc
        client/mysqlbinlog.cc
        client/mysqlcheck.c
        client/mysqldump.c
        client/mysqlimport.c
        client/mysqlshow.c
        client/mysqlslap.c
        client/mysqltest.cc
        cmd-line-utils/readline/rlmbutil.h
        cmd-line-utils/readline/text.c
        configure.in
        extra/yassl/include/yassl_error.hpp
        extra/yassl/src/ssl.cpp
        extra/yassl/src/yassl_error.cpp
        mysql-test/include/mtr_warnings.sql
        mysql-test/lib/My/ConfigFactory.pm
        mysql-test/lib/My/SafeProcess.pm
        mysql-test/lib/My/SafeProcess/safe_process_win.cc
        mysql-test/lib/mtr_cases.pm
        mysql-test/lib/mtr_gprof.pl
        mysql-test/lib/mtr_misc.pl
        mysql-test/lib/mtr_report.pm
        mysql-test/lib/mtr_stress.pl
        mysql-test/lib/v1/mtr_stress.pl
        mysql-test/lib/v1/mysql-test-run.pl
        mysql-test/mysql-test-run.pl
        mysql-test/r/archive.result
        mysql-test/r/backup.result
        mysql-test/r/bigint.result
        mysql-test/r/csv.result
        mysql-test/r/default.result
        mysql-test/r/delete.result
        mysql-test/r/fulltext.result
        mysql-test/r/func_gconcat.result
        mysql-test/r/func_time.result
        mysql-test/r/group_by.result
        mysql-test/r/group_min_max.result
        mysql-test/r/having.result
        mysql-test/r/innodb-autoinc.result
        mysql-test/r/innodb_mysql.result
        mysql-test/r/join.result
        mysql-test/r/log_state.result
        mysql-test/r/multi_update.result
        mysql-test/r/myisam.result
        mysql-test/r/mysqltest.result
        mysql-test/r/show_check.result
        mysql-test/r/sp-bugs.result
        mysql-test/r/sp-error.result
        mysql-test/r/sp.result
        mysql-test/r/sp_notembedded.result
        mysql-test/r/sp_trans.result
        mysql-test/r/subselect.result
        mysql-test/r/type_bit.result
        mysql-test/r/type_blob.result
        mysql-test/r/type_timestamp.result
        mysql-test/r/view.result
        mysql-test/r/view_grant.result
        mysql-test/r/warnings.result
        mysql-test/suite/rpl/r/rpl_sp.result
        mysql-test/suite/rpl/t/rpl_loaddata_symlink.test
        mysql-test/suite/sys_vars/r/log_basic.result
        mysql-test/suite/sys_vars/r/log_bin_trust_routine_creators_basic.result
        mysql-test/suite/sys_vars/r/slow_query_log_func.result
        mysql-test/suite/sys_vars/t/slow_query_log_func.test
        mysql-test/t/archive.test
        mysql-test/t/bigint.test
        mysql-test/t/csv.test
        mysql-test/t/delete.test
        mysql-test/t/fulltext.test
        mysql-test/t/func_gconcat.test
        mysql-test/t/group_by.test
        mysql-test/t/group_min_max.test
        mysql-test/t/having.test
        mysql-test/t/innodb-autoinc.test
        mysql-test/t/innodb_mysql.test
        mysql-test/t/join.test
        mysql-test/t/multi_update.test
        mysql-test/t/myisam.test
        mysql-test/t/mysqltest.test
        mysql-test/t/sp-bugs.test
        mysql-test/t/sp_notembedded.test
        mysql-test/t/subselect.test
        mysql-test/t/type_bit.test
        mysql-test/t/view.test
        mysql-test/t/view_grant.test
        mysys/default.c
        scripts/mysqld_multi.sh
        server-tools/instance-manager/options.cc
        sql/field.cc
        sql/ha_partition.cc
        sql/item.cc
        sql/item.h
        sql/item_cmpfunc.h
        sql/item_row.cc
        sql/item_sum.cc
        sql/item_timefunc.cc
        sql/log.cc
        sql/log_event.cc
        sql/log_event_old.cc
        sql/mysql_priv.h
        sql/mysqld.cc
        sql/opt_range.cc
        sql/opt_sum.cc
        sql/share/errmsg.txt
        sql/sp.cc
        sql/sp_cache.cc
        sql/sp_head.cc
        sql/sql_base.cc
        sql/sql_class.cc
        sql/sql_class.h
        sql/sql_lex.cc
        sql/sql_lex.h
        sql/sql_parse.cc
        sql/sql_repl.cc
        sql/sql_select.cc
        sql/sql_select.h
        sql/sql_table.cc
        sql/sql_trigger.cc
        sql/sql_update.cc
        sql/sql_view.cc
        sql/table.cc
        sql/table.h
        storage/archive/ha_archive.cc
        storage/csv/ha_tina.cc
        storage/innobase/buf/buf0buf.c
        storage/innobase/buf/buf0rea.c
        storage/innobase/handler/ha_innodb.cc
        storage/innobase/include/buf0rea.h
        storage/innobase/lock/lock0lock.c
        storage/innobase/os/os0file.c
        storage/myisam/ft_boolean_search.c
        storage/myisam/mi_dynrec.c
        storage/myisam/mi_locking.c
        support-files/mysql.spec.sh

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2010-03-12 06:06:23 +0000
+++ b/client/mysql.cc	2010-06-09 14:07:08 +0000
@@ -1341,7 +1341,7 @@ static struct my_option my_long_options[
   {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
    0, 0, 0, 0, 0},
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"auto-rehash", OPT_AUTO_REHASH,
@@ -1352,15 +1352,15 @@ static struct my_option my_long_options[
    "No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"batch", 'B',
-   "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+   "Don't use history file. Disable interactive behavior. (Enables --silent.)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"column-type-info", OPT_COLUMN_TYPES, "Display column type information.",
    (uchar**) &column_types_flag, (uchar**) &column_types_flag,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"comments", 'c', "Preserve comments. Send comments to the server."
-   " The default is --skip-comments (discard comments), enable with --comments",
+   " The default is --skip-comments (discard comments), enable with --comments.",
    (uchar**) &preserve_comments, (uchar**) &preserve_comments,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"compress", 'C', "Use compression in server/client protocol.",
@@ -1368,10 +1368,10 @@ static struct my_option my_long_options[
    0, 0, 0},
 
 #ifdef DBUG_OFF
-  {"debug", '#', "This is a non-debug version. Catch this and exit",
+  {"debug", '#', "This is a non-debug version. Catch this and exit.",
    0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #else
-  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
+  {"debug", '#', "Output debug log.", (uchar**) &default_dbug_option,
    (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
@@ -1386,12 +1386,12 @@ static struct my_option my_long_options[
    (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"delimiter", OPT_DELIMITER, "Delimiter to be used.", (uchar**) &delimiter_str,
    (uchar**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
+  {"execute", 'e', "Execute command and quit. (Disables --force and history file.)", 0,
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"vertical", 'E', "Print the output of a query (rows) vertically.",
    (uchar**) &vertical, (uchar**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
    0},
-  {"force", 'f', "Continue even if we get an sql error.",
+  {"force", 'f', "Continue even if we get an SQL error.",
    (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
    0, 0, 0, 0},
   {"named-commands", 'G',
@@ -1399,7 +1399,11 @@ static struct my_option my_long_options[
    (uchar**) &named_cmds, (uchar**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"no-named-commands", 'g',
-   "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead.",
+   "Named commands are disabled. Use \\* form only, or use named commands "
+   "only in the beginning of a line ending with a semicolon (;). Since "
+   "version 10.9, the client now starts with this option ENABLED by default. "
+   "Disable with '-G'. Long format commands still work from the first line. "
+   "WARNING: option deprecated; use --disable-named-commands instead.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"ignore-spaces", 'i', "Ignore space after function names.",
    (uchar**) &ignore_spaces, (uchar**) &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0,
@@ -1413,7 +1417,7 @@ static struct my_option my_long_options[
    (uchar**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"html", 'H', "Produce HTML output.", (uchar**) &opt_html, (uchar**) &opt_html,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"xml", 'X', "Produce XML output", (uchar**) &opt_xml, (uchar**) &opt_xml, 0,
+  {"xml", 'X', "Produce XML output.", (uchar**) &opt_xml, (uchar**) &opt_xml, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
    (uchar**) &line_numbers, (uchar**) &line_numbers, 0, GET_BOOL,
@@ -1431,7 +1435,7 @@ static struct my_option my_long_options[
   {"set-variable", 'O',
    "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C)",
+  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C).",
    (uchar**) &opt_sigint_ignore,  (uchar**) &opt_sigint_ignore, 0, GET_BOOL,
    NO_ARG, 0, 0, 0, 0, 0, 0},
   {"one-database", 'o',
@@ -1439,7 +1443,7 @@ static struct my_option my_long_options[
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef USE_POPEN
   {"pager", OPT_PAGER,
-   "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default.",
+   "Pager to use to display results. If you don't supply an option, the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"no-pager", OPT_NOPAGER,
    "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.",
@@ -1463,7 +1467,7 @@ static struct my_option my_long_options[
   {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
    (uchar**) &current_prompt, (uchar**) &current_prompt, 0, GET_STR_ALLOC,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"quick", 'q',
    "Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file.",
@@ -1480,7 +1484,7 @@ static struct my_option my_long_options[
    "Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name, 
    0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR_ALLOC,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include "sslopt-longopts.h"
@@ -1489,7 +1493,7 @@ static struct my_option my_long_options[
   {"tee", OPT_TEE,
    "Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG,
+  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: Option deprecated; use --disable-tee instead.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifndef DONT_ALLOW_USER_CHANGE
   {"user", 'u', "User for login if not current user.", (uchar**) &current_user,
@@ -1513,26 +1517,26 @@ static struct my_option my_long_options[
    (uchar**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
    0, 0},
   {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
-   "Max packet length to send to, or receive from server",
+   "The maximum packet length to send to or receive from server.",
    (uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
    GET_ULONG, REQUIRED_ARG, 16 *1024L*1024L, 4096,
    (longlong) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
   {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
-   "Buffer for TCP/IP and socket communication",
+   "The buffer size for TCP/IP and socket communication.",
    (uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0, GET_ULONG,
    REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
   {"select_limit", OPT_SELECT_LIMIT,
-   "Automatic limit for SELECT when using --safe-updates",
+   "Automatic limit for SELECT when using --safe-updates.",
    (uchar**) &select_limit,
    (uchar**) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
    0, 1, 0},
   {"max_join_size", OPT_MAX_JOIN_SIZE,
-   "Automatic limit for rows in a join when using --safe-updates",
+   "Automatic limit for rows in a join when using --safe-updates.",
    (uchar**) &max_join_size,
    (uchar**) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
    0, 1, 0},
   {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
-    " uses old (pre-4.1.1) protocol", (uchar**) &opt_secure_auth,
+    " uses old (pre-4.1.1) protocol.", (uchar**) &opt_secure_auth,
     (uchar**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"server-arg", OPT_SERVER_ARG, "Send embedded server this as a parameter.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},

=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2010-03-12 06:06:23 +0000
+++ b/client/mysql_upgrade.c	2010-06-09 14:07:08 +0000
@@ -65,21 +65,21 @@ static struct my_option my_long_options[
 {
   {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"basedir", 'b', "Not used by mysql_upgrade. Only for backward compatibilty",
+  {"basedir", 'b', "Not used by mysql_upgrade. Only for backward compatibility.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", 0,
+   "Directory for character set files.", 0,
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
    (uchar**)&not_used, (uchar**)&not_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"datadir", 'd',
-   "Not used by mysql_upgrade. Only for backward compatibilty",
+   "Not used by mysql_upgrade. Only for backward compatibility.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef DBUG_OFF
-  {"debug", '#', "This is a non-debug version. Catch this and exit",
+  {"debug", '#', "This is a non-debug version. Catch this and exit.",
    0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #else
-  {"debug", '#', "Output debug log", (uchar* *) & default_dbug_option,
+  {"debug", '#', "Output debug log.", (uchar* *) & default_dbug_option,
    (uchar* *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
@@ -97,7 +97,7 @@ static struct my_option my_long_options[
   {"host",'h', "Connect to host.", 0,
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"password", 'p',
-   "Password to use when connecting to server. If password is not given"
+   "Password to use when connecting to server. If password is not given,"
    " it's solicited on the tty.", (uchar**) &opt_password,(uchar**) &opt_password,
    0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef __WIN__
@@ -112,21 +112,21 @@ static struct my_option my_long_options[
    "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"protocol", OPT_MYSQL_PROTOCOL,
-   "The protocol of connection (tcp,socket,pipe,memory).",
+   "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_SMEM
   {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
    "Base name of shared memory.", 0,
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
-  {"tmpdir", 't', "Directory for temporary files",
+  {"tmpdir", 't', "Directory for temporary files.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"user", 'u', "User for login if not current user.", (uchar**) &opt_user,
    (uchar**) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"verbose", 'v', "Display more output about the process",
+  {"verbose", 'v', "Display more output about the process.",
    (uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
    GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
   {"write-binlog", OPT_WRITE_BINLOG,
@@ -231,7 +231,7 @@ get_one_option(int optid, const struct m
   case '?':
     printf("%s  Ver %s Distrib %s, for %s (%s)\n",
            my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
-    puts("MySQL utility for upgrading databases to new MySQL versions\n");
+    puts("MySQL utility for upgrading databases to new MySQL versions.\n");
     my_print_help(my_long_options);
     exit(0);
     break;

=== modified file 'client/mysqladmin.cc'
--- a/client/mysqladmin.cc	2010-03-12 06:06:23 +0000
+++ b/client/mysqladmin.cc	2010-06-09 14:07:08 +0000
@@ -120,7 +120,7 @@ static TYPELIB command_typelib=
 static struct my_option my_long_options[] =
 {
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"count", 'c',
@@ -131,7 +131,7 @@ static struct my_option my_long_options[
   {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
+  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
    (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
@@ -145,7 +145,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
    0, 0, 0},
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"default-character-set", OPT_DEFAULT_CHARSET,
    "Set the default character set.", (uchar**) &default_charset,
@@ -171,10 +171,10 @@ static struct my_option my_long_options[
    "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
    (uchar**) &tcp_port,
    (uchar**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
     0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"relative", 'r',
-   "Show difference between current and previous values when used with -i. Currently works only with extended-status.",
+   "Show difference between current and previous values when used with -i. Currently only works with extended-status.",
    (uchar**) &opt_relative, (uchar**) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
   0, 0, 0},
   {"set-variable", 'O',
@@ -187,10 +187,10 @@ static struct my_option my_long_options[
 #endif
   {"silent", 's', "Silently exit if one can't connect to server.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &unix_port, (uchar**) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
    0, 0, 0},
-  {"sleep", 'i', "Execute commands again and again with a sleep between.",
+  {"sleep", 'i', "Execute commands repeatedly with a sleep between.",
    (uchar**) &interval, (uchar**) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
    0, 0},
 #include <sslopt-longopts.h>

=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2010-03-12 06:06:23 +0000
+++ b/client/mysqlbinlog.cc	2010-06-09 14:07:08 +0000
@@ -992,7 +992,7 @@ static struct my_option my_long_options[
   {"help", '?', "Display this help and exit.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"base64-output", OPT_BASE64_OUTPUT_MODE,
@@ -1016,7 +1016,7 @@ static struct my_option my_long_options[
     SET @`a`:=_cp850 0x4DFC6C6C6572 COLLATE `cp850_general_ci`;
   */
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"database", 'd', "List entries for just this database (local log only).",
    (uchar**) &database, (uchar**) &database, 0, GET_STR_ALLOC, REQUIRED_ARG,
@@ -1070,9 +1070,9 @@ static struct my_option my_long_options[
    /* COM_BINLOG_DUMP accepts only 4 bytes for the position */
    (ulonglong)(~(uint32)0), 0, 0, 0},
   {"protocol", OPT_MYSQL_PROTOCOL,
-   "The protocol of connection (tcp,socket,pipe,memory).",
+   "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"read-from-remote-server", 'R', "Read binary logs from a MySQL server",
+  {"read-from-remote-server", 'R', "Read binary logs from a MySQL server.",
    (uchar**) &remote_opt, (uchar**) &remote_opt, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"result-file", 'r', "Direct output to a given file.", 0, 0, 0, GET_STR,
@@ -1096,7 +1096,7 @@ static struct my_option my_long_options[
    "using --base64-output=never instead.",
    (uchar**) &short_form, (uchar**) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &sock, (uchar**) &sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 
    0, 0},
   {"start-datetime", OPT_START_DATETIME,
@@ -1138,12 +1138,12 @@ that may lead to an endless loop.",
    (uchar**) &user, (uchar**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0,
    0, 0},
   {"verbose", 'v', "Reconstruct SQL statements out of row events. "
-                   "-v -v adds comments on column data types",
+                   "-v -v adds comments on column data types.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"version", 'V', "Print version and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
    0, 0, 0, 0, 0},
   {"open_files_limit", OPT_OPEN_FILES_LIMIT,
-   "Used to reserve file descriptors for usage by this program",
+   "Used to reserve file descriptors for use by this program.",
    (uchar**) &open_files_limit, (uchar**) &open_files_limit, 0, GET_ULONG,
    REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0},
   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
@@ -1242,11 +1242,11 @@ static void usage()
   print_version();
   puts("By Monty and Sasha, for your professional use\n\
 This software comes with NO WARRANTY:  This is free software,\n\
-and you are welcome to modify and redistribute it under the GPL license\n");
+and you are welcome to modify and redistribute it under the GPL license.\n");
 
   printf("\
 Dumps a MySQL binary log in a format usable for viewing or for piping to\n\
-the mysql command line client\n\n");
+the mysql command line client.\n\n");
   printf("Usage: %s [options] log-files\n", my_progname);
   my_print_help(my_long_options);
   my_print_variables(my_long_options);

=== modified file 'client/mysqlcheck.c'
--- a/client/mysqlcheck.c	2009-12-17 10:14:52 +0000
+++ b/client/mysqlcheck.c	2010-06-09 14:07:08 +0000
@@ -56,7 +56,7 @@ enum operations { DO_CHECK, DO_REPAIR, D
 static struct my_option my_long_options[] =
 {
   {"all-databases", 'A',
-   "Check all the databases. This will be same as  --databases with all databases selected.",
+   "Check all the databases. This is the same as --databases with all databases selected.",
    (uchar**) &opt_alldbs, (uchar**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
@@ -66,7 +66,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_all_in_1, (uchar**) &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
    0, 0, 0},
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"auto-repair", OPT_AUTO_REPAIR,
@@ -74,7 +74,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_auto_repair, (uchar**) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
    0, 0, 0, 0, 0},
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
    0, 0, 0, 0},
@@ -88,7 +88,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
    0, 0, 0},
   {"databases", 'B',
-   "To check several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames.",
+   "Check several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names.",
    (uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
 #ifdef DBUG_OFF
@@ -116,7 +116,7 @@ static struct my_option my_long_options[
   {"fix-table-names", OPT_FIX_TABLE_NAMES, "Fix table names.",
     (uchar**) &opt_fix_table_names, (uchar**) &opt_fix_table_names,
     0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"force", 'f', "Continue even if we get an sql-error.",
+  {"force", 'f', "Continue even if we get an SQL error.",
    (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
    0, 0, 0, 0},
   {"extended", 'e',
@@ -137,7 +137,7 @@ static struct my_option my_long_options[
   {"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"password", 'p',
-   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
+   "Password to use when connecting to server. If password is not given, it's solicited on the tty.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef __WIN__
   {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
@@ -152,7 +152,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_mysql_port,
    (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
    0},
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"quick", 'q',
    "If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.",
@@ -168,7 +168,7 @@ static struct my_option my_long_options[
 #endif
   {"silent", 's', "Print only error messages.", (uchar**) &opt_silent,
    (uchar**) &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
@@ -224,14 +224,14 @@ static void print_version(void)
 static void usage(void)
 {
   print_version();
-  puts("By Jani Tolonen, 2001-04-20, MySQL Development Team\n");
+  puts("By Jani Tolonen, 2001-04-20, MySQL Development Team.\n");
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n");
   puts("and you are welcome to modify and redistribute it under the GPL license.\n");
-  puts("This program can be used to CHECK (-c,-m,-C), REPAIR (-r), ANALYZE (-a)");
+  puts("This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a),");
   puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
   puts("used at the same time. Not all options are supported by all storage engines.");
   puts("Please consult the MySQL manual for latest information about the");
-  puts("above. The options -c,-r,-a and -o are exclusive to each other, which");
+  puts("above. The options -c, -r, -a, and -o are exclusive to each other, which");
   puts("means that the last option will be used, if several was specified.\n");
   puts("The option -c will be used by default, if none was specified. You");
   puts("can change the default behavior by making a symbolic link, or");

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2010-03-12 06:06:23 +0000
+++ b/client/mysqldump.c	2010-06-09 14:07:08 +0000
@@ -197,24 +197,24 @@ static struct my_option my_long_options[
    "Do not dump any tablespace information.",
    (uchar**) &opt_notspcs, (uchar**) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
-  {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.",
+  {"add-drop-database", OPT_DROP_DATABASE, "Add a DROP DATABASE before each create.",
    (uchar**) &opt_drop_database, (uchar**) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
    0},
-  {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
+  {"add-drop-table", OPT_DROP, "Add a DROP TABLE before each create.",
    (uchar**) &opt_drop, (uchar**) &opt_drop, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
    0},
-  {"add-locks", OPT_LOCKS, "Add locks around insert statements.",
+  {"add-locks", OPT_LOCKS, "Add locks around INSERT statements.",
    (uchar**) &opt_lock, (uchar**) &opt_lock, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0,
    0},
   {"allow-keywords", OPT_KEYWORDS,
    "Allow creation of column names that are keywords.", (uchar**) &opt_keywords,
    (uchar**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"comments", 'i', "Write additional information.",
    (uchar**) &opt_comments, (uchar**) &opt_comments, 0, GET_BOOL, NO_ARG,
@@ -224,7 +224,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_compatible_mode_str, (uchar**) &opt_compatible_mode_str, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"compact", OPT_COMPACT,
-   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset",
+   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset.",
    (uchar**) &opt_compact, (uchar**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"complete-insert", 'c', "Use complete insert statements.",
@@ -238,14 +238,14 @@ static struct my_option my_long_options[
    (uchar**) &create_options, (uchar**) &create_options, 0, GET_BOOL, NO_ARG, 1,
    0, 0, 0, 0, 0},
   {"databases", 'B',
-   "To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
+   "Dump several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. 'USE db_name;' will be included in the output.",
    (uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
    0, 0, 0, 0},
 #ifdef DBUG_OFF
-  {"debug", '#', "This is a non-debug version. Catch this and exit",
+  {"debug", '#', "This is a non-debug version. Catch this and exit.",
    0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #else
-  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
+  {"debug", '#', "Output debug log.", (uchar**) &default_dbug_option,
    (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
@@ -257,7 +257,7 @@ static struct my_option my_long_options[
   {"default-character-set", OPT_DEFAULT_CHARSET,
    "Set the default character set.", (uchar**) &default_charset,
    (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED; ",
+  {"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED.",
    (uchar**) &opt_delayed, (uchar**) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"delete-master-logs", OPT_DELETE_MASTER_LOGS,
@@ -275,16 +275,21 @@ static struct my_option my_long_options[
    (uchar**) &extended_insert, (uchar**) &extended_insert, 0, GET_BOOL, NO_ARG,
    1, 0, 0, 0, 0, 0},
   {"fields-terminated-by", OPT_FTB,
-   "Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
-   (uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+   "Fields in the output file are terminated by the given string.", 
+   (uchar**) &fields_terminated, (uchar**) &fields_terminated, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"fields-enclosed-by", OPT_ENC,
-   "Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
-   (uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
+   "Fields in the output file are enclosed by the given character.", 
+   (uchar**) &enclosed, (uchar**) &enclosed, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
   {"fields-optionally-enclosed-by", OPT_O_ENC,
-   "Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
-   (uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
-  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
-   (uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+   "Fields in the output file are optionally enclosed by the given character.", 
+   (uchar**) &opt_enclosed, (uchar**) &opt_enclosed, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
+  {"fields-escaped-by", OPT_ESC, 
+   "Fields in the output file are escaped by the given character.",
+   (uchar**) &escaped, (uchar**) &escaped, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"first-slave", OPT_FIRST_SLAVE, "Deprecated, renamed to --lock-all-tables.",
    (uchar**) &opt_lock_all_tables, (uchar**) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
@@ -296,7 +301,7 @@ static struct my_option my_long_options[
    "in this case the logs will be flushed only once, corresponding "
    "to the moment all tables are locked. So if you want your dump and "
    "the log flush to happen at the same exact moment you should use "
-   "--lock-all-tables or --master-data with --flush-logs",
+   "--lock-all-tables or --master-data with --flush-logs.",
    (uchar**) &flush_logs, (uchar**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
@@ -305,7 +310,7 @@ static struct my_option my_long_options[
    "that depends on the data in the mysql database for proper restore. ",
    (uchar**) &flush_privileges, (uchar**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
-  {"force", 'f', "Continue even if we get an sql-error.",
+  {"force", 'f', "Continue even if we get an SQL error.",
    (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
   {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
@@ -318,12 +323,14 @@ static struct my_option my_long_options[
   {"ignore-table", OPT_IGNORE_TABLE,
    "Do not dump the specified table. To specify more than one table to ignore, "
    "use the directive multiple times, once for each table.  Each table must "
-   "be specified with both database and table names, e.g. --ignore-table=database.table",
+   "be specified with both database and table names, e.g., "
+   "--ignore-table=database.table.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"insert-ignore", OPT_INSERT_IGNORE, "Insert rows with INSERT IGNORE.",
    (uchar**) &opt_ignore, (uchar**) &opt_ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
-  {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
+  {"lines-terminated-by", OPT_LTB, 
+   "Lines in the output file are terminated by the given string.",
    (uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"lock-all-tables", 'x', "Locks all tables across all databases. This "
@@ -342,17 +349,19 @@ static struct my_option my_long_options[
    " to 2, that command will be prefixed with a comment symbol. "
    "This option will turn --lock-all-tables on, unless "
    "--single-transaction is specified too (in which case a "
-   "global read lock is only taken a short time at the beginning of the dump "
-   "- don't forget to read about --single-transaction below). In all cases "
-   "any action on logs will happen at the exact moment of the dump."
+   "global read lock is only taken a short time at the beginning of the dump; "
+   "don't forget to read about --single-transaction below). In all cases, "
+   "any action on logs will happen at the exact moment of the dump. "
    "Option automatically turns --lock-tables off.",
    (uchar**) &opt_master_data, (uchar**) &opt_master_data, 0,
    GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
-  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
+  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, 
+   "The maximum packet length to send to or receive from server.",
     (uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
     GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
    (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
-  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
+  {"net_buffer_length", OPT_NET_BUFFER_LENGTH, 
+   "The buffer size for TCP/IP and socket communication.",
     (uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0,
     GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L,
    MALLOC_OVERHEAD-1024, 1024, 0},
@@ -361,9 +370,11 @@ static struct my_option my_long_options[
    (uchar**) &opt_autocommit, (uchar**) &opt_autocommit, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
   {"no-create-db", 'n',
-   "'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}.",
-   (uchar**) &opt_create_db, (uchar**) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
-   0, 0, 0, 0},
+   "Suppress the CREATE DATABASE ... IF EXISTS statement that normally is "
+   "output for each dumped database if --all-databases or --databases is "
+   "given.",
+   (uchar**) &opt_create_db, (uchar**) &opt_create_db, 0, 
+   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"no-create-info", 't', "Don't write table creation info.",
    (uchar**) &opt_no_create_info, (uchar**) &opt_no_create_info, 0, GET_BOOL,
    NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -387,8 +398,9 @@ static struct my_option my_long_options[
   {"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
    (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
    0},
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
-   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"protocol", OPT_MYSQL_PROTOCOL, 
+   "The protocol to use for connection (tcp, socket, pipe, memory).",
+   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"quick", 'q', "Don't buffer query, dump directly to stdout.",
    (uchar**) &quick, (uchar**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
   {"quote-names",'Q', "Quote table and column names with backticks (`).",
@@ -438,18 +450,20 @@ static struct my_option my_long_options[
   {"skip-opt", OPT_SKIP_OPTIMIZATION,
    "Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
-   (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
-   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"socket", 'S', "The socket file to use for connection.",
+   (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
   {"tab",'T',
-   "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
+   "Create tab-separated textfile for each table to given path. (Create .sql "
+   "and .txt files.) NOTE: This only works if mysqldump is run on the same "
+   "machine as the mysqld server.",
    (uchar**) &path, (uchar**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"tables", OPT_TABLES, "Overrides option --databases (-B).",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-   {"triggers", OPT_TRIGGERS, "Dump triggers for each dumped table",
-     (uchar**) &opt_dump_triggers, (uchar**) &opt_dump_triggers, 0, GET_BOOL,
-     NO_ARG, 1, 0, 0, 0, 0, 0},
+  {"triggers", OPT_TRIGGERS, "Dump triggers for each dumped table.",
+   (uchar**) &opt_dump_triggers, (uchar**) &opt_dump_triggers, 0, GET_BOOL,
+   NO_ARG, 1, 0, 0, 0, 0, 0},
   {"tz-utc", OPT_TZ_UTC,
     "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
     (uchar**) &opt_tz_utc, (uchar**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
@@ -462,7 +476,7 @@ static struct my_option my_long_options[
    (uchar**) &verbose, (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"version",'V', "Output version information and exit.", 0, 0, 0,
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"where", 'w', "Dump only selected records; QUOTES mandatory!",
+  {"where", 'w', "Dump only selected records. Quotes are mandatory.",
    (uchar**) &where, (uchar**) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -556,9 +570,9 @@ static void short_usage_sub(void)
 static void usage(void)
 {
   print_version();
-  puts("By Igor Romanenko, Monty, Jani & Sinisa");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
-  puts("Dumping definition and data mysql database or table");
+  puts("By Igor Romanenko, Monty, Jani & Sinisa.");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n");
+  puts("Dumping structure and contents of MySQL databases and tables.");
   short_usage_sub();
   print_defaults("my",load_default_groups);
   my_print_help(my_long_options);

=== modified file 'client/mysqlimport.c'
--- a/client/mysqlimport.c	2009-12-17 10:14:52 +0000
+++ b/client/mysqlimport.c	2010-06-09 14:07:08 +0000
@@ -71,11 +71,11 @@ static char *shared_memory_base_name=0;
 static struct my_option my_long_options[] =
 {
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &charsets_dir,
+   "Directory for character set files.", (uchar**) &charsets_dir,
    (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"default-character-set", OPT_DEFAULT_CHARSET,
    "Set the default character set.", (uchar**) &default_charset,
@@ -98,18 +98,22 @@ static struct my_option my_long_options[
   {"delete", 'd', "First delete all rows from table.", (uchar**) &opt_delete,
    (uchar**) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"fields-terminated-by", OPT_FTB,
-   "Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
-   (uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+   "Fields in the input file are terminated by the given string.", 
+   (uchar**) &fields_terminated, (uchar**) &fields_terminated, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"fields-enclosed-by", OPT_ENC,
-   "Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
-   (uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+   "Fields in the import file are enclosed by the given character.", 
+   (uchar**) &enclosed, (uchar**) &enclosed, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"fields-optionally-enclosed-by", OPT_O_ENC,
-   "Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
-   (uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
+   "Fields in the input file are optionally enclosed by the given character.", 
+   (uchar**) &opt_enclosed, (uchar**) &opt_enclosed, 0, 
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"fields-escaped-by", OPT_ESC, 
+   "Fields in the input file are escaped by the given character.",
    (uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
    0, 0},
-  {"force", 'f', "Continue even if we get an sql-error.",
+  {"force", 'f', "Continue even if we get an SQL error.",
    (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
    0, 0, 0, 0},
   {"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG,
@@ -121,7 +125,8 @@ static struct my_option my_long_options[
   {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
    (uchar**) &opt_ignore_lines, (uchar**) &opt_ignore_lines, 0, GET_LL,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
+  {"lines-terminated-by", OPT_LTB, 
+   "Lines in the input file are terminated by the given string.",
    (uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"local", 'L', "Read all files through the client.", (uchar**) &opt_local_file,
@@ -148,7 +153,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_mysql_port,
    (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
    0},
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"replace", 'r', "If duplicate unique key was found, replace old row.",
    (uchar**) &replace, (uchar**) &replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -159,7 +164,7 @@ static struct my_option my_long_options[
 #endif
   {"silent", 's', "Be more silent.", (uchar**) &silent, (uchar**) &silent, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
@@ -196,7 +201,7 @@ static void usage(void)
 {
   print_version();
   puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n");
   printf("\
 Loads tables from text files in various formats.  The base name of the\n\
 text file must be the name of the table that should be used.\n\

=== modified file 'client/mysqlshow.c'
--- a/client/mysqlshow.c	2009-08-25 19:44:04 +0000
+++ b/client/mysqlshow.c	2010-06-09 14:07:08 +0000
@@ -163,17 +163,17 @@ int main(int argc, char **argv)
 static struct my_option my_long_options[] =
 {
 #ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"character-sets-dir", 'c', "Directory where character sets are.",
+  {"character-sets-dir", 'c', "Directory for character set files.",
    (uchar**) &charsets_dir, (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
    0, 0, 0, 0, 0},
   {"default-character-set", OPT_DEFAULT_CHARSET,
    "Set the default character set.", (uchar**) &default_charset,
    (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"count", OPT_COUNT,
-   "Show number of rows per table (may be slow for not MyISAM tables)",
+   "Show number of rows per table (may be slow for non-MyISAM tables).",
    (uchar**) &opt_count, (uchar**) &opt_count, 0, GET_BOOL, NO_ARG, 0, 0, 0,
    0, 0, 0},
   {"compress", 'C', "Use compression in server/client protocol.",
@@ -197,7 +197,8 @@ static struct my_option my_long_options[
   {"keys", 'k', "Show keys for table.", (uchar**) &opt_show_keys,
    (uchar**) &opt_show_keys, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"password", 'p',
-   "Password to use when connecting to server. If password is not given it's asked from the tty.",
+   "Password to use when connecting to server. If password is not given, it's "
+   "solicited on the tty.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"port", 'P', "Port number to use for connection or 0 for default to, in "
    "order of preference, my.cnf, $MYSQL_TCP_PORT, "
@@ -212,7 +213,8 @@ static struct my_option my_long_options[
   {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+  {"protocol", OPT_MYSQL_PROTOCOL, 
+   "The protocol to use for connection (tcp, socket, pipe, memory).",
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_SMEM
   {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
@@ -222,7 +224,7 @@ static struct my_option my_long_options[
   {"show-table-type", 't', "Show table type column.",
    (uchar**) &opt_table_type, (uchar**) &opt_table_type, 0, GET_BOOL,
    NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
@@ -231,7 +233,8 @@ static struct my_option my_long_options[
    (uchar**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"verbose", 'v',
-   "More verbose output; You can use this multiple times to get even more verbose output.",
+   "More verbose output; you can use this multiple times to get even more "
+   "verbose output.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -253,16 +256,16 @@ static void usage(void)
 {
   print_version();
   puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
-  puts("Shows the structure of a mysql database (databases,tables and columns)\n");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n");
+  puts("Shows the structure of a MySQL database (databases, tables, and columns).\n");
   printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);
   puts("\n\
 If last argument contains a shell or SQL wildcard (*,?,% or _) then only\n\
 what\'s matched by the wildcard is shown.\n\
 If no database is given then all matching databases are shown.\n\
-If no table is given then all matching tables in database are shown\n\
-If no column is given then all matching columns and columntypes in table\n\
-are shown");
+If no table is given, then all matching tables in database are shown.\n\
+If no column is given, then all matching columns and column types in table\n\
+are shown.");
   print_defaults("my",load_default_groups);
   my_print_help(my_long_options);
   my_print_variables(my_long_options);

=== modified file 'client/mysqlslap.c'
--- a/client/mysqlslap.c	2009-12-17 10:14:52 +0000
+++ b/client/mysqlslap.c	2010-06-09 14:07:08 +0000
@@ -611,8 +611,8 @@ static struct my_option my_long_options[
     (uchar**) &num_of_query, (uchar**) &num_of_query, 0,
     GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"only-print", OPT_MYSQL_ONLY_PRINT,
-    "This causes mysqlslap to not connect to the databases, but instead print "
-      "out what it would have done instead.",
+    "Do not connect to the databases, but instead print out what would have "
+     "been done.",
     (uchar**) &opt_only_print, (uchar**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
     0, 0, 0, 0, 0, 0},
   {"password", 'p',
@@ -646,7 +646,7 @@ static struct my_option my_long_options[
     (uchar**) &pre_system,
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"protocol", OPT_MYSQL_PROTOCOL,
-    "The protocol of connection (tcp,socket,pipe,memory).",
+    "The protocol to use for connection (tcp, socket, pipe, memory).",
     0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"query", 'q', "Query to run or file containing query to run.",
     (uchar**) &user_supplied_query, (uchar**) &user_supplied_query,
@@ -660,7 +660,7 @@ static struct my_option my_long_options[
   {"silent", 's', "Run program in silent mode - no output.",
     (uchar**) &opt_silent, (uchar**) &opt_silent, 0, GET_BOOL,  NO_ARG,
     0, 0, 0, 0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
     (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
     REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #include <sslopt-longopts.h>
@@ -691,8 +691,8 @@ static void usage(void)
 {
   print_version();
   puts("Copyright (C) 2005 MySQL AB");
-  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
-  puts("Run a query multiple times against the server\n");
+  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n");
+  puts("Run a query multiple times against the server.\n");
   printf("Usage: %s [OPTIONS]\n",my_progname);
   print_defaults("my",load_default_groups);
   my_print_help(my_long_options);

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2010-03-12 06:06:23 +0000
+++ b/client/mysqltest.cc	2010-06-09 14:07:08 +0000
@@ -70,6 +70,7 @@
 #define MAX_COLUMNS            256
 #define MAX_EMBEDDED_SERVER_ARGS 64
 #define MAX_DELIMITER_LENGTH 16
+#define DEFAULT_MAX_CONN       128
 
 /* Flags controlling send and reap */
 #define QUERY_SEND_FLAG  1
@@ -78,8 +79,8 @@
 enum {
   OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
   OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
-  OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
-  OPT_RESULT_FORMAT_VERSION
+  OPT_MAX_CONNECT_RETRIES, OPT_MAX_CONNECTIONS, OPT_MARK_PROGRESS,
+  OPT_LOG_DIR, OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION
 };
 
 static int record= 0, opt_sleep= -1;
@@ -93,6 +94,7 @@ const char *opt_include= 0, *opt_charset
 static int opt_port= 0;
 static int opt_max_connect_retries;
 static int opt_result_format_version;
+static int opt_max_connections= DEFAULT_MAX_CONN;
 static my_bool opt_compress= 0, silent= 0, verbose= 0;
 static my_bool debug_info_flag= 0, debug_check_flag= 0;
 static my_bool tty_password= 0;
@@ -102,7 +104,7 @@ static my_bool sp_protocol= 0, sp_protoc
 static my_bool view_protocol= 0, view_protocol_enabled= 0;
 static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0;
 static my_bool parsing_disabled= 0;
-static my_bool display_result_vertically= FALSE,
+static my_bool display_result_vertically= FALSE, display_result_lower= FALSE,
   display_metadata= FALSE, display_result_sorted= FALSE;
 static my_bool disable_query_log= 0, disable_result_log= 0;
 static my_bool disable_warnings= 0;
@@ -137,6 +139,7 @@ struct st_block
   int             line; /* Start line of block */
   my_bool         ok;   /* Should block be executed */
   enum block_cmd  cmd;  /* Command owning the block */
+  char            delim[MAX_DELIMITER_LENGTH];  /* Delimiter before block */
 };
 
 static struct st_block block_stack[32];
@@ -233,6 +236,8 @@ struct st_connection
   char *name;
   size_t name_len;
   MYSQL_STMT* stmt;
+  /* Set after send to disallow other queries before reap */
+  my_bool pending;
 
 #ifdef EMBEDDED_LIBRARY
   const char *cur_query;
@@ -242,7 +247,8 @@ struct st_connection
   int query_done;
 #endif /*EMBEDDED_LIBRARY*/
 };
-struct st_connection connections[128];
+
+struct st_connection *connections= NULL;
 struct st_connection* cur_con= NULL, *next_con, *connections_end;
 
 /*
@@ -277,6 +283,7 @@ enum enum_commands {
   Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR,
   Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS,
   Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULT,
+  Q_LOWERCASE,
   Q_START_TIMER, Q_END_TIMER,
   Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL,
   Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT,
@@ -289,7 +296,7 @@ enum enum_commands {
   Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
   Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
   Q_RESULT_FORMAT_VERSION,
-  Q_MOVE_FILE,
+  Q_MOVE_FILE, Q_REMOVE_FILES_WILDCARD, Q_SEND_EVAL,
 
   Q_UNKNOWN,			       /* Unknown command.   */
   Q_COMMENT,			       /* Comments, ignored. */
@@ -353,6 +360,7 @@ const char *command_names[]=
   "query_vertical",
   "query_horizontal",
   "sorted_result",
+  "lowercase_result",
   "start_timer",
   "end_timer",
   "character_set",
@@ -389,6 +397,8 @@ const char *command_names[]=
   "shutdown_server",
   "result_format",
   "move_file",
+  "remove_files_wildcard",
+  "send_eval",
 
   0
 };
@@ -492,6 +502,8 @@ void free_replace();
 void do_get_replace_regex(struct st_command *command);
 void free_replace_regex();
 
+/* Used by sleep */
+void check_eol_junk_line(const char *eol);
 
 void free_all_replace(){
   free_replace();
@@ -1046,7 +1058,7 @@ void check_command_args(struct st_comman
   }
   /* Check for too many arguments passed */
   ptr= command->last_argument;
-  while(ptr <= command->end)
+  while(ptr <= command->end && *ptr != '#')
   {
     if (*ptr && *ptr != ' ')
       die("Extra argument '%s' passed to '%.*s'",
@@ -1104,6 +1116,7 @@ void close_connections()
       mysql_close(next_con->util_mysql);
     my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR));
   }
+  my_free(connections, MYF(MY_WME));
   DBUG_VOID_RETURN;
 }
 
@@ -1130,7 +1143,7 @@ void close_files()
     if (cur_file->file && cur_file->file != stdin)
     {
       DBUG_PRINT("info", ("closing file: %s", cur_file->file_name));
-      my_fclose(cur_file->file, MYF(0));
+      fclose(cur_file->file);
     }
     my_free((uchar*) cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR));
     cur_file->file_name= 0;
@@ -1144,7 +1157,8 @@ void free_used_memory()
   uint i;
   DBUG_ENTER("free_used_memory");
 
-  close_connections();
+  if (connections)
+    close_connections();
   close_files();
   hash_free(&var_hash);
 
@@ -2505,7 +2519,7 @@ int open_file(const char *name)
   if (cur_file == file_stack_end)
     die("Source directives are nesting too deep");
   cur_file++;
-  if (!(cur_file->file = my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
+  if (!(cur_file->file = fopen(buff, "rb")))
   {
     cur_file--;
     die("Could not open '%s' for reading, errno: %d", buff, errno);
@@ -2717,6 +2731,10 @@ void do_exec(struct st_command *command)
 #endif
 #endif
 
+  /* exec command is interpreted externally and will not take newlines */
+  while(replace(&ds_cmd, "\n", 1, " ", 1) == 0)
+    ;
+  
   DBUG_PRINT("info", ("Executing '%s' as '%s'",
                       command->first_argument, ds_cmd.str));
 
@@ -2942,6 +2960,81 @@ void do_remove_file(struct st_command *c
 
 /*
   SYNOPSIS
+  do_remove_files_wildcard
+  command	called command
+
+  DESCRIPTION
+  remove_files_wildcard <directory> [<file_name_pattern>]
+  Remove the files in <directory> optionally matching <file_name_pattern>
+*/
+
+void do_remove_files_wildcard(struct st_command *command)
+{
+  int error= 0;
+  uint i;
+  MY_DIR *dir_info;
+  FILEINFO *file;
+  char dir_separator[2];
+  static DYNAMIC_STRING ds_directory;
+  static DYNAMIC_STRING ds_wild;
+  static DYNAMIC_STRING ds_file_to_remove;
+  char dirname[FN_REFLEN];
+  
+  const struct command_arg rm_args[] = {
+    { "directory", ARG_STRING, TRUE, &ds_directory,
+      "Directory containing files to delete" },
+    { "filename", ARG_STRING, FALSE, &ds_wild, "File pattern to delete" }
+  };
+  DBUG_ENTER("do_remove_files_wildcard");
+
+  check_command_args(command, command->first_argument,
+                     rm_args, sizeof(rm_args)/sizeof(struct command_arg),
+                     ' ');
+  fn_format(dirname, ds_directory.str, "", "", MY_UNPACK_FILENAME);
+
+  DBUG_PRINT("info", ("listing directory: %s", dirname));
+  /* Note that my_dir sorts the list if not given any flags */
+  if (!(dir_info= my_dir(dirname, MYF(MY_DONT_SORT | MY_WANT_STAT))))
+  {
+    error= 1;
+    goto end;
+  }
+  init_dynamic_string(&ds_file_to_remove, dirname, 1024, 1024);
+  dir_separator[0]= FN_LIBCHAR;
+  dir_separator[1]= 0;
+  dynstr_append(&ds_file_to_remove, dir_separator);
+  for (i= 0; i < (uint) dir_info->number_off_files; i++)
+  {
+    file= dir_info->dir_entry + i;
+    /* Remove only regular files, i.e. no directories etc. */
+    /* if (!MY_S_ISREG(file->mystat->st_mode)) */
+    /* MY_S_ISREG does not work here on Windows, just skip directories */
+    if (MY_S_ISDIR(file->mystat->st_mode))
+      continue;
+    if (ds_wild.length &&
+        wild_compare(file->name, ds_wild.str, 0))
+      continue;
+    ds_file_to_remove.length= ds_directory.length + 1;
+    ds_file_to_remove.str[ds_directory.length + 1]= 0;
+    dynstr_append(&ds_file_to_remove, file->name);
+    DBUG_PRINT("info", ("removing file: %s", ds_file_to_remove.str));
+    error= my_delete(ds_file_to_remove.str, MYF(0)) != 0;
+    if (error)
+      break;
+  }
+  my_dirend(dir_info);
+
+end:
+  handle_command_error(command, error);
+  dynstr_free(&ds_directory);
+  dynstr_free(&ds_wild);
+  dynstr_free(&ds_file_to_remove);
+  DBUG_VOID_RETURN;
+}
+
+
+/*
+  SYNOPSIS
   do_copy_file
   command	command handle
 
@@ -3696,49 +3789,58 @@ void do_perl(struct st_command *command)
                      sizeof(perl_args)/sizeof(struct command_arg),
                      ' ');
 
-  /* If no delimiter was provided, use EOF */
-  if (ds_delimiter.length == 0)
-    dynstr_set(&ds_delimiter, "EOF");
+  ds_script= command->content;
+  /* If it hasn't been done already by a loop iteration, fill it in */
+  if (! ds_script.str)
+  {
+    /* If no delimiter was provided, use EOF */
+    if (ds_delimiter.length == 0)
+      dynstr_set(&ds_delimiter, "EOF");
 
-  init_dynamic_string(&ds_script, "", 1024, 1024);
-  read_until_delimiter(&ds_script, &ds_delimiter);
+    init_dynamic_string(&ds_script, "", 1024, 1024);
+    read_until_delimiter(&ds_script, &ds_delimiter);
+    command->content= ds_script;
+  }
 
-  DBUG_PRINT("info", ("Executing perl: %s", ds_script.str));
+  /* This function could be called even if "false", so check before doing */
+  if (cur_block->ok)
+  {
+    DBUG_PRINT("info", ("Executing perl: %s", ds_script.str));
 
-  /* Create temporary file name */
-  if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
-                            "tmp", O_CREAT | O_SHARE | O_RDWR,
-                            MYF(MY_WME))) < 0)
-    die("Failed to create temporary file for perl command");
-  my_close(fd, MYF(0));
+    /* Create temporary file name */
+    if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
+                              "tmp", O_CREAT | O_SHARE | O_RDWR,
+                              MYF(MY_WME))) < 0)
+      die("Failed to create temporary file for perl command");
+    my_close(fd, MYF(0));
 
-  str_to_file(temp_file_path, ds_script.str, ds_script.length);
+    str_to_file(temp_file_path, ds_script.str, ds_script.length);
 
-  /* Format the "perl <filename>" command */
-  my_snprintf(buf, sizeof(buf), "perl %s", temp_file_path);
+    /* Format the "perl <filename>" command */
+    my_snprintf(buf, sizeof(buf), "perl %s", temp_file_path);
 
-  if (!(res_file= popen(buf, "r")) && command->abort_on_error)
-    die("popen(\"%s\", \"r\") failed", buf);
+    if (!(res_file= popen(buf, "r")) && command->abort_on_error)
+     die("popen(\"%s\", \"r\") failed", buf);
 
-  while (fgets(buf, sizeof(buf), res_file))
-  {
-    if (disable_result_log)
-    {
-      buf[strlen(buf)-1]=0;
-      DBUG_PRINT("exec_result",("%s", buf));
-    }
-    else
+    while (fgets(buf, sizeof(buf), res_file))
     {
-      replace_dynstr_append(&ds_res, buf);
+      if (disable_result_log)
+      {
+	buf[strlen(buf)-1]=0;
+	DBUG_PRINT("exec_result",("%s", buf));
+      }
+      else
+      {
+	replace_dynstr_append(&ds_res, buf);
+      }
     }
-  }
-  error= pclose(res_file);
+    error= pclose(res_file);
 
-  /* Remove the temporary file */
-  my_delete(temp_file_path, MYF(0));
+    /* Remove the temporary file */
+    my_delete(temp_file_path, MYF(0));
 
-  handle_command_error(command, WEXITSTATUS(error));
-  dynstr_free(&ds_script);
+    handle_command_error(command, WEXITSTATUS(error));
+  }
   dynstr_free(&ds_delimiter);
   DBUG_VOID_RETURN;
 }
@@ -4177,10 +4279,19 @@ int do_disable_rpl_parse(struct st_comma
 int do_sleep(struct st_command *command, my_bool real_sleep)
 {
   int error= 0;
-  char *p= command->first_argument;
-  char *sleep_start, *sleep_end= command->end;
+  char *sleep_start, *sleep_end;
   double sleep_val;
+  char *p;
+  static DYNAMIC_STRING ds_sleep;
+  const struct command_arg sleep_args[] = {
+    { "sleep_delay", ARG_STRING, TRUE, &ds_sleep, "Number of seconds to sleep." }
+  };
+  check_command_args(command, command->first_argument, sleep_args,
+                     sizeof(sleep_args)/sizeof(struct command_arg),
+                     ' ');
 
+  p= ds_sleep.str;
+  sleep_end= ds_sleep.str + ds_sleep.length;
   while (my_isspace(charset_info, *p))
     p++;
   if (!*p)
@@ -4189,11 +4300,13 @@ int do_sleep(struct st_command *command,
   /* Check that arg starts with a digit, not handled by my_strtod */
   if (!my_isdigit(charset_info, *sleep_start))
     die("Invalid argument to %.*s \"%s\"", command->first_word_len,
-        command->query,command->first_argument);
+        command->query, sleep_start);
   sleep_val= my_strtod(sleep_start, &sleep_end, &error);
+  check_eol_junk_line(sleep_end);
   if (error)
     die("Invalid argument to %.*s \"%s\"", command->first_word_len,
         command->query, command->first_argument);
+  dynstr_free(&ds_sleep);
 
   /* Fixed sleep time selected by --sleep option */
   if (opt_sleep >= 0 && !real_sleep)
@@ -4202,7 +4315,6 @@ int do_sleep(struct st_command *command,
   DBUG_PRINT("info", ("sleep_val: %f", sleep_val));
   if (sleep_val)
     my_sleep((ulong) (sleep_val * 1000000L));
-  command->last_argument= sleep_end;
   return 0;
 }
 
@@ -4740,7 +4852,8 @@ void do_close_connection(struct st_comma
   if (con->util_mysql)
     mysql_close(con->util_mysql);
   con->util_mysql= 0;
-
+  con->pending= FALSE;
+  
   my_free(con->name, MYF(0));
 
   /*
@@ -5074,7 +5187,7 @@ void do_connect(struct st_command *comma
   {
     if (!(con_slot= find_connection_by_name("-closed_connection-")))
       die("Connection limit exhausted, you can have max %d connections",
-          (int) (sizeof(connections)/sizeof(struct st_connection)));
+          opt_max_connections);
   }
 
 #ifdef EMBEDDED_LIBRARY
@@ -5188,6 +5301,12 @@ int do_done(struct st_command *command)
   }
   else
   {
+    if (*cur_block->delim) 
+    {
+      /* Restore "old" delimiter after false if block */
+      strcpy (delimiter, cur_block->delim);
+      delimiter_length= strlen(delimiter);
+    }
     /* Pop block from stack, goto next line */
     cur_block--;
     parser.current_line++;
@@ -5246,6 +5365,7 @@ void do_block(enum block_cmd cmd, struct
     cur_block++;
     cur_block->cmd= cmd;
     cur_block->ok= FALSE;
+    cur_block->delim[0]= '\0';
     DBUG_VOID_RETURN;
   }
 
@@ -5282,6 +5402,15 @@ void do_block(enum block_cmd cmd, struct
   if (not_expr)
     cur_block->ok = !cur_block->ok;
 
+  if (cur_block->ok) 
+  {
+    cur_block->delim[0]= '\0';
+  } else
+  {
+    /* Remember "old" delimiter if entering a false if block */
+    strcpy (cur_block->delim, delimiter);
+  }
+  
   DBUG_PRINT("info", ("OK: %d", cur_block->ok));
 
   var_free(&v);
@@ -5384,7 +5513,7 @@ int read_line(char *buf, int size)
   found_eof:
       if (cur_file->file != stdin)
       {
-	my_fclose(cur_file->file, MYF(0));
+	fclose(cur_file->file);
         cur_file->file= 0;
       }
       my_free((uchar*) cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR));
@@ -5787,7 +5916,7 @@ static struct my_option my_long_options[
   {"basedir", 'b', "Basedir for tests.", (uchar**) &opt_basedir,
    (uchar**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"character-sets-dir", OPT_CHARSETS_DIR,
-   "Directory where character sets are.", (uchar**) &opt_charsets_dir,
+   "Directory for character set files.", (uchar**) &opt_charsets_dir,
    (uchar**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"compress", 'C', "Use the compressed server/client protocol.",
    (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
@@ -5817,13 +5946,17 @@ static struct my_option my_long_options[
   {"logdir", OPT_LOG_DIR, "Directory for log files", (uchar**) &opt_logdir,
    (uchar**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"mark-progress", OPT_MARK_PROGRESS,
-   "Write linenumber and elapsed time to <testname>.progress ",
+   "Write line number and elapsed time to <testname>.progress.",
    (uchar**) &opt_mark_progress, (uchar**) &opt_mark_progress, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
-   "Max number of connection attempts when connecting to server",
+   "Maximum number of attempts to connect to server.",
    (uchar**) &opt_max_connect_retries, (uchar**) &opt_max_connect_retries, 0,
    GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
+  {"max-connections", OPT_MAX_CONNECTIONS,
+   "Max number of open connections to server",
+   (uchar**) &opt_max_connections, (uchar**) &opt_max_connections, 0,
+   GET_INT, REQUIRED_ARG, 128, 8, 5120, 0, 0, 0},
   {"password", 'p', "Password to use when connecting to server.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"port", 'P', "Port number to use for connection or 0 for default to, in "
@@ -5834,14 +5967,15 @@ static struct my_option my_long_options[
    "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
    (uchar**) &opt_port,
    (uchar**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"ps-protocol", OPT_PS_PROTOCOL, "Use prepared statements protocol for communication",
+  {"ps-protocol", OPT_PS_PROTOCOL, 
+   "Use prepared-statement protocol for communication.",
    (uchar**) &ps_protocol, (uchar**) &ps_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"quiet", 's', "Suppress all normal output.", (uchar**) &silent,
    (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"record", 'r', "Record output of test_file into result file.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"result-file", 'R', "Read/Store result from/in this file.",
+  {"result-file", 'R', "Read/store result from/in this file.",
    (uchar**) &result_file_name, (uchar**) &result_file_name, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"result-format-version", OPT_RESULT_FORMAT_VERSION,
@@ -5864,23 +5998,23 @@ static struct my_option my_long_options[
   {"skip-safemalloc", OPT_SKIP_SAFEMALLOC,
    "Don't use the memory allocation checking.", 0, 0, 0, GET_NO_ARG, NO_ARG,
    0, 0, 0, 0, 0, 0},
-  {"sleep", 'T', "Sleep always this many seconds on sleep commands.",
+  {"sleep", 'T', "Always sleep this many seconds on sleep commands.",
    (uchar**) &opt_sleep, (uchar**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
    0, 0, 0},
-  {"socket", 'S', "Socket file to use for connection.",
+  {"socket", 'S', "The socket file to use for connection.",
    (uchar**) &unix_sock, (uchar**) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
    0, 0, 0},
-  {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select",
+  {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select.",
    (uchar**) &sp_protocol, (uchar**) &sp_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 #include "sslopt-longopts.h"
   {"tail-lines", OPT_TAIL_LINES,
-   "Number of lines of the resul to include in a failure report",
+   "Number of lines of the result to include in a failure report.",
    (uchar**) &opt_tail_lines, (uchar**) &opt_tail_lines, 0,
    GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
   {"test-file", 'x', "Read test from/in this file (default stdin).",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"timer-file", 'm', "File where the timing in micro seconds is stored.",
+  {"timer-file", 'm', "File where the timing in microseconds is stored.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"tmpdir", 't', "Temporary directory where sockets are put.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -5890,7 +6024,7 @@ static struct my_option my_long_options[
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"version", 'V', "Output version information and exit.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select",
+  {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select.",
    (uchar**) &view_protocol, (uchar**) &view_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
@@ -5991,7 +6125,7 @@ get_one_option(int optid, const struct m
     fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
     DBUG_ASSERT(cur_file == file_stack && cur_file->file == 0);
     if (!(cur_file->file=
-          my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
+          fopen(buff, "rb")))
       die("Could not open '%s' for reading, errno: %d", buff, errno);
     cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
     cur_file->lineno= 1;
@@ -6606,8 +6740,11 @@ void run_query_normal(struct st_connecti
     wait_query_thread_end(cn);
 #endif /*EMBEDDED_LIBRARY*/
   if (!(flags & QUERY_REAP_FLAG))
+  {
+    cn->pending= TRUE;
     DBUG_VOID_RETURN;
-
+  }
+  
   do
   {
     /*
@@ -6696,6 +6833,7 @@ void run_query_normal(struct st_connecti
 
 end:
 
+  cn->pending= FALSE;
   /*
     We save the return code (mysql_errno(mysql)) from the last call sent
     to the server into the mysqltest builtin variable $mysql_errno. This
@@ -7174,10 +7312,13 @@ void run_query(struct st_connection *cn,
 
   init_dynamic_string(&ds_warnings, NULL, 0, 256);
 
+  if (cn->pending && (flags & QUERY_SEND_FLAG))
+    die ("Cannot run query on connection between send and reap");
+
   /*
     Evaluate query if this is an eval command
   */
-  if (command->type == Q_EVAL)
+  if (command->type == Q_EVAL || command->type == Q_SEND_EVAL)
   {
     init_dynamic_string(&eval_query, "", command->query_len+256, 1024);
     do_eval(&eval_query, command->query, command->end, FALSE);
@@ -7696,12 +7837,6 @@ int main(int argc, char **argv)
   /* Init expected errors */
   memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
 
-  /* Init connections */
-  memset(connections, 0, sizeof(connections));
-  connections_end= connections +
-    (sizeof(connections)/sizeof(struct st_connection)) - 1;
-  next_con= connections + 1;
-
 #ifdef EMBEDDED_LIBRARY
   /* set appropriate stack for the 'query' threads */
   (void) pthread_attr_init(&cn_thd_attrib);
@@ -7728,7 +7863,14 @@ int main(int argc, char **argv)
                 1024, 0, 0, get_var_key, var_free, MYF(0)))
     die("Variable hash initialization failed");
 
-  var_set_string("$MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION);
+  var_set_string("MYSQL_SERVER_VERSION", MYSQL_SERVER_VERSION);
+  var_set_string("MYSQL_SYSTEM_TYPE", SYSTEM_TYPE);
+  var_set_string("MYSQL_MACHINE_TYPE", MACHINE_TYPE);
+  if (sizeof(void *) == 8) {
+    var_set_string("MYSQL_SYSTEM_ARCHITECTURE", "64");
+  } else {
+    var_set_string("MYSQL_SYSTEM_ARCHITECTURE", "32");
+  }
 
   memset(&master_pos, 0, sizeof(master_pos));
 
@@ -7756,6 +7898,13 @@ int main(int argc, char **argv)
     verbose_msg("Tracing progress in '%s'.", progress_file.file_name());
   }
 
+  /* Init connections, allocate 1 extra as buffer + 1 for default */
+  connections= (struct st_connection*)
+    my_malloc((opt_max_connections+2) * sizeof(struct st_connection),
+              MYF(MY_WME | MY_ZEROFILL));
+  connections_end= connections + opt_max_connections +1;
+  next_con= connections + 1;
+  
   var_set_int("$PS_PROTOCOL", ps_protocol);
   var_set_int("$SP_PROTOCOL", sp_protocol);
   var_set_int("$VIEW_PROTOCOL", view_protocol);
@@ -7855,7 +8004,8 @@ int main(int argc, char **argv)
       command->type= Q_COMMENT;
     }
 
-    my_bool ok_to_do= cur_block->ok;
+    /* delimiter needs to be executed so we can continue to parse */
+    my_bool ok_to_do= cur_block->ok || command->type == Q_DELIMITER;
     /*
       Some commands need to be "done" the first time if they may get
       re-iterated over in a true context. This can only happen if there's 
@@ -7916,6 +8066,7 @@ int main(int argc, char **argv)
       case Q_ECHO: do_echo(command); command_executed++; break;
       case Q_SYSTEM: do_system(command); break;
       case Q_REMOVE_FILE: do_remove_file(command); break;
+      case Q_REMOVE_FILES_WILDCARD: do_remove_files_wildcard(command); break;
       case Q_MKDIR: do_mkdir(command); break;
       case Q_RMDIR: do_rmdir(command); break;
       case Q_LIST_FILES: do_list_files(command); break;
@@ -7953,6 +8104,13 @@ int main(int argc, char **argv)
         */
 	display_result_sorted= TRUE;
         break;
+      case Q_LOWERCASE:
+        /*
+          Turn on lowercasing of result, will be reset after next
+          command
+        */
+        display_result_lower= TRUE;
+        break;
       case Q_LET: do_let(command); break;
       case Q_EVAL_RESULT:
         die("'eval_result' command  is deprecated");
@@ -8002,6 +8160,7 @@ int main(int argc, char **argv)
 	break;
       }
       case Q_SEND:
+      case Q_SEND_EVAL:
         if (!*command->first_argument)
         {
           /*
@@ -8196,8 +8355,9 @@ int main(int argc, char **argv)
       */
       free_all_replace();
 
-      /* Also reset "sorted_result" */
+      /* Also reset "sorted_result" and "lowercase"*/
       display_result_sorted= FALSE;
+      display_result_lower= FALSE;
     }
     last_command_executed= command_executed;
 
@@ -9537,7 +9697,7 @@ int insert_pointer_name(reg1 POINTER_ARR
   if (pa->length+length >= pa->max_length)
   {
     if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str,
-				      (uint) (pa->max_length+PS_MALLOC),
+                                      (uint) (pa->length+length+PS_MALLOC),
 				      MYF(MY_WME))))
       DBUG_RETURN(1);
     if (new_pos != pa->str)
@@ -9548,7 +9708,7 @@ int insert_pointer_name(reg1 POINTER_ARR
 					      char*);
       pa->str=new_pos;
     }
-    pa->max_length+=PS_MALLOC;
+    pa->max_length= pa->length+length+PS_MALLOC;
   }
   if (pa->typelib.count >= pa->max_count-1)
   {
@@ -9601,6 +9761,18 @@ void replace_dynstr_append_mem(DYNAMIC_S
   fix_win_paths(val, len);
 #endif
 
+  if (display_result_lower) 
+  {
+    /* Convert to lower case, and do this first */
+    char lower[512];
+    char *c= lower;
+    for (const char *v= val;  *v;  v++)
+      *c++= my_tolower(charset_info, *v);
+    *c= '\0';
+    /* Copy from this buffer instead */
+    val= lower;
+  }
+  
   if (glob_replace_regex)
   {
     /* Regex replace */

=== modified file 'cmd-line-utils/readline/rlmbutil.h'
--- a/cmd-line-utils/readline/rlmbutil.h	2007-11-19 13:38:08 +0000
+++ b/cmd-line-utils/readline/rlmbutil.h	2010-02-22 13:23:47 +0000
@@ -109,8 +109,8 @@ extern int _rl_is_mbchar_matched PARAMS(
 extern wchar_t _rl_char_value PARAMS((char *, int));
 extern int _rl_walphabetic PARAMS((wchar_t));
 
-#define _rl_to_wupper(wc)	(iswlower (wc) ? towupper (wc) : (wc))
-#define _rl_to_wlower(wc)	(iswupper (wc) ? towlower (wc) : (wc))
+#define _rl_to_wupper(wc)	(iswlower (wc) ? (wchar_t)towupper (wc) : (wc))
+#define _rl_to_wlower(wc)	(iswupper (wc) ? (wchar_t)towlower (wc) : (wc))
 
 #define MB_NEXTCHAR(b,s,c,f) \
 	((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \

=== modified file 'cmd-line-utils/readline/text.c'
--- a/cmd-line-utils/readline/text.c	2009-06-29 13:17:01 +0000
+++ b/cmd-line-utils/readline/text.c	2010-02-22 13:23:47 +0000
@@ -614,7 +614,7 @@ rl_arrow_keys (count, c)
 #ifdef HANDLE_MULTIBYTE
 static char pending_bytes[MB_LEN_MAX];
 static int pending_bytes_length = 0;
-static mbstate_t ps = {0};
+static mbstate_t ps;
 #endif
 
 /* Insert the character C at the current location, moving point forward.

=== modified file 'configure.in'
--- a/configure.in	2010-03-12 06:06:23 +0000
+++ b/configure.in	2010-06-09 14:07:08 +0000
@@ -7,7 +7,16 @@ AC_PREREQ(2.59)
 # Remember to also update version.c in ndb.
 # When changing major version number please also check switch statement
 # in mysqlbinlog::check_master_version().
-AC_INIT([MySQL Server], [5.1.44-ndb-6.2.19], [], [mysql])
+dnl Various people throughout the community may parse configure.in to
+dnl get the MySQL version from the source branch.  If the formatting
+dnl of this line is going to be changed, please announce the change to
+dnl internals@stripped in advance of pushing the change.
+dnl
+dnl When changing the major version number please also check the switch
+dnl statement in mysqlbinlog::check_master_version().  You may also need
+dnl to update version.c in ndb.
+AC_INIT([MySQL Server], [5.1.45-ndb-6.2.19], [], [mysql])
+
 AC_CONFIG_SRCDIR([sql/mysqld.cc])
 AC_CANONICAL_SYSTEM
 # USTAR format gives us the possibility to store longer path names in
@@ -2714,7 +2723,7 @@ case $SYSTEM_TYPE in
     fi
 
     # if there is no readline, but we want to build with readline, we fail
-    if [test "$want_to_use_readline" = "yes"] && [test ! -d "./cmd-line-utils/readline"]
+    if [test "$want_to_use_readline" = "yes"] && [test ! -d "$srcdir/cmd-line-utils/readline"]
     then
 	AC_MSG_ERROR([This commercially licensed MySQL source package can't
 	      be built with libreadline. Please use --with-libedit to use

=== modified file 'extra/yassl/include/yassl_error.hpp'
--- a/extra/yassl/include/yassl_error.hpp	2009-05-26 18:53:34 +0000
+++ b/extra/yassl/include/yassl_error.hpp	2010-06-09 14:07:08 +0000
@@ -64,7 +64,7 @@ enum YasslError {
 enum Library { yaSSL_Lib = 0, CryptoLib, SocketLib };
 enum { MAX_ERROR_SZ = 80 };
 
-void SetErrorString(YasslError, char*);
+void SetErrorString(unsigned long, char*);
 
 /* remove for now, if go back to exceptions use this wrapper
 // Base class for all yaSSL exceptions

=== modified file 'extra/yassl/src/ssl.cpp'
--- a/extra/yassl/src/ssl.cpp	2009-05-26 18:53:34 +0000
+++ b/extra/yassl/src/ssl.cpp	2010-06-09 14:07:08 +0000
@@ -991,7 +991,7 @@ char* ERR_error_string(unsigned long err
   static char* msg = (char*)"Please supply a buffer for error string";
 
     if (buffer) {
-        SetErrorString(YasslError(errNumber), buffer);
+        SetErrorString(errNumber, buffer);
         return buffer;
     }
 

=== modified file 'extra/yassl/src/yassl_error.cpp'
--- a/extra/yassl/src/yassl_error.cpp	2009-05-26 18:53:34 +0000
+++ b/extra/yassl/src/yassl_error.cpp	2010-06-09 14:07:08 +0000
@@ -55,7 +55,7 @@ Library Error::get_lib() const
 */
 
 
-void SetErrorString(YasslError error, char* buffer)
+void SetErrorString(unsigned long error, char* buffer)
 {
     using namespace TaoCrypt;
     const int max = MAX_ERROR_SZ;  // shorthand

=== modified file 'mysql-test/include/mtr_warnings.sql'
--- a/mysql-test/include/mtr_warnings.sql	2010-03-12 06:06:23 +0000
+++ b/mysql-test/include/mtr_warnings.sql	2010-06-09 14:07:08 +0000
@@ -175,6 +175,19 @@ INSERT INTO global_suppressions VALUES
  ("Can't find file: '.\\\\test\\\\\\?{8}.frm'"),
  ("Slave: Unknown table 't1' Error_code: 1051"),
 
+ /* Messages from valgrind */
+ ("==[0-9]*== Memcheck,"),
+ ("==[0-9]*== Copyright"),
+ ("==[0-9]*== Using"),
+ ("==[0-9]*== For more details"),
+ /* This comes with innodb plugin tests */
+ ("==[0-9]*== Warning: set address range perms: large range"),
+
+ /* valgrind warnings: invalid file descriptor -1 in syscall
+    write()/read(). Bug #50414 */
+ ("==[0-9]*== Warning: invalid file descriptor -1 in syscall write()"),
+ ("==[0-9]*== Warning: invalid file descriptor -1 in syscall read()"),
+
  /*
    Transient network failures that cause warnings on reconnect.
    BUG#47743 and BUG#47983.

=== added file 'mysql-test/include/not_binlog_format_row.inc'
--- a/mysql-test/include/not_binlog_format_row.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/not_binlog_format_row.inc	2010-02-18 08:48:15 +0000
@@ -0,0 +1,4 @@
+if (`SELECT @@binlog_format = 'ROW'`)
+{
+     skip Test cannot run with binlog_format row;
+}

=== modified file 'mysql-test/lib/My/ConfigFactory.pm'
--- a/mysql-test/lib/My/ConfigFactory.pm	2009-12-17 10:14:52 +0000
+++ b/mysql-test/lib/My/ConfigFactory.pm	2010-06-09 14:07:08 +0000
@@ -373,11 +373,14 @@ sub post_check_client_group {
   
   if (IS_WINDOWS)
   {
-    # Shared memory base may or may not be defined (e.g not defined in embedded)
-    my $shm = $group_to_copy_from->option("shared-memory-base-name");
-    if (defined $shm)
+    if (! $self->{ARGS}->{embedded})
     {
-      $config->insert($client_group_name,"shared-memory-base-name", $shm->value());
+      # Shared memory base may or may not be defined (e.g not defined in embedded)
+      my $shm = $group_to_copy_from->option("shared-memory-base-name");
+      if (defined $shm)
+      {
+        $config->insert($client_group_name,"shared-memory-base-name", $shm->value());
+      }
     }
   }
 }

=== modified file 'mysql-test/lib/My/SafeProcess.pm'
--- a/mysql-test/lib/My/SafeProcess.pm	2009-08-25 19:44:04 +0000
+++ b/mysql-test/lib/My/SafeProcess.pm	2010-06-09 14:07:08 +0000
@@ -82,24 +82,28 @@ sub is_child {
 }
 
 
-# Find the safe process binary or script
 my @safe_process_cmd;
 my $safe_kill;
-if (IS_WIN32PERL or IS_CYGWIN){
-  # Use my_safe_process.exe
-  my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
-		       "my_safe_process");
-  push(@safe_process_cmd, $exe);
-
-  # Use my_safe_kill.exe
-  $safe_kill= my_find_bin(".", "lib/My/SafeProcess", "my_safe_kill");
-}
-else
-{
-  # Use my_safe_process
-  my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
-		       "my_safe_process");
-  push(@safe_process_cmd, $exe);
+
+# Find the safe process binary or script
+sub find_bin {
+  if (IS_WIN32PERL or IS_CYGWIN)
+  {
+    # Use my_safe_process.exe
+    my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
+			 "my_safe_process");
+    push(@safe_process_cmd, $exe);
+
+    # Use my_safe_kill.exe
+    $safe_kill= my_find_bin(".", "lib/My/SafeProcess", "my_safe_kill");
+  }
+  else
+  {
+    # Use my_safe_process
+    my $exe= my_find_bin(".", ["lib/My/SafeProcess", "My/SafeProcess"],
+			 "my_safe_process");
+    push(@safe_process_cmd, $exe);
+  }
 }
 
 
@@ -185,63 +189,6 @@ sub run {
 }
 
 #
-# Start a process that returns after "duration" seconds
-# or when it's parent process does not exist anymore
-#
-sub timer {
-  my $class= shift;
-  my $duration= shift or croak "duration required";
-  my $parent_pid= $$;
-
-  my $pid= My::SafeProcess::Base::_safe_fork();
-  if ($pid){
-    # Parent
-    my $proc= bless
-      ({
-	SAFE_PID  => $pid,
-	SAFE_NAME => "timer",
-	PARENT => $$,
-       }, $class);
-
-    # Put the new process in list of running
-    $running{$pid}= $proc;
-    return $proc;
-  }
-
-  # Child, install signal handlers and sleep for "duration"
-  $SIG{INT}= 'IGNORE';
-
-  $SIG{TERM}= sub {
-    #print STDERR "timer $$: woken up, exiting!\n";
-    exit(0);
-  };
-
-  $0= "safe_timer($duration)";
-
-  if (IS_WIN32PERL){
-    # Just a thread in same process
-    sleep($duration);
-    print STDERR "timer $$: expired after $duration seconds\n";
-    exit(0);
-  }
-
-  my $count_down= $duration;
-  while($count_down--){
-
-    # Check that parent is still alive
-    if (kill(0, $parent_pid) == 0){
-      #print STDERR "timer $$: parent gone, exiting!\n";
-      exit(0);
-    }
-
-    sleep(1);
-  }
-  print STDERR "timer $$: expired after $duration seconds\n";
-  exit(0);
-}
-
-
-#
 # Shutdown process nicely, and wait for shutdown_timeout seconds
 # If processes hasn't shutdown, kill them hard and wait for return
 #
@@ -350,12 +297,12 @@ sub start_kill {
     $ret= system($safe_kill, $winpid) >> 8;
 
     if ($ret == 3){
-      print "Couldn't open the winpid: $winpid ",
+      print "Couldn't open the winpid: $winpid ".
 	"for pid: $pid, try one more time\n";
       sleep(1);
       $winpid= _winpid($pid);
       $ret= system($safe_kill, $winpid) >> 8;
-      print "Couldn't open the winpid: $winpid ",
+      print "Couldn't open the winpid: $winpid ".
 	"for pid: $pid, continue and see what happens...\n";
     }
   }
@@ -550,6 +497,40 @@ sub wait_any {
 
 
 #
+# Wait for any process to exit, or a timeout
+#
+# Returns a reference to the SafeProcess that
+# exited or a pseudo-process with $proc->{timeout} == 1
+#
+
+sub wait_any_timeout {
+  my $class= shift;
+  my $timeout= shift;
+  my $proc;
+  my $millis=10;
+
+  do {
+    ::mtr_milli_sleep($millis);
+    # Slowly increse interval up to max. 1 second
+    $millis++ if $millis < 1000;
+    # Return a "fake" process for timeout
+    if (::has_expired($timeout)) {
+      $proc= bless
+	({
+	  SAFE_PID  => 0,
+	  SAFE_NAME => "timer",
+	  timeout => 1,
+	 }, $class);
+    } else {
+      $proc= check_any();
+    }
+  } while (! $proc);
+
+  return $proc;
+}
+
+
+#
 # Wait for all processes to exit
 #
 sub wait_all {
@@ -606,7 +587,7 @@ sub self2str {
 
 sub _verbose {
   return unless $_verbose;
-  print STDERR " ## ", @_, "\n";
+  print STDERR " ## ". @_. "\n";
 }
 
 

=== modified file 'mysql-test/lib/My/SafeProcess/safe_process_win.cc'
--- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc	2009-12-17 10:14:52 +0000
+++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc	2010-06-09 14:07:08 +0000
@@ -189,14 +189,20 @@ int main(int argc, const char** argv )
         die("No real args -> nothing to do");
       /* Copy the remaining args to child_arg */
       for (int j= i+1; j < argc; j++) {
-	if (strchr (argv[j], ' ')) {
-	  /* Protect with "" if this arg contains a space */
-	  to+= _snprintf(to, child_args + sizeof(child_args) - to,
-                         "\"%s\" ", argv[j]);
-	} else {
-	  to+= _snprintf(to, child_args + sizeof(child_args) - to,
-	                 "%s ", argv[j]);
-	}
+        arg= argv[j];
+        if (strchr (arg, ' ') &&
+            arg[0] != '\"' &&
+            arg[strlen(arg)] != '\"')
+        {
+          /* Quote arg that contains spaces and are not quoted already */
+          to+= _snprintf(to, child_args + sizeof(child_args) - to,
+                         "\"%s\" ", arg);
+        }
+        else
+        {
+          to+= _snprintf(to, child_args + sizeof(child_args) - to,
+          "%s ", arg);
+        }
       }
       break;
     } else {

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2010-03-12 06:06:23 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2010-06-09 14:07:08 +0000
@@ -41,7 +41,6 @@ our $default_storage_engine;
 our $opt_with_ndbcluster_only;
 our $defaults_file;
 our $defaults_extra_file;
-our $reorder= 1;
 our $quick_collect;
 
 sub collect_option {
@@ -100,7 +99,8 @@ sub init_pattern {
 #
 ##############################################################################
 
-sub collect_test_cases ($$) {
+sub collect_test_cases ($$$) {
+  my $opt_reorder= shift; # True if we're reordering tests
   my $suites= shift; # Semicolon separated list of test suites
   my $opt_cases= shift;
   my $cases= []; # Array of hash(one hash for each testcase)
@@ -119,10 +119,16 @@ sub collect_test_cases ($$) {
 		      !(IS_WINDOWS && $::opt_embedded_server) &&
 		      $lib_innodb_plugin);
 
-  foreach my $suite (split(",", $suites))
+  # If not reordering, we also shouldn't group by suites, unless
+  # no test cases were named.
+  # This also effects some logic in the loop following this.
+  if ($opt_reorder or !@$opt_cases)
   {
-    push(@$cases, collect_one_suite($suite, $opt_cases));
-    last if $some_test_found;
+    foreach my $suite (split(",", $suites))
+    {
+      push(@$cases, collect_one_suite($suite, $opt_cases));
+      last if $some_test_found;
+    }
   }
 
   if ( @$opt_cases )
@@ -136,6 +142,7 @@ sub collect_test_cases ($$) {
       my ($sname, $tname, $extension)= split_testname($test_name_spec);
       foreach my $test ( @$cases )
       {
+	last unless $opt_reorder;
 	# test->{name} is always in suite.name format
 	if ( $test->{name} =~ /.*\.$tname/ )
 	{
@@ -145,12 +152,13 @@ sub collect_test_cases ($$) {
       }
       if ( not $found )
       {
+	$sname= "main" if !$opt_reorder and !$sname;
 	mtr_error("Could not find '$tname' in '$suites' suite(s)") unless $sname;
-	# If suite was part of name, find it there
-	my ($this_case) = collect_one_suite($sname, [ $tname ]);
-	if ($this_case)
+	# If suite was part of name, find it there, may come with combinations
+	my @this_case = collect_one_suite($sname, [ $tname ]);
+	if (@this_case)
         {
-	  push (@$cases, $this_case);
+	  push (@$cases, @this_case);
 	}
 	else
 	{
@@ -160,7 +168,7 @@ sub collect_test_cases ($$) {
     }
   }
 
-  if ( $reorder && !$quick_collect)
+  if ( $opt_reorder && !$quick_collect)
   {
     # Reorder the test cases in an order that will make them faster to run
     my %sort_criteria;

=== modified file 'mysql-test/lib/mtr_gprof.pl'
--- a/mysql-test/lib/mtr_gprof.pl	2009-05-26 18:53:34 +0000
+++ b/mysql-test/lib/mtr_gprof.pl	2010-06-09 14:07:08 +0000
@@ -21,43 +21,20 @@
 
 use strict;
 
-# These are not to be prefixed with "mtr_"
+sub gprof_collect ($@) {
+  my ($exe_mysqld, @gprof_dirs)= @_;
 
-sub gprof_prepare ();
-sub gprof_collect ();
+  print ("Collecting gprof reports.....\n");
 
-##############################################################################
-#
-#  
-#
-##############################################################################
-
-sub gprof_prepare () {
-
-  rmtree($::opt_gprof_dir);
-  mkdir($::opt_gprof_dir);
-}
-
-# FIXME what about master1 and slave1?!
-sub gprof_collect () {
-
-  if ( -f "$::master->[0]->{'path_myddir'}/gmon.out" )
-  {
-    # FIXME check result code?!
-    mtr_run("gprof",
-            [$::exe_master_mysqld,
-             "$::master->[0]->{'path_myddir'}/gmon.out"],
-            $::opt_gprof_master, "", "", "");
-    print "Master execution profile has been saved in $::opt_gprof_master\n";
-  }
-  if ( -f "$::slave->[0]->{'path_myddir'}/gmon.out" )
+  foreach my $datadir (@gprof_dirs)
   {
-    # FIXME check result code?!
-    mtr_run("gprof",
-            [$::exe_slave_mysqld,
-             "$::slave->[0]->{'path_myddir'}/gmon.out"],
-            $::opt_gprof_slave, "", "", "");
-    print "Slave execution profile has been saved in $::opt_gprof_slave\n";
+    my $gprof_msg= "$datadir/gprof.msg";
+    my $gprof_err= "$datadir/gprof.err";
+    if ( -f "$datadir/gmon.out" )
+    {
+      system("gprof $exe_mysqld $datadir/gmon.out 2>$gprof_err >$gprof_msg");
+      print ("GPROF output in $gprof_msg, errors in $gprof_err\n");
+    }
   }
 }
 

=== modified file 'mysql-test/lib/mtr_misc.pl'
--- a/mysql-test/lib/mtr_misc.pl	2009-05-26 18:53:34 +0000
+++ b/mysql-test/lib/mtr_misc.pl	2010-06-09 14:07:08 +0000
@@ -31,7 +31,9 @@ sub mtr_script_exists(@);
 sub mtr_file_exists(@);
 sub mtr_exe_exists(@);
 sub mtr_exe_maybe_exists(@);
-
+sub mtr_milli_sleep($);
+sub start_timer($);
+sub has_expired($);
 
 ##############################################################################
 #
@@ -168,11 +170,18 @@ sub mtr_exe_exists (@) {
 }
 
 
-sub mtr_milli_sleep {
+sub mtr_milli_sleep ($) {
   die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1;
   my ($millis)= @_;
 
   select(undef, undef, undef, ($millis/1000));
 }
 
+# Simple functions to start and check timers (have to be actively polled)
+# Timer can be "killed" by setting it to 0
+
+sub start_timer ($) { return time + $_[0]; }
+
+sub has_expired ($) { return $_[0] && time gt $_[0]; }
+
 1;

=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm	2009-12-17 10:14:52 +0000
+++ b/mysql-test/lib/mtr_report.pm	2010-06-09 14:07:08 +0000
@@ -70,7 +70,7 @@ sub _mtr_report_test_name ($) {
   $tname.= " '$tinfo->{combination}'"
     if defined $tinfo->{combination};
 
-  print _name(), _timestamp();
+  print _name(). _timestamp();
   printf "%-40s ", $tname;
   my $worker = $tinfo->{worker};
   printf "w$worker " if $worker;
@@ -223,8 +223,8 @@ sub mtr_report_test ($) {
 }
 
 
-sub mtr_report_stats ($;$) {
-  my ($tests, $dont_error)= @_;
+sub mtr_report_stats ($$;$) {
+  my ($prefix, $tests, $dont_error)= @_;
 
   # ----------------------------------------------------------------------
   # Find out how we where doing
@@ -339,6 +339,9 @@ sub mtr_report_stats ($;$) {
     }
   }
 
+  # Print summary line prefix
+  print "$prefix: ";
+
   # Print a list of testcases that failed
   if ( $tot_failed != 0 )
   {
@@ -404,13 +407,13 @@ sub mtr_report_stats ($;$) {
 ##############################################################################
 
 sub mtr_print_line () {
-  print '-' x 60, "\n";
+  print '-' x 60 . "\n";
 }
 
 
 sub mtr_print_thick_line {
   my $char= shift || '=';
-  print $char x 78, "\n";
+  print $char x 78 . "\n";
 }
 
 
@@ -468,7 +471,7 @@ sub _timestamp {
 
 # Always print message to screen
 sub mtr_print (@) {
-  print _name(), join(" ", @_), "\n";
+  print _name(). join(" ", @_). "\n";
 }
 
 
@@ -476,22 +479,22 @@ sub mtr_print (@) {
 sub mtr_report (@) {
   if (defined $verbose)
   {
-    print _name(), join(" ", @_), "\n";
+    print _name(). join(" ", @_). "\n";
   }
 }
 
 
 # Print warning to screen
 sub mtr_warning (@) {
-  print STDERR _name(), _timestamp(),
-    "mysql-test-run: WARNING: ", join(" ", @_), "\n";
+  print STDERR _name(). _timestamp().
+    "mysql-test-run: WARNING: ". join(" ", @_). "\n";
 }
 
 
 # Print error to screen and then exit
 sub mtr_error (@) {
-  print STDERR _name(), _timestamp(),
-    "mysql-test-run: *** ERROR: ", join(" ", @_), "\n";
+  print STDERR _name(). _timestamp().
+    "mysql-test-run: *** ERROR: ". join(" ", @_). "\n";
   if (IS_WINDOWS)
   {
     POSIX::_exit(1);
@@ -506,8 +509,8 @@ sub mtr_error (@) {
 sub mtr_debug (@) {
   if ( $verbose > 2 )
   {
-    print STDERR _name(),
-      _timestamp(), "####: ", join(" ", @_), "\n";
+    print STDERR _name().
+      _timestamp(). "####: ". join(" ", @_). "\n";
   }
 }
 
@@ -515,8 +518,8 @@ sub mtr_debug (@) {
 sub mtr_verbose (@) {
   if ( $verbose )
   {
-    print STDERR _name(), _timestamp(),
-      "> ",join(" ", @_),"\n";
+    print STDERR _name(). _timestamp().
+      "> ".join(" ", @_)."\n";
   }
 }
 
@@ -526,8 +529,8 @@ sub mtr_verbose_restart (@) {
   my $proc= $server->{proc};
   if ( $verbose_restart )
   {
-    print STDERR _name(),_timestamp(),
-      "> Restart $proc - ",join(" ", @args),"\n";
+    print STDERR _name()._timestamp().
+      "> Restart $proc - ".join(" ", @args)."\n";
   }
 }
 

=== modified file 'mysql-test/lib/mtr_stress.pl'
--- a/mysql-test/lib/mtr_stress.pl	2009-05-26 18:53:34 +0000
+++ b/mysql-test/lib/mtr_stress.pl	2010-06-09 14:07:08 +0000
@@ -151,7 +151,7 @@ sub run_stress_test () 
   mtr_add_arg($args, "--verbose");
   mtr_add_arg($args, "--cleanup");
   mtr_add_arg($args, "--log-error-details");
-  mtr_add_arg($args, "--abort-on-error");
+  mtr_add_arg($args, "--abort-on-error=1");
 
   if ( $::opt_stress_init_file )
   {

=== modified file 'mysql-test/lib/v1/mtr_stress.pl'
--- a/mysql-test/lib/v1/mtr_stress.pl	2009-05-26 18:53:34 +0000
+++ b/mysql-test/lib/v1/mtr_stress.pl	2010-06-09 14:07:08 +0000
@@ -151,7 +151,7 @@ sub run_stress_test () 
   mtr_add_arg($args, "--verbose");
   mtr_add_arg($args, "--cleanup");
   mtr_add_arg($args, "--log-error-details");
-  mtr_add_arg($args, "--abort-on-error");
+  mtr_add_arg($args, "--abort-on-error=1");
 
   if ( $::opt_stress_init_file )
   {

=== modified file 'mysql-test/lib/v1/mysql-test-run.pl'
--- a/mysql-test/lib/v1/mysql-test-run.pl	2010-03-12 06:06:23 +0000
+++ b/mysql-test/lib/v1/mysql-test-run.pl	2010-06-09 14:07:08 +0000
@@ -906,6 +906,11 @@ sub command_line_setup () {
   mtr_report("Using default engine '$used_default_engine'")
     if defined $used_default_engine;
 
+  if ($glob_win32 and defined $opt_mem) {
+    mtr_report("--mem not supported on Windows, ignored");
+    $opt_mem= undef;
+  }
+
   # --------------------------------------------------------------------------
   # Check if we should speed up tests by trying to run on tmpfs
   # --------------------------------------------------------------------------

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2010-03-12 06:06:23 +0000
+++ b/mysql-test/mysql-test-run.pl	2010-06-09 14:07:08 +0000
@@ -68,8 +68,8 @@ use My::File::Path; # Patched version of
 use File::Basename;
 use File::Copy;
 use File::Find;
-use File::Temp qw / tempdir /;
-use File::Spec::Functions qw / splitdir /;
+use File::Temp qw/tempdir/;
+use File::Spec::Functions qw/splitdir/;
 use My::Platform;
 use My::SafeProcess;
 use My::ConfigFactory;
@@ -87,6 +87,7 @@ use IO::Select;
 require "lib/mtr_process.pl";
 require "lib/mtr_io.pl";
 require "lib/mtr_gcov.pl";
+require "lib/mtr_gprof.pl";
 require "lib/mtr_misc.pl";
 
 $SIG{INT}= sub { mtr_error("Got ^C signal"); };
@@ -118,6 +119,8 @@ END {
   }
 }
 
+sub env_or_val($$) { defined $ENV{$_[0]} ? $ENV{$_[0]} : $_[1] }
+
 my $path_config_file;           # The generated config file, var/my.cnf
 
 # Visual Studio produces executables in different sub-directories based on the
@@ -167,6 +170,9 @@ our $opt_gcov_exe= "gcov";
 our $opt_gcov_err= "mysql-test-gcov.msg";
 our $opt_gcov_msg= "mysql-test-gcov.err";
 
+our $opt_gprof;
+our %gprof_dirs;
+
 our $glob_debugger= 0;
 our $opt_gdb;
 our $opt_client_gdb;
@@ -185,7 +191,9 @@ our $opt_experimental = "collections/def
 our $experimental_test_cases;
 
 my $baseport;
+# $opt_build_thread may later be set from $opt_port_base
 my $opt_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
+my $opt_port_base= $ENV{'MTR_PORT_BASE'} || "auto";
 my $build_thread= 0;
 
 my $opt_record;
@@ -195,6 +203,7 @@ my $opt_skip_core;
 
 our $opt_check_testcases= 1;
 my $opt_mark_progress;
+my $opt_max_connections;
 
 my $opt_sleep;
 
@@ -213,7 +222,8 @@ my $start_only;
 my $opt_wait_all;
 my $opt_repeat= 1;
 my $opt_retry= 3;
-my $opt_retry_failure= 2;
+my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
+my $opt_reorder= 1;
 
 my $opt_strace_client;
 
@@ -226,6 +236,7 @@ my @default_valgrind_args= ("--show-reac
 my @valgrind_args;
 my $opt_valgrind_path;
 my $opt_callgrind;
+my %mysqld_logs;
 my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions.
 
 our $opt_warnings= 1;
@@ -243,9 +254,9 @@ our %mysqld_variables;
 
 my $source_dist= 0;
 
-my $opt_max_save_core= $ENV{MTR_MAX_SAVE_CORE} || 5;
-my $opt_max_save_datadir= $ENV{MTR_MAX_SAVE_DATADIR} || 20;
-my $opt_max_test_fail= $ENV{MTR_MAX_TEST_FAIL} || 10;
+my $opt_max_save_core= env_or_val(MTR_MAX_SAVE_CORE => 5);
+my $opt_max_save_datadir= env_or_val(MTR_MAX_SAVE_DATADIR => 20);
+my $opt_max_test_fail= env_or_val(MTR_MAX_TEST_FAIL => 10);
 
 my $opt_parallel= $ENV{MTR_PARALLEL} || 1;
 
@@ -266,6 +277,9 @@ sub main {
 
   command_line_setup();
 
+  # --help will not reach here, so now it's safe to assume we have binaries
+  My::SafeProcess::find_bin();
+
   if ( $opt_gcov ) {
     gcov_prepare($basedir);
   }
@@ -298,7 +312,7 @@ sub main {
   }
 
   mtr_report("Collecting tests...");
-  my $tests= collect_test_cases($opt_suites, \@opt_cases);
+  my $tests= collect_test_cases($opt_reorder, $opt_suites, \@opt_cases);
 
   if ( $opt_report_features ) {
     # Put "report features" as the first test to run
@@ -415,7 +429,7 @@ sub main {
 		 $opt_gcov_msg, $opt_gcov_err);
   }
 
-  mtr_report_stats($completed);
+  mtr_report_stats("Completed", $completed);
 
   exit(0);
 }
@@ -439,7 +453,7 @@ sub run_test_server ($$$) {
   my $result;
   my $exe_mysqld= find_mysqld($basedir) || ""; # Used as hint to CoreDump
 
-  my $suite_timeout_proc= My::SafeProcess->timer(suite_timeout());
+  my $suite_timeout= start_timer(suite_timeout());
 
   my $s= IO::Select->new();
   $s->add($server);
@@ -460,7 +474,6 @@ sub run_test_server ($$$) {
 	  mtr_verbose("Child closed socket");
 	  $s->remove($sock);
 	  if (--$childs == 0){
-	    $suite_timeout_proc->kill();
 	    return $completed;
 	  }
 	  next;
@@ -529,15 +542,13 @@ sub run_test_server ($$$) {
 
 	    if ( !$opt_force ) {
 	      # Test has failed, force is off
-	      $suite_timeout_proc->kill();
 	      push(@$completed, $result);
 	      return $completed;
 	    }
 	    elsif ($opt_max_test_fail > 0 and
 		   $num_failed_test >= $opt_max_test_fail) {
-	      $suite_timeout_proc->kill();
 	      push(@$completed, $result);
-	      mtr_report_stats($completed, 1);
+	      mtr_report_stats("Too many failed", $completed, 1);
 	      mtr_report("Too many tests($num_failed_test) failed!",
 			 "Terminating...");
 	      return undef;
@@ -624,9 +635,9 @@ sub run_test_server ($$$) {
 	    next;
 	  }
 
-	  # Prefer same configuration
-	  if (defined $result and
-	      $result->{template_path} eq $t->{template_path})
+	  # Prefer same configuration, or just use next if --noreorder
+	  if (!$opt_reorder or (defined $result and
+	      $result->{template_path} eq $t->{template_path}))
 	  {
 	    #mtr_report("Test uses same config => good match");
 	    # Test uses same config => good match
@@ -667,9 +678,9 @@ sub run_test_server ($$$) {
     # ----------------------------------------------------
     # Check if test suite timer expired
     # ----------------------------------------------------
-    if ( ! $suite_timeout_proc->wait_one(0) )
+    if ( has_expired($suite_timeout) )
     {
-      mtr_report_stats($completed, 1);
+      mtr_report_stats("Timeout", $completed, 1);
       mtr_report("Test suite timeout! Terminating...");
       return undef;
     }
@@ -745,6 +756,12 @@ sub run_worker ($) {
     elsif ($line eq 'BYE'){
       mtr_report("Server said BYE");
       stop_all_servers($opt_shutdown_timeout);
+      if ($opt_valgrind_mysqld) {
+        valgrind_exit_reports();
+      }
+      if ( $opt_gprof ) {
+	gprof_collect (find_mysqld($basedir), keys %gprof_dirs);
+      }
       exit(0);
     }
     else {
@@ -787,11 +804,12 @@ sub set_vardir {
 sub command_line_setup {
   my $opt_comment;
   my $opt_usage;
+  my $opt_list_options;
 
   # Read the command line options
   # Note: Keep list, and the order, in sync with usage at end of this file
   Getopt::Long::Configure("pass_through");
-  GetOptions(
+  my %options=(
              # Control what engine/variation to run
              'embedded-server'          => \$opt_embedded_server,
              'ps-protocol'              => \$opt_ps_protocol,
@@ -828,6 +846,7 @@ sub command_line_setup {
 
              # Specify ports
 	     'build-thread|mtr-build-thread=i' => \$opt_build_thread,
+	     'port-base|mtr-port-base=i'       => \$opt_port_base,
 
              # Test case authoring
              'record'                   => \$opt_record,
@@ -858,6 +877,7 @@ sub command_line_setup {
 
              # Coverage, profiling etc
              'gcov'                     => \$opt_gcov,
+             'gprof'                    => \$opt_gprof,
              'valgrind|valgrind-all'    => \$opt_valgrind,
              'valgrind-mysqltest'       => \$opt_valgrind_mysqltest,
              'valgrind-mysqld'          => \$opt_valgrind_mysqld,
@@ -888,7 +908,7 @@ sub command_line_setup {
              'report-features'          => \$opt_report_features,
              'comment=s'                => \$opt_comment,
              'fast'                     => \$opt_fast,
-             'reorder!'                 => \&collect_option,
+             'reorder!'                 => \$opt_reorder,
              'enable-disabled'          => \&collect_option,
              'verbose+'                 => \$opt_verbose,
              'verbose-restart'          => \&report_option,
@@ -908,11 +928,16 @@ sub command_line_setup {
              'warnings!'                => \$opt_warnings,
 	     'timestamp'                => \&report_option,
 	     'timediff'                 => \&report_option,
+	     'max-connections=i'        => \$opt_max_connections,
 
              'help|h'                   => \$opt_usage,
-            ) or usage("Can't read options");
+	       'list-options'             => \$opt_list_options,
+	      );
+
+  GetOptions(%options) or usage("Can't read options");
 
   usage("") if $opt_usage;
+  list_options(\%options) if $opt_list_options;
 
   # --------------------------------------------------------------------------
   # Setup verbosity
@@ -928,6 +953,11 @@ sub command_line_setup {
 
   # Find the absolute path to the test directory
   $glob_mysql_test_dir= cwd();
+  if ($glob_mysql_test_dir =~ / /)
+  {
+    die("Working directory \"$glob_mysql_test_dir\" contains space\n".
+	"Bailing out, cannot function properly with space in path");
+  }
   if (IS_CYGWIN)
   {
     # Use mixed path format i.e c:/path/to/
@@ -1080,6 +1110,21 @@ sub command_line_setup {
     }
   }
 
+  if (IS_WINDOWS and defined $opt_mem) {
+    mtr_report("--mem not supported on Windows, ignored");
+    $opt_mem= undef;
+  }
+
+  if ($opt_port_base ne "auto")
+  {
+    if (my $rem= $opt_port_base % 10)
+    {
+      mtr_warning ("Port base $opt_port_base rounded down to multiple of 10");
+      $opt_port_base-= $rem;
+    }
+    $opt_build_thread= $opt_port_base / 10 - 1000;
+  }
+
   # --------------------------------------------------------------------------
   # Check if we should speed up tests by trying to run on tmpfs
   # --------------------------------------------------------------------------
@@ -1245,7 +1290,7 @@ sub command_line_setup {
   # --------------------------------------------------------------------------
   # Gcov flag
   # --------------------------------------------------------------------------
-  if ( $opt_gcov and ! $source_dist )
+  if ( ($opt_gcov or $opt_gprof) and ! $source_dist )
   {
     mtr_error("Coverage test needs the source - please use source dist");
   }
@@ -1344,8 +1389,7 @@ sub command_line_setup {
     push(@valgrind_args, @default_valgrind_args)
       unless @valgrind_args;
 
-    # Make valgrind run in quiet mode so it only print errors
-    push(@valgrind_args, "--quiet" );
+    # Don't add --quiet; you will loose the summary reports.
 
     mtr_report("Running valgrind with options \"",
 	       join(" ", @valgrind_args), "\"");
@@ -1450,6 +1494,12 @@ sub collect_mysqld_features {
   mtr_add_arg($args, "--verbose");
   mtr_add_arg($args, "--help");
 
+  # Need --user=root if running as *nix root user
+  if (!IS_WINDOWS and $> == 0)
+  {
+    mtr_add_arg($args, "--user=root");
+  }
+
   my $exe_mysqld= find_mysqld($basedir);
   my $cmd= join(" ", $exe_mysqld, @$args);
   my $list= `$cmd`;
@@ -1773,11 +1823,11 @@ sub environment_setup {
     {
       push(@ld_library_paths, "$basedir/libmysql/.libs/",
 	   "$basedir/libmysql_r/.libs/",
-	   "$basedir/zlib.libs/");
+	   "$basedir/zlib/.libs/");
     }
     else
     {
-      push(@ld_library_paths, "$basedir/lib");
+      push(@ld_library_paths, "$basedir/lib", "$basedir/lib/mysql");
     }
   }
 
@@ -2521,6 +2571,7 @@ sub create_config_file_for_extern {
 # binlog reads from [client] and [mysqlbinlog]
 [mysqlbinlog]
 character-sets-dir= $path_charsetsdir
+local-load= $opt_tmpdir
 
 # mysql_fix_privilege_tables.sh don't read from [client]
 [mysql_fix_privilege_tables]
@@ -2950,11 +3001,11 @@ sub check_testcase($$)
   # Return immediately if no check proceess was started
   return 0 unless ( keys %started );
 
-  my $timeout_proc= My::SafeProcess->timer(check_timeout());
+  my $timeout= start_timer(check_timeout());
 
   while (1){
     my $result;
-    my $proc= My::SafeProcess->wait_any();
+    my $proc= My::SafeProcess->wait_any_timeout($timeout);
     mtr_report("Got $proc");
 
     if ( delete $started{$proc->pid()} ) {
@@ -2978,9 +3029,6 @@ sub check_testcase($$)
 
 	if ( keys(%started) == 0){
 	  # All checks completed
-
-	  $timeout_proc->kill();
-
 	  return 0;
 	}
 	# Wait for next process to exit
@@ -3021,10 +3069,9 @@ test case was executed:\n";
 
       }
     }
-    elsif ( $proc eq $timeout_proc ) {
-      $tinfo->{comment}.= "Timeout $timeout_proc for ".
-	"'check-testcase' expired after ".check_timeout().
-	  " seconds";
+    elsif ( $proc->{timeout} ) {
+      $tinfo->{comment}.= "Timeout for 'check-testcase' expired after "
+	.check_timeout()." seconds";
       $result= 4;
     }
     else {
@@ -3039,8 +3086,6 @@ test case was executed:\n";
     # Kill any check processes still running
     map($_->kill(), values(%started));
 
-    $timeout_proc->kill();
-
     return $result;
   }
 
@@ -3112,11 +3157,11 @@ sub run_on_all($$)
   # Return immediately if no check proceess was started
   return 0 unless ( keys %started );
 
-  my $timeout_proc= My::SafeProcess->timer(check_timeout());
+  my $timeout= start_timer(check_timeout());
 
   while (1){
     my $result;
-    my $proc= My::SafeProcess->wait_any();
+    my $proc= My::SafeProcess->wait_any_timeout($timeout);
     mtr_report("Got $proc");
 
     if ( delete $started{$proc->pid()} ) {
@@ -3135,17 +3180,15 @@ sub run_on_all($$)
 
       if ( keys(%started) == 0){
 	# All completed
-	$timeout_proc->kill();
 	return 0;
       }
 
       # Wait for next process to exit
       next;
     }
-    elsif ( $proc eq $timeout_proc ) {
-      $tinfo->{comment}.= "Timeout $timeout_proc for '$run' ".
-	"expired after ". check_timeout().
-	  " seconds";
+    elsif ($proc->{timeout}) {
+      $tinfo->{comment}.= "Timeout for '$run' expired after "
+	.check_timeout()." seconds";
     }
     else {
       # Unknown process returned, most likley a crash, abort everything
@@ -3157,8 +3200,6 @@ sub run_on_all($$)
     # Kill any check processes still running
     map($_->kill(), values(%started));
 
-    $timeout_proc->kill();
-
     return 1;
   }
   mtr_error("INTERNAL_ERROR: run_on_all");
@@ -3265,9 +3306,11 @@ sub run_testcase ($) {
 
   mtr_verbose("Running test:", $tinfo->{name});
 
-  # Allow only alpanumerics pluss _ - + . in combination names
+  # Allow only alpanumerics pluss _ - + . in combination names,
+  # or anything beginning with -- (the latter comes from --combination)
   my $combination= $tinfo->{combination};
-  if ($combination && $combination !~ /^\w[-\w\.\+]+$/)
+  if ($combination && $combination !~ /^\w[-\w\.\+]+$/
+                   && $combination !~ /^--/)
   {
     mtr_error("Combination '$combination' contains illegal characters");
   }
@@ -3388,7 +3431,7 @@ sub run_testcase ($) {
     }
   }
 
-  my $test_timeout_proc= My::SafeProcess->timer(testcase_timeout());
+  my $test_timeout= start_timer(testcase_timeout());
 
   do_before_run_mysqltest($tinfo);
 
@@ -3396,9 +3439,6 @@ sub run_testcase ($) {
     # Failed to record state of server or server crashed
     report_failure_and_restart($tinfo);
 
-    # Stop the test case timer
-    $test_timeout_proc->kill();
-
     return 1;
   }
 
@@ -3416,20 +3456,20 @@ sub run_testcase ($) {
       if ($proc)
       {
 	mtr_verbose ("Found exited process $proc");
-	# If that was the timeout, cancel waiting
-	if ( $proc eq $test_timeout_proc )
-	{
-	  $keep_waiting_proc = 0;
-	}
       }
       else
       {
 	$proc = $keep_waiting_proc;
+	# Also check if timer has expired, if so cancel waiting
+	if ( has_expired($test_timeout) )
+	{
+	  $keep_waiting_proc = 0;
+	}
       }
     }
-    else
+    if (! $keep_waiting_proc)
     {
-      $proc= My::SafeProcess->wait_any();
+      $proc= My::SafeProcess->wait_any_timeout($test_timeout);
     }
 
     # Will be restored if we need to keep waiting
@@ -3446,9 +3486,6 @@ sub run_testcase ($) {
     # ----------------------------------------------------
     if ($proc eq $test)
     {
-      # Stop the test case timer
-      $test_timeout_proc->kill();
-
       my $res= $test->exit_status();
 
       if ($res == 0 and $opt_warnings and check_warnings($tinfo) )
@@ -3505,6 +3542,14 @@ sub run_testcase ($) {
 	  run_on_all($tinfo, "analyze-$analyze");
 	}
 
+	# Wait a bit and see if a server died, if so report that instead
+	mtr_milli_sleep(100);
+	my $srvproc= My::SafeProcess::check_any();
+	if ($srvproc && grep($srvproc eq $_, started(all_servers()))) {
+	  $proc= $srvproc;
+	  goto SRVDIED;
+	}
+
 	# Test case failure reported by mysqltest
 	report_failure_and_restart($tinfo);
       }
@@ -3512,7 +3557,7 @@ sub run_testcase ($) {
       {
 	# mysqltest failed, probably crashed
 	$tinfo->{comment}=
-	  "mysqltest failed with unexpected return code $res";
+	  "mysqltest failed with unexpected return code $res\n";
 	report_failure_and_restart($tinfo);
       }
 
@@ -3530,6 +3575,7 @@ sub run_testcase ($) {
     # ----------------------------------------------------
     # Check if it was an expected crash
     # ----------------------------------------------------
+    SRVDIED:
     my $check_crash = check_expected_crash_and_restart($proc);
     if ($check_crash)
     {
@@ -3542,7 +3588,7 @@ sub run_testcase ($) {
     # ----------------------------------------------------
     # Stop the test case timer
     # ----------------------------------------------------
-    $test_timeout_proc->kill();
+    $test_timeout= 0;
 
     # ----------------------------------------------------
     # Check if it was a server that died
@@ -3581,7 +3627,7 @@ sub run_testcase ($) {
     # ----------------------------------------------------
     # Check if testcase timer expired
     # ----------------------------------------------------
-    if ( $proc eq $test_timeout_proc )
+    if ( $proc->{timeout} )
     {
       my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
       $tinfo->{comment}=
@@ -3703,16 +3749,24 @@ sub extract_warning_lines ($$) {
     (
      qr/^Warning:|mysqld: Warning|\[Warning\]/,
      qr/^Error:|\[ERROR\]/,
-     qr/^==\d*==/, # valgrind errors
+     qr/^==\d+==\s+\S/, # valgrind errors
      qr/InnoDB: Warning|InnoDB: Error/,
      qr/^safe_mutex:|allocated at line/,
      qr/missing DBUG_RETURN/,
      qr/Attempting backtrace/,
      qr/Assertion .* failed/,
     );
+  my $skip_valgrind= 0;
 
   foreach my $line ( @lines )
   {
+    if ($opt_valgrind_mysqld) {
+      # Skip valgrind summary from tests where server has been restarted
+      # Should this contain memory leaks, the final report will find it
+      $skip_valgrind= 1 if $line =~ /^==\d+== ERROR SUMMARY:/;
+      $skip_valgrind= 0 unless $line =~ /^==\d+==/;
+      next if $skip_valgrind;
+    }
     foreach my $pat ( @patterns )
     {
       if ( $line =~ /$pat/ )
@@ -3752,7 +3806,6 @@ sub start_check_warnings ($$) {
 
   mtr_add_arg($args, "--skip-safemalloc");
   mtr_add_arg($args, "--test-file=%s", "include/check-warnings.test");
-  mtr_add_arg($args, "--verbose");
 
   if ( $opt_embedded_server )
   {
@@ -3815,11 +3868,11 @@ sub check_warnings ($) {
   # Return immediately if no check proceess was started
   return 0 unless ( keys %started );
 
-  my $timeout_proc= My::SafeProcess->timer(check_timeout());
+  my $timeout= start_timer(check_timeout());
 
   while (1){
     my $result= 0;
-    my $proc= My::SafeProcess->wait_any();
+    my $proc= My::SafeProcess->wait_any_timeout($timeout);
     mtr_report("Got $proc");
 
     if ( delete $started{$proc->pid()} ) {
@@ -3848,9 +3901,6 @@ sub check_warnings ($) {
 
 	if ( keys(%started) == 0){
 	  # All checks completed
-
-	  $timeout_proc->kill();
-
 	  return $result;
 	}
 	# Wait for next process to exit
@@ -3867,10 +3917,9 @@ sub check_warnings ($) {
 	$result= 2;
       }
     }
-    elsif ( $proc eq $timeout_proc ) {
-      $tinfo->{comment}.= "Timeout $timeout_proc for ".
-	"'check warnings' expired after ".check_timeout().
-	  " seconds";
+    elsif ( $proc->{timeout} ) {
+      $tinfo->{comment}.= "Timeout for 'check warnings' expired after "
+	.check_timeout()." seconds";
       $result= 4;
     }
     else {
@@ -3884,8 +3933,6 @@ sub check_warnings ($) {
     # Kill any check processes still running
     map($_->kill(), values(%started));
 
-    $timeout_proc->kill();
-
     return $result;
   }
 
@@ -3903,7 +3950,7 @@ sub check_expected_crash_and_restart {
 
   foreach my $mysqld ( mysqlds() )
   {
-    next unless ( $mysqld->{proc} eq $proc );
+    next unless ( $mysqld->{proc} and $mysqld->{proc} eq $proc );
 
     # Check if crash expected by looking at the .expect file
     # in var/tmp
@@ -4101,6 +4148,20 @@ sub report_failure_and_restart ($) {
 	# about what failed has been saved to file. Save the report
 	# in tinfo
 	$tinfo->{logfile}= mtr_fromfile($logfile);
+	# If no newlines in the test log:
+	# (it will contain the CURRENT_TEST written by mtr, so is not empty)
+	if ($tinfo->{logfile} !~ /\n/)
+	{
+	  # Show how far it got before suddenly failing
+	  $tinfo->{comment}.= "mysqltest failed but provided no output\n";
+	  my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
+	  if (-e $log_file_name) {
+	    $tinfo->{comment}.=
+	      "The result from queries just before the failure was:".
+	      "\n< snip >\n".
+	      mtr_lastlinesfromfile($log_file_name, 20)."\n";
+	  }
+	}
       }
       else
       {
@@ -4346,6 +4407,10 @@ sub mysqld_start ($$) {
     # see the exact location where valgrind complains
     $output= "$opt_vardir/log/".$mysqld->name().".trace";
   }
+  # Remember this log file for valgrind error report search
+  $mysqld_logs{$output}= 1 if $opt_valgrind;
+  # Remember data dir for gmon.out files if using gprof
+  $gprof_dirs{$mysqld->value('datadir')}= 1 if $opt_gprof;
 
   if ( defined $exe )
   {
@@ -4895,6 +4960,10 @@ sub start_mysqltest ($) {
     mtr_add_arg($args, "--ssl");
   }
 
+  if ( $opt_max_connections ) {
+    mtr_add_arg($args, "--max-connections=%d", $opt_max_connections);
+  }
+
   if ( $opt_embedded_server )
   {
 
@@ -4995,7 +5064,7 @@ sub gdb_arguments {
   my $type= shift;
 
   # Write $args to gdb init file
-  my $str= join(" ", @$$args);
+  my $str= join " ", map { s/"/\\"/g; "\"$_\""; } @$$args;
   my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
 
   # Remove the old gdbinit file
@@ -5059,7 +5128,7 @@ sub ddd_arguments {
   my $type= shift;
 
   # Write $args to ddd init file
-  my $str= join(" ", @$$args);
+  my $str= join " ", map { s/"/\\"/g; "\"$_\""; } @$$args;
   my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
 
   # Remove the old gdbinit file
@@ -5123,9 +5192,9 @@ sub debugger_arguments {
   {
     # vc[express] /debugexe exe arg1 .. argn
 
-    # Add /debugexe and name of the exe before args
-    unshift(@$$args, "/debugexe");
+    # Add name of the exe and /debugexe before args
     unshift(@$$args, "$$exe");
+    unshift(@$$args, "/debugexe");
 
     # Set exe to debuggername
     $$exe= $debugger;
@@ -5198,6 +5267,66 @@ sub valgrind_arguments {
   }
 }
 
+#
+# Search server logs for valgrind reports printed at mysqld termination
+#
+
+sub valgrind_exit_reports() {
+  foreach my $log_file (keys %mysqld_logs)
+  {
+    my @culprits= ();
+    my $valgrind_rep= "";
+    my $found_report= 0;
+    my $err_in_report= 0;
+
+    my $LOGF = IO::File->new($log_file)
+      or mtr_error("Could not open file '$log_file' for reading: $!");
+
+    while ( my $line = <$LOGF> )
+    {
+      if ($line =~ /^CURRENT_TEST: (.+)$/)
+      {
+        my $testname= $1;
+        # If we have a report, report it if needed and start new list of tests
+        if ($found_report)
+        {
+          if ($err_in_report)
+          {
+            mtr_print ("Valgrind report from $log_file after tests:\n",
+                        @culprits);
+            mtr_print_line();
+            print ("$valgrind_rep\n");
+            $err_in_report= 0;
+          }
+          # Make ready to collect new report
+          @culprits= ();
+          $found_report= 0;
+          $valgrind_rep= "";
+        }
+        push (@culprits, $testname);
+        next;
+      }
+      # This line marks the start of a valgrind report
+      $found_report= 1 if $line =~ /ERROR SUMMARY:/;
+
+      if ($found_report) {
+        $line=~ s/^==\d+== //;
+        $valgrind_rep .= $line;
+        $err_in_report= 1 if $line =~ /ERROR SUMMARY: [1-9]/;
+        $err_in_report= 1 if $line =~ /definitely lost: [1-9]/;
+        $err_in_report= 1 if $line =~ /possibly lost: [1-9]/;
+      }
+    }
+
+    $LOGF= undef;
+
+    if ($err_in_report) {
+      mtr_print ("Valgrind report from $log_file after tests:\n", @culprits);
+      mtr_print_line();
+      print ("$valgrind_rep\n");
+    }
+  }
+}
 
 #
 # Usage
@@ -5277,6 +5406,11 @@ Options to control what test suites or c
 
 Options that specify ports
 
+  mtr-port-base=#       Base for port numbers, ports from this number to
+  port-base=#           number+9 are reserved. Should be divisible by 10;
+                        if not it will be rounded down. May be set with
+                        environment variable MTR_PORT_BASE. If this value is
+                        set and is not "auto", it overrides build-thread.
   mtr-build-thread=#    Specify unique number to calculate port number(s) from.
   build-thread=#        Can be set in environment variable MTR_BUILD_THREAD.
                         Set  MTR_BUILD_THREAD="auto" to automatically aquire
@@ -5388,9 +5522,22 @@ Misc options
   timestamp             Print timestamp before each test report line
   timediff              With --timestamp, also print time passed since
                         *previous* test started
+  max-connections=N     Max number of open connection to server in mysqltest
 
 HERE
   exit(1);
 
 }
 
+sub list_options ($) {
+  my $hash= shift;
+
+  for (keys %$hash) {
+    s/([:=].*|[+!])$//;
+    s/\|/\n--/g;
+    print "--$_\n" unless /list-options/;
+  }
+
+  exit(1);
+}
+

=== modified file 'mysql-test/r/archive.result'
--- a/mysql-test/r/archive.result	2009-11-11 08:03:29 +0000
+++ b/mysql-test/r/archive.result	2010-02-12 12:33:03 +0000
@@ -12728,3 +12728,12 @@ Table	Op	Msg_type	Msg_text
 test.t1	repair	Error	Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
 test.t1	repair	error	Corrupt
 DROP TABLE t1;
+#
+# BUG#48757 - missing .ARZ file causes server crash
+#
+CREATE TABLE t1(a INT) ENGINE=ARCHIVE;
+FLUSH TABLE t1;
+SELECT * FROM t1;
+ERROR HY000: Can't find file: 't1' (errno: 2)
+DROP TABLE t1;
+ERROR 42S02: Unknown table 't1'

=== modified file 'mysql-test/r/backup.result'
--- a/mysql-test/r/backup.result	2009-02-16 11:38:15 +0000
+++ b/mysql-test/r/backup.result	2010-02-09 10:30:50 +0000
@@ -4,23 +4,23 @@ create table t4(n int);
 backup table t4 to '../../bogus';
 Table	Op	Msg_type	Msg_text
 test.t4	backup	error	Failed copying .frm file (errno: X)
-test.t4	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t4	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t4	backup	Error	Can't create/write to file 'MYSQLTEST_VARDIR/bogus/t4.frm' (Errcode: X)
 test.t4	backup	status	Operation failed
 backup table t4 to '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t4	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t4	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t4	backup	status	OK
 backup table t4 to '../../tmp';
 Table	Op	Msg_type	Msg_text
 test.t4	backup	error	Failed copying .frm file (errno: X)
-test.t4	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t4	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t4	backup	Error	Can't create/write to file 'MYSQLTEST_VARDIR/tmp/t4.frm' (Errcode: X)
 test.t4	backup	status	Operation failed
 drop table t4;
 restore table t4 from '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t4	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t4	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t4	restore	status	OK
 select count(*) from t4;
 count(*)
@@ -29,18 +29,18 @@ create table t1(n int);
 insert into t1 values (23),(45),(67);
 backup table t1 to '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t1	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	backup	status	OK
 drop table t1;
 restore table t1 from '../../bogus';
 Table	Op	Msg_type	Msg_text
 t1	restore	error	Failed copying .frm file
 Warnings:
-Warning	1287	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+Warning	1287	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 Error	29	File 'MYSQLTEST_VARDIR/bogus/t1.frm' not found (Errcode: X)
 restore table t1 from '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t1	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	restore	status	OK
 select n from t1;
 n
@@ -53,13 +53,13 @@ insert into t2 values (123),(145),(167);
 insert into t3 values (223),(245),(267);
 backup table t2,t3 to '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t2	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t2	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t2	backup	status	OK
 test.t3	backup	status	OK
 drop table t1,t2,t3;
 restore table t1,t2,t3 from '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t1	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	restore	status	OK
 test.t2	restore	status	OK
 test.t3	restore	status	OK
@@ -81,14 +81,14 @@ k
 drop table t1,t2,t3,t4;
 restore table t1 from '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t1	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	restore	status	OK
 rename table t1 to t5;
 lock tables t5 write;
 backup table t5 to '../../tmp';
 unlock tables;
 Table	Op	Msg_type	Msg_text
-test.t5	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t5	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t5	backup	status	OK
 drop table t5;
 DROP TABLE IF EXISTS `t+1`;
@@ -96,12 +96,12 @@ CREATE  TABLE `t+1` (c1 INT);
 INSERT  INTO  `t+1` VALUES (1), (2), (3);
 BACKUP  TABLE `t+1` TO '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t+1	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t+1	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t+1	backup	status	OK
 DROP    TABLE `t+1`;
 RESTORE TABLE `t+1` FROM '../../tmp';
 Table	Op	Msg_type	Msg_text
-test.t+1	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t+1	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t+1	restore	status	OK
 SELECT * FROM `t+1`;
 c1

=== modified file 'mysql-test/r/bigint.result'
--- a/mysql-test/r/bigint.result	2007-11-12 13:09:57 +0000
+++ b/mysql-test/r/bigint.result	2010-02-25 19:13:11 +0000
@@ -404,3 +404,37 @@ describe t1;
 Field	Type	Null	Key	Default	Extra
 bi	decimal(19,0)	NO		0	
 drop table t1;
+#
+# Bug #45360: wrong results
+#
+CREATE TABLE t1 (id INT AUTO_INCREMENT PRIMARY KEY,
+a BIGINT(20) UNSIGNED,
+b VARCHAR(20));
+INSERT INTO t1 (a) VALUES
+(0),
+(CAST(0x7FFFFFFFFFFFFFFF AS UNSIGNED)),
+(CAST(0x8000000000000000 AS UNSIGNED)),
+(CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
+UPDATE t1 SET b = a;
+# FFFFFFFFFFFFFFFF
+EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a = 18446744073709551615 AND TRIM(a) = b;
+SHOW WARNINGS;
+Level	Code	Message
+Note	1003	select 1 AS `1` from `test`.`t1` where ((`test`.`t1`.`a` = 18446744073709551615) and ('18446744073709551615' = `test`.`t1`.`b`))
+# 8000000000000000
+EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a = 9223372036854775808 AND TRIM(a) = b;
+SHOW WARNINGS;
+Level	Code	Message
+Note	1003	select 1 AS `1` from `test`.`t1` where ((`test`.`t1`.`a` = 9223372036854775808) and ('9223372036854775808' = `test`.`t1`.`b`))
+# 7FFFFFFFFFFFFFFF
+EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a = 9223372036854775807 AND TRIM(a) = b;
+SHOW WARNINGS;
+Level	Code	Message
+Note	1003	select 1 AS `1` from `test`.`t1` where ((`test`.`t1`.`a` = 9223372036854775807) and ('9223372036854775807' = `test`.`t1`.`b`))
+# 0
+EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a = 0 AND TRIM(a) = b;
+SHOW WARNINGS;
+Level	Code	Message
+Note	1003	select 1 AS `1` from `test`.`t1` where ((`test`.`t1`.`a` = 0) and ('0' = `test`.`t1`.`b`))
+DROP TABLE t1;
+# End of 5.1 tests

=== added file 'mysql-test/r/bug39022.result'
--- a/mysql-test/r/bug39022.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/bug39022.result	2010-02-18 08:48:15 +0000
@@ -0,0 +1,32 @@
+#
+# Bug #39022: Mysql randomly crashing in lock_sec_rec_cons_read_sees
+#
+CREATE TABLE t1(a TINYINT NOT NULL,b TINYINT,PRIMARY KEY(b)) ENGINE=innodb;
+CREATE TABLE t2(d TINYINT NOT NULL,UNIQUE KEY(d)) ENGINE=innodb;
+INSERT INTO t1 VALUES (13,0),(8,1),(9,2),(6,3),
+(11,5),(11,6),(7,7),(7,8),(4,9),(6,10),(3,11),(11,12),
+(12,13),(7,14);
+INSERT INTO t2 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
+(11),(12),(13),(14);
+# in thread1
+START TRANSACTION;
+# in thread2
+REPLACE INTO t2 VALUES (-17);
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d);
+d
+# in thread1
+REPLACE INTO t1(a,b) VALUES (67,20);
+# in thread2
+COMMIT;
+START TRANSACTION;
+REPLACE INTO t1(a,b) VALUES (65,-50);
+REPLACE INTO t2 VALUES (-91);
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d);
+# in thread1
+# should not crash
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d);
+ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
+# in thread2
+d
+# in thread1;
+DROP TABLE t1,t2;

=== modified file 'mysql-test/r/csv.result'
--- a/mysql-test/r/csv.result	2009-01-23 12:22:05 +0000
+++ b/mysql-test/r/csv.result	2010-02-17 12:13:42 +0000
@@ -5394,17 +5394,24 @@ select * from t1;
 ERROR HY000: File 'MYSQLD_DATADIR/test/t1.CSV' not found (Errcode: 2)
 unlock tables;
 drop table t1;
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
+CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
+INSERT INTO t1 VALUES();
+INSERT INTO t1 VALUES(default);
+INSERT INTO t1 VALUES(0);
 Warnings:
-Warning	1265	Data truncated for column 'a' at row 1
-select * from t1 limit 1;
-ERROR HY000: Table 't1' is marked as crashed and should be repaired
-repair table t1;
-Table	Op	Msg_type	Msg_text
-test.t1	repair	Warning	Data truncated for column 'a' at row 1
-test.t1	repair	status	OK
-select * from t1 limit 1;
-a
-drop table t1;
+Warning	1265	Data truncated for column 'e' at row 1
+INSERT INTO t1 VALUES(3);
+Warnings:
+Warning	1265	Data truncated for column 'e' at row 1
+INSERT INTO t1 VALUES(-1);
+Warnings:
+Warning	1265	Data truncated for column 'e' at row 1
+SELECT * FROM t1;
+e
+foo
+foo
+
+
+
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/default.result'
--- a/mysql-test/r/default.result	2008-09-03 08:06:03 +0000
+++ b/mysql-test/r/default.result	2010-02-17 12:13:42 +0000
@@ -180,7 +180,6 @@ insert into bug20691 values (2, 3, 5, '0
 insert into bug20691 values (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, 4);
 Warnings:
 Warning	1364	Field 'a' doesn't have a default value
-Warning	1364	Field 'b' doesn't have a default value
 Warning	1364	Field 'c' doesn't have a default value
 Warning	1364	Field 'd' doesn't have a default value
 Warning	1364	Field 'e' doesn't have a default value
@@ -193,7 +192,7 @@ a	b	c	d	e	f	g	h	i	x
 two	large	00:00:05	0007-01-01	11	13	17	0019-01-01 00:00:00	23	1
 	small	00:00:00	0000-00-00	0			0000-00-00 00:00:00	0	2
 two	large	00:00:05	0007-01-01	11	13	17	0019-01-01 00:00:00	23	3
-		00:00:00	0000-00-00	0			0000-00-00 00:00:00	0	4
+	small	00:00:00	0000-00-00	0			0000-00-00 00:00:00	0	4
 drop table bug20691;
 create table t1 (id int not null);
 insert into t1 values(default);

=== modified file 'mysql-test/r/delete.result'
--- a/mysql-test/r/delete.result	2010-01-29 09:36:28 +0000
+++ b/mysql-test/r/delete.result	2010-02-25 15:12:15 +0000
@@ -278,6 +278,18 @@ DELETE FROM t1 ORDER BY (f1(10)) LIMIT 1
 ERROR 42000: Incorrect number of arguments for FUNCTION test.f1; expected 0, got 1
 DROP TABLE t1;
 DROP FUNCTION f1;
+#
+# Bug #49552 : sql_buffer_result cause crash + not found records 
+#   in multitable delete/subquery
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+SET SESSION SQL_BUFFER_RESULT=1;
+DELETE t1 FROM (SELECT SUM(a) a FROM t1) x,t1;
+SET SESSION SQL_BUFFER_RESULT=DEFAULT;
+SELECT * FROM t1;
+a
+DROP TABLE t1;
 End of 5.0 tests
 #
 # Bug#46958: Assertion in Diagnostics_area::set_ok_status, trigger, 
@@ -337,16 +349,4 @@ END |
 DELETE IGNORE FROM t1;
 ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
 DROP TABLE t1;
-#
-# Bug #49552 : sql_buffer_result cause crash + not found records 
-#   in multitable delete/subquery
-#
-CREATE TABLE t1(a INT);
-INSERT INTO t1 VALUES (1),(2),(3);
-SET SESSION SQL_BUFFER_RESULT=1;
-DELETE t1 FROM (SELECT SUM(a) a FROM t1) x,t1;
-SET SESSION SQL_BUFFER_RESULT=DEFAULT;
-SELECT * FROM t1;
-a
-DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/fulltext.result'
--- a/mysql-test/r/fulltext.result	2010-02-02 16:37:56 +0000
+++ b/mysql-test/r/fulltext.result	2010-02-26 13:16:46 +0000
@@ -603,6 +603,26 @@ WHERE t3.a=t1.a AND MATCH(b2) AGAINST('s
 count(*)
 0
 DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (a VARCHAR(4), FULLTEXT(a));
+INSERT INTO t1 VALUES
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('awrd'),('cwrd'),
+('awrd');
+SELECT COUNT(*) FROM t1 WHERE MATCH(a) AGAINST("+awrd bwrd* +cwrd*" IN BOOLEAN MODE);
+COUNT(*)
+0
+DROP TABLE t1;
 #
 # Bug #49445: Assertion failed: 0, file .\item_row.cc, line 55 with 
 #   fulltext search and row op

=== modified file 'mysql-test/r/func_gconcat.result'
--- a/mysql-test/r/func_gconcat.result	2008-05-01 11:54:59 +0000
+++ b/mysql-test/r/func_gconcat.result	2010-02-19 19:06:47 +0000
@@ -978,4 +978,21 @@ GROUP BY t1.a
 1
 1
 DROP TABLE t1, t2;
+CREATE TABLE t1 (f1 INT);
+INSERT INTO t1 VALUES (),();
+EXPLAIN EXTENDED SELECT 1 FROM
+(SELECT DISTINCT GROUP_CONCAT(td.f1) FROM t1,t1 AS td GROUP BY td.f1) AS d,t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort; Distinct
+2	DERIVED	td	ALL	NULL	NULL	NULL	NULL	2	100.00	Distinct; Using join buffer
+Warnings:
+Note	1003	select 1 AS `1` from (select distinct group_concat(`test`.`td`.`f1` separator ',') AS `GROUP_CONCAT(td.f1)` from `test`.`t1` join `test`.`t1` `td` group by `test`.`td`.`f1`) `d` join `test`.`t1`
+SELECT 1 FROM
+(SELECT DISTINCT GROUP_CONCAT(td.f1) FROM t1,t1 AS td GROUP BY td.f1) AS d,t1;
+1
+1
+1
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2010-01-21 08:10:05 +0000
+++ b/mysql-test/r/func_time.result	2010-02-09 10:30:50 +0000
@@ -682,7 +682,7 @@ select timestampadd(SQL_TSI_FRAC_SECOND,
 timestampadd(SQL_TSI_FRAC_SECOND, 1, date)
 2003-01-02 00:00:00.000001
 Warnings:
-Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 5.6. Please use MICROSECOND instead
+Warning	1287	'FRAC_SECOND' is deprecated and will be removed in a future release. Please use MICROSECOND instead
 select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
 a
 3
@@ -717,7 +717,7 @@ select timestampdiff(SQL_TSI_FRAC_SECOND
 a
 7689538999999
 Warnings:
-Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 5.6. Please use MICROSECOND instead
+Warning	1287	'FRAC_SECOND' is deprecated and will be removed in a future release. Please use MICROSECOND instead
 select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1,
 timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2,
 timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
@@ -1088,7 +1088,7 @@ timestampdiff(SQL_TSI_FRAC_SECOND, '2001
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 Warnings:
-Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 5.6. Please use MICROSECOND instead
+Warning	1287	'FRAC_SECOND' is deprecated and will be removed in a future release. Please use MICROSECOND instead
 Note	1003	select timestampdiff(WEEK,'2001-02-01','2001-05-01') AS `a1`,timestampdiff(SECOND_FRAC,'2001-02-01 12:59:59.120000','2001-05-01 12:58:58.119999') AS `a2`
 select time_format('100:00:00', '%H %k %h %I %l');
 time_format('100:00:00', '%H %k %h %I %l')
@@ -1287,12 +1287,12 @@ SELECT TIMESTAMPADD(FRAC_SECOND, 1, '200
 TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18')
 2008-02-18 00:00:00.000001
 Warnings:
-Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 5.6. Please use MICROSECOND instead
+Warning	1287	'FRAC_SECOND' is deprecated and will be removed in a future release. Please use MICROSECOND instead
 SELECT TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18');
 TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18')
 86400000000
 Warnings:
-Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 5.6. Please use MICROSECOND instead
+Warning	1287	'FRAC_SECOND' is deprecated and will be removed in a future release. Please use MICROSECOND instead
 SELECT DATE_ADD('2008-02-18', INTERVAL 1 FRAC_SECOND);
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND)' at line 1
 SELECT DATE_SUB('2008-02-18', INTERVAL 1 FRAC_SECOND);

=== modified file 'mysql-test/r/group_by.result'
--- a/mysql-test/r/group_by.result	2009-02-26 17:17:06 +0000
+++ b/mysql-test/r/group_by.result	2010-02-06 19:54:30 +0000
@@ -1703,3 +1703,91 @@ COUNT(i)
 1
 DROP TABLE t1;
 SET @@sql_mode = @old_sql_mode;
+#
+# Bug #45640: optimizer bug produces wrong results
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (4, 40), (1, 10), (2, 20), (2, 20), (3, 30);
+# should return 4 ordered records:
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa;
+aa	COUNT(DISTINCT b)
+1	1
+2	1
+3	1
+4	1
+SELECT (SELECT (SELECT t1.a)) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa;
+aa	COUNT(DISTINCT b)
+1	1
+2	1
+3	1
+4	1
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa+0;
+aa	COUNT(DISTINCT b)
+1	1
+2	1
+3	1
+4	1
+# should return the same result in a reverse order:
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
+aa	COUNT(DISTINCT b)
+4	1
+3	1
+2	1
+1	1
+# execution plan should not use temporary table:
+EXPLAIN EXTENDED
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa+0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using filesort
+2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select `test`.`t1`.`a` AS `a`) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by ((select `test`.`t1`.`a` AS `a`) + 0)
+EXPLAIN EXTENDED
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using filesort
+2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select `test`.`t1`.`a` AS `a`) AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by -((select `test`.`t1`.`a` AS `a`))
+# should return only one record
+SELECT (SELECT tt.a FROM t1 tt LIMIT 1) aa, COUNT(DISTINCT b) FROM t1
+GROUP BY aa;
+aa	COUNT(DISTINCT b)
+4	4
+CREATE TABLE t2 SELECT DISTINCT a FROM t1;
+# originally reported queries (1st two columns of next two query
+# results should be same):
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(DISTINCT b)
+FROM t1 GROUP BY aa, b;
+aa	b	COUNT(DISTINCT b)
+1	10	1
+2	20	1
+3	30	1
+4	40	1
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(         b)
+FROM t1 GROUP BY aa, b;
+aa	b	COUNT(         b)
+1	10	1
+2	20	2
+3	30	1
+4	40	1
+# ORDER BY for sure:
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(DISTINCT b)
+FROM t1 GROUP BY aa, b ORDER BY -aa, -b;
+aa	b	COUNT(DISTINCT b)
+4	40	1
+3	30	1
+2	20	1
+1	10	1
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(         b)
+FROM t1 GROUP BY aa, b ORDER BY -aa, -b;
+aa	b	COUNT(         b)
+4	40	1
+3	30	1
+2	20	2
+1	10	1
+DROP TABLE t1, t2;
+#
+# End of 5.1 tests

=== modified file 'mysql-test/r/group_min_max.result'
--- a/mysql-test/r/group_min_max.result	2009-11-23 10:04:17 +0000
+++ b/mysql-test/r/group_min_max.result	2010-02-09 08:53:13 +0000
@@ -2524,4 +2524,17 @@ SELECT a, MAX(b) FROM t WHERE b GROUP BY
 a	MAX(b)
 2	1
 DROP TABLE t;
+CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL, KEY (b));
+INSERT INTO t1 VALUES(1,1),(2,1);
+ANALYZE TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+SELECT 1 AS c, b FROM t1 WHERE b IN (1,2) GROUP BY c, b;
+c	b
+1	1
+SELECT a FROM t1 WHERE b=1;
+a
+1
+2
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/having.result'
--- a/mysql-test/r/having.result	2009-01-16 15:38:38 +0000
+++ b/mysql-test/r/having.result	2010-02-26 11:39:25 +0000
@@ -430,4 +430,24 @@ SELECT b, COUNT(DISTINCT a) FROM t1 GROU
 b	COUNT(DISTINCT a)
 NULL	1
 DROP TABLE t1;
+#
+# Bug#50995 Having clause on subquery result produces incorrect results.
+#
+CREATE TABLE t1
+(
+id1 INT,
+id2 INT NOT NULL,
+INDEX id1(id2)
+);
+INSERT INTO t1 SET id1=1, id2=1;
+INSERT INTO t1 SET id1=2, id2=1;
+INSERT INTO t1 SET id1=3, id2=1;
+SELECT t1.id1,
+(SELECT 0 FROM DUAL
+WHERE t1.id1=t1.id1) AS amount FROM t1
+WHERE t1.id2 = 1
+HAVING amount > 0
+ORDER BY t1.id1;
+id1	amount
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/innodb-autoinc.result'
--- a/mysql-test/r/innodb-autoinc.result	2010-01-22 10:02:17 +0000
+++ b/mysql-test/r/innodb-autoinc.result	2010-02-26 09:02:57 +0000
@@ -1161,3 +1161,86 @@ t1	CREATE TABLE `t1` (
   PRIMARY KEY (`c1`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
 DROP TABLE t1;
+DROP TABLE IF EXISTS t1;
+Warnings:
+Note	1051	Unknown table 't1'
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (-685113344), (1), (NULL), (NULL);
+SELECT * FROM t1;
+c1
+-685113344
+1
+2
+3
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (-685113344), (2), (NULL), (NULL);
+SELECT * FROM t1;
+c1
+-685113344
+2
+3
+4
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (NULL), (2), (-685113344), (NULL);
+INSERT INTO  t1 VALUES (4), (5), (6), (NULL);
+SELECT * FROM t1;
+c1
+-685113344
+1
+2
+3
+4
+5
+6
+7
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (NULL), (2), (-685113344), (5);
+SELECT * FROM t1;
+c1
+-685113344
+1
+2
+5
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (1), (2), (-685113344), (NULL);
+SELECT * FROM t1;
+c1
+-685113344
+1
+2
+3
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
+DROP TABLE t1;

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2010-03-12 06:06:23 +0000
+++ b/mysql-test/r/innodb_mysql.result	2010-06-09 14:07:08 +0000
@@ -2274,4 +2274,26 @@ END|
 DROP PROCEDURE p1;
 DROP VIEW v1;
 DROP TABLE t1,t2;
+#
+# Bug #49324: more valgrind errors in test_if_skip_sort_order
+#
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
+#should not cause valgrind warnings
+SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
+1
+DROP TABLE t1;
+#
+# Bug#50843: Filesort used instead of clustered index led to
+#            performance degradation.
+#
+create table t1(f1 int not null primary key, f2 int) engine=innodb;
+create table t2(f1 int not null, key (f1)) engine=innodb;
+insert into t1 values (1,1),(2,2),(3,3);
+insert into t2 values (1),(2),(3);
+explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	3	
+1	SIMPLE	t2	ref	f1	f1	4	test.t1.f1	1	Using index
+drop table t1,t2;
+#
 End of 5.1 tests

=== modified file 'mysql-test/r/join.result'
--- a/mysql-test/r/join.result	2009-12-17 10:14:52 +0000
+++ b/mysql-test/r/join.result	2010-06-09 14:07:08 +0000
@@ -1128,3 +1128,31 @@ EXECUTE stmt;
 DEALLOCATE PREPARE stmt;
 DROP VIEW v1;
 DROP TABLE t1, t2;
+CREATE TABLE t1(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
+CREATE TABLE t2(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
+INSERT INTO t1 VALUES ('1',null),(null,null);
+INSERT INTO t2 VALUES ('1',null),(null,null);
+CREATE TABLE mm1(a CHAR(9),b INT,KEY(b),KEY(a))
+ENGINE=MERGE  UNION=(t1,t2);
+SELECT t1.a FROM mm1,t1;
+a
+NULL
+1
+NULL
+1
+NULL
+1
+NULL
+1
+DROP TABLE t1, t2, mm1;
+#
+# Bug #50335: Assertion `!(order->used & map)' in eq_ref_table
+# 
+CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b));
+INSERT INTO t1 VALUES (0,0), (1,1);
+SELECT * FROM t1 STRAIGHT_JOIN t1 t2 ON t1.a=t2.a AND t1.a=t2.b ORDER BY t2.a, t1.a;
+a	b	a	b
+0	0	0	0
+1	1	1	1
+DROP TABLE t1;
+End of 5.1 tests

=== modified file 'mysql-test/r/log_state.result'
--- a/mysql-test/r/log_state.result	2009-01-23 12:22:05 +0000
+++ b/mysql-test/r/log_state.result	2010-02-09 10:30:50 +0000
@@ -199,7 +199,7 @@ SELECT @@general_log, @@log;
 1	1
 SET GLOBAL log = 0;
 Warnings:
-Warning	1287	The syntax '@@log' is deprecated and will be removed in MySQL 7.0. Please use '@@general_log' instead
+Warning	1287	'@@log' is deprecated and will be removed in a future release. Please use '@@general_log' instead
 SHOW VARIABLES LIKE 'general_log';
 Variable_name	Value
 general_log	OFF
@@ -230,7 +230,7 @@ SELECT @@slow_query_log, @@log_slow_quer
 0	0
 SET GLOBAL log_slow_queries = 0;
 Warnings:
-Warning	1287	The syntax '@@log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '@@slow_query_log' instead
+Warning	1287	'@@log_slow_queries' is deprecated and will be removed in a future release. Please use '@@slow_query_log' instead
 SHOW VARIABLES LIKE 'slow_query_log';
 Variable_name	Value
 slow_query_log	OFF
@@ -283,16 +283,16 @@ SET GLOBAL slow_query_log_file = @old_sl
 deprecated:
 SET GLOBAL log = 0;
 Warnings:
-Warning	1287	The syntax '@@log' is deprecated and will be removed in MySQL 7.0. Please use '@@general_log' instead
+Warning	1287	'@@log' is deprecated and will be removed in a future release. Please use '@@general_log' instead
 SET GLOBAL log_slow_queries = 0;
 Warnings:
-Warning	1287	The syntax '@@log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '@@slow_query_log' instead
+Warning	1287	'@@log_slow_queries' is deprecated and will be removed in a future release. Please use '@@slow_query_log' instead
 SET GLOBAL log = DEFAULT;
 Warnings:
-Warning	1287	The syntax '@@log' is deprecated and will be removed in MySQL 7.0. Please use '@@general_log' instead
+Warning	1287	'@@log' is deprecated and will be removed in a future release. Please use '@@general_log' instead
 SET GLOBAL log_slow_queries = DEFAULT;
 Warnings:
-Warning	1287	The syntax '@@log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '@@slow_query_log' instead
+Warning	1287	'@@log_slow_queries' is deprecated and will be removed in a future release. Please use '@@slow_query_log' instead
 not deprecated:
 SELECT @@global.general_log_file INTO @my_glf;
 SELECT @@global.slow_query_log_file INTO @my_sqlf;

=== modified file 'mysql-test/r/multi_update.result'
--- a/mysql-test/r/multi_update.result	2009-03-05 10:23:46 +0000
+++ b/mysql-test/r/multi_update.result	2010-02-10 14:37:34 +0000
@@ -634,4 +634,15 @@ select count(*) from t3 /* must be 1 */;
 count(*)
 1
 drop table t1, t2, t3;
+#
+# Bug#49534: multitable IGNORE update with sql_safe_updates error
+# causes debug assertion
+#
+CREATE TABLE t1( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (1), (2), (3);
+SET SESSION sql_safe_updates = 1;
+# Must not cause failed assertion
+UPDATE IGNORE t1, t1 t1a SET t1.a = 1 WHERE t1a.a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+DROP TABLE t1;
 end of tests

=== modified file 'mysql-test/r/myisam.result'
--- a/mysql-test/r/myisam.result	2009-12-17 06:52:43 +0000
+++ b/mysql-test/r/myisam.result	2010-02-12 12:47:43 +0000
@@ -1868,6 +1868,19 @@ CHECKSUM TABLE t1 EXTENDED;
 Table	Checksum
 test.t1	467455460
 DROP TABLE t1;
+#
+# BUG#48438 - crash with error in unioned query against merge table and view...
+#
+SET GLOBAL table_open_cache=3;
+CREATE TABLE t1(a INT);
+SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4 FOR UPDATE;
+1
+SELECT TABLE_ROWS, DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
+TABLE_ROWS	DATA_LENGTH
+0	0
+DROP TABLE t1;
+SET GLOBAL table_open_cache=DEFAULT;
 End of 5.0 tests
 create table t1 (a int not null, key `a` (a) key_block_size=1024);
 show create table t1;
@@ -2313,4 +2326,17 @@ CHECK TABLE t1;
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 DROP TABLE t1;
+#
+# BUG#49628 - corrupt table after legal SQL, LONGTEXT column
+#
+CREATE TABLE t1(a INT, b LONGTEXT, UNIQUE(a));
+REPLACE INTO t1 VALUES
+(1, REPEAT('a', 129015)),(1, NULL),
+(2, NULL),(3, NULL),(4, NULL),(5, NULL),(6, NULL),(7, NULL),
+(1, REPEAT('b', 129016)),(1, NULL),
+(1, REPEAT('c', 129015)),(1, REPEAT('d', 129015));
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/mysqltest.result'
--- a/mysql-test/r/mysqltest.result	2009-10-08 09:30:03 +0000
+++ b/mysql-test/r/mysqltest.result	2010-02-09 17:13:57 +0000
@@ -147,9 +147,10 @@ hello
 hello
 ;;;;;;;;
 # MySQL: -- The
-mysqltest: At line 1: End of line junk detected: "6"
-mysqltest: At line 1: End of line junk detected: "6"
-mysqltest: At line 1: Missing delimiter
+mysqltest: At line 1: Extra argument '6' passed to 'sleep'
+mysqltest: At line 1: Extra argument '6' passed to 'sleep'
+mysqltest: At line 1: Extra argument 'A comment
+show status' passed to 'sleep'
 mysqltest: At line 1: End of line junk detected: "sleep 7
 # Another comment
 "
@@ -216,6 +217,12 @@ source database
 echo message echo message
 
 mysqltest: At line 1: Missing argument in exec
+1
+1
+2
+2
+X
+3
 MySQL
 "MySQL"
 MySQL: The
@@ -348,8 +355,10 @@ here is the sourced script
 here is the sourced script
 "hello"
 "hello"
-mysqltest: At line 1: Missing argument to sleep
-mysqltest: At line 1: Missing argument to real_sleep
+mysqltest: At line 2: Invalid argument to sleep "xyz"
+mysqltest: At line 2: Invalid argument to real_sleep "xyz"
+mysqltest: At line 1: Missing required argument 'sleep_delay' to command 'sleep'
+mysqltest: At line 1: Missing required argument 'sleep_delay' to command 'real_sleep'
 mysqltest: At line 1: Invalid argument to sleep "abc"
 mysqltest: At line 1: Invalid argument to real_sleep "abc"
 1
@@ -377,6 +386,10 @@ test
 test2
 test3
 test4
+outer
+true-inner
+true-inner again
+true-outer
 Counter is greater than 0, (counter=10)
 Counter is not 0, (counter=0)
 1
@@ -417,6 +430,9 @@ mysqltest: At line 1: Wrong number of ar
 mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a b'
 mysqltest: At line 1: Wrong column number to replace_column in 'replace_column a 1'
 mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1 b c '
+select "LONG_STRING" as x;
+x
+LONG_STRING
 mysqltest: At line 1: Invalid integer argument "10!"
 mysqltest: At line 1: Invalid integer argument "a"
 mysqltest: At line 1: Missing required argument 'connection name' to command 'connect'
@@ -523,7 +539,28 @@ a	D
 1	1
 1	4
 drop table t1;
+create table t1 ( f1 char(10));
+insert into t1 values ("Abcd");
+select * from t1;
+f1
+Abcd
+select * from t2;;
+ERROR 42S02: Table 'test.t2' doesn't exist
+select * from t1;
+f1
+Abcd
+select * from t1;;
+Result coming up
+f1
+Abcd
+select * from t1;;
+f1
+Abcd
+mysqltest: At line 2: Cannot run query on connection between send and reap
+select * from t1;;
+drop table t1;
 mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file'
+mysqltest: At line 1: Missing required argument 'directory' to command 'remove_files_wildcard'
 mysqltest: At line 1: Missing required argument 'filename' to command 'write_file'
 mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found
 Content for test_file1
@@ -553,6 +590,8 @@ hello
 mysqltest: At line 1: Max delimiter length(16) exceeded
 hello
 hello
+val is 5
+val is 5
 mysqltest: At line 1: test of die
 Some output
 create table t1( a int, b char(255), c timestamp);
@@ -680,6 +719,29 @@ INSERT INTO t1 SELECT f1 - 256 FROM t1;
 INSERT INTO t1 SELECT f1 - 512 FROM t1;
 SELECT * FROM t1;
 DROP TABLE t1;
+select "500g bl�rsyltet�s "will be lower cased";
+will be lower cased
+500g bl�rsyltet�ELECT "UPPER" AS "WILL NOT BE lower cased";
+WILL NOT BE lower cased
+UPPER
+UP
+SELECT 0 as "UP AGAIN";
+UP AGAIN
+0
+select "abcdef" as "uvwxyz";
+uvwxyz
+abcdef
+select "xyz" as name union select "abc" as name order by name desc;
+name
+abc
+xyz
+select 1 as "some new text";
+some new text
+1
+select 0 as "will not lower case ��;
+will not lower case ��+0
 CREATE TABLE t1(
 a int, b varchar(255), c datetime
 );
@@ -726,6 +788,8 @@ mysqltest: At line 1: change user failed
 file1.txt
 file1.txt
 file2.txt
+file11.txt
+dir-list.txt
 SELECT 'c:\\a.txt' AS col;
 col
 z

=== added file 'mysql-test/r/no_binlog.result'
--- a/mysql-test/r/no_binlog.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/no_binlog.result	2010-02-05 17:51:55 +0000
@@ -0,0 +1,2 @@
+SHOW BINARY LOGS;
+ERROR HY000: You are not using binary logging

=== added file 'mysql-test/r/partition_debug_sync.result'
--- a/mysql-test/r/partition_debug_sync.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_debug_sync.result	2010-02-01 15:07:00 +0000
@@ -0,0 +1,57 @@
+DROP TABLE IF EXISTS t1, t2;
+SET DEBUG_SYNC= 'RESET';
+#
+# Bug#42438: Crash ha_partition::change_table_ptr
+# Test when remove partitioning is done while drop table is waiting
+# for the table.
+# Con 1
+SET DEBUG_SYNC= 'RESET';
+CREATE TABLE t1
+(a INTEGER,
+b INTEGER NOT NULL,
+KEY (b))
+ENGINE = MYISAM
+/*!50100  PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (2),
+PARTITION p1 VALUES LESS THAN (20),
+PARTITION p2 VALUES LESS THAN (100),
+PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+SET DEBUG_SYNC= 'alter_table_before_create_table_no_lock SIGNAL removing_partitioning WAIT_FOR waiting_for_alter';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL partitioning_removed';
+ALTER TABLE t1 REMOVE PARTITIONING;
+# Con default
+SET DEBUG_SYNC= 'now WAIT_FOR removing_partitioning';
+SET DEBUG_SYNC= 'waiting_for_table SIGNAL waiting_for_alter';
+SET DEBUG_SYNC= 'rm_table_part2_before_delete_table WAIT_FOR partitioning_removed';
+DROP TABLE IF EXISTS t1;
+# Con 1
+SET DEBUG_SYNC= 'RESET';
+SET DEBUG_SYNC= 'RESET';
+#
+# Bug#42438: Crash ha_partition::change_table_ptr
+# Test when remove partitioning is failing due to drop table is already
+# in progress.
+CREATE TABLE t2
+(a INTEGER,
+b INTEGER NOT NULL,
+KEY (b))
+ENGINE = MYISAM
+/*!50100  PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (2),
+PARTITION p1 VALUES LESS THAN (20),
+PARTITION p2 VALUES LESS THAN (100),
+PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+SET DEBUG_SYNC= 'before_lock_tables_takes_lock SIGNAL removing_partitions WAIT_FOR waiting_for_alter';
+SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done';
+ALTER TABLE t2 REMOVE PARTITIONING;
+# Con default
+SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions';
+SET DEBUG_SYNC= 'waiting_for_table SIGNAL waiting_for_alter';
+SET DEBUG_SYNC= 'rm_table_part2_before_binlog SIGNAL delete_done';
+DROP TABLE IF EXISTS t2;
+# Con 1
+ERROR 42S02: Table 'test.t2' doesn't exist
+SET DEBUG_SYNC= 'RESET';
+# Con default
+SET DEBUG_SYNC= 'RESET';
+End of 5.1 tests

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2010-01-13 10:28:42 +0000
+++ b/mysql-test/r/show_check.result	2010-02-09 10:30:50 +0000
@@ -1295,7 +1295,7 @@ drop database mysqltest;
 show full plugin;
 show warnings;
 Level	Code	Message
-Warning	1287	The syntax 'SHOW PLUGIN' is deprecated and will be removed in MySQL 6.0. Please use 'SHOW PLUGINS' instead
+Warning	1287	'SHOW PLUGIN' is deprecated and will be removed in a future release. Please use 'SHOW PLUGINS' instead
 show plugin;
 show plugins;
 create database `mysqlttest\1`;

=== modified file 'mysql-test/r/sp-bugs.result'
--- a/mysql-test/r/sp-bugs.result	2009-10-26 09:55:57 +0000
+++ b/mysql-test/r/sp-bugs.result	2010-02-13 10:35:14 +0000
@@ -44,4 +44,33 @@ SELECT f2 ();
 f2 ()
 NULL
 DROP SCHEMA testdb;
+USE test;
+#
+# Bug#50423: Crash on second call of a procedure dropping a trigger
+#
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+CALL p1 ();
+CALL p1 ();
+ERROR HY000: Trigger does not exist
+DROP TABLE t1;
+DROP PROCEDURE p1;
+#
+# Bug#50423: Crash on second call of a procedure dropping a trigger
+#
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+CALL p1 ();
+CALL p1 ();
+ERROR HY000: Trigger does not exist
+DROP TABLE t1;
+DROP PROCEDURE p1;
 End of 5.1 tests

=== modified file 'mysql-test/r/sp-error.result'
--- a/mysql-test/r/sp-error.result	2009-12-08 09:26:11 +0000
+++ b/mysql-test/r/sp-error.result	2010-02-09 10:30:50 +0000
@@ -1643,7 +1643,7 @@ create table t1 (a int) type=MyISAM;
 drop table t1;
 end|
 Warnings:
-Warning	1287	The syntax 'TYPE=storage_engine' is deprecated and will be removed in MySQL 6.0. Please use 'ENGINE=storage_engine' instead
+Warning	1287	'TYPE=storage_engine' is deprecated and will be removed in a future release. Please use 'ENGINE=storage_engine' instead
 call p1();
 call p1();
 drop procedure p1;

=== modified file 'mysql-test/r/sp.result'
--- a/mysql-test/r/sp.result	2010-03-12 06:06:23 +0000
+++ b/mysql-test/r/sp.result	2010-06-09 14:07:08 +0000
@@ -4304,10 +4304,10 @@ call bug13012()|
 Table	Op	Msg_type	Msg_text
 test.t1	repair	status	OK
 Table	Op	Msg_type	Msg_text
-test.t1	backup	Warning	The syntax 'BACKUP TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	backup	Warning	'BACKUP TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	backup	status	OK
 Table	Op	Msg_type	Msg_text
-test.t1	restore	Warning	The syntax 'RESTORE TABLE' is deprecated and will be removed in MySQL 6.0. Please use MySQL Administrator (mysqldump, mysql) instead
+test.t1	restore	Warning	'RESTORE TABLE' is deprecated and will be removed in a future release. Please use MySQL Administrator (mysqldump, mysql) instead
 test.t1	restore	status	OK
 drop procedure bug13012|
 create view v1 as select * from t1|

=== modified file 'mysql-test/r/sp_notembedded.result'
--- a/mysql-test/r/sp_notembedded.result	2009-10-13 18:21:42 +0000
+++ b/mysql-test/r/sp_notembedded.result	2010-02-05 09:39:46 +0000
@@ -268,6 +268,17 @@ SELECT RELEASE_LOCK('Bug44521');
 RELEASE_LOCK('Bug44521')
 1
 DROP PROCEDURE p;
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES (1);
+CREATE FUNCTION f1 (inp TEXT) RETURNS INT NO SQL RETURN sleep(60);
+CREATE VIEW v1 AS SELECT f1('a') FROM t1;
+SELECT * FROM v1;;
+SELECT * FROM v1;
+ERROR 70100: Query execution was interrupted
+ERROR 70100: Query execution was interrupted
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION f1;
 # ------------------------------------------------------------------
 # -- End of 5.1 tests
 # ------------------------------------------------------------------

=== modified file 'mysql-test/r/sp_trans.result'
--- a/mysql-test/r/sp_trans.result	2009-02-16 11:38:15 +0000
+++ b/mysql-test/r/sp_trans.result	2010-02-09 10:30:50 +0000
@@ -535,7 +535,7 @@ use db_bug7787|
 CREATE PROCEDURE p1()
 SHOW INNODB STATUS; |
 Warnings:
-Warning	1287	The syntax 'SHOW INNODB STATUS' is deprecated and will be removed in MySQL 6.0. Please use 'SHOW ENGINE INNODB STATUS' instead
+Warning	1287	'SHOW INNODB STATUS' is deprecated and will be removed in a future release. Please use 'SHOW ENGINE INNODB STATUS' instead
 GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost|
 DROP DATABASE db_bug7787|
 drop user user_bug7787@localhost|

=== modified file 'mysql-test/r/subselect.result'
--- a/mysql-test/r/subselect.result	2009-12-23 15:11:22 +0000
+++ b/mysql-test/r/subselect.result	2010-02-26 13:16:46 +0000
@@ -4615,4 +4615,16 @@ FROM t1,t1 a
 );
 1
 DROP TABLE t1;
+#
+# Bug #45989 take 2 : memory leak after explain encounters an 
+# error in the query
+#
+CREATE TABLE t1(a LONGTEXT);
+INSERT INTO t1 VALUES (repeat('a',@@global.max_allowed_packet));
+INSERT INTO t1 VALUES (repeat('b',@@global.max_allowed_packet));
+EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
+(SELECT DISTINCTROW a AS away FROM t1 GROUP BY a WITH ROLLUP) AS d1  
+WHERE t1.a = d1.a;
+ERROR 42S22: Unknown column 'd1.a' in 'where clause'
+DROP TABLE t1;
 End of 5.1 tests.

=== modified file 'mysql-test/r/type_bit.result'
--- a/mysql-test/r/type_bit.result	2009-10-08 15:36:36 +0000
+++ b/mysql-test/r/type_bit.result	2010-02-16 09:13:49 +0000
@@ -785,4 +785,19 @@ t1	CREATE TABLE `t1` (
   KEY `a` (`a`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
+#
+# Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
+#
+CREATE TABLE t1(a INT, b BIT(7) NOT NULL);
+INSERT INTO t1 VALUES (NULL, 0),(NULL, 0);
+SELECT SUM(a) FROM t1 GROUP BY b, a;
+SUM(a)
+NULL
+DROP TABLE t1;
+CREATE TABLE t1(a INT, b BIT(7) NOT NULL, c BIT(8) NOT NULL);
+INSERT INTO t1 VALUES (NULL, 0, 0),(NULL, 0, 0);
+SELECT SUM(a) FROM t1 GROUP BY c, b, a;
+SUM(a)
+NULL
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/type_blob.result'
--- a/mysql-test/r/type_blob.result	2009-02-16 11:38:15 +0000
+++ b/mysql-test/r/type_blob.result	2010-02-09 10:30:50 +0000
@@ -891,11 +891,11 @@ CREATE TABLE b15776 (a year(-2));
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2))' at line 1
 CREATE TABLE b15776 (a timestamp(4294967294));
 Warnings:
-Warning	1287	The syntax 'TIMESTAMP(4294967294)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(4294967294)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
 DROP TABLE b15776;
 CREATE TABLE b15776 (a timestamp(4294967295));
 Warnings:
-Warning	1287	The syntax 'TIMESTAMP(4294967295)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(4294967295)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
 DROP TABLE b15776;
 CREATE TABLE b15776 (a timestamp(4294967296));
 ERROR 42000: Display width out of range for column 'a' (max = 4294967295)

=== modified file 'mysql-test/r/type_timestamp.result'
--- a/mysql-test/r/type_timestamp.result	2009-02-16 11:38:15 +0000
+++ b/mysql-test/r/type_timestamp.result	2010-02-09 10:30:50 +0000
@@ -101,13 +101,13 @@ create table t1 (t2 timestamp(2), t4 tim
 t8 timestamp(8), t10 timestamp(10), t12 timestamp(12),
 t14 timestamp(14));
 Warnings:
-Warning	1287	The syntax 'TIMESTAMP(2)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(4)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(6)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(8)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(10)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(12)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
-Warning	1287	The syntax 'TIMESTAMP(14)' is deprecated and will be removed in MySQL 6.0. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(2)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(4)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(6)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(8)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(10)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(12)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
+Warning	1287	'TIMESTAMP(14)' is deprecated and will be removed in a future release. Please use 'TIMESTAMP' instead
 insert t1 values (0,0,0,0,0,0,0),
 ("1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",
 "1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",

=== renamed file 'mysql-test/r/variables+c.result' => 'mysql-test/r/variables_community.result'
=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2009-08-31 14:09:09 +0000
+++ b/mysql-test/r/view.result	2010-02-12 09:44:20 +0000
@@ -3844,6 +3844,36 @@ CREATE VIEW v1 AS SELECT a FROM t1;
 ALTER TABLE v1;
 DROP VIEW v1;
 DROP TABLE t1;
+#
+# Bug#48449: hang on show create view after upgrading when
+#            view contains function of view
+#
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2;
+DROP FUNCTION IF EXISTS f1;
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+SELECT a FROM v2 INTO @a;
+RETURN @a;
+END//
+# Trigger pre-locking when opening v2.
+CREATE VIEW v1 AS SELECT f1() FROM t1;
+SHOW CREATE VIEW v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f1`() AS `f1()` from `t1`	latin1	latin1_swedish_ci
+Warnings:
+Note	1599	View `test`.`v2` has no creation context
+DROP VIEW v1,v2;
+DROP TABLE t1,t2;
+DROP FUNCTION f1;
+CREATE TABLE t1(f1 INT);
+INSERT INTO t1 VALUES ();
+CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE
+ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE  f1 >= ANY ( SELECT '1' )));
+DROP VIEW v1;
+DROP TABLE t1;
 # -----------------------------------------------------------------
 # -- End of 5.1 tests.
 # -----------------------------------------------------------------

=== modified file 'mysql-test/r/view_grant.result'
--- a/mysql-test/r/view_grant.result	2009-10-16 11:12:21 +0000
+++ b/mysql-test/r/view_grant.result	2010-02-12 02:54:14 +0000
@@ -1237,3 +1237,14 @@ SELECT a FROM v2;
 a
 DROP USER mysqluser1;
 DROP DATABASE mysqltest1;
+USE test;
+#
+# Bug#47734: Assertion failed: ! is_set() when locking a view with non-existing definer
+#
+DROP VIEW IF EXISTS v1;
+CREATE DEFINER=`unknown`@`unknown` SQL SECURITY DEFINER VIEW v1 AS SELECT 1;
+Warnings:
+Note	1449	The user specified as a definer ('unknown'@'unknown') does not exist
+LOCK TABLES v1 READ;
+ERROR HY000: The user specified as a definer ('unknown'@'unknown') does not exist
+DROP VIEW v1;

=== modified file 'mysql-test/r/warnings.result'
--- a/mysql-test/r/warnings.result	2009-09-10 08:49:49 +0000
+++ b/mysql-test/r/warnings.result	2010-02-09 10:30:50 +0000
@@ -168,7 +168,7 @@ max_error_count	10
 drop table t1;
 set table_type=MYISAM;
 Warnings:
-Warning	1287	The syntax '@@table_type' is deprecated and will be removed in MySQL 6.0. Please use '@@storage_engine' instead
+Warning	1287	'@@table_type' is deprecated and will be removed in a future release. Please use '@@storage_engine' instead
 create table t1 (a int);
 insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
 update t1 set a='abc';

=== added file 'mysql-test/std_data/bug48449.frm'
--- a/mysql-test/std_data/bug48449.frm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/bug48449.frm	2010-02-10 18:11:08 +0000
@@ -0,0 +1,12 @@
+TYPE=VIEW
+query=select `test`.`t2`.`a` AS `a` from `test`.`t2`
+md5=5e6eaf216e7b016fcedfd4e1113517af
+updatable=1
+algorithm=0
+definer_user=root
+definer_host=localhost
+suid=2
+with_check_option=0
+timestamp=2010-01-01 15:00:00
+create-version=1
+source=select * from t2

=== added file 'mysql-test/suite/rpl/r/rpl_slow_query_log.result'
--- a/mysql-test/suite/rpl/r/rpl_slow_query_log.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_slow_query_log.result	2010-02-05 17:48:01 +0000
@@ -0,0 +1,91 @@
+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;
+CALL mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
+include/stop_slave.inc
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+include/start_slave.inc
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 values(1, 1);
+INSERT INTO t1 values(1, sleep(3));
+TRUNCATE mysql.slow_log;
+SELECT 1, sleep(3);
+1	sleep(3)
+1	0
+SELECT 1;
+1
+1
+TRUNCATE mysql.slow_log;
+SET TIMESTAMP= 1;
+SELECT 2, sleep(3);
+2	sleep(3)
+2	0
+SELECT 2;
+2
+2
+TRUNCATE mysql.slow_log;
+SET @old_slow_query_log= @@slow_query_log;
+SET GLOBAL slow_query_log= 'OFF';
+SELECT 3, sleep(3);
+3	sleep(3)
+3	0
+SELECT 3;
+3
+3
+TRUNCATE mysql.slow_log;
+SET GLOBAL slow_query_log= @old_slow_query_log;
+DROP TABLE t1;
+include/stop_slave.inc
+SET GLOBAL long_query_time= @old_long_query_time;
+SET GLOBAL log_output= @old_log_output;
+include/start_slave.inc
+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;
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET GLOBAL long_query_time= 2;
+SET @old_long_query_time= @@long_query_time;
+SET SESSION long_query_time= 2;
+TRUNCATE mysql.slow_log;
+include/stop_slave.inc
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+include/start_slave.inc
+CREATE TABLE t1 (a int, b int);
+********************************************************************
+**** INSERT one row that exceeds long_query_time
+**** Outcome: query ends up in both master and slave slow log
+********************************************************************
+INSERT INTO t1 values(1, sleep(3));
+### Assertion is good. Both Master and Slave exhibit the 
+### same number of queries in slow log: 1
+TRUNCATE mysql.slow_log;
+TRUNCATE mysql.slow_log;
+********************************************************************
+**** Now do inserts again, but first add an index to the table.
+**** Outcome: Note that the slave contains the same one entry (as 
+****          the master does)  whereas before the patch it did not.
+********************************************************************
+ALTER TABLE t1 ADD INDEX id1(a);
+INSERT INTO t1 values(1, sleep(3));
+### Assertion is good. Both Master and Slave exhibit the 
+### same number of queries in slow log: 1
+SET @@global.log_output= @old_log_output;
+SET @@global.long_query_time= @old_long_query_time;
+DROP TABLE t1;
+SET @@global.log_output= @old_log_output;
+SET @@global.long_query_time= @old_long_query_time;

=== modified file 'mysql-test/suite/rpl/r/rpl_sp.result'
--- a/mysql-test/suite/rpl/r/rpl_sp.result	2010-02-02 13:38:44 +0000
+++ b/mysql-test/suite/rpl/r/rpl_sp.result	2010-02-09 10:30:50 +0000
@@ -195,7 +195,7 @@ set @old_log_bin_trust_routine_creators=
 set @old_log_bin_trust_function_creators= @@global.log_bin_trust_function_creators;
 set global log_bin_trust_routine_creators=1;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 5.6. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 set global log_bin_trust_function_creators=0;
 set global log_bin_trust_function_creators=1;
 set @old_log_bin_trust_routine_creators= @@global.log_bin_trust_routine_creators;
@@ -559,11 +559,11 @@ end
 master-bin.000001	#	Query	1	#	use `mysqltest`; SELECT `mysqltest2`.`f1`()
 set @@global.log_bin_trust_routine_creators= @old_log_bin_trust_routine_creators;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 5.6. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 set @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
 set @@global.log_bin_trust_routine_creators= @old_log_bin_trust_routine_creators;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 5.6. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 set @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
 drop database mysqltest;
 drop database mysqltest2;

=== modified file 'mysql-test/suite/rpl/t/rpl_loaddata_symlink.test'
--- a/mysql-test/suite/rpl/t/rpl_loaddata_symlink.test	2009-11-28 04:43:16 +0000
+++ b/mysql-test/suite/rpl/t/rpl_loaddata_symlink.test	2010-02-05 06:49:01 +0000
@@ -4,6 +4,7 @@
 # if the path of the load data file is a symbolic link.
 #
 --source include/master-slave.inc
+--source include/not_windows.inc
 --source include/have_binlog_format_statement.inc
 
 create table t1(a int not null auto_increment, b int, primary key(a) );

=== added file 'mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt'
--- a/mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt	2010-02-05 17:01:09 +0000
@@ -0,0 +1 @@
+--force-restart --log-slow-slave-statements --log-slow-queries

=== added file 'mysql-test/suite/rpl/t/rpl_slow_query_log.test'
--- a/mysql-test/suite/rpl/t/rpl_slow_query_log.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slow_query_log.test	2010-02-05 17:48:01 +0000
@@ -0,0 +1,308 @@
+#
+# BUG#23300: Slow query log on slave does not log slow replicated statements
+#
+# Description:
+#   The slave should log slow queries replicated from master when
+#   --log-slow-slave-statements is used.
+#
+#   Test is implemented as follows:
+#      i) stop slave
+#     ii) On slave, set long_query_time to a small value.
+#     ii) start slave so that long_query_time variable is picked by sql thread
+#    iii) On master, do one short time query and one long time query, on slave
+#         and check that slow query is logged to slow query log but fast query 
+#         is not.
+#     iv) On slave, check that slow queries go into the slow log and fast dont,
+#         when issued through a regular client connection
+#      v) On slave, check that slow queries go into the slow log and fast dont
+#         when we use SET TIMESTAMP= 1 on a regular client connection.
+#     vi) check that when setting slow_query_log= OFF in a connection 'extra2'
+#         prevents logging slow queries in a connection 'extra'
+#
+# OBS: 
+#   This test only runs for statement binlogging format because on row format
+#   slow queries do not get slow query logged. 
+#   Note that due to the sleep() command the insert is written to the binary
+#   log in row format.
+
+source include/master-slave.inc;
+source include/have_binlog_format_statement.inc;
+
+CALL mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
+
+
+# Prepare slave for different long_query_time we need to stop the slave 
+# and restart it as long_query_time variable is dynamic and, after 
+# setting it, it only takes effect on new connections. 
+#
+# Reference: 
+#   http://dev.mysql.com/doc/refman/6.0/en/set-option.html
+connection slave;
+
+source include/stop_slave.inc;
+
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+
+source include/start_slave.inc;
+
+connection master;
+CREATE TABLE t1 (a int, b int); 
+
+# test:
+#   check that slave logs the slow query to the slow log, but not the fast one.
+
+let $slow_query= INSERT INTO t1 values(1, sleep(3));
+let $fast_query= INSERT INTO t1 values(1, 1);
+
+eval $fast_query;
+--disable_warnings
+eval $slow_query;
+--enable_warnings
+sync_slave_with_master;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# regular checks for slow query log (using a new connection - 'extra' - to slave)
+
+# test: 
+#   when using direct connections to the slave, check that slow query is logged 
+#   but not the fast one.
+
+connect(extra,127.0.0.1,root,,test,$SLAVE_MYPORT);
+connection extra;
+
+let $fast_query= SELECT 1;
+let $slow_query= SELECT 1, sleep(3);
+
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# test:
+#   when using direct connections to the slave, check that when setting timestamp to 1 the 
+#   slow query is logged but the fast one is not.
+
+let $fast_query= SELECT 2;
+let $slow_query= SELECT 2, sleep(3);
+
+SET TIMESTAMP= 1;
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# test: 
+#   check that when setting the slow_query_log= OFF on connection 'extra2'
+#   prevents connection 'extra' from logging to slow query log.
+
+let $fast_query= SELECT 3;
+let $slow_query= SELECT 3, sleep(3);
+
+connect(extra2,127.0.0.1,root,,test,$SLAVE_MYPORT);
+connection extra2;
+
+SET @old_slow_query_log= @@slow_query_log;
+SET GLOBAL slow_query_log= 'OFF';
+
+connection extra;
+
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
+}
+
+if ($found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# clean up: drop tables, reset the variables back to the previous value,
+#           disconnect extra connections
+connection extra2;
+SET GLOBAL slow_query_log= @old_slow_query_log;
+
+connection master;
+DROP TABLE t1;
+sync_slave_with_master;
+
+source include/stop_slave.inc;
+
+SET GLOBAL long_query_time= @old_long_query_time;
+SET GLOBAL log_output= @old_log_output;
+
+source include/start_slave.inc;
+
+disconnect extra;
+disconnect extra2;
+
+#
+# BUG#50620: Adding an index to a table prevents slave from logging into slow log
+#
+
+-- source include/master-slave-reset.inc
+
+-- connection master
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET GLOBAL long_query_time= 2;
+SET @old_long_query_time= @@long_query_time;
+SET SESSION long_query_time= 2;
+TRUNCATE mysql.slow_log;
+-- connection slave
+
+-- source include/stop_slave.inc
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+-- source include/start_slave.inc
+
+let $slow_query= INSERT INTO t1 values(1, sleep(3));
+
+-- connection master
+CREATE TABLE t1 (a int, b int); 
+
+-- echo ********************************************************************
+-- echo **** INSERT one row that exceeds long_query_time
+-- echo **** Outcome: query ends up in both master and slave slow log
+-- echo ********************************************************************
+
+-- disable_warnings
+-- eval $slow_query
+-- enable_warnings
+
+let $master_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+-- sync_slave_with_master
+let $slave_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if (`SELECT $master_slow_query != $slave_slow_query`)
+{
+  -- connection master
+  -- echo ***********************************************
+  -- echo ** DUMPING MASTER SLOW LOG CONTENTS 
+  -- echo ***********************************************
+  SELECT * FROM mysql.slow_log;
+
+  -- connection slave
+  -- echo ***********************************************
+  -- echo ** DUMPING SLAVE SLOW LOG CONTENTS 
+  -- echo ***********************************************
+  SELECT * FROM mysql.slow_log;
+
+  -- die "Assertion failed! Master and slave slow log contents differ. Bailing out!"
+}
+
+if (`SELECT $master_slow_query = $slave_slow_query`)
+{
+  -- echo ### Assertion is good. Both Master and Slave exhibit the 
+  -- echo ### same number of queries in slow log: $master_slow_query
+}
+
+TRUNCATE mysql.slow_log;
+-- connection master
+TRUNCATE mysql.slow_log;
+
+-- echo ********************************************************************
+-- echo **** Now do inserts again, but first add an index to the table.
+-- echo **** Outcome: Note that the slave contains the same one entry (as 
+-- echo ****          the master does)  whereas before the patch it did not.
+-- echo ********************************************************************
+
+ALTER TABLE t1 ADD INDEX id1(a);
+
+-- disable_warnings
+-- eval $slow_query
+-- enable_warnings
+
+let $master_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+-- sync_slave_with_master
+let $slave_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if (`SELECT $master_slow_query != $slave_slow_query`)
+{
+  -- connection master
+  -- echo ***********************************************
+  -- echo ** DUMPING MASTER SLOW LOG CONTENTS 
+  -- echo ***********************************************
+  SELECT * FROM mysql.slow_log;
+
+  -- connection slave
+  -- echo ***********************************************
+  -- echo ** DUMPING SLAVE SLOW LOG CONTENTS 
+  -- echo ***********************************************
+  SELECT * FROM mysql.slow_log;
+
+  -- die "Assertion failed! Master and slave slow log contents differ. Bailing out!"
+}
+
+if (`SELECT $master_slow_query = $slave_slow_query`)
+{
+  -- echo ### Assertion is good. Both Master and Slave exhibit the 
+  -- echo ### same number of queries in slow log: $master_slow_query
+}
+
+-- connection master
+SET @@global.log_output= @old_log_output;
+SET @@global.long_query_time= @old_long_query_time;
+DROP TABLE t1;
+
+-- sync_slave_with_master
+SET @@global.log_output= @old_log_output;
+SET @@global.long_query_time= @old_long_query_time;

=== modified file 'mysql-test/suite/sys_vars/r/log_basic.result'
--- a/mysql-test/suite/sys_vars/r/log_basic.result	2009-01-29 16:59:46 +0000
+++ b/mysql-test/suite/sys_vars/r/log_basic.result	2010-02-23 11:33:20 +0000
@@ -18,4 +18,4 @@ VARIABLE_VALUE
 OFF
 SET @@global.log= @start_log;
 Warnings:
-Warning	1287	The syntax '@@log' is deprecated and will be removed in MySQL 7.0. Please use '@@general_log' instead
+Warning	1287	'@@log' is deprecated and will be removed in a future release. Please use '@@general_log' instead

=== modified file 'mysql-test/suite/sys_vars/r/log_bin_trust_routine_creators_basic.result'
--- a/mysql-test/suite/sys_vars/r/log_bin_trust_routine_creators_basic.result	2009-02-16 11:38:15 +0000
+++ b/mysql-test/suite/sys_vars/r/log_bin_trust_routine_creators_basic.result	2010-02-23 11:33:20 +0000
@@ -5,17 +5,17 @@ SELECT @start_global_value;
 '#--------------------FN_DYNVARS_064_01-------------------------#'
 SET @@global.log_bin_trust_routine_creators = TRUE;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SET @@global.log_bin_trust_routine_creators = DEFAULT;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 0
 '#--------------------FN_DYNVARS_064_02-------------------------#'
 SET @@global.log_bin_trust_routine_creators = DEFAULT;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators = 'FALSE';
 @@global.log_bin_trust_routine_creators = 'FALSE'
 1
@@ -24,37 +24,37 @@ Warning	1292	Truncated incorrect DOUBLE 
 '#--------------------FN_DYNVARS_064_03-------------------------#'
 SET @@global.log_bin_trust_routine_creators = ON;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 1
 SET @@global.log_bin_trust_routine_creators = OFF;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 0
 SET @@global.log_bin_trust_routine_creators = 0;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 0
 SET @@global.log_bin_trust_routine_creators = 1;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 1
 SET @@global.log_bin_trust_routine_creators = TRUE;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 1
 SET @@global.log_bin_trust_routine_creators = FALSE;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 0
@@ -70,7 +70,7 @@ SET @@global.log_bin_trust_routine_creat
 ERROR 42000: Variable 'log_bin_trust_routine_creators' can't be set to the value of 'OFFF'
 SET @@global.log_bin_trust_routine_creators = OF;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 0
@@ -96,14 +96,14 @@ ERROR HY000: Variable 'log_bin_trust_rou
 '#---------------------FN_DYNVARS_064_07----------------------#'
 SET @@global.log_bin_trust_routine_creators = TRUE;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@log_bin_trust_routine_creators = @@global.log_bin_trust_routine_creators;
 @@log_bin_trust_routine_creators = @@global.log_bin_trust_routine_creators
 1
 '#---------------------FN_DYNVARS_064_08----------------------#'
 SET @@global.log_bin_trust_routine_creators = TRUE;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@log_bin_trust_routine_creators;
 @@log_bin_trust_routine_creators
 1
@@ -115,7 +115,7 @@ SELECT log_bin_trust_routine_creators = 
 ERROR 42S22: Unknown column 'log_bin_trust_routine_creators' in 'field list'
 SET @@global.log_bin_trust_routine_creators = @start_global_value;
 Warnings:
-Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
+Warning	1287	'@@log_bin_trust_routine_creators' is deprecated and will be removed in a future release. Please use '@@log_bin_trust_function_creators' instead
 SELECT @@global.log_bin_trust_routine_creators;
 @@global.log_bin_trust_routine_creators
 1

=== modified file 'mysql-test/suite/sys_vars/r/slow_query_log_func.result'
--- a/mysql-test/suite/sys_vars/r/slow_query_log_func.result	2009-03-20 17:11:22 +0000
+++ b/mysql-test/suite/sys_vars/r/slow_query_log_func.result	2010-02-11 20:10:13 +0000
@@ -20,5 +20,21 @@ sleep(2)
 SELECT count(*) > 0 FROM mysql.slow_log;
 count(*) > 0
 1
+'Bug#47905 stored procedures not logged correctly to slow query log'
+TRUNCATE mysql.slow_log;
+CREATE PROCEDURE p_test() 
+BEGIN
+select sleep(2);
+select 1;
+END//
+CALL p_test();
+sleep(2)
+0
+1
+1
+SELECT count(*) > 0 FROM mysql.slow_log;
+count(*) > 0
+1
+DROP PROCEDURE p_test;
 SET @@global.log_output = @global_log_output;
 SET @global.slow_query_log = @global_slow_query_log;

=== modified file 'mysql-test/suite/sys_vars/t/slow_query_log_func.test'
--- a/mysql-test/suite/sys_vars/t/slow_query_log_func.test	2009-03-20 17:11:22 +0000
+++ b/mysql-test/suite/sys_vars/t/slow_query_log_func.test	2010-02-11 20:10:13 +0000
@@ -31,6 +31,27 @@ SELECT sleep(2);
 
 SELECT count(*) > 0 FROM mysql.slow_log;
 
+
+#==========================================================================
+--echo 'Bug#47905 stored procedures not logged correctly to slow query log'
+#==========================================================================
+# assumes logging to table turned on with long_query_time=1 as above
+ 
+TRUNCATE mysql.slow_log;
+
+DELIMITER //;
+CREATE PROCEDURE p_test() 
+BEGIN
+   select sleep(2);
+   select 1;
+END//
+DELIMITER ;//
+
+CALL p_test();
+SELECT count(*) > 0 FROM mysql.slow_log;
+DROP PROCEDURE p_test;
+
+
 #restore
 SET @@global.log_output = @global_log_output;
 SET @global.slow_query_log = @global_slow_query_log;

=== modified file 'mysql-test/t/archive.test'
--- a/mysql-test/t/archive.test	2009-11-11 08:03:29 +0000
+++ b/mysql-test/t/archive.test	2010-02-12 12:33:03 +0000
@@ -1644,3 +1644,14 @@ INSERT INTO t1 (col1, col2) VALUES (1, "
 REPAIR TABLE t1;
 DROP TABLE t1;
 remove_file $MYSQLD_DATADIR/test/t1.ARM;
+
+--echo #
+--echo # BUG#48757 - missing .ARZ file causes server crash
+--echo #
+CREATE TABLE t1(a INT) ENGINE=ARCHIVE;
+FLUSH TABLE t1;
+--remove_file $MYSQLD_DATADIR/test/t1.ARZ
+--error ER_FILE_NOT_FOUND
+SELECT * FROM t1;
+--error ER_BAD_TABLE_ERROR
+DROP TABLE t1;

=== modified file 'mysql-test/t/bigint.test'
--- a/mysql-test/t/bigint.test	2007-11-12 13:09:57 +0000
+++ b/mysql-test/t/bigint.test	2010-02-25 19:13:11 +0000
@@ -327,3 +327,38 @@ drop table t1;
 create table t1 select -9223372036854775809 bi;
 describe t1;
 drop table t1;
+
+--echo #
+--echo # Bug #45360: wrong results
+--echo #
+
+CREATE TABLE t1 (id INT AUTO_INCREMENT PRIMARY KEY,
+                 a BIGINT(20) UNSIGNED,
+                 b VARCHAR(20));
+
+INSERT INTO t1 (a) VALUES
+  (0),
+  (CAST(0x7FFFFFFFFFFFFFFF AS UNSIGNED)),
+  (CAST(0x8000000000000000 AS UNSIGNED)),
+  (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
+
+UPDATE t1 SET b = a;
+
+let $n = `SELECT MAX(id) FROM t1`;
+while($n) {
+  let $x = `SELECT a FROM t1 WHERE id = $n`;
+  dec $n;
+  let $hex = `SELECT HEX($x)`;
+  echo # $hex;
+
+  --disable_result_log
+  eval EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE a = $x AND TRIM(a) = b;
+  --enable_result_log
+  SHOW WARNINGS;
+}
+
+DROP TABLE t1;
+
+--echo # End of 5.1 tests
+
+

=== added file 'mysql-test/t/bug39022.test'
--- a/mysql-test/t/bug39022.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/bug39022.test	2010-02-18 08:48:15 +0000
@@ -0,0 +1,63 @@
+-- source include/have_log_bin.inc
+-- source include/have_innodb.inc
+-- source include/not_binlog_format_row.inc
+
+--echo #
+--echo # Bug #39022: Mysql randomly crashing in lock_sec_rec_cons_read_sees
+--echo #
+
+CREATE TABLE t1(a TINYINT NOT NULL,b TINYINT,PRIMARY KEY(b)) ENGINE=innodb;
+CREATE TABLE t2(d TINYINT NOT NULL,UNIQUE KEY(d)) ENGINE=innodb;
+INSERT INTO t1 VALUES (13,0),(8,1),(9,2),(6,3),
+(11,5),(11,6),(7,7),(7,8),(4,9),(6,10),(3,11),(11,12),
+(12,13),(7,14);
+INSERT INTO t2 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
+(11),(12),(13),(14);
+
+connect (thread1, localhost, root,,);
+connect (thread2, localhost, root,,);
+
+connection thread1;
+--echo # in thread1
+START TRANSACTION;
+
+connection thread2;
+--echo # in thread2
+REPLACE INTO t2 VALUES (-17);
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d);
+
+connection thread1;
+--echo # in thread1
+REPLACE INTO t1(a,b) VALUES (67,20);
+
+connection thread2;
+--echo # in thread2
+COMMIT;
+START TRANSACTION;
+REPLACE INTO t1(a,b) VALUES (65,-50);
+REPLACE INTO t2 VALUES (-91);
+send;
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d); #waits
+
+connection thread1;
+--echo # in thread1
+
+--echo # should not crash
+--error ER_LOCK_DEADLOCK
+SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d); #crashes
+
+connection thread2;
+--echo # in thread2
+REAP;
+
+disconnect thread2;
+--source include/wait_until_disconnected.inc
+
+connection thread1;
+--echo # in thread1;
+disconnect thread1;
+--source include/wait_until_disconnected.inc
+
+connection default;
+
+DROP TABLE t1,t2;

=== modified file 'mysql-test/t/csv.test'
--- a/mysql-test/t/csv.test	2009-05-15 10:15:56 +0000
+++ b/mysql-test/t/csv.test	2010-02-17 12:13:42 +0000
@@ -1807,16 +1807,16 @@ unlock tables;
 drop table t1;
 
 #
-# Bug#41441 repair csv table crashes debug server
+# Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM
 #
-# Note: The test should be removed after Bug#33717 is fixed
+CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
+INSERT INTO t1 VALUES();
+INSERT INTO t1 VALUES(default);
+INSERT INTO t1 VALUES(0);
+INSERT INTO t1 VALUES(3);
+INSERT INTO t1 VALUES(-1);
+SELECT * FROM t1;
+DROP TABLE t1;
 
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
---error ER_CRASHED_ON_USAGE
-select * from t1 limit 1;
-repair table t1;
-select * from t1 limit 1;
-drop table t1;
 
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/delete.test'
--- a/mysql-test/t/delete.test	2010-01-29 09:36:28 +0000
+++ b/mysql-test/t/delete.test	2010-02-25 15:12:15 +0000
@@ -291,6 +291,21 @@ DELETE FROM t1 ORDER BY (f1(10)) LIMIT 1
 DROP TABLE t1;
 DROP FUNCTION f1;
 
+
+--echo #
+--echo # Bug #49552 : sql_buffer_result cause crash + not found records 
+--echo #   in multitable delete/subquery
+--echo #
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+SET SESSION SQL_BUFFER_RESULT=1;
+DELETE t1 FROM (SELECT SUM(a) a FROM t1) x,t1;
+
+SET SESSION SQL_BUFFER_RESULT=DEFAULT;
+SELECT * FROM t1;
+DROP TABLE t1;
+
 --echo End of 5.0 tests
 
 --echo #
@@ -360,18 +375,4 @@ DELETE IGNORE FROM t1;
 DROP TABLE t1;
 
 
---echo #
---echo # Bug #49552 : sql_buffer_result cause crash + not found records 
---echo #   in multitable delete/subquery
---echo #
-
-CREATE TABLE t1(a INT);
-INSERT INTO t1 VALUES (1),(2),(3);
-SET SESSION SQL_BUFFER_RESULT=1;
-DELETE t1 FROM (SELECT SUM(a) a FROM t1) x,t1;
-
-SET SESSION SQL_BUFFER_RESULT=DEFAULT;
-SELECT * FROM t1;
-DROP TABLE t1;
-
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/fulltext.test'
--- a/mysql-test/t/fulltext.test	2010-02-02 16:37:56 +0000
+++ b/mysql-test/t/fulltext.test	2010-02-26 13:16:46 +0000
@@ -544,6 +544,27 @@ SELECT count(*) FROM t1 WHERE 
 
 DROP TABLE t1,t2,t3;
 
+#
+# BUG#50351 - ft_min_word_len=2 Causes query to hang
+#
+CREATE TABLE t1 (a VARCHAR(4), FULLTEXT(a));
+INSERT INTO t1 VALUES
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),
+('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('cwrd'),('awrd'),('cwrd'),
+('awrd');
+SELECT COUNT(*) FROM t1 WHERE MATCH(a) AGAINST("+awrd bwrd* +cwrd*" IN BOOLEAN MODE);
+DROP TABLE t1;
 
 --echo #
 --echo # Bug #49445: Assertion failed: 0, file .\item_row.cc, line 55 with 

=== modified file 'mysql-test/t/func_gconcat.test'
--- a/mysql-test/t/func_gconcat.test	2008-05-01 11:54:59 +0000
+++ b/mysql-test/t/func_gconcat.test	2010-02-19 19:06:47 +0000
@@ -693,4 +693,19 @@ SELECT 1 FROM t1 WHERE t1.a NOT IN
 
 DROP TABLE t1, t2;
 
+#
+# Bug #49487: crash with explain extended and group_concat in a derived table
+#
+
+CREATE TABLE t1 (f1 INT);
+INSERT INTO t1 VALUES (),();
+
+EXPLAIN EXTENDED SELECT 1 FROM
+ (SELECT DISTINCT GROUP_CONCAT(td.f1) FROM t1,t1 AS td GROUP BY td.f1) AS d,t1;
+
+SELECT 1 FROM
+ (SELECT DISTINCT GROUP_CONCAT(td.f1) FROM t1,t1 AS td GROUP BY td.f1) AS d,t1;
+
+DROP TABLE t1;
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/group_by.test'
--- a/mysql-test/t/group_by.test	2009-02-26 17:17:06 +0000
+++ b/mysql-test/t/group_by.test	2010-02-06 19:54:30 +0000
@@ -1158,3 +1158,53 @@ SELECT COUNT(i) FROM t1 WHERE i > 1;
 DROP TABLE t1;
 SET @@sql_mode = @old_sql_mode;
 
+--echo #
+--echo # Bug #45640: optimizer bug produces wrong results
+--echo #
+
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (4, 40), (1, 10), (2, 20), (2, 20), (3, 30);
+
+--echo # should return 4 ordered records:
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa;
+
+SELECT (SELECT (SELECT t1.a)) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa;
+
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa+0;
+
+--echo # should return the same result in a reverse order:
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
+
+--echo # execution plan should not use temporary table:
+EXPLAIN EXTENDED
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa+0;
+
+EXPLAIN EXTENDED
+SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
+
+--echo # should return only one record
+SELECT (SELECT tt.a FROM t1 tt LIMIT 1) aa, COUNT(DISTINCT b) FROM t1
+  GROUP BY aa;
+
+CREATE TABLE t2 SELECT DISTINCT a FROM t1;
+
+--echo # originally reported queries (1st two columns of next two query
+--echo # results should be same):
+
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(DISTINCT b)
+  FROM t1 GROUP BY aa, b;
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(         b)
+  FROM t1 GROUP BY aa, b;
+
+--echo # ORDER BY for sure:
+
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(DISTINCT b)
+  FROM t1 GROUP BY aa, b ORDER BY -aa, -b;
+SELECT (SELECT t2.a FROM t2 WHERE t2.a = t1.a) aa, b, COUNT(         b)
+  FROM t1 GROUP BY aa, b ORDER BY -aa, -b;
+
+DROP TABLE t1, t2;
+
+--echo #
+
+--echo # End of 5.1 tests

=== modified file 'mysql-test/t/group_min_max.test'
--- a/mysql-test/t/group_min_max.test	2009-11-23 10:04:17 +0000
+++ b/mysql-test/t/group_min_max.test	2010-02-09 08:53:13 +0000
@@ -1044,4 +1044,14 @@ SELECT a, MAX(b) FROM t WHERE b GROUP BY
 
 DROP TABLE t;
 
+#
+# BUG#49902 - SELECT returns incorrect results
+#
+CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL, KEY (b));
+INSERT INTO t1 VALUES(1,1),(2,1);
+ANALYZE TABLE t1;
+SELECT 1 AS c, b FROM t1 WHERE b IN (1,2) GROUP BY c, b;
+SELECT a FROM t1 WHERE b=1;
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/having.test'
--- a/mysql-test/t/having.test	2009-01-16 15:38:38 +0000
+++ b/mysql-test/t/having.test	2010-02-26 11:39:25 +0000
@@ -442,4 +442,30 @@ INSERT INTO t1 VALUES (1, 1), (2,2), (3,
 SELECT b, COUNT(DISTINCT a) FROM t1 GROUP BY b HAVING b is NULL;
 DROP TABLE t1;
 
+
+--echo #
+--echo # Bug#50995 Having clause on subquery result produces incorrect results.
+--echo #
+
+CREATE TABLE t1
+(
+ id1 INT,
+ id2 INT NOT NULL,
+ INDEX id1(id2)
+);
+
+INSERT INTO t1 SET id1=1, id2=1;
+INSERT INTO t1 SET id1=2, id2=1;
+INSERT INTO t1 SET id1=3, id2=1;
+
+SELECT t1.id1,
+(SELECT 0 FROM DUAL
+ WHERE t1.id1=t1.id1) AS amount FROM t1
+WHERE t1.id2 = 1
+HAVING amount > 0
+ORDER BY t1.id1;
+
+DROP TABLE t1;
+
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/innodb-autoinc.test'
--- a/mysql-test/t/innodb-autoinc.test	2010-01-22 10:02:17 +0000
+++ b/mysql-test/t/innodb-autoinc.test	2010-02-26 09:02:57 +0000
@@ -631,3 +631,34 @@ REPLACE INTO t1 VALUES (-1);
 SELECT * FROM t1;
 SHOW CREATE TABLE t1;
 DROP TABLE t1;
+
+##
+# 49497: Error 1467 (ER_AUTOINC_READ_FAILED) on inserting a negative value
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (-685113344), (1), (NULL), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (-685113344), (2), (NULL), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (NULL), (2), (-685113344), (NULL);
+INSERT INTO  t1 VALUES (4), (5), (6), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (NULL), (2), (-685113344), (5);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1  (c1 INTEGER AUTO_INCREMENT, PRIMARY KEY (c1)) ENGINE=InnoDB;
+INSERT INTO  t1 VALUES (1), (2), (-685113344), (NULL);
+SELECT * FROM t1;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;

=== modified file 'mysql-test/t/innodb_mysql.test'
--- a/mysql-test/t/innodb_mysql.test	2009-12-08 09:26:11 +0000
+++ b/mysql-test/t/innodb_mysql.test	2010-02-26 11:17:00 +0000
@@ -536,4 +536,26 @@ DROP PROCEDURE p1;
 DROP VIEW v1;
 DROP TABLE t1,t2;
 
+
+--echo #
+--echo # Bug #49324: more valgrind errors in test_if_skip_sort_order
+--echo #
+CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
+--echo #should not cause valgrind warnings
+SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#50843: Filesort used instead of clustered index led to
+--echo #            performance degradation.
+--echo #
+create table t1(f1 int not null primary key, f2 int) engine=innodb;
+create table t2(f1 int not null, key (f1)) engine=innodb;
+insert into t1 values (1,1),(2,2),(3,3);
+insert into t2 values (1),(2),(3);
+explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
+drop table t1,t2;
+--echo #
+
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/join.test'
--- a/mysql-test/t/join.test	2009-10-30 08:03:18 +0000
+++ b/mysql-test/t/join.test	2010-02-25 15:48:53 +0000
@@ -804,3 +804,28 @@ DEALLOCATE PREPARE stmt;
 
 DROP VIEW v1;
 DROP TABLE t1, t2;
+
+#
+# Bug#45195 valgrind warnings about uninitialized values in store_record_in_cache()
+#
+CREATE TABLE t1(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
+CREATE TABLE t2(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
+INSERT INTO t1 VALUES ('1',null),(null,null);
+INSERT INTO t2 VALUES ('1',null),(null,null);
+CREATE TABLE mm1(a CHAR(9),b INT,KEY(b),KEY(a))
+ENGINE=MERGE  UNION=(t1,t2);
+SELECT t1.a FROM mm1,t1;
+DROP TABLE t1, t2, mm1;
+
+--echo #
+--echo # Bug #50335: Assertion `!(order->used & map)' in eq_ref_table
+--echo # 
+
+CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b));
+INSERT INTO t1 VALUES (0,0), (1,1);
+
+SELECT * FROM t1 STRAIGHT_JOIN t1 t2 ON t1.a=t2.a AND t1.a=t2.b ORDER BY t2.a, t1.a;
+
+DROP TABLE t1;
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/multi_update.test'
--- a/mysql-test/t/multi_update.test	2009-02-09 21:00:15 +0000
+++ b/mysql-test/t/multi_update.test	2010-02-10 14:37:34 +0000
@@ -637,5 +637,17 @@ drop table t1, t2, t3;
 # Add further tests from here
 #
 
+--echo #
+--echo # Bug#49534: multitable IGNORE update with sql_safe_updates error
+--echo # causes debug assertion
+--echo #
+CREATE TABLE t1( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (1), (2), (3);
+SET SESSION sql_safe_updates = 1;
+--echo # Must not cause failed assertion
+--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
+UPDATE IGNORE t1, t1 t1a SET t1.a = 1 WHERE t1a.a = 1;
+DROP TABLE t1;
+
 
 --echo end of tests

=== modified file 'mysql-test/t/myisam.test'
--- a/mysql-test/t/myisam.test	2009-12-17 06:52:43 +0000
+++ b/mysql-test/t/myisam.test	2010-02-12 12:47:43 +0000
@@ -1198,6 +1198,17 @@ CHECKSUM TABLE t1 EXTENDED;
 DROP TABLE t1;
 
 
+--echo #
+--echo # BUG#48438 - crash with error in unioned query against merge table and view...
+--echo #
+SET GLOBAL table_open_cache=3;
+CREATE TABLE t1(a INT);
+SELECT 1 FROM t1 AS a1, t1 AS a2, t1 AS a3, t1 AS a4 FOR UPDATE;
+SELECT TABLE_ROWS, DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES
+  WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
+DROP TABLE t1;
+SET GLOBAL table_open_cache=DEFAULT;
+
 --echo End of 5.0 tests
 
 
@@ -1563,5 +1574,18 @@ SET myisam_sort_buffer_size=@@global.myi
 CHECK TABLE t1;
 DROP TABLE t1;
 
+
+--echo #
+--echo # BUG#49628 - corrupt table after legal SQL, LONGTEXT column
+--echo #
+CREATE TABLE t1(a INT, b LONGTEXT, UNIQUE(a));
+REPLACE INTO t1 VALUES
+(1, REPEAT('a', 129015)),(1, NULL),
+(2, NULL),(3, NULL),(4, NULL),(5, NULL),(6, NULL),(7, NULL),
+(1, REPEAT('b', 129016)),(1, NULL),
+(1, REPEAT('c', 129015)),(1, REPEAT('d', 129015));
+CHECK TABLE t1;
+DROP TABLE t1;
+
 --echo End of 5.1 tests
 

=== modified file 'mysql-test/t/mysqltest.test'
--- a/mysql-test/t/mysqltest.test	2009-10-08 09:30:03 +0000
+++ b/mysql-test/t/mysqltest.test	2010-02-09 17:13:57 +0000
@@ -605,6 +605,15 @@ echo ;
 --error 1
 --exec echo "--exec " | $MYSQL_TEST 2>&1
 
+# Multi-line exec
+exec $MYSQL
+    test -e "select 1";
+exec $MYSQL test -e "select
+    2";
+let $query = select 3
+    as X;
+exec $MYSQL test -e "$query";
+
 # ----------------------------------------------------------------------------
 # Test let command
 # ----------------------------------------------------------------------------
@@ -911,6 +920,28 @@ sleep 0.5;
 sleep 1;
 real_sleep 1;
 
+# Parameter from variable, legal and illegal
+let $sleep_var= 0.1;
+sleep $sleep_var;
+let $sleep_var= 1;
+--real_sleep $sleep_var
+
+--write_file $MYSQL_TMP_DIR/sleep.inc
+let $sleep_var= xyz;
+--sleep $sleep_var
+EOF
+--error 1
+--exec $MYSQL_TEST < $MYSQL_TMP_DIR/sleep.inc 2>&1
+--remove_file $MYSQL_TMP_DIR/sleep.inc
+
+--write_file $MYSQL_TMP_DIR/sleep.inc
+let $sleep_var= xyz;
+real_sleep $sleep_var;
+EOF
+--error 1
+--exec $MYSQL_TEST < $MYSQL_TMP_DIR/sleep.inc 2>&1
+--remove_file $MYSQL_TMP_DIR/sleep.inc
+
 # Missing parameter
 --error 1
 --exec echo "sleep ;" | $MYSQL_TEST 2>&1
@@ -1006,6 +1037,37 @@ echo test3stop
 --delimiter ;
 echo test4;
 
+# ----------------------------------------------------------------------------
+# Test that delimiter within if() works in in various combinations
+# ----------------------------------------------------------------------------
+
+if (0)
+{
+  delimiter ||;
+  echo false-inner||
+  if (0)
+  {
+    delimiter *||
+    echo false-innerer*
+    delimiter ||*
+  }
+  echo false-inner again||
+}
+echo outer;
+if (1)
+{
+  delimiter /;
+  echo true-inner/
+  if (0)
+  {
+    delimiter %/
+    echo true-innerer%
+  }
+  echo true-inner again/
+}
+echo true-outer/
+delimiter ;/
+
 
 # ----------------------------------------------------------------------------
 # Test if
@@ -1285,6 +1347,17 @@ select "a" as col1, "c" as col2;
 --error 1
 --exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1
 
+let $long_rep= 1234567890123456789012345678901234567890;
+let $long_rep= $long_rep,$long_rep;
+let $long_rep= $long_rep,$long_rep;
+let $long_rep= $long_rep,$long_rep;
+let $long_rep= $long_rep,$long_rep;
+let $long_rep= $long_rep,$long_rep;
+
+# This tests from strings > 1024 (here 1311)
+
+--replace_result $long_rep LONG_STRING
+eval select "$long_rep" as x;
 
 # ----------------------------------------------------------------------------
 # Test sync_with_master
@@ -1606,6 +1679,57 @@ select * from t1;
 drop table t1;
 
 # ----------------------------------------------------------------------------
+# Tests of send
+# ----------------------------------------------------------------------------
+
+create table t1 ( f1 char(10));
+insert into t1 values ("Abcd");
+
+# 1. Basic test
+
+send select * from t1;
+reap;
+
+# 2. Test with error
+
+--send select * from t2;
+--error ER_NO_SUCH_TABLE
+--reap
+
+# 3. test send of next stmt
+
+--send
+select * from t1;
+--reap
+
+# 4. Non-query stmt betwen send and reap allowed
+
+--send select * from t1;
+--sleep 0.05
+--echo Result coming up
+--reap
+
+# 5. Test of send_eval
+
+--let $my_stmt= select * from t1;
+--send_eval $my_stmt
+--reap
+
+# 6. Test that mysqltest does not allow query stmt between send and reap
+# Untestable directly as it causes mysqltest to fail
+
+--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.in
+--send select * from t1;
+select 1;
+--reap
+EOF
+--error 1
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.in 2>&1
+remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.in;
+
+drop table t1;
+
+# ----------------------------------------------------------------------------
 # test for remove_file
 # ----------------------------------------------------------------------------
 
@@ -1616,6 +1740,19 @@ drop table t1;
 remove_file non_existing_file;
 
 # ----------------------------------------------------------------------------
+# test for remove_files_wildcard
+# ----------------------------------------------------------------------------
+
+--error 1
+--exec echo "remove_files_wildcard ;" | $MYSQL_TEST 2>&1
+
+--error 1
+remove_files_wildcard non_existing_dir;
+
+--error 1
+remove_files_wildcard non_existing_dir non_existing_file;
+
+# ----------------------------------------------------------------------------
 # test for write_file
 # ----------------------------------------------------------------------------
 --error 1
@@ -1905,6 +2042,20 @@ perl;
   print "hello\n";
 EOF
 
+# Test perl within while, also with if being false first iteration
+let $outer= 3;
+let $ifval= 0;
+while ($outer) {
+  if ($ifval) {
+    perl UNTIL;
+      my $val= 5;
+      print "val is $val\n";
+UNTIL
+  }
+  inc $ifval;
+  dec $outer;
+}
+
 # ----------------------------------------------------------------------------
 # test for die
 # ----------------------------------------------------------------------------
@@ -2045,6 +2196,44 @@ INSERT INTO t1 SELECT f1 - 512 FROM t1;
 SELECT * FROM t1;
 --enable_result_log
 DROP TABLE t1;
+
+# ----------------------------------------------------------------------------
+# test for lowercase_result
+# ----------------------------------------------------------------------------
+
+# 1. Basic test
+--lowercase_result
+SELECT "500g BL��SYLTET�" AS "WILL BE lower cased";
+
+# 2. test that it does not apply to next statement
+SELECT "UPPER" AS "WILL NOT BE lower cased";
+
+# 3. test that it does not affect non-SQL or the following statement
+--lowercase_result
+--echo UP
+SELECT 0 as "UP AGAIN";
+
+# 4. test that it works with eval and variables
+let $lower_stmt=SELECT "ABCdef" AS "uvwXYZ";
+--lowercase_result
+eval $lower_stmt;
+
+# 5. test that it works in combination with sort
+sorted_result;
+lowercase_result;
+SELECT "Xyz" AS Name UNION SELECT "Abc" as Name ORDER BY Name DESC;
+
+# 6. Test combination with replace, and that lower casing is done first
+--lowercase_result
+--replace_result old new
+SELECT 1 as "SOME OLD TEXT";
+
+# 7. Test missing lower casing of "unknown" characters
+--character_set utf8
+--lowercase_result
+SELECT 0 as "WILL NOT lower case ��;
+--character_set latin1
+
 # ----------------------------------------------------------------------------
 # Some coverage tests
 # ----------------------------------------------------------------------------
@@ -2230,9 +2419,14 @@ rmdir $MYSQLTEST_VARDIR/tmp/testdir;
 
 cat_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
 
-remove_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt;
-remove_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt;
-remove_file $MYSQLTEST_VARDIR/tmp/testdir/file3.txt;
+list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file11.txt $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
+remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file?.txt;
+list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
+cat_file $MYSQLTEST_VARDIR/tmp/testdir/dir-list.txt;
+remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir file*.txt;
+list_files $MYSQLTEST_VARDIR/tmp/testdir;
+remove_files_wildcard $MYSQLTEST_VARDIR/tmp/testdir;
+list_files $MYSQLTEST_VARDIR/tmp/testdir;
 rmdir $MYSQLTEST_VARDIR/tmp/testdir;
 
 #

=== added file 'mysql-test/t/no_binlog.test'
--- a/mysql-test/t/no_binlog.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/no_binlog.test	2010-02-07 00:12:04 +0000
@@ -0,0 +1,6 @@
+-- source include/not_embedded.inc
+
+# BUG#50780: 'show binary logs' debug assertion when binary logging is disabled
+
+-- error ER_NO_BINARY_LOGGING
+SHOW BINARY LOGS;

=== added file 'mysql-test/t/partition_debug_sync.test'
--- a/mysql-test/t/partition_debug_sync.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_debug_sync.test	2010-02-01 15:07:00 +0000
@@ -0,0 +1,81 @@
+#--disable_abort_on_error
+#
+# Test for the partition storage engine which require DEBUG_SYNC feature to
+# Created by Mattias Jonsson
+#
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+SET DEBUG_SYNC= 'RESET';
+--enable_warnings
+
+--echo #
+--echo # Bug#42438: Crash ha_partition::change_table_ptr
+--echo # Test when remove partitioning is done while drop table is waiting
+--echo # for the table.
+connect(con1, localhost, root,,);
+--echo # Con 1
+SET DEBUG_SYNC= 'RESET';
+CREATE TABLE t1
+(a INTEGER,
+ b INTEGER NOT NULL,
+ KEY (b))
+ENGINE = MYISAM
+/*!50100  PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (2),
+ PARTITION p1 VALUES LESS THAN (20),
+ PARTITION p2 VALUES LESS THAN (100),
+ PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+SET DEBUG_SYNC= 'alter_table_before_create_table_no_lock SIGNAL removing_partitioning WAIT_FOR waiting_for_alter';
+SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL partitioning_removed';
+--send ALTER TABLE t1 REMOVE PARTITIONING
+connection default;
+--echo # Con default
+SET DEBUG_SYNC= 'now WAIT_FOR removing_partitioning';
+SET DEBUG_SYNC= 'waiting_for_table SIGNAL waiting_for_alter';
+SET DEBUG_SYNC= 'rm_table_part2_before_delete_table WAIT_FOR partitioning_removed';
+DROP TABLE IF EXISTS t1;
+--echo # Con 1
+connection con1;
+--reap
+connection default;
+SET DEBUG_SYNC= 'RESET';
+connection con1;
+SET DEBUG_SYNC= 'RESET';
+
+--echo #
+--echo # Bug#42438: Crash ha_partition::change_table_ptr
+--echo # Test when remove partitioning is failing due to drop table is already
+--echo # in progress.
+CREATE TABLE t2
+(a INTEGER,
+ b INTEGER NOT NULL,
+ KEY (b))
+ENGINE = MYISAM
+/*!50100  PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (2),
+ PARTITION p1 VALUES LESS THAN (20),
+ PARTITION p2 VALUES LESS THAN (100),
+ PARTITION p3 VALUES LESS THAN MAXVALUE ) */;
+SET DEBUG_SYNC= 'before_lock_tables_takes_lock SIGNAL removing_partitions WAIT_FOR waiting_for_alter';
+SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done';
+--send ALTER TABLE t2 REMOVE PARTITIONING
+connection default;
+--echo # Con default
+SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions';
+SET DEBUG_SYNC= 'waiting_for_table SIGNAL waiting_for_alter';
+SET DEBUG_SYNC= 'rm_table_part2_before_binlog SIGNAL delete_done';
+DROP TABLE IF EXISTS t2;
+--echo # Con 1
+connection con1;
+--error ER_NO_SUCH_TABLE
+--reap
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+connection default;
+--echo # Con default
+SET DEBUG_SYNC= 'RESET';
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/sp-bugs.test'
--- a/mysql-test/t/sp-bugs.test	2009-10-26 09:55:57 +0000
+++ b/mysql-test/t/sp-bugs.test	2010-02-13 10:35:14 +0000
@@ -57,5 +57,48 @@ SELECT f2 ();
 
 DROP SCHEMA testdb;
 
+USE test;
+
+--echo #
+--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+
+CALL p1 ();
+--error ER_TRG_DOES_NOT_EXIST
+CALL p1 ();
+
+DROP TABLE t1;
+DROP PROCEDURE p1;
+
+--echo #
+--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+
+CALL p1 ();
+--error ER_TRG_DOES_NOT_EXIST
+CALL p1 ();
+
+DROP TABLE t1;
+DROP PROCEDURE p1;
 
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/sp_notembedded.test'
--- a/mysql-test/t/sp_notembedded.test	2009-10-13 18:21:42 +0000
+++ b/mysql-test/t/sp_notembedded.test	2010-02-05 09:39:46 +0000
@@ -413,6 +413,43 @@ let $wait_condition=
 --source include/wait_condition.inc 
 DROP PROCEDURE p;
 
+#
+# Bug#47736 killing a select from a view when the view is processing a function, asserts
+#
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES (1);
+CREATE FUNCTION f1 (inp TEXT) RETURNS INT NO SQL RETURN sleep(60);
+CREATE VIEW v1 AS SELECT f1('a') FROM t1;
+
+--connect (con1, localhost, root,,)
+--let $ID_1= `SELECT connection_id()`
+--send SELECT * FROM v1;
+
+--connect (con2, localhost, root,,)
+--let $ID_2= `SELECT connection_id()`
+--send SELECT * FROM v1
+
+--connection default
+--disable_query_log
+--eval KILL QUERY $ID_2
+--eval KILL QUERY $ID_1
+--enable_query_log
+
+--connection con1
+--error ER_QUERY_INTERRUPTED
+--reap
+--connection con2
+--error ER_QUERY_INTERRUPTED
+--reap
+
+--connection default
+DROP VIEW v1;
+DROP TABLE t1;
+DROP FUNCTION f1;
+--disconnect con1
+--disconnect con2
+
+
 --echo # ------------------------------------------------------------------
 --echo # -- End of 5.1 tests
 --echo # ------------------------------------------------------------------

=== modified file 'mysql-test/t/subselect.test'
--- a/mysql-test/t/subselect.test	2009-12-23 15:11:22 +0000
+++ b/mysql-test/t/subselect.test	2010-02-26 13:16:46 +0000
@@ -3600,4 +3600,21 @@ SELECT 1 FROM t1 WHERE a <> SOME
 );
 DROP TABLE t1;
 
+--echo #
+--echo # Bug #45989 take 2 : memory leak after explain encounters an 
+--echo # error in the query
+--echo #
+
+CREATE TABLE t1(a LONGTEXT);
+INSERT INTO t1 VALUES (repeat('a',@@global.max_allowed_packet));
+INSERT INTO t1 VALUES (repeat('b',@@global.max_allowed_packet));
+
+--error ER_BAD_FIELD_ERROR
+EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
+(SELECT DISTINCTROW a AS away FROM t1 GROUP BY a WITH ROLLUP) AS d1  
+WHERE t1.a = d1.a;
+
+DROP TABLE t1;
+
+
 --echo End of 5.1 tests.

=== modified file 'mysql-test/t/type_bit.test'
--- a/mysql-test/t/type_bit.test	2009-10-08 15:36:36 +0000
+++ b/mysql-test/t/type_bit.test	2010-02-16 09:13:49 +0000
@@ -425,4 +425,17 @@ select hex(a) from t1;
 show create table t1;
 drop table t1;
 
+--echo #
+--echo # Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
+--echo #
+CREATE TABLE t1(a INT, b BIT(7) NOT NULL);
+INSERT INTO t1 VALUES (NULL, 0),(NULL, 0);
+SELECT SUM(a) FROM t1 GROUP BY b, a;
+DROP TABLE t1;
+
+CREATE TABLE t1(a INT, b BIT(7) NOT NULL, c BIT(8) NOT NULL);
+INSERT INTO t1 VALUES (NULL, 0, 0),(NULL, 0, 0);
+SELECT SUM(a) FROM t1 GROUP BY c, b, a;
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== renamed file 'mysql-test/t/variables+c.test' => 'mysql-test/t/variables_community.test'
=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2009-08-31 14:09:09 +0000
+++ b/mysql-test/t/view.test	2010-02-12 09:44:20 +0000
@@ -3869,6 +3869,52 @@ ALTER TABLE v1;
 DROP VIEW v1;
 DROP TABLE t1;
 
+--echo #
+--echo # Bug#48449: hang on show create view after upgrading when
+--echo #            view contains function of view
+--echo #
+
+--disable_warnings
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2;
+DROP FUNCTION IF EXISTS f1;
+--enable_warnings
+
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+
+delimiter //;
+CREATE FUNCTION f1() RETURNS INT
+BEGIN
+  SELECT a FROM v2 INTO @a;
+  RETURN @a;
+END//
+delimiter ;//
+
+--echo # Trigger pre-locking when opening v2.
+CREATE VIEW v1 AS SELECT f1() FROM t1;
+
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+copy_file std_data/bug48449.frm $MYSQLD_DATADIR/test/v2.frm;
+
+SHOW CREATE VIEW v1;
+
+DROP VIEW v1,v2;
+DROP TABLE t1,t2;
+DROP FUNCTION f1;
+
+
+#
+# Bug#48294 assertion when creating a view based on some row() construct in select query
+#
+CREATE TABLE t1(f1 INT);
+INSERT INTO t1 VALUES ();
+
+CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE
+ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE  f1 >= ANY ( SELECT '1' )));
+
+DROP VIEW v1;
+DROP TABLE t1;
 
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.1 tests.

=== modified file 'mysql-test/t/view_grant.test'
--- a/mysql-test/t/view_grant.test	2009-10-16 11:12:21 +0000
+++ b/mysql-test/t/view_grant.test	2010-02-12 02:54:14 +0000
@@ -1532,3 +1532,17 @@ SELECT a FROM v2;
 --disconnect mysqluser1
 DROP USER mysqluser1;
 DROP DATABASE mysqltest1;
+USE test;
+
+--echo #
+--echo # Bug#47734: Assertion failed: ! is_set() when locking a view with non-existing definer
+--echo #
+
+--disable_warnings
+DROP VIEW IF EXISTS v1;
+--enable_warnings
+
+CREATE DEFINER=`unknown`@`unknown` SQL SECURITY DEFINER VIEW v1 AS SELECT 1;
+--error ER_NO_SUCH_USER
+LOCK TABLES v1 READ;
+DROP VIEW v1;

=== modified file 'mysys/default.c'
--- a/mysys/default.c	2010-03-12 06:06:23 +0000
+++ b/mysys/default.c	2010-06-09 14:07:08 +0000
@@ -998,10 +998,10 @@ void print_defaults(const char *conf_fil
     }
   }
   puts("\nThe following options may be given as the first argument:\n\
---print-defaults	Print the program argument list and exit\n\
---no-defaults		Don't read default options from any options file\n\
---defaults-file=#	Only read default options from the given file #\n\
---defaults-extra-file=# Read this file after the global files are read");
+--print-defaults        Print the program argument list and exit.\n\
+--no-defaults           Don't read default options from any option file.\n\
+--defaults-file=#       Only read default options from the given file #.\n\
+--defaults-extra-file=# Read this file after the global files are read.");
 }
 
 #include <help_end.h>

=== modified file 'scripts/mysqld_multi.sh'
--- a/scripts/mysqld_multi.sh	2010-01-21 08:10:05 +0000
+++ b/scripts/mysqld_multi.sh	2010-02-26 12:49:13 +0000
@@ -71,7 +71,6 @@ sub main
       print "WARNING: --config-file is deprecated and will be removed\n";
       print "in MySQL 5.6.  Please use --defaults-extra-file instead\n";
     }
-   }
   }
 
   foreach (@defaults_options)

=== modified file 'server-tools/instance-manager/options.cc'
--- a/server-tools/instance-manager/options.cc	2010-03-12 06:06:23 +0000
+++ b/server-tools/instance-manager/options.cc	2010-06-09 14:07:08 +0000
@@ -151,7 +151,7 @@ static struct my_option my_long_options[
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
   { "add-user", OPT_ADD_USER,
-    "Add a user to the password file",
+    "Add a user to the password file.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
 #ifndef __WIN__
@@ -167,11 +167,11 @@ static struct my_option my_long_options[
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
   { "check-password-file", OPT_CHECK_PASSWORD_FILE,
-    "Check the password file for consistency",
+    "Check the password file for consistency.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
   { "clean-password-file", OPT_CLEAN_PASSWORD_FILE,
-    "Clean the password file",
+    "Clean the password file.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
 #ifndef DBUG_OFF
@@ -188,11 +188,11 @@ static struct my_option my_long_options[
     0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0 },
 
   { "drop-user", OPT_DROP_USER,
-    "Drop existing user from the password file",
+    "Drop existing user from the password file.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
   { "edit-user", OPT_EDIT_USER,
-    "Edit existing user in the password file",
+    "Edit existing user in the password file.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
 #ifdef __WIN__
@@ -203,7 +203,7 @@ static struct my_option my_long_options[
 #endif
 
   { "list-users", OPT_LIST_USERS,
-    "Print out a list of registered users",
+    "Print out a list of registered users.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
 #ifndef __WIN__
@@ -221,7 +221,7 @@ static struct my_option my_long_options[
     0, 0, 0, 0, 0 },
 
   { "mysqld-safe-compatible", OPT_MYSQLD_SAFE_COMPATIBLE,
-    "Start Instance Manager in mysqld_safe compatible manner",
+    "Start Instance Manager in mysqld_safe-compatible manner.",
     (uchar* *) &Options::Main::mysqld_safe_compatible,
     (uchar* *) &Options::Main::mysqld_safe_compatible,
     0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
@@ -230,7 +230,7 @@ static struct my_option my_long_options[
     "Print out a user entry as a line for the password file and exit.",
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
 
-  { "password", OPT_PASSWORD, "Password to update the password file",
+  { "password", OPT_PASSWORD, "Password to update the password file.",
     (uchar* *) &Options::User_management::password,
     (uchar* *) &Options::User_management::password,
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
@@ -246,7 +246,7 @@ static struct my_option my_long_options[
     (uchar* *) &Options::Main::pid_file_name,
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
-  { "port", OPT_PORT, "Port number to use for connections",
+  { "port", OPT_PORT, "Port number to use for connections.",
     (uchar* *) &Options::Main::port_number,
     (uchar* *) &Options::Main::port_number,
     0, GET_UINT, REQUIRED_ARG, DEFAULT_PORT, 0, 0, 0, 0, 0 },
@@ -276,14 +276,14 @@ static struct my_option my_long_options[
     (uchar* *) &Options::Service::stand_alone,
     0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0},
 #else
-  { "user", OPT_USER, "Username to start mysqlmanager",
+  { "user", OPT_USER, "Username to start mysqlmanager.",
     (uchar* *) &Options::Daemon::user,
     (uchar* *) &Options::Daemon::user,
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 #endif
 
   { "username", OPT_USERNAME,
-    "Username to update the password file",
+    "Username to update the password file.",
     (uchar* *) &Options::User_management::user_name,
     (uchar* *) &Options::User_management::user_name,
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
@@ -315,16 +315,16 @@ static void usage()
 {
   version();
 
-  printf("Copyright (C) 2003, 2004 MySQL AB\n"
+  printf("Copyright (C) 2003, 2004 MySQL AB.\n"
   "This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
-  "and you are welcome to modify and redistribute it under the GPL license\n");
+  "and you are welcome to modify and redistribute it under the GPL license.\n");
   printf("Usage: %s [OPTIONS] \n", my_progname);
 
   my_print_help(my_long_options);
   printf("\nThe following options may be given as the first argument:\n"
-  "--print-defaults        Print the program argument list and exit\n"
+  "--print-defaults        Print the program argument list and exit.\n"
   "--defaults-file=#       Only read manager configuration and instance\n"
-  "                        setings from the given file #. The same file\n"
+  "                        settings from the given file #. The same file\n"
   "                        will be used to modify configuration of instances\n"
   "                        with SET commands.\n");
   my_print_variables(my_long_options);

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2010-03-12 06:06:23 +0000
+++ b/sql/field.cc	2010-06-09 14:07:08 +0000
@@ -1707,11 +1707,10 @@ uint Field::fill_cache_field(CACHE_FIELD
   uint store_length;
   copy->str=ptr;
   copy->length=pack_length();
-  copy->blob_field=0;
+  copy->field= this;
   if (flags & BLOB_FLAG)
   {
-    copy->blob_field=(Field_blob*) this;
-    copy->strip=0;
+    copy->type= CACHE_BLOB;
     copy->length-= table->s->blob_ptr_size;
     return copy->length;
   }
@@ -1719,15 +1718,15 @@ uint Field::fill_cache_field(CACHE_FIELD
            (type() == MYSQL_TYPE_STRING && copy->length >= 4 &&
             copy->length < 256))
   {
-    copy->strip=1;				/* Remove end space */
+    copy->type= CACHE_STRIPPED;
     store_length= 2;
   }
   else
   {
-    copy->strip=0;
+    copy->type= 0;
     store_length= 0;
   }
-  return copy->length+ store_length;
+  return copy->length + store_length;
 }
 
 

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2010-03-12 06:06:23 +0000
+++ b/sql/ha_partition.cc	2010-06-09 14:07:08 +0000
@@ -1749,13 +1749,23 @@ void ha_partition::update_create_info(HA
 
 void ha_partition::change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
 {
-  handler **file_array= m_file;
+  handler **file_array;
   table= table_arg;
   table_share= share;
-  do
+  /*
+    m_file can be NULL when using an old cached table in DROP TABLE, when the
+    table just has REMOVED PARTITIONING, see Bug#42438
+  */
+  if (m_file)
   {
-    (*file_array)->change_table_ptr(table_arg, share);
-  } while (*(++file_array));
+    file_array= m_file;
+    DBUG_ASSERT(*file_array);
+    do
+    {
+      (*file_array)->change_table_ptr(table_arg, share);
+    } while (*(++file_array));
+  }
+
   if (m_added_file && m_added_file[0])
   {
     /* if in middle of a drop/rename etc */
@@ -6087,7 +6097,13 @@ void ha_partition::print_error(int error
   if (error == HA_ERR_NO_PARTITION_FOUND)
     m_part_info->print_no_partition_found(table);
   else
-    m_file[m_last_part]->print_error(error, errflag);
+  {
+    /* In case m_file has not been initialized, like in bug#42438 */
+    if (m_file)
+      m_file[m_last_part]->print_error(error, errflag);
+    else
+      handler::print_error(error, errflag);
+  }
   DBUG_VOID_RETURN;
 }
 
@@ -6097,7 +6113,12 @@ bool ha_partition::get_error_message(int
   DBUG_ENTER("ha_partition::get_error_message");
 
   /* Should probably look for my own errors first */
-  DBUG_RETURN(m_file[m_last_part]->get_error_message(error, buf));
+
+  /* In case m_file has not been initialized, like in bug#42438 */
+  if (m_file)
+    DBUG_RETURN(m_file[m_last_part]->get_error_message(error, buf));
+  DBUG_RETURN(handler::get_error_message(error, buf));
+
 }
 
 

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-03-12 14:32:53 +0000
+++ b/sql/item.cc	2010-06-09 14:07:08 +0000
@@ -2212,14 +2212,14 @@ String *Item_int::val_str(String *str)
 {
   // following assert is redundant, because fixed=1 assigned in constructor
   DBUG_ASSERT(fixed == 1);
-  str->set(value, &my_charset_bin);
+  str->set_int(value, unsigned_flag, &my_charset_bin);
   return str;
 }
 
 void Item_int::print(String *str, enum_query_type query_type)
 {
   // my_charset_bin is good enough for numbers
-  str_value.set(value, &my_charset_bin);
+  str_value.set_int(value, unsigned_flag, &my_charset_bin);
   str->append(str_value);
 }
 
@@ -4303,17 +4303,33 @@ bool Item_field::fix_fields(THD *thd, It
               It's not an Item_field in the select list so we must make a new
               Item_ref to point to the Item in the select list and replace the
               Item_field created by the parser with the new Item_ref.
+
+              NOTE: If we are fixing an alias reference inside ORDER/GROUP BY
+              item tree, then we use new Item_ref as an intermediate value
+              to resolve referenced item only.
+              In this case the new Item_ref item is unused.
             */
             Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
             if (!rf)
               return 1;
-            thd->change_item_tree(reference, rf);
+
+            bool save_group_fix_field= thd->lex->current_select->group_fix_field;
             /*
-              Because Item_ref never substitutes itself with other items 
-              in Item_ref::fix_fields(), we can safely use the original 
-              pointer to it even after fix_fields()
-             */
-            return rf->fix_fields(thd, reference) ||  rf->check_cols(1);
+              No need for recursive resolving of aliases.
+            */
+            thd->lex->current_select->group_fix_field= 0;
+
+            bool ret= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1);
+            thd->lex->current_select->group_fix_field= save_group_fix_field;
+            if (ret)
+              return TRUE;
+
+            if (save_group_fix_field && alias_name_used)
+              thd->change_item_tree(reference, *rf->ref);
+            else
+              thd->change_item_tree(reference, rf);
+
+            return FALSE;
           }
         }
       }
@@ -5144,7 +5160,7 @@ int Item::save_in_field(Field *field, bo
     field->set_notnull();
     error=field->store(nr, unsigned_flag);
   }
-  return error ? error : (field->table->in_use->is_error() ? 2 : 0);
+  return error ? error : (field->table->in_use->is_error() ? 1 : 0);
 }
 
 
@@ -6475,7 +6491,8 @@ int Item_default_value::save_in_field(Fi
 {
   if (!arg)
   {
-    if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
+    if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
+        field_arg->real_type() != MYSQL_TYPE_ENUM)
     {
       if (field_arg->reset())
       {

=== modified file 'sql/item.h'
--- a/sql/item.h	2010-03-12 06:06:23 +0000
+++ b/sql/item.h	2010-06-09 14:07:08 +0000
@@ -907,6 +907,7 @@ public:
   virtual bool change_context_processor(uchar *context) { return 0; }
   virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
   virtual bool is_expensive_processor(uchar *arg) { return 0; }
+  virtual bool find_item_processor(uchar *arg) { return this == (void *) arg; }
   virtual bool register_field_in_read_map(uchar *arg) { return 0; }
   /*
     Check if a partition function is allowed
@@ -2281,7 +2282,10 @@ public:
     return ref ? (*ref)->real_item() : this;
   }
   bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
-  { return (*ref)->walk(processor, walk_subquery, arg); }
+  {
+    return (*ref)->walk(processor, walk_subquery, arg) ||
+           (this->*processor)(arg);
+  }
   virtual void print(String *str, enum_query_type query_type);
   bool result_as_longlong()
   {

=== modified file 'sql/item_cmpfunc.h'
--- a/sql/item_cmpfunc.h	2010-03-12 06:06:23 +0000
+++ b/sql/item_cmpfunc.h	2010-06-09 14:07:08 +0000
@@ -1477,9 +1477,21 @@ public:
   Item_cond(THD *thd, Item_cond *item);
   Item_cond(List<Item> &nlist)
     :Item_bool_func(), list(nlist), abort_on_null(0) {}
-  bool add(Item *item) { return list.push_back(item); }
-  bool add_at_head(Item *item) { return list.push_front(item); }
-  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
+  bool add(Item *item)
+  {
+    DBUG_ASSERT(item);
+    return list.push_back(item);
+  }
+  bool add_at_head(Item *item)
+  {
+    DBUG_ASSERT(item);
+    return list.push_front(item);
+  }
+  void add_at_head(List<Item> *nlist)
+  {
+    DBUG_ASSERT(nlist->elements);
+    list.prepand(nlist);
+  }
   bool fix_fields(THD *, Item **ref);
 
   enum Type type() const { return COND_ITEM; }

=== modified file 'sql/item_row.cc'
--- a/sql/item_row.cc	2009-05-26 18:53:34 +0000
+++ b/sql/item_row.cc	2010-06-09 14:07:08 +0000
@@ -74,7 +74,12 @@ bool Item_row::fix_fields(THD *thd, Item
     Item *item= *arg;
     used_tables_cache |= item->used_tables();
     const_item_cache&= item->const_item() && !with_null;
-    if (const_item_cache)
+    /*
+      Some subqueries transformations aren't done in the view_prepare_mode thus
+      is_null() will fail. So we skip is_null() calculation for CREATE VIEW as
+      not necessary.
+    */
+    if (const_item_cache && !thd->lex->view_prepare_mode)
     {
       if (item->cols() > 1)
 	with_null|= item->null_inside();

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2010-03-12 06:06:23 +0000
+++ b/sql/item_sum.cc	2010-06-09 14:07:08 +0000
@@ -3405,6 +3405,8 @@ String* Item_func_group_concat::val_str(
 
 void Item_func_group_concat::print(String *str, enum_query_type query_type)
 {
+  /* orig_args is not filled with valid values until fix_fields() */
+  Item **pargs= fixed ? orig_args : args;
   str->append(STRING_WITH_LEN("group_concat("));
   if (distinct)
     str->append(STRING_WITH_LEN("distinct "));
@@ -3412,7 +3414,7 @@ void Item_func_group_concat::print(Strin
   {
     if (i)
       str->append(',');
-    args[i]->print(str, query_type);
+    pargs[i]->print(str, query_type);
   }
   if (arg_count_order)
   {

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2010-03-12 06:06:23 +0000
+++ b/sql/item_timefunc.cc	2010-06-09 14:07:08 +0000
@@ -879,7 +879,7 @@ static bool get_interval_info(const char
       value= value*LL(10) + (longlong) (*str - '0');
     if (transform_msec && i == count - 1) // microseconds always last
     {
-      int msec_length= 6 - (int)(str - start);
+      int msec_length= 6 - (int) (str - start);
       if (msec_length > 0)
         value*= (long)log_10_int[msec_length];
     }

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-03-12 06:06:23 +0000
+++ b/sql/log.cc	2010-06-09 14:07:08 +0000
@@ -967,6 +967,7 @@ bool LOGGER::slow_log_print(THD *thd, co
   uint user_host_len= 0;
   ulonglong query_utime, lock_utime;
 
+  DBUG_ASSERT(thd->enable_slow_log);
   /*
     Print the message to the buffer if we have slow log enabled
   */

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-03-12 06:06:23 +0000
+++ b/sql/log_event.cc	2010-06-09 14:07:08 +0000
@@ -3173,6 +3173,18 @@ int Query_log_event::do_apply_event(Rela
       const char* found_semicolon= NULL;
       mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon);
       log_slow_statement(thd);
+
+      /*
+        Resetting the enable_slow_log thd variable.
+
+        We need to reset it back to the opt_log_slow_slave_statements
+        value after the statement execution (and slow logging
+        is done). It might have changed if the statement was an
+        admin statement (in which case, down in mysql_parse execution
+        thd->enable_slow_log is set to the value of
+        opt_log_slow_admin_statements).
+      */
+      thd->enable_slow_log= opt_log_slow_slave_statements;
     }
     else
     {
@@ -8768,7 +8780,7 @@ static bool record_compare(TABLE *table)
   DBUG_DUMP("record[1]", table->record[1], table->s->reclength);
 
   bool result= FALSE;
-  uchar saved_x[2], saved_filler[2];
+  uchar saved_x[2]= {0, 0}, saved_filler[2]= {0, 0};
 
   if (table->s->null_bytes > 0)
   {

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2010-01-24 07:03:23 +0000
+++ b/sql/log_event_old.cc	2010-02-22 13:23:47 +0000
@@ -337,7 +337,7 @@ static bool record_compare(TABLE *table)
    */
 
   bool result= FALSE;
-  uchar saved_x[2], saved_filler[2];
+  uchar saved_x[2]= {0, 0}, saved_filler[2]= {0, 0};
 
   if (table->s->null_bytes > 0)
   {

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2010-03-12 06:06:23 +0000
+++ b/sql/mysql_priv.h	2010-06-09 14:07:08 +0000
@@ -121,13 +121,15 @@ char* query_table_status(THD *thd,const 
 #define WARN_DEPRECATED(Thd,Ver,Old,New)                                             \
   do {                                                                               \
     DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0);              \
-    if (((uchar*)Thd) != NULL)                                                         \
+    if (((uchar*)Thd) != NULL)                                                       \
       push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN,                \
-                        ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER), \
-                        (Old), (Ver), (New));                                        \
+                        ER_WARN_DEPRECATED_SYNTAX,                                   \
+                        ER(ER_WARN_DEPRECATED_SYNTAX),                               \
+                        (Old), (New));                                               \
     else                                                                             \
-      sql_print_warning("The syntax '%s' is deprecated and will be removed "         \
-                        "in a future release. Please use %s instead.", (Old), (New)); \
+      sql_print_warning("'%s' is deprecated and will be removed "                    \
+                        "in a future release. Please use '%s' instead.",             \
+                        (Old), (New));                                               \
   } while(0)
 
 extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
@@ -1211,7 +1213,7 @@ int setup_group(THD *thd, Item **ref_poi
 		List<Item> &fields, List<Item> &all_fields, ORDER *order,
 		bool *hidden_group_fields);
 bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
-                   Item **ref_pointer_array);
+                   Item **ref_pointer_array, ORDER *group_list= NULL);
 
 bool handle_select(THD *thd, LEX *lex, select_result *result,
                    ulong setup_tables_done_option);

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-03-12 06:06:23 +0000
+++ b/sql/mysqld.cc	2010-06-09 14:07:08 +0000
@@ -5242,9 +5242,9 @@ pthread_handler_t handle_connections_soc
 
     create_new_thread(thd);
   }
-
+  DBUG_LEAVE;
   decrement_handler_count();
-  DBUG_RETURN(0);
+  return 0;
 }
 
 
@@ -5340,8 +5340,9 @@ pthread_handler_t handle_connections_nam
     create_new_thread(thd);
   }
   CloseHandle(connectOverlapped.hEvent);
+  DBUG_LEAVE;
   decrement_handler_count();
-  DBUG_RETURN(0);
+  return 0;
 }
 #endif /* __NT__ */
 
@@ -5577,9 +5578,9 @@ error:
   if (handle_connect_file_map)	CloseHandle(handle_connect_file_map);
   if (event_connect_answer)	CloseHandle(event_connect_answer);
   if (smem_event_connect_request) CloseHandle(smem_event_connect_request);
-
+  DBUG_LEAVE;
   decrement_handler_count();
-  DBUG_RETURN(0);
+  return 0;
 }
 #endif /* HAVE_SMEM */
 #endif /* EMBEDDED_LIBRARY */
@@ -5795,12 +5796,12 @@ struct my_option my_long_options[] =
   {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'.", 0, 0, 0,
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"auto-increment-increment", OPT_AUTO_INCREMENT,
-   "Auto-increment columns are incremented by this",
+   "Auto-increment columns are incremented by this.",
    (uchar**) &global_system_variables.auto_increment_increment,
    (uchar**) &max_system_variables.auto_increment_increment, 0, GET_ULONG,
    OPT_ARG, 1, 1, 65535, 0, 1, 0 },
   {"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
-   "Offset added to Auto-increment columns. Used when auto-increment-increment != 1",
+   "Offset added to Auto-increment columns. Used when auto-increment-increment != 1.",
    (uchar**) &global_system_variables.auto_increment_offset,
    (uchar**) &max_system_variables.auto_increment_offset, 0, GET_ULONG, OPT_ARG,
    1, 1, 65535, 0, 1, 0 },
@@ -5813,7 +5814,7 @@ struct my_option my_long_options[] =
    (uchar**) &mysql_home_ptr, (uchar**) &mysql_home_ptr, 0, GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0},
   {"big-tables", OPT_BIG_TABLES,
-   "Allow big result sets by saving all temporary sets on file (Solves most 'table full' errors).",
+   "Allow big result sets by saving all temporary sets on file (solves most 'table full' errors).",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
    (uchar**) &my_bind_addr_str, (uchar**) &my_bind_addr_str, 0, GET_STR,
@@ -5821,11 +5822,10 @@ struct my_option my_long_options[] =
   {"binlog_format", OPT_BINLOG_FORMAT,
    "Does not have any effect without '--log-bin'. "
    "Tell the master the form of binary logging to use: either 'row' for "
-   "row-based binary logging, or 'statement' for statement-based binary "
+   "row-based binary logging, 'statement' for statement-based binary "
    "logging, or 'mixed'. 'mixed' is statement-based binary logging except "
-   "for those statements where only row-based is correct: those which "
-   "involve user-defined functions (i.e. UDFs) or the UUID() function; for "
-   "those, row-based binary logging is automatically used. "
+   "for statements where only row-based is correct: Statements that involve "
+   "user-defined functions (i.e., UDFs) or the UUID() function."
 #ifdef HAVE_NDB_BINLOG
    "If ndbcluster is enabled and binlog_format is `mixed', the format switches"
    " to 'row' and back implicitly per each query accessing a NDB table."
@@ -5836,7 +5836,7 @@ struct my_option my_long_options[] =
    "Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"binlog-ignore-db", OPT_BINLOG_IGNORE_DB,
-   "Tells the master that updates to the given database should not be logged tothe binary log.",
+   "Tells the master that updates to the given database should not be logged to the binary log.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"binlog-row-event-max-size", OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
    "The maximum size of a row-based binary log event in bytes. Rows will be "
@@ -5880,10 +5880,10 @@ struct my_option my_long_options[] =
    (uchar**) &max_system_variables.completion_type, 0, GET_ULONG,
    REQUIRED_ARG, 0, 0, 2, 0, 1, 0},
   {"concurrent-insert", OPT_CONCURRENT_INSERT,
-   "Use concurrent insert with MyISAM. Disable with --concurrent-insert=0",
+   "Use concurrent insert with MyISAM. Disable with --concurrent-insert=0.",
    (uchar**) &myisam_concurrent_insert, (uchar**) &myisam_concurrent_insert,
    0, GET_ULONG, OPT_ARG, 1, 0, 2, 0, 0, 0},
-  {"console", OPT_CONSOLE, "Write error output on screen; Don't remove the console window on windows.",
+  {"console", OPT_CONSOLE, "Write error output on screen; don't remove the console window on windows.",
    (uchar**) &opt_console, (uchar**) &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0,
    0, 0, 0},
   {"core-file", OPT_WANT_CORE, "Write core on errors.", 0, 0, 0, GET_NO_ARG,
@@ -5915,7 +5915,7 @@ struct my_option my_long_options[] =
   {"delay-key-write", OPT_DELAY_KEY_WRITE, "Type of DELAY_KEY_WRITE.",
    0,0,0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"delay-key-write-for-all-tables", OPT_DELAY_KEY_WRITE_ALL,
-   "Don't flush key buffers between writes for any MyISAM table (Deprecated option, use --delay-key-write=all instead).",
+   "Don't flush key buffers between writes for any MyISAM table. (Deprecated option, use --delay-key-write=all instead.)",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_OPENSSL
   {"des-key-file", OPT_DES_KEY_FILE,
@@ -5953,7 +5953,7 @@ struct my_option my_long_options[] =
   /* See how it's handled in get_one_option() */
   {"event-scheduler", OPT_EVENT_SCHEDULER, "Enable/disable the event scheduler.",
    NULL,  NULL, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"exit-info", 'T', "Used for debugging;  Use at your own risk!", 0, 0, 0,
+  {"exit-info", 'T', "Used for debugging. Use at your own risk.", 0, 0, 0,
    GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"external-locking", OPT_USE_LOCKING, "Use system (external) locking (disabled by default).  With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running. Disable with --skip-external-locking.",
    (uchar**) &opt_external_locking, (uchar**) &opt_external_locking,
@@ -5963,11 +5963,11 @@ struct my_option my_long_options[] =
   /* We must always support the next option to make scripts like mysqltest
      easier to do */
   {"gdb", OPT_DEBUGGING,
-   "Set up signals usable for debugging",
+   "Set up signals usable for debugging.",
    (uchar**) &opt_debugging, (uchar**) &opt_debugging,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"general_log", OPT_GENERAL_LOG,
-   "Enable|disable general log", (uchar**) &opt_log,
+   "Enable/disable general log.", (uchar**) &opt_log,
    (uchar**) &opt_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_LARGE_PAGES
   {"large-pages", OPT_ENABLE_LARGE_PAGES, "Enable support for large pages. \
@@ -5976,9 +5976,10 @@ Disable with --skip-large-pages.",
    0, 0, 0},
 #endif
   {"ignore-builtin-innodb", OPT_IGNORE_BUILTIN_INNODB ,
-   "Disable initialization of builtin InnoDB plugin",
+   "Disable initialization of builtin InnoDB plugin.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"init-connect", OPT_INIT_CONNECT, "Command(s) that are executed for each new connection",
+  {"init-connect", OPT_INIT_CONNECT, 
+   "Command(s) that are executed for each new connection.",
    (uchar**) &opt_init_connect, (uchar**) &opt_init_connect, 0, GET_STR_ALLOC,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifndef DISABLE_GRANT_OPTIONS
@@ -6002,7 +6003,7 @@ each time the SQL thread starts.",
    (uchar**) &lc_time_names_name,
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
   {"local-infile", OPT_LOCAL_INFILE,
-   "Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0).",
+   "Enable/disable LOAD DATA LOCAL INFILE (takes values 1 or 0).",
    (uchar**) &opt_local_infile,
    (uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
    1, 0, 0, 0, 0, 0},
@@ -6040,8 +6041,9 @@ each time the SQL thread starts.",
   */
   {"log-bin-trust-function-creators", OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
    "If equal to 0 (the default), then when --log-bin is used, creation of "
-   "a stored function (or trigger) is allowed only to users having the SUPER privilege "
-   "and only if this stored function (trigger) may not break binary logging."
+   "a stored function (or trigger) is allowed only to users having the SUPER "
+   "privilege, and only if this stored function (trigger) may not break "
+   "binary logging."
    "Note that if ALL connections to this server ALWAYS use row-based binary "
    "logging, the security issues do not exist and the binary logging cannot "
    "break, so you can safely set this to 1."
@@ -6098,7 +6100,7 @@ each time the SQL thread starts.",
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"log-tc", OPT_LOG_TC,
    "Path to transaction coordinator log (used for transactions that affect "
-   "more than one storage engine, when binary log is disabled)",
+   "more than one storage engine, when binary log is disabled).",
    (uchar**) &opt_tc_log_file, (uchar**) &opt_tc_log_file, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_MMAP
@@ -6122,7 +6124,9 @@ log and this option justs turns on --log
    (uchar**) &max_system_variables.low_priority_updates,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"master-connect-retry", OPT_MASTER_CONNECT_RETRY,
-   "The number of seconds the slave thread will sleep before retrying to connect to the master in case the master goes down or the connection is lost.",
+   "The number of seconds the slave thread will sleep before retrying to "
+   "connect to the master, in case the master goes down or the connection "
+   "is lost.",
    (uchar**) &master_connect_retry, (uchar**) &master_connect_retry, 0, GET_UINT,
    REQUIRED_ARG, 60, 0, 0, 0, 0, 0},
   {"master-host", OPT_MASTER_HOST,
@@ -6135,7 +6139,9 @@ thread is in the master's binlogs.",
    (uchar**) &master_info_file, (uchar**) &master_info_file, 0, GET_STR,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"master-password", OPT_MASTER_PASSWORD,
-   "The password the slave thread will authenticate with when connecting to the master. If not set, an empty password is assumed.The value in master.info will take precedence if it can be read.",
+   "The password the slave thread will authenticate with when connecting to "
+   "the master. If not set, an empty password is assumed. The value in "
+   "master.info will take precedence if it can be read.",
    (uchar**)&master_password, (uchar**)&master_password, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"master-port", OPT_MASTER_PORT,
@@ -6159,8 +6165,8 @@ thread is in the master's binlogs.",
    (uchar**) &master_ssl_capath, (uchar**) &master_ssl_capath, 0, GET_STR, OPT_ARG,
    0, 0, 0, 0, 0, 0},
   {"master-ssl-cert", OPT_MASTER_SSL_CERT,
-   "Master SSL certificate file name. Only applies if you have enabled \
-master-ssl",
+   "Master SSL certificate file name. Only applies if you have enabled "
+   "master-ssl.",
    (uchar**) &master_ssl_cert, (uchar**) &master_ssl_cert, 0, GET_STR, OPT_ARG,
    0, 0, 0, 0, 0, 0},
   {"master-ssl-cipher", OPT_MASTER_SSL_CIPHER,
@@ -6227,14 +6233,14 @@ master-ssl",
 #ifdef HAVE_NDB_BINLOG
   {"ndb-report-thresh-binlog-epoch-slip", OPT_NDB_REPORT_THRESH_BINLOG_EPOCH_SLIP,
    "Threshold on number of epochs to be behind before reporting binlog status. "
-   "E.g. 3 means that if the difference between what epoch has been received "
+   "E.g., 3 means that if the difference between what epoch has been received "
    "from the storage nodes and what has been applied to the binlog is 3 or more, "
    "a status message will be sent to the cluster log.",
    (uchar**) &ndb_report_thresh_binlog_epoch_slip,
    (uchar**) &ndb_report_thresh_binlog_epoch_slip,
    0, GET_ULONG, REQUIRED_ARG, 3, 0, 256, 0, 0, 0},
   {"ndb-report-thresh-binlog-mem-usage", OPT_NDB_REPORT_THRESH_BINLOG_MEM_USAGE,
-   "Threshold on percentage of free memory before reporting binlog status. E.g. "
+   "Threshold on percentage of free memory before reporting binlog status. E.g., "
    "10 means that if amount of available memory for receiving binlog data from "
    "the storage nodes goes below 10%, "
    "a status message will be sent to the cluster log.",
@@ -6284,7 +6290,7 @@ master-ssl",
    (uchar**) &global_system_variables.ndb_use_exact_count,
    0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
   {"ndb_use_exact_count", OPT_NDB_USE_EXACT_COUNT,
-   "same as --ndb-use-exact-count.",
+   "Same as --ndb-use-exact-count.",
    (uchar**) &global_system_variables.ndb_use_exact_count,
    (uchar**) &global_system_variables.ndb_use_exact_count,
    0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
@@ -6295,7 +6301,7 @@ master-ssl",
    (uchar**) &global_system_variables.ndb_use_transactions,
    0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
   {"ndb_use_transactions", OPT_NDB_USE_TRANSACTIONS,
-   "same as --ndb-use-transactions.",
+   "Same as --ndb-use-transactions.",
    (uchar**) &global_system_variables.ndb_use_transactions,
    (uchar**) &global_system_variables.ndb_use_transactions,
    0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
@@ -6310,7 +6316,9 @@ master-ssl",
    (uchar**) &opt_ndb_optimized_node_selection,
    0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
   { "ndb-cache-check-time", OPT_NDB_CACHE_CHECK_TIME,
-    "A dedicated thread is created to, at the given millisecons interval, invalidate the query cache if another MySQL server in the cluster has changed the data in the database.",
+    "A dedicated thread is created to, at the given milliseconds interval, "
+    "invalidate the query cache if another MySQL server in the cluster has "
+    "changed the data in the database.",
     (uchar**) &opt_ndb_cache_check_time, (uchar**) &opt_ndb_cache_check_time, 0, GET_ULONG, REQUIRED_ARG,
     0, 0, LONG_TIMEOUT, 0, 1, 0},
   {"ndb-index-stat-enable", OPT_NDB_INDEX_STAT_ENABLE,
@@ -6334,12 +6342,13 @@ master-ssl",
     (uchar**) &opt_ndb_cluster_connection_pool,
     0, GET_ULONG, REQUIRED_ARG, 1, 1, 63, 0, 0, 0},
 #endif
-  {"new", 'n', "Use very new possible 'unsafe' functions.",
+  {"new", 'n', "Use very new, possibly 'unsafe', functions.",
    (uchar**) &global_system_variables.new_mode,
    (uchar**) &max_system_variables.new_mode,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef NOT_YET
-  {"no-mix-table-types", OPT_NO_MIX_TYPE, "Don't allow commands with uses two different table types.",
+  {"no-mix-table-types", OPT_NO_MIX_TYPE, 
+   "Don't allow commands that use two different table types.",
    (uchar**) &opt_no_mix_types, (uchar**) &opt_no_mix_types, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
 #endif
@@ -6353,10 +6362,12 @@ master-ssl",
    (uchar**) &max_system_variables.old_passwords, 0, GET_BOOL, NO_ARG,
    0, 0, 0, 0, 0, 0},
   {"one-thread", OPT_ONE_THREAD,
-   "(deprecated): Only use one thread (for debugging under Linux). Use thread-handling=no-threads instead",
+   "(Deprecated): Only use one thread (for debugging under Linux). Use "
+   "thread-handling=no-threads instead.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"old-style-user-limits", OPT_OLD_STYLE_USER_LIMITS,
-   "Enable old-style user limits (before 5.0.3 user resources were counted per each user+host vs. per account)",
+   "Enable old-style user limits (before 5.0.3, user resources were counted "
+   "per each user+host vs. per account).",
    (uchar**) &opt_old_style_user_limits, (uchar**) &opt_old_style_user_limits,
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"pid-file", OPT_PID_FILE, "Pid file used by safe_mysqld.",
@@ -6372,10 +6383,10 @@ master-ssl",
    (uchar**) &mysqld_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
    "Maximum time in seconds to wait for the port to become free. "
-   "(Default: no wait)", (uchar**) &mysqld_port_timeout,
+   "(Default: No wait).", (uchar**) &mysqld_port_timeout,
    (uchar**) &mysqld_port_timeout, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
-  {"profiling_history_size", OPT_PROFILING, "Limit of query profiling memory",
+  {"profiling_history_size", OPT_PROFILING, "Limit of query profiling memory.",
    (uchar**) &global_system_variables.profiling_history_size,
    (uchar**) &max_system_variables.profiling_history_size,
    0, GET_ULONG, REQUIRED_ARG, 15, 0, 100, 0, 0, 0},
@@ -6445,7 +6456,7 @@ Can't be set to 1 if --log-slave-updates
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifndef TO_BE_DELETED
   {"safe-show-database", OPT_SAFE_SHOW_DB,
-   "Deprecated option; use GRANT SHOW DATABASES instead...",
+   "Deprecated option; use GRANT SHOW DATABASES instead.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"safe-user-create", OPT_SAFE_USER_CREATE,
@@ -6459,7 +6470,7 @@ Can't be set to 1 if --log-slave-updates
    (uchar**) &opt_secure_auth, (uchar**) &opt_secure_auth, 0, GET_BOOL, NO_ARG,
    my_bool(0), 0, 0, 0, 0, 0},
   {"secure-file-priv", OPT_SECURE_FILE_PRIV,
-   "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory",
+   "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory.",
    (uchar**) &opt_secure_file_priv, (uchar**) &opt_secure_file_priv, 0,
    GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"server-id",	OPT_SERVER_ID,
@@ -6467,7 +6478,8 @@ Can't be set to 1 if --log-slave-updates
    (uchar**) &server_id, (uchar**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, UINT_MAX32,
    0, 0, 0},
   {"set-variable", 'O',
-   "Change the value of a variable. Please note that this option is deprecated;you can set variables directly with --variable-name=value.",
+   "Change the value of a variable. Please note that this option is deprecated; "
+   "you can set variables directly with --variable-name=value.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #ifdef HAVE_SMEM
   {"shared-memory", OPT_ENABLE_SHARED_MEMORY,
@@ -6480,12 +6492,12 @@ Can't be set to 1 if --log-slave-updates
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"show-slave-auth-info", OPT_SHOW_SLAVE_AUTH_INFO,
-   "Show user and password in SHOW SLAVE HOSTS on this master",
+   "Show user and password in SHOW SLAVE HOSTS on this master.",
    (uchar**) &opt_show_slave_auth_info, (uchar**) &opt_show_slave_auth_info, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifndef DISABLE_GRANT_OPTIONS
   {"skip-grant-tables", OPT_SKIP_GRANT,
-   "Start without grant tables. This gives all users FULL ACCESS to all tables!",
+   "Start without grant tables. This gives all users FULL ACCESS to all tables.",
    (uchar**) &opt_noacl, (uchar**) &opt_noacl, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
    0},
 #endif
@@ -6500,7 +6512,7 @@ Can't be set to 1 if --log-slave-updates
   {"skip-networking", OPT_SKIP_NETWORKING,
    "Don't allow connection with TCP/IP.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0,
    0, 0, 0},
-  {"skip-new", OPT_SKIP_NEW, "Don't use new, possible wrong routines.",
+  {"skip-new", OPT_SKIP_NEW, "Don't use new, possibly wrong routines.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 #ifndef DBUG_OFF
 #ifdef SAFEMALLOC
@@ -6518,7 +6530,7 @@ Can't be set to 1 if --log-slave-updates
   {"skip-stack-trace", OPT_SKIP_STACK_TRACE,
    "Don't print a stack trace on failure.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
    0, 0, 0, 0},
-  {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Deprecated option.  Use --skip-symbolic-links instead.",
+  {"skip-symlink", OPT_SKIP_SYMLINKS, "Don't allow symlinking of tables. Deprecated option. Use --skip-symbolic-links instead.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"skip-thread-priority", OPT_SKIP_PRIOR,
    "Don't give threads different priorities. Deprecated option.", 0, 0, 0, GET_NO_ARG, NO_ARG,
@@ -6533,11 +6545,11 @@ replicating a LOAD DATA INFILE command."
    "Tells the slave thread to continue replication when a query event returns an error from the provided list.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"slave-exec-mode", OPT_SLAVE_EXEC_MODE,
-   "Modes for how replication events should be executed.  Legal values are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, replication will not stop for operations that are idempotent. In STRICT mode, replication will stop on any unexpected difference between the master and the slave.",
+   "Modes for how replication events should be executed. Legal values are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, replication will not stop for operations that are idempotent. In STRICT mode, replication will stop on any unexpected difference between the master and the slave.",
    (uchar**) &slave_exec_mode_str, (uchar**) &slave_exec_mode_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 #endif
   {"slow-query-log", OPT_SLOW_LOG,
-   "Enable|disable slow query log", (uchar**) &opt_slow_log,
+   "Enable/disable slow query log.", (uchar**) &opt_slow_log,
    (uchar**) &opt_slow_log, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"socket", OPT_SOCKET, "Socket file to use for connection.",
    (uchar**) &mysqld_unix_port, (uchar**) &mysqld_unix_port, 0, GET_STR,
@@ -6599,7 +6611,7 @@ log and this option does nothing anymore
    0, 0, 0, 0, 0},
 
   {"timed_mutexes", OPT_TIMED_MUTEXES,
-   "Specify whether to time mutexes (only InnoDB mutexes are currently supported)",
+   "Specify whether to time mutexes (only InnoDB mutexes are currently supported).",
    (uchar**) &timed_mutexes, (uchar**) &timed_mutexes, 0, GET_BOOL, NO_ARG, 0, 
     0, 0, 0, 0, 0},
   {"tmpdir", 't',
@@ -6620,7 +6632,7 @@ log and this option does nothing anymore
    IF_PURIFY(0,1), 0, 0, 0, 0, 0},
   {"user", 'u', "Run mysqld daemon as user.", 0, 0, 0, GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0},
-  {"verbose", 'v', "Used with --help option for detailed help",
+  {"verbose", 'v', "Used with --help option for detailed help.",
    (uchar**) &opt_verbose, (uchar**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
@@ -6638,7 +6650,7 @@ log and this option does nothing anymore
    (uchar**) &binlog_cache_size, (uchar**) &binlog_cache_size, 0, GET_ULONG,
    REQUIRED_ARG, 32*1024L, IO_SIZE, ULONG_MAX, 0, IO_SIZE, 0},
   {"bulk_insert_buffer_size", OPT_BULK_INSERT_BUFFER_SIZE,
-   "Size of tree cache used in bulk insert optimisation. Note that this is a limit per thread!",
+   "Size of tree cache used in bulk insert optimization. Note that this is a limit per thread.",
    (uchar**) &global_system_variables.bulk_insert_buff_size,
    (uchar**) &max_system_variables.bulk_insert_buff_size,
    0, GET_ULONG, REQUIRED_ARG, 8192*1024, 0, ULONG_MAX, 0, 1, 0},
@@ -6647,7 +6659,7 @@ log and this option does nothing anymore
     (uchar**) &connect_timeout, (uchar**) &connect_timeout,
    0, GET_ULONG, REQUIRED_ARG, CONNECT_TIMEOUT, 2, LONG_TIMEOUT, 0, 1, 0 },
   { "date_format", OPT_DATE_FORMAT,
-    "The DATE format (For future).",
+    "The DATE format (for future).",
     (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE],
     (uchar**) &opt_date_time_formats[MYSQL_TIMESTAMP_DATE],
     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -6689,7 +6701,7 @@ log and this option does nothing anymore
     (uchar**) &flush_time, (uchar**) &flush_time, 0, GET_ULONG, REQUIRED_ARG,
     FLUSH_TIME, 0, LONG_TIMEOUT, 0, 1, 0},
   { "ft_boolean_syntax", OPT_FT_BOOLEAN_SYNTAX,
-    "List of operators for MATCH ... AGAINST ( ... IN BOOLEAN MODE)",
+    "List of operators for MATCH ... AGAINST ( ... IN BOOLEAN MODE).",
     0, 0, 0, GET_STR,
     REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   { "ft_max_word_len", OPT_FT_MAX_WORD_LEN,
@@ -6701,7 +6713,7 @@ log and this option does nothing anymore
     (uchar**) &ft_min_word_len, (uchar**) &ft_min_word_len, 0, GET_ULONG,
     REQUIRED_ARG, 4, 1, HA_FT_MAXCHARLEN, 0, 1, 0},
   { "ft_query_expansion_limit", OPT_FT_QUERY_EXPANSION_LIMIT,
-    "Number of best matches to use for query expansion",
+    "Number of best matches to use for query expansion.",
     (uchar**) &ft_query_expansion_limit, (uchar**) &ft_query_expansion_limit, 0, GET_ULONG,
     REQUIRED_ARG, 20, 0, 1000, 0, 1, 0},
   { "ft_stopword_file", OPT_FT_STOPWORD_FILE,
@@ -6709,7 +6721,7 @@ log and this option does nothing anymore
     (uchar**) &ft_stopword_file, (uchar**) &ft_stopword_file, 0, GET_STR,
     REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   { "group_concat_max_len", OPT_GROUP_CONCAT_MAX_LEN,
-    "The maximum length of the result of function  group_concat.",
+    "The maximum length of the result of function group_concat.",
     (uchar**) &global_system_variables.group_concat_max_len,
     (uchar**) &max_system_variables.group_concat_max_len, 0, GET_ULONG,
     REQUIRED_ARG, 1024, 4, ULONG_MAX, 0, 1, 0},
@@ -6737,30 +6749,36 @@ log and this option does nothing anymore
    REQUIRED_ARG, KEY_CACHE_SIZE, MALLOC_OVERHEAD, SIZE_T_MAX, MALLOC_OVERHEAD,
    IO_SIZE, 0},
   {"key_cache_age_threshold", OPT_KEY_CACHE_AGE_THRESHOLD,
-   "This characterizes the number of hits a hot block has to be untouched until it is considered aged enough to be downgraded to a warm block. This specifies the percentage ratio of that number of hits to the total number of blocks in key cache",
+   "This characterizes the number of hits a hot block has to be untouched "
+   "until it is considered aged enough to be downgraded to a warm block. "
+   "This specifies the percentage ratio of that number of hits to the total "
+   "number of blocks in key cache.",
    (uchar**) &dflt_key_cache_var.param_age_threshold,
    (uchar**) 0,
    0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG, 
    300, 100, ULONG_MAX, 0, 100, 0},
   {"key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,
-   "The default size of key cache blocks",
+   "The default size of key cache blocks.",
    (uchar**) &dflt_key_cache_var.param_block_size,
    (uchar**) 0,
    0, (GET_ULONG | GET_ASK_ADDR), REQUIRED_ARG,
    KEY_CACHE_BLOCK_SIZE, 512, 1024 * 16, 0, 512, 0},
   {"key_cache_division_limit", OPT_KEY_CACHE_DIVISION_LIMIT,
-   "The minimum percentage of warm blocks in key cache",
+   "The minimum percentage of warm blocks in key cache.",
    (uchar**) &dflt_key_cache_var.param_division_limit,
    (uchar**) 0,
    0, (GET_ULONG | GET_ASK_ADDR) , REQUIRED_ARG, 100,
    1, 100, 0, 1, 0},
   {"long_query_time", OPT_LONG_QUERY_TIME,
-   "Log all queries that have taken more than long_query_time seconds to execute to file. "
-   "The argument will be treated as a decimal value with microsecond precission.",
+   "Log all queries that have taken more than long_query_time seconds to "
+   "execute. The argument will be treated as a decimal value with "
+   "microsecond precision.",
    (uchar**) &long_query_time, (uchar**) &long_query_time, 0, GET_DOUBLE,
    REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0},
   {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
-   "If set to 1 table names are stored in lowercase on disk and table names will be case-insensitive.  Should be set to 2 if you are using a case insensitive file system",
+   "If set to 1, table names are stored in lowercase on disk and table names "
+   "will be case-insensitive.  Should be set to 2 if you are using a case-"
+   "insensitive file system.",
    (uchar**) &lower_case_table_names,
    (uchar**) &lower_case_table_names, 0, GET_UINT, OPT_ARG,
 #ifdef FN_NO_CASE_SENCE
@@ -6770,7 +6788,7 @@ log and this option does nothing anymore
 #endif
    , 0, 2, 0, 1, 0},
   {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
-   "Max packetlength to send/receive from to server.",
+   "The maximum packet length to send to or receive from server.",
    (uchar**) &global_system_variables.max_allowed_packet,
    (uchar**) &max_system_variables.max_allowed_packet, 0, GET_ULONG,
    REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
@@ -6829,7 +6847,7 @@ The minimum value for this variable is 4
    (uchar**) &max_relay_log_size, (uchar**) &max_relay_log_size, 0, GET_ULONG,
    REQUIRED_ARG, 0L, 0L, 1024*1024L*1024L, 0, IO_SIZE, 0},
   { "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
-    "Limit assumed max number of seeks when looking up rows based on a key",
+    "Limit assumed max number of seeks when looking up rows based on a key.",
     (uchar**) &global_system_variables.max_seeks_for_key,
     (uchar**) &max_system_variables.max_seeks_for_key, 0, GET_ULONG,
     REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 },
@@ -6905,7 +6923,7 @@ The minimum value for this variable is 4
    (uchar**) &max_system_variables.myisam_sort_buff_size, 0,
    GET_ULONG, REQUIRED_ARG, 8192*1024, 4, ~0L, 0, 1, 0},
   {"myisam_use_mmap", OPT_MYISAM_USE_MMAP,
-   "Use memory mapping for reading and writing MyISAM tables",
+   "Use memory mapping for reading and writing MyISAM tables.",
    (uchar**) &opt_myisam_use_mmap,
    (uchar**) &opt_myisam_use_mmap, 0, GET_BOOL, NO_ARG, 0, 
     0, 0, 0, 0, 0},
@@ -6931,7 +6949,8 @@ The minimum value for this variable is 4
    (uchar**) &max_system_variables.net_retry_count,0,
    GET_ULONG, REQUIRED_ARG, MYSQLD_NET_RETRY_COUNT, 1, ULONG_MAX, 0, 1, 0},
   {"net_write_timeout", OPT_NET_WRITE_TIMEOUT,
-   "Number of seconds to wait for a block to be written to a connection  before aborting the write.",
+   "Number of seconds to wait for a block to be written to a connection before "
+   "aborting the write.",
    (uchar**) &global_system_variables.net_write_timeout,
    (uchar**) &max_system_variables.net_write_timeout, 0, GET_ULONG,
    REQUIRED_ARG, NET_WRITE_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
@@ -6971,12 +6990,12 @@ The minimum value for this variable is 4
    (uchar**) &opt_plugin_load, (uchar**) &opt_plugin_load, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
-   "The size of the buffer that is allocated when preloading indexes",
+   "The size of the buffer that is allocated when preloading indexes.",
    (uchar**) &global_system_variables.preload_buff_size,
    (uchar**) &max_system_variables.preload_buff_size, 0, GET_ULONG,
    REQUIRED_ARG, 32*1024L, 1024, 1024*1024*1024L, 0, 1, 0},
   {"query_alloc_block_size", OPT_QUERY_ALLOC_BLOCK_SIZE,
-   "Allocation block size for query parsing and execution",
+   "Allocation block size for query parsing and execution.",
    (uchar**) &global_system_variables.query_alloc_block_size,
    (uchar**) &max_system_variables.query_alloc_block_size, 0, GET_ULONG,
    REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
@@ -6986,7 +7005,8 @@ The minimum value for this variable is 4
    (uchar**) &query_cache_limit, (uchar**) &query_cache_limit, 0, GET_ULONG,
    REQUIRED_ARG, 1024*1024L, 0, ULONG_MAX, 0, 1, 0},
   {"query_cache_min_res_unit", OPT_QUERY_CACHE_MIN_RES_UNIT,
-   "minimal size of unit in wich space for results is allocated (last unit will be trimed after writing all result data.",
+   "Minimal size of unit in which space for results is allocated (last unit "
+   "will be trimmed after writing all result data).",
    (uchar**) &query_cache_min_res_unit, (uchar**) &query_cache_min_res_unit,
    0, GET_ULONG, REQUIRED_ARG, QUERY_CACHE_MIN_RESULT_DATA_SIZE,
    0, ULONG_MAX, 0, 1, 0},
@@ -7002,19 +7022,19 @@ The minimum value for this variable is 4
    (uchar**) &max_system_variables.query_cache_type,
    0, GET_ULONG, REQUIRED_ARG, 1, 0, 2, 0, 1, 0},
   {"query_cache_wlock_invalidate", OPT_QUERY_CACHE_WLOCK_INVALIDATE,
-   "Invalidate queries in query cache on LOCK for write",
+   "Invalidate queries in query cache on LOCK for write.",
    (uchar**) &global_system_variables.query_cache_wlock_invalidate,
    (uchar**) &max_system_variables.query_cache_wlock_invalidate,
    0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
 #endif /*HAVE_QUERY_CACHE*/
   {"query_prealloc_size", OPT_QUERY_PREALLOC_SIZE,
-   "Persistent buffer for query parsing and execution",
+   "Persistent buffer for query parsing and execution.",
    (uchar**) &global_system_variables.query_prealloc_size,
    (uchar**) &max_system_variables.query_prealloc_size, 0, GET_ULONG,
    REQUIRED_ARG, QUERY_ALLOC_PREALLOC_SIZE, QUERY_ALLOC_PREALLOC_SIZE,
    ULONG_MAX, 0, 1024, 0},
   {"range_alloc_block_size", OPT_RANGE_ALLOC_BLOCK_SIZE,
-   "Allocation block size for storing ranges during optimization",
+   "Allocation block size for storing ranges during optimization.",
    (uchar**) &global_system_variables.range_alloc_block_size,
    (uchar**) &max_system_variables.range_alloc_block_size, 0, GET_ULONG,
    REQUIRED_ARG, RANGE_ALLOC_BLOCK_SIZE, RANGE_ALLOC_BLOCK_SIZE, ULONG_MAX,
@@ -7026,12 +7046,15 @@ The minimum value for this variable is 4
    128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, INT_MAX32, MALLOC_OVERHEAD, IO_SIZE,
    0},
   {"read_only", OPT_READONLY,
-   "Make all non-temporary tables read-only, with the exception for replication (slave) threads and users with the SUPER privilege",
+   "Make all non-temporary tables read-only, with the exception of replication "
+   "(slave) threads and users with the SUPER privilege.",
    (uchar**) &opt_readonly,
    (uchar**) &opt_readonly,
    0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
   {"read_rnd_buffer_size", OPT_RECORD_RND_BUFFER,
-   "When reading rows in sorted order after a sort, the rows are read through this buffer to avoid a disk seeks. If not set, then it's set to the value of record_buffer.",
+   "When reading rows in sorted order after a sort, the rows are read through "
+   "this buffer to avoid disk seeks. If not set, then it's set to the value of "
+   "record_buffer.",
    (uchar**) &global_system_variables.read_rnd_buff_size,
    (uchar**) &max_system_variables.read_rnd_buff_size, 0,
    GET_ULONG, REQUIRED_ARG, 256*1024L, IO_SIZE*2+MALLOC_OVERHEAD,
@@ -7118,7 +7141,8 @@ The minimum value for this variable is 4
    DEFAULT_CONCURRENCY, 1, 512, 0, 1, 0},
 #if HAVE_POOL_OF_THREADS == 1
   {"thread_pool_size", OPT_THREAD_CACHE_SIZE,
-   "How many threads we should create to handle query requests in case of 'thread_handling=pool-of-threads'",
+   "How many threads we should create to handle query requests in case of "
+   "'thread_handling=pool-of-threads'.",
    (uchar**) &thread_pool_size, (uchar**) &thread_pool_size, 0, GET_ULONG,
    REQUIRED_ARG, 20, 1, 16384, 0, 1, 0},
 #endif
@@ -7138,18 +7162,18 @@ The minimum value for this variable is 4
    (uchar**) &max_system_variables.tmp_table_size, 0, GET_ULL,
    REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
   {"transaction_alloc_block_size", OPT_TRANS_ALLOC_BLOCK_SIZE,
-   "Allocation block size for transactions to be stored in binary log",
+   "Allocation block size for transactions to be stored in binary log.",
    (uchar**) &global_system_variables.trans_alloc_block_size,
    (uchar**) &max_system_variables.trans_alloc_block_size, 0, GET_ULONG,
    REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
   {"transaction_prealloc_size", OPT_TRANS_PREALLOC_SIZE,
-   "Persistent buffer for transactions to be stored in binary log",
+   "Persistent buffer for transactions to be stored in binary log.",
    (uchar**) &global_system_variables.trans_prealloc_size,
    (uchar**) &max_system_variables.trans_prealloc_size, 0, GET_ULONG,
    REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
   {"thread_handling", OPT_THREAD_HANDLING,
-   "Define threads usage for handling queries:  "
-   "one-thread-per-connection or no-threads", 0, 0,
+   "Define threads usage for handling queries: "
+   "one-thread-per-connection or no-threads.", 0, 0,
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"updatable_views_with_limit", OPT_UPDATABLE_VIEWS_WITH_LIMIT,
    "1 = YES = Don't issue an error message (warning only) if a VIEW without presence of a key of the underlying table is used in queries with a LIMIT clause for updating. 0 = NO = Prohibit update of a VIEW, which does not contain a key of the underlying table and the query uses a LIMIT clause (usually get from GUI tools).",
@@ -7163,7 +7187,11 @@ The minimum value for this variable is 4
    REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, IF_WIN(INT_MAX32/1000, LONG_TIMEOUT),
    0, 1, 0},
   {"binlog-direct-non-transactional-updates", OPT_BINLOG_DIRECT_NON_TRANS_UPDATE,
-   "Causes updates to non-transactional engines using statement format to be written directly to binary log. Before using this option make sure that there are no dependencies between transactional and non-transactional tables such as in the statement INSERT INTO t_myisam SELECT * FROM t_innodb; otherwise, slaves may diverge from the master.",
+   "Causes updates to non-transactional engines using statement format to be "
+   "written directly to binary log. Before using this option, make sure that "
+   "there are no dependencies between transactional and non-transactional "
+   "tables such as in the statement INSERT INTO t_myisam SELECT * FROM "
+   "t_innodb; otherwise, slaves may diverge from the master.",
    (uchar**) &global_system_variables.binlog_direct_non_trans_update, (uchar**) &max_system_variables.binlog_direct_non_trans_update, 0, GET_BOOL, NO_ARG, 0,
     0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
@@ -7679,27 +7707,27 @@ static void usage(void)
     default_collation_name= (char*) default_charset_info->name;
   print_version();
   puts("\
-Copyright (C) 2000-2008 MySQL AB, by Monty and others\n\
+Copyright (C) 2000-2008 MySQL AB, by Monty and others.\n\
 Copyright (C) 2008 Sun Microsystems, Inc.\n\
 This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
 and you are welcome to modify and redistribute it under the GPL license\n\n\
-Starts the MySQL database server\n");
+Starts the MySQL database server.\n");
 
   printf("Usage: %s [OPTIONS]\n", my_progname);
   if (!opt_verbose)
-    puts("\nFor more help options (several pages), use mysqld --verbose --help");
+    puts("\nFor more help options (several pages), use mysqld --verbose --help.");
   else
   {
 #ifdef __WIN__
   puts("NT and Win32 specific options:\n\
-  --install                     Install the default service (NT)\n\
-  --install-manual              Install the default service started manually (NT)\n\
-  --install service_name        Install an optional service (NT)\n\
-  --install-manual service_name Install an optional service started manually (NT)\n\
-  --remove                      Remove the default service from the service list (NT)\n\
-  --remove service_name         Remove the service_name from the service list (NT)\n\
-  --enable-named-pipe           Only to be used for the	default server (NT)\n\
-  --standalone                  Dummy option to start as a standalone server (NT)\
+  --install                     Install the default service (NT).\n\
+  --install-manual              Install the default service started manually (NT).\n\
+  --install service_name        Install an optional service (NT).\n\
+  --install-manual service_name Install an optional service started manually (NT).\n\
+  --remove                      Remove the default service from the service list (NT).\n\
+  --remove service_name         Remove the service_name from the service list (NT).\n\
+  --enable-named-pipe           Only to be used for the default server (NT).\n\
+  --standalone                  Dummy option to start as a standalone server (NT).\
 ");
   puts("");
 #endif

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-03-12 06:06:23 +0000
+++ b/sql/opt_range.cc	2010-06-09 14:07:08 +0000
@@ -1174,11 +1174,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT(
     if (file) 
     {
       range_end();
-      if (head->key_read)
-      {
-        head->key_read= 0;
-        file->extra(HA_EXTRA_NO_KEYREAD);
-      }
+      head->set_keyread(FALSE);
       if (free_file)
       {
         DBUG_PRINT("info", ("Freeing separate handler 0x%lx (free: %d)", (long) file,
@@ -1380,10 +1376,7 @@ end:
   head->file= file;
   /* We don't have to set 'head->keyread' here as the 'file' is unique */
   if (!head->no_keyread)
-  {
-    head->key_read= 1;
     head->mark_columns_used_by_index(index);
-  }
   head->prepare_for_position();
   head->file= org_file;
   bitmap_copy(&column_bitmap, head->read_set);
@@ -8168,7 +8161,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
   DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge");
 
   /* We're going to just read rowids. */
-  file->extra(HA_EXTRA_KEYREAD);
+  head->set_keyread(TRUE);
   head->prepare_for_position();
 
   cur_quick_it.rewind();
@@ -8244,7 +8237,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
   delete unique;
   doing_pk_scan= FALSE;
   /* index_merge currently doesn't support "using index" at all */
-  file->extra(HA_EXTRA_NO_KEYREAD);
+  head->set_keyread(FALSE);
   init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE);
   DBUG_RETURN(result);
 }
@@ -10631,7 +10624,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::reset(vo
   int result;
   DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::reset");
 
-  file->extra(HA_EXTRA_KEYREAD); /* We need only the key attributes */
+  head->set_keyread(TRUE); /* We need only the key attributes */
   if ((result= file->ha_index_init(index,1)))
     DBUG_RETURN(result);
   if (quick_prefix_select && quick_prefix_select->reset())

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	2009-12-17 10:14:52 +0000
+++ b/sql/opt_sum.cc	2010-06-09 14:07:08 +0000
@@ -329,11 +329,7 @@ int opt_sum_query(TABLE_LIST *tables, Li
 	  if (!error && reckey_in_range(0, &ref, item_field->field, 
 			                conds, range_fl, prefix_len))
 	    error= HA_ERR_KEY_NOT_FOUND;
-          if (table->key_read)
-          {
-            table->key_read= 0;
-            table->file->extra(HA_EXTRA_NO_KEYREAD);
-          }
+          table->set_keyread(FALSE);
           table->file->ha_index_end();
           if (error)
 	  {
@@ -416,11 +412,7 @@ int opt_sum_query(TABLE_LIST *tables, Li
 	  if (!error && reckey_in_range(1, &ref, item_field->field,
 			                conds, range_fl, prefix_len))
 	    error= HA_ERR_KEY_NOT_FOUND;
-          if (table->key_read)
-          {
-            table->key_read=0;
-            table->file->extra(HA_EXTRA_NO_KEYREAD);
-          }
+          table->set_keyread(FALSE);
           table->file->ha_index_end();
           if (error)
           {
@@ -879,10 +871,7 @@ static bool find_key_for_maxmin(bool max
             converted (for example to upper case)
           */
           if (field->part_of_key.is_set(idx))
-          {
-            table->key_read= 1;
-            table->file->extra(HA_EXTRA_KEYREAD);
-          }
+            table->set_keyread(TRUE);
           return 1;
         }
       }

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2010-03-12 06:06:23 +0000
+++ b/sql/share/errmsg.txt	2010-06-09 14:07:08 +0000
@@ -5027,7 +5027,7 @@ ER_UNKNOWN_STORAGE_ENGINE 42000 
 # When using this error code, use ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER)
 # for the message string.  See, for example, code in mysql_priv.h.
 ER_WARN_DEPRECATED_SYNTAX  
-        eng "'%s' is deprecated; use '%s' instead"
+        eng "'%s' is deprecated and will be removed in a future release. Please use %s instead"
         ger "'%s' ist veraltet. Bitte benutzen Sie '%s'"
         por "'%s' �esatualizado. Use '%s' em seu lugar"
         spa "'%s' est�esaprobado, use '%s' en su lugar"

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sp.cc	2010-06-09 14:07:08 +0000
@@ -1901,6 +1901,10 @@ sp_cache_routines_and_add_tables_aux(THD
         ret= SP_OK;
         break;
       default:
+        /* Query might have been killed, don't set error. */
+        if (thd->killed)
+          break;
+
         /*
           Any error when loading an existing routine is either some problem
           with the mysql.proc table, or a parse error because the contents

=== modified file 'sql/sp_cache.cc'
--- a/sql/sp_cache.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sp_cache.cc	2010-06-09 14:07:08 +0000
@@ -178,8 +178,9 @@ sp_head *sp_cache_lookup(sp_cache **cp, 
     sp_cache_invalidate()
       
   NOTE
-    This is called when a VIEW definition is modifed. We can't destroy sp_head
-    objects here as one may modify VIEW definitions from prelocking-free SPs.
+    This is called when a VIEW definition is created or modified (and in some
+    other contexts). We can't destroy sp_head objects here as one may modify
+    VIEW definitions from prelocking-free SPs.
 */
 
 void sp_cache_invalidate()

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sp_head.cc	2010-06-09 14:07:08 +0000
@@ -1851,6 +1851,8 @@ sp_head::execute_procedure(THD *thd, Lis
 {
   bool err_status= FALSE;
   uint params = m_pcont->context_var_count();
+  /* Query start time may be reset in a multi-stmt SP; keep this for later. */
+  ulonglong utime_before_sp_exec= thd->utime_after_lock;
   sp_rcontext *save_spcont, *octx;
   sp_rcontext *nctx = NULL;
   bool save_enable_slow_log= false;
@@ -2043,6 +2045,7 @@ sp_head::execute_procedure(THD *thd, Lis
 
   delete nctx;
   thd->spcont= save_spcont;
+  thd->utime_after_lock= utime_before_sp_exec;
 
   DBUG_RETURN(err_status);
 }

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_base.cc	2010-06-09 14:07:08 +0000
@@ -2177,6 +2177,7 @@ void wait_for_condition(THD *thd, pthrea
   proc_info=thd->proc_info;
   thd_proc_info(thd, "Waiting for table");
   DBUG_ENTER("wait_for_condition");
+  DEBUG_SYNC(thd, "waiting_for_table");
   if (!thd->killed)
     (void) pthread_cond_wait(cond, mutex);
 
@@ -4599,7 +4600,20 @@ int open_tables(THD *thd, TABLE_LIST **s
         safe_to_ignore_table= prelock_handler.safely_trapped_errors();
       }
       else
+      {
         tables->table= open_table(thd, tables, &new_frm_mem, &refresh, flags);
+
+        /*
+          Skip further processing if there has been a fatal error while
+          trying to open a table. For example, this might happen due to
+          stack shortage, unknown definer in views, etc.
+        */
+        if (!tables->table && thd->is_error())
+        {
+          result= -1;
+          goto err;
+        }
+      }
     }
     else
       DBUG_PRINT("tcache", ("referenced table: '%s'.'%s' 0x%lx",

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_class.cc	2010-06-09 14:07:08 +0000
@@ -728,25 +728,24 @@ void THD::push_internal_handler(Internal
 bool THD::handle_error(uint sql_errno, const char *message,
                        MYSQL_ERROR::enum_warning_level level)
 {
-  if (!m_internal_handler)
-    return FALSE;
-
   for (Internal_error_handler *error_handler= m_internal_handler;
        error_handler;
-       error_handler= m_internal_handler->m_prev_internal_handler)
+       error_handler= error_handler->m_prev_internal_handler)
   {
     if (error_handler->handle_error(sql_errno, message, level, this))
-    return TRUE;
+      return TRUE;
   }
 
   return FALSE;
 }
 
 
-void THD::pop_internal_handler()
+Internal_error_handler *THD::pop_internal_handler()
 {
   DBUG_ASSERT(m_internal_handler != NULL);
+  Internal_error_handler *popped_handler= m_internal_handler;
   m_internal_handler= m_internal_handler->m_prev_internal_handler;
+  return popped_handler;
 }
 
 extern "C"

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-03-12 06:06:23 +0000
+++ b/sql/sql_class.h	2010-06-09 14:07:08 +0000
@@ -2316,7 +2316,7 @@ public:
   /**
     Remove the error handler last pushed.
   */
-  void pop_internal_handler();
+  Internal_error_handler *pop_internal_handler();
 
   /** Overloaded to guard query/query_length fields */
   virtual void set_statement(Statement *stmt);

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2009-12-17 10:14:52 +0000
+++ b/sql/sql_lex.cc	2010-06-09 14:07:08 +0000
@@ -1595,6 +1595,7 @@ void st_select_lex::init_query()
   having= prep_having= where= prep_where= 0;
   olap= UNSPECIFIED_OLAP_TYPE;
   having_fix_field= 0;
+  group_fix_field= 0;
   context.select_lex= this;
   context.init();
   /*

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2010-03-12 06:06:23 +0000
+++ b/sql/sql_lex.h	2010-06-09 14:07:08 +0000
@@ -651,6 +651,8 @@ public:
   bool  braces;   	/* SELECT ... UNION (SELECT ... ) <- this braces */
   /* TRUE when having fix field called in processing of this SELECT */
   bool having_fix_field;
+  /* TRUE when GROUP BY fix field called in processing of this SELECT */
+  bool group_fix_field;
   /* List of references to fields referenced from inner selects */
   List<Item_outer_ref> inner_refs_list;
   /* Number of Item_sum-derived objects in this SELECT */

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_parse.cc	2010-06-09 14:07:08 +0000
@@ -1659,9 +1659,9 @@ void log_slow_statement(THD *thd)
 
   /*
     Do not log administrative statements unless the appropriate option is
-    set; do not log into slow log if reading from backup.
+    set.
   */
-  if (thd->enable_slow_log && !thd->user_time)
+  if (thd->enable_slow_log)
   {
     ulonglong end_utime_of_query= thd->current_utime();
     thd_proc_info(thd, "logging slow query");

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_repl.cc	2010-06-09 14:07:08 +0000
@@ -1641,7 +1641,7 @@ bool show_binlogs(THD* thd)
   if (!mysql_bin_log.is_open())
   {
     my_message(ER_NO_BINARY_LOGGING, ER(ER_NO_BINARY_LOGGING), MYF(0));
-    return 1;
+    DBUG_RETURN(TRUE);
   }
 
   field_list.push_back(new Item_empty_string("Log_name", 255));

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_select.cc	2010-06-09 14:07:08 +0000
@@ -290,6 +290,7 @@ bool handle_select(THD *thd, LEX *lex, s
     all_fields        List of all fields used in select
     select            Current select
     ref_pointer_array Array of references to Items used in current select
+    group_list        GROUP BY list (is NULL by default)
 
   DESCRIPTION
     The function serves 3 purposes - adds fields referenced from inner
@@ -308,6 +309,8 @@ bool handle_select(THD *thd, LEX *lex, s
       function is aggregated in the select where the outer field was
       resolved or in some more inner select then the Item_direct_ref
       class should be used.
+      Also it should be used if we are grouping by a subquery containing
+      the outer field.
     The resolution is done here and not at the fix_fields() stage as
     it can be done only after sum functions are fixed and pulled up to
     selects where they are have to be aggregated.
@@ -324,7 +327,7 @@ bool handle_select(THD *thd, LEX *lex, s
 
 bool
 fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
-                 Item **ref_pointer_array)
+                 Item **ref_pointer_array, ORDER *group_list)
 {
   Item_outer_ref *ref;
   bool res= FALSE;
@@ -374,6 +377,22 @@ fix_inner_refs(THD *thd, List<Item> &all
         }
       }
     }
+    else
+    {
+      /*
+        Check if GROUP BY item trees contain the outer ref:
+        in this case we have to use Item_direct_ref instead of Item_ref.
+      */
+      for (ORDER *group= group_list; group; group= group->next)
+      {
+        if ((*group->item)->walk(&Item::find_item_processor, TRUE,
+                                 (uchar *) ref))
+        {
+          direct_ref= TRUE;
+          break;
+        }
+      }
+    }
     new_ref= direct_ref ?
               new Item_direct_ref(ref->context, item_ref, ref->table_name,
                           ref->field_name, ref->alias_name_used) :
@@ -580,7 +599,8 @@ JOIN::prepare(Item ***rref_pointer_array
   }
 
   if (select_lex->inner_refs_list.elements &&
-      fix_inner_refs(thd, all_fields, select_lex, ref_pointer_array))
+      fix_inner_refs(thd, all_fields, select_lex, ref_pointer_array,
+                     group_list))
     DBUG_RETURN(-1);
 
   if (group_list)
@@ -2316,7 +2336,13 @@ JOIN::destroy()
 	tab->cleanup();
     }
     tmp_join->tmp_join= 0;
-    tmp_table_param.copy_field= 0;
+    /*
+      We need to clean up tmp_table_param for reusable JOINs (having non-zero
+      and different from self tmp_join) because it's not being cleaned up
+      anywhere else (as we need to keep the join is reusable).
+    */
+    tmp_table_param.cleanup();
+    tmp_table_param.copy_field= tmp_join->tmp_table_param.copy_field= 0;
     DBUG_RETURN(tmp_join->destroy());
   }
   cond_equal= 0;
@@ -5841,6 +5867,12 @@ JOIN::make_simple_join(JOIN *parent, TAB
   const_table_map= 0;
   tmp_table_param.field_count= tmp_table_param.sum_func_count=
     tmp_table_param.func_count= 0;
+  /*
+    We need to destruct the copy_field (allocated in create_tmp_table())
+    before setting it to 0 if the join is not "reusable".
+  */
+  if (!tmp_join || tmp_join != this) 
+    tmp_table_param.cleanup(); 
   tmp_table_param.copy_field= tmp_table_param.copy_field_end=0;
   first_record= sort_and_group=0;
   send_records= (ha_rows) 0;
@@ -6610,10 +6642,7 @@ make_join_readinfo(JOIN *join, ulonglong
     case JT_CONST:				// Only happens with left join
       if (table->covering_keys.is_set(tab->ref.key) &&
 	  !table->no_keyread)
-      {
-	table->key_read=1;
-	table->file->extra(HA_EXTRA_KEYREAD);
-      }
+        table->set_keyread(TRUE);
       break;
     case JT_ALL:
       /*
@@ -6674,10 +6703,7 @@ make_join_readinfo(JOIN *join, ulonglong
 	  if (tab->select && tab->select->quick &&
               tab->select->quick->index != MAX_KEY && //not index_merge
 	      table->covering_keys.is_set(tab->select->quick->index))
-	  {
-	    table->key_read=1;
-	    table->file->extra(HA_EXTRA_KEYREAD);
-	  }
+            table->set_keyread(TRUE);
 	  else if (!table->covering_keys.is_clear_all() &&
 		   !(tab->select && tab->select->quick))
 	  {					// Only read index tree
@@ -6761,11 +6787,7 @@ void JOIN_TAB::cleanup()
   limit= 0;
   if (table)
   {
-    if (table->key_read)
-    {
-      table->key_read= 0;
-      table->file->extra(HA_EXTRA_NO_KEYREAD);
-    }
+    table->set_keyread(FALSE);
     table->file->ha_index_or_rnd_end();
     /*
       We need to reset this for next select
@@ -7009,9 +7031,11 @@ eq_ref_table(JOIN *join, ORDER *start_or
       }
       if (order)
       {
-	found++;
-	DBUG_ASSERT(!(order->used & map));
-	order->used|=map;
+        if (!(order->used & map))
+        {
+          found++;
+          order->used|= map;
+        }
 	continue;				// Used in ORDER BY
       }
       if (!only_eq_ref_tables(join,start_order, (*ref_item)->used_tables()))
@@ -8179,7 +8203,8 @@ static Item *eliminate_item_equal(COND *
   else
   {
     DBUG_ASSERT(cond->type() == Item::COND_ITEM);
-    ((Item_cond *) cond)->add_at_head(&eq_list);
+    if (eq_list.elements)
+      ((Item_cond *) cond)->add_at_head(&eq_list);
   }
 
   cond->quick_fix_field();
@@ -9803,7 +9828,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
   KEY_PART_INFO *key_part_info;
   Item **copy_func;
   MI_COLUMNDEF *recinfo;
-  uint total_uneven_bit_length= 0;
+  /*
+    total_uneven_bit_length is uneven bit length for visible fields
+    hidden_uneven_bit_length is uneven bit length for hidden fields
+  */
+  uint total_uneven_bit_length= 0, hidden_uneven_bit_length= 0;
   bool force_copy_fields= param->force_copy_fields;
   /* Treat sum functions as normal ones when loose index scan is used. */
   save_sum_fields|= param->precomputed_group_by;
@@ -10080,6 +10109,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
       */
       param->hidden_field_count= fieldnr;
       null_count= 0;
+      /*
+        On last hidden field we store uneven bit length in
+        hidden_uneven_bit_length and proceed calculation of
+        uneven bits for visible fields into
+        total_uneven_bit_length variable.
+      */
+      hidden_uneven_bit_length= total_uneven_bit_length;
+      total_uneven_bit_length= 0;
     }
   }
   DBUG_ASSERT(fieldnr == (uint) (reg_field - table->field));
@@ -10125,7 +10162,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
     else
       null_count++;
   }
-  hidden_null_pack_length=(hidden_null_count+7)/8;
+  hidden_null_pack_length= (hidden_null_count + 7 +
+                            hidden_uneven_bit_length) / 8;
   null_pack_length= (hidden_null_pack_length +
                      (null_count + total_uneven_bit_length + 7) / 8);
   reclength+=null_pack_length;
@@ -11512,21 +11550,45 @@ flush_cached_records(JOIN *join,JOIN_TAB
       return NESTED_LOOP_KILLED; // Aborted by user /* purecov: inspected */
     }
     SQL_SELECT *select=join_tab->select;
-    if (rc == NESTED_LOOP_OK &&
-        (!join_tab->cache.select || !join_tab->cache.select->skip_record()))
+    if (rc == NESTED_LOOP_OK)
     {
-      uint i;
-      reset_cache_read(&join_tab->cache);
-      for (i=(join_tab->cache.records- (skip_last ? 1 : 0)) ; i-- > 0 ;)
+      bool consider_record= !join_tab->cache.select || 
+        !join_tab->cache.select->skip_record();
+
+      /*
+        Check for error: skip_record() can execute code by calling
+        Item_subselect::val_*. We need to check for errors (if any)
+        after such call.
+      */
+      if (join->thd->is_error())
       {
-	read_cached_record(join_tab);
-	if (!select || !select->skip_record())
+        reset_cache_write(&join_tab->cache);
+        return NESTED_LOOP_ERROR;
+      }
+
+      if (consider_record)  
+      {
+        uint i;
+        reset_cache_read(&join_tab->cache);
+        for (i=(join_tab->cache.records- (skip_last ? 1 : 0)) ; i-- > 0 ;)
         {
-          rc= (join_tab->next_select)(join,join_tab+1,0);
-	  if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
+          read_cached_record(join_tab);
+          if (!select || !select->skip_record())
           {
-            reset_cache_write(&join_tab->cache);
-            return rc;
+            /*
+              Check for error: skip_record() can execute code by calling
+              Item_subselect::val_*. We need to check for errors (if any)
+              after such call.
+              */
+            if (join->thd->is_error())
+              rc= NESTED_LOOP_ERROR;
+            else
+              rc= (join_tab->next_select)(join,join_tab+1,0);
+            if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
+            {
+              reset_cache_write(&join_tab->cache);
+              return rc;
+            }
           }
         }
       }
@@ -11611,16 +11673,11 @@ join_read_const_table(JOIN_TAB *tab, POS
 	!table->no_keyread &&
         (int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY)
     {
-      table->key_read=1;
-      table->file->extra(HA_EXTRA_KEYREAD);
+      table->set_keyread(TRUE);
       tab->index= tab->ref.key;
     }
     error=join_read_const(tab);
-    if (table->key_read)
-    {
-      table->key_read=0;
-      table->file->extra(HA_EXTRA_NO_KEYREAD);
-    }
+    table->set_keyread(FALSE);
     if (error)
     {
       tab->info="unique row not found";
@@ -11975,12 +12032,8 @@ join_read_first(JOIN_TAB *tab)
 {
   int error;
   TABLE *table=tab->table;
-  if (!table->key_read && table->covering_keys.is_set(tab->index) &&
-      !table->no_keyread)
-  {
-    table->key_read=1;
-    table->file->extra(HA_EXTRA_KEYREAD);
-  }
+  if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
+    table->set_keyread(TRUE);
   tab->table->status=0;
   tab->read_record.read_record=join_read_next;
   tab->read_record.table=table;
@@ -12014,12 +12067,8 @@ join_read_last(JOIN_TAB *tab)
 {
   TABLE *table=tab->table;
   int error;
-  if (!table->key_read && table->covering_keys.is_set(tab->index) &&
-      !table->no_keyread)
-  {
-    table->key_read=1;
-    table->file->extra(HA_EXTRA_KEYREAD);
-  }
+  if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
+    table->set_keyread(TRUE);
   tab->table->status=0;
   tab->read_record.read_record=join_read_prev;
   tab->read_record.table=table;
@@ -12780,7 +12829,7 @@ static int test_if_order_by_key(ORDER *o
   key_part_end=key_part+table->key_info[idx].key_parts;
   key_part_map const_key_parts=table->const_key_parts[idx];
   int reverse=0;
-  my_bool on_primary_key= FALSE;
+  my_bool on_pk_suffix= FALSE;
   DBUG_ENTER("test_if_order_by_key");
 
   for (; order ; order=order->next, const_key_parts>>=1)
@@ -12802,11 +12851,12 @@ static int test_if_order_by_key(ORDER *o
         key as a suffix to the secondary keys. If it has continue to check
         the primary key as a suffix.
       */
-      if (!on_primary_key &&
+      if (!on_pk_suffix &&
           (table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
-          table->s->primary_key != MAX_KEY)
+          table->s->primary_key != MAX_KEY &&
+          table->s->primary_key != idx)
       {
-        on_primary_key= TRUE;
+        on_pk_suffix= TRUE;
         key_part= table->key_info[table->s->primary_key].key_part;
         key_part_end=key_part+table->key_info[table->s->primary_key].key_parts;
         const_key_parts=table->const_key_parts[table->s->primary_key];
@@ -12838,7 +12888,7 @@ static int test_if_order_by_key(ORDER *o
     reverse=flag;				// Remember if reverse
     key_part++;
   }
-  if (on_primary_key)
+  if (on_pk_suffix)
   {
     uint used_key_parts_secondary= table->key_info[idx].key_parts;
     uint used_key_parts_pk=
@@ -13260,12 +13310,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
     */
     if (select_limit >= table_records)
     {
-      /* 
-        filesort() and join cache are usually faster than reading in 
-        index order and not using join cache
-        */
-      if (tab->type == JT_ALL && tab->join->tables > tab->join->const_tables + 1)
-        DBUG_RETURN(0);
       keys= *table->file->keys_to_use_for_scanning();
       keys.merge(table->covering_keys);
 
@@ -13327,8 +13371,15 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
             select_limit= table_records;
           if (group)
           {
-            rec_per_key= used_key_parts ? keyinfo->rec_per_key[used_key_parts-1]
-                                        : 1;
+            /* 
+              Used_key_parts can be larger than keyinfo->key_parts
+              when using a secondary index clustered with a primary 
+              key (e.g. as in Innodb). 
+              See Bug #28591 for details.
+            */  
+            rec_per_key= used_key_parts &&
+                         used_key_parts <= keyinfo->key_parts ?
+                         keyinfo->rec_per_key[used_key_parts-1] : 1;
             set_if_bigger(rec_per_key, 1);
             /*
               With a grouping query each group containing on average
@@ -13408,6 +13459,19 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
 	}      
       }
     }
+
+    /*
+      filesort() and join cache are usually faster than reading in 
+      index order and not using join cache, except in case that chosen
+      index is clustered primary key.
+    */
+    if ((select_limit >= table_records) &&
+        (tab->type == JT_ALL &&
+         tab->join->tables > tab->join->const_tables + 1) &&
+         ((unsigned) best_key != table->s->primary_key ||
+          !table->file->primary_key_is_clustered()))
+      DBUG_RETURN(0);
+
     if (best_key >= 0)
     {
       bool quick_created= FALSE;
@@ -13429,11 +13493,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
            If ref_key used index tree reading only ('Using index' in EXPLAIN),
            and best_key doesn't, then revert the decision.
         */
-        if (!table->covering_keys.is_set(best_key) && table->key_read)
-        {
-          table->key_read= 0;
-          table->file->extra(HA_EXTRA_NO_KEYREAD);          
-        }        
+        if (!table->covering_keys.is_set(best_key))
+          table->set_keyread(FALSE);
         if (!quick_created)
 	{
           tab->index= best_key;
@@ -13446,10 +13507,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
             select->quick= 0;
           }
           if (table->covering_keys.is_set(best_key))
-          {
-            table->key_read=1;
-            table->file->extra(HA_EXTRA_KEYREAD);
-          }
+            table->set_keyread(TRUE);
           table->file->ha_index_or_rnd_end();
           if (join->select_options & SELECT_DESCRIBE)
           {
@@ -13623,11 +13681,8 @@ create_sort_index(THD *thd, JOIN *join, 
         We can only use 'Only index' if quick key is same as ref_key
         and in index_merge 'Only index' cannot be used
       */
-      if (table->key_read && ((uint) tab->ref.key != select->quick->index))
-      {
-	table->key_read=0;
-	table->file->extra(HA_EXTRA_NO_KEYREAD);
-      }
+      if (((uint) tab->ref.key != select->quick->index))
+        table->set_keyread(FALSE);
     }
     else
     {
@@ -13683,11 +13738,7 @@ create_sort_index(THD *thd, JOIN *join, 
   tab->type=JT_ALL;				// Read with normal read_record
   tab->read_first_record= join_init_read_record;
   tab->join->examined_rows+=examined_rows;
-  if (table->key_read)				// Restore if we used indexes
-  {
-    table->key_read=0;
-    table->file->extra(HA_EXTRA_NO_KEYREAD);
-  }
+  table->set_keyread(FALSE); // Restore if we used indexes
   DBUG_RETURN(table->sort.found_records == HA_POS_ERROR);
 err:
   DBUG_RETURN(-1);
@@ -14124,7 +14175,7 @@ join_init_cache(THD *thd,JOIN_TAB *table
       {
 	used_fields--;
 	length+=field->fill_cache_field(copy);
-	if (copy->blob_field)
+	if (copy->type == CACHE_BLOB)
 	  (*blob_ptr++)=copy;
 	if (field->real_maybe_null())
 	  null_fields++;
@@ -14139,8 +14190,8 @@ join_init_cache(THD *thd,JOIN_TAB *table
     {						/* must copy null bits */
       copy->str= tables[i].table->null_flags;
       copy->length= tables[i].table->s->null_bytes;
-      copy->strip=0;
-      copy->blob_field=0;
+      copy->type=0;
+      copy->field=0;
       length+=copy->length;
       copy++;
       cache->fields++;
@@ -14150,8 +14201,8 @@ join_init_cache(THD *thd,JOIN_TAB *table
     {
       copy->str= (uchar*) &tables[i].table->null_row;
       copy->length=sizeof(tables[i].table->null_row);
-      copy->strip=0;
-      copy->blob_field=0;
+      copy->type=0;
+      copy->field=0;
       length+=copy->length;
       copy++;
       cache->fields++;
@@ -14176,9 +14227,10 @@ used_blob_length(CACHE_FIELD **ptr)
   uint length,blob_length;
   for (length=0 ; *ptr ; ptr++)
   {
-    (*ptr)->blob_length=blob_length=(*ptr)->blob_field->get_length();
+    Field_blob *field_blob= (Field_blob *) (*ptr)->field;
+    (*ptr)->blob_length=blob_length= field_blob->get_length();
     length+=blob_length;
-    (*ptr)->blob_field->get_ptr(&(*ptr)->str);
+    field_blob->get_ptr(&(*ptr)->str);
   }
   return length;
 }
@@ -14207,30 +14259,35 @@ store_record_in_cache(JOIN_CACHE *cache)
   cache->records++;
   for (copy=cache->field ; copy < end_field; copy++)
   {
-    if (copy->blob_field)
+    if (copy->type == CACHE_BLOB)
     {
+      Field_blob *blob_field= (Field_blob *) copy->field;
       if (last_record)
       {
-	copy->blob_field->get_image(pos, copy->length+sizeof(char*), 
-				    copy->blob_field->charset());
+	blob_field->get_image(pos, copy->length+sizeof(char*), 
+                              blob_field->charset());
 	pos+=copy->length+sizeof(char*);
       }
       else
       {
-	copy->blob_field->get_image(pos, copy->length, // blob length
-				    copy->blob_field->charset());
+	blob_field->get_image(pos, copy->length, // blob length
+                              blob_field->charset());
 	memcpy(pos+copy->length,copy->str,copy->blob_length);  // Blob data
 	pos+=copy->length+copy->blob_length;
       }
     }
     else
     {
-      if (copy->strip)
+      if (copy->type == CACHE_STRIPPED)
       {
 	uchar *str,*end;
-	for (str=copy->str,end= str+copy->length;
-	     end > str && end[-1] == ' ' ;
-	     end--) ;
+        Field *field= copy->field;
+        if (field && field->maybe_null() && field->is_null())
+          end= str= copy->str;
+        else
+          for (str=copy->str,end= str+copy->length;
+               end > str && end[-1] == ' ' ;
+               end--) ;
 	length=(uint) (end-str);
 	memcpy(pos+2, str, length);
         int2store(pos, length);
@@ -14279,23 +14336,24 @@ read_cached_record(JOIN_TAB *tab)
        copy < end_field;
        copy++)
   {
-    if (copy->blob_field)
+    if (copy->type == CACHE_BLOB)
     {
+      Field_blob *blob_field= (Field_blob *) copy->field;
       if (last_record)
       {
-	copy->blob_field->set_image(pos, copy->length+sizeof(char*),
-				    copy->blob_field->charset());
+	blob_field->set_image(pos, copy->length+sizeof(char*),
+                              blob_field->charset());
 	pos+=copy->length+sizeof(char*);
       }
       else
       {
-	copy->blob_field->set_ptr(pos, pos+copy->length);
-	pos+=copy->length+copy->blob_field->get_length();
+	blob_field->set_ptr(pos, pos+copy->length);
+	pos+=copy->length + blob_field->get_length();
       }
     }
     else
     {
-      if (copy->strip)
+      if (copy->type == CACHE_STRIPPED)
       {
         length= uint2korr(pos);
 	memcpy(copy->str, pos+2, length);
@@ -14506,11 +14564,29 @@ find_order_in_list(THD *thd, Item **ref_
 
     We check order_item->fixed because Item_func_group_concat can put
     arguments for which fix_fields already was called.
+    
+    group_fix_field= TRUE is to resolve aliases from the SELECT list
+    without creating of Item_ref-s: JOIN::exec() wraps aliased items
+    in SELECT list with Item_copy items. To re-evaluate such a tree
+    that includes Item_copy items we have to refresh Item_copy caches,
+    but:
+      - filesort() never refresh Item_copy items,
+      - end_send_group() checks every record for group boundary by the
+        test_if_group_changed function that obtain data from these
+        Item_copy items, but the copy_fields function that
+        refreshes Item copy items is called after group boundaries only -
+        that is a vicious circle.
+    So we prevent inclusion of Item_copy items.
   */
-  if (!order_item->fixed &&
+  bool save_group_fix_field= thd->lex->current_select->group_fix_field;
+  if (is_group_field)
+    thd->lex->current_select->group_fix_field= TRUE;
+  bool ret= (!order_item->fixed &&
       (order_item->fix_fields(thd, order->item) ||
        (order_item= *order->item)->check_cols(1) ||
-       thd->is_fatal_error))
+       thd->is_fatal_error));
+  thd->lex->current_select->group_fix_field= save_group_fix_field;
+  if (ret)
     return TRUE; /* Wrong field. */
 
   uint el= all_fields.elements;
@@ -15592,7 +15668,7 @@ static bool add_ref_to_table_cond(THD *t
 
   Item_cond_and *cond=new Item_cond_and();
   TABLE *table=join_tab->table;
-  int error;
+  int error= 0;
   if (!cond)
     DBUG_RETURN(TRUE);
 
@@ -15610,7 +15686,8 @@ static bool add_ref_to_table_cond(THD *t
     cond->fix_fields(thd, (Item**)&cond);
   if (join_tab->select)
   {
-    error=(int) cond->add(join_tab->select->cond);
+    if (join_tab->select->cond)
+      error=(int) cond->add(join_tab->select->cond);
     join_tab->select_cond=join_tab->select->cond=cond;
   }
   else if ((join_tab->select= make_select(join_tab->table, 0, 0, cond, 0,

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2010-03-12 06:06:23 +0000
+++ b/sql/sql_select.h	2010-06-09 14:07:08 +0000
@@ -98,6 +98,10 @@ typedef struct st_table_ref
 } TABLE_REF;
 
 
+
+#define CACHE_BLOB      1        /* blob field  */
+#define CACHE_STRIPPED  2        /* field stripped of trailing spaces */
+
 /**
   CACHE_FIELD and JOIN_CACHE is used on full join to cache records in outer
   table
@@ -106,8 +110,8 @@ typedef struct st_table_ref
 typedef struct st_cache_field {
   uchar *str;
   uint length, blob_length;
-  Field_blob *blob_field;
-  bool strip;
+  Field *field;
+  uint type;    /**< category of the of the copied field (CACHE_BLOB et al.) */
 } CACHE_FIELD;
 
 
@@ -357,7 +361,25 @@ public:
   */
   bool no_const_tables; 
   
-  JOIN *tmp_join; ///< copy of this JOIN to be used with temporary tables
+  /**
+    Copy of this JOIN to be used with temporary tables.
+
+    tmp_join is used when the JOIN needs to be "reusable" (e.g. in a subquery
+    that gets re-executed several times) and we know will use temporary tables
+    for materialization. The materialization to a temporary table overwrites the
+    JOIN structure to point to the temporary table after the materialization is
+    done. This is where tmp_join is used : it's a copy of the JOIN before the
+    materialization and is used in restoring before re-execution by overwriting
+    the current JOIN structure with the saved copy.
+    Because of this we should pay extra care of not freeing up helper structures
+    that are referenced by the original contents of the JOIN. We can check for
+    this by making sure the "current" join is not the temporary copy, e.g.
+    !tmp_join || tmp_join != join
+ 
+    We should free these sub-structures at JOIN::destroy() if the "current" join
+    has a copy is not that copy.
+  */
+  JOIN *tmp_join;
   ROLLUP rollup;				///< Used with rollup
 
   bool select_distinct;				///< Set if SELECT DISTINCT
@@ -717,10 +739,11 @@ public:
      we need to check for errors executing it and react accordingly
     */
     if (!res && table->in_use->is_error())
-      res= 2;
+      res= 1; /* STORE_KEY_FATAL */
     dbug_tmp_restore_column_map(table->write_set, old_map);
     null_key= to_field->is_null() || item->null_value;
-    return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res); 
+    return ((err != 0 || res < 0 || res > 2) ? STORE_KEY_FATAL : 
+            (store_key_result) res);
   }
 };
 
@@ -749,17 +772,17 @@ protected:  
       if ((res= item->save_in_field(to_field, 1)))
       {       
         if (!err)
-          err= res;
+          err= res < 0 ? 1 : res; /* 1=STORE_KEY_FATAL */
       }
       /*
         Item::save_in_field() may call Item::val_xxx(). And if this is a subquery
         we need to check for errors executing it and react accordingly
         */
       if (!err && to_field->table->in_use->is_error())
-        err= 2;
+        err= 1; /* STORE_KEY_FATAL */
     }
     null_key= to_field->is_null() || item->null_value;
-    return (err > 2 ?  STORE_KEY_FATAL : (store_key_result) err);
+    return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
   }
 };
 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_table.cc	2010-06-09 14:07:08 +0000
@@ -25,6 +25,7 @@
 #include "sp_head.h"
 #include "sql_trigger.h"
 #include "sql_show.h"
+#include "debug_sync.h"
 
 #ifdef __WIN__
 #include <io.h>
@@ -1901,22 +1902,10 @@ int mysql_rm_table_part2(THD *thd, TABLE
 
   pthread_mutex_lock(&LOCK_open);
 
-  /*
-    If we have the table in the definition cache, we don't have to check the
-    .frm file to find if the table is a normal table (not view) and what
-    engine to use.
-  */
-
+  /* Disable drop of enabled log tables, must be done before name locking */
   for (table= tables; table; table= table->next_local)
   {
-    TABLE_SHARE *share;
-    table->db_type= NULL;
-    if ((share= get_cached_table_share(table->db, table->table_name)))
-      table->db_type= share->db_type();
-
-    /* Disable drop of enabled log tables */
-    if (share && (share->table_category == TABLE_CATEGORY_PERFORMANCE) &&
-        check_if_log_table(table->db_length, table->db,
+    if (check_if_log_table(table->db_length, table->db,
                            table->table_name_length, table->table_name, 1))
     {
       my_error(ER_BAD_LOG_STATEMENT, MYF(0), "DROP");
@@ -1935,7 +1924,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
   {
     char *db=table->db;
     handlerton *table_type;
-    enum legacy_db_type frm_db_type;
+    enum legacy_db_type frm_db_type= DB_TYPE_UNKNOWN;
 
     DBUG_PRINT("table", ("table_l: '%s'.'%s'  table: 0x%lx  s: 0x%lx",
                          table->db, table->table_name, (long) table->table,
@@ -2000,7 +1989,6 @@ int mysql_rm_table_part2(THD *thd, TABLE
       built_query.append("`,");
     }
 
-    table_type= table->db_type;
     if (!drop_temporary)
     {
       TABLE *locked_table;
@@ -2027,9 +2015,9 @@ int mysql_rm_table_part2(THD *thd, TABLE
                                         table->internal_tmp_table ?
                                         FN_IS_TMP : 0);
     }
+    DEBUG_SYNC(thd, "rm_table_part2_before_delete_table");
     if (drop_temporary ||
-        ((table_type == NULL &&        
-         access(path, F_OK) &&
+        ((access(path, F_OK) &&
           ha_create_table_from_engine(thd, db, alias)) ||
          (!drop_view &&
           mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
@@ -2045,15 +2033,26 @@ int mysql_rm_table_part2(THD *thd, TABLE
     else
     {
       char *end;
-      if (table_type == NULL)
+      /*
+        Cannot use the db_type from the table, since that might have changed
+        while waiting for the exclusive name lock. We are under LOCK_open,
+        so reading from the frm-file is safe.
+      */
+      if (frm_db_type == DB_TYPE_UNKNOWN)
       {
         mysql_frm_type(thd, path, &frm_db_type);
         table_type= ha_resolve_by_legacy_type(thd, frm_db_type);
+        DBUG_PRINT("info", ("frm_db_type %d from %s", frm_db_type, path));
       }
+      table_type= ha_resolve_by_legacy_type(thd, frm_db_type);
       // Remove extension for delete
       *(end= path + path_length - reg_ext_length)= '\0';
+      DBUG_PRINT("info", ("deleting table of type %d",
+                          (table_type ? table_type->db_type : 0)));
       error= ha_delete_table(thd, table_type, path, db, table->table_name,
                              !dont_log_query);
+
+      /* No error if non existent table and 'IF EXIST' clause or view */
       if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && 
 	  (if_exists || table_type == NULL))
       {
@@ -2093,6 +2092,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
     on the table name.
   */
   pthread_mutex_unlock(&LOCK_open);
+  DEBUG_SYNC(thd, "rm_table_part2_before_binlog");
   thd->thread_specific_used|= tmp_table_deleted;
   error= 0;
   if (wrong_tables.length())
@@ -6221,14 +6221,15 @@ int create_temporary_table(THD *thd,
   else
     create_info->data_file_name=create_info->index_file_name=0;
 
+  DEBUG_SYNC(thd, "alter_table_before_create_table_no_lock");
   /*
     Create a table with a temporary name.
     With create_info->frm_only == 1 this creates a .frm file only.
     We don't log the statement, it will be logged later.
   */
   tmp_disable_binlog(thd);
-  error= mysql_create_table(thd, new_db, tmp_name,
-                            create_info, alter_info, 1, 0);
+  error= mysql_create_table_no_lock(thd, new_db, tmp_name,
+                                    create_info, alter_info, 1, 0);
   reenable_binlog(thd);
 
   DBUG_RETURN(error);
@@ -7640,6 +7641,7 @@ view_err:
     intern_close_table(new_table);
     my_free(new_table,MYF(0));
   }
+  DEBUG_SYNC(thd, "alter_table_before_rename_result_table");
   VOID(pthread_mutex_lock(&LOCK_open));
   if (error)
   {
@@ -7732,6 +7734,7 @@ end_online:
   thd_proc_info(thd, "end");
 
   DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
+  DEBUG_SYNC(thd, "alter_table_before_main_binlog");
 
   ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
                       thd->query(), thd->query_length(),

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_trigger.cc	2010-06-09 14:07:08 +0000
@@ -330,6 +330,7 @@ bool mysql_create_or_drop_trigger(THD *t
   TABLE *table;
   bool result= TRUE;
   String stmt_query;
+  Query_tables_list backup;
   bool need_start_waiting= FALSE;
 
   DBUG_ENTER("mysql_create_or_drop_trigger");
@@ -396,6 +397,12 @@ bool mysql_create_or_drop_trigger(THD *t
   {
     bool if_exists= thd->lex->drop_if_exists;
 
+    /*
+      Protect the query table list from the temporary and potentially
+      destructive changes necessary to open the trigger's table.
+    */
+    thd->lex->reset_n_backup_query_tables_list(&backup);
+
     if (add_table_for_trigger(thd, thd->lex->spname, if_exists, & tables))
       goto end;
 
@@ -515,6 +522,10 @@ end:
 
   VOID(pthread_mutex_unlock(&LOCK_open));
 
+  /* Restore the query table list. Used only for drop trigger. */
+  if (!create)
+    thd->lex->restore_backup_query_tables_list(&backup);
+
   if (need_start_waiting)
     start_waiting_global_read_lock(thd);
 
@@ -1628,10 +1639,6 @@ bool add_table_for_trigger(THD *thd,
   if (load_table_name_for_trigger(thd, trg_name, &trn_path, &tbl_name))
     DBUG_RETURN(TRUE);
 
-  /* We need to reset statement table list to be PS/SP friendly. */
-  lex->query_tables= 0;
-  lex->query_tables_last= &lex->query_tables;
-
   *table= sp_add_to_query_tables(thd, lex, trg_name->m_db.str,
                                  tbl_name.str, TL_IGNORE);
 

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_update.cc	2010-06-09 14:07:08 +0000
@@ -400,10 +400,7 @@ int mysql_update(THD *thd,
       matching rows before updating the table!
     */
     if (used_index < MAX_KEY && old_covering_keys.is_set(used_index))
-    {
-      table->key_read=1;
       table->mark_columns_used_by_index(used_index);
-    }
     else
     {
       table->use_all_columns();
@@ -847,11 +844,7 @@ int mysql_update(THD *thd,
 err:
   delete select;
   free_underlaid_joins(thd, select_lex);
-  if (table->key_read)
-  {
-    table->key_read=0;
-    table->file->extra(HA_EXTRA_NO_KEYREAD);
-  }
+  table->set_keyread(FALSE);
   thd->abort_on_warning= 0;
   DBUG_RETURN(1);
 }
@@ -1198,6 +1191,56 @@ reopen_tables:
 }
 
 
+/**
+   Implementation of the safe update options during UPDATE IGNORE. This syntax
+   causes an UPDATE statement to ignore all errors. In safe update mode,
+   however, we must never ignore the ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE. There
+   is a special hook in my_message_sql that will otherwise delete all errors
+   when the IGNORE option is specified. 
+
+   In the future, all IGNORE handling should be used with this class and all
+   traces of the hack outlined below should be removed.
+
+   - The parser detects IGNORE option and sets thd->lex->ignore= 1
+   
+   - In JOIN::optimize, if this is set, then 
+     thd->lex->current_select->no_error gets set.
+
+   - In my_message_sql(), if the flag above is set then any error is
+     unconditionally converted to a warning.
+
+   We are moving in the direction of using Internal_error_handler subclasses
+   to do all such error tweaking, please continue this effort if new bugs
+   appear.
+ */
+class Safe_dml_handler : public Internal_error_handler {
+
+private:
+  bool m_handled_error;
+
+public:
+  explicit Safe_dml_handler() : m_handled_error(FALSE) {}
+
+  bool handle_error(uint sql_errno,
+                    const char *message,
+                    MYSQL_ERROR::enum_warning_level level,
+                    THD *thd)
+  {
+    if (level == MYSQL_ERROR::WARN_LEVEL_ERROR &&
+        sql_errno == ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE)
+        
+    {      
+      thd->main_da.set_error_status(thd, sql_errno, message);
+      m_handled_error= TRUE;
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  bool handled_error() { return m_handled_error; }
+
+};
+
 /*
   Setup multi-update handling and call SELECT to do the join
 */
@@ -1226,18 +1269,36 @@ bool mysql_multi_update(THD *thd,
                                MODE_STRICT_ALL_TABLES));
 
   List<Item> total_list;
+
+  Safe_dml_handler handler;
+  bool using_handler= thd->options & OPTION_SAFE_UPDATES;
+  if (using_handler)
+    thd->push_internal_handler(&handler);
+
   res= mysql_select(thd, &select_lex->ref_pointer_array,
-                      table_list, select_lex->with_wild,
-                      total_list,
-                      conds, 0, (ORDER *) NULL, (ORDER *)NULL, (Item *) NULL,
-                      (ORDER *)NULL,
-                      options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
-                      OPTION_SETUP_TABLES_DONE,
-                      result, unit, select_lex);
-  DBUG_PRINT("info",("res: %d  report_error: %d", res,
-                     (int) thd->is_error()));
+                    table_list, select_lex->with_wild,
+                    total_list,
+                    conds, 0, (ORDER *) NULL, (ORDER *)NULL, (Item *) NULL,
+                    (ORDER *)NULL,
+                    options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
+                    OPTION_SETUP_TABLES_DONE,
+                    result, unit, select_lex);
+
+  if (using_handler)
+  {
+    Internal_error_handler *top_handler;
+    top_handler= thd->pop_internal_handler();
+    DBUG_ASSERT(&handler == top_handler);
+  }
+
+  DBUG_PRINT("info",("res: %d  report_error: %d", res, (int) thd->is_error()));
   res|= thd->is_error();
-  if (unlikely(res))
+  /*
+    Todo: remove below code and make Safe_dml_handler do error processing
+    instead. That way we can return the actual error instead of
+    ER_UNKNOWN_ERROR.
+  */
+  if (unlikely(res) && (!using_handler || !handler.handled_error()))
   {
     /* If we had a another error reported earlier then this will be ignored */
     result->send_error(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR));

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2010-03-12 06:06:23 +0000
+++ b/sql/sql_view.cc	2010-06-09 14:07:08 +0000
@@ -402,17 +402,14 @@ bool mysql_create_view(THD *thd, TABLE_L
   DBUG_ASSERT(!lex->proc_list.first && !lex->result &&
               !lex->param_list.elements);
 
-  if (mode != VIEW_CREATE_NEW)
+  if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view))
   {
-    if (mode == VIEW_ALTER &&
-        fill_defined_view_parts(thd, view))
-    {
-      res= TRUE;
-      goto err;
-    }
-    sp_cache_invalidate();
+    res= TRUE;
+    goto err;
   }
 
+  sp_cache_invalidate();
+
   if (!lex->definer)
   {
     /*

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2010-03-12 06:06:23 +0000
+++ b/sql/table.cc	2010-06-09 14:07:08 +0000
@@ -3425,7 +3425,7 @@ bool TABLE_LIST::prep_check_option(THD *
 
 void TABLE_LIST::hide_view_error(THD *thd)
 {
-  if (thd->get_internal_handler())
+  if (thd->killed || thd->get_internal_handler())
     return;
   /* Hide "Unknown column" or "Unknown function" error */
   DBUG_ASSERT(thd->is_error());
@@ -4434,7 +4434,7 @@ void st_table::mark_columns_used_by_inde
   MY_BITMAP *bitmap= &tmp_set;
   DBUG_ENTER("st_table::mark_columns_used_by_index");
 
-  (void) file->extra(HA_EXTRA_KEYREAD);
+  set_keyread(TRUE);
   bitmap_clear_all(bitmap);
   mark_columns_used_by_index_no_reset(index, bitmap);
   column_bitmaps_set(bitmap, bitmap);
@@ -4457,8 +4457,7 @@ void st_table::restore_column_maps_after
 {
   DBUG_ENTER("st_table::restore_column_maps_after_mark_index");
 
-  key_read= 0;
-  (void) file->extra(HA_EXTRA_NO_KEYREAD);
+  set_keyread(FALSE);
   default_column_bitmaps();
   file->column_bitmaps_signal();
   DBUG_VOID_RETURN;

=== modified file 'sql/table.h'
--- a/sql/table.h	2010-03-12 06:06:23 +0000
+++ b/sql/table.h	2010-06-09 14:07:08 +0000
@@ -907,6 +907,20 @@ struct st_table {
   inline bool needs_reopen_or_name_lock()
   { return s->version != refresh_version; }
   bool is_children_attached(void);
+  inline void set_keyread(bool flag)
+  {
+    DBUG_ASSERT(file);
+    if (flag && !key_read)
+    {
+      key_read= 1;
+      file->extra(HA_EXTRA_KEYREAD);
+    }
+    else if (!flag && key_read)
+    {
+      key_read= 0;
+      file->extra(HA_EXTRA_NO_KEYREAD);
+    }
+  }
 };
 
 enum enum_schema_table_state

=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc	2010-03-12 06:06:23 +0000
+++ b/storage/archive/ha_archive.cc	2010-06-09 14:07:08 +0000
@@ -358,6 +358,9 @@ ARCHIVE_SHARE *ha_archive::get_share(con
     */
     if (!(azopen(&archive_tmp, share->data_file_name, O_RDONLY|O_BINARY)))
     {
+      *rc= my_errno ? my_errno : -1;
+      pthread_mutex_unlock(&archive_mutex);
+      my_free(share, MYF(0));
       DBUG_RETURN(NULL);
     }
     stats.auto_increment_value= archive_tmp.auto_increment + 1;
@@ -507,16 +510,18 @@ int ha_archive::open(const char *name, i
     For now we have to refuse to open such table to avoid
     potential data loss.
   */
-  if ((rc == HA_ERR_CRASHED_ON_USAGE && !(open_options & HA_OPEN_FOR_REPAIR))
-      ||  rc == HA_ERR_TABLE_NEEDS_UPGRADE)
+  switch (rc)
   {
-    /* purecov: begin inspected */
+  case 0:
+    break;
+  case HA_ERR_CRASHED_ON_USAGE:
+    if (open_options & HA_OPEN_FOR_REPAIR)
+      break;
+    /* fall through */
+  case HA_ERR_TABLE_NEEDS_UPGRADE:
     free_share();
-    DBUG_RETURN(rc);
-    /* purecov: end */    
-  }
-  else if (rc == HA_ERR_OUT_OF_MEM)
-  {
+    /* fall through */
+  default:
     DBUG_RETURN(rc);
   }
 

=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc	2009-12-17 10:14:52 +0000
+++ b/storage/csv/ha_tina.cc	2010-06-09 14:07:08 +0000
@@ -682,9 +682,21 @@ int ha_tina::find_current_row(uchar *buf
 
     if (read_all || bitmap_is_set(table->read_set, (*field)->field_index))
     {
+      bool is_enum= ((*field)->real_type() ==  MYSQL_TYPE_ENUM);
+      /*
+        Here CHECK_FIELD_WARN checks that all values in the csv file are valid
+        which is normally the case, if they were written  by
+        INSERT -> ha_tina::write_row. '0' values on ENUM fields are considered
+        invalid by Field_enum::store() but it can store them on INSERT anyway.
+        Thus, for enums we silence the warning, as it doesn't really mean
+        an invalid value.
+      */
       if ((*field)->store(buffer.ptr(), buffer.length(), buffer.charset(),
-                          CHECK_FIELD_WARN))
-        goto err;
+                          is_enum ? CHECK_FIELD_IGNORE : CHECK_FIELD_WARN))
+      {
+        if (!is_enum)
+          goto err;
+      }
       if ((*field)->flags & BLOB_FLAG)
       {
         Field_blob *blob= *(Field_blob**) field;

=== modified file 'storage/innobase/buf/buf0buf.c'
--- a/storage/innobase/buf/buf0buf.c	2008-08-20 00:37:41 +0000
+++ b/storage/innobase/buf/buf0buf.c	2010-02-26 09:03:58 +0000
@@ -224,6 +224,9 @@ in the free list to the frames.
 /* Value in microseconds */
 static const int WAIT_FOR_READ	= 20000;
 
+/* Number of attemtps made to read in a page in the buffer pool */
+static const ulint BUF_PAGE_READ_MAX_RETRIES = 100;
+
 buf_pool_t*	buf_pool = NULL; /* The buffer buf_pool of the database */
 
 #ifdef UNIV_DEBUG
@@ -1160,6 +1163,7 @@ buf_page_get_gen(
 	ulint		fix_type;
 	ibool		success;
 	ibool		must_read;
+	ulint		retries = 0;
 
 	ut_ad(mtr);
 	ut_ad((rw_latch == RW_S_LATCH)
@@ -1200,7 +1204,29 @@ loop:
 			return(NULL);
 		}
 
-		buf_read_page(space, offset);
+		if (buf_read_page(space, offset)) {
+			retries = 0;
+		} else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
+			++retries;
+		} else {
+			fprintf(stderr, "InnoDB: Error: Unable"
+				" to read tablespace %lu page no"
+				" %lu into the buffer pool after"
+				" %lu attempts\n"
+				"InnoDB: The most probable cause"
+				" of this error may be that the"
+				" table has been corrupted.\n"
+				"InnoDB: You can try to fix this"
+				" problem by using"
+				" innodb_force_recovery.\n"
+				"InnoDB: Please see reference manual"
+				" for more details.\n"
+				"InnoDB: Aborting...\n",
+				space, offset,
+				BUF_PAGE_READ_MAX_RETRIES);
+
+			ut_error;
+		}
 
 #ifdef UNIV_DEBUG
 		buf_dbg_counter++;

=== modified file 'storage/innobase/buf/buf0rea.c'
--- a/storage/innobase/buf/buf0rea.c	2006-09-21 07:39:09 +0000
+++ b/storage/innobase/buf/buf0rea.c	2010-02-26 09:03:58 +0000
@@ -299,30 +299,27 @@ buffer buf_pool if it is not already the
 an exclusive lock on the buffer frame. The flag is cleared and the x-lock
 released by the i/o-handler thread. Does a random read-ahead if it seems
 sensible. */
-
-ulint
+ibool
 buf_read_page(
 /*==========*/
-			/* out: number of page read requests issued: this can
-			be > 1 if read-ahead occurred */
+			/* out: TRUE if success, FALSE otherwise */
 	ulint	space,	/* in: space id */
 	ulint	offset)	/* in: page number */
 {
 	ib_longlong	tablespace_version;
 	ulint		count;
-	ulint		count2;
 	ulint		err;
 
 	tablespace_version = fil_space_get_version(space);
 
-	count = buf_read_ahead_random(space, offset);
+	buf_read_ahead_random(space, offset);
 
 	/* We do the i/o in the synchronous aio mode to save thread
 	switches: hence TRUE */
 
-	count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
+	count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
 				   tablespace_version, offset);
-	srv_buf_pool_reads+= count2;
+	srv_buf_pool_reads+= count;
 	if (err == DB_TABLESPACE_DELETED) {
 		ut_print_timestamp(stderr);
 		fprintf(stderr,
@@ -336,7 +333,7 @@ buf_read_page(
 	/* Flush pages from the end of the LRU list if necessary */
 	buf_flush_free_margin();
 
-	return(count + count2);
+	return(count > 0);
 }
 
 /************************************************************************

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2010-03-12 06:06:23 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2010-06-09 14:07:08 +0000
@@ -2655,9 +2655,9 @@ ha_innobase::innobase_initialize_autoinc
 		auto_inc = innobase_get_int_col_max_value(field);
 	} else {
 		/* We have no idea what's been passed in to us as the
-		autoinc column. We set it to the MAX_INT of our table
-		autoinc type. */
-		auto_inc = 0xFFFFFFFFFFFFFFFFULL;
+		autoinc column. We set it to the 0, effectively disabling
+		updates to the table. */
+		auto_inc = 0;
 
 		ut_print_timestamp(stderr);
 		fprintf(stderr, "  InnoDB: Unable to determine the AUTOINC "
@@ -2666,7 +2666,7 @@ ha_innobase::innobase_initialize_autoinc
 
 	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
 		/* If the recovery level is set so high that writes
-		are disabled we force the AUTOINC counter to the MAX
+		are disabled we force the AUTOINC counter to 0
 		value effectively disabling writes to the table.
 		Secondly, we avoid reading the table in case the read
 		results in failure due to a corrupted table/index.
@@ -2675,7 +2675,10 @@ ha_innobase::innobase_initialize_autoinc
 		tables can be dumped with minimal hassle.  If an error
 		were returned in this case, the first attempt to read
 		the table would fail and subsequent SELECTs would succeed. */
+		auto_inc = 0;
 	} else if (field == NULL) {
+		/* This is a far more serious error, best to avoid
+		opening the table and return failure. */
 		my_error(ER_AUTOINC_READ_FAILED, MYF(0));
 	} else {
 		dict_index_t*	index;
@@ -2704,7 +2707,7 @@ ha_innobase::innobase_initialize_autoinc
 				"InnoDB: Unable to find the AUTOINC column "
 				"%s in the InnoDB table %s.\n"
 				"InnoDB: We set the next AUTOINC column "
-				"value to the maximum possible value,\n"
+				"value to 0,\n"
 				"InnoDB: in effect disabling the AUTOINC "
 				"next value generation.\n"
 				"InnoDB: You can either set the next "
@@ -2713,7 +2716,13 @@ ha_innobase::innobase_initialize_autoinc
 				"recreating the table.\n",
 				col_name, index->table->name);
 
-			my_error(ER_AUTOINC_READ_FAILED, MYF(0));
+			/* This will disable the AUTOINC generation. */
+			auto_inc = 0;
+
+			/* We want the open to succeed, so that the user can
+			take corrective action. ie. reads should succeed but
+			updates should fail. */
+			err = DB_SUCCESS;
 			break;
 		default:
 			/* row_search_max_autoinc() should only return
@@ -3971,11 +3980,17 @@ no_commit:
 		prebuilt->autoinc_error = DB_SUCCESS;
 
 		if ((error = update_auto_increment())) {
-
 			/* We don't want to mask autoinc overflow errors. */
-			if (prebuilt->autoinc_error != DB_SUCCESS) {
-				error = (int) prebuilt->autoinc_error;
 
+			/* Handle the case where the AUTOINC sub-system
+			failed during initialization. */
+			if (prebuilt->autoinc_error == DB_UNSUPPORTED) {
+				error_result = ER_AUTOINC_READ_FAILED;
+				/* Set the error message to report too. */
+				my_error(ER_AUTOINC_READ_FAILED, MYF(0));
+				goto func_exit;
+			} else if (prebuilt->autoinc_error != DB_SUCCESS) {
+				error = (int) prebuilt->autoinc_error;
 				goto report_error;
 			}
 
@@ -7886,7 +7901,10 @@ ha_innobase::innobase_get_autoinc(
 		*value = dict_table_autoinc_read(prebuilt->table);
 
 		/* It should have been initialized during open. */
-		ut_a(*value != 0);
+		if (*value == 0) {
+			prebuilt->autoinc_error = DB_UNSUPPORTED;
+			dict_table_autoinc_unlock(prebuilt->table);
+		}
 	}
   
 	return(ulong(prebuilt->autoinc_error));
@@ -7966,6 +7984,11 @@ ha_innobase::get_auto_increment(
 	invoking this method. So we are not sure if it's guaranteed to
 	be 0 or not. */
 
+	/* We need the upper limit of the col type to check for
+	whether we update the table autoinc counter or not. */
+	ulonglong	col_max_value = innobase_get_int_col_max_value(
+		table->next_number_field);
+
 	/* Called for the first time ? */
 	if (trx->n_autoinc_rows == 0) {
 
@@ -7982,6 +8005,11 @@ ha_innobase::get_auto_increment(
 	/* Not in the middle of a mult-row INSERT. */
 	} else if (prebuilt->autoinc_last_value == 0) {
 		set_if_bigger(*first_value, autoinc);
+	/* Check for -ve values. */
+	} else if (*first_value > col_max_value && trx->n_autoinc_rows > 0) {
+		/* Set to next logical value. */
+		ut_a(autoinc > trx->n_autoinc_rows);
+		*first_value = (autoinc - trx->n_autoinc_rows) - 1;
 	}
 
 	*nb_reserved_values = trx->n_autoinc_rows;
@@ -7992,12 +8020,6 @@ ha_innobase::get_auto_increment(
 		ulonglong	need;
 		ulonglong	current;
 		ulonglong	next_value;
-		ulonglong	col_max_value;
-
-		/* We need the upper limit of the col type to check for
-		whether we update the table autoinc counter or not. */
-		col_max_value = innobase_get_int_col_max_value(
-			table->next_number_field);
 
 		current = *first_value > col_max_value ? autoinc : *first_value;
 		need = *nb_reserved_values * increment;

=== modified file 'storage/innobase/include/buf0rea.h'
--- a/storage/innobase/include/buf0rea.h	2006-09-05 01:52:15 +0000
+++ b/storage/innobase/include/buf0rea.h	2010-02-26 09:03:58 +0000
@@ -18,12 +18,10 @@ buffer buf_pool if it is not already the
 an exclusive lock on the buffer frame. The flag is cleared and the x-lock
 released by the i/o-handler thread. Does a random read-ahead if it seems
 sensible. */
-
-ulint
+ibool
 buf_read_page(
 /*==========*/
-			/* out: number of page read requests issued: this can
-			be > 1 if read-ahead occurred */
+			/* out: TRUE if success, FALSE otherwise */
 	ulint	space,	/* in: space id */
 	ulint	offset);/* in: page number */
 /************************************************************************

=== modified file 'storage/innobase/lock/lock0lock.c'
--- a/storage/innobase/lock/lock0lock.c	2009-12-23 06:59:34 +0000
+++ b/storage/innobase/lock/lock0lock.c	2010-02-26 13:16:46 +0000
@@ -306,6 +306,7 @@ FILE*	lock_latest_err_file;
 /* Flags for recursive deadlock search */
 #define LOCK_VICTIM_IS_START	1
 #define LOCK_VICTIM_IS_OTHER	2
+#define LOCK_EXCEED_MAX_DEPTH	3
 
 /************************************************************************
 Checks if a lock request results in a deadlock. */
@@ -332,16 +333,18 @@ lock_deadlock_recursive(
 				was found and we chose some other trx as a
 				victim: we must do the search again in this
 				last case because there may be another
-				deadlock! */
+				deadlock!
+				LOCK_EXCEED_MAX_DEPTH if the lock search
+				exceeds max steps and/or max depth. */
 	trx_t*	start,		/* in: recursion starting point */
 	trx_t*	trx,		/* in: a transaction waiting for a lock */
 	lock_t*	wait_lock,	/* in: the lock trx is waiting to be granted */
 	ulint*	cost,		/* in/out: number of calculation steps thus
 				far: if this exceeds LOCK_MAX_N_STEPS_...
-				we return LOCK_VICTIM_IS_START */
+				we return LOCK_EXCEED_MAX_DEPTH */
 	ulint	depth);		/* in: recursion depth: if this exceeds
 				LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK, we
-				return LOCK_VICTIM_IS_START */
+				return LOCK_EXCEED_MAX_DEPTH */
 
 /*************************************************************************
 Gets the nth bit of a record lock. */
@@ -3084,8 +3087,6 @@ lock_deadlock_occurs(
 	lock_t*	lock,	/* in: lock the transaction is requesting */
 	trx_t*	trx)	/* in: transaction */
 {
-	dict_table_t*	table;
-	dict_index_t*	index;
 	trx_t*		mark_trx;
 	ulint		ret;
 	ulint		cost	= 0;
@@ -3107,31 +3108,50 @@ retry:
 
 	ret = lock_deadlock_recursive(trx, trx, lock, &cost, 0);
 
-	if (ret == LOCK_VICTIM_IS_OTHER) {
+	switch (ret) {
+	case LOCK_VICTIM_IS_OTHER:
 		/* We chose some other trx as a victim: retry if there still
 		is a deadlock */
-
 		goto retry;
-	}
 
-	if (ret == LOCK_VICTIM_IS_START) {
-		if (lock_get_type(lock) & LOCK_TABLE) {
-			table = lock->un_member.tab_lock.table;
-			index = NULL;
+	case LOCK_EXCEED_MAX_DEPTH:
+		/* If the lock search exceeds the max step
+		or the max depth, the current trx will be
+		the victim. Print its information. */
+		rewind(lock_latest_err_file);
+		ut_print_timestamp(lock_latest_err_file);
+
+		fputs("TOO DEEP OR LONG SEARCH IN THE LOCK TABLE"
+		      " WAITS-FOR GRAPH, WE WILL ROLL BACK"
+		      " FOLLOWING TRANSACTION \n",
+		      lock_latest_err_file);
+
+		fputs("\n*** TRANSACTION:\n", lock_latest_err_file);
+		      trx_print(lock_latest_err_file, trx, 3000);
+
+		fputs("*** WAITING FOR THIS LOCK TO BE GRANTED:\n",
+		      lock_latest_err_file);
+
+		if (lock_get_type(lock) == LOCK_REC) {
+			lock_rec_print(lock_latest_err_file, lock);
 		} else {
-			index = lock->index;
-			table = index->table;
+			lock_table_print(lock_latest_err_file, lock);
 		}
+		break;
 
-		lock_deadlock_found = TRUE;
-
+	case LOCK_VICTIM_IS_START:
 		fputs("*** WE ROLL BACK TRANSACTION (2)\n",
 		      lock_latest_err_file);
+		break;
 
-		return(TRUE);
+	default:
+		/* No deadlock detected*/
+		return(FALSE);
 	}
 
-	return(FALSE);
+	lock_deadlock_found = TRUE;
+
+	return(TRUE);
 }
 
 /************************************************************************
@@ -3147,16 +3167,18 @@ lock_deadlock_recursive(
 				was found and we chose some other trx as a
 				victim: we must do the search again in this
 				last case because there may be another
-				deadlock! */
+				deadlock!
+				LOCK_EXCEED_MAX_DEPTH if the lock search
+				exceeds max steps and/or max depth. */
 	trx_t*	start,		/* in: recursion starting point */
 	trx_t*	trx,		/* in: a transaction waiting for a lock */
 	lock_t*	wait_lock,	/* in: the lock trx is waiting to be granted */
 	ulint*	cost,		/* in/out: number of calculation steps thus
 				far: if this exceeds LOCK_MAX_N_STEPS_...
-				we return LOCK_VICTIM_IS_START */
+				we return LOCK_EXCEED_MAX_DEPTH */
 	ulint	depth)		/* in: recursion depth: if this exceeds
 				LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK, we
-				return LOCK_VICTIM_IS_START */
+				return LOCK_EXCEED_MAX_DEPTH */
 {
 	lock_t*	lock;
 	ulint	bit_no		= ULINT_UNDEFINED;
@@ -3215,7 +3237,7 @@ lock_deadlock_recursive(
 
 			lock_trx = lock->trx;
 
-			if (lock_trx == start || too_far) {
+			if (lock_trx == start) {
 
 				/* We came back to the recursion starting
 				point: a deadlock detected; or we have
@@ -3262,19 +3284,10 @@ lock_deadlock_recursive(
 				}
 #ifdef UNIV_DEBUG
 				if (lock_print_waits) {
-					fputs("Deadlock detected"
-					      " or too long search\n",
+					fputs("Deadlock detected\n",
 					      stderr);
 				}
 #endif /* UNIV_DEBUG */
-				if (too_far) {
-
-					fputs("TOO DEEP OR LONG SEARCH"
-					      " IN THE LOCK TABLE"
-					      " WAITS-FOR GRAPH\n", ef);
-
-					return(LOCK_VICTIM_IS_START);
-				}
 
 				if (trx_weight_cmp(wait_lock->trx,
 						   start) >= 0) {
@@ -3310,6 +3323,21 @@ lock_deadlock_recursive(
 				return(LOCK_VICTIM_IS_OTHER);
 			}
 
+			if (too_far) {
+
+#ifdef UNIV_DEBUG
+				if (lock_print_waits) {
+					fputs("Deadlock search exceeds"
+					      " max steps or depth.\n",
+					      stderr);
+				}
+#endif /* UNIV_DEBUG */
+				/* The information about transaction/lock
+				to be rolled back is available in the top
+				level. Do not print anything here. */
+				return(LOCK_EXCEED_MAX_DEPTH);
+			}
+
 			if (lock_trx->que_state == TRX_QUE_LOCK_WAIT) {
 
 				/* Another trx ahead has requested lock	in an

=== modified file 'storage/innobase/os/os0file.c'
--- a/storage/innobase/os/os0file.c	2010-03-15 13:41:49 +0000
+++ b/storage/innobase/os/os0file.c	2010-06-09 14:07:08 +0000
@@ -759,7 +759,15 @@ next_file:
 #ifdef HAVE_READDIR_R
 	ret = readdir_r(dir, (struct dirent*)dirent_buf, &ent);
 
-	if (ret != 0) {
+	if (ret != 0
+#ifdef UNIV_AIX
+	    /* On AIX, only if we got non-NULL 'ent' (result) value and
+	    a non-zero 'ret' (return) value, it indicates a failed
+	    readdir_r() call. An NULL 'ent' with an non-zero 'ret'
+	    would indicate the "end of the directory" is reached. */
+	    && ent != NULL
+#endif
+	   ) {
 		fprintf(stderr,
 			"InnoDB: cannot read directory %s, error %lu\n",
 			dirname, (ulong)ret);

=== modified file 'storage/myisam/ft_boolean_search.c'
--- a/storage/myisam/ft_boolean_search.c	2010-03-12 06:06:23 +0000
+++ b/storage/myisam/ft_boolean_search.c	2010-06-09 14:07:08 +0000
@@ -440,8 +440,18 @@ static int _ft2_search(FTB *ftb, FTB_WOR
         return 0;
     }
 
-    /* going up to the first-level tree to continue search there */
+    /*
+      Going up to the first-level tree to continue search there.
+      Only done when performing prefix search.
+
+      Key buffer data pointer as well as docid[0] may be smaller
+      than values we got while searching first-level tree. Thus
+      they must be restored to original values to avoid dead-loop,
+      when subsequent search for a bigger value eventually ends up
+      in this same second-level tree.
+    */
     _mi_dpointer(info, (uchar*) (lastkey_buf+HA_FT_WLEN), ftbw->key_root);
+    ftbw->docid[0]= ftbw->key_root;
     ftbw->key_root=info->s->state.key_root[ftb->keynr];
     ftbw->keyinfo=info->s->keyinfo+ftb->keynr;
     ftbw->off=0;

=== modified file 'storage/myisam/mi_dynrec.c'
--- a/storage/myisam/mi_dynrec.c	2009-09-30 18:51:17 +0000
+++ b/storage/myisam/mi_dynrec.c	2010-06-09 14:07:08 +0000
@@ -936,8 +936,16 @@ static int update_dynamic_record(MI_INFO
   }
 
   if (block_info.next_filepos != HA_OFFSET_ERROR)
+  {
+    /*
+      delete_dynamic_record() may change data file position.
+      IO cache must be notified as it may still have cached
+      data, which has to be flushed later.
+    */
+    info->rec_cache.seek_not_done= 1;
     if (delete_dynamic_record(info,block_info.next_filepos,1))
       goto err;
+  }
   DBUG_RETURN(0);
 err:
   DBUG_RETURN(1);

=== modified file 'storage/myisam/mi_locking.c'
--- a/storage/myisam/mi_locking.c	2009-05-26 18:53:34 +0000
+++ b/storage/myisam/mi_locking.c	2010-06-09 14:07:08 +0000
@@ -324,8 +324,8 @@ void mi_update_status(void* param)
 			    (long) info->s->state.state.data_file_length));
 #endif
     info->s->state.state= *info->state;
-    info->state= &info->s->state.state;
   }
+  info->state= &info->s->state.state;
   info->append_insert_at_end= 0;
 
   /*

=== modified file 'support-files/mysql.spec.sh'
--- a/support-files/mysql.spec.sh	2010-03-12 06:06:23 +0000
+++ b/support-files/mysql.spec.sh	2010-06-09 14:07:08 +0000
@@ -1,5 +1,5 @@
 # Copyright (C) 2000-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.
-# 
+#
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; version 2 of the License.
@@ -14,98 +14,129 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 #
 
-%define mysql_version		@VERSION@
+##############################################################################
+# Some common macro definitions
+##############################################################################
 
 # NOTE: "vendor" is used in upgrade/downgrade check, so you can't
 # change these, has to be exactly as is.
 %define mysql_old_vendor	MySQL AB
-%define mysql_vendor		Sun Microsystems, Inc.
+%define mysql_vendor_2		Sun Microsystems, Inc.
+%define mysql_vendor		Oracle and/or its affiliates
+
+%define mysql_version @VERSION@
+
+%define mysqld_user    mysql
+%define mysqld_group   mysql
+%define mysqldatadir   /var/lib/mysql
+%define see_base For a description of MySQL see the base MySQL RPM or http://www.mysql.com
+
+# ------------------------------------------------------------------------------
+# On SuSE 9 no separate "debuginfo" package is built. To enable basic
+# debugging on that platform, we don't strip binaries on SuSE 9. We
+# disable the strip of binaries by redefining the RPM macro
+# "__os_install_post" leaving out the script calls that normally does
+# this. We do this in all cases, as on platforms where "debuginfo" is
+# created, a script "find-debuginfo.sh" will be called that will do
+# the strip anyway, part of separating the executable and debug
+# information into separate files put into separate packages.
+#
+# Some references (shows more advanced conditional usage):
+# http://www.redhat.com/archives/rpm-list/2001-November/msg00257.html
+# http://www.redhat.com/archives/rpm-list/2003-February/msg00275.html
+# http://www.redhat.com/archives/rhl-devel-list/2004-January/msg01546.html
+# http://lists.opensuse.org/archive/opensuse-commit/2006-May/1171.html
+# ------------------------------------------------------------------------------
+%define __os_install_post /usr/lib/rpm/brp-compress
+
+# ------------------------------------------------------------------------------
+# We don't package all files installed into the build root by intention -
+# See BUG#998 for details.
+# ------------------------------------------------------------------------------
+%define _unpackaged_files_terminate_build 0
+
+# ------------------------------------------------------------------------------
+# RPM build tools now automatically detects Perl module dependencies. This
+# detection gives problems as it is broken in some versions, and it also
+# give unwanted dependencies from mandatory scripts in our package.
+# Might not be possible to disable in all RPM tool versions, but here we
+# try. We keep the "AutoReqProv: no" for the "test" sub package, as disabling
+# here might fail, and that package has the most problems.
+# See http://fedoraproject.org/wiki/Packaging/Perl#Filtering_Requires:_and_Provides
+#     http://www.wideopen.com/archives/rpm-list/2002-October/msg00343.html
+# ------------------------------------------------------------------------------
+%undefine __perl_provides
+%undefine __perl_requires
 
-# use "rpmbuild --with static" or "rpm --define '_with_static 1'" (for RPM 3.x)
-# to enable static linking (off by default)
-%{?_with_static:%define STATIC_BUILD 1}
-%{!?_with_static:%define STATIC_BUILD 0}
+##############################################################################
+# Command line handling
+##############################################################################
 
+# ----------------------------------------------------------------------
 # use "rpmbuild --with yassl" or "rpm --define '_with_yassl 1'" (for RPM 3.x)
 # to build with yaSSL support (off by default)
+# ----------------------------------------------------------------------
 %{?_with_yassl:%define YASSL_BUILD 1}
 %{!?_with_yassl:%define YASSL_BUILD 0}
 
 # ----------------------------------------------------------------------
-# use "rpmbuild --with bundled_zlib" or "rpm --define '_with_bundled_zlib 1'"
-# (for RPM 3.x) to build using the bundled zlib (off by default)
+# use "rpmbuild --without bundled_zlib" or "rpm --define '_without_bundled_zlib 1'"
+# (for RPM 3.x) to not build using the bundled zlib (on by default)
 # ----------------------------------------------------------------------
+%{!?_with_bundled_zlib: %{!?_without_bundled_zlib: %define WITH_BUNDLED_ZLIB 1}}
 %{?_with_bundled_zlib:%define WITH_BUNDLED_ZLIB 1}
-%{!?_with_bundled_zlib:%define WITH_BUNDLED_ZLIB 0}
+%{?_without_bundled_zlib:%define WITH_BUNDLED_ZLIB 0}
 
 # ----------------------------------------------------------------------
 # use "rpmbuild --without innodb_plugin" or "rpm --define '_without_innodb_plugin 1'"
 # (for RPM 3.x) to not build the innodb plugin (on by default with innodb builds)
 # ----------------------------------------------------------------------
-%{?_without_innodb_plugin:%define WITHOUT_INNODB_PLUGIN 1}
-%{!?_without_innodb_plugin:%define WITHOUT_INNODB_PLUGIN 0}
+%{!?_with_innodb_plugin: %{!?_without_innodb_plugin: %define WITH_INNODB_PLUGIN 1}}
+%{?_with_innodb_plugin:%define WITH_INNODB_PLUGIN 1}
+%{?_without_innodb_plugin:%define WITH_INNODB_PLUGIN 0}
 
+# ----------------------------------------------------------------------
 # use "rpmbuild --with cluster" or "rpm --define '_with_cluster 1'" (for RPM 3.x)
 # to build with cluster support (off by default)
+# ----------------------------------------------------------------------
 %{?_with_cluster:%define CLUSTER_BUILD 1}
 %{!?_with_cluster:%define CLUSTER_BUILD 0}
 
-%if %{STATIC_BUILD}
-%define release 1
-%else
-%define release 1.glibc23
-%endif
-%define mysql_license	GPL
-%define mysqld_user	mysql
-%define mysqld_group	mysql
-%define server_suffix -standard
-%define mysqldatadir /var/lib/mysql
-
-# We don't package all files installed into the build root by intention -
-# See BUG#998 for details.
-%define _unpackaged_files_terminate_build 0
+##############################################################################
+# Product definitions - set for a "community" package
+##############################################################################
 
-# ------------------------------------------------------------------------------
-# RPM build tools now automatically detects Perl module dependencies. This 
-# detection gives problems as it is broken in some versions, and it also
-# give unwanted dependencies from mandatory scripts in our package.
-# Might not be possible to disable in all RPM tool versions, but here we
-# try. We keep the "AutoReqProv: no" for the "test" sub package, as disabling
-# here might fail, and that package has the most problems.
-# See http://fedoraproject.org/wiki/Packaging/Perl#Filtering_Requires:_and_Provides
-#     http://www.wideopen.com/archives/rpm-list/2002-October/msg00343.html
-# ------------------------------------------------------------------------------
-%undefine __perl_provides
-%undefine __perl_requires
+%define server_suffix  -community
+%define package_suffix -community
+%define ndbug_comment MySQL Community Server (GPL)
+%define debug_comment MySQL Community Server - Debug (GPL)
+%define commercial 0
+%define EMBEDDED_BUILD 1
+%define PARTITION_BUILD 1
+# Default for CLUSTER_BUILD is "0", but command line option may override it
+%define COMMUNITY_BUILD 1
+%define INNODB_BUILD 1
+%define NORMAL_TEST_MODE test-bt
+%define DEBUG_TEST_MODE test-bt-debug
 
-%define see_base For a description of MySQL see the base MySQL RPM or http://www.mysql.com
+%define release 1.glibc23
 
-# On SuSE 9 no separate "debuginfo" package is built. To enable basic
-# debugging on that platform, we don't strip binaries on SuSE 9. We
-# disable the strip of binaries by redefining the RPM macro
-# "__os_install_post" leaving out the script calls that normally does
-# this. We do this in all cases, as on platforms where "debuginfo" is
-# created, a script "find-debuginfo.sh" will be called that will do
-# the strip anyway, part of separating the executable and debug
-# information into separate files put into separate packages.
-#
-# Some references (shows more advanced conditional usage):
-# http://www.redhat.com/archives/rpm-list/2001-November/msg00257.html
-# http://www.redhat.com/archives/rpm-list/2003-February/msg00275.html
-# http://www.redhat.com/archives/rhl-devel-list/2004-January/msg01546.html
-# http://lists.opensuse.org/archive/opensuse-commit/2006-May/1171.html
+%define mysql_license GPL
+%define src_dir mysql-%{mysql_version}
 
-%define __os_install_post /usr/lib/rpm/brp-compress
+##############################################################################
+# Main spec file section
+##############################################################################
 
-Name: MySQL
+Name:		MySQL
 Summary:	MySQL: a very fast and reliable SQL database server
 Group:		Applications/Databases
 Version:	@MYSQL_U_SCORE_VERSION@
 Release:	%{release}
-License:	Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ Sun Microsystems, Inc.  All rights reserved.  Use is subject to license terms.  Under %{mysql_license} license as shown in the Description field.
-Source:		http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/mysql-%{mysql_version}.tar.gz
+License:	Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ %{mysql_vendor}  All rights reserved.  Use is subject to license terms.  Under %{mysql_license} license as shown in the Description field.
+Source:		http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/%{src_dir}.tar.gz
 URL:		http://www.mysql.com/
-Packager:	Sun Microsystems, Inc. Product Engineering Team <build@stripped>
+Packager:	%{mysql_vendor} Product Engineering Team <build@stripped>
 Vendor:		%{mysql_vendor}
 Provides:	msqlormysql MySQL-server mysql
 BuildRequires: ncurses-devel
@@ -121,9 +152,9 @@ The MySQL(TM) software delivers a very f
 and robust SQL (Structured Query Language) database server. MySQL Server
 is intended for mission-critical, heavy-load production systems as well
 as for embedding into mass-deployed software. MySQL is a trademark of
-Sun Microsystems, Inc.
+%{mysql_vendor}
 
-Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ Sun Microsystems, Inc.  All rights reserved.
+Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ %{mysql_vendor}  All rights reserved.
 Use is subject to license terms.
 
 This software comes with ABSOLUTELY NO WARRANTY. This is free software,
@@ -133,6 +164,10 @@ The MySQL web site (http://www.mysql.com
 news and information about the MySQL software. Also please see the
 documentation and the manual for more information.
 
+##############################################################################
+# Sub package definition
+##############################################################################
+
 %package server
 Summary:	MySQL: a very fast and reliable SQL database server
 Group:		Applications/Databases
@@ -145,9 +180,9 @@ The MySQL(TM) software delivers a very f
 and robust SQL (Structured Query Language) database server. MySQL Server
 is intended for mission-critical, heavy-load production systems as well
 as for embedding into mass-deployed software. MySQL is a trademark of
-Sun Microsystems, Inc.
+%{mysql_vendor}
 
-Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ Sun Microsystems, Inc.  All rights reserved.
+Copyright 2000-2008 MySQL AB, @MYSQL_COPYRIGHT_YEAR@ %{mysql_vendor}  All rights reserved.
 Use is subject to license terms.
 
 This software comes with ABSOLUTELY NO WARRANTY. This is free software,
@@ -157,12 +192,17 @@ The MySQL web site (http://www.mysql.com
 news and information about the MySQL software. Also please see the
 documentation and the manual for more information.
 
-This package includes the MySQL server binary (incl. InnoDB) as well
-as related utilities to run and administrate a MySQL server.
+This package includes the MySQL server binary
+%if %{INNODB_BUILD}
+(configured including InnoDB)
+%endif
+as well as related utilities to run and administer a MySQL server.
 
 If you want to access and work with the database, you have to install
 package "MySQL-client" as well!
 
+# ------------------------------------------------------------------------------
+
 %package client
 Summary: MySQL - Client
 Group: Applications/Databases
@@ -170,33 +210,39 @@ Obsoletes: mysql-client
 Provides: mysql-client
 
 %description client
-This package contains the standard MySQL clients and administration tools. 
+This package contains the standard MySQL clients and administration tools.
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %if %{CLUSTER_BUILD}
 %package ndb-storage
 Summary:	MySQL - ndbcluster storage engine
 Group:		Applications/Databases
 
 %description ndb-storage
-This package contains the ndbcluster storage engine. 
-It is necessary to have this package installed on all 
+This package contains the ndbcluster storage engine.
+It is necessary to have this package installed on all
 computers that should store ndbcluster table data.
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %package ndb-management
 Summary:	MySQL - ndbcluster storage engine management
 Group:		Applications/Databases
 
 %description ndb-management
 This package contains ndbcluster storage engine management.
-It is necessary to have this package installed on at least 
+It is necessary to have this package installed on at least
 one computer in the cluster.
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %package ndb-tools
 Summary:	MySQL - ndbcluster storage engine basic tools
 Group:		Applications/Databases
@@ -206,6 +252,8 @@ This package contains ndbcluster storage
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %package ndb-extra
 Summary:	MySQL - ndbcluster storage engine extra tools
 Group:		Applications/Databases
@@ -217,6 +265,8 @@ They should be used with caution.
 %{see_base}
 %endif
 
+# ------------------------------------------------------------------------------
+
 %package test
 Requires: %{name}-client perl
 Summary: MySQL - Test suite
@@ -230,6 +280,8 @@ This package contains the MySQL regressi
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %package devel
 Summary: MySQL - Development header files and libraries
 Group: Applications/Databases
@@ -242,6 +294,8 @@ necessary to develop MySQL client applic
 
 %{see_base}
 
+# ------------------------------------------------------------------------------
+
 %package shared
 Summary: MySQL - Shared libraries
 Group: Applications/Databases
@@ -250,6 +304,10 @@ Group: Applications/Databases
 This package contains the shared libraries (*.so*) which certain
 languages and applications need to dynamically load and use MySQL.
 
+# ------------------------------------------------------------------------------
+
+%if %{EMBEDDED_BUILD}
+
 %package embedded
 Requires: %{name}-devel
 Summary: MySQL - embedded library
@@ -269,6 +327,12 @@ client/server version.
 
 %{see_base}
 
+%endif
+
+##############################################################################
+#
+##############################################################################
+
 %prep
 # We unpack the source two times, for 'debug' and 'release' build.
 %setup -T -a 0 -c -n mysql-%{mysql_version}
@@ -276,29 +340,53 @@ mv mysql-%{mysql_version} mysql-debug-%{
 %setup -D -T -a 0 -n mysql-%{mysql_version}
 mv mysql-%{mysql_version} mysql-release-%{mysql_version}
 
+##############################################################################
+# The actual build
+##############################################################################
+
 %build
 
 BuildMySQL() {
+# Let "MYSQL_BUILD_*FLAGS" take precedence.
+CFLAGS=${MYSQL_BUILD_CFLAGS:-$CFLAGS}
+CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-$CXXFLAGS}
+LDFLAGS=${MYSQL_BUILD_LDFLAGS:-$LDFLAGS}
+# Fall back on RPM_OPT_FLAGS (part of RPM environment) if no flags are given.
+CFLAGS=${CFLAGS:-$RPM_OPT_FLAGS}
+CXXFLAGS=${CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors -fno-exceptions -fno-rtti }
+# Evaluate current setting of $DEBUG
+if [ $DEBUG -gt 0 ] ; then
+	OPT_COMMENT='--with-comment="%{debug_comment}"'
+	OPT_DEBUG='--with-debug'
+	CFLAGS=`echo   " $CFLAGS "   | \
+	    sed -e 's/ -O[0-9]* / /' -e 's/ -unroll2 / /' -e 's/ -ip / /' \
+	        -e 's/^ //' -e 's/ $//'`
+	CXXFLAGS=`echo " $CXXFLAGS " | \
+	    sed -e 's/ -O[0-9]* / /' -e 's/ -unroll2 / /' -e 's/ -ip / /' \
+	        -e 's/^ //' -e 's/ $//'`
+else
+	OPT_COMMENT='--with-comment="%{ndbug_comment}"'
+	OPT_DEBUG=''
+fi
 # The --enable-assembler simply does nothing on systems that does not
 # support assembler speedups.
 sh -c  "PATH=\"${MYSQL_BUILD_PATH:-$PATH}\" \
-	CC=\"${CC:-$MYSQL_BUILD_CC}\" \
-	CXX=\"${CXX:-$MYSQL_BUILD_CXX}\" \
+	CC=\"${MYSQL_BUILD_CC:-$CC}\" \
+	CXX=\"${MYSQL_BUILD_CXX:-$CXX}\" \
 	CFLAGS=\"$CFLAGS\" \
 	CXXFLAGS=\"$CXXFLAGS\" \
-	LDFLAGS=\"$MYSQL_BUILD_LDFLAGS\" \
+	LDFLAGS=\"$LDFLAGS\" \
 	./configure \
  	    $* \
 	    --with-mysqld-ldflags='-static' \
 	    --with-client-ldflags='-static' \
-	    --with-zlib-dir=bundled \
 	    --enable-assembler \
 	    --enable-local-infile \
 	    --with-fast-mutexes \
-            --with-mysqld-user=%{mysqld_user} \
-            --with-unix-socket-path=/var/lib/mysql/mysql.sock \
+	    --with-mysqld-user=%{mysqld_user} \
+	    --with-unix-socket-path=/var/lib/mysql/mysql.sock \
 	    --with-pic \
-            --prefix=/ \
+	    --prefix=/ \
 %if %{CLUSTER_BUILD}
 	    --with-extra-charsets=all \
 %else
@@ -306,42 +394,62 @@ sh -c  "PATH=\"${MYSQL_BUILD_PATH:-$PATH
 %endif
 %if %{YASSL_BUILD}
 	    --with-ssl \
+%else
+	    --without-ssl \
 %endif
-            --exec-prefix=%{_exec_prefix} \
-            --libexecdir=%{_sbindir} \
-            --libdir=%{_libdir} \
-            --sysconfdir=%{_sysconfdir} \
-            --datadir=%{_datadir} \
-            --localstatedir=%{mysqldatadir} \
-            --infodir=%{_infodir} \
-            --includedir=%{_includedir} \
-            --mandir=%{_mandir} \
+	    --exec-prefix=%{_exec_prefix} \
+	    --libexecdir=%{_sbindir} \
+	    --libdir=%{_libdir} \
+	    --sysconfdir=%{_sysconfdir} \
+	    --datadir=%{_datadir} \
+	    --localstatedir=%{mysqldatadir} \
+	    --infodir=%{_infodir} \
+	    --includedir=%{_includedir} \
+	    --mandir=%{_mandir} \
 	    --enable-thread-safe-client \
+	    $OPT_COMMENT \
+	    $OPT_DEBUG \
 	    --with-readline \
-		--with-innodb \
-%if %{WITHOUT_INNODB_PLUGIN}
-		--without-plugin-innodb_plugin \
+%if %{WITH_BUNDLED_ZLIB}
+	    --with-zlib-dir=bundled \
 %endif
 %if %{CLUSTER_BUILD}
-		--with-ndbcluster \
+		--with-plugin-ndbcluster \
+%else
+		--without-plugin-ndbcluster \
+%endif
+%if %{INNODB_BUILD}
+		--with-plugin-innobase \
+%if %{WITH_INNODB_PLUGIN}
 %else
-		--without-ndbcluster \
+		--without-plugin-innodb_plugin \
 %endif
-		--with-archive-storage-engine \
-		--with-csv-storage-engine \
-		--with-blackhole-storage-engine \
-		--with-federated-storage-engine \
+%else
+		--without-plugin-innobase \
+		--without-plugin-innodb_plugin \
+%endif
+%if %{PARTITION_BUILD}
+		--with-plugin-partition \
+%else
+		--without-plugin-partition \
+%endif
+		--with-plugin-csv \
+		--with-plugin-archive \
+		--with-plugin-blackhole \
+		--with-plugin-federated \
 		--without-plugin-daemon_example \
 		--without-plugin-ftexample \
-		--with-partition \
-		--with-big-tables \
-%if %{WITH_BUNDLED_ZLIB}
-		--with-zlib-dir=bundled \
+%if %{EMBEDDED_BUILD}
+		--with-embedded-server \
+%else
+		--without-embedded-server \
 %endif
+		--with-big-tables \
 		--enable-shared \
 		"
  make
 }
+# end of function definition "BuildMySQL"
 
 # Use our own copy of glibc
 
@@ -370,15 +478,10 @@ export PATH
 
 # Use gcc for C and C++ code (to avoid a dependency on libstdc++ and
 # including exceptions into the code
-if [ -z "$CXX" -a -z "$CC" ]
-then
-	export CC="gcc"
-	export CXX="gcc"
+if [ -z "$CXX" -a -z "$CC" ] ; then
+	export CC="gcc" CXX="gcc"
 fi
 
-# Prepare compiler flags
-CFLAGS=${MYSQL_BUILD_CFLAGS:-$RPM_OPT_FLAGS}
-CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-$RPM_OPT_FLAGS -felide-constructors -fno-exceptions -fno-rtti }
 
 ##############################################################################
 #
@@ -388,20 +491,14 @@ CXXFLAGS=${MYSQL_BUILD_CXXFLAGS:-$RPM_OP
 
 (
 # We are in a subshell, so we can modify variables just for one run.
-CFLAGS=`echo   " $CFLAGS "   | \
-    sed -e 's/ -O[0-9]* / /' -e 's/ -unroll2 / /' -e 's/ -ip / /' \
-        -e 's/^ //' -e 's/ $//'`
-CXXFLAGS=`echo " $CXXFLAGS " | \
-    sed -e 's/ -O[0-9]* / /' -e 's/ -unroll2 / /' -e 's/ -ip / /' \
-        -e 's/^ //' -e 's/ $//'`
 
 # Add -g and --with-debug.
+DEBUG=1
 cd mysql-debug-%{mysql_version} &&
 CFLAGS="$CFLAGS" \
 CXXFLAGS="$CXXFLAGS" \
-BuildMySQL "\
-		--with-debug \
-		--with-comment=\"MySQL Community Server - Debug (%{mysql_license})\"")
+BuildMySQL 
+)
 
 # We might want to save the config log file
 if test -n "$MYSQL_DEBUGCONFLOG_DEST"
@@ -417,12 +514,12 @@ fi
 #
 ##############################################################################
 
+DEBUG=0
 (cd mysql-release-%{mysql_version} &&
 CFLAGS="$CFLAGS" \
 CXXFLAGS="$CXXFLAGS" \
-BuildMySQL "\
-		--with-embedded-server \
-		--with-comment=\"MySQL Community Server (%{mysql_license})\"")
+BuildMySQL 
+)
 # We might want to save the config log file
 if test -n "$MYSQL_CONFLOG_DEST"
 then
@@ -433,15 +530,27 @@ fi
 
 ##############################################################################
 
-# Include libgcc.a in the devel subpackage (BUG 4921)
-if expr "$CC" : ".*gcc.*" > /dev/null ;
+# For gcc builds, include libgcc.a in the devel subpackage (BUG 4921)
+# Some "icc" calls may have "gcc" in the argument string, so we should first
+# check for "icc". (If we don't check, the "--print-libgcc-file" call will fail.)
+if expr "$CC" : ".*icc.*" > /dev/null ;
+then
+    %define WITH_LIBGCC 0
+    :
+elif expr "$CC" : ".*gcc.*" > /dev/null ;
 then
   libgcc=`$CC $CFLAGS --print-libgcc-file`
   if [ -f $libgcc ]
   then
-    %define have_libgcc 1
+    %define WITH_LIBGCC 1
     install -m 644 $libgcc $RBR%{_libdir}/mysql/libmygcc.a
+  else
+    %define WITH_LIBGCC 0
+    :
   fi
+else
+    %define WITH_LIBGCC 0
+    :
 fi
 
 ##############################################################################
@@ -460,7 +569,7 @@ install -d $RBR%{_mandir}
 install -d $RBR%{_sbindir}
 
 
-# Install all binaries 
+# Install all binaries
 (cd $MBD && make install DESTDIR=$RBR testroot=%{_datadir})
 # Old packages put shared libs in %{_libdir}/ (not %{_libdir}/mysql), so do
 # the same here.
@@ -478,15 +587,17 @@ install -m 755 $MBD/extra/perror $RBR%{_
 install -m 644 $MBD/support-files/mysql-log-rotate $RBR%{_sysconfdir}/logrotate.d/mysql
 install -m 755 $MBD/support-files/mysql.server $RBR%{_sysconfdir}/init.d/mysql
 
+%if %{EMBEDDED_BUILD}
 # Install embedded server library in the build root
 install -m 644 $MBD/libmysqld/libmysqld.a $RBR%{_libdir}/mysql/
+%endif
 
 # in RPMs, it is unlikely that anybody should use "sql-bench"
 rm -fr $RBR%{_datadir}/sql-bench
 
 # Create a symlink "rcmysql", pointing to the init.script. SuSE users
 # will appreciate that, as all services usually offer this.
-ln -s %{_sysconfdir}/init.d/mysql $RPM_BUILD_ROOT%{_sbindir}/rcmysql
+ln -s %{_sysconfdir}/init.d/mysql $RBR%{_sbindir}/rcmysql
 
 # Touch the place where the my.cnf config file and mysqlmanager.passwd
 # (MySQL Instance Manager password file) might be located
@@ -494,6 +605,10 @@ ln -s %{_sysconfdir}/init.d/mysql $RPM_B
 touch $RBR%{_sysconfdir}/my.cnf
 touch $RBR%{_sysconfdir}/mysqlmanager.passwd
 
+##############################################################################
+#  Post processing actions, i.e. when installed
+##############################################################################
+
 %pre server
 # Check if we can safely upgrade.  An upgrade is only safe if it's from one
 # of our RPMs in the same version family.
@@ -503,6 +618,7 @@ if [ $? -eq 0 -a -n "$installed" ]; then
   vendor=`rpm -q --queryformat='%{VENDOR}' "$installed" 2>&1`
   version=`rpm -q --queryformat='%{VERSION}' "$installed" 2>&1`
   myoldvendor='%{mysql_old_vendor}'
+  myvendor_2='%{mysql_vendor_2}'
   myvendor='%{mysql_vendor}'
   myversion='%{mysql_version}'
 
@@ -514,10 +630,10 @@ if [ $? -eq 0 -a -n "$installed" ]; then
   [ -z "$new_family" ] && new_family="<bad package specification: version $myversion>"
 
   error_text=
-  if [ "$vendor" != "$myoldvendor" -a "$vendor" != "$myvendor" ]; then
+  if [ "$vendor" != "$myoldvendor" -a "$vendor" != "$myvendor_2" -a "$vendor" != "$myvendor" ]; then
     error_text="$error_text
 The current MySQL server package is provided by a different
-vendor ($vendor) than $myoldvendor or $myvendor.
+vendor ($vendor) than $myoldvendor, $myvendor_2, or $myvendor.
 Some files may be installed to different locations, including log
 files and the service startup script in %{_sysconfdir}/init.d/.
 "
@@ -563,58 +679,66 @@ HERE
 fi
 
 # Shut down a previously installed server first
-if test -x %{_sysconfdir}/init.d/mysql
-then
-  %{_sysconfdir}/init.d/mysql stop > /dev/null 2>&1
-  echo "Giving mysqld a couple of seconds to exit nicely"
-  sleep 5
-elif test -x %{_sysconfdir}/rc.d/init.d/mysql
-then
-  %{_sysconfdir}/rc.d/init.d/mysql stop > /dev/null 2>&1
-  echo "Giving mysqld a couple of seconds to exit nicely"
-  sleep 5
+if [ -x %{_sysconfdir}/init.d/mysql ] ; then
+	%{_sysconfdir}/init.d/mysql stop > /dev/null 2>&1
+	echo "Giving mysqld 5 seconds to exit nicely"
+	sleep 5
 fi
 
 %post server
 mysql_datadir=%{mysqldatadir}
 
+# ----------------------------------------------------------------------
 # Create data directory if needed
-if test ! -d $mysql_datadir; then mkdir -m 755 $mysql_datadir; fi
-if test ! -d $mysql_datadir/mysql; then mkdir $mysql_datadir/mysql; fi
-if test ! -d $mysql_datadir/test; then mkdir $mysql_datadir/test; fi
+# ----------------------------------------------------------------------
+if [ ! -d $mysql_datadir ] ; then mkdir -m 755 $mysql_datadir; fi
+if [ ! -d $mysql_datadir/mysql ] ; then mkdir $mysql_datadir/mysql; fi
+if [ ! -d $mysql_datadir/test ] ; then mkdir $mysql_datadir/test; fi
 
+# ----------------------------------------------------------------------
 # Make MySQL start/shutdown automatically when the machine does it.
+# ----------------------------------------------------------------------
 # use insserv for older SuSE Linux versions
-if test -x /sbin/insserv
-then
+if [ -x /sbin/insserv ] ; then
 	/sbin/insserv %{_sysconfdir}/init.d/mysql
 # use chkconfig on Red Hat and newer SuSE releases
-elif test -x /sbin/chkconfig
-then
+elif [ -x /sbin/chkconfig ] ; then
 	/sbin/chkconfig --add mysql
 fi
 
+# ----------------------------------------------------------------------
 # Create a MySQL user and group. Do not report any problems if it already
 # exists.
+# ----------------------------------------------------------------------
 groupadd -r %{mysqld_group} 2> /dev/null || true
-useradd -M -r -d $mysql_datadir -s /bin/bash -c "MySQL server" -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true 
+useradd -M -r -d $mysql_datadir -s /bin/bash -c "MySQL server" -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true
 # The user may already exist, make sure it has the proper group nevertheless (BUG#12823)
 usermod -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true
 
+# ----------------------------------------------------------------------
 # Change permissions so that the user that will run the MySQL daemon
 # owns all database files.
+# ----------------------------------------------------------------------
 chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir
 
+# ----------------------------------------------------------------------
 # Initiate databases if needed
+# ----------------------------------------------------------------------
 %{_bindir}/mysql_install_db --rpm --user=%{mysqld_user}
 
+# ----------------------------------------------------------------------
 # Upgrade databases if needed would go here - but it cannot be automated yet
+# ----------------------------------------------------------------------
 
+# ----------------------------------------------------------------------
 # Change permissions again to fix any new files.
+# ----------------------------------------------------------------------
 chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir
 
+# ----------------------------------------------------------------------
 # Fix permissions for the permission database so that only the user
 # can read them.
+# ----------------------------------------------------------------------
 chmod -R og-rw $mysql_datadir/mysql
 
 # Restart in the same way that mysqld will be started normally.
@@ -627,7 +751,7 @@ sleep 2
 #systems, we recommend MySQL Enterprise, which contains enterprise-ready
 #software, intelligent advisory services, and full production support with
 #scheduled service packs and more.  Visit www.mysql.com/enterprise for more
-#information." 
+#information."
 
 %if %{CLUSTER_BUILD}
 %post ndb-storage
@@ -638,37 +762,38 @@ if test ! -d $mysql_clusterdir; then mkd
 %endif
 
 %preun server
-if test $1 = 0
-then
-  # Stop MySQL before uninstalling it
-  if test -x %{_sysconfdir}/init.d/mysql
-  then
-    %{_sysconfdir}/init.d/mysql stop > /dev/null
-
-    # Remove autostart of mysql
-    # for older SuSE Linux versions
-    if test -x /sbin/insserv
-    then
-      /sbin/insserv -r %{_sysconfdir}/init.d/mysql
-    # use chkconfig on Red Hat and newer SuSE releases
-    elif test -x /sbin/chkconfig
-    then
-      /sbin/chkconfig --del mysql
-    fi
-  fi
+if [ $1 = 0 ] ; then
+	# Stop MySQL before uninstalling it
+	if [ -x %{_sysconfdir}/init.d/mysql ] ; then
+		%{_sysconfdir}/init.d/mysql stop > /dev/null
+		# Remove autostart of MySQL
+		# For older SuSE Linux versions
+		if [ -x /sbin/insserv ] ; then
+			/sbin/insserv -r %{_sysconfdir}/init.d/mysql
+		# use chkconfig on Red Hat and newer SuSE releases
+		elif [ -x /sbin/chkconfig ] ; then
+			/sbin/chkconfig --del mysql
+		fi
+	fi
 fi
 
 # We do not remove the mysql user since it may still own a lot of
 # database files.
 
-# Clean up the BuildRoot
+# ----------------------------------------------------------------------
+# Clean up the BuildRoot after build is done
+# ----------------------------------------------------------------------
 %clean
 [ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT;
 
+##############################################################################
+#  Files section
+##############################################################################
+
 %files server
 %defattr(-,root,root,0755)
 
-%doc mysql-release-%{mysql_version}/COPYING mysql-release-%{mysql_version}/README 
+%doc mysql-release-%{mysql_version}/COPYING mysql-release-%{mysql_version}/README
 %doc mysql-release-%{mysql_version}/support-files/my-*.cnf
 %if %{CLUSTER_BUILD}
 %doc mysql-release-%{mysql_version}/support-files/ndb-*.ini
@@ -676,17 +801,24 @@ fi
 
 %doc %attr(644, root, root) %{_infodir}/mysql.info*
 
+%if %{INNODB_BUILD}
 %doc %attr(644, root, man) %{_mandir}/man1/innochecksum.1*
+%endif
 %doc %attr(644, root, man) %{_mandir}/man1/my_print_defaults.1*
 %doc %attr(644, root, man) %{_mandir}/man1/myisam_ftdump.1*
 %doc %attr(644, root, man) %{_mandir}/man1/myisamchk.1*
 %doc %attr(644, root, man) %{_mandir}/man1/myisamlog.1*
 %doc %attr(644, root, man) %{_mandir}/man1/myisampack.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_convert_table_format.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_fix_extensions.1*
 %doc %attr(644, root, man) %{_mandir}/man8/mysqld.8*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqld_multi.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqld_safe.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysqldumpslow.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_fix_privilege_tables.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_install_db.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_secure_installation.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_setpermission.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_upgrade.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqlhotcopy.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqlman.1*
@@ -698,11 +830,15 @@ fi
 %doc %attr(644, root, man) %{_mandir}/man1/mysqlbug.1*
 %doc %attr(644, root, man) %{_mandir}/man1/perror.1*
 %doc %attr(644, root, man) %{_mandir}/man1/replace.1*
+%doc %attr(644, root, man) %{_mandir}/man1/resolve_stack_dump.1*
+%doc %attr(644, root, man) %{_mandir}/man1/resolveip.1*
 
 %ghost %config(noreplace,missingok) %{_sysconfdir}/my.cnf
 %ghost %config(noreplace,missingok) %{_sysconfdir}/mysqlmanager.passwd
 
+%if %{INNODB_BUILD}
 %attr(755, root, root) %{_bindir}/innochecksum
+%endif
 %attr(755, root, root) %{_bindir}/my_print_defaults
 %attr(755, root, root) %{_bindir}/myisam_ftdump
 %attr(755, root, root) %{_bindir}/myisamchk
@@ -728,16 +864,16 @@ fi
 %attr(755, root, root) %{_bindir}/resolve_stack_dump
 %attr(755, root, root) %{_bindir}/resolveip
 
-%attr(755, root, root) %{_libdir}/mysql/plugin/ha_example.so*
-%if %{WITHOUT_INNODB_PLUGIN}
-%else
-%attr(755, root, root) %{_libdir}/mysql/plugin/ha_innodb_plugin.so*
-%endif
-
 %attr(755, root, root) %{_sbindir}/mysqld
 %attr(755, root, root) %{_sbindir}/mysqld-debug
 %attr(755, root, root) %{_sbindir}/mysqlmanager
 %attr(755, root, root) %{_sbindir}/rcmysql
+%if %{INNODB_BUILD}
+%if %{WITH_INNODB_PLUGIN}
+%attr(755, root, root) %{_libdir}/mysql/plugin/ha_innodb_plugin.so*
+%endif
+%endif
+%attr(755, root, root) %{_libdir}/mysql/plugin/ha_example.so*
 
 %attr(644, root, root) %config(noreplace,missingok) %{_sysconfdir}/logrotate.d/mysql
 %attr(755, root, root) %{_sysconfdir}/init.d/mysql
@@ -841,7 +977,7 @@ fi
 %{_datadir}/aclocal/mysql.m4
 %{_libdir}/mysql/libdbug.a
 %{_libdir}/mysql/libheap.a
-%if %{have_libgcc}
+%if %{WITH_LIBGCC}
 %{_libdir}/mysql/libmygcc.a
 %endif
 %{_libdir}/mysql/libmyisam.a
@@ -861,11 +997,12 @@ fi
 %{_libdir}/mysql/libz.la
 %{_libdir}/mysql/plugin/ha_example.a
 %{_libdir}/mysql/plugin/ha_example.la
-%if %{WITHOUT_INNODB_PLUGIN}
-%else
+%if %{INNODB_BUILD}
+%if %{WITH_INNODB_PLUGIN}
 %{_libdir}/mysql/plugin/ha_innodb_plugin.a
 %{_libdir}/mysql/plugin/ha_innodb_plugin.la
 %endif
+%endif
 
 %files shared
 %defattr(-, root, root, 0755)
@@ -879,22 +1016,55 @@ fi
 %defattr(-, root, root, 0755)
 %attr(-, root, root) %{_datadir}/mysql-test
 %attr(755, root, root) %{_bindir}/mysql_client_test
-%attr(755, root, root) %{_bindir}/mysql_client_test_embedded
-%attr(755, root, root) %{_bindir}/mysqltest_embedded
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_client_test.1*
-%doc %attr(644, root, man) %{_mandir}/man1/mysql_client_test_embedded.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql-stress-test.pl.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql-test-run.pl.1*
+%if %{EMBEDDED_BUILD}
+%attr(755, root, root) %{_bindir}/mysql_client_test_embedded
+%attr(755, root, root) %{_bindir}/mysqltest_embedded
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_client_test_embedded.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqltest_embedded.1*
+%endif
 
+%if %{EMBEDDED_BUILD}
 %files embedded
-%defattr(-, root, root, 0755) 
+%defattr(-, root, root, 0755)
 %attr(644, root, root) %{_libdir}/mysql/libmysqld.a
+%endif
 
+##############################################################################
 # The spec file changelog only includes changes made to the spec file
 # itself - note that they must be ordered by date (important when
 # merging BK trees)
+##############################################################################
 %changelog
+* Mon Mar 01 2010 Joerg Bruehe <joerg.bruehe@stripped>
+
+- Set "Oracle and/or its affiliates" as the vendor and copyright owner,
+  accept upgrading from packages showing MySQL or Sun as vendor.
+
+* Fri Feb 05 2010 Joerg Bruehe <joerg.bruehe@stripped>
+
+- Formatting changes:
+  Have a consistent structure of separator lines and of indentation
+  (8 leading blanks => tab).
+- Introduce the variable "src_dir".
+- Give the environment variables "MYSQL_BUILD_CC(CXX)" precedence
+  over "CC" ("CXX").
+- Drop the old "with_static" argument analysis, this is not supported
+  in 5.1 since ages.
+- Introduce variables to control the handlers individually, as well
+  as other options.
+- Handle the InnoDB plugin using a positive logic: "WITH_INNODB_PLUGIN",
+  the old negative logic ("WITHOUT_INNODB_PLUGIN") was obfuscating.
+- Use the new "--with-plugin" notation for the table handlers.
+- Drop handling "/etc/rc.d/init.d/mysql", the switch to "/etc/init.d/mysql"
+  was done back in 2002 already.
+- Make "--with-zlib-dir=bundled" the default, add an option to disable it.
+- Add missing manual pages to the file list.
+- Improve the runtime check for "libgcc.a", protect it against being tried
+  with the Intel compiler "icc".
+
 * Mon Jan 11 2010 Joerg Bruehe <joerg.bruehe@stripped>
 
 - Change RPM file naming:
@@ -918,7 +1088,7 @@ fi
 
 - Correct yesterday's fix, so that it also works for the last flag,
   and fix a wrong quoting: un-quoted quote marks must not be escaped.
-  
+
 * Thu Nov 06 2008 Kent Boortz <kent.boortz@sun.com>
 
 - Removed "mysql_upgrade_shell"
@@ -928,7 +1098,7 @@ fi
 
 - Modify CFLAGS and CXXFLAGS such that a debug build is not optimized.
   This should cover both gcc and icc flags.  Fixes bug#40546.
-  
+
 * Fri Aug 29 2008 Kent Boortz <kent@stripped>
 
 - Removed the "Federated" storage engine option, and enabled in all
@@ -963,7 +1133,7 @@ fi
 
 * Wed May 02 2007 Joerg Bruehe <joerg@mysql.com>
 
-- "ndb_size.tmpl" is not needed any more, 
+- "ndb_size.tmpl" is not needed any more,
   "man1/mysql_install_db.1" lacked the trailing '*'.
 
 * Sat Apr 07 2007 Kent Boortz <kent@stripped>
@@ -1002,12 +1172,12 @@ fi
 
 * Thu Nov 30 2006 Joerg Bruehe <joerg@stripped>
 
-- Call "make install" using "benchdir_root=%{_datadir}", 
+- Call "make install" using "benchdir_root=%{_datadir}",
   because that is affecting the regression test suite as well.
 
 * Thu Nov 16 2006 Joerg Bruehe <joerg@stripped>
 
-- Explicitly note that the "MySQL-shared" RPMs (as built by MySQL AB) 
+- Explicitly note that the "MySQL-shared" RPMs (as built by MySQL AB)
   replace "mysql-shared" (as distributed by SuSE) to allow easy upgrading
   (bug#22081).
 
@@ -1123,8 +1293,8 @@ fi
 
 * Mon Dec 05 2005 Joerg Bruehe <joerg@stripped>
 
-- Avoid using the "bundled" zlib on "shared" builds: 
-  As it is not installed (on the build system), this gives dependency 
+- Avoid using the "bundled" zlib on "shared" builds:
+  As it is not installed (on the build system), this gives dependency
   problems with "libtool" causing the build to fail.
   (Change was done on Nov 11, but left uncommented.)
 
@@ -1314,7 +1484,7 @@ fi
 
 * Thu Feb 12 2004 Lenz Grimmer <lenz@stripped>
 
-- when using gcc, _always_ use CXX=gcc 
+- when using gcc, _always_ use CXX=gcc
 - replaced Copyright with License field (Copyright is obsolete)
 
 * Tue Feb 03 2004 Lenz Grimmer <lenz@stripped>
@@ -1404,7 +1574,7 @@ fi
 
 * Wed Nov 27 2002 Lenz Grimmer <lenz@strippedm>
 
-- moved init script from /etc/rc.d/init.d to /etc/init.d (the majority of 
+- moved init script from /etc/rc.d/init.d to /etc/init.d (the majority of
   Linux distributions now support this scheme as proposed by the LSB either
   directly or via a compatibility symlink)
 - Use new "restart" init script action instead of starting and stopping
@@ -1419,7 +1589,7 @@ fi
   (mixing 3.23 and 4.0 packages)
 
 * Fri Aug 09 2002 Lenz Grimmer <lenz@strippedom>
- 
+
 - Turn off OpenSSL in MySQL-Max for now until it works properly again
 - enable RAID for the Max binary instead
 - added compatibility link: safe_mysqld -> mysqld_safe to ease the

Thread
bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:3103) Bug#23300Bug#31602 Bug#33717 Bug#35250 Bug#35543 Bug#38901 Bug#39022 Bug#39774Bug#42438...Martin Skold9 Jun