summaryrefslogtreecommitdiff
path: root/mysql-test/include
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/include')
-rw-r--r--mysql-test/include/analyze-sync_with_master.test6
-rw-r--r--mysql-test/include/analyze-timeout.test3
-rw-r--r--mysql-test/include/analyze_failure_sync_with_master.test15
-rw-r--r--mysql-test/include/check-testcase.test52
-rw-r--r--mysql-test/include/check-warnings.test61
-rw-r--r--mysql-test/include/check_events_off.inc31
-rw-r--r--mysql-test/include/circular_rpl_for_4_hosts_init.inc130
-rw-r--r--mysql-test/include/circular_rpl_for_4_hosts_sync.inc23
-rw-r--r--mysql-test/include/cleanup_fake_relay_log.inc16
-rw-r--r--mysql-test/include/commit.inc756
-rw-r--r--mysql-test/include/concurrent.inc644
-rw-r--r--mysql-test/include/connect2.inc56
-rw-r--r--mysql-test/include/ctype_german.inc40
-rw-r--r--mysql-test/include/ddl_i18n.check_events.inc48
-rw-r--r--mysql-test/include/ddl_i18n.check_sp.inc83
-rw-r--r--mysql-test/include/ddl_i18n.check_triggers.inc106
-rw-r--r--mysql-test/include/ddl_i18n.check_views.inc44
-rw-r--r--mysql-test/include/deadlock.inc172
-rw-r--r--mysql-test/include/default_my.cnf25
-rw-r--r--mysql-test/include/default_mysqld.cnf21
-rw-r--r--mysql-test/include/default_ndbd.cnf27
-rw-r--r--mysql-test/include/delete_anonymous_users.inc2
-rw-r--r--mysql-test/include/diff_tables.inc122
-rw-r--r--mysql-test/include/federated.inc23
-rw-r--r--mysql-test/include/federated_cleanup.inc11
-rw-r--r--mysql-test/include/gis_generic.inc35
-rw-r--r--mysql-test/include/grant_cache.inc203
-rw-r--r--mysql-test/include/handler.inc720
-rw-r--r--mysql-test/include/have_32bit.inc16
-rw-r--r--mysql-test/include/have_64bit.inc14
-rw-r--r--mysql-test/include/have_archive.inc4
-rw-r--r--mysql-test/include/have_bdb.inc4
-rw-r--r--mysql-test/include/have_binlog_format_mixed.inc6
-rw-r--r--mysql-test/include/have_binlog_format_mixed_or_row.inc7
-rw-r--r--mysql-test/include/have_binlog_format_mixed_or_statement.inc8
-rw-r--r--mysql-test/include/have_binlog_format_row.inc6
-rw-r--r--mysql-test/include/have_binlog_format_row_or_statement.inc7
-rw-r--r--mysql-test/include/have_binlog_format_statement.inc6
-rw-r--r--mysql-test/include/have_blackhole.inc9
-rw-r--r--mysql-test/include/have_bug25714.inc7
-rw-r--r--mysql-test/include/have_case_insensitive_file_system.inc4
-rw-r--r--mysql-test/include/have_community_features.inc4
-rw-r--r--mysql-test/include/have_cp1251.inc7
-rw-r--r--mysql-test/include/have_cp866.inc7
-rw-r--r--mysql-test/include/have_csv.inc4
-rw-r--r--mysql-test/include/have_debug.inc2
-rw-r--r--mysql-test/include/have_example_plugin.inc16
-rw-r--r--mysql-test/include/have_exampledb.inc4
-rw-r--r--mysql-test/include/have_federated_db.inc4
-rw-r--r--mysql-test/include/have_innodb.inc4
-rw-r--r--mysql-test/include/have_koi8r.inc7
-rw-r--r--mysql-test/include/have_log_bin.inc8
-rw-r--r--mysql-test/include/have_lowercase0.inc2
-rw-r--r--mysql-test/include/have_lowercase2.inc4
-rw-r--r--mysql-test/include/have_multi_ndb.inc48
-rw-r--r--mysql-test/include/have_ndb.inc21
-rw-r--r--mysql-test/include/have_ndb_extra.inc2
-rw-r--r--mysql-test/include/have_ndbapi_examples.inc4
-rw-r--r--mysql-test/include/have_outfile.inc2
-rw-r--r--mysql-test/include/have_partition.inc4
-rw-r--r--mysql-test/include/have_query_cache.inc3
-rw-r--r--mysql-test/include/have_simple_parser.inc16
-rw-r--r--mysql-test/include/have_symlink.inc10
-rw-r--r--mysql-test/include/have_udf.inc4
-rw-r--r--mysql-test/include/have_utf8.inc7
-rw-r--r--mysql-test/include/im_check_env.inc25
-rw-r--r--mysql-test/include/index_merge1.inc530
-rw-r--r--mysql-test/include/index_merge2.inc345
-rw-r--r--mysql-test/include/index_merge_2sweeps.inc65
-rw-r--r--mysql-test/include/index_merge_ror.inc289
-rw-r--r--mysql-test/include/index_merge_ror_cpk.inc128
-rw-r--r--mysql-test/include/innodb_rollback_on_timeout.inc4
-rw-r--r--mysql-test/include/innodb_trx_weight.inc51
-rw-r--r--mysql-test/include/is_embedded.inc5
-rw-r--r--mysql-test/include/linux_sys_vars.inc33
-rw-r--r--mysql-test/include/load_sysvars.inc15
-rw-r--r--mysql-test/include/loaddata_autocom.inc12
-rw-r--r--mysql-test/include/master-slave-end.inc6
-rw-r--r--mysql-test/include/master-slave-reset.inc36
-rw-r--r--mysql-test/include/master-slave.inc24
-rw-r--r--mysql-test/include/mix1.inc1478
-rw-r--r--mysql-test/include/mix2.inc2477
-rw-r--r--mysql-test/include/mix2_ucs2.inc228
-rw-r--r--mysql-test/include/mtr_check.sql59
-rw-r--r--mysql-test/include/mtr_warnings.sql238
-rw-r--r--mysql-test/include/mysqlbinlog_row_engine.inc1922
-rw-r--r--mysql-test/include/mysqltest-x.inc1
-rw-r--r--mysql-test/include/ndb_backup.inc22
-rw-r--r--mysql-test/include/ndb_master-slave.inc20
-rw-r--r--mysql-test/include/ndb_master-slave_2ch.inc136
-rw-r--r--mysql-test/include/ndb_not_readonly.inc30
-rw-r--r--mysql-test/include/ndb_restore_master.inc8
-rw-r--r--mysql-test/include/ndb_restore_slave_eoption.inc11
-rw-r--r--mysql-test/include/ndb_setup_slave.inc27
-rw-r--r--mysql-test/include/no_running_event_scheduler.inc23
-rw-r--r--mysql-test/include/no_running_events.inc25
-rw-r--r--mysql-test/include/not_as_root.inc7
-rw-r--r--mysql-test/include/not_embedded.inc2
-rw-r--r--mysql-test/include/not_ndb.inc7
-rw-r--r--mysql-test/include/not_ndb_default.inc4
-rw-r--r--mysql-test/include/not_valgrind.inc4
-rw-r--r--mysql-test/include/not_windows.inc2
-rw-r--r--mysql-test/include/one_thread_per_connection.inc5
-rwxr-xr-xmysql-test/include/parser_bug21114.inc59
-rw-r--r--mysql-test/include/ps_ddl_1.inc25
-rw-r--r--mysql-test/include/ps_modify.inc4
-rw-r--r--mysql-test/include/query_cache.inc182
-rw-r--r--mysql-test/include/query_cache_sql_prepare.inc497
-rw-r--r--mysql-test/include/read_many_rows.inc167
-rw-r--r--mysql-test/include/report-features.test1
-rw-r--r--mysql-test/include/reset_master_and_slave.inc8
-rw-r--r--mysql-test/include/restart_mysqld.inc25
-rw-r--r--mysql-test/include/rowid_order.inc121
-rw-r--r--mysql-test/include/rpl_events.inc159
-rw-r--r--mysql-test/include/rpl_multi_engine.inc16
-rw-r--r--mysql-test/include/rpl_multi_engine2.inc91
-rw-r--r--mysql-test/include/rpl_multi_engine3.inc61
-rw-r--r--mysql-test/include/rpl_stmt_seq.inc114
-rw-r--r--mysql-test/include/rpl_udf.inc189
-rw-r--r--mysql-test/include/running_event_scheduler.inc30
-rw-r--r--mysql-test/include/safe_set_to_maybe_ro_var.inc23
-rw-r--r--mysql-test/include/select_ndb_apply_status.inc13
-rw-r--r--mysql-test/include/set_binlog_format_mixed.sql2
-rw-r--r--mysql-test/include/set_binlog_format_row.sql2
-rw-r--r--mysql-test/include/set_binlog_format_statement.sql2
-rw-r--r--mysql-test/include/setup_fake_relay_log.inc77
-rw-r--r--mysql-test/include/show_binary_logs.inc6
-rw-r--r--mysql-test/include/show_binlog_events.inc6
-rw-r--r--mysql-test/include/show_binlog_events2.inc2
-rw-r--r--mysql-test/include/show_binlog_using_logname.inc13
-rw-r--r--mysql-test/include/show_master_logs.inc5
-rw-r--r--mysql-test/include/show_master_status.inc5
-rw-r--r--mysql-test/include/show_rpl_debug_info.inc87
-rw-r--r--mysql-test/include/show_slave_status.inc6
-rw-r--r--mysql-test/include/show_slave_status2.inc8
-rw-r--r--mysql-test/include/start_slave.inc21
-rw-r--r--mysql-test/include/stop_slave.inc21
-rw-r--r--mysql-test/include/sync_slave_io_with_master.inc36
-rw-r--r--mysql-test/include/system_db_struct.inc4
-rw-r--r--mysql-test/include/test_fieldsize.inc40
-rw-r--r--mysql-test/include/testdb_only.inc12
-rw-r--r--mysql-test/include/tpcb.inc155
-rw-r--r--mysql-test/include/tpcb_disk_data.inc166
-rw-r--r--mysql-test/include/unsafe_binlog.inc265
-rw-r--r--mysql-test/include/varchar.inc12
-rw-r--r--mysql-test/include/wait_condition_sp.inc62
-rw-r--r--mysql-test/include/wait_for_binlog_event.inc33
-rw-r--r--mysql-test/include/wait_for_query_to_succeed.inc (renamed from mysql-test/include/wait_for_query_to_suceed.inc)4
-rw-r--r--mysql-test/include/wait_for_slave_io_to_start.inc19
-rw-r--r--mysql-test/include/wait_for_slave_io_to_stop.inc51
-rw-r--r--mysql-test/include/wait_for_slave_param.inc90
-rw-r--r--mysql-test/include/wait_for_slave_sql_error.inc39
-rw-r--r--mysql-test/include/wait_for_slave_sql_error_and_skip.inc38
-rw-r--r--mysql-test/include/wait_for_slave_sql_to_start.inc17
-rw-r--r--mysql-test/include/wait_for_slave_sql_to_stop.inc48
-rw-r--r--mysql-test/include/wait_for_slave_to_start.inc51
-rw-r--r--mysql-test/include/wait_for_slave_to_stop.inc57
-rw-r--r--mysql-test/include/wait_show_pattern.inc51
-rw-r--r--mysql-test/include/wait_slave_status.inc129
-rw-r--r--mysql-test/include/wait_until_connected_again.inc24
-rw-r--r--mysql-test/include/wait_until_disconnected.inc21
-rw-r--r--mysql-test/include/wait_until_rows_count.inc20
-rw-r--r--mysql-test/include/windows_sys_vars.inc33
163 files changed, 14966 insertions, 630 deletions
diff --git a/mysql-test/include/analyze-sync_with_master.test b/mysql-test/include/analyze-sync_with_master.test
new file mode 100644
index 00000000000..684c0dbbab7
--- /dev/null
+++ b/mysql-test/include/analyze-sync_with_master.test
@@ -0,0 +1,6 @@
+SHOW PROCESSLIST;
+
+let $binlog_name= query_get_value("SHOW MASTER STATUS", File, 1);
+eval SHOW BINLOG EVENTS IN '$binlog_name';
+
+exit; \ No newline at end of file
diff --git a/mysql-test/include/analyze-timeout.test b/mysql-test/include/analyze-timeout.test
new file mode 100644
index 00000000000..179ad8f748a
--- /dev/null
+++ b/mysql-test/include/analyze-timeout.test
@@ -0,0 +1,3 @@
+SHOW PROCESSLIST;
+
+exit;
diff --git a/mysql-test/include/analyze_failure_sync_with_master.test b/mysql-test/include/analyze_failure_sync_with_master.test
deleted file mode 100644
index e6fd32d2f46..00000000000
--- a/mysql-test/include/analyze_failure_sync_with_master.test
+++ /dev/null
@@ -1,15 +0,0 @@
-# Connect to both master and slave
-connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
-connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
-
-vertical_results;
-
-echo == MASTER ===========================================================;
-connection master;
-show master status;
-show slave status;
-
-echo == SLAVE ===========================================================;
-connection slave;
-show master status;
-show slave status;
diff --git a/mysql-test/include/check-testcase.test b/mysql-test/include/check-testcase.test
index a9885f7b0ec..6dcb01c13cf 100644
--- a/mysql-test/include/check-testcase.test
+++ b/mysql-test/include/check-testcase.test
@@ -1,51 +1,15 @@
+
#
# This test is executed twice for each test case if mysql-test-run is passed
-# the flag --check-testcase.
-# Before every testcase it's run with mysqltest in record mode and will
-# thus produce an output file
-# that can be compared to output from after the tescase.
-# In that way it's possible to check that a testcase does not have
+# the flag --check-testcase. Before every testcase it is run with mysqltest
+# in record mode and will thus produce an output file that can be compared
+# to output from after the tescase.
+# In that way its possible to check that a testcase does not have
# any unwanted side affects.
#
-
-#
-# Dump all global variables
-#
-SHOW GLOBAL VARIABLES WHERE variable_name != 'timestamp';
-
-#
-# Dump all databases
-#
-SHOW DATABASES;
-
-#
-# Dump the "test" database, all it's tables and their data
-#
---exec $MYSQL_DUMP --skip-comments test
-
-#
-# Dump the "mysql" database and it's tables
-# Select data separately to add "order by"
-#
---exec $MYSQL_DUMP --skip-comments --no-data mysql
-use mysql;
-SELECT * FROM columns_priv;
-SELECT * FROM db ORDER BY host, db, user;
-SELECT * FROM func;
-SELECT * FROM help_category;
-SELECT * FROM help_keyword;
-SELECT * FROM help_relation;
-SELECT * FROM help_relation;
-SELECT * FROM host;
-SELECT * FROM proc;
-SELECT * FROM procs_priv;
-SELECT * FROM tables_priv;
-SELECT * FROM time_zone;
-SELECT * FROM time_zone_leap_second;
-SELECT * FROM time_zone_name;
-SELECT * FROM time_zone_transition;
-SELECT * FROM time_zone_transition_type;
-SELECT * FROM user;
+--disable_query_log
+call mtr.check_testcase();
+--enable_query_log
diff --git a/mysql-test/include/check-warnings.test b/mysql-test/include/check-warnings.test
new file mode 100644
index 00000000000..2144957f742
--- /dev/null
+++ b/mysql-test/include/check-warnings.test
@@ -0,0 +1,61 @@
+#
+# This test is executed once after each test to check the servers
+# for unexpected warnings found in the servers error log
+#
+# NOTE! mysql-test-run.pl has already done a rough filtering
+# of the file and written any suspicious lines
+# to $error_log.warnings file
+#
+--disable_query_log
+
+# Don't write these queries to binlog
+set SQL_LOG_BIN=0;
+
+# Turn off any debug crashes, allow the variable to be
+# non existent in release builds
+--error 0,1193
+set debug="";
+
+use mtr;
+
+create temporary table error_log (
+ row int auto_increment primary key,
+ suspicious int default 1,
+ file_name varchar(255),
+ line varchar(1024) default null
+) engine=myisam;
+
+# Get the name of servers error log
+let $log_error= query_get_value(show variables like 'log_error', Value, 1);
+let $log_warning= $log_error.warnings;
+
+# Try tload the warnings into a temporary table,
+# it might fail with error saying "The MySQL server is
+# running with the --secure-file-priv" in which case
+# an attempt to load the file using LOAD DATA LOCAL is made
+--error 0,1290
+eval load data infile '$log_warning' into table error_log
+ fields terminated by 'xykls37' escaped by ''
+ ignore 1 lines
+ (line)
+ set file_name='$log_error';
+
+if ($mysql_errno)
+{
+ # Try LOAD DATA LOCAL
+ eval load data local infile '$log_warning' into table error_log
+ fields terminated by 'xykls37' escaped by ''
+ ignore 1 lines
+ (line)
+ set file_name='$log_error';
+}
+
+# Call check_warnings to filter out any warning in
+# the error_log table
+call mtr.check_warnings(@result);
+if (`select @result = 0`){
+ skip OK;
+}
+--enable_query_log
+echo ^ Found warnings!!;
+exit;
diff --git a/mysql-test/include/check_events_off.inc b/mysql-test/include/check_events_off.inc
new file mode 100644
index 00000000000..599a4b9e504
--- /dev/null
+++ b/mysql-test/include/check_events_off.inc
@@ -0,0 +1,31 @@
+########## include/check_events_off.inc ####################################
+# #
+# Purpose: #
+# Wait till we can expect that we have no event activity till the scheduler is #
+# switched on again. #
+# = There will be no modifications of user tables by existing events #
+# except they use "INSERT DELAYED" or the server system variable #
+# "concurrent_inserts" is not switched off. #
+# Only some storage engines support concurrent_inserts" or "INSERT DELAYED". #
+# #
+# Creation: #
+# 2008-12-19 mleich Implement this check needed for bug fixes in tests #
+# #
+################################################################################
+
+# 1. Check that the server system variable shows the state needed
+if (`SELECT @@global.event_scheduler <> 'OFF'`)
+{
+ --echo # Error: We expect here that the event scheduler is switched off.
+ SELECT @@global.event_scheduler;
+ --echo # Thinkable reasons:
+ --echo # 1. SET GLOBAL event_scheduler = OFF had not the expected effect.
+ --echo # 2. Use of the current routine (include/check_events_off.inc)
+ --echo # within the wrong situation
+ --die
+}
+# 2. Wait till we have no event_scheduler session within the processlist
+--source include/no_running_event_scheduler.inc
+# 3. Wait till we have no event executor sessions within the processlist
+--source include/no_running_events.inc
+
diff --git a/mysql-test/include/circular_rpl_for_4_hosts_init.inc b/mysql-test/include/circular_rpl_for_4_hosts_init.inc
new file mode 100644
index 00000000000..ac6654777db
--- /dev/null
+++ b/mysql-test/include/circular_rpl_for_4_hosts_init.inc
@@ -0,0 +1,130 @@
+#############################################################
+#
+# Author: Serge Kozlov <skozlov@mysql.com>
+# Date: 03/11/2008
+# Purpose: Set up circular replication based on schema
+# A->B->C->D->A
+#
+# Notes:
+# 1. --slave-num=3 must be added to *-master.opt file
+# 2. Even the test uses new names for servers but file names
+# of log files are still old:
+# master_a -> master.[log|err]
+# master_b -> slave.[log|err]
+# master_c -> slave1.[log|err]
+# master_d -> slave2.[log|err]
+#
+#############################################################
+--source include/master-slave.inc
+
+#
+# Set up circular ring by schema A->B->C->D->A
+#
+
+--connection slave
+STOP SLAVE;
+RESET SLAVE;
+
+# master a
+--connection master
+--disconnect master
+connect (master_a,127.0.0.1,root,,test,$MASTER_MYPORT,);
+RESET MASTER;
+--disable_warnings
+STOP SLAVE;
+--enable_warnings
+RESET SLAVE;
+SET auto_increment_increment = 4;
+SET auto_increment_offset = 1;
+let $_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+
+# master b
+--connection slave
+--disconnect slave
+connect (master_b,127.0.0.1,root,,test,$SLAVE_MYPORT,);
+RESET MASTER;
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_A_PORT $_binlog_file MASTER_A_LOG_FILE
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$MASTER_MYPORT,master_user='root',MASTER_LOG_FILE='$_binlog_file'
+SET auto_increment_increment = 4;
+SET auto_increment_offset = 2;
+let $_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+
+# master c
+--connection slave1
+--disconnect slave1
+connect (master_c,127.0.0.1,root,,test,$SLAVE_MYPORT1,);
+RESET MASTER;
+--disable_warnings
+STOP SLAVE;
+--enable_warnings
+RESET SLAVE;
+--replace_result $SLAVE_MYPORT MASTER_B_PORT $_binlog_file MASTER_B_LOG_FILE
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$SLAVE_MYPORT,master_user='root',MASTER_LOG_FILE='$_binlog_file'
+SET auto_increment_increment = 4;
+SET auto_increment_offset = 3;
+let $_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+
+# master d
+connect (master_d,127.0.0.1,root,,test,$SLAVE_MYPORT2,);
+RESET MASTER;
+--disable_warnings
+STOP SLAVE;
+--enable_warnings
+RESET SLAVE;
+--replace_result $SLAVE_MYPORT1 MASTER_C_PORT $_binlog_file MASTER_C_LOG_FILE
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$SLAVE_MYPORT1,master_user='root',MASTER_LOG_FILE='$_binlog_file'
+SET auto_increment_increment = 4;
+SET auto_increment_offset = 4;
+let $_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+
+# master a
+--connection master_a
+--replace_result $SLAVE_MYPORT2 MASTER_D_PORT $_binlog_file MASTER_D_LOG_FILE
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$SLAVE_MYPORT2,master_user='root',MASTER_LOG_FILE='$_binlog_file'
+
+
+
+# Check server_ids: they should be different
+--connection master_a
+let $_id_a= query_get_value(SHOW VARIABLES LIKE 'server_id', Value, 1);
+SHOW VARIABLES LIKE 'auto_increment_%';
+--connection master_b
+let $_id_b= query_get_value(SHOW VARIABLES LIKE 'server_id', Value, 1);
+SHOW VARIABLES LIKE 'auto_increment_%';
+--connection master_c
+let $_id_c= query_get_value(SHOW VARIABLES LIKE 'server_id', Value, 1);
+SHOW VARIABLES LIKE 'auto_increment_%';
+--connection master_d
+let $_id_d= query_get_value(SHOW VARIABLES LIKE 'server_id', Value, 1);
+SHOW VARIABLES LIKE 'auto_increment_%';
+--connection master_a
+let $_compared_ids= (($_id_a <> $_id_b) AND ($_id_a <> $_id_c) AND ($_id_a <> $_id_d) AND ($_id_b <> $_id_c) AND ($_id_b <> $_id_d) AND ($_id_c <> $_id_d)) AS a;
+let $_compared_ids_result= query_get_value(SELECT $_compared_ids, a, 1);
+--echo $_compared_ids_result
+
+# Start ring
+--connection master_a
+connect(slave,127.0.0.1,root,,test,$MASTER_MYPORT);
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+--disconnect slave
+
+--connection master_b
+connect(slave,127.0.0.1,root,,test,$SLAVE_MYPORT1);
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+--disconnect slave
+
+--connection master_c
+connect(slave,127.0.0.1,root,,test,$SLAVE_MYPORT);
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+--disconnect slave
+
+--connection master_d
+connect(slave,127.0.0.1,root,,test,$SLAVE_MYPORT2);
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+--disconnect slave
+
diff --git a/mysql-test/include/circular_rpl_for_4_hosts_sync.inc b/mysql-test/include/circular_rpl_for_4_hosts_sync.inc
new file mode 100644
index 00000000000..68aede76913
--- /dev/null
+++ b/mysql-test/include/circular_rpl_for_4_hosts_sync.inc
@@ -0,0 +1,23 @@
+#############################################################
+#
+# Author: Serge Kozlov <skozlov@mysql.com>
+# Date: 03/11/2008
+# Purpose: Sync all hosts for circular replication based on
+# schema A->B->C->D->A
+#
+# Notes: see include/circular_rpl_for_4_hosts_init.inc
+#
+#############################################################
+
+# Make the full loop of sync
+--connection master_a
+--disable_query_log
+--sync_slave_with_master master_b
+--sync_slave_with_master master_c
+--sync_slave_with_master master_d
+--sync_slave_with_master master_a
+--sync_slave_with_master master_b
+--sync_slave_with_master master_c
+--save_master_pos
+--connection master_a
+--enable_query_log
diff --git a/mysql-test/include/cleanup_fake_relay_log.inc b/mysql-test/include/cleanup_fake_relay_log.inc
new file mode 100644
index 00000000000..43aa46cb657
--- /dev/null
+++ b/mysql-test/include/cleanup_fake_relay_log.inc
@@ -0,0 +1,16 @@
+# ==== Purpose ====
+#
+# Clean up files create by setup_fake_relay_log.inc.
+#
+# ==== Usage ====
+#
+# See setup_fake_relay_log.inc
+
+--echo Cleaning up after setup_fake_relay_log.inc
+
+# Remove files.
+remove_file $_fake_relay_log;
+remove_file $_fake_relay_index;
+--disable_query_log
+eval SET @@global.relay_log_purge= $_fake_relay_log_purge;
+--enable_query_log
diff --git a/mysql-test/include/commit.inc b/mysql-test/include/commit.inc
new file mode 100644
index 00000000000..a4e7d9ae601
--- /dev/null
+++ b/mysql-test/include/commit.inc
@@ -0,0 +1,756 @@
+## Bug#12713 (Error in a stored function called from a SELECT doesn't cause
+## ROLLBACK of statem)
+
+##
+## Pre-Requisites :
+## - $engine_type should be set
+##
+
+set sql_mode=no_engine_substitution;
+eval set storage_engine = $engine_type;
+set autocommit=1;
+
+--disable_warnings
+drop table if exists t1;
+drop table if exists t2;
+drop table if exists t3;
+drop function if exists f2;
+drop procedure if exists bug12713_call;
+drop procedure if exists bug12713_dump_spvars;
+drop procedure if exists dummy;
+--enable_warnings
+
+create table t1 (a int);
+create table t2 (a int unique);
+create table t3 (a int);
+
+# a workaround for Bug#32633: Can not create any routine if
+# SQL_MODE=no_engine_substitution
+
+set sql_mode=default;
+
+insert into t1 (a) values (1), (2);
+insert into t3 (a) values (1), (2);
+
+delimiter |;
+
+## Cause a failure every time
+create function f2(x int) returns int
+begin
+ insert into t2 (a) values (x);
+ insert into t2 (a) values (x);
+ return x;
+end|
+
+delimiter ;|
+
+set autocommit=0;
+
+flush status;
+##============================================================================
+## Design notes
+##
+## In each case, statement rollback is expected.
+## for transactional engines, the rollback should be properly executed
+## for non transactional engines, the rollback may cause warnings.
+##
+## The test pattern is as follows
+## - insert 1000+N
+## - statement with a side effect, that fails to insert N twice
+## - a statement rollback is expected (expecting 1 row 1000+N only) in t2
+## - a rollback is performed
+## - expecting a clean table t2.
+##============================================================================
+
+insert into t2 (a) values (1001);
+--error ER_DUP_ENTRY
+insert into t1 (a) values (f2(1));
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1002);
+--error ER_DUP_ENTRY
+insert into t3 (a) select f2(2) from t1;
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1003);
+--error ER_DUP_ENTRY
+update t1 set a= a + f2(3);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1004);
+--error ER_DUP_ENTRY
+update t1, t3 set t1.a = 0, t3.a = 0 where (f2(4) = 4) and (t1.a = t3.a);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1005);
+--error ER_DUP_ENTRY
+delete from t1 where (a = f2(5));
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1006);
+--error ER_DUP_ENTRY
+delete from t1, t3 using t1, t3 where (f2(6) = 6) ;
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1007);
+--error ER_DUP_ENTRY
+replace t1 values (f2(7));
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1008);
+--error ER_DUP_ENTRY
+replace into t3 (a) select f2(8) from t1;
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1009);
+--error ER_DUP_ENTRY
+select f2(9) from t1 ;
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1010);
+--error ER_DUP_ENTRY
+show databases where (f2(10) = 10);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1011);
+--error ER_DUP_ENTRY
+show tables where (f2(11) = 11);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1012);
+--error ER_DUP_ENTRY
+show triggers where (f2(12) = 12);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1013);
+--error ER_DUP_ENTRY
+show table status where (f2(13) = 13);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1014);
+--error ER_DUP_ENTRY
+show open tables where (f2(14) = 14);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1015);
+--error ER_DUP_ENTRY
+show columns in mysql.proc where (f2(15) = 15);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1016);
+--error ER_DUP_ENTRY
+show status where (f2(16) = 16);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1017);
+--error ER_DUP_ENTRY
+show variables where (f2(17) = 17);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1018);
+--error ER_DUP_ENTRY
+show charset where (f2(18) = 18);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1019);
+--error ER_DUP_ENTRY
+show collation where (f2(19) = 19);
+select * from t2;
+rollback;
+select * from t2;
+
+--echo # We need at least one procedure to make sure the WHERE clause is
+--echo # evaluated
+create procedure dummy() begin end;
+insert into t2 (a) values (1020);
+--error ER_DUP_ENTRY
+show procedure status where (f2(20) = 20);
+select * from t2;
+rollback;
+select * from t2;
+drop procedure dummy;
+
+insert into t2 (a) values (1021);
+--error ER_DUP_ENTRY
+show function status where (f2(21) = 21);
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1022);
+prepare stmt from "insert into t1 (a) values (f2(22))";
+--error ER_DUP_ENTRY
+execute stmt;
+select * from t2;
+rollback;
+select * from t2;
+
+insert into t2 (a) values (1023);
+do (f2(23));
+select * from t2;
+rollback;
+select * from t2;
+
+## Please note :
+## This will insert a record 1024 in t1 (statement commit)
+## This will insert a record 24 in t1 (statement commit)
+## then will rollback the second insert only (24) (statement rollback)
+## then will rollback the complete transaction (transaction rollback)
+
+delimiter |;
+
+create procedure bug12713_call ()
+begin
+ insert into t2 (a) values (24);
+ insert into t2 (a) values (24);
+end|
+
+delimiter ;|
+
+insert into t2 (a) values (1024);
+--error ER_DUP_ENTRY
+call bug12713_call();
+select * from t2;
+rollback;
+select * from t2;
+
+--echo =======================================================================
+--echo Testing select_to_file
+--echo =======================================================================
+
+insert into t2 (a) values (1025);
+
+--replace_result $MYSQLTEST_VARDIR ..
+--error ER_DUP_ENTRY
+eval select f2(25) into outfile "$MYSQLTEST_VARDIR/tmp/dml.out" from t1;
+select * from t2;
+rollback;
+select * from t2;
+--remove_file $MYSQLTEST_VARDIR/tmp/dml.out
+
+insert into t2 (a) values (1026);
+--replace_result $MYSQLTEST_VARDIR ..
+--error ER_DUP_ENTRY
+eval load data infile "../../std_data/words.dat" into table t1 (a) set a:=f2(26);
+
+select * from t2;
+rollback;
+select * from t2;
+
+--echo =======================================================================
+--echo Testing select_dumpvar
+--echo =======================================================================
+
+insert into t2 (a) values (1027);
+--error ER_DUP_ENTRY
+select f2(27) into @foo;
+select * from t2;
+rollback;
+select * from t2;
+
+--echo =======================================================================
+--echo Testing Select_fetch_into_spvars
+--echo =======================================================================
+
+delimiter |;
+
+create procedure bug12713_dump_spvars ()
+begin
+ declare foo int;
+
+ declare continue handler for sqlexception
+ begin
+ select "Exception trapped";
+ end;
+
+ select f2(28) into foo;
+ select * from t2;
+end|
+
+delimiter ;|
+
+insert into t2 (a) values (1028);
+call bug12713_dump_spvars ();
+rollback;
+select * from t2;
+
+--echo =======================================================================
+--echo Cleanup
+--echo =======================================================================
+
+set autocommit=default;
+
+drop table t1;
+drop table t2;
+drop table t3;
+drop function f2;
+drop procedure bug12713_call;
+drop procedure bug12713_dump_spvars;
+--echo #
+--echo # Bug#12713 Error in a stored function called from a SELECT doesn't
+--echo # cause ROLLBACK of statem
+--echo #
+--echo # Verify that two-phase commit is not issued for read-only
+--echo # transactions.
+--echo #
+--echo # Verify that two-phase commit is issued for read-write transactions,
+--echo # even if the change is done inside a stored function called from
+--echo # SELECT or SHOW statement.
+--echo #
+set autocommit=0;
+--disable_warnings
+drop table if exists t1;
+drop table if exists t2;
+drop function if exists f1;
+drop procedure if exists p_verify_status_increment;
+--enable_warnings
+
+# Save binlog_format in a user variable. References to system
+# variables are "unsafe", meaning they are written as rows instead of
+# as statements to the binlog, if the loggging mode is 'mixed'. But
+# we don't want p_verify_status_increment to affect the logging mode.
+# Hence, we save binlog_format in a user variable (which is not
+# unsafe) and use that inside p_verify_status_increment.
+set @binlog_format=@@global.binlog_format;
+
+set sql_mode=no_engine_substitution;
+create table t1 (a int unique);
+create table t2 (a int) engine=myisam;
+set sql_mode=default;
+--echo #
+--echo # An auxiliary procedure to track Handler_prepare and Handler_commit
+--echo # statistics.
+--echo #
+delimiter |;
+create procedure
+p_verify_status_increment(commit_inc_mixed int, prepare_inc_mixed int,
+ commit_inc_row int, prepare_inc_row int)
+begin
+ declare commit_inc int;
+ declare prepare_inc int;
+ declare old_commit_count int default ifnull(@commit_count, 0);
+ declare old_prepare_count int default ifnull(@prepare_count, 0);
+ declare c_res int;
+# Use a cursor to have just one access to I_S instead of 2, it is very slow
+# and amounts for over 90% of test CPU time
+ declare c cursor for
+ select variable_value
+ from information_schema.session_status
+ where variable_name='Handler_commit' or variable_name='Handler_prepare'
+ order by variable_name;
+
+ if @binlog_format = 'ROW' then
+ set commit_inc= commit_inc_row;
+ set prepare_inc= prepare_inc_row;
+ else
+ set commit_inc= commit_inc_mixed;
+ set prepare_inc= prepare_inc_mixed;
+ end if;
+
+ open c;
+ fetch c into c_res;
+ set @commit_count=c_res;
+ fetch c into c_res;
+ set @prepare_count=c_res;
+ close c;
+
+ if old_commit_count + commit_inc <> @commit_count then
+ select concat("Expected commit increment: ", commit_inc,
+ " actual: ", @commit_count - old_commit_count)
+ as 'ERROR';
+ elseif old_prepare_count + prepare_inc <> @prepare_count then
+ select concat("Expected prepare increment: ", prepare_inc,
+ " actual: ", @prepare_count - old_prepare_count)
+ as 'ERROR';
+ else
+ select '' as 'SUCCESS';
+ end if;
+end|
+delimiter ;|
+--echo # Reset Handler_commit and Handler_prepare counters
+flush status;
+--echo #
+--echo # 1. Read-only statement: SELECT
+--echo #
+select * from t1;
+call p_verify_status_increment(1, 0, 1, 0);
+commit;
+call p_verify_status_increment(1, 0, 1, 0);
+
+--echo # 2. Read-write statement: INSERT, insert 1 row.
+--echo #
+insert into t1 (a) values (1);
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 3. Read-write statement: UPDATE, update 1 row.
+--echo #
+update t1 set a=2;
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 4. Read-write statement: UPDATE, update 0 rows, 1 row matches WHERE
+--echo #
+update t1 set a=2;
+call p_verify_status_increment(2, 2, 1, 0);
+commit;
+call p_verify_status_increment(2, 2, 1, 0);
+
+--echo # 5. Read-write statement: UPDATE, update 0 rows, 0 rows match WHERE
+--echo #
+--echo # In mixed replication mode, there is a read-only transaction
+--echo # in InnoDB and also the statement is written to the binary log.
+--echo # So we have two commits but no 2pc, since the first engine's
+--echo # transaction is read-only.
+--echo # In the row level replication mode, we only have the read-only
+--echo # transaction in InnoDB and nothing is written to the binary log.
+--echo #
+update t1 set a=3 where a=1;
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 6. Read-write statement: DELETE, delete 0 rows.
+--echo #
+delete from t1 where a=1;
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 7. Read-write statement: DELETE, delete 1 row.
+--echo #
+delete from t1 where a=2;
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 8. Read-write statement: unqualified DELETE
+--echo #
+--echo # In statement or mixed replication mode, we call
+--echo # handler::ha_delete_all_rows() and write statement text
+--echo # to the binary log. This results in two read-write transactions.
+--echo # In row level replication mode, we do not call
+--echo # handler::ha_delete_all_rows(), but delete rows one by one.
+--echo # Since there are no rows, nothing is written to the binary log.
+--echo # Thus we have just one read-only transaction in InnoDB.
+delete from t1;
+call p_verify_status_increment(2, 2, 1, 0);
+commit;
+call p_verify_status_increment(2, 2, 1, 0);
+
+--echo # 9. Read-write statement: REPLACE, change 1 row.
+--echo #
+replace t1 set a=1;
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 10. Read-write statement: REPLACE, change 0 rows.
+--echo #
+replace t1 set a=1;
+call p_verify_status_increment(2, 2, 1, 0);
+commit;
+call p_verify_status_increment(2, 2, 1, 0);
+
+--echo # 11. Read-write statement: IODKU, change 1 row.
+--echo #
+insert t1 set a=1 on duplicate key update a=a+1;
+call p_verify_status_increment(2, 2, 2, 2);
+select * from t1;
+call p_verify_status_increment(1, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 12. Read-write statement: IODKU, change 0 rows.
+--echo #
+insert t1 set a=2 on duplicate key update a=2;
+call p_verify_status_increment(1, 0, 1, 0);
+commit;
+call p_verify_status_increment(1, 0, 1, 0);
+
+--echo # 13. Read-write statement: INSERT IGNORE, change 0 rows.
+--echo #
+insert ignore t1 set a=2;
+call p_verify_status_increment(1, 0, 1, 0);
+commit;
+call p_verify_status_increment(1, 0, 1, 0);
+
+--echo # 14. Read-write statement: INSERT IGNORE, change 1 row.
+--echo #
+insert ignore t1 set a=1;
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+--echo # 15. Read-write statement: UPDATE IGNORE, change 0 rows.
+--echo #
+update ignore t1 set a=2 where a=1;
+call p_verify_status_increment(2, 2, 1, 0);
+commit;
+call p_verify_status_increment(2, 2, 1, 0);
+--echo #
+--echo # Create a stored function that modifies a
+--echo # non-transactional table. Demonstrate that changes in
+--echo # non-transactional tables do not affect the two phase commit
+--echo # algorithm.
+--echo #
+delimiter |;
+create function f1() returns int
+begin
+ insert t2 set a=2;
+ return 2;
+end|
+delimiter ;|
+call p_verify_status_increment(0, 0, 0, 0);
+
+--echo # 16. A function changes non-trans-table.
+--echo #
+--echo # For row-based logging, there is an extra commit for the
+--echo # non-transactional changes saved in the transaction cache to
+--echo # the binary log.
+--echo #
+select f1();
+call p_verify_status_increment(0, 0, 1, 0);
+commit;
+call p_verify_status_increment(0, 0, 1, 0);
+
+--echo # 17. Read-only statement, a function changes non-trans-table.
+--echo #
+--echo # For row-based logging, there is an extra commit for the
+--echo # non-transactional changes saved in the transaction cache to
+--echo # the binary log.
+--echo #
+select f1() from t1;
+call p_verify_status_increment(1, 0, 2, 0);
+commit;
+call p_verify_status_increment(1, 0, 2, 0);
+
+--echo # 18. Read-write statement: UPDATE, change 0 (transactional) rows.
+--echo #
+select count(*) from t2;
+update t1 set a=2 where a=f1()+10;
+select count(*) from t2;
+call p_verify_status_increment(2, 0, 2, 0);
+commit;
+call p_verify_status_increment(2, 0, 2, 0);
+--echo #
+--echo # Replace the non-transactional table with a temporary
+--echo # transactional table. Demonstrate that a change to a temporary
+--echo # transactional table does not provoke 2-phase commit, although
+--echo # does trigger a commit and a binlog write (in statement mode).
+--echo #
+drop table t2;
+set sql_mode=no_engine_substitution;
+create temporary table t2 (a int);
+call p_verify_status_increment(0, 0, 0, 0);
+set sql_mode=default;
+--echo # 19. A function changes temp-trans-table.
+--echo #
+select f1();
+--echo # Two commits because a binary log record is written
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 20. Read-only statement, a function changes non-trans-table.
+--echo #
+select f1() from t1;
+--echo # Two commits because a binary log record is written
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 21. Read-write statement: UPDATE, change 0 (transactional) rows.
+--echo #
+update t1 set a=2 where a=f1()+10;
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 22. DDL: ALTER TEMPORARY TABLE, should not cause a 2pc
+--echo #
+alter table t2 add column b int default 5;
+--echo # A commit is done internally by ALTER.
+call p_verify_status_increment(2, 0, 2, 0);
+commit;
+--echo # There is nothing left to commit
+call p_verify_status_increment(0, 0, 0, 0);
+
+--echo # 23. DDL: RENAME TEMPORARY TABLE, does not start a transaction
+--echo
+--echo # No test because of Bug#8729 "rename table fails on temporary table"
+
+--echo # 24. DDL: TRUNCATE TEMPORARY TABLE
+--echo
+truncate table t2;
+call p_verify_status_increment(4, 0, 4, 0);
+commit;
+--echo # There is nothing left to commit
+call p_verify_status_increment(0, 0, 0, 0);
+
+--echo # 25. Read-write statement: unqualified DELETE
+--echo
+delete from t2;
+call p_verify_status_increment(2, 0, 1, 0);
+commit;
+--echo # There is nothing left to commit
+call p_verify_status_increment(2, 0, 1, 0);
+
+--echo # 25. DDL: DROP TEMPORARY TABLE, does not start a transaction
+--echo #
+drop temporary table t2;
+call p_verify_status_increment(0, 0, 0, 0);
+commit;
+call p_verify_status_increment(0, 0, 0, 0);
+
+--echo # 26. Verify that SET AUTOCOMMIT issues an implicit commit
+--echo #
+insert t1 set a=3;
+call p_verify_status_increment(2, 2, 2, 2);
+set autocommit=1;
+call p_verify_status_increment(2, 2, 2, 2);
+rollback;
+select a from t1 where a=3;
+call p_verify_status_increment(1, 0, 1, 0);
+delete from t1 where a=3;
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(0, 0, 0, 0);
+set autocommit=0;
+call p_verify_status_increment(0, 0, 0, 0);
+insert t1 set a=3;
+call p_verify_status_increment(2, 2, 2, 2);
+--echo # Sic: not actually changing the value of autocommit
+set autocommit=0;
+call p_verify_status_increment(0, 0, 0, 0);
+rollback;
+select a from t1 where a=3;
+call p_verify_status_increment(1, 0, 1, 0);
+
+--echo # 27. Savepoint management
+--echo #
+insert t1 set a=3;
+call p_verify_status_increment(2, 2, 2, 2);
+savepoint a;
+call p_verify_status_increment(0, 0, 0, 0);
+insert t1 set a=4;
+--echo # Binlog does not register itself this time for other than the 1st
+--echo # statement of the transaction with MIXED/STATEMENT binlog_format.
+--echo # It needs registering with the ROW format. Therefore 1,0,2,2 are
+--echo # the correct arguments to this test after bug#40221 fixed.
+call p_verify_status_increment(1, 0, 2, 2);
+release savepoint a;
+rollback;
+call p_verify_status_increment(0, 0, 0, 0);
+select a from t1 where a=3;
+call p_verify_status_increment(1, 0, 1, 0);
+commit;
+call p_verify_status_increment(1, 0, 1, 0);
+
+--echo # 28. Read-write statement: DO
+--echo #
+create table t2 (a int);
+call p_verify_status_increment(0, 0, 0, 0);
+do (select f1() from t1 where a=2);
+call p_verify_status_increment(2, 2, 2, 2);
+commit;
+call p_verify_status_increment(2, 2, 2, 2);
+
+--echo # 29. Read-write statement: MULTI-DELETE
+--echo #
+delete t1, t2 from t1 join t2 on (t1.a=t2.a) where t1.a=2;
+commit;
+call p_verify_status_increment(4, 4, 4, 4);
+
+--echo # 30. Read-write statement: INSERT-SELECT, MULTI-UPDATE, REPLACE-SELECT
+--echo #
+insert into t2 select a from t1;
+commit;
+replace into t2 select a from t1;
+commit;
+call p_verify_status_increment(8, 8, 8, 8);
+#
+# Multi-update is one of the few remaining statements that still
+# locks the tables at prepare step (and hence starts the transaction.
+# Disable the PS protocol, since in this protocol we get a different
+# number of commmits (there is an extra commit after prepare
+#
+--disable_ps_protocol
+update t1, t2 set t1.a=4, t2.a=8 where t1.a=t2.a and t1.a=1;
+--enable_ps_protocol
+commit;
+call p_verify_status_increment(4, 4, 4, 4);
+
+--echo # 31. DDL: various DDL with transactional tables
+--echo #
+--echo # Sic: no table is created.
+create table if not exists t2 (a int) select 6 union select 7;
+--echo # Sic: first commits the statement, and then the transaction.
+call p_verify_status_increment(4, 4, 4, 4);
+create table t3 select a from t2;
+call p_verify_status_increment(4, 4, 4, 4);
+alter table t3 add column (b int);
+call p_verify_status_increment(2, 0, 2, 0);
+alter table t3 rename t4;
+call p_verify_status_increment(1, 0, 1, 0);
+rename table t4 to t3;
+call p_verify_status_increment(1, 0, 1, 0);
+truncate table t3;
+call p_verify_status_increment(4, 4, 4, 4);
+create view v1 as select * from t2;
+call p_verify_status_increment(1, 0, 1, 0);
+check table t1;
+call p_verify_status_increment(3, 0, 3, 0);
+--echo # Sic: after this bug is fixed, CHECK leaves no pending transaction
+commit;
+call p_verify_status_increment(0, 0, 0, 0);
+check table t1, t2, t3;
+call p_verify_status_increment(6, 0, 6, 0);
+commit;
+call p_verify_status_increment(0, 0, 0, 0);
+drop view v1;
+call p_verify_status_increment(0, 0, 0, 0);
+
+--echo #
+--echo # Cleanup
+--echo #
+drop table t1, t2, t3;
+drop procedure p_verify_status_increment;
+drop function f1;
diff --git a/mysql-test/include/concurrent.inc b/mysql-test/include/concurrent.inc
new file mode 100644
index 00000000000..3b34a5b1ede
--- /dev/null
+++ b/mysql-test/include/concurrent.inc
@@ -0,0 +1,644 @@
+# include/concurrent.inc
+#
+# Concurrent tests for transactional storage engines, mainly in UPDATE's
+# Bug#3300
+# Designed and tested by Sinisa Milivojevic, sinisa@mysql.com
+#
+# These variables have to be set before sourcing this script:
+# TRANSACTION ISOLATION LEVEL REPEATABLE READ
+# innodb_locks_unsafe_for_binlog 0 (default) or 1 (by
+# --innodb_locks_unsafe_for_binlog)
+# $engine_type storage engine to be tested
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/innodb_concurrent.test
+# main code went into include/concurrent.inc
+# 2008-06-03 KP test refactored; removed name locks, added comments.
+# renamed wrapper t/concurrent_innodb.test ->
+# t/concurrent_innodb_unsafelog.test
+# new wrapper t/concurrent_innodb_safelog.test
+#
+
+connection default;
+
+#
+# Show prerequisites for this test.
+#
+SELECT @@global.tx_isolation;
+SELECT @@global.innodb_locks_unsafe_for_binlog;
+#
+# When innodb_locks_unsafe_for_binlog is not set (zero), which is the
+# default, InnoDB takes "next-key locks"/"gap locks". This means it
+# locks the gap before the keys that it accessed to find the rows to
+# use for a statement. In this case we have to expect some more lock
+# wait timeouts in the tests below as if innodb_locks_unsafe_for_binlog
+# is set (non-zero). In the latter case no "next-key locks"/"gap locks"
+# are taken and locks on keys that do not match the WHERE conditon are
+# released. Hence less lock collisions occur.
+# We use the variable $keep_locks to set the expectations for
+# lock wait timeouts accordingly.
+#
+let $keep_locks= `SELECT NOT @@global.innodb_locks_unsafe_for_binlog`;
+--echo # keep_locks == $keep_locks
+
+#
+# Set up privileges and remove user level locks, if exist.
+#
+GRANT USAGE ON test.* TO mysqltest@localhost;
+
+#
+# Preparatory cleanup.
+#
+DO release_lock("hello");
+DO release_lock("hello2");
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+
+--echo
+--echo **
+--echo ** two UPDATE's running and both changing distinct result sets
+--echo **
+ --echo ** connection thread1
+ connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+ --echo ** Get user level lock (ULL) for thread 1
+ select get_lock("hello",10);
+
+ --echo ** connection thread2
+ connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Start transaction for thread 2
+ begin;
+ --echo ** Update will cause a table scan and a new ULL will
+ --echo ** be created and blocked on the first row where tipo=11.
+ send update t1 set eta=1+get_lock("hello",10)*0 where tipo=11;
+ sleep 1;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Start new transaction for thread 1
+ begin;
+ --echo ** Update on t1 will cause a table scan which will be blocked because
+ --echo ** the previously initiated table scan applied exclusive key locks on
+ --echo ** all primary keys.
+ --echo ** Not so if innodb_locks_unsafe_for_binlog is set. The locks that
+ --echo ** do not match the WHERE condition are released.
+ if ($keep_locks)
+ {
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set eta=2 where tipo=22;
+ }
+ if (!$keep_locks)
+ {
+ update t1 set eta=2 where tipo=22;
+ }
+ --echo ** Release user level name lock from thread 1. This will cause the ULL
+ --echo ** on thread 2 to end its wait.
+ select release_lock("hello");
+ --echo ** Table is now updated with a new eta on tipo=22 for thread 1.
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Release the lock and collect result from update on thread 2
+ reap;
+ select release_lock("hello");
+ --echo ** Table should have eta updates where tipo=11 but updates made by
+ --echo ** thread 1 shouldn't be visible yet.
+ select * from t1;
+ --echo ** Sending commit on thread 2.
+ commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Make sure table reads didn't change yet on thread 1.
+ select * from t1;
+ --echo ** And send final commit on thread 1.
+ commit;
+ --echo ** Table should now be updated by both updates in the order of
+ --echo ** thread 1,2.
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Make sure the output is similar for t1.
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** two UPDATE's running and one changing result set
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+ --echo ** Get ULL "hello" on thread 1
+ select get_lock("hello",10);
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Start transaction on thread 2
+ begin;
+ --echo ** Update will cause a table scan.
+ --echo ** This will cause a hang on the first row where tipo=1 until the
+ --echo ** blocking ULL is released.
+ send update t1 set eta=1+get_lock("hello",10)*0 where tipo=1;
+ sleep 1;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Start transaction on thread 1
+ begin;
+ --echo ** Update on t1 will cause a table scan which will be blocked because
+ --echo ** the previously initiated table scan applied exclusive key locks on
+ --echo ** all primary keys.
+ --echo ** Not so if innodb_locks_unsafe_for_binlog is set. The locks that
+ --echo ** do not match the WHERE condition are released.
+ if ($keep_locks)
+ {
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set tipo=1 where tipo=2;
+ }
+ if (!$keep_locks)
+ {
+ update t1 set tipo=1 where tipo=2;
+ }
+ --echo ** Release ULL. This will release the next waiting ULL on thread 2.
+ select release_lock("hello");
+ --echo ** The table should still be updated with updates for thread 1 only:
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Release the lock and collect result from thread 2:
+ reap;
+ select release_lock("hello");
+ --echo ** Seen from thread 2 the table should have been updated on four
+ --echo ** places.
+ select * from t1;
+ commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Thread 2 has committed but the result should remain the same for
+ --echo ** thread 1 (updated on three places):
+ select * from t1;
+ commit;
+ --echo ** After a commit the table should be merged with the previous
+ --echo ** commit.
+ --echo ** This select should show both updates:
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** One UPDATE and one INSERT .... Monty's test
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1 (a int not null, b int not null);
+ insert into t1 values (1,1),(2,1),(3,1),(4,1);
+ --echo ** Create ULL 'hello2'
+ select get_lock("hello2",10);
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Begin a new transaction on thread 2
+ begin;
+ --echo ** Update will create a table scan which creates a ULL where a=2;
+ --echo ** this will hang waiting on thread 1.
+ send update t1 set b=10+get_lock(concat("hello",a),10)*0 where a=2;
+ sleep 1;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Insert new values to t1 from thread 1; this created an implicit
+ --echo ** commit since there are no on-going transactions.
+ insert into t1 values (1,1);
+ --echo ** Release the ULL (thread 2 updates will finish).
+ select release_lock("hello2");
+ --echo ** ..but thread 1 will still see t1 as if nothing has happend:
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Collect results from thread 2 and release the lock.
+ reap;
+ select release_lock("hello2");
+ --echo ** The table should look like the original+updates for thread 2,
+ --echo ** and consist of new rows:
+ select * from t1;
+ --echo ** Commit changes from thread 2
+ commit;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** one UPDATE changing result set and SELECT ... FOR UPDATE
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Begin a new transaction on thread 2
+ begin;
+ --echo ** Select a range for update.
+ select * from t1 where tipo=2 FOR UPDATE;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Begin a new transaction on thread 1
+ begin;
+ --echo ** Update the same range which is marked for update on thread 2; this
+ --echo ** will hang because of row locks.
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set tipo=1 where tipo=2;
+ --echo ** After the update the table will be unmodified because the previous
+ --echo ** transaction failed and was rolled back.
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** The table should look unmodified from thread 2.
+ select * from t1;
+ --echo ** Sending a commit should release the row locks and enable
+ --echo ** thread 1 to complete the transaction.
+ commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Commit on thread 1.
+ commit;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** The table should not have been changed.
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Even on thread 1:
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** one UPDATE not changing result set and SELECT ... FOR UPDATE
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Starting new transaction on thread 2.
+ begin;
+ --echo ** Starting SELECT .. FOR UPDATE
+ select * from t1 where tipo=2 FOR UPDATE;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo
+ --echo ** Starting new transaction on thread 1
+ begin;
+ --echo ** Updating single row using a table scan. This will time out
+ --echo ** because of ongoing transaction on thread 1 holding lock on
+ --echo ** all primary keys in the scan.
+ --echo ** Not so if innodb_locks_unsafe_for_binlog is set. The locks that
+ --echo ** do not match the WHERE condition are released.
+ if ($keep_locks)
+ {
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set tipo=11 where tipo=22;
+ }
+ if (!$keep_locks)
+ {
+ update t1 set tipo=11 where tipo=22;
+ }
+ --echo ** After the time out the transaction is aborted; no rows should
+ --echo ** have changed.
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** The same thing should hold true for the transaction on
+ --echo ** thread 2
+ select * from t1;
+ send commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ commit;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Even after committing:
+ reap;
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** two SELECT ... FOR UPDATE
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ --echo ** Begin a new transaction on thread 2
+ begin;
+ select * from t1 where tipo=2 FOR UPDATE;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Begin a new transaction on thread 1
+ begin;
+ --echo ** Selecting a range for update by table scan will be blocked
+ --echo ** because of on-going transaction on thread 2.
+ --error ER_LOCK_WAIT_TIMEOUT
+ select * from t1 where tipo=1 FOR UPDATE;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Table will be unchanged and the select command will not be
+ --echo ** blocked:
+ select * from t1;
+ --echo ** Commit transacton on thread 2.
+ commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Commit transaction on thread 1.
+ commit;
+
+ --echo ** connection thread2
+ connection thread2;
+ --echo ** Make sure table isn't blocked on thread 2:
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ --echo ** Make sure table isn't blocked on thread 1:
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** one UPDATE changing result set and DELETE
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ begin;
+ send delete from t1 where tipo=2;
+ sleep 1;
+
+ --echo ** connection thread1
+ connection thread1;
+ begin;
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set tipo=1 where tipo=2;
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ reap;
+ select * from t1;
+ send commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ commit;
+
+ --echo ** connection thread2
+ connection thread2;
+ reap;
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+
+
+--echo
+--echo **
+--echo ** one UPDATE not changing result set and DELETE
+--echo **
+ --echo ** connection thread1
+ #connect (thread1, localhost, mysqltest,,);
+ connection thread1;
+ --echo ** Set up table
+ eval SET SESSION STORAGE_ENGINE = $engine_type;
+ create table t1(eta int(11) not null, tipo int(11), c varchar(255));
+ insert into t1 values (7,7, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ insert into t1 values (8,8, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
+ insert into t1 values (10,1,"ccccccccccccccccccccccccccccccccccccccccccc");
+ insert into t1 values (20,2,"ddddddddddddddddddddddddddddddddddddddddddd");
+ insert into t1 values (30,1,"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
+ insert into t1 values (40,2,"fffffffffffffffffffffffffffffffffffffffffff");
+ insert into t1 values (50,1,"ggggggggggggggggggggggggggggggggggggggggggg");
+ insert into t1 values (60,2,"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
+ insert into t1 values (70,1,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
+ insert into t1 values (80,22,"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
+ insert into t1 values (90,11,"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
+
+ --echo ** connection thread2
+ #connect (thread2, localhost, mysqltest,,);
+ connection thread2;
+ begin;
+ send delete from t1 where tipo=2;
+ sleep 1;
+
+ --echo ** connection thread1
+ connection thread1;
+ begin;
+ --echo ** Update on t1 will cause a table scan which will be blocked because
+ --echo ** the previously initiated table scan applied exclusive key locks on
+ --echo ** all primary keys.
+ --echo ** Not so if innodb_locks_unsafe_for_binlog is set. The locks that
+ --echo ** do not match the WHERE condition are released.
+ if ($keep_locks)
+ {
+ --error ER_LOCK_WAIT_TIMEOUT
+ update t1 set tipo=1 where tipo=22;
+ }
+ if (!$keep_locks)
+ {
+ update t1 set tipo=1 where tipo=22;
+ }
+ select * from t1;
+
+ --echo ** connection thread2
+ connection thread2;
+ reap;
+ select * from t1;
+ send commit;
+
+ --echo ** connection thread1
+ connection thread1;
+ commit;
+
+ --echo ** connection thread2
+ connection thread2;
+ reap;
+ select * from t1;
+
+ --echo ** connection thread1
+ connection thread1;
+ select * from t1;
+
+--echo ** connection default
+connection default;
+drop table t1;
+drop user mysqltest@localhost;
+
+disconnect thread1;
+disconnect thread2;
+
diff --git a/mysql-test/include/connect2.inc b/mysql-test/include/connect2.inc
new file mode 100644
index 00000000000..6b830a909ed
--- /dev/null
+++ b/mysql-test/include/connect2.inc
@@ -0,0 +1,56 @@
+# include/connect2.inc
+#
+# SUMMARY
+#
+# Make several attempts to connect.
+#
+# USAGE
+#
+# EXAMPLE
+#
+# connect.test
+#
+
+--disable_query_log
+
+let $wait_counter= 300;
+if ($wait_timeout)
+{
+ let $wait_counter= `SELECT $wait_timeout * 10`;
+}
+# Reset $wait_timeout so that its value won't be used on subsequent
+# calls, and default will be used instead.
+let $wait_timeout= 0;
+
+--echo # -- Establishing connection '$con_name' (user: $con_user_name)...
+
+while ($wait_counter)
+{
+ --disable_abort_on_error
+ --disable_result_log
+ --connect ($con_name,localhost,$con_user_name)
+ --enable_result_log
+ --enable_abort_on_error
+
+ let $error = $mysql_errno;
+
+ if (!$error)
+ {
+ let $wait_counter= 0;
+ }
+ if ($error)
+ {
+ real_sleep 0.1;
+ dec $wait_counter;
+ }
+}
+if ($error)
+{
+ --echo # -- Error: can not establish connection '$con_name'.
+}
+if (!$error)
+{
+ --echo # -- Connection '$con_name' has been established.
+}
+
+--enable_query_log
diff --git a/mysql-test/include/ctype_german.inc b/mysql-test/include/ctype_german.inc
new file mode 100644
index 00000000000..14d09358bea
--- /dev/null
+++ b/mysql-test/include/ctype_german.inc
@@ -0,0 +1,40 @@
+#
+# Bug #27877 incorrect german order in utf8_general_ci
+#
+# Testing if "SHARP S" is equal to "S",
+# like in latin1_german1_ci, utf8_general_ci, ucs2_general_ci
+# Or if "SHART S" is equal to "SS",
+# like in latin1_german2_ci, utf8_unicode_ci, ucs2_unicode_ci
+#
+# Also testing A-uml, O-uml, U-uml
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Create a table with a varchar(x) column,
+# using current values of
+# @@character_set_connection and @@collation_connection.
+#
+
+create table t1 as select repeat(' ', 64) as s1;
+select collation(s1) from t1;
+delete from t1;
+
+#
+# Populate data
+#
+
+insert into t1 values ('a'),('ae'),(_latin1 0xE4);
+insert into t1 values ('o'),('oe'),(_latin1 0xF6);
+insert into t1 values ('s'),('ss'),(_latin1 0xDF);
+insert into t1 values ('u'),('ue'),(_latin1 0xFC);
+
+#
+# Check order
+#
+select s1, hex(s1) from t1 order by s1, binary s1;
+select group_concat(s1 order by binary s1) from t1 group by s1;
+drop table t1;
diff --git a/mysql-test/include/ddl_i18n.check_events.inc b/mysql-test/include/ddl_i18n.check_events.inc
new file mode 100644
index 00000000000..8b0d70e3c0e
--- /dev/null
+++ b/mysql-test/include/ddl_i18n.check_events.inc
@@ -0,0 +1,48 @@
+# - Check SHOW CREATE statement;
+
+--echo
+--echo
+
+SHOW CREATE EVENT ev1|
+--echo
+SHOW CREATE EVENT ev2|
+--echo
+SHOW CREATE EVENT mysqltest2.ev3|
+--echo
+SHOW CREATE EVENT mysqltest2.ev3|
+
+# - Check SHOW statement;
+
+--echo
+--echo
+
+SHOW EVENTS LIKE 'ev1'|
+
+--echo
+SHOW EVENTS LIKE 'ev2'|
+
+--echo
+SHOW EVENTS LIKE 'ev3'|
+
+--echo
+SHOW EVENTS LIKE 'ev4'|
+
+# - Check INFORMATION_SCHEMA;
+
+--echo
+--echo
+
+--replace_column 17 CREATED 18 LAST_ALTERED
+SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE event_name = 'ev1'|
+
+--echo
+--replace_column 17 CREATED 18 LAST_ALTERED
+SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE event_name = 'ev2'|
+
+--echo
+--replace_column 17 CREATED 18 LAST_ALTERED
+SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE event_name = 'ev3'|
+
+--echo
+--replace_column 17 CREATED 18 LAST_ALTERED
+SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE event_name = 'ev4'|
diff --git a/mysql-test/include/ddl_i18n.check_sp.inc b/mysql-test/include/ddl_i18n.check_sp.inc
new file mode 100644
index 00000000000..bb1657d7072
--- /dev/null
+++ b/mysql-test/include/ddl_i18n.check_sp.inc
@@ -0,0 +1,83 @@
+# - Check SHOW CREATE statement;
+
+--echo
+--echo
+
+SHOW CREATE PROCEDURE p1|
+--echo
+SHOW CREATE PROCEDURE p2|
+--echo
+SHOW CREATE PROCEDURE mysqltest2.p3|
+--echo
+SHOW CREATE PROCEDURE mysqltest2.p4|
+
+# - Check SHOW statement;
+
+--echo
+--echo
+
+--replace_column 5 MODIFIED 6 CREATED
+SHOW PROCEDURE STATUS LIKE 'p1'|
+
+--echo
+--replace_column 5 MODIFIED 6 CREATED
+SHOW PROCEDURE STATUS LIKE 'p2'|
+
+--echo
+--replace_column 5 MODIFIED 6 CREATED
+SHOW PROCEDURE STATUS LIKE 'p3'|
+
+--echo
+--replace_column 5 MODIFIED 6 CREATED
+SHOW PROCEDURE STATUS LIKE 'p4'|
+
+# - Check INFORMATION_SCHEMA;
+
+--echo
+--echo
+
+--replace_column 16 CREATED 17 ALTERED
+SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_name = 'p1'|
+
+--echo
+--replace_column 16 CREATED 17 ALTERED
+SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_name = 'p2'|
+
+--echo
+--replace_column 16 CREATED 17 ALTERED
+SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_name = 'p3'|
+
+--echo
+--replace_column 16 CREATED 17 ALTERED
+SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_name = 'p4'|
+
+# - Initialize the used variables (actual values don't matter);
+
+--echo
+--echo
+
+SET @a = '1'|
+SET @b = '2'|
+
+# - Execute the routines;
+
+--echo
+--echo
+
+CALL p1(@a, @b)|
+SELECT COLLATION(@a) AS ca, COLLATION(@b) cb|
+
+--echo
+
+CALL p2(@a, @b)|
+SELECT COLLATION(@a) AS ca, COLLATION(@b) cb|
+
+--echo
+
+CALL mysqltest2.p3(@a, @b)|
+SELECT COLLATION(@a) AS ca, COLLATION(@b) cb|
+
+--echo
+
+CALL mysqltest2.p4(@a, @b)|
+SELECT COLLATION(@a) AS ca, COLLATION(@b) cb|
diff --git a/mysql-test/include/ddl_i18n.check_triggers.inc b/mysql-test/include/ddl_i18n.check_triggers.inc
new file mode 100644
index 00000000000..dbfbc3cda5e
--- /dev/null
+++ b/mysql-test/include/ddl_i18n.check_triggers.inc
@@ -0,0 +1,106 @@
+# - Check SHOW CREATE statement;
+
+--echo
+--echo
+
+SHOW CREATE TRIGGER trg1|
+--echo
+SHOW CREATE TRIGGER trg2|
+--echo
+SHOW CREATE TRIGGER mysqltest2.trg3|
+--echo
+SHOW CREATE TRIGGER mysqltest2.trg4|
+
+# - Check SHOW statement;
+
+--echo
+--echo
+
+SHOW TRIGGERS|
+
+--echo
+
+use mysqltest2|
+
+--echo
+
+SHOW TRIGGERS|
+
+use mysqltest1|
+
+# - Check INFORMATION_SCHEMA;
+
+--echo
+--echo
+
+--replace_column 17 CREATED
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 'trg1'|
+
+--echo
+--replace_column 17 CREATED
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 'trg2'|
+
+--echo
+--replace_column 17 CREATED
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 'trg3'|
+
+--echo
+--replace_column 17 CREATED
+SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 'trg4'|
+
+# - Initialize the used variables (actual values don't matter);
+
+--echo
+--echo
+
+SET @a1 = '1'|
+SET @a2 = '1'|
+SET @a3 = '1'|
+
+SET @b1 = '2'|
+SET @b2 = '2'|
+SET @b3 = '2'|
+
+# - Execute the triggers;
+
+--echo
+--echo
+
+INSERT INTO t1 VALUES(1)|
+
+--echo
+--echo ---> Log:
+SELECT msg FROM log|
+
+--echo
+SELECT
+ COLLATION(@a1) AS ca1,
+ COLLATION(@a2) AS ca2,
+ COLLATION(@a3) AS ca3,
+ COLLATION(@b1) AS cb1,
+ COLLATION(@b2) AS cb2,
+ COLLATION(@b3) AS cb3|
+
+--echo
+DELETE FROM log|
+
+--echo
+--echo
+
+INSERT INTO mysqltest2.t1 VALUES(1)|
+
+--echo
+--echo ---> Log:
+SELECT msg FROM mysqltest2.log|
+
+--echo
+SELECT
+ COLLATION(@a1) AS ca1,
+ COLLATION(@a2) AS ca2,
+ COLLATION(@a3) AS ca3,
+ COLLATION(@b1) AS cb1,
+ COLLATION(@b2) AS cb2,
+ COLLATION(@b3) AS cb3|
+
+--echo
+DELETE FROM mysqltest2.log|
diff --git a/mysql-test/include/ddl_i18n.check_views.inc b/mysql-test/include/ddl_i18n.check_views.inc
new file mode 100644
index 00000000000..db3ad02f459
--- /dev/null
+++ b/mysql-test/include/ddl_i18n.check_views.inc
@@ -0,0 +1,44 @@
+# - Check SHOW CREATE statement;
+
+--echo
+--echo
+
+SHOW CREATE VIEW v1|
+
+--echo
+
+SHOW CREATE VIEW v2|
+
+--echo
+
+SHOW CREATE VIEW v3|
+
+# - Check INFORMATION_SCHEMA;
+
+--echo
+--echo
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v1'|
+
+--echo
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v2'|
+
+--echo
+
+SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE table_name = 'v3'|
+
+# - Execute the views;
+
+--echo
+--echo
+
+SELECT COLLATION(c1), COLLATION(c2) FROM v1|
+
+--echo
+
+SELECT COLLATION(c1) FROM v2|
+
+--echo
+
+SELECT * FROM v3|
diff --git a/mysql-test/include/deadlock.inc b/mysql-test/include/deadlock.inc
new file mode 100644
index 00000000000..89c34abc871
--- /dev/null
+++ b/mysql-test/include/deadlock.inc
@@ -0,0 +1,172 @@
+# include/deadlock.inc
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Last update:
+# 2006-07-26 ML refactoring + print when connection is switched
+# old name was t/innodb-deadlock.test
+# main code went into include/deadlock.inc
+#
+
+--echo # Establish connection con1 (user=root)
+connect (con1,localhost,root,,);
+--echo # Establish connection con2 (user=root)
+connect (con2,localhost,root,,);
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
+#
+# Testing of FOR UPDATE
+#
+
+--echo # Switch to connection con1
+connection con1;
+eval create table t1 (id integer, x integer) engine = $engine_type;
+insert into t1 values(0, 0);
+set autocommit=0;
+SELECT * from t1 where id = 0 FOR UPDATE;
+
+--echo # Switch to connection con2
+connection con2;
+set autocommit=0;
+
+# The following query should hang because con1 is locking the record
+--send
+update t1 set x=2 where id = 0;
+--sleep 2
+
+--echo # Switch to connection con1
+connection con1;
+update t1 set x=1 where id = 0;
+select * from t1;
+commit;
+
+--echo # Switch to connection con2
+connection con2;
+reap;
+commit;
+
+--echo # Switch to connection con1
+connection con1;
+select * from t1;
+commit;
+
+drop table t1;
+#
+# Testing of FOR UPDATE
+#
+
+--echo # Switch to connection con1
+connection con1;
+eval create table t1 (id integer, x integer) engine = $engine_type;
+eval create table t2 (b integer, a integer) engine = $engine_type;
+insert into t1 values(0, 0), (300, 300);
+insert into t2 values(0, 10), (1, 20), (2, 30);
+commit;
+set autocommit=0;
+select * from t2;
+update t2 set a=100 where b=(SELECT x from t1 where id = b FOR UPDATE);
+select * from t2;
+select * from t1;
+
+--echo # Switch to connection con2
+connection con2;
+set autocommit=0;
+
+# The following query should hang because con1 is locking the record
+--send
+update t1 set x=2 where id = 0;
+--sleep 2
+
+--echo # Switch to connection con1
+connection con1;
+update t1 set x=1 where id = 0;
+select * from t1;
+commit;
+
+--echo # Switch to connection con2
+connection con2;
+reap;
+commit;
+
+--echo # Switch to connection con1
+connection con1;
+select * from t1;
+commit;
+
+drop table t1, t2;
+eval create table t1 (id integer, x integer) engine = $engine_type;
+eval create table t2 (b integer, a integer) engine = $engine_type;
+insert into t1 values(0, 0), (300, 300);
+insert into t2 values(0, 0), (1, 20), (2, 30);
+commit;
+
+--echo # Switch to connection con1
+connection con1;
+select a,b from t2 UNION SELECT id, x from t1 FOR UPDATE;
+select * from t2;
+select * from t1;
+
+--echo # Switch to connection con2
+connection con2;
+
+# The following query should hang because con1 is locking the record
+update t2 set a=2 where b = 0;
+select * from t2;
+--send
+update t1 set x=2 where id = 0;
+--sleep 2
+
+--echo # Switch to connection con1
+connection con1;
+update t1 set x=1 where id = 0;
+select * from t1;
+commit;
+
+--echo # Switch to connection con2
+connection con2;
+reap;
+commit;
+
+--echo # Switch to connection con1
+connection con1;
+select * from t1;
+commit;
+
+# Cleanup
+--echo # Switch to connection default + disconnect con1 and con2
+connection default;
+disconnect con1;
+disconnect con2;
+drop table t1, t2;
+
+--echo End of 4.1 tests
+
+#
+# Bug#25164 create table `a` as select * from `A` hangs
+#
+
+set storage_engine=innodb;
+
+--disable_warnings
+drop table if exists a;
+drop table if exists A;
+--enable_warnings
+
+create table A (c int);
+insert into A (c) values (0);
+--error 0,ER_LOCK_DEADLOCK,ER_UPDATE_TABLE_USED
+create table a as select * from A;
+drop table A;
+
+--disable_warnings
+drop table if exists a;
+--enable_warnings
+
+set storage_engine=default;
+
+--echo End of 5.0 tests.
diff --git a/mysql-test/include/default_my.cnf b/mysql-test/include/default_my.cnf
new file mode 100644
index 00000000000..d77fee0e200
--- /dev/null
+++ b/mysql-test/include/default_my.cnf
@@ -0,0 +1,25 @@
+# Use default setting for mysqld processes
+!include default_mysqld.cnf
+
+[mysqld.1]
+
+# Run the master.sh script before starting this process
+#!run-master-sh
+
+log-bin= master-bin
+
+
+[mysqlbinlog]
+disable-force-if-open
+
+# mysql_fix_privilege_tables.sh does not read from [client] so it
+# need its own section
+[mysql_fix_privilege_tables]
+socket= @client.socket
+port= @client.port
+user= @client.user
+password= @client.password
+
+[ENV]
+MASTER_MYPORT= @mysqld.1.port
+MASTER_MYSOCK= @mysqld.1.socket
diff --git a/mysql-test/include/default_mysqld.cnf b/mysql-test/include/default_mysqld.cnf
new file mode 100644
index 00000000000..ad0090aaf36
--- /dev/null
+++ b/mysql-test/include/default_mysqld.cnf
@@ -0,0 +1,21 @@
+# Default values that applies to all MySQL Servers
+[mysqld]
+open-files-limit= 1024
+local-infile
+default-character-set= latin1
+
+# Increase default connect_timeout to avoid intermittent
+# disconnects when test servers are put under load see BUG#28359
+connect-timeout= 60
+
+log-bin-trust-function-creators=1
+key_buffer_size= 1M
+sort_buffer= 256K
+max_heap_table_size= 1M
+
+loose-innodb_data_file_path= ibdata1:10M:autoextend
+
+slave-net-timeout=120
+
+log-bin=mysqld-bin
+
diff --git a/mysql-test/include/default_ndbd.cnf b/mysql-test/include/default_ndbd.cnf
new file mode 100644
index 00000000000..9a88a5936aa
--- /dev/null
+++ b/mysql-test/include/default_ndbd.cnf
@@ -0,0 +1,27 @@
+
+[cluster_config]
+MaxNoOfSavedMessages= 1000
+MaxNoOfConcurrentTransactions= 128
+MaxNoOfConcurrentOperations= 10000
+DataMemory= 20M
+IndexMemory= 1M
+Diskless= 0
+TimeBetweenWatchDogCheck= 30000
+MaxNoOfOrderedIndexes= 32
+MaxNoOfAttributes= 2048
+TimeBetweenGlobalCheckpoints= 500
+NoOfFragmentLogFiles= 4
+FragmentLogFileSize= 12M
+DiskPageBufferMemory= 4M
+
+# O_DIRECT has issues on 2.4 whach have not been handled, Bug #29612
+#ODirect= 1
+# the following parametes just function as a small regression
+# test that the parameter exists
+InitialNoOfOpenFiles= 27
+
+# Increase timeouts for slow test-machines
+HeartbeatIntervalDbDb= 30000
+HeartbeatIntervalDbApi= 30000
+
+#TransactionDeadlockDetectionTimeout= 7500
diff --git a/mysql-test/include/delete_anonymous_users.inc b/mysql-test/include/delete_anonymous_users.inc
index 9f642223748..704e74ae4a3 100644
--- a/mysql-test/include/delete_anonymous_users.inc
+++ b/mysql-test/include/delete_anonymous_users.inc
@@ -1,5 +1,7 @@
# Remove anonymous users added by add_anonymous_users.inc
+disable_warnings;
disable_query_log;
DELETE FROM mysql.user where host='localhost' and user='';
FLUSH PRIVILEGES;
enable_query_log;
+enable_warnings;
diff --git a/mysql-test/include/diff_tables.inc b/mysql-test/include/diff_tables.inc
new file mode 100644
index 00000000000..d15dd56b35d
--- /dev/null
+++ b/mysql-test/include/diff_tables.inc
@@ -0,0 +1,122 @@
+# ==== Purpose ====
+#
+# Check if the two given tables (possibly residing on different
+# master/slave servers) are equal.
+#
+# ==== Usage ====
+#
+# The tables to check are given by the test language variables
+# $diff_table_1 and $diff_table_2. They must be of the
+# following form:
+#
+# [master:|slave:]database.table
+#
+# I.e., both database and table must be speicified. Optionally, you
+# can prefix the name with 'master:' (to read the table on master) or
+# with 'slave:' (to read the table on slave). If no prefix is given,
+# reads the table from the current connection. If one of these
+# variables has a prefix, both should have a prefix.
+#
+# ==== Side effects ====
+#
+# - Prints "Comparing tables $diff_table_1 and $diff_tables_2".
+#
+# - If the tables are different, prints the difference in a
+# system-specific format (unified diff if supported) and generates
+# an error.
+#
+# - If $diff_table_1 or $diff_table_2 begins with 'master:' or
+# 'slave:', it will stay connected to one of those hosts after
+# execution. The host is only guaranteed to remain unchanged if
+# none of $diff_table_1 or $diff_table_2 begins with 'master:' or
+# 'slave:'.
+#
+# ==== Bugs ====
+#
+# - It is currently not possible to use this for tables that are
+# supposed to be different, because if the files are different:
+# - 'diff' produces system-dependent output,
+# - the output includes the absolute path of the compared files,
+# - the output includes a timestamp.
+# To fix that, we'd probably have to use SQL to compute the
+# symmetric difference between the tables. I'm not sure how to do
+# that efficiently. If we implement this, it would be nice to
+# compare the table definitions too.
+#
+# - It actually compares the result of "SELECT * FROM table ORDER BY
+# col1, col2, ..., colN INTO OUTFILE 'file'". Hence, it is assumed
+# that the comparison orders for both tables are equal and that two
+# rows that are equal in the comparison order cannot differ, e.g.,
+# by character case.
+
+
+# ==== Save both tables to file ====
+
+--echo Comparing tables $diff_table_1 and $diff_table_2
+disable_query_log;
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+let $_diff_table=$diff_table_2;
+let $_diff_i=2;
+while ($_diff_i) {
+
+ # Parse out any leading "master:" or "slave:" from the table
+ # specification and connect the appropriate server.
+ let $_diff_conn_master=`SELECT SUBSTR('$_diff_table', 1, 7) = 'master:'`;
+ if ($_diff_conn_master) {
+ let $_diff_table=`SELECT SUBSTR('$_diff_table', 8)`;
+ connection master;
+ }
+ let $_diff_conn_slave=`SELECT SUBSTR('$_diff_table', 1, 6) = 'slave:'`;
+ if ($_diff_conn_slave) {
+ let $_diff_table=`SELECT SUBSTR('$_diff_table', 7)`;
+ connection slave;
+ }
+
+ # Sanity-check the input.
+ let $_diff_error= `SELECT '$_diff_table' NOT LIKE '_%._%'`;
+ if ($_diff_error) {
+ --echo !!!ERROR IN TEST: \$diff_table_$_diff_i='$_diff_table' is not in the form database.table
+ exit;
+ }
+
+ # We need the output files to be sorted (so that diff_files does not
+ # think the files are different just because they are differently
+ # ordered). To this end, we first generate a query that sorts the
+ # table by all columns. Since ORDER BY accept column indices, we
+ # just generate a comma-separated list of all numbers from 1 to the
+ # number of columns in the table.
+ let $_diff_column_index=`SELECT MAX(ordinal_position)
+ FROM information_schema.columns
+ WHERE CONCAT(table_schema, '.', table_name) =
+ '$_diff_table'`;
+ let $_diff_column_list=$_diff_column_index;
+ dec $_diff_column_index;
+ while ($_diff_column_index) {
+ let $_diff_column_list=$_diff_column_index, $_diff_column_list;
+ dec $_diff_column_index;
+ }
+
+ # Now that we have the comma-separated list of columns, we can write
+ # the table to a file.
+ eval SELECT * FROM $_diff_table ORDER BY $_diff_column_list
+ INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/diff_table_$_diff_i';
+
+ # Do the same for $diff_table_1.
+ dec $_diff_i;
+ let $_diff_table=$diff_table_1;
+}
+
+
+# ==== Compare the generated files ====
+
+diff_files $MYSQLTEST_VARDIR/tmp/diff_table_1 $MYSQLTEST_VARDIR/tmp/diff_table_2;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+enable_query_log;
diff --git a/mysql-test/include/federated.inc b/mysql-test/include/federated.inc
deleted file mode 100644
index 7bdb2efaa8b..00000000000
--- a/mysql-test/include/federated.inc
+++ /dev/null
@@ -1,23 +0,0 @@
---source include/have_log_bin.inc
---source include/not_embedded.inc
---source ./include/have_federated_db.inc
-
-source ./include/master-slave.inc;
-
-# remote table creation
-
-connection slave;
-#--replicate-ignore-db=federated
-stop slave;
-
---disable_warnings
-# at this point, we are connected to master
-DROP DATABASE IF EXISTS federated;
---enable_warnings
-CREATE DATABASE federated;
-
-connection master;
---disable_warnings
-DROP DATABASE IF EXISTS federated;
---enable_warnings
-CREATE DATABASE federated;
diff --git a/mysql-test/include/federated_cleanup.inc b/mysql-test/include/federated_cleanup.inc
deleted file mode 100644
index 17a6e1e5100..00000000000
--- a/mysql-test/include/federated_cleanup.inc
+++ /dev/null
@@ -1,11 +0,0 @@
-connection master;
---disable_warnings
-DROP TABLE IF EXISTS federated.t1;
-DROP DATABASE IF EXISTS federated;
---enable_warnings
-
-connection slave;
---disable_warnings
-DROP TABLE IF EXISTS federated.t1;
-DROP DATABASE IF EXISTS federated;
---enable_warnings
diff --git a/mysql-test/include/gis_generic.inc b/mysql-test/include/gis_generic.inc
index 70e82a13364..e4fee4448c1 100644
--- a/mysql-test/include/gis_generic.inc
+++ b/mysql-test/include/gis_generic.inc
@@ -8,14 +8,14 @@
DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
--enable_warnings
-CREATE TABLE gis_point (fid INTEGER, g POINT);
-CREATE TABLE gis_line (fid INTEGER, g LINESTRING);
-CREATE TABLE gis_polygon (fid INTEGER, g POLYGON);
-CREATE TABLE gis_multi_point (fid INTEGER, g MULTIPOINT);
-CREATE TABLE gis_multi_line (fid INTEGER, g MULTILINESTRING);
-CREATE TABLE gis_multi_polygon (fid INTEGER, g MULTIPOLYGON);
-CREATE TABLE gis_geometrycollection (fid INTEGER, g GEOMETRYCOLLECTION);
-CREATE TABLE gis_geometry (fid INTEGER, g GEOMETRY);
+CREATE TABLE gis_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POINT);
+CREATE TABLE gis_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g LINESTRING);
+CREATE TABLE gis_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g POLYGON);
+CREATE TABLE gis_multi_point (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOINT);
+CREATE TABLE gis_multi_line (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTILINESTRING);
+CREATE TABLE gis_multi_polygon (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g MULTIPOLYGON);
+CREATE TABLE gis_geometrycollection (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRYCOLLECTION);
+CREATE TABLE gis_geometry (fid INTEGER PRIMARY KEY AUTO_INCREMENT, g GEOMETRY);
SHOW CREATE TABLE gis_point;
SHOW FIELDS FROM gis_point;
@@ -141,6 +141,7 @@ DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gi
# Check that ALTER TABLE doesn't loose geometry type
#
CREATE TABLE t1 (
+ a INTEGER PRIMARY KEY AUTO_INCREMENT,
gp point,
ln linestring,
pg polygon,
@@ -156,24 +157,24 @@ ALTER TABLE t1 ADD fid INT;
SHOW FIELDS FROM t1;
DROP TABLE t1;
-create table t1 (a geometry not null);
-insert into t1 values (GeomFromText('Point(1 2)'));
+create table t1 (pk integer primary key auto_increment, a geometry not null);
+insert into t1 (a) values (GeomFromText('Point(1 2)'));
-- error 1416
-insert into t1 values ('Garbage');
+insert into t1 (a) values ('Garbage');
-- error 1416
-insert IGNORE into t1 values ('Garbage');
+insert IGNORE into t1 (a) values ('Garbage');
drop table t1;
-create table t1 (fl geometry not null);
+create table t1 (pk integer primary key auto_increment, fl geometry not null);
--error 1416
-insert into t1 values (1);
+insert into t1 (fl) values (1);
--error 1416
-insert into t1 values (1.11);
+insert into t1 (fl) values (1.11);
--error 1416
-insert into t1 values ("qwerty");
+insert into t1 (fl) values ("qwerty");
--error 1048
-insert into t1 values (pointfromtext('point(1,1)'));
+insert into t1 (fl) values (pointfromtext('point(1,1)'));
drop table t1;
diff --git a/mysql-test/include/grant_cache.inc b/mysql-test/include/grant_cache.inc
new file mode 100644
index 00000000000..501e115f0ee
--- /dev/null
+++ b/mysql-test/include/grant_cache.inc
@@ -0,0 +1,203 @@
+################### include/grant_cache.inc ####################
+#
+# Test grants with query cache
+#
+# Last update:
+# 2007-05-03 ML - Move t/grant_cache.test to include/grant_cache.inc
+# - Remove the disabling of the ps-protocol
+# - minor improvements like error names instead of numbers
+# - Create two toplevel tests sourcing this routine
+#
+# Running this test with and without "--ps-protocol" produces different
+# Qcache_not_cached results because of the following reason:
+# In normal protocol, a SELECT failing due to insufficient privileges
+# increments Qcache_not_cached, while in ps-protocol, no.
+# In detail:
+# - In normal protocol,
+# the "access denied" errors on SELECT are issued at (stack trace):
+# mysql_parse/mysql_execute_command/execute_sqlcom_select/handle_select/
+# mysql_select/JOIN::prepare/setup_wild/insert_fields/
+# check_grant_all_columns/my_error/my_message_sql, which then calls
+# push_warning/query_cache_abort: at this moment,
+# query_cache_store_query() has been called, so query exists in cache,
+# so thd->net.query_cache_query!=NULL, so query_cache_abort() removes
+# the query from cache, which causes a query_cache.refused++ (thus,
+# a Qcache_not_cached++).
+# - In ps-protocol,
+# the error is issued at prepare time;
+# for this mysql_test_select() is called, not execute_sqlcom_select()
+# (and that also leads to JOIN::prepare/etc). Thus, as
+# query_cache_store_query() has not been called,
+# thd->net.query_cache_query==NULL, so query_cache_abort() does nothing:
+# Qcache_not_cached is not incremented.
+#
+# A run of this tests with sp/cursor/view protocol does not make sense
+# because these protocols serve totally different purposes than this test.
+#
+
+--source include/add_anonymous_users.inc
+
+#
+--disable_warnings
+drop table if exists test.t1,mysqltest.t1,mysqltest.t2;
+drop database if exists mysqltest;
+--enable_warnings
+
+set GLOBAL query_cache_size=1355776;
+
+reset query cache;
+flush status;
+--echo ----- establish connection root -----
+connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection root;
+show grants for current_user;
+show grants;
+--disable_warnings
+create database if not exists mysqltest;
+--enable_warnings
+
+create table mysqltest.t1 (a int,b int,c int);
+create table mysqltest.t2 (a int,b int,c int);
+insert into mysqltest.t1 values (1,1,1),(2,2,2);
+insert into mysqltest.t2 values (3,3,3);
+create table test.t1 (a char (10));
+insert into test.t1 values ("test.t1");
+select * from t1;
+--echo ----- establish connection root2 -----
+connect (root2,localhost,root,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection root2;
+# put queries in cache
+select * from t1;
+select a from t1;
+select c from t1;
+select * from t2;
+select * from mysqltest.t1,test.t1;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits%";
+
+# Create the test users
+grant SELECT on mysqltest.* to mysqltest_1@localhost;
+grant SELECT on mysqltest.t1 to mysqltest_2@localhost;
+grant SELECT on test.t1 to mysqltest_2@localhost;
+grant SELECT(a) on mysqltest.t1 to mysqltest_3@localhost;
+
+# The following queries should be fetched from cache
+--echo ----- establish connection user1 (user=mysqltest_1) -----
+connect (user1,localhost,mysqltest_1,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection user1;
+show grants for current_user();
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+select "user1";
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+select * from t1;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+# The pre and end space are intentional
+ select a from t1 ;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+select c from t1;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+
+--echo ----- establish connection unkuser (user=unkuser) -----
+# Don't use '' as user because it will pick Unix login
+connect (unkuser,localhost,unkuser,,,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection unkuser;
+show grants for current_user();
+
+# The following queries should be fetched from cache
+--echo ----- establish connection user2 (user=mysqltest_2) -----
+connect (user2,localhost,mysqltest_2,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection user2;
+select "user2";
+select * from t1;
+select a from t1;
+select c from t1;
+select * from mysqltest.t1,test.t1;
+--replace_result 127.0.0.1 localhost
+--error ER_TABLEACCESS_DENIED_ERROR
+select * from t2;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# The following queries should not be fetched from cache
+--echo ----- establish connection user3 (user=mysqltest_3) -----
+connect (user3,localhost,mysqltest_3,,mysqltest,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection user3;
+select "user3";
+--replace_result 127.0.0.1 localhost
+--error ER_TABLEACCESS_DENIED_ERROR
+select * from t1;
+select a from t1;
+--replace_result 127.0.0.1 localhost
+--error ER_COLUMNACCESS_DENIED_ERROR
+select c from t1;
+--replace_result 127.0.0.1 localhost
+--error ER_TABLEACCESS_DENIED_ERROR
+select * from t2;
+--replace_result 127.0.0.1 localhost
+--error ER_COLUMNACCESS_DENIED_ERROR
+select mysqltest.t1.c from test.t1,mysqltest.t1;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Connect without a database
+--echo ----- establish connection user4 (user=mysqltest_1) -----
+connect (user4,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK);
+connection user4;
+select "user4";
+show grants;
+--error ER_NO_DB_ERROR
+select a from t1;
+# The following query is not cached before (different database)
+select * from mysqltest.t1,test.t1;
+# Cache a query with 'no database'
+select a from mysqltest.t1;
+select a from mysqltest.t1;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+show status like "Qcache_not_cached";
+
+# Cleanup
+
+--echo ----- switch to connection default and close connections -----
+connection default;
+disconnect root;
+disconnect root2;
+disconnect user1;
+disconnect user2;
+disconnect user3;
+disconnect user4;
+disconnect unkuser;
+
+#
+# A temporary 4.1 workaround to make this test pass if
+# mysql was compiled with other than latin1 --with-charset=XXX.
+# Without "set names binary" the below queries fail with
+# "Illegal mix of collations" error.
+# In 5.0 we will change grant tables to use NCHAR(N) instead
+# of "CHAR(N) BINARY", and use cast-to-nchar: N'mysqltest_1'.
+#
+set names binary;
+delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
+delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
+delete from mysql.tables_priv where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
+delete from mysql.columns_priv where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
+flush privileges;
+drop table test.t1,mysqltest.t1,mysqltest.t2;
+drop database mysqltest;
+
+set GLOBAL query_cache_size=default;
+
+--source include/delete_anonymous_users.inc
diff --git a/mysql-test/include/handler.inc b/mysql-test/include/handler.inc
new file mode 100644
index 00000000000..04f4cac831d
--- /dev/null
+++ b/mysql-test/include/handler.inc
@@ -0,0 +1,720 @@
+# include/handler.inc
+#
+# The variables
+# $engine_type -- storage engine to be tested
+# $other_engine_type -- storage engine <> $engine_type
+# $other_handler_engine_type -- storage engine <> $engine_type, if possible
+# 1. $other_handler_engine_type must support handler
+# 2. $other_handler_engine_type must point to an all
+# time available storage engine
+# 2006-08 MySQL 5.1 MyISAM and MEMORY only
+# have to be set before sourcing this script.
+-- source include/not_embedded.inc
+#
+# test of HANDLER ...
+#
+# Last update:
+# 2006-07-31 ML test refactored (MySQL 5.1)
+# code of t/handler.test and t/innodb_handler.test united
+# main testing code put into include/handler.inc
+#
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1,t3,t4,t5;
+--enable_warnings
+
+create table t1 (a int, b char(10), key a(a), key b(a,b));
+insert into t1 values
+(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
+(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
+(20,"ggg"),(21,"hhh"),(22,"iii");
+handler t1 open as t2;
+-- error 1064
+handler t2 read a=(SELECT 1);
+handler t2 read a first;
+handler t2 read a next;
+handler t2 read a next;
+handler t2 read a prev;
+handler t2 read a last;
+handler t2 read a prev;
+handler t2 read a prev;
+
+handler t2 read a first;
+handler t2 read a prev;
+
+handler t2 read a last;
+handler t2 read a prev;
+handler t2 read a next;
+handler t2 read a next;
+
+handler t2 read a=(15);
+handler t2 read a=(16);
+
+--error 1070
+handler t2 read a=(19,"fff");
+
+handler t2 read b=(19,"fff");
+handler t2 read b=(19,"yyy");
+handler t2 read b=(19);
+
+--error 1109
+handler t1 read a last;
+
+handler t2 read a=(11);
+handler t2 read a>=(11);
+
+handler t2 read a=(18);
+handler t2 read a>=(18);
+handler t2 read a>(18);
+handler t2 read a<=(18);
+handler t2 read a<(18);
+
+handler t2 read a first limit 5;
+handler t2 read a next limit 3;
+handler t2 read a prev limit 10;
+
+handler t2 read a>=(16) limit 4;
+handler t2 read a>=(16) limit 2,2;
+handler t2 read a last limit 3;
+
+handler t2 read a=(19);
+handler t2 read a=(19) where b="yyy";
+
+handler t2 read first;
+handler t2 read next;
+handler t2 read next;
+--error 1064
+handler t2 read last;
+handler t2 close;
+
+handler t1 open;
+handler t1 read a next; # this used to crash as a bug#5373
+handler t1 read a next;
+handler t1 close;
+
+handler t1 open;
+handler t1 read a prev; # this used to crash as a bug#5373
+handler t1 read a prev;
+handler t1 close;
+
+handler t1 open as t2;
+handler t2 read first;
+eval alter table t1 engine = $engine_type;
+--error 1109
+handler t2 read first;
+
+#
+# DROP TABLE / ALTER TABLE
+#
+handler t1 open as t2;
+drop table t1;
+create table t1 (a int);
+insert into t1 values (17);
+--error 1109
+handler t2 read first;
+handler t1 open as t2;
+eval alter table t1 engine=$other_engine_type;
+--error 1109
+handler t2 read first;
+drop table t1;
+
+#
+# Test case for the bug #787
+#
+create table t1 (a int);
+insert into t1 values (1),(2),(3),(4),(5),(6);
+delete from t1 limit 2;
+handler t1 open;
+handler t1 read first;
+handler t1 read first limit 1,1;
+handler t1 read first limit 2,2;
+delete from t1 limit 3;
+handler t1 read first;
+drop table t1;
+
+#
+# Test for #751
+#
+create table t1(a int, index(a));
+insert into t1 values (1), (2), (3);
+handler t1 open;
+--error 1054
+handler t1 read a=(W);
+--error 1210
+handler t1 read a=(a);
+drop table t1;
+#
+# BUG#2304
+#
+create table t1 (a char(5));
+insert into t1 values ("Ok");
+handler t1 open as t;
+handler t read first;
+use mysql;
+handler t read first;
+handler t close;
+handler test.t1 open as t;
+handler t read first;
+handler t close;
+use test;
+drop table t1;
+
+#
+# BUG#3649
+#
+create table t1 ( a int, b int, INDEX a (a) );
+insert into t1 values (1,2), (2,1);
+handler t1 open;
+handler t1 read a=(1) where b=2;
+handler t1 read a=(1) where b=3;
+handler t1 read a=(1) where b=1;
+handler t1 close;
+drop table t1;
+
+#
+# Check if two database names beginning the same are seen as different.
+#
+# This database begins like the usual 'test' database.
+#
+--disable_warnings
+drop database if exists test_test;
+--enable_warnings
+create database test_test;
+use test_test;
+create table t1(table_id char(20) primary key);
+insert into t1 values ('test_test.t1');
+insert into t1 values ('');
+handler t1 open;
+handler t1 read first limit 9;
+create table t2(table_id char(20) primary key);
+insert into t2 values ('test_test.t2');
+insert into t2 values ('');
+handler t2 open;
+handler t2 read first limit 9;
+#
+# This is the usual 'test' database.
+#
+use test;
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1(table_id char(20) primary key);
+insert into t1 values ('test.t1');
+insert into t1 values ('');
+--error 1066
+handler t1 open;
+#
+# Check accesibility of all the tables.
+#
+use test;
+--error 1064
+handler test.t1 read first limit 9;
+--error 1064
+handler test_test.t1 read first limit 9;
+handler t1 read first limit 9;
+--error 1064
+handler test_test.t2 read first limit 9;
+handler t2 read first limit 9;
+
+#
+# Cleanup.
+#
+
+--error 1064
+handler test_test.t1 close;
+handler t1 close;
+drop table test_test.t1;
+--error 1064
+handler test_test.t2 close;
+handler t2 close;
+drop table test_test.t2;
+drop database test_test;
+
+#
+use test;
+--error 1064
+handler test.t1 close;
+--error 1109
+handler t1 close;
+drop table test.t1;
+
+#
+# BUG#4335
+#
+--disable_warnings
+drop database if exists test_test;
+drop table if exists t1;
+drop table if exists t2;
+drop table if exists t3;
+--enable_warnings
+create database test_test;
+use test_test;
+create table t1 (c1 char(20));
+insert into t1 values ('test_test.t1');
+create table t3 (c1 char(20));
+insert into t3 values ('test_test.t3');
+handler t1 open;
+handler t1 read first limit 9;
+handler t1 open h1;
+handler h1 read first limit 9;
+use test;
+create table t1 (c1 char(20));
+create table t2 (c1 char(20));
+create table t3 (c1 char(20));
+insert into t1 values ('t1');
+insert into t2 values ('t2');
+insert into t3 values ('t3');
+--error 1066
+handler t1 open;
+--error 1066
+handler t2 open t1;
+--error 1066
+handler t3 open t1;
+handler t1 read first limit 9;
+--error 1064
+handler test.t1 close;
+--error 1066
+handler test.t1 open h1;
+--error 1066
+handler test_test.t1 open h1;
+handler test_test.t3 open h3;
+handler test.t1 open h2;
+handler t1 read first limit 9;
+handler h1 read first limit 9;
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h2 read first limit 9;
+--error 1064
+handler test.h1 close;
+handler t1 close;
+handler h1 close;
+handler h2 close;
+--error 1109
+handler t1 read first limit 9;
+--error 1109
+handler h1 read first limit 9;
+--error 1109
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h3 read first limit 9;
+use test_test;
+handler h3 read first limit 9;
+--error 1064
+handler test.h3 read first limit 9;
+handler h3 close;
+use test;
+drop table t3;
+drop table t2;
+drop table t1;
+drop database test_test;
+
+#
+# Test if fix for BUG#4286 correctly closes handler tables.
+#
+create table t1 (c1 char(20));
+insert into t1 values ("t1");
+handler t1 open as h1;
+handler h1 read first limit 9;
+create table t2 (c1 char(20));
+insert into t2 values ("t2");
+handler t2 open as h2;
+handler h2 read first limit 9;
+create table t3 (c1 char(20));
+insert into t3 values ("t3");
+handler t3 open as h3;
+handler h3 read first limit 9;
+create table t4 (c1 char(20));
+insert into t4 values ("t4");
+handler t4 open as h4;
+handler h4 read first limit 9;
+create table t5 (c1 char(20));
+insert into t5 values ("t5");
+handler t5 open as h5;
+handler h5 read first limit 9;
+# close first
+eval alter table t1 engine=$other_handler_engine_type;
+--error 1109
+handler h1 read first limit 9;
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h4 read first limit 9;
+handler h5 read first limit 9;
+# close last
+eval alter table t5 engine=$other_handler_engine_type;
+--error 1109
+handler h1 read first limit 9;
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h4 read first limit 9;
+--error 1109
+handler h5 read first limit 9;
+# close middle
+eval alter table t3 engine=$other_handler_engine_type;
+--error 1109
+handler h1 read first limit 9;
+handler h2 read first limit 9;
+--error 1109
+handler h3 read first limit 9;
+handler h4 read first limit 9;
+--error 1109
+handler h5 read first limit 9;
+handler h2 close;
+handler h4 close;
+# close all depending handler tables
+handler t1 open as h1_1;
+handler t1 open as h1_2;
+handler t1 open as h1_3;
+handler h1_1 read first limit 9;
+handler h1_2 read first limit 9;
+handler h1_3 read first limit 9;
+eval alter table t1 engine=$engine_type;
+--error 1109
+handler h1_1 read first limit 9;
+--error 1109
+handler h1_2 read first limit 9;
+--error 1109
+handler h1_3 read first limit 9;
+drop table t1;
+drop table t2;
+drop table t3;
+drop table t4;
+drop table t5;
+
+#
+# Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash
+#
+create table t1 (c1 int);
+insert into t1 values (1);
+# client 1
+handler t1 open;
+handler t1 read first;
+# client 2
+connect (con2,localhost,root,,);
+connection con2;
+--exec echo send the below to another connection, do not wait for the result
+send optimize table t1;
+--sleep 1
+# client 1
+--exec echo proceed with the normal connection
+connection default;
+handler t1 read next;
+handler t1 close;
+# client 2
+--exec echo read the result from the other connection
+connection con2;
+reap;
+# client 1
+--exec echo proceed with the normal connection
+connection default;
+drop table t1;
+
+CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2));
+INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2);
+HANDLER t1 OPEN;
+HANDLER t1 READ `primary` = (1, 1000);
+HANDLER t1 READ `primary` PREV;
+DROP TABLE t1;
+
+# End of 4.1 tests
+
+#
+# Addendum to Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash
+# Show that DROP TABLE can no longer deadlock against
+# FLUSH TABLES WITH READ LOCK. This is a 5.0 issue.
+#
+create table t1 (c1 int);
+insert into t1 values (14397);
+flush tables with read lock;
+# The thread with the global read lock cannot drop the table itself:
+--error 1223
+drop table t1;
+#
+# client 2
+# We need a second connection to try the drop.
+# The drop waits for the global read lock to go away.
+# Without the addendum fix it locked LOCK_open before entering the wait loop.
+connection con2;
+--exec echo send the below to another connection, do not wait for the result
+send drop table t1;
+--sleep 1
+#
+# client 1
+# Now we need something that wants LOCK_open. A simple table access which
+# opens the table does the trick.
+--exec echo proceed with the normal connection
+connection default;
+# This would hang on LOCK_open without the 5.0 addendum fix.
+select * from t1;
+# Release the read lock. This should make the DROP go through.
+unlock tables;
+#
+# client 2
+# Read the result of the drop command.
+connection con2;
+--exec echo read the result from the other connection
+reap;
+#
+# client 1
+# Now back to normal operation. The table should not exist any more.
+--exec echo proceed with the normal connection
+connection default;
+--error 1146
+select * from t1;
+# Just to be sure and not confuse the next test case writer.
+drop table if exists t1;
+
+#
+# Bug#25856 - HANDLER table OPEN in one connection lock DROP TABLE in another one
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+eval create table t1 (a int) ENGINE=$other_engine_type;
+--echo --> client 2
+connection con2;
+--error 1031
+handler t1 open;
+--echo --> client 1
+connection default;
+drop table t1;
+
+#
+# Bug#30632 HANDLER read failure causes hang
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int);
+handler t1 open as t1_alias;
+--error 1176
+handler t1_alias read a next;
+--error 1054
+handler t1_alias READ a next where inexistent > 0;
+--error 1176
+handler t1_alias read a next;
+--error 1054
+handler t1_alias READ a next where inexistent > 0;
+handler t1_alias close;
+drop table t1;
+
+#
+# Bug#21587 FLUSH TABLES causes server crash when used with HANDLER statements
+#
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+create table t1 (c1 int);
+create table t2 (c1 int);
+insert into t1 values (1);
+insert into t2 values (2);
+--echo connection: default
+handler t1 open;
+handler t1 read first;
+connect (flush,localhost,root,,);
+connection flush;
+--echo connection: flush
+--send flush tables;
+connection default;
+--echo connection: default
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Flushing tables";
+--source include/wait_condition.inc
+handler t2 open;
+handler t2 read first;
+handler t1 read next;
+handler t1 close;
+handler t2 close;
+connection flush;
+reap;
+connection default;
+drop table t1,t2;
+disconnect flush;
+
+#
+# Bug#31409 RENAME TABLE causes server crash or deadlock when used with HANDLER statements
+#
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+create table t1 (c1 int);
+--echo connection: default
+handler t1 open;
+handler t1 read first;
+connect (flush,localhost,root,,);
+connection flush;
+--echo connection: flush
+--send rename table t1 to t2;
+connection default;
+--echo connection: default
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table" and info = "rename table t1 to t2";
+--source include/wait_condition.inc
+handler t2 open;
+handler t2 read first;
+--error ER_NO_SUCH_TABLE
+handler t1 read next;
+handler t1 close;
+handler t2 close;
+connection flush;
+reap;
+connection default;
+drop table t2;
+disconnect flush;
+
+#
+# Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
+#
+# Test HANDLER statements in conjunction with temporary tables. While the temporary table
+# is open by a HANDLER, no other statement can access it.
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create temporary table t1 (a int, b char(1), key a(a), key b(a,b));
+insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
+ (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+select a,b from t1;
+handler t1 open as a1;
+handler a1 read a first;
+handler a1 read a next;
+handler a1 read a next;
+--error ER_CANT_REOPEN_TABLE
+select a,b from t1;
+handler a1 read a prev;
+handler a1 read a prev;
+handler a1 read a=(6) where b="g";
+handler a1 close;
+select a,b from t1;
+handler t1 open as a2;
+handler a2 read a first;
+handler a2 read a last;
+handler a2 read a prev;
+handler a2 close;
+drop table t1;
+
+#
+# Bug#31397 Inconsistent drop table behavior of handler tables.
+#
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+create table t1 (a int);
+handler t1 open as t1_alias;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+flush tables;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias close;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias read first;
+drop table t1;
+--error ER_UNKNOWN_TABLE
+handler t1_alias read next;
+
+# Test that temporary tables associated with handlers are properly dropped.
+
+create table t1 (a int);
+create temporary table t2 (a int, key(a));
+handler t1 open as a1;
+handler t2 open as a2;
+handler a2 read a first;
+drop table t1, t2;
+--error ER_UNKNOWN_TABLE
+handler a2 read a next;
+--error ER_UNKNOWN_TABLE
+handler a1 close;
+
+# Alter table drop handlers
+
+create table t1 (a int, key(a));
+create table t2 like t1;
+handler t1 open as a1;
+handler t2 open as a2;
+handler a1 read a first;
+handler a2 read a first;
+alter table t1 add b int;
+--error ER_UNKNOWN_TABLE
+handler a1 close;
+handler a2 close;
+drop table t1, t2;
+
+# Rename table drop handlers
+
+create table t1 (a int, key(a));
+handler t1 open as a1;
+handler a1 read a first;
+rename table t1 to t2;
+--error ER_UNKNOWN_TABLE
+handler a1 read a first;
+drop table t2;
+
+# Optimize table drop handlers
+
+create table t1 (a int, key(a));
+create table t2 like t1;
+handler t1 open as a1;
+handler t2 open as a2;
+handler a1 read a first;
+handler a2 read a first;
+optimize table t1;
+--error ER_UNKNOWN_TABLE
+handler a1 close;
+handler a2 close;
+drop table t1, t2;
+
+# Flush tables causes handlers reopen
+
+create table t1 (a int, b char(1), key a(a), key b(a,b));
+insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
+ (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+handler t1 open;
+handler t1 read a first;
+handler t1 read a next;
+flush tables;
+handler t1 read a next;
+handler t1 read a next;
+flush tables with read lock;
+handler t1 read a next;
+unlock tables;
+drop table t1;
+--error ER_UNKNOWN_TABLE
+handler t1 read a next;
+
+#
+# Bug#41110: crash with handler command when used concurrently with alter table
+# Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int);
+insert into t1 values (1);
+handler t1 open;
+connect(con1,localhost,root,,);
+send alter table t1 engine=memory;
+connection default;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "rename result table" and info = "alter table t1 engine=memory";
+--source include/wait_condition.inc
+--error ER_ILLEGAL_HA
+handler t1 read a next;
+handler t1 close;
+connection con1;
+--reap
+drop table t1;
+connection default;
diff --git a/mysql-test/include/have_32bit.inc b/mysql-test/include/have_32bit.inc
new file mode 100644
index 00000000000..66684fb5325
--- /dev/null
+++ b/mysql-test/include/have_32bit.inc
@@ -0,0 +1,16 @@
+# Created by Horst Hunger 2008-04-15
+# see also have_64bit.inc
+
+--disable_query_log
+--disable_warnings
+let $save = `SELECT @@global.sort_buffer_size`;
+SET @@global.sort_buffer_size = 4294967296;
+let $mach32 = `SELECT @@global.sort_buffer_size <= 4294967295`;
+eval SET @@global.sort_buffer_size = $save;
+--enable_warnings
+--enable_query_log
+if (!$mach32)
+{
+ skip Need a 32 bit machine/binary;
+}
+
diff --git a/mysql-test/include/have_64bit.inc b/mysql-test/include/have_64bit.inc
new file mode 100644
index 00000000000..cbba5e1d338
--- /dev/null
+++ b/mysql-test/include/have_64bit.inc
@@ -0,0 +1,14 @@
+# Created by Horst Hunger 2008-04-15
+# see also have_32bit.inc
+
+--disable_query_log
+let $save = `SELECT @@session.sort_buffer_size`;
+SET @@session.sort_buffer_size = 4294967296;
+let $mach64 = `SELECT @@session.sort_buffer_size > 4294967295`;
+eval SET @@session.sort_buffer_size = $save;
+--enable_query_log
+if (!$mach64)
+{
+ skip Need a 64 binary ;
+}
+
diff --git a/mysql-test/include/have_archive.inc b/mysql-test/include/have_archive.inc
index 75460316322..82399ca4c6c 100644
--- a/mysql-test/include/have_archive.inc
+++ b/mysql-test/include/have_archive.inc
@@ -1,4 +1,4 @@
---require r/have_archive.require
--disable_query_log
-show variables like 'have_archive';
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'archive';
--enable_query_log
diff --git a/mysql-test/include/have_bdb.inc b/mysql-test/include/have_bdb.inc
deleted file mode 100644
index c2f29e0d286..00000000000
--- a/mysql-test/include/have_bdb.inc
+++ /dev/null
@@ -1,4 +0,0 @@
--- require r/have_bdb.require
-disable_query_log;
-show variables like 'have_bdb';
-enable_query_log;
diff --git a/mysql-test/include/have_binlog_format_mixed.inc b/mysql-test/include/have_binlog_format_mixed.inc
new file mode 100644
index 00000000000..f3e09f8649b
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_mixed.inc
@@ -0,0 +1,6 @@
+--source include/have_log_bin.inc
+
+-- require r/have_binlog_format_mixed.require
+disable_query_log;
+show variables like 'binlog_format';
+enable_query_log;
diff --git a/mysql-test/include/have_binlog_format_mixed_or_row.inc b/mysql-test/include/have_binlog_format_mixed_or_row.inc
new file mode 100644
index 00000000000..9217b607bb7
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_mixed_or_row.inc
@@ -0,0 +1,7 @@
+--source include/have_log_bin.inc
+
+--require r/have_binlog_format_row.require
+--disable_query_log
+--replace_result MIXED ROW
+show variables like 'binlog_format';
+--enable_query_log
diff --git a/mysql-test/include/have_binlog_format_mixed_or_statement.inc b/mysql-test/include/have_binlog_format_mixed_or_statement.inc
new file mode 100644
index 00000000000..6010d1ee7a8
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_mixed_or_statement.inc
@@ -0,0 +1,8 @@
+source include/have_log_bin.inc;
+
+
+--require r/have_binlog_format_statement.require
+--disable_query_log
+--replace_result MIXED STATEMENT
+show variables like 'binlog_format';
+--enable_query_log
diff --git a/mysql-test/include/have_binlog_format_row.inc b/mysql-test/include/have_binlog_format_row.inc
new file mode 100644
index 00000000000..e3d40ae76a8
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_row.inc
@@ -0,0 +1,6 @@
+--source include/have_log_bin.inc
+
+-- require r/have_binlog_format_row.require
+disable_query_log;
+show variables like 'binlog_format';
+enable_query_log;
diff --git a/mysql-test/include/have_binlog_format_row_or_statement.inc b/mysql-test/include/have_binlog_format_row_or_statement.inc
new file mode 100644
index 00000000000..4b6413d062b
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_row_or_statement.inc
@@ -0,0 +1,7 @@
+--source include/have_log_bin.inc
+
+-- require r/have_binlog_format_statement.require
+--disable_query_log
+--replace_result ROW STATEMENT
+show variables like 'binlog_format';
+--enable_query_log
diff --git a/mysql-test/include/have_binlog_format_statement.inc b/mysql-test/include/have_binlog_format_statement.inc
new file mode 100644
index 00000000000..1624773ec81
--- /dev/null
+++ b/mysql-test/include/have_binlog_format_statement.inc
@@ -0,0 +1,6 @@
+--source include/have_log_bin.inc
+
+-- require r/have_binlog_format_statement.require
+disable_query_log;
+show variables like 'binlog_format';
+enable_query_log;
diff --git a/mysql-test/include/have_blackhole.inc b/mysql-test/include/have_blackhole.inc
index d13c9fda3f5..146f5afb0d5 100644
--- a/mysql-test/include/have_blackhole.inc
+++ b/mysql-test/include/have_blackhole.inc
@@ -1,4 +1,5 @@
--- require r/have_blackhole.require
-disable_query_log;
-show variables like 'have_blackhole_engine';
-enable_query_log;
+if (!`SELECT count(*) FROM information_schema.engines WHERE
+ (support = 'YES' OR support = 'DEFAULT') AND
+ engine = 'blackhole'`){
+ skip Need blackhole engine;
+}
diff --git a/mysql-test/include/have_bug25714.inc b/mysql-test/include/have_bug25714.inc
deleted file mode 100644
index 0c09ae1a035..00000000000
--- a/mysql-test/include/have_bug25714.inc
+++ /dev/null
@@ -1,7 +0,0 @@
-#
-# Check if the variable MYSQL_BUG25714 is set
-#
---require r/have_bug25714.require
-disable_query_log;
-eval select LENGTH("$MYSQL_BUG25714") > 0 as "have_bug25714_exe";
-enable_query_log;
diff --git a/mysql-test/include/have_case_insensitive_file_system.inc b/mysql-test/include/have_case_insensitive_file_system.inc
new file mode 100644
index 00000000000..78bb7c229ca
--- /dev/null
+++ b/mysql-test/include/have_case_insensitive_file_system.inc
@@ -0,0 +1,4 @@
+--require r/case_insensitive_file_system.require
+--disable_query_log
+show variables like "lower_case_file_system";
+--enable_query_log
diff --git a/mysql-test/include/have_community_features.inc b/mysql-test/include/have_community_features.inc
new file mode 100644
index 00000000000..66697d8dd00
--- /dev/null
+++ b/mysql-test/include/have_community_features.inc
@@ -0,0 +1,4 @@
+--require r/have_community_features.require
+--disable_query_log
+show variables like 'have_community_features';
+--enable_query_log
diff --git a/mysql-test/include/have_cp1251.inc b/mysql-test/include/have_cp1251.inc
new file mode 100644
index 00000000000..2d5f1b3b529
--- /dev/null
+++ b/mysql-test/include/have_cp1251.inc
@@ -0,0 +1,7 @@
+--require r/have_cp1251.require
+
+--disable_query_log
+
+SHOW COLLATION LIKE 'cp1251_general_ci';
+
+--enable_query_log
diff --git a/mysql-test/include/have_cp866.inc b/mysql-test/include/have_cp866.inc
new file mode 100644
index 00000000000..27390d87d51
--- /dev/null
+++ b/mysql-test/include/have_cp866.inc
@@ -0,0 +1,7 @@
+--require r/have_cp866.require
+
+--disable_query_log
+
+SHOW COLLATION LIKE 'cp866_general_ci';
+
+--enable_query_log
diff --git a/mysql-test/include/have_csv.inc b/mysql-test/include/have_csv.inc
index 12e69962486..410caa95285 100644
--- a/mysql-test/include/have_csv.inc
+++ b/mysql-test/include/have_csv.inc
@@ -1,4 +1,4 @@
--- require r/have_csv.require
disable_query_log;
-show variables like 'have_csv';
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'csv';
enable_query_log;
diff --git a/mysql-test/include/have_debug.inc b/mysql-test/include/have_debug.inc
index ff59037b6eb..6f3a82881f5 100644
--- a/mysql-test/include/have_debug.inc
+++ b/mysql-test/include/have_debug.inc
@@ -1,4 +1,4 @@
-- require r/have_debug.require
disable_query_log;
-select (version() like "%debug%") as debug;
+select (version() like '%debug%') as debug;
enable_query_log;
diff --git a/mysql-test/include/have_example_plugin.inc b/mysql-test/include/have_example_plugin.inc
new file mode 100644
index 00000000000..8e57c725eb5
--- /dev/null
+++ b/mysql-test/include/have_example_plugin.inc
@@ -0,0 +1,16 @@
+#
+# Check if server has support for loading udf's
+# i.e it will support dlopen
+#
+--require r/have_dynamic_loading.require
+disable_query_log;
+show variables like 'have_dynamic_loading';
+enable_query_log;
+
+#
+# Check if the variable EXAMPLE_PLUGIN is set
+#
+--require r/have_example_plugin.require
+disable_query_log;
+eval select LENGTH('$EXAMPLE_PLUGIN') > 0 as 'have_example_plugin';
+enable_query_log;
diff --git a/mysql-test/include/have_exampledb.inc b/mysql-test/include/have_exampledb.inc
index b8f9a24463e..db3985e3c7c 100644
--- a/mysql-test/include/have_exampledb.inc
+++ b/mysql-test/include/have_exampledb.inc
@@ -1,4 +1,4 @@
--- require r/have_exampledb.require
disable_query_log;
-show variables like 'have_example_engine';
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'example';
enable_query_log;
diff --git a/mysql-test/include/have_federated_db.inc b/mysql-test/include/have_federated_db.inc
deleted file mode 100644
index 4745534780d..00000000000
--- a/mysql-test/include/have_federated_db.inc
+++ /dev/null
@@ -1,4 +0,0 @@
--- require r/have_federated_db.require
-disable_query_log;
-show variables like 'have_federated_engine';
-enable_query_log;
diff --git a/mysql-test/include/have_innodb.inc b/mysql-test/include/have_innodb.inc
index 4142b84813b..8944cc46f3e 100644
--- a/mysql-test/include/have_innodb.inc
+++ b/mysql-test/include/have_innodb.inc
@@ -1,4 +1,4 @@
--- require r/have_innodb.require
disable_query_log;
-show variables like 'have_innodb';
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` from information_schema.engines where engine = 'innodb';
enable_query_log;
diff --git a/mysql-test/include/have_koi8r.inc b/mysql-test/include/have_koi8r.inc
new file mode 100644
index 00000000000..1fe163565ba
--- /dev/null
+++ b/mysql-test/include/have_koi8r.inc
@@ -0,0 +1,7 @@
+--require r/have_koi8r.require
+
+--disable_query_log
+
+SHOW COLLATION LIKE 'koi8r_general_ci';
+
+--enable_query_log
diff --git a/mysql-test/include/have_log_bin.inc b/mysql-test/include/have_log_bin.inc
index 5bcdb30b3e0..369af9b8e1d 100644
--- a/mysql-test/include/have_log_bin.inc
+++ b/mysql-test/include/have_log_bin.inc
@@ -1,3 +1,11 @@
+# ==== Purpose ====
+#
+# Ensure that the server is running with binlogging on
+#
+# ==== Usage ====
+#
+# source include/have_log_bin.inc;
+
-- require r/have_log_bin.require
disable_query_log;
show variables like 'log_bin';
diff --git a/mysql-test/include/have_lowercase0.inc b/mysql-test/include/have_lowercase0.inc
index 6192acb7b01..9cd21a42f6a 100644
--- a/mysql-test/include/have_lowercase0.inc
+++ b/mysql-test/include/have_lowercase0.inc
@@ -1,4 +1,4 @@
--require r/lowercase0.require
--disable_query_log
-show variables like 'lower_case_%';
+show variables like "lower_case_table_names";
--enable_query_log
diff --git a/mysql-test/include/have_lowercase2.inc b/mysql-test/include/have_lowercase2.inc
new file mode 100644
index 00000000000..43b34653f54
--- /dev/null
+++ b/mysql-test/include/have_lowercase2.inc
@@ -0,0 +1,4 @@
+--require r/lowercase2.require
+--disable_query_log
+show variables like 'lower_case_table_names';
+--enable_query_log
diff --git a/mysql-test/include/have_multi_ndb.inc b/mysql-test/include/have_multi_ndb.inc
index 7f922d85ff2..8dbfa2aa034 100644
--- a/mysql-test/include/have_multi_ndb.inc
+++ b/mysql-test/include/have_multi_ndb.inc
@@ -4,25 +4,49 @@ connect (server2,127.0.0.1,root,,test,$MASTER_MYPORT1,);
# Check that server1 has NDB support
connection server1;
+let $engines_table= query_get_value(SHOW TABLES FROM information_schema LIKE 'ENGINES', Tables_in_information_schema (ENGINES), 1);
disable_query_log;
---disable_warnings
-drop table if exists t1, t2;
---enable_warnings
-flush tables;
---require r/have_ndb.require
-show variables like 'have_ndbcluster';
+if (`SELECT 1 FROM dual WHERE '$engines_table' = 'engines'`)
+{
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+}
enable_query_log;
# Check that server2 has NDB support
connection server2;
+let $engines_table= query_get_value(SHOW TABLES FROM information_schema LIKE 'ENGINES', Tables_in_information_schema (ENGINES), 1);
+disable_query_log;
+if (`SELECT 1 FROM dual WHERE '$engines_table' = 'engines'`)
+{
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') as `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+}
+enable_query_log;
+
+# cleanup
+
+connection server1;
+disable_query_log;
+disable_warnings;
+--error 0,1051
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+flush tables;
+flush status;
+enable_warnings;
+enable_query_log;
+
+connection server2;
disable_query_log;
---disable_warnings
-drop table if exists t1, t2;
---enable_warnings
+disable_warnings;
+--error 0,1051
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
flush tables;
---require r/have_ndb.require
-show variables like 'have_ndbcluster';
+flush status;
+enable_warnings;
enable_query_log;
-# Set the default connection to 'server1'
+# Set the default connection
connection server1;
diff --git a/mysql-test/include/have_ndb.inc b/mysql-test/include/have_ndb.inc
index 691adc12231..cfc5b5d0ff8 100644
--- a/mysql-test/include/have_ndb.inc
+++ b/mysql-test/include/have_ndb.inc
@@ -1,13 +1,10 @@
# Check that server is compiled and started with support for NDB
--- require r/have_ndb.require
-disable_query_log;
-show variables like 'have_ndbcluster';
-enable_query_log;
-
-# Check that NDB is installed and known to be working
--- require r/have_ndb_status_ok.require
-disable_query_log;
-eval select "$NDB_STATUS_OK" as ndb_status_ok;
-enable_query_log;
-
-
+#disable_query_log;
+#--require r/true.require
+#select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'ndbcluster';
+#--source include/ndb_not_readonly.inc
+#enable_query_log;
+# always make sure we have both mysql servers started ok before test starts
+# there are some initial startup bugs that are avoided by doing this, avoiding sporadic
+# failures in mysql-test-run
+--source include/have_multi_ndb.inc
diff --git a/mysql-test/include/have_ndb_extra.inc b/mysql-test/include/have_ndb_extra.inc
new file mode 100644
index 00000000000..4837a7ad4ea
--- /dev/null
+++ b/mysql-test/include/have_ndb_extra.inc
@@ -0,0 +1,2 @@
+-- require r/have_ndb_extra.require
+eval select $NDB_EXTRA_TEST;
diff --git a/mysql-test/include/have_ndbapi_examples.inc b/mysql-test/include/have_ndbapi_examples.inc
new file mode 100644
index 00000000000..88499d555c0
--- /dev/null
+++ b/mysql-test/include/have_ndbapi_examples.inc
@@ -0,0 +1,4 @@
+--require r/have_ndbapi_examples.require
+disable_query_log;
+eval select LENGTH('$NDB_EXAMPLES_BINARY') > 0 as 'have_ndb_example';
+enable_query_log;
diff --git a/mysql-test/include/have_outfile.inc b/mysql-test/include/have_outfile.inc
index ae4a2723840..d1d4e1a0fee 100644
--- a/mysql-test/include/have_outfile.inc
+++ b/mysql-test/include/have_outfile.inc
@@ -1,5 +1,5 @@
-- require r/have_outfile.require
disable_query_log;
-select load_file(concat(@tmpdir,"/outfile.test"));
+select load_file(concat(@tmpdir,'/outfile.test'));
--remove_file $MYSQLTEST_VARDIR/tmp/outfile.test
enable_query_log;
diff --git a/mysql-test/include/have_partition.inc b/mysql-test/include/have_partition.inc
new file mode 100644
index 00000000000..b45572ad31e
--- /dev/null
+++ b/mysql-test/include/have_partition.inc
@@ -0,0 +1,4 @@
+-- require r/have_partition.require
+disable_query_log;
+show variables like 'have_partitioning';
+enable_query_log;
diff --git a/mysql-test/include/have_query_cache.inc b/mysql-test/include/have_query_cache.inc
index 647f8598ae6..09602fd2dd5 100644
--- a/mysql-test/include/have_query_cache.inc
+++ b/mysql-test/include/have_query_cache.inc
@@ -1,7 +1,4 @@
-- require r/have_query_cache.require
-# As PS are not cached we disable them to ensure the we get the right number
-# of query cache hits
--- disable_ps_protocol
disable_query_log;
show variables like 'have_query_cache';
enable_query_log;
diff --git a/mysql-test/include/have_simple_parser.inc b/mysql-test/include/have_simple_parser.inc
new file mode 100644
index 00000000000..c85786bd524
--- /dev/null
+++ b/mysql-test/include/have_simple_parser.inc
@@ -0,0 +1,16 @@
+#
+# Check if server has support for loading udf's
+# i.e it will support dlopen
+#
+--require r/have_dynamic_loading.require
+disable_query_log;
+show variables like 'have_dynamic_loading';
+enable_query_log;
+
+#
+# Check if the variable SIMPLE_PARSER is set
+#
+--require r/have_simple_parser.require
+disable_query_log;
+eval select LENGTH('$SIMPLE_PARSER') > 0 as 'have_simple_parser';
+enable_query_log;
diff --git a/mysql-test/include/have_symlink.inc b/mysql-test/include/have_symlink.inc
new file mode 100644
index 00000000000..ec4743531fd
--- /dev/null
+++ b/mysql-test/include/have_symlink.inc
@@ -0,0 +1,10 @@
+# Several partition-related tests include this file, because Valgrind/Purify
+# builds disable symlink support; some partition functionality depends on
+# symlink support, and so does not test correctly under valgrind. See the
+# comment in mysqld.cc for the --symbolic-links option.
+
+-- require r/have_symlink.require
+
+disable_query_log;
+show variables like 'have_symlink';
+enable_query_log;
diff --git a/mysql-test/include/have_udf.inc b/mysql-test/include/have_udf.inc
index 154dccf2270..3f7e260c5ba 100644
--- a/mysql-test/include/have_udf.inc
+++ b/mysql-test/include/have_udf.inc
@@ -2,7 +2,7 @@
# Check if server has support for loading udf's
# i.e it will support dlopen
#
---require r/have_udf.require
+--require r/have_dynamic_loading.require
disable_query_log;
show variables like 'have_dynamic_loading';
enable_query_log;
@@ -12,5 +12,5 @@ enable_query_log;
#
--require r/have_udf_example.require
disable_query_log;
-eval select LENGTH("$UDF_EXAMPLE_LIB") > 0 as "have_udf_example_lib";
+eval select LENGTH('$UDF_EXAMPLE_LIB') > 0 as 'have_udf_example_lib';
enable_query_log;
diff --git a/mysql-test/include/have_utf8.inc b/mysql-test/include/have_utf8.inc
new file mode 100644
index 00000000000..58b74f4072f
--- /dev/null
+++ b/mysql-test/include/have_utf8.inc
@@ -0,0 +1,7 @@
+--require r/have_utf8.require
+
+--disable_query_log
+
+SHOW COLLATION LIKE 'utf8_general_ci';
+
+--enable_query_log
diff --git a/mysql-test/include/im_check_env.inc b/mysql-test/include/im_check_env.inc
deleted file mode 100644
index 019e0984614..00000000000
--- a/mysql-test/include/im_check_env.inc
+++ /dev/null
@@ -1,25 +0,0 @@
-# This file is intended to be used in each IM-test. It contains stamements,
-# that ensure that starting conditions (environment) for the IM-test are as
-# expected.
-
-# Check the running instances.
-
---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
-
---connection mysql1_con
-
-SHOW VARIABLES LIKE 'server_id';
-
---source include/not_windows.inc
-
---connection default
-
-# Let IM detect that mysqld1 is online. This delay should be longer than
-# monitoring interval.
-
---sleep 2
-
-# Check that IM understands that mysqld1 is online, while mysqld2 is
-# offline.
-
-SHOW INSTANCES;
diff --git a/mysql-test/include/index_merge1.inc b/mysql-test/include/index_merge1.inc
new file mode 100644
index 00000000000..5837df67a75
--- /dev/null
+++ b/mysql-test/include/index_merge1.inc
@@ -0,0 +1,530 @@
+# include/index_merge1.inc
+#
+# Index merge tests
+#
+# The variables
+# $engine_type -- storage engine to be tested
+# $merge_table_support -- 1 storage engine supports merge tables
+# -- 0 storage engine does not support merge tables
+# have to be set before sourcing this script.
+#
+# Note: The comments/expectations refer to MyISAM.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/index_merge.test
+# main code went into include/index_merge1.inc
+#
+
+--echo #---------------- Index merge test 1 -------------------------------------------
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t0, t1, t2, t3, t4;
+--enable_warnings
+
+# Create and fill a table with simple keys
+create table t0
+(
+ key1 int not null,
+ INDEX i1(key1)
+);
+
+--disable_query_log
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+
+let $1=7;
+set @d=8;
+while ($1)
+{
+ eval insert into t0 select key1+@d from t0;
+ eval set @d=@d*2;
+ dec $1;
+}
+--enable_query_log
+
+alter table t0 add key2 int not null, add index i2(key2);
+alter table t0 add key3 int not null, add index i3(key3);
+alter table t0 add key4 int not null, add index i4(key4);
+alter table t0 add key5 int not null, add index i5(key5);
+alter table t0 add key6 int not null, add index i6(key6);
+alter table t0 add key7 int not null, add index i7(key7);
+alter table t0 add key8 int not null, add index i8(key8);
+
+update t0 set key2=key1,key3=key1,key4=key1,key5=key1,key6=key1,key7=key1,key8=1024-key1;
+analyze table t0;
+
+# 1. One index
+explain select * from t0 where key1 < 3 or key1 > 1020;
+
+# 2. Simple cases
+explain
+select * from t0 where key1 < 3 or key2 > 1020;
+select * from t0 where key1 < 3 or key2 > 1020;
+
+explain select * from t0 where key1 < 3 or key2 <4;
+
+explain
+select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40);
+# Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
+select * from t0 where (key1 > 30 and key1<35) or (key2 >32 and key2 < 40);
+
+# 3. Check that index_merge doesn't break "ignore/force/use index"
+explain select * from t0 ignore index (i2) where key1 < 3 or key2 <4;
+explain select * from t0 where (key1 < 3 or key2 <4) and key3 = 50;
+explain select * from t0 use index (i1,i2) where (key1 < 3 or key2 <4) and key3 = 50;
+
+explain select * from t0 where (key1 > 1 or key2 > 2);
+explain select * from t0 force index (i1,i2) where (key1 > 1 or key2 > 2);
+
+
+# 4. Check if conjuncts are grouped by keyuse
+explain
+ select * from t0 where key1<3 or key2<3 or (key1>5 and key1<8) or
+ (key1>10 and key1<12) or (key2>100 and key2<110);
+
+# 5. Check index_merge with conjuncts that are always true/false
+# verify fallback to "range" if there is only one non-confluent condition
+explain select * from t0 where key2 = 45 or key1 <=> null;
+
+explain select * from t0 where key2 = 45 or key1 is not null;
+explain select * from t0 where key2 = 45 or key1 is null;
+
+# the last conj. is always false and will be discarded
+explain select * from t0 where key2=10 or key3=3 or key4 <=> null;
+
+# the last conj. is always true and will cause 'all' scan
+explain select * from t0 where key2=10 or key3=3 or key4 is null;
+
+# some more complicated cases
+explain select key1 from t0 where (key1 <=> null) or (key2 < 5) or
+ (key3=10) or (key4 <=> null);
+explain select key1 from t0 where (key1 <=> null) or (key1 < 5) or
+ (key3=10) or (key4 <=> null);
+
+# 6.Several ways to do index_merge, (ignored) index_merge vs. range
+explain select * from t0 where
+ (key1 < 3 or key2 < 3) and (key3 < 4 or key4 < 4) and (key5 < 5 or key6 < 5);
+
+explain
+select * from t0 where (key1 < 3 or key2 < 6) and (key1 < 7 or key3 < 4);
+
+select * from t0 where (key1 < 3 or key2 < 6) and (key1 < 7 or key3 < 4);
+
+
+explain select * from t0 where
+ (key1 < 3 or key2 < 3) and (key3 < 4 or key4 < 4) and (key5 < 2 or key6 < 2);
+
+# now index_merge is not used at all when "range" is possible
+explain select * from t0 where
+ (key1 < 3 or key2 < 3) and (key3 < 100);
+
+# this even can cause "all" scan:
+explain select * from t0 where
+ (key1 < 3 or key2 < 3) and (key3 < 1000);
+
+
+# 7. Complex cases
+# tree_or(List<SEL_IMERGE>, range SEL_TREE).
+explain select * from t0 where
+ ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4))
+ or
+ key2 > 5;
+
+explain select * from t0 where
+ ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4))
+ or
+ key1 < 7;
+
+select * from t0 where
+ ((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4))
+ or
+ key1 < 7;
+
+# tree_or(List<SEL_IMERGE>, List<SEL_IMERGE>).
+explain select * from t0 where
+ ((key1 < 4 or key2 < 4) and (key3 <5 or key5 < 4))
+ or
+ ((key5 < 5 or key6 < 6) and (key7 <7 or key8 < 4));
+
+explain select * from t0 where
+ ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
+ or
+ ((key7 <7 or key8 < 4) and (key5 < 5 or key6 < 6));
+
+explain select * from t0 where
+ ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
+ or
+ ((key3 <7 or key5 < 2) and (key5 < 5 or key6 < 6));
+
+explain select * from t0 where
+ ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
+ or
+ (((key3 <7 and key7 < 6) or key5 < 2) and (key5 < 5 or key6 < 6));
+
+explain select * from t0 where
+ ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
+ or
+ ((key3 >=5 or key5 < 2) and (key5 < 5 or key6 < 6));
+
+explain select * from t0 force index(i1, i2, i3, i4, i5, i6 ) where
+ ((key3 <5 or key5 < 4) and (key1 < 4 or key2 < 4))
+ or
+ ((key3 >=5 or key5 < 2) and (key5 < 5 or key6 < 6));
+
+# 8. Verify that "order by" after index merge uses filesort
+select * from t0 where key1 < 5 or key8 < 4 order by key1;
+
+explain
+select * from t0 where key1 < 5 or key8 < 4 order by key1;
+
+# 9. Check that index_merge cost is compared to 'index' where possible
+create table t2 like t0;
+insert into t2 select * from t0;
+
+alter table t2 add index i1_3(key1, key3);
+alter table t2 add index i2_3(key2, key3);
+alter table t2 drop index i1;
+alter table t2 drop index i2;
+alter table t2 add index i321(key3, key2, key1);
+
+# index_merge vs 'index', index_merge is better.
+explain select key3 from t2 where key1 = 100 or key2 = 100;
+
+# index_merge vs 'index', 'index' is better.
+explain select key3 from t2 where key1 <100 or key2 < 100;
+
+# index_merge vs 'all', index_merge is better.
+explain select key7 from t2 where key1 <100 or key2 < 100;
+
+# 10. Multipart keys.
+create table t4 (
+ key1a int not null,
+ key1b int not null,
+ key2 int not null,
+ key2_1 int not null,
+ key2_2 int not null,
+ key3 int not null,
+ index i1a (key1a, key1b),
+ index i1b (key1b, key1a),
+ index i2_1(key2, key2_1),
+ index i2_2(key2, key2_1)
+);
+
+insert into t4 select key1,key1,key1 div 10, key1 % 10, key1 % 10, key1 from t0;
+
+# the following will be handled by index_merge:
+select * from t4 where key1a = 3 or key1b = 4;
+explain select * from t4 where key1a = 3 or key1b = 4;
+
+# and the following will not
+explain select * from t4 where key2 = 1 and (key2_1 = 1 or key3 = 5);
+
+explain select * from t4 where key2 = 1 and (key2_1 = 1 or key2_2 = 5);
+
+explain select * from t4 where key2_1 = 1 or key2_2 = 5;
+
+
+# 11. Multitable selects
+create table t1 like t0;
+insert into t1 select * from t0;
+
+# index_merge on first table in join
+explain select * from t0 left join t1 on (t0.key1=t1.key1)
+ where t0.key1=3 or t0.key2=4;
+
+select * from t0 left join t1 on (t0.key1=t1.key1)
+ where t0.key1=3 or t0.key2=4;
+
+explain
+select * from t0,t1 where (t0.key1=t1.key1) and ( t0.key1=3 or t0.key2=4);
+
+# index_merge vs. ref
+explain
+select * from t0,t1 where (t0.key1=t1.key1) and
+ (t0.key1=3 or t0.key2=4) and t1.key1<200;
+
+# index_merge vs. ref
+explain
+select * from t0,t1 where (t0.key1=t1.key1) and
+ (t0.key1=3 or t0.key2<4) and t1.key1=2;
+
+# index_merge on second table in join
+explain select * from t0,t1 where t0.key1 = 5 and
+ (t1.key1 = t0.key1 or t1.key8 = t0.key1);
+
+# Fix for bug#1974
+explain select * from t0,t1 where t0.key1 < 3 and
+ (t1.key1 = t0.key1 or t1.key8 = t0.key1);
+
+# index_merge inside union
+explain select * from t1 where key1=3 or key2=4
+ union select * from t1 where key1<4 or key3=5;
+
+# index merge in subselect
+explain select * from (select * from t1 where key1 = 3 or key2 =3) as Z where key8 >5;
+
+# 12. check for long index_merges.
+create table t3 like t0;
+insert into t3 select * from t0;
+alter table t3 add key9 int not null, add index i9(key9);
+alter table t3 add keyA int not null, add index iA(keyA);
+alter table t3 add keyB int not null, add index iB(keyB);
+alter table t3 add keyC int not null, add index iC(keyC);
+update t3 set key9=key1,keyA=key1,keyB=key1,keyC=key1;
+
+explain select * from t3 where
+ key1=1 or key2=2 or key3=3 or key4=4 or
+ key5=5 or key6=6 or key7=7 or key8=8 or
+ key9=9 or keyA=10 or keyB=11 or keyC=12;
+
+select * from t3 where
+ key1=1 or key2=2 or key3=3 or key4=4 or
+ key5=5 or key6=6 or key7=7 or key8=8 or
+ key9=9 or keyA=10 or keyB=11 or keyC=12;
+
+# Test for Bug#3183
+explain select * from t0 where key1 < 3 or key2 < 4;
+# Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
+select * from t0 where key1 < 3 or key2 < 4;
+
+update t0 set key8=123 where key1 < 3 or key2 < 4;
+# Bug#21277: InnoDB, wrong result set, index_merge strategy, second index not evaluated
+select * from t0 where key1 < 3 or key2 < 4;
+
+delete from t0 where key1 < 3 or key2 < 4;
+select * from t0 where key1 < 3 or key2 < 4;
+select count(*) from t0;
+
+# Test for BUG#4177
+drop table t4;
+create table t4 (a int);
+insert into t4 values (1),(4),(3);
+set @save_join_buffer_size=@@join_buffer_size;
+set join_buffer_size= 4000;
+explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
+ where (A.key1 < 500000 or A.key2 < 3)
+ and (B.key1 < 500000 or B.key2 < 3);
+
+select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
+ where (A.key1 < 500000 or A.key2 < 3)
+ and (B.key1 < 500000 or B.key2 < 3);
+
+update t0 set key1=1;
+explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
+ where (A.key1 = 1 or A.key2 = 1)
+ and (B.key1 = 1 or B.key2 = 1);
+
+select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
+ where (A.key1 = 1 or A.key2 = 1)
+ and (B.key1 = 1 or B.key2 = 1);
+
+alter table t0 add filler1 char(200), add filler2 char(200), add filler3 char(200);
+update t0 set key2=1, key3=1, key4=1, key5=1,key6=1,key7=1 where key7 < 500;
+
+# The next query will not use index i7 in intersection if the OS doesn't
+# support file sizes > 2GB. (ha_myisam::ref_length depends on this and index
+# scan cost estimates depend on ha_myisam::ref_length)
+--replace_column 9 #
+--replace_result "4,4,4,4,4,4,4" X "4,4,4,4,4,4" X "i6,i7" "i6,i7?" "i6" "i6,i7?"
+explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A, t0 as B
+ where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
+ and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
+
+select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
+ from t0 as A, t0 as B
+ where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
+ and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
+
+set join_buffer_size= @save_join_buffer_size;
+# Test for BUG#4177 ends
+
+drop table t0, t1, t2, t3, t4;
+
+# BUG#16166
+CREATE TABLE t1 (
+ cola char(3) not null, colb char(3) not null, filler char(200),
+ key(cola), key(colb)
+);
+INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ');
+
+--disable_query_log
+let $1=9;
+while ($1)
+{
+ eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo';
+ dec $1;
+}
+
+let $1=13;
+while ($1)
+{
+ eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo';
+ dec $1;
+}
+
+--enable_query_log
+
+OPTIMIZE TABLE t1;
+select count(*) from t1;
+explain select * from t1 WHERE cola = 'foo' AND colb = 'bar';
+explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar';
+drop table t1;
+
+if ($merge_table_support)
+{
+#
+# BUG#17314: Index_merge/intersection not choosen by the optimizer for MERGE tables
+#
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+ a int, b int,
+ filler1 char(200), filler2 char(200),
+ key(a),key(b)
+);
+insert into t1 select @v:= A.a, @v, 't1', 'filler2' from t0 A, t0 B, t0 C;
+create table t2 like t1;
+
+create table t3 (
+ a int, b int,
+ filler1 char(200), filler2 char(200),
+ key(a),key(b)
+) engine=merge union=(t1,t2);
+
+--replace_column 9 #
+explain select * from t1 where a=1 and b=1;
+--replace_column 9 #
+explain select * from t3 where a=1 and b=1;
+
+drop table t3;
+drop table t0, t1, t2;
+}
+
+#
+# BUG#20256 - LOCK WRITE - MyISAM
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(1);
+CREATE TABLE t2(a INT, b INT, dummy CHAR(16) DEFAULT '', KEY(a), KEY(b));
+INSERT INTO t2(a,b) VALUES
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
+(1,2);
+LOCK TABLES t1 WRITE, t2 WRITE;
+INSERT INTO t2(a,b) VALUES(1,2);
+SELECT t2.a FROM t1,t2 WHERE t2.b=2 AND t2.a=1;
+UNLOCK TABLES;
+DROP TABLE t1, t2;
+
+#
+# BUG#29740: HA_KEY_SCAN_NOT_ROR wasn't set for HEAP engine
+#
+CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `filler` char(200) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ KEY `a` (`a`),
+ KEY `b` (`b`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1;
+
+insert into t1 values
+(0, 'filler', 0), (1, 'filler', 1), (2, 'filler', 2), (3, 'filler', 3),
+(4, 'filler', 4), (5, 'filler', 5), (6, 'filler', 6), (7, 'filler', 7),
+(8, 'filler', 8), (9, 'filler', 9), (0, 'filler', 0), (1, 'filler', 1),
+(2, 'filler', 2), (3, 'filler', 3), (4, 'filler', 4), (5, 'filler', 5),
+(6, 'filler', 6), (7, 'filler', 7), (8, 'filler', 8), (9, 'filler', 9),
+(10, 'filler', 10), (11, 'filler', 11), (12, 'filler', 12), (13, 'filler', 13),
+(14, 'filler', 14), (15, 'filler', 15), (16, 'filler', 16), (17, 'filler', 17),
+(18, 'filler', 18), (19, 'filler', 19), (4, '5 ', 0), (5, '4 ', 0),
+(4, '4 ', 0), (4, 'qq ', 5), (5, 'qq ', 4), (4, 'zz ', 4);
+
+create table t2(
+ `a` int(11) DEFAULT NULL,
+ `filler` char(200) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ KEY USING BTREE (`a`),
+ KEY USING BTREE (`b`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1;
+insert into t2 select * from t1;
+
+--echo must use sort-union rather than union:
+--replace_column 9 #
+explain select * from t1 where a=4 or b=4;
+--sorted_result
+select * from t1 where a=4 or b=4;
+--sorted_result
+select * from t1 ignore index(a,b) where a=4 or b=4;
+
+--echo must use union, not sort-union:
+--replace_column 9 #
+explain select * from t2 where a=4 or b=4;
+--sorted_result
+select * from t2 where a=4 or b=4;
+
+drop table t1, t2;
+
+#
+# Bug #37943: Reproducible mysqld crash/sigsegv in sel_trees_can_be_ored
+#
+
+CREATE TABLE t1 (a varchar(8), b set('a','b','c','d','e','f','g','h'),
+ KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES ('y',''), ('z','');
+
+#should not crash
+SELECT b,a from t1 WHERE (b!='c' AND b!='f' && b!='h') OR
+ (a='pure-S') OR (a='DE80337a') OR (a='DE80799');
+
+DROP TABLE t1;
+
+--echo #
+--echo # BUG#40974: Incorrect query results when using clause evaluated using range check
+--echo #
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (a int);
+insert into t1 values (1),(2);
+create table t2(a int, b int);
+insert into t2 values (1,1), (2, 1000);
+create table t3 (a int, b int, filler char(100), key(a), key(b));
+
+insert into t3 select 1000, 1000,'filler' from t0 A, t0 B, t0 C;
+insert into t3 values (1,1,'data');
+insert into t3 values (1,1,'data');
+-- echo The plan should be ALL/ALL/ALL(Range checked for each record (index map: 0x3)
+explain select * from t1
+where exists (select 1 from t2, t3
+ where t2.a=t1.a and (t3.a=t2.b or t3.b=t2.b or t3.b=t2.b+1));
+
+select * from t1
+where exists (select 1 from t2, t3
+ where t2.a=t1.a and (t3.a=t2.b or t3.b=t2.b or t3.b=t2.b+1));
+
+drop table t0, t1, t2, t3;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/include/index_merge2.inc b/mysql-test/include/index_merge2.inc
new file mode 100644
index 00000000000..d65115eac0f
--- /dev/null
+++ b/mysql-test/include/index_merge2.inc
@@ -0,0 +1,345 @@
+# include/index_merge2.inc
+#
+# Index merge tests
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Note: The comments/expectations refer to InnoDB.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/index_merge_innodb.test
+# main code went into include/index_merge2.inc
+#
+
+--echo #---------------- Index merge test 2 -------------------------------------------
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
+create table t1
+(
+ key1 int not null,
+ key2 int not null,
+
+ INDEX i1(key1),
+ INDEX i2(key2)
+);
+
+--disable_query_log
+let $1=200;
+while ($1)
+{
+ eval insert into t1 values (200-$1, $1);
+ dec $1;
+}
+--enable_query_log
+
+# No primary key
+explain select * from t1 where key1 < 5 or key2 > 197;
+
+select * from t1 where key1 < 5 or key2 > 197;
+
+explain select * from t1 where key1 < 3 or key2 > 195;
+select * from t1 where key1 < 3 or key2 > 195;
+
+# Primary key as case-sensitive string with \0s.
+# also make primary key be longer then max. index length of MyISAM.
+alter table t1 add str1 char (255) not null,
+ add zeroval int not null default 0,
+ add str2 char (255) not null,
+ add str3 char (255) not null;
+
+update t1 set str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', 'A'));
+
+alter table t1 add primary key (str1, zeroval, str2, str3);
+
+explain select * from t1 where key1 < 5 or key2 > 197;
+
+select * from t1 where key1 < 5 or key2 > 197;
+
+explain select * from t1 where key1 < 3 or key2 > 195;
+select * from t1 where key1 < 3 or key2 > 195;
+
+# Test for BUG#5401
+drop table t1;
+create table t1 (
+ pk integer not null auto_increment primary key,
+ key1 integer,
+ key2 integer not null,
+ filler char (200),
+ index (key1),
+ index (key2)
+);
+show warnings;
+--disable_query_log
+let $1=30;
+while ($1)
+{
+ eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data');
+ dec $1;
+}
+--enable_query_log
+explain select pk from t1 where key1 = 1 and key2 = 1;
+select pk from t1 where key2 = 1 and key1 = 1;
+select pk from t1 ignore index(key1,key2) where key2 = 1 and key1 = 1;
+
+# More tests for BUG#5401.
+drop table t1;
+create table t1 (
+ pk int primary key auto_increment,
+ key1a int,
+ key2a int,
+ key1b int,
+ key2b int,
+ dummy1 int,
+ dummy2 int,
+ dummy3 int,
+ dummy4 int,
+ key3a int,
+ key3b int,
+ filler1 char (200),
+ index i1(key1a, key1b),
+ index i2(key2a, key2b),
+ index i3(key3a, key3b)
+);
+
+create table t2 (a int);
+insert into t2 values (0),(1),(2),(3),(4),(NULL);
+
+insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
+ select A.a, B.a, C.a, D.a, C.a, D.a from t2 A,t2 B,t2 C, t2 D;
+insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
+ select key1a, key1b, key2a, key2b, key3a, key3b from t1;
+insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
+ select key1a, key1b, key2a, key2b, key3a, key3b from t1;
+analyze table t1;
+select count(*) from t1;
+
+explain select count(*) from t1 where
+ key1a = 2 and key1b is null and key2a = 2 and key2b is null;
+
+select count(*) from t1 where
+ key1a = 2 and key1b is null and key2a = 2 and key2b is null;
+
+explain select count(*) from t1 where
+ key1a = 2 and key1b is null and key3a = 2 and key3b is null;
+
+select count(*) from t1 where
+ key1a = 2 and key1b is null and key3a = 2 and key3b is null;
+
+drop table t1,t2;
+
+# Test for BUG#8441
+create table t1 (
+ id1 int,
+ id2 date ,
+ index idx2 (id1,id2),
+ index idx1 (id2)
+);
+insert into t1 values(1,'20040101'), (2,'20040102');
+select * from t1 where id1 = 1 and id2= '20040101';
+drop table t1;
+
+# Test for BUG#12720
+--disable_warnings
+drop view if exists v1;
+--enable_warnings
+CREATE TABLE t1 (
+ `oid` int(11) unsigned NOT NULL auto_increment,
+ `fk_bbk_niederlassung` int(11) unsigned NOT NULL,
+ `fk_wochentag` int(11) unsigned NOT NULL,
+ `uhrzeit_von` time NOT NULL COMMENT 'HH:MM',
+ `uhrzeit_bis` time NOT NULL COMMENT 'HH:MM',
+ `geloescht` tinyint(4) NOT NULL,
+ `version` int(5) NOT NULL,
+ PRIMARY KEY (`oid`),
+ KEY `fk_bbk_niederlassung` (`fk_bbk_niederlassung`),
+ KEY `fk_wochentag` (`fk_wochentag`),
+ KEY `ix_version` (`version`)
+) DEFAULT CHARSET=latin1;
+
+insert into t1 values
+(1, 38, 1, '08:00:00', '13:00:00', 0, 1),
+(2, 38, 2, '08:00:00', '13:00:00', 0, 1),
+(3, 38, 3, '08:00:00', '13:00:00', 0, 1),
+(4, 38, 4, '08:00:00', '13:00:00', 0, 1),
+(5, 38, 5, '08:00:00', '13:00:00', 0, 1),
+(6, 38, 5, '08:00:00', '13:00:00', 1, 2),
+(7, 38, 3, '08:00:00', '13:00:00', 1, 2),
+(8, 38, 1, '08:00:00', '13:00:00', 1, 2),
+(9, 38, 2, '08:00:00', '13:00:00', 1, 2),
+(10, 38, 4, '08:00:00', '13:00:00', 1, 2),
+(11, 38, 1, '08:00:00', '13:00:00', 0, 3),
+(12, 38, 2, '08:00:00', '13:00:00', 0, 3),
+(13, 38, 3, '08:00:00', '13:00:00', 0, 3),
+(14, 38, 4, '08:00:00', '13:00:00', 0, 3),
+(15, 38, 5, '08:00:00', '13:00:00', 0, 3),
+(16, 38, 4, '08:00:00', '13:00:00', 0, 4),
+(17, 38, 5, '08:00:00', '13:00:00', 0, 4),
+(18, 38, 1, '08:00:00', '13:00:00', 0, 4),
+(19, 38, 2, '08:00:00', '13:00:00', 0, 4),
+(20, 38, 3, '08:00:00', '13:00:00', 0, 4),
+(21, 7, 1, '08:00:00', '13:00:00', 0, 1),
+(22, 7, 2, '08:00:00', '13:00:00', 0, 1),
+(23, 7, 3, '08:00:00', '13:00:00', 0, 1),
+(24, 7, 4, '08:00:00', '13:00:00', 0, 1),
+(25, 7, 5, '08:00:00', '13:00:00', 0, 1);
+
+create view v1 as
+select
+ zeit1.oid AS oid,
+ zeit1.fk_bbk_niederlassung AS fk_bbk_niederlassung,
+ zeit1.fk_wochentag AS fk_wochentag,
+ zeit1.uhrzeit_von AS uhrzeit_von,
+ zeit1.uhrzeit_bis AS uhrzeit_bis,
+ zeit1.geloescht AS geloescht,
+ zeit1.version AS version
+from
+ t1 zeit1
+where
+(zeit1.version =
+ (select max(zeit2.version) AS `max(version)`
+ from t1 zeit2
+ where
+ ((zeit1.fk_bbk_niederlassung = zeit2.fk_bbk_niederlassung) and
+ (zeit1.fk_wochentag = zeit2.fk_wochentag) and
+ (zeit1.uhrzeit_von = zeit2.uhrzeit_von) and
+ (zeit1.uhrzeit_bis = zeit2.uhrzeit_bis)
+ )
+ )
+)
+and (zeit1.geloescht = 0);
+
+select * from v1 where oid = 21;
+drop view v1;
+drop table t1;
+##
+CREATE TABLE t1(
+ t_cpac varchar(2) NOT NULL,
+ t_vers varchar(4) NOT NULL,
+ t_rele varchar(2) NOT NULL,
+ t_cust varchar(4) NOT NULL,
+ filler1 char(250) default NULL,
+ filler2 char(250) default NULL,
+ PRIMARY KEY (t_cpac,t_vers,t_rele,t_cust),
+ UNIQUE KEY IX_4 (t_cust,t_cpac,t_vers,t_rele),
+ KEY IX_5 (t_vers,t_rele,t_cust)
+);
+
+insert into t1 values
+('tm','2.5 ','a ',' ','',''), ('tm','2.5U','a ','stnd','',''),
+('da','3.3 ','b ',' ','',''), ('da','3.3U','b ','stnd','',''),
+('tl','7.6 ','a ',' ','',''), ('tt','7.6 ','a ',' ','',''),
+('bc','B61 ','a ',' ','',''), ('bp','B61 ','a ',' ','',''),
+('ca','B61 ','a ',' ','',''), ('ci','B61 ','a ',' ','',''),
+('cp','B61 ','a ',' ','',''), ('dm','B61 ','a ',' ','',''),
+('ec','B61 ','a ',' ','',''), ('ed','B61 ','a ',' ','',''),
+('fm','B61 ','a ',' ','',''), ('nt','B61 ','a ',' ','',''),
+('qm','B61 ','a ',' ','',''), ('tc','B61 ','a ',' ','',''),
+('td','B61 ','a ',' ','',''), ('tf','B61 ','a ',' ','',''),
+('tg','B61 ','a ',' ','',''), ('ti','B61 ','a ',' ','',''),
+('tp','B61 ','a ',' ','',''), ('ts','B61 ','a ',' ','',''),
+('wh','B61 ','a ',' ','',''), ('bc','B61U','a ','stnd','',''),
+('bp','B61U','a ','stnd','',''), ('ca','B61U','a ','stnd','',''),
+('ci','B61U','a ','stnd','',''), ('cp','B61U','a ','stnd','',''),
+('dm','B61U','a ','stnd','',''), ('ec','B61U','a ','stnd','',''),
+('fm','B61U','a ','stnd','',''), ('nt','B61U','a ','stnd','',''),
+('qm','B61U','a ','stnd','',''), ('tc','B61U','a ','stnd','',''),
+('td','B61U','a ','stnd','',''), ('tf','B61U','a ','stnd','',''),
+('tg','B61U','a ','stnd','',''), ('ti','B61U','a ','stnd','',''),
+('tp','B61U','a ','stnd','',''), ('ts','B61U','a ','stnd','',''),
+('wh','B61U','a ','stnd','','');
+show create table t1;
+
+select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6';
+select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6'
+ and t_rele='a' and t_cust = ' ';
+
+drop table t1;
+
+# BUG#19021: Crash in index_merge/ROR-intersection optimizer under
+# specific circumstances.
+create table t1 (
+ pk int(11) not null auto_increment,
+ a int(11) not null default '0',
+ b int(11) not null default '0',
+ c int(11) not null default '0',
+
+ filler1 datetime, filler2 varchar(15),
+ filler3 longtext,
+
+ kp1 varchar(4), kp2 varchar(7),
+ kp3 varchar(2), kp4 varchar(4),
+ kp5 varchar(7),
+ filler4 char(1),
+
+ primary key (pk),
+ key idx1(a,b,c),
+ key idx2(c),
+ key idx3(kp1,kp2,kp3,kp4,kp5)
+) default charset=latin1;
+--disable_query_log
+set @fill= uncompress(unhex(concat(
+'F91D0000789CDD993D6FDB301086F7FE0A6D4E0105B8E3F1335D5BA028DA0EEDE28E1D320408',
+'52A0713BF4D7571FB62C51A475924839080307B603E77DEE787C8FA41F9E9EEF7F1F8A87A7C3',
+'AFE280C5DF9F8F7FEE9F8B1B2CB114D6902E918455245DB91300FA16E42D5201FA4EE29DA05D',
+'B9FB3718A33718A3FA8C30AEFAFDE1F317D016AA67BA7A60FDE45BF5F8BA7B5BDE8812AA9F1A',
+'069DB03C9804346644F3A3A6A1338DB572756A3C4D1BCC804CABF912C654AE9BB855A2B85962',
+'3A479259CAE6A86C0411D01AE5483581EDCBD9A39C45252D532E533979EB9F82E971D979BDB4',
+'8531105670740AFBFD1E34AAB0029E4AD0A1D46A6D0946A21A16038A5CD965CD2D524673F712',
+'20C304477315CE18405EAF9BD0AFFEAC74FDA14F1FBF5BD34C769D73FBBEDF4750ADD4E5A99C',
+'5C8DC04934AFA275D483D536D174C11B12AF27F8F888B41B6FC9DBA569E1FD7BD72D698130B7',
+'91B23A98803512B3D31881E8DCDA2AC1754E3644C4BB3A8466750B911681274A39E35E8624B7',
+'444A42AC1213F354758E3CF1A4CDD5A688C767CF1B11ABC5867CB15D8A18E0B91E9EC275BB94',
+'58F33C2936F64690D55BC29E4A293D95A798D84217736CEAAA538CE1354269EE2162053FBC66',
+'496D90CB53323CB279D3A6AF651B4B22B9E430743D83BE48E995A09D4FC9871C22D8D189B945',
+'706911BCB8C3C774B9C08D2FC6ED853ADACA37A14A4CB2E027630E5B80ECACD939431B1CDF62',
+'7D71487536EA2C678F59685E91F4B6C144BCCB94C1EBA9FA6F5552DDCA4E4539BE326A2720CB',
+'45ED028EB3616AC93C46E775FEA9FA6DA7CFCEC6DEBA5FCD1F915EED4D983BDDB881528AD9AB',
+'43C1576F29AAB35BDFBC21D422F52B307D350589D45225A887AC46C8EDD72D99EC3ED2E1BCEF',
+'7AF26FC4C74097B6768A5EDAFA660CC64278F7E63F99AC954B')));
+prepare x from @fill;
+execute x;
+deallocate prepare x;
+--enable_query_log
+set @fill=NULL;
+SELECT COUNT(*) FROM t1 WHERE b = 0 AND a = 0 AND c = 13286427 AND
+ kp1='279' AND kp2='ELM0678' AND kp3='6' AND kp4='10' AND kp5 = 'R ';
+
+drop table t1;
+
+# BUG#21277: Index Merge/sort_union: wrong query results
+create table t1
+(
+ key1 int not null,
+ key2 int not null default 0,
+ key3 int not null default 0
+);
+
+insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
+
+let $1=7;
+set @d=8;
+while ($1)
+{
+ eval insert into t1 (key1) select key1+@d from t1;
+ eval set @d=@d*2;
+ dec $1;
+}
+
+alter table t1 add index i2(key2);
+alter table t1 add index i3(key3);
+update t1 set key2=key1,key3=key1;
+
+# to test the bug, the following must use "sort_union":
+explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
+select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
+drop table t1;
+
diff --git a/mysql-test/include/index_merge_2sweeps.inc b/mysql-test/include/index_merge_2sweeps.inc
new file mode 100644
index 00000000000..3ae7e5b3c09
--- /dev/null
+++ b/mysql-test/include/index_merge_2sweeps.inc
@@ -0,0 +1,65 @@
+# include/index_merge_2sweeps.inc
+#
+# 2-sweeps read Index_merge test
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was index_merge_innodb2.test
+# main code went into include/index_merge_2sweeps.inc
+#
+
+--echo #---------------- 2-sweeps read Index merge test 2 -------------------------------
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+create table t1 (
+ pk int primary key,
+ key1 int,
+ key2 int,
+ filler char(200),
+ filler2 char(200),
+ index(key1),
+ index(key2)
+);
+
+
+--disable_query_log
+let $1=1000;
+while ($1)
+{
+ eval insert into t1 values($1, $1, $1, 'filler-data','filler-data-2');
+ dec $1;
+}
+--enable_query_log
+
+select * from t1 where (key1 >= 2 and key1 <= 10) or (pk >= 4 and pk <=8 );
+
+set @maxv=1000;
+
+select * from t1 where
+ (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10)
+ or key1=18 or key1=60;
+
+select * from t1 where
+ (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10)
+ or key1 < 3 or key1 > @maxv-11;
+
+select * from t1 where
+ (pk < 5) or (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 ) or (pk > @maxv-10)
+ or
+ (key1 < 5) or (key1 > 10 and key1 < 15) or (key1 >= 50 and key1 < 55 ) or (key1 > @maxv-10);
+
+select * from t1 where
+ (pk > 10 and pk < 15) or (pk >= 50 and pk < 55 )
+ or
+ (key1 < 5) or (key1 > @maxv-10);
+
+drop table t1;
diff --git a/mysql-test/include/index_merge_ror.inc b/mysql-test/include/index_merge_ror.inc
new file mode 100644
index 00000000000..2764cbea468
--- /dev/null
+++ b/mysql-test/include/index_merge_ror.inc
@@ -0,0 +1,289 @@
+# include/index_merge_ror.inc
+#
+# ROR-index_merge tests.
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Note: The comments/expectations refer to MyISAM.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/index_merge_ror.test
+# main code went into include/index_merge_ror.inc
+#
+
+--echo #---------------- ROR-index_merge tests -----------------------
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t0,t1,t2;
+--enable_warnings
+create table t1
+(
+ /* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */
+ st_a int not null default 0,
+ swt1a int not null default 0,
+ swt2a int not null default 0,
+
+ st_b int not null default 0,
+ swt1b int not null default 0,
+ swt2b int not null default 0,
+
+ /* fields/keys for row retrieval tests */
+ key1 int,
+ key2 int,
+ key3 int,
+ key4 int,
+
+ /* make rows much bigger then keys */
+ filler1 char (200),
+ filler2 char (200),
+ filler3 char (200),
+ filler4 char (200),
+ filler5 char (200),
+ filler6 char (200),
+
+ /* order of keys is important */
+ key sta_swt12a(st_a,swt1a,swt2a),
+ key sta_swt1a(st_a,swt1a),
+ key sta_swt2a(st_a,swt2a),
+ key sta_swt21a(st_a,swt2a,swt1a),
+
+ key st_a(st_a),
+ key stb_swt1a_2b(st_b,swt1b,swt2a),
+ key stb_swt1b(st_b,swt1b),
+ key st_b(st_b),
+
+ key(key1),
+ key(key2),
+ key(key3),
+ key(key4)
+) ;
+
+# Fill table
+create table t0 as select * from t1;
+--disable_query_log
+--echo # Printing of many insert into t0 values (....) disabled.
+let $cnt=1000;
+while ($cnt)
+{
+ eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
+ dec $cnt;
+}
+--enable_query_log
+
+alter table t1 disable keys;
+--disable_query_log
+--echo # Printing of many insert into t1 select .... from t0 disabled.
+let $1=4;
+while ($1)
+{
+ let $2=4;
+ while ($2)
+ {
+ let $3=4;
+ while ($3)
+ {
+ eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0;
+ dec $3;
+ }
+ dec $2;
+ }
+ dec $1;
+}
+
+--echo # Printing of many insert into t1 (...) values (....) disabled.
+# Row retrieval tests
+# -1 is used for values 'out of any range we are using'
+# insert enough rows for index intersection to be used for (key1,key2)
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4');
+let $cnt=400;
+while ($cnt)
+{
+ eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
+ dec $cnt;
+}
+let $cnt=400;
+while ($cnt)
+{
+ eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
+ dec $cnt;
+}
+--enable_query_log
+alter table t1 enable keys;
+select count(*) from t1;
+
+# One row results tests for cases where a single row matches all conditions
+explain select key1,key2 from t1 where key1=100 and key2=100;
+select key1,key2 from t1 where key1=100 and key2=100;
+explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+
+# Several-rows results
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
+insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
+
+# ROR-intersection, not covering
+explain select key1,key2,filler1 from t1 where key1=100 and key2=100;
+select key1,key2,filler1 from t1 where key1=100 and key2=100;
+
+# ROR-intersection, covering
+explain select key1,key2 from t1 where key1=100 and key2=100;
+select key1,key2 from t1 where key1=100 and key2=100;
+
+# ROR-union of ROR-intersections
+explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+
+# 3-way ROR-intersection
+explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
+select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
+
+# ROR-union(ROR-intersection, ROR-range)
+insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101');
+explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
+select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
+
+# Run some ROR updates/deletes
+select key1,key2, filler1 from t1 where key1=100 and key2=100;
+update t1 set filler1='to be deleted' where key1=100 and key2=100;
+update t1 set key1=200,key2=200 where key1=100 and key2=100;
+delete from t1 where key1=200 and key2=200;
+select key1,key2,filler1 from t1 where key2=100 and key2=200;
+
+# ROR-union(ROR-intersection) with one of ROR-intersection giving empty
+# results
+explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+
+delete from t1 where key3=100 and key4=100;
+
+# ROR-union with all ROR-intersections giving empty results
+explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
+
+# ROR-intersection with empty result
+explain select key1,key2 from t1 where key1=100 and key2=100;
+select key1,key2 from t1 where key1=100 and key2=100;
+
+# ROR-union tests with various cases.
+# All scans returning duplicate rows:
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1');
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2');
+insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3');
+
+explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+
+insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4');
+
+explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+
+insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3');
+
+explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
+
+##
+## Optimizer tests
+##
+
+# Check that the shortest key is used for ROR-intersection, covering and non-covering.
+explain select * from t1 where st_a=1 and st_b=1;
+explain select st_a,st_b from t1 where st_a=1 and st_b=1;
+
+# Check if "ingore index" syntax works
+explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1;
+
+# Do many tests
+# Check that keys that don't improve selectivity are skipped.
+#
+
+# Different value on 32 and 64 bit
+--replace_result sta_swt12a sta_swt21a sta_swt12a, sta_swt12a,
+explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1;
+
+explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
+
+explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
+
+explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b)
+ where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
+
+explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b)
+ where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
+
+explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b)
+ where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
+
+explain select * from t1
+ where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
+
+explain select * from t1
+ where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
+
+explain select st_a from t1
+ where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
+
+explain select st_a from t1
+ where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
+
+drop table t0,t1;
+
+# 'Partially' covered fields test
+
+create table t2 (
+ a char(10),
+ b char(10),
+ filler1 char(255),
+ filler2 char(255),
+ key(a(5)),
+ key(b(5))
+);
+
+--disable_query_log
+let $1=8;
+while ($1)
+{
+ eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2');
+ dec $1;
+}
+insert into t2 select * from t2;
+insert into t2 select * from t2;
+--enable_query_log
+
+# The table row buffer is reused. Fill it with rows that don't match.
+select count(a) from t2 where a='BBBBBBBB';
+select count(a) from t2 where b='BBBBBBBB';
+
+# BUG#1:
+--replace_result a a_or_b b a_or_b
+explain select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
+select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
+select count(a) from t2 ignore index(a,b) where a='AAAAAAAA' and b='AAAAAAAA';
+
+insert into t2 values ('ab', 'ab', 'uh', 'oh');
+explain select a from t2 where a='ab';
+drop table t2;
+
+#
+# BUG#25048 - ERROR 126 : Incorrect key file for table '.XXXX.MYI'; try to
+# repair it
+#
+CREATE TABLE t1(c1 INT, c2 INT DEFAULT 0, c3 CHAR(255) DEFAULT '',
+KEY(c1), KEY(c2), KEY(c3));
+INSERT INTO t1(c1) VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),
+(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
+INSERT INTO t1 VALUES(0,0,0);
+CREATE TABLE t2(c1 int);
+INSERT INTO t2 VALUES(1);
+DELETE t1 FROM t1,t2 WHERE t1.c1=0 AND t1.c2=0;
+SELECT * FROM t1;
+DROP TABLE t1,t2;
diff --git a/mysql-test/include/index_merge_ror_cpk.inc b/mysql-test/include/index_merge_ror_cpk.inc
new file mode 100644
index 00000000000..cfc2ed3885e
--- /dev/null
+++ b/mysql-test/include/index_merge_ror_cpk.inc
@@ -0,0 +1,128 @@
+# include/index_merge_ror_cpk.inc
+#
+# Clustered PK ROR-index_merge tests
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Note: The comments/expectations refer to InnoDB.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/index_merge_ror_cpk.test
+# main code went into include/index_merge_ror_cpk.inc
+#
+
+--echo #---------------- Clustered PK ROR-index_merge tests -----------------------------
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+create table t1
+(
+ pk1 int not null,
+ pk2 int not null,
+
+ key1 int not null,
+ key2 int not null,
+
+ pktail1ok int not null,
+ pktail2ok int not null,
+ pktail3bad int not null,
+ pktail4bad int not null,
+ pktail5bad int not null,
+
+ pk2copy int not null,
+ badkey int not null,
+
+ filler1 char (200),
+ filler2 char (200),
+ key (key1),
+ key (key2),
+
+ /* keys with tails from CPK members */
+ key (pktail1ok, pk1),
+ key (pktail2ok, pk1, pk2),
+ key (pktail3bad, pk2, pk1),
+ key (pktail4bad, pk1, pk2copy),
+ key (pktail5bad, pk1, pk2, pk2copy),
+
+ primary key (pk1, pk2)
+);
+
+--disable_query_log
+set autocommit=0;
+let $1=10000;
+while ($1)
+{
+ eval insert into t1 values ($1 div 10,$1 mod 100, $1/100,$1/100, $1/100,$1/100,$1/100,$1/100,$1/100, $1 mod 100, $1/1000,'filler-data-$1','filler2');
+ dec $1;
+}
+set autocommit=1;
+--enable_query_log
+
+# Verify that range scan on CPK is ROR
+# (use index_intersection because it is impossible to check that for index union)
+explain select * from t1 where pk1 = 1 and pk2 < 80 and key1=0;
+# CPK scan + 1 ROR range scan is a special case
+select * from t1 where pk1 = 1 and pk2 < 80 and key1=0;
+
+# Verify that CPK fields are considered to be covered by index scans
+explain select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1;
+select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1;
+
+# Verify that CPK is always used for index intersection scans
+# (this is because it is used as a filter, not for retrieval)
+explain select * from t1 where badkey=1 and key1=10;
+--replace_column 9 ROWS
+explain select * from t1 where pk1 < 7500 and key1 = 10;
+
+# Verify that keys with 'tails' of PK members are ok.
+explain select * from t1 where pktail1ok=1 and key1=10;
+explain select * from t1 where pktail2ok=1 and key1=10;
+
+# Note: The following is actually a deficiency, it uses sort_union currently.
+# This comment refers to InnoDB and is probably not valid for other engines.
+explain select * from t1 where (pktail2ok=1 and pk1< 50000) or key1=10;
+
+# The expected rows differs a bit from platform to platform
+--replace_result 98 ROWS 99 ROWS
+explain select * from t1 where pktail3bad=1 and key1=10;
+explain select * from t1 where pktail4bad=1 and key1=10;
+explain select * from t1 where pktail5bad=1 and key1=10;
+
+# Test for problem with innodb key values prefetch buffer:
+explain select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10;
+select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10;
+
+drop table t1;
+# Testcase for BUG#4984
+create table t1
+(
+ RUNID varchar(22),
+ SUBMITNR varchar(5),
+ ORDERNR char(1),
+ PROGRAMM varchar(8),
+ TESTID varchar(4),
+ UCCHECK char(1),
+ ETEXT varchar(80),
+ ETEXT_TYPE char(1),
+ INFO char(1),
+ SEVERITY tinyint(3),
+ TADIRFLAG char(1),
+ PRIMARY KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK),
+ KEY `TVERM~KEY` (PROGRAMM,TESTID,UCCHECK)
+) DEFAULT CHARSET=latin1;
+
+update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`=''
+WHERE
+ `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND
+ `TESTID`='' AND `UCCHECK`='';
+
+drop table t1;
+
diff --git a/mysql-test/include/innodb_rollback_on_timeout.inc b/mysql-test/include/innodb_rollback_on_timeout.inc
index 73c7374c79e..6be47397e4b 100644
--- a/mysql-test/include/innodb_rollback_on_timeout.inc
+++ b/mysql-test/include/innodb_rollback_on_timeout.inc
@@ -2,6 +2,10 @@
# Bug #24200: Provide backwards compatibility mode for 4.x "rollback on
# transaction timeout"
#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
show variables like 'innodb_rollback_on_timeout';
create table t1 (a int unsigned not null primary key) engine = innodb;
insert into t1 values (1);
diff --git a/mysql-test/include/innodb_trx_weight.inc b/mysql-test/include/innodb_trx_weight.inc
new file mode 100644
index 00000000000..56d3d47da36
--- /dev/null
+++ b/mysql-test/include/innodb_trx_weight.inc
@@ -0,0 +1,51 @@
+-- connect (con1,localhost,root,,)
+-- connect (con2,localhost,root,,)
+
+-- connection con1
+SET autocommit=0;
+SELECT * FROM t1 FOR UPDATE;
+-- if ($con1_extra_sql_present) {
+ -- eval $con1_extra_sql
+-- }
+
+-- connection con2
+SET autocommit=0;
+SELECT * FROM t2 FOR UPDATE;
+-- if ($con2_extra_sql_present) {
+ -- eval $con2_extra_sql
+-- }
+
+-- if ($con1_should_be_rolledback) {
+ -- connection con1
+ -- send
+ INSERT INTO t2 VALUES (0);
+
+ -- connection con2
+ INSERT INTO t1 VALUES (0);
+ ROLLBACK;
+
+ -- connection con1
+ -- error ER_LOCK_DEADLOCK
+ -- reap
+-- }
+# else
+-- if (!$con1_should_be_rolledback) {
+ -- connection con2
+ -- send
+ INSERT INTO t1 VALUES (0);
+
+ -- connection con1
+ INSERT INTO t2 VALUES (0);
+ ROLLBACK;
+
+ -- connection con2
+ -- error ER_LOCK_DEADLOCK
+ -- reap
+-- }
+
+-- connection default
+
+DELETE FROM t5_nontrans;
+
+-- disconnect con1
+-- disconnect con2
diff --git a/mysql-test/include/is_embedded.inc b/mysql-test/include/is_embedded.inc
new file mode 100644
index 00000000000..6d95772843c
--- /dev/null
+++ b/mysql-test/include/is_embedded.inc
@@ -0,0 +1,5 @@
+-- require r/is_embedded.require
+disable_query_log;
+select version() like '%embedded%' as 'have_embedded';
+enable_query_log;
+
diff --git a/mysql-test/include/linux_sys_vars.inc b/mysql-test/include/linux_sys_vars.inc
new file mode 100644
index 00000000000..85d7c6df7dc
--- /dev/null
+++ b/mysql-test/include/linux_sys_vars.inc
@@ -0,0 +1,33 @@
+#
+# This file contains default,min and max values for sys variables for redhat linux
+#
+
+--disable_query_log
+
+SET @default_flush_time = 0;
+SET @min_flush_time = 0;
+#SET @max_flush_time = 0;
+
+SET @default_key_buffer_size = 131072;
+
+#SET @default_join_buffer_size = 131072;
+#SET @min_join_buffer_size = 8200;
+#SET @max_join_buffer_size = 4294967295;
+
+SET @default_max_join_size = 4294967295;
+SET @min_max_join_size = 1;
+SET @max_max_join_size = 4294967295;
+
+SET @default_sql_max_join_size = 4294967295;
+SET @min_sql_max_join_size = 1;
+SET @max_sql_max_join_size = 4294967295;
+
+SET @default_sql_select_limit = 4294967295;
+SET @min_sql_select_limit = 0;
+SET @max_sql_select_limit = 4294967295;
+
+SET @default_wait_timeout= 28800;
+SET @min_wait_timeout= 1;
+SET @max_wait_timeout= 31536000;
+
+--enable_query_log
diff --git a/mysql-test/include/load_sysvars.inc b/mysql-test/include/load_sysvars.inc
new file mode 100644
index 00000000000..bcae9fa8d9c
--- /dev/null
+++ b/mysql-test/include/load_sysvars.inc
@@ -0,0 +1,15 @@
+#
+# This script is included by tests of system variables to include system
+# dependant values for the variables: default, minimum and maximum values
+#
+
+if (`SELECT convert(@@version_compile_os using latin1)
+ IN ('Win32','Win64','Windows')`)
+{
+ --source include/windows_sys_vars.inc
+}
+if (!`SELECT convert(@@version_compile_os using latin1)
+ IN ('Win32','Win64','Windows')`)
+{
+ --source include/linux_sys_vars.inc
+}
diff --git a/mysql-test/include/loaddata_autocom.inc b/mysql-test/include/loaddata_autocom.inc
index e5071c73c49..bb286fb4169 100644
--- a/mysql-test/include/loaddata_autocom.inc
+++ b/mysql-test/include/loaddata_autocom.inc
@@ -7,14 +7,20 @@ eval SET SESSION STORAGE_ENGINE = $engine_type;
drop table if exists t1;
--enable_warnings
-create table t1 (a text, b text);
+let $load_file= $MYSQLTEST_VARDIR/std_data/loaddata2.dat;
+
+# NDB does not support the create option 'Binlog of table with BLOB attribute and no PK'
+# So use a dummy PK here.
+create table t1 (id int unsigned not null auto_increment primary key, a text, b text);
start transaction;
-load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
+--replace_result $load_file LOAD_FILE
+eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
commit;
select count(*) from t1;
truncate table t1;
start transaction;
-load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
+--replace_result $load_file LOAD_FILE
+eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
rollback;
select count(*) from t1;
diff --git a/mysql-test/include/master-slave-end.inc b/mysql-test/include/master-slave-end.inc
new file mode 100644
index 00000000000..74e4c7b608a
--- /dev/null
+++ b/mysql-test/include/master-slave-end.inc
@@ -0,0 +1,6 @@
+--connection master
+--sync_slave_with_master
+--connection slave
+--disable_query_log
+STOP SLAVE;
+--enable_query_log
diff --git a/mysql-test/include/master-slave-reset.inc b/mysql-test/include/master-slave-reset.inc
new file mode 100644
index 00000000000..938eb2c074a
--- /dev/null
+++ b/mysql-test/include/master-slave-reset.inc
@@ -0,0 +1,36 @@
+# Reset the master and the slave to start fresh.
+#
+# It is necessary to execute RESET MASTER and RESET SLAVE on both
+# master and slave since the replication setup might be circular.
+#
+# Since we expect STOP SLAVE to produce a warning as the slave is
+# stopped (the server was started with skip-slave-start), we disable
+# warnings when doing STOP SLAVE.
+
+connection slave;
+--disable_warnings
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+--enable_warnings
+connection master;
+--disable_warnings
+--disable_query_log
+use test;
+--enable_query_log
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+reset master;
+--disable_query_log
+reset slave;
+--enable_query_log
+connection slave;
+reset slave;
+# Clean up old test tables
+--disable_warnings
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+--disable_query_log
+reset master;
+--enable_query_log
+start slave;
+source include/wait_for_slave_to_start.inc;
diff --git a/mysql-test/include/master-slave.inc b/mysql-test/include/master-slave.inc
index 0c27a1d8225..e0eb87f02f7 100644
--- a/mysql-test/include/master-slave.inc
+++ b/mysql-test/include/master-slave.inc
@@ -5,28 +5,8 @@ connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
connect (slave1,127.0.0.1,root,,test,$SLAVE_MYPORT,);
-connection slave;
-#we expect STOP SLAVE to produce a warning as the slave is stopped
-#(the server was started with skip-slave-start)
---disable_warnings
-stop slave;
---enable_warnings
---require r/slave-stopped.result
-show status like 'Slave_running';
-connection master;
---disable_warnings
-drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
---enable_warnings
-reset master;
-connection slave;
-reset slave;
-# Clean up old test tables
---disable_warnings
-drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
---enable_warnings
-start slave;
---require r/slave-running.result
-show status like 'Slave_running';
+
+-- source include/master-slave-reset.inc
# Set the default connection to 'master'
connection master;
diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc
new file mode 100644
index 00000000000..cc9183205be
--- /dev/null
+++ b/mysql-test/include/mix1.inc
@@ -0,0 +1,1478 @@
+# include/mix1.inc
+#
+# The variables
+# $engine_type -- storage engine to be tested
+# $other_engine_type -- storage engine <> $engine_type
+# $other_engine_type must point to an all
+# time available storage engine
+# 2006-08 MySQL 5.1 MyISAM and MEMORY only
+# $test_foreign_keys -- 0, skip foreign key tests
+# -- 1, do not skip foreign key tests
+# have to be set before sourcing this script.
+#
+# Note: The comments/expectations refer to InnoDB.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-15 ML refactoring of t/innodb_mysql.test
+# - shift main code of t/innodb_mysql.test to include/mix1.inc
+# - replace hardcoded assignment of storage engine by
+# use of $engine_type and $other_engine_type variables
+# - remove redundant replay testcase of
+# Bug#12882 min/max inconsistent on empty table
+# - corrected analyze table t1; to analyze table t4;
+# Much older versions of this test show that the table
+# where just some indexes have been created must be used.
+#
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
+drop procedure if exists p1;
+--enable_warnings
+
+
+# BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer
+# (repeatable only w/innodb).
+create table t1 (
+ c_id int(11) not null default '0',
+ org_id int(11) default null,
+ unique key contacts$c_id (c_id),
+ key contacts$org_id (org_id)
+);
+insert into t1 values
+ (2,null),(120,null),(141,null),(218,7), (128,1),
+ (151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3),
+ (246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4);
+
+create table t2 (
+ slai_id int(11) not null default '0',
+ owner_tbl int(11) default null,
+ owner_id int(11) default null,
+ sla_id int(11) default null,
+ inc_web int(11) default null,
+ inc_email int(11) default null,
+ inc_chat int(11) default null,
+ inc_csr int(11) default null,
+ inc_total int(11) default null,
+ time_billed int(11) default null,
+ activedate timestamp null default null,
+ expiredate timestamp null default null,
+ state int(11) default null,
+ sla_set int(11) default null,
+ unique key t2$slai_id (slai_id),
+ key t2$owner_id (owner_id),
+ key t2$sla_id (sla_id)
+);
+insert into t2(slai_id, owner_tbl, owner_id, sla_id) values
+ (1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7),
+ (8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12);
+
+flush tables;
+select si.slai_id
+from t1 c join t2 si on
+ ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
+ ( si.owner_tbl = 2 and si.owner_id = c.c_id))
+where
+ c.c_id = 218 and expiredate is null;
+
+select * from t1 where org_id is null;
+select si.slai_id
+from t1 c join t2 si on
+ ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
+ ( si.owner_tbl = 2 and si.owner_id = c.c_id))
+where
+ c.c_id = 218 and expiredate is null;
+
+drop table t1, t2;
+
+#
+# Bug#17212: results not sorted correctly by ORDER BY when using index
+# (repeatable only w/innodb because of index props)
+#
+CREATE TABLE t1 (a int, b int, KEY b (b));
+CREATE TABLE t2 (a int, b int, PRIMARY KEY (a,b));
+CREATE TABLE t3 (a int, b int, c int, PRIMARY KEY (a),
+ UNIQUE KEY b (b,c), KEY a (a,b,c));
+
+INSERT INTO t1 VALUES (1, 1);
+INSERT INTO t1 SELECT a + 1, b + 1 FROM t1;
+INSERT INTO t1 SELECT a + 2, b + 2 FROM t1;
+
+INSERT INTO t2 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
+INSERT INTO t2 SELECT a + 1, b FROM t2;
+DELETE FROM t2 WHERE a = 1 AND b < 2;
+
+INSERT INTO t3 VALUES (1,1,1),(2,1,2);
+INSERT INTO t3 SELECT a + 2, a + 2, 3 FROM t3;
+INSERT INTO t3 SELECT a + 4, a + 4, 3 FROM t3;
+
+# demonstrate a problem when a must-use-sort table flag
+# (sort_by_table=1) is being neglected.
+SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
+ t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
+ ORDER BY t1.b LIMIT 2;
+
+# demonstrate the problem described in the bug report
+SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
+ t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
+ ORDER BY t1.b LIMIT 5;
+DROP TABLE t1, t2, t3;
+
+
+# BUG#21077 (The testcase is not deterministic so correct execution doesn't
+# prove anything) For proof one should track if sequence of ha_innodb::* func
+# calls is correct.
+CREATE TABLE `t1` (`id1` INT) ;
+INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
+
+CREATE TABLE `t2` (
+ `id1` INT,
+ `id2` INT NOT NULL,
+ `id3` INT,
+ `id4` INT NOT NULL,
+ UNIQUE (`id2`,`id4`),
+ KEY (`id1`)
+);
+
+INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
+(1,1,1,0),
+(1,1,2,1),
+(5,1,2,2),
+(6,1,2,3),
+(1,2,2,2),
+(1,2,1,1);
+
+SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
+DROP TABLE t1, t2;
+
+#
+# Bug #22728 - Handler_rollback value is growing
+#
+
+let $before= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`;
+create table t1 (c1 int) engine=innodb;
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+connection con2;
+handler t1 open;
+handler t1 read first;
+disconnect con2;
+connection con1;
+let $after= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`;
+# Compare the before and after value, it should be equal
+--disable_query_log
+eval select STRCMP("$before", "$after") as "Before and after comparison";
+--enable_query_log
+connection default;
+drop table t1;
+disconnect con1;
+
+#
+# Bug #13191: INSERT...ON DUPLICATE KEY UPDATE of UTF-8 string fields
+# used in partial unique indices.
+#
+
+CREATE TABLE t1(c1 TEXT, UNIQUE (c1(1)), cnt INT DEFAULT 1)
+ ENGINE=INNODB CHARACTER SET UTF8;
+INSERT INTO t1 (c1) VALUES ('1a');
+SELECT * FROM t1;
+INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(c1 VARCHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
+ ENGINE=INNODB CHARACTER SET UTF8;
+INSERT INTO t1 (c1) VALUES ('1a');
+SELECT * FROM t1;
+INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(c1 CHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
+ ENGINE=INNODB CHARACTER SET UTF8;
+INSERT INTO t1 (c1) VALUES ('1a');
+SELECT * FROM t1;
+INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+#
+# Bug #28272: EXPLAIN for SELECT from an empty InnoDB table
+#
+
+CREATE TABLE t1 (
+ a1 decimal(10,0) DEFAULT NULL,
+ a2 blob,
+ a3 time DEFAULT NULL,
+ a4 blob,
+ a5 char(175) DEFAULT NULL,
+ a6 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ a7 tinyblob,
+ INDEX idx (a6,a7(239),a5)
+) ENGINE=InnoDB;
+
+EXPLAIN SELECT a4 FROM t1 WHERE
+a6=NULL AND
+a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
+
+EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
+t.a6=t.a6 AND t1.a6=NULL AND
+t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
+
+DROP TABLE t1;
+
+#
+# Bug #12882 min/max inconsistent on empty table
+#
+
+--disable_warnings
+eval create table t1m (a int) engine = $other_engine_type;
+create table t1i (a int);
+eval create table t2m (a int) engine = $other_engine_type;
+create table t2i (a int);
+--enable_warnings
+insert into t2m values (5);
+insert into t2i values (5);
+
+# test with $engine_type
+select min(a) from t1i;
+select min(7) from t1i;
+select min(7) from DUAL;
+explain select min(7) from t2i join t1i;
+select min(7) from t2i join t1i;
+
+select max(a) from t1i;
+select max(7) from t1i;
+select max(7) from DUAL;
+explain select max(7) from t2i join t1i;
+select max(7) from t2i join t1i;
+
+select 1, min(a) from t1i where a=99;
+select 1, min(a) from t1i where 1=99;
+select 1, min(1) from t1i where a=99;
+select 1, min(1) from t1i where 1=99;
+
+select 1, max(a) from t1i where a=99;
+select 1, max(a) from t1i where 1=99;
+select 1, max(1) from t1i where a=99;
+select 1, max(1) from t1i where 1=99;
+
+# mixed $engine_type/$other_engine_type test
+explain select count(*), min(7), max(7) from t1m, t1i;
+select count(*), min(7), max(7) from t1m, t1i;
+
+explain select count(*), min(7), max(7) from t1m, t2i;
+select count(*), min(7), max(7) from t1m, t2i;
+
+explain select count(*), min(7), max(7) from t2m, t1i;
+select count(*), min(7), max(7) from t2m, t1i;
+
+drop table t1m, t1i, t2m, t2i;
+
+#
+# Bug #12882: primary key implcitly included in every innodb index
+# (was part of group_min_max.test)
+#
+
+eval create table t1 (
+ a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+) ENGINE = $other_engine_type;
+
+insert into t1 (a1, a2, b, c, d) values
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
+('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
+('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
+('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
+('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
+('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
+('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
+('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
+('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
+('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
+('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
+('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
+('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
+('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
+('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
+('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
+('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
+--disable_warnings
+create table t4 (
+ pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
+);
+--enable_warnings
+insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
+
+create index idx12672_0 on t4 (a1);
+create index idx12672_1 on t4 (a1,a2,b,c);
+create index idx12672_2 on t4 (a1,a2,b);
+analyze table t4;
+
+select distinct a1 from t4 where pk_col not in (1,2,3,4);
+
+drop table t1,t4;
+
+
+#
+# BUG#18819: DELETE IGNORE hangs on foreign key parent delete
+#
+# The bug itself does not relate to InnoDB, but we have to use foreign
+# keys to reproduce it.
+#
+--disable_warnings
+DROP TABLE IF EXISTS t2, t1;
+--enable_warnings
+
+CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
+CREATE TABLE t2 (
+ i INT NOT NULL,
+ FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
+) ENGINE= InnoDB;
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1);
+
+DELETE IGNORE FROM t1 WHERE i = 1;
+
+SELECT * FROM t1, t2;
+
+DROP TABLE t2, t1;
+
+
+--echo End of 4.1 tests.
+
+
+#
+# Bug #6142: a problem with the empty innodb table
+# (was part of group_min_max.test)
+#
+
+--disable_warnings
+create table t1 (
+ a varchar(30), b varchar(30), primary key(a), key(b)
+);
+--enable_warnings
+select distinct a from t1;
+drop table t1;
+
+#
+# Bug #9798: group by with rollup
+# (was part of group_min_max.test)
+#
+
+--disable_warnings
+create table t1(a int, key(a));
+--enable_warnings
+insert into t1 values(1);
+select a, count(a) from t1 group by a with rollup;
+drop table t1;
+
+#
+# Bug #13293 Wrongly used index results in endless loop.
+# (was part of group_min_max.test)
+#
+create table t1 (f1 int, f2 char(1), primary key(f1,f2));
+insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
+alter table t1 drop primary key, add primary key (f2, f1);
+explain select distinct f1 a, f1 b from t1;
+explain select distinct f1, f2 from t1;
+drop table t1;
+
+#
+# Test for bug #17164: ORed FALSE blocked conversion of outer join into join
+#
+
+CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20),
+ INDEX (name));
+CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11));
+# CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11),
+# FOREIGN KEY (fkey) REFERENCES t2(id));
+if ($test_foreign_keys)
+{
+ ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
+}
+INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
+INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
+
+EXPLAIN
+SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
+ WHERE t1.name LIKE 'A%';
+
+EXPLAIN
+SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
+ WHERE t1.name LIKE 'A%' OR FALSE;
+
+DROP TABLE t1,t2;
+
+#
+# Bug#26159: crash for a loose scan of a table that has been emptied
+#
+
+CREATE TABLE t1 (
+ id int NOT NULL,
+ name varchar(20) NOT NULL,
+ dept varchar(20) NOT NULL,
+ age tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (id),
+ INDEX (name,dept)
+) ENGINE=InnoDB;
+INSERT INTO t1(id, dept, age, name) VALUES
+ (3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
+ (3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
+ (4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
+ (4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
+
+EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
+SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
+DELETE FROM t1;
+EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
+SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
+
+DROP TABLE t1;
+
+--source include/innodb_rollback_on_timeout.inc
+
+#
+# Bug #27210: INNODB ON DUPLICATE KEY UPDATE
+#
+
+set @save_qcache_size=@@global.query_cache_size;
+set @save_qcache_type=@@global.query_cache_type;
+set global query_cache_size=10*1024*1024;
+set global query_cache_type=1;
+connect (con1,localhost,root,,);
+connection con1;
+drop table if exists `test`;
+CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
+ `test2` varchar(4) NOT NULL,PRIMARY KEY (`test1`))
+ ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
+disconnect con1;
+connect (con2,localhost,root,,);
+connection con2;
+select * from test;
+INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
+ ON DUPLICATE KEY UPDATE `test2` = '1234';
+select * from test;
+flush tables;
+select * from test;
+disconnect con2;
+connection default;
+drop table test;
+set global query_cache_type=@save_qcache_type;
+set global query_cache_size=@save_qcache_size;
+
+--source include/innodb_rollback_on_timeout.inc
+
+#
+# Bug #27650: INSERT fails after multi-row INSERT of the form:
+# INSERT INTO t (id...) VALUES (NULL...) ON DUPLICATE KEY UPDATE id=VALUES(id)
+#
+
+create table t1(
+id int auto_increment,
+c char(1) not null,
+counter int not null default 1,
+primary key (id),
+unique key (c)
+) engine=innodb;
+
+insert into t1 (id, c) values
+(NULL, 'a'),
+(NULL, 'a')
+on duplicate key update id = values(id), counter = counter + 1;
+
+select * from t1;
+
+insert into t1 (id, c) values
+(NULL, 'b')
+on duplicate key update id = values(id), counter = counter + 1;
+
+select * from t1;
+
+truncate table t1;
+
+insert into t1 (id, c) values (NULL, 'a');
+
+select * from t1;
+
+insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+
+select * from t1;
+
+insert into t1 (id, c) values (NULL, 'a')
+on duplicate key update id = values(id), c = values(c), counter = counter + 1;
+
+select * from t1;
+
+drop table t1;
+
+#
+# Bug #28189: optimizer erroniously prefers ref access to range access
+# for an InnoDB table
+#
+
+CREATE TABLE t1(
+ id int AUTO_INCREMENT PRIMARY KEY,
+ stat_id int NOT NULL,
+ acct_id int DEFAULT NULL,
+ INDEX idx1 (stat_id, acct_id),
+ INDEX idx2 (acct_id)
+) ENGINE=MyISAM;
+
+CREATE TABLE t2(
+ id int AUTO_INCREMENT PRIMARY KEY,
+ stat_id int NOT NULL,
+ acct_id int DEFAULT NULL,
+ INDEX idx1 (stat_id, acct_id),
+ INDEX idx2 (acct_id)
+) ENGINE=InnoDB;
+
+INSERT INTO t1(stat_id,acct_id) VALUES
+ (1,759), (2,831), (3,785), (4,854), (1,921),
+ (1,553), (2,589), (3,743), (2,827), (2,545),
+ (4,779), (4,783), (1,597), (1,785), (4,832),
+ (1,741), (1,833), (3,788), (2,973), (1,907);
+
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
+UPDATE t1 SET acct_id=785
+ WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
+OPTIMIZE TABLE t1;
+
+SELECT COUNT(*) FROM t1;
+SELECT COUNT(*) FROM t1 WHERE acct_id=785;
+
+EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
+
+INSERT INTO t2 SELECT * FROM t1;
+OPTIMIZE TABLE t2;
+
+EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
+
+DROP TABLE t1,t2;
+
+#
+# Bug #28652: assert when alter innodb table operation
+#
+create table t1(a int) engine=innodb;
+alter table t1 comment '123';
+show create table t1;
+drop table t1;
+
+#
+# Bug #25866: Getting "#HY000 Can't find record in..." on and INSERT
+#
+CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB DEFAULT CHARSET=UTF8;
+INSERT INTO t1 VALUES ('uk'),('bg');
+SELECT * FROM t1 WHERE a = 'uk';
+DELETE FROM t1 WHERE a = 'uk';
+SELECT * FROM t1 WHERE a = 'uk';
+UPDATE t1 SET a = 'us' WHERE a = 'uk';
+SELECT * FROM t1 WHERE a = 'uk';
+
+CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
+INSERT INTO t2 VALUES ('uk'),('bg');
+SELECT * FROM t2 WHERE a = 'uk';
+DELETE FROM t2 WHERE a = 'uk';
+SELECT * FROM t2 WHERE a = 'uk';
+INSERT INTO t2 VALUES ('uk');
+UPDATE t2 SET a = 'us' WHERE a = 'uk';
+SELECT * FROM t2 WHERE a = 'uk';
+
+CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
+INSERT INTO t3 VALUES ('uk'),('bg');
+SELECT * FROM t3 WHERE a = 'uk';
+DELETE FROM t3 WHERE a = 'uk';
+SELECT * FROM t3 WHERE a = 'uk';
+INSERT INTO t3 VALUES ('uk');
+UPDATE t3 SET a = 'us' WHERE a = 'uk';
+SELECT * FROM t3 WHERE a = 'uk';
+
+DROP TABLE t1,t2,t3;
+
+#
+# Test bug when trying to drop data file which no InnoDB directory entry
+#
+
+create table t1 (a int) engine=innodb;
+let $MYSQLD_DATADIR= `select @@datadir`;
+copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/bug29807.frm;
+--error 1146
+select * from bug29807;
+drop table t1;
+--error 1051
+drop table bug29807;
+create table bug29807 (a int);
+drop table bug29807;
+
+
+#
+# Bug #29154: LOCK TABLES is not atomic when >1 InnoDB tables are locked
+#
+
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
+
+CONNECT (c1,localhost,root,,);
+CONNECT (c2,localhost,root,,);
+
+--echo switch to connection c1
+CONNECTION c1;
+SET AUTOCOMMIT=0;
+INSERT INTO t2 VALUES (1);
+
+--echo switch to connection c2
+CONNECTION c2;
+SET AUTOCOMMIT=0;
+--error ER_LOCK_WAIT_TIMEOUT
+LOCK TABLES t1 READ, t2 READ;
+
+--echo switch to connection c1
+CONNECTION c1;
+COMMIT;
+INSERT INTO t1 VALUES (1);
+
+--echo switch to connection default
+CONNECTION default;
+SET AUTOCOMMIT=default;
+DISCONNECT c1;
+DISCONNECT c2;
+DROP TABLE t1,t2;
+
+#
+# Bug #25798: a query with forced index merge returns wrong result
+#
+
+CREATE TABLE t1 (
+ id int NOT NULL auto_increment PRIMARY KEY,
+ b int NOT NULL,
+ c datetime NOT NULL,
+ INDEX idx_b(b),
+ INDEX idx_c(c)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ b int NOT NULL auto_increment PRIMARY KEY,
+ c datetime NOT NULL
+) ENGINE= MyISAM;
+
+INSERT INTO t2(c) VALUES ('2007-01-01');
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+INSERT INTO t2(c) SELECT c FROM t2;
+
+INSERT INTO t1(b,c) SELECT b,c FROM t2;
+UPDATE t2 SET c='2007-01-02';
+INSERT INTO t1(b,c) SELECT b,c FROM t2;
+UPDATE t2 SET c='2007-01-03';
+INSERT INTO t1(b,c) SELECT b,c FROM t2;
+
+set @@sort_buffer_size=8192;
+
+SELECT COUNT(*) FROM t1;
+
+--replace_column 9 #
+EXPLAIN
+SELECT COUNT(*) FROM t1
+ WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
+SELECT COUNT(*) FROM t1
+ WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
+
+--replace_column 9 #
+EXPLAIN
+SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
+ WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
+SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
+ WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
+
+set @@sort_buffer_size=default;
+
+DROP TABLE t1,t2;
+
+# Test of behaviour with CREATE ... SELECT
+#
+
+CREATE TABLE t1 (a int, b int);
+insert into t1 values (1,1),(1,2);
+--error ER_DUP_ENTRY
+CREATE TABLE t2 (primary key (a)) select * from t1;
+# This should give warning
+drop table if exists t2;
+--error ER_DUP_ENTRY
+CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
+# This should give warning
+drop table if exists t2;
+CREATE TABLE t2 (a int, b int, primary key (a));
+BEGIN;
+INSERT INTO t2 values(100,100);
+--error ER_DUP_ENTRY
+CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
+SELECT * from t2;
+ROLLBACK;
+SELECT * from t2;
+TRUNCATE table t2;
+--error ER_DUP_ENTRY
+INSERT INTO t2 select * from t1;
+SELECT * from t2;
+drop table t2;
+
+CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
+BEGIN;
+INSERT INTO t2 values(100,100);
+--error ER_DUP_ENTRY
+CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
+SELECT * from t2;
+COMMIT;
+BEGIN;
+INSERT INTO t2 values(101,101);
+--error ER_DUP_ENTRY
+CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
+SELECT * from t2;
+ROLLBACK;
+SELECT * from t2;
+TRUNCATE table t2;
+--error ER_DUP_ENTRY
+INSERT INTO t2 select * from t1;
+SELECT * from t2;
+drop table t1,t2;
+
+#
+# Bug#17530: Incorrect key truncation on table creation caused server crash.
+#
+create table t1(f1 varchar(800) binary not null, key(f1))
+ character set utf8 collate utf8_general_ci;
+insert into t1 values('aaa');
+drop table t1;
+
+
+#
+# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
+
+INSERT INTO t1 VALUES ( 1 , 1 , 1);
+INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
+INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
+
+EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
+EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
+DROP TABLE t1;
+
+--source include/innodb_rollback_on_timeout.inc
+
+#
+# Bug#27296 Assertion in ALTER TABLE SET DEFAULT in Linux Debug build
+# (possible deadlock).
+#
+# The bug is applicable only to a transactoinal table.
+# Cover with tests behavior that no longer causes an
+# assertion.
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int) engine=innodb;
+alter table t1 alter a set default 1;
+drop table t1;
+
+--echo
+--echo Bug#24918 drop table and lock / inconsistent between
+--echo perm and temp tables
+--echo
+--echo Check transactional tables under LOCK TABLES
+--echo
+--disable_warnings
+drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp,
+t24918_access;
+--enable_warnings
+create table t24918_access (id int);
+create table t24918 (id int) engine=myisam;
+create temporary table t24918_tmp (id int) engine=myisam;
+create table t24918_trans (id int) engine=innodb;
+create temporary table t24918_trans_tmp (id int) engine=innodb;
+
+lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
+drop table t24918;
+--error ER_TABLE_NOT_LOCKED
+select * from t24918_access;
+drop table t24918_trans;
+--error ER_TABLE_NOT_LOCKED
+select * from t24918_access;
+drop table t24918_trans_tmp;
+--error ER_TABLE_NOT_LOCKED
+select * from t24918_access;
+drop table t24918_tmp;
+--error ER_TABLE_NOT_LOCKED
+select * from t24918_access;
+unlock tables;
+
+drop table t24918_access;
+#
+# Bug #28591: MySQL need not sort the records in case of ORDER BY
+# primary_key on InnoDB table
+#
+
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
+INSERT INTO t1 SELECT a + 8, 2 FROM t1;
+INSERT INTO t1 SELECT a + 16, 1 FROM t1;
+query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
+SELECT * FROM t1 WHERE b=2 ORDER BY a;
+query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
+SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
+query_vertical EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
+SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
+
+CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
+ ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
+INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
+INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
+
+query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
+SELECT * FROM t2 WHERE b=1 ORDER BY a;
+query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
+SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
+query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
+SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
+query_vertical EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
+SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
+
+DROP TABLE t1,t2;
+
+
+#
+# Bug #29644: alter table hangs if records locked in share mode by long
+# running transaction
+#
+
+CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+INSERT INTO t1 SELECT a + 8 FROM t1;
+INSERT INTO t1 SELECT a + 16 FROM t1;
+
+DELIMITER |;
+CREATE PROCEDURE p1 ()
+BEGIN
+ DECLARE i INT DEFAULT 50;
+ DECLARE cnt INT;
+ START TRANSACTION;
+ ALTER TABLE t1 ENGINE=InnoDB;
+ COMMIT;
+ START TRANSACTION;
+ WHILE (i > 0) DO
+ SET i = i - 1;
+ SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
+ END WHILE;
+ COMMIT;
+END;|
+
+DELIMITER ;|
+
+CONNECT (con1,localhost,root,,);
+CONNECT (con2,localhost,root,,);
+
+CONNECTION con1;
+SEND CALL p1();
+CONNECTION con2;
+SEND CALL p1();
+CONNECTION default;
+CALL p1();
+
+CONNECTION con1;
+REAP;
+CONNECTION con2;
+REAP;
+CONNECTION default;
+DISCONNECT con1;
+DISCONNECT con2;
+
+DROP PROCEDURE p1;
+DROP TABLE t1;
+
+#
+# Bug #28125: ERROR 2013 when adding index.
+#
+create table t1(a text) engine=innodb default charset=utf8;
+insert into t1 values('aaa');
+alter table t1 add index(a(1024));
+show create table t1;
+drop table t1;
+
+#
+# Bug #28570: handler::index_read() is called with different find_flag when
+# ORDER BY is used
+#
+
+CREATE TABLE t1 (
+ a INT,
+ b INT,
+ KEY (b)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
+
+START TRANSACTION;
+SELECT * FROM t1 WHERE b=20 FOR UPDATE;
+
+--connect (conn2, localhost, root,,test)
+
+# This statement gives a "failed: 1205: Lock wait timeout exceeded; try
+# restarting transaction" message when the bug is present.
+START TRANSACTION;
+SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
+ROLLBACK;
+
+--disconnect conn2
+--connection default
+
+ROLLBACK;
+DROP TABLE t1;
+
+#
+# Bug#30596: GROUP BY optimization gives wrong result order
+#
+CREATE TABLE t1(
+ a INT,
+ b INT NOT NULL,
+ c INT NOT NULL,
+ d INT,
+ UNIQUE KEY (c,b)
+) engine=innodb;
+
+INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
+
+EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
+SELECT c,b,d FROM t1 GROUP BY c,b,d;
+EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
+SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
+EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
+SELECT c,b,d FROM t1 ORDER BY c,b,d;
+
+EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
+SELECT c,b,d FROM t1 GROUP BY c,b;
+EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
+SELECT c,b FROM t1 GROUP BY c,b;
+
+DROP TABLE t1;
+
+#
+# Bug #31001: ORDER BY DESC in InnoDB not working
+#
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
+INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
+
+#The two queries below should produce different results, but they don't.
+query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
+SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
+query_vertical EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
+SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
+
+query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
+SELECT * FROM t1 ORDER BY b ASC, a ASC;
+query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
+SELECT * FROM t1 ORDER BY b DESC, a DESC;
+query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
+SELECT * FROM t1 ORDER BY b ASC, a DESC;
+query_vertical EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
+SELECT * FROM t1 ORDER BY b DESC, a ASC;
+
+DROP TABLE t1;
+
+###########################################################################
+
+--echo
+--echo #
+--echo # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
+--echo #
+
+--echo
+--echo # - prepare;
+--echo
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo
+
+CREATE TABLE t1(c INT)
+ ENGINE = InnoDB
+ ROW_FORMAT = COMPACT;
+
+--echo
+--echo # - initial check;
+--echo
+
+SELECT table_schema, table_name, row_format
+FROM INFORMATION_SCHEMA.TABLES
+WHERE table_schema = DATABASE() AND table_name = 't1';
+
+--echo
+--echo # - change ROW_FORMAT and check;
+--echo
+
+ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
+
+--echo
+
+SELECT table_schema, table_name, row_format
+FROM INFORMATION_SCHEMA.TABLES
+WHERE table_schema = DATABASE() AND table_name = 't1';
+
+--echo
+--echo # - that's it, cleanup.
+--echo
+
+DROP TABLE t1;
+
+###########################################################################
+
+#
+# Bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0
+#
+create table t1(a char(10) not null, unique key aa(a(1)),
+ b char(4) not null, unique key bb(b(4))) engine=innodb;
+desc t1;
+show create table t1;
+drop table t1;
+
+#
+# Bug #32815: query with ORDER BY and a possible ref_or_null access
+#
+
+CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+ (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
+
+EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
+SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
+
+DROP TABLE t1;
+
+#
+# Bug #34223: Assertion failed: (optp->var_type & 127) == 8,
+# file .\my_getopt.c, line 830
+#
+
+set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
+set global innodb_autoextend_increment=8;
+set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
+
+set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
+set global innodb_commit_concurrency=0;
+set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
+
+#
+# Bug #37830: ORDER BY ASC/DESC - no difference
+#
+
+CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
+ ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
+INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
+
+# should be range access
+EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+# should produce '8 7 6 5 4' for a
+SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
+
+DROP TABLE t1;
+
+--echo End of 5.0 tests
+
+# Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY
+# UPDATE": if the row is updated, it's like a regular UPDATE:
+# LAST_INSERT_ID() is not affected.
+CREATE TABLE `t2` (
+ `k` int(11) NOT NULL auto_increment,
+ `a` int(11) default NULL,
+ `c` int(11) default NULL,
+ PRIMARY KEY (`k`),
+ UNIQUE KEY `idx_1` (`a`)
+);
+insert into t2 ( a ) values ( 6 ) on duplicate key update c =
+ifnull( c,
+0 ) + 1;
+insert into t2 ( a ) values ( 7 ) on duplicate key update c =
+ifnull( c,
+0 ) + 1;
+select last_insert_id();
+select * from t2;
+insert into t2 ( a ) values ( 6 ) on duplicate key update c =
+ifnull( c,
+0 ) + 1;
+select last_insert_id();
+# test again when last_insert_id() is 0 initially
+select last_insert_id(0);
+insert into t2 ( a ) values ( 6 ) on duplicate key update c =
+ifnull( c,
+0 ) + 1;
+select last_insert_id();
+select * from t2;
+
+# Test of LAST_INSERT_ID() when autogenerated will fail:
+# last_insert_id() should not change
+insert ignore into t2 values (null,6,1),(10,8,1);
+select last_insert_id();
+# First and second autogenerated will fail, last_insert_id() should
+# point to third
+insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
+select last_insert_id();
+select * from t2;
+
+# Test of the workaround which enables people to know the id of the
+# updated row in INSERT ON DUPLICATE KEY UPDATE, by using
+# LAST_INSERT_ID(autoinc_col) in the UPDATE clause.
+
+insert into t2 ( a ) values ( 6 ) on duplicate key update c =
+ifnull( c,
+0 ) + 1, k=last_insert_id(k);
+select last_insert_id();
+select * from t2;
+
+drop table t2;
+
+
+#
+# Tests for bug #28415 "Some ALTER TABLE statements no longer work
+# under LOCK TABLES" and some aspects of fast ALTER TABLE behaviour
+# for transactional tables.
+#
+--disable_warnings
+drop table if exists t1, t2;
+--enable_warnings
+create table t1 (i int);
+alter table t1 modify i int default 1;
+alter table t1 modify i int default 2, rename t2;
+lock table t2 write;
+alter table t2 modify i int default 3;
+unlock tables;
+lock table t2 write;
+alter table t2 modify i int default 4, rename t1;
+unlock tables;
+drop table t1;
+
+
+#
+# Some more tests for ALTER TABLE and LOCK TABLES for transactional tables.
+#
+# Table which is altered under LOCK TABLES should stay in list of locked
+# tables and be available after alter takes place unless ALTER contains
+# RENAME clause. We should see the new definition of table, of course.
+# Before 5.1 this behavior was inconsistent across the platforms and
+# different engines. See also tests in alter_table.test
+#
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (i int);
+insert into t1 values ();
+lock table t1 write;
+# Example of so-called 'fast' ALTER TABLE
+alter table t1 modify i int default 1;
+insert into t1 values ();
+select * from t1;
+# And now full-blown ALTER TABLE
+alter table t1 change i c char(10) default "Two";
+insert into t1 values ();
+select * from t1;
+unlock tables;
+select * from t1;
+drop tables t1;
+
+#
+# Bug#29310: An InnoDB table was updated when the data wasn't actually changed.
+#
+create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
+ CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
+insert into t1(f1) values(1);
+--replace_column 1 #
+select @a:=f2 from t1;
+--sleep 5
+update t1 set f1=1;
+--replace_column 1 #
+select @b:=f2 from t1;
+select if(@a=@b,"ok","wrong");
+--sleep 5
+insert into t1(f1) values (1) on duplicate key update f1="1";
+--replace_column 1 #
+select @b:=f2 from t1;
+select if(@a=@b,"ok","wrong");
+--sleep 5
+insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
+--replace_column 1 #
+select @b:=f2 from t1;
+select if(@a=@b,"ok","wrong");
+drop table t1;
+
+#
+# Bug #31310: Locked rows silently skipped in read-committed isolation level.
+#
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+SET SESSION AUTOCOMMIT = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+set binlog_format=mixed;
+--echo # Switch to connection con1
+connection con1;
+
+eval
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
+ENGINE = $engine_type;
+INSERT INTO t1 VALUES (1,2);
+
+--echo # 1. test for locking:
+
+BEGIN;
+--enable_info
+UPDATE t1 SET b = 12 WHERE a = 1;
+--disable_info
+SELECT * FROM t1;
+
+--echo # Switch to connection con2
+connection con2;
+
+--enable_info
+--disable_abort_on_error
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET b = 21 WHERE a = 1;
+--disable_info
+
+--echo # Switch to connection con1
+connection con1;
+SELECT * FROM t1;
+ROLLBACK;
+
+--echo # 2. test for serialized update:
+
+CREATE TABLE t2 (a INT);
+
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1,'init');
+
+DELIMITER |;
+CREATE PROCEDURE p1()
+BEGIN
+ UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
+ INSERT INTO t2 VALUES ();
+END|
+DELIMITER ;|
+
+BEGIN;
+--enable_info
+UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
+--disable_info
+SELECT * FROM t1;
+
+--echo # Switch to connection con2
+connection con2;
+
+--send CALL p1;
+
+--echo # Switch to connection con1
+connection con1;
+SELECT * FROM t1;
+COMMIT;
+
+let $bug31310 = 1;
+while ($bug31310)
+{
+ let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
+}
+
+SELECT * FROM t1;
+
+--echo # Switch to connection con2
+connection con2;
+--reap
+SELECT * FROM t1;
+
+--echo # Switch to connection con1
+connection con1;
+
+--echo # 3. test for updated key column:
+
+TRUNCATE t1;
+TRUNCATE t2;
+
+INSERT INTO t1 VALUES (1,'init');
+
+BEGIN;
+--enable_info
+UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
+--disable_info
+SELECT * FROM t1;
+
+--echo # Switch to connection con2
+connection con2;
+
+--send CALL p1;
+
+--echo # Switch to connection con1
+connection con1;
+SELECT * FROM t1;
+COMMIT;
+
+let $bug31310 = 1;
+while ($bug31310)
+{
+ let $bug31310= `SELECT 1 - COUNT(*) FROM t2`;
+}
+
+SELECT * FROM t1;
+
+--echo # Switch to connection con2
+connection con2;
+SELECT * FROM t1;
+
+connection default;
+disconnect con1;
+disconnect con2;
+DROP PROCEDURE p1;
+DROP TABLE t1, t2;
+# Bug#30747 Create table with identical constraint names behaves incorrectly
+#
+
+if ($test_foreign_keys)
+{
+ CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
+ --error ER_WRONG_FK_DEF
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
+ --error ER_WRONG_FK_DEF
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
+ CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
+ ALTER TABLE t2 DROP FOREIGN KEY c2;
+ DROP TABLE t2;
+ --error ER_WRONG_FK_DEF
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
+ --error ER_WRONG_FK_DEF
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
+ CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
+ CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
+ CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
+ FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
+ FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
+ SHOW CREATE TABLE t2;
+ DROP TABLE t2;
+ DROP TABLE t1;
+}
+
+#
+# Bug #26447: "ALTER TABLE .. ORDER" does not work with InnoDB and
+# auto_increment keys
+#
+create table t1 (a int auto_increment primary key) engine=innodb;
+alter table t1 order by a;
+drop table t1;
+
+#
+# Bug #33697: ORDER BY primary key DESC vs. ref access + filesort
+# (reproduced only with InnoDB tables)
+#
+
+CREATE TABLE t1
+ (vid integer NOT NULL,
+ tid integer NOT NULL,
+ idx integer NOT NULL,
+ name varchar(128) NOT NULL,
+ type varchar(128) NULL,
+ PRIMARY KEY(idx, vid, tid),
+ UNIQUE(vid, tid, name)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES
+ (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
+ (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
+ (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
+ (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
+ (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
+
+EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
+
+SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
+
+DROP TABLE t1;
+
+#
+# Bug#21704: Renaming column does not update FK definition.
+#
+
+#
+# --disable_warnings
+# DROP TABLE IF EXISTS t1;
+# DROP TABLE IF EXISTS t2;
+# --enable_warnings
+#
+# CREATE TABLE t1(id INT PRIMARY KEY)
+# ENGINE=innodb;
+#
+# CREATE TABLE t2(
+# t1_id INT PRIMARY KEY,
+# CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
+# ENGINE=innodb;
+#
+# --echo
+#
+# --disable_result_log
+# --error ER_ERROR_ON_RENAME
+# ALTER TABLE t1 CHANGE id id2 INT;
+# --enable_result_log
+#
+# --echo
+#
+# DROP TABLE t2;
+# DROP TABLE t1;
+#
+
+--echo End of 5.1 tests
diff --git a/mysql-test/include/mix2.inc b/mysql-test/include/mix2.inc
new file mode 100644
index 00000000000..b4c4a9b8836
--- /dev/null
+++ b/mysql-test/include/mix2.inc
@@ -0,0 +1,2477 @@
+################################################################################
+# #
+# include/mix2.inc #
+# #
+# This is a derivate of t/innodb.test and has to be maintained by MySQL #
+# guys only. #
+# #
+# Please, DO NOT create a toplevel testcase mix2_innodb.test, because #
+# innodb.test does already these tests. #
+# #
+# Variables which have to be set before calling this script: #
+# $engine_type -- Storage engine to be tested #
+# $other_engine_type -- storage engine <> $engine_type #
+# $other_engine_type1 -- storage engine <> $engine_type #
+# storage engine <> $other_engine_type, if possible #
+# $other_non_trans_engine_type -- storage engine <> $engine_type #
+# $other_non_trans_engine_type must be a non #
+# transactional storage engine #
+# $other_non_live_chks_engine_type #
+# -- storage engine <> $engine_type, if possible #
+# storage engine must not support live checksum #
+# $other_live_chks_engine_type #
+# -- storage engine <> $engine_type, if possible #
+# storage engine must support live checksum #
+# General Note: The $other_*_engine_type variables must point to all #
+# time available storage engines #
+# 2006-08 MySQL 5.1 MyISAM and MEMORY only #
+# $test_transactions -- 0, skip transactional tests #
+# -- 1, do not skip transactional tests #
+# $test_foreign_keys -- 0, skip foreign key tests #
+# -- 1, do not skip foreign key tests #
+# $fulltext_query_unsupported -- 0, execute fulltext_query tests #
+# -- 1, skip fulltext query tests #
+# $no_autoinc_update -- 0, skip tests where it is expected that an update #
+# does not update the internal auto-increment value#
+# -- 1, do not skip these tests #
+# $no_spatial_key -- 0, skip tests where it is expected that keys on #
+# spatial data type are not allowed #
+# -- 1, do not skip these tests #
+# #
+# The comments/expectations refer to InnoDB. #
+# They might be not valid for other storage engines. #
+# #
+# #
+# Last update: #
+# 2006-08-15 ML - introduce several $variables #
+# - correct some storage engine assignments #
+# - minor improvements like correct wrong table after analyze #
+# - let checksum testcase meet all table variants with/without #
+# live checksum feature exiting and/or enabled #
+# 2006-07-26 ML create script by using t/innodb.test and introduce $variables #
+# #
+################################################################################
+
+# Set the SESSION DEFAULT STORAGE ENGINE to a value <> storage engine
+# to be tested. This must not affect any CREATE TABLE statement, where
+# the storage engine is assigned explicitely,
+eval SET SESSION STORAGE_ENGINE = $other_engine_type;
+
+#
+# Small basic test with ignore
+#
+
+--disable_warnings
+drop table if exists t1,t2,t3,t4;
+drop database if exists mysqltest;
+--enable_warnings
+
+eval create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=$engine_type;
+
+insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
+select id, code, name from t1 order by id;
+
+update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
+select id, code, name from t1 order by id;
+update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
+select id, code, name from t1 order by id;
+
+drop table t1;
+
+#
+# A bit bigger test
+# The 'replace_column' statements are needed because the cardinality calculated
+# by innodb is not always the same between runs
+#
+
+eval CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ parent_id int(11) DEFAULT '0' NOT NULL,
+ level tinyint(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (id),
+ KEY parent_id (parent_id),
+ KEY level (level)
+) engine=$engine_type;
+INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
+update t1 set parent_id=parent_id+100;
+select * from t1 where parent_id=102;
+update t1 set id=id+1000;
+-- error ER_DUP_ENTRY,1022
+update t1 set id=1024 where id=1009;
+select * from t1;
+update ignore t1 set id=id+1; # This will change all rows
+select * from t1;
+update ignore t1 set id=1023 where id=1010;
+select * from t1 where parent_id=102;
+--replace_column 9 #
+explain select level from t1 where level=1;
+--replace_column 9 #
+explain select level,id from t1 where level=1;
+--replace_column 9 #
+explain select level,id,parent_id from t1 where level=1;
+select level,id from t1 where level=1;
+select level,id,parent_id from t1 where level=1;
+optimize table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+#
+# Test replace
+#
+
+eval CREATE TABLE t1 (
+ gesuchnr int(11) DEFAULT '0' NOT NULL,
+ benutzer_id int(11) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (gesuchnr,benutzer_id)
+) engine=$engine_type;
+
+replace into t1 (gesuchnr,benutzer_id) values (2,1);
+replace into t1 (gesuchnr,benutzer_id) values (1,1);
+replace into t1 (gesuchnr,benutzer_id) values (1,1);
+select * from t1;
+drop table t1;
+
+#
+# test delete using hidden_primary_key
+#
+
+eval create table t1 (a int) engine=$engine_type;
+insert into t1 values (1), (2);
+optimize table t1;
+delete from t1 where a = 1;
+select * from t1;
+check table t1;
+drop table t1;
+
+eval create table t1 (a int,b varchar(20)) engine=$engine_type;
+insert into t1 values (1,""), (2,"testing");
+delete from t1 where a = 1;
+select * from t1;
+create index skr on t1 (a);
+insert into t1 values (3,""), (4,"testing");
+analyze table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+
+# Test of reading on secondary key with may be null
+
+eval create table t1 (a int,b varchar(20),key(a)) engine=$engine_type;
+insert into t1 values (1,""), (2,"testing");
+select * from t1 where a = 1;
+drop table t1;
+
+if ($test_transactions)
+{
+#
+# Test rollback
+#
+
+eval create table t1 (n int not null primary key) engine=$engine_type;
+set autocommit=0;
+insert into t1 values (4);
+rollback;
+select n, "after rollback" from t1;
+insert into t1 values (4);
+commit;
+select n, "after commit" from t1;
+commit;
+insert into t1 values (5);
+-- error ER_DUP_ENTRY
+insert into t1 values (4);
+commit;
+select n, "after commit" from t1;
+set autocommit=1;
+insert into t1 values (6);
+-- error ER_DUP_ENTRY
+insert into t1 values (4);
+select n from t1;
+set autocommit=0;
+#
+# savepoints
+#
+begin;
+savepoint `my_savepoint`;
+insert into t1 values (7);
+savepoint `savept2`;
+insert into t1 values (3);
+select n from t1;
+savepoint savept3;
+rollback to savepoint savept2;
+--error 1305
+rollback to savepoint savept3;
+rollback to savepoint savept2;
+release savepoint `my_savepoint`;
+select n from t1;
+-- error 1305
+rollback to savepoint `my_savepoint`;
+--error 1305
+rollback to savepoint savept2;
+insert into t1 values (8);
+savepoint sv;
+commit;
+savepoint sv;
+set autocommit=1;
+# nop
+rollback;
+drop table t1;
+
+#
+# Test for commit and FLUSH TABLES WITH READ LOCK
+#
+
+eval create table t1 (n int not null primary key) engine=$engine_type;
+start transaction;
+insert into t1 values (4);
+flush tables with read lock;
+#
+# Current code can't handle a read lock in middle of transaction
+#--error 1223;
+commit;
+unlock tables;
+commit;
+select * from t1;
+drop table t1;
+
+#
+# Testing transactions
+#
+
+eval create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=$engine_type;
+begin;
+insert into t1 values(1,'hamdouni');
+select id as afterbegin_id,nom as afterbegin_nom from t1;
+rollback;
+select id as afterrollback_id,nom as afterrollback_nom from t1;
+set autocommit=0;
+insert into t1 values(2,'mysql');
+select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
+rollback;
+select id as afterrollback_id,nom as afterrollback_nom from t1;
+set autocommit=1;
+drop table t1;
+
+#
+# Simple not autocommit test
+#
+
+eval CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=$engine_type;
+insert into t1 values ('pippo', 12);
+-- error ER_DUP_ENTRY
+insert into t1 values ('pippo', 12); # Gives error
+delete from t1;
+delete from t1 where id = 'pippo';
+select * from t1;
+
+insert into t1 values ('pippo', 12);
+set autocommit=0;
+delete from t1;
+rollback;
+select * from t1;
+delete from t1;
+commit;
+select * from t1;
+drop table t1;
+
+#
+# Test of active transactions
+#
+
+eval create table t1 (a integer) engine=$engine_type;
+start transaction;
+rename table t1 to t2;
+eval create table t1 (b integer) engine=$engine_type;
+insert into t1 values (1);
+rollback;
+drop table t1;
+rename table t2 to t1;
+drop table t1;
+set autocommit=1;
+
+#
+# The following simple tests failed at some point
+#
+
+eval CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=$engine_type;
+INSERT INTO t1 VALUES (1, 'Jochen');
+select * from t1;
+drop table t1;
+
+eval CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=$engine_type;
+set autocommit=0;
+INSERT INTO t1 SET _userid='marc@anyware.co.uk';
+COMMIT;
+SELECT * FROM t1;
+SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
+drop table t1;
+set autocommit=1;
+
+}
+# End of transactional tests
+
+#
+# Test when reading on part of unique key
+#
+eval CREATE TABLE t1 (
+ user_id int(10) DEFAULT '0' NOT NULL,
+ name varchar(100),
+ phone varchar(100),
+ ref_email varchar(100) DEFAULT '' NOT NULL,
+ detail varchar(200),
+ PRIMARY KEY (user_id,ref_email)
+)engine=$engine_type;
+
+INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
+select * from t1 where user_id=10292;
+INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
+select * from t1 where user_id=10292;
+select * from t1 where user_id>=10292;
+select * from t1 where user_id>10292;
+select * from t1 where user_id<10292;
+drop table t1;
+
+#
+# Test that keys are created in right order
+#
+
+eval CREATE TABLE t1 (a int not null, b int not null,c int not null,
+key(a),primary key(a,b), unique(c),key(a),unique(b)) ENGINE = $engine_type;
+--replace_column 7 #
+show index from t1;
+drop table t1;
+
+#
+# Test of ALTER TABLE and innodb tables
+#
+
+eval create table t1 (col1 int not null, col2 char(4) not null, primary key(col1)) ENGINE = $other_engine_type;
+eval alter table t1 engine=$engine_type;
+insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
+select * from t1;
+update t1 set col2='7' where col1='4';
+select * from t1;
+alter table t1 add co3 int not null;
+select * from t1;
+update t1 set col2='9' where col1='2';
+select * from t1;
+drop table t1;
+
+#
+# INSERT INTO innodb tables
+#
+
+eval create table t1 (a int not null , b int, primary key (a)) engine = $engine_type;
+eval create table t2 (a int not null , b int, primary key (a)) engine = $other_engine_type;
+insert into t1 VALUES (1,3) , (2,3), (3,3);
+select * from t1;
+insert into t2 select * from t1;
+select * from t2;
+delete from t1 where b = 3;
+select * from t1;
+insert into t1 select * from t2;
+select * from t1;
+select * from t2;
+drop table t1,t2;
+
+#
+# Search on unique key
+#
+
+eval CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ ggid varchar(32) binary DEFAULT '' NOT NULL,
+ email varchar(64) DEFAULT '' NOT NULL,
+ passwd varchar(32) binary DEFAULT '' NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE ggid (ggid)
+) ENGINE=$engine_type;
+
+insert into t1 (ggid,passwd) values ('test1','xxx');
+insert into t1 (ggid,passwd) values ('test2','yyy');
+-- error ER_DUP_ENTRY
+insert into t1 (ggid,passwd) values ('test2','this will fail');
+-- error ER_DUP_ENTRY
+insert into t1 (ggid,id) values ('this will fail',1);
+
+select * from t1 where ggid='test1';
+select * from t1 where passwd='xxx';
+select * from t1 where id=2;
+
+replace into t1 (ggid,id) values ('this will work',1);
+replace into t1 (ggid,passwd) values ('test2','this will work');
+-- error ER_DUP_ENTRY
+update t1 set id=100,ggid='test2' where id=1;
+select * from t1;
+select * from t1 where id=1;
+select * from t1 where id=999;
+drop table t1;
+
+#
+# ORDER BY on not primary key
+#
+
+eval CREATE TABLE t1 (
+ user_name varchar(12),
+ password text,
+ subscribed char(1),
+ user_id int(11) DEFAULT '0' NOT NULL,
+ quota bigint(20),
+ weight double,
+ access_date date,
+ access_time time,
+ approved datetime,
+ dummy_primary_key int(11) NOT NULL auto_increment,
+ PRIMARY KEY (dummy_primary_key)
+) ENGINE=$engine_type;
+INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
+INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
+INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
+INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
+INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
+select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
+drop table t1;
+
+#
+# Testing of tables without primary keys
+#
+
+eval CREATE TABLE t1 (
+ id int(11) NOT NULL auto_increment,
+ parent_id int(11) DEFAULT '0' NOT NULL,
+ level tinyint(4) DEFAULT '0' NOT NULL,
+ KEY (id),
+ KEY parent_id (parent_id),
+ KEY level (level)
+) engine=$engine_type;
+INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
+INSERT INTO t1 values (179,5,2);
+update t1 set parent_id=parent_id+100;
+select * from t1 where parent_id=102;
+update t1 set id=id+1000;
+update t1 set id=1024 where id=1009;
+select * from t1;
+update ignore t1 set id=id+1; # This will change all rows
+select * from t1;
+update ignore t1 set id=1023 where id=1010;
+select * from t1 where parent_id=102;
+--replace_column 9 #
+explain select level from t1 where level=1;
+select level,id from t1 where level=1;
+select level,id,parent_id from t1 where level=1;
+select level,id from t1 where level=1 order by id;
+delete from t1 where level=1;
+select * from t1;
+drop table t1;
+
+#
+# Test of index only reads
+#
+eval CREATE TABLE t1 (
+ sca_code char(6) NOT NULL,
+ cat_code char(6) NOT NULL,
+ sca_desc varchar(50),
+ lan_code char(2) NOT NULL,
+ sca_pic varchar(100),
+ sca_sdesc varchar(50),
+ sca_sch_desc varchar(16),
+ PRIMARY KEY (sca_code, cat_code, lan_code),
+ INDEX sca_pic (sca_pic)
+) engine = $engine_type ;
+
+INSERT INTO t1 ( sca_code, cat_code, sca_desc, lan_code, sca_pic, sca_sdesc, sca_sch_desc) VALUES ( 'PD', 'J', 'PENDANT', 'EN', NULL, NULL, 'PENDANT'),( 'RI', 'J', 'RING', 'EN', NULL, NULL, 'RING'),( 'QQ', 'N', 'RING', 'EN', 'not null', NULL, 'RING');
+select count(*) from t1 where sca_code = 'PD';
+select count(*) from t1 where sca_code <= 'PD';
+select count(*) from t1 where sca_pic is null;
+alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
+select count(*) from t1 where sca_code='PD' and sca_pic is null;
+select count(*) from t1 where cat_code='E';
+
+alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
+select count(*) from t1 where sca_code='PD' and sca_pic is null;
+select count(*) from t1 where sca_pic >= 'n';
+select sca_pic from t1 where sca_pic is null;
+update t1 set sca_pic="test" where sca_pic is null;
+delete from t1 where sca_code='pd';
+drop table t1;
+
+#
+# Test of opening table twice and timestamps
+#
+set @a:=now();
+eval CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=$engine_type;
+insert into t1 (a) values(1),(2),(3);
+select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
+select a from t1 natural join t1 as t2 where b >= @a order by a;
+update t1 set a=5 where a=1;
+select a from t1;
+drop table t1;
+
+#
+# Test with variable length primary key
+#
+eval create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=$engine_type;
+insert into t1 values("hello",1),("world",2);
+select * from t1 order by b desc;
+optimize table t1;
+--replace_column 7 #
+show keys from t1;
+drop table t1;
+
+#
+# Test of create index with NULL columns
+#
+eval create table t1 (i int, j int ) ENGINE=$engine_type;
+insert into t1 values (1,2);
+select * from t1 where i=1 and j=2;
+create index ax1 on t1 (i,j);
+select * from t1 where i=1 and j=2;
+drop table t1;
+
+#
+# Test min-max optimization
+#
+
+eval CREATE TABLE t1 (
+ a int3 unsigned NOT NULL,
+ b int1 unsigned NOT NULL,
+ UNIQUE (a, b)
+) ENGINE = $engine_type;
+
+INSERT INTO t1 VALUES (1, 1);
+SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
+drop table t1;
+
+#
+# Test INSERT DELAYED
+#
+
+eval CREATE TABLE t1 (a int unsigned NOT NULL) engine=$engine_type;
+# Can't test this in 3.23
+# INSERT DELAYED INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+
+#
+# Crash when using many tables (Test case by Jeremy D Zawodny)
+#
+
+eval create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = $engine_type;
+insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+--replace_column 9 #
+explain select * from t1 where a > 0 and a < 50;
+drop table t1;
+
+#
+# Test lock tables
+#
+
+eval create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=$engine_type;
+insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
+LOCK TABLES t1 WRITE;
+--error ER_DUP_ENTRY
+insert into t1 values (99,1,2,'D'),(1,1,2,'D');
+select id from t1;
+select id from t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+eval create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=$engine_type;
+insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
+LOCK TABLES t1 WRITE;
+begin;
+--error ER_DUP_ENTRY
+insert into t1 values (99,1,2,'D'),(1,1,2,'D');
+select id from t1;
+insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
+commit;
+select id,id3 from t1;
+UNLOCK TABLES;
+DROP TABLE t1;
+
+#
+# Test prefix key
+#
+eval create table t1 (a char(20), unique (a(5))) engine=$engine_type;
+drop table t1;
+eval create table t1 (a char(20), index (a(5))) engine=$engine_type;
+show create table t1;
+drop table t1;
+
+#
+# Test using temporary table and auto_increment
+#
+
+eval create temporary table t1 (a int not null auto_increment, primary key(a)) engine=$engine_type;
+insert into t1 values (NULL),(NULL),(NULL);
+delete from t1 where a=3;
+insert into t1 values (NULL);
+select * from t1;
+alter table t1 add b int;
+select * from t1;
+drop table t1;
+
+#Slashdot bug
+eval create table t1
+ (
+ id int auto_increment primary key,
+ name varchar(32) not null,
+ value text not null,
+ uid int not null,
+ unique key(name,uid)
+ ) engine=$engine_type;
+insert into t1 values (1,'one','one value',101),
+ (2,'two','two value',102),(3,'three','three value',103);
+set insert_id=5;
+replace into t1 (value,name,uid) values ('other value','two',102);
+delete from t1 where uid=102;
+set insert_id=5;
+replace into t1 (value,name,uid) values ('other value','two',102);
+set insert_id=6;
+replace into t1 (value,name,uid) values ('other value','two',102);
+select * from t1;
+drop table t1;
+
+#
+# Test DROP DATABASE
+#
+# ML: Test logics
+# Check that the creation of a table with engine = $engine_type does
+# in a certain database (already containing some tables using other
+# storage engines) not prevent the dropping of this database.
+
+create database mysqltest;
+eval create table mysqltest.t1 (a int not null) engine= $engine_type;
+insert into mysqltest.t1 values(1);
+eval create table mysqltest.t2 (a int not null) engine= $other_engine_type;
+insert into mysqltest.t2 values(1);
+eval create table mysqltest.t3 (a int not null) engine= $other_engine_type1;
+insert into mysqltest.t3 values(1);
+commit;
+drop database mysqltest;
+# Don't check error message
+--error 1049
+show tables from mysqltest;
+
+#
+# Test truncate table with and without auto_commit
+#
+
+set autocommit=0;
+eval create table t1 (a int not null) engine= $engine_type;
+insert into t1 values(1),(2);
+truncate table t1;
+commit;
+truncate table t1;
+truncate table t1;
+select * from t1;
+insert into t1 values(1),(2);
+delete from t1;
+select * from t1;
+commit;
+drop table t1;
+set autocommit=1;
+
+eval create table t1 (a int not null) engine= $engine_type;
+insert into t1 values(1),(2);
+truncate table t1;
+insert into t1 values(1),(2);
+select * from t1;
+truncate table t1;
+insert into t1 values(1),(2);
+delete from t1;
+select * from t1;
+drop table t1;
+
+#
+# Test of how ORDER BY works when doing it on the whole table
+#
+
+eval create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=$engine_type;
+insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
+--replace_column 9 #
+explain select * from t1 order by a;
+--replace_column 9 #
+explain select * from t1 order by b;
+--replace_column 9 #
+explain select * from t1 order by c;
+--replace_column 9 #
+explain select a from t1 order by a;
+--replace_column 9 #
+explain select b from t1 order by b;
+--replace_column 9 #
+explain select a,b from t1 order by b;
+--replace_column 9 #
+explain select a,b from t1;
+--replace_column 9 #
+explain select a,b,c from t1;
+drop table t1;
+
+#
+# Check describe
+#
+
+eval create table t1 (t int not null default 1, key (t)) engine=$engine_type;
+desc t1;
+drop table t1;
+
+#
+# Test of multi-table-delete
+#
+
+eval CREATE TABLE t1 (
+ number bigint(20) NOT NULL default '0',
+ cname char(15) NOT NULL default '',
+ carrier_id smallint(6) NOT NULL default '0',
+ privacy tinyint(4) NOT NULL default '0',
+ last_mod_date timestamp NOT NULL,
+ last_mod_id smallint(6) NOT NULL default '0',
+ last_app_date timestamp NOT NULL,
+ last_app_id smallint(6) default '-1',
+ version smallint(6) NOT NULL default '0',
+ assigned_scps int(11) default '0',
+ status tinyint(4) default '0'
+) ENGINE=$engine_type;
+INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
+INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
+INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
+INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
+INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
+INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
+eval CREATE TABLE t2 (
+ number bigint(20) NOT NULL default '0',
+ cname char(15) NOT NULL default '',
+ carrier_id smallint(6) NOT NULL default '0',
+ privacy tinyint(4) NOT NULL default '0',
+ last_mod_date timestamp NOT NULL,
+ last_mod_id smallint(6) NOT NULL default '0',
+ last_app_date timestamp NOT NULL,
+ last_app_id smallint(6) default '-1',
+ version smallint(6) NOT NULL default '0',
+ assigned_scps int(11) default '0',
+ status tinyint(4) default '0'
+) ENGINE=$engine_type;
+INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
+INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
+INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
+INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
+select * from t1;
+select * from t2;
+delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
+select * from t1;
+select * from t2;
+select * from t2;
+drop table t1,t2;
+
+#
+# A simple test with some isolation levels
+# TODO: Make this into a test using replication to really test how
+# this works.
+#
+
+eval create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=$engine_type;
+
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+SELECT @@tx_isolation,@@global.tx_isolation;
+insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
+select id, code, name from t1 order by id;
+COMMIT;
+
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
+select id, code, name from t1 order by id;
+COMMIT;
+
+BEGIN;
+SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
+select id, code, name from t1 order by id;
+COMMIT;
+DROP TABLE t1;
+
+#
+# Test of multi-table-update
+#
+eval create table t1 (n int(10), d int(10)) engine=$engine_type;
+eval create table t2 (n int(10), d int(10)) engine=$engine_type;
+insert into t1 values(1,1),(1,2);
+insert into t2 values(1,10),(2,20);
+UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
+select * from t1;
+select * from t2;
+drop table t1,t2;
+
+#
+# Testing of IFNULL
+#
+eval create table t1 (a int, b int) engine=$engine_type;
+insert into t1 values(20,null);
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a;
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a order by 1;
+insert into t1 values(10,null);
+select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
+t2.b=t3.a order by 1;
+drop table t1;
+
+#
+# Test of read_through not existing const_table
+#
+
+eval create table t1 (a varchar(10) not null) engine = $other_engine_type;
+eval create table t2 (b varchar(10) not null unique) engine=$engine_type;
+select t1.a from t1,t2 where t1.a=t2.b;
+drop table t1,t2;
+eval create table t1 (a int not null, b int, primary key (a)) engine = $engine_type;
+eval create table t2 (a int not null, b int, primary key (a)) engine = $engine_type;
+insert into t1 values (10, 20);
+insert into t2 values (10, 20);
+update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
+drop table t1,t2;
+
+if ($test_foreign_keys)
+{
+#
+# Test of multi-table-delete with foreign key constraints
+#
+
+eval CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
+eval CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=$engine_type;
+insert into t1 set id=1;
+insert into t2 set id=1, t1_id=1;
+delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
+select * from t1;
+select * from t2;
+drop table t2,t1;
+eval CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=$engine_type;
+eval CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=$engine_type;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, 1);
+SELECT * from t1;
+UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
+SELECT * from t1;
+UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
+SELECT * from t1;
+DROP TABLE t1,t2;
+}
+
+if ($test_transactions)
+{
+#
+# Test of range_optimizer
+#
+
+set autocommit=0;
+
+eval CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=$engine_type;
+
+eval CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=$engine_type;
+
+eval CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=$engine_type;
+
+INSERT INTO t3 VALUES("my-test-1", "my-test-2");
+COMMIT;
+
+INSERT INTO t1 VALUES("this-key", "will disappear");
+INSERT INTO t2 VALUES("this-key", "will also disappear");
+DELETE FROM t3 WHERE id1="my-test-1";
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+ROLLBACK;
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
+COMMIT;
+set autocommit=1;
+DROP TABLE t1,t2,t3;
+}
+
+#
+# Check update with conflicting key
+#
+
+eval CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=$engine_type;
+INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+# We need the a < 1000 test here to quard against the halloween problems
+UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
+SELECT * from t1;
+drop table t1;
+
+#
+# Test multi update with different join methods
+#
+
+eval CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=$engine_type;
+eval CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=$engine_type;
+INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);
+INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
+
+# Full join, without key
+update t1,t2 set t1.a=t1.a+100;
+select * from t1;
+
+# unique key
+update t1,t2 set t1.a=t1.a+100 where t1.a=101;
+select * from t1;
+
+# ref key
+update t1,t2 set t1.b=t1.b+10 where t1.b=2;
+select * from t1;
+
+# Range key (in t1)
+update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100;
+select * from t1;
+select * from t2;
+
+drop table t1,t2;
+eval CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=$other_non_trans_engine_type;
+eval CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=$engine_type;
+SET AUTOCOMMIT=0;
+INSERT INTO t1 ( B_ID ) VALUES ( 1 );
+INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
+ROLLBACK;
+SELECT * FROM t1;
+drop table t1,t2;
+eval create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = $engine_type;
+insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
+select distinct parent,child from t1 order by parent;
+drop table t1;
+
+#
+# Test that MySQL priorities clustered indexes
+#
+eval create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=$engine_type;
+eval create table t2 (a int not null auto_increment primary key, b int) ENGINE = $other_engine_type;
+insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
+insert into t2 (a) select b from t1;
+insert into t1 (b) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+insert into t2 (a) select b from t1;
+insert into t1 (a) select b from t2;
+select count(*) from t1;
+--replace_column 9 #
+explain select * from t1 where c between 1 and 2500;
+update t1 set c=a;
+--replace_column 9 #
+explain select * from t1 where c between 1 and 2500;
+drop table t1,t2;
+
+#
+# Test of UPDATE ... ORDER BY
+#
+
+eval create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=$engine_type;
+
+insert into t1 (id) values (null),(null),(null),(null),(null);
+update t1 set fk=69 where fk is null order by id limit 1;
+SELECT * from t1;
+drop table t1;
+
+eval create table t1 (a int not null, b int not null, key (a)) engine=$engine_type;
+insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
+SET @tmp=0;
+update t1 set b=(@tmp:=@tmp+1) order by a;
+update t1 set b=99 where a=1 order by b asc limit 1;
+update t1 set b=100 where a=1 order by b desc limit 2;
+update t1 set a=a+10+b where a=1 order by b;
+select * from t1 order by a,b;
+drop table t1;
+
+#
+# Test of multi-table-updates (bug #1980).
+#
+
+eval create table t1 ( c char(8) not null ) engine=$engine_type;
+insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
+insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
+
+alter table t1 add b char(8) not null;
+alter table t1 add a char(8) not null;
+alter table t1 add primary key (a,b,c);
+update t1 set a=c, b=c;
+
+eval create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=$engine_type;
+insert into t2 select * from t1;
+
+delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
+drop table t1,t2;
+
+#
+# test autoincrement with TRUNCATE
+#
+
+SET AUTOCOMMIT=1;
+eval create table t1 (a integer auto_increment primary key) engine=$engine_type;
+insert into t1 (a) values (NULL),(NULL);
+truncate table t1;
+insert into t1 (a) values (NULL),(NULL);
+SELECT * from t1;
+drop table t1;
+
+
+if ($test_foreign_keys)
+{
+#
+# Test dictionary handling with spaceand quoting
+#
+
+eval CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=$engine_type;
+eval CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (`t1_id`) REFERENCES `t1`(`id 1`) ON DELETE CASCADE ) ENGINE=$engine_type;
+#show create table t2;
+drop table t2,t1;
+
+#
+# Test of multi updated and foreign keys
+#
+
+eval create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = $engine_type;
+insert into `t1`values ( 1 ) ;
+eval create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = $engine_type;
+insert into `t2`values ( 1 ) ;
+eval create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = $engine_type;
+insert into `t3`values ( 1 ) ;
+--error 1451
+delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+--error 1451
+update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+--error 1054
+update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
+drop table t3,t2,t1;
+
+#
+# test for recursion depth limit
+#
+eval create table t1(
+ id int primary key,
+ pid int,
+ index(pid),
+ foreign key(pid) references t1(id) on delete cascade) engine=$engine_type;
+insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
+ (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
+-- error 1451
+delete from t1 where id=0;
+delete from t1 where id=15;
+delete from t1 where id=0;
+
+drop table t1;
+}
+# End of FOREIGN KEY tests
+
+#
+# Test timestamps
+#
+
+eval CREATE TABLE t1 (col1 int(1))ENGINE=$engine_type;
+eval CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
+(stamp))ENGINE=$engine_type;
+insert into t1 values (1),(2),(3);
+# Note that timestamp 3 is wrong
+insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
+SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
+'20020204120000' GROUP BY col1;
+drop table t1,t2;
+
+#
+# Test by Francois MASUREL
+#
+
+eval CREATE TABLE t1 (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_object` int(10) unsigned default '0',
+ `id_version` int(10) unsigned NOT NULL default '1',
+ `label` varchar(100) NOT NULL default '',
+ `description` text,
+ PRIMARY KEY (`id`),
+ KEY `id_object` (`id_object`),
+ KEY `id_version` (`id_version`)
+) ENGINE=$engine_type;
+
+INSERT INTO t1 VALUES("6", "3382", "9", "Test", NULL), ("7", "102", "5", "Le Pekin (Test)", NULL),("584", "1794", "4", "Test de resto", NULL),("837", "1822", "6", "Test 3", NULL),("1119", "3524", "1", "Societe Test", NULL),("1122", "3525", "1", "Fournisseur Test", NULL);
+
+eval CREATE TABLE t2 (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `id_version` int(10) unsigned NOT NULL default '1',
+ PRIMARY KEY (`id`),
+ KEY `id_version` (`id_version`)
+) ENGINE=$engine_type;
+
+INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
+
+SELECT t2.id, t1.`label` FROM t2 INNER JOIN
+(SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
+ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
+drop table t1,t2;
+
+# Live checksum feature available + enabled
+eval create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=$other_live_chks_engine_type;
+# Live checksum feature available + disabled
+eval create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=$other_live_chks_engine_type;
+#
+# Live checksum feature not available + enabled
+eval create table t3 (a int, b varchar(200), c varchar(200) not null) checksum=1 engine=$other_non_live_chks_engine_type;
+# Live checksum feature not available + disabled
+eval create table t4 (a int, b varchar(200), c varchar(200) not null) checksum=0 engine=$other_non_live_chks_engine_type;
+#
+# Live checksum feature probably available + enabled
+eval create table t5 (a int, b varchar(200), c text not null) checksum=1 engine=$engine_type;
+# Live checksum feature probably available + disabled
+eval create table t6 (a int, b varchar(200), c text not null) checksum=0 engine=$engine_type;
+#
+insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
+insert t2 select * from t1;
+insert t3 select * from t1;
+insert t4 select * from t1;
+insert t5 select * from t1;
+insert t6 select * from t1;
+checksum table t1, t2, t3, t4, t5, t6, t7 quick;
+checksum table t1, t2, t3, t4, t5, t6, t7;
+checksum table t1, t2, t3, t4, t5, t6, t7 extended;
+# #show table status;
+drop table t1,t2,t3, t4, t5, t6;
+
+#
+# Test problem with refering to different fields in same table in UNION
+# (Bug#2552: UNION returns NULL instead of expected value (innoDB only tables))
+#
+eval create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=$engine_type;
+insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
+select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
+drop table t1;
+
+#
+# Bug#2160: Extra error message for CREATE TABLE LIKE with InnoDB
+#
+eval create table t1 (a int) engine=$engine_type;
+create table t2 like t1;
+show create table t2;
+drop table t1,t2;
+
+if ($test_foreign_keys)
+{
+#
+# Test of automaticly created foreign keys
+#
+
+eval create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=$engine_type;
+eval create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = $engine_type;
+show create table t1;
+show create table t2;
+create index id on t2 (id);
+show create table t2;
+create index id2 on t2 (id);
+show create table t2;
+drop index id2 on t2;
+--error 1025,1025
+drop index id on t2;
+show create table t2;
+drop table t2;
+
+eval create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = $engine_type;
+show create table t2;
+create unique index id on t2 (id,id2);
+show create table t2;
+drop table t2;
+
+# Check foreign key columns created in different order than key columns
+eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
+show create table t2;
+drop table t2;
+
+eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = $engine_type;
+show create table t2;
+drop table t2;
+
+eval create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = $engine_type;
+show create table t2;
+drop table t2;
+
+eval create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = $engine_type;
+show create table t2;
+drop table t2;
+
+eval create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= $engine_type;
+show create table t2;
+alter table t2 add index id_test (id), add index id_test2 (id,id2);
+show create table t2;
+drop table t2;
+
+# Test error handling
+
+# Clean up filename -- embedded server reports whole path without .frm,
+# regular server reports relative path with .frm (argh!)
+--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t2.frm t2
+--error 1005
+eval create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = $engine_type;
+
+# bug#3749
+
+eval create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
+show create table t2;
+drop table t2;
+eval create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=$engine_type;
+show create table t2;
+drop table t2, t1;
+}
+# End of FOREIGN KEY tests
+
+
+#
+# Let us test binlog_cache_use and binlog_cache_disk_use status vars.
+# Actually this test has nothing to do with innodb per se, it just requires
+# transactional table.
+#
+flush status;
+show status like "binlog_cache_use";
+show status like "binlog_cache_disk_use";
+
+eval create table t1 (a int) engine=$engine_type;
+
+# Now we are going to create transaction which is long enough so its
+# transaction binlog will be flushed to disk...
+let $1=2000;
+disable_query_log;
+begin;
+while ($1)
+{
+ eval insert into t1 values( $1 );
+ dec $1;
+}
+commit;
+enable_query_log;
+show status like "binlog_cache_use";
+show status like "binlog_cache_disk_use";
+
+# Transaction which should not be flushed to disk and so should not
+# increase binlog_cache_disk_use.
+begin;
+delete from t1;
+commit;
+show status like "binlog_cache_use";
+show status like "binlog_cache_disk_use";
+drop table t1;
+
+#
+# Bug #6126: Duplicate columns in keys gives misleading error message
+#
+--error 1060
+eval create table t1 (c char(10), index (c,c)) engine=$engine_type;
+--error 1060
+eval create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=$engine_type;
+--error 1060
+eval create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=$engine_type;
+--error 1060
+eval create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=$engine_type;
+eval create table t1 (c1 char(10), c2 char(10)) engine=$engine_type;
+--error 1060
+alter table t1 add key (c1,c1);
+--error 1060
+alter table t1 add key (c2,c1,c1);
+--error 1060
+alter table t1 add key (c1,c2,c1);
+--error 1060
+alter table t1 add key (c1,c1,c2);
+drop table t1;
+
+#
+# Bug #4082: integer truncation
+#
+
+eval create table t1(a int(1) , b int(1)) engine=$engine_type;
+insert into t1 values ('1111', '3333');
+select distinct concat(a, b) from t1;
+drop table t1;
+
+if ($fulltext_query_unsupported)
+{
+#
+# BUG#7709 test case - Boolean fulltext query against unsupported
+# engines does not fail
+#
+
+eval CREATE TABLE t1 ( a char(10) ) ENGINE=$engine_type;
+--error 1214
+SELECT a FROM t1 WHERE MATCH (a) AGAINST ('test' IN BOOLEAN MODE);
+DROP TABLE t1;
+}
+
+if ($test_foreign_keys)
+{
+#
+# check null values #1
+#
+
+--disable_warnings
+eval CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=$engine_type DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1),(2),(3);
+eval CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
+ CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=$engine_type DEFAULT CHARSET=latin1;
+--enable_warnings
+INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
+SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
+DROP TABLE t2;
+DROP TABLE t1;
+}
+
+#
+# Bug#11816 - Truncate table doesn't work with temporary innodb tables
+# This is not an innodb bug, but we test it using innodb.
+#
+eval create temporary table t1 (a int) engine=$engine_type;
+insert into t1 values (4711);
+truncate t1;
+insert into t1 values (42);
+select * from t1;
+drop table t1;
+# Show that it works with permanent tables too.
+eval create table t1 (a int) engine=$engine_type;
+insert into t1 values (4711);
+truncate t1;
+insert into t1 values (42);
+select * from t1;
+drop table t1;
+
+#
+# Bug #13025 Server crash during filesort
+#
+
+eval create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=$engine_type;
+insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
+select * from t1 order by a,b,c,d;
+explain select * from t1 order by a,b,c,d;
+drop table t1;
+
+#
+# BUG#11039,#13218 Wrong key length in min()
+#
+
+eval create table t1 (a char(1), b char(1), key(a, b)) engine=$engine_type;
+insert into t1 values ('8', '6'), ('4', '7');
+select min(a) from t1;
+select min(b) from t1 where a='8';
+drop table t1;
+
+# End of 4.1 tests
+
+#
+# range optimizer problem
+#
+
+eval create table t1 (x bigint unsigned not null primary key) engine=$engine_type;
+insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
+select * from t1;
+select count(*) from t1 where x>0;
+select count(*) from t1 where x=0;
+select count(*) from t1 where x<0;
+select count(*) from t1 where x < -16;
+select count(*) from t1 where x = -16;
+explain select count(*) from t1 where x > -16;
+select count(*) from t1 where x > -16;
+select * from t1 where x > -16;
+select count(*) from t1 where x = 18446744073709551601;
+drop table t1;
+
+# Please do not remove the following skipped InnoDB specific tests.
+# They make the synchronization with innodb.test easier and give
+# an idea what to test on other storage engines.
+if (0)
+{
+
+# Test for testable InnoDB status variables. This test
+# uses previous ones(pages_created, rows_deleted, ...).
+show status like "Innodb_buffer_pool_pages_total";
+show status like "Innodb_page_size";
+show status like "Innodb_rows_deleted";
+show status like "Innodb_rows_inserted";
+show status like "Innodb_rows_updated";
+
+# Test for row locks InnoDB status variables.
+show status like "Innodb_row_lock_waits";
+show status like "Innodb_row_lock_current_waits";
+show status like "Innodb_row_lock_time";
+show status like "Innodb_row_lock_time_max";
+show status like "Innodb_row_lock_time_avg";
+
+# Test for innodb_sync_spin_loops variable
+show variables like "innodb_sync_spin_loops";
+set global innodb_sync_spin_loops=1000;
+show variables like "innodb_sync_spin_loops";
+set global innodb_sync_spin_loops=0;
+show variables like "innodb_sync_spin_loops";
+set global innodb_sync_spin_loops=20;
+show variables like "innodb_sync_spin_loops";
+
+# Test for innodb_thread_concurrency variable
+show variables like "innodb_thread_concurrency";
+set global innodb_thread_concurrency=1001;
+show variables like "innodb_thread_concurrency";
+set global innodb_thread_concurrency=0;
+show variables like "innodb_thread_concurrency";
+set global innodb_thread_concurrency=16;
+show variables like "innodb_thread_concurrency";
+
+# Test for innodb_concurrency_tickets variable
+show variables like "innodb_concurrency_tickets";
+set global innodb_concurrency_tickets=1000;
+show variables like "innodb_concurrency_tickets";
+set global innodb_concurrency_tickets=0;
+show variables like "innodb_concurrency_tickets";
+set global innodb_concurrency_tickets=500;
+show variables like "innodb_concurrency_tickets";
+
+# Test for innodb_thread_sleep_delay variable
+show variables like "innodb_thread_sleep_delay";
+set global innodb_thread_sleep_delay=100000;
+show variables like "innodb_thread_sleep_delay";
+set global innodb_thread_sleep_delay=0;
+show variables like "innodb_thread_sleep_delay";
+set global innodb_thread_sleep_delay=10000;
+show variables like "innodb_thread_sleep_delay";
+
+}
+
+
+#
+# Test varchar
+#
+
+let $default=`select @@storage_engine`;
+eval set storage_engine=$engine_type;
+source include/varchar.inc;
+
+#
+# Some errors/warnings on create
+#
+
+# Clean up filename -- embedded server reports whole path without .frm,
+# regular server reports relative path with .frm (argh!)
+--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t1.frm t1
+create table t1 (v varchar(65530), key(v));
+drop table t1;
+create table t1 (v varchar(65536));
+show create table t1;
+drop table t1;
+create table t1 (v varchar(65530) character set utf8);
+show create table t1;
+drop table t1;
+
+eval set storage_engine=$default;
+
+# InnoDB specific varchar tests
+eval create table t1 (v varchar(16384)) engine=$engine_type;
+drop table t1;
+
+#
+# BUG#11039 Wrong key length in min()
+#
+
+eval create table t1 (a char(1), b char(1), key(a, b)) engine=$engine_type;
+insert into t1 values ('8', '6'), ('4', '7');
+select min(a) from t1;
+select min(b) from t1 where a='8';
+drop table t1;
+
+#
+# Bug #11080 & #11005 Multi-row REPLACE fails on a duplicate key error
+#
+
+eval CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=$engine_type;
+insert into t1 (b) values (1);
+replace into t1 (b) values (2), (1), (3);
+select * from t1;
+truncate table t1;
+insert into t1 (b) values (1);
+replace into t1 (b) values (2);
+replace into t1 (b) values (1);
+replace into t1 (b) values (3);
+select * from t1;
+drop table t1;
+
+eval create table t1 (rowid int not null auto_increment, val int not null,primary
+key (rowid), unique(val)) engine=$engine_type;
+replace into t1 (val) values ('1'),('2');
+replace into t1 (val) values ('1'),('2');
+--error ER_DUP_ENTRY
+insert into t1 (val) values ('1'),('2');
+select * from t1;
+drop table t1;
+
+if ($no_autoinc_update)
+{
+#
+# Test that update does not change internal auto-increment value
+#
+
+eval create table t1 (a int not null auto_increment primary key, val int) engine=$engine_type;
+insert into t1 (val) values (1);
+update t1 set a=2 where a=1;
+# We should get the following error because InnoDB does not update the counter
+--error ER_DUP_ENTRY
+insert into t1 (val) values (1);
+select * from t1;
+drop table t1;
+}
+
+
+#
+# Bug#10465: DECIMAL, crash on DELETE (InnoDB only)
+#
+
+--disable_warnings
+eval CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=$engine_type;
+--enable_warnings
+INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
+SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
+SELECT GRADE FROM t1 WHERE GRADE= 151;
+DROP TABLE t1;
+
+#
+# Bug #12340 multitable delete deletes only one record
+#
+eval create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=$engine_type;
+eval create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=$engine_type;
+insert into t2 values ('aa','cc');
+insert into t1 values ('aa','bb'),('aa','cc');
+delete t1 from t1,t2 where f1=f3 and f4='cc';
+select * from t1;
+drop table t1,t2;
+
+if ($test_foreign_keys)
+{
+#
+# Test that the slow TRUNCATE implementation resets autoincrement columns
+# (bug #11946)
+#
+
+eval CREATE TABLE t1 (
+id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
+) ENGINE=$engine_type;
+
+eval CREATE TABLE t2 (
+id INTEGER NOT NULL,
+FOREIGN KEY (id) REFERENCES t1 (id)
+) ENGINE=$engine_type;
+
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+TRUNCATE t1;
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+
+# continued from above; test that doing a slow TRUNCATE on a table with 0
+# rows resets autoincrement columns
+DELETE FROM t1;
+TRUNCATE t1;
+INSERT INTO t1 (id) VALUES (NULL);
+SELECT * FROM t1;
+DROP TABLE t2, t1;
+
+# Test that foreign keys in temporary tables are not accepted (bug #12084)
+eval CREATE TABLE t1
+(
+ id INT PRIMARY KEY
+) ENGINE=$engine_type;
+
+--error 1005,1005
+eval CREATE TEMPORARY TABLE t2
+(
+ id INT NOT NULL PRIMARY KEY,
+ b INT,
+ FOREIGN KEY (b) REFERENCES test.t1(id)
+) ENGINE=$engine_type;
+DROP TABLE t1;
+}
+# End of FOREIGN KEY test
+
+# Please do not remove the following skipped InnoDB specific tests.
+# They make the synchronization with innodb.test easier and give
+# an idea what to test on other storage engines.
+if (0)
+{
+
+#
+# Test that index column max sizes are honored (bug #13315)
+#
+
+# prefix index
+eval create table t1 (col1 varchar(2000), index (col1(767)))
+ character set = latin1 engine = $engine_type;
+
+# normal indexes
+eval create table t2 (col1 char(255), index (col1))
+ character set = latin1 engine = $engine_type;
+eval create table t3 (col1 binary(255), index (col1))
+ character set = latin1 engine = $engine_type;
+eval create table t4 (col1 varchar(767), index (col1))
+ character set = latin1 engine = $engine_type;
+eval create table t5 (col1 varchar(767) primary key)
+ character set = latin1 engine = $engine_type;
+eval create table t6 (col1 varbinary(767) primary key)
+ character set = latin1 engine = $engine_type;
+eval create table t7 (col1 text, index(col1(767)))
+ character set = latin1 engine = $engine_type;
+eval create table t8 (col1 blob, index(col1(767)))
+ character set = latin1 engine = $engine_type;
+
+
+# multi-column indexes are allowed to be longer
+eval create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
+ character set = latin1 engine = $engine_type;
+
+show create table t9;
+
+drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
+
+# these should have their index length trimmed
+eval create table t1 (col1 varchar(768), index(col1))
+ character set = latin1 engine = $engine_type;
+eval create table t2 (col1 varbinary(768), index(col1))
+ character set = latin1 engine = $engine_type;
+eval create table t3 (col1 text, index(col1(768)))
+ character set = latin1 engine = $engine_type;
+eval create table t4 (col1 blob, index(col1(768)))
+ character set = latin1 engine = $engine_type;
+
+show create table t1;
+
+drop table t1, t2, t3, t4;
+
+}
+# End of skipped test
+
+# Please do not remove the following skipped InnoDB specific tests.
+# They make the synchronization with innodb.test easier and give
+# an idea what to test on other storage engines.
+if (0)
+{
+
+# these should be refused
+--error 1071
+eval create table t1 (col1 varchar(768) primary key)
+ character set = latin1 engine = $engine_type;
+--error 1071
+eval create table t2 (col1 varbinary(768) primary key)
+ character set = latin1 engine = $engine_type;
+--error 1071
+eval create table t3 (col1 text, primary key(col1(768)))
+ character set = latin1 engine = $engine_type;
+--error 1071
+eval create table t4 (col1 blob, primary key(col1(768)))
+ character set = latin1 engine = $engine_type;
+
+}
+
+if ($test_foreign_keys)
+{
+#
+# Test improved foreign key error messages (bug #3443)
+#
+
+eval CREATE TABLE t1
+(
+ id INT PRIMARY KEY
+) ENGINE=$engine_type;
+
+eval CREATE TABLE t2
+(
+ v INT,
+ CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
+) ENGINE=$engine_type;
+
+--error 1452
+INSERT INTO t2 VALUES(2);
+
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1);
+
+--error 1451
+DELETE FROM t1 WHERE id = 1;
+
+--error 1217
+DROP TABLE t1;
+
+SET FOREIGN_KEY_CHECKS=0;
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS=1;
+
+--error 1452
+INSERT INTO t2 VALUES(3);
+
+DROP TABLE t2;
+}
+# End of FOREIGN tests
+
+if ($test_transactions)
+{
+#
+# Test that checksum table uses a consistent read Bug #12669
+#
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null) engine=$engine_type DEFAULT CHARSET=latin1;
+insert into t1 values (1),(2);
+set autocommit=0;
+checksum table t1;
+connection b;
+insert into t1 values(3);
+connection a;
+#
+# Here checksum should not see insert
+#
+checksum table t1;
+connection a;
+commit;
+checksum table t1;
+commit;
+drop table t1;
+#
+# autocommit = 1
+#
+connection a;
+eval create table t1(a int not null) engine=$engine_type DEFAULT CHARSET=latin1;
+insert into t1 values (1),(2);
+set autocommit=1;
+checksum table t1;
+connection b;
+set autocommit=1;
+insert into t1 values(3);
+connection a;
+#
+# Here checksum sees insert
+#
+checksum table t1;
+drop table t1;
+
+connection default;
+disconnect a;
+disconnect b;
+}
+
+# tests for bugs #9802 and #13778
+
+if ($test_foreign_keys)
+{
+# test that FKs between invalid types are not accepted
+
+set foreign_key_checks=0;
+eval create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = $engine_type;
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+-- error 1005
+eval create table t1(a char(10) primary key, b varchar(20)) engine = $engine_type;
+set foreign_key_checks=1;
+drop table t2;
+
+# test that FKs between different charsets are not accepted in CREATE even
+# when f_k_c is 0
+
+set foreign_key_checks=0;
+eval create table t1(a varchar(10) primary key) engine = $engine_type DEFAULT CHARSET=latin1;
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+-- error 1005
+eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type DEFAULT CHARSET=utf8;
+set foreign_key_checks=1;
+drop table t1;
+
+# test that invalid datatype conversions with ALTER are not allowed
+
+set foreign_key_checks=0;
+eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type;
+eval create table t1(a varchar(10) primary key) engine = $engine_type;
+-- error 1025,1025
+alter table t1 modify column a int;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that charset conversions with ALTER are allowed when f_k_c is 0
+
+set foreign_key_checks=0;
+eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type DEFAULT CHARSET=latin1;
+eval create table t1(a varchar(10) primary key) engine = $engine_type DEFAULT CHARSET=latin1;
+alter table t1 convert to character set utf8;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that RENAME does not allow invalid charsets when f_k_c is 0
+
+set foreign_key_checks=0;
+eval create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = $engine_type DEFAULT CHARSET=latin1;
+eval create table t3(a varchar(10) primary key) engine = $engine_type DEFAULT CHARSET=utf8;
+--replace_result $MYSQLTEST_VARDIR . master-data/ ''
+-- error 1025
+rename table t3 to t1;
+set foreign_key_checks=1;
+drop table t2,t3;
+
+# test that foreign key errors are reported correctly (Bug #15550)
+
+eval create table t1(a int primary key) row_format=redundant engine=$engine_type;
+eval create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=$engine_type;
+eval create table t3(a int primary key) row_format=compact engine=$engine_type;
+eval create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=$engine_type;
+
+insert into t1 values(1);
+insert into t3 values(1);
+-- error 1452
+insert into t2 values(2);
+-- error 1452
+insert into t4 values(2);
+insert into t2 values(1);
+insert into t4 values(1);
+-- error 1451
+update t1 set a=2;
+-- error 1452
+update t2 set a=2;
+-- error 1451
+update t3 set a=2;
+-- error 1452
+update t4 set a=2;
+-- error 1451
+truncate t1;
+-- error 1451
+truncate t3;
+truncate t2;
+truncate t4;
+truncate t1;
+truncate t3;
+
+drop table t4,t3,t2,t1;
+}
+# End of FOREIGN KEY tests
+
+
+# Please do not remove the following skipped InnoDB specific tests.
+# They make the synchronization with innodb.test easier and give
+# an idea what to test on other storage engines.
+if (0)
+{
+
+#
+# Test that we can create a large (>1K) key
+#
+eval create table t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ key (a,b,c,d)) engine=$engine_type;
+drop table t1;
+--error ER_TOO_LONG_KEY
+eval create table t1 (a varchar(255) character set utf8,
+ b varchar(255) character set utf8,
+ c varchar(255) character set utf8,
+ d varchar(255) character set utf8,
+ e varchar(255) character set utf8,
+ key (a,b,c,d,e)) engine=$engine_type;
+
+
+# test the padding of BINARY types and collations (Bug #14189)
+
+eval create table t1 (s1 varbinary(2),primary key (s1)) engine=$engine_type;
+eval create table t2 (s1 binary(2),primary key (s1)) engine=$engine_type;
+eval create table t3 (s1 varchar(2) binary,primary key (s1)) engine=$engine_type;
+eval create table t4 (s1 char(2) binary,primary key (s1)) engine=$engine_type;
+
+insert into t1 values (0x41),(0x4120),(0x4100);
+-- error ER_DUP_ENTRY
+insert into t2 values (0x41),(0x4120),(0x4100);
+insert into t2 values (0x41),(0x4120);
+-- error ER_DUP_ENTRY
+insert into t3 values (0x41),(0x4120),(0x4100);
+insert into t3 values (0x41),(0x4100);
+-- error ER_DUP_ENTRY
+insert into t4 values (0x41),(0x4120),(0x4100);
+insert into t4 values (0x41),(0x4100);
+select hex(s1) from t1;
+select hex(s1) from t2;
+select hex(s1) from t3;
+select hex(s1) from t4;
+drop table t1,t2,t3,t4;
+}
+
+if (test_foreign_keys)
+{
+eval create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=$engine_type;
+eval create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=$engine_type;
+
+insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
+-- error 1452
+insert into t2 values(0x42);
+insert into t2 values(0x41);
+select hex(s1) from t2;
+update t1 set s1=0x123456 where a=2;
+select hex(s1) from t2;
+-- error 1451
+update t1 set s1=0x12 where a=1;
+-- error 1451
+update t1 set s1=0x12345678 where a=1;
+-- error 1451
+update t1 set s1=0x123457 where a=1;
+update t1 set s1=0x1220 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x1200 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x4200 where a=1;
+select hex(s1) from t2;
+-- error 1451
+delete from t1 where a=1;
+delete from t1 where a=2;
+update t2 set s1=0x4120;
+-- error 1451
+delete from t1;
+delete from t1 where a!=3;
+select a,hex(s1) from t1;
+select hex(s1) from t2;
+
+drop table t2,t1;
+
+eval create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=$engine_type;
+eval create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=$engine_type;
+
+insert into t1 values(1,0x4100),(2,0x41);
+insert into t2 values(0x41);
+select hex(s1) from t2;
+update t1 set s1=0x1234 where a=1;
+select hex(s1) from t2;
+update t1 set s1=0x12 where a=2;
+select hex(s1) from t2;
+delete from t1 where a=1;
+-- error 1451
+delete from t1 where a=2;
+select a,hex(s1) from t1;
+select hex(s1) from t2;
+
+drop table t2,t1;
+}
+# End FOREIGN KEY tests
+
+if ($test_foreign_keys)
+{
+# Ensure that <tablename>_ibfk_0 is not mistreated as a
+# generated foreign key identifier. (Bug #16387)
+
+eval CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=$engine_type;
+eval CREATE TABLE t2(a INT) ENGINE=$engine_type;
+ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
+ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
+ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
+SHOW CREATE TABLE t2;
+DROP TABLE t2,t1;
+}
+
+#
+# Test case for bug #16229: MySQL/InnoDB uses full explicit table locks in trigger processing
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+insert into t1(a) values (1),(2),(3);
+commit;
+connection b;
+set autocommit = 0;
+update t1 set b = 5 where a = 2;
+connection a;
+delimiter |;
+create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
+delimiter ;|
+set autocommit = 0;
+connection a;
+insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
+(11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
+(12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
+(13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
+(14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
+connection b;
+commit;
+connection a;
+commit;
+drop trigger t1t;
+drop table t1;
+disconnect a;
+disconnect b;
+#
+# Another trigger test
+#
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+eval create table t2(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+eval create table t3(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+eval create table t4(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+eval create table t5(a int not null, b int, c int, d int, primary key(a)) engine=$engine_type;
+insert into t1(a) values (1),(2),(3);
+insert into t2(a) values (1),(2),(3);
+insert into t3(a) values (1),(2),(3);
+insert into t4(a) values (1),(2),(3);
+insert into t3(a) values (5),(7),(8);
+insert into t4(a) values (5),(7),(8);
+insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
+
+delimiter |;
+create trigger t1t before insert on t1 for each row begin
+ INSERT INTO t2 SET a = NEW.a;
+end |
+
+create trigger t2t before insert on t2 for each row begin
+ DELETE FROM t3 WHERE a = NEW.a;
+end |
+
+create trigger t3t before delete on t3 for each row begin
+ UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
+end |
+
+create trigger t4t before update on t4 for each row begin
+ UPDATE t5 SET b = b + 1 where a = NEW.a;
+end |
+delimiter ;|
+commit;
+set autocommit = 0;
+update t1 set b = b + 5 where a = 1;
+update t2 set b = b + 5 where a = 1;
+update t3 set b = b + 5 where a = 1;
+update t4 set b = b + 5 where a = 1;
+insert into t5(a) values(20);
+connection b;
+set autocommit = 0;
+insert into t1(a) values(7);
+insert into t2(a) values(8);
+delete from t2 where a = 3;
+update t4 set b = b + 1 where a = 3;
+commit;
+drop trigger t1t;
+drop trigger t2t;
+drop trigger t3t;
+drop trigger t4t;
+drop table t1, t2, t3, t4, t5;
+connection default;
+disconnect a;
+disconnect b;
+
+if ($test_foreign_keys)
+{
+#
+# Test that cascading updates leading to duplicate keys give the correct
+# error message (bug #9680)
+#
+
+eval CREATE TABLE t1 (
+ field1 varchar(8) NOT NULL DEFAULT '',
+ field2 varchar(8) NOT NULL DEFAULT '',
+ PRIMARY KEY (field1, field2)
+) ENGINE=$engine_type;
+
+eval CREATE TABLE t2 (
+ field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
+ FOREIGN KEY (field1) REFERENCES t1 (field1)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=$engine_type;
+
+INSERT INTO t1 VALUES ('old', 'somevalu');
+INSERT INTO t1 VALUES ('other', 'anyvalue');
+
+INSERT INTO t2 VALUES ('old');
+INSERT INTO t2 VALUES ('other');
+
+--error ER_FOREIGN_DUPLICATE_KEY
+UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
+
+DROP TABLE t2;
+DROP TABLE t1;
+
+#
+# Bug#18477 - MySQL/InnoDB Ignoring Foreign Keys in ALTER TABLE
+#
+eval create table t1 (
+ c1 bigint not null,
+ c2 bigint not null,
+ primary key (c1),
+ unique key (c2)
+) engine=$engine_type;
+#
+eval create table t2 (
+ c1 bigint not null,
+ primary key (c1)
+) engine=$engine_type;
+#
+alter table t1 add constraint c2_fk foreign key (c2)
+ references t2(c1) on delete cascade;
+show create table t1;
+#
+alter table t1 drop foreign key c2_fk;
+show create table t1;
+#
+drop table t1, t2;
+}
+# End FOREIGN KEY test
+
+#
+# Bug #14360: problem with intervals
+#
+
+eval create table t1(a date) engine=$engine_type;
+eval create table t2(a date, key(a)) engine=$engine_type;
+insert into t1 values('2005-10-01');
+insert into t2 values('2005-10-01');
+select * from t1, t2
+ where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
+drop table t1, t2;
+
+eval create table t1 (id int not null, f_id int not null, f int not null,
+primary key(f_id, id)) engine=$engine_type;
+eval create table t2 (id int not null,s_id int not null,s varchar(200),
+primary key(id)) engine=$engine_type;
+INSERT INTO t1 VALUES (8, 1, 3);
+INSERT INTO t1 VALUES (1, 2, 1);
+INSERT INTO t2 VALUES (1, 0, '');
+INSERT INTO t2 VALUES (8, 1, '');
+commit;
+DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
+WHERE mm.id IS NULL;
+select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
+where mm.id is null lock in share mode;
+drop table t1,t2;
+
+#
+# Test case where X-locks on unused rows should be released in a
+# update (because READ COMMITTED isolation level)
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine=$engine_type;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
+commit;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+update t1 set b = 5 where b = 1;
+connection b;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+#
+# X-lock to record (7,3) should be released in a update
+#
+select * from t1 where a = 7 and b = 3 for update;
+connection a;
+commit;
+connection b;
+commit;
+drop table t1;
+connection default;
+disconnect a;
+disconnect b;
+
+if ($test_transactions)
+{
+#
+# Test case where no locks should be released (because we are not
+# using READ COMMITTED isolation level)
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine=$engine_type;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
+commit;
+set autocommit = 0;
+select * from t1 lock in share mode;
+update t1 set b = 5 where b = 1;
+connection b;
+set autocommit = 0;
+#
+# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
+#
+--error 1205
+select * from t1 where a = 2 and b = 2 for update;
+#
+# X-lock to record (1,1),(3,1),(5,1) should not be released in a update
+#
+--error 1205
+connection a;
+commit;
+connection b;
+commit;
+connection default;
+disconnect a;
+disconnect b;
+drop table t1;
+
+#
+# Consistent read should be used in following selects
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine=$engine_type;
+insert into t1 values (1,2),(5,3),(4,2);
+eval create table t2(d int not null, e int, primary key(d)) engine=$engine_type;
+insert into t2 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+insert into t1 select * from t2;
+update t1 set b = (select e from t2 where a = d);
+eval create table t3(d int not null, e int, primary key(d)) engine=$engine_type
+select * from t2;
+commit;
+connection a;
+commit;
+connection default;
+disconnect a;
+disconnect b;
+drop table t1, t2, t3;
+
+#
+# Consistent read should not be used if
+#
+# (a) isolation level is serializable OR
+# (b) select ... lock in share mode OR
+# (c) select ... for update
+#
+# in following queries:
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (b,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (c,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (d,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (e,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (f,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (g,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (h,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (i,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (j,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connection a;
+create table t1(a int not null, b int, primary key(a));
+insert into t1 values (1,2),(5,3),(4,2);
+create table t2(a int not null, b int, primary key(a));
+insert into t2 values (8,6),(12,1),(3,1);
+create table t3(d int not null, b int, primary key(d));
+insert into t3 values (8,6),(12,1),(3,1);
+create table t5(a int not null, b int, primary key(a));
+insert into t5 values (1,2),(5,3),(4,2);
+create table t6(d int not null, e int, primary key(d));
+insert into t6 values (8,6),(12,1),(3,1);
+create table t8(a int not null, b int, primary key(a));
+insert into t8 values (1,2),(5,3),(4,2);
+create table t9(d int not null, e int, primary key(d));
+insert into t9 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+insert into t1 select * from t2;
+connection c;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+update t3 set b = (select b from t2 where a = d);
+connection d;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+create table t4(a int not null, b int, primary key(a)) select * from t2;
+connection e;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+insert into t5 (select * from t2 lock in share mode);
+connection f;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+update t6 set e = (select b from t2 where a = d lock in share mode);
+connection g;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+create table t7(a int not null, b int, primary key(a)) select * from t2 lock in share mode;
+connection h;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+insert into t8 (select * from t2 for update);
+connection i;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+update t9 set e = (select b from t2 where a = d for update);
+connection j;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
+--send
+create table t10(a int not null, b int, primary key(a)) select * from t2 for update;
+
+connection b;
+--error 1205
+reap;
+
+connection c;
+--error 1205
+reap;
+
+connection d;
+--error 1205
+reap;
+
+connection e;
+--error 1205
+reap;
+
+connection f;
+--error 1205
+reap;
+
+connection g;
+--error 1205
+reap;
+
+connection h;
+--error 1205
+reap;
+
+connection i;
+--error 1205
+reap;
+
+connection j;
+--error 1205
+reap;
+
+connection a;
+commit;
+
+connection default;
+disconnect a;
+disconnect b;
+disconnect c;
+disconnect d;
+disconnect e;
+disconnect f;
+disconnect g;
+disconnect h;
+disconnect i;
+disconnect j;
+drop table t1, t2, t3, t5, t6, t8, t9;
+}
+# End transactional tests
+
+if (test_foreign_keys)
+{
+# bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
+--error 1005
+eval CREATE TABLE t1 (DB_ROW_ID int) engine=$engine_type;
+
+#
+# Bug #17152: Wrong result with BINARY comparison on aliased column
+#
+
+eval CREATE TABLE t1 (
+ a BIGINT(20) NOT NULL,
+ PRIMARY KEY (a)
+ ) ENGINE=$engine_type DEFAULT CHARSET=UTF8;
+
+eval CREATE TABLE t2 (
+ a BIGINT(20) NOT NULL,
+ b VARCHAR(128) NOT NULL,
+ c TEXT NOT NULL,
+ PRIMARY KEY (a,b),
+ KEY idx_t2_b_c (b,c(200)),
+ CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
+ ON DELETE CASCADE
+ ) ENGINE=$engine_type DEFAULT CHARSET=UTF8;
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1, 'bar', 'vbar');
+INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
+INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
+INSERT INTO t2 VALUES (1, 'customer_over', '1');
+
+SELECT * FROM t2 WHERE b = 'customer_over';
+SELECT * FROM t2 WHERE BINARY b = 'customer_over';
+SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
+/* Bang: Empty result set, above was expected: */
+SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
+SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
+
+drop table t2, t1;
+}
+
+if ($no_spatial_key)
+{
+#
+# Bug #15680 (SPATIAL key in innodb)
+#
+--error ER_TABLE_CANT_HANDLE_SPKEYS
+eval create table t1 (g geometry not null, spatial gk(g)) engine=$engine_type;
+}
+
+#
+# Test optimize on table with open transaction
+#
+
+eval CREATE TABLE t1 ( a int ) ENGINE=$engine_type;
+BEGIN;
+INSERT INTO t1 VALUES (1);
+OPTIMIZE TABLE t1;
+DROP TABLE t1;
+
+#######################################################################
+# #
+# This is derivate of t/innodb.test and has to be maintained by #
+# MySQL guys only. #
+# #
+# Please synchronize this file from time to time with t/innodb.test. #
+# Please, DO NOT create a toplevel testcase innodb-mix2.test, because #
+# innodb.test does already these tests. #
+# #
+#######################################################################
diff --git a/mysql-test/include/mix2_ucs2.inc b/mysql-test/include/mix2_ucs2.inc
new file mode 100644
index 00000000000..418bc7aad74
--- /dev/null
+++ b/mysql-test/include/mix2_ucs2.inc
@@ -0,0 +1,228 @@
+#
+# Tests from mix2.inc which require ucs2 character sets should go here
+#
+
+#
+# BUG 14056 Column prefix index on UTF-8 primary key column causes: Can't find record..
+#
+
+eval create table t1 (
+ a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = $engine_type;
+eval create table t2 (
+ a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = $engine_type;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+eval create table t1 (
+ a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = $engine_type;
+eval create table t2 (
+ a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = $engine_type;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+
+
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+eval create table t1 (
+ a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = $engine_type;
+eval create table t2 (
+ a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = $engine_type;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
+insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
+insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+
+eval create table t1 (
+ a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
+) character set utf8 engine = $engine_type;
+eval create table t2 (
+ a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
+) character set ucs2 engine = $engine_type;
+insert into t1 values (1,'abcdefg','abcdefg','one');
+insert into t1 values (2,'ijkilmn','ijkilmn','two');
+insert into t1 values (3,'qrstuvw','qrstuvw','three');
+insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
+insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
+insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
+insert into t2 values (1,'abcdefg','abcdefg','one');
+insert into t2 values (2,'ijkilmn','ijkilmn','two');
+insert into t2 values (3,'qrstuvw','qrstuvw','three');
+insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
+insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
+insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
+insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
+insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
+insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
+insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
+update t1 set filler = 'boo' where a = 1;
+update t2 set filler ='email' where a = 4;
+select a,hex(b),hex(c),filler from t1 order by filler;
+select a,hex(b),hex(c),filler from t2 order by filler;
+drop table t1;
+drop table t2;
+commit;
+
+#
+# Test cases for bug #15308 Problem of Order with Enum Column in Primary Key
+#
+eval CREATE TABLE t1 (
+ ind enum('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=utf8;
+eval CREATE TABLE t2 (
+ ind enum('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=ucs2;
+
+INSERT INTO t1 VALUES ('1', ''),('2', '');
+INSERT INTO t2 VALUES ('1', ''),('2', '');
+SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
+SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
+drop table t1,t2;
+
+eval CREATE TABLE t1 (
+ ind set('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=utf8;
+eval CREATE TABLE t2 (
+ ind set('0','1','2') NOT NULL default '0',
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=ucs2;
+
+INSERT INTO t1 VALUES ('1', ''),('2', '');
+INSERT INTO t2 VALUES ('1', ''),('2', '');
+SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
+SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
+drop table t1,t2;
+
+eval CREATE TABLE t1 (
+ ind bit not null,
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=utf8;
+eval CREATE TABLE t2 (
+ ind bit not null,
+ string1 varchar(250) NOT NULL,
+ PRIMARY KEY (ind)
+) ENGINE=$engine_type DEFAULT CHARSET=ucs2;
+insert into t1 values(0,''),(1,'');
+insert into t2 values(0,''),(1,'');
+select hex(ind),hex(string1) from t1 order by string1;
+select hex(ind),hex(string1) from t2 order by string1;
+drop table t1,t2;
+
+# tests for bug #14056 Column prefix index on UTF-8 primary key column causes 'Can't find record..'
+
+eval create table t2 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set utf8 engine = $engine_type;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+eval create table t2 (
+ a int, b char(10), filler char(10), primary key(a, b(2))
+) character set ucs2 engine = $engine_type;
+
+insert into t2 values (1,'abcdefg','one');
+insert into t2 values (2,'ijkilmn','two');
+insert into t2 values (3, 'qrstuvw','three');
+update t2 set a=5, filler='booo' where a=1;
+drop table t2;
+
+eval create table t1(a int not null, b char(110),primary key(a,b(100))) engine=$engine_type default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+eval create table t1(a int not null, b text(110),primary key(a,b(100))) engine=$engine_type default charset=utf8;
+insert into t1 values(1,'abcdefg'),(2,'defghijk');
+insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
+insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
+select a,hex(b) from t1 order by b;
+update t1 set b = 'three' where a = 6;
+drop table t1;
+
diff --git a/mysql-test/include/mtr_check.sql b/mysql-test/include/mtr_check.sql
new file mode 100644
index 00000000000..12cb2c870a2
--- /dev/null
+++ b/mysql-test/include/mtr_check.sql
@@ -0,0 +1,59 @@
+delimiter ||;
+
+use mtr||
+
+--
+-- Procedure used to check if server has been properly
+-- restored after testcase has been run
+--
+CREATE DEFINER=root@localhost PROCEDURE check_testcase()
+BEGIN
+
+ -- Dump all global variables except those
+ -- that are supposed to change
+ SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+ WHERE variable_name != 'timestamp' ORDER BY VARIABLE_NAME;
+
+ -- Dump all databases, there should be none
+ -- except those that was created during bootstrap
+ SELECT * FROM INFORMATION_SCHEMA.SCHEMATA;
+
+ -- The test database should not contain any tables
+ SELECT table_name AS tables_in_test FROM INFORMATION_SCHEMA.TABLES
+ WHERE table_schema='test';
+
+ -- Show "mysql" database, tables and columns
+ SELECT CONCAT(table_schema, '.', table_name) AS tables_in_mysql
+ FROM INFORMATION_SCHEMA.TABLES
+ WHERE table_schema='mysql' AND table_name != 'ndb_apply_status'
+ ORDER BY tables_in_mysql;
+ SELECT CONCAT(table_schema, '.', table_name) AS columns_in_mysql,
+ column_name, ordinal_position, column_default, is_nullable,
+ data_type, character_maximum_length, character_octet_length,
+ numeric_precision, numeric_scale, character_set_name,
+ collation_name, column_type, column_key, extra, column_comment
+ FROM INFORMATION_SCHEMA.COLUMNS
+ WHERE table_schema='mysql' AND table_name != 'ndb_apply_status'
+ ORDER BY columns_in_mysql;
+
+ -- Checksum system tables to make sure they have been properly
+ -- restored after test
+ checksum table
+ mysql.columns_priv,
+ mysql.db,
+ mysql.func,
+ mysql.help_category,
+ mysql.help_keyword,
+ mysql.help_relation,
+ mysql.host,
+ mysql.proc,
+ mysql.procs_priv,
+ mysql.tables_priv,
+ mysql.time_zone,
+ mysql.time_zone_leap_second,
+ mysql.time_zone_name,
+ mysql.time_zone_transition,
+ mysql.time_zone_transition_type,
+ mysql.user;
+
+END||
diff --git a/mysql-test/include/mtr_warnings.sql b/mysql-test/include/mtr_warnings.sql
new file mode 100644
index 00000000000..73287900f3c
--- /dev/null
+++ b/mysql-test/include/mtr_warnings.sql
@@ -0,0 +1,238 @@
+delimiter ||;
+
+use mtr||
+
+--
+-- Create table where testcases can insert patterns to
+-- be suppressed
+--
+CREATE TABLE test_suppressions (
+ pattern VARCHAR(255)
+) ENGINE=MyISAM||
+
+
+--
+-- Declare a trigger that makes sure
+-- no invalid patterns can be inserted
+-- into test_suppressions
+--
+/*!50002
+CREATE DEFINER=root@localhost TRIGGER ts_insert
+BEFORE INSERT ON test_suppressions
+FOR EACH ROW BEGIN
+ DECLARE dummy INT;
+ SELECT "" REGEXP NEW.pattern INTO dummy;
+END
+*/||
+
+
+--
+-- Load table with patterns that will be suppressed globally(always)
+--
+CREATE TABLE global_suppressions (
+ pattern VARCHAR(255)
+) ENGINE=MyISAM||
+
+
+-- Declare a trigger that makes sure
+-- no invalid patterns can be inserted
+-- into global_suppressions
+--
+/*!50002
+CREATE DEFINER=root@localhost TRIGGER gs_insert
+BEFORE INSERT ON global_suppressions
+FOR EACH ROW BEGIN
+ DECLARE dummy INT;
+ SELECT "" REGEXP NEW.pattern INTO dummy;
+END
+*/||
+
+
+
+--
+-- Insert patterns that should always be suppressed
+--
+INSERT INTO global_suppressions VALUES
+ ("'SELECT UNIX_TIMESTAMP\\(\\)' failed on master"),
+ ("Aborted connection"),
+ ("Client requested master to start replication from impossible position"),
+ ("Could not find first log file name in binary log"),
+ ("Enabling keys got errno"),
+ ("Error reading master configuration"),
+ ("Error reading packet"),
+ ("Event Scheduler"),
+ ("Failed to open log"),
+ ("Failed to open the existing master info file"),
+ ("Forcing shutdown of [0-9]* plugins"),
+ ("Forcing close of thread"),
+
+ /*
+ Due to timing issues, it might be that this warning
+ is printed when the server shuts down and the
+ computer is loaded.
+ */
+
+ ("Got error [0-9]* when reading table"),
+ ("Incorrect definition of table"),
+ ("Incorrect information in file"),
+ ("InnoDB: Warning: we did not need to do crash recovery"),
+ ("Invalid \\(old\\?\\) table or database name"),
+ ("Lock wait timeout exceeded"),
+ ("Log entry on master is longer than max_allowed_packet"),
+ ("unknown option '--loose-"),
+ ("unknown variable 'loose-"),
+ ("You have forced lower_case_table_names to 0 through a command-line option"),
+ ("Setting lower_case_table_names=2"),
+ ("NDB Binlog:"),
+ ("NDB: failed to setup table"),
+ ("NDB: only row based binary logging"),
+ ("Neither --relay-log nor --relay-log-index were used"),
+ ("Query partially completed"),
+ ("Slave I.O thread aborted while waiting for relay log"),
+ ("Slave SQL thread is stopped because UNTIL condition"),
+ ("Slave SQL thread retried transaction"),
+ ("Slave \\(additional info\\)"),
+ ("Slave: .*Duplicate column name"),
+ ("Slave: .*master may suffer from"),
+ ("Slave: According to the master's version"),
+ ("Slave: Column [0-9]* type mismatch"),
+ ("Slave: Error .* doesn't exist"),
+ ("Slave: Error .*Unknown table"),
+ ("Slave: Error in Write_rows event: "),
+ ("Slave: Field .* of table .* has no default value"),
+ ("Slave: Field .* doesn't have a default value"),
+ ("Slave: Query caused different errors on master and slave"),
+ ("Slave: Table .* doesn't exist"),
+ ("Slave: Table width mismatch"),
+ ("Slave: The incident LOST_EVENTS occured on the master"),
+ ("Slave: Unknown error.* 1105"),
+ ("Slave: Can't drop database.* database doesn't exist"),
+ ("Slave SQL:.*(Error_code: \[\[:digit:\]\]+|Query:.*)"),
+ ("Sort aborted"),
+ ("Time-out in NDB"),
+ ("Warning:\s+One can only use the --user.*root"),
+ ("Warning:\s+Setting lower_case_table_names=2"),
+ ("Warning:\s+Table:.* on (delete|rename)"),
+ ("You have an error in your SQL syntax"),
+ ("deprecated"),
+ ("description of time zone"),
+ ("equal MySQL server ids"),
+ ("error .*connecting to master"),
+ ("error reading log entry"),
+ ("lower_case_table_names is set"),
+ ("skip-name-resolve mode"),
+ ("slave SQL thread aborted"),
+ ("Slave: .*Duplicate entry"),
+
+ /*
+ Special case, made as specific as possible, for:
+ Bug #28436: Incorrect position in SHOW BINLOG EVENTS causes
+ server coredump
+ */
+
+ ("Error in Log_event::read_log_event\\\(\\\): 'Sanity check failed', data_len: 258, event_type: 49"),
+
+ ("Statement is not safe to log in statement format"),
+
+ /* test case for Bug#bug29807 copies a stray frm into database */
+ ("InnoDB: Error: table `test`.`bug29807` does not exist in the InnoDB internal"),
+ ("Cannot find or open table test\/bug29807 from"),
+
+ /* innodb foreign key tests that fail in ALTER or RENAME produce this */
+ ("InnoDB: Error: in ALTER TABLE `test`.`t[12]`"),
+ ("InnoDB: Error: in RENAME TABLE table `test`.`t1`"),
+ ("InnoDB: Error: table `test`.`t[12]` does not exist in the InnoDB internal"),
+
+ /* Test case for Bug#14233 produces the following warnings: */
+ ("Stored routine 'test'.'bug14233_1': invalid value in column mysql.proc"),
+ ("Stored routine 'test'.'bug14233_2': invalid value in column mysql.proc"),
+ ("Stored routine 'test'.'bug14233_3': invalid value in column mysql.proc"),
+
+ /*
+ BUG#32080 - Excessive warnings on Solaris: setrlimit could not
+ change the size of core files
+ */
+ ("setrlimit could not change the size of core files to 'infinity'"),
+
+ /*
+ rpl_extrColmaster_*.test, the slave thread produces warnings
+ when it get updates to a table that has more columns on the
+ master
+ */
+ ("Slave: Unknown column 'c7' in 't15' Error_code: 1054"),
+ ("Slave: Can't DROP 'c7'.* 1091"),
+ ("Slave: Key column 'c6'.* 1072"),
+
+ /* Test case for Bug#31590 in order_by.test produces the following error */
+ ("Out of sort memory; increase server sort buffer size"),
+
+ /* Special case for Bug #26402 in show_check.test
+ - Question marks are not valid file name parts on Windows. Ignore
+ this error message.
+ */
+ ("Can't find file: '.\\\\test\\\\\\?{8}.frm'"),
+
+ ("THE_LAST_SUPPRESSION")||
+
+
+--
+-- Procedure that uses the above created tables to check
+-- the servers error log for warnings
+--
+CREATE DEFINER=root@localhost PROCEDURE check_warnings(OUT result INT)
+BEGIN
+ DECLARE `pos` bigint unsigned;
+
+ -- Don't write these queries to binlog
+ SET SQL_LOG_BIN=0;
+
+ --
+ -- Remove mark from lines that are suppressed by global suppressions
+ --
+ UPDATE error_log el, global_suppressions gs
+ SET suspicious=0
+ WHERE el.suspicious=1 AND el.line REGEXP gs.pattern;
+
+ --
+ -- Remove mark from lines that are suppressed by test specific suppressions
+ --
+ UPDATE error_log el, test_suppressions ts
+ SET suspicious=0
+ WHERE el.suspicious=1 AND el.line REGEXP ts.pattern;
+
+ --
+ -- Get the number of marked lines and return result
+ --
+ SELECT COUNT(*) INTO @num_warnings FROM error_log
+ WHERE suspicious=1;
+
+ IF @num_warnings > 0 THEN
+ SELECT file_name, line
+ FROM error_log WHERE suspicious=1;
+ --SELECT * FROM test_suppressions;
+ -- Return 2 -> check failed
+ SELECT 2 INTO result;
+ ELSE
+ -- Return 0 -> OK
+ SELECT 0 INTO RESULT;
+ END IF;
+
+ -- Cleanup for next test
+ TRUNCATE test_suppressions;
+ DROP TABLE error_log;
+
+END||
+
+--
+-- Declare a procedure testcases can use to insert test
+-- specific suppressions
+--
+/*!50001
+CREATE DEFINER=root@localhost
+PROCEDURE add_suppression(pattern VARCHAR(255))
+BEGIN
+ INSERT INTO test_suppressions (pattern) VALUES (pattern);
+END
+*/||
+
+
diff --git a/mysql-test/include/mysqlbinlog_row_engine.inc b/mysql-test/include/mysqlbinlog_row_engine.inc
new file mode 100644
index 00000000000..95440ab04a0
--- /dev/null
+++ b/mysql-test/include/mysqlbinlog_row_engine.inc
@@ -0,0 +1,1922 @@
+# mysqlbinlog_row.test
+#
+# Show that mysqlbinlog displays human readable comments to
+# row-based log events.
+#
+# Procedure:
+# Create a table that represents all-known types in 5.1.
+# Write rows that contain the mins, maxes, and NULL for each type.
+# Write a random or "problematic" value (i.e. one that might require
+# escaping if it's represented as a string-y type) for each type.
+# Update each of these rows.
+# Delete each of these rows.
+# Inspect the binlog.
+#
+# Bug#31455 - mysqlbinlog don't print user readable info about RBR events
+#
+
+--source include/have_log_bin.inc
+
+SET NAMES 'utf8';
+#SHOW VARIABLES LIKE 'character_set%';
+
+
+--echo #
+--echo # Preparatory cleanup.
+--echo #
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2, t3;
+--enable_warnings
+
+--echo #
+--echo # We need a fixed timestamp to avoid varying results.
+--echo #
+SET timestamp=1000000000;
+
+--echo #
+--echo # ===================================================
+--echo # Test #1 - Insert/update/delete with all data types.
+--echo # ===================================================
+--echo #
+--echo # Delete all existing binary logs.
+--echo #
+RESET MASTER;
+
+--echo #
+--echo # Create a test table with all data types.
+--echo #
+eval CREATE TABLE t1 (
+ c01 BIT,
+ c02 BIT(64),
+ c03 TINYINT,
+ c04 TINYINT UNSIGNED,
+ c05 TINYINT ZEROFILL,
+ c06 BOOL,
+ c07 SMALLINT,
+ c08 SMALLINT UNSIGNED,
+ c09 SMALLINT ZEROFILL,
+ c10 MEDIUMINT,
+ c11 MEDIUMINT UNSIGNED,
+ c12 MEDIUMINT ZEROFILL,
+ c13 INT,
+ c14 INT UNSIGNED,
+ c15 INT ZEROFILL,
+ c16 BIGINT,
+ c17 BIGINT UNSIGNED,
+ c18 BIGINT ZEROFILL,
+ c19 FLOAT,
+ c20 FLOAT UNSIGNED,
+ c21 FLOAT ZEROFILL,
+ c22 DOUBLE,
+ c23 DOUBLE UNSIGNED,
+ c24 DOUBLE ZEROFILL,
+ c25 DECIMAL,
+ c26 DECIMAL UNSIGNED,
+ c27 DECIMAL ZEROFILL,
+ #
+ c28 DATE,
+ c29 DATETIME,
+ c30 TIMESTAMP,
+ c31 TIME,
+ c32 YEAR,
+ #
+ c33 CHAR,
+ c34 CHAR(0),
+ c35 CHAR(1),
+ c36 CHAR(255),
+ c37 NATIONAL CHAR,
+ c38 NATIONAL CHAR(0),
+ c39 NATIONAL CHAR(1),
+ c40 NATIONAL CHAR(255),
+ c41 CHAR CHARACTER SET UCS2,
+ c42 CHAR(0) CHARACTER SET UCS2,
+ c43 CHAR(1) CHARACTER SET UCS2,
+ c44 CHAR(255) CHARACTER SET UCS2,
+ #
+ c45 VARCHAR(0),
+ c46 VARCHAR(1),
+ c47 VARCHAR(255),
+ c48 VARCHAR(261),
+ c49 NATIONAL VARCHAR(0),
+ c50 NATIONAL VARCHAR(1),
+ c51 NATIONAL VARCHAR(255),
+ c52 NATIONAL VARCHAR(261),
+ c53 VARCHAR(0) CHARACTER SET UCS2,
+ c54 VARCHAR(1) CHARACTER SET UCS2,
+ c55 VARCHAR(255) CHARACTER SET UCS2,
+ c56 VARCHAR(261) CHARACTER SET UCS2,
+ #
+ c57 BINARY,
+ c58 BINARY(0),
+ c59 BINARY(1),
+ c60 BINARY(255),
+ #
+ c61 VARBINARY(0),
+ c62 VARBINARY(1),
+ c63 VARBINARY(255),
+ c64 VARBINARY(261),
+ #
+ c65 TINYBLOB,
+ c66 TINYTEXT,
+ c67 TINYTEXT CHARACTER SET UCS2,
+ c68 BLOB,
+ c69 TEXT,
+ c70 TEXT CHARACTER SET UCS2,
+ c71 MEDIUMBLOB,
+ c72 MEDIUMTEXT,
+ c73 MEDIUMTEXT CHARACTER SET UCS2,
+ c74 LONGBLOB,
+ c75 LONGTEXT,
+ c76 LONGTEXT CHARACTER SET UCS2,
+ #
+ c77 ENUM('a','b','c'),
+ c78 SET('a','b','c'),
+ #
+ crn INT -- row number
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+
+--echo #
+--echo # Insert minimum values.
+--echo #
+INSERT INTO t1 VALUES (
+ b'0', -- c01
+ b'0000000000000000000000000000000000000000000000000000000000000000', -- c02
+ -128, -- c03
+ 0, -- c04
+ 000, -- c05
+ false, -- c06
+ -32768, -- c07
+ 0, -- c08
+ 00000, -- c09
+ -8388608, -- c10
+ 0, -- c11
+ 00000000, -- c12
+ -2147483648, -- c13
+ 0, -- c14
+ 0000000000, -- c15
+ -9223372036854775808, -- c16
+ 0, -- c17
+ 00000000000000000000, -- c18
+ -3.402823466E+38, -- c19
+ 1.175494351E-38, -- c20
+ 000000000000, -- c21
+ -1.7976931348623E+308, -- c22 three digits cut for ps-protocol
+ 2.2250738585072E-308, -- c23 three digits cut for ps-protocol
+ 0000000000000000000000, -- c24
+ -9999999999, -- c25
+ 0, -- c26
+ 0000000000, -- c27
+ #
+ '1000-01-01', -- c28
+ '1000-01-01 00:00:00', -- c29
+ '1970-01-02 00:00:01', -- c30 one day later due to timezone issues
+ '-838:59:59', -- c31
+ '1901', -- c32
+ #
+ '', -- c33
+ '', -- c34
+ '', -- c35
+ '', -- c36
+ '', -- c37
+ '', -- c38
+ '', -- c39
+ '', -- c40
+ '', -- c41
+ '', -- c42
+ '', -- c43
+ '', -- c44
+ #
+ '', -- c45
+ '', -- c46
+ '', -- c47
+ '', -- c48
+ '', -- c49
+ '', -- c50
+ '', -- c51
+ '', -- c52
+ '', -- c53
+ '', -- c54
+ '', -- c55
+ '', -- c56
+ #
+ '', -- c57
+ '', -- c58
+ '', -- c59
+ '', -- c60
+ #
+ '', -- c61
+ '', -- c62
+ '', -- c63
+ '', -- c64
+ #
+ '', -- c65
+ '', -- c66
+ '', -- c67
+ '', -- c68
+ '', -- c69
+ '', -- c70
+ '', -- c71
+ '', -- c72
+ '', -- c73
+ '', -- c74
+ '', -- c75
+ '', -- c76
+ #
+ 'a', -- c77
+ '', -- c78
+ #
+ 1 -- crn -- row number
+ );
+
+--echo #
+--echo # Insert maximum values.
+--echo #
+INSERT INTO t1 VALUES (
+ b'1', -- c01
+ b'1111111111111111111111111111111111111111111111111111111111111111', -- c02
+ 127, -- c03
+ 255, -- c04
+ 255, -- c05
+ true, -- c06
+ 32767, -- c07
+ 65535, -- c08
+ 65535, -- c09
+ 8388607, -- c10
+ 16777215, -- c11
+ 16777215, -- c12
+ 2147483647, -- c13
+ 4294967295, -- c14
+ 4294967295, -- c15
+ 9223372036854775807, -- c16
+ 18446744073709551615, -- c17
+ 18446744073709551615, -- c18
+ 3.402823466E+38, -- c19
+ 3.402823466E+38, -- c20
+ 3.402823466E+38, -- c21
+ 1.7976931348623E+308, -- c22 three digits cut for ps-protocol
+ 1.7976931348623E+308, -- c23 three digits cut for ps-protocol
+ 1.7976931348623E+308, -- c24 three digits cut for ps-protocol
+ 9999999999, -- c25
+ 9999999999, -- c26
+ 9999999999, -- c27
+ #
+ '9999-12-31', -- c28
+ '9999-12-31 23:59:59', -- c29
+ '2038-01-08 03:14:07', -- c30 one day earlier due to timezone issues
+ '838:59:59', -- c31
+ '2155', -- c32
+ #
+ x'ff', -- c33
+ '', -- c34
+ x'ff', -- c35
+ REPEAT(x'ff',255), -- c36
+ _utf8 x'efbfbf', -- c37
+ '', -- c38
+ _utf8 x'efbfbf', -- c39
+ REPEAT(_utf8 x'efbfbf',255), -- c40
+ _ucs2 x'ffff', -- c41
+ '', -- c42
+ _ucs2 x'ffff', -- c43
+ REPEAT(_ucs2 x'ffff',255), -- c44
+ #
+ '', -- c45
+ x'ff', -- c46
+ REPEAT(x'ff',255), -- c47
+ REPEAT(x'ff',261), -- c48
+ '', -- c49
+ _utf8 x'efbfbf', -- c50
+ REPEAT(_utf8 x'efbfbf',255), -- c51
+ REPEAT(_utf8 x'efbfbf',261), -- c52
+ '', -- c53
+ _ucs2 x'ffff', -- c54
+ REPEAT(_ucs2 x'ffff',255), -- c55
+ REPEAT(_ucs2 x'ffff',261), -- c56
+ #
+ x'ff', -- c57
+ '', -- c58
+ x'ff', -- c59
+ REPEAT(x'ff',255), -- c60
+ #
+ '', -- c61
+ x'ff', -- c62
+ REPEAT(x'ff',255), -- c63
+ REPEAT(x'ff',261), -- c64
+ #
+ 'tinyblob', -- c65 not using maximum value here
+ 'tinytext', -- c66 not using maximum value here
+ 'tinytext-ucs2', -- c67 not using maximum value here
+ 'blob', -- c68 not using maximum value here
+ 'text', -- c69 not using maximum value here
+ 'text-ucs2', -- c70 not using maximum value here
+ 'mediumblob', -- c71 not using maximum value here
+ 'mediumtext', -- c72 not using maximum value here
+ 'mediumtext-ucs2', -- c73 not using maximum value here
+ 'longblob', -- c74 not using maximum value here
+ 'longtext', -- c75 not using maximum value here
+ 'longtext-ucs2', -- c76 not using maximum value here
+ #
+ 'c', -- c77
+ 'a,b,c', -- c78
+ #
+ 2 -- crn -- row number
+ );
+
+--echo #
+--echo # Insert a row with NULL values and one with arbitrary values.
+--echo #
+INSERT INTO t1 VALUES (
+ NULL, -- c01
+ NULL, -- c02
+ NULL, -- c03
+ NULL, -- c04
+ NULL, -- c05
+ NULL, -- c06
+ NULL, -- c07
+ NULL, -- c08
+ NULL, -- c09
+ NULL, -- c10
+ NULL, -- c11
+ NULL, -- c12
+ NULL, -- c13
+ NULL, -- c14
+ NULL, -- c15
+ NULL, -- c16
+ NULL, -- c17
+ NULL, -- c18
+ NULL, -- c19
+ NULL, -- c20
+ NULL, -- c21
+ NULL, -- c22
+ NULL, -- c23
+ NULL, -- c24
+ NULL, -- c25
+ NULL, -- c26
+ NULL, -- c27
+ #
+ NULL, -- c28
+ NULL, -- c29
+ NULL, -- c30
+ NULL, -- c31
+ NULL, -- c32
+ #
+ NULL, -- c33
+ NULL, -- c34
+ NULL, -- c35
+ NULL, -- c36
+ NULL, -- c37
+ NULL, -- c38
+ NULL, -- c39
+ NULL, -- c40
+ NULL, -- c41
+ NULL, -- c42
+ NULL, -- c43
+ NULL, -- c44
+ #
+ NULL, -- c45
+ NULL, -- c46
+ NULL, -- c47
+ NULL, -- c48
+ NULL, -- c49
+ NULL, -- c50
+ NULL, -- c51
+ NULL, -- c52
+ NULL, -- c53
+ NULL, -- c54
+ NULL, -- c55
+ NULL, -- c56
+ #
+ NULL, -- c57
+ NULL, -- c58
+ NULL, -- c59
+ NULL, -- c60
+ #
+ NULL, -- c61
+ NULL, -- c62
+ NULL, -- c63
+ NULL, -- c64
+ #
+ NULL, -- c65
+ NULL, -- c66
+ NULL, -- c67
+ NULL, -- c68
+ NULL, -- c69
+ NULL, -- c70
+ NULL, -- c71
+ NULL, -- c72
+ NULL, -- c73
+ NULL, -- c74
+ NULL, -- c75
+ NULL, -- c76
+ #
+ NULL, -- c77
+ NULL, -- c78
+ #
+ 3 -- crn -- row number
+ ), (
+ b'1', -- c01
+ b'1111111111111111111111111111111111111111111111111111111111111111', -- c02
+ 127, -- c03
+ 0, -- c04
+ 001, -- c05
+ true, -- c06
+ 32767, -- c07
+ 0, -- c08
+ 00001, -- c09
+ 8388607, -- c10
+ 0, -- c11
+ 00000001, -- c12
+ 2147483647, -- c13
+ 0, -- c14
+ 0000000001, -- c15
+ 9223372036854775807, -- c16
+ 0, -- c17
+ 00000000000000000001, -- c18
+ -1.175494351E-38, -- c19
+ 1.175494351E-38, -- c20
+ 000000000000001, -- c21
+ -2.2250738585072E-308, -- c22
+ 2.2250738585072E-308, -- c23
+ 00000000000000000000001, -- c24
+ -9999999999, -- c25
+ 9999999999, -- c26
+ 0000000001, -- c27
+ #
+ '2008-08-04', -- c28
+ '2008-08-04 16:18:06', -- c29
+ '2008-08-04 16:18:24', -- c30
+ '16:18:47', -- c31
+ '2008', -- c32
+ #
+ 'a', -- c33
+ '', -- c34
+ 'e', -- c35
+ REPEAT('i',255), -- c36
+ _utf8 x'c3a4', -- c37
+ '', -- c38
+ _utf8 x'c3b6', -- c39
+ REPEAT(_utf8 x'c3bc',255), -- c40
+ _ucs2 x'00e4', -- c41
+ '', -- c42
+ _ucs2 x'00f6', -- c43
+ REPEAT(_ucs2 x'00fc',255), -- c44
+ #
+ '', -- c45
+ 'a', -- c46
+ REPEAT('e',255), -- c47
+ REPEAT('i',261), -- c48
+ '', -- c49
+ _utf8 x'c3a4', -- c50
+ REPEAT(_utf8 x'c3b6',255), -- c51
+ REPEAT(_utf8 x'c3bc',261), -- c52
+ '', -- c53
+ _ucs2 x'00e4', -- c54
+ REPEAT(_ucs2 x'00f6',255), -- c55
+ REPEAT(_ucs2 x'00fc',261), -- c56
+ #
+ '0', -- c57
+ '', -- c58
+ '1', -- c59
+ REPEAT('1',255), -- c60
+ #
+ '', -- c61
+ 'b', -- c62
+ REPEAT('c',255), -- c63
+ REPEAT('\'',261), -- c64
+ #
+ 'tinyblob', -- c65
+ 'tinytext', -- c66
+ 'tinytext-ucs2', -- c67
+ 'blob', -- c68
+ 'text', -- c69
+ 'text-ucs2', -- c70
+ 'mediumblob', -- c71
+ 'mediumtext', -- c72
+ 'mediumtext-ucs2', -- c73
+ 'longblob', -- c74
+ 'longtext', -- c75
+ 'longtext-ucs2', -- c76
+ #
+ 'b', -- c77
+ 'b,c', -- c78
+ #
+ 4 -- crn -- row number
+ );
+
+--echo #
+--echo # Show what we have in the table.
+--echo # Do not display bit type output. It's binary and confuses diff.
+--echo # Also BINARY with nul-bytes should be avoided.
+--echo #
+--replace_column 1 # 2 # 57 # 58 # 59 # 60 #
+query_vertical SELECT * FROM t1;
+
+--echo #
+--echo # NOTE: For matching FLOAT and DOUBLE values in WHERE conditions,
+--echo # don't use exact match, but < or > and tweak the numbers a bit.
+--echo #
+--echo # Show how much rows are affected by each statement.
+--echo #
+--enable_info
+
+--echo #
+--echo # Update min values to max values.
+--echo #
+UPDATE t1 SET
+ c01 = b'1',
+ c02 = b'1111111111111111111111111111111111111111111111111111111111111111',
+ c03 = 127,
+ c04 = 255,
+ c05 = 255,
+ c06 = true,
+ c07 = 32767,
+ c08 = 65535,
+ c09 = 65535,
+ c10 = 8388607,
+ c11 = 16777215,
+ c12 = 16777215,
+ c13 = 2147483647,
+ c14 = 4294967295,
+ c15 = 4294967295,
+ c16 = 9223372036854775807,
+ c17 = 18446744073709551615,
+ c18 = 18446744073709551615,
+ c19 = 3.402823466E+38,
+ c20 = 3.402823466E+38,
+ c21 = 3.402823466E+38,
+ c22 = 1.7976931348623E+308,
+ c23 = 1.7976931348623E+308,
+ c24 = 1.7976931348623E+308,
+ c25 = 9999999999,
+ c26 = 9999999999,
+ c27 = 9999999999,
+ #
+ c28 = '9999-12-31',
+ c29 = '9999-12-31 23:59:59',
+ c30 = '2038-01-08 03:14:07',
+ c31 = '838:59:59',
+ c32 = '2155',
+ #
+ c33 = x'ff',
+ c34 = '',
+ c35 = x'ff',
+ c36 = REPEAT(x'ff',255),
+ c37 = _utf8 x'efbfbf',
+ c38 = '',
+ c39 = _utf8 x'efbfbf',
+ c40 = REPEAT(_utf8 x'efbfbf',255),
+ c41 = _ucs2 x'ffff',
+ c42 = '',
+ c43 = _ucs2 x'ffff',
+ c44 = REPEAT(_ucs2 x'ffff',255),
+ #
+ c45 = '',
+ c46 = x'ff',
+ c47 = REPEAT(x'ff',255),
+ c48 = REPEAT(x'ff',261),
+ c49 = '',
+ c50 = _utf8 x'efbfbf',
+ c51 = REPEAT(_utf8 x'efbfbf',255),
+ c52 = REPEAT(_utf8 x'efbfbf',261),
+ c53 = '',
+ c54 = _ucs2 x'ffff',
+ c55 = REPEAT(_ucs2 x'ffff',255),
+ c56 = REPEAT(_ucs2 x'ffff',261),
+ #
+ c57 = x'ff',
+ c58 = '',
+ c59 = x'ff',
+ c60 = REPEAT(x'ff',255),
+ #
+ c61 = '',
+ c62 = x'ff',
+ c63 = REPEAT(x'ff',255),
+ c64 = REPEAT(x'ff',261),
+ #
+ c65 = 'tinyblob',
+ c66 = 'tinytext',
+ c67 = 'tinytext-ucs2',
+ c68 = 'blob',
+ c69 = 'text',
+ c70 = 'text-ucs2',
+ c71 = 'mediumblob',
+ c72 = 'mediumtext',
+ c73 = 'mediumtext-ucs2',
+ c74 = 'longblob',
+ c75 = 'longtext',
+ c76 = 'longtext-ucs2',
+ #
+ c77 = 'c',
+ c78 = 'a,b,c',
+ #
+ crn = crn
+ #
+ WHERE
+ #
+ c01 = b'0' AND
+ c02 = b'0000000000000000000000000000000000000000000000000000000000000000' AND
+ c03 = -128 AND
+ c04 = 0 AND
+ c05 = 000 AND
+ c06 = false AND
+ c07 = -32768 AND
+ c08 = 0 AND
+ c09 = 00000 AND
+ c10 = -8388608 AND
+ c11 = 0 AND
+ c12 = 00000000 AND
+ c13 = -2147483648 AND
+ c14 = 0 AND
+ c15 = 0000000000 AND
+ c16 = -9223372036854775808 AND
+ c17 = 0 AND
+ c18 = 00000000000000000000 AND
+ c19 < -3.402823465E+38 AND
+ c20 < 1.175494352E-38 AND
+ c21 = 000000000000 AND
+ c22 < -1.7976931348622E+308 AND
+ c23 < 2.2250738585073E-308 AND
+ c24 = 0000000000000000000000 AND
+ c25 = -9999999999 AND
+ c26 = 0 AND
+ c27 = 0000000000 AND
+ #
+ c28 = '1000-01-01' AND
+ c29 = '1000-01-01 00:00:00' AND
+ c30 = '1970-01-02 00:00:01' AND
+ c31 = '-838:59:59' AND
+ c32 = '1901' AND
+ #
+ c33 = '' AND
+ c34 = '' AND
+ c35 = '' AND
+ c36 = '' AND
+ c37 = '' AND
+ c38 = '' AND
+ c39 = '' AND
+ c40 = '' AND
+ c41 = '' AND
+ c42 = '' AND
+ c43 = '' AND
+ c44 = '' AND
+ #
+ c45 = '' AND
+ c46 = '' AND
+ c47 = '' AND
+ c48 = '' AND
+ c49 = '' AND
+ c50 = '' AND
+ c51 = '' AND
+ c52 = '' AND
+ c53 = '' AND
+ c54 = '' AND
+ c55 = '' AND
+ c56 = '' AND
+ #
+ # this does not reproduce the inserted value: c57 = '' AND
+ c58 = '' AND
+ # this does not reproduce the inserted value: c59 = '' AND
+ # this does not reproduce the inserted value: c60 = '' AND
+ #
+ c61 = '' AND
+ c62 = '' AND
+ c63 = '' AND
+ c64 = '' AND
+ #
+ c65 = '' AND
+ c66 = '' AND
+ c67 = '' AND
+ c68 = '' AND
+ c69 = '' AND
+ c70 = '' AND
+ c71 = '' AND
+ c72 = '' AND
+ c73 = '' AND
+ c74 = '' AND
+ c75 = '' AND
+ c76 = '' AND
+ #
+ c77 = 'a' AND
+ c78 = '' AND
+ #
+ crn = 1;
+
+--echo #
+--echo # Update max values to min values.
+--echo #
+UPDATE t1 SET
+ c01 = b'0',
+ c02 = b'0000000000000000000000000000000000000000000000000000000000000000',
+ c03 = -128,
+ c04 = 0,
+ c05 = 000,
+ c06 = false,
+ c07 = -32768,
+ c08 = 0,
+ c09 = 00000,
+ c10 = -8388608,
+ c11 = 0,
+ c12 = 00000000,
+ c13 = -2147483648,
+ c14 = 0,
+ c15 = 0000000000,
+ c16 = -9223372036854775808,
+ c17 = 0,
+ c18 = 00000000000000000000,
+ c19 = -3.402823466E+38,
+ c20 = 1.175494351E-38,
+ c21 = 000000000000,
+ c22 = -1.7976931348623E+308,
+ c23 = 2.2250738585072E-308,
+ c24 = 0000000000000000000000,
+ c25 = -9999999999,
+ c26 = 0,
+ c27 = 0000000000,
+ #
+ c28 = '1000-01-01',
+ c29 = '1000-01-01 00:00:00',
+ c30 = '1970-01-02 00:00:01',
+ c31 = '-838:59:59',
+ c32 = '1901',
+ #
+ c33 = '',
+ c34 = '',
+ c35 = '',
+ c36 = '',
+ c37 = '',
+ c38 = '',
+ c39 = '',
+ c40 = '',
+ c41 = '',
+ c42 = '',
+ c43 = '',
+ c44 = '',
+ #
+ c45 = '',
+ c46 = '',
+ c47 = '',
+ c48 = '',
+ c49 = '',
+ c50 = '',
+ c51 = '',
+ c52 = '',
+ c53 = '',
+ c54 = '',
+ c55 = '',
+ c56 = '',
+ #
+ c57 = '',
+ c58 = '',
+ c59 = '',
+ c60 = '',
+ #
+ c61 = '',
+ c62 = '',
+ c63 = '',
+ c64 = '',
+ #
+ c65 = '',
+ c66 = '',
+ c67 = '',
+ c68 = '',
+ c69 = '',
+ c70 = '',
+ c71 = '',
+ c72 = '',
+ c73 = '',
+ c74 = '',
+ c75 = '',
+ c76 = '',
+ #
+ c77 = 'a',
+ c78 = '',
+ #
+ crn = crn
+ #
+ WHERE
+ #
+ c01 = b'1' AND
+ # the below does not reproduce the inserted value:
+ #c02 = b'1111111111111111111111111111111111111111111111111111111111111111' AND
+ c03 = 127 AND
+ c04 = 255 AND
+ c05 = 255 AND
+ c06 = true AND
+ c07 = 32767 AND
+ c08 = 65535 AND
+ c09 = 65535 AND
+ c10 = 8388607 AND
+ c11 = 16777215 AND
+ c12 = 16777215 AND
+ c13 = 2147483647 AND
+ c14 = 4294967295 AND
+ c15 = 4294967295 AND
+ c16 = 9223372036854775807 AND
+ c17 = 18446744073709551615 AND
+ c18 = 18446744073709551615 AND
+ c19 > 3.402823465E+38 AND
+ c20 > 3.402823465E+38 AND
+ c21 > 3.402823465E+38 AND
+ c22 > 1.7976931348622E+308 AND
+ c23 > 1.7976931348622E+308 AND
+ c24 > 1.7976931348622E+308 AND
+ c25 = 9999999999 AND
+ c26 = 9999999999 AND
+ c27 = 9999999999 AND
+ #
+ c28 = '9999-12-31' AND
+ c29 = '9999-12-31 23:59:59' AND
+ c30 = '2038-01-08 03:14:07' AND
+ c31 = '838:59:59' AND
+ c32 = '2155' AND
+ #
+ c33 = x'ff' AND
+ c34 = '' AND
+ c35 = x'ff' AND
+ c36 = REPEAT(x'ff',255) AND
+ c37 = _utf8 x'efbfbf' AND
+ c38 = '' AND
+ c39 = _utf8 x'efbfbf' AND
+ c40 = REPEAT(_utf8 x'efbfbf',255) AND
+ c41 = _ucs2 x'ffff' AND
+ c42 = '' AND
+ c43 = _ucs2 x'ffff' AND
+ c44 = REPEAT(_ucs2 x'ffff',255) AND
+ #
+ c45 = '' AND
+ c46 = x'ff' AND
+ c47 = REPEAT(x'ff',255) AND
+ c48 = REPEAT(x'ff',261) AND
+ c49 = '' AND
+ c50 = _utf8 x'efbfbf' AND
+ c51 = REPEAT(_utf8 x'efbfbf',255) AND
+ c52 = REPEAT(_utf8 x'efbfbf',261) AND
+ c53 = '' AND
+ c54 = _ucs2 x'ffff' AND
+ c55 = REPEAT(_ucs2 x'ffff',255) AND
+ c56 = REPEAT(_ucs2 x'ffff',261) AND
+ #
+ c57 = x'ff' AND
+ c58 = '' AND
+ c59 = x'ff' AND
+ c60 = REPEAT(x'ff',255) AND
+ #
+ c61 = '' AND
+ c62 = x'ff' AND
+ c63 = REPEAT(x'ff',255) AND
+ c64 = REPEAT(x'ff',261) AND
+ #
+ c65 = 'tinyblob' AND
+ c66 = 'tinytext' AND
+ c67 = 'tinytext-ucs2' AND
+ c68 = 'blob' AND
+ c69 = 'text' AND
+ c70 = 'text-ucs2' AND
+ c71 = 'mediumblob' AND
+ c72 = 'mediumtext' AND
+ c73 = 'mediumtext-ucs2' AND
+ c74 = 'longblob' AND
+ c75 = 'longtext' AND
+ c76 = 'longtext-ucs2' AND
+ #
+ c77 = 'c' AND
+ c78 = 'a,b,c' AND
+ #
+ crn = 2;
+
+--echo #
+--echo # Update NULL values to arbitrary values.
+--echo #
+UPDATE t1 SET
+ c01 = b'1',
+ c02 = b'1111111111111111111111111111111111111111111111111111111111111111',
+ c03 = 127,
+ c04 = 0,
+ c05 = 001,
+ c06 = true,
+ c07 = 32767,
+ c08 = 0,
+ c09 = 00001,
+ c10 = 8388607,
+ c11 = 0,
+ c12 = 00000001,
+ c13 = 2147483647,
+ c14 = 0,
+ c15 = 0000000001,
+ c16 = 9223372036854775807,
+ c17 = 0,
+ c18 = 00000000000000000001,
+ c19 = -1.175494351E-38,
+ c20 = 1.175494351E-38,
+ c21 = 000000000000001,
+ c22 = -2.2250738585072E-308,
+ c23 = 2.2250738585072E-308,
+ c24 = 00000000000000000000001,
+ c25 = -9999999999,
+ c26 = 9999999999,
+ c27 = 0000000001,
+ #
+ c28 = '2008-08-04',
+ c29 = '2008-08-04 16:18:06',
+ c30 = '2008-08-04 16:18:24',
+ c31 = '16:18:47',
+ c32 = '2008',
+ #
+ c33 = 'a',
+ c34 = '',
+ c35 = 'e',
+ c36 = REPEAT('i',255),
+ c37 = _utf8 x'c3a4',
+ c38 = '',
+ c39 = _utf8 x'c3b6',
+ c40 = REPEAT(_utf8 x'c3bc',255),
+ c41 = _ucs2 x'00e4',
+ c42 = '',
+ c43 = _ucs2 x'00f6',
+ c44 = REPEAT(_ucs2 x'00fc',255),
+ #
+ c45 = '',
+ c46 = 'a',
+ c47 = REPEAT('e',255),
+ c48 = REPEAT('i',261),
+ c49 = '',
+ c50 = _utf8 x'c3a4',
+ c51 = REPEAT(_utf8 x'c3b6',255),
+ c52 = REPEAT(_utf8 x'c3bc',261),
+ c53 = '',
+ c54 = _ucs2 x'00e4',
+ c55 = REPEAT(_ucs2 x'00f6',255),
+ c56 = REPEAT(_ucs2 x'00fc',261),
+ #
+ c57 = '0',
+ c58 = '',
+ c59 = '1',
+ c60 = REPEAT('1',255),
+ #
+ c61 = '',
+ c62 = 'b',
+ c63 = REPEAT('c',255),
+ c64 = REPEAT('\'',261),
+ #
+ c65 = 'tinyblob',
+ c66 = 'tinytext',
+ c67 = 'tinytext-ucs2',
+ c68 = 'blob',
+ c69 = 'text',
+ c70 = 'text-ucs2',
+ c71 = 'mediumblob',
+ c72 = 'mediumtext',
+ c73 = 'mediumtext-ucs2',
+ c74 = 'longblob',
+ c75 = 'longtext',
+ c76 = 'longtext-ucs2',
+ #
+ c77 = 'b',
+ c78 = 'b,c',
+ #
+ crn = crn
+ #
+ WHERE
+ #
+ c01 IS NULL AND
+ c02 IS NULL AND
+ c03 IS NULL AND
+ c04 IS NULL AND
+ c05 IS NULL AND
+ c06 IS NULL AND
+ c07 IS NULL AND
+ c08 IS NULL AND
+ c09 IS NULL AND
+ c10 IS NULL AND
+ c11 IS NULL AND
+ c12 IS NULL AND
+ c13 IS NULL AND
+ c14 IS NULL AND
+ c15 IS NULL AND
+ c16 IS NULL AND
+ c17 IS NULL AND
+ c18 IS NULL AND
+ c19 IS NULL AND
+ c20 IS NULL AND
+ c21 IS NULL AND
+ c22 IS NULL AND
+ c23 IS NULL AND
+ c24 IS NULL AND
+ c25 IS NULL AND
+ c26 IS NULL AND
+ c27 IS NULL AND
+ #
+ c28 IS NULL AND
+ c29 IS NULL AND
+ # this got a timestamp instead of NULL: c30 IS NULL AND
+ c31 IS NULL AND
+ c32 IS NULL AND
+ #
+ c33 IS NULL AND
+ c34 IS NULL AND
+ c35 IS NULL AND
+ c36 IS NULL AND
+ c37 IS NULL AND
+ c38 IS NULL AND
+ c39 IS NULL AND
+ c40 IS NULL AND
+ c41 IS NULL AND
+ c42 IS NULL AND
+ c43 IS NULL AND
+ c44 IS NULL AND
+ #
+ c45 IS NULL AND
+ c46 IS NULL AND
+ c47 IS NULL AND
+ c48 IS NULL AND
+ c49 IS NULL AND
+ c50 IS NULL AND
+ c51 IS NULL AND
+ c52 IS NULL AND
+ c53 IS NULL AND
+ c54 IS NULL AND
+ c55 IS NULL AND
+ c56 IS NULL AND
+ #
+ c57 IS NULL AND
+ c58 IS NULL AND
+ c59 IS NULL AND
+ c60 IS NULL AND
+ #
+ c61 IS NULL AND
+ c62 IS NULL AND
+ c63 IS NULL AND
+ c64 IS NULL AND
+ #
+ c65 IS NULL AND
+ c66 IS NULL AND
+ c67 IS NULL AND
+ c68 IS NULL AND
+ c69 IS NULL AND
+ c70 IS NULL AND
+ c71 IS NULL AND
+ c72 IS NULL AND
+ c73 IS NULL AND
+ c74 IS NULL AND
+ c75 IS NULL AND
+ c76 IS NULL AND
+ #
+ c77 IS NULL AND
+ c78 IS NULL AND
+ #
+ crn = 3;
+
+--echo #
+--echo # Update arbitrary values to NULL values.
+--echo #
+UPDATE t1 SET
+ c01 = NULL,
+ c02 = NULL,
+ c03 = NULL,
+ c04 = NULL,
+ c05 = NULL,
+ c06 = NULL,
+ c07 = NULL,
+ c08 = NULL,
+ c09 = NULL,
+ c10 = NULL,
+ c11 = NULL,
+ c12 = NULL,
+ c13 = NULL,
+ c14 = NULL,
+ c15 = NULL,
+ c16 = NULL,
+ c17 = NULL,
+ c18 = NULL,
+ c19 = NULL,
+ c20 = NULL,
+ c21 = NULL,
+ c22 = NULL,
+ c23 = NULL,
+ c24 = NULL,
+ c25 = NULL,
+ c26 = NULL,
+ c27 = NULL,
+ #
+ c28 = NULL,
+ c29 = NULL,
+ c30 = NULL,
+ c31 = NULL,
+ c32 = NULL,
+ #
+ c33 = NULL,
+ c34 = NULL,
+ c35 = NULL,
+ c36 = NULL,
+ c37 = NULL,
+ c38 = NULL,
+ c39 = NULL,
+ c40 = NULL,
+ c41 = NULL,
+ c42 = NULL,
+ c43 = NULL,
+ c44 = NULL,
+ #
+ c45 = NULL,
+ c46 = NULL,
+ c47 = NULL,
+ c48 = NULL,
+ c49 = NULL,
+ c50 = NULL,
+ c51 = NULL,
+ c52 = NULL,
+ c53 = NULL,
+ c54 = NULL,
+ c55 = NULL,
+ c56 = NULL,
+ #
+ c57 = NULL,
+ c58 = NULL,
+ c59 = NULL,
+ c60 = NULL,
+ #
+ c61 = NULL,
+ c62 = NULL,
+ c63 = NULL,
+ c64 = NULL,
+ #
+ c65 = NULL,
+ c66 = NULL,
+ c67 = NULL,
+ c68 = NULL,
+ c69 = NULL,
+ c70 = NULL,
+ c71 = NULL,
+ c72 = NULL,
+ c73 = NULL,
+ c74 = NULL,
+ c75 = NULL,
+ c76 = NULL,
+ #
+ c77 = NULL,
+ c78 = NULL,
+ #
+ crn = crn
+ #
+ WHERE
+ #
+ c01 = b'1' AND
+ # the below does not reproduce the inserted value:
+ #c02 = b'1111111111111111111111111111111111111111111111111111111111111111' AND
+ c03 = 127 AND
+ c04 = 0 AND
+ c05 = 001 AND
+ c06 = true AND
+ c07 = 32767 AND
+ c08 = 0 AND
+ c09 = 00001 AND
+ c10 = 8388607 AND
+ c11 = 0 AND
+ c12 = 00000001 AND
+ c13 = 2147483647 AND
+ c14 = 0 AND
+ c15 = 0000000001 AND
+ c16 = 9223372036854775807 AND
+ c17 = 0 AND
+ c18 = 00000000000000000001 AND
+ c19 > -1.175494352E-38 AND
+ c20 < 1.175494352E-38 AND
+ c21 = 000000000000001 AND
+ c22 > -2.2250738585073E-308 AND
+ c23 < 2.2250738585073E-308 AND
+ c24 = 00000000000000000000001 AND
+ c25 = -9999999999 AND
+ c26 = 9999999999 AND
+ c27 = 0000000001 AND
+ #
+ c28 = '2008-08-04' AND
+ c29 = '2008-08-04 16:18:06' AND
+ c30 = '2008-08-04 16:18:24' AND
+ c31 = '16:18:47' AND
+ c32 = '2008' AND
+ #
+ c33 = 'a' AND
+ c34 = '' AND
+ c35 = 'e' AND
+ c36 = REPEAT('i',255) AND
+ c37 = _utf8 x'c3a4' AND
+ c38 = '' AND
+ c39 = _utf8 x'c3b6' AND
+ c40 = REPEAT(_utf8 x'c3bc',255) AND
+ c41 = _ucs2 x'00e4' AND
+ c42 = '' AND
+ c43 = _ucs2 x'00f6' AND
+ c44 = REPEAT(_ucs2 x'00fc',255) AND
+ #
+ c45 = '' AND
+ c46 = 'a' AND
+ c47 = REPEAT('e',255) AND
+ c48 = REPEAT('i',261) AND
+ c49 = '' AND
+ c50 = _utf8 x'c3a4' AND
+ c51 = REPEAT(_utf8 x'c3b6',255) AND
+ c52 = REPEAT(_utf8 x'c3bc',261) AND
+ c53 = '' AND
+ c54 = _ucs2 x'00e4' AND
+ c55 = REPEAT(_ucs2 x'00f6',255) AND
+ c56 = REPEAT(_ucs2 x'00fc',261) AND
+ #
+ c57 = '0' AND
+ c58 = '' AND
+ c59 = '1' AND
+ c60 = REPEAT('1',255) AND
+ #
+ c61 = '' AND
+ c62 = 'b' AND
+ c63 = REPEAT('c',255) AND
+ c64 = REPEAT('\'',261) AND
+ #
+ c65 = 'tinyblob' AND
+ c66 = 'tinytext' AND
+ c67 = 'tinytext-ucs2' AND
+ c68 = 'blob' AND
+ c69 = 'text' AND
+ c70 = 'text-ucs2' AND
+ c71 = 'mediumblob' AND
+ c72 = 'mediumtext' AND
+ c73 = 'mediumtext-ucs2' AND
+ c74 = 'longblob' AND
+ c75 = 'longtext' AND
+ c76 = 'longtext-ucs2' AND
+ #
+ c77 = 'b' AND
+ c78 = 'b,c' AND
+ #
+ crn = 4;
+
+--echo #
+--echo # Show what we have in the table.
+--echo # Do not display bit type output. It's binary and confuses diff.
+--echo # Also BINARY with nul-bytes should be avoided.
+--echo #
+--replace_column 1 # 2 # 57 # 58 # 59 # 60 #
+query_vertical SELECT * FROM t1;
+
+--echo #
+--echo # Delete the row that has max values now.
+--echo #
+DELETE FROM t1 WHERE
+ #
+ c01 = b'1' AND
+ # the below does not reproduce the inserted value:
+ #c02 = b'1111111111111111111111111111111111111111111111111111111111111111' AND
+ c03 = 127 AND
+ c04 = 255 AND
+ c05 = 255 AND
+ c06 = true AND
+ c07 = 32767 AND
+ c08 = 65535 AND
+ c09 = 65535 AND
+ c10 = 8388607 AND
+ c11 = 16777215 AND
+ c12 = 16777215 AND
+ c13 = 2147483647 AND
+ c14 = 4294967295 AND
+ c15 = 4294967295 AND
+ c16 = 9223372036854775807 AND
+ c17 = 18446744073709551615 AND
+ c18 = 18446744073709551615 AND
+ c19 > 3.402823465E+38 AND
+ c20 > 3.402823465E+38 AND
+ c21 > 3.402823465E+38 AND
+ c22 > 1.7976931348622E+308 AND
+ c23 > 1.7976931348622E+308 AND
+ c24 > 1.7976931348622E+308 AND
+ c25 = 9999999999 AND
+ c26 = 9999999999 AND
+ c27 = 9999999999 AND
+ #
+ c28 = '9999-12-31' AND
+ c29 = '9999-12-31 23:59:59' AND
+ c30 = '2038-01-08 03:14:07' AND
+ c31 = '838:59:59' AND
+ c32 = '2155' AND
+ #
+ c33 = x'ff' AND
+ c34 = '' AND
+ c35 = x'ff' AND
+ c36 = REPEAT(x'ff',255) AND
+ c37 = _utf8 x'efbfbf' AND
+ c38 = '' AND
+ c39 = _utf8 x'efbfbf' AND
+ c40 = REPEAT(_utf8 x'efbfbf',255) AND
+ c41 = _ucs2 x'ffff' AND
+ c42 = '' AND
+ c43 = _ucs2 x'ffff' AND
+ c44 = REPEAT(_ucs2 x'ffff',255) AND
+ #
+ c45 = '' AND
+ c46 = x'ff' AND
+ c47 = REPEAT(x'ff',255) AND
+ c48 = REPEAT(x'ff',261) AND
+ c49 = '' AND
+ c50 = _utf8 x'efbfbf' AND
+ c51 = REPEAT(_utf8 x'efbfbf',255) AND
+ c52 = REPEAT(_utf8 x'efbfbf',261) AND
+ c53 = '' AND
+ c54 = _ucs2 x'ffff' AND
+ c55 = REPEAT(_ucs2 x'ffff',255) AND
+ c56 = REPEAT(_ucs2 x'ffff',261) AND
+ #
+ c57 = x'ff' AND
+ c58 = '' AND
+ c59 = x'ff' AND
+ c60 = REPEAT(x'ff',255) AND
+ #
+ c61 = '' AND
+ c62 = x'ff' AND
+ c63 = REPEAT(x'ff',255) AND
+ c64 = REPEAT(x'ff',261) AND
+ #
+ c65 = 'tinyblob' AND
+ c66 = 'tinytext' AND
+ c67 = 'tinytext-ucs2' AND
+ c68 = 'blob' AND
+ c69 = 'text' AND
+ c70 = 'text-ucs2' AND
+ c71 = 'mediumblob' AND
+ c72 = 'mediumtext' AND
+ c73 = 'mediumtext-ucs2' AND
+ c74 = 'longblob' AND
+ c75 = 'longtext' AND
+ c76 = 'longtext-ucs2' AND
+ #
+ c77 = 'c' AND
+ c78 = 'a,b,c' AND
+ #
+ crn = 1;
+
+--echo #
+--echo # Delete the row that has min values now.
+--echo #
+DELETE FROM t1 WHERE
+ #
+ c01 = b'0' AND
+ c02 = b'0000000000000000000000000000000000000000000000000000000000000000' AND
+ c03 = -128 AND
+ c04 = 0 AND
+ c05 = 000 AND
+ c06 = false AND
+ c07 = -32768 AND
+ c08 = 0 AND
+ c09 = 00000 AND
+ c10 = -8388608 AND
+ c11 = 0 AND
+ c12 = 00000000 AND
+ c13 = -2147483648 AND
+ c14 = 0 AND
+ c15 = 0000000000 AND
+ c16 = -9223372036854775808 AND
+ c17 = 0 AND
+ c18 = 00000000000000000000 AND
+ c19 < -3.402823465E+38 AND
+ c20 < 1.175494352E-38 AND
+ c21 = 000000000000 AND
+ c22 < -1.7976931348622E+308 AND
+ c23 < 2.2250738585073E-308 AND
+ c24 = 0000000000000000000000 AND
+ c25 = -9999999999 AND
+ c26 = 0 AND
+ c27 = 0000000000 AND
+ #
+ c28 = '1000-01-01' AND
+ c29 = '1000-01-01 00:00:00' AND
+ c30 = '1970-01-02 00:00:01' AND
+ c31 = '-838:59:59' AND
+ c32 = '1901' AND
+ #
+ c33 = '' AND
+ c34 = '' AND
+ c35 = '' AND
+ c36 = '' AND
+ c37 = '' AND
+ c38 = '' AND
+ c39 = '' AND
+ c40 = '' AND
+ c41 = '' AND
+ c42 = '' AND
+ c43 = '' AND
+ c44 = '' AND
+ #
+ c45 = '' AND
+ c46 = '' AND
+ c47 = '' AND
+ c48 = '' AND
+ c49 = '' AND
+ c50 = '' AND
+ c51 = '' AND
+ c52 = '' AND
+ c53 = '' AND
+ c54 = '' AND
+ c55 = '' AND
+ c56 = '' AND
+ #
+ # this does not reproduce the inserted value: c57 = '' AND
+ c58 = '' AND
+ # this does not reproduce the inserted value: c59 = '' AND
+ # this does not reproduce the inserted value: c60 = '' AND
+ #
+ c61 = '' AND
+ c62 = '' AND
+ c63 = '' AND
+ c64 = '' AND
+ #
+ c65 = '' AND
+ c66 = '' AND
+ c67 = '' AND
+ c68 = '' AND
+ c69 = '' AND
+ c70 = '' AND
+ c71 = '' AND
+ c72 = '' AND
+ c73 = '' AND
+ c74 = '' AND
+ c75 = '' AND
+ c76 = '' AND
+ #
+ c77 = 'a' AND
+ c78 = '' AND
+ #
+ crn = 2;
+
+--echo #
+--echo # Delete the row that has arbitrary values now.
+--echo #
+DELETE FROM t1 WHERE
+ #
+ c01 = b'1' AND
+ # the below does not reproduce the inserted value:
+ #c02 = b'1111111111111111111111111111111111111111111111111111111111111111' AND
+ c03 = 127 AND
+ c04 = 0 AND
+ c05 = 001 AND
+ c06 = true AND
+ c07 = 32767 AND
+ c08 = 0 AND
+ c09 = 00001 AND
+ c10 = 8388607 AND
+ c11 = 0 AND
+ c12 = 00000001 AND
+ c13 = 2147483647 AND
+ c14 = 0 AND
+ c15 = 0000000001 AND
+ c16 = 9223372036854775807 AND
+ c17 = 0 AND
+ c18 = 00000000000000000001 AND
+ c19 > -1.175494352E-38 AND
+ c20 < 1.175494352E-38 AND
+ c21 = 000000000000001 AND
+ c22 > -2.2250738585073E-308 AND
+ c23 < 2.2250738585073E-308 AND
+ c24 = 00000000000000000000001 AND
+ c25 = -9999999999 AND
+ c26 = 9999999999 AND
+ c27 = 0000000001 AND
+ #
+ c28 = '2008-08-04' AND
+ c29 = '2008-08-04 16:18:06' AND
+ c30 = '2008-08-04 16:18:24' AND
+ c31 = '16:18:47' AND
+ c32 = '2008' AND
+ #
+ c33 = 'a' AND
+ c34 = '' AND
+ c35 = 'e' AND
+ c36 = REPEAT('i',255) AND
+ c37 = _utf8 x'c3a4' AND
+ c38 = '' AND
+ c39 = _utf8 x'c3b6' AND
+ c40 = REPEAT(_utf8 x'c3bc',255) AND
+ c41 = _ucs2 x'00e4' AND
+ c42 = '' AND
+ c43 = _ucs2 x'00f6' AND
+ c44 = REPEAT(_ucs2 x'00fc',255) AND
+ #
+ c45 = '' AND
+ c46 = 'a' AND
+ c47 = REPEAT('e',255) AND
+ c48 = REPEAT('i',261) AND
+ c49 = '' AND
+ c50 = _utf8 x'c3a4' AND
+ c51 = REPEAT(_utf8 x'c3b6',255) AND
+ c52 = REPEAT(_utf8 x'c3bc',261) AND
+ c53 = '' AND
+ c54 = _ucs2 x'00e4' AND
+ c55 = REPEAT(_ucs2 x'00f6',255) AND
+ c56 = REPEAT(_ucs2 x'00fc',261) AND
+ #
+ c57 = '0' AND
+ c58 = '' AND
+ c59 = '1' AND
+ c60 = REPEAT('1',255) AND
+ #
+ c61 = '' AND
+ c62 = 'b' AND
+ c63 = REPEAT('c',255) AND
+ c64 = REPEAT('\'',261) AND
+ #
+ c65 = 'tinyblob' AND
+ c66 = 'tinytext' AND
+ c67 = 'tinytext-ucs2' AND
+ c68 = 'blob' AND
+ c69 = 'text' AND
+ c70 = 'text-ucs2' AND
+ c71 = 'mediumblob' AND
+ c72 = 'mediumtext' AND
+ c73 = 'mediumtext-ucs2' AND
+ c74 = 'longblob' AND
+ c75 = 'longtext' AND
+ c76 = 'longtext-ucs2' AND
+ #
+ c77 = 'b' AND
+ c78 = 'b,c' AND
+ #
+ crn = 3;
+
+--echo #
+--echo # Delete the row that has NULL values now.
+--echo #
+DELETE FROM t1 WHERE
+ #
+ c01 IS NULL AND
+ c02 IS NULL AND
+ c03 IS NULL AND
+ c04 IS NULL AND
+ c05 IS NULL AND
+ c06 IS NULL AND
+ c07 IS NULL AND
+ c08 IS NULL AND
+ c09 IS NULL AND
+ c10 IS NULL AND
+ c11 IS NULL AND
+ c12 IS NULL AND
+ c13 IS NULL AND
+ c14 IS NULL AND
+ c15 IS NULL AND
+ c16 IS NULL AND
+ c17 IS NULL AND
+ c18 IS NULL AND
+ c19 IS NULL AND
+ c20 IS NULL AND
+ c21 IS NULL AND
+ c22 IS NULL AND
+ c23 IS NULL AND
+ c24 IS NULL AND
+ c25 IS NULL AND
+ c26 IS NULL AND
+ c27 IS NULL AND
+ #
+ c28 IS NULL AND
+ c29 IS NULL AND
+ # this got a timestamp instead of NULL: c30 IS NULL AND
+ c31 IS NULL AND
+ c32 IS NULL AND
+ #
+ c33 IS NULL AND
+ c34 IS NULL AND
+ c35 IS NULL AND
+ c36 IS NULL AND
+ c37 IS NULL AND
+ c38 IS NULL AND
+ c39 IS NULL AND
+ c40 IS NULL AND
+ c41 IS NULL AND
+ c42 IS NULL AND
+ c43 IS NULL AND
+ c44 IS NULL AND
+ #
+ c45 IS NULL AND
+ c46 IS NULL AND
+ c47 IS NULL AND
+ c48 IS NULL AND
+ c49 IS NULL AND
+ c50 IS NULL AND
+ c51 IS NULL AND
+ c52 IS NULL AND
+ c53 IS NULL AND
+ c54 IS NULL AND
+ c55 IS NULL AND
+ c56 IS NULL AND
+ #
+ c57 IS NULL AND
+ c58 IS NULL AND
+ c59 IS NULL AND
+ c60 IS NULL AND
+ #
+ c61 IS NULL AND
+ c62 IS NULL AND
+ c63 IS NULL AND
+ c64 IS NULL AND
+ #
+ c65 IS NULL AND
+ c66 IS NULL AND
+ c67 IS NULL AND
+ c68 IS NULL AND
+ c69 IS NULL AND
+ c70 IS NULL AND
+ c71 IS NULL AND
+ c72 IS NULL AND
+ c73 IS NULL AND
+ c74 IS NULL AND
+ c75 IS NULL AND
+ c76 IS NULL AND
+ #
+ c77 IS NULL AND
+ c78 IS NULL AND
+ #
+ crn = 4;
+
+--echo #
+--echo # Show what we have in the table. Should be empty now.
+--echo #
+query_vertical SELECT * FROM t1;
+
+--echo #
+--echo # Hide how much rows are affected by each statement.
+--echo #
+--disable_info
+
+--echo #
+--echo # Flush all log buffers to the log file.
+--echo #
+FLUSH LOGS;
+
+--echo #
+--echo # Call mysqlbinlog to display the log file contents.
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/ /exec_time=[0-9]*/exec_time=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /(@[0-9]*=[0-9-]*[.][0-9]{1,3})[0-9e+-]*[^ ]*[ ]*(.*(FLOAT|DOUBLE).*[*].)/\1... \2/
+--exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/master-bin.000001
+
+--echo #
+--echo # Cleanup.
+--echo #
+DROP TABLE t1;
+
+--echo #
+--echo # =========================================
+--echo # Test #2 - Multi-row insert/update/delete.
+--echo # =========================================
+--echo #
+--echo # Delete all existing binary logs.
+--echo #
+RESET MASTER;
+
+--echo #
+--echo # Create a test table with selected data types.
+--echo #
+eval CREATE TABLE t1 (
+ c28 DATE,
+ c47 VARCHAR(24),
+ crn INT -- row number
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+
+--echo #
+--echo # Show how much rows are affected by each statement.
+--echo #
+--enable_info
+
+--echo #
+--echo # Multi-row insert.
+--echo #
+INSERT INTO t1 VALUES
+ ('2008-08-01','VARCHAR-01',1),
+ ('2008-08-02','VARCHAR-02',2),
+ ('2008-08-03','VARCHAR-03',3),
+ ('2008-08-04','VARCHAR-04',4),
+ ('2008-08-05','VARCHAR-05',5),
+ ('2008-08-06','VARCHAR-06',6),
+ ('2008-08-07','VARCHAR-07',7),
+ ('2008-08-08','VARCHAR-08',8),
+ ('2008-08-09','VARCHAR-09',9);
+
+--echo #
+--echo # Multi-row update.
+--echo #
+UPDATE t1 SET c28 = ADDDATE(c28,10) WHERE crn < 8;
+
+--echo #
+--echo # Show what we have in the table.
+--echo #
+SELECT * FROM t1;
+
+--echo #
+--echo # Multi-row delete.
+--echo #
+DELETE FROM t1 WHERE crn < 8;
+
+--echo #
+--echo # Show what we have in the table.
+--echo #
+SELECT * FROM t1;
+
+--echo #
+--echo # Hide how much rows are affected by each statement.
+--echo #
+--disable_info
+
+--echo #
+--echo # Flush all log buffers to the log file.
+--echo #
+FLUSH LOGS;
+
+--echo #
+--echo # Call mysqlbinlog to display the log file contents.
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/ /exec_time=[0-9]*/exec_time=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /(@[0-9]*=[0-9-]*[.][0-9]{1,3})[0-9e+-]*[^ ]*[ ]*(.*(FLOAT|DOUBLE).*[*].)/\1... \2/
+--exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/master-bin.000001
+
+--echo #
+--echo # Cleanup.
+--echo #
+DROP TABLE t1;
+
+--echo #
+--echo # ====================================
+--echo # Test #3 - Multi-table update/delete.
+--echo # ====================================
+--echo #
+--echo # Delete all existing binary logs.
+--echo #
+RESET MASTER;
+
+--echo #
+--echo # Create test tables with selected data types.
+--echo #
+eval CREATE TABLE t1 (
+ c_1_1 DATE,
+ c_1_2 VARCHAR(255),
+ c_1_n INT -- row number
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+#
+eval CREATE TABLE t2 (
+ c_2_1 DATE,
+ c_2_2 VARCHAR(255),
+ c_2_n INT -- row number
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+#
+eval CREATE TABLE t3 (
+ c_3_1 DATE,
+ c_3_2 VARCHAR(255),
+ c_3_n INT -- row number
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+
+--echo #
+--echo # Show how much rows are affected by each statement.
+--echo #
+--enable_info
+
+--echo #
+--echo # Insert data.
+--echo #
+INSERT INTO t1 VALUES
+ ('2008-01-01','VARCHAR-01-01',11),
+ ('2008-01-02','VARCHAR-01-02',2),
+ ('2008-01-03','VARCHAR-01-03',3),
+ ('2008-01-04','VARCHAR-01-04',4),
+ ('2008-01-05','VARCHAR-01-05',5),
+ ('2008-01-06','VARCHAR-01-06',6),
+ ('2008-01-07','VARCHAR-01-07',7),
+ ('2008-01-08','VARCHAR-01-08',18),
+ ('2008-01-09','VARCHAR-01-09',19);
+#
+INSERT INTO t2 VALUES
+ ('2008-02-01','VARCHAR-02-01',21),
+ ('2008-02-02','VARCHAR-02-02',2),
+ ('2008-02-03','VARCHAR-02-03',3),
+ ('2008-02-04','VARCHAR-02-04',4),
+ ('2008-02-05','VARCHAR-02-05',5),
+ ('2008-02-06','VARCHAR-02-06',6),
+ ('2008-02-07','VARCHAR-02-07',7),
+ ('2008-02-08','VARCHAR-02-08',28),
+ ('2008-02-09','VARCHAR-02-09',29);
+#
+INSERT INTO t3 VALUES
+ ('2008-03-01','VARCHAR-03-01',31),
+ ('2008-03-02','VARCHAR-03-02',2),
+ ('2008-03-03','VARCHAR-03-03',3),
+ ('2008-03-04','VARCHAR-03-04',4),
+ ('2008-03-05','VARCHAR-03-05',5),
+ ('2008-03-06','VARCHAR-03-06',6),
+ ('2008-03-07','VARCHAR-03-07',7),
+ ('2008-03-08','VARCHAR-03-08',38),
+ ('2008-03-09','VARCHAR-03-09',39);
+
+--echo #
+--echo # Multi-table update.
+--echo #
+UPDATE t1,t2,t3 SET
+ c_1_1 = ADDDATE(c_1_1,INTERVAL 10 YEAR),
+ c_2_1 = ADDDATE(c_2_1,INTERVAL 20 YEAR),
+ c_3_1 = ADDDATE(c_3_1,INTERVAL 30 YEAR)
+ WHERE c_1_n = c_2_n AND c_2_n = c_3_n;
+
+--echo #
+--echo # Show what we have in the tables.
+--echo #
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+
+--echo #
+--echo # Multi-table delete.
+--echo #
+DELETE FROM t1,t2,t3 USING t1 INNER JOIN t2 INNER JOIN t3
+ WHERE c_1_n = c_2_n AND c_2_n = c_3_n;
+
+--echo #
+--echo # Show what we have in the tables.
+--echo #
+SELECT * FROM t1;
+SELECT * FROM t2;
+SELECT * FROM t3;
+
+--echo #
+--echo # Hide how much rows are affected by each statement.
+--echo #
+--disable_info
+
+--echo #
+--echo # Flush all log buffers to the log file.
+--echo #
+FLUSH LOGS;
+
+--echo #
+--echo # Call mysqlbinlog to display the log file contents.
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/ /exec_time=[0-9]*/exec_time=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /(@[0-9]*=[0-9-]*[.][0-9]{1,3})[0-9e+-]*[^ ]*[ ]*(.*(FLOAT|DOUBLE).*[*].)/\1... \2/
+--exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/master-bin.000001
+
+--echo #
+--echo # Cleanup.
+--echo #
+DROP TABLE t1, t2, t3;
+
+--echo #
+--echo # ===========================
+--echo # Test #4 - LOAD DATA INFILE.
+--echo # ===========================
+--echo #
+--echo # Delete all existing binary logs.
+--echo #
+RESET MASTER;
+
+--echo #
+--echo # Create a test table with selected data types.
+--echo #
+eval CREATE TABLE t1 (
+ c1 INT DEFAULT 100,
+ c2 INT,
+ c3 VARCHAR(60)
+ ) ENGINE=$engine_type DEFAULT CHARSET latin1;
+
+--echo #
+--echo # Show how much rows are affected by each statement.
+--echo #
+--enable_info
+
+--echo #
+--echo # Load data.
+--echo #
+LOAD DATA INFILE '../../std_data/loaddata5.dat'
+ INTO TABLE t1 FIELDS TERMINATED BY '' ENCLOSED BY '' (c1,c2)
+ SET c3 = 'Wow';
+
+--echo #
+--echo # Show what we have in the table.
+--echo #
+SELECT * FROM t1;
+
+--echo #
+--echo # Hide how much rows are affected by each statement.
+--echo #
+--disable_info
+
+--echo #
+--echo # Flush all log buffers to the log file.
+--echo #
+FLUSH LOGS;
+
+--echo #
+--echo # Call mysqlbinlog to display the log file contents.
+--echo #
+let $MYSQLD_DATADIR= `select @@datadir`;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/ /exec_time=[0-9]*/exec_time=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /(@[0-9]*=[0-9-]*[.][0-9]{1,3})[0-9e+-]*[^ ]*[ ]*(.*(FLOAT|DOUBLE).*[*].)/\1... \2/
+--exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/master-bin.000001
+
+--echo #
+--echo # Cleanup.
+--echo #
+DROP TABLE t1;
+
+
diff --git a/mysql-test/include/mysqltest-x.inc b/mysql-test/include/mysqltest-x.inc
index dd1468aed07..797c5c39f3f 100644
--- a/mysql-test/include/mysqltest-x.inc
+++ b/mysql-test/include/mysqltest-x.inc
@@ -1,2 +1,3 @@
echo Output from mysqltest-x.inc;
+exit;
diff --git a/mysql-test/include/ndb_backup.inc b/mysql-test/include/ndb_backup.inc
index 3239030bb64..ea56d79cbba 100644
--- a/mysql-test/include/ndb_backup.inc
+++ b/mysql-test/include/ndb_backup.inc
@@ -9,23 +9,21 @@
# resolved
--source include/not_windows.inc
---exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT
+--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "start backup" >> $NDB_TOOLS_OUTPUT
# there is no neat way to find the backupid, this is a hack to find it...
+let $dump_file= $MYSQLTEST_VARDIR/tmp/tmp.dat;
+--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="$NDB_CONNECTSTRING" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $dump_file
---exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat
+CREATE TEMPORARY TABLE test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
-CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
+--replace_result $dump_file DUMP_FILE
+eval LOAD DATA INFILE '$dump_file' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
-DELETE FROM test.backup_info;
-
-LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
-
---replace_column 1 <the_backup_id>
-
-SELECT @the_backup_id:=backup_id FROM test.backup_info;
+# Load backup id into environment variable
+let the_backup_id=`SELECT backup_id from test.backup_info`;
+DROP TABLE test.backup_info;
-let the_backup_id=`select @the_backup_id`;
+remove_file $dump_file;
-DROP TABLE test.backup_info;
diff --git a/mysql-test/include/ndb_master-slave.inc b/mysql-test/include/ndb_master-slave.inc
new file mode 100644
index 00000000000..0bf4b701f0c
--- /dev/null
+++ b/mysql-test/include/ndb_master-slave.inc
@@ -0,0 +1,20 @@
+# Replication tests need binlog
+source include/have_log_bin.inc;
+
+connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
+connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT,);
+connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
+connect (slave1,127.0.0.1,root,,test,$SLAVE_MYPORT,);
+
+connection slave;
+# Check that server is compiled and started with support for NDB
+disable_query_log;
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+enable_query_log;
+
+-- source include/master-slave-reset.inc
+
+# Set the default connection to 'master'
+connection master;
diff --git a/mysql-test/include/ndb_master-slave_2ch.inc b/mysql-test/include/ndb_master-slave_2ch.inc
new file mode 100644
index 00000000000..52a06c01d86
--- /dev/null
+++ b/mysql-test/include/ndb_master-slave_2ch.inc
@@ -0,0 +1,136 @@
+#############################################################
+# Author: Serge Kozlov <skozlov@mysql.com>
+# Date: 03/17/2008
+# Purpose: Set up circular cluster replication where each
+# cluster has two mysqlds and replication directions are
+# following:
+# master ---> slave
+# / \
+# cluster A cluster B
+# \ /
+# master1 <--- slave1
+#############################################################
+
+--source include/have_log_bin.inc
+
+# Make connections to mysqlds
+
+connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
+connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT1,);
+connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
+connect (slave1,127.0.0.1,root,,test,$SLAVE_MYPORT1,);
+
+# Check that all mysqld compiled with ndb support
+
+--connection master
+--disable_query_log
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT') AS `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+--enable_query_log
+
+--connection master1
+--disable_query_log
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT') AS `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+--enable_query_log
+
+--connection slave
+--disable_query_log
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT') AS `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+--enable_query_log
+
+--connection slave1
+--disable_query_log
+--require r/true.require
+SELECT (support = 'YES' or support = 'DEFAULT') AS `TRUE` FROM information_schema.engines WHERE engine = 'ndbcluster';
+--source include/ndb_not_readonly.inc
+--enable_query_log
+
+# Stop slaves
+
+--connection master
+--disable_warnings
+STOP SLAVE;
+--wait_for_slave_to_stop
+--enable_warnings
+
+--connection master1
+--disable_warnings
+STOP SLAVE;
+--wait_for_slave_to_stop
+--enable_warnings
+
+--connection slave
+--disable_warnings
+STOP SLAVE;
+--wait_for_slave_to_stop
+--enable_warnings
+
+--connection slave1
+--disable_warnings
+STOP SLAVE;
+--wait_for_slave_to_stop
+--enable_warnings
+
+# Reset masters
+
+--connection master
+--disable_warnings
+--disable_query_log
+USE test;
+--enable_query_log
+DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+RESET MASTER;
+
+--connection master1
+--disable_warnings
+--disable_query_log
+USE test;
+--enable_query_log
+DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+RESET MASTER;
+
+--connection slave
+--disable_warnings
+--disable_query_log
+USE test;
+--enable_query_log
+DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+RESET MASTER;
+
+--connection slave1
+--disable_warnings
+--disable_query_log
+USE test;
+--enable_query_log
+DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9;
+--enable_warnings
+RESET MASTER;
+
+# Start slaves
+
+--connection slave
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_MYPORT
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$MASTER_MYPORT,master_user='root'
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+
+--connection master1
+RESET SLAVE;
+--replace_result $SLAVE_MYPORT1 SLAVE_MYPORT1
+--eval CHANGE MASTER TO master_host='127.0.0.1',master_port=$SLAVE_MYPORT1,master_user='root'
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
+
+
+# Set the default connection to 'master' (cluster A)
+connection master;
+
diff --git a/mysql-test/include/ndb_not_readonly.inc b/mysql-test/include/ndb_not_readonly.inc
new file mode 100644
index 00000000000..f50ca0cab66
--- /dev/null
+++ b/mysql-test/include/ndb_not_readonly.inc
@@ -0,0 +1,30 @@
+# Check that server has come out ot readonly mode
+#
+# wait for server to connect properly to cluster
+#
+set @saved_log = @@sql_log_bin;
+set sql_log_bin = 0;
+--error 0,ER_NO_SUCH_TABLE,ER_OPEN_AS_READONLY,ER_GET_ERRMSG,ER_KEY_NOT_FOUND
+delete from mysql.ndb_apply_status where server_id=0;
+let $mysql_errno= 1;
+let $counter= 600;
+while ($mysql_errno)
+{
+ # Table is readonly until the mysqld has connected properly
+ --error 0,ER_NO_SUCH_TABLE,ER_OPEN_AS_READONLY,ER_GET_ERRMSG
+ replace into mysql.ndb_apply_status values(0,0,"",0,0);
+ if ($mysql_errno)
+ {
+ if (!$counter)
+ {
+ die Failed while waiting for mysqld to come out of readonly mode;
+ }
+ dec $counter;
+ --sleep 0.1
+ }
+}
+delete from mysql.ndb_apply_status where server_id=0;
+set sql_log_bin = @saved_log;
+#
+# connected
+#
diff --git a/mysql-test/include/ndb_restore_master.inc b/mysql-test/include/ndb_restore_master.inc
new file mode 100644
index 00000000000..ae5f055b442
--- /dev/null
+++ b/mysql-test/include/ndb_restore_master.inc
@@ -0,0 +1,8 @@
+######################################################
+# By JBM 2006-02-16 So that the code is not repeated #
+# in test cases and can be reused. #
+######################################################
+
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
diff --git a/mysql-test/include/ndb_restore_slave_eoption.inc b/mysql-test/include/ndb_restore_slave_eoption.inc
new file mode 100644
index 00000000000..a8657f68c8d
--- /dev/null
+++ b/mysql-test/include/ndb_restore_slave_eoption.inc
@@ -0,0 +1,11 @@
+######################################################
+# By JBM 2006-03-08 So that the code is not repeated #
+# in test cases and can be reused. #
+######################################################
+
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 2 -r -e --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+
+
diff --git a/mysql-test/include/ndb_setup_slave.inc b/mysql-test/include/ndb_setup_slave.inc
new file mode 100644
index 00000000000..5ee55150550
--- /dev/null
+++ b/mysql-test/include/ndb_setup_slave.inc
@@ -0,0 +1,27 @@
+#
+# now setup replication to continue from last epoch
+# 1. get ndb_apply_status epoch from slave
+# 2. get corresponding _next_ binlog postition from master
+# 3. change master on slave
+
+# 1.
+--connection slave
+--replace_column 1 <the_epoch>
+SELECT @the_epoch:=MAX(epoch) FROM mysql.ndb_apply_status;
+--let $the_epoch= `select @the_epoch`
+
+# 2.
+--connection master
+--replace_result $the_epoch <the_epoch>
+--replace_column 1 <the_pos>
+eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1)
+ FROM mysql.ndb_binlog_index WHERE epoch > $the_epoch ORDER BY epoch ASC LIMIT 1;
+--let $the_pos= `SELECT @the_pos`
+--let $the_file= `SELECT @the_file`
+
+# 3.
+--connection slave
+--replace_result $the_pos <the_pos>
+eval CHANGE MASTER TO
+ master_log_file = '$the_file',
+ master_log_pos = $the_pos ;
diff --git a/mysql-test/include/no_running_event_scheduler.inc b/mysql-test/include/no_running_event_scheduler.inc
new file mode 100644
index 00000000000..92813df9f96
--- /dev/null
+++ b/mysql-test/include/no_running_event_scheduler.inc
@@ -0,0 +1,23 @@
+########## include/no_running_event_scheduler.inc ##########################
+# #
+# Wait till the event scheduler disappeared from processlist. #
+# #
+# The characteristics of the event_scheduler entry within the processlist is #
+# user = 'event_scheduler' and command = 'Daemon'. I am not 100% sure if #
+# ther is no short phase with command <> 'Daemon'. #
+# A query with WHERE user = 'event_scheduler' only will also catch events in #
+# startup phase. This is no problem since this phase is very short. #
+# #
+# A wait_timeout of >= 3 seconds was within experiments sufficient even on a #
+# testing box with heavy parallel load. Therefore 5 seconds should be enough. #
+# #
+# Creation: #
+# 2008-12-19 mleich Implement this check needed for test bug fixes #
+# #
+################################################################################
+
+let $wait_timeout= 5;
+let $wait_condition=
+ SELECT COUNT(*) = 0 FROM information_schema.processlist
+ WHERE user = 'event_scheduler';
+--source include/wait_condition.inc
diff --git a/mysql-test/include/no_running_events.inc b/mysql-test/include/no_running_events.inc
new file mode 100644
index 00000000000..8090b2706b8
--- /dev/null
+++ b/mysql-test/include/no_running_events.inc
@@ -0,0 +1,25 @@
+########## include/no_running_events.inc ###################################
+# #
+# Wait till all event executors have finished their work. #
+# #
+# Different event executors share the characteristics that their entry within #
+# processlist contains command = 'Connect'. #
+# Of course the corresponding query will also catch other connections being #
+# within the connect phase. This is no problem since the connect phase is #
+# usually very short. #
+# #
+# A wait_timeout of >= 3 seconds was during experiments in case of "simple" #
+# SQL commands sufficient even on a testing box with heavy parallel load. #
+# "simple" = no sleeps, no long running commands, no waiting for lock ... #
+# We use here the default of 30 seconds because this wastes some time only in #
+# case of unexpected situations. #
+# #
+# Creation: #
+# 2008-12-19 mleich Implement this check needed for test bug fixes #
+# #
+################################################################################
+
+let $wait_condition=
+ SELECT COUNT(*) = 0 FROM information_schema.processlist
+ WHERE command = 'Connect';
+--source include/wait_condition.inc
diff --git a/mysql-test/include/not_as_root.inc b/mysql-test/include/not_as_root.inc
index e0277ea593e..6c88051d632 100644
--- a/mysql-test/include/not_as_root.inc
+++ b/mysql-test/include/not_as_root.inc
@@ -1,4 +1,3 @@
--- require r/not_as_root.require
-disable_query_log;
-eval select "$MYSQL_TEST_ROOT" as running_as_root;
-enable_query_log;
+if ($MYSQL_TEST_ROOT){
+ skip Not as root;
+}
diff --git a/mysql-test/include/not_embedded.inc b/mysql-test/include/not_embedded.inc
index fcc1756caab..360f268ad4f 100644
--- a/mysql-test/include/not_embedded.inc
+++ b/mysql-test/include/not_embedded.inc
@@ -1,5 +1,5 @@
-- require r/not_embedded.require
disable_query_log;
-select version() like N'%embedded%' as 'have_embedded';
+select version() like '%embedded%' as 'have_embedded';
enable_query_log;
diff --git a/mysql-test/include/not_ndb.inc b/mysql-test/include/not_ndb.inc
new file mode 100644
index 00000000000..965538c20a7
--- /dev/null
+++ b/mysql-test/include/not_ndb.inc
@@ -0,0 +1,7 @@
+-- require r/not_ndb.require
+disable_query_log;
+# so that both DISABLED and NO is output as NO
+-- replace_result DISABLED NO
+show variables like "have_ndbcluster";
+enable_query_log;
+
diff --git a/mysql-test/include/not_ndb_default.inc b/mysql-test/include/not_ndb_default.inc
new file mode 100644
index 00000000000..ca3c57a671a
--- /dev/null
+++ b/mysql-test/include/not_ndb_default.inc
@@ -0,0 +1,4 @@
+--require r/not_ndb_default.require
+disable_query_log;
+select convert(@@table_type using latin1) NOT IN ("ndbcluster","NDBCLUSTER") as "TRUE";
+enable_query_log;
diff --git a/mysql-test/include/not_valgrind.inc b/mysql-test/include/not_valgrind.inc
new file mode 100644
index 00000000000..bdddaf534ca
--- /dev/null
+++ b/mysql-test/include/not_valgrind.inc
@@ -0,0 +1,4 @@
+--require r/not_valgrind.require
+--disable_query_log
+eval select $VALGRIND_TEST as using_valgrind;
+--enable_query_log
diff --git a/mysql-test/include/not_windows.inc b/mysql-test/include/not_windows.inc
index 54e9e0e817a..9240271077a 100644
--- a/mysql-test/include/not_windows.inc
+++ b/mysql-test/include/not_windows.inc
@@ -1,4 +1,4 @@
---require r/true.require
+--require r/not_windows.require
disable_query_log;
select convert(@@version_compile_os using latin1) NOT IN ("Win32","Win64","Windows") as "TRUE";
enable_query_log;
diff --git a/mysql-test/include/one_thread_per_connection.inc b/mysql-test/include/one_thread_per_connection.inc
new file mode 100644
index 00000000000..4b38800733b
--- /dev/null
+++ b/mysql-test/include/one_thread_per_connection.inc
@@ -0,0 +1,5 @@
+-- require r/one_thread_per_connection.require
+disable_query_log;
+select @@thread_handling;
+enable_query_log;
+
diff --git a/mysql-test/include/parser_bug21114.inc b/mysql-test/include/parser_bug21114.inc
new file mode 100755
index 00000000000..eb709d5cc03
--- /dev/null
+++ b/mysql-test/include/parser_bug21114.inc
@@ -0,0 +1,59 @@
+#
+# Bug#21114 (Foreign key creation fails to table with name format)
+#
+# Trying to trick the parser into thinking $FCT(...) is a function call,
+# which is not in the CREATE TABLE and FOREIGN KEY ... REFERENCES syntax
+#
+# Usage :
+#
+# let $engine_type=InnoDb;
+# let $verbose=1;
+# let $FCT= <value_1>;
+# -- source parser_stress_func.inc
+# let $FCT= <value_2>;
+# -- source parser_stress_func.inc
+# let $verbose=0;
+# let $FCT= <value_3>;
+# -- source parser_stress_func.inc
+# let $FCT= <value_4>;
+# -- source parser_stress_func.inc
+
+-- disable_warnings
+eval drop table if exists $FCT;
+drop table if exists bug21114_child;
+-- enable_warnings
+
+--disable_query_log
+--disable_result_log
+
+eval CREATE TABLE $FCT(
+ col1 int not null,
+ col2 int not null,
+ col3 varchar(10),
+ CONSTRAINT pk PRIMARY KEY (col1, col2)
+) ENGINE $engine_type;
+
+eval CREATE TABLE bug21114_child(
+ pk int not null,
+ fk_col1 int not null,
+ fk_col2 int not null,
+ fk_col3 int not null,
+ fk_col4 int not null,
+ CONSTRAINT fk_fct FOREIGN KEY (fk_col1, fk_col2)
+ REFERENCES $FCT(col1, col2),
+ CONSTRAINT fk_fct_space FOREIGN KEY (fk_col3, fk_col4)
+ REFERENCES $FCT (col1, col2)
+) ENGINE $engine_type;
+
+--enable_query_log
+--enable_result_log
+
+if ($verbose)
+{
+ eval SHOW CREATE TABLE $FCT;
+ SHOW CREATE TABLE bug21114_child;
+}
+
+DROP TABLE bug21114_child;
+eval DROP TABLE $FCT;
+
diff --git a/mysql-test/include/ps_ddl_1.inc b/mysql-test/include/ps_ddl_1.inc
new file mode 100644
index 00000000000..f6b4c8108a1
--- /dev/null
+++ b/mysql-test/include/ps_ddl_1.inc
@@ -0,0 +1,25 @@
+# include/ps_ddl_1.inc
+#
+# Auxiliary script to be used in ps_ddl.test
+#
+
+prepare stmt_sf from 'select f_12093();';
+prepare stmt_sp from 'call p_12093(f_12093())';
+execute stmt_sf;
+execute stmt_sp;
+
+connection con1;
+eval $my_drop;
+#
+connection default;
+--echo # XXX: used to be a bug
+execute stmt_sf;
+--echo # XXX: used to be a bug
+execute stmt_sp;
+#
+--echo # XXX: used to be a bug
+execute stmt_sf;
+--echo # XXX: used to be a bug
+execute stmt_sp;
+
+connection default;
diff --git a/mysql-test/include/ps_modify.inc b/mysql-test/include/ps_modify.inc
index 633c317f4b2..f66f888261d 100644
--- a/mysql-test/include/ps_modify.inc
+++ b/mysql-test/include/ps_modify.inc
@@ -193,7 +193,7 @@ prepare stmt1 from 'insert into t1 values(6, ? )';
execute stmt1 using @arg00;
select a,b from t1 where b = @arg00;
# the second insert fails, because the first column is primary key
---error 1062
+--error ER_DUP_ENTRY
execute stmt1 using @arg00;
set @arg00=NULL ;
prepare stmt1 from 'insert into t1 values(0, ? )';
@@ -272,7 +272,7 @@ execute stmt1 using @arg00, @arg01;
select * from t1 order by a;
set @arg00=81 ;
set @arg01=1 ;
---error 1062
+--error ER_DUP_ENTRY
execute stmt1 using @arg00, @arg01;
## insert, autoincrement column and ' SELECT LAST_INSERT_ID() '
diff --git a/mysql-test/include/query_cache.inc b/mysql-test/include/query_cache.inc
new file mode 100644
index 00000000000..77ea0021a5d
--- /dev/null
+++ b/mysql-test/include/query_cache.inc
@@ -0,0 +1,182 @@
+# include/query_cache.inc
+#
+# The variables
+# $engine_type -- storage engine to be tested
+# $test_foreign_keys -- 0, skip foreign key tests
+# -- 1, do not skip foreign key tests
+# have to be set before sourcing this script.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was innodb_cache.test
+# main code went into include/query_cache.inc
+#
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+# Initialise
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+
+#
+# Without auto_commit.
+#
+flush status;
+set autocommit=0;
+create table t1 (a int not null);
+insert into t1 values (1),(2),(3);
+select * from t1;
+show status like "Qcache_queries_in_cache";
+drop table t1;
+commit;
+set autocommit=1;
+begin;
+create table t1 (a int not null);
+insert into t1 values (1),(2),(3);
+select * from t1;
+show status like "Qcache_queries_in_cache";
+drop table t1;
+commit;
+create table t1 (a int not null);
+create table t2 (a int not null);
+create table t3 (a int not null);
+insert into t1 values (1),(2);
+insert into t2 values (1),(2);
+insert into t3 values (1),(2);
+select * from t1;
+select * from t2;
+select * from t3;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+begin;
+select * from t1;
+select * from t2;
+select * from t3;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+insert into t1 values (3);
+insert into t2 values (3);
+insert into t1 values (4);
+select * from t1;
+select * from t2;
+select * from t3;
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+commit;
+show status like "Qcache_queries_in_cache";
+drop table t3,t2,t1;
+
+CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id));
+select count(*) from t1;
+insert into t1 (id) values (0);
+select count(*) from t1;
+drop table t1;
+
+if ($test_foreign_keys)
+{
+#
+# one statement roll back inside transation
+#
+let $save_query_cache_size=`select @@global.query_cache_size`;
+set GLOBAL query_cache_size=1355776;
+CREATE TABLE t1 ( id int(10) NOT NULL auto_increment, a varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY a (a));
+CREATE TABLE t2 ( id int(10) NOT NULL auto_increment, b varchar(25) default NULL, PRIMARY KEY (id), UNIQUE KEY b (b));
+CREATE TABLE t3 ( id int(10) NOT NULL auto_increment, t1_id int(10) NOT NULL default '0', t2_id int(10) NOT NULL default '0', state int(11) default NULL, PRIMARY KEY (id), UNIQUE KEY t1_id (t1_id,t2_id), KEY t2_id (t2_id,t1_id), CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`), CONSTRAINT `t3_ibfk_2` FOREIGN KEY (`t2_id`) REFERENCES `t2` (`id`));
+INSERT INTO t1 VALUES (1,'me');
+INSERT INTO t2 VALUES (1,'you');
+INSERT INTO t3 VALUES (2,1,1,2);
+delete from t3 where t1_id = 1 and t2_id = 1;
+select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc;
+begin;
+insert into t3 VALUES ( NULL, 1, 1, 2 );
+-- error ER_DUP_ENTRY
+insert into t3 VALUES ( NULL, 1, 1, 2 );
+commit;
+select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc;
+drop table t3,t2,t1;
+--disable_query_log
+eval set GLOBAL query_cache_size=$save_query_cache_size;
+--enable_query_log
+}
+
+#
+# Test query cache with two interleaving transactions
+#
+
+# Establish connection1
+connect (connection1,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+SET @@autocommit=1;
+
+connection default;
+--echo connection default
+# This should be 'YES'.
+SHOW VARIABLES LIKE 'have_query_cache';
+
+SET GLOBAL query_cache_size = 200000;
+flush status;
+SET @@autocommit=1;
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+CREATE TABLE t2 (s1 int, s2 varchar(1000), key(s1));
+INSERT INTO t2 VALUES (1,repeat('a',10)),(2,repeat('a',10)),(3,repeat('a',10)),(4,repeat('a',10));
+COMMIT;
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+UPDATE t2 SET s2 = 'w' WHERE s1 = 3;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+show status like "Qcache_queries_in_cache";
+
+connection connection1;
+--echo connection connection1
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+INSERT INTO t2 VALUES (5,'w');
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+COMMIT;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+
+show status like "Qcache_queries_in_cache";
+
+connection default;
+--echo connection default
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+COMMIT;
+
+show status like "Qcache_queries_in_cache";
+
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+show status like "Qcache_queries_in_cache";
+
+connection connection1;
+--echo connection connection1
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+INSERT INTO t2 VALUES (6,'w');
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+
+connection default;
+--echo connection default
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+START TRANSACTION;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+DELETE from t2 WHERE s1=3;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+COMMIT;
+
+connection connection1;
+--echo connection connection1
+
+COMMIT;
+SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
+
+show status like "Qcache_queries_in_cache";
+show status like "Qcache_hits";
+
+# Final cleanup
+eval set GLOBAL query_cache_size=$save_query_cache_size;
+connection default;
+drop table t2;
+disconnect connection1;
diff --git a/mysql-test/include/query_cache_sql_prepare.inc b/mysql-test/include/query_cache_sql_prepare.inc
new file mode 100644
index 00000000000..1842d5412bb
--- /dev/null
+++ b/mysql-test/include/query_cache_sql_prepare.inc
@@ -0,0 +1,497 @@
+############### include/query_cache_sql_prepare.inc ################
+#
+# This is to see how statements prepared via the PREPARE SQL command
+# go into the query cache: if using parameters they cannot; if not
+# using parameters they can.
+# Query cache is abbreviated as "QC"
+#
+# Last update:
+# 2007-05-03 ML - Move t/query_cache_sql_prepare.test
+# to include/query_cache_sql_prepare.inc
+# - Create two toplevel tests sourcing this routine
+# - Add tests checking that
+# - another connection gets the same amount of QC hits
+# - statements running via ps-protocol do not hit QC results
+# of preceding sql EXECUTEs
+#
+
+--source include/have_query_cache.inc
+# embedded can't make more than one connection, which this test needs
+-- source include/not_embedded.inc
+
+--echo ---- establish connection con1 (root) ----
+connect (con1,localhost,root,,test,$MASTER_MYPORT,);
+--echo ---- switch to connection default ----
+connection default;
+
+set @initial_query_cache_size = @@global.query_cache_size;
+set @@global.query_cache_size=100000;
+flush status;
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1(c1 int);
+insert into t1 values(1),(10),(100);
+
+# First, prepared statements with no parameters
+prepare stmt1 from "select * from t1 where c1=10";
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+# Another prepared statement (same text, same connection), should hit the QC
+prepare stmt2 from "select * from t1 where c1=10";
+execute stmt2;
+show status like 'Qcache_hits';
+execute stmt2;
+show status like 'Qcache_hits';
+execute stmt2;
+show status like 'Qcache_hits';
+# Another prepared statement (same text, other connection), should hit the QC
+--echo ---- switch to connection con1 ----
+connection con1;
+prepare stmt3 from "select * from t1 where c1=10";
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+
+# Mixup tests, where statements without PREPARE.../EXECUTE.... meet statements
+# with PREPARE.../EXECUTE.... (text protocol). Both statements have the
+# same text. QC hits occur only when both statements use the same protocol.
+# The outcome of the test depends on the mysqltest startup options
+# - with "--ps-protocol"
+# Statements without PREPARE.../EXECUTE.... run as prepared statements
+# with binary protocol. Expect to get no QC hits.
+# - without any "--<whatever>-protocol"
+# Statements without PREPARE.../EXECUTE run as non prepared statements
+# with text protocol. Expect to get QC hits.
+############################################################################
+#
+# Statement with PREPARE.../EXECUTE.... first
+let $my_stmt= SELECT * FROM t1 WHERE c1 = 100;
+eval prepare stmt10 from "$my_stmt";
+show status like 'Qcache_hits';
+execute stmt10;
+show status like 'Qcache_hits';
+execute stmt10;
+show status like 'Qcache_hits';
+eval $my_stmt;
+show status like 'Qcache_hits';
+--echo ---- switch to connection con1 ----
+connection con1;
+eval $my_stmt;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+#
+# Statement without PREPARE.../EXECUTE.... first
+let $my_stmt= SELECT * FROM t1 WHERE c1 = 1;
+eval prepare stmt11 from "$my_stmt";
+--echo ---- switch to connection con1 ----
+connection con1;
+eval prepare stmt12 from "$my_stmt";
+--echo ---- switch to connection default ----
+connection default;
+eval $my_stmt;
+show status like 'Qcache_hits';
+eval $my_stmt;
+show status like 'Qcache_hits';
+execute stmt11;
+show status like 'Qcache_hits';
+--echo ---- switch to connection con1 ----
+connection con1;
+execute stmt12;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+
+# Query caching also works when statement has parameters
+# (BUG#29318 Statements prepared with PREPARE and with one parameter don't use
+# query cache)
+prepare stmt1 from "select * from t1 where c1=?";
+show status like 'Qcache_hits';
+set @a=1;
+execute stmt1 using @a;
+show status like 'Qcache_hits';
+execute stmt1 using @a;
+show status like 'Qcache_hits';
+--echo ---- switch to connection con1 ----
+connection con1;
+set @a=1;
+prepare stmt4 from "select * from t1 where c1=?";
+execute stmt4 using @a;
+show status like 'Qcache_hits';
+# verify that presence of user variables forbids caching
+prepare stmt4 from "select @a from t1 where c1=?";
+execute stmt4 using @a;
+show status like 'Qcache_hits';
+execute stmt4 using @a;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+
+# See if enabling/disabling the query cache between PREPARE and
+# EXECUTE is an issue; the expected result is that the query cache
+# will not be used.
+# Indeed, decision to read/write the query cache is taken at PREPARE
+# time, so if the query cache was disabled at PREPARE time then no
+# execution of the statement will read/write the query cache.
+# If the query cache was enabled at PREPARE time, but disabled at
+# EXECUTE time, at EXECUTE time the query cache internal functions do
+# nothing so again the query cache is not read/written. But if the
+# query cache is re-enabled before another execution then that
+# execution will read/write the query cache.
+
+# QC is enabled at PREPARE
+prepare stmt1 from "select * from t1 where c1=10";
+# then QC is disabled at EXECUTE
+# Expect to see no additional Qcache_hits.
+set global query_cache_size=0;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+# The QC is global = affects also other connections.
+# Expect to see no additional Qcache_hits.
+--echo ---- switch to connection con1 ----
+connection con1;
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+#
+# then QC is re-enabled for more EXECUTE.
+--echo ---- switch to connection default ----
+connection default;
+set global query_cache_size=100000;
+# Expect to see additional Qcache_hits.
+# The fact that the QC was temporary disabled should have no affect
+# except that the first execute will not hit results from the
+# beginning of the test (because QC has been emptied meanwhile by
+# setting its size to 0).
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+# The QC is global = affects also other connections.
+--echo ---- switch to connection con1 ----
+connection con1;
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+#
+# then QC is re-disabled for more EXECUTE.
+# Expect to see no additional Qcache_hits.
+# The fact that the QC was temporary enabled should have no affect.
+set global query_cache_size=0;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+# The QC is global = affects also other connections.
+--echo ---- switch to connection con1 ----
+connection con1;
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+#
+
+--echo ---- switch to connection default ----
+connection default;
+# QC is disabled at PREPARE
+set global query_cache_size=0;
+prepare stmt1 from "select * from t1 where c1=10";
+--echo ---- switch to connection con1 ----
+connection con1;
+prepare stmt3 from "select * from t1 where c1=10";
+--echo ---- switch to connection default ----
+connection default;
+# then QC is enabled at EXECUTE
+set global query_cache_size=100000;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+execute stmt1;
+show status like 'Qcache_hits';
+# The QC is global = affects also other connections.
+--echo ---- switch to connection con1 ----
+connection con1;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+execute stmt3;
+show status like 'Qcache_hits';
+--echo ---- switch to connection default ----
+connection default;
+#
+# QC is disabled at PREPARE
+set global query_cache_size=0;
+prepare stmt1 from "select * from t1 where c1=?";
+# then QC is enabled at EXECUTE
+set global query_cache_size=100000;
+show status like 'Qcache_hits';
+set @a=1;
+execute stmt1 using @a;
+show status like 'Qcache_hits';
+set @a=100;
+execute stmt1 using @a;
+show status like 'Qcache_hits';
+set @a=10;
+execute stmt1 using @a;
+show status like 'Qcache_hits';
+
+
+drop table t1;
+--echo ---- disconnect connection con1 ----
+disconnect con1;
+
+#
+# Bug #25843 Changing default database between PREPARE and EXECUTE of statement
+# breaks binlog.
+#
+# There were actually two problems discovered by this bug:
+#
+# 1. Default (current) database is not fixed at the creation time.
+# That leads to wrong output of DATABASE() function.
+#
+# 2. Database attributes (@@collation_database) are not fixed at the creation
+# time. That leads to wrong resultset.
+#
+# Binlog breakage and Query Cache wrong output happened because of the first
+# problem.
+#
+
+--echo ########################################################################
+--echo #
+--echo # BUG#25843: Changing default database between PREPARE and EXECUTE of
+--echo # statement breaks binlog.
+--echo #
+--echo ########################################################################
+
+###############################################################################
+
+--echo
+--echo #
+--echo # Check that default database and its attributes are fixed at the
+--echo # creation time.
+--echo #
+
+# Prepare data structures.
+
+--echo
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest1;
+DROP DATABASE IF EXISTS mysqltest2;
+--enable_warnings
+
+--echo
+CREATE DATABASE mysqltest1 COLLATE utf8_unicode_ci;
+CREATE DATABASE mysqltest2 COLLATE utf8_general_ci;
+
+--echo
+CREATE TABLE mysqltest1.t1(msg VARCHAR(255));
+CREATE TABLE mysqltest2.t1(msg VARCHAR(255));
+
+# - Create a prepared statement with mysqltest1 as default database;
+
+--echo
+
+use mysqltest1;
+
+PREPARE stmt_a_1 FROM 'INSERT INTO t1 VALUES(DATABASE())';
+PREPARE stmt_a_2 FROM 'INSERT INTO t1 VALUES(@@collation_database)';
+
+# - Execute on mysqltest1.
+
+--echo
+
+EXECUTE stmt_a_1;
+EXECUTE stmt_a_2;
+
+# - Execute on mysqltest2.
+
+--echo
+
+use mysqltest2;
+
+EXECUTE stmt_a_1;
+EXECUTE stmt_a_2;
+
+# - Check the results;
+
+--echo
+SELECT * FROM mysqltest1.t1;
+
+--echo
+SELECT * FROM mysqltest2.t1;
+
+# - Drop prepared statements.
+
+--echo
+DROP PREPARE stmt_a_1;
+DROP PREPARE stmt_a_2;
+
+###############################################################################
+
+--echo
+--echo #
+--echo # The Query Cache test case.
+--echo #
+
+--echo
+DELETE FROM mysqltest1.t1;
+DELETE FROM mysqltest2.t1;
+
+--echo
+INSERT INTO mysqltest1.t1 VALUES('mysqltest1.t1');
+INSERT INTO mysqltest2.t1 VALUES('mysqltest2.t1');
+
+--echo
+use mysqltest1;
+PREPARE stmt_b_1 FROM 'SELECT * FROM t1';
+
+--echo
+use mysqltest2;
+PREPARE stmt_b_2 FROM 'SELECT * FROM t1';
+
+--echo
+EXECUTE stmt_b_1;
+
+--echo
+EXECUTE stmt_b_2;
+
+--echo
+use mysqltest1;
+
+--echo
+EXECUTE stmt_b_1;
+
+--echo
+EXECUTE stmt_b_2;
+
+--echo
+DROP PREPARE stmt_b_1;
+DROP PREPARE stmt_b_2;
+
+# Cleanup.
+
+--echo
+use test;
+
+--echo
+DROP DATABASE mysqltest1;
+DROP DATABASE mysqltest2;
+
+###############################################################################
+
+--echo
+--echo #
+--echo # Check that prepared statements work properly when there is no current
+--echo # database.
+--echo #
+
+--echo
+CREATE DATABASE mysqltest1 COLLATE utf8_unicode_ci;
+CREATE DATABASE mysqltest2 COLLATE utf8_general_ci;
+
+--echo
+use mysqltest1;
+
+--echo
+PREPARE stmt_c_1 FROM 'SELECT DATABASE(), @@collation_database';
+
+--echo
+use mysqltest2;
+
+--echo
+PREPARE stmt_c_2 FROM 'SELECT DATABASE(), @@collation_database';
+
+--echo
+DROP DATABASE mysqltest2;
+
+--echo
+SELECT DATABASE(), @@collation_database;
+
+# -- Here we have: current db: NULL; stmt db: mysqltest1;
+--echo
+EXECUTE stmt_c_1;
+
+--echo
+SELECT DATABASE(), @@collation_database;
+
+# -- Here we have: current db: NULL; stmt db: mysqltest2 (non-existent);
+--echo
+EXECUTE stmt_c_2;
+
+--echo
+SELECT DATABASE(), @@collation_database;
+
+# -- Create prepared statement, which has no current database.
+
+--echo
+PREPARE stmt_c_3 FROM 'SELECT DATABASE(), @@collation_database';
+
+# -- Here we have: current db: NULL; stmt db: NULL;
+--echo
+EXECUTE stmt_c_3;
+
+--echo
+use mysqltest1;
+
+# -- Here we have: current db: mysqltest1; stmt db: mysqltest2 (non-existent);
+--echo
+EXECUTE stmt_c_2;
+
+--echo
+SELECT DATABASE(), @@collation_database;
+
+# -- Here we have: current db: mysqltest1; stmt db: NULL;
+--echo
+EXECUTE stmt_c_3;
+
+--echo
+SELECT DATABASE(), @@collation_database;
+
+--echo
+DROP DATABASE mysqltest1;
+
+--echo
+use test;
+
+--echo
+--echo ########################################################################
+
+###############################################################################
+
+set @@global.query_cache_size=@initial_query_cache_size;
+flush status; # reset Qcache status variables for next tests
diff --git a/mysql-test/include/read_many_rows.inc b/mysql-test/include/read_many_rows.inc
new file mode 100644
index 00000000000..ff57c0ca13d
--- /dev/null
+++ b/mysql-test/include/read_many_rows.inc
@@ -0,0 +1,167 @@
+# include/read_many_rows.inc
+#
+# Test how filesort and buffered-record-reads works
+# This test needs a lot of time.
+#
+# The variables
+# $engine_type -- storage engine to be tested
+# $other_engine_type -- storage engine <> $engine_type, if possible
+# 1. $other_engine_type must allow to store many rows
+# without using non standard server options
+# (does not need a t/read_many_rows_*-master.opt file)
+# 2. $other_engine_type must point to an all time
+# available storage engine
+# 2006-08 MySQL 5.1 MyISAM and MEMORY only
+# have to be set before sourcing this script.
+#
+# Last update:
+# 2006-08-03 ML test refactored (MySQL 5.1)
+# main code t/innodb-big.test --> include/read_many_rows.inc
+#
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2, t3, t4;
+--enable_warnings
+
+eval CREATE TABLE t1 (id INTEGER) ENGINE=$other_engine_type;
+CREATE TABLE t2 (id INTEGER PRIMARY KEY);
+CREATE TABLE t3 (a CHAR(32) PRIMARY KEY,id INTEGER);
+eval CREATE TABLE t4 (a CHAR(32) PRIMARY KEY,id INTEGER) ENGINE=$other_engine_type;
+
+INSERT INTO t1 (id) VALUES (1);
+INSERT INTO t1 SELECT id+1 FROM t1;
+INSERT INTO t1 SELECT id+2 FROM t1;
+INSERT INTO t1 SELECT id+4 FROM t1;
+INSERT INTO t1 SELECT id+8 FROM t1;
+INSERT INTO t1 SELECT id+16 FROM t1;
+INSERT INTO t1 SELECT id+32 FROM t1;
+INSERT INTO t1 SELECT id+64 FROM t1;
+INSERT INTO t1 SELECT id+128 FROM t1;
+INSERT INTO t1 SELECT id+256 FROM t1;
+INSERT INTO t1 SELECT id+512 FROM t1;
+INSERT INTO t1 SELECT id+1024 FROM t1;
+INSERT INTO t1 SELECT id+2048 FROM t1;
+INSERT INTO t1 SELECT id+4096 FROM t1;
+INSERT INTO t1 SELECT id+8192 FROM t1;
+INSERT INTO t1 SELECT id+16384 FROM t1;
+INSERT INTO t1 SELECT id+32768 FROM t1;
+INSERT INTO t1 SELECT id+65536 FROM t1;
+INSERT INTO t1 SELECT id+131072 FROM t1;
+INSERT INTO t1 SELECT id+262144 FROM t1;
+INSERT INTO t1 SELECT id+524288 FROM t1;
+INSERT INTO t1 SELECT id+1048576 FROM t1;
+
+INSERT INTO t2 SELECT * FROM t1;
+INSERT INTO t3 SELECT CONCAT(id),id FROM t2 ORDER BY -id;
+INSERT INTO t4 SELECT * FROM t3 ORDER BY CONCAT(a);
+SELECT SUM(id) FROM t3;
+
+DROP TABLE t1,t2,t3,t4;
+
+#
+# Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
+#
+CREATE TABLE t1 (f1 int NOT NULL) ENGINE=InnoDB;
+CREATE TABLE t2 (f2 int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
+DELIMITER |;
+CREATE TRIGGER t1_bi before INSERT
+ ON t1 FOR EACH ROW
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @a:= 'deadlock';
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
+ INSERT INTO t2 (f2) VALUES (1);
+ DELETE FROM t2 WHERE f2 = 1;
+END;|
+
+CREATE PROCEDURE proc24989()
+BEGIN
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' SET @b:= 'deadlock';
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
+ INSERT INTO t2 (f2) VALUES (1);
+ DELETE FROM t2 WHERE f2 = 1;
+END;|
+
+create procedure proc24989_2()
+ deterministic
+begin
+ declare continue handler for sqlexception
+ select 'Outer handler' as 'exception';
+
+ insert into t1 values(1);
+ select "continued";
+end|
+
+DELIMITER ;|
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+
+connection con1;
+start transaction;
+insert into t1 values(1);
+
+connection con2;
+start transaction;
+insert into t2 values(123);
+send insert into t1 values(1);
+
+connection con1;
+--sleep 1
+insert into t1 values(1);
+
+connection con2;
+--error 1213
+reap;
+select @a;
+# check that the whole transaction was rolled back
+select * from t2;
+
+connection con1;
+commit;
+start transaction;
+insert into t1 values(1);
+
+connection con2;
+start transaction;
+insert into t2 values(123);
+send call proc24989();
+
+connection con1;
+--sleep 1
+insert into t1 values(1);
+
+connection con2;
+reap;
+select @a,@b;
+# check that the whole transaction was rolled back
+select * from t2;
+
+connection con1;
+commit;
+start transaction;
+insert into t1 values(1);
+
+connection con2;
+start transaction;
+insert into t2 values(123);
+send call proc24989_2();
+
+connection con1;
+--sleep 1
+insert into t1 values(1);
+commit;
+
+connection con2;
+reap;
+# check that the whole transaction was rolled back
+select * from t2;
+
+disconnect con1;
+disconnect con2;
+connection default;
+drop procedure proc24989;
+drop procedure proc24989_2;
+drop table t1,t2;
+
diff --git a/mysql-test/include/report-features.test b/mysql-test/include/report-features.test
index df395f6e3f0..1e4ab232490 100644
--- a/mysql-test/include/report-features.test
+++ b/mysql-test/include/report-features.test
@@ -9,3 +9,4 @@ show engines;
show variables;
--echo ===== STOP =====
--enable_query_log
+exit; \ No newline at end of file
diff --git a/mysql-test/include/reset_master_and_slave.inc b/mysql-test/include/reset_master_and_slave.inc
new file mode 100644
index 00000000000..30ba1f07a40
--- /dev/null
+++ b/mysql-test/include/reset_master_and_slave.inc
@@ -0,0 +1,8 @@
+--echo **** Resetting master and slave ****
+connection slave;
+source include/stop_slave.inc;
+RESET SLAVE;
+connection master;
+RESET MASTER;
+connection slave;
+source include/start_slave.inc;
diff --git a/mysql-test/include/restart_mysqld.inc b/mysql-test/include/restart_mysqld.inc
new file mode 100644
index 00000000000..0f363ff1ee3
--- /dev/null
+++ b/mysql-test/include/restart_mysqld.inc
@@ -0,0 +1,25 @@
+
+# Write file to make mysql-test-run.pl expect the "crash", but don't start
+# it until it's told to
+--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+wait
+EOF
+
+# Send shutdown to the connected server and give
+# it 10 seconds to die before zapping it
+shutdown_server 10;
+
+# Write file to make mysql-test-run.pl start up the server again
+--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+restart
+EOF
+
+# Turn on reconnect
+--enable_reconnect
+
+# Call script that will poll the server waiting for it to be back online again
+--source include/wait_until_connected_again.inc
+
+# Turn off reconnect again
+--disable_reconnect
+
diff --git a/mysql-test/include/rowid_order.inc b/mysql-test/include/rowid_order.inc
new file mode 100644
index 00000000000..b05bad45cde
--- /dev/null
+++ b/mysql-test/include/rowid_order.inc
@@ -0,0 +1,121 @@
+# include/rowid_order.inc
+#
+# Test for rowid ordering (and comparison) functions.
+# do index_merge select for tables with PK of various types.
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Note: The comments/expections refer to InnoDB.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was t/rowid_order.test
+# main code went into include/rowid_order.inc
+#
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+
+--disable_warnings
+drop table if exists t1, t2, t3,t4;
+--enable_warnings
+
+# Signed number as rowid
+create table t1 (
+ pk1 int not NULL,
+ key1 int(11),
+ key2 int(11),
+ PRIMARY KEY (pk1),
+ KEY key1 (key1),
+ KEY key2 (key2)
+);
+insert into t1 values (-5, 1, 1),
+ (-100, 1, 1),
+ (3, 1, 1),
+ (0, 1, 1),
+ (10, 1, 1);
+explain select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+drop table t1;
+
+# Unsigned numbers as rowids
+create table t1 (
+ pk1 int unsigned not NULL,
+ key1 int(11),
+ key2 int(11),
+ PRIMARY KEY (pk1),
+ KEY key1 (key1),
+ KEY key2 (key2)
+);
+insert into t1 values (0, 1, 1),
+ (0xFFFFFFFF, 1, 1),
+ (0xFFFFFFFE, 1, 1),
+ (1, 1, 1),
+ (2, 1, 1);
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+drop table t1;
+
+# Case-insensitive char(N)
+create table t1 (
+ pk1 char(4) not NULL,
+ key1 int(11),
+ key2 int(11),
+ PRIMARY KEY (pk1),
+ KEY key1 (key1),
+ KEY key2 (key2)
+) collate latin2_general_ci;
+insert into t1 values ('a1', 1, 1),
+ ('b2', 1, 1),
+ ('A3', 1, 1),
+ ('B4', 1, 1);
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+drop table t1;
+
+# Multi-part PK
+create table t1 (
+ pk1 int not NULL,
+ pk2 char(4) not NULL collate latin1_german1_ci,
+ pk3 char(4) not NULL collate latin1_bin,
+ key1 int(11),
+ key2 int(11),
+ PRIMARY KEY (pk1,pk2,pk3),
+ KEY key1 (key1),
+ KEY key2 (key2)
+);
+insert into t1 values
+ (1, 'u', 'u', 1, 1),
+ (1, 'u', char(0xEC), 1, 1),
+ (1, 'u', 'x', 1, 1);
+insert ignore into t1 select pk1, char(0xEC), pk3, key1, key2 from t1;
+insert ignore into t1 select pk1, 'x', pk3, key1, key2 from t1 where pk2='u';
+insert ignore into t1 select 2, pk2, pk3, key1, key2 from t1;
+select * from t1;
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+
+# Hidden PK
+alter table t1 drop primary key;
+select * from t1;
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+drop table t1;
+
+# Variable-length PK
+# this is also test for Bug#2688
+create table t1 (
+ pk1 varchar(8) NOT NULL default '',
+ pk2 varchar(4) NOT NULL default '',
+ key1 int(11),
+ key2 int(11),
+ primary key(pk1, pk2),
+ KEY key1 (key1),
+ KEY key2 (key2)
+);
+insert into t1 values ('','empt',2,2),
+ ('a','a--a',2,2),
+ ('bb','b--b',2,2),
+ ('ccc','c--c',2,2),
+ ('dddd','d--d',2,2);
+select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
+
+drop table t1;
diff --git a/mysql-test/include/rpl_events.inc b/mysql-test/include/rpl_events.inc
new file mode 100644
index 00000000000..0effa8c4e5c
--- /dev/null
+++ b/mysql-test/include/rpl_events.inc
@@ -0,0 +1,159 @@
+##################################################################
+# Author: Giuseppe, Chuck Bell #
+# Date: 17-January-2007 #
+# Purpose: To test that event effects are replicated #
+# in both row based and statement based format #
+##################################################################
+
+--disable_warnings
+DROP EVENT IF EXISTS test.justonce;
+drop table if exists t1,t2;
+--enable_warnings
+
+# first, we need a table to record something from an event
+
+eval CREATE TABLE `t1` (
+ `id` INT(10) UNSIGNED NOT NULL,
+ `c` VARCHAR(50) NOT NULL,
+ `ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+) ENGINE=$engine_type DEFAULT CHARSET=utf8;
+
+INSERT INTO t1 (id, c) VALUES (1, 'manually');
+
+# We create the event so that it inserts exactly 1 row in the table
+# A recuring event is used so that we can be sure the event will
+# fire regardless of timing delays on the server. Otherwise, it is
+# possible for the event to timeout before it has inserted a row.
+--echo "Creating event test.justonce on the master"
+CREATE EVENT test.justonce ON SCHEDULE EVERY 2 SECOND DO
+ INSERT IGNORE INTO t1 (id, c) VALUES (2, 'from justonce');
+
+# Show the event is alive and present on master
+--echo "Checking event is active on master"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
+
+# Wait until event has fired. We know this because t1 will contain
+# the row from the event.
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM t1 WHERE c = 'from justonce';
+--source include/wait_condition.inc
+
+# check that table t1 contains something
+--echo "Checking event data on the master"
+let $events_done=`SELECT count(*) FROM t1 id`;
+--disable_query_log
+eval SELECT $events_done > 0 as ONE;
+--enable_query_log
+
+sync_slave_with_master;
+
+--echo "Checking event data on the slave"
+--disable_query_log
+eval SELECT count(*) - $events_done as ZERO FROM t1 id;
+--enable_query_log
+
+--echo "Checking event is inactive on slave"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
+
+# Create an event on the slave and check to see what the originator is.
+--echo "Dropping event test.slave_once on the slave"
+--disable_warnings
+DROP EVENT IF EXISTS test.slave_once;
+--enable_warnings
+
+# Create an event on slave and check its state. An event shouldn't be executed
+# so set start time in 1 hour.
+CREATE EVENT test.slave_once ON SCHEDULE EVERY 5 MINUTE STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
+ INSERT IGNORE INTO t1(id, c) VALUES (3, 'from slave_once');
+
+--echo "Checking event status on the slave for originator value = slave's server_id"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_once';
+
+--echo "Dropping event test.slave_once on the slave"
+--disable_warnings
+DROP EVENT IF EXISTS test.slave_once;
+--enable_warnings
+
+connection master;
+
+# BUG#20384 - disable events on slave
+--echo "Dropping event test.justonce on the master"
+--disable_warnings
+DROP EVENT IF EXISTS test.justonce;
+--enable_warnings
+
+# Create an event on master and check its state on slave. An event shouldn't be executed
+# so set start time in 1 hour. Check that changes of event statement replicated to slave
+
+--echo "Creating event test.er on the master"
+CREATE EVENT test.er ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
+ INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er');
+
+--echo "Checking event status on the master"
+SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
+
+sync_slave_with_master;
+
+--echo "Checking event status on the slave"
+SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
+
+connection master;
+--echo "Altering event test.er on the master"
+ALTER EVENT test.er ON SCHEDULE EVERY 5 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
+ INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er');
+
+--echo "Checking event status on the master"
+SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
+
+sync_slave_with_master;
+
+--echo "Checking event status on the slave"
+SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
+
+connection master;
+--echo "Dropping event test.er on the master"
+DROP EVENT test.er;
+
+--echo "Checking event status on the master"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
+
+--disable_info
+
+sync_slave_with_master;
+
+--echo "Checking event status on the slave"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
+
+# test the DISABLE ON SLAVE for setting event SLAVESIDE_DISABLED as status
+# on CREATE EVENT
+
+# Create an event on slave and check its status. An event shouldn't be executed
+# so set start time in 1 hour.
+
+--echo "Creating event test.slave_terminate on the slave"
+CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
+ INSERT IGNORE INTO t1(id, c) VALUES (6, 'from slave_terminate');
+
+--echo "Checking event status on the slave"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
+
+--echo "Dropping event test.slave_terminate on the slave"
+DROP EVENT test.slave_terminate;
+
+--echo "Creating event test.slave_terminate with DISABLE ON SLAVE on the slave"
+CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DISABLE ON SLAVE DO
+ INSERT IGNORE INTO t1(c) VALUES (7, 'from slave_terminate');
+
+--echo "Checking event status on the slave"
+SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
+
+--echo "Dropping event test.slave_terminate on the slave"
+DROP EVENT test.slave_terminate;
+
+--echo "Cleanup"
+connection master;
+DROP TABLE t1;
+sync_slave_with_master;
+connection master;
+
diff --git a/mysql-test/include/rpl_multi_engine.inc b/mysql-test/include/rpl_multi_engine.inc
new file mode 100644
index 00000000000..b2d1a9c1cef
--- /dev/null
+++ b/mysql-test/include/rpl_multi_engine.inc
@@ -0,0 +1,16 @@
+connection master;
+INSERT INTO t1 VALUES(42,1,'Testing MySQL databases is a cool ', 'Must make it bug free for the customer',654321.4321,15.21,0,1965,"2005-11-14");
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+sync_slave_with_master;
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+connection master;
+UPDATE t1 SET b1 = 0, t="2005-09-09" WHERE b1 = 1;
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+sync_slave_with_master;
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+connection master;
+DELETE FROM t1 WHERE id = 42;
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+sync_slave_with_master;
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+connection master;
diff --git a/mysql-test/include/rpl_multi_engine2.inc b/mysql-test/include/rpl_multi_engine2.inc
new file mode 100644
index 00000000000..e683a1d5838
--- /dev/null
+++ b/mysql-test/include/rpl_multi_engine2.inc
@@ -0,0 +1,91 @@
+#############################################################
+# Author: Rafal
+# Date: 2007-08-20
+# based on rpl_multi_engine3.inc
+#############################################################
+
+connection slave;
+STOP SLAVE;
+RESET SLAVE;
+
+connection master;
+RESET MASTER;
+
+connection slave;
+START SLAVE;
+
+--echo --- Populate t1 with data ---
+connection master;
+--disable_query_log
+INSERT INTO t1 VALUES(42,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1905-11-14");
+INSERT INTO t1 VALUES(2,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1965-11-14");
+INSERT INTO t1 VALUES(4,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1985-11-14");
+INSERT INTO t1 VALUES(142,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1995-11-14");
+INSERT INTO t1 VALUES(412,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"2005-11-14");
+--enable_query_log
+
+--echo --- Select from t1 on master ---
+select *
+from t1
+order by id;
+
+sync_slave_with_master;
+--echo --- Select from t1 on slave ---
+select *
+from t1
+order by id;
+
+--echo --- Perform basic operation on master ---
+--echo --- and ensure replicated correctly ---
+connection master;
+
+--echo --- Update t1 on master --
+UPDATE t1 SET b1 = 0, bc='updated', t="2006-02-22"
+WHERE id < 100
+ORDER BY id;
+
+--echo --- Check the update on master ---
+SELECT *
+FROM t1
+WHERE id < 100
+ORDER BY id;
+
+# Must give injector thread a little time to get update
+# into the binlog other wise we will miss the update.
+
+sync_slave_with_master;
+--echo --- Check Update on slave ---
+SELECT *
+FROM t1
+WHERE id < 100
+ORDER BY id;
+
+connection master;
+--echo --- Remove a record from t1 on master ---
+# Note: there is an error in replication of Delete_row
+# from NDB to MyISAM (BUG#28538). However, if there is
+# only one row in Delete_row event then it works fine,
+# as this test demonstrates.
+DELETE FROM t1 WHERE id = 412;
+
+--echo --- Show current count on master for t1 ---
+SELECT COUNT(*) FROM t1;
+
+sync_slave_with_master;
+--echo --- Show current count on slave for t1 ---
+SELECT COUNT(*) FROM t1;
+
+connection master;
+TRUNCATE TABLE t1;
+sync_slave_with_master;
+connection master;
diff --git a/mysql-test/include/rpl_multi_engine3.inc b/mysql-test/include/rpl_multi_engine3.inc
new file mode 100644
index 00000000000..e1a80df336c
--- /dev/null
+++ b/mysql-test/include/rpl_multi_engine3.inc
@@ -0,0 +1,61 @@
+#############################################################
+# Author: JBM
+# Date: 2006-02-23
+# Purpose: To reuse through out test and make maint easier
+#############################################################
+connection master;
+--echo "--- Insert into t1 --" as "";
+
+--disable_query_log
+INSERT INTO t1 VALUES(42,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1905-11-14");
+INSERT INTO t1 VALUES(2,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1965-11-14");
+INSERT INTO t1 VALUES(4,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1985-11-14");
+INSERT INTO t1 VALUES(142,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"1995-11-14");
+INSERT INTO t1 VALUES(412,1,'Testing MySQL databases is a cool ',
+ 'Must make it bug free for the customer',
+ 654321.4321,15.21,0,1965,"2005-11-14");
+--enable_query_log
+
+--echo --- Select from t1 on master ---
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+
+sync_slave_with_master;
+--echo --- Select from t1 on slave ---
+select id,hex(b1),vc,bc,d,f,total,y,t from t1 order by id;
+
+connection master;
+
+--echo --- Update t1 on master --
+UPDATE t1 SET b1 = 0, t="2006-02-22" WHERE id = 412;
+
+--echo --- Check the update on master ---
+SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412;
+
+# Must give injector thread a little time to get update
+# into the binlog other wise we will miss the update.
+
+sync_slave_with_master;
+--echo --- Check Update on slave ---
+SELECT id,hex(b1),vc,bc,d,f,total,y,t FROM t1 WHERE id = 412;
+
+connection master;
+--echo --- Remove a record from t1 on master ---
+DELETE FROM t1 WHERE id = 42;
+
+--echo --- Show current count on master for t1 ---
+SELECT COUNT(*) FROM t1;
+
+sync_slave_with_master;
+--echo --- Show current count on slave for t1 ---
+SELECT COUNT(*) FROM t1;
+
+connection master;
+DELETE FROM t1;
diff --git a/mysql-test/include/rpl_stmt_seq.inc b/mysql-test/include/rpl_stmt_seq.inc
index 3c91505d0d6..6c944dc4729 100644
--- a/mysql-test/include/rpl_stmt_seq.inc
+++ b/mysql-test/include/rpl_stmt_seq.inc
@@ -1,30 +1,51 @@
-# include/rpl_stmt_seq.inc
-#
-# Please be very careful when editing this routine, because the handling of
-# the $variables is extreme sensitive.
-#
+################### include/rpl_stmt_seq.inc ###########################
+# #
+# Check if a given SQL statement (->$my_stmt) / AUTOCOMMIT mode / #
+# storage engine somehow involved causes COMMIT or ROLLBACK. #
+# #
+# #
+# The typical test sequence #
+# ------------------------- #
+# 1. master connection: INSERT without commit #
+# check table content of master and slave #
+# 2. master connection: EXECUTE the statement #
+# check table content of master and slave #
+# 3. master connection: ROLLBACK #
+# check table content of master and slave #
+# 4. flush the logs #
+# #
+# The variables #
+# $show_binlog -- print binlog entries #
+# 0 - default + fits to the file with #
+# results #
+# 1 - useful for debugging #
+# This variable is used within #
+# include/rpl_stmt_seq.inc. #
+# $manipulate -- Manipulation of the binary logs #
+# 0 - do nothing #
+# 1 - so that the output of SHOW BINLOG #
+# EVENTS IN <current log> contains only #
+# commands of the current test sequence #
+# This is especially useful, if the #
+# $show_binlog is set to 1 and many #
+# subtest are executed. #
+# This variable is used within #
+# include/rpl_stmt_seq.inc. #
+# have to be set before sourcing this script. #
+# #
+# Please be very careful when editing this routine, because the #
+# handling of the $variables is extreme sensitive. #
+# #
+########################################################################
-###############################################################
-# Debug options : To debug this test script
-###############################################################
-let $show_binlog= 0;
-let $manipulate= 1;
-
-######## The typical test sequence
-# 1. INSERT without commit
-# check table content of master and slave
-# 2. EXECUTE the statement
-# check table content of master and slave
-# 3. ROLLBACK
-# check table content of master and slave
-# 4. flush the logs
+# Last update:
+# 2007-02-12 ML Replace comments via SQL by "--echo ..."
+#
let $VERSION=`select version()`;
---disable_query_log
-# SELECT '######## new test sequence ########' as "";
-eval SELECT CONCAT('######## ','$my_stmt',' ########') as "";
---enable_query_log
+--echo
+--echo ######## $my_stmt ########
###############################################################
@@ -49,11 +70,10 @@ let $_log_num_s= `select @aux`;
###############################################################
# INSERT
###############################################################
+--echo
+--echo -------- switch to master -------
connection master;
---disable_query_log
-SELECT '-------- switch to master -------' as "";
---enable_query_log
-# Maybe it would be smarter to use a table with autoincrement column.
+# Maybe it would be smarter to use a table with an autoincrement column.
let $MAX= `SELECT MAX(f1) FROM t1` ;
eval INSERT INTO t1 SET f1= $MAX + 1;
# results before DDL(to be tested)
@@ -66,10 +86,9 @@ eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
}
sync_slave_with_master;
+--echo
+--echo -------- switch to slave --------
connection slave;
---disable_query_log
-SELECT '-------- switch to slave --------' as "";
---enable_query_log
# results before DDL(to be tested)
SELECT MAX(f1) FROM t1;
if ($show_binlog)
@@ -82,10 +101,9 @@ eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
###############################################################
# command to be tested
###############################################################
+--echo
+--echo -------- switch to master -------
connection master;
---disable_query_log
-SELECT '-------- switch to master -------' as "";
---enable_query_log
eval $my_stmt;
# Devaluate $my_stmt, to detect script bugs
let $my_stmt= ERROR: YOU FORGOT TO FILL IN THE STATEMENT;
@@ -99,10 +117,9 @@ eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
}
sync_slave_with_master;
+--echo
+--echo -------- switch to slave --------
connection slave;
---disable_query_log
-SELECT '-------- switch to slave --------' as "";
---enable_query_log
# results after DDL(to be tested)
SELECT MAX(f1) FROM t1;
if ($show_binlog)
@@ -115,10 +132,9 @@ eval SHOW BINLOG EVENTS IN 'slave-bin.$_log_num_s';
###############################################################
# ROLLBACK
###############################################################
+--echo
+--echo -------- switch to master -------
connection master;
---disable_query_log
-SELECT '-------- switch to master -------' as "";
---enable_query_log
ROLLBACK;
# results after final ROLLBACK
SELECT MAX(f1) FROM t1;
@@ -140,10 +156,9 @@ eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
}
sync_slave_with_master;
+--echo
+--echo -------- switch to slave --------
connection slave;
---disable_query_log
-SELECT '-------- switch to slave --------' as "";
---enable_query_log
# results after final ROLLBACK
SELECT MAX(f1) FROM t1;
--disable_query_log
@@ -172,19 +187,17 @@ if ($manipulate)
# - flush the master and the slave log
# ---> both start to write into new logs with incremented number
# - increment $_log_num_n
+--echo
+--echo -------- switch to master -------
connection master;
---disable_query_log
-SELECT '-------- switch to master -------' as "";
---enable_query_log
flush logs;
# sleep 1;
# eval SHOW BINLOG EVENTS IN 'master-bin.$_log_num_s';
sync_slave_with_master;
+--echo
+--echo -------- switch to slave --------
connection slave;
---disable_query_log
-SELECT '-------- switch to slave --------' as "";
---enable_query_log
# the final content of the binary log
flush logs;
# The next sleep is urgent needed.
@@ -195,7 +208,6 @@ flush logs;
inc $_log_num_n;
}
+--echo
+--echo -------- switch to master -------
connection master;
---disable_query_log
-SELECT '-------- switch to master -------' as "";
---enable_query_log
diff --git a/mysql-test/include/rpl_udf.inc b/mysql-test/include/rpl_udf.inc
new file mode 100644
index 00000000000..30f39d79d49
--- /dev/null
+++ b/mysql-test/include/rpl_udf.inc
@@ -0,0 +1,189 @@
+#####################################################################
+# Author: Chuck Bell #
+# Date: 2006-12-21 #
+# Purpose: To test that UDFs are replicated in both row based and #
+# statement based format. This tests work completed in WL#3629. #
+# #
+# This test is designed to exercise two of the three types of UDFs: #
+# 1) UDFs via loadable libraries, and 2) UDFs with a SQL body. #
+#####################################################################
+
+--source include/have_udf.inc
+
+#
+# To run this tests the "sql/udf_example.c" need to be compiled into
+# udf_example.so and LD_LIBRARY_PATH should be setup to point out where
+# the library are.
+#
+
+connection master;
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Test 1) Test UDFs via loadable libraries
+#
+--echo "*** Test 1) Test UDFs via loadable libraries ***
+--echo "Running on the master"
+--enable_info
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+--error ER_CANT_FIND_DL_ENTRY
+eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+--replace_column 3 UDF_LIB
+SELECT * FROM mysql.func ORDER BY name;
+--disable_info
+
+save_master_pos;
+connection slave;
+sync_with_master;
+
+# Check to see that UDF CREATE statements were replicated
+--echo "Running on the slave"
+--enable_info
+--replace_column 3 UDF_LIB
+SELECT * FROM mysql.func ORDER BY name;
+--disable_info
+
+connection master;
+
+# Use the UDFs to do something
+--echo "Running on the master"
+--enable_info
+eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
+INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
+INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
+INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
+INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
+SELECT * FROM t1 ORDER BY sum;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see if data was replicated
+--echo "Running on the slave"
+--enable_info
+SELECT * FROM t1 ORDER BY sum;
+
+# Check to see that the functions are available for execution on the slave
+SELECT myfunc_int(25);
+SELECT myfunc_double(75.00);
+--disable_info
+
+connection master;
+
+# Drop the functions
+--echo "Running on the master"
+--enable_info
+DROP FUNCTION myfunc_double;
+DROP FUNCTION myfunc_int;
+SELECT * FROM mysql.func ORDER BY name;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see if the UDFs were dropped on the slave
+--echo "Running on the slave"
+--enable_info
+SELECT * FROM mysql.func ORDER BY name;
+--disable_info
+
+connection master;
+
+# Cleanup
+--echo "Running on the master"
+--enable_info
+DROP TABLE t1;
+--disable_info
+
+#
+# Test 2) Test UDFs with SQL body
+#
+--echo "*** Test 2) Test UDFs with SQL body ***
+--echo "Running on the master"
+--enable_info
+CREATE FUNCTION myfuncsql_int(i INT) RETURNS INTEGER DETERMINISTIC RETURN i;
+CREATE FUNCTION myfuncsql_double(d DOUBLE) RETURNS INTEGER DETERMINISTIC RETURN d * 2.00;
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see that UDF CREATE statements were replicated
+--echo "Running on the slave"
+--enable_info
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+--disable_info
+
+connection master;
+
+# Use the UDFs to do something
+--echo "Running on the master"
+--enable_info
+eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
+INSERT INTO t1 VALUES(myfuncsql_int(100), myfuncsql_double(50.00));
+INSERT INTO t1 VALUES(myfuncsql_int(10), myfuncsql_double(5.00));
+INSERT INTO t1 VALUES(myfuncsql_int(200), myfuncsql_double(25.00));
+INSERT INTO t1 VALUES(myfuncsql_int(1), myfuncsql_double(500.00));
+SELECT * FROM t1 ORDER BY sum;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see if data was replicated
+--echo "Running on the slave"
+--enable_info
+SELECT * FROM t1 ORDER BY sum;
+--disable_info
+
+connection master;
+
+# Modify the UDFs to add a comment
+--echo "Running on the master"
+--enable_info
+ALTER FUNCTION myfuncsql_int COMMENT "This was altered.";
+ALTER FUNCTION myfuncsql_double COMMENT "This was altered.";
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see if data was replicated
+--echo "Running on the slave"
+--enable_info
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+
+# Check to see that the functions are available for execution on the slave
+SELECT myfuncsql_int(25);
+SELECT myfuncsql_double(75.00);
+--disable_info
+
+connection master;
+
+# Drop the functions
+--echo "Running on the master"
+--enable_info
+DROP FUNCTION myfuncsql_double;
+DROP FUNCTION myfuncsql_int;
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+--disable_info
+
+sync_slave_with_master;
+
+# Check to see if the UDFs were dropped on the slave
+--echo "Running on the slave"
+--enable_info
+SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
+--disable_info
+
+connection master;
+
+# Cleanup
+--echo "Running on the master"
+--enable_info
+DROP TABLE t1;
+--disable_info
diff --git a/mysql-test/include/running_event_scheduler.inc b/mysql-test/include/running_event_scheduler.inc
new file mode 100644
index 00000000000..296bf842e82
--- /dev/null
+++ b/mysql-test/include/running_event_scheduler.inc
@@ -0,0 +1,30 @@
+############# include/running_event_scheduler.inc ##########################
+# #
+# Wait till the event scheduler reached its final state within the processlist.#
+# #
+# The characteristics of the event_scheduler entry within the processlist is #
+# user = 'event_scheduler' and command = 'Daemon'. I am not 100% sure if #
+# ther is no short phase with command <> 'Daemon'. #
+# A query with WHERE user = 'event_scheduler' only will also catch events in #
+# startup phase. #
+# #
+# Creation: #
+# 2008-12-19 mleich Implement this check needed for test bug fixes #
+# #
+################################################################################
+
+# 1. Check that the server system variable shows the state needed
+if (`SELECT @@global.event_scheduler <> 'ON'`)
+{
+ --echo # Error: We expect here that the event scheduler is switched on.
+ SELECT @@global.event_scheduler;
+ --echo # Thinkable reasons:
+ --echo # 1. SET GLOBAL event_scheduler = ON had not the expected effect.
+ --echo # 2. Use of the current routine (include/running_event_scheduler.inc)
+ --echo # within the wrong situation
+ --die
+}
+let $wait_condition=
+ SELECT COUNT(*) = 1 FROM information_schema.processlist
+ WHERE user = 'event_scheduler' AND command = 'Daemon';
+--source include/wait_condition.inc
diff --git a/mysql-test/include/safe_set_to_maybe_ro_var.inc b/mysql-test/include/safe_set_to_maybe_ro_var.inc
new file mode 100644
index 00000000000..add7f2091b3
--- /dev/null
+++ b/mysql-test/include/safe_set_to_maybe_ro_var.inc
@@ -0,0 +1,23 @@
+# to mask out the error - never abort neither log in result file - in setting
+# to read-only variable.
+# It is assumed that the new value is equal to one the var was set to.
+# Such situation happens particularily with binlog_format that becomes read-only
+# with ndb default storage.
+#
+# when generate results always watch the file to find what is expected,
+# the SET query may fail
+
+# script accepts $maybe_ro_var the var name and $val4var the value
+
+### USAGE:
+### let $maybe_ro_var= ...
+### let $val4var= ...
+### include/safe_set_to_maybe_ro_var.inc
+
+--disable_result_log
+--disable_abort_on_error
+eval SET $maybe_ro_var = $val4var;
+--enable_abort_on_error
+--enable_result_log
+
+eval SELECT $maybe_ro_var;
diff --git a/mysql-test/include/select_ndb_apply_status.inc b/mysql-test/include/select_ndb_apply_status.inc
new file mode 100644
index 00000000000..a676b7cfb06
--- /dev/null
+++ b/mysql-test/include/select_ndb_apply_status.inc
@@ -0,0 +1,13 @@
+##################################################
+# Author: Jeb
+# Date: 2007/04
+# Purpose: To select out log name, start and end
+# positions from ndb_apply_status table
+##################################################
+--replace_column 1 <log_name> 2 <start_pos> 3 <end_pos>
+select @log_name:=log_name, @start_pos:=start_pos, @end_pos:=end_pos
+ from mysql.ndb_apply_status;
+--let $start_pos = `select @start_pos`
+--let $end_pos = `select @end_pos`
+--let $log_name = `select @log_name`
+
diff --git a/mysql-test/include/set_binlog_format_mixed.sql b/mysql-test/include/set_binlog_format_mixed.sql
new file mode 100644
index 00000000000..836992d1080
--- /dev/null
+++ b/mysql-test/include/set_binlog_format_mixed.sql
@@ -0,0 +1,2 @@
+SET GLOBAL BINLOG_FORMAT=MIXED;
+SET SESSION BINLOG_FORMAT=MIXED;
diff --git a/mysql-test/include/set_binlog_format_row.sql b/mysql-test/include/set_binlog_format_row.sql
new file mode 100644
index 00000000000..49f34c8ccd1
--- /dev/null
+++ b/mysql-test/include/set_binlog_format_row.sql
@@ -0,0 +1,2 @@
+SET GLOBAL BINLOG_FORMAT=ROW;
+SET SESSION BINLOG_FORMAT=ROW;
diff --git a/mysql-test/include/set_binlog_format_statement.sql b/mysql-test/include/set_binlog_format_statement.sql
new file mode 100644
index 00000000000..ed286e7e3cc
--- /dev/null
+++ b/mysql-test/include/set_binlog_format_statement.sql
@@ -0,0 +1,2 @@
+SET GLOBAL BINLOG_FORMAT=STATEMENT;
+SET SESSION BINLOG_FORMAT=STATEMENT;
diff --git a/mysql-test/include/setup_fake_relay_log.inc b/mysql-test/include/setup_fake_relay_log.inc
new file mode 100644
index 00000000000..f88806e1079
--- /dev/null
+++ b/mysql-test/include/setup_fake_relay_log.inc
@@ -0,0 +1,77 @@
+# ==== Purpose ====
+#
+# Setup replication from an existing relay log in the current
+# connection.
+#
+# ==== Usage ====
+#
+# Make sure the slave is not running and issue:
+#
+# let $fake_relay_log= /path/to/fake-relay-log-file.000001
+# source include/setup_fake_relay_log.inc;
+# START SLAVE SQL_THREAD; # setup_fake_relay_log doesn't start slave
+# ...
+# source include/cleanup_fake_relay_log.inc
+#
+# You must run the server with --relay-log=FILE. You probably want to
+# run with --replicate-same-server-id too.
+#
+# ==== Implementation ====
+#
+# First makes a sanity check, ensuring that the slave threads are not
+# running. Then copies the $fake_relay_log to RELAY_BIN-fake.000001,
+# where RELAY_BIN is the basename of the relay log, and updates
+# RELAY_BIN.index. Finally issues CHANGE MASTER so that it uses the
+# given files.
+#
+# ==== Side effects ====
+#
+# Creates a binlog file and a binlog index file, and sets
+# @@global.relay_log_purge=1. All this is restored when you call
+# cleanup_fake_relay_log.inc.
+#
+# Enables the query log.
+
+
+--disable_query_log
+
+# Print message.
+let $_fake_relay_log_printable= `SELECT REPLACE('$fake_relay_log', '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`;
+--echo Setting up fake replication from $_fake_relay_log_printable
+
+# Sanity check.
+let $_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1);
+let $_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1);
+if (`SELECT "$_sql_running" = "Yes" OR "$_io_running" = "Yes"`) {
+ --echo Error: Slave was running when test case sourced
+ --echo include/setup_fake_replication.inc
+ --echo Slave_IO_Running = $_io_running; Slave_SQL_Running = $_sql_running
+ --echo Printing some debug info:
+ SHOW SLAVE STATUS;
+ SHOW MASTER STATUS;
+ SHOW BINLOG EVENTS;
+ SHOW PROCESSLIST;
+}
+
+# Read server variables.
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+let $_fake_filename= query_get_value(SHOW VARIABLES LIKE 'relay_log', Value, 1);
+if (`SELECT '$_fake_filename' = ''`) {
+ --echo Badly written test case: relay_log variable is empty. Please use the
+ --echo server option --relay-log=FILE.
+}
+let $_fake_relay_log= $MYSQLD_DATADIR/$_fake_filename-fake.000001;
+let $_fake_relay_index= $MYSQLD_DATADIR/$_fake_filename.index;
+# Need to restore relay_log_purge in cleanup_fake_relay_log.inc, since
+# CHANGE MASTER modifies it (see the manual for CHANGE MASTER).
+let $_fake_relay_log_purge= `SELECT @@global.relay_log_purge`;
+
+# Create relay log file.
+copy_file $fake_relay_log $_fake_relay_log;
+# Create relay log index.
+--exec echo $_fake_filename-fake.000001 > $_fake_relay_index
+
+# Setup replication from existing relay log.
+eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4;
+
+--enable_query_log
diff --git a/mysql-test/include/show_binary_logs.inc b/mysql-test/include/show_binary_logs.inc
index 43a9d5d2eed..c3729a8f9b9 100644
--- a/mysql-test/include/show_binary_logs.inc
+++ b/mysql-test/include/show_binary_logs.inc
@@ -1,3 +1,5 @@
---replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
---replace_column 2 #
+# show binary logs
+
+# mask out the binlog position
+-- replace_column 2 #
show binary logs;
diff --git a/mysql-test/include/show_binlog_events.inc b/mysql-test/include/show_binlog_events.inc
index 50b910b553b..68f913a16a3 100644
--- a/mysql-test/include/show_binlog_events.inc
+++ b/mysql-test/include/show_binlog_events.inc
@@ -2,9 +2,9 @@
if (!$binlog_start)
{
- let $binlog_start=98;
+ let $binlog_start=106;
}
---replace_result $binlog_start <binlog_start>
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR $binlog_start <binlog_start>
--replace_column 2 # 4 # 5 #
---replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /file_id=[0-9]+/file_id=#/
+--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /file_id=[0-9]+/file_id=#/ /block_len=[0-9]+/block_len=#/
--eval show binlog events from $binlog_start
diff --git a/mysql-test/include/show_binlog_events2.inc b/mysql-test/include/show_binlog_events2.inc
index fa244c5a5a3..5dd272c562d 100644
--- a/mysql-test/include/show_binlog_events2.inc
+++ b/mysql-test/include/show_binlog_events2.inc
@@ -1,4 +1,4 @@
---let $binlog_start=98
+--let $binlog_start=106
--replace_result $binlog_start <binlog_start>
--replace_column 2 # 5 #
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
diff --git a/mysql-test/include/show_binlog_using_logname.inc b/mysql-test/include/show_binlog_using_logname.inc
new file mode 100644
index 00000000000..d78c28e5916
--- /dev/null
+++ b/mysql-test/include/show_binlog_using_logname.inc
@@ -0,0 +1,13 @@
+########################################################
+# Author: Jeb
+# Date: 2007/04
+# Purpose: To select out 1 row from offset 1
+# from the start position in the binlog whose
+# name is = log_name
+########################################################
+
+--replace_result $start_pos <start_pos> $end_pos <end_pos>
+--replace_column 2 #
+--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
+--eval show binlog events in '$log_name' from $start_pos limit $off_set,1
+
diff --git a/mysql-test/include/show_master_logs.inc b/mysql-test/include/show_master_logs.inc
new file mode 100644
index 00000000000..4792ebd9651
--- /dev/null
+++ b/mysql-test/include/show_master_logs.inc
@@ -0,0 +1,5 @@
+# show master logs
+
+# mask out the binlog position
+-- replace_column 2 #
+query_vertical show master logs;
diff --git a/mysql-test/include/show_master_status.inc b/mysql-test/include/show_master_status.inc
new file mode 100644
index 00000000000..b7b32a65df4
--- /dev/null
+++ b/mysql-test/include/show_master_status.inc
@@ -0,0 +1,5 @@
+# show master status
+
+# mask out the binlog position
+-- replace_column 2 # 3 <Binlog_Do_DB> 4 <Binlog_Ignore_DB>
+show master status;
diff --git a/mysql-test/include/show_rpl_debug_info.inc b/mysql-test/include/show_rpl_debug_info.inc
new file mode 100644
index 00000000000..252d63f1bf4
--- /dev/null
+++ b/mysql-test/include/show_rpl_debug_info.inc
@@ -0,0 +1,87 @@
+# ==== Purpose ====
+#
+# Print status information for replication, typically used to debug
+# test failures.
+#
+# First, the following is printed on slave:
+#
+# SHOW SLAVE STATUS
+# SHOW PROCESSLIST
+# SHOW BINLOG EVENTS IN <binlog_name>
+#
+# Where <binlog_name> is the currently active binlog.
+#
+# Then, the following is printed on master:
+#
+# SHOW MASTER STATUS
+# SHOW PROCESSLIST
+# SHOW BINLOG EVENTS IN <sql_binlog_name>
+# SHOW BINLOG EVENTS IN <io_binlog_name>
+#
+# Where <sql_binlog_name> is the binlog name that the slave sql thread
+# is currently reading from and <io_binlog_name> is the binlog that
+# the slave IO thread is currently reading from.
+#
+# ==== Usage ====
+#
+# [let $master_connection= <connection>;]
+# source include/show_rpl_debug_info.inc;
+#
+# If $master_connection is set, debug info will be retrieved from the
+# connection named $master_connection. Otherwise, it will be
+# retrieved from the 'master' connection if the current connection is
+# 'slave'.
+
+let $_con= $CURRENT_CONNECTION;
+--echo
+--echo [on $_con]
+--echo
+--echo **** SHOW SLAVE STATUS on $_con ****
+query_vertical SHOW SLAVE STATUS;
+--echo
+--echo **** SHOW PROCESSLIST on $_con ****
+SHOW PROCESSLIST;
+--echo
+--echo **** SHOW BINLOG EVENTS on $_con ****
+let $binlog_name= query_get_value("SHOW MASTER STATUS", File, 1);
+eval SHOW BINLOG EVENTS IN '$binlog_name';
+
+let $_master_con= $master_connection;
+if (`SELECT '$_master_con' = ''`)
+{
+ if (`SELECT '$_con' = 'slave'`)
+ {
+ let $_master_con= master;
+ }
+ if (`SELECT '$_master_con' = ''`)
+ {
+ --echo Unable to determine master connection. No debug info printed for master.
+ --echo Please fix the test case by setting $master_connection before sourcing
+ --echo show_rpl_debug_info.inc.
+ }
+}
+
+if (`SELECT '$_master_con' != ''`)
+{
+
+ let $master_binlog_name_io= query_get_value("SHOW SLAVE STATUS", Master_Log_File, 1);
+ let $master_binlog_name_sql= query_get_value("SHOW SLAVE STATUS", Relay_Master_Log_File, 1);
+ --echo
+ --echo [on $_master_con]
+ connection $_master_con;
+ --echo
+ --echo **** SHOW MASTER STATUS on $_master_con ****
+ query_vertical SHOW MASTER STATUS;
+ --echo
+ --echo **** SHOW PROCESSLIST on $_master_con ****
+ SHOW PROCESSLIST;
+ --echo
+ --echo **** SHOW BINLOG EVENTS on $_master_con ****
+ eval SHOW BINLOG EVENTS IN '$master_binlog_name_sql';
+ if (`SELECT '$master_binlog_name_io' != '$master_binlog_name_sql'`)
+ {
+ eval SHOW BINLOG EVENTS IN '$master_binlog_name_io';
+ }
+
+ connection $_con;
+}
diff --git a/mysql-test/include/show_slave_status.inc b/mysql-test/include/show_slave_status.inc
new file mode 100644
index 00000000000..b315b9e45ca
--- /dev/null
+++ b/mysql-test/include/show_slave_status.inc
@@ -0,0 +1,6 @@
+# Include file to show the slave status, masking out some information
+# that varies depending on where the test is executed.
+
+--replace_result $MASTER_MYPORT MASTER_PORT
+--replace_column 1 # 8 # 9 # 16 # 23 # 33 # 35 # 36 #
+query_vertical SHOW SLAVE STATUS;
diff --git a/mysql-test/include/show_slave_status2.inc b/mysql-test/include/show_slave_status2.inc
new file mode 100644
index 00000000000..9c4e14c62c2
--- /dev/null
+++ b/mysql-test/include/show_slave_status2.inc
@@ -0,0 +1,8 @@
+# Include file to show the slave status, masking out some information
+# that varies depending on where the test is executed.
+
+# masked out log positions
+
+--replace_result $MASTER_MYPORT MASTER_PORT
+--replace_column 1 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
+query_vertical SHOW SLAVE STATUS;
diff --git a/mysql-test/include/start_slave.inc b/mysql-test/include/start_slave.inc
new file mode 100644
index 00000000000..78a02736de8
--- /dev/null
+++ b/mysql-test/include/start_slave.inc
@@ -0,0 +1,21 @@
+# ==== Purpose ====
+#
+# Issues START SLAVE on the current connection. Then waits until both
+# the IO and SQL threads have started, or until a timeout is reached.
+#
+# Please use this instead of 'START SLAVE', to reduce the risk of test
+# case bugs.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_to_start.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
+
+--disable_query_log
+START SLAVE;
+--enable_query_log
+--echo include/start_slave.inc
+source include/wait_for_slave_to_start.inc;
diff --git a/mysql-test/include/stop_slave.inc b/mysql-test/include/stop_slave.inc
new file mode 100644
index 00000000000..7161e6fe739
--- /dev/null
+++ b/mysql-test/include/stop_slave.inc
@@ -0,0 +1,21 @@
+# ==== Purpose ====
+#
+# Issues STOP SLAVE on the current connection. Then waits until both
+# the IO and SQL threads have stopped, or until a timeout is reached.
+#
+# Please use this instead of 'STOP SLAVE', to reduce the risk of test
+# case bugs.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_to_start.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
+
+--disable_query_log
+STOP SLAVE;
+--enable_query_log
+--echo include/stop_slave.inc
+source include/wait_for_slave_to_stop.inc;
diff --git a/mysql-test/include/sync_slave_io_with_master.inc b/mysql-test/include/sync_slave_io_with_master.inc
new file mode 100644
index 00000000000..f7dd563039c
--- /dev/null
+++ b/mysql-test/include/sync_slave_io_with_master.inc
@@ -0,0 +1,36 @@
+# ==== Purpose ====
+#
+# Waits until the slave IO thread has been synced, i.e., all events
+# have been copied over to slave. Does not care if the SQL thread is
+# in sync.
+#
+#
+# ==== Usage ====
+#
+# source include/sync_slave_io_with_master.inc;
+#
+# Syncs to the current position on master, as found by SHOW MASTER
+# STATUS.
+#
+# Must be called on the master. Will change connection to the slave.
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
+
+let $_master_file= query_get_value("SHOW MASTER STATUS", File, 1);
+let $_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1);
+
+connection slave;
+
+let $slave_error_message= Failed while waiting for slave IO thread to sync;
+
+let $slave_param= Master_Log_File;
+let $slave_param_value= $_master_file;
+source include/wait_for_slave_param.inc;
+
+let $slave_param= Read_Master_Log_Pos;
+let $slave_param_value= $_master_pos;
+source include/wait_for_slave_param.inc;
+
+let $slave_error_message= ;
diff --git a/mysql-test/include/system_db_struct.inc b/mysql-test/include/system_db_struct.inc
index c66590b2fd8..123c82484b9 100644
--- a/mysql-test/include/system_db_struct.inc
+++ b/mysql-test/include/system_db_struct.inc
@@ -11,4 +11,8 @@ show create table func;
show create table tables_priv;
show create table columns_priv;
show create table procs_priv;
+show create table servers;
show create table proc;
+show create table event;
+show create table general_log;
+show create table slow_log;
diff --git a/mysql-test/include/test_fieldsize.inc b/mysql-test/include/test_fieldsize.inc
new file mode 100644
index 00000000000..cbe63e26318
--- /dev/null
+++ b/mysql-test/include/test_fieldsize.inc
@@ -0,0 +1,40 @@
+#
+# include/test_fieldsize.inc
+#
+# This include file is designed to create a table with one column
+# whose size on the master is greater than that on the slave. The
+# test should fail with an error on the slave.
+#
+
+connection master;
+DROP TABLE IF EXISTS t1;
+
+sync_slave_with_master;
+STOP SLAVE;
+RESET SLAVE;
+eval $test_table_slave;
+
+connection master;
+eval $test_table_master;
+RESET MASTER;
+
+eval $test_insert;
+
+connection slave;
+START SLAVE;
+wait_for_slave_to_stop;
+--replace_result $MASTER_MYPORT MASTER_PORT
+--replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
+--query_vertical SHOW SLAVE STATUS
+
+# The following should be 0
+SELECT COUNT(*) FROM t1;
+STOP SLAVE;
+RESET SLAVE;
+
+connection master;
+RESET MASTER;
+
+connection slave;
+START SLAVE;
+
diff --git a/mysql-test/include/testdb_only.inc b/mysql-test/include/testdb_only.inc
index ddc3f123d45..528e2f3eb9d 100644
--- a/mysql-test/include/testdb_only.inc
+++ b/mysql-test/include/testdb_only.inc
@@ -19,12 +19,6 @@
# #
###################################################################
---disable_query_log
-eval set @USE_RUNNING_SERVER= '$USE_RUNNING_SERVER';
---require r/testdb_only.require
-SELECT 'use extern server'
- AS "Variable_name ",
- IF(@USE_RUNNING_SERVER= '1','YES',
- IF(@USE_RUNNING_SERVER= '0','NO','UNEXPECTED'))
- AS "Value" ;
---enable_query_log
+if ($USE_RUNNING_SERVER){
+ skip Not with extern server;
+}
diff --git a/mysql-test/include/tpcb.inc b/mysql-test/include/tpcb.inc
new file mode 100644
index 00000000000..84a5c98f9c2
--- /dev/null
+++ b/mysql-test/include/tpcb.inc
@@ -0,0 +1,155 @@
+##################################################
+# Author: Jeb
+# Date: 2007/04
+# Purpose: To create a tpcb database, tables and
+# stored procedures to load the database
+# and run transactions against the DB
+##################################################
+--disable_warnings
+DROP DATABASE IF EXISTS tpcb;
+--enable_warnings
+CREATE DATABASE tpcb;
+
+--echo
+CREATE TABLE tpcb.account (id INT, bid INT, balance DECIMAL(10,2),
+ filler CHAR(255), PRIMARY KEY(id));
+--echo
+CREATE TABLE tpcb.branch (bid INT, balance DECIMAL(10,2), filler VARCHAR(255),
+ PRIMARY KEY(bid));
+--echo
+CREATE TABLE tpcb.teller (tid INT, balance DECIMAL(10,2), filler VARCHAR(255),
+ PRIMARY KEY(tid));
+--echo
+CREATE TABLE tpcb.history (id MEDIUMINT NOT NULL AUTO_INCREMENT,aid INT,
+ tid INT, bid INT, amount DECIMAL(10,2),
+ tdate DATETIME, teller CHAR(20), uuidf LONGBLOB,
+ filler CHAR(80),PRIMARY KEY (id));
+
+--echo
+--echo --- Create stored procedures & functions ---
+--echo
+
+--disable_query_log
+delimiter |;
+CREATE PROCEDURE tpcb.load()
+BEGIN
+ DECLARE acct INT DEFAULT 100;
+ DECLARE brch INT DEFAULT 10;
+ DECLARE tell INT DEFAULT 100;
+ DECLARE tmp INT DEFAULT 10;
+ WHILE brch > 0 DO
+ SET tmp = 100;
+ WHILE tmp > 0 DO
+ INSERT INTO tpcb.account VALUES (acct, brch, 0.0, "FRESH ACCOUNT");
+ SET acct = acct - 1;
+ SET tmp = tmp -1;
+ END WHILE;
+ INSERT INTO tpcb.branch VALUES (brch, 0.0, "FRESH BRANCH");
+ SET brch = brch - 1;
+ END WHILE;
+ WHILE tell > 0 DO
+ INSERT INTO tpcb.teller VALUES (tell, 0.0, "FRESH TELLER");
+ SET tell = tell - 1;
+ END WHILE;
+END|
+
+CREATE FUNCTION tpcb.account_id () RETURNS INT
+BEGIN
+ DECLARE num INT;
+ DECLARE ran INT;
+ SELECT RAND() * 10 INTO ran;
+ IF (ran < 5)
+ THEN
+ SELECT RAND() * 10 INTO num;
+ ELSE
+ SELECT RAND() * 100 INTO num;
+ END IF;
+ IF (num < 1)
+ THEN
+ RETURN 1;
+ END IF;
+ RETURN num;
+END|
+
+CREATE FUNCTION tpcb.teller_id () RETURNS INT
+BEGIN
+ DECLARE num INT;
+ DECLARE ran INT;
+ SELECT RAND() * 10 INTO ran;
+ IF (ran < 5)
+ THEN
+ SELECT RAND() * 10 INTO num;
+ ELSE
+ SELECT RAND() * 100 INTO num;
+ END IF;
+ IF (num < 1)
+ THEN
+ RETURN 1;
+ END IF;
+ RETURN num;
+END|
+
+CREATE PROCEDURE tpcb.trans(in format varchar(3))
+BEGIN
+ DECLARE acct INT DEFAULT 0;
+ DECLARE brch INT DEFAULT 0;
+ DECLARE tell INT DEFAULT 0;
+ DECLARE bal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE amount DECIMAL(10,2) DEFAULT 1.00;
+ DECLARE test INT DEFAULT 0;
+ DECLARE bbal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE tbal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE local_uuid VARCHAR(255);
+ DECLARE local_user VARCHAR(255);
+ DECLARE local_time TIMESTAMP;
+
+ SELECT RAND() * 10 INTO test;
+ SELECT tpcb.account_id() INTO acct;
+ SELECT tpcb.teller_id() INTO tell;
+
+ SELECT account.balance INTO bal FROM tpcb.account WHERE id = acct;
+ SELECT account.bid INTO brch FROM tpcb.account WHERE id = acct;
+ SELECT teller.balance INTO tbal FROM tpcb.teller WHERE tid = tell;
+ SELECT branch.balance INTO bbal FROM tpcb.branch WHERE bid = brch;
+
+ IF (test < 5)
+ THEN
+ SET bal = bal + amount;
+ SET bbal = bbal + amount;
+ SET tbal = tbal + amount;
+ UPDATE tpcb.account SET balance = bal, filler = 'account updated'
+ WHERE id = acct;
+ UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
+ WHERE bid = brch;
+ UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
+ WHERE tid = tell;
+ ELSE
+ SET bal = bal - amount;
+ SET bbal = bbal - amount;
+ SET tbal = tbal - amount;
+ UPDATE tpcb.account SET balance = bal, filler = 'account updated'
+ WHERE id = acct;
+ UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
+ WHERE bid = brch;
+ UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
+ WHERE tid = tell;
+ END IF;
+
+ IF (format = 'SBR')
+ THEN
+ SET local_uuid=UUID();
+ SET local_user=USER();
+ SET local_time= NOW();
+ INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, local_time,local_user,
+ local_uuid,'completed trans');
+ ELSE
+ INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, NOW(), USER(),
+ UUID(),'completed trans');
+ END IF;
+END|
+delimiter ;|
+--enable_query_log
+--echo
+--echo *** Stored Procedures Created ***
+--echo
+
diff --git a/mysql-test/include/tpcb_disk_data.inc b/mysql-test/include/tpcb_disk_data.inc
new file mode 100644
index 00000000000..dbdf3766bbc
--- /dev/null
+++ b/mysql-test/include/tpcb_disk_data.inc
@@ -0,0 +1,166 @@
+##################################################
+# Author: Jeb
+# Date: 2007/05
+# Purpose: To create a tpcb database using Disk Data,
+# tables and stored procedures to load the database
+# and run transactions against the DB
+##################################################
+--disable_warnings
+DROP DATABASE IF EXISTS tpcb;
+--enable_warnings
+CREATE DATABASE tpcb;
+
+--echo
+eval CREATE TABLE tpcb.account
+ (id INT, bid INT, balance DECIMAL(10,2),
+ filler CHAR(255), PRIMARY KEY(id))
+ TABLESPACE $table_space STORAGE DISK
+ ENGINE=$engine_type;
+--echo
+eval CREATE TABLE tpcb.branch
+ (bid INT, balance DECIMAL(10,2), filler VARCHAR(255),
+ PRIMARY KEY(bid))TABLESPACE $table_space STORAGE DISK
+ ENGINE=$engine_type;
+--echo
+eval CREATE TABLE tpcb.teller
+ (tid INT, balance DECIMAL(10,2), filler VARCHAR(255),
+ PRIMARY KEY(tid)) TABLESPACE $table_space STORAGE DISK
+ ENGINE=$engine_type;
+
+--echo
+eval CREATE TABLE tpcb.history
+ (id MEDIUMINT NOT NULL AUTO_INCREMENT,aid INT,
+ tid INT, bid INT, amount DECIMAL(10,2),
+ tdate DATETIME, teller CHAR(20), uuidf LONGBLOB,
+ filler CHAR(80),PRIMARY KEY (id))
+ TABLESPACE $table_space STORAGE DISK
+ ENGINE=$engine_type;
+
+--echo
+--echo --- Create stored procedures & functions ---
+--echo
+
+--disable_query_log
+delimiter |;
+CREATE PROCEDURE tpcb.load()
+BEGIN
+ DECLARE acct INT DEFAULT 100;
+ DECLARE brch INT DEFAULT 10;
+ DECLARE tell INT DEFAULT 100;
+ DECLARE tmp INT DEFAULT 10;
+ WHILE brch > 0 DO
+ SET tmp = 100;
+ WHILE tmp > 0 DO
+ INSERT INTO tpcb.account VALUES (acct, brch, 0.0, "FRESH ACCOUNT");
+ SET acct = acct - 1;
+ SET tmp = tmp -1;
+ END WHILE;
+ INSERT INTO tpcb.branch VALUES (brch, 0.0, "FRESH BRANCH");
+ SET brch = brch - 1;
+ END WHILE;
+ WHILE tell > 0 DO
+ INSERT INTO tpcb.teller VALUES (tell, 0.0, "FRESH TELLER");
+ SET tell = tell - 1;
+ END WHILE;
+END|
+
+CREATE FUNCTION tpcb.account_id () RETURNS INT
+BEGIN
+ DECLARE num INT;
+ DECLARE ran INT;
+ SELECT RAND() * 10 INTO ran;
+ IF (ran < 5)
+ THEN
+ SELECT RAND() * 10 INTO num;
+ ELSE
+ SELECT RAND() * 100 INTO num;
+ END IF;
+ IF (num < 1)
+ THEN
+ RETURN 1;
+ END IF;
+ RETURN num;
+END|
+
+CREATE FUNCTION tpcb.teller_id () RETURNS INT
+BEGIN
+ DECLARE num INT;
+ DECLARE ran INT;
+ SELECT RAND() * 10 INTO ran;
+ IF (ran < 5)
+ THEN
+ SELECT RAND() * 10 INTO num;
+ ELSE
+ SELECT RAND() * 100 INTO num;
+ END IF;
+ IF (num < 1)
+ THEN
+ RETURN 1;
+ END IF;
+ RETURN num;
+END|
+
+CREATE PROCEDURE tpcb.trans(in format varchar(3))
+BEGIN
+ DECLARE acct INT DEFAULT 0;
+ DECLARE brch INT DEFAULT 0;
+ DECLARE tell INT DEFAULT 0;
+ DECLARE bal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE amount DECIMAL(10,2) DEFAULT 1.00;
+ DECLARE test INT DEFAULT 0;
+ DECLARE bbal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE tbal DECIMAL(10,2) DEFAULT 0.0;
+ DECLARE local_uuid VARCHAR(255);
+ DECLARE local_user VARCHAR(255);
+ DECLARE local_time TIMESTAMP;
+
+ SELECT RAND() * 10 INTO test;
+ SELECT tpcb.account_id() INTO acct;
+ SELECT tpcb.teller_id() INTO tell;
+
+ SELECT account.balance INTO bal FROM tpcb.account WHERE id = acct;
+ SELECT account.bid INTO brch FROM tpcb.account WHERE id = acct;
+ SELECT teller.balance INTO tbal FROM tpcb.teller WHERE tid = tell;
+ SELECT branch.balance INTO bbal FROM tpcb.branch WHERE bid = brch;
+
+ IF (test < 5)
+ THEN
+ SET bal = bal + amount;
+ SET bbal = bbal + amount;
+ SET tbal = tbal + amount;
+ UPDATE tpcb.account SET balance = bal, filler = 'account updated'
+ WHERE id = acct;
+ UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
+ WHERE bid = brch;
+ UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
+ WHERE tid = tell;
+ ELSE
+ SET bal = bal - amount;
+ SET bbal = bbal - amount;
+ SET tbal = tbal - amount;
+ UPDATE tpcb.account SET balance = bal, filler = 'account updated'
+ WHERE id = acct;
+ UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
+ WHERE bid = brch;
+ UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
+ WHERE tid = tell;
+ END IF;
+
+ IF (format = 'SBR')
+ THEN
+ SET local_uuid=UUID();
+ SET local_user=USER();
+ SET local_time= NOW();
+ INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, local_time,local_user,
+ local_uuid,'completed trans');
+ ELSE
+ INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, NOW(), USER(),
+ UUID(),'completed trans');
+ END IF;
+END|
+delimiter ;|
+--enable_query_log
+--echo
+--echo *** Stored Procedures Created ***
+--echo
+
diff --git a/mysql-test/include/unsafe_binlog.inc b/mysql-test/include/unsafe_binlog.inc
new file mode 100644
index 00000000000..2fc2ad77bc9
--- /dev/null
+++ b/mysql-test/include/unsafe_binlog.inc
@@ -0,0 +1,265 @@
+# include/unsafe_binlog.inc
+#
+# The variable
+# $engine_type -- storage engine to be tested
+# has to be set before sourcing this script.
+#
+# Notes:
+# 1. This test uses at least in case of InnoDB options
+# innodb_locks_unsafe_for_binlog = true
+# innodb_lock_timeout = 5
+# 2. The comments/expectations refer to InnoDB.
+# They might be not valid for other storage engines.
+#
+# Last update:
+# 2006-08-02 ML test refactored
+# old name was innodb_unsafe_binlog.test
+# main code went into include/unsafe_binlog.inc
+#
+
+#
+# Test cases for bug#15650
+# DELETE with LEFT JOIN crashes server with innodb_locks_unsafe_for_binlog
+#
+
+--disable_warnings
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
+--enable_warnings
+eval create table t1 (id int not null, f_id int not null, f int not null,
+primary key(f_id, id)) engine = $engine_type;
+eval create table t2 (id int not null,s_id int not null,s varchar(200),
+primary key(id)) engine = $engine_type;
+INSERT INTO t1 VALUES (8, 1, 3);
+INSERT INTO t1 VALUES (1, 2, 1);
+INSERT INTO t2 VALUES (1, 0, '');
+INSERT INTO t2 VALUES (8, 1, '');
+commit;
+DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
+WHERE mm.id IS NULL;
+select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
+where mm.id is null lock in share mode;
+drop table t1,t2;
+
+#
+# Test case for unlock row bug where unlock releases all locks granted for
+# a row. Only the latest lock should be released.
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
+commit;
+set autocommit = 0;
+select * from t1 lock in share mode;
+update t1 set b = 5 where b = 1;
+connection b;
+set autocommit = 0;
+#
+# S-lock to records (2,2),(4,2), and (6,2) should not be released in a update
+#
+--error ER_LOCK_WAIT_TIMEOUT
+select * from t1 where a = 2 and b = 2 for update;
+connection a;
+commit;
+connection b;
+commit;
+drop table t1;
+connection default;
+disconnect a;
+disconnect b;
+
+#
+# unlock row test
+#
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
+commit;
+set autocommit = 0;
+update t1 set b = 5 where b = 1;
+connection b;
+set autocommit = 0;
+#
+# X-lock to record (7,3) should be released in a update
+#
+select * from t1 where a = 7 and b = 3 for update;
+commit;
+connection a;
+commit;
+drop table t1;
+connection default;
+disconnect a;
+disconnect b;
+
+
+#
+# Consistent read should be used in following selects
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t1 values (1,2),(5,3),(4,2);
+eval create table t2(d int not null, e int, primary key(d)) engine = $engine_type;
+insert into t2 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+set autocommit = 0;
+insert into t1 select * from t2;
+update t1 set b = (select e from t2 where a = d);
+eval create table t3(d int not null, e int, primary key(d)) engine = $engine_type
+select * from t2;
+commit;
+connection a;
+commit;
+connection default;
+disconnect a;
+disconnect b;
+drop table t1, t2, t3;
+
+#
+# Consistent read should not be used if
+#
+# (a) isolation level is serializable OR
+# (b) select ... lock in share mode OR
+# (c) select ... for update
+#
+# in following queries:
+#
+# 1) INSERT INTO ... SELECT
+# 2) UPDATE ... = ( SELECT ...)
+# 3) CREATE ... SELECT
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+connect (c,localhost,root,,);
+connect (d,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (e,localhost,root,,);
+connect (f,localhost,root,,);
+connect (g,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connect (h,localhost,root,,);
+connect (i,localhost,root,,);
+connect (j,localhost,root,,);
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+connection a;
+eval create table t1(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t1 values (1,2),(5,3),(4,2);
+eval create table t2(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t2 values (8,6),(12,1),(3,1);
+eval create table t3(d int not null, b int, primary key(d)) engine = $engine_type;
+insert into t3 values (8,6),(12,1),(3,1);
+eval create table t5(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t5 values (1,2),(5,3),(4,2);
+eval create table t6(d int not null, e int, primary key(d)) engine = $engine_type;
+insert into t6 values (8,6),(12,1),(3,1);
+eval create table t8(a int not null, b int, primary key(a)) engine = $engine_type;
+insert into t8 values (1,2),(5,3),(4,2);
+eval create table t9(d int not null, e int, primary key(d)) engine = $engine_type;
+insert into t9 values (8,6),(12,1),(3,1);
+commit;
+set autocommit = 0;
+select * from t2 for update;
+connection b;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+insert into t1 select * from t2;
+connection c;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+update t3 set b = (select b from t2 where a = d);
+connection d;
+set autocommit = 0;
+SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+--send
+create table t4(a int not null, b int, primary key(a)) select * from t2;
+connection e;
+set autocommit = 0;
+--send
+insert into t5 (select * from t2 lock in share mode);
+connection f;
+set autocommit = 0;
+--send
+update t6 set e = (select b from t2 where a = d lock in share mode);
+connection g;
+set autocommit = 0;
+--send
+create table t7(a int not null, b int, primary key(a)) select * from t2 lock in share mode;
+connection h;
+set autocommit = 0;
+--send
+insert into t8 (select * from t2 for update);
+connection i;
+set autocommit = 0;
+--send
+update t9 set e = (select b from t2 where a = d for update);
+connection j;
+set autocommit = 0;
+--send
+create table t10(a int not null, b int, primary key(a)) select * from t2 for update;
+
+connection b;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection c;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection d;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection e;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection f;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection g;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection h;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection i;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection j;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+
+connection a;
+commit;
+
+connection default;
+disconnect a;
+disconnect b;
+disconnect c;
+disconnect d;
+disconnect e;
+disconnect f;
+disconnect g;
+disconnect h;
+disconnect i;
+disconnect j;
+drop table t1, t2, t3, t5, t6, t8, t9;
diff --git a/mysql-test/include/varchar.inc b/mysql-test/include/varchar.inc
index 70b563e871c..15306ed8385 100644
--- a/mysql-test/include/varchar.inc
+++ b/mysql-test/include/varchar.inc
@@ -81,7 +81,7 @@ explain select count(*) from t1 where v between 'a' and 'a ';
--replace_column 9 #
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
---error 1062
+--error ER_DUP_ENTRY
alter table t1 add unique(v);
alter table t1 add key(v);
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
@@ -179,17 +179,17 @@ drop table t1;
create table t1 (a char(10), unique (a));
insert into t1 values ('a ');
---error 1062
+--error ER_DUP_ENTRY
insert into t1 values ('a ');
alter table t1 modify a varchar(10);
---error 1062
+--error ER_DUP_ENTRY
insert into t1 values ('a '),('a '),('a '),('a ');
---error 1062
+--error ER_DUP_ENTRY
insert into t1 values ('a ');
---error 1062
+--error ER_DUP_ENTRY
insert into t1 values ('a ');
---error 1062
+--error ER_DUP_ENTRY
insert into t1 values ('a ');
update t1 set a='a ' where a like 'a%';
select concat(a,'.') from t1;
diff --git a/mysql-test/include/wait_condition_sp.inc b/mysql-test/include/wait_condition_sp.inc
new file mode 100644
index 00000000000..66301da557c
--- /dev/null
+++ b/mysql-test/include/wait_condition_sp.inc
@@ -0,0 +1,62 @@
+# include/wait_condition.inc
+#
+# SUMMARY
+#
+# Waits until the passed statement returns true, or the operation
+# times out.
+#
+# USAGE
+#
+# let $wait_condition=
+# SELECT c = 3 FROM t;
+# --source include/wait_condition.inc
+#
+# OR
+#
+# let $wait_timeout= 60; # Override default 30 seconds with 60.
+# let $wait_condition=
+# SELECT c = 3 FROM t;
+# --source include/wait_condition.inc
+# --echo Executed the test condition $wait_condition_reps times
+#
+# EXAMPLE
+# events_bugs.test, events_time_zone.test
+#
+
+--disable_query_log
+
+let $wait_counter= 300;
+if ($wait_timeout)
+{
+ let $wait_counter= `SELECT $wait_timeout * 10`;
+}
+# Reset $wait_timeout so that its value won't be used on subsequent
+# calls, and default will be used instead.
+let $wait_timeout= 0;
+
+# Keep track of how many times the wait condition is tested
+# This is used by some tests (e.g., main.status)
+let $wait_condition_reps= 0;
+while ($wait_counter)
+{
+ let $success= `$wait_condition`;
+ inc $wait_condition_reps;
+ if ($success)
+ {
+ let $wait_counter= 0;
+ }
+ if (!$success)
+ {
+ real_sleep 0.1;
+ dec $wait_counter;
+ }
+}
+if (!$success)
+{
+ echo Timeout in wait_condition.inc for $wait_condition;
+ show master status;
+ show slave status;
+}
+
+--enable_query_log
+
diff --git a/mysql-test/include/wait_for_binlog_event.inc b/mysql-test/include/wait_for_binlog_event.inc
new file mode 100644
index 00000000000..2a57c191413
--- /dev/null
+++ b/mysql-test/include/wait_for_binlog_event.inc
@@ -0,0 +1,33 @@
+# include/wait_for_binlog_event.inc
+#
+# SUMMARY
+#
+# Waits until SHOW BINLOG EVENTS has returned in last event a specified substring.
+#
+# USAGE
+#
+# let $wait_binlog_event= DROP;
+# --source include/wait_for_binlog_event.inc
+
+let $_loop_count= 300;
+let $_last_event= ;
+let $_event_pos= 1;
+
+while (`SELECT INSTR("$_last_event","$wait_binlog_event") = 0`)
+{
+ dec $_loop_count;
+ if (!$_loop_count)
+ {
+ SHOW BINLOG EVENTS;
+ --die ERROR: failed while waiting for $wait_binlog_event in binlog
+ }
+ real_sleep 0.1;
+ let $_event= query_get_value(SHOW BINLOG EVENTS, Info, $_event_pos);
+ let $_last_event= $_event;
+ while (`SELECT "$_event" != "No such row"`)
+ {
+ inc $_event_pos;
+ let $_last_event= $_event;
+ let $_event= query_get_value(SHOW BINLOG EVENTS, Info, $_event_pos);
+ }
+}
diff --git a/mysql-test/include/wait_for_query_to_suceed.inc b/mysql-test/include/wait_for_query_to_succeed.inc
index 6ac1144620e..12ba5c4d9b8 100644
--- a/mysql-test/include/wait_for_query_to_suceed.inc
+++ b/mysql-test/include/wait_for_query_to_succeed.inc
@@ -1,5 +1,5 @@
#
-# Run a query over and over until it suceeds ot timeout occurs
+# Run a query over and over until it succeeds ot timeout occurs
#
@@ -17,7 +17,7 @@ while ($mysql_errno)
if (!$counter)
{
- die("Waited too long for query to suceed");
+ --die "Waited too long for query to succeed";
}
}
enable_abort_on_error;
diff --git a/mysql-test/include/wait_for_slave_io_to_start.inc b/mysql-test/include/wait_for_slave_io_to_start.inc
new file mode 100644
index 00000000000..abdc8339290
--- /dev/null
+++ b/mysql-test/include/wait_for_slave_io_to_start.inc
@@ -0,0 +1,19 @@
+# ==== Purpose ====
+#
+# Waits until the IO thread of the current connection has started and
+# connected to the master (i.e., until SHOW SLAVE STATUS returns Yes
+# in the Slave_IO_Running field), or until a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_io_to_start.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
+
+let $slave_param= Slave_IO_Running;
+let $slave_param_value= Yes;
+let $slave_error_message= Failed while waiting for slave IO thread to start;
+source include/wait_for_slave_param.inc;
+let $slave_error_message= ;
diff --git a/mysql-test/include/wait_for_slave_io_to_stop.inc b/mysql-test/include/wait_for_slave_io_to_stop.inc
index 004f8bbbd8d..f61b0db1ed7 100644
--- a/mysql-test/include/wait_for_slave_io_to_stop.inc
+++ b/mysql-test/include/wait_for_slave_io_to_stop.inc
@@ -1,33 +1,24 @@
-###################################################
-#Author: Jeb
-#Date: 2007-06-11
-#Purpose: used for io errors on the slave. If Slave gets an io
-# error, the io trhead should stop
-#Details:
-# 1) Fill in and setup variables
-# 2) loop through looking for
-# sql threads to stop
-# 3) If loops too long die.
-####################################################
-connection slave;
-let $my_show= SHOW SLAVE STATUS;
-let $sql_running= Slave_IO_Running;
-let $row_number= 1;
-let $run= 1;
-let $counter= 300;
+# ==== Purpose ====
+#
+# Waits until the IO thread of the current connection has stopped, or
+# until a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_io_to_stop.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
-while ($run)
+# if server has not used CHANGE MASTER to initiate slave, SHOW SLAVE
+# STATUS will return an empty set.
+let $_slave_io_running= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1);
+if (`SELECT '$_slave_io_running' != 'No such row'`)
{
- let $io_result= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, $row_number);
- if (`SELECT '$io_result' = 'No'`){
- let $run= 0;
- }
- sleep 0.1;
- if (!$counter){
- --echo "Failed while waiting for slave IO thread to stop"
- SHOW SLAVE STATUS;
- exit;
- }
- dec $counter;
+ let $slave_param= Slave_IO_Running;
+ let $slave_param_value= No;
+ let $slave_error_message= Failed while waiting for slave IO thread to stop;
+ source include/wait_for_slave_param.inc;
+ let $slave_error_message= ;
}
-
diff --git a/mysql-test/include/wait_for_slave_param.inc b/mysql-test/include/wait_for_slave_param.inc
index fed97195aba..82e57922913 100644
--- a/mysql-test/include/wait_for_slave_param.inc
+++ b/mysql-test/include/wait_for_slave_param.inc
@@ -1,26 +1,82 @@
-# include/wait_for_slave_param.inc
+# ==== Purpose ====
#
-# SUMMARY
+# Waits until SHOW SLAVE STATUS has returned a specified value, or
+# until a timeout is reached.
#
-# Waits until SHOW SLAVE STATUS has returned a spicified value.
+# ==== Usage ====
#
-# USAGE
+# let $slave_param= Slave_SQL_Running;
+# let $slave_param_value= No;
+# source include/slave_wait_param.inc;
#
-# let $slave_param= Slave_SQL_Running;
-# let $slave_param_value= No;
-# --source include/slave_wait_param.inc
+# Parameters:
+#
+# $slave_param, $slave_param_value
+# This macro will wait until the column of the output of SHOW SLAVE
+# STATUS named $slave_param gets the value $slave_param_value. See
+# the example above.
+#
+# $slave_param_comparison
+# By default, this file waits until $slave_param becomes equal to
+# $slave_param_value. If you want to wait until $slave_param
+# becomes *unequal* to $slave_param_value, set this parameter to the
+# string '!=', like this:
+# let $slave_param_comparison= !=;
+#
+# $slave_timeout
+# The default timeout is 5 minutes. You can change the timeout by
+# setting $slave_timeout. The unit is tenths of seconds.
+#
+# $master_connection
+# If the timeout is reached, debug info is given by calling SHOW
+# SLAVE STATUS, SHOW PROCESSLIST, and SHOW BINLOG EVENTS. Then, a
+# 'connection master' is then issued, and more debug info is given
+# by calling SHOW MASTER STATUS, SHOW PROCESSLIST, and SHOW BINLOG
+# EVENTS. If $master_connection is set, the latter three commands
+# will be issued on $master_connection instead of on the host named
+# 'master'. See also show_rpl_debug_info.inc
+#
+# $slave_error_message
+# If set, this is printed when a timeout occurs. This is primarily
+# intended to be used by other wait_for_slave_* macros, to indicate
+# what the purpose of the wait was. (A very similar error message is
+# given by default, but the wait_for_slave_* macros use this to give
+# an error message identical to that in previous versions, so that
+# errors are easier searchable in the pushbuild history.)
+
+let $_slave_timeout_counter= $slave_timeout;
+if (!$_slave_timeout_counter)
+{
+ let $_slave_timeout_counter= 3000;
+}
+
+let $_slave_param_comparison= $slave_param_comparison;
+if (`SELECT '$_slave_param_comparison' = ''`)
+{
+ let $_slave_param_comparison= =;
+}
+
+let $_show_slave_status_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1);
+while (`SELECT NOT('$_show_slave_status_value' $_slave_param_comparison '$slave_param_value') AND $_slave_timeout_counter > 0`)
+{
+ dec $_slave_timeout_counter;
+ if ($_slave_timeout_counter)
+ {
+ sleep 0.1;
+ let $_show_slave_status_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1);
+ }
+}
-let $slave_wait_param_counter= 300;
-let $slave_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1);
-while (`select "$slave_value" != "$slave_param_value"`)
+# This has to be outside the loop until BUG#41913 has been fixed
+if (!$_slave_timeout_counter)
{
- dec $slave_wait_param_counter;
- if (!$slave_wait_param_counter)
+ --echo **** ERROR: timeout after $slave_timeout seconds while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value ****
+ if (`SELECT '$slave_error_message' != ''`)
{
- --echo ERROR: failed while waiting for slave parameter $slave_param: $slave_param_value
- query_vertical show slave status;
- exit;
+ --echo Message: $slave_error_message
}
- sleep 0.1;
- let $slave_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1);
+ --echo Current connection is '$CURRENT_CONNECTION'
+ echo Note: the following output may have changed since the failure was detected;
+ source include/show_rpl_debug_info.inc;
+ exit;
}
diff --git a/mysql-test/include/wait_for_slave_sql_error.inc b/mysql-test/include/wait_for_slave_sql_error.inc
new file mode 100644
index 00000000000..ad1d7a9e639
--- /dev/null
+++ b/mysql-test/include/wait_for_slave_sql_error.inc
@@ -0,0 +1,39 @@
+# ==== Purpose ====
+#
+# Waits until the SQL thread of the current connection has got an
+# error, or until a timeout is reached. Also waits until the SQL
+# thread has completely stopped.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_sql_error.inc;
+#
+# Parameters:
+#
+# $slave_sql_errno
+# The expected SQL error number. This is required.
+# (After BUG#41956 has been fixed, this will be required to be a
+# symbolic name instead of a number.)
+#
+# $slave_timeout
+# See wait_for_slave_param.inc for description.
+#
+# $master_connection
+# See wait_for_slave_param.inc for description.
+
+if (`SELECT '$slave_sql_errno' = ''`) {
+ --echo !!!ERROR IN TEST: you must set \$slave_sql_errno before sourcing wait_fro_slave_sql_error.inc
+ exit;
+}
+
+let $slave_param= Slave_SQL_Running;
+let $slave_param_value= No;
+let $slave_error_message= Failed while waiting for slave to stop the SQL thread (expecting error in the SQL thread);
+source include/wait_for_slave_param.inc;
+
+let $_error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1);
+if (`SELECT '$_error' != '$slave_sql_errno'`) {
+ --echo Slave stopped with wrong error code: $_error (expected $slave_sql_errno)
+ source include/show_rpl_debug_info.inc;
+ exit;
+}
diff --git a/mysql-test/include/wait_for_slave_sql_error_and_skip.inc b/mysql-test/include/wait_for_slave_sql_error_and_skip.inc
new file mode 100644
index 00000000000..247de3a41a1
--- /dev/null
+++ b/mysql-test/include/wait_for_slave_sql_error_and_skip.inc
@@ -0,0 +1,38 @@
+# ==== Purpose ====
+#
+# Wait for slave SQL error, skip the erroneous statement and restart
+# slave
+#
+# ==== Usage ====
+#
+# let $slave_sql_error= <ERRNO>;
+# source include/wait_for_slave_sql_error_and_skip.inc;
+#
+# Parameters:
+#
+# $slave_sql_errno
+# The error number to wait for. This is required. (See
+# wait_for_slave_sql_error.inc)
+#
+# $show_sql_error
+# If set, will print the error to the query log.
+#
+# $slave_timeout
+# See wait_for_slave_param.inc for description.
+#
+# $master_connection
+# See wait_for_slave_param.inc for description.
+
+echo --source include/wait_for_slave_sql_error_and_skip.inc;
+connection slave;
+source include/wait_for_slave_sql_error.inc;
+if ($show_sql_error)
+{
+ let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+ echo Last_SQL_Error = $error;
+}
+
+# skip the erroneous statement
+set global sql_slave_skip_counter=1;
+source include/start_slave.inc;
+connection master;
diff --git a/mysql-test/include/wait_for_slave_sql_to_start.inc b/mysql-test/include/wait_for_slave_sql_to_start.inc
new file mode 100644
index 00000000000..48744f5dd13
--- /dev/null
+++ b/mysql-test/include/wait_for_slave_sql_to_start.inc
@@ -0,0 +1,17 @@
+# ==== Purpose ====
+#
+# Waits the SQL thread of the current connection has started, or until
+# a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_sql_to_start.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
+
+let $slave_param= Slave_SQL_Running;
+let $slave_param_value= Yes;
+let $slave_error_message= Failed while waiting for slave SQL to start;
+source include/wait_for_slave_param.inc;
diff --git a/mysql-test/include/wait_for_slave_sql_to_stop.inc b/mysql-test/include/wait_for_slave_sql_to_stop.inc
index ee765c81f6a..6992613b646 100644
--- a/mysql-test/include/wait_for_slave_sql_to_stop.inc
+++ b/mysql-test/include/wait_for_slave_sql_to_stop.inc
@@ -1,30 +1,24 @@
-###################################################
-#Author: Jeb
-#Date: 2007-06-11
-#Purpose: used for SQL errors on the slave. If Slave gets a sql
-# error, the SQL trhead should stop
-#Details:
-# 1) Fill in and setup variables
-# 2) loop through looking for
-# sql threads to stop
-# 3) If loops too long die.
-####################################################
-connection slave;
-let $row_number= 1;
-let $run= 1;
-let $counter= 300;
+# ==== Purpose ====
+#
+# Waits the SQL thread of the current connection has stopped, or until
+# a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_sql_to_stop.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
-while ($run)
+# if server has not used CHANGE MASTER to initiate slave, SHOW SLAVE
+# STATUS will return an empty set.
+let $_slave_io_running= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1);
+if (`SELECT '$_slave_io_running' != 'No such row'`)
{
- let $sql_result= query_get_value("SHOW SLAVE STATUS", Slave_SQL_Running, $row_number);
- if (`SELECT '$sql_result' = 'No'`){
- let $run= 0;
- }
- sleep 0.1;
- if (!$counter){
- --echo "Failed while waiting for slave SQL thread to stop"
- SHOW SLAVE STATUS;
- exit;
- }
- dec $counter;
+ let $slave_param= Slave_SQL_Running;
+ let $slave_param_value= No;
+ let $slave_error_message= Failed while waiting for slave SQL thread to stop;
+ source include/wait_for_slave_param.inc;
+ let $slave_error_message= ;
}
diff --git a/mysql-test/include/wait_for_slave_to_start.inc b/mysql-test/include/wait_for_slave_to_start.inc
index 84e1d646efe..567950cc6d7 100644
--- a/mysql-test/include/wait_for_slave_to_start.inc
+++ b/mysql-test/include/wait_for_slave_to_start.inc
@@ -1,35 +1,24 @@
-###################################################
-#Author: Jeb
-#Date: 2007-06-11
-#Purpose: To wait a brief time for slave to start
-#Details:
-# 1) Fill in and setup variables
-# 2) loop through looking for both
-# io and sql threads to start
-# 3) If loops too long die.
-####################################################
-connection slave;
-let $row_number= 1;
-let $run= 1;
-let $counter= 300;
+# ==== Purpose ====
+#
+# Waits until both the IO and SQL threads of the current connection
+# have started, or until a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_to_start.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
-while ($run)
-{
- let $io_result= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, $row_number);
- if (`SELECT '$io_result' = 'Yes'`){
+let $slave_error_message= Failed while waiting for slave to start;
- let $sql_result= query_get_value("SHOW SLAVE STATUS", Slave_SQL_Running, $row_number);
- if (`SELECT '$sql_result' = 'Yes'`){
- let $run= 0;
- }
- }
- sleep 0.1;
- if (!$counter){
- --echo "Failed while waiting for slave to start"
- SHOW SLAVE STATUS;
- exit;
- }
- dec $counter;
-}
+let $slave_param= Slave_IO_Running;
+let $slave_param_value= Yes;
+source include/wait_for_slave_param.inc;
+let $slave_param= Slave_SQL_Running;
+let $slave_param_value= Yes;
+source include/wait_for_slave_param.inc;
+let $slave_error_message= ;
diff --git a/mysql-test/include/wait_for_slave_to_stop.inc b/mysql-test/include/wait_for_slave_to_stop.inc
index 13acbecb835..56d0e7b0c91 100644
--- a/mysql-test/include/wait_for_slave_to_stop.inc
+++ b/mysql-test/include/wait_for_slave_to_stop.inc
@@ -1,37 +1,30 @@
-###################################################
-#Author: Jeb
-#Date: 2007-06-11
-#Purpose: To replace the mysqltest.c executable
-# wait_for_slave_to_stop function and
-# return this to the test language.
-#Details:
-# 1) Fill in and setup variables
-# 2) loop through looking for both
-# io and sql threads to stop
-# 3) If loops too long die.
-####################################################
-connection slave;
-let $row_number= 1;
-let $run= 1;
-let $counter= 300;
+# ==== Purpose ====
+#
+# Waits until both the IO and SQL threads of the current connection
+# have stopped, or until a timeout is reached.
+#
+# ==== Usage ====
+#
+# source include/wait_for_slave_to_stop.inc;
+#
+# Parameters to this macro are $slave_timeout and
+# $master_connection. See wait_for_slave_param.inc for
+# descriptions.
-while ($run)
+# if server has not used CHANGE MASTER to initiate slave, SHOW SLAVE
+# STATUS will return an empty set.
+let $_slave_io_running= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1);
+if (`SELECT '$_slave_io_running' != 'No such row'`)
{
- let $io_result= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, $row_number);
- if (`SELECT '$io_result' = 'No'`){
+ let $slave_error_message= Failed while waiting for slave to stop;
- let $sql_result= query_get_value("SHOW SLAVE STATUS", Slave_SQL_Running, $row_number);
- if (`SELECT '$sql_result' = 'No'`){
- let $run= 0;
- }
- }
- sleep 0.1;
- if (!$counter){
- --echo "Failed while waiting for slave to stop"
- SHOW SLAVE STATUS;
- exit;
- }
- dec $counter;
-}
+ let $slave_param= Slave_IO_Running;
+ let $slave_param_value= No;
+ source include/wait_for_slave_param.inc;
+ let $slave_param= Slave_SQL_Running;
+ let $slave_param_value= No;
+ source include/wait_for_slave_param.inc;
+ let $slave_error_message= ;
+}
diff --git a/mysql-test/include/wait_show_pattern.inc b/mysql-test/include/wait_show_pattern.inc
deleted file mode 100644
index c9f84ce7f08..00000000000
--- a/mysql-test/include/wait_show_pattern.inc
+++ /dev/null
@@ -1,51 +0,0 @@
-# include/wait_show_pattern.inc
-#
-# SUMMARY
-#
-# Waits until output produced by SHOW statement which particular type is
-# specified as parameter matches certain pattern or maximum time reached.
-#
-# NOTES
-#
-# Only the first row produced by the parameter statement is checked.
-#
-# USAGE
-#
-# let $show_type= <Tail of SHOW statement>;
-# let $show_pattern= 'Pattern to be used for LIKE matching';
-# --source wait_show_pattern.inc
-#
-# EXAMPLES
-#
-# alter_table-big.test, wait_slave_status.inc
-#
-# SEE ALSO
-#
-# wait_slave_status.inc, wait_condition.inc (>=5.1)
-#
-###############################################################################
-
---disable_query_log
-
-# We accept to wait maximum 30 seconds (0.2 sec/loop).
-let $wait_counter= 150;
-while ($wait_counter)
-{
- let $result= `SHOW $show_type`;
- let $success= `SELECT '$result' LIKE $show_pattern`;
- if ($success)
- {
- let $wait_counter= 0;
- }
- if (!$success)
- {
- real_sleep 0.2;
- dec $wait_counter;
- }
-}
-if (!$success)
-{
- echo Timeout in wait_show_pattern.inc \$show_type= $show_type \$show_pattern= $show_pattern (\$result= '$result');
-}
-
---enable_query_log
diff --git a/mysql-test/include/wait_slave_status.inc b/mysql-test/include/wait_slave_status.inc
deleted file mode 100644
index d8d048527cf..00000000000
--- a/mysql-test/include/wait_slave_status.inc
+++ /dev/null
@@ -1,129 +0,0 @@
-# include/wait_slave_status.inc
-#
-# Created by Matthias Leich
-#
-# SUMMARY
-#
-# Waits until slave has reached certain state or maximum time reached.
-#
-# (This script will not work, when the SHOW command delivers more than one
-# result record, because only the first record will be caught.)
-#
-# USAGE
-#
-# Set $result_pattern in test file and source this file:
-#
-# let $result_pattern= <pattern used for LIKE on the result of
-# SHOW STATUS SLAVE>
-# --include wait_slave_status.inc
-#
-# EXAMPLE
-#
-# The script rpl_until.test:
-# ...
-# --replace_result $MASTER_MYPORT MASTER_MYPORT
-# --replace_column 1 # 9 # 23 # 33 #
-# --vertical_results show slave status;
-#
-# outputs
-# show slave status;
-# Slave_IO_State #
-# Master_Host 127.0.0.1
-# Master_User root
-# Master_Port MASTER_MYPORT
-# Connect_Retry 1
-# Master_Log_File master-bin.000001
-# Read_Master_Log_Pos 776
-# Relay_Log_File slave-relay-bin.000004
-# Relay_Log_Pos #
-# Relay_Master_Log_File master-bin.000001
-# Slave_IO_Running Yes
-# Slave_SQL_Running No
-# Replicate_Do_DB
-# Replicate_Ignore_DB
-# Replicate_Do_Table
-# Replicate_Ignore_Table
-# Replicate_Wild_Do_Table
-# Replicate_Wild_Ignore_Table
-# Last_Errno 0
-# Last_Error
-# Skip_Counter 0
-# Exec_Master_Log_Pos 319
-# Relay_Log_Space #
-# Until_Condition Master
-# Until_Log_File master-bin.000001
-# Until_Log_Pos 319
-# Master_SSL_Allowed No
-# Master_SSL_CA_File
-# Master_SSL_CA_Path
-# Master_SSL_Cert
-# Master_SSL_Cipher
-# Master_SSL_Key
-# Seconds_Behind_Master #
-#
-# The main problem with the "show slave status;" in rpl_until is, that
-# depending on the total test engine power and the current load caused by
-# other processes, the expected slave status might be not reached though
-# it will happen in maybe some seconds.
-#
-# The typical problem with rpl_until is that Slave_IO_Running is "No"
-# instead of "Yes".
-#
-# The expected result follows the LIKE pattern:
-#
-# let $result_pattern= '%127.0.0.1%root%1%master-bin.000001%776%slave-relay-bin.000004%master-bin.000001%Yes%No%0%0%319%Master%master-bin.000001%319%No%';
-#
-# The Slave_IO_Running value is the "Yes" just after the "master-bin.000001".
-#
-# How to get this pattern ?
-#
-# Any lines "--replace_result ..." and "--replace_colum ..." just before
-# the SHOW TABLE STATUS and of course the expected result itself
-# show us columns where the content must be unified, because it is non
-# deterministic or it depends on the current test environment.
-#
-# Unfortunately "--replace_result ..." and "--replace_colum ..." do not
-# affect the result of our assignment let $my_val= `SHOW SLAVE STATUS`;
-# Therefore such content must be covered by '%'.
-#
-# Please be careful. A more simple pattern might be dangerous, because we
-# might get "wrong" matches. Example: There might be several "Yes" and "No"
-# within one result row.
-#
-###############################################################################
-
-# We do not want to print the auxiliary commands, because they are not of
-# interest and their amount will vary depending how fast we get the
-# desired state.
---disable_query_log
-
-# The protocol should show
-# - the setting of $result_pattern and
-# - that this file is sourced ,
-# because this increases the chance to use the protocol as replay script.
-eval SELECT "let \$result_pattern= $result_pattern ;" AS "";
-SELECT '--source include/wait_slave_status.inc' AS "";
-
-let $show_type= SLAVE STATUS;
-let $show_pattern= $result_pattern;
---enable_query_log
-
---source include/wait_show_pattern.inc
-
-if (!$success)
-{
-let $message= ! Attention: Timeout in wait_slave_status.inc.
- | Possible reasons with decreasing probability:
- | - The LIKE pattern is wrong, because the
- | testcase was altered or the layout of the
- | SHOW SLAVE STATUS result set changed.
- | - There is a new bug within the replication.
- | - We met an extreme testing environment and timeout is
- | too small.;
---source include/show_msg80.inc
---echo DEBUG INFO START (wait_slave_status.inc):
---echo $result_pattern
---vertical_results
-show slave status;
---echo DEBUG INFO END
-}
diff --git a/mysql-test/include/wait_until_connected_again.inc b/mysql-test/include/wait_until_connected_again.inc
new file mode 100644
index 00000000000..c7bb774929a
--- /dev/null
+++ b/mysql-test/include/wait_until_connected_again.inc
@@ -0,0 +1,24 @@
+#
+# Include this script to wait until the connection to the
+# server has been restored or timeout occurs
+--disable_result_log
+--disable_query_log
+let $counter= 500;
+let $mysql_errno= 9999;
+while ($mysql_errno)
+{
+ # Strangely enough, the server might return "Too many connections"
+ # while being shutdown, thus 1040 is an "allowed" error
+ # See BUG#36228
+ --error 0,1040,1053,2002,2003,2006,2013
+ show status;
+
+ dec $counter;
+ if (!$counter)
+ {
+ --die Server failed to restart
+ }
+ --sleep 0.1
+}
+--enable_query_log
+--enable_result_log
diff --git a/mysql-test/include/wait_until_disconnected.inc b/mysql-test/include/wait_until_disconnected.inc
new file mode 100644
index 00000000000..a4362e52d01
--- /dev/null
+++ b/mysql-test/include/wait_until_disconnected.inc
@@ -0,0 +1,21 @@
+#
+# Include this script to wait until the connection to the
+# server has been dropped
+--disable_result_log
+--disable_query_log
+let $counter= 500;
+let $mysql_errno= 0;
+while (!$mysql_errno)
+{
+ --error 0,1053,2002,2006,2013
+ show status;
+
+ dec $counter;
+ if (!$counter)
+ {
+ --die Server failed to dissapear
+ }
+ --sleep 0.1
+}
+--enable_query_log
+--enable_result_log
diff --git a/mysql-test/include/wait_until_rows_count.inc b/mysql-test/include/wait_until_rows_count.inc
new file mode 100644
index 00000000000..f1b79c54424
--- /dev/null
+++ b/mysql-test/include/wait_until_rows_count.inc
@@ -0,0 +1,20 @@
+# include/wait_until_rows_count.inc
+#
+# SUMMARY
+#
+# Waits until SELECT count(*) = $count from $table returns true, or
+# the operation times out.
+#
+# USAGE
+#
+# let $count= 5;
+# let $table= t1;
+# --source include/wait_until_rows_count.inc
+#
+# EXAMPLE
+# extra/binlog/binlog_insert_delayed.test
+#
+
+let $wait_condition=
+ select count(*) = $count from $table;
+--source include/wait_condition.inc
diff --git a/mysql-test/include/windows_sys_vars.inc b/mysql-test/include/windows_sys_vars.inc
new file mode 100644
index 00000000000..1d51ddb52f9
--- /dev/null
+++ b/mysql-test/include/windows_sys_vars.inc
@@ -0,0 +1,33 @@
+#
+# This file contains default,min and max values for sys variables for windows
+#
+
+--disable_query_log
+
+SET @default_flush_time = 1800;
+SET @min_flush_time = 0;
+#SET @max_flush_time = 0;
+
+SET @default_key_buffer_size= 131072;
+
+#SET @default_join_buffer_size = 131072;
+#SET @min_join_buffer_size = 8200;
+#SET @max_join_buffer_size = 4294967295;
+
+SET @default_max_join_size = 4294967295;
+SET @min_max_join_size = 1;
+SET @max_max_join_size = 4294967295;
+
+SET @default_sql_max_join_size = 4294967295;
+SET @min_sql_max_join_size = 1;
+SET @max_sql_max_join_size = 4294967295;
+
+SET @default_sql_select_limit = 4294967295;
+SET @min_sql_select_limit = 0;
+SET @max_sql_select_limit = 4294967295;
+
+let $default_wait_timeout = 28800;
+let $min_wait_timeout = 1;
+let $max_wait_timeout = 2147483;
+
+--enable_query_log