diff --git a/client/mysqldump.c b/client/mysqldump.c index 0a6ebf0eb2f..459d03dfe2e 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1273,8 +1273,9 @@ static int get_options(int *argc, char ***argv) if (opt_slave_data) { opt_lock_all_tables= !opt_single_transaction; - opt_master_data= 0; opt_delete_master_logs= 0; + if (opt_slave_data != MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) + opt_master_data= 0; } /* Ensure consistency of the set of binlog & locking options */ @@ -1287,10 +1288,7 @@ static int get_options(int *argc, char ***argv) return(EX_USAGE); } if (opt_master_data) - { opt_lock_all_tables= !opt_single_transaction; - opt_slave_data= 0; - } if (opt_single_transaction || opt_lock_all_tables) lock_tables= 0; if (enclosed && opt_enclosed) @@ -6227,17 +6225,12 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos, } - /* SHOW MASTER STATUS reports file and position */ - print_comment(md_result_file, 0, - "\n--\n-- Position to start replication or point-in-time " - "recovery from\n--\n\n"); - fprintf(md_result_file, - "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", - (use_gtid ? "-- " : comment_prefix), file, offset); + /* gtid */ if (have_mariadb_gtid) { print_comment(md_result_file, 0, - "\n--\n-- GTID to start replication from\n--\n\n"); + "\n-- Preferably use GTID to start replication from GTID " + "position:\n\n"); if (use_gtid) fprintf(md_result_file, "%sCHANGE MASTER TO MASTER_USE_GTID=slave_pos;\n", @@ -6246,6 +6239,19 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos, "%sSET GLOBAL gtid_slave_pos='%s';\n", (!use_gtid ? "-- " : comment_prefix), gtid_pos); } + + /* SHOW MASTER STATUS reports file and position */ + print_comment(md_result_file, 0, + "\n--\n-- Alternately, following is the position of the binary " + "logging from SHOW MASTER STATUS at point of backup." + "\n-- Use this when creating a replica of the primary server " + "where the backup was made." + "\n-- The new server will be connecting to the primary server " + "where the backup was taken." + "\n--\n\n"); + fprintf(md_result_file, + "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", + (use_gtid ? "-- " : comment_prefix), file, offset); check_io(md_result_file); if (!consistent_binlog_pos) @@ -6324,7 +6330,6 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid, (opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : ""; const char *gtid_comment_prefix= (use_gtid ? comment_prefix : "-- "); const char *nogtid_comment_prefix= (!use_gtid ? comment_prefix : "-- "); - int set_gtid_done= 0; if (mysql_query_with_error_report(mysql_con, &slave, multi_source ? @@ -6340,23 +6345,36 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid, return 1; } + print_comment(md_result_file, 0, + "\n--\n-- The following is the SQL position of the replication " + "taken from SHOW SLAVE STATUS at the time of backup.\n" + "-- Use this position when creating a clone of, or replacement " + "server, from where the backup was taken." + "\n-- This new server will connects to the same primary " + "server%s.\n--\n", + multi_source ? "(s)" : ""); + + if (multi_source) + { + char gtid_pos[MAX_GTID_LENGTH]; + if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 0)) + { + mysql_free_result(slave); + return 1; + } + print_comment(md_result_file, 0, + "-- GTID position to start replication:\n"); + fprintf(md_result_file, "%sSET GLOBAL gtid_slave_pos='%s';\n", + gtid_comment_prefix, gtid_pos); + } + if (use_gtid) + print_comment(md_result_file, 0, + "\n-- Use only the MASTER_USE_GTID=slave_pos or " + "MASTER_LOG_FILE/MASTER_LOG_POS in the statements below." + "\n\n"); + while ((row= mysql_fetch_row(slave))) { - if (multi_source && !set_gtid_done) - { - char gtid_pos[MAX_GTID_LENGTH]; - if (have_mariadb_gtid && get_gtid_pos(gtid_pos, 0)) - { - mysql_free_result(slave); - return 1; - } - if (opt_comments) - fprintf(md_result_file, "\n--\n-- Gtid position to start replication " - "from\n--\n\n"); - fprintf(md_result_file, "%sSET GLOBAL gtid_slave_pos='%s';\n", - gtid_comment_prefix, gtid_pos); - set_gtid_done= 1; - } if (row[9 + multi_source] && row[21 + multi_source]) { if (use_gtid) @@ -6370,11 +6388,6 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid, } /* SHOW MASTER STATUS reports file and position */ - if (opt_comments) - fprintf(md_result_file, - "\n--\n-- Position to start replication or point-in-time " - "recovery from (the master of this slave)\n--\n\n"); - if (multi_source) fprintf(md_result_file, "%sCHANGE MASTER '%.80s' TO ", nogtid_comment_prefix, row[0]); @@ -6395,6 +6408,7 @@ static int do_show_slave_status(MYSQL *mysql_con, int use_gtid, check_io(md_result_file); } } + fprintf(md_result_file, "\n"); mysql_free_result(slave); return 0; } diff --git a/cmake/pcre.cmake b/cmake/pcre.cmake index 3c427b881fc..752f882d4a8 100644 --- a/cmake/pcre.cmake +++ b/cmake/pcre.cmake @@ -4,6 +4,9 @@ SET(WITH_PCRE "auto" CACHE STRING "Which pcre to use (possible values are 'bundled', 'system', or 'auto')") MACRO(BUNDLE_PCRE2) + SET(WITH_PCRE "bundled" CACHE STRING + "Which pcre to use (possible values are 'bundled', 'system', or 'auto')") + SET(dir "${CMAKE_BINARY_DIR}/extra/pcre2") SET(PCRE_INCLUDE_DIRS ${dir}/src/pcre2-build ${dir}/src/pcre2/src) MESSAGE(STATUS "Will download and bundle pcre2") diff --git a/debian/mariadb-server.mariadb.init b/debian/mariadb-server.mariadb.init index 960e5de60cf..26439cf44e4 100644 --- a/debian/mariadb-server.mariadb.init +++ b/debian/mariadb-server.mariadb.init @@ -88,7 +88,7 @@ sanity_checks() { # If datadir location is not changed int configuration # then it's not printed with /usr/sbin/mariadbd --print-defaults # then we use 'sane' default. - if [ -z "$datadir"] + if [ -z "$datadir" ] then datadir="/var/lib/mysql" fi diff --git a/debian/rules b/debian/rules index f90d943efc2..b4ca7897dcc 100755 --- a/debian/rules +++ b/debian/rules @@ -98,7 +98,6 @@ endif -DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DMYSQL_SERVER_SUFFIX="-$(DEB_VERSION_REVISION)" \ -DSYSTEM_TYPE="debian-$(DEB_HOST_GNU_SYSTEM)" \ - -DCMAKE_SYSTEM_PROCESSOR=$(DEB_HOST_ARCH) \ -DBUILD_CONFIG=mysql_release \ -DCONC_DEFAULT_CHARSET=utf8mb4 \ -DPLUGIN_AWS_KEY_MANAGEMENT=NO \ diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc index c2f15da48f8..bc76b5b2b6b 100644 --- a/extra/mariabackup/backup_mysql.cc +++ b/extra/mariabackup/backup_mysql.cc @@ -47,6 +47,12 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include #include #include +#ifdef HAVE_PWD_H +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#include +#endif #include "common.h" #include "xtrabackup.h" #include "srv0srv.h" @@ -92,11 +98,54 @@ MYSQL *mysql_connection; extern my_bool opt_ssl_verify_server_cert, opt_use_ssl; + +/* + get_os_user() + Ressemles read_user_name() from libmariadb/libmariadb/mariadb_lib.c. +*/ + +#if !defined(_WIN32) + +#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) +struct passwd *getpwuid(uid_t); +char* getlogin(void); +#endif + +static const char *get_os_user() // Posix +{ + if (!geteuid()) + return "root"; +#ifdef HAVE_GETPWUID + struct passwd *pw; + const char *str; + if ((pw= getpwuid(geteuid())) != NULL) + return pw->pw_name; + if ((str= getlogin()) != NULL) + return str; +#endif + if ((str= getenv("USER")) || + (str= getenv("LOGNAME")) || + (str= getenv("LOGIN"))) + return str; + return NULL; +} + +#else + +static const char *get_os_user() // Windows +{ + return getenv("USERNAME"); +} + +#endif // _WIN32 + + MYSQL * xb_mysql_connect() { MYSQL *connection = mysql_init(NULL); char mysql_port_str[std::numeric_limits::digits10 + 3]; + const char *user= opt_user ? opt_user : get_os_user(); sprintf(mysql_port_str, "%d", opt_port); @@ -126,7 +175,7 @@ xb_mysql_connect() msg("Connecting to MariaDB server host: %s, user: %s, password: %s, " "port: %s, socket: %s", opt_host ? opt_host : "localhost", - opt_user ? opt_user : "not set", + user ? user : "not set", opt_password ? "set" : "not set", opt_port != 0 ? mysql_port_str : "not set", opt_socket ? opt_socket : "not set"); @@ -147,7 +196,7 @@ xb_mysql_connect() if (!mysql_real_connect(connection, opt_host ? opt_host : "localhost", - opt_user, + user, opt_password, "" /*database*/, opt_port, opt_socket, 0)) { diff --git a/include/mysql/service_print_check_msg.h b/include/mysql/service_print_check_msg.h new file mode 100644 index 00000000000..c2c7cf0a381 --- /dev/null +++ b/include/mysql/service_print_check_msg.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2019, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#pragma once + +/** + @file include/mysql/service_print_check_msg.h + This service provides functions to write messages for check or repair +*/ + +#ifdef __cplusplus +extern "C" { +#endif + + +extern struct print_check_msg_service_st { + void (*print_check_msg)(MYSQL_THD, const char *db_name, const char *table_name, + const char *op, const char *msg_type, const char *message, + my_bool print_to_log); +} *print_check_msg_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN +# define print_check_msg_context(_THD) print_check_msg_service->print_check_msg +#else +extern void print_check_msg(MYSQL_THD, const char *db_name, const char *table_name, + const char *op, const char *msg_type, const char *message, + my_bool print_to_log); +#endif + +#ifdef __cplusplus +} +#endif diff --git a/include/service_versions.h b/include/service_versions.h index 9abae740a7b..c8169614de2 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -44,6 +44,7 @@ #define VERSION_wsrep 0x0500 #define VERSION_json 0x0100 #define VERSION_thd_mdl 0x0100 +#define VERSION_print_check_msg 0x0100 #define VERSION_sql_service 0x0101 #define VERSION_provider_bzip2 0x0100 diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index 8c559cb07f5..37c24646791 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -25,6 +25,7 @@ SET(MYSQLSERVICES_SOURCES my_crypt_service.c my_md5_service.c my_print_error_service.c + print_check_msg_service.c my_sha1_service.c my_sha2_service.c my_snprintf_service.c diff --git a/libservices/print_check_msg_service.c b/libservices/print_check_msg_service.c new file mode 100644 index 00000000000..12f7bc51118 --- /dev/null +++ b/libservices/print_check_msg_service.c @@ -0,0 +1,18 @@ +/* Copyright (c) 2024, MariaDB Plc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +SERVICE_VERSION print_check_msg_context= (void*) VERSION_print_check_msg; diff --git a/mysql-test/include/rpl_clone_slave_using_mariadb-backup.inc b/mysql-test/include/rpl_clone_slave_using_mariadb-backup.inc new file mode 100644 index 00000000000..96fcfa2110a --- /dev/null +++ b/mysql-test/include/rpl_clone_slave_using_mariadb-backup.inc @@ -0,0 +1,297 @@ +if ($cnf == "galera2_to_mariadb") +{ + --let MASTER_MYPORT= $NODE_MYPORT_1 + --connect master, 127.0.0.1, root, , test, $NODE_MYPORT_1 + --connect slave, 127.0.0.1, root, , test, $NODE_MYPORT_3 + --disable_query_log + --replace_result $MASTER_MYPORT ### + --eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_PORT=$MASTER_MYPORT, MASTER_USE_GTID=NO; + --enable_query_log + START SLAVE; + --source include/wait_for_slave_to_start.inc + + --let XTRABACKUP_BACKUP_OPTIONS=--no-defaults --user=root --host='127.0.0.1' --port=$NODE_MYPORT_3 + --let XTRABACKUP_COPY_BACK_OPTIONS= --no-defaults +} + +if ($cnf == "mariadb_to_mariadb") +{ + --let XTRABACKUP_BACKUP_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 + --let XTRABACKUP_COPY_BACK_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 +} + +--connection master +--let $MYSQLD_DATADIR_MASTER= `select @@datadir` +--connection slave +--let $MYSQLD_DATADIR_SLAVE= `select @@datadir` + +# This test covers the filename:pos based synchronization +# between the master and the slave. +# If we ever need to test a GTID based synchronization, +# it should be done in a separate test. + + +--echo ############################################################## +--echo ### Initial block with some transactions + +--echo ### Slave: Make sure replication is not using GTID +--connection slave +--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1) +--echo # Using_Gtid=$value + +--echo ### Master: Create and populate t1 +--connection master +CREATE TABLE t1(a TEXT) ENGINE=InnoDB; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#00:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#02 - slave run#0, before backup'); +COMMIT; +--sync_slave_with_master + + + +--echo ############################################################## +--echo ### Run the last transaction before mariadb-backup --backup +--echo ### Remember SHOW MASTER STATUS and @@gtid_binlog_pos +--echo ### before and after the transaction. + +--echo ### Master: Rember MASTER STATUS and @@gtid_binlog_pos before tr#01 +--connection master +--let $master_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $master_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $master_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos before tr#01 +--connection slave +--let $slave_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $slave_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $slave_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + +--echo ### Master: Run the actual last transaction before the backup +--connection master +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#01:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#02 - slave run#0, before backup'); +COMMIT; +--sync_slave_with_master + +--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +--connection master +--let $master_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $master_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $master_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +--connection slave +--let $slave_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $slave_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $slave_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + + +--echo ############################################################## +--echo ### Running `mariadb-backup --backup,--prepare` and checking +--echo ### that xtrabackup_slave_info and xtrabackup_binlog_info are OK + +--echo ### Slave: Create a backup +--let $backup_slave=$MYSQLTEST_VARDIR/tmp/backup-slave +--disable_result_log +--exec $XTRABACKUP $XTRABACKUP_BACKUP_OPTIONS --slave-info --backup --target-dir=$backup_slave +--enable_result_log + +--echo ### Slave: Prepare the backup +--exec $XTRABACKUP --prepare --target-dir=$backup_slave + +--echo ### Slave: xtrabackup files: +--echo ############################ xtrabackup_slave_info +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position +--cat_file $backup_slave/xtrabackup_slave_info +--echo ############################ xtrabackup_binlog_info +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr01_gtid_binlog_pos slave_after_tr01_gtid_binlog_pos +--cat_file $backup_slave/xtrabackup_binlog_info +--echo ############################ + + +--echo ############################################################## +--echo ### Run more transactions after the backup: +--echo ### - while the slave is still running, then +--echo ### - while the slave is shut down + +--echo ### Master: Run another transaction while the slave is still running +--connection master +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt#01 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt@02 - slave run#0, after backup'); +COMMIT; +--sync_slave_with_master + +--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +--connection master +--let $master_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $master_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $master_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +--connection slave +--let $slave_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) +--let $slave_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) +--let $slave_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` + + +--echo ### Master: Checking SHOW BINLOG EVENTS + +--connection master +--vertical_results +### The BEGIN event +--replace_column 4 # 5 # +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position $master_after_tr02_gtid_binlog_pos master_after_tr02_gtid_binlog_pos +--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 0,1 +### The INSERT event +--replace_column 2 # 4 # 5 # +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position +# Hide the difference between row and stmt binary logging +--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/ +--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 1,1 +--horizontal_results + +--echo ### Slave: Checking SHOW BINLOG EVENTS +--connection slave +--vertical_results +### The BEGIN event +--replace_column 2 # 5 # +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos +--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 0,1 +### The INSERT event +--replace_column 2 # 4 # 5 # +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos +# Hide the difference between row and stmt binary logging +--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/ +--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 1,1 +--horizontal_results + +--echo ### Slave: Stop replication +--connection slave +STOP SLAVE; +--source include/wait_for_slave_to_stop.inc +RESET SLAVE; + +--echo ### Slave: Shutdown the server + +if ($cnf == "mariadb_to_mariadb") +{ + --let $rpl_server_number= 2 + --source include/rpl_stop_server.inc +} + +if ($cnf == "galera2_to_mariadb") +{ + --connection slave + --source $MYSQL_TEST_DIR/include/shutdown_mysqld.inc +} + +--echo ### Master: Run a transaction while the slave is shut down +--connection master +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#03:stmt#00 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#01 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#02 - after slave run#0, slave is shut down, after backup'); +COMMIT; + + +--echo ############################################################## +--echo ### Emulate starting a new virgin slave + +--echo ### Slave: Remove the data directory +--rmdir $MYSQLD_DATADIR_SLAVE + +--echo ### Slave: Copy back the backup +--exec $XTRABACKUP $XTRABACKUP_COPY_BACK_OPTIONS --copy-back --datadir=$MYSQLD_DATADIR_SLAVE --target-dir=$backup_slave + +--echo ### Slave: Restart the server +if ($cnf == "mariadb_to_mariadb") +{ + --let $rpl_server_number= 2 + --source include/rpl_start_server.inc + --source include/wait_until_connected_again.inc +} + +if ($cnf == "galera2_to_mariadb") +{ + --connection slave + --source $MYSQL_TEST_DIR/include/start_mysqld.inc +} + +--echo ### Slave: Display the restored data before START SLAVE +--connection slave +SELECT * FROM t1 ORDER BY a; + +--echo ### Slave: Execute the CHANGE MASTER statement to set up the host and port +--replace_result $MASTER_MYPORT ### +--eval CHANGE MASTER '' TO MASTER_USER='root', MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_CONNECT_RETRY=1 + +--echo ### Slave: Execute the CHANGE MASTER statement from xtrabackup_slave_info +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position +--source $backup_slave/xtrabackup_slave_info + +--echo ### Slave: Execute START SLAVE +--source include/start_slave.inc + +--echo ### Master: Wait for the slave to apply all master events +--connection master +--sync_slave_with_master slave + +--echo ### Slave: Make sure replication is not using GTID after the slave restart +--connection slave +--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1) +--echo # Using_Gtid=$value + +--echo ### Slave: Display the restored data after START SLAVE +--connection slave +SELECT * FROM t1 ORDER BY a; + + +--echo ############################################################## +--echo ### Continue master transactions, check the new slave replicates well. + +--echo ### Master: Run a transaction after restarting replication +--connection master +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#04:stmt#00 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#01 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#02 - slave run#1'); +COMMIT; +--sync_slave_with_master + +--echo ### Slave: Display the restored data + new transactions +--connection slave +SELECT * FROM t1 ORDER BY a; + + +--echo ############################################################## +--echo ### Cleanup + +--echo ### Removing the backup directory +--rmdir $backup_slave + +--connection master +DROP TABLE t1; +--sync_slave_with_master + +if ($cnf == "mariadb_to_mariadb") +{ + --source include/rpl_end.inc +} + +if ($cnf == "galera2_to_mariadb") +{ + STOP SLAVE; + --source include/wait_for_slave_to_stop.inc + RESET SLAVE ALL; + + --connection master + set global wsrep_on=OFF; + RESET MASTER; + set global wsrep_on=ON; +} diff --git a/mysql-test/lib/mtr_report.pm b/mysql-test/lib/mtr_report.pm index 97c48c19112..0c3c45f3b18 100644 --- a/mysql-test/lib/mtr_report.pm +++ b/mysql-test/lib/mtr_report.pm @@ -87,12 +87,16 @@ sub flush_out { $out_line = ""; } +use if $^O eq "MSWin32", "threads::shared"; +my $flush_lock :shared; + # Print to stdout sub print_out { if(IS_WIN32PERL) { $out_line .= $_[0]; # Flush buffered output on new lines. if (rindex($_[0], "\n") != -1) { + lock($flush_lock); flush_out(); } } else { diff --git a/mysql-test/main/innodb_ext_key.test b/mysql-test/main/innodb_ext_key.test index abec58a1d53..bb46f7d47fc 100644 --- a/mysql-test/main/innodb_ext_key.test +++ b/mysql-test/main/innodb_ext_key.test @@ -5,6 +5,8 @@ --source include/innodb_prefix_index_cluster_optimization.inc --source include/no_valgrind_without_big.inc +--source include/innodb_stable_estimates.inc + SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; set @innodb_stats_persistent_save= @@innodb_stats_persistent; diff --git a/mysql-test/main/rpl_mysqldump_slave.result b/mysql-test/main/rpl_mysqldump_slave.result index 9f93e3c405e..0d0378abd5b 100644 --- a/mysql-test/main/rpl_mysqldump_slave.result +++ b/mysql-test/main/rpl_mysqldump_slave.result @@ -9,23 +9,27 @@ use test; connection slave; -- SET GLOBAL gtid_slave_pos=''; CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + STOP ALL SLAVES; -- SET GLOBAL gtid_slave_pos=''; CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + START ALL SLAVES; STOP ALL SLAVES; -- SET GLOBAL gtid_slave_pos=''; CHANGE MASTER '' TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + START ALL SLAVES; start slave; Warnings: Note 1254 Slave is already running -- SET GLOBAL gtid_slave_pos=''; CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + start slave; Warnings: Note 1254 Slave is already running -*** Test mysqldump --dump-slave GTID functionality. +*** Test mysqldump --dump-slave GTID/non-gtid functionality. connection master; SET gtid_seq_no = 1000; CREATE TABLE t1 (a INT PRIMARY KEY); @@ -35,36 +39,170 @@ connection slave; CREATE TABLE t2 (a INT PRIMARY KEY); DROP TABLE t2; -1. --dump-slave=1 +1. --dump-slave=1 --gtid SET GLOBAL gtid_slave_pos='0-1-1001'; CHANGE MASTER '' TO MASTER_USE_GTID=slave_pos; -- CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; -2. --dump-slave=2 + +1a. --dump-slave=1 + +-- SET GLOBAL gtid_slave_pos='0-1-1001'; +CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + + +2. --dump-slave=2 --gtid -- SET GLOBAL gtid_slave_pos='0-1-1001'; -- CHANGE MASTER '' TO MASTER_USE_GTID=slave_pos; -- CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; -*** Test mysqldump --master-data GTID functionality. -1. --master-data=1 --- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; +2. --dump-slave=2 + +-- SET GLOBAL gtid_slave_pos='0-1-1001'; +-- CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + +*** Test mysqldump --master-data GTID/non-gtid functionality. + +1. --master-data=1 --gtid + CHANGE MASTER TO MASTER_USE_GTID=slave_pos; SET GLOBAL gtid_slave_pos='0-2-1003'; - -2. --master-data=2 - -- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +1a. --master-data=1 + +-- SET GLOBAL gtid_slave_pos='0-2-1003'; +CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +2. --master-data=2 --gtid + +-- CHANGE MASTER TO MASTER_USE_GTID=slave_pos; +-- SET GLOBAL gtid_slave_pos='0-2-1003'; +-- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +2a. --master-data=2 + +-- SET GLOBAL gtid_slave_pos='0-2-1003'; +-- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +3. --master-data --single-transaction --gtid + +CHANGE MASTER TO MASTER_USE_GTID=slave_pos; +SET GLOBAL gtid_slave_pos='0-2-1003'; +-- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +3a. --master-data --single-transaction + +-- SET GLOBAL gtid_slave_pos='0-2-1003'; +CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +4. --master-data=2 --dump-slave=2 --single-transaction --gtid (MDEV-4827) + +-- MariaDB dump-- +-- Host: localhost Database: test +-- ------------------------------------------------------ +-- Server version +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- Preferably use GTID to start replication from GTID position: + -- CHANGE MASTER TO MASTER_USE_GTID=slave_pos; -- SET GLOBAL gtid_slave_pos='0-2-1003'; -3. --master-data --single-transaction +-- +-- Alternately, following is the position of the binary logging from SHOW MASTER STATUS at point of backup. +-- Use this when creating a replica of the primary server where the backup was made. +-- The new server will be connecting to the primary server where the backup was taken. +-- -- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; -CHANGE MASTER TO MASTER_USE_GTID=slave_pos; -SET GLOBAL gtid_slave_pos='0-2-1003'; + +-- +-- The following is the SQL position of the replication taken from SHOW SLAVE STATUS at the time of backup. +-- Use this position when creating a clone of, or replacement server, from where the backup was taken. +-- This new server will connects to the same primary server(s). +-- +-- GTID position to start replication: +-- SET GLOBAL gtid_slave_pos='0-1-1001'; + +-- Use only the MASTER_USE_GTID=slave_pos or MASTER_LOG_FILE/MASTER_LOG_POS in the statements below. + +-- CHANGE MASTER '' TO MASTER_USE_GTID=slave_pos; +-- CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed + +4a. --master-data=2 --dump-slave=2 --single-transaction (MDEV-4827) + +-- MariaDB dump-- +-- Host: localhost Database: test +-- ------------------------------------------------------ +-- Server version +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- Preferably use GTID to start replication from GTID position: + +-- SET GLOBAL gtid_slave_pos='0-2-1003'; + +-- +-- Alternately, following is the position of the binary logging from SHOW MASTER STATUS at point of backup. +-- Use this when creating a replica of the primary server where the backup was made. +-- The new server will be connecting to the primary server where the backup was taken. +-- + +-- CHANGE MASTER TO MASTER_LOG_FILE='slave-bin.000001', MASTER_LOG_POS=BINLOG_START; + +-- +-- The following is the SQL position of the replication taken from SHOW SLAVE STATUS at the time of backup. +-- Use this position when creating a clone of, or replacement server, from where the backup was taken. +-- This new server will connects to the same primary server(s). +-- +-- GTID position to start replication: +-- SET GLOBAL gtid_slave_pos='0-1-1001'; +-- CHANGE MASTER '' TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=BINLOG_START; + +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed connection master; CREATE TABLE t ( id int @@ -77,8 +215,8 @@ include/stop_slave.inc change master to master_use_gtid=slave_pos; connection master; # Ensuring the binlog dump thread is killed on primary... --- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000002', MASTER_LOG_POS=BINLOG_START; -- SET GLOBAL gtid_slave_pos='0-1-1005'; +-- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000002', MASTER_LOG_POS=BINLOG_START; connection slave; include/start_slave.inc include/rpl_end.inc diff --git a/mysql-test/main/rpl_mysqldump_slave.test b/mysql-test/main/rpl_mysqldump_slave.test index 0273e196db5..9dbee604520 100644 --- a/mysql-test/main/rpl_mysqldump_slave.test +++ b/mysql-test/main/rpl_mysqldump_slave.test @@ -37,7 +37,7 @@ start slave; start slave; ---echo *** Test mysqldump --dump-slave GTID functionality. +--echo *** Test mysqldump --dump-slave GTID/non-gtid functionality. --connection master SET gtid_seq_no = 1000; @@ -52,37 +52,80 @@ CREATE TABLE t2 (a INT PRIMARY KEY); DROP TABLE t2; --echo ---echo 1. --dump-slave=1 +--echo 1. --dump-slave=1 --gtid --echo --replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ --exec $MYSQL_DUMP_SLAVE --compact --dump-slave=1 --gtid test --echo ---echo 2. --dump-slave=2 +--echo 1a. --dump-slave=1 +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ +--exec $MYSQL_DUMP_SLAVE --compact --dump-slave=1 test + +--echo +--echo 2. --dump-slave=2 --gtid --echo --replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ --exec $MYSQL_DUMP_SLAVE --compact --dump-slave=2 --gtid test - ---echo *** Test mysqldump --master-data GTID functionality. --echo ---echo 1. --master-data=1 +--echo 2. --dump-slave=2 +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ +--exec $MYSQL_DUMP_SLAVE --compact --dump-slave=2 test + + +--echo *** Test mysqldump --master-data GTID/non-gtid functionality. +--echo +--echo 1. --master-data=1 --gtid --echo --replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ --exec $MYSQL_DUMP_SLAVE --compact --master-data=1 --gtid test --echo ---echo 2. --master-data=2 +--echo 1a. --master-data=1 +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ +--exec $MYSQL_DUMP_SLAVE --compact --master-data=1 test + +--echo +--echo 2. --master-data=2 --gtid --echo --replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ --exec $MYSQL_DUMP_SLAVE --compact --master-data=2 --gtid test --echo ---echo 3. --master-data --single-transaction +--echo 2a. --master-data=2 +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ +--exec $MYSQL_DUMP_SLAVE --compact --master-data=2 test + +--echo +--echo 3. --master-data --single-transaction --gtid --echo --replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ --exec $MYSQL_DUMP_SLAVE --compact --master-data --single-transaction --gtid test +--echo +--echo 3a. --master-data --single-transaction +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ +--exec $MYSQL_DUMP_SLAVE --compact --master-data --single-transaction test + +--echo +--echo 4. --master-data=2 --dump-slave=2 --single-transaction --gtid (MDEV-4827) +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ /MariaDB dump.*/MariaDB dump/ /Dump completed.*/Dump completed/ /Server version.*/Server version/ +--exec $MYSQL_DUMP_SLAVE --master-data=2 --dump-slave=2 --single-transaction --gtid test +--echo + +--echo +--echo 4a. --master-data=2 --dump-slave=2 --single-transaction (MDEV-4827) +--echo +--replace_regex /MASTER_LOG_POS=[0-9]+/MASTER_LOG_POS=BINLOG_START/ /MariaDB dump.*/MariaDB dump/ /Dump completed.*/Dump completed/ /Server version.*/Server version/ +--exec $MYSQL_DUMP_SLAVE --master-data=2 --dump-slave=2 --single-transaction test +--echo # # MDEV-32611 Added test for mysqldump --delete-master-logs option. # This options is alias of diff --git a/mysql-test/main/selectivity_innodb_notembedded.result b/mysql-test/main/selectivity_innodb_notembedded.result index 8b06fe7556b..a387d241ff3 100644 --- a/mysql-test/main/selectivity_innodb_notembedded.result +++ b/mysql-test/main/selectivity_innodb_notembedded.result @@ -88,15 +88,142 @@ sel ] set optimizer_trace=@tmp; drop table t0,t1,t10; -set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set histogram_size=@save_histogram_size; -set use_stat_tables= @save_use_stat_tables; # # End of 10.4 tests # # +# MDEV-33314: Crash inside calculate_cond_selectivity_for_table() with many columns +# +set optimizer_use_condition_selectivity= 4; +set use_stat_tables= preferably; +# +# create table t1 (col0 int, col1 int, col2 int, ...); +# +$create_tbl; +# +# insert into t1 select seq, ... seq from seq_1_to_10; +# +$insert_cmd; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +set @trace_tmp=@@optimizer_trace; +set optimizer_trace=1; +# +# Basic testcase: don't crash for many-column selectivity +# explain extended select * from t1 where col0>1 and col1>1 and col2>1 and ... +# +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 53.32928848, + "attached_condition": "t1.col0 > 1 and t1.col1 > 1 and t1.col2 > 1 and t1.col3 > 1 and t1.col4 > 1 and t1.col5 > 1 and t1.col6 > 1 and t1.col7 > 1 and t1.col8 > 1 and t1.col9 > 1 and t1.col10 > 1 and t1.col11 > 1 and t1.col12 > 1 and t1.col13 > 1 and t1.col14 > 1 and t1.col15 > 1 and t1.col16 > 1 and t1.col17 > 1 and t1.col18 > 1 and t1.col19 > 1 and t1.col20 > 1 and t1.col21 > 1 and t1.col22 > 1 and t1.col23 > 1 and t1.col24 > 1 and t1.col25 > 1 and t1.col26 > 1 and t1.col27 > 1 and t1.col28 > 1 and t1.col29 > 1 and t1.col30 > 1 and t1.col31 > 1 and t1.col32 > 1 and t1.col33 > 1 and t1.col34 > 1 and t1.col35 > 1 and t1.col36 > 1 and t1.col37 > 1 and t1.col38 > 1 and t1.col39 > 1 and t1.col40 > 1 and t1.col41 > 1 and t1.col42 > 1 and t1.col43 > 1 and t1.col44 > 1 and t1.col45 > 1 and t1.col46 > 1 and t1.col47 > 1 and t1.col48 > 1 and t1.col49 > 1 and t1.col50 > 1 and t1.col51 > 1 and t1.col52 > 1 and t1.col53 > 1 and t1.col54 > 1 and t1.col55 > 1 and t1.col56 > 1 and t1.col57 > 1 and t1.col58 > 1 and t1.col59 > 1 and t1.col60 > 1 and t1.col61 > 1 and t1.col62 > 1 and t1.col63 > 1 and t1.col64 > 1 and t1.col65 > 1 and t1.col66 > 1 and t1.col67 > 1 and t1.col68 > 1 and t1.col69 > 1 and t1.col70 > 1 and t1.col71 > 1 and t1.col72 > 1 and t1.col73 > 1 and t1.col74 > 1 and t1.col75 > 1 and t1.col76 > 1 and t1.col77 > 1 and t1.col78 > 1 and t1.col79 > 1 and t1.col80 > 1 and t1.col81 > 1 and t1.col82 > 1 and t1.col83 > 1 and t1.col84 > 1 and t1.col85 > 1 and t1.col86 > 1 and t1.col87 > 1 and t1.col88 > 1 and t1.col89 > 1 and t1.col90 > 1 and t1.col91 > 1 and t1.col92 > 1 and t1.col93 > 1 and t1.col94 > 1 and t1.col95 > 1 and t1.col96 > 1 and t1.col97 > 1 and t1.col98 > 1 and t1.col99 > 1 and t1.col100 > 1 and t1.col101 > 1 and t1.col102 > 1 and t1.col103 > 1 and t1.col104 > 1 and t1.col105 > 1 and t1.col106 > 1 and t1.col107 > 1 and t1.col108 > 1 and t1.col109 > 1 and t1.col110 > 1 and t1.col111 > 1 and t1.col112 > 1 and t1.col113 > 1 and t1.col114 > 1 and t1.col115 > 1 and t1.col116 > 1 and t1.col117 > 1 and t1.col118 > 1 and t1.col119 > 1 and t1.col120 > 1 and t1.col121 > 1 and t1.col122 > 1 and t1.col123 > 1 and t1.col124 > 1 and t1.col125 > 1 and t1.col126 > 1 and t1.col127 > 1 and t1.col128 > 1 and t1.col129 > 1 and t1.col130 > 1 and t1.col131 > 1 and t1.col132 > 1 and t1.col133 > 1 and t1.col134 > 1 and t1.col135 > 1 and t1.col136 > 1 and t1.col137 > 1 and t1.col138 > 1 and t1.col139 > 1 and t1.col140 > 1 and t1.col141 > 1 and t1.col142 > 1 and t1.col143 > 1 and t1.col144 > 1 and t1.col145 > 1 and t1.col146 > 1 and t1.col147 > 1 and t1.col148 > 1 and t1.col149 > 1 and t1.col150 > 1 and t1.col151 > 1 and t1.col152 > 1 and t1.col153 > 1 and t1.col154 > 1 and t1.col155 > 1 and t1.col156 > 1 and t1.col157 > 1 and t1.col158 > 1 and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns[0]')) as JS +from +information_schema.optimizer_trace; +JS +[ + { + "column_name": "col0", + "ranges": + ["1 < col0"], + "selectivity_from_histogram": 0.996078431 + } +] +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 53.32928848, + "attached_condition": "t1.col0 > 1 and t1.col1 > 1 and t1.col2 > 1 and t1.col3 > 1 and t1.col4 > 1 and t1.col5 > 1 and t1.col6 > 1 and t1.col7 > 1 and t1.col8 > 1 and t1.col9 > 1 and t1.col10 > 1 and t1.col11 > 1 and t1.col12 > 1 and t1.col13 > 1 and t1.col14 > 1 and t1.col15 > 1 and t1.col16 > 1 and t1.col17 > 1 and t1.col18 > 1 and t1.col19 > 1 and t1.col20 > 1 and t1.col21 > 1 and t1.col22 > 1 and t1.col23 > 1 and t1.col24 > 1 and t1.col25 > 1 and t1.col26 > 1 and t1.col27 > 1 and t1.col28 > 1 and t1.col29 > 1 and t1.col30 > 1 and t1.col31 > 1 and t1.col32 > 1 and t1.col33 > 1 and t1.col34 > 1 and t1.col35 > 1 and t1.col36 > 1 and t1.col37 > 1 and t1.col38 > 1 and t1.col39 > 1 and t1.col40 > 1 and t1.col41 > 1 and t1.col42 > 1 and t1.col43 > 1 and t1.col44 > 1 and t1.col45 > 1 and t1.col46 > 1 and t1.col47 > 1 and t1.col48 > 1 and t1.col49 > 1 and t1.col50 > 1 and t1.col51 > 1 and t1.col52 > 1 and t1.col53 > 1 and t1.col54 > 1 and t1.col55 > 1 and t1.col56 > 1 and t1.col57 > 1 and t1.col58 > 1 and t1.col59 > 1 and t1.col60 > 1 and t1.col61 > 1 and t1.col62 > 1 and t1.col63 > 1 and t1.col64 > 1 and t1.col65 > 1 and t1.col66 > 1 and t1.col67 > 1 and t1.col68 > 1 and t1.col69 > 1 and t1.col70 > 1 and t1.col71 > 1 and t1.col72 > 1 and t1.col73 > 1 and t1.col74 > 1 and t1.col75 > 1 and t1.col76 > 1 and t1.col77 > 1 and t1.col78 > 1 and t1.col79 > 1 and t1.col80 > 1 and t1.col81 > 1 and t1.col82 > 1 and t1.col83 > 1 and t1.col84 > 1 and t1.col85 > 1 and t1.col86 > 1 and t1.col87 > 1 and t1.col88 > 1 and t1.col89 > 1 and t1.col90 > 1 and t1.col91 > 1 and t1.col92 > 1 and t1.col93 > 1 and t1.col94 > 1 and t1.col95 > 1 and t1.col96 > 1 and t1.col97 > 1 and t1.col98 > 1 and t1.col99 > 1 and t1.col100 > 1 and t1.col101 > 1 and t1.col102 > 1 and t1.col103 > 1 and t1.col104 > 1 and t1.col105 > 1 and t1.col106 > 1 and t1.col107 > 1 and t1.col108 > 1 and t1.col109 > 1 and t1.col110 > 1 and t1.col111 > 1 and t1.col112 > 1 and t1.col113 > 1 and t1.col114 > 1 and t1.col115 > 1 and t1.col116 > 1 and t1.col117 > 1 and t1.col118 > 1 and t1.col119 > 1 and t1.col120 > 1 and t1.col121 > 1 and t1.col122 > 1 and t1.col123 > 1 and t1.col124 > 1 and t1.col125 > 1 and t1.col126 > 1 and t1.col127 > 1 and t1.col128 > 1 and t1.col129 > 1 and t1.col130 > 1 and t1.col131 > 1 and t1.col132 > 1 and t1.col133 > 1 and t1.col134 > 1 and t1.col135 > 1 and t1.col136 > 1 and t1.col137 > 1 and t1.col138 > 1 and t1.col139 > 1 and t1.col140 > 1 and t1.col141 > 1 and t1.col142 > 1 and t1.col143 > 1 and t1.col144 > 1 and t1.col145 > 1 and t1.col146 > 1 and t1.col147 > 1 and t1.col148 > 1 and t1.col149 > 1 and t1.col150 > 1 and t1.col151 > 1 and t1.col152 > 1 and t1.col153 > 1 and t1.col154 > 1 and t1.col155 > 1 and t1.col156 > 1 and t1.col157 > 1 and t1.col158 > 1 and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns[159]')) as JS +from +information_schema.optimizer_trace; +JS +[ + { + "column_name": "col159", + "ranges": + ["1 < col159"], + "selectivity_from_histogram": 0.996078431 + } +] +# +# Check if not being able to infer anything for the first MAX_KEY +# columns doesn't prevent further inferences. +# +# explain extended select * from t1 +# where (1>2 or col0>1 or col1>1 or ...) and col99>1 +# +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 99.60784149, + "attached_condition": "(t1.col1 > 1 or t1.col2 > 1 or t1.col3 > 1 or t1.col4 > 1 or t1.col5 > 1 or t1.col6 > 1 or t1.col7 > 1 or t1.col8 > 1 or t1.col9 > 1 or t1.col10 > 1 or t1.col11 > 1 or t1.col12 > 1 or t1.col13 > 1 or t1.col14 > 1 or t1.col15 > 1 or t1.col16 > 1 or t1.col17 > 1 or t1.col18 > 1 or t1.col19 > 1 or t1.col20 > 1 or t1.col21 > 1 or t1.col22 > 1 or t1.col23 > 1 or t1.col24 > 1 or t1.col25 > 1 or t1.col26 > 1 or t1.col27 > 1 or t1.col28 > 1 or t1.col29 > 1 or t1.col30 > 1 or t1.col31 > 1 or t1.col32 > 1 or t1.col33 > 1 or t1.col34 > 1 or t1.col35 > 1 or t1.col36 > 1 or t1.col37 > 1 or t1.col38 > 1 or t1.col39 > 1 or t1.col40 > 1 or t1.col41 > 1 or t1.col42 > 1 or t1.col43 > 1 or t1.col44 > 1 or t1.col45 > 1 or t1.col46 > 1 or t1.col47 > 1 or t1.col48 > 1 or t1.col49 > 1 or t1.col50 > 1 or t1.col51 > 1 or t1.col52 > 1 or t1.col53 > 1 or t1.col54 > 1 or t1.col55 > 1 or t1.col56 > 1 or t1.col57 > 1 or t1.col58 > 1 or t1.col59 > 1 or t1.col60 > 1 or t1.col61 > 1 or t1.col62 > 1 or t1.col63 > 1 or t1.col64 > 1 or t1.col65 > 1 or t1.col66 > 1 or t1.col67 > 1 or t1.col68 > 1 or t1.col69 > 1 or t1.col70 > 1 or t1.col71 > 1 or t1.col72 > 1 or t1.col73 > 1 or t1.col74 > 1 or t1.col75 > 1 or t1.col76 > 1 or t1.col77 > 1 or t1.col78 > 1 or t1.col79 > 1 or t1.col80 > 1 or t1.col81 > 1 or t1.col82 > 1 or t1.col83 > 1 or t1.col84 > 1 or t1.col85 > 1 or t1.col86 > 1 or t1.col87 > 1 or t1.col88 > 1 or t1.col89 > 1 or t1.col90 > 1 or t1.col91 > 1 or t1.col92 > 1 or t1.col93 > 1 or t1.col94 > 1 or t1.col95 > 1 or t1.col96 > 1 or t1.col97 > 1 or t1.col98 > 1 or t1.col99 > 1 or t1.col100 > 1 or t1.col101 > 1 or t1.col102 > 1 or t1.col103 > 1 or t1.col104 > 1 or t1.col105 > 1 or t1.col106 > 1 or t1.col107 > 1 or t1.col108 > 1 or t1.col109 > 1 or t1.col110 > 1 or t1.col111 > 1 or t1.col112 > 1 or t1.col113 > 1 or t1.col114 > 1 or t1.col115 > 1 or t1.col116 > 1 or t1.col117 > 1 or t1.col118 > 1 or t1.col119 > 1 or t1.col120 > 1 or t1.col121 > 1 or t1.col122 > 1 or t1.col123 > 1 or t1.col124 > 1 or t1.col125 > 1 or t1.col126 > 1 or t1.col127 > 1 or t1.col128 > 1 or t1.col129 > 1 or t1.col130 > 1 or t1.col131 > 1 or t1.col132 > 1 or t1.col133 > 1 or t1.col134 > 1 or t1.col135 > 1 or t1.col136 > 1 or t1.col137 > 1 or t1.col138 > 1 or t1.col139 > 1 or t1.col140 > 1 or t1.col141 > 1 or t1.col142 > 1 or t1.col143 > 1 or t1.col144 > 1 or t1.col145 > 1 or t1.col146 > 1 or t1.col147 > 1 or t1.col148 > 1 or t1.col149 > 1 or t1.col150 > 1 or t1.col151 > 1 or t1.col152 > 1 or t1.col153 > 1 or t1.col154 > 1 or t1.col155 > 1 or t1.col156 > 1 or t1.col157 > 1 or t1.col158 > 1) and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns')) as JS +from +information_schema.optimizer_trace; +JS +[ + [ + { + "column_name": "col159", + "ranges": + ["1 < col159"], + "selectivity_from_histogram": 0.996078431 + } + ] +] +set optimizer_trace=@trace_tmp; +drop table t1; +# # Clean up # +set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +set use_stat_tables= @save_use_stat_tables; set @@global.histogram_size=@save_histogram_size; set optimizer_switch=@save_optimizer_switch_for_selectivity_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/main/selectivity_notembedded.result b/mysql-test/main/selectivity_notembedded.result index d2e90a19a68..ac8922a2579 100644 --- a/mysql-test/main/selectivity_notembedded.result +++ b/mysql-test/main/selectivity_notembedded.result @@ -83,13 +83,140 @@ sel ] set optimizer_trace=@tmp; drop table t0,t1,t10; -set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set histogram_size=@save_histogram_size; -set use_stat_tables= @save_use_stat_tables; # # End of 10.4 tests # # +# MDEV-33314: Crash inside calculate_cond_selectivity_for_table() with many columns +# +set optimizer_use_condition_selectivity= 4; +set use_stat_tables= preferably; +# +# create table t1 (col0 int, col1 int, col2 int, ...); +# +$create_tbl; +# +# insert into t1 select seq, ... seq from seq_1_to_10; +# +$insert_cmd; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +set @trace_tmp=@@optimizer_trace; +set optimizer_trace=1; +# +# Basic testcase: don't crash for many-column selectivity +# explain extended select * from t1 where col0>1 and col1>1 and col2>1 and ... +# +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 53.32928848, + "attached_condition": "t1.col0 > 1 and t1.col1 > 1 and t1.col2 > 1 and t1.col3 > 1 and t1.col4 > 1 and t1.col5 > 1 and t1.col6 > 1 and t1.col7 > 1 and t1.col8 > 1 and t1.col9 > 1 and t1.col10 > 1 and t1.col11 > 1 and t1.col12 > 1 and t1.col13 > 1 and t1.col14 > 1 and t1.col15 > 1 and t1.col16 > 1 and t1.col17 > 1 and t1.col18 > 1 and t1.col19 > 1 and t1.col20 > 1 and t1.col21 > 1 and t1.col22 > 1 and t1.col23 > 1 and t1.col24 > 1 and t1.col25 > 1 and t1.col26 > 1 and t1.col27 > 1 and t1.col28 > 1 and t1.col29 > 1 and t1.col30 > 1 and t1.col31 > 1 and t1.col32 > 1 and t1.col33 > 1 and t1.col34 > 1 and t1.col35 > 1 and t1.col36 > 1 and t1.col37 > 1 and t1.col38 > 1 and t1.col39 > 1 and t1.col40 > 1 and t1.col41 > 1 and t1.col42 > 1 and t1.col43 > 1 and t1.col44 > 1 and t1.col45 > 1 and t1.col46 > 1 and t1.col47 > 1 and t1.col48 > 1 and t1.col49 > 1 and t1.col50 > 1 and t1.col51 > 1 and t1.col52 > 1 and t1.col53 > 1 and t1.col54 > 1 and t1.col55 > 1 and t1.col56 > 1 and t1.col57 > 1 and t1.col58 > 1 and t1.col59 > 1 and t1.col60 > 1 and t1.col61 > 1 and t1.col62 > 1 and t1.col63 > 1 and t1.col64 > 1 and t1.col65 > 1 and t1.col66 > 1 and t1.col67 > 1 and t1.col68 > 1 and t1.col69 > 1 and t1.col70 > 1 and t1.col71 > 1 and t1.col72 > 1 and t1.col73 > 1 and t1.col74 > 1 and t1.col75 > 1 and t1.col76 > 1 and t1.col77 > 1 and t1.col78 > 1 and t1.col79 > 1 and t1.col80 > 1 and t1.col81 > 1 and t1.col82 > 1 and t1.col83 > 1 and t1.col84 > 1 and t1.col85 > 1 and t1.col86 > 1 and t1.col87 > 1 and t1.col88 > 1 and t1.col89 > 1 and t1.col90 > 1 and t1.col91 > 1 and t1.col92 > 1 and t1.col93 > 1 and t1.col94 > 1 and t1.col95 > 1 and t1.col96 > 1 and t1.col97 > 1 and t1.col98 > 1 and t1.col99 > 1 and t1.col100 > 1 and t1.col101 > 1 and t1.col102 > 1 and t1.col103 > 1 and t1.col104 > 1 and t1.col105 > 1 and t1.col106 > 1 and t1.col107 > 1 and t1.col108 > 1 and t1.col109 > 1 and t1.col110 > 1 and t1.col111 > 1 and t1.col112 > 1 and t1.col113 > 1 and t1.col114 > 1 and t1.col115 > 1 and t1.col116 > 1 and t1.col117 > 1 and t1.col118 > 1 and t1.col119 > 1 and t1.col120 > 1 and t1.col121 > 1 and t1.col122 > 1 and t1.col123 > 1 and t1.col124 > 1 and t1.col125 > 1 and t1.col126 > 1 and t1.col127 > 1 and t1.col128 > 1 and t1.col129 > 1 and t1.col130 > 1 and t1.col131 > 1 and t1.col132 > 1 and t1.col133 > 1 and t1.col134 > 1 and t1.col135 > 1 and t1.col136 > 1 and t1.col137 > 1 and t1.col138 > 1 and t1.col139 > 1 and t1.col140 > 1 and t1.col141 > 1 and t1.col142 > 1 and t1.col143 > 1 and t1.col144 > 1 and t1.col145 > 1 and t1.col146 > 1 and t1.col147 > 1 and t1.col148 > 1 and t1.col149 > 1 and t1.col150 > 1 and t1.col151 > 1 and t1.col152 > 1 and t1.col153 > 1 and t1.col154 > 1 and t1.col155 > 1 and t1.col156 > 1 and t1.col157 > 1 and t1.col158 > 1 and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns[0]')) as JS +from +information_schema.optimizer_trace; +JS +[ + { + "column_name": "col0", + "ranges": + ["1 < col0"], + "selectivity_from_histogram": 0.996078431 + } +] +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 53.32928848, + "attached_condition": "t1.col0 > 1 and t1.col1 > 1 and t1.col2 > 1 and t1.col3 > 1 and t1.col4 > 1 and t1.col5 > 1 and t1.col6 > 1 and t1.col7 > 1 and t1.col8 > 1 and t1.col9 > 1 and t1.col10 > 1 and t1.col11 > 1 and t1.col12 > 1 and t1.col13 > 1 and t1.col14 > 1 and t1.col15 > 1 and t1.col16 > 1 and t1.col17 > 1 and t1.col18 > 1 and t1.col19 > 1 and t1.col20 > 1 and t1.col21 > 1 and t1.col22 > 1 and t1.col23 > 1 and t1.col24 > 1 and t1.col25 > 1 and t1.col26 > 1 and t1.col27 > 1 and t1.col28 > 1 and t1.col29 > 1 and t1.col30 > 1 and t1.col31 > 1 and t1.col32 > 1 and t1.col33 > 1 and t1.col34 > 1 and t1.col35 > 1 and t1.col36 > 1 and t1.col37 > 1 and t1.col38 > 1 and t1.col39 > 1 and t1.col40 > 1 and t1.col41 > 1 and t1.col42 > 1 and t1.col43 > 1 and t1.col44 > 1 and t1.col45 > 1 and t1.col46 > 1 and t1.col47 > 1 and t1.col48 > 1 and t1.col49 > 1 and t1.col50 > 1 and t1.col51 > 1 and t1.col52 > 1 and t1.col53 > 1 and t1.col54 > 1 and t1.col55 > 1 and t1.col56 > 1 and t1.col57 > 1 and t1.col58 > 1 and t1.col59 > 1 and t1.col60 > 1 and t1.col61 > 1 and t1.col62 > 1 and t1.col63 > 1 and t1.col64 > 1 and t1.col65 > 1 and t1.col66 > 1 and t1.col67 > 1 and t1.col68 > 1 and t1.col69 > 1 and t1.col70 > 1 and t1.col71 > 1 and t1.col72 > 1 and t1.col73 > 1 and t1.col74 > 1 and t1.col75 > 1 and t1.col76 > 1 and t1.col77 > 1 and t1.col78 > 1 and t1.col79 > 1 and t1.col80 > 1 and t1.col81 > 1 and t1.col82 > 1 and t1.col83 > 1 and t1.col84 > 1 and t1.col85 > 1 and t1.col86 > 1 and t1.col87 > 1 and t1.col88 > 1 and t1.col89 > 1 and t1.col90 > 1 and t1.col91 > 1 and t1.col92 > 1 and t1.col93 > 1 and t1.col94 > 1 and t1.col95 > 1 and t1.col96 > 1 and t1.col97 > 1 and t1.col98 > 1 and t1.col99 > 1 and t1.col100 > 1 and t1.col101 > 1 and t1.col102 > 1 and t1.col103 > 1 and t1.col104 > 1 and t1.col105 > 1 and t1.col106 > 1 and t1.col107 > 1 and t1.col108 > 1 and t1.col109 > 1 and t1.col110 > 1 and t1.col111 > 1 and t1.col112 > 1 and t1.col113 > 1 and t1.col114 > 1 and t1.col115 > 1 and t1.col116 > 1 and t1.col117 > 1 and t1.col118 > 1 and t1.col119 > 1 and t1.col120 > 1 and t1.col121 > 1 and t1.col122 > 1 and t1.col123 > 1 and t1.col124 > 1 and t1.col125 > 1 and t1.col126 > 1 and t1.col127 > 1 and t1.col128 > 1 and t1.col129 > 1 and t1.col130 > 1 and t1.col131 > 1 and t1.col132 > 1 and t1.col133 > 1 and t1.col134 > 1 and t1.col135 > 1 and t1.col136 > 1 and t1.col137 > 1 and t1.col138 > 1 and t1.col139 > 1 and t1.col140 > 1 and t1.col141 > 1 and t1.col142 > 1 and t1.col143 > 1 and t1.col144 > 1 and t1.col145 > 1 and t1.col146 > 1 and t1.col147 > 1 and t1.col148 > 1 and t1.col149 > 1 and t1.col150 > 1 and t1.col151 > 1 and t1.col152 > 1 and t1.col153 > 1 and t1.col154 > 1 and t1.col155 > 1 and t1.col156 > 1 and t1.col157 > 1 and t1.col158 > 1 and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns[159]')) as JS +from +information_schema.optimizer_trace; +JS +[ + { + "column_name": "col159", + "ranges": + ["1 < col159"], + "selectivity_from_histogram": 0.996078431 + } +] +# +# Check if not being able to infer anything for the first MAX_KEY +# columns doesn't prevent further inferences. +# +# explain extended select * from t1 +# where (1>2 or col0>1 or col1>1 or ...) and col99>1 +# +$query_tbl; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 100, + "filtered": 99.60784149, + "attached_condition": "(t1.col1 > 1 or t1.col2 > 1 or t1.col3 > 1 or t1.col4 > 1 or t1.col5 > 1 or t1.col6 > 1 or t1.col7 > 1 or t1.col8 > 1 or t1.col9 > 1 or t1.col10 > 1 or t1.col11 > 1 or t1.col12 > 1 or t1.col13 > 1 or t1.col14 > 1 or t1.col15 > 1 or t1.col16 > 1 or t1.col17 > 1 or t1.col18 > 1 or t1.col19 > 1 or t1.col20 > 1 or t1.col21 > 1 or t1.col22 > 1 or t1.col23 > 1 or t1.col24 > 1 or t1.col25 > 1 or t1.col26 > 1 or t1.col27 > 1 or t1.col28 > 1 or t1.col29 > 1 or t1.col30 > 1 or t1.col31 > 1 or t1.col32 > 1 or t1.col33 > 1 or t1.col34 > 1 or t1.col35 > 1 or t1.col36 > 1 or t1.col37 > 1 or t1.col38 > 1 or t1.col39 > 1 or t1.col40 > 1 or t1.col41 > 1 or t1.col42 > 1 or t1.col43 > 1 or t1.col44 > 1 or t1.col45 > 1 or t1.col46 > 1 or t1.col47 > 1 or t1.col48 > 1 or t1.col49 > 1 or t1.col50 > 1 or t1.col51 > 1 or t1.col52 > 1 or t1.col53 > 1 or t1.col54 > 1 or t1.col55 > 1 or t1.col56 > 1 or t1.col57 > 1 or t1.col58 > 1 or t1.col59 > 1 or t1.col60 > 1 or t1.col61 > 1 or t1.col62 > 1 or t1.col63 > 1 or t1.col64 > 1 or t1.col65 > 1 or t1.col66 > 1 or t1.col67 > 1 or t1.col68 > 1 or t1.col69 > 1 or t1.col70 > 1 or t1.col71 > 1 or t1.col72 > 1 or t1.col73 > 1 or t1.col74 > 1 or t1.col75 > 1 or t1.col76 > 1 or t1.col77 > 1 or t1.col78 > 1 or t1.col79 > 1 or t1.col80 > 1 or t1.col81 > 1 or t1.col82 > 1 or t1.col83 > 1 or t1.col84 > 1 or t1.col85 > 1 or t1.col86 > 1 or t1.col87 > 1 or t1.col88 > 1 or t1.col89 > 1 or t1.col90 > 1 or t1.col91 > 1 or t1.col92 > 1 or t1.col93 > 1 or t1.col94 > 1 or t1.col95 > 1 or t1.col96 > 1 or t1.col97 > 1 or t1.col98 > 1 or t1.col99 > 1 or t1.col100 > 1 or t1.col101 > 1 or t1.col102 > 1 or t1.col103 > 1 or t1.col104 > 1 or t1.col105 > 1 or t1.col106 > 1 or t1.col107 > 1 or t1.col108 > 1 or t1.col109 > 1 or t1.col110 > 1 or t1.col111 > 1 or t1.col112 > 1 or t1.col113 > 1 or t1.col114 > 1 or t1.col115 > 1 or t1.col116 > 1 or t1.col117 > 1 or t1.col118 > 1 or t1.col119 > 1 or t1.col120 > 1 or t1.col121 > 1 or t1.col122 > 1 or t1.col123 > 1 or t1.col124 > 1 or t1.col125 > 1 or t1.col126 > 1 or t1.col127 > 1 or t1.col128 > 1 or t1.col129 > 1 or t1.col130 > 1 or t1.col131 > 1 or t1.col132 > 1 or t1.col133 > 1 or t1.col134 > 1 or t1.col135 > 1 or t1.col136 > 1 or t1.col137 > 1 or t1.col138 > 1 or t1.col139 > 1 or t1.col140 > 1 or t1.col141 > 1 or t1.col142 > 1 or t1.col143 > 1 or t1.col144 > 1 or t1.col145 > 1 or t1.col146 > 1 or t1.col147 > 1 or t1.col148 > 1 or t1.col149 > 1 or t1.col150 > 1 or t1.col151 > 1 or t1.col152 > 1 or t1.col153 > 1 or t1.col154 > 1 or t1.col155 > 1 or t1.col156 > 1 or t1.col157 > 1 or t1.col158 > 1) and t1.col159 > 1" + } + } + ] + } +} +select +json_detailed(json_extract(trace,'$**.selectivity_for_columns')) as JS +from +information_schema.optimizer_trace; +JS +[ + [ + { + "column_name": "col159", + "ranges": + ["1 < col159"], + "selectivity_from_histogram": 0.996078431 + } + ] +] +set optimizer_trace=@trace_tmp; +drop table t1; +# # Clean up # +set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +set use_stat_tables= @save_use_stat_tables; set @@global.histogram_size=@save_histogram_size; diff --git a/mysql-test/main/selectivity_notembedded.test b/mysql-test/main/selectivity_notembedded.test index 6752bd3c7e1..30e0b7f0d2f 100644 --- a/mysql-test/main/selectivity_notembedded.test +++ b/mysql-test/main/selectivity_notembedded.test @@ -105,17 +105,113 @@ from information_schema.optimizer_trace; set optimizer_trace=@tmp; drop table t0,t1,t10; -set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set histogram_size=@save_histogram_size; -set use_stat_tables= @save_use_stat_tables; - --echo # --echo # End of 10.4 tests --echo # +--echo # +--echo # MDEV-33314: Crash inside calculate_cond_selectivity_for_table() with many columns +--echo # +set optimizer_use_condition_selectivity= 4; +set use_stat_tables= preferably; + +let $N_CONDS=160; +let $N_LAST_COND=159; +--echo # +--echo # create table t1 (col0 int, col1 int, col2 int, ...); +--echo # +let $create_tbl= create table t1 ( col0 int; +let $i=1; + +while ($i < $N_CONDS) { + let $create_tbl= $create_tbl, col$i int; + let $i=`select $i + 1`; +} + +let $create_tbl= $create_tbl ); +#echo $create_tbl; +evalp $create_tbl; + + +--echo # +--echo # insert into t1 select seq, ... seq from seq_1_to_10; +--echo # +let $insert_cmd= insert into t1 select seq; +let $i=1; + +while ($i < $N_CONDS) { + let $insert_cmd = $insert_cmd ,seq; + let $i=`select $i + 1`; +} +let $insert_cmd= $insert_cmd from seq_1_to_100; + +# echo $insert_cmd; +evalp $insert_cmd; + +analyze table t1 persistent for all; +set @trace_tmp=@@optimizer_trace; +set optimizer_trace=1; + +--echo # +--echo # Basic testcase: don't crash for many-column selectivity +--echo # explain extended select * from t1 where col0>1 and col1>1 and col2>1 and ... +--echo # +let $query_tbl= explain format=json select * from t1 where col0>1; + +let $i=1; +while ($i < $N_CONDS) { + let $query_tbl= $query_tbl and col$i>1; + let $i=`select $i + 1`; +} + +#echo $query_tbl; +evalp $query_tbl; + +select + json_detailed(json_extract(trace,'$**.selectivity_for_columns[0]')) as JS +from + information_schema.optimizer_trace; + +evalp $query_tbl; +eval select + json_detailed(json_extract(trace,'\$**.selectivity_for_columns[$N_LAST_COND]')) as JS +from + information_schema.optimizer_trace; + + +--echo # +--echo # Check if not being able to infer anything for the first MAX_KEY +--echo # columns doesn't prevent further inferences. +--echo # +--echo # explain extended select * from t1 +--echo # where (1>2 or col0>1 or col1>1 or ...) and col99>1 +--echo # +let $query_tbl= explain format=json select * from t1 where (1>2 ; + +let $i=1; +while ($i < $N_LAST_COND) { + let $query_tbl= $query_tbl or col$i>1; + let $i=`select $i + 1`; +} +let $query_tbl= $query_tbl) and col$N_LAST_COND>1; + +#echo $query_tbl; +evalp $query_tbl; + +select + json_detailed(json_extract(trace,'$**.selectivity_for_columns')) as JS +from + information_schema.optimizer_trace; + +set optimizer_trace=@trace_tmp; +drop table t1; + --echo # --echo # Clean up --echo # --source include/restore_charset.inc +set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +set use_stat_tables= @save_use_stat_tables; set @@global.histogram_size=@save_histogram_size; diff --git a/mysql-test/mariadb-test-run.pl b/mysql-test/mariadb-test-run.pl index 8effcfeb84e..ee8acffb868 100755 --- a/mysql-test/mariadb-test-run.pl +++ b/mysql-test/mariadb-test-run.pl @@ -3101,7 +3101,7 @@ sub mysql_install_db { mtr_add_arg($args, "--core-file"); mtr_add_arg($args, "--console"); mtr_add_arg($args, "--character-set-server=latin1"); - mtr_add_arg($args, "--disable-performance-schema"); + mtr_add_arg($args, "--loose-disable-performance-schema"); if ( $opt_debug ) { diff --git a/mysql-test/std_data/autoinc_import_101.frm b/mysql-test/std_data/autoinc_import_101.frm new file mode 100644 index 00000000000..b16ae91b110 Binary files /dev/null and b/mysql-test/std_data/autoinc_import_101.frm differ diff --git a/mysql-test/std_data/autoinc_import_57.frm b/mysql-test/std_data/autoinc_import_57.frm new file mode 100644 index 00000000000..a333931b97b Binary files /dev/null and b/mysql-test/std_data/autoinc_import_57.frm differ diff --git a/mysql-test/suite/encryption/r/innodb-redo-nokeys.result b/mysql-test/suite/encryption/r/innodb-redo-nokeys.result index b7d6eb50e70..78c2a200731 100644 --- a/mysql-test/suite/encryption/r/innodb-redo-nokeys.result +++ b/mysql-test/suite/encryption/r/innodb-redo-nokeys.result @@ -23,6 +23,15 @@ insert into t2 select * from t1; insert into t3 select * from t1; insert into t4 select * from t1; commit; + +# Flush all dirty pages from buffer pool +SET @no_checkpoint_save_pct= @@GLOBAL.innodb_max_dirty_pages_pct; +SET @no_checkpoint_save_pct_lwm= @@GLOBAL.innodb_max_dirty_pages_pct_lwm; +SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; +SET GLOBAL innodb_max_dirty_pages_pct=0.0; +SET GLOBAL innodb_max_dirty_pages_pct= @no_checkpoint_save_pct; +SET GLOBAL innodb_max_dirty_pages_pct_lwm= @no_checkpoint_save_pct_lwm; + CREATE TABLE t5 (a VARCHAR(8)) ENGINE=InnoDB ENCRYPTED=YES; SET GLOBAL innodb_flush_log_at_trx_commit=1; begin; @@ -42,6 +51,6 @@ SELECT * FROM INFORMATION_SCHEMA.ENGINES WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS -FOUND 1 /\[ERROR\] InnoDB: Encryption key is not found for .*test.t1.ibd/ in mysqld.1.err +FOUND 1 /\[ERROR\] InnoDB: Encryption key is not found for .*test.t[1-5].ibd/ in mysqld.1.err # restart: --file-key-management-filename=MYSQL_TEST_DIR/std_data/keys2.txt drop table t1,t2,t3,t4,t5; diff --git a/mysql-test/suite/encryption/t/innodb-redo-nokeys.test b/mysql-test/suite/encryption/t/innodb-redo-nokeys.test index 52c12761f69..9cf515f5675 100644 --- a/mysql-test/suite/encryption/t/innodb-redo-nokeys.test +++ b/mysql-test/suite/encryption/t/innodb-redo-nokeys.test @@ -44,7 +44,9 @@ insert into t3 select * from t1; insert into t4 select * from t1; commit; +let $no_checkpoint_flush= 1; --source ../../suite/innodb/include/no_checkpoint_start.inc + # # We test redo log page read at recv_read_page using # keys that are not in std_data/keys.txt. If checkpoint @@ -77,7 +79,7 @@ WHERE engine = 'innodb' AND support IN ('YES', 'DEFAULT', 'ENABLED'); let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err; -let SEARCH_PATTERN = \[ERROR\] InnoDB: Encryption key is not found for .*test.t1.ibd; +let SEARCH_PATTERN = \[ERROR\] InnoDB: Encryption key is not found for .*test.t[1-5].ibd; --source include/search_pattern_in_file.inc # diff --git a/mysql-test/suite/federated/federatedx_create_handlers.result b/mysql-test/suite/federated/federatedx_create_handlers.result index 1a2f8c5d3a8..7288c520cbc 100644 --- a/mysql-test/suite/federated/federatedx_create_handlers.result +++ b/mysql-test/suite/federated/federatedx_create_handlers.result @@ -521,6 +521,23 @@ use federated; SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 WHERE id=2) dt2) dt; id name +PREPARE stmt FROM " +SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 + WHERE id=3) dt2) dt; +"; +EXECUTE stmt; +id name +3 xxx +EXECUTE stmt; +id name +3 xxx +DEALLOCATE PREPARE stmt; +EXPLAIN +SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 +WHERE id=3) dt2) dt; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 5 Using where +4 PUSHED DERIVED NULL NULL NULL NULL NULL NULL NULL NULL connection slave; CREATE TABLE federated.t10 (a INT,b INT); CREATE TABLE federated.t11 (a INT, b INT); @@ -541,6 +558,54 @@ WHERE id=2) dt2) dt a b a b id name 1 1 NULL NULL NULL NULL 2 2 NULL NULL NULL NULL +# +# MDEV-31361: Second execution of PS for query with derived table +# +connection slave; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( +id int(20) NOT NULL, +name varchar(16) NOT NULL default '' +) +DEFAULT CHARSET=latin1; +INSERT INTO federated.t1 VALUES +(3,'xxx'), (7,'yyy'), (4,'xxx'), (1,'zzz'), (5,'yyy'); +connection master; +DROP TABLE IF EXISTS federated.t1; +CREATE TABLE federated.t1 ( +id int(20) NOT NULL, +name varchar(16) NOT NULL default '' +) +ENGINE="FEDERATED" DEFAULT CHARSET=latin1 +CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t1'; +use federated; +SELECT * FROM +(SELECT * FROM +(SELECT * FROM +(SELECT * FROM t1 where id>3) dt3 +WHERE id>3) dt2 +) dt; +id name +7 yyy +4 xxx +5 yyy +PREPARE stmt FROM "SELECT * FROM +(SELECT * FROM +(SELECT * FROM +(SELECT * FROM t1 where id>3) dt3 +WHERE id>3) dt2 +) dt"; +EXECUTE stmt; +id name +7 yyy +4 xxx +5 yyy +EXECUTE stmt; +id name +7 yyy +4 xxx +5 yyy +DEALLOCATE PREPARE stmt; set global federated_pushdown=0; connection master; DROP TABLE IF EXISTS federated.t1; diff --git a/mysql-test/suite/federated/federatedx_create_handlers.test b/mysql-test/suite/federated/federatedx_create_handlers.test index 61dc32a2e44..c5ac36de644 100644 --- a/mysql-test/suite/federated/federatedx_create_handlers.test +++ b/mysql-test/suite/federated/federatedx_create_handlers.test @@ -94,12 +94,9 @@ DEFAULT CHARSET=latin1; INSERT INTO federated.t3 VALUES ('yyy'), ('www'), ('yyy'), ('xxx'), ('www'), ('yyy'), ('www'); -#Enable after fix MDEV-31361 ---disable_ps2_protocol SELECT * FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t WHERE federated.t3.name=t.name; ---enable_ps2_protocol EXPLAIN SELECT * @@ -354,6 +351,18 @@ use federated; SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 WHERE id=2) dt2) dt; +PREPARE stmt FROM " +SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 + WHERE id=3) dt2) dt; +"; +EXECUTE stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +EXPLAIN +SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 + WHERE id=3) dt2) dt; + connection slave; CREATE TABLE federated.t10 (a INT,b INT); CREATE TABLE federated.t11 (a INT, b INT); @@ -379,6 +388,52 @@ SELECT * FROM t10 LEFT JOIN WHERE id=2) dt2) dt ) ON t10.a=t11.a; +--echo # +--echo # MDEV-31361: Second execution of PS for query with derived table +--echo # + +connection slave; +DROP TABLE IF EXISTS federated.t1; + +CREATE TABLE federated.t1 ( + id int(20) NOT NULL, + name varchar(16) NOT NULL default '' +) +DEFAULT CHARSET=latin1; + +INSERT INTO federated.t1 VALUES + (3,'xxx'), (7,'yyy'), (4,'xxx'), (1,'zzz'), (5,'yyy'); + +connection master; +DROP TABLE IF EXISTS federated.t1; + +--replace_result $SLAVE_MYPORT SLAVE_PORT +eval +CREATE TABLE federated.t1 ( + id int(20) NOT NULL, + name varchar(16) NOT NULL default '' +) +ENGINE="FEDERATED" DEFAULT CHARSET=latin1 +CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1'; + +use federated; + +let $q= +SELECT * FROM + (SELECT * FROM + (SELECT * FROM + (SELECT * FROM t1 where id>3) dt3 + WHERE id>3) dt2 + ) dt; + +eval $q; + +eval PREPARE stmt FROM "$q"; +EXECUTE stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + + set global federated_pushdown=0; source include/federated_cleanup.inc; diff --git a/mysql-test/suite/galera/r/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.result b/mysql-test/suite/galera/r/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.result new file mode 100644 index 00000000000..76c13fa7b89 --- /dev/null +++ b/mysql-test/suite/galera/r/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.result @@ -0,0 +1,211 @@ +connection node_2; +connection node_1; +# +# MDEV-33355 Add a Galera-2-node-to-MariaDB replication MTR test cloning the slave with mariadb-backup +# +connect master, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connect slave, 127.0.0.1, root, , test, $NODE_MYPORT_3; +START SLAVE; +include/wait_for_slave_to_start.inc +connection master; +connection slave; +############################################################## +### Initial block with some transactions +### Slave: Make sure replication is not using GTID +connection slave; +# Using_Gtid=No +### Master: Create and populate t1 +connection master; +CREATE TABLE t1(a TEXT) ENGINE=InnoDB; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#00:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#02 - slave run#0, before backup'); +COMMIT; +connection slave; +############################################################## +### Run the last transaction before mariadb-backup --backup +### Remember SHOW MASTER STATUS and @@gtid_binlog_pos +### before and after the transaction. +### Master: Rember MASTER STATUS and @@gtid_binlog_pos before tr#01 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos before tr#01 +connection slave; +### Master: Run the actual last transaction before the backup +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#01:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#02 - slave run#0, before backup'); +COMMIT; +connection slave; +### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +connection slave; +############################################################## +### Running `mariadb-backup --backup,--prepare` and checking +### that xtrabackup_slave_info and xtrabackup_binlog_info are OK +### Slave: Create a backup +### Slave: Prepare the backup +### Slave: xtrabackup files: +############################ xtrabackup_slave_info +CHANGE MASTER TO MASTER_LOG_FILE='master_after_tr01_show_master_status_file', MASTER_LOG_POS=master_after_tr01_show_master_status_position; +############################ xtrabackup_binlog_info +slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_position slave_after_tr01_gtid_binlog_pos +############################ +############################################################## +### Run more transactions after the backup: +### - while the slave is still running, then +### - while the slave is shut down +### Master: Run another transaction while the slave is still running +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt#01 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt@02 - slave run#0, after backup'); +COMMIT; +connection slave; +### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +connection slave; +### Master: Checking SHOW BINLOG EVENTS +connection master; +SHOW BINLOG EVENTS IN 'master_after_tr01_show_master_status_file' FROM master_after_tr01_show_master_status_position LIMIT 0,1; +Log_name master_after_tr01_show_master_status_file +Pos master_after_tr01_show_master_status_position +Event_type Gtid +Server_id # +End_log_pos # +Info BEGIN GTID master_after_tr02_gtid_binlog_pos +SHOW BINLOG EVENTS IN 'master_after_tr01_show_master_status_file' FROM master_after_tr01_show_master_status_position LIMIT 1,1; +Log_name master_after_tr01_show_master_status_file +Pos # +Event_type Query_or_Annotate_rows +Server_id # +End_log_pos # +Info INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup') +### Slave: Checking SHOW BINLOG EVENTS +connection slave; +SHOW BINLOG EVENTS IN 'slave_after_tr01_show_master_status_file' FROM slave_after_tr01_show_master_status_position LIMIT 0,1; +Log_name slave_after_tr01_show_master_status_file +Pos # +Event_type Gtid +Server_id 1 +End_log_pos # +Info BEGIN GTID slave_after_tr02_gtid_binlog_pos +SHOW BINLOG EVENTS IN 'slave_after_tr01_show_master_status_file' FROM slave_after_tr01_show_master_status_position LIMIT 1,1; +Log_name slave_after_tr01_show_master_status_file +Pos # +Event_type Query_or_Annotate_rows +Server_id # +End_log_pos # +Info INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup') +### Slave: Stop replication +connection slave; +STOP SLAVE; +include/wait_for_slave_to_stop.inc +RESET SLAVE; +Warnings: +Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos' +### Slave: Shutdown the server +connection slave; +### Master: Run a transaction while the slave is shut down +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#03:stmt#00 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#01 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#02 - after slave run#0, slave is shut down, after backup'); +COMMIT; +############################################################## +### Emulate starting a new virgin slave +### Slave: Remove the data directory +### Slave: Copy back the backup +### Slave: Restart the server +connection slave; +# restart +### Slave: Display the restored data before START SLAVE +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +### Slave: Execute the CHANGE MASTER statement to set up the host and port +CHANGE MASTER '' TO MASTER_USER='root', MASTER_HOST='127.0.0.1', MASTER_PORT=###, MASTER_CONNECT_RETRY=1; +### Slave: Execute the CHANGE MASTER statement from xtrabackup_slave_info +CHANGE MASTER TO MASTER_LOG_FILE='master_after_tr01_show_master_status_file', MASTER_LOG_POS=master_after_tr01_show_master_status_position; +Warnings: +Note 4190 CHANGE MASTER TO is implicitly changing the value of 'Using_Gtid' from 'Slave_Pos' to 'No' +### Slave: Execute START SLAVE +include/start_slave.inc +### Master: Wait for the slave to apply all master events +connection master; +connection slave; +### Slave: Make sure replication is not using GTID after the slave restart +connection slave; +# Using_Gtid=No +### Slave: Display the restored data after START SLAVE +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +tr#02:stmt#00 - slave run#0, after backup +tr#02:stmt#01 - slave run#0, after backup +tr#02:stmt@02 - slave run#0, after backup +tr#03:stmt#00 - after slave run#0, slave is shut down, after backup +tr#03:stmt#01 - after slave run#0, slave is shut down, after backup +tr#03:stmt#02 - after slave run#0, slave is shut down, after backup +############################################################## +### Continue master transactions, check the new slave replicates well. +### Master: Run a transaction after restarting replication +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#04:stmt#00 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#01 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#02 - slave run#1'); +COMMIT; +connection slave; +### Slave: Display the restored data + new transactions +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +tr#02:stmt#00 - slave run#0, after backup +tr#02:stmt#01 - slave run#0, after backup +tr#02:stmt@02 - slave run#0, after backup +tr#03:stmt#00 - after slave run#0, slave is shut down, after backup +tr#03:stmt#01 - after slave run#0, slave is shut down, after backup +tr#03:stmt#02 - after slave run#0, slave is shut down, after backup +tr#04:stmt#00 - slave run#1 +tr#04:stmt#01 - slave run#1 +tr#04:stmt#02 - slave run#1 +############################################################## +### Cleanup +### Removing the backup directory +connection master; +DROP TABLE t1; +connection slave; +STOP SLAVE; +include/wait_for_slave_to_stop.inc +RESET SLAVE ALL; +Warnings: +Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos' +connection master; +set global wsrep_on=OFF; +RESET MASTER; +set global wsrep_on=ON; diff --git a/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.cnf b/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.cnf new file mode 100644 index 00000000000..52fd3093931 --- /dev/null +++ b/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.cnf @@ -0,0 +1 @@ +!include ../galera_2nodes_as_master.cnf diff --git a/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.test b/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.test new file mode 100644 index 00000000000..29590e327fd --- /dev/null +++ b/mysql-test/suite/galera/t/rpl_galera_to_mariadb_clone_slave_using_mariadb-backup.test @@ -0,0 +1,9 @@ +--source include/have_innodb.inc +--source include/galera_cluster.inc + +--echo # +--echo # MDEV-33355 Add a Galera-2-node-to-MariaDB replication MTR test cloning the slave with mariadb-backup +--echo # + +--let cnf=galera2_to_mariadb +--source include/rpl_clone_slave_using_mariadb-backup.inc diff --git a/mysql-test/suite/innodb/include/no_checkpoint_start.inc b/mysql-test/suite/innodb/include/no_checkpoint_start.inc index a903fee67d4..69823dd0a03 100644 --- a/mysql-test/suite/innodb/include/no_checkpoint_start.inc +++ b/mysql-test/suite/innodb/include/no_checkpoint_start.inc @@ -1,5 +1,28 @@ # Preparation for using no_checkpoint_end.inc +# no_checkpoint_flush: Set to trigger flushing the dirty pages from buffer pool +# and checkpoint before the "no checkpoint" block. + +if ($no_checkpoint_flush) { + --echo + --echo # Flush all dirty pages from buffer pool + SET @no_checkpoint_save_pct= @@GLOBAL.innodb_max_dirty_pages_pct; + SET @no_checkpoint_save_pct_lwm= @@GLOBAL.innodb_max_dirty_pages_pct_lwm; + + SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; + SET GLOBAL innodb_max_dirty_pages_pct=0.0; + + let $wait_condition = + SELECT variable_value = 0 + FROM information_schema.global_status + WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY'; + --source include/wait_condition.inc + + SET GLOBAL innodb_max_dirty_pages_pct= @no_checkpoint_save_pct; + SET GLOBAL innodb_max_dirty_pages_pct_lwm= @no_checkpoint_save_pct_lwm; + --echo +} + let MYSQLD_DATADIR= `select @@datadir`; --replace_regex /.*Last checkpoint at[ ]*([0-9]+).*/\1/ let CHECKPOINT_LSN=`SHOW ENGINE INNODB STATUS`; diff --git a/mysql-test/suite/innodb/r/autoinc_import.result b/mysql-test/suite/innodb/r/autoinc_import.result new file mode 100644 index 00000000000..4a8ddd02e3d --- /dev/null +++ b/mysql-test/suite/innodb/r/autoinc_import.result @@ -0,0 +1,232 @@ +CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES(42); +CREATE TABLE t1b LIKE t1; +INSERT INTO t1b VALUES(3); +CREATE TABLE t1z LIKE t1; +CREATE TABLE t1t (id TINYINT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t0t LIKE t1t; +INSERT INTO t1t VALUES(123); +FLUSH TABLES t1,t1b,t1t FOR EXPORT; +UNLOCK TABLES; +CREATE TABLE t5_7 LIKE t1; +CREATE TABLE t5_7b LIKE t1b; +CREATE TABLE t10_1 LIKE t1; +CREATE TABLE t10_1b LIKE t1b; +ALTER TABLE t1 DISCARD TABLESPACE; +ALTER TABLE t1b DISCARD TABLESPACE; +ALTER TABLE t1z DISCARD TABLESPACE; +ALTER TABLE t1t DISCARD TABLESPACE; +ALTER TABLE t0t DISCARD TABLESPACE; +ALTER TABLE t5_7 DISCARD TABLESPACE; +ALTER TABLE t5_7b DISCARD TABLESPACE; +ALTER TABLE t10_1 DISCARD TABLESPACE; +ALTER TABLE t10_1b DISCARD TABLESPACE; +FLUSH TABLES; +ALTER TABLE t0t IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t0t.cfg', will attempt to import without schema verification +INSERT INTO t0t VALUES(NULL); +SELECT * FROM t0t; +id +123 +124 +DROP TABLE t0t; +ALTER TABLE t1 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t1.cfg', will attempt to import without schema verification +ALTER TABLE t1b IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t1b.cfg', will attempt to import without schema verification +ALTER TABLE t1z IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t1z.cfg', will attempt to import without schema verification +ALTER TABLE t1t IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t1t.cfg', will attempt to import without schema verification +ALTER TABLE t5_7 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t5_7.cfg', will attempt to import without schema verification +ALTER TABLE t5_7b IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t5_7b.cfg', will attempt to import without schema verification +ALTER TABLE t10_1 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t10_1.cfg', will attempt to import without schema verification +ALTER TABLE t10_1b IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t10_1b.cfg', will attempt to import without schema verification +FOUND 1 /InnoDB: Resetting PAGE_ROOT_AUTO_INC from 128 to 123 on table `test`\.`t0t`/ in mysqld.1.err +FOUND 1 /InnoDB: Resetting PAGE_ROOT_AUTO_INC from 0 to 42 on table `test`\.`t1z`/ in mysqld.1.err +FOUND 1 /InnoDB: Resetting PAGE_ROOT_AUTO_INC from 128 to 123 on table `test`\.`t1t`/ in mysqld.1.err +FOUND 1 /InnoDB: Resetting PAGE_ROOT_AUTO_INC from 3 to 42 on table `test`\.`t5_7` \(created with version 50744\)/ in mysqld.1.err +FOUND 1 /InnoDB: Resetting PAGE_ROOT_AUTO_INC from 3 to 42 on table `test`\.`t10_1` \(created with version 100149\)/ in mysqld.1.err +FOUND 5 /InnoDB: Resetting PAGE_ROOT_AUTO_INC/ in mysqld.1.err +# restart: --read-only +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7 check status OK +test.t5_7b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7b check status OK +test.t10_1 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1 check status OK +test.t10_1b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1b check status OK +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7 check status OK +test.t5_7b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7b check status OK +test.t10_1 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1 check status OK +test.t10_1b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1b check status OK +# restart: --innodb-read-only --read-only +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7 check status OK +test.t5_7b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7b check status OK +test.t10_1 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1 check status OK +test.t10_1b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1b check status OK +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7 check status OK +test.t5_7b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t5_7b check status OK +test.t10_1 check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1 check status OK +test.t10_1b check note Auto_increment will be checked on each open until CHECK TABLE FOR UPGRADE is executed +test.t10_1b check status OK +# restart: --innodb-read-only +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check status Operation failed +test.t5_7b check status Operation failed +test.t10_1 check status Operation failed +test.t10_1b check status Operation failed +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check status Operation failed +test.t5_7b check status Operation failed +test.t10_1 check status Operation failed +test.t10_1b check status Operation failed +SELECT COUNT(*) FROM t1; +COUNT(*) +1 +SELECT COUNT(*) FROM t1b; +COUNT(*) +1 +SELECT COUNT(*) FROM t1t; +COUNT(*) +1 +SELECT COUNT(*) FROM t1z; +COUNT(*) +1 +SELECT COUNT(*) FROM t5_7; +COUNT(*) +1 +SELECT COUNT(*) FROM t5_7b; +COUNT(*) +1 +SELECT COUNT(*) FROM t10_1; +COUNT(*) +1 +SELECT COUNT(*) FROM t10_1b; +COUNT(*) +1 +# restart +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check note Auto_increment checked and .frm file version updated +test.t5_7 check status OK +test.t5_7b check note Auto_increment checked and .frm file version updated +test.t5_7b check status OK +test.t10_1 check note Auto_increment checked and .frm file version updated +test.t10_1 check status OK +test.t10_1b check note Auto_increment checked and .frm file version updated +test.t10_1b check status OK +INSERT INTO t1 VALUES(NULL); +INSERT INTO t1b VALUES(NULL); +INSERT INTO t1t VALUES(NULL); +INSERT INTO t1z VALUES(NULL); +INSERT INTO t5_7 VALUES(NULL); +INSERT INTO t5_7b VALUES(NULL); +INSERT INTO t10_1 VALUES(NULL); +INSERT INTO t10_1b VALUES(NULL); +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; +Table Op Msg_type Msg_text +test.t1 check status OK +test.t1b check status OK +test.t1t check status OK +test.t1z check status OK +test.t5_7 check status OK +test.t5_7b check status OK +test.t10_1 check status OK +test.t10_1b check status OK +SELECT * FROM t1; +id +4 +42 +SELECT * FROM t1b; +id +3 +347 +SELECT * FROM t1t; +id +123 +124 +SELECT * FROM t1z; +id +42 +43 +SELECT * FROM t5_7; +id +42 +43 +SELECT * FROM t5_7b; +id +3 +347 +SELECT * FROM t10_1; +id +42 +43 +SELECT * FROM t10_1b; +id +3 +347 +DROP TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 808e2270e27..80a0afb8d06 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -1035,9 +1035,22 @@ BEGIN; INSERT INTO child SET a=1; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`)) connection default; +TRUNCATE TABLE parent; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) +DROP TABLE parent; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails +SET innodb_lock_wait_timeout=0; +RENAME TABLE parent TO transparent; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +ALTER TABLE parent FORCE, ALGORITHM=COPY; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +ALTER TABLE parent FORCE, ALGORITHM=INPLACE; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction SET innodb_lock_wait_timeout=0, foreign_key_checks=0; TRUNCATE TABLE parent; ERROR HY000: Lock wait timeout exceeded; try restarting transaction +DROP TABLE parent; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction ALTER TABLE parent FORCE, ALGORITHM=COPY; ERROR HY000: Lock wait timeout exceeded; try restarting transaction ALTER TABLE parent FORCE, ALGORITHM=INPLACE; @@ -1052,7 +1065,13 @@ TRUNCATE TABLE parent; ALTER TABLE parent FORCE, ALGORITHM=COPY; ALTER TABLE parent FORCE, ALGORITHM=INPLACE; ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT; -DROP TABLE child, parent; +SET foreign_key_checks=ON; +TRUNCATE TABLE parent; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) +ALTER TABLE parent FORCE, ALGORITHM=COPY; +ALTER TABLE parent FORCE, ALGORITHM=INPLACE; +RENAME TABLE parent TO transparent; +DROP TABLE child, transparent; # # MDEV-26217 Failing assertion: list.count > 0 in ut_list_remove # or Assertion `lock->trx == this' failed in dberr_t trx_t::drop_table diff --git a/mysql-test/suite/innodb/r/full_crc32_import.result b/mysql-test/suite/innodb/r/full_crc32_import.result index 548e69c1c52..416f607cc33 100644 --- a/mysql-test/suite/innodb/r/full_crc32_import.result +++ b/mysql-test/suite/innodb/r/full_crc32_import.result @@ -50,7 +50,15 @@ t1 CREATE TABLE `t1` ( `b` blob DEFAULT NULL, `c` blob DEFAULT NULL, PRIMARY KEY (`a`) -) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=DYNAMIC +) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=DYNAMIC +# Auto increment value must be more than maximum column value +SELECT MAX(a) FROM t1; +MAX(a) +45 +SELECT auto_increment FROM information_schema.tables +WHERE table_name like 't1'; +auto_increment +46 UPDATE t1 set b = repeat("de", 100) where b = repeat("cd", 200); explain SELECT a FROM t1 where b = repeat("de", 100); id select_type table type possible_keys key key_len ref rows Extra @@ -132,7 +140,15 @@ t1 CREATE TABLE `t1` ( `c2` point NOT NULL, `c3` linestring NOT NULL, PRIMARY KEY (`c1`) -) ENGINE=InnoDB AUTO_INCREMENT=16372 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=DYNAMIC +) ENGINE=InnoDB AUTO_INCREMENT=14325 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=DYNAMIC +# Auto increment value must be more than maximum column value +SELECT MAX(c1) FROM t1; +MAX(c1) +14324 +SELECT auto_increment FROM information_schema.tables +WHERE table_name like 't1'; +auto_increment +14325 UPDATE t1 SET C2 = ST_GeomFromText('POINT(0 0)'); SELECT COUNT(*) FROM t1; COUNT(*) diff --git a/mysql-test/suite/innodb/r/import_bugs.result b/mysql-test/suite/innodb/r/import_bugs.result index 98f3e76763b..6bcd31eab7e 100644 --- a/mysql-test/suite/innodb/r/import_bugs.result +++ b/mysql-test/suite/innodb/r/import_bugs.result @@ -15,6 +15,41 @@ CREATE TABLE imp_t1 (a INT PRIMARY KEY) ENGINE=InnoDB; DROP TABLE imp_t1, t1; SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; # +# MDEV-18288: Transportable Tablespaces leave AUTO_INCREMENT in mismatched +# state, causing INSERT errors in newly imported tables when .cfg is not used. +# +CREATE TABLE t1( +id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) ENGINE=INNODB; +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 DISCARD TABLESPACE; +INSERT INTO t1() VALUES(); +INSERT INTO t1() VALUES(); +FLUSH TABLES test.t1 FOR EXPORT; +# Copy data file +# Skip CFG file copy +UNLOCK TABLES; +DROP TABLE t1; +ALTER TABLE t2 IMPORT TABLESPACE; +Warnings: +Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification +SELECT * FROM t2 ORDER BY id; +id +1 +2 +INSERT INTO t2() VALUES(); +INSERT INTO t2() VALUES(); +INSERT INTO t2() VALUES(); +SELECT * FROM t2 ORDER BY id; +id +1 +2 +3 +4 +5 +DROP TABLE t2; +# # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)' # failed in dberr_t row_discard_tablespace_for_mysql # (dict_table_t*, trx_t*) diff --git a/mysql-test/suite/innodb/r/innodb_ut_format_name.result b/mysql-test/suite/innodb/r/innodb_ut_format_name.result deleted file mode 100644 index 41a5b0f7149..00000000000 --- a/mysql-test/suite/innodb/r/innodb_ut_format_name.result +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE t (c INT) ENGINE=INNODB; -SET @save_dbug = @@debug_dbug; -SET debug_dbug = '+d,test_ut_format_name'; -DROP TABLE t; -SET debug_dbug = @save_dbug; diff --git a/mysql-test/suite/innodb/r/undo_space_dblwr.result b/mysql-test/suite/innodb/r/undo_space_dblwr.result index d6822b20eb7..4466df9857b 100644 --- a/mysql-test/suite/innodb/r/undo_space_dblwr.result +++ b/mysql-test/suite/innodb/r/undo_space_dblwr.result @@ -4,15 +4,14 @@ Variable_name Value innodb_doublewrite ON create table t1(f1 int not null, f2 int not null)engine=innodb; insert into t1 values (1, 1); -InnoDB 0 transactions not purged -set GLOBAL innodb_log_checkpoint_now=1; +SET GLOBAL innodb_fast_shutdown = 0; +# restart: --debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0 # Make the first page dirty for undo tablespace set global innodb_saved_page_number_debug = 0; set global innodb_fil_make_page_dirty_debug = 1; -SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; -SET GLOBAL innodb_max_dirty_pages_pct=0.0; +SET GLOBAL innodb_buf_flush_list_now = 1; # Kill the server -# restart +# restart: --debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0 FOUND 1 /Checksum mismatch in the first page of file/ in mysqld.1.err check table t1; Table Op Msg_type Msg_text diff --git a/mysql-test/suite/innodb/t/autoinc_import.test b/mysql-test/suite/innodb/t/autoinc_import.test new file mode 100644 index 00000000000..e137413dfb5 --- /dev/null +++ b/mysql-test/suite/innodb/t/autoinc_import.test @@ -0,0 +1,168 @@ +--source include/have_innodb.inc + +CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES(42); +CREATE TABLE t1b LIKE t1; +INSERT INTO t1b VALUES(3); +CREATE TABLE t1z LIKE t1; +CREATE TABLE t1t (id TINYINT AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t0t LIKE t1t; +INSERT INTO t1t VALUES(123); +--let DATADIR=`select @@datadir` +--let PAGE_SIZE=`select @@innodb_page_size` +FLUSH TABLES t1,t1b,t1t FOR EXPORT; +--copy_file $DATADIR/test/t1.ibd $DATADIR/test/t.ibd +--copy_file $DATADIR/test/t1.ibd $DATADIR/test/tz.ibd +--copy_file $DATADIR/test/t1b.ibd $DATADIR/test/tb.ibd +--copy_file $DATADIR/test/t1t.ibd $DATADIR/test/tt.ibd +UNLOCK TABLES; +CREATE TABLE t5_7 LIKE t1; +CREATE TABLE t5_7b LIKE t1b; +CREATE TABLE t10_1 LIKE t1; +CREATE TABLE t10_1b LIKE t1b; +ALTER TABLE t1 DISCARD TABLESPACE; +ALTER TABLE t1b DISCARD TABLESPACE; +ALTER TABLE t1z DISCARD TABLESPACE; +ALTER TABLE t1t DISCARD TABLESPACE; +ALTER TABLE t0t DISCARD TABLESPACE; +ALTER TABLE t5_7 DISCARD TABLESPACE; +ALTER TABLE t5_7b DISCARD TABLESPACE; +ALTER TABLE t10_1 DISCARD TABLESPACE; +ALTER TABLE t10_1b DISCARD TABLESPACE; +FLUSH TABLES; + +# Update the PAGE_ROOT_AUTO_INC field of a few files. +perl; +do "$ENV{MTR_SUITE_DIR}/include/crc32.pl"; +sub update_autoinc +{ + my ($file, $value) = @_; + open(FILE, "+<$file") || die "Unable to open $file"; + binmode FILE; + my $ps= $ENV{PAGE_SIZE}; + my $page; + die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps; + my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS + sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n"; + die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps; + substr($page,56,8)=pack("NN",0,$value); + my $polynomial = 0x82f63b78; # CRC-32C + if ($full_crc32) { + my $ck = mycrc32(substr($page, 0, $ps-4), 0, $polynomial); + substr($page, $ps-4, 4) = pack("N", $ck); + } + else + { + my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^ + mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial)); + substr($page,0,4)=$ck; + substr($page,$ps-8,4)=$ck; + } + sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n"; + syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n"; + close(FILE) || die "Unable to close $file"; +} +update_autoinc("$ENV{DATADIR}/test/tz.ibd", 0); +update_autoinc("$ENV{DATADIR}/test/t.ibd", 3); +update_autoinc("$ENV{DATADIR}/test/tb.ibd", 346); +update_autoinc("$ENV{DATADIR}/test/tt.ibd", 128); +EOF + +--remove_file $DATADIR/test/t5_7.frm +--remove_file $DATADIR/test/t5_7b.frm +--copy_file $MYSQL_TEST_DIR/std_data/autoinc_import_57.frm $DATADIR/test/t5_7.frm +--copy_file $MYSQL_TEST_DIR/std_data/autoinc_import_57.frm $DATADIR/test/t5_7b.frm +--remove_file $DATADIR/test/t10_1.frm +--remove_file $DATADIR/test/t10_1b.frm +--copy_file $MYSQL_TEST_DIR/std_data/autoinc_import_101.frm $DATADIR/test/t10_1.frm +--copy_file $MYSQL_TEST_DIR/std_data/autoinc_import_101.frm $DATADIR/test/t10_1b.frm +--copy_file $DATADIR/test/t.ibd $DATADIR/test/t5_7.ibd +--copy_file $DATADIR/test/tb.ibd $DATADIR/test/t5_7b.ibd +--copy_file $DATADIR/test/t.ibd $DATADIR/test/t10_1.ibd +--copy_file $DATADIR/test/tb.ibd $DATADIR/test/t10_1b.ibd +--move_file $DATADIR/test/t.ibd $DATADIR/test/t1.ibd +--move_file $DATADIR/test/tb.ibd $DATADIR/test/t1b.ibd +--copy_file $DATADIR/test/tt.ibd $DATADIR/test/t0t.ibd +--move_file $DATADIR/test/tt.ibd $DATADIR/test/t1t.ibd +--move_file $DATADIR/test/tz.ibd $DATADIR/test/t1z.ibd + +ALTER TABLE t0t IMPORT TABLESPACE; +INSERT INTO t0t VALUES(NULL); +SELECT * FROM t0t; +DROP TABLE t0t; +ALTER TABLE t1 IMPORT TABLESPACE; +ALTER TABLE t1b IMPORT TABLESPACE; +ALTER TABLE t1z IMPORT TABLESPACE; +ALTER TABLE t1t IMPORT TABLESPACE; +ALTER TABLE t5_7 IMPORT TABLESPACE; +ALTER TABLE t5_7b IMPORT TABLESPACE; +ALTER TABLE t10_1 IMPORT TABLESPACE; +ALTER TABLE t10_1b IMPORT TABLESPACE; + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC from 128 to 123 on table `test`\.`t0t` +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC from 0 to 42 on table `test`\.`t1z` +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC from 128 to 123 on table `test`\.`t1t` +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC from 3 to 42 on table `test`\.`t5_7` \(created with version 50744\) +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC from 3 to 42 on table `test`\.`t10_1` \(created with version 100149\) +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= InnoDB: Resetting PAGE_ROOT_AUTO_INC +--source include/search_pattern_in_file.inc + +# Restart, so that the InnoDB tables will be loaded into the data dictionary. +--let $restart_parameters=--read-only +--source include/restart_mysqld.inc + +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; + +--let $restart_parameters=--innodb-read-only --read-only +--source include/restart_mysqld.inc + +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; + +--let $restart_parameters=--innodb-read-only +--source include/restart_mysqld.inc + +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; + +SELECT COUNT(*) FROM t1; +SELECT COUNT(*) FROM t1b; +SELECT COUNT(*) FROM t1t; +SELECT COUNT(*) FROM t1z; +SELECT COUNT(*) FROM t5_7; +SELECT COUNT(*) FROM t5_7b; +SELECT COUNT(*) FROM t10_1; +SELECT COUNT(*) FROM t10_1b; + +--let $restart_parameters= +--source include/restart_mysqld.inc + +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; + +INSERT INTO t1 VALUES(NULL); +INSERT INTO t1b VALUES(NULL); +INSERT INTO t1t VALUES(NULL); +INSERT INTO t1z VALUES(NULL); +INSERT INTO t5_7 VALUES(NULL); +INSERT INTO t5_7b VALUES(NULL); +INSERT INTO t10_1 VALUES(NULL); +INSERT INTO t10_1b VALUES(NULL); + +CHECK TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b FOR UPGRADE; + +SELECT * FROM t1; +SELECT * FROM t1b; +SELECT * FROM t1t; +SELECT * FROM t1z; +SELECT * FROM t5_7; +SELECT * FROM t5_7b; +SELECT * FROM t10_1; +SELECT * FROM t10_1b; +DROP TABLE t1, t1b, t1t, t1z, t5_7, t5_7b, t10_1, t10_1b; diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index 0db3a7ca377..e793e261abd 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -1077,10 +1077,23 @@ BEGIN; --error ER_NO_REFERENCED_ROW_2 INSERT INTO child SET a=1; connection default; +--error ER_TRUNCATE_ILLEGAL_FK +TRUNCATE TABLE parent; +--error ER_ROW_IS_REFERENCED_2 +DROP TABLE parent; +SET innodb_lock_wait_timeout=0; +--error ER_LOCK_WAIT_TIMEOUT +RENAME TABLE parent TO transparent; +--error ER_LOCK_WAIT_TIMEOUT +ALTER TABLE parent FORCE, ALGORITHM=COPY; +--error ER_LOCK_WAIT_TIMEOUT +ALTER TABLE parent FORCE, ALGORITHM=INPLACE; SET innodb_lock_wait_timeout=0, foreign_key_checks=0; --error ER_LOCK_WAIT_TIMEOUT TRUNCATE TABLE parent; --error ER_LOCK_WAIT_TIMEOUT +DROP TABLE parent; +--error ER_LOCK_WAIT_TIMEOUT ALTER TABLE parent FORCE, ALGORITHM=COPY; --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE parent FORCE, ALGORITHM=INPLACE; @@ -1095,7 +1108,13 @@ TRUNCATE TABLE parent; ALTER TABLE parent FORCE, ALGORITHM=COPY; ALTER TABLE parent FORCE, ALGORITHM=INPLACE; ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT; -DROP TABLE child, parent; +SET foreign_key_checks=ON; +--error ER_TRUNCATE_ILLEGAL_FK +TRUNCATE TABLE parent; +ALTER TABLE parent FORCE, ALGORITHM=COPY; +ALTER TABLE parent FORCE, ALGORITHM=INPLACE; +RENAME TABLE parent TO transparent; +DROP TABLE child, transparent; --echo # --echo # MDEV-26217 Failing assertion: list.count > 0 in ut_list_remove diff --git a/mysql-test/suite/innodb/t/full_crc32_import.test b/mysql-test/suite/innodb/t/full_crc32_import.test index 0eb31f8d63f..6f02b2ab7e8 100644 --- a/mysql-test/suite/innodb/t/full_crc32_import.test +++ b/mysql-test/suite/innodb/t/full_crc32_import.test @@ -63,6 +63,12 @@ ALTER TABLE t1 DROP INDEX b; ALTER TABLE t1 IMPORT TABLESPACE; --enable_warnings SHOW CREATE TABLE t1; + +--echo # Auto increment value must be more than maximum column value +SELECT MAX(a) FROM t1; +SELECT auto_increment FROM information_schema.tables +WHERE table_name like 't1'; + UPDATE t1 set b = repeat("de", 100) where b = repeat("cd", 200); --replace_column 9 # explain SELECT a FROM t1 where b = repeat("de", 100); @@ -145,6 +151,12 @@ ALTER TABLE t1 DROP INDEX idx1; ALTER TABLE t1 IMPORT TABLESPACE; --disable_warnings SHOW CREATE TABLE t1; + +--echo # Auto increment value must be more than maximum column value +SELECT MAX(c1) FROM t1; +SELECT auto_increment FROM information_schema.tables +WHERE table_name like 't1'; + UPDATE t1 SET C2 = ST_GeomFromText('POINT(0 0)'); SELECT COUNT(*) FROM t1; DELETE FROM t1; diff --git a/mysql-test/suite/innodb/t/import_bugs.test b/mysql-test/suite/innodb/t/import_bugs.test index 7fcab9f9abc..6b0f68d3fa3 100644 --- a/mysql-test/suite/innodb/t/import_bugs.test +++ b/mysql-test/suite/innodb/t/import_bugs.test @@ -22,6 +22,47 @@ DROP TABLE imp_t1, t1; SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; +--echo # +--echo # MDEV-18288: Transportable Tablespaces leave AUTO_INCREMENT in mismatched +--echo # state, causing INSERT errors in newly imported tables when .cfg is not used. +--echo # + +CREATE TABLE t1( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) ENGINE=INNODB; + +CREATE TABLE t2 LIKE t1; + +ALTER TABLE t2 DISCARD TABLESPACE; + +INSERT INTO t1() VALUES(); +INSERT INTO t1() VALUES(); + +FLUSH TABLES test.t1 FOR EXPORT; + +--echo # Copy data file +--copy_file $datadir/test/t1.ibd $datadir/test/t2.ibd + +--echo # Skip CFG file copy +#--copy_file $datadir/test/t1.cfg $datadir/test/t2.cfg +--remove_file $datadir/test/t1.cfg + +UNLOCK TABLES; +DROP TABLE t1; + +--replace_regex /opening '.*\/test\//opening '.\/test\// +ALTER TABLE t2 IMPORT TABLESPACE; + +SELECT * FROM t2 ORDER BY id; + +INSERT INTO t2() VALUES(); +INSERT INTO t2() VALUES(); +INSERT INTO t2() VALUES(); + +SELECT * FROM t2 ORDER BY id; +DROP TABLE t2; + --echo # --echo # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)' --echo # failed in dberr_t row_discard_tablespace_for_mysql diff --git a/mysql-test/suite/innodb/t/innodb_ut_format_name.test b/mysql-test/suite/innodb/t/innodb_ut_format_name.test deleted file mode 100644 index 6e4023c7088..00000000000 --- a/mysql-test/suite/innodb/t/innodb_ut_format_name.test +++ /dev/null @@ -1,17 +0,0 @@ -# -# Test ut_format_name() -# - --- source include/have_debug.inc --- source include/have_innodb.inc - -CREATE TABLE t (c INT) ENGINE=INNODB; - -# This will invoke test_ut_format_name() in debug builds - -SET @save_dbug = @@debug_dbug; -SET debug_dbug = '+d,test_ut_format_name'; - -DROP TABLE t; - -SET debug_dbug = @save_dbug; diff --git a/mysql-test/suite/innodb/t/undo_space_dblwr.test b/mysql-test/suite/innodb/t/undo_space_dblwr.test index b6fd6738a1c..3f61e91ddf5 100644 --- a/mysql-test/suite/innodb/t/undo_space_dblwr.test +++ b/mysql-test/suite/innodb/t/undo_space_dblwr.test @@ -9,19 +9,19 @@ show variables like 'innodb_doublewrite'; create table t1(f1 int not null, f2 int not null)engine=innodb; insert into t1 values (1, 1); ---source include/wait_all_purged.inc +# Slow shutdown and restart to make sure ibuf merge is finished +SET GLOBAL innodb_fast_shutdown = 0; +let $shutdown_timeout=; +let $restart_parameters="--debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0"; +--source include/restart_mysqld.inc -set GLOBAL innodb_log_checkpoint_now=1; --source ../include/no_checkpoint_start.inc - --echo # Make the first page dirty for undo tablespace set global innodb_saved_page_number_debug = 0; set global innodb_fil_make_page_dirty_debug = 1; -SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; -SET GLOBAL innodb_max_dirty_pages_pct=0.0; +SET GLOBAL innodb_buf_flush_list_now = 1; -sleep 1; --let CLEANUP_IF_CHECKPOINT=drop table t1; --source ../include/no_checkpoint_end.inc diff --git a/mysql-test/suite/mariabackup/partial.result b/mysql-test/suite/mariabackup/partial.result index 981bef4e40c..9ff3a20c01f 100644 --- a/mysql-test/suite/mariabackup/partial.result +++ b/mysql-test/suite/mariabackup/partial.result @@ -14,6 +14,14 @@ ALTER TABLE t1 IMPORT TABLESPACE; SELECT * FROM t1; i 1 +# MDEV-33023 Crash in mariadb-backup --prepare --export after --prepare +t1.cfg +t21.cfg +ALTER TABLE t1 DISCARD TABLESPACE; +ALTER TABLE t1 IMPORT TABLESPACE; +SELECT * FROM t1; +i +1 DROP TABLE t1; DROP TABLE t2; DROP TABLE t21; diff --git a/mysql-test/suite/mariabackup/partial.test b/mysql-test/suite/mariabackup/partial.test index d0d07daf2ea..85808749b62 100644 --- a/mysql-test/suite/mariabackup/partial.test +++ b/mysql-test/suite/mariabackup/partial.test @@ -55,6 +55,25 @@ copy_file $targetdir/test/t1.cfg $MYSQLD_DATADIR/test/t1.cfg; ALTER TABLE t1 IMPORT TABLESPACE; SELECT * FROM t1; + +--echo # MDEV-33023 Crash in mariadb-backup --prepare --export after --prepare +--disable_result_log +exec $XTRABACKUP --defaults-file=$server_cnf --defaults-group-suffix=.1 --prepare --target-dir=$targetdir; +exec $XTRABACKUP --defaults-file=$server_cnf --defaults-group-suffix=.1 --prepare --export --target-dir=$targetdir; +--enable_result_log + +list_files $targetdir/test *.cfg; +# There must not be binary logs created on --prepare step +list_files $targetdir/ mysqld-bin.*; + +let $MYSQLD_DATADIR= `select @@datadir`; +ALTER TABLE t1 DISCARD TABLESPACE; +copy_file $targetdir/test/t1.ibd $MYSQLD_DATADIR/test/t1.ibd; +copy_file $targetdir/test/t1.cfg $MYSQLD_DATADIR/test/t1.cfg; +ALTER TABLE t1 IMPORT TABLESPACE; + +SELECT * FROM t1; + DROP TABLE t1; DROP TABLE t2; DROP TABLE t21; diff --git a/mysql-test/suite/mariabackup/rpl_clone_slave.result b/mysql-test/suite/mariabackup/rpl_clone_slave.result new file mode 100644 index 00000000000..2e6c27016f0 --- /dev/null +++ b/mysql-test/suite/mariabackup/rpl_clone_slave.result @@ -0,0 +1,202 @@ +include/master-slave.inc +[connection master] +# +# MDEV-33342 Add a replication MTR test cloning the slave with mariadb-backup +# +connection slave; +stop slave; +change master to master_use_gtid=no; +start slave; +connection master; +connection slave; +############################################################## +### Initial block with some transactions +### Slave: Make sure replication is not using GTID +connection slave; +# Using_Gtid=No +### Master: Create and populate t1 +connection master; +CREATE TABLE t1(a TEXT) ENGINE=InnoDB; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#00:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#00:stmt#02 - slave run#0, before backup'); +COMMIT; +connection slave; +############################################################## +### Run the last transaction before mariadb-backup --backup +### Remember SHOW MASTER STATUS and @@gtid_binlog_pos +### before and after the transaction. +### Master: Rember MASTER STATUS and @@gtid_binlog_pos before tr#01 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos before tr#01 +connection slave; +### Master: Run the actual last transaction before the backup +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#01:stmt#00 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#01 - slave run#0, before backup'); +INSERT INTO t1 VALUES ('tr#01:stmt#02 - slave run#0, before backup'); +COMMIT; +connection slave; +### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 +connection slave; +############################################################## +### Running `mariadb-backup --backup,--prepare` and checking +### that xtrabackup_slave_info and xtrabackup_binlog_info are OK +### Slave: Create a backup +### Slave: Prepare the backup +### Slave: xtrabackup files: +############################ xtrabackup_slave_info +CHANGE MASTER TO MASTER_LOG_FILE='master_after_tr01_show_master_status_file', MASTER_LOG_POS=master_after_tr01_show_master_status_position; +############################ xtrabackup_binlog_info +slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_position slave_after_tr01_gtid_binlog_pos +############################ +############################################################## +### Run more transactions after the backup: +### - while the slave is still running, then +### - while the slave is shut down +### Master: Run another transaction while the slave is still running +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt#01 - slave run#0, after backup'); +INSERT INTO t1 VALUES ('tr#02:stmt@02 - slave run#0, after backup'); +COMMIT; +connection slave; +### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +connection master; +### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 +connection slave; +### Master: Checking SHOW BINLOG EVENTS +connection master; +SHOW BINLOG EVENTS IN 'master_after_tr01_show_master_status_file' FROM master_after_tr01_show_master_status_position LIMIT 0,1; +Log_name master_after_tr01_show_master_status_file +Pos master_after_tr01_show_master_status_position +Event_type Gtid +Server_id # +End_log_pos # +Info BEGIN GTID master_after_tr02_gtid_binlog_pos +SHOW BINLOG EVENTS IN 'master_after_tr01_show_master_status_file' FROM master_after_tr01_show_master_status_position LIMIT 1,1; +Log_name master_after_tr01_show_master_status_file +Pos # +Event_type Query_or_Annotate_rows +Server_id # +End_log_pos # +Info INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup') +### Slave: Checking SHOW BINLOG EVENTS +connection slave; +SHOW BINLOG EVENTS IN 'slave_after_tr01_show_master_status_file' FROM slave_after_tr01_show_master_status_position LIMIT 0,1; +Log_name slave_after_tr01_show_master_status_file +Pos # +Event_type Gtid +Server_id 1 +End_log_pos # +Info BEGIN GTID slave_after_tr02_gtid_binlog_pos +SHOW BINLOG EVENTS IN 'slave_after_tr01_show_master_status_file' FROM slave_after_tr01_show_master_status_position LIMIT 1,1; +Log_name slave_after_tr01_show_master_status_file +Pos # +Event_type Query_or_Annotate_rows +Server_id # +End_log_pos # +Info INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup') +### Slave: Stop replication +connection slave; +STOP SLAVE; +include/wait_for_slave_to_stop.inc +RESET SLAVE; +Warnings: +Note 4190 RESET SLAVE is implicitly changing the value of 'Using_Gtid' from 'No' to 'Slave_Pos' +### Slave: Shutdown the server +include/rpl_stop_server.inc [server_number=2] +### Master: Run a transaction while the slave is shut down +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#03:stmt#00 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#01 - after slave run#0, slave is shut down, after backup'); +INSERT INTO t1 VALUES ('tr#03:stmt#02 - after slave run#0, slave is shut down, after backup'); +COMMIT; +############################################################## +### Emulate starting a new virgin slave +### Slave: Remove the data directory +### Slave: Copy back the backup +### Slave: Restart the server +include/rpl_start_server.inc [server_number=2] +### Slave: Display the restored data before START SLAVE +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +### Slave: Execute the CHANGE MASTER statement to set up the host and port +CHANGE MASTER '' TO MASTER_USER='root', MASTER_HOST='127.0.0.1', MASTER_PORT=###, MASTER_CONNECT_RETRY=1; +### Slave: Execute the CHANGE MASTER statement from xtrabackup_slave_info +CHANGE MASTER TO MASTER_LOG_FILE='master_after_tr01_show_master_status_file', MASTER_LOG_POS=master_after_tr01_show_master_status_position; +Warnings: +Note 4190 CHANGE MASTER TO is implicitly changing the value of 'Using_Gtid' from 'Slave_Pos' to 'No' +### Slave: Execute START SLAVE +include/start_slave.inc +### Master: Wait for the slave to apply all master events +connection master; +connection slave; +### Slave: Make sure replication is not using GTID after the slave restart +connection slave; +# Using_Gtid=No +### Slave: Display the restored data after START SLAVE +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +tr#02:stmt#00 - slave run#0, after backup +tr#02:stmt#01 - slave run#0, after backup +tr#02:stmt@02 - slave run#0, after backup +tr#03:stmt#00 - after slave run#0, slave is shut down, after backup +tr#03:stmt#01 - after slave run#0, slave is shut down, after backup +tr#03:stmt#02 - after slave run#0, slave is shut down, after backup +############################################################## +### Continue master transactions, check the new slave replicates well. +### Master: Run a transaction after restarting replication +connection master; +START TRANSACTION; +INSERT INTO t1 VALUES ('tr#04:stmt#00 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#01 - slave run#1'); +INSERT INTO t1 VALUES ('tr#04:stmt#02 - slave run#1'); +COMMIT; +connection slave; +### Slave: Display the restored data + new transactions +connection slave; +SELECT * FROM t1 ORDER BY a; +a +tr#00:stmt#00 - slave run#0, before backup +tr#00:stmt#01 - slave run#0, before backup +tr#00:stmt#02 - slave run#0, before backup +tr#01:stmt#00 - slave run#0, before backup +tr#01:stmt#01 - slave run#0, before backup +tr#01:stmt#02 - slave run#0, before backup +tr#02:stmt#00 - slave run#0, after backup +tr#02:stmt#01 - slave run#0, after backup +tr#02:stmt@02 - slave run#0, after backup +tr#03:stmt#00 - after slave run#0, slave is shut down, after backup +tr#03:stmt#01 - after slave run#0, slave is shut down, after backup +tr#03:stmt#02 - after slave run#0, slave is shut down, after backup +tr#04:stmt#00 - slave run#1 +tr#04:stmt#01 - slave run#1 +tr#04:stmt#02 - slave run#1 +############################################################## +### Cleanup +### Removing the backup directory +connection master; +DROP TABLE t1; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/mariabackup/rpl_clone_slave.test b/mysql-test/suite/mariabackup/rpl_clone_slave.test new file mode 100644 index 00000000000..7d93f72327f --- /dev/null +++ b/mysql-test/suite/mariabackup/rpl_clone_slave.test @@ -0,0 +1,17 @@ +# +# Cloning a slave using mariadb-backup +# +--source include/have_innodb.inc +--source include/master-slave.inc + +--echo # +--echo # MDEV-33342 Add a replication MTR test cloning the slave with mariadb-backup +--echo # + +connection slave; +stop slave; +change master to master_use_gtid=no; +start slave; + +--let cnf=mariadb_to_mariadb +--source include/rpl_clone_slave_using_mariadb-backup.inc diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result index 78b1ac18b8d..36a9086f02b 100644 --- a/mysql-test/suite/period/r/overlaps.result +++ b/mysql-test/suite/period/r/overlaps.result @@ -449,3 +449,85 @@ VALUES ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' DROP TABLE t1; +# MDEV-25370 Update for portion changes autoincrement key in period table +create or replace table cars(id int auto_increment, +price int, s date, e date, +period for p(s,e), +primary key(id, p without overlaps)); +insert into cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +select * from cars; +id price s e +1 1000 2018-01-01 2020-01-01 +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +select * from cars; +id price s e +1 1000 2018-01-01 2019-01-01 +1 1000 2019-12-01 2020-01-01 +1 1100 2019-01-01 2019-12-01 +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +select * from cars; +id price s e +1 1000 2018-01-01 2019-01-01 +1 1000 2019-12-01 2019-12-10 +1 1000 2019-12-20 2020-01-01 +1 1100 2019-01-01 2019-12-01 +# AUTO_INCREMENT field is separate from WITHOUT OVERLAPS +create or replace table cars(id int primary key auto_increment, +car_id int, +price int, s date, e date, +period for p(s,e), +unique(car_id, p without overlaps)); +insert cars(car_id, price, s, e) values (1, 1000, '2018-01-01', '2020-01-01'); +select * from cars; +id car_id price s e +1 1 1000 2018-01-01 2020-01-01 +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +select * from cars; +id car_id price s e +1 1 1100 2019-01-01 2019-12-01 +2 1 1000 2018-01-01 2019-01-01 +3 1 1000 2019-12-01 2020-01-01 +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +select * from cars; +id car_id price s e +1 1 1100 2019-01-01 2019-12-01 +2 1 1000 2018-01-01 2019-01-01 +4 1 1000 2019-12-01 2019-12-10 +5 1 1000 2019-12-20 2020-01-01 +# AUTO_INCREMENT field is both standalone and in WITHOUT OVERLAPS +create or replace table cars(id int primary key auto_increment, +price int, s date, e date, +period for p(s,e), +unique(id, p without overlaps)); +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +insert cars(price, s, e) values (1000, '2021-01-01', '2022-01-01'); +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +# autoincrement index is: id int primary key +# id increments each time. +select * from cars; +id price s e +1 1100 2019-01-01 2019-12-01 +2 1000 2021-01-01 2022-01-01 +3 1000 2018-01-01 2019-01-01 +4 1000 2019-12-01 2020-01-01 +truncate cars; +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +select * from cars; +id price s e +2 1000 2018-01-01 2019-12-10 +3 1000 2019-12-20 2020-01-01 +create or replace table cars(id int unique auto_increment, +price int, s date, e date, +period for p(s,e), +primary key (id, p without overlaps)); +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +# autoincrement index is: primary key (id, p without overlaps) +# id is not incremented, hence duplication error +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +ERROR 23000: Duplicate entry '1' for key 'id' +truncate cars; +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +ERROR 23000: Duplicate entry '1' for key 'id' +drop table cars; diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test index 4e71d64d595..b762743be24 100644 --- a/mysql-test/suite/period/t/overlaps.test +++ b/mysql-test/suite/period/t/overlaps.test @@ -458,3 +458,80 @@ VALUES ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc '), ('2000-01-01 00:00:00.000000', '2001-01-01 00:00:00.000000', 'abc'); DROP TABLE t1; + +--echo # MDEV-25370 Update for portion changes autoincrement key in period table +create or replace table cars(id int auto_increment, + price int, s date, e date, + period for p(s,e), + primary key(id, p without overlaps)); + +insert into cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +select * from cars; + +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +--sorted_result +select * from cars; + +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +--sorted_result +select * from cars; + +--echo # AUTO_INCREMENT field is separate from WITHOUT OVERLAPS +create or replace table cars(id int primary key auto_increment, + car_id int, + price int, s date, e date, + period for p(s,e), + unique(car_id, p without overlaps)); + +insert cars(car_id, price, s, e) values (1, 1000, '2018-01-01', '2020-01-01'); +select * from cars; + +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +--sorted_result +select * from cars; + +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +--sorted_result +select * from cars; + + +--echo # AUTO_INCREMENT field is both standalone and in WITHOUT OVERLAPS +create or replace table cars(id int primary key auto_increment, + price int, s date, e date, + period for p(s,e), + unique(id, p without overlaps)); + +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +insert cars(price, s, e) values (1000, '2021-01-01', '2022-01-01'); + +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; +--echo # autoincrement index is: id int primary key +--echo # id increments each time. +--sorted_result +select * from cars; + +truncate cars; +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); + +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; +--sorted_result +select * from cars; + +create or replace table cars(id int unique auto_increment, + price int, s date, e date, + period for p(s,e), + primary key (id, p without overlaps)); + +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); +--echo # autoincrement index is: primary key (id, p without overlaps) +--echo # id is not incremented, hence duplication error +--error ER_DUP_ENTRY +update cars for portion of p from '2019-01-01' to '2019-12-01' set price= 1100; + +truncate cars; +insert cars(price, s, e) values (1000, '2018-01-01', '2020-01-01'); + +--error ER_DUP_ENTRY +delete from cars for portion of p from '2019-12-10' to '2019-12-20'; + +drop table cars; diff --git a/mysql-test/suite/sys_vars/r/innodb_fil_make_page_dirty_debug_basic.result b/mysql-test/suite/sys_vars/r/innodb_fil_make_page_dirty_debug_basic.result index 477eb7fcb61..db0de5e389a 100644 --- a/mysql-test/suite/sys_vars/r/innodb_fil_make_page_dirty_debug_basic.result +++ b/mysql-test/suite/sys_vars/r/innodb_fil_make_page_dirty_debug_basic.result @@ -22,7 +22,4 @@ Warning 1287 '