From 7a1923c3693332584921e5ca938537fdef4bb29c Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 30 Sep 2020 17:22:43 +0200 Subject: [PATCH 01/15] MDEV-23697: bin/env perl -i -> bin perl -i --- scripts/convert-debug-for-diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/convert-debug-for-diff.sh b/scripts/convert-debug-for-diff.sh index 60b328d946b..478d730d15a 100755 --- a/scripts/convert-debug-for-diff.sh +++ b/scripts/convert-debug-for-diff.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env perl -i +#!/usr/bin perl -i # # This script converts all numbers that look like addresses or memory sizes, # in a debug files generated by --debug (like mysqld --debug-dbug), to #. From 904b811636ef62478db2d78fdd8c01080eaac0f9 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 1 Oct 2020 16:10:11 +1000 Subject: [PATCH 02/15] mtr: innodb_stats_dropped_locked cleanup As discovered in later test, this test doesn't remove the innodb_{index,table}_stats entries generated in the test upon completion. --- mysql-test/suite/innodb/r/innodb_stats_drop_locked.result | 2 ++ mysql-test/suite/innodb/t/innodb_stats_drop_locked.test | 2 ++ 2 files changed, 4 insertions(+) diff --git a/mysql-test/suite/innodb/r/innodb_stats_drop_locked.result b/mysql-test/suite/innodb/r/innodb_stats_drop_locked.result index 13cc45e0ef9..c8329156162 100644 --- a/mysql-test/suite/innodb/r/innodb_stats_drop_locked.result +++ b/mysql-test/suite/innodb/r/innodb_stats_drop_locked.result @@ -43,3 +43,5 @@ innodb_stats_drop_locked innodb_stats_drop_locked innodb_stats_drop_locked innodb_stats_drop_locked +DELETE FROM mysql.innodb_index_stats WHERE database_name='test' AND table_name='innodb_stats_drop_locked'; +DELETE FROM mysql.innodb_table_stats WHERE database_name='test' AND table_name='innodb_stats_drop_locked'; diff --git a/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test b/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test index 26367b8e6ae..07c77299451 100644 --- a/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test +++ b/mysql-test/suite/innodb/t/innodb_stats_drop_locked.test @@ -56,6 +56,8 @@ WHERE table_name='innodb_stats_drop_locked'; SELECT table_name FROM mysql.innodb_index_stats WHERE table_name='innodb_stats_drop_locked'; +DELETE FROM mysql.innodb_index_stats WHERE database_name='test' AND table_name='innodb_stats_drop_locked'; +DELETE FROM mysql.innodb_table_stats WHERE database_name='test' AND table_name='innodb_stats_drop_locked'; --disable_query_log call mtr.add_suppression("Unable to delete statistics for table test.innodb_stats_drop_locked: Lock wait timeout. They can be deleted later using DELETE FROM mysql.innodb_index_stats WHERE database_name"); --enable_query_log From 82301aea4f2e1cdbcee5bb40d3235afc6b9bc468 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Fri, 2 Oct 2020 05:19:41 +0200 Subject: [PATCH 03/15] MDEV-23697: bin/env perl -i -> bin/perl -i - reverting 37c88445e30d doesn't mean adding space where shouldn't been - /bin/perl instead of /bin perl --- scripts/convert-debug-for-diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/convert-debug-for-diff.sh b/scripts/convert-debug-for-diff.sh index 478d730d15a..5b3ce05b815 100755 --- a/scripts/convert-debug-for-diff.sh +++ b/scripts/convert-debug-for-diff.sh @@ -1,4 +1,4 @@ -#!/usr/bin perl -i +#!/usr/bin/perl -i # # This script converts all numbers that look like addresses or memory sizes, # in a debug files generated by --debug (like mysqld --debug-dbug), to #. From 65c632cb9cf44aea8132b65cc7a08253ec4282af Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Tue, 29 Sep 2020 19:12:00 +0300 Subject: [PATCH 04/15] MDEV-23832 Crash at startup in Log_event::read_log_event The crash was caused by improper raising of an error or replication checksum verification at time of the server initialization. As there is no THD object associated with the main initializing thread yet the error text should be assigned with calling a respective macro that is aware of that possibility. Fixed accordingly. [At merging to 10.4 the new test result file needs +# restart: --master_verify_checksum=ON --debug_dbug=+d,corrupt_read_log_event_char that mtr run will hint on.] --- .../r/binlog_recover_checksum_error.result | 7 ++++ .../t/binlog_recover_checksum_error.test | 37 +++++++++++++++++++ sql/log_event.cc | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/binlog/r/binlog_recover_checksum_error.result create mode 100644 mysql-test/suite/binlog/t/binlog_recover_checksum_error.test diff --git a/mysql-test/suite/binlog/r/binlog_recover_checksum_error.result b/mysql-test/suite/binlog/r/binlog_recover_checksum_error.result new file mode 100644 index 00000000000..f65f7797d7f --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_recover_checksum_error.result @@ -0,0 +1,7 @@ +set @@global.binlog_checksum = CRC32; +call mtr.add_suppression("Replication event checksum verification failed"); +call mtr.add_suppression("Error in Log_event::read_log_event"); +set @@global.debug_dbug = VALUE; +set @@global.master_verify_checksum = DO_CHECKSUM; +set @@global.binlog_checksum = BINLOG_CHECKSUM; +# EOF the test diff --git a/mysql-test/suite/binlog/t/binlog_recover_checksum_error.test b/mysql-test/suite/binlog/t/binlog_recover_checksum_error.test new file mode 100644 index 00000000000..12c9f3d914f --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_recover_checksum_error.test @@ -0,0 +1,37 @@ +# The test verifies server binlog-based recovery. +# +# MDEV-23832 checksum error at server binlog recovery should not crash + +# The test logic really requires --log-bin. +--source include/have_binlog_format_mixed.inc +--source include/have_debug.inc + +--let $do_checksum = `SELECT @@global.master_verify_checksum` +--let $debug_dbug_saved = `SELECT @@global.debug_dbug` +--let $binlog_checksum = `SELECT @@global.binlog_checksum` +set @@global.binlog_checksum = CRC32; + +call mtr.add_suppression("Replication event checksum verification failed"); +call mtr.add_suppression("Error in Log_event::read_log_event"); + +# Proof of no crash follows. +# There's no need for actual bin-loggable queries to the server +--let $restart_parameters= --master_verify_checksum=ON --debug_dbug="+d,corrupt_read_log_event_char" +--let $shutdown_timeout=0 +--source include/restart_mysqld.inc +--let $restart_parameters= +--let $shutdown_timeout= + +# +# Cleanup + +--replace_regex /= .*/= VALUE/ +--eval set @@global.debug_dbug = "$debug_dbug_saved" + +--replace_result $do_checksum DO_CHECKSUM +--eval set @@global.master_verify_checksum = $do_checksum +--replace_result $binlog_checksum BINLOG_CHECKSUM +--eval set @@global.binlog_checksum = $binlog_checksum +# +--echo # EOF the test +# diff --git a/sql/log_event.cc b/sql/log_event.cc index 3d28c249e21..146d8bd5dbe 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1632,7 +1632,7 @@ Log_event* Log_event::read_log_event(const char* buf, uint event_len, else DBUG_RETURN(NULL); #else - *error= ER(ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE); + *error= ER_THD_OR_DEFAULT(current_thd, ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE); sql_print_error("%s", *error); DBUG_RETURN(NULL); #endif From 1a850225d38484ce68901756347e5197adc17a9c Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 7 Oct 2020 11:22:10 -0400 Subject: [PATCH 05/15] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 453e11b3aae..1c88e2091d0 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=1 -MYSQL_VERSION_PATCH=47 +MYSQL_VERSION_PATCH=48 From 00c44fb18ec54682ffd208126e0de6ab172fa50b Mon Sep 17 00:00:00 2001 From: Nisha Gopalakrishnan Date: Thu, 20 Sep 2012 12:34:31 +0530 Subject: [PATCH 06/15] MDEV-4851: BUG#11763447: 'YOU CANNOT 'ALTER' A LOG TABLE IF LOGGING IS ENABLED' EVEN IF I LOG TO FILE. Analysis: ---------- MYSQL_UPGRADE of the master breaks the replication when the query logging is enabled with FILE/NONE 'log-output' option on the slave. mysql_upgrade modifies the 'general_log' and 'slow_log' tables after the logging is disabled as below: SET @old_log_state = @@global.general_log; SET GLOBAL general_log = 'OFF'; ALTER TABLE general_log MODIFY event_time TIMESTAMP NOT NULL, ( .... ); SET GLOBAL general_log = @old_log_state; and SET @old_log_state = @@global.slow_query_log; SET GLOBAL slow_query_log = 'OFF'; ALTER TABLE slow_log MODIFY start_time TIMESTAMP NOT NULL, ( .... ); SET GLOBAL slow_query_log = @old_log_state; In the binary log, only the ALTER statements are logged but not the SET statements which turns ON/OFF the logging. So when the slave replays the binary log,the ALTER of LOG tables throws an error since the logging is enabled. Also the 'log-output' option is not checked to determine whether to allow/disallow the ALTER operation. Fix: ---- The 'log-output' option is included in the check while determining whether the query logging happens using the log tables. Picked from mysql respository at 0daaf8aecd8f84ff1fb400029139222ea1f0d812 --- sql/log.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 8049b94bab1..f2fe0d852d1 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2012, 2018, Oracle and/or its affiliates. Copyright (c) 2009, 2019, MariaDB Corporation This program is free software; you can redistribute it and/or modify @@ -534,9 +534,11 @@ bool LOGGER::is_log_table_enabled(uint log_table_type) { switch (log_table_type) { case QUERY_LOG_SLOW: - return (table_log_handler != NULL) && global_system_variables.sql_log_slow; + return (table_log_handler != NULL) && global_system_variables.sql_log_slow + && (log_output_options & LOG_TABLE); case QUERY_LOG_GENERAL: - return (table_log_handler != NULL) && opt_log ; + return (table_log_handler != NULL) && opt_log + && (log_output_options & LOG_TABLE); default: DBUG_ASSERT(0); return FALSE; /* make compiler happy */ From 874942a0f910731b54eb57aef01c1bef701ab6ba Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 5 Oct 2020 13:26:28 +1100 Subject: [PATCH 07/15] MDEV-4851: (tests) log tables modifiable on log_output!=TABLE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test we can ALTER log tables directly when not being written to. This removes the contraint in the rpl_mysql_upgrade.test such that we can run mysql_upgrade --write-binlog all the way through to a replica. We test this in the replication scenario where the mysql.{slow,general}_log tables aren't being written to. Reviewers: Vicențiu Ciorbaru, Anel Husakovic --- mysql-test/r/log_tables.result | 8 +++ .../suite/rpl/r/rpl_mysql_upgrade.result | 54 ++++++++++++++++--- mysql-test/suite/rpl/t/rpl_mysql_upgrade.test | 34 +++++++++--- mysql-test/t/log_tables.test | 20 ++++++- 4 files changed, 101 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/log_tables.result b/mysql-test/r/log_tables.result index ff5055e1ae4..cfecae91733 100644 --- a/mysql-test/r/log_tables.result +++ b/mysql-test/r/log_tables.result @@ -377,6 +377,14 @@ slow_log slow_log_new drop table slow_log_new, general_log_new; use test; +SET GLOBAL LOG_OUTPUT = 'FILE'; +SET GLOBAL slow_query_log = 1; +SET GLOBAL general_log = 1; +ALTER TABLE mysql.slow_log ADD COLUMN comment_text TEXT NOT NULL; +ALTER TABLE mysql.general_log ADD COLUMN comment_text TEXT NOT NULL; +SET GLOBAL LOG_OUTPUT = 'NONE'; +ALTER TABLE mysql.slow_log DROP COLUMN comment_text; +ALTER TABLE mysql.general_log DROP COLUMN comment_text; SET GLOBAL LOG_OUTPUT = 'TABLE'; SET GLOBAL general_log = 0; FLUSH LOGS; diff --git a/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result b/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result index 9e360beba2c..5bc891d90fc 100644 --- a/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result +++ b/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result @@ -2,12 +2,54 @@ include/master-slave.inc [connection master] call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); call mtr.add_suppression("table or database name 'mysqltest-1'"); -DROP DATABASE IF EXISTS `#mysql50#mysqltest-1`; -CREATE DATABASE `#mysql50#mysqltest-1`; +CREATE DATABASE `mysqltest-1`; Master position is not changed -STOP SLAVE SQL_THREAD; -include/wait_for_slave_sql_to_stop.inc -Master position has been changed +SET @old_general_log_state = @@global.general_log; +SET @old_slow_log_state = @@global.slow_query_log; +SET @old_log_output = @@global.log_output; +SET GLOBAL general_log = 'ON'; +SET GLOBAL slow_query_log = 'ON'; +SET GLOBAL log_output = 'FILE'; +ALTER TABLE mysql.slow_log DROP COLUMN thread_id, DROP COLUMN rows_affected; DROP DATABASE `mysqltest-1`; -DROP DATABASE `#mysql50#mysqltest-1`; +SHOW CREATE TABLE mysql.slow_log; +Table Create Table +slow_log CREATE TABLE `slow_log` ( + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `user_host` mediumtext NOT NULL, + `query_time` time(6) NOT NULL, + `lock_time` time(6) NOT NULL, + `rows_sent` int(11) NOT NULL, + `rows_examined` int(11) NOT NULL, + `db` varchar(512) NOT NULL, + `last_insert_id` int(11) NOT NULL, + `insert_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `sql_text` mediumtext NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +Master position has been changed +SHOW CREATE TABLE mysql.slow_log; +Table Create Table +slow_log CREATE TABLE `slow_log` ( + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `user_host` mediumtext NOT NULL, + `query_time` time(6) NOT NULL, + `lock_time` time(6) NOT NULL, + `rows_sent` int(11) NOT NULL, + `rows_examined` int(11) NOT NULL, + `db` varchar(512) NOT NULL, + `last_insert_id` int(11) NOT NULL, + `insert_id` int(11) NOT NULL, + `server_id` int(10) unsigned NOT NULL, + `sql_text` mediumtext NOT NULL, + `thread_id` bigint(21) unsigned NOT NULL, + `rows_affected` int(11) NOT NULL +) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +SET GLOBAL general_log = 'OFF'; +SET GLOBAL slow_query_log = 'OFF'; +truncate mysql.slow_log; +truncate mysql.general_log; +SET GLOBAL general_log = @old_general_log_state; +SET GLOBAL slow_query_log = @old_slow_log_state; +SET GLOBAL log_output = @old_log_output; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test b/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test index 1931e2eab2a..f44c883ef4e 100644 --- a/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test +++ b/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test @@ -14,8 +14,7 @@ call mtr.add_suppression("table or database name 'mysqltest-1'"); connection master; --disable_warnings -DROP DATABASE IF EXISTS `#mysql50#mysqltest-1`; -CREATE DATABASE `#mysql50#mysqltest-1`; +CREATE DATABASE `mysqltest-1`; --enable_warnings sync_slave_with_master; @@ -34,13 +33,25 @@ if ($before_position == $after_position) echo Master position is not changed; } -#Some log events of the mysql_upgrade's will cause errors on slave. +# Some log events of the mysql_upgrade previously caused errors on slave, +# however with MDEV-4851 this should be ok, so we test it: connection slave; -STOP SLAVE SQL_THREAD; -source include/wait_for_slave_sql_to_stop.inc; +SET @old_general_log_state = @@global.general_log; +SET @old_slow_log_state = @@global.slow_query_log; +SET @old_log_output = @@global.log_output; +SET GLOBAL general_log = 'ON'; +SET GLOBAL slow_query_log = 'ON'; +SET GLOBAL log_output = 'FILE'; connection master; #With '--force' option, mysql_upgrade always executes all sql statements for upgrading. +ALTER TABLE mysql.slow_log DROP COLUMN thread_id, DROP COLUMN rows_affected; +DROP DATABASE `mysqltest-1`; +sync_slave_with_master; + +connection slave; +SHOW CREATE TABLE mysql.slow_log; +connection master; --exec $MYSQL_UPGRADE --skip-verbose --write-binlog --force --user=root > $MYSQLTEST_VARDIR/log/mysql_upgrade.log 2>&1 let $datadir= `select @@datadir`; @@ -55,8 +66,15 @@ if ($before_position != $after_position) echo Master position has been changed; } -DROP DATABASE `mysqltest-1`; +sync_slave_with_master; connection slave; -DROP DATABASE `#mysql50#mysqltest-1`; ---let $rpl_only_running_threads= 1 +SHOW CREATE TABLE mysql.slow_log; +SET GLOBAL general_log = 'OFF'; +SET GLOBAL slow_query_log = 'OFF'; +truncate mysql.slow_log; +truncate mysql.general_log; +SET GLOBAL general_log = @old_general_log_state; +SET GLOBAL slow_query_log = @old_slow_log_state; +SET GLOBAL log_output = @old_log_output; + --source include/rpl_end.inc diff --git a/mysql-test/t/log_tables.test b/mysql-test/t/log_tables.test index f822ec8d758..0196e62f12f 100644 --- a/mysql-test/t/log_tables.test +++ b/mysql-test/t/log_tables.test @@ -58,7 +58,7 @@ select * from general_log where argument like '%general_log%'; # # Check some basic queries interfering with the log tables. -# In our test we'll use a tbale with verbose comments to the short +# In our test we'll use a table with verbose comments to the short # command type names, used in the tables # @@ -470,6 +470,24 @@ show tables like "%log%"; drop table slow_log_new, general_log_new; use test; +# +# Bug#69953 / MDEV-4851 +# Log tables should be modifable on LOG_OUTPUT != TABLE +# +# + +SET GLOBAL LOG_OUTPUT = 'FILE'; +SET GLOBAL slow_query_log = 1; +SET GLOBAL general_log = 1; + +ALTER TABLE mysql.slow_log ADD COLUMN comment_text TEXT NOT NULL; +ALTER TABLE mysql.general_log ADD COLUMN comment_text TEXT NOT NULL; + +SET GLOBAL LOG_OUTPUT = 'NONE'; +ALTER TABLE mysql.slow_log DROP COLUMN comment_text; +ALTER TABLE mysql.general_log DROP COLUMN comment_text; + + # # Bug#27857 (Log tables supplies the wrong value for generating # AUTO_INCREMENT numbers) From 6504d3d229b086d20e5e4798b1ae10bbbd70d3c7 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 29 Sep 2020 16:18:43 +0530 Subject: [PATCH 08/15] MDEV-23722 InnoDB: Assertion: result != FTS_INVALID in fts_trx_row_get_new_state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Marking of deletion of row in fts index happens twice in self-referential foreign key relation. So while performing referential checks of foreign key, InnoDB can avoid updating of fts index if the foreign key has self-referential relationship. Reviewed-by: Marko Mäkelä --- mysql-test/suite/innodb/r/foreign_key.result | 35 ++++++++++++++++ mysql-test/suite/innodb/t/foreign_key.test | 35 ++++++++++++++++ .../innodb_fts/r/innodb_fts_misc_1.result | 42 +++++++++++++++++++ .../suite/innodb_fts/t/innodb_fts_misc_1.test | 42 +++++++++++++++++++ storage/innobase/dict/dict0mem.cc | 19 +++++++++ storage/innobase/include/dict0mem.h | 4 ++ storage/innobase/row/row0ins.cc | 41 +++--------------- storage/xtradb/dict/dict0mem.cc | 19 +++++++++ storage/xtradb/include/dict0mem.h | 4 ++ storage/xtradb/row/row0ins.cc | 41 +++--------------- 10 files changed, 212 insertions(+), 70 deletions(-) diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index e9fbc742379..74d7cbb7d9a 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -244,3 +244,38 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction XA END 'xid'; XA ROLLBACK 'xid'; DROP TABLE t1; +CREATE TABLE t1 (pk INT PRIMARY KEY, +f1 VARCHAR(10), f2 VARCHAR(10), +f3 VARCHAR(10), f4 VARCHAR(10), +f5 VARCHAR(10), f6 VARCHAR(10), +f7 VARCHAR(10), f8 VARCHAR(10), +INDEX(f1), INDEX(f2), INDEX(f3), INDEX(f4), +INDEX(f5), INDEX(f6), INDEX(f7), INDEX(f8)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 'mariadb', 'mariadb', 'mariadb', 'mariadb', +'mariadb', 'mariadb', 'mariadb', 'mariadb'), +(2, 'mariadb', 'mariadb', 'mariadb', 'mariadb', +'mariadb', 'mariadb', 'mariadb', 'mariadb'), +(3, 'innodb', 'innodb', 'innodb', 'innodb', +'innodb', 'innodb', 'innodb', 'innodb'); +ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t1 (f2) ON DELETE SET NULL; +START TRANSACTION; +DELETE FROM t1 where f1='mariadb'; +SELECT * FROM t1; +pk f1 f2 f3 f4 f5 f6 f7 f8 +2 NULL mariadb mariadb mariadb mariadb mariadb mariadb mariadb +3 innodb innodb innodb innodb innodb innodb innodb innodb +ROLLBACK; +ALTER TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f4) ON DELETE CASCADE; +START TRANSACTION; +DELETE FROM t1 where f3='mariadb'; +SELECT * FROM t1; +pk f1 f2 f3 f4 f5 f6 f7 f8 +3 innodb innodb innodb innodb innodb innodb innodb innodb +ROLLBACK; +ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; +UPDATE t1 SET f6='update'; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; +UPDATE t1 SET f6='cascade'; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index 3269aeed62b..29bf91f2f24 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -299,6 +299,41 @@ ALTER TABLE t1 ADD FOREIGN KEY f (a) REFERENCES t1 (pk), LOCK=EXCLUSIVE;# Cleanu XA END 'xid'; XA ROLLBACK 'xid'; DROP TABLE t1; + +CREATE TABLE t1 (pk INT PRIMARY KEY, + f1 VARCHAR(10), f2 VARCHAR(10), + f3 VARCHAR(10), f4 VARCHAR(10), + f5 VARCHAR(10), f6 VARCHAR(10), + f7 VARCHAR(10), f8 VARCHAR(10), + INDEX(f1), INDEX(f2), INDEX(f3), INDEX(f4), + INDEX(f5), INDEX(f6), INDEX(f7), INDEX(f8)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 'mariadb', 'mariadb', 'mariadb', 'mariadb', + 'mariadb', 'mariadb', 'mariadb', 'mariadb'), + (2, 'mariadb', 'mariadb', 'mariadb', 'mariadb', + 'mariadb', 'mariadb', 'mariadb', 'mariadb'), + (3, 'innodb', 'innodb', 'innodb', 'innodb', + 'innodb', 'innodb', 'innodb', 'innodb'); +ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t1 (f2) ON DELETE SET NULL; +START TRANSACTION; +DELETE FROM t1 where f1='mariadb'; +SELECT * FROM t1; +ROLLBACK; + +ALTER TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f4) ON DELETE CASCADE; + +START TRANSACTION; +DELETE FROM t1 where f3='mariadb'; +SELECT * FROM t1; +ROLLBACK; + +ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; +--error ER_ROW_IS_REFERENCED_2 +UPDATE t1 SET f6='update'; + +ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; +--error ER_ROW_IS_REFERENCED_2 +UPDATE t1 SET f6='cascade'; +DROP TABLE t1; # # End of 10.1 tests # diff --git a/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result b/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result index 9f5c1f271fc..43f79241626 100644 --- a/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result +++ b/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result @@ -913,4 +913,46 @@ DROP TABLE t1; DROP TABLE t2; DROP TABLE t3; DROP TABLE t4; +# +# InnoDB: Failing assertion: result != FTS_INVALID in +# fts_trx_row_get_new_state +# +SET FOREIGN_KEY_CHECKS=1; +CREATE TABLE t1 (pk INT PRIMARY KEY, +f1 VARCHAR(10), f2 VARCHAR(10), +f3 VARCHAR(10), f4 VARCHAR(10), +f5 VARCHAR(10), f6 VARCHAR(10), +f7 VARCHAR(10), f8 VARCHAR(10), +FULLTEXT(f1), FULLTEXT(f2), FULLTEXT(f3), FULLTEXT(f4), +FULLTEXT(f5), FULLTEXT(f6), FULLTEXT(f7), FULLTEXT(f8), +INDEX(f1), INDEX(f2), INDEX(f3), INDEX(f4), +INDEX(f5), INDEX(f6), INDEX(f7), INDEX(f8)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 'mariadb', 'mariadb', 'mariadb', 'mariadb', +'mariadb', 'mariadb', 'mariadb', 'mariadb'), +(2, 'mariadb', 'mariadb', 'mariadb', 'mariadb', +'mariadb', 'mariadb', 'mariadb', 'mariadb'), +(3, 'innodb', 'innodb', 'innodb', 'innodb', +'innodb', 'innodb', 'innodb', 'innodb'); +ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t1 (f2) ON DELETE SET NULL; +START TRANSACTION; +DELETE FROM t1 where f1='mariadb'; +SELECT * FROM t1; +pk f1 f2 f3 f4 f5 f6 f7 f8 +2 NULL mariadb mariadb mariadb mariadb mariadb mariadb mariadb +3 innodb innodb innodb innodb innodb innodb innodb innodb +ROLLBACK; +ALTER TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f4) ON DELETE CASCADE; +START TRANSACTION; +DELETE FROM t1 where f3='mariadb'; +SELECT * FROM t1; +pk f1 f2 f3 f4 f5 f6 f7 f8 +3 innodb innodb innodb innodb innodb innodb innodb innodb +ROLLBACK; +ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; +UPDATE t1 SET f6='update'; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; +UPDATE t1 SET f6='cascade'; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +DROP TABLE t1; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; diff --git a/mysql-test/suite/innodb_fts/t/innodb_fts_misc_1.test b/mysql-test/suite/innodb_fts/t/innodb_fts_misc_1.test index 6ef0452f4c6..e8a3035ba25 100644 --- a/mysql-test/suite/innodb_fts/t/innodb_fts_misc_1.test +++ b/mysql-test/suite/innodb_fts/t/innodb_fts_misc_1.test @@ -907,4 +907,46 @@ DROP TABLE t2; DROP TABLE t3; DROP TABLE t4; +--echo # +--echo # InnoDB: Failing assertion: result != FTS_INVALID in +--echo # fts_trx_row_get_new_state +--echo # +SET FOREIGN_KEY_CHECKS=1; +CREATE TABLE t1 (pk INT PRIMARY KEY, + f1 VARCHAR(10), f2 VARCHAR(10), + f3 VARCHAR(10), f4 VARCHAR(10), + f5 VARCHAR(10), f6 VARCHAR(10), + f7 VARCHAR(10), f8 VARCHAR(10), + FULLTEXT(f1), FULLTEXT(f2), FULLTEXT(f3), FULLTEXT(f4), + FULLTEXT(f5), FULLTEXT(f6), FULLTEXT(f7), FULLTEXT(f8), + INDEX(f1), INDEX(f2), INDEX(f3), INDEX(f4), + INDEX(f5), INDEX(f6), INDEX(f7), INDEX(f8)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 'mariadb', 'mariadb', 'mariadb', 'mariadb', + 'mariadb', 'mariadb', 'mariadb', 'mariadb'), + (2, 'mariadb', 'mariadb', 'mariadb', 'mariadb', + 'mariadb', 'mariadb', 'mariadb', 'mariadb'), + (3, 'innodb', 'innodb', 'innodb', 'innodb', + 'innodb', 'innodb', 'innodb', 'innodb'); +ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t1 (f2) ON DELETE SET NULL; +START TRANSACTION; +DELETE FROM t1 where f1='mariadb'; +SELECT * FROM t1; +ROLLBACK; + +ALTER TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f4) ON DELETE CASCADE; + +START TRANSACTION; +DELETE FROM t1 where f3='mariadb'; +SELECT * FROM t1; +ROLLBACK; + +ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; +--error ER_ROW_IS_REFERENCED_2 +UPDATE t1 SET f6='update'; + +ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; +--error ER_ROW_IS_REFERENCED_2 +UPDATE t1 SET f6='cascade'; +DROP TABLE t1; + SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 6ace0ee9a75..157e695f696 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -852,3 +852,22 @@ operator<< (std::ostream& out, const dict_foreign_set& fk_set) return(out); } +/** Check whether fulltext index gets affected by foreign +key constraint. */ +bool dict_foreign_t::affects_fulltext() const +{ + if (foreign_table == referenced_table || !foreign_table->fts) + return false; + + for (ulint i = 0; i < n_fields; i++) + { + if (dict_table_is_fts_column( + foreign_table->fts->indexes, + dict_index_get_nth_col_no(foreign_index, i)) + != ULINT_UNDEFINED) + return true; + } + + return false; +} + diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 505d4925324..7c59789d313 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -848,6 +848,10 @@ struct dict_foreign_t{ does not generate new indexes implicitly */ dict_index_t* referenced_index;/*!< referenced index */ + + /** Check whether the fulltext index gets affected by + foreign key constraint */ + bool affects_fulltext() const; }; std::ostream& diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index ecbfd03ec93..4d86b0f333c 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -510,7 +510,7 @@ row_ins_cascade_calc_update_vec( n_fields_updated = 0; - *fts_col_affected = FALSE; + *fts_col_affected = foreign->affects_fulltext(); if (table->fts) { doc_id_pos = dict_table_get_nth_col_pos( @@ -631,16 +631,6 @@ row_ins_cascade_calc_update_vec( padded_data, min_size); } - /* Check whether the current column has - FTS index on it */ - if (table->fts - && dict_table_is_fts_column( - table->fts->indexes, - dict_col_get_no(col)) - != ULINT_UNDEFINED) { - *fts_col_affected = TRUE; - } - /* If Doc ID is updated, check whether the Doc ID is valid */ if (table->fts @@ -977,7 +967,6 @@ row_ins_foreign_check_on_constraint( upd_t* update; ulint n_to_update; dberr_t err; - ulint i; trx_t* trx; mem_heap_t* tmp_heap = NULL; doc_id_t doc_id = FTS_NULL_DOC_ID; @@ -1191,7 +1180,7 @@ row_ins_foreign_check_on_constraint( UNIV_MEM_INVALID(update->fields, update->n_fields * sizeof *update->fields); - for (i = 0; i < foreign->n_fields; i++) { + for (ulint i = 0; i < foreign->n_fields; i++) { upd_field_t* ufield = &update->fields[i]; ufield->field_no = dict_table_get_nth_col_pos( @@ -1200,32 +1189,14 @@ row_ins_foreign_check_on_constraint( ufield->orig_len = 0; ufield->exp = NULL; dfield_set_null(&ufield->new_val); - - if (table->fts && dict_table_is_fts_column( - table->fts->indexes, - dict_index_get_nth_col_no(index, i)) - != ULINT_UNDEFINED) { - fts_col_affacted = TRUE; - } } - if (fts_col_affacted) { - fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); - } - } else if (table->fts && cascade->is_delete) { - /* DICT_FOREIGN_ON_DELETE_CASCADE case */ - for (i = 0; i < foreign->n_fields; i++) { - if (table->fts && dict_table_is_fts_column( - table->fts->indexes, - dict_index_get_nth_col_no(index, i)) - != ULINT_UNDEFINED) { - fts_col_affacted = TRUE; - } - } - - if (fts_col_affacted) { + if (foreign->affects_fulltext()) { fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); } + } else if (table->fts && cascade->is_delete + && foreign->affects_fulltext()) { + fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); } if (!node->is_delete diff --git a/storage/xtradb/dict/dict0mem.cc b/storage/xtradb/dict/dict0mem.cc index 89b9bd9aead..82480b13827 100644 --- a/storage/xtradb/dict/dict0mem.cc +++ b/storage/xtradb/dict/dict0mem.cc @@ -853,3 +853,22 @@ operator<< (std::ostream& out, const dict_foreign_set& fk_set) return(out); } +/** Check whether fulltext index gets affected by foreign +key constraint. */ +bool dict_foreign_t::affects_fulltext() const +{ + if (foreign_table == referenced_table || !foreign_table->fts) + return false; + + for (ulint i = 0; i < n_fields; i++) + { + if (dict_table_is_fts_column( + foreign_table->fts->indexes, + dict_index_get_nth_col_no(foreign_index, i)) + != ULINT_UNDEFINED) + return true; + } + + return false; +} + diff --git a/storage/xtradb/include/dict0mem.h b/storage/xtradb/include/dict0mem.h index 1dcc3ebdd0c..f39c89d8e4b 100644 --- a/storage/xtradb/include/dict0mem.h +++ b/storage/xtradb/include/dict0mem.h @@ -864,6 +864,10 @@ struct dict_foreign_t{ does not generate new indexes implicitly */ dict_index_t* referenced_index;/*!< referenced index */ + + /** Check whether the fulltext index gets affected by + foreign key constraint */ + bool affects_fulltext() const; }; std::ostream& diff --git a/storage/xtradb/row/row0ins.cc b/storage/xtradb/row/row0ins.cc index f7371d6b83e..c78f5bc8dc4 100644 --- a/storage/xtradb/row/row0ins.cc +++ b/storage/xtradb/row/row0ins.cc @@ -516,7 +516,7 @@ row_ins_cascade_calc_update_vec( n_fields_updated = 0; - *fts_col_affected = FALSE; + *fts_col_affected = foreign->affects_fulltext(); if (table->fts) { doc_id_pos = dict_table_get_nth_col_pos( @@ -637,16 +637,6 @@ row_ins_cascade_calc_update_vec( padded_data, min_size); } - /* Check whether the current column has - FTS index on it */ - if (table->fts - && dict_table_is_fts_column( - table->fts->indexes, - dict_col_get_no(col)) - != ULINT_UNDEFINED) { - *fts_col_affected = TRUE; - } - /* If Doc ID is updated, check whether the Doc ID is valid */ if (table->fts @@ -983,7 +973,6 @@ row_ins_foreign_check_on_constraint( upd_t* update; ulint n_to_update; dberr_t err; - ulint i; trx_t* trx; mem_heap_t* tmp_heap = NULL; doc_id_t doc_id = FTS_NULL_DOC_ID; @@ -1197,7 +1186,7 @@ row_ins_foreign_check_on_constraint( UNIV_MEM_INVALID(update->fields, update->n_fields * sizeof *update->fields); - for (i = 0; i < foreign->n_fields; i++) { + for (ulint i = 0; i < foreign->n_fields; i++) { upd_field_t* ufield = &update->fields[i]; ufield->field_no = dict_table_get_nth_col_pos( @@ -1206,32 +1195,14 @@ row_ins_foreign_check_on_constraint( ufield->orig_len = 0; ufield->exp = NULL; dfield_set_null(&ufield->new_val); - - if (table->fts && dict_table_is_fts_column( - table->fts->indexes, - dict_index_get_nth_col_no(index, i)) - != ULINT_UNDEFINED) { - fts_col_affacted = TRUE; - } } - if (fts_col_affacted) { - fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); - } - } else if (table->fts && cascade->is_delete) { - /* DICT_FOREIGN_ON_DELETE_CASCADE case */ - for (i = 0; i < foreign->n_fields; i++) { - if (table->fts && dict_table_is_fts_column( - table->fts->indexes, - dict_index_get_nth_col_no(index, i)) - != ULINT_UNDEFINED) { - fts_col_affacted = TRUE; - } - } - - if (fts_col_affacted) { + if (foreign->affects_fulltext()) { fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); } + } else if (table->fts && cascade->is_delete + && foreign->affects_fulltext()) { + fts_trx_add_op(trx, table, doc_id, FTS_DELETE, NULL); } if (!node->is_delete From 72cb20820b4f48fda0ae5e0ead4783d76dde3ec0 Mon Sep 17 00:00:00 2001 From: unki Date: Fri, 25 Sep 2020 08:41:26 +0200 Subject: [PATCH 09/15] mysqlimport manpage - s/mysqldump/mysqlimport/g Closes PR #1672 - Note there are some legacy format not visible when invoking `man` Reviewed by: Ian Gilfillan, Anel Husakovic --- man/mysqlimport.1 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/man/mysqlimport.1 b/man/mysqlimport.1 index 61d270d7057..449c59cb648 100644 --- a/man/mysqlimport.1 +++ b/man/mysqlimport.1 @@ -57,13 +57,13 @@ all would be imported into a table named patient\&. .PP .PP -\fBmysqldump\fR +\fBmysqlimport\fR supports the following options, which can be specified on the command line or in the -[mysqldump] +[mysqlimport] and [client] option file groups\&. -\fBmysqldump\fR +\fBmysqlimport\fR also supports the options for processing option files\&. .sp .RS 4 @@ -267,17 +267,17 @@ Empty the table before importing the text file\&. .sp -1 .IP \(bu 2.3 .\} -.\" mysqldump: fields-terminated-by option -.\" fields-terminated-by option: mysqldump +.\" mysqlimport: fields-terminated-by option +.\" fields-terminated-by option: mysqlimport \fB\-\-fields\-terminated\-by=\&.\&.\&.\fR, -.\" mysqldump: fields-enclosed-by option -.\" fields-enclosed-by option: mysqldump +.\" mysqlimport: fields-enclosed-by option +.\" fields-enclosed-by option: mysqlimport \fB\-\-fields\-enclosed\-by=\&.\&.\&.\fR, -.\" mysqldump: fields-optionally-enclosed-by option -.\" fields-optionally-enclosed-by option: mysqldump +.\" mysqlimport: fields-optionally-enclosed-by option +.\" fields-optionally-enclosed-by option: mysqlimport \fB\-\-fields\-optionally\-enclosed\-by=\&.\&.\&.\fR, -.\" mysqldump: fields-escaped-by option -.\" fields-escaped-by option: mysqldump +.\" mysqlimport: fields-escaped-by option +.\" fields-escaped-by option: mysqlimport \fB\-\-fields\-escaped\-by=\&.\&.\&.\fR .sp These options have the same meaning as the corresponding clauses for @@ -379,8 +379,8 @@ lines of the data file\&. .sp -1 .IP \(bu 2.3 .\} -.\" mysqldump: lines-terminated-by option -.\" lines-terminated-by option: mysqldump +.\" mysqlimport: lines-terminated-by option +.\" lines-terminated-by option: mysqlimport \fB\-\-lines\-terminated\-by=\&.\&.\&.\fR .sp This option has the same meaning as the corresponding clause for From 3e807d255e0e667eec9791dd505a5be4bbfc6a25 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 9 Oct 2020 17:48:22 +0300 Subject: [PATCH 10/15] MDEV-23938: innodb row_search_idx_cond_check handle ICP_ABORTED_BY_USER - row_search_mvcc() should return DB_INTERRUPTED when it got killed. - Add a syncpoint for the ICP check. - Add test coverage for killed-during-ICP-check scenario Backport of MDEV-22761 fixes for ICP from 10.4 commits: * a6f956488c712bef3b13660584d1b905e0c676cc * c03885cd9ceb1ede7f49a9e218022b401b3a1e28 XtraDB was fixed in deb3b9a17498 Reviewer: Daniel Black --- mysql-test/include/icp_debug_kill.inc | 50 +++++++++++++++++++++++++++ mysql-test/t/aria_icp_debug.result | 34 ++++++++++++++++++ mysql-test/t/aria_icp_debug.test | 5 +++ mysql-test/t/innodb_icp_debug.result | 34 ++++++++++++++++++ mysql-test/t/innodb_icp_debug.test | 6 ++++ mysql-test/t/myisam_icp_debug.result | 32 +++++++++++++++++ mysql-test/t/myisam_icp_debug.test | 1 + sql/handler.cc | 1 + storage/innobase/row/row0sel.cc | 19 ++++++---- 9 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 mysql-test/include/icp_debug_kill.inc create mode 100644 mysql-test/t/aria_icp_debug.result create mode 100644 mysql-test/t/aria_icp_debug.test create mode 100644 mysql-test/t/innodb_icp_debug.result create mode 100644 mysql-test/t/innodb_icp_debug.test create mode 100644 mysql-test/t/myisam_icp_debug.result create mode 100644 mysql-test/t/myisam_icp_debug.test diff --git a/mysql-test/include/icp_debug_kill.inc b/mysql-test/include/icp_debug_kill.inc new file mode 100644 index 00000000000..d0ecc842869 --- /dev/null +++ b/mysql-test/include/icp_debug_kill.inc @@ -0,0 +1,50 @@ +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/count_sessions.inc + +--disable_warnings +drop table if exists t0,t1,t2; +--enable_warnings + +create table t0(a int primary key); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1(a int primary key); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; + +create table t2 ( + kp1 int, + kp2 int, + col char(100), + key(kp1, kp2) +); +insert into t2 select a, a, a from t1; + +select engine from information_schema.tables +where table_schema=database() and table_name='t2'; + +explain +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; + +let $target_id= `select connection_id()`; + +set debug_sync='handler_index_cond_check SIGNAL at_icp_check WAIT_FOR go'; +send +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; + +connect (con1, localhost, root,,); +connection con1; +set debug_sync='now WAIT_FOR at_icp_check'; +evalp kill query $target_id; +set debug_sync='now SIGNAL go'; + +connection default; + +--error ER_QUERY_INTERRUPTED +reap; +set debug_sync='RESET'; + +disconnect con1; +drop table t0,t1,t2; +--source include/wait_until_count_sessions.inc + diff --git a/mysql-test/t/aria_icp_debug.result b/mysql-test/t/aria_icp_debug.result new file mode 100644 index 00000000000..fc01ee4fb3b --- /dev/null +++ b/mysql-test/t/aria_icp_debug.result @@ -0,0 +1,34 @@ +set default_storage_engine=aria; +drop table if exists t0,t1,t2; +create table t0(a int primary key); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int primary key); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; +create table t2 ( +kp1 int, +kp2 int, +col char(100), +key(kp1, kp2) +); +insert into t2 select a, a, a from t1; +select engine from information_schema.tables +where table_schema=database() and table_name='t2'; +engine +Aria +explain +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range kp1 kp1 5 NULL 10 Using index condition +set debug_sync='handler_index_cond_check SIGNAL at_icp_check WAIT_FOR go'; +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +connect con1, localhost, root,,; +connection con1; +set debug_sync='now WAIT_FOR at_icp_check'; +kill query $target_id; +set debug_sync='now SIGNAL go'; +connection default; +ERROR 70100: Query execution was interrupted +set debug_sync='RESET'; +disconnect con1; +drop table t0,t1,t2; +set default_storage_engine=default; diff --git a/mysql-test/t/aria_icp_debug.test b/mysql-test/t/aria_icp_debug.test new file mode 100644 index 00000000000..bbdd59d6012 --- /dev/null +++ b/mysql-test/t/aria_icp_debug.test @@ -0,0 +1,5 @@ + +set default_storage_engine=aria; +--source include/icp_debug_kill.inc +set default_storage_engine=default; + diff --git a/mysql-test/t/innodb_icp_debug.result b/mysql-test/t/innodb_icp_debug.result new file mode 100644 index 00000000000..5a169650c8e --- /dev/null +++ b/mysql-test/t/innodb_icp_debug.result @@ -0,0 +1,34 @@ +set default_storage_engine=innodb; +drop table if exists t0,t1,t2; +create table t0(a int primary key); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int primary key); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; +create table t2 ( +kp1 int, +kp2 int, +col char(100), +key(kp1, kp2) +); +insert into t2 select a, a, a from t1; +select engine from information_schema.tables +where table_schema=database() and table_name='t2'; +engine +InnoDB +explain +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range kp1 kp1 5 NULL 11 Using index condition +set debug_sync='handler_index_cond_check SIGNAL at_icp_check WAIT_FOR go'; +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +connect con1, localhost, root,,; +connection con1; +set debug_sync='now WAIT_FOR at_icp_check'; +kill query $target_id; +set debug_sync='now SIGNAL go'; +connection default; +ERROR 70100: Query execution was interrupted +set debug_sync='RESET'; +disconnect con1; +drop table t0,t1,t2; +set default_storage_engine=default; diff --git a/mysql-test/t/innodb_icp_debug.test b/mysql-test/t/innodb_icp_debug.test new file mode 100644 index 00000000000..4aa08c61e87 --- /dev/null +++ b/mysql-test/t/innodb_icp_debug.test @@ -0,0 +1,6 @@ +--source include/have_innodb.inc + +set default_storage_engine=innodb; +--source include/icp_debug_kill.inc +set default_storage_engine=default; + diff --git a/mysql-test/t/myisam_icp_debug.result b/mysql-test/t/myisam_icp_debug.result new file mode 100644 index 00000000000..cb45a0e2274 --- /dev/null +++ b/mysql-test/t/myisam_icp_debug.result @@ -0,0 +1,32 @@ +drop table if exists t0,t1,t2; +create table t0(a int primary key); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int primary key); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; +create table t2 ( +kp1 int, +kp2 int, +col char(100), +key(kp1, kp2) +); +insert into t2 select a, a, a from t1; +select engine from information_schema.tables +where table_schema=database() and table_name='t2'; +engine +MyISAM +explain +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range kp1 kp1 5 NULL 11 Using index condition +set debug_sync='handler_index_cond_check SIGNAL at_icp_check WAIT_FOR go'; +select * from t2 where kp1 between 10 and 20 and kp2 +1 >100; +connect con1, localhost, root,,; +connection con1; +set debug_sync='now WAIT_FOR at_icp_check'; +kill query $target_id; +set debug_sync='now SIGNAL go'; +connection default; +ERROR 70100: Query execution was interrupted +set debug_sync='RESET'; +disconnect con1; +drop table t0,t1,t2; diff --git a/mysql-test/t/myisam_icp_debug.test b/mysql-test/t/myisam_icp_debug.test new file mode 100644 index 00000000000..d5b1af799fa --- /dev/null +++ b/mysql-test/t/myisam_icp_debug.test @@ -0,0 +1 @@ +--source include/icp_debug_kill.inc diff --git a/sql/handler.cc b/sql/handler.cc index 76a187f4312..09ce175e967 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5519,6 +5519,7 @@ extern "C" enum icp_result handler_index_cond_check(void* h_arg) THD *thd= h->table->in_use; enum icp_result res; + DEBUG_SYNC(thd, "handler_index_cond_check"); enum thd_kill_levels abort_at= h->has_transactions() ? THD_ABORT_SOFTLY : THD_ABORT_ASAP; if (thd_kill_level(thd) > abort_at) diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index f45702157c8..a6654a603db 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3588,7 +3588,7 @@ row_sel_try_search_shortcut_for_mysql( /*********************************************************************//** Check a pushed-down index condition. -@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */ +@return ICP_ABORTED_BY_USER, ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */ static enum icp_result row_search_idx_cond_check( @@ -4110,10 +4110,13 @@ row_search_for_mysql( switch (row_search_idx_cond_check( buf, prebuilt, rec, offsets)) { + case ICP_ABORTED_BY_USER: + mtr_commit(&mtr); + err = DB_INTERRUPTED; + goto release_search_latch_if_needed; + case ICP_ERROR: case ICP_NO_MATCH: case ICP_OUT_OF_RANGE: - case ICP_ABORTED_BY_USER: - case ICP_ERROR: goto shortcut_mismatch; case ICP_MATCH: goto shortcut_match; @@ -4849,8 +4852,10 @@ no_gap_lock: buf, prebuilt, rec, offsets)) { case ICP_NO_MATCH: goto next_rec; - case ICP_OUT_OF_RANGE: case ICP_ABORTED_BY_USER: + err = DB_INTERRUPTED; + goto idx_cond_failed; + case ICP_OUT_OF_RANGE: case ICP_ERROR: err = DB_RECORD_NOT_FOUND; goto idx_cond_failed; @@ -4904,9 +4909,11 @@ locks_ok_del_marked: row_unlock_for_mysql(prebuilt, TRUE); } goto next_rec; + case ICP_ABORTED_BY_USER: + err = DB_INTERRUPTED; + goto idx_cond_failed; case ICP_OUT_OF_RANGE: - case ICP_ABORTED_BY_USER: - case ICP_ERROR: + case ICP_ERROR: err = DB_RECORD_NOT_FOUND; goto idx_cond_failed; case ICP_MATCH: From d36cd5f01ec322c4cdf2feda288c3932260c5c57 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Mon, 27 Jul 2020 02:51:33 +0530 Subject: [PATCH 11/15] MDEV-17729: Assertion `! is_set() || m_can_overwrite_status' failed in Diagnostics_area::set_error_status Analysis: When strict mode is enabled, all warnings are converted to errors including those which do not occur because of bad data. Fix: Query should not be aborted when we have warning because limit to examine rows was reached because it doesn't happen due to bad data. So thd->abort_on_warning should be false. --- mysql-test/r/limit_rows_examined.result | 15 +++++++++++++++ mysql-test/t/limit_rows_examined.test | 17 +++++++++++++++++ sql/sql_select.cc | 3 +++ 3 files changed, 35 insertions(+) diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result index 0b3bc196a31..a3ab6122c59 100644 --- a/mysql-test/r/limit_rows_examined.result +++ b/mysql-test/r/limit_rows_examined.result @@ -853,3 +853,18 @@ Warnings: Warning 1931 Query execution was interrupted. The query examined at least 22 rows, which exceeds LIMIT ROWS EXAMINED (21). The query result may be incomplete. drop view v; drop table t1, t2; +# +# 10.1 Test +# +# MDEV-17729: Assertion `! is_set() || m_can_overwrite_status' +# failed in Diagnostics_area::set_error_status +# +set @old_mode= @@sql_mode; +CREATE TABLE t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,k INT, c CHAR(20)); +INSERT INTO t1 (k,c) VALUES(0,'0'), (0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0'); +SET @@sql_mode='STRICT_TRANS_TABLES'; +INSERT INTO t1 (c) SELECT k FROM t1 LIMIT ROWS EXAMINED 2; +Warnings: +Warning 1931 Query execution was interrupted. The query examined at least 4 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete. +SET @@sql_mode=@old_mode; +DROP TABLE t1; diff --git a/mysql-test/t/limit_rows_examined.test b/mysql-test/t/limit_rows_examined.test index 45ee483c7aa..346a0478891 100644 --- a/mysql-test/t/limit_rows_examined.test +++ b/mysql-test/t/limit_rows_examined.test @@ -576,3 +576,20 @@ EXECUTE ps; drop view v; drop table t1, t2; + +--echo # +--echo # 10.1 Test +--echo # +--echo # MDEV-17729: Assertion `! is_set() || m_can_overwrite_status' +--echo # failed in Diagnostics_area::set_error_status +--echo # +set @old_mode= @@sql_mode; + +CREATE TABLE t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,k INT, c CHAR(20)); +INSERT INTO t1 (k,c) VALUES(0,'0'), (0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0'),(0,'0'); + +SET @@sql_mode='STRICT_TRANS_TABLES'; +INSERT INTO t1 (c) SELECT k FROM t1 LIMIT ROWS EXAMINED 2; + +SET @@sql_mode=@old_mode; +DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e2e87bb1a86..138f98212aa 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -399,11 +399,14 @@ bool handle_select(THD *thd, LEX *lex, select_result *result, If LIMIT ROWS EXAMINED interrupted query execution, issue a warning, continue with normal processing and produce an incomplete query result. */ + bool saved_abort_on_warning= thd->abort_on_warning; + thd->abort_on_warning= false; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT, ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT), thd->accessed_rows_and_keys, thd->lex->limit_rows_examined->val_uint()); + thd->abort_on_warning= saved_abort_on_warning; thd->reset_killed(); } /* Disable LIMIT ROWS EXAMINED after query execution. */ From 9fca6645f42a6322215de51d97c9237f4a28a2d1 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Thu, 17 Sep 2020 18:55:59 +0530 Subject: [PATCH 12/15] MDEV-5628: Assertion `! is_set()' or `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' fails on UPDATE on a partitioned table with subquery (MySQL:71630) Analysis and fix: Error is not checked. So correct error state is not returned. Fix: Check for error and return the error state. --- mysql-test/r/partition.result | 11 +++++++++++ mysql-test/t/partition.test | 16 ++++++++++++++++ sql/sql_update.cc | 2 ++ 3 files changed, 29 insertions(+) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 57fa374d4f1..662929c5b48 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -2796,5 +2796,16 @@ id 16 drop table t1; # +# MDEV-5628: Assertion `! is_set()' or `!is_set() || +# (m_status == DA_OK_BULK && is_bulk_op())' fails on UPDATE on a +# partitioned table with subquery (MySQL:71630) +# +CREATE TABLE t1 (a INT) PARTITION BY HASH(a) PARTITIONS 2; +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1),(2); +UPDATE t1 SET a = 7 WHERE a = ( SELECT b FROM t2 ) ORDER BY a LIMIT 6; +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1,t2; +# # End of 10.1 tests # diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 23f3fa0b4d8..b82485dfc5c 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -2998,6 +2998,22 @@ insert t1 values (6, 'ab'), (4, 'ab'), (5, 'ab'), (16, 'ab'), (14, 'ab'), (15, ' select id from t1 where data = 'ab' order by id; drop table t1; +--echo # +--echo # MDEV-5628: Assertion `! is_set()' or `!is_set() || +--echo # (m_status == DA_OK_BULK && is_bulk_op())' fails on UPDATE on a +--echo # partitioned table with subquery (MySQL:71630) +--echo # + +CREATE TABLE t1 (a INT) PARTITION BY HASH(a) PARTITIONS 2; + +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1),(2); + +--error ER_SUBQUERY_NO_1_ROW +UPDATE t1 SET a = 7 WHERE a = ( SELECT b FROM t2 ) ORDER BY a LIMIT 6; + +DROP TABLE t1,t2; + --echo # --echo # End of 10.1 tests --echo # diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 9b2d24c3ba3..f44aaa2ea99 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -413,6 +413,8 @@ int mysql_update(THD *thd, query_plan.set_no_partitions(); if (thd->lex->describe || thd->lex->analyze_stmt) goto produce_explain_and_leave; + if (thd->is_error()) + DBUG_RETURN(1); my_ok(thd); // No matching records DBUG_RETURN(0); From 0627c4ae21adaae414dec28bc26f225f3deed431 Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Sat, 17 Oct 2020 14:18:54 +0200 Subject: [PATCH 13/15] Updated mtr help - Updated combination example to use `innodb_plugin` ``` $ ./mysql-test/mtr rpl.rpl_invoked_features # no rpl.rpl_invoked_features,mix,xtradb_plugin worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019 rpl.rpl_invoked_features 'innodb_plugin,mix' [ pass ] 904 rpl.rpl_invoked_features 'mix,xtradb' [ pass ] 1707 rpl.rpl_invoked_features 'innodb_plugin,row' [ pass ] 927 rpl.rpl_invoked_features 'row,xtradb' [ pass ] 828 rpl.rpl_invoked_features 'innodb_plugin,stmt' [ pass ] 855 rpl.rpl_invoked_features 'stmt,xtradb' [ pass ] 952 -------------------------------------------------------------------------- ``` - `gdb` option can take optional gdb arguments (good documentation in KB) --- mysql-test/mysql-test-run.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 52920530132..e76712cc079 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -6088,7 +6088,7 @@ Examples: alias main.alias 'main' is the name of the suite for the 't' directory. -rpl.rpl_invoked_features,mix,xtradb_plugin +rpl.rpl_invoked_features,mix,innodb_plugin suite/rpl/t/rpl.rpl_invoked_features Options to control what engine/variation to run: @@ -6216,7 +6216,7 @@ Options for debugging the product debug-server Use debug version of server, but without turning on tracing debugger=NAME Start mysqld in the selected debugger - gdb Start the mysqld(s) in gdb + gdb[=gdb_arguments] Start the mysqld(s) in gdb manual-debug Let user manually start mysqld in debugger, before running test(s) manual-gdb Let user manually start mysqld in gdb, before running From c7552969d0d33e2d8a678ea30de9453253ca2ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 21 Oct 2020 10:04:44 +0300 Subject: [PATCH 14/15] MDEV-23999 Potential stack overflow in InnoDB fulltext search fts_query_t::nested_sub_exp: Keep track of nested fts_ast_visit_sub_exp() calls. fts_ast_visit_sub_exp(): Return DB_OUT_OF_MEMORY if the maximum recursion depth is exceeded. This is motivated by a change in MySQL 5.6.50: mysql/mysql-server@e2a46b4834a0030e5380d45789772cb6beab6e92 Bug #29929684 USING MANY NESTED ARGUMENTS WITH BOOLEAN FTS CAN LEAD TO TERMINATE SERVER --- mysql-test/suite/innodb_fts/r/basic.result | 21 +++++++++++++++++++++ mysql-test/suite/innodb_fts/t/basic.test | 20 ++++++++++++++++++++ storage/innobase/fts/fts0que.cc | 19 ++++++++++++++++--- storage/innobase/include/fts0ast.h | 15 +-------------- storage/xtradb/fts/fts0que.cc | 19 ++++++++++++++++--- storage/xtradb/include/fts0ast.h | 15 +-------------- 6 files changed, 75 insertions(+), 34 deletions(-) diff --git a/mysql-test/suite/innodb_fts/r/basic.result b/mysql-test/suite/innodb_fts/r/basic.result index ae23b93dc84..749787b8e1c 100644 --- a/mysql-test/suite/innodb_fts/r/basic.result +++ b/mysql-test/suite/innodb_fts/r/basic.result @@ -125,6 +125,27 @@ id title body 3 Optimizing MySQL In this tutorial we will show ... 4 1001 MySQL Tricks 1. Never run mysqld as root. 2. ... 5 MySQL vs. YourSQL In the following database comparison ... +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((((Security)))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +ERROR HY000: Table handler out of memory +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('((((((((((((((((((((((((((((((((Security))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +id title body +6 MySQL Security When configured properly, MySQL ... +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((vs))))))))))))))))))))))))))))))),(((to)))' + IN BOOLEAN MODE); +id title body +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('((((((((((((((((((((((((((((((((Security)))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +ERROR 42000: syntax error, unexpected $end +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((((Security))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +ERROR 42000: syntax error, unexpected $end SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('+ MySQL + (>Well < stands)' IN BOOLEAN MODE); id title body diff --git a/mysql-test/suite/innodb_fts/t/basic.test b/mysql-test/suite/innodb_fts/t/basic.test index 58f36be08a5..3c6d64a6fce 100644 --- a/mysql-test/suite/innodb_fts/t/basic.test +++ b/mysql-test/suite/innodb_fts/t/basic.test @@ -99,6 +99,26 @@ SELECT * FROM articles WHERE MATCH (title,body) SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('+ MySQL - (Well stands)' IN BOOLEAN MODE); +--error 128 +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((((Security)))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('((((((((((((((((((((((((((((((((Security))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((vs))))))))))))))))))))))))))))))),(((to)))' + IN BOOLEAN MODE); + +--error ER_PARSE_ERROR +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('((((((((((((((((((((((((((((((((Security)))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); +--error ER_PARSE_ERROR +SELECT * FROM articles WHERE MATCH (title,body) AGAINST +('(((((((((((((((((((((((((((((((((Security))))))))))))))))))))))))))))))))' + IN BOOLEAN MODE); + # Test sub-expression boolean search. Find rows contain # "MySQL" and "Well" or "MySQL" and "stands". But rank the # doc with "Well" higher, and doc with "stands" lower. diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index ce6151e63b8..f1a5b4ccbe4 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -1,7 +1,7 @@ /***************************************************************************** -Copyright (c) 2007, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2007, 2020, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -146,6 +146,8 @@ struct fts_query_t { fts_word_freq_t */ bool multi_exist; /*!< multiple FTS_EXIST oper */ + byte visiting_sub_exp; /*!< count of nested + fts_ast_visit_sub_exp() */ }; /** For phrase matching, first we collect the documents and the positions @@ -2836,6 +2838,8 @@ fts_query_get_token( return(new_ptr); } +static dberr_t fts_ast_visit_sub_exp(fts_ast_node_t*, fts_ast_callback, void*); + /*****************************************************************//** Visit every node of the AST. */ static @@ -2925,7 +2929,7 @@ Process (nested) sub-expression, create a new result set to store the sub-expression result by processing nodes under current sub-expression list. Merge the sub-expression result with that of parent expression list. @return DB_SUCCESS if all well */ -UNIV_INTERN +static dberr_t fts_ast_visit_sub_exp( /*==================*/ @@ -2945,6 +2949,14 @@ fts_ast_visit_sub_exp( ut_a(node->type == FTS_AST_SUBEXP_LIST); + /* To avoid stack overflow, we limit the mutual recursion + depth between fts_ast_visit(), fts_query_visitor() and + fts_ast_visit_sub_exp(). */ + if (query->visiting_sub_exp++ > 31) { + query->error = DB_OUT_OF_MEMORY; + DBUG_RETURN(query->error); + } + cur_oper = query->oper; /* Save current result set */ @@ -2967,6 +2979,7 @@ fts_ast_visit_sub_exp( /* Reinstate parent node state */ query->multi_exist = multi_exist; query->oper = cur_oper; + query->visiting_sub_exp--; /* Merge the sub-expression result with the parent result set. */ subexpr_doc_ids = query->doc_ids; diff --git a/storage/innobase/include/fts0ast.h b/storage/innobase/include/fts0ast.h index b7d467e0082..b7870cbc7bc 100644 --- a/storage/innobase/include/fts0ast.h +++ b/storage/innobase/include/fts0ast.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2018, MariaDB Corporation. +Copyright (c) 2016, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -204,19 +204,6 @@ fts_ast_visit( operator, currently we only ignore FTS_IGNORE operator */ MY_ATTRIBUTE((nonnull, warn_unused_result)); -/*****************************************************************//** -Process (nested) sub-expression, create a new result set to store the -sub-expression result by processing nodes under current sub-expression -list. Merge the sub-expression result with that of parent expression list. -@return DB_SUCCESS if all went well */ -UNIV_INTERN -dberr_t -fts_ast_visit_sub_exp( -/*==================*/ - fts_ast_node_t* node, /*!< in: instance to traverse*/ - fts_ast_callback visitor, /*!< in: callback */ - void* arg) /*!< in: callback arg */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); /******************************************************************** Create a lex instance.*/ UNIV_INTERN diff --git a/storage/xtradb/fts/fts0que.cc b/storage/xtradb/fts/fts0que.cc index 8fce8efac2b..0c51e702907 100644 --- a/storage/xtradb/fts/fts0que.cc +++ b/storage/xtradb/fts/fts0que.cc @@ -1,7 +1,7 @@ /***************************************************************************** -Copyright (c) 2007, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2007, 2020, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2017, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -146,6 +146,8 @@ struct fts_query_t { fts_word_freq_t */ bool multi_exist; /*!< multiple FTS_EXIST oper */ + byte visiting_sub_exp; /*!< count of nested + fts_ast_visit_sub_exp() */ }; /** For phrase matching, first we collect the documents and the positions @@ -2856,6 +2858,8 @@ fts_query_get_token( return(new_ptr); } +static dberr_t fts_ast_visit_sub_exp(fts_ast_node_t*, fts_ast_callback, void*); + /*****************************************************************//** Visit every node of the AST. */ static @@ -2945,7 +2949,7 @@ Process (nested) sub-expression, create a new result set to store the sub-expression result by processing nodes under current sub-expression list. Merge the sub-expression result with that of parent expression list. @return DB_SUCCESS if all well */ -UNIV_INTERN +static dberr_t fts_ast_visit_sub_exp( /*==================*/ @@ -2965,6 +2969,14 @@ fts_ast_visit_sub_exp( ut_a(node->type == FTS_AST_SUBEXP_LIST); + /* To avoid stack overflow, we limit the mutual recursion + depth between fts_ast_visit(), fts_query_visitor() and + fts_ast_visit_sub_exp(). */ + if (query->visiting_sub_exp++ > 31) { + query->error = DB_OUT_OF_MEMORY; + DBUG_RETURN(query->error); + } + cur_oper = query->oper; /* Save current result set */ @@ -2987,6 +2999,7 @@ fts_ast_visit_sub_exp( /* Reinstate parent node state */ query->multi_exist = multi_exist; query->oper = cur_oper; + query->visiting_sub_exp--; /* Merge the sub-expression result with the parent result set. */ subexpr_doc_ids = query->doc_ids; diff --git a/storage/xtradb/include/fts0ast.h b/storage/xtradb/include/fts0ast.h index b7d467e0082..b7870cbc7bc 100644 --- a/storage/xtradb/include/fts0ast.h +++ b/storage/xtradb/include/fts0ast.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2018, MariaDB Corporation. +Copyright (c) 2016, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -204,19 +204,6 @@ fts_ast_visit( operator, currently we only ignore FTS_IGNORE operator */ MY_ATTRIBUTE((nonnull, warn_unused_result)); -/*****************************************************************//** -Process (nested) sub-expression, create a new result set to store the -sub-expression result by processing nodes under current sub-expression -list. Merge the sub-expression result with that of parent expression list. -@return DB_SUCCESS if all went well */ -UNIV_INTERN -dberr_t -fts_ast_visit_sub_exp( -/*==================*/ - fts_ast_node_t* node, /*!< in: instance to traverse*/ - fts_ast_callback visitor, /*!< in: callback */ - void* arg) /*!< in: callback arg */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); /******************************************************************** Create a lex instance.*/ UNIV_INTERN From b4c225ac354686242b5336da84b7a758640936bd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 7 Oct 2020 16:06:20 +1100 Subject: [PATCH 15/15] MDEV-23887: check_linker_flags correct for old cmake compatibility It was only from CMake-3.14.0 that CMAKE_REQUIRED_LINK_OPTIONS was used in CHECK_CXX_SOURCE_COMPILES. Without this, it could be the case (as was on OSX) that a flag was never checked in CHECK_CXX_SOURCE_COMPILES, the CHECK successfully passed, but failed at link time. As such we use CMAKE_REQUIRED_LIBRARIES to include the flags to check as its compatible enough with the cmake versions for non-Windows compilers/linkers. Tested on x86_64 with: * 3.11.4 * 3.17.4 Corrects: 7473e1841c630d86f1873a2a7afacb53955b3f6f In the future: * cmake >=3.14.0 can use CMAKE_REQUIRED_LINK_OPTIONS * cmake >=3.18.0 can use CHECK_LINKER_FLAG (with policy CMP0057 NEW) (e.g: commit c7ac2deff9a2c965887dcc67cbf2a3a7c3e0123d) CMAKE_REQUIRED_LIBRARIES suggested by serg@mariadb.com Reviewed-by: anel@mariadb.org --- cmake/check_linker_flag.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/check_linker_flag.cmake b/cmake/check_linker_flag.cmake index ff4b91e89f6..1ea1772d79e 100644 --- a/cmake/check_linker_flag.cmake +++ b/cmake/check_linker_flag.cmake @@ -6,11 +6,11 @@ FUNCTION(MY_CHECK_AND_SET_LINKER_FLAG flag_to_set) RETURN() ENDIF() STRING(REGEX REPLACE "[-,= +]" "_" result "HAVE_LINK_FLAG_${flag_to_set}") - SET(SAVE_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}") + SET(SAVE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") STRING(REGEX REPLACE "^-Wno-" "-W" flag_to_check ${flag_to_set}) - SET(CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} ${flag_to_check}) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${flag_to_check}) CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${result}) - SET(CMAKE_REQUIRED_LINK_OPTIONS "${SAVE_CMAKE_REQUIRED_LINK_OPTIONS}") + SET(CMAKE_REQUIRED_LIBRARIES "${SAVE_CMAKE_REQUIRED_LIBRARIES}") IF (${result}) FOREACH(linktype SHARED MODULE EXE) IF(ARGN)