1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Merge 10.5 into 10.6

This commit is contained in:
Marko Mäkelä
2024-02-07 13:51:03 +02:00
36 changed files with 1667 additions and 109 deletions

1
debian/rules vendored
View File

@@ -92,7 +92,6 @@ endif
-DCOMPILATION_COMMENT="mariadb.org binary distribution" \ -DCOMPILATION_COMMENT="mariadb.org binary distribution" \
-DMYSQL_SERVER_SUFFIX="-$(DEB_VERSION_REVISION)" \ -DMYSQL_SERVER_SUFFIX="-$(DEB_VERSION_REVISION)" \
-DSYSTEM_TYPE="debian-$(DEB_HOST_GNU_SYSTEM)" \ -DSYSTEM_TYPE="debian-$(DEB_HOST_GNU_SYSTEM)" \
-DCMAKE_SYSTEM_PROCESSOR=$(DEB_HOST_ARCH) \
-DBUILD_CONFIG=mysql_release \ -DBUILD_CONFIG=mysql_release \
-DCONC_DEFAULT_CHARSET=utf8mb4 \ -DCONC_DEFAULT_CHARSET=utf8mb4 \
-DPLUGIN_AWS_KEY_MANAGEMENT=NO \ -DPLUGIN_AWS_KEY_MANAGEMENT=NO \

View File

@@ -47,6 +47,12 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits> #include <limits>
#ifdef HAVE_PWD_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <pwd.h>
#endif
#include "common.h" #include "common.h"
#include "xtrabackup.h" #include "xtrabackup.h"
#include "srv0srv.h" #include "srv0srv.h"
@@ -95,11 +101,54 @@ MYSQL *mysql_connection;
extern my_bool opt_ssl_verify_server_cert, opt_use_ssl; 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 * MYSQL *
xb_mysql_connect() xb_mysql_connect()
{ {
MYSQL *connection = mysql_init(NULL); MYSQL *connection = mysql_init(NULL);
char mysql_port_str[std::numeric_limits<int>::digits10 + 3]; char mysql_port_str[std::numeric_limits<int>::digits10 + 3];
const char *user= opt_user ? opt_user : get_os_user();
sprintf(mysql_port_str, "%d", opt_port); sprintf(mysql_port_str, "%d", opt_port);
@@ -129,7 +178,7 @@ xb_mysql_connect()
msg("Connecting to MariaDB server host: %s, user: %s, password: %s, " msg("Connecting to MariaDB server host: %s, user: %s, password: %s, "
"port: %s, socket: %s", opt_host ? opt_host : "localhost", "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_password ? "set" : "not set",
opt_port != 0 ? mysql_port_str : "not set", opt_port != 0 ? mysql_port_str : "not set",
opt_socket ? opt_socket : "not set"); opt_socket ? opt_socket : "not set");
@@ -150,7 +199,7 @@ xb_mysql_connect()
if (!mysql_real_connect(connection, if (!mysql_real_connect(connection,
opt_host ? opt_host : "localhost", opt_host ? opt_host : "localhost",
opt_user, user,
opt_password, opt_password,
"" /*database*/, opt_port, "" /*database*/, opt_port,
opt_socket, 0)) { opt_socket, 0)) {

View File

@@ -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;
--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;
}

View File

@@ -5,6 +5,8 @@
--source include/innodb_prefix_index_cluster_optimization.inc --source include/innodb_prefix_index_cluster_optimization.inc
--source include/no_valgrind_without_big.inc --source include/no_valgrind_without_big.inc
--source include/innodb_stable_estimates.inc
SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB';
set @innodb_stats_persistent_save= @@innodb_stats_persistent; set @innodb_stats_persistent_save= @@innodb_stats_persistent;

View File

@@ -88,15 +88,130 @@ sel
] ]
set optimizer_trace=@tmp; set optimizer_trace=@tmp;
drop table t0,t1,t10; drop table t0,t1,t10;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set histogram_size=@save_histogram_size; set histogram_size=@save_histogram_size;
set use_stat_tables= @save_use_stat_tables;
# #
# End of 10.4 tests # 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,
"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,
"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,
"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 # 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 @@global.histogram_size=@save_histogram_size;
set optimizer_switch=@save_optimizer_switch_for_selectivity_test; set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@@ -83,13 +83,128 @@ sel
] ]
set optimizer_trace=@tmp; set optimizer_trace=@tmp;
drop table t0,t1,t10; drop table t0,t1,t10;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set histogram_size=@save_histogram_size; set histogram_size=@save_histogram_size;
set use_stat_tables= @save_use_stat_tables;
# #
# End of 10.4 tests # 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,
"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,
"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,
"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 # 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 @@global.histogram_size=@save_histogram_size;

View File

@@ -105,17 +105,113 @@ from information_schema.optimizer_trace;
set optimizer_trace=@tmp; set optimizer_trace=@tmp;
drop table t0,t1,t10; drop table t0,t1,t10;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set histogram_size=@save_histogram_size; set histogram_size=@save_histogram_size;
set use_stat_tables= @save_use_stat_tables;
--echo # --echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo # --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 #
--echo # Clean up --echo # Clean up
--echo # --echo #
--source include/restore_charset.inc --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; set @@global.histogram_size=@save_histogram_size;

View File

@@ -3100,7 +3100,7 @@ sub mysql_install_db {
mtr_add_arg($args, "--core-file"); mtr_add_arg($args, "--core-file");
mtr_add_arg($args, "--console"); mtr_add_arg($args, "--console");
mtr_add_arg($args, "--character-set-server=latin1"); 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 ) if ( $opt_debug )
{ {

View File

@@ -497,6 +497,23 @@ use federated;
SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3
WHERE id=2) dt2) dt; WHERE id=2) dt2) dt;
id name 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 <derived4> ALL NULL NULL NULL NULL 5 Using where
4 PUSHED DERIVED NULL NULL NULL NULL NULL NULL NULL NULL
connection slave; connection slave;
CREATE TABLE federated.t10 (a INT,b INT); CREATE TABLE federated.t10 (a INT,b INT);
CREATE TABLE federated.t11 (a INT, b INT); CREATE TABLE federated.t11 (a INT, b INT);
@@ -517,6 +534,54 @@ WHERE id=2) dt2) dt
a b a b id name a b a b id name
1 1 NULL NULL NULL NULL 1 1 NULL NULL NULL NULL
2 2 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; set global federated_pushdown=0;
connection master; connection master;
DROP TABLE IF EXISTS federated.t1; DROP TABLE IF EXISTS federated.t1;

View File

@@ -94,12 +94,9 @@ DEFAULT CHARSET=latin1;
INSERT INTO federated.t3 VALUES INSERT INTO federated.t3 VALUES
('yyy'), ('www'), ('yyy'), ('xxx'), ('www'), ('yyy'), ('www'); ('yyy'), ('www'), ('yyy'), ('xxx'), ('www'), ('yyy'), ('www');
#Enable after fix MDEV-31361
--disable_ps2_protocol
SELECT * SELECT *
FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t
WHERE federated.t3.name=t.name; WHERE federated.t3.name=t.name;
--enable_ps2_protocol
EXPLAIN EXPLAIN
SELECT * SELECT *
@@ -351,6 +348,18 @@ use federated;
SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3 SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM t1 where id=3) dt3
WHERE id=2) dt2) dt; 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; connection slave;
CREATE TABLE federated.t10 (a INT,b INT); CREATE TABLE federated.t10 (a INT,b INT);
CREATE TABLE federated.t11 (a INT, b INT); CREATE TABLE federated.t11 (a INT, b INT);
@@ -376,6 +385,52 @@ SELECT * FROM t10 LEFT JOIN
WHERE id=2) dt2) dt WHERE id=2) dt2) dt
) ON t10.a=t11.a; ) 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; set global federated_pushdown=0;
source include/federated_cleanup.inc; source include/federated_cleanup.inc;

View File

@@ -0,0 +1,205 @@
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;
### 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;
### 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;
connection master;
set global wsrep_on=OFF;
RESET MASTER;
set global wsrep_on=ON;

View File

@@ -0,0 +1 @@
!include ../galera_2nodes_as_master.cnf

View File

@@ -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

View File

@@ -50,7 +50,15 @@ t1 CREATE TABLE `t1` (
`b` blob DEFAULT NULL, `b` blob DEFAULT NULL,
`c` blob DEFAULT NULL, `c` blob DEFAULT NULL,
PRIMARY KEY (`a`) 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); UPDATE t1 set b = repeat("de", 100) where b = repeat("cd", 200);
explain SELECT a FROM t1 where b = repeat("de", 100); explain SELECT a FROM t1 where b = repeat("de", 100);
id select_type table type possible_keys key key_len ref rows Extra 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, `c2` point NOT NULL,
`c3` linestring NOT NULL, `c3` linestring NOT NULL,
PRIMARY KEY (`c1`) 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)'); UPDATE t1 SET C2 = ST_GeomFromText('POINT(0 0)');
SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1;
COUNT(*) COUNT(*)

View File

@@ -15,6 +15,41 @@ CREATE TABLE imp_t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
DROP TABLE imp_t1, t1; DROP TABLE imp_t1, t1;
SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; 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)' # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)'
# failed in dberr_t row_discard_tablespace_for_mysql # failed in dberr_t row_discard_tablespace_for_mysql
# (dict_table_t*, trx_t*) # (dict_table_t*, trx_t*)

View File

@@ -4,15 +4,14 @@ Variable_name Value
innodb_doublewrite ON innodb_doublewrite ON
create table t1(f1 int not null, f2 int not null)engine=innodb; create table t1(f1 int not null, f2 int not null)engine=innodb;
insert into t1 values (1, 1); insert into t1 values (1, 1);
InnoDB 0 transactions not purged SET GLOBAL innodb_fast_shutdown = 0;
set GLOBAL innodb_log_checkpoint_now=1; # restart: --debug_dbug=+d,ib_log_checkpoint_avoid_hard --innodb_flush_sync=0
# Make the first page dirty for undo tablespace # Make the first page dirty for undo tablespace
set global innodb_saved_page_number_debug = 0; set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = 1; set global innodb_fil_make_page_dirty_debug = 1;
SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; SET GLOBAL innodb_buf_flush_list_now = 1;
SET GLOBAL innodb_max_dirty_pages_pct=0.0;
# Kill the server # 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 FOUND 1 /Checksum mismatch in the first page of file/ in mysqld.1.err
check table t1; check table t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text

View File

@@ -63,6 +63,12 @@ ALTER TABLE t1 DROP INDEX b;
ALTER TABLE t1 IMPORT TABLESPACE; ALTER TABLE t1 IMPORT TABLESPACE;
--enable_warnings --enable_warnings
SHOW CREATE TABLE t1; 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); UPDATE t1 set b = repeat("de", 100) where b = repeat("cd", 200);
--replace_column 9 # --replace_column 9 #
explain SELECT a FROM t1 where b = repeat("de", 100); 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; ALTER TABLE t1 IMPORT TABLESPACE;
--disable_warnings --disable_warnings
SHOW CREATE TABLE t1; 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)'); UPDATE t1 SET C2 = ST_GeomFromText('POINT(0 0)');
SELECT COUNT(*) FROM t1; SELECT COUNT(*) FROM t1;
DELETE FROM t1; DELETE FROM t1;

View File

@@ -22,6 +22,47 @@ DROP TABLE imp_t1, t1;
SET GLOBAL innodb_checksum_algorithm=@save_innodb_checksum_algorithm; 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 #
--echo # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)' --echo # MDEV-27006 Assertion `!lock_trx_has_sys_table_locks(trx)'
--echo # failed in dberr_t row_discard_tablespace_for_mysql --echo # failed in dberr_t row_discard_tablespace_for_mysql

View File

@@ -9,19 +9,19 @@ show variables like 'innodb_doublewrite';
create table t1(f1 int not null, f2 int not null)engine=innodb; create table t1(f1 int not null, f2 int not null)engine=innodb;
insert into t1 values (1, 1); 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 --source ../include/no_checkpoint_start.inc
--echo # Make the first page dirty for undo tablespace --echo # Make the first page dirty for undo tablespace
set global innodb_saved_page_number_debug = 0; set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = 1; set global innodb_fil_make_page_dirty_debug = 1;
SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0; SET GLOBAL innodb_buf_flush_list_now = 1;
SET GLOBAL innodb_max_dirty_pages_pct=0.0;
sleep 1;
--let CLEANUP_IF_CHECKPOINT=drop table t1; --let CLEANUP_IF_CHECKPOINT=drop table t1;
--source ../include/no_checkpoint_end.inc --source ../include/no_checkpoint_end.inc

View File

@@ -0,0 +1,194 @@
include/master-slave.inc
[connection master]
#
# MDEV-33342 Add a replication MTR test cloning the slave with mariadb-backup
#
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;
### 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;
### 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

View File

@@ -0,0 +1,12 @@
#
# 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 #
--let cnf=mariadb_to_mariadb
--source include/rpl_clone_slave_using_mariadb-backup.inc

View File

@@ -449,3 +449,85 @@ 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');
ERROR 23000: Duplicate entry 'abc-2001-01-01 00:00:00.000000-2000-01-01 00:00:00.000000' for key 'index_name' 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; 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;

View File

@@ -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 '),
('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; 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;

View File

@@ -22,7 +22,4 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be
set global innodb_saved_page_number_debug = 0; set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = @space_id; set global innodb_fil_make_page_dirty_debug = @space_id;
drop table t1; drop table t1;
# Must always be 0. set global innodb_fil_make_page_dirty_debug = 0;
SELECT @@global.innodb_fil_make_page_dirty_debug;
@@global.innodb_fil_make_page_dirty_debug
0

View File

@@ -23,6 +23,7 @@ set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = @space_id; set global innodb_fil_make_page_dirty_debug = @space_id;
drop table t1; drop table t1;
set global innodb_saved_page_number_debug = 0; set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = 0;
SELECT @@global.innodb_saved_page_number_debug; SELECT @@global.innodb_saved_page_number_debug;
@@global.innodb_saved_page_number_debug @@global.innodb_saved_page_number_debug
0 0

View File

@@ -31,6 +31,4 @@ set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = @space_id; set global innodb_fil_make_page_dirty_debug = @space_id;
drop table t1; drop table t1;
--echo # Must always be 0. set global innodb_fil_make_page_dirty_debug = 0;
SELECT @@global.innodb_fil_make_page_dirty_debug;

View File

@@ -32,6 +32,7 @@ set global innodb_fil_make_page_dirty_debug = @space_id;
drop table t1; drop table t1;
set global innodb_saved_page_number_debug = 0; set global innodb_saved_page_number_debug = 0;
set global innodb_fil_make_page_dirty_debug = 0;
SELECT @@global.innodb_saved_page_number_debug; SELECT @@global.innodb_saved_page_number_debug;

View File

@@ -3133,6 +3133,53 @@ SQL_SELECT::test_quick_select(THD *thd,
****************************************************************************/ ****************************************************************************/
/*
@brief
Create a bitmap of columns for which to perform Range Analysis for EITS
condition selectivity estimates.
@detail
Walk through the bitmap of fields used in the query, and
- pick columns for which EITS data is usable (see is_eits_usable() call)
- do not produce more than MAX_KEY columns. Range Analyzer cannot handle
more than that. If there are more than MAX_KEY eligible columns,
this function should be called multiple times to produce multiple
bitmaps.
@param used_fields Columns used by the query
@param col_no Start from this column
@param out OUT Filled column bitmap
@return
(uint)-1 If there are no more columns for range analysis.
Other Index of the last considered column. Pass this to next call to
this function
*/
uint get_columns_for_pseudo_indexes(const TABLE *table,
const MY_BITMAP *used_fields, int col_no,
MY_BITMAP *out)
{
bitmap_clear_all(out);
int n_bits= 0;
for (; table->field[col_no]; col_no++)
{
if (bitmap_is_set(used_fields, col_no) &&
is_eits_usable(table->field[col_no]))
{
bitmap_set_bit(out, col_no);
if (++n_bits == MAX_KEY)
{
col_no++;
break;
}
}
}
return n_bits? col_no: (uint)-1;
}
/* /*
Build descriptors of pseudo-indexes over columns to perform range analysis Build descriptors of pseudo-indexes over columns to perform range analysis
@@ -3158,22 +3205,11 @@ bool create_key_parts_for_pseudo_indexes(RANGE_OPT_PARAM *param,
{ {
Field **field_ptr; Field **field_ptr;
TABLE *table= param->table; TABLE *table= param->table;
uint parts= 0; uint parts= bitmap_bits_set(used_fields);
for (field_ptr= table->field; *field_ptr; field_ptr++)
{
Field *field= *field_ptr;
if (bitmap_is_set(used_fields, field->field_index) &&
is_eits_usable(field))
parts++;
}
KEY_PART *key_part; KEY_PART *key_part;
uint keys= 0; uint keys= 0;
if (!parts)
return TRUE;
if (!(key_part= (KEY_PART *) alloc_root(param->mem_root, if (!(key_part= (KEY_PART *) alloc_root(param->mem_root,
sizeof(KEY_PART) * parts))) sizeof(KEY_PART) * parts)))
return TRUE; return TRUE;
@@ -3185,9 +3221,6 @@ bool create_key_parts_for_pseudo_indexes(RANGE_OPT_PARAM *param,
Field *field= *field_ptr; Field *field= *field_ptr;
if (bitmap_is_set(used_fields, field->field_index)) if (bitmap_is_set(used_fields, field->field_index))
{ {
if (!is_eits_usable(field))
continue;
uint16 store_length; uint16 store_length;
uint16 max_key_part_length= (uint16) table->file->max_key_part_length(); uint16 max_key_part_length= (uint16) table->file->max_key_part_length();
key_part->key= keys; key_part->key= keys;
@@ -3528,8 +3561,6 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
PARAM param; PARAM param;
MEM_ROOT alloc; MEM_ROOT alloc;
SEL_TREE *tree; SEL_TREE *tree;
double rows;
init_sql_alloc(key_memory_quick_range_select_root, &alloc, init_sql_alloc(key_memory_quick_range_select_root, &alloc,
thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC));
bzero((void*) &param, sizeof(param)); bzero((void*) &param, sizeof(param));
@@ -3539,67 +3570,90 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
param.table= table; param.table= table;
param.remove_false_where_parts= true; param.remove_false_where_parts= true;
if (create_key_parts_for_pseudo_indexes(&param, used_fields))
goto free_alloc;
param.prev_tables= param.read_tables= 0; param.prev_tables= param.read_tables= 0;
param.current_table= table->map; param.current_table= table->map;
param.using_real_indexes= FALSE; param.using_real_indexes= FALSE;
param.real_keynr[0]= 0; MEM_UNDEFINED(&param.real_keynr, sizeof(param.real_keynr));
param.alloced_sel_args= 0; param.alloced_sel_args= 0;
param.max_key_parts= 0; param.max_key_parts= 0;
thd->no_errors=1; thd->no_errors=1;
tree= cond[0]->get_mm_tree(&param, cond);
if (!tree)
goto free_alloc;
table->reginfo.impossible_range= 0; table->reginfo.impossible_range= 0;
if (tree->type == SEL_TREE::IMPOSSIBLE)
{
rows= 0;
table->reginfo.impossible_range= 1;
goto free_alloc;
}
else if (tree->type == SEL_TREE::ALWAYS)
{
rows= table_records;
goto free_alloc;
}
else if (tree->type == SEL_TREE::MAYBE)
{
rows= table_records;
goto free_alloc;
}
for (uint idx= 0; idx < param.keys; idx++) uint used_fields_buff_size= bitmap_buffer_size(table->s->fields);
uint32 *used_fields_buff= (uint32*)thd->alloc(used_fields_buff_size);
MY_BITMAP cols_for_indexes;
(void) my_bitmap_init(&cols_for_indexes, used_fields_buff, table->s->fields, 0);
bitmap_clear_all(&cols_for_indexes);
uint column_no= 0; // Start looping from the first column.
/*
Try getting selectivity estimates for every field that is used in the
query and has EITS statistics. We do this:
for every usable field col
create a pseudo INDEX(col);
Run the range analyzer (get_mm_tree) for these pseudo-indexes;
Look at produced ranges and get their selectivity estimates;
Note that the range analyzer can process at most MAX_KEY indexes. If
the table has >MAX_KEY eligible columns, we will do several range
analyzer runs.
*/
while (1)
{ {
SEL_ARG *key= tree->keys[idx]; column_no= get_columns_for_pseudo_indexes(table, used_fields, column_no,
if (key) &cols_for_indexes);
if (column_no == (uint)-1)
break; /* Couldn't create any pseudo-indexes. This means we're done */
if (create_key_parts_for_pseudo_indexes(&param, &cols_for_indexes))
goto free_alloc;
tree= cond[0]->get_mm_tree(&param, cond);
if (!tree ||
tree->type == SEL_TREE::ALWAYS ||
tree->type == SEL_TREE::MAYBE)
{ {
Json_writer_object selectivity_for_column(thd); /* Couldn't infer anything. But there could be more fields, so continue */
selectivity_for_column.add("column_name", key->field->field_name); continue;
if (key->type == SEL_ARG::IMPOSSIBLE) }
if (tree->type == SEL_TREE::IMPOSSIBLE)
{
table->reginfo.impossible_range= 1;
goto free_alloc;
}
for (uint idx= 0; idx < param.keys; idx++)
{
SEL_ARG *key= tree->keys[idx];
if (key)
{ {
rows= 0; Json_writer_object selectivity_for_column(thd);
table->reginfo.impossible_range= 1; selectivity_for_column.add("column_name", key->field->field_name);
selectivity_for_column.add("selectivity_from_histogram", rows); if (key->type == SEL_ARG::IMPOSSIBLE)
selectivity_for_column.add("cause", "impossible range");
goto free_alloc;
}
else
{
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
rows= records_in_column_ranges(&param, idx, key);
thd->count_cuted_fields= save_count_cuted_fields;
if (rows != DBL_MAX)
{ {
key->field->cond_selectivity= rows/table_records; table->reginfo.impossible_range= 1;
selectivity_for_column.add("selectivity_from_histogram", selectivity_for_column.add("selectivity_from_histogram", 0);
key->field->cond_selectivity); selectivity_for_column.add("cause", "impossible range");
goto free_alloc;
}
else
{
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
double rows= records_in_column_ranges(&param, idx, key);
thd->count_cuted_fields= save_count_cuted_fields;
if (rows != DBL_MAX)
{
key->field->cond_selectivity= rows/table_records;
selectivity_for_column.add("selectivity_from_histogram",
key->field->cond_selectivity);
}
} }
} }
} }

View File

@@ -263,7 +263,10 @@ int update_portion_of_time(THD *thd, TABLE *table,
res= src->save_in_field(table->field[dst_fieldno], true); res= src->save_in_field(table->field[dst_fieldno], true);
if (likely(!res)) if (likely(!res))
{
table->period_prepare_autoinc();
res= table->update_generated_fields(); res= table->update_generated_fields();
}
if(likely(!res)) if(likely(!res))
res= table->file->ha_update_row(table->record[1], table->record[0]); res= table->file->ha_update_row(table->record[1], table->record[0]);

View File

@@ -1233,7 +1233,9 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
/* Execute the query that specifies the derived table by a foreign engine */ /* Execute the query that specifies the derived table by a foreign engine */
res= derived->pushdown_derived->execute(); res= derived->pushdown_derived->execute();
unit->executed= true; unit->executed= true;
if (res)
DBUG_RETURN(res); DBUG_RETURN(res);
goto after_exec;
} }
if (unit->executed && !derived_is_recursive && if (unit->executed && !derived_is_recursive &&
@@ -1294,6 +1296,7 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
derived_result, unit, first_select); derived_result, unit, first_select);
} }
after_exec:
if (!res && !derived_is_recursive) if (!res && !derived_is_recursive)
{ {
if (derived_result->flush()) if (derived_result->flush())

View File

@@ -9133,10 +9133,9 @@ int TABLE::update_default_fields(bool ignore_errors)
int TABLE::update_generated_fields() int TABLE::update_generated_fields()
{ {
int res= 0; int res= 0;
if (found_next_number_field) if (next_number_field)
{ {
next_number_field= found_next_number_field; res= next_number_field->set_default();
res= found_next_number_field->set_default();
if (likely(!res)) if (likely(!res))
res= file->update_auto_increment(); res= file->update_auto_increment();
next_number_field= NULL; next_number_field= NULL;
@@ -9151,6 +9150,18 @@ int TABLE::update_generated_fields()
return res; return res;
} }
void TABLE::period_prepare_autoinc()
{
if (!found_next_number_field)
return;
/* Don't generate a new value if the autoinc index is WITHOUT OVERLAPS */
DBUG_ASSERT(s->next_number_index != (uint)-1);
if (key_info[s->next_number_index].without_overlaps)
return;
next_number_field= found_next_number_field;
}
int TABLE::period_make_insert(Item *src, Field *dst) int TABLE::period_make_insert(Item *src, Field *dst)
{ {
THD *thd= in_use; THD *thd= in_use;
@@ -9160,7 +9171,10 @@ int TABLE::period_make_insert(Item *src, Field *dst)
int res= src->save_in_field(dst, true); int res= src->save_in_field(dst, true);
if (likely(!res)) if (likely(!res))
{
period_prepare_autoinc();
res= update_generated_fields(); res= update_generated_fields();
}
if (likely(!res) && triggers) if (likely(!res) && triggers)
res= triggers->process_triggers(thd, TRG_EVENT_INSERT, res= triggers->process_triggers(thd, TRG_EVENT_INSERT,

View File

@@ -1795,6 +1795,7 @@ public:
ulonglong vers_end_id() const; ulonglong vers_end_id() const;
int update_generated_fields(); int update_generated_fields();
void period_prepare_autoinc();
int period_make_insert(Item *src, Field *dst); int period_make_insert(Item *src, Field *dst);
int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds, int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
ha_rows *rows_inserted); ha_rows *rows_inserted);

View File

@@ -17590,6 +17590,7 @@ innodb_make_page_dirty(THD*, st_mysql_sys_var*, void*, const void* save)
{ {
mtr_t mtr; mtr_t mtr;
uint space_id = *static_cast<const uint*>(save); uint space_id = *static_cast<const uint*>(save);
srv_fil_make_page_dirty_debug= space_id;
mysql_mutex_unlock(&LOCK_global_system_variables); mysql_mutex_unlock(&LOCK_global_system_variables);
fil_space_t* space = fil_space_t::get(space_id); fil_space_t* space = fil_space_t::get(space_id);
@@ -18326,13 +18327,15 @@ buf_flush_list_now_set(THD*, st_mysql_sys_var*, void*, const void* save)
return; return;
const uint s= srv_fil_make_page_dirty_debug; const uint s= srv_fil_make_page_dirty_debug;
mysql_mutex_unlock(&LOCK_global_system_variables); mysql_mutex_unlock(&LOCK_global_system_variables);
if (s) if (s == 0 || srv_is_undo_tablespace(s))
buf_flush_sync();
else
{ {
while (buf_flush_list_space(fil_system.sys_space, nullptr)); fil_space_t *space= fil_system.sys_space;
if (s) { space= fil_space_get(s); }
while (buf_flush_list_space(space, nullptr));
os_aio_wait_until_no_pending_writes(true); os_aio_wait_until_no_pending_writes(true);
} }
else
buf_flush_sync();
mysql_mutex_lock(&LOCK_global_system_variables); mysql_mutex_lock(&LOCK_global_system_variables);
} }

View File

@@ -515,7 +515,9 @@ void log_t::file::write(os_offset_t offset, span<byte> buf)
{ {
srv_stats.os_log_pending_writes.inc(); srv_stats.os_log_pending_writes.inc();
if (const dberr_t err= fd.write(offset, buf)) if (const dberr_t err= fd.write(offset, buf))
ib::fatal() << "write(" << fd.get_path() << ") returned " << err; ib::fatal() << "write(" << fd.get_path() << ") returned " << err
<< ". Operating system error number "
<< IF_WIN(GetLastError(), errno) << ".";
srv_stats.os_log_pending_writes.dec(); srv_stats.os_log_pending_writes.dec();
srv_stats.os_log_written.add(buf.size()); srv_stats.os_log_written.add(buf.size());
srv_stats.log_writes.inc(); srv_stats.log_writes.inc();

View File

@@ -4585,13 +4585,16 @@ row_import_for_mysql(
table->flags2 &= ~DICT_TF2_DISCARDED & ((1U << DICT_TF2_BITS) - 1); table->flags2 &= ~DICT_TF2_DISCARDED & ((1U << DICT_TF2_BITS) - 1);
/* Set autoinc value read from .cfg file, if one was specified. /* Set autoinc value read from .cfg file, if one was specified.
Otherwise, keep the PAGE_ROOT_AUTO_INC as is. */ Otherwise, read the PAGE_ROOT_AUTO_INC and set it to table autoinc. */
if (autoinc) { if (autoinc) {
ib::info() << table->name << " autoinc value set to " ib::info() << table->name << " autoinc value set to "
<< autoinc; << autoinc;
table->autoinc = autoinc--; table->autoinc = autoinc--;
btr_write_autoinc(dict_table_get_first_index(table), autoinc); btr_write_autoinc(dict_table_get_first_index(table), autoinc);
} else if (table->persistent_autoinc) {
autoinc = btr_read_autoinc(dict_table_get_first_index(table));
table->autoinc = ++autoinc;
} }
return row_import_cleanup(prebuilt, err); return row_import_cleanup(prebuilt, err);

View File

@@ -19,8 +19,10 @@ eval create table t0 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",
eval alter table t2 ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t0"'; eval alter table t2 ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t0"';
--error 12719 --error 12719
select * from t0; select * from t0;
--replace_result test.t1 test.t0 test.t2 test.t0
--error 12719 --error 12719
select * from t1; select * from t1;
--replace_result test.t1 test.t0 test.t2 test.t0
--error 12719 --error 12719
select * from t2; select * from t2;
drop table t0, t1, t2; drop table t0, t1, t2;