diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d9b8b8b129..7357b062d1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,8 +198,9 @@ OPTION(NOT_FOR_DISTRIBUTION "Allow linking with GPLv2-incompatible system librar # Can be switched on only for debug build. # OPTION(WITH_PROTECT_STATEMENT_MEMROOT "Enable protection of statement's memory root after first SP/PS execution. Turned into account only for debug build" OFF) -IF (CMAKE_BUILD_TYPE MATCHES "Debug" AND WITH_PROTECT_STATEMENT_MEMROOT) - ADD_DEFINITIONS(-DPROTECT_STATEMENT_MEMROOT) +IF (WITH_PROTECT_STATEMENT_MEMROOT) + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DPROTECT_STATEMENT_MEMROOT") ENDIF() INCLUDE(check_compiler_flag) diff --git a/README.md b/README.md index 58dbf105fb9..5fe95f46a6b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Code status: * [![Appveyor CI status](https://ci.appveyor.com/api/projects/status/4u6pexmtpuf8jq66?svg=true)](https://ci.appveyor.com/project/rasmushoj/server) ci.appveyor.com -## MariaDB: The open source relational database +## MariaDB: The innovative open source database MariaDB was designed as a drop-in replacement of MySQL(R) with more features, new storage engines, fewer bugs, and better performance. @@ -33,28 +33,23 @@ https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/ https://mariadb.com/kb/en/new-and-old-releases/ +Getting the code, building it and testing it +--------------------------------------------------------------- + +Refer to the following guide: https://mariadb.org/get-involved/getting-started-for-developers/get-code-build-test/ which outlines how to correctly build the source code and run the MariaDB testing framework. + Help ----- More help is available from the Maria Discuss mailing list -https://launchpad.net/~maria-discuss, MariaDB's Zulip +https://lists.mariadb.org/postorius/lists/discuss.lists.mariadb.org/ and MariaDB's Zulip instance, https://mariadb.zulipchat.com/ -Live QA for beginner contributors ----- -MariaDB has a dedicated time each week when we answer new contributor questions live on Zulip. -From 8:00 to 10:00 UTC on Mondays, and 10:00 to 12:00 UTC on Thursdays, -anyone can ask any questions they’d like, and a live developer will be available to assist. - -New contributors can ask questions any time, but we will provide immediate feedback during that interval. - Licensing --------- *************************************************************************** -NOTE: - MariaDB is specifically available only under version 2 of the GNU General Public License (GPLv2). (I.e. Without the "any later version" clause.) This is inherited from MySQL. Please see the README file in diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 45205eb7b97..367e415c319 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1404,7 +1404,9 @@ static void usage(void) refresh Flush all tables and close and open logfiles\n\ shutdown Take server down\n\ status Gives a short status message from the server\n\ + start-all-slaves Start all slaves\n\ start-slave Start slave\n\ + stop-all-slaves Stop all slaves\n\ stop-slave Stop slave\n\ variables Prints variables available\n\ version Get version info from server"); diff --git a/mysql-test/collections/buildbot_suites.bat b/mysql-test/collections/buildbot_suites.bat index d4a6e665840..13ea5ddb949 100644 --- a/mysql-test/collections/buildbot_suites.bat +++ b/mysql-test/collections/buildbot_suites.bat @@ -1,5 +1,5 @@ if "%MTR_PARALLEL%"=="" set MTR_PARALLEL=%NUMBER_OF_PROCESSORS% -perl mysql-test-run.pl --verbose-restart --force --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=^ +perl mysql-test-run.pl --force --suite-timeout=120 --max-test-fail=10 --retry=3 --suite=^ vcol,gcol,perfschema,^ main,^ innodb,^ diff --git a/mysql-test/include/commit.inc b/mysql-test/include/commit.inc index c696613dab3..132fdcff7bd 100644 --- a/mysql-test/include/commit.inc +++ b/mysql-test/include/commit.inc @@ -613,13 +613,17 @@ call p_verify_status_increment(2, 0, 2, 0); drop table t2; set sql_mode=no_engine_substitution; create temporary table t2 (a int); -call p_verify_status_increment(1, 0, 0, 0); +# One commit for the create temporary table, and two for committing the +# read of the stored procedure from Aria table (creating temporary table +# clears the sp cache). +call p_verify_status_increment(3, 0, 2, 0); set sql_mode=default; --echo # 19. A function changes temp-trans-table. --echo # select f1(); ---echo # Two commits because a binary log record is written -call p_verify_status_increment(2, 0, 1, 0); +--echo # Two commits because a binary log record is written, and another two +--echo # as the function f1() is reloaded after creating temporary table. +call p_verify_status_increment(4, 0, 3, 0); commit; call p_verify_status_increment(2, 0, 1, 0); @@ -672,9 +676,11 @@ call p_verify_status_increment(2, 0, 1, 0); --echo # 25. DDL: DROP TEMPORARY TABLE, does not start a transaction --echo # drop temporary table t2; -call p_verify_status_increment(1, 0, 1, 0); +# Dropping temporary table clears SP caches, so get another two commit +# increments from loading the p_verify_status_increment procedure. +call p_verify_status_increment(3, 0, 2, 0); commit; -call p_verify_status_increment(1, 0, 1, 0); +call p_verify_status_increment(1, 0, 0, 0); --echo # 26. Verify that SET AUTOCOMMIT issues an implicit commit --echo # @@ -721,7 +727,9 @@ call p_verify_status_increment(1, 0, 1, 0); create table t2 (a int); call p_verify_status_increment(0, 0, 0, 0); do (select f1() from t1 where a=2); -call p_verify_status_increment(2, 2, 2, 2); +# Again extra 2 commit increments from re-loading function f1 after +# dropping temporary table. +call p_verify_status_increment(4, 2, 4, 2); commit; call p_verify_status_increment(2, 2, 2, 2); diff --git a/mysql-test/main/commit_1innodb.result b/mysql-test/main/commit_1innodb.result index d090844cb74..973be9fde0d 100644 --- a/mysql-test/main/commit_1innodb.result +++ b/mysql-test/main/commit_1innodb.result @@ -634,7 +634,7 @@ SUCCESS drop table t2; set sql_mode=no_engine_substitution; create temporary table t2 (a int); -call p_verify_status_increment(1, 0, 0, 0); +call p_verify_status_increment(3, 0, 2, 0); SUCCESS set sql_mode=default; @@ -643,8 +643,9 @@ set sql_mode=default; select f1(); f1() 2 -# Two commits because a binary log record is written -call p_verify_status_increment(2, 0, 1, 0); +# Two commits because a binary log record is written, and another two +# as the function f1() is reloaded after creating temporary table. +call p_verify_status_increment(4, 0, 3, 0); SUCCESS commit; @@ -715,11 +716,11 @@ SUCCESS # 25. DDL: DROP TEMPORARY TABLE, does not start a transaction # drop temporary table t2; -call p_verify_status_increment(1, 0, 1, 0); +call p_verify_status_increment(3, 0, 2, 0); SUCCESS commit; -call p_verify_status_increment(1, 0, 1, 0); +call p_verify_status_increment(1, 0, 0, 0); SUCCESS # 26. Verify that SET AUTOCOMMIT issues an implicit commit @@ -801,7 +802,7 @@ call p_verify_status_increment(0, 0, 0, 0); SUCCESS do (select f1() from t1 where a=2); -call p_verify_status_increment(2, 2, 2, 2); +call p_verify_status_increment(4, 2, 4, 2); SUCCESS commit; diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index 37f16b6ade1..aacdfa639ba 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -6396,5 +6396,27 @@ b b d c c 10 NULL NULL NULL NULL DROP TABLE t1,t2,t3,t4; # +# MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); +# Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( +SELECT c FROM t2 WHERE EXISTS ( +SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 +3 SUBQUERY t3a range e e 5 NULL 2 Using where; Using index +3 SUBQUERY t3b index NULL e 5 NULL 2 Using index; Using join buffer (flat, BNL join) +DROP TABLE t1,t2,t3; +# # End of 10.4 tests # diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test index e5544e475f2..6707a741337 100644 --- a/mysql-test/main/join_cache.test +++ b/mysql-test/main/join_cache.test @@ -4304,6 +4304,27 @@ eval $q2; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # MDEV-21102: Server crashes in JOIN_CACHE::write_record_data upon EXPLAIN with subqueries and constant tables +--echo # +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; + +CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,10); + +CREATE TABLE t3 (e int, key (e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(3); + +--echo # Must not crash, must use join buffer in subquery +EXPLAIN +SELECT * FROM t1 +WHERE a > b OR a IN ( + SELECT c FROM t2 WHERE EXISTS ( + SELECT * FROM t3 t3a JOIN t3 t3b WHERE t3a.e < d + ) +); +DROP TABLE t1,t2,t3; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/kill_processlist-6619.test b/mysql-test/main/kill_processlist-6619.test index 09c41f28a8f..0f53034eaa8 100644 --- a/mysql-test/main/kill_processlist-6619.test +++ b/mysql-test/main/kill_processlist-6619.test @@ -4,13 +4,16 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc -let $wait_condition=select count(*) = 1 from information_schema.processlist; -source include/wait_condition.inc; +--disable_ps_protocol +# Ensure no lingering connections from an earlier test run, which can very +# rarely still be visible in SHOW PROCESSLIST here. +--let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist +--source include/wait_condition.inc --connect (con1,localhost,root,,) --let $con_id = `SELECT CONNECTION_ID()` -let $wait_condition=select info is NULL from information_schema.processlist where id != $con_id; +let $wait_condition=select command = 'sleep' from information_schema.processlist where id != $con_id; source include/wait_condition.inc; --replace_result Execute Query @@ -32,9 +35,7 @@ reap; SET DEBUG_SYNC='reset'; # Wait until default connection has reset query string -let $wait_condition= - SELECT COUNT(*) = 1 from information_schema.processlist - WHERE info is NULL; +let $wait_condition=select command = 'sleep' from information_schema.processlist where id != $con_id; --source include/wait_condition.inc --replace_result Execute Query diff --git a/mysql-test/main/mysqld_option_err.result b/mysql-test/main/mysqld_option_err.result index e2c7b0bd213..157edb58532 100644 --- a/mysql-test/main/mysqld_option_err.result +++ b/mysql-test/main/mysqld_option_err.result @@ -4,13 +4,16 @@ Test bad default storage engine. Test non-numeric value passed to number option. Test that bad value for plugin enum option is rejected correctly. Test to see if multiple unknown options will be displayed in the error output -unknown option '--nonexistentoption' -unknown option '--alsononexistent' -unknown variable 'nonexistentvariable=1' +FOUND 1 /unknown option '--nonexistentoption2'/ in mysqltest.log +FOUND 1 /unknown option '--alsononexistent'/ in mysqltest.log +FOUND 1 /unknown variable 'nonexistentvariable=1'/ in mysqltest.log Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output -Error while setting value 'invalid_value' to 'sql_mode' -ambiguous option '--character' (character-set-client-handshake, character_sets_dir) -option '--bootstrap' cannot take an argument +FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log +FOUND 1 /ambiguous option '--character'/ in mysqltest.log +FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log +FOUND 1 /Integer value out of range for uint64: '18446744073709551616' for binlog_cache_size/ in mysqltest.log +FOUND 1 /Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E/ in mysqltest.log +FOUND 1 /Error while setting value '123y' to 'bulk_insert_buffer_size'/ in mysqltest.log Test that --help --verbose works Test that --not-known-option --help --verbose gives error Done. diff --git a/mysql-test/main/mysqld_option_err.test b/mysql-test/main/mysqld_option_err.test index ad4df61b0f8..c2b943bafa1 100644 --- a/mysql-test/main/mysqld_option_err.test +++ b/mysql-test/main/mysqld_option_err.test @@ -25,7 +25,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test bad binlog format. ---error 1 +--error 13 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --log-bin --binlog-format=badformat >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 @@ -35,7 +35,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --echo Test non-numeric value passed to number option. ---error 1 +--error 9 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --min-examined-row-limit=notanumber >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 @@ -46,17 +46,35 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; --error 7 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --plugin-dir=$MYSQLTEST_VARDIR/plugins --plugin-load=example=ha_example.so --plugin-example-enum-var=noexist >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 +--let SEARCH_FILE = $MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log + --echo Test to see if multiple unknown options will be displayed in the error output -# Remove the noise to make the test robust ---replace_regex /^((?!nonexistent).)*$// /.*unknown/unknown/ --error 7 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --nonexistentoption --alsononexistent --nonexistentvariable=1 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --nonexistentoption2 --alsononexistent --nonexistentvariable=1 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 + +--let SEARCH_PATTERN=unknown option '--nonexistentoption2' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=unknown option '--alsononexistent' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=unknown variable 'nonexistentvariable=1' +--source include/search_pattern_in_file.inc --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output -# Remove the noise to make the test robust ---replace_regex /^((?!('sql_mode'|'--character'|'--bootstrap')).)*$// /.*Error while setting value/Error while setting value/ /.*ambiguous option/ambiguous option/ /.*option '--bootstrap'/option '--bootstrap'/ ---error 1 ---exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob 2>&1 +--error 9 +--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 --bulk_insert_buffer_size=123y >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 + +--let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=ambiguous option '--character' +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=option '--bootstrap' cannot take an argument +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Integer value out of range for uint64: '18446744073709551616' for binlog_cache_size +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN=Error while setting value '123y' to 'bulk_insert_buffer_size' +--source include/search_pattern_in_file.inc # # Test that an wrong option with --help --verbose gives an error diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index e437b63761b..9f99d613539 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -5979,6 +5979,19 @@ EXECUTE stmt USING DEFAULT; # Clean up DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +# MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +CREATE TABLE t1 AS SELECT 1 f; +PREPARE stmt FROM 'SHOW CREATE TABLE t1'; +DROP TABLE t1; +EXECUTE stmt; +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE VIEW t1 AS SELECT 1; +EXECUTE stmt; +View Create View character_set_client collation_connection +t1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `t1` AS select 1 AS `1` latin1 latin1_swedish_ci +# Clean up +DEALLOCATE PREPARE stmt; +DROP VIEW t1; # # End of 10.4 tests # diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test index a360d0efd0f..c7568f73beb 100644 --- a/mysql-test/main/ps.test +++ b/mysql-test/main/ps.test @@ -5421,6 +5421,18 @@ EXECUTE stmt USING DEFAULT; DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +--echo # MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +CREATE TABLE t1 AS SELECT 1 f; +PREPARE stmt FROM 'SHOW CREATE TABLE t1'; +DROP TABLE t1; +--error ER_NO_SUCH_TABLE +EXECUTE stmt; +CREATE VIEW t1 AS SELECT 1; +EXECUTE stmt; +--echo # Clean up +DEALLOCATE PREPARE stmt; +DROP VIEW t1; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/main/query_cache.result b/mysql-test/main/query_cache.result index 3a81b648171..6cdbf8242c3 100644 --- a/mysql-test/main/query_cache.result +++ b/mysql-test/main/query_cache.result @@ -2208,12 +2208,42 @@ Qcache_queries_in_cache 0 DROP FUNCTION foo; drop table t1; # +# MDEV-33861: main.query_cache fails with embedded after +# enabling WITH_PROTECT_STATEMENT_MEMROOT +# +create table t1 (s1 int); +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +Call f4(); +s1 +cAll f3(); +s1 +insert into t1 values (2); +caLl f3(); +s1 +2 +drop procedure f3; +drop procedure f4; +drop table t1; +# +# End of 10.4 tests +# +# # MDEV-24858 SIGABRT in DbugExit from my_malloc in Query_cache::init_cache Regression # SET @qc= @@query_cache_size; set global Query_cache_size=18446744073709547520; SET GLOBAL query_cache_size= @qc; # +# End of 10.5 tests +# +# # MDEV-22301 JSON_TABLE: Queries are not inserted into query cache. # create table t1 (a text); @@ -2239,3 +2269,4 @@ DROP TABLE t; restore defaults SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; +# End of 10.6 tests diff --git a/mysql-test/main/query_cache.test b/mysql-test/main/query_cache.test index 257ab80b8a5..b9ac5e9d44d 100644 --- a/mysql-test/main/query_cache.test +++ b/mysql-test/main/query_cache.test @@ -1807,6 +1807,40 @@ show status like "Qcache_queries_in_cache"; DROP FUNCTION foo; drop table t1; +--echo # +--echo # MDEV-33861: main.query_cache fails with embedded after +--echo # enabling WITH_PROTECT_STATEMENT_MEMROOT +--echo # + +create table t1 (s1 int); +--delimiter // +create procedure f3 () begin +select * from t1; +end; +// +create procedure f4 () begin +select * from t1; +end; +// +--delimiter ; + +Call f4(); + +cAll f3(); + +insert into t1 values (2); + +caLl f3(); + +drop procedure f3; +drop procedure f4; +drop table t1; + + +--echo # +--echo # End of 10.4 tests +--echo # + --echo # --echo # MDEV-24858 SIGABRT in DbugExit from my_malloc in Query_cache::init_cache Regression --echo # @@ -1816,6 +1850,10 @@ set global Query_cache_size=18446744073709547520; SET GLOBAL query_cache_size= @qc; --enable_warnings +--echo # +--echo # End of 10.5 tests +--echo # + --echo # --echo # MDEV-22301 JSON_TABLE: Queries are not inserted into query cache. --echo # @@ -1838,3 +1876,5 @@ DROP TABLE t; SET GLOBAL query_cache_type= default; SET GLOBAL query_cache_size=@save_query_cache_size; --enable_ps2_protocol + +--echo # End of 10.6 tests diff --git a/mysql-test/main/read_only_innodb.result b/mysql-test/main/read_only_innodb.result index abfc5322ed0..03046f7dad8 100644 --- a/mysql-test/main/read_only_innodb.result +++ b/mysql-test/main/read_only_innodb.result @@ -70,7 +70,7 @@ UNLOCK TABLES; DROP TABLE t1; DROP USER test@localhost; disconnect con1; -echo End of 5.1 tests +# End of 5.1 tests # # Bug#33669: Transactional temporary tables do not work under --read-only # @@ -244,3 +244,26 @@ connection default; SET GLOBAL READ_ONLY = OFF; DROP USER bug33669@localhost; DROP DATABASE db1; +# End of 5.5 tests +# +# MDEV-33889 Read only server throws error when running a create temporary table as select statement +# +create table t1(a int) engine=innodb; +create user u1@localhost; +grant insert, select, update, delete, create temporary tables on test.* to u1@localhost; +insert into t1 values (1); +set global read_only=1; +connect u1,localhost,u1; +set default_tmp_storage_engine=innodb; +create temporary table tt1 (a int); +create temporary table tt2 like t1; +create temporary table tt3 as select * from t1; +select * from tt3; +a +1 +disconnect u1; +connection default; +drop table t1; +drop user u1@localhost; +set global read_only=0; +# End of 10.5 tests diff --git a/mysql-test/main/read_only_innodb.test b/mysql-test/main/read_only_innodb.test index 4b00c32b185..7ad05ca55af 100644 --- a/mysql-test/main/read_only_innodb.test +++ b/mysql-test/main/read_only_innodb.test @@ -103,7 +103,7 @@ DROP USER test@localhost; disconnect con1; ---echo echo End of 5.1 tests +--echo # End of 5.1 tests --echo # --echo # Bug#33669: Transactional temporary tables do not work under --read-only @@ -250,3 +250,29 @@ SET GLOBAL READ_ONLY = OFF; DROP USER bug33669@localhost; DROP DATABASE db1; +--echo # End of 5.5 tests + +--echo # +--echo # MDEV-33889 Read only server throws error when running a create temporary table as select statement +--echo # +create table t1(a int) engine=innodb; +create user u1@localhost; +grant insert, select, update, delete, create temporary tables on test.* to u1@localhost; +insert into t1 values (1); +set global read_only=1; + +connect u1,localhost,u1; +set default_tmp_storage_engine=innodb; + +create temporary table tt1 (a int); +create temporary table tt2 like t1; +create temporary table tt3 as select * from t1; +select * from tt3; +disconnect u1; + +connection default; +drop table t1; +drop user u1@localhost; +set global read_only=0; + +--echo # End of 10.5 tests diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 9b5d48adf95..f3818f25924 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -3900,5 +3900,105 @@ Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where !<`test`.`t1`.`c1`,`test`.`t1`.`pk`>((`test`.`t1`.`c1`,(/* select#2 */ select `test`.`t2`.`c1` from `test`.`t2` join `test`.`t1` `a1` where `test`.`t2`.`i1` = `test`.`t1`.`pk` and `test`.`t2`.`i1` between 3 and 5 and trigcond((`test`.`t1`.`c1`) = `test`.`t2`.`c1`)))) DROP TABLE t1,t2; -set global innodb_stats_persistent= @stats.save; +# +# MDEV-31154: Fatal InnoDB error or assertion `!is_v' failure upon multi-update with indexed virtual column +# +# Test with auto generated Primary Key +# +SET @save_optimizer_switch= @@optimizer_switch; +SET optimizer_switch='rowid_filter=on'; +CREATE TABLE t0(a int); +INSERT INTO t0 SELECT seq FROM seq_1_to_20; +ANALYZE TABLE t0 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t0 analyze status Engine-independent statistics collected +test.t0 analyze status OK +CREATE TABLE t1 ( +a int, +b int as (a * 2) VIRTUAL, +f char(200), /* Filler */ +key (b), +key (a) +) engine=innodb; +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +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 +# Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +count(*) +10 +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +count(*) +10 +# Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100; +count(*) +49 +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +count(*) +49 +# Test with Primary Key +# +DROP TABLE t1; +CREATE TABLE t1 ( +p int PRIMARY KEY AUTO_INCREMENT, +a int, +b int as (a * 2) VIRTUAL, +f char(200), /* Filler */ +key (b), +key (a) +) engine=innodb; +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +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 +# Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +count(*) +10 +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 20 Using where +1 SIMPLE t1 ref|filter b,a b|a 5|5 test.t0.a 1 (2%) Using where; Using rowid filter +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +count(*) +10 +# Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100; +count(*) +49 +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range|filter b,a b|a 5|5 NULL 49 (10%) Using where; Using rowid filter +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +count(*) +49 +SET optimizer_switch=@save_optimizer_switch; +DROP TABLE t0, t1; # End of 10.4 tests +# End of 10.6 tests +set global innodb_stats_persistent= @stats.save; diff --git a/mysql-test/main/rowid_filter_innodb.test b/mysql-test/main/rowid_filter_innodb.test index 6777baf8322..b0d65837127 100644 --- a/mysql-test/main/rowid_filter_innodb.test +++ b/mysql-test/main/rowid_filter_innodb.test @@ -1,6 +1,8 @@ --source include/no_valgrind_without_big.inc --source include/have_innodb.inc --source include/have_debug.inc +--source include/have_sequence.inc +--source include/innodb_stable_estimates.inc SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; @@ -683,6 +685,82 @@ eval EXPLAIN EXTENDED $q; DROP TABLE t1,t2; -set global innodb_stats_persistent= @stats.save; +--echo # +--echo # MDEV-31154: Fatal InnoDB error or assertion `!is_v' failure upon multi-update with indexed virtual column +--echo # + +--echo # Test with auto generated Primary Key +--echo # + +SET @save_optimizer_switch= @@optimizer_switch; +SET optimizer_switch='rowid_filter=on'; + +CREATE TABLE t0(a int); +INSERT INTO t0 SELECT seq FROM seq_1_to_20; +ANALYZE TABLE t0 PERSISTENT FOR ALL; + +CREATE TABLE t1 ( + a int, + b int as (a * 2) VIRTUAL, + f char(200), /* Filler */ + key (b), + key (a) +) engine=innodb; + +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; + +--echo # Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; + +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; + +--echo # Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +SELECT count(*) FROM t1 WHERE a<100 and b <100; + +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; + +--echo # Test with Primary Key +--echo # + +DROP TABLE t1; +CREATE TABLE t1 ( + p int PRIMARY KEY AUTO_INCREMENT, + a int, + b int as (a * 2) VIRTUAL, + f char(200), /* Filler */ + key (b), + key (a) +) engine=innodb; + +INSERT INTO t1 (a, f) SELECT seq, seq FROM seq_1_to_1000; +ANALYZE TABLE t1 PERSISTENT FOR ALL; + +--echo # Test for type 'ref|filter' +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20; + +EXPLAIN SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; +SELECT count(*) from t0,t1 WHERE t0.a=t1.b AND t1.a<20 FOR UPDATE; + +--echo # Test for type 'range|filter' +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100; +SELECT count(*) FROM t1 WHERE a<100 and b <100; + +EXPLAIN SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; +SELECT count(*) FROM t1 WHERE a<100 and b <100 FOR UPDATE; + +SET optimizer_switch=@save_optimizer_switch; + +DROP TABLE t0, t1; --echo # End of 10.4 tests + +--echo # End of 10.6 tests + +set global innodb_stats_persistent= @stats.save; + diff --git a/mysql-test/main/sp.result b/mysql-test/main/sp.result index 2dbd2d74e5f..9efd098fd9c 100644 --- a/mysql-test/main/sp.result +++ b/mysql-test/main/sp.result @@ -7179,15 +7179,14 @@ CREATE VIEW t1 AS SELECT 10 AS f1; CALL p1(1); ERROR HY000: The target table t1 of the INSERT is not insertable-into CREATE TEMPORARY TABLE t1 (f1 INT); -# t1 still refers to the view since it was inlined CALL p1(2); -ERROR HY000: The target table t1 of the INSERT is not insertable-into DROP VIEW t1; # t1 now refers to the temporary table CALL p1(3); # Check which values were inserted into the temp table. SELECT * FROM t1; f1 +2 3 DROP TEMPORARY TABLE t1; DROP PROCEDURE p1; diff --git a/mysql-test/main/sp.test b/mysql-test/main/sp.test index a7349189952..67bd22f6e7e 100644 --- a/mysql-test/main/sp.test +++ b/mysql-test/main/sp.test @@ -8632,8 +8632,6 @@ CALL p1(1); CREATE TEMPORARY TABLE t1 (f1 INT); ---echo # t1 still refers to the view since it was inlined ---error ER_NON_INSERTABLE_TABLE CALL p1(2); DROP VIEW t1; diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index 1f2f1781398..414f9954b35 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -3303,4 +3303,33 @@ a 2 DEALLOCATE PREPARE stmt; DROP TABLE t1,t2,t3; +# +# MDEV-33747: Optimization of (SELECT) IN (SELECT ...) executes subquery at prepare stage +# +create table t1 (a int, b int); +insert into t1 select seq, seq from seq_1_to_200; +create table t2 as select * from t1; +create table t3 as select * from t1; +analyze table t1,t2,t3; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +test.t2 analyze status Engine-independent statistics collected +test.t2 analyze status OK +test.t3 analyze status Engine-independent statistics collected +test.t3 analyze status OK +select @@expensive_subquery_limit < 200 as DEFAULTS_ARE_SUITABLE; +DEFAULTS_ARE_SUITABLE +1 +flush status; +explain select * from t1 where a<3 or (select max(a) from t2) in (select b from t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 200 Using where +3 SUBQUERY t3 ALL NULL NULL NULL NULL 200 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 200 +# Must show 0. If this shows 200, this means subquery was executed and you have a bug: +show status like 'Handler_read_rnd_next%'; +Variable_name Value +Handler_read_rnd_next 0 +drop table t1,t2,t3; # End of 10.4 tests diff --git a/mysql-test/main/subselect4.test b/mysql-test/main/subselect4.test index 1aabaa0a41c..2d39fa1f7ef 100644 --- a/mysql-test/main/subselect4.test +++ b/mysql-test/main/subselect4.test @@ -2670,4 +2670,19 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1,t2,t3; +--echo # +--echo # MDEV-33747: Optimization of (SELECT) IN (SELECT ...) executes subquery at prepare stage +--echo # +create table t1 (a int, b int); +insert into t1 select seq, seq from seq_1_to_200; +create table t2 as select * from t1; +create table t3 as select * from t1; +analyze table t1,t2,t3; +select @@expensive_subquery_limit < 200 as DEFAULTS_ARE_SUITABLE; +flush status; +explain select * from t1 where a<3 or (select max(a) from t2) in (select b from t3); +--echo # Must show 0. If this shows 200, this means subquery was executed and you have a bug: +show status like 'Handler_read_rnd_next%'; +drop table t1,t2,t3; + --echo # End of 10.4 tests diff --git a/mysql-test/main/temp_table.result b/mysql-test/main/temp_table.result index 23052e03a43..61b78f96d4f 100644 --- a/mysql-test/main/temp_table.result +++ b/mysql-test/main/temp_table.result @@ -614,6 +614,55 @@ Tables_in_test # in 11.2 and above here should be listed above used temporary tables DROP TEMPORARY TABLE t1, t2; # +# MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +# +CREATE VIEW v1 AS SELECT 5; +CREATE PROCEDURE sp() SELECT * FROM v1; +CREATE TEMPORARY TABLE v1 as SELECT 7; +# sp() accesses the temporary table v1 that hides the view with the same name +# Therefore expected output is the row (7) +CALL sp(); +7 +7 +DROP TEMPORARY TABLE v1; +# After the temporary table v1 has been dropped the next invocation of sp() +# accesses the view v1. So, expected output is the row (5) +CALL sp(); +5 +5 +# Clean up +DROP VIEW v1; +DROP PROCEDURE sp; +# Another use case is when a temporary table hides a view is dropped +# inside a stored routine being called. +CREATE VIEW t1 AS SELECT 1; +CREATE PROCEDURE p1() +BEGIN +DROP TEMPORARY TABLE t1; +END +| +CREATE FUNCTION f1() RETURNS INT +BEGIN +CALL p1(); +RETURN 1; +END +| +CREATE TEMPORARY TABLE t1 AS SELECT 1 AS a; +PREPARE stmt FROM 'SELECT f1()'; +EXECUTE stmt; +f1() +1 +# The temporary table t1 has been dropped on first +# execution of the prepared statement 'stmt', +# next time this statement is run it results in issuing +# the error ER_BAD_TABLE_ERROR +EXECUTE stmt; +ERROR 42S02: Unknown table 'test.t1' +# Clean up +DROP VIEW t1; +DROP FUNCTION f1; +DROP PROCEDURE p1; +# # End of 10.4 tests # create function f1() returns int diff --git a/mysql-test/main/temp_table.test b/mysql-test/main/temp_table.test index 11a667435d1..529ce4a6af6 100644 --- a/mysql-test/main/temp_table.test +++ b/mysql-test/main/temp_table.test @@ -669,6 +669,60 @@ SHOW TABLES; DROP TEMPORARY TABLE t1, t2; +--echo # +--echo # MDEV-33218: Assertion `active_arena->is_stmt_prepare_or_first_stmt_execute() || active_arena->state == Query_arena::STMT_SP_QUERY_ARGUMENTS' failed. in st_select_lex::fix_prepare_information +--echo # +CREATE VIEW v1 AS SELECT 5; +CREATE PROCEDURE sp() SELECT * FROM v1; +CREATE TEMPORARY TABLE v1 as SELECT 7; +--echo # sp() accesses the temporary table v1 that hides the view with the same name +--echo # Therefore expected output is the row (7) +CALL sp(); +DROP TEMPORARY TABLE v1; +--echo # After the temporary table v1 has been dropped the next invocation of sp() +--echo # accesses the view v1. So, expected output is the row (5) +CALL sp(); + +--echo # Clean up +DROP VIEW v1; +DROP PROCEDURE sp; + +--echo # Another use case is when a temporary table hides a view is dropped +--echo # inside a stored routine being called. + +CREATE VIEW t1 AS SELECT 1; + +--delimiter | +CREATE PROCEDURE p1() +BEGIN + DROP TEMPORARY TABLE t1; +END +| + +CREATE FUNCTION f1() RETURNS INT +BEGIN + CALL p1(); + RETURN 1; +END +| + +--delimiter ; + +CREATE TEMPORARY TABLE t1 AS SELECT 1 AS a; +PREPARE stmt FROM 'SELECT f1()'; +EXECUTE stmt; +--echo # The temporary table t1 has been dropped on first +--echo # execution of the prepared statement 'stmt', +--echo # next time this statement is run it results in issuing +--echo # the error ER_BAD_TABLE_ERROR +--error ER_BAD_TABLE_ERROR +EXECUTE stmt; + +--echo # Clean up +DROP VIEW t1; +DROP FUNCTION f1; +DROP PROCEDURE p1; + --echo # --echo # End of 10.4 tests --echo # diff --git a/mysql-test/mariadb-test-run.pl b/mysql-test/mariadb-test-run.pl index fb21d48b2f6..5410bbb36e4 100755 --- a/mysql-test/mariadb-test-run.pl +++ b/mysql-test/mariadb-test-run.pl @@ -4550,8 +4550,6 @@ sub extract_warning_lines ($$) { qr/WSREP: Guessing address for incoming client/, qr/InnoDB: Difficult to find free blocks in the buffer pool*/, - # for UBSAN - qr/decimal\.c.*: runtime error: signed integer overflow/, # Disable test for UBSAN on dynamically loaded objects qr/runtime error: member call.*object.*'Handler_share'/, qr/sql_type\.cc.* runtime error: member call.*object.* 'Type_collection'/, diff --git a/mysql-test/suite/galera/include/shutdown_mysqld.inc b/mysql-test/suite/galera/include/shutdown_mysqld.inc deleted file mode 100644 index 793be8d76ac..00000000000 --- a/mysql-test/suite/galera/include/shutdown_mysqld.inc +++ /dev/null @@ -1,18 +0,0 @@ -# This is the first half of include/restart_mysqld.inc. -if ($rpl_inited) -{ - if (!$allow_rpl_inited) - { - --die ERROR IN TEST: When using the replication test framework (master-slave.inc, rpl_init.inc etc), use rpl_restart_server.inc instead of restart_mysqld.inc. If you know what you are doing and you really have to use restart_mysqld.inc, set allow_rpl_inited=1 before you source restart_mysqld.inc - } -} - -# Write file to make mysql-test-run.pl expect the "crash", but don't start it ---let $_expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')` ---let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/$_expect_file_name.expect ---exec echo "wait" > $_expect_file_name - -# Send shutdown to the connected server ---shutdown_server ---source include/wait_until_disconnected.inc - diff --git a/mysql-test/suite/galera/r/MDEV-26499.result b/mysql-test/suite/galera/r/MDEV-26499.result new file mode 100644 index 00000000000..15d372470a4 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-26499.result @@ -0,0 +1,6 @@ +connection node_2; +connection node_1; +connection node_1; +connection node_2; +connection node_2; +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; diff --git a/mysql-test/suite/galera/r/MDEV-27806.result b/mysql-test/suite/galera/r/MDEV-27806.result index 0f7ac79e4cd..6fe288f4e8e 100644 --- a/mysql-test/suite/galera/r/MDEV-27806.result +++ b/mysql-test/suite/galera/r/MDEV-27806.result @@ -37,7 +37,7 @@ mysqld-bin.000002 # Gtid # # BEGIN GTID #-#-# mysqld-bin.000002 # Query # # use `test`; CREATE TABLE `ts1` ( `f1` int(11) NOT NULL ) -mysqld-bin.000002 # Xid # # COMMIT /* XID */ +mysqld-bin.000002 # Query # # COMMIT connection node_2; include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info diff --git a/mysql-test/suite/galera/suite.pm b/mysql-test/suite/galera/suite.pm index d09cb89df5c..4c4d26db4c5 100644 --- a/mysql-test/suite/galera/suite.pm +++ b/mysql-test/suite/galera/suite.pm @@ -1,5 +1,6 @@ package My::Suite::Galera; +use warnings; use lib 'suite'; use wsrep::common; @@ -63,7 +64,7 @@ push @::global_suppressions, qr(WSREP: Failed to remove page file .*), qr(WSREP: wsrep_sst_method is set to 'mysqldump' yet mysqld bind_address is set to .*), qr|WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.|, - qr|WSREP: Send action {.* STATE_REQUEST} returned -107 \(Transport endpoint is not connected\)|, + qr|WSREP: Send action \{.* STATE_REQUEST} returned -107 \(Transport endpoint is not connected\)|, qr|WSREP: Trying to continue unpaused monitor|, qr|WSREP: Wait for gtid returned error 3 while waiting for prior transactions to commit before setting position|, qr|WSREP: Failed to report last committed|, diff --git a/mysql-test/suite/galera/t/MDEV-26499.test b/mysql-test/suite/galera/t/MDEV-26499.test new file mode 100644 index 00000000000..824b28c14f3 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-26499.test @@ -0,0 +1,20 @@ +# +# MDEV-26499 +# +# This test reproduces some failure on mysql_shutdown() call +# which manifests sporadically in some galera MTR tests during +# restart of a node. +# + +--source include/galera_cluster.inc +--source include/have_debug_sync.inc + +--let $node_1=node_1 +--let $node_2=node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 +SET GLOBAL debug_dbug="+d,simulate_slow_client_at_shutdown"; +--source include/restart_mysqld.inc + +--source include/auto_increment_offset_restore.inc diff --git a/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result b/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result new file mode 100644 index 00000000000..a1495f1c138 --- /dev/null +++ b/mysql-test/suite/galera_sr/r/galera_sr_bf_abort_idle.result @@ -0,0 +1,33 @@ +connection node_2; +connection node_1; +connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1; +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); +SET SESSION wsrep_trx_fragment_size=10; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; +connection node_2; +INSERT INTO t1 VALUES (10,2); +connection node_1a; +connection node_1; +INSERT INTO t1 VALUES (9,1); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ROLLBACK; +DROP TABLE t1; +connection node_1; +CREATE TABLE t1(f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); +SET SESSION wsrep_trx_fragment_size=5; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; +connection node_2; +INSERT INTO t1 VALUES (10,2); +connection node_1a; +connection node_1; +INSERT INTO t1 VALUES (9,1); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ROLLBACK; +DROP TABLE t1; diff --git a/mysql-test/suite/galera_sr/t/MDEV-25718.test b/mysql-test/suite/galera_sr/t/MDEV-25718.test index 9aebbdc7c5c..037cd300709 100644 --- a/mysql-test/suite/galera_sr/t/MDEV-25718.test +++ b/mysql-test/suite/galera_sr/t/MDEV-25718.test @@ -43,8 +43,9 @@ SET SESSION wsrep_sync_wait = 0; SET debug_sync = "now SIGNAL write_row_continue"; # Let's give the INSERT some time, to make sure it does rollback ---let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO = "INSERT INTO t1 VALUES (1)" AND STATE = "Freeing items"; ---source include/wait_condition.inc +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE INFO = "INSERT INTO t1 VALUES (1)" AND (STATE = "Freeing items" OR STATE = 'Rollback'); +--let $wait_condition_on_error_output = SELECT INFO, STATE FROM INFORMATION_SCHEMA.PROCESSLIST +--source include/wait_condition_with_debug.inc # Resume the DDL in streaming_rollback SET SESSION debug_sync = "now SIGNAL wsrep_streaming_rollback_continue"; diff --git a/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test b/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test new file mode 100644 index 00000000000..66259b790cc --- /dev/null +++ b/mysql-test/suite/galera_sr/t/galera_sr_bf_abort_idle.test @@ -0,0 +1,68 @@ +# +# Test BF abort for idle SR transactions +# + +--source include/galera_cluster.inc + +--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 + +# +# Case 1: BF abort idle SR transaction that has not yet replicated any fragments +# +--connection node_1 +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); + +--let $bf_count = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.global_status WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'` + +SET SESSION wsrep_trx_fragment_size=10; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; + +--connection node_2 +INSERT INTO t1 VALUES (10,2); + +# Wait for SR transaction to be BF aborted +--connection node_1a +--let $wait_condition = SELECT VARIABLE_VALUE = $bf_count + 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts' +--source include/wait_condition.inc + + +--connection node_1 +--error ER_LOCK_DEADLOCK +INSERT INTO t1 VALUES (9,1); +ROLLBACK; + +DROP TABLE t1; + + +# +# Case 2: BF abort idle SR transaction that has already replicated a fragment +# +--connection node_1 +CREATE TABLE t1(f1 INTEGER PRIMARY KEY, f2 INTEGER); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1); + +--let $bf_count = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.global_status WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts'` + + +SET SESSION wsrep_trx_fragment_size=5; +SET SESSION wsrep_trx_fragment_unit='rows'; +START TRANSACTION; +UPDATE t1 SET f2 = f2 + 10; + +--connection node_2 +INSERT INTO t1 VALUES (10,2); + +# Wait for SR transaction to be BF aborted +--connection node_1a +--let $wait_condition = SELECT VARIABLE_VALUE = $bf_count + 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_bf_aborts' +--source include/wait_condition.inc + +--connection node_1 +--error ER_LOCK_DEADLOCK +INSERT INTO t1 VALUES (9,1); +ROLLBACK; + +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff index 44446602b9f..ad1f3a447c2 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,32k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:29:25.129637040 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 131072 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff index ef55ad971fe..1412df393ff 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,4k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:39.288769153 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 16384 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff index bcdcea31160..156925597ab 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,64k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:30:28.957174270 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,12 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -14,7 +14,7 @@ -# bytes: 65536 +# bytes: 262144 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; --# bytes: 4194304 +-# bytes: 2097152 -DROP TABLE t1; -CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) -ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff index 7b699ef4cea..55cf59737d3 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff +++ b/mysql-test/suite/innodb/r/check_ibd_filesize,8k.rdiff @@ -1,5 +1,5 @@ ---- mysql-test/suite/innodb/r/check_ibd_filesize.result 2022-08-16 17:28:06.462350465 +0530 -+++ mysql-test/suite/innodb/r/check_ibd_filesize.reject 2022-08-16 17:31:03.516962339 +0530 +--- mysql-test/suite/innodb/r/check_ibd_filesize.result ++++ mysql-test/suite/innodb/r/check_ibd_filesize.reject @@ -3,18 +3,18 @@ # SPACE IN 5.7 THAN IN 5.6 # @@ -13,7 +13,7 @@ -# bytes: 65536 +# bytes: 32768 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; - # bytes: 4194304 + # bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/check_ibd_filesize.result b/mysql-test/suite/innodb/r/check_ibd_filesize.result index 0d224d6ac5f..b0f376183ea 100644 --- a/mysql-test/suite/innodb/r/check_ibd_filesize.result +++ b/mysql-test/suite/innodb/r/check_ibd_filesize.result @@ -10,7 +10,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB; # bytes: 65536 INSERT INTO t1 SELECT seq,REPEAT('a',30000) FROM seq_1_to_20; -# bytes: 4194304 +# bytes: 2097152 DROP TABLE t1; CREATE TABLE t1 (a INT PRIMARY KEY, b BLOB) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; diff --git a/mysql-test/suite/innodb/r/cursor-restore-unique-null.result b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result new file mode 100644 index 00000000000..29edc47a483 --- /dev/null +++ b/mysql-test/suite/innodb/r/cursor-restore-unique-null.result @@ -0,0 +1,24 @@ +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) +ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; +connect con1,localhost,root; +BEGIN; +INSERT INTO t SET a=2, c=2; +connection default; +BEGIN; +SET DEBUG_SYNC="lock_wait_start SIGNAL select_locked"; +SELECT * FROM t FORCE INDEX(b) FOR UPDATE; +connection con1; +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; +connection default; +# If the bug is not fixed, and the both unique index key fields are +# NULL, there will be two (1, NULL, 2) rows in the result, +# because cursor will be restored to (NULL, 2, 1) position for +# secondary key instead of "supremum". +a b c +1 NULL 2 +COMMIT; +SET DEBUG_SYNC="RESET"; +disconnect con1; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/r/instant_alter_extend.result b/mysql-test/suite/innodb/r/instant_alter_extend.result index 33a5f57c7b6..c22043eceb1 100644 Binary files a/mysql-test/suite/innodb/r/instant_alter_extend.result and b/mysql-test/suite/innodb/r/instant_alter_extend.result differ diff --git a/mysql-test/suite/innodb/r/instant_alter_import.result b/mysql-test/suite/innodb/r/instant_alter_import.result index e1ef373af06..dc4a6b542a4 100644 --- a/mysql-test/suite/innodb/r/instant_alter_import.result +++ b/mysql-test/suite/innodb/r/instant_alter_import.result @@ -64,6 +64,7 @@ alter table t1 discard tablespace; flush tables t2 for export; unlock tables; alter table t1 import tablespace; +# restart select * from t1; z 42 diff --git a/mysql-test/suite/innodb/r/lock_isolation.result b/mysql-test/suite/innodb/r/lock_isolation.result index eaba6b899a1..31843266617 100644 --- a/mysql-test/suite/innodb/r/lock_isolation.result +++ b/mysql-test/suite/innodb/r/lock_isolation.result @@ -123,7 +123,6 @@ ROLLBACK; connection con_weird; a b 1 NULL -1 NULL SELECT * FROM t FORCE INDEX (b) FOR UPDATE; a b 1 NULL diff --git a/mysql-test/suite/innodb/t/cursor-restore-unique-null.test b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test new file mode 100644 index 00000000000..409694d695b --- /dev/null +++ b/mysql-test/suite/innodb/t/cursor-restore-unique-null.test @@ -0,0 +1,36 @@ +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/count_sessions.inc + + +CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, UNIQUE KEY `b_c` (`b`,`c`)) + ENGINE=InnoDB, STATS_PERSISTENT=0; +INSERT INTO t SET a = 1, c = 2; + +--connect con1,localhost,root +BEGIN; + INSERT INTO t SET a=2, c=2; + +--connection default +BEGIN; +SET DEBUG_SYNC="lock_wait_start SIGNAL select_locked"; +--send SELECT * FROM t FORCE INDEX(b) FOR UPDATE + +--connection con1 +SET DEBUG_SYNC="now WAIT_FOR select_locked"; +ROLLBACK; + +--connection default +--echo # If the bug is not fixed, and the both unique index key fields are +--echo # NULL, there will be two (1, NULL, 2) rows in the result, +--echo # because cursor will be restored to (NULL, 2, 1) position for +--echo # secondary key instead of "supremum". +--reap +COMMIT; + +SET DEBUG_SYNC="RESET"; + +--disconnect con1 +DROP TABLE t; +--source include/wait_until_count_sessions.inc diff --git a/mysql-test/suite/innodb/t/instant_alter_extend.test b/mysql-test/suite/innodb/t/instant_alter_extend.test index 7258ba6d238..636527e598c 100644 --- a/mysql-test/suite/innodb/t/instant_alter_extend.test +++ b/mysql-test/suite/innodb/t/instant_alter_extend.test @@ -256,3 +256,16 @@ select * from t1; check table t1; drop database best; + +--echo # +--echo # MDEV-33214 Table is getting rebuild with +--echo # ALTER TABLE ADD COLUMN +--echo # +use test; +CREATE TABLE t1(f1 INT, f2 VARCHAR(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +INSERT INTO t1 VALUES(1,'abc'),(2,'def'); +ALTER TABLE t1 ADD (f3 VARCHAR(5000), f4 VARCHAR(20)), ALGORITHM=instant; +ALTER TABLE t1 ADD f5 TEXT, ALGORITHM=INSTANT; +DROP TABLE t1; + +--echo # End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test index 87a36186150..f0fab121576 100644 --- a/mysql-test/suite/innodb/t/instant_alter_import.test +++ b/mysql-test/suite/innodb/t/instant_alter_import.test @@ -83,6 +83,7 @@ flush tables t2 for export; unlock tables; alter table t1 import tablespace; +--source include/restart_mysqld.inc select * from t1; --remove_file $MYSQLD_DATADIR/test/t1.ibd diff --git a/mysql-test/suite/multi_source/gtid_ignore_duplicates.result b/mysql-test/suite/multi_source/gtid_ignore_duplicates.result index e142ff8b981..88b525e21ff 100644 --- a/mysql-test/suite/multi_source/gtid_ignore_duplicates.result +++ b/mysql-test/suite/multi_source/gtid_ignore_duplicates.result @@ -174,6 +174,105 @@ a 10 11 12 +*** MDEV-33475: --gtid-ignore-duplicate can double-apply event in case of parallel replication retry +connection server_2; +STOP SLAVE "c2b"; +SET default_master_connection = "c2b"; +include/wait_for_slave_to_stop.inc +STOP SLAVE "a2b"; +SET default_master_connection = "a2b"; +include/wait_for_slave_to_stop.inc +connection server_1; +CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +BEGIN; +INSERT INTO t2 VALUES (0, 0); +INSERT INTO t2 VALUES (1, 0); +INSERT INTO t2 VALUES (2, 0); +INSERT INTO t2 VALUES (3, 0); +INSERT INTO t2 VALUES (4, 0); +INSERT INTO t2 VALUES (5, 0); +INSERT INTO t2 VALUES (6, 0); +INSERT INTO t2 VALUES (7, 0); +INSERT INTO t2 VALUES (8, 0); +INSERT INTO t2 VALUES (9, 0); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (0+10, 100); +UPDATE t2 SET b=0 WHERE a<10; +INSERT INTO t2 VALUES (0+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (1+10, 100); +UPDATE t2 SET b=1 WHERE a<10; +INSERT INTO t2 VALUES (1+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (2+10, 100); +UPDATE t2 SET b=2 WHERE a<10; +INSERT INTO t2 VALUES (2+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (3+10, 100); +UPDATE t2 SET b=3 WHERE a<10; +INSERT INTO t2 VALUES (3+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (4+10, 100); +UPDATE t2 SET b=4 WHERE a<10; +INSERT INTO t2 VALUES (4+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (5+10, 100); +UPDATE t2 SET b=5 WHERE a<10; +INSERT INTO t2 VALUES (5+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (6+10, 100); +UPDATE t2 SET b=6 WHERE a<10; +INSERT INTO t2 VALUES (6+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (7+10, 100); +UPDATE t2 SET b=7 WHERE a<10; +INSERT INTO t2 VALUES (7+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (8+10, 100); +UPDATE t2 SET b=8 WHERE a<10; +INSERT INTO t2 VALUES (8+20, 200); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (9+10, 100); +UPDATE t2 SET b=9 WHERE a<10; +INSERT INTO t2 VALUES (9+20, 200); +COMMIT; +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +include/save_master_gtid.inc +connection server_2; +SET @old_mode= @@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode=aggressive; +SET default_master_connection = "a2b"; +START SLAVE; +include/wait_for_slave_to_start.inc +SET default_master_connection = "c2b"; +START SLAVE; +include/wait_for_slave_to_start.inc +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +connection server_3; +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 +connection server_4; +include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +COUNT(*) SUM(a) SUM(b) +30 435 3090 *** Test also with not using parallel replication. connection server_1; SET default_master_connection = "b2a"; @@ -474,6 +573,7 @@ Warnings: Note 1938 SLAVE 'a2b' stopped Note 1938 SLAVE 'c2b' stopped SET GLOBAL slave_parallel_threads= @old_parallel; +SET GLOBAL slave_parallel_mode= @old_mode; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; connection server_3; SET GLOBAL gtid_domain_id=0; @@ -491,22 +591,22 @@ Note 1938 SLAVE 'a2d' stopped SET GLOBAL slave_parallel_threads= @old_parallel; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; connection server_1; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_1; connection server_2; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_2; connection server_3; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_3; connection server_4; -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; include/reset_master_slave.inc disconnect server_4; diff --git a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test index 3d2d151bd0d..cbc06920b41 100644 --- a/mysql-test/suite/multi_source/gtid_ignore_duplicates.test +++ b/mysql-test/suite/multi_source/gtid_ignore_duplicates.test @@ -173,6 +173,65 @@ SET default_master_connection = "a2b"; SELECT * FROM t1 WHERE a >= 10 ORDER BY a; +--echo *** MDEV-33475: --gtid-ignore-duplicate can double-apply event in case of parallel replication retry + +# Create a bunch of transactions that will cause conflicts and retries. +# The bug was that the retry code was not handling the --gtid-ignore-duplicates +# option, so events could be doubly-applied. + +--connection server_2 +STOP SLAVE "c2b"; +SET default_master_connection = "c2b"; +--source include/wait_for_slave_to_stop.inc +STOP SLAVE "a2b"; +SET default_master_connection = "a2b"; +--source include/wait_for_slave_to_stop.inc + +--connection server_1 +CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +BEGIN; +--let $i= 0 +while ($i < 10) { + eval INSERT INTO t2 VALUES ($i, 0); + inc $i; +} +COMMIT; + +--let $i= 0 +while ($i < 10) { + BEGIN; + eval INSERT INTO t2 VALUES ($i+10, 100); + eval UPDATE t2 SET b=$i WHERE a<10; + eval INSERT INTO t2 VALUES ($i+20, 200); + COMMIT; + inc $i; +} + +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; +--source include/save_master_gtid.inc + +--connection server_2 +SET @old_mode= @@GLOBAL.slave_parallel_mode; +SET GLOBAL slave_parallel_mode=aggressive; +SET default_master_connection = "a2b"; +START SLAVE; +--source include/wait_for_slave_to_start.inc +SET default_master_connection = "c2b"; +START SLAVE; +--source include/wait_for_slave_to_start.inc + +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + +--connection server_3 +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + +--connection server_4 +--source include/sync_with_master_gtid.inc +SELECT COUNT(*), SUM(a), SUM(b) FROM t2; + + --echo *** Test also with not using parallel replication. --connection server_1 @@ -414,6 +473,7 @@ SET GLOBAL gtid_domain_id=0; --sorted_result STOP ALL SLAVES; SET GLOBAL slave_parallel_threads= @old_parallel; +SET GLOBAL slave_parallel_mode= @old_mode; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; --connection server_3 @@ -431,25 +491,25 @@ SET GLOBAL slave_parallel_threads= @old_parallel; SET GLOBAL gtid_ignore_duplicates= @old_ignore_duplicates; --connection server_1 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_1 --connection server_2 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_2 --connection server_3 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_3 --connection server_4 -DROP TABLE t1; +DROP TABLE t1, t2; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; --source include/reset_master_slave.inc --disconnect server_4 diff --git a/mysql-test/suite/parts/r/mdev_21007.result b/mysql-test/suite/parts/r/mdev_21007.result new file mode 100644 index 00000000000..fb2417ac3ae --- /dev/null +++ b/mysql-test/suite/parts/r/mdev_21007.result @@ -0,0 +1,5 @@ +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/t/mdev_21007.test b/mysql-test/suite/parts/t/mdev_21007.test new file mode 100644 index 00000000000..ec6fbe4d108 --- /dev/null +++ b/mysql-test/suite/parts/t/mdev_21007.test @@ -0,0 +1,9 @@ +--source include/have_partition.inc + +CREATE TABLE t1 (a INT) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (1), PARTITION p1 VALUES LESS THAN (MAXVALUE)); +INSERT INTO t1 VALUES (1),(2); +ALTER TABLE t1 MODIFY a INT AUTO_INCREMENT PRIMARY KEY; +UPDATE t1 PARTITION (p1) SET a=9 ORDER BY a LIMIT 1; + +# Cleanup +DROP TABLE t1; diff --git a/mysql-test/suite/rpl/r/parallel_backup.result b/mysql-test/suite/rpl/r/parallel_backup.result index 83c7a916c13..361838927e9 100644 --- a/mysql-test/suite/rpl/r/parallel_backup.result +++ b/mysql-test/suite/rpl/r/parallel_backup.result @@ -125,7 +125,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -168,7 +168,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result b/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result index e1fd7701fcc..08955a77291 100644 --- a/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result +++ b/mysql-test/suite/rpl/r/parallel_backup_lsu_off.result @@ -128,7 +128,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -171,7 +171,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result b/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result index 9e29e5a3875..bb00bf9cbf5 100644 --- a/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result +++ b/mysql-test/suite/rpl/r/parallel_backup_slave_binlog_off.result @@ -128,7 +128,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; @@ -171,7 +171,7 @@ include/save_master_gtid.inc connection slave; SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; -SET @@global.innodb_lock_wait_timeout =1; +SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; include/start_slave.inc connection aux_slave; diff --git a/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result b/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result index f6eff3f9efc..948b4f48737 100644 --- a/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result +++ b/mysql-test/suite/rpl/r/rpl_domain_id_filter_restart.result @@ -21,8 +21,9 @@ INSERT INTO t2 VALUES(1); SELECT * FROM t2; i 1 +include/save_master_gtid.inc connection slave; -connection slave; +include/sync_with_master_gtid.inc SELECT * FROM t1; i 1 diff --git a/mysql-test/suite/rpl/t/parallel_backup_xa.inc b/mysql-test/suite/rpl/t/parallel_backup_xa.inc index 83a6fb79345..5f287aa0ca6 100644 --- a/mysql-test/suite/rpl/t/parallel_backup_xa.inc +++ b/mysql-test/suite/rpl/t/parallel_backup_xa.inc @@ -41,7 +41,7 @@ if ($slave_ooo_error) { SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout; SET @sav_slave_transaction_retries = @@global.slave_transaction_retries; - SET @@global.innodb_lock_wait_timeout =1; + SET @@global.innodb_lock_wait_timeout =5; SET @@global.slave_transaction_retries=0; } --source include/start_slave.inc diff --git a/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test b/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test index 8083b8f232f..38cbbdec7f3 100644 --- a/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test +++ b/mysql-test/suite/rpl/t/rpl_domain_id_filter_restart.test @@ -35,9 +35,10 @@ SET @@session.gtid_domain_id= 1; INSERT INTO t2 VALUES(1); SELECT * FROM t2; -sync_slave_with_master; +source include/save_master_gtid.inc; connection slave; +source include/sync_with_master_gtid.inc; SELECT * FROM t1; SELECT * FROM t2; diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 7abffebda91..f8fcf075b78 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -133,7 +133,7 @@ double getopt_ulonglong2double(ulonglong v) return u.dbl; } -#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); continue; } +#define SET_HO_ERROR_AND_CONTINUE(e) { ho_error= (e); (*argc)--; continue; } /** Handle command line options. @@ -864,7 +864,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, } if (err) { - res= EXIT_UNKNOWN_SUFFIX; + res= err; goto ret; }; } @@ -998,7 +998,7 @@ static inline ulonglong eval_num_suffix(char *suffix, int *error) case 'E': return 1ULL << 60; default: - *error= 1; + *error= EXIT_UNKNOWN_SUFFIX; return 0ULL; } } @@ -1024,15 +1024,18 @@ static longlong eval_num_suffix_ll(char *argument, if (errno == ERANGE) { my_getopt_error_reporter(ERROR_LEVEL, - "Incorrect integer value: '%s'", argument); - *error= 1; + "Integer value out of range for int64:" + " '%s' for %s", + argument, option_name); + *error= EXIT_ARGUMENT_INVALID; DBUG_RETURN(0); } num*= eval_num_suffix(endchar, error); if (*error) - fprintf(stderr, - "Unknown suffix '%c' used for variable '%s' (value '%s')\n", - *endchar, option_name, argument); + my_getopt_error_reporter(ERROR_LEVEL, + "Unknown suffix '%c' used for variable '%s' (value '%s'). " + "Legal suffix characters are: K, M, G, T, P, E", + *endchar, option_name, argument); DBUG_RETURN(num); } @@ -1055,7 +1058,7 @@ static ulonglong eval_num_suffix_ull(char *argument, my_getopt_error_reporter(ERROR_LEVEL, "Incorrect unsigned value: '%s' for %s", argument, option_name); - *error= 1; + *error= EXIT_ARGUMENT_INVALID; DBUG_RETURN(0); } *error= 0; @@ -1064,15 +1067,18 @@ static ulonglong eval_num_suffix_ull(char *argument, if (errno == ERANGE) { my_getopt_error_reporter(ERROR_LEVEL, - "Incorrect integer value: '%s' for %s", + "Integer value out of range for uint64:" + " '%s' for %s", argument, option_name); - *error= 1; + *error= EXIT_ARGUMENT_INVALID; DBUG_RETURN(0); } num*= eval_num_suffix(endchar, error); if (*error) my_getopt_error_reporter(ERROR_LEVEL, - "Unknown suffix '%c' used for variable '%s' (value '%s')", + "Unknown suffix '%c' used for variable '%s'" + " (value '%s')." + " Legal suffix characters are: K, M, G, T, P, E", *endchar, option_name, argument); DBUG_RETURN(num); } @@ -1092,6 +1098,8 @@ static ulonglong eval_num_suffix_ull(char *argument, static longlong getopt_ll(char *arg, const struct my_option *optp, int *err) { longlong num=eval_num_suffix_ll(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ll_limit_value(num, optp, NULL); } @@ -1169,6 +1177,8 @@ longlong getopt_ll_limit_value(longlong num, const struct my_option *optp, static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err) { ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name); + if (*err) + return(0); return getopt_ull_limit_value(num, optp, NULL); } diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index ba4850f4cba..845e40ccf52 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -339,6 +339,10 @@ static int free(void *p) shutdown_plugin= true; mysql_cond_signal(&sleep_condition); mysql_mutex_unlock(&sleep_mutex); + + for (uint i= 0; i < url_count; i++) + urls[i]->abort(); + pthread_join(sender_thread, NULL); mysql_mutex_destroy(&sleep_mutex); diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index 04fe1ab6aa1..6021eb85860 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -52,6 +52,7 @@ class Url { const char *url() { return full_url.str; } size_t url_length() { return full_url.length; } + virtual void abort() = 0; virtual int send(const char* data, size_t data_length) = 0; virtual int set_proxy(const char *proxy, size_t proxy_len) { diff --git a/plugin/feedback/url_http.cc b/plugin/feedback/url_http.cc index 98116dd04f1..590bb06cc5f 100644 --- a/plugin/feedback/url_http.cc +++ b/plugin/feedback/url_http.cc @@ -37,8 +37,9 @@ static const uint FOR_WRITING= 1; class Url_http: public Url { protected: const LEX_STRING host, port, path; - bool ssl; LEX_STRING proxy_host, proxy_port; + my_socket fd; + bool ssl; bool use_proxy() { @@ -47,7 +48,8 @@ class Url_http: public Url { Url_http(LEX_STRING &url_arg, LEX_STRING &host_arg, LEX_STRING &port_arg, LEX_STRING &path_arg, bool ssl_arg) : - Url(url_arg), host(host_arg), port(port_arg), path(path_arg), ssl(ssl_arg) + Url(url_arg), host(host_arg), port(port_arg), path(path_arg), + fd(INVALID_SOCKET), ssl(ssl_arg) { proxy_host.length= 0; } @@ -60,6 +62,7 @@ class Url_http: public Url { } public: + void abort(); int send(const char* data, size_t data_length); int set_proxy(const char *proxy, size_t proxy_len) { @@ -158,13 +161,18 @@ Url* http_create(const char *url, size_t url_length) return new Url_http(full_url, host, port, path, ssl); } +void Url_http::abort() +{ + if (fd != INVALID_SOCKET) + closesocket(fd); // interrupt I/O waits +} + /* do the vio_write and check that all data were sent ok */ #define write_check(VIO, DATA, LEN) \ (vio_write((VIO), (uchar*)(DATA), (LEN)) != (LEN)) int Url_http::send(const char* data, size_t data_length) { - my_socket fd= INVALID_SOCKET; char buf[1024]; size_t len= 0; @@ -180,6 +188,7 @@ int Url_http::send(const char* data, size_t data_length) return 1; } + DBUG_ASSERT(fd == INVALID_SOCKET); for (addr= addrs; addr != NULL; addr= addr->ai_next) { fd= socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); @@ -208,6 +217,7 @@ int Url_http::send(const char* data, size_t data_length) sql_print_error("feedback plugin: vio_new failed for url '%s'", full_url.str); closesocket(fd); + fd= INVALID_SOCKET; return 1; } @@ -236,6 +246,7 @@ int Url_http::send(const char* data, size_t data_length) free_vio_ssl_acceptor_fd(ssl_fd); closesocket(fd); vio_delete(vio); + fd= INVALID_SOCKET; return 1; } } @@ -334,6 +345,7 @@ int Url_http::send(const char* data, size_t data_length) } #endif + fd= INVALID_SOCKET; return res; } diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.result b/plugin/type_inet/mysql-test/type_inet/type_inet6.result index 38af2c16076..c8719b38fd1 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6.result +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.result @@ -2358,3 +2358,14 @@ Warning 1292 Incorrect inet6 value: '' Warning 1292 Incorrect inet6 value: '' Warning 1292 Incorrect inet6 value: '' DROP TABLE t1; +# +# MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6 +# +CREATE TABLE t1 (c CHAR(3)); +INSERT INTO t1 VALUES ('1:0'),('00:'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +c +Warnings: +Warning 1292 Incorrect inet6 value: '1:0' +Warning 1292 Incorrect inet6 value: '00:' +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.test b/plugin/type_inet/mysql-test/type_inet/type_inet6.test index 32638573825..508fa73c8ef 100644 --- a/plugin/type_inet/mysql-test/type_inet/type_inet6.test +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.test @@ -1701,3 +1701,13 @@ SELECT 1.00 + (b = a) AS f FROM t1 ORDER BY f; SELECT 1.00 + (b BETWEEN a AND '') AS f FROM t1 ORDER BY f; SELECT 1.00 + (b IN (a,'')) AS f FROM t1 ORDER BY f; DROP TABLE t1; + + +--echo # +--echo # MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6 +--echo # + +CREATE TABLE t1 (c CHAR(3)); +INSERT INTO t1 VALUES ('1:0'),('00:'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +DROP TABLE t1; diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index b8d2ef706a9..0596e11a3d8 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -229,7 +229,7 @@ bool Inet6::ascii_to_fbt(const char *str, size_t str_length) continue; } - if (!*p || p >= str_end) + if (p >= str_end || !*p) { DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " "ending at ':'.", (int) str_length, str)); diff --git a/plugin/versioning/versioning.cc b/plugin/versioning/versioning.cc index 38ebf76256b..a4916e2f9c1 100644 --- a/plugin/versioning/versioning.cc +++ b/plugin/versioning/versioning.cc @@ -36,8 +36,8 @@ public: static Create_func_trt s_singleton; protected: - Create_func_trt() = default; - virtual ~Create_func_trt() = default; + Create_func_trt() = default; + virtual ~Create_func_trt() = default; }; template @@ -132,8 +132,8 @@ public: static Create_func_trt_trx_sees s_singleton; protected: - Create_func_trt_trx_sees() = default; - virtual ~Create_func_trt_trx_sees() = default; + Create_func_trt_trx_sees() = default; + virtual ~Create_func_trt_trx_sees() = default; }; template diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 4a0762b01bb..e9680a83b94 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -693,6 +693,7 @@ int ha_partition::create_partitioning_metadata(const char *path, partition_element *part; DBUG_ENTER("ha_partition::create_partitioning_metadata"); + mark_trx_read_write(); /* We need to update total number of parts since we might write the handler file as part of a partition management command @@ -8636,7 +8637,7 @@ int ha_partition::info(uint flag) file->stats.auto_increment_value); } while (*(++file_array)); - DBUG_ASSERT(auto_increment_value); + DBUG_ASSERT(!all_parts_opened || auto_increment_value); stats.auto_increment_value= auto_increment_value; if (all_parts_opened && auto_inc_is_first_in_idx) { diff --git a/sql/handler.cc b/sql/handler.cc index adacdb18839..b1a92cca7ea 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5596,8 +5596,6 @@ handler::ha_create_partitioning_metadata(const char *name, DBUG_ASSERT(m_lock_type == F_UNLCK || (!old_name && strcmp(name, table_share->path.str))); - - mark_trx_read_write(); return create_partitioning_metadata(name, old_name, action_flag); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index a2b7efb8ce8..cc944e0c08a 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1411,7 +1411,13 @@ bool Item_in_optimizer::fix_left(THD *thd) eval_not_null_tables(NULL); with_flags|= (args[0]->with_flags | (args[1]->with_flags & item_with_t::SP_VAR)); - if ((const_item_cache= args[0]->const_item())) + + /* + If left expression is a constant, cache its value. + But don't do that if that involves computing a subquery, as we are in a + prepare-phase rewrite. + */ + if ((const_item_cache= args[0]->const_item()) && !args[0]->with_subquery()) { cache->store(args[0]); cache->cache_value(); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index f393635d1e4..5a1dc876212 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -3529,13 +3529,11 @@ template class LI, typename T> class Item_equal_iterator { protected: Item_equal *item_equal; - Item *curr_item; + Item *curr_item= nullptr; public: - Item_equal_iterator(Item_equal &item_eq) - :LI (item_eq.equal_items) + Item_equal_iterator(Item_equal &item_eq) + :LI (item_eq.equal_items), item_equal(&item_eq) { - curr_item= NULL; - item_equal= &item_eq; if (item_eq.with_const) { LI *list_it= this; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index e8766c3c3c2..75152522770 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1377,15 +1377,16 @@ String *Item_func_regexp_replace::val_str_internal(String *str, LEX_CSTRING src, rpl; size_t startoffset= 0; - if ((null_value= - (!(source= args[0]->val_str(&tmp0)) || - !(replace= args[2]->val_str_null_to_empty(&tmp2, null_to_empty)) || - re.recompile(args[1])))) - return (String *) 0; - + source= args[0]->val_str(&tmp0); + if (!source) + goto err; + replace= args[2]->val_str_null_to_empty(&tmp2, null_to_empty); + if (!replace || re.recompile(args[1])) + goto err; if (!(source= re.convert_if_needed(source, &re.subject_converter)) || !(replace= re.convert_if_needed(replace, &re.replace_converter))) goto err; + null_value= false; source->get_value(&src); replace->get_value(&rpl); @@ -1431,7 +1432,7 @@ String *Item_func_regexp_replace::val_str_internal(String *str, err: null_value= true; - return (String *) 0; + return nullptr; } @@ -1567,13 +1568,21 @@ bool Item_func_insert::fix_length_and_dec() String *Item_str_conv::val_str(String *str) { DBUG_ASSERT(fixed()); - String *res; - size_t alloced_length, len; + String *res= args[0]->val_str(&tmp_value); - if ((null_value= (!(res= args[0]->val_str(&tmp_value)) || - str->alloc((alloced_length= res->length() * multiply))))) - return 0; + if (!res) + { + err: + null_value= true; + return nullptr; + } + size_t alloced_length= res->length() * multiply, len; + + if (str->alloc((alloced_length))) + goto err; + + null_value= false; len= converter(collation.collation, (char*) res->ptr(), res->length(), (char*) str->ptr(), alloced_length); DBUG_ASSERT(len <= alloced_length); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 99b31530d7d..75b9ac6cbe9 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -568,6 +568,9 @@ void Item_subselect::recalc_used_tables(st_select_lex *new_parent, This measure is used instead of JOIN::read_time, because it is considered to be much more reliable than the cost estimate. + Note: the logic in this function must agree with + JOIN::init_join_cache_and_keyread(). + @return true if the subquery is expensive @return false otherwise */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b5cec519574..0d2f1bd0309 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4013,8 +4013,9 @@ static int init_common_variables() SQLCOM_END + 10); #endif - if (get_options(&remaining_argc, &remaining_argv)) - exit(1); + int opt_err; + if ((opt_err= get_options(&remaining_argc, &remaining_argv))) + exit(opt_err); if (IS_SYSVAR_AUTOSIZE(&server_version_ptr)) set_server_version(server_version, sizeof(server_version)); diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index fdc960a8fc6..3dff9bf8ade 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -212,6 +212,13 @@ finish_event_group(rpl_parallel_thread *rpt, uint64 sub_id, signal_error_to_sql_driver_thread(thd, rgi, err); thd->wait_for_commit_ptr= NULL; + /* + Calls to check_duplicate_gtid() must match up with + record_and_update_gtid() (or release_domain_owner() in error case). This + assertion tries to catch any missing release of the domain. + */ + DBUG_ASSERT(rgi->gtid_ignore_duplicate_state != rpl_group_info::GTID_DUPLICATE_OWNER); + mysql_mutex_lock(&entry->LOCK_parallel_entry); /* We need to mark that this event group started its commit phase, in case we @@ -875,7 +882,13 @@ do_retry: }); #endif - rgi->cleanup_context(thd, 1); + /* + We are still applying the event group, even though we will roll it back + and retry it. So for --gtid-ignore-duplicates, keep ownership of the + domain during the retry so another master connection will not try to take + over and duplicate apply the same event group (MDEV-33475). + */ + rgi->cleanup_context(thd, 1, 1 /* keep_domain_owner */); wait_for_pending_deadlock_kill(thd, rgi); thd->reset_killed(); thd->clear_error(); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 845f14c3c28..1bf9505134f 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -2253,7 +2253,7 @@ delete_or_keep_event_post_apply(rpl_group_info *rgi, } -void rpl_group_info::cleanup_context(THD *thd, bool error) +void rpl_group_info::cleanup_context(THD *thd, bool error, bool keep_domain_owner) { DBUG_ENTER("rpl_group_info::cleanup_context"); DBUG_PRINT("enter", ("error: %d", (int) error)); @@ -2308,7 +2308,7 @@ void rpl_group_info::cleanup_context(THD *thd, bool error) Ensure we always release the domain for others to process, when using --gtid-ignore-duplicates. */ - if (gtid_ignore_duplicate_state != GTID_DUPLICATE_NULL) + if (gtid_ignore_duplicate_state != GTID_DUPLICATE_NULL && !keep_domain_owner) rpl_global_gtid_slave_state->release_domain_owner(this); } diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index 151317930c3..bad6eb60b83 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -922,7 +922,7 @@ struct rpl_group_info } void clear_tables_to_lock(); - void cleanup_context(THD *, bool); + void cleanup_context(THD *, bool, bool keep_domain_owner= false); void slave_close_thread_tables(THD *); void mark_start_commit_no_lock(); void mark_start_commit(); diff --git a/sql/sp.cc b/sql/sp.cc index 4907bf521f0..72c7fd180ee 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1946,7 +1946,7 @@ Sp_handler::sp_show_create_routine(THD *thd, DBUG_EXECUTE_IF("cache_sp_in_show_create", /* Some tests need just need a way to cache SP without other side-effects.*/ - sp_cache_routine(thd, name, false, &sp); + sp_cache_routine(thd, name, &sp); sp->show_create_routine(thd, this); DBUG_RETURN(false); ); @@ -2370,7 +2370,7 @@ Sp_handler::sp_cache_routine_reentrant(THD *thd, int ret; Parser_state *oldps= thd->m_parser_state; thd->m_parser_state= NULL; - ret= sp_cache_routine(thd, name, false, sp); + ret= sp_cache_routine(thd, name, sp); thd->m_parser_state= oldps; return ret; } @@ -2777,7 +2777,6 @@ void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx, */ int Sroutine_hash_entry::sp_cache_routine(THD *thd, - bool lookup_only, sp_head **sp) const { char qname_buff[NAME_LEN*2+1+1]; @@ -2790,7 +2789,7 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, */ DBUG_ASSERT(mdl_request.ticket || this == thd->lex->sroutines_list.first); - return m_handler->sp_cache_routine(thd, &name, lookup_only, sp); + return m_handler->sp_cache_routine(thd, &name, sp); } @@ -2802,9 +2801,6 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, @param[in] thd Thread context. @param[in] name Name of routine. - @param[in] lookup_only Only check that the routine is in the cache. - If it's not, don't try to load. If it is present, - but old, don't try to reload. @param[out] sp Pointer to sp_head object for routine, NULL if routine was not found. @@ -2815,7 +2811,6 @@ int Sroutine_hash_entry::sp_cache_routine(THD *thd, int Sp_handler::sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const { int ret= 0; @@ -2827,9 +2822,6 @@ int Sp_handler::sp_cache_routine(THD *thd, *sp= sp_cache_lookup(spc, name); - if (lookup_only) - DBUG_RETURN(SP_OK); - if (*sp) { sp_cache_flush_obsolete(spc, sp); @@ -2881,7 +2873,6 @@ int Sp_handler::sp_cache_routine(THD *thd, * name->m_db is a database name, e.g. "dbname" * name->m_name is a package-qualified name, e.g. "pkgname.spname" - @param lookup_only - don't load mysql.proc if not cached @param [OUT] sp - the result is returned here. @retval false - loaded or does not exists @retval true - error while loading mysql.proc @@ -2891,14 +2882,13 @@ int Sp_handler::sp_cache_package_routine(THD *thd, const LEX_CSTRING &pkgname_cstr, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { DBUG_ENTER("sp_cache_package_routine"); DBUG_ASSERT(type() == SP_TYPE_FUNCTION || type() == SP_TYPE_PROCEDURE); sp_name pkgname(&name->m_db, &pkgname_cstr, false); sp_head *ph= NULL; int ret= sp_handler_package_body.sp_cache_routine(thd, &pkgname, - lookup_only, &ph); if (!ret) { @@ -2933,12 +2923,12 @@ Sp_handler::sp_cache_package_routine(THD *thd, int Sp_handler::sp_cache_package_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { DBUG_ENTER("Sp_handler::sp_cache_package_routine"); Prefix_name_buf pkgname(thd, name->m_name); DBUG_ASSERT(pkgname.length); - DBUG_RETURN(sp_cache_package_routine(thd, pkgname, name, lookup_only, sp)); + DBUG_RETURN(sp_cache_package_routine(thd, pkgname, name, sp)); } diff --git a/sql/sp.h b/sql/sp.h index c73ff2877b0..698b576e40e 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -102,10 +102,10 @@ protected: int sp_cache_package_routine(THD *thd, const LEX_CSTRING &pkgname_cstr, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; int sp_cache_package_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; sp_head *sp_find_package_routine(THD *thd, const LEX_CSTRING pkgname_str, const Database_qualified_name *name, @@ -202,7 +202,7 @@ public: const Database_qualified_name *name, bool cache_only) const; virtual int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const; + sp_head **sp) const; int sp_cache_routine_reentrant(THD *thd, const Database_qualified_name *nm, @@ -283,9 +283,9 @@ class Sp_handler_package_procedure: public Sp_handler_procedure { public: int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { - return sp_cache_package_routine(thd, name, lookup_only, sp); + return sp_cache_package_routine(thd, name, sp); } sp_head *sp_find_routine(THD *thd, const Database_qualified_name *name, @@ -332,9 +332,9 @@ class Sp_handler_package_function: public Sp_handler_function { public: int sp_cache_routine(THD *thd, const Database_qualified_name *name, - bool lookup_only, sp_head **sp) const + sp_head **sp) const { - return sp_cache_package_routine(thd, name, lookup_only, sp); + return sp_cache_package_routine(thd, name, sp); } sp_head *sp_find_routine(THD *thd, const Database_qualified_name *name, @@ -632,7 +632,7 @@ public: const Sp_handler *m_handler; - int sp_cache_routine(THD *thd, bool lookup_only, sp_head **sp) const; + int sp_cache_routine(THD *thd, sp_head **sp) const; }; diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index 1da807e9d59..f67ef4218af 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -78,6 +78,8 @@ private: /* All routines in this cache */ HASH m_hashtable; +public: + void clear(); }; // class sp_cache #ifdef HAVE_PSI_INTERFACE @@ -313,6 +315,10 @@ sp_cache::cleanup() my_hash_free(&m_hashtable); } +void sp_cache::clear() +{ + my_hash_reset(&m_hashtable); +} void Sp_caches::sp_caches_clear() { @@ -321,3 +327,15 @@ void Sp_caches::sp_caches_clear() sp_cache_clear(&sp_package_spec_cache); sp_cache_clear(&sp_package_body_cache); } + +void Sp_caches::sp_caches_empty() +{ + if (sp_proc_cache) + sp_proc_cache->clear(); + if (sp_func_cache) + sp_func_cache->clear(); + if (sp_package_spec_cache) + sp_package_spec_cache->clear(); + if (sp_package_body_cache) + sp_package_body_cache->clear(); +} diff --git a/sql/sp_head.cc b/sql/sp_head.cc index c95761309a7..094dd026aae 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3784,6 +3784,9 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) thd->update_stats(); thd->lex->sql_command= save_sql_command; *nextp= m_ip+1; +#ifdef PROTECT_STATEMENT_MEMROOT + mark_as_qc_used(); +#endif } thd->set_query(query_backup); thd->query_name_consts= 0; diff --git a/sql/sp_head.h b/sql/sp_head.h index c0ed2b52edb..e07c83f4359 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -1126,7 +1126,7 @@ public: sp_instr(uint ip, sp_pcontext *ctx) :Query_arena(0, STMT_INITIALIZED_FOR_SP), marked(0), m_ip(ip), m_ctx(ctx) #ifdef PROTECT_STATEMENT_MEMROOT - , m_has_been_run(false) + , m_has_been_run(NON_RUN) #endif {} @@ -1221,21 +1221,29 @@ public: #ifdef PROTECT_STATEMENT_MEMROOT bool has_been_run() const { - return m_has_been_run; + return m_has_been_run == RUN; + } + + void mark_as_qc_used() + { + m_has_been_run= QC; } void mark_as_run() { - m_has_been_run= true; + if (m_has_been_run == QC) + m_has_been_run= NON_RUN; // answer was from WC => not really executed + else + m_has_been_run= RUN; } void mark_as_not_run() { - m_has_been_run= false; + m_has_been_run= NON_RUN; } private: - bool m_has_been_run; + enum {NON_RUN, QC, RUN} m_has_been_run; #endif }; // class sp_instr : public Sql_alloc diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 7c09c5ac41c..2f48fa35424 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3511,7 +3511,7 @@ open_and_process_routine(THD *thd, Query_tables_list *prelocking_ctx, DBUG_RETURN(TRUE); /* Ensures the routine is up-to-date and cached, if exists. */ - if (rt->sp_cache_routine(thd, has_prelocking_list, &sp)) + if (rt->sp_cache_routine(thd, &sp)) DBUG_RETURN(TRUE); /* Remember the version of the routine in the parse tree. */ @@ -3552,7 +3552,7 @@ open_and_process_routine(THD *thd, Query_tables_list *prelocking_ctx, Validating routine version is unnecessary, since CALL does not affect the prepared statement prelocked list. */ - if (rt->sp_cache_routine(thd, false, &sp)) + if (rt->sp_cache_routine(thd, &sp)) DBUG_RETURN(TRUE); } } @@ -5578,13 +5578,23 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, uint flags) } } - DEBUG_SYNC(thd, "before_lock_tables_takes_lock"); +#ifdef ENABLED_DEBUG_SYNC + if (!tables || + !(strcmp(tables->db.str, "mysql") == 0 && + strcmp(tables->table_name.str, "proc") == 0)) + DEBUG_SYNC(thd, "before_lock_tables_takes_lock"); +#endif if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start), flags))) DBUG_RETURN(TRUE); - DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); +#ifdef ENABLED_DEBUG_SYNC + if (!tables || + !(strcmp(tables->db.str, "mysql") == 0 && + strcmp(tables->table_name.str, "proc") == 0)) + DEBUG_SYNC(thd, "after_lock_tables_takes_lock"); +#endif if (thd->lex->requires_prelocking() && thd->lex->sql_command != SQLCOM_LOCK_TABLES && diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6cabd7fbabd..9536d4b16aa 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -896,6 +896,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) prepare_derived_at_open= FALSE; create_tmp_table_for_derived= FALSE; save_prep_leaf_list= FALSE; + reset_sp_cache= false; org_charset= 0; /* Restore THR_THD */ set_current_thd(old_THR_THD); diff --git a/sql/sql_class.h b/sql/sql_class.h index a9b36f9dfb1..d49f550cd1a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1,5 +1,4 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. Copyright (c) 2009, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify @@ -2485,6 +2484,11 @@ public: swap_variables(sp_cache*, sp_package_body_cache, rhs.sp_package_body_cache); } void sp_caches_clear(); + /** + Clear content of sp related caches. + Don't delete cache objects itself. + */ + void sp_caches_empty(); }; @@ -2975,6 +2979,12 @@ public: bool save_prep_leaf_list; + /** + The data member reset_sp_cache is to signal that content of sp_cache + must be reset (all items be removed from it). + */ + bool reset_sp_cache; + /* container for handler's private per-connection data */ Ha_data ha_data[MAX_HA]; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index f8ac6516a00..2ee6317123b 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -1590,6 +1590,7 @@ bool JOIN_CACHE::put_record() { bool is_full; uchar *link= 0; + DBUG_ASSERT(!for_explain_only); if (prev_cache) link= prev_cache->get_curr_rec_link(); write_record_data(link, &is_full); diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index 5cd66d8047a..b3d95c9ed31 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -26,7 +26,11 @@ #include "sql_manager.h" #include "sql_base.h" // flush_tables -static bool volatile manager_thread_in_use = 0; +/* + Values for manager_thread_in_use: 0 means "not started". 1 means "started + and active". 2 means "stopped". +*/ +static int volatile manager_thread_in_use = 0; static bool abort_manager = false; pthread_t manager_thread; @@ -44,7 +48,7 @@ static struct handler_cb *cb_list; // protected by LOCK_manager bool mysql_manager_submit(void (*action)(void *), void *data) { bool result= FALSE; - DBUG_ASSERT(manager_thread_in_use); + DBUG_ASSERT(manager_thread_in_use == 1); struct handler_cb **cb; mysql_mutex_lock(&LOCK_manager); cb= &cb_list; @@ -119,7 +123,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) mysql_mutex_lock(&LOCK_manager); } DBUG_ASSERT(cb_list == NULL); - manager_thread_in_use = 0; + manager_thread_in_use = 2; mysql_mutex_unlock(&LOCK_manager); mysql_mutex_destroy(&LOCK_manager); mysql_cond_destroy(&COND_manager); @@ -148,6 +152,15 @@ void start_handle_manager() } mysql_mutex_lock(&LOCK_manager); + /* + Wait for manager thread to have started, otherwise in extreme cases the + server may start up and have initiated shutdown at the time the manager + thread even starts to run. + + Allow both values 1 and 2 for manager_thread_in_use, so that we will not + get stuck here if the manager thread somehow manages to start up and + abort again before we have time to test it here. + */ while (!manager_thread_in_use) mysql_cond_wait(&COND_manager, &LOCK_manager); mysql_mutex_unlock(&LOCK_manager); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 60b4fed9fb3..eb1997b3524 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2252,6 +2252,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD * my_eof(thd); kill_mysql(thd); error=TRUE; + DBUG_EXECUTE_IF("simulate_slow_client_at_shutdown", my_sleep(2000000);); break; } #endif @@ -2409,6 +2410,11 @@ resume: } #endif /* WITH_WSREP */ + if (thd->reset_sp_cache) + { + thd->sp_caches_empty(); + thd->reset_sp_cache= false; + } if (do_end_of_statement) { @@ -2485,6 +2491,7 @@ resume: MYSQL_COMMAND_DONE(res); } DEBUG_SYNC(thd,"dispatch_command_end"); + DEBUG_SYNC(thd,"dispatch_command_end2"); /* Check that some variables are reset properly */ DBUG_ASSERT(thd->abort_on_warning == 0); @@ -5883,7 +5890,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt) if (sph->sp_resolve_package_routine(thd, thd->lex->sphead, lex->spname, &sph, &pkgname)) return true; - if (sph->sp_cache_routine(thd, lex->spname, false, &sp)) + if (sph->sp_cache_routine(thd, lex->spname, &sp)) goto error; if (!sp || sp->show_routine_code(thd)) { diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 9fed661ea7e..2cc2ab6f5e1 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -4263,7 +4263,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, if (unlikely(error)) { - sql_print_error("Parsing options for plugin '%s' failed.", + sql_print_error("Parsing options for plugin '%s' failed. Disabling plugin", tmp->name.str); goto err; } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 1ac6db00a15..6cfb10f6bee 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -221,7 +221,7 @@ static int fake_rotate_event(binlog_send_info *info, ulonglong position, char* p = info->log_file_name+dirname_length(info->log_file_name); uint ident_len = (uint) strlen(p); String *packet= info->packet; - ha_checksum crc; + ha_checksum crc= 0; /* reset transmit packet for the fake rotate event below */ if (reset_transmit_packet(info, info->flags, &ev_offset, &info->errmsg)) @@ -262,7 +262,7 @@ static int fake_gtid_list_event(binlog_send_info *info, { my_bool do_checksum; int err; - ha_checksum crc; + ha_checksum crc= 0; char buf[128]; String str(buf, sizeof(buf), system_charset_info); String* packet= info->packet; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index dfe8214c0a9..219ab8c91d8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3568,7 +3568,7 @@ bool JOIN::make_aggr_tables_info() distinct in the engine, so we do this for all queries, not only GROUP BY queries. */ - if (tables_list && top_join_tab_count && !procedure) + if (tables_list && top_join_tab_count && !only_const_tables() && !procedure) { /* At the moment we only support push down for queries where @@ -31424,7 +31424,26 @@ void JOIN::init_join_cache_and_keyread() if (!(table->file->index_flags(table->file->keyread, 0, 1) & HA_CLUSTERED_INDEX)) table->mark_index_columns(table->file->keyread, table->read_set); } - if (tab->cache && tab->cache->init(select_options & SELECT_DESCRIBE)) + bool init_for_explain= false; + + /* + Can we use lightweight initalization mode just for EXPLAINs? We can if + we're certain that the optimizer will not execute the subquery. + The optimzier will not execute the subquery if it's too expensive. For + the exact criteria, see Item_subselect::is_expensive(). + Note that the subquery might be a UNION and we might not yet know if it + is expensive. + What we do know is that if this SELECT is too expensive, then the whole + subquery will be too expensive as well. + So, we can use lightweight initialization (init_for_explain=true) if this + SELECT examines more than @@expensive_subquery_limit rows. + */ + if ((select_options & SELECT_DESCRIBE) && + get_examined_rows() >= thd->variables.expensive_subquery_limit) + { + init_for_explain= true; + } + if (tab->cache && tab->cache->init(init_for_explain)) revise_cache_usage(tab); else tab->remove_redundant_bnl_scan_conds(); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 44802e24da9..5a52e66193d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1326,6 +1326,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, temporary_table_was_dropped= 1; } is_temporary= 1; + thd->reset_sp_cache= true; } if ((drop_temporary && if_exists) || temporary_table_was_dropped) @@ -1699,8 +1700,11 @@ report_error: } DBUG_PRINT("table", ("table: %p s: %p", table->table, table->table ? table->table->s : NULL)); + if (is_temporary_table(table)) + thd->reset_sp_cache= true; } DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog"); + thd->thread_specific_used= TRUE; error= 0; @@ -4492,6 +4496,7 @@ int create_table_impl(THD *thd, if (is_trans != NULL) *is_trans= table->file->has_transactions(); + thd->reset_sp_cache= true; thd->thread_specific_used= TRUE; create_info->table= table; // Store pointer to table } diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index f8da5171bcc..13c83dfa116 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1108,10 +1108,8 @@ void wsrep_recover() } } - -void wsrep_stop_replication(THD *thd) +static void wsrep_stop_replication_common(THD *thd) { - WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); if (Wsrep_server_state::instance().state() != Wsrep_server_state::s_disconnected) { @@ -1124,10 +1122,10 @@ void wsrep_stop_replication(THD *thd) } } - /* my connection, should not terminate with wsrep_close_client_connection(), - make transaction to rollback - */ - if (thd && !thd->wsrep_applier) trans_rollback(thd); + /* my connection, should not terminate with + wsrep_close_client_connections(), make transaction to rollback */ + if (thd && !thd->wsrep_applier) + trans_rollback(thd); wsrep_close_client_connections(TRUE, thd); /* wait until appliers have stopped */ @@ -1136,26 +1134,16 @@ void wsrep_stop_replication(THD *thd) node_uuid= WSREP_UUID_UNDEFINED; } +void wsrep_stop_replication(THD *thd) +{ + WSREP_INFO("Stop replication by %llu", (thd) ? thd->thread_id : 0); + wsrep_stop_replication_common(thd); +} + void wsrep_shutdown_replication() { WSREP_INFO("Shutdown replication"); - if (Wsrep_server_state::instance().state() != wsrep::server_state::s_disconnected) - { - WSREP_DEBUG("Disconnect provider"); - Wsrep_server_state::instance().disconnect(); - if (Wsrep_server_state::instance().wait_until_state( - Wsrep_server_state::s_disconnected)) - { - WSREP_WARN("Wsrep interrupted while waiting for disconnected state"); - } - } - - wsrep_close_client_connections(TRUE); - - /* wait until appliers have stopped */ - wsrep_wait_appliers_close(NULL); - node_uuid= WSREP_UUID_UNDEFINED; - + wsrep_stop_replication_common(nullptr); /* Undocking the thread specific data. */ set_current_thd(nullptr); } @@ -3266,14 +3254,20 @@ static my_bool have_client_connections(THD *thd, void*) { DBUG_PRINT("quit",("Informing thread %lld that it's time to die", (longlong) thd->thread_id)); - if (is_client_connection(thd) && - (thd->killed == KILL_CONNECTION || - thd->killed == KILL_CONNECTION_HARD)) + if (is_client_connection(thd)) { - (void)abort_replicated(thd); - return 1; + if (thd->killed == KILL_CONNECTION || + thd->killed == KILL_CONNECTION_HARD) + { + (void)abort_replicated(thd); + return true; + } + if (thd->get_stmt_da()->is_eof()) + { + return true; + } } - return 0; + return false; } static void wsrep_close_thread(THD *thd) @@ -3311,14 +3305,24 @@ static my_bool kill_all_threads(THD *thd, THD *caller_thd) /* We skip slave threads & scheduler on this first loop through. */ if (is_client_connection(thd) && thd != caller_thd) { + if (thd->get_stmt_da()->is_eof()) + { + return 0; + } + if (is_replaying_connection(thd)) + { thd->set_killed(KILL_CONNECTION_HARD); - else if (!abort_replicated(thd)) + return 0; + } + + if (!abort_replicated(thd)) { /* replicated transactions must be skipped */ WSREP_DEBUG("closing connection %lld", (longlong) thd->thread_id); /* instead of wsrep_close_thread() we do now soft kill by THD::awake */ thd->awake(KILL_CONNECTION_HARD); + return 0; } } return 0; @@ -3330,6 +3334,7 @@ static my_bool kill_remaining_threads(THD *thd, THD *caller_thd) if (is_client_connection(thd) && !abort_replicated(thd) && !is_replaying_connection(thd) && + !thd->get_stmt_da()->is_eof() && thd_is_connection_alive(thd) && thd != caller_thd) { diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index 5a759c74ef7..4ad829c14a6 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -264,25 +264,17 @@ static void finish_stmt(THD* thd) { close_thread_tables(thd); } -static int open_table(THD* thd, - const LEX_CSTRING *schema_name, - const LEX_CSTRING *table_name, - enum thr_lock_type const lock_type, - TABLE** table) { - assert(table); - *table= NULL; - +static int open_table(THD *thd, const LEX_CSTRING *schema_name, + const LEX_CSTRING *table_name, + enum thr_lock_type const lock_type, + TABLE_LIST *table_list) +{ + assert(table_list); DBUG_ENTER("Wsrep_schema::open_table()"); - - TABLE_LIST tables; - uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | - MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | - MYSQL_OPEN_IGNORE_FLUSH | - MYSQL_LOCK_IGNORE_TIMEOUT); - - tables.init_one_table(schema_name, - table_name, - NULL, lock_type); + const uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT); + table_list->init_one_table(schema_name, table_name, NULL, lock_type); thd->lex->query_tables_own_last= 0; // No need to open table if the query was bf aborted, @@ -292,37 +284,39 @@ static int open_table(THD* thd, (thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED)); if (interrupted || - !open_n_lock_single_table(thd, &tables, tables.lock_type, flags)) { + !open_n_lock_single_table(thd, table_list, table_list->lock_type, flags)) + { close_thread_tables(thd); DBUG_RETURN(1); } - *table= tables.table; - (*table)->use_all_columns(); + table_list->table->use_all_columns(); DBUG_RETURN(0); } - -static int open_for_write(THD* thd, const char* table_name, TABLE** table) { +static int open_for_write(THD* thd, const char* table_name, TABLE_LIST* table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_WRITE, - table)) { + table_list)) + { // No need to log an error if the query was bf aborted, // thd client will get ER_LOCK_DEADLOCK in the end. const bool interrupted= thd->killed || (thd->is_error() && (thd->get_stmt_da()->sql_errno() == ER_QUERY_INTERRUPTED)); - if (!interrupted) { + if (!interrupted) + { WSREP_ERROR("Failed to open table %s.%s for writing", schema_str.str, table_name); } return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -464,19 +458,21 @@ static int delete_row(TABLE* table) { return 0; } -static int open_for_read(THD* thd, const char* table_name, TABLE** table) { - +static int open_for_read(THD *thd, const char *table_name, + TABLE_LIST *table_list) +{ LEX_CSTRING schema_str= { wsrep_schema_str.c_str(), wsrep_schema_str.length() }; LEX_CSTRING table_str= { table_name, strlen(table_name) }; if (Wsrep_schema_impl::open_table(thd, &schema_str, &table_str, TL_READ, - table)) { + table_list)) + { WSREP_ERROR("Failed to open table %s.%s for reading", schema_str.str, table_name); return 1; } - empty_record(*table); - (*table)->use_all_columns(); - restore_record(*table, s->default_values); + empty_record(table_list->table); + table_list->table->use_all_columns(); + restore_record(table_list->table, s->default_values); return 0; } @@ -731,8 +727,10 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) assert(view.status() == Wsrep_view::primary); int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; - TABLE* members_table= 0; + TABLE_LIST members_table_l; + TABLE* members_table = 0; #ifdef WSREP_SCHEMA_MEMBERS_HISTORY TABLE* members_history_table= 0; #endif /* WSREP_SCHEMA_MEMBERS_HISTORY */ @@ -757,11 +755,13 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) Store cluster view info */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table)) + if (Wsrep_schema_impl::open_for_write(thd, cluster_table_str.c_str(), &cluster_table_l)) { goto out; } + cluster_table= cluster_table_l.table; + Wsrep_schema_impl::store(cluster_table, 0, view.state_id().id()); Wsrep_schema_impl::store(cluster_table, 1, view.view_seqno().get()); Wsrep_schema_impl::store(cluster_table, 2, view.state_id().seqno().get()); @@ -781,12 +781,14 @@ int Wsrep_schema::store_view(THD* thd, const Wsrep_view& view) */ Wsrep_schema_impl::init_stmt(thd); if (Wsrep_schema_impl::open_for_write(thd, members_table_str.c_str(), - &members_table)) + &members_table_l)) { WSREP_ERROR("failed to open wsrep.members table"); goto out; } + members_table= members_table_l.table; + for (size_t i= 0; i < view.members().size(); ++i) { Wsrep_schema_impl::store(members_table, 0, view.members()[i].id()); @@ -840,8 +842,10 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { int ret= 1; int error; + TABLE_LIST cluster_table_l; TABLE* cluster_table= 0; bool end_cluster_scan= false; + TABLE_LIST members_table_l; TABLE* members_table= 0; bool end_members_scan= false; @@ -867,8 +871,12 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read cluster info from cluster table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) { + if (Wsrep_schema_impl::open_for_read(thd, cluster_table_str.c_str(), &cluster_table_l)) { + goto out; + } + cluster_table = cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { goto out; } @@ -892,8 +900,14 @@ Wsrep_view Wsrep_schema::restore_view(THD* thd, const Wsrep_id& own_id) const { Read members from members table */ Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), &members_table) || - Wsrep_schema_impl::init_for_scan(members_table)) { + if (Wsrep_schema_impl::open_for_read(thd, members_table_str.c_str(), + &members_table_l)) + { + goto out; + } + + members_table= members_table_l.table; + if (Wsrep_schema_impl::init_for_scan(members_table)) { goto out; } end_members_scan= true; @@ -997,14 +1011,15 @@ int Wsrep_schema::append_fragment(THD* thd, Wsrep_schema_impl::sql_safe_updates sql_safe_updates(thd); Wsrep_schema_impl::init_stmt(thd); - TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { trans_rollback_stmt(thd); thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + TABLE* frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, server_id); Wsrep_schema_impl::store(frag_table, 1, transaction_id.get()); Wsrep_schema_impl::store(frag_table, 2, seqno.get()); @@ -1048,13 +1063,15 @@ int Wsrep_schema::update_fragment_meta(THD* thd, uchar *key=NULL; key_part_map key_map= 0; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; Wsrep_schema_impl::init_stmt(thd); - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { thd->lex->restore_backup_query_tables_list(&query_tables_list_backup); DBUG_RETURN(1); } + frag_table= frag_table_l.table; /* Find record with the given uuid, trx id, and seqno -1 */ Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); @@ -1142,7 +1159,10 @@ static int remove_fragment(THD* thd, seqno.get(), error); } - ret= error; + else + { + ret= error; + } } else if (Wsrep_schema_impl::delete_row(frag_table)) { @@ -1174,12 +1194,14 @@ int Wsrep_schema::remove_fragments(THD* thd, thd->reset_n_backup_open_tables_state(&open_tables_backup); TABLE* frag_table= 0; - if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table)) + TABLE_LIST frag_table_l; + if (Wsrep_schema_impl::open_for_write(thd, sr_table_str.c_str(), &frag_table_l)) { ret= 1; } else { + frag_table= frag_table_l.table; for (std::vector::const_iterator i= fragments.begin(); i != fragments.end(); ++i) { @@ -1243,6 +1265,7 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, int ret= 1; int error; TABLE* frag_table= 0; + TABLE_LIST frag_table_l; uchar *key=NULL; key_part_map key_map= 0; @@ -1250,12 +1273,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, i != fragments.end(); ++i) { Wsrep_schema_impl::init_stmt(&thd); - if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table))) + if ((error= Wsrep_schema_impl::open_for_read(&thd, sr_table_str.c_str(), &frag_table_l))) { WSREP_WARN("Could not open SR table for read: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; Wsrep_schema_impl::store(frag_table, 0, ws_meta.server_id()); Wsrep_schema_impl::store(frag_table, 1, ws_meta.transaction_id().get()); @@ -1301,12 +1325,13 @@ int Wsrep_schema::replay_transaction(THD* orig_thd, if ((error= Wsrep_schema_impl::open_for_write(&thd, sr_table_str.c_str(), - &frag_table))) + &frag_table_l))) { WSREP_WARN("Could not open SR table for write: %d", error); Wsrep_schema_impl::finish_stmt(&thd); DBUG_RETURN(1); } + frag_table= frag_table_l.table; error= Wsrep_schema_impl::init_for_index_scan(frag_table, key, @@ -1348,7 +1373,9 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) (char*) &storage_thd); wsrep_assign_from_threadvars(&storage_thd); TABLE* frag_table= 0; + TABLE_LIST frag_table_l; TABLE* cluster_table= 0; + TABLE_LIST cluster_table_l; Wsrep_storage_service storage_service(&storage_thd); Wsrep_schema_impl::binlog_off binlog_off(&storage_thd); Wsrep_schema_impl::wsrep_off wsrep_off(&storage_thd); @@ -1363,10 +1390,15 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Wsrep_schema_impl::init_stmt(&storage_thd); storage_thd.wsrep_skip_locking= FALSE; - if (Wsrep_schema_impl::open_for_read(&storage_thd, - cluster_table_str.c_str(), - &cluster_table) || - Wsrep_schema_impl::init_for_scan(cluster_table)) + if (Wsrep_schema_impl::open_for_read(&storage_thd, cluster_table_str.c_str(), + &cluster_table_l)) + { + Wsrep_schema_impl::finish_stmt(&storage_thd); + DBUG_RETURN(1); + } + cluster_table= cluster_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(cluster_table)) { Wsrep_schema_impl::finish_stmt(&storage_thd); DBUG_RETURN(1); @@ -1404,12 +1436,19 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd) Open the table for reading and writing so that fragments without valid seqno can be deleted. */ - if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), &frag_table) || - Wsrep_schema_impl::init_for_scan(frag_table)) + if (Wsrep_schema_impl::open_for_write(&storage_thd, sr_table_str.c_str(), + &frag_table_l)) { WSREP_ERROR("Failed to open SR table for write"); goto out; } + frag_table= frag_table_l.table; + + if (Wsrep_schema_impl::init_for_scan(frag_table)) + { + WSREP_ERROR("Failed to init for index scan"); + goto out; + } while (0 == error) { diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index aa8ff37272c..5eaf4013827 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -6127,7 +6127,6 @@ btr_store_big_rec_extern_fields( for (ulint blob_npages = 0;; ++blob_npages) { buf_block_t* block; const ulint commit_freq = 4; - uint32_t r_extents; ut_ad(page_align(field_ref) == page_align(rec)); @@ -6162,24 +6161,18 @@ btr_store_big_rec_extern_fields( hint_prev = rec_block->page.id().page_no(); } - error = fsp_reserve_free_extents( - &r_extents, index->table->space, 1, - FSP_BLOB, &mtr, 1); - if (UNIV_UNLIKELY(error != DB_SUCCESS)) { -alloc_fail: - mtr.commit(); - goto func_exit; - } - block = btr_page_alloc(index, hint_prev + 1, FSP_NO_DIR, 0, &mtr, &mtr, &error); - index->table->space->release_free_extents(r_extents); if (!block) { - goto alloc_fail; +alloc_fail: + mtr.commit(); + goto func_exit; } + ut_a(block != NULL); + const uint32_t page_no = block->page.id().page_no(); if (prev_page_no == FIL_NULL) { diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc index 3ecdf64fb5f..d30f037ab99 100644 --- a/storage/innobase/btr/btr0pcur.cc +++ b/storage/innobase/btr/btr0pcur.cc @@ -468,8 +468,15 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) return restore_status::SAME_ALL; } - if (n_matched_fields >= index->n_uniq) - ret_val= restore_status::SAME_UNIQ; + if (n_matched_fields >= index->n_uniq + /* Unique indexes can contain "NULL" keys, and if all + unique fields are NULL and not all tuple + fields match to record fields, then treat it as if + restored cursor position points to the record with + not the same unique key. */ + && !(index->n_nullable + && dtuple_contains_null(tuple, index->n_uniq))) + ret_val= restore_status::SAME_UNIQ; } mem_heap_free(heap); diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 7f4f73d969b..d0f7476b228 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1987,7 +1987,6 @@ dict_index_add_to_cache( new_index->n_fields = new_index->n_def; new_index->trx_id = index->trx_id; new_index->set_committed(index->is_committed()); - new_index->nulls_equal = index->nulls_equal; n_ord = new_index->n_uniq; /* Flag the ordering columns and also set column max_prefix */ diff --git a/storage/innobase/fil/fil0crypt.cc b/storage/innobase/fil/fil0crypt.cc index c1f1157b0d3..12de62ac2be 100644 --- a/storage/innobase/fil/fil0crypt.cc +++ b/storage/innobase/fil/fil0crypt.cc @@ -2289,7 +2289,7 @@ void fil_space_crypt_close_tablespace(const fil_space_t *space) << space->chain.start->name << " (" << space->id << ") active threads " << crypt_data->rotate_state.active_threads - << "flushing=" + << " flushing=" << crypt_data->rotate_state.flushing << "."; last = now; } diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index 9aedd4af69c..4aab68e9ca2 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -507,7 +507,7 @@ rtr_pcur_move_to_next( mysql_mutex_unlock(&rtr_info->matches->rtr_match_mutex); cursor->btr_cur.page_cur.rec = rec.r_rec; - cursor->btr_cur.page_cur.block = &rtr_info->matches->block; + cursor->btr_cur.page_cur.block = rtr_info->matches->block; DEBUG_SYNC_C("rtr_pcur_move_to_next_return"); return(true); @@ -1318,21 +1318,15 @@ rtr_create_rtr_info( rtr_info->index = index; if (init_matches) { - rtr_info->heap = mem_heap_create(sizeof(*(rtr_info->matches))); rtr_info->matches = static_cast( - mem_heap_zalloc( - rtr_info->heap, - sizeof(*rtr_info->matches))); + ut_zalloc_nokey(sizeof *rtr_info->matches)); rtr_info->matches->matched_recs = UT_NEW_NOKEY(rtr_rec_vector()); - rtr_info->matches->bufp = page_align(rtr_info->matches->rec_buf - + UNIV_PAGE_SIZE_MAX + 1); mysql_mutex_init(rtr_match_mutex_key, &rtr_info->matches->rtr_match_mutex, nullptr); - rtr_info->matches->block.page.lock.init(); } rtr_info->path = UT_NEW_NOKEY(rtr_node_path_t()); @@ -1451,18 +1445,16 @@ rtr_clean_rtr_info( if (free_all) { if (rtr_info->matches) { - if (rtr_info->matches->matched_recs != NULL) { - UT_DELETE(rtr_info->matches->matched_recs); + if (rtr_info->matches->block) { + buf_block_free(rtr_info->matches->block); + rtr_info->matches->block = nullptr; } - rtr_info->matches->block.page.lock.free(); + UT_DELETE(rtr_info->matches->matched_recs); mysql_mutex_destroy( &rtr_info->matches->rtr_match_mutex); - } - - if (rtr_info->heap) { - mem_heap_free(rtr_info->heap); + ut_free(rtr_info->matches); } if (initialized) { @@ -1572,7 +1564,7 @@ rtr_check_discard_page( if (auto matches = rtr_info->matches) { mysql_mutex_lock(&matches->rtr_match_mutex); - if (matches->block.page.id() == id) { + if (matches->block->page.id() == id) { matches->matched_recs->clear(); matches->valid = false; } @@ -1766,7 +1758,7 @@ rtr_leaf_push_match_rec( ulint data_len; rtr_rec_t rtr_rec; - buf = match_rec->block.page.frame + match_rec->used; + buf = match_rec->block->page.frame + match_rec->used; ut_ad(page_rec_is_leaf(rec)); copy = rec_copy(buf, rec, offsets); @@ -1863,43 +1855,6 @@ rtr_non_leaf_insert_stack_push( new_seq, level, child_no, my_cursor, mbr_inc); } -/** Copy a buf_block_t, except "block->page.lock". -@param[in,out] matches copy to match->block -@param[in] block block to copy */ -static -void -rtr_copy_buf( - matched_rec_t* matches, - const buf_block_t* block) -{ - /* Copy all members of "block" to "matches->block" except "lock". - We skip "lock" because it is not used - from the dummy buf_block_t we create here and because memcpy()ing - it generates (valid) compiler warnings that the vtable pointer - will be copied. */ - matches->block.page.lock.free(); - new (&matches->block.page) buf_page_t(block->page); - matches->block.page.frame = block->page.frame; - matches->block.unzip_LRU = block->unzip_LRU; - - ut_d(matches->block.in_unzip_LRU_list = block->in_unzip_LRU_list); - ut_d(matches->block.in_withdraw_list = block->in_withdraw_list); - - /* Skip buf_block_t::lock */ - matches->block.modify_clock = block->modify_clock; -#ifdef BTR_CUR_HASH_ADAPT - matches->block.n_hash_helps = block->n_hash_helps; - matches->block.n_fields = block->n_fields; - matches->block.left_side = block->left_side; -#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG - matches->block.n_pointers = 0; -#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - matches->block.curr_n_fields = block->curr_n_fields; - matches->block.curr_left_side = block->curr_left_side; - matches->block.index = block->index; -#endif /* BTR_CUR_HASH_ADAPT */ -} - /****************************************************************//** Generate a shadow copy of the page block header to save the matched records */ @@ -1913,16 +1868,18 @@ rtr_init_match( { ut_ad(matches->matched_recs->empty()); matches->locked = false; - rtr_copy_buf(matches, block); - matches->block.page.frame = matches->bufp; matches->valid = false; + if (!matches->block) { + matches->block = buf_block_alloc(); + } + + matches->block->page.init(buf_page_t::MEMORY, block->page.id()); /* We have to copy PAGE_*_SUPREMUM_END bytes so that we can use infimum/supremum of this page as normal btr page for search. */ - memcpy(matches->block.page.frame, page, page_is_comp(page) - ? PAGE_NEW_SUPREMUM_END : PAGE_OLD_SUPREMUM_END); matches->used = page_is_comp(page) ? PAGE_NEW_SUPREMUM_END : PAGE_OLD_SUPREMUM_END; + memcpy(matches->block->page.frame, page, matches->used); #ifdef RTR_SEARCH_DIAGNOSTIC ulint pageno = page_get_page_no(page); fprintf(stderr, "INNODB_RTR: Searching leaf page %d\n", @@ -2349,7 +2306,7 @@ rtr_cur_search_with_match( #endif /* UNIV_DEBUG */ /* Pop the last match record and position on it */ match_rec->matched_recs->pop_back(); - page_cur_position(test_rec.r_rec, &match_rec->block, + page_cur_position(test_rec.r_rec, match_rec->block, cursor); } } else { diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e22d5075cbe..d6210c5bfaa 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -7408,26 +7408,55 @@ ha_innobase::build_template( ulint num_v = 0; - if (active_index != MAX_KEY - && active_index == pushed_idx_cond_keyno) { - m_prebuilt->idx_cond = this; - goto icp; - } else if (pushed_rowid_filter && rowid_filter_is_active) { -icp: - /* Push down an index condition or an end_range check. */ + /* MDEV-31154: For pushed down index condition we don't support virtual + column and idx_cond_push() does check for it. For row ID filtering we + don't need such restrictions but we get into trouble trying to use the + ICP path. + + 1. It should be fine to follow no_icp path if primary key is generated. + However, with user specified primary key(PK), the row is identified by + the PK and those columns need to be converted to mysql format in + row_search_idx_cond_check before doing the comparison. Since secondary + indexes always have PK appended in innodb, it works with current ICP + handling code when fetch_primary_key_cols is set to TRUE. + + 2. Although ICP comparison and Row ID comparison works on different + columns the current ICP code can be shared by both. + + 3. In most cases, it works today by jumping to goto no_icp when we + encounter a virtual column. This is hackish and already have some + issues as it cannot handle PK and all states are not reset properly, + for example, idx_cond_n_cols is not reset. + + 4. We already encountered MDEV-28747 m_prebuilt->idx_cond was being set. + + Neither ICP nor row ID comparison needs virtual columns and the code is + simplified to handle both. It should handle the issues. */ + + const bool pushed_down = active_index != MAX_KEY + && active_index == pushed_idx_cond_keyno; + + m_prebuilt->idx_cond = pushed_down ? this : nullptr; + + if (m_prebuilt->idx_cond || m_prebuilt->pk_filter) { + /* Push down an index condition, end_range check or row ID + filter */ for (ulint i = 0; i < n_fields; i++) { const Field* field = table->field[i]; const bool is_v = !field->stored_in_db(); - if (is_v && skip_virtual) { - num_v++; - continue; - } + bool index_contains = index->contains_col_or_prefix( is_v ? num_v : i - num_v, is_v); - if (is_v && index_contains) { - m_prebuilt->n_template = 0; - num_v = 0; - goto no_icp; + + if (is_v) { + if (index_contains) { + /* We want to ensure that ICP is not + used with virtual columns. */ + ut_ad(!pushed_down); + m_prebuilt->idx_cond = nullptr; + } + num_v++; + continue; } /* Test if an end_range or an index condition @@ -7447,7 +7476,7 @@ icp: which would be acceptable if end_range==NULL. */ if (build_template_needs_field_in_icp( index, m_prebuilt, index_contains, - is_v ? num_v : i - num_v, is_v)) { + i - num_v, false)) { if (!whole_row) { field = build_template_needs_field( index_contains, @@ -7456,15 +7485,10 @@ icp: fetch_primary_key_cols, index, table, i, num_v); if (!field) { - if (is_v) { - num_v++; - } continue; } } - ut_ad(!is_v); - mysql_row_templ_t* templ= build_template_field( m_prebuilt, clust_index, index, table, field, i - num_v, 0); @@ -7541,15 +7565,16 @@ icp: */ } - if (is_v) { - num_v++; - } } - ut_ad(m_prebuilt->idx_cond_n_cols > 0); - ut_ad(m_prebuilt->idx_cond_n_cols == m_prebuilt->n_template); - num_v = 0; + ut_ad(m_prebuilt->idx_cond_n_cols == m_prebuilt->n_template); + if (m_prebuilt->idx_cond_n_cols == 0) { + /* No columns to push down. It is safe to jump to np ICP + path. */ + m_prebuilt->idx_cond = nullptr; + goto no_icp; + } /* Include the fields that are not needed in index condition pushdown. */ @@ -7564,7 +7589,7 @@ icp: bool index_contains = index->contains_col_or_prefix( is_v ? num_v : i - num_v, is_v); - if (!build_template_needs_field_in_icp( + if (is_v || !build_template_needs_field_in_icp( index, m_prebuilt, index_contains, is_v ? num_v : i - num_v, is_v)) { /* Not needed in ICP */ @@ -7597,7 +7622,7 @@ icp: } else { no_icp: /* No index condition pushdown */ - m_prebuilt->idx_cond = NULL; + ut_ad(!m_prebuilt->idx_cond); ut_ad(num_v == 0); for (ulint i = 0; i < n_fields; i++) { diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 96c03891679..087a0c32319 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1728,11 +1728,9 @@ instant_alter_column_possible( ut_ad(!is_null || nullable); n_nullable += nullable; n_add++; - uint l; + uint l = (*af)->pack_length(); switch ((*af)->type()) { case MYSQL_TYPE_VARCHAR: - l = reinterpret_cast - (*af)->get_length(); variable_length: if (l >= min_local_len) { max_size += blob_prefix @@ -1746,7 +1744,6 @@ instant_alter_column_possible( if (!is_null) { min_size += l; } - l = (*af)->pack_length(); max_size += l; lenlen += l > 255 ? 2 : 1; } @@ -1760,7 +1757,6 @@ instant_alter_column_possible( ((*af))->get_length(); goto variable_length; default: - l = (*af)->pack_length(); if (l > 255 && ib_table.not_redundant()) { goto variable_length; } diff --git a/storage/innobase/include/data0data.h b/storage/innobase/include/data0data.h index 5eaad5bf552..6b1a1915350 100644 --- a/storage/innobase/include/data0data.h +++ b/storage/innobase/include/data0data.h @@ -349,15 +349,12 @@ dtuple_set_types_binary( dtuple_t* tuple, /*!< in: data tuple */ ulint n) /*!< in: number of fields to set */ MY_ATTRIBUTE((nonnull)); -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number = 0); /**********************************************************//** Checks that a data field is typed. Asserts an error if not. @return TRUE if ok */ diff --git a/storage/innobase/include/data0data.inl b/storage/innobase/include/data0data.inl index 2d1bf5a2d50..b6c6ace8dc0 100644 --- a/storage/innobase/include/data0data.inl +++ b/storage/innobase/include/data0data.inl @@ -596,28 +596,18 @@ data_write_sql_null( memset(data, 0, len); } -/**********************************************************************//** -Checks if a dtuple contains an SQL null value. -@return TRUE if some field is SQL null */ +/** Checks if a dtuple contains an SQL null value. +@param tuple tuple +@param fields_number number of fields in the tuple to check +@return true if some field is SQL null */ UNIV_INLINE -ibool -dtuple_contains_null( -/*=================*/ - const dtuple_t* tuple) /*!< in: dtuple */ +bool dtuple_contains_null(const dtuple_t *tuple, ulint fields_number) { - ulint n; - ulint i; - - n = dtuple_get_n_fields(tuple); - - for (i = 0; i < n; i++) { - if (dfield_is_null(dtuple_get_nth_field(tuple, i))) { - - return(TRUE); - } - } - - return(FALSE); + ulint n= fields_number ? fields_number : dtuple_get_n_fields(tuple); + for (ulint i= 0; i < n; i++) + if (dfield_is_null(dtuple_get_nth_field(tuple, i))) + return true; + return false; } /**************************************************************//** diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 43316622225..f8b83919f83 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1019,8 +1019,6 @@ struct dict_index_t { /*!< number of columns the user defined to be in the index: in the internal representation we add more columns */ - unsigned nulls_equal:1; - /*!< if true, SQL NULL == SQL NULL */ unsigned n_uniq:10;/*!< number of fields from the beginning which are enough to determine an index entry uniquely */ diff --git a/storage/innobase/include/dict0mem.inl b/storage/innobase/include/dict0mem.inl index d60ee5d9bf4..edb7cf92cd5 100644 --- a/storage/innobase/include/dict0mem.inl +++ b/storage/innobase/include/dict0mem.inl @@ -63,6 +63,5 @@ dict_mem_fill_index_struct( & index->MAX_N_FIELDS; /* The '1 +' above prevents allocation of an empty mem block */ - index->nulls_equal = false; ut_d(index->magic_n = DICT_INDEX_MAGIC_N); } diff --git a/storage/innobase/include/dyn0buf.h b/storage/innobase/include/dyn0buf.h index 208e49c34a7..e86e6e22a12 100644 --- a/storage/innobase/include/dyn0buf.h +++ b/storage/innobase/include/dyn0buf.h @@ -60,7 +60,7 @@ public: ulint used() const MY_ATTRIBUTE((warn_unused_result)) { - return(static_cast(m_used & ~DYN_BLOCK_FULL_FLAG)); + return m_used; } /** @@ -153,8 +153,7 @@ public: /** Storage */ byte m_data[MAX_DATA_SIZE]; - /** number of data bytes used in this block; - DYN_BLOCK_FULL_FLAG is set when the block becomes full */ + /** number of data bytes used in this block */ uint32_t m_used; friend class mtr_buf_t; diff --git a/storage/innobase/include/dyn0types.h b/storage/innobase/include/dyn0types.h index 83d0b0d64c2..af7f663d970 100644 --- a/storage/innobase/include/dyn0types.h +++ b/storage/innobase/include/dyn0types.h @@ -33,7 +33,4 @@ Created 2013-03-16 Sunny Bains /** This is the initial 'payload' size of a dynamic array */ #define DYN_ARRAY_DATA_SIZE 512 -/** Flag for dyn_block_t::used that indicates a full block */ -#define DYN_BLOCK_FULL_FLAG 0x1000000UL - #endif /* dyn0types_h */ diff --git a/storage/innobase/include/gis0type.h b/storage/innobase/include/gis0type.h index d6a4ef67a38..2dc25a898b7 100644 --- a/storage/innobase/include/gis0type.h +++ b/storage/innobase/include/gis0type.h @@ -66,10 +66,7 @@ typedef std::vector > rtr_rec_vector; /* Structure for matched records on the leaf page */ typedef struct matched_rec { - byte* bufp; /*!< aligned buffer point */ - byte rec_buf[UNIV_PAGE_SIZE_MAX * 2]; - /*!< buffer used to copy matching rec */ - buf_block_t block; /*!< the shadow buffer block */ + buf_block_t* block; /*!< the shadow buffer block */ ulint used; /*!< memory used */ rtr_rec_vector* matched_recs; /*!< vector holding the matching rec */ mysql_mutex_t rtr_match_mutex;/*!< mutex protect the match_recs @@ -107,7 +104,6 @@ typedef struct rtr_info{ /*!< mutex protect the "path" vector */ rtr_mbr_t mbr; /*!< the search MBR */ que_thr_t* thr; /*!< the search thread */ - mem_heap_t* heap; /*!< memory heap */ btr_cur_t* cursor; /*!< cursor used for search */ dict_index_t* index; /*!< index it is searching */ bool need_prdt_lock; diff --git a/storage/innobase/include/mtr0log.h b/storage/innobase/include/mtr0log.h index d34a62e7bb2..0562080e086 100644 --- a/storage/innobase/include/mtr0log.h +++ b/storage/innobase/include/mtr0log.h @@ -347,11 +347,12 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) ut_ad(d >= 8); ut_ad(s >= 8); ut_ad(len); - ut_ad(s <= ulint(srv_page_size)); - ut_ad(s + len <= ulint(srv_page_size)); + ut_d(const ulint ps= srv_page_size); + ut_ad(s <= ps); + ut_ad(s + len <= ps); ut_ad(s != d); - ut_ad(d <= ulint(srv_page_size)); - ut_ad(d + len <= ulint(srv_page_size)); + ut_ad(d <= ps); + ut_ad(d + len <= ps); set_modified(b); if (!is_logged()) @@ -359,17 +360,17 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len) static_assert(MIN_4BYTE > UNIV_PAGE_SIZE_MAX, "consistency"); size_t lenlen= (len < MIN_2BYTE ? 1 : len < MIN_3BYTE ? 2 : 3); /* The source offset is encoded relative to the destination offset, - with the sign in the least significant bit. */ - if (s > d) - s= (s - d) << 1; - else - s= (d - s) << 1 | 1; + with the sign in the least significant bit. + Because the source offset 0 is not possible, our encoding + subtracts 1 from the offset. */ + const uint16_t S= s > d + ? uint16_t((s - d - 1) << 1) + : uint16_t((d - s - 1) << 1 | 1); /* The source offset 0 is not possible. */ - s-= 1 << 1; - size_t slen= (s < MIN_2BYTE ? 1 : s < MIN_3BYTE ? 2 : 3); + size_t slen= (S < MIN_2BYTE ? 1 : S < MIN_3BYTE ? 2 : 3); byte *l= log_write(b.page.id(), &b.page, lenlen + slen, true, d); l= mlog_encode_varint(l, len); - l= mlog_encode_varint(l, s); + l= mlog_encode_varint(l, S); m_log.close(l); m_last_offset= static_cast(d + len); } diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index 40b4ff47d54..0eda905decc 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -1867,14 +1867,39 @@ PageConverter::update_records( bool clust_index = m_index->m_srv_index == m_cluster_index; /* This will also position the cursor on the first user record. */ + rec_t* rec = m_rec_iter.open(block, m_index->m_srv_index); - if (!m_rec_iter.open(block, m_index->m_srv_index)) { + if (!rec) { return DB_CORRUPTION; } + ulint deleted; + + if (!page_has_prev(block->page.frame) + && m_index->m_srv_index->is_instant()) { + /* Expect to find the hidden metadata record */ + if (page_rec_is_supremum(rec)) { + return DB_CORRUPTION; + } + + const ulint info_bits = rec_get_info_bits(rec, comp); + + if (!(info_bits & REC_INFO_MIN_REC_FLAG)) { + return DB_CORRUPTION; + } + + if (!(info_bits & REC_INFO_DELETED_FLAG) + != !m_index->m_srv_index->table->instant) { + return DB_CORRUPTION; + } + + deleted = 0; + goto first; + } + while (!m_rec_iter.end()) { - rec_t* rec = m_rec_iter.current(); - ibool deleted = rec_get_deleted_flag(rec, comp); + rec = m_rec_iter.current(); + deleted = rec_get_deleted_flag(rec, comp); /* For the clustered index we have to adjust the BLOB reference and the system fields irrespective of the @@ -1882,6 +1907,7 @@ PageConverter::update_records( cluster records is required for purge to work later. */ if (deleted || clust_index) { +first: m_offsets = rec_get_offsets( rec, m_index->m_srv_index, m_offsets, m_index->m_srv_index->n_core_fields, @@ -3312,7 +3338,7 @@ static dict_table_t *build_fts_hidden_table( return new_table; } -/* find, parse instant metadata, performing variaous checks, +/* find, parse instant metadata, performing various checks, and apply it to dict_table_t @return DB_SUCCESS or some error */ static dberr_t handle_instant_metadata(dict_table_t *table, diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 990c14d1a8f..9897c813f02 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -2000,7 +2000,7 @@ row_ins_dupl_error_with_rec( /* In a unique secondary index we allow equal key values if they contain SQL NULLs */ - if (!dict_index_is_clust(index) && !index->nulls_equal) { + if (!dict_index_is_clust(index)) { for (i = 0; i < n_unique; i++) { if (dfield_is_null(dtuple_get_nth_field(entry, i))) { @@ -2102,16 +2102,8 @@ row_ins_scan_sec_index_for_duplicate( /* If the secondary index is unique, but one of the fields in the n_unique first fields is NULL, a unique key violation cannot occur, since we define NULL != NULL in this case */ - - if (!index->nulls_equal) { - for (ulint i = 0; i < n_unique; i++) { - if (UNIV_SQL_NULL == dfield_get_len( - dtuple_get_nth_field(entry, i))) { - - DBUG_RETURN(DB_SUCCESS); - } - } - } + if (index->n_nullable && dtuple_contains_null(entry, n_unique)) + DBUG_RETURN(DB_SUCCESS); /* Store old value on n_fields_cmp */ diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 6886ca1ae5d..5ebcab88b01 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -1190,11 +1190,11 @@ sel_set_rtr_rec_lock( ut_ad(page_align(first_rec) == cur_block->page.frame); ut_ad(match->valid); - match->block.page.lock.x_lock(); + match->block->page.lock.x_lock(); retry: cur_block = btr_pcur_get_block(pcur); - ut_ad(match->block.page.lock.have_x() - || match->block.page.lock.have_s()); + ut_ad(match->block->page.lock.have_x() + || match->block->page.lock.have_s()); ut_ad(page_is_leaf(cur_block->page.frame)); err = lock_sec_rec_read_check_and_lock( @@ -1294,7 +1294,7 @@ re_scan: ULINT_UNDEFINED, &heap); err = lock_sec_rec_read_check_and_lock( - 0, &match->block, rtr_rec->r_rec, index, + 0, match->block, rtr_rec->r_rec, index, my_offsets, static_cast(mode), type, thr); @@ -1310,7 +1310,7 @@ re_scan: match->locked = true; func_end: - match->block.page.lock.x_unlock(); + match->block->page.lock.x_unlock(); if (heap != NULL) { mem_heap_free(heap); } @@ -3410,7 +3410,7 @@ Row_sel_get_clust_rec_for_mysql::operator()( if (dict_index_is_spatial(sec_index) && btr_cur->rtr_info->matches && (page_align(rec) - == btr_cur->rtr_info->matches->block.page.frame + == btr_cur->rtr_info->matches->block->page.frame || rec != btr_pcur_get_rec(prebuilt->pcur))) { #ifdef UNIV_DEBUG rtr_info_t* rtr_info = btr_cur->rtr_info; diff --git a/storage/perfschema/pfs_buffer_container.h b/storage/perfschema/pfs_buffer_container.h index d5745e76249..b5506fe0195 100644 --- a/storage/perfschema/pfs_buffer_container.h +++ b/storage/perfschema/pfs_buffer_container.h @@ -1084,8 +1084,7 @@ template class PFS_buffer_processor { public: - virtual ~PFS_buffer_processor () - {} + virtual ~PFS_buffer_processor()= default; virtual void operator()(T *element) = 0; }; diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 60e2bc198a8..7ded6ab4bad 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -22,10 +22,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "ha_partition.h" #include "spd_param.h" #include "spd_err.h" @@ -48,15 +43,9 @@ #include "spd_ping_table.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_CAN_BG_SEARCH (1LL << 37) #define SPIDER_CAN_BG_INSERT (1LL << 38) #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#else -#define SPIDER_CAN_BG_SEARCH (LL(1) << 37) -#define SPIDER_CAN_BG_INSERT (LL(1) << 38) -#define SPIDER_CAN_BG_UPDATE (LL(1) << 39) -#endif extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; @@ -480,12 +469,23 @@ int ha_spider::open( result_list.last = NULL; result_list.current = NULL; result_list.record_num = 0; - if ( - !(result_list.sqls = new spider_string[share->link_count]) || - !(result_list.insert_sqls = new spider_string[share->link_count]) || - !(result_list.update_sqls = new spider_string[share->link_count]) || - !(result_list.tmp_sqls = new spider_string[share->link_count]) - ) { + if (!(result_list.sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.insert_sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.update_sqls = new spider_string[share->link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + if (!(result_list.tmp_sqls = new spider_string[share->link_count])) + { error_num = HA_ERR_OUT_OF_MEM; goto error_init_result_list; } @@ -1576,14 +1576,11 @@ int ha_spider::extra( if (!(wide_handler->trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#if MYSQL_VERSION_ID < 50500 -#else case HA_EXTRA_ADD_CHILDREN_LIST: DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST")); if (!(wide_handler->trx = spider_get_trx(ha_thd(), TRUE, &error_num))) DBUG_RETURN(error_num); break; -#endif #if defined(HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN) || defined(HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF) #ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN case HA_EXTRA_STARTING_ORDERED_INDEX_SCAN: @@ -4077,7 +4074,6 @@ bool ha_spider::check_no_where_cond() } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -4087,17 +4083,6 @@ ha_rows ha_spider::multi_range_read_info_const( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info_const"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4142,7 +4127,6 @@ ha_rows ha_spider::multi_range_read_info_const( DBUG_RETURN(rows); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows ha_spider::multi_range_read_info( uint keyno, uint n_ranges, @@ -4152,17 +4136,6 @@ ha_rows ha_spider::multi_range_read_info( uint *flags, Cost_estimate *cost ) -#else -ha_rows ha_spider::multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost -) -#endif { DBUG_ENTER("ha_spider::multi_range_read_info"); DBUG_PRINT("info",("spider this=%p", this)); @@ -4235,16 +4208,10 @@ int ha_spider::multi_range_read_init( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_first( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_first( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_first_internal( uchar *buf, KEY_MULTI_RANGE **found_range_p, @@ -4731,19 +4698,11 @@ int ha_spider::read_multi_range_first_internal( DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); spider_free(spider_current_trx, multi_range_keys, MYF(0)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 if (!(multi_range_keys = (range_id_t *) spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_1, sizeof(range_id_t) * (multi_range_num < result_list.multi_split_read ? multi_range_num : result_list.multi_split_read), MYF(MY_WME))) ) -#else - if (!(multi_range_keys = (char **) - spider_malloc(spider_current_trx, SPD_MID_HA_SPIDER_MULTI_RANGE_READ_NEXT_FIRST_2, sizeof(char *) * - (multi_range_num < result_list.multi_split_read ? - multi_range_num : result_list.multi_split_read), MYF(MY_WME))) - ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys)); if (!mrr_key_buff) @@ -4961,11 +4920,7 @@ int ha_spider::read_multi_range_first_internal( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -5088,11 +5043,7 @@ int ha_spider::read_multi_range_first_internal( { #ifdef HA_MRR_USE_DEFAULT_IMPL DBUG_PRINT("info",("spider range_res7=%d", range_res)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -5637,15 +5588,9 @@ int ha_spider::pre_multi_range_read_next( DBUG_RETURN(0); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next( range_id_t *range_info ) -#else -int ha_spider::multi_range_read_next( - char **range_info -) -#endif { int error_num; DBUG_ENTER("ha_spider::multi_range_read_next"); @@ -5723,16 +5668,10 @@ int ha_spider::read_multi_range_first( #endif #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int ha_spider::multi_range_read_next_next( range_id_t *range_info ) #else -int ha_spider::multi_range_read_next_next( - char **range_info -) -#endif -#else int ha_spider::read_multi_range_next( KEY_MULTI_RANGE **found_range_p ) @@ -6449,11 +6388,7 @@ int ha_spider::read_multi_range_next( } #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if (bka_mode == 2) { @@ -6574,11 +6509,7 @@ int ha_spider::read_multi_range_next( #endif { #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; -#else - multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; -#endif #endif if ((error_num = spider_db_append_select(this))) DBUG_RETURN(error_num); @@ -9676,19 +9607,10 @@ int ha_spider::write_row( bulk_access_pre_called = FALSE; DBUG_RETURN(spider_db_bulk_bulk_insert(this)); } -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_write_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -9701,11 +9623,6 @@ int ha_spider::write_row( } #ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT ha_statistic_increment(&SSV::ha_write_count); -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) - table->timestamp_field->set_time(); #endif if (!bulk_insert) store_last_insert_id = 0; @@ -9802,21 +9719,12 @@ int ha_spider::pre_write_row( THD *thd = wide_handler->trx->thd; DBUG_ENTER("ha_spider::pre_write_row"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_current->spider->ha_write_row(buf); bulk_access_link_current->spider->bulk_access_pre_called = TRUE; bulk_access_link_current->called = TRUE; -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -9939,20 +9847,11 @@ int ha_spider::update_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_update_row( old_data, new_data); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -9961,11 +9860,6 @@ int ha_spider::update_row( #endif #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS do_direct_update = FALSE; -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) - table->timestamp_field->set_time(); #endif if ((error_num = spider_db_update(this, table, old_data))) DBUG_RETURN(check_error_mode(error_num)); @@ -10111,14 +10005,10 @@ int ha_spider::direct_update_rows_init( direct_update_fields ) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10286,14 +10176,10 @@ int ha_spider::direct_update_rows_init() if (wide_handler->direct_update_fields) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10628,19 +10514,10 @@ int ha_spider::delete_row( bulk_access_link_exec_tgt->called ) { ulonglong option_backup = 0; -#if MYSQL_VERSION_ID < 50500 - option_backup = thd->options; - thd->options &= ~OPTION_BIN_LOG; -#else option_backup = thd->variables.option_bits; thd->variables.option_bits &= ~OPTION_BIN_LOG; -#endif error_num = bulk_access_link_exec_tgt->spider->ha_delete_row(buf); -#if MYSQL_VERSION_ID < 50500 - thd->options = option_backup; -#else thd->variables.option_bits = option_backup; -#endif DBUG_RETURN(error_num); } #endif @@ -10734,14 +10611,10 @@ int ha_spider::direct_delete_rows_init( if (!range_count) { if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -10840,14 +10713,10 @@ int ha_spider::direct_delete_rows_init() wide_handler->cond_check = FALSE; spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif !select_lex || select_lex->table_list.elements != 1 || @@ -15688,13 +15557,8 @@ int ha_spider::bulk_tmp_table_rnd_next() if (tmp_table[roop_count]) { if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 !(error_num = tmp_table[roop_count]->file->ha_rnd_next( tmp_table[roop_count]->record[0])) -#else - !(error_num = tmp_table[roop_count]->file->rnd_next( - tmp_table[roop_count]->record[0])) -#endif ) { DBUG_RETURN(error_num); } diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index 3036f8d522a..b1301d91cab 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -140,11 +140,7 @@ public: bool have_second_range; KEY_MULTI_RANGE mrr_second_range; spider_string *mrr_key_buff; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 range_id_t *multi_range_keys; -#else - char **multi_range_keys; -#endif #else KEY_MULTI_RANGE *multi_range_ranges; #endif @@ -332,7 +328,6 @@ public: void reset_no_where_cond(); bool check_no_where_cond(); #ifdef HA_MRR_USE_DEFAULT_IMPL -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 ha_rows multi_range_read_info_const( uint keyno, RANGE_SEQ_IF *seq, @@ -351,26 +346,6 @@ public: uint *flags, Cost_estimate *cost ); -#else - ha_rows multi_range_read_info_const( - uint keyno, - RANGE_SEQ_IF *seq, - void *seq_init_param, - uint n_ranges, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); - ha_rows multi_range_read_info( - uint keyno, - uint n_ranges, - uint keys, - uint key_parts, - uint *bufsz, - uint *flags, - COST_VECT *cost - ); -#endif int multi_range_read_init( RANGE_SEQ_IF *seq, void *seq_init_param, @@ -378,7 +353,6 @@ public: uint mode, HANDLER_BUFFER *buf ); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 int multi_range_read_next( range_id_t *range_info ); @@ -388,17 +362,6 @@ public: int multi_range_read_next_next( range_id_t *range_info ); -#else - int multi_range_read_next( - char **range_info - ); - int multi_range_read_next_first( - char **range_info - ); - int multi_range_read_next_next( - char **range_info - ); -#endif #else int read_multi_range_first( KEY_MULTI_RANGE **found_range_p, @@ -1251,3 +1214,26 @@ public: void bulk_access_end(); #endif }; + + +/* This is a hack for ASAN + * Libraries such as libxml2 and libodbc do not like being unloaded before + * exit and will show as a leak in ASAN with no stack trace (as the plugin + * has been unloaded from memory). + * + * The below is designed to trick the compiler into adding a "UNIQUE" symbol + * which can be seen using: + * readelf -s storage/spider/ha_spider.so | grep UNIQUE + * + * Having this symbol means that the plugin remains in memory after dlclose() + * has been called. Thereby letting the libraries clean up properly. + */ +#if defined(__SANITIZE_ADDRESS__) +__attribute__((__used__)) +inline int dummy(void) +{ + static int d; + d++; + return d; +} +#endif diff --git a/storage/spider/hs_client/config.cpp b/storage/spider/hs_client/config.cpp index 0003c3fd645..ac5acbccd16 100644 --- a/storage/spider/hs_client/config.cpp +++ b/storage/spider/hs_client/config.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" @@ -228,23 +223,22 @@ config::operator =(const config& x) conf_param *param, *new_param; for(ulong i = 0; i < x.conf_hash.records; i++) { - if ( - (param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i)) && - (new_param = new conf_param()) - ) { - if ( - !new_param->key.copy(param->key) && - !new_param->val.copy(param->val) - ) { - new_param->key.c_ptr_safe(); - new_param->val.c_ptr_safe(); - DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", - new_param->key.ptr(), new_param->val.ptr())); - if (my_hash_insert(&conf_hash, (uchar*) new_param)) + if ((param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i))) + if ((new_param = new conf_param())) + { + if ( + !new_param->key.copy(param->key) && + !new_param->val.copy(param->val) + ) { + new_param->key.c_ptr_safe(); + new_param->val.c_ptr_safe(); + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", + new_param->key.ptr(), new_param->val.ptr())); + if (my_hash_insert(&conf_hash, (uchar*) new_param)) + delete new_param; + } else delete new_param; - } else - delete new_param; - } + } } } DENA_VERBOSE(10, fprintf(stderr, "config operator = end %p", this)); diff --git a/storage/spider/hs_client/config.hpp b/storage/spider/hs_client/config.hpp index 6d85c7e3d7c..88d48cbaaac 100644 --- a/storage/spider/hs_client/config.hpp +++ b/storage/spider/hs_client/config.hpp @@ -11,14 +11,9 @@ #define DENA_CONFIG_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #define DENA_VERBOSE(lv, x) if (dena::verbose_level >= (lv)) { (x); } diff --git a/storage/spider/hs_client/fatal.cpp b/storage/spider/hs_client/fatal.cpp index cfbc14df64a..1ed20189a93 100644 --- a/storage/spider/hs_client/fatal.cpp +++ b/storage/spider/hs_client/fatal.cpp @@ -9,13 +9,8 @@ #include #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "fatal.hpp" diff --git a/storage/spider/hs_client/fatal.hpp b/storage/spider/hs_client/fatal.hpp index 38fc149e98e..859b695baf3 100644 --- a/storage/spider/hs_client/fatal.hpp +++ b/storage/spider/hs_client/fatal.hpp @@ -11,14 +11,9 @@ #define DENA_FATAL_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif namespace dena { diff --git a/storage/spider/hs_client/hs_compat.h b/storage/spider/hs_client/hs_compat.h index fb9b02ad4f0..b12711fa3d1 100644 --- a/storage/spider/hs_client/hs_compat.h +++ b/storage/spider/hs_client/hs_compat.h @@ -16,26 +16,9 @@ #ifndef HS_COMPAT_H #define HS_COMPAT_H -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 #define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ my_init_dynamic_array2(PSI_INSTRUMENT_ME, A, B, C, D, E, F) #define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ init_alloc_root(PSI_INSTRUMENT_ME, A, B, C, D) -#elif defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100213 -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E, F) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, "spider", B, C, D) -#elif defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E, F) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C, D) -#else -#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ - my_init_dynamic_array2(A, B, C, D, E) -#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ - init_alloc_root(A, B, C) -#endif #endif diff --git a/storage/spider/hs_client/hstcpcli.cpp b/storage/spider/hs_client/hstcpcli.cpp index b3dea208f8f..8c3915da9e2 100644 --- a/storage/spider/hs_client/hstcpcli.cpp +++ b/storage/spider/hs_client/hstcpcli.cpp @@ -10,14 +10,9 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "hstcpcli.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/hstcpcli.hpp b/storage/spider/hs_client/hstcpcli.hpp index aac02ce7f46..06044f169a3 100644 --- a/storage/spider/hs_client/hstcpcli.hpp +++ b/storage/spider/hs_client/hstcpcli.hpp @@ -13,13 +13,8 @@ #define HANDLERSOCKET_MYSQL_UTIL 1 #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "config.hpp" #include "socket.hpp" diff --git a/storage/spider/hs_client/socket.cpp b/storage/spider/hs_client/socket.cpp index 9a2ecddedd7..44772433fe7 100644 --- a/storage/spider/hs_client/socket.cpp +++ b/storage/spider/hs_client/socket.cpp @@ -16,16 +16,9 @@ #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 #include -#endif #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "socket.hpp" #include "string_util.hpp" diff --git a/storage/spider/hs_client/socket.hpp b/storage/spider/hs_client/socket.hpp index a3e6527a46d..e4f7530aec9 100644 --- a/storage/spider/hs_client/socket.hpp +++ b/storage/spider/hs_client/socket.hpp @@ -11,13 +11,8 @@ #define DENA_SOCKET_HPP #include "mysql_version.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "auto_addrinfo.hpp" #include "auto_file.hpp" diff --git a/storage/spider/hs_client/string_util.cpp b/storage/spider/hs_client/string_util.cpp index 39934148cb8..647cf877805 100644 --- a/storage/spider/hs_client/string_util.cpp +++ b/storage/spider/hs_client/string_util.cpp @@ -10,13 +10,8 @@ #include #include "mysql_version.h" #include "hs_compat.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" -#endif #include "string_util.hpp" diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result index 4386b4cbd4d..dbf0f54c804 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result @@ -72,7 +72,6 @@ SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argum argument select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote`.`tbl_a` select `pkey`,`val` from `auto_test_remote`.`tbl_a` SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' @@ -86,7 +85,6 @@ argument select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 -select 1 from (select 1) t0 select `pkey`,`val` from `auto_test_remote2`.`tbl_a` SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' SELECT pkey, val FROM tbl_a ORDER BY pkey; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result index 531e48b880b..60ef8e2dea4 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result @@ -66,9 +66,6 @@ id greeting connection child2_1; SELECT argument FROM mysql.general_log WHERE argument LIKE 'select `id`,`greeting` from %'; argument -select `id`,`greeting` from `auto_test_remote`.`tbl_a` where `greeting` = 'Aloha!' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_b` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) -select `id`,`greeting` from `auto_test_remote`.`tbl_c` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) connection child2_1; SET @@global.general_log = @general_log_backup; SET @@global.log_output = @log_output_backup; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result index 7e4fd3cd084..5fd412b69ea 100644 --- a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result @@ -5,6 +5,8 @@ for master_1 for child2 for child3 set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); # testing monitoring_* @@ -173,6 +175,7 @@ max(d) 93 drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; for master_1 for child2 for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result new file mode 100644 index 00000000000..796c75cc560 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result @@ -0,0 +1,4 @@ +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result new file mode 100644 index 00000000000..c021bc70e57 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result @@ -0,0 +1,25 @@ +# +# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +# +for master_1 +for child2 +for child3 +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; +a c +1 1 +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test index a1642f7a9cd..9ccfc3784ef 100644 --- a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test @@ -10,6 +10,9 @@ # This test covers some table params under consideration for inclusion # in the engine-defined options to be implemented in MDEV-28856. set spider_same_server_link=1; +set @old_spider_same_server_link=@@global.spider_same_server_link; +set global spider_same_server_link=1; + evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); @@ -153,6 +156,7 @@ select max(d) from t1; drop table t1, t2; drop server srv; +set global spider_same_server_link=@old_spider_same_server_link; --disable_query_log --disable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test new file mode 100644 index 00000000000..886449716eb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test @@ -0,0 +1,11 @@ +# This test tests spider init with global no_zero_date sql mode +set @old_sql_mode=@@global.sql_mode; +set global sql_mode='traditional'; +install soname 'ha_spider'; +set global sql_mode=@old_sql_mode; + +--disable_query_log +--disable_result_log +--source ../../include/clean_up_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test new file mode 100644 index 00000000000..eee47a21163 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test @@ -0,0 +1,29 @@ +--echo # +--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to () +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM; +CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM; +SET spider_same_server_link= on; +CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER; +CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL +, PRIMARY KEY (`a`) USING BTREE +) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER; +INSERT INTO t1_spider VALUES(1,'oooo'); +INSERT INTO t2_spider VALUES(1,1); +SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1; + +drop table t1, t2, t1_spider, t2_spider; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_case.result b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result new file mode 100644 index 00000000000..613ce377865 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result @@ -0,0 +1,57 @@ +# +# MDEV-28993 Spider: Push down CASE statement +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); +explain select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +case c when 3 then "three" when 42 then "answer" else "other" end +answer +three +other +other +explain select case c when 3 then "three" when 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case c when 3 then "three" when 42 then "answer" end from t1; +case c when 3 then "three" when 42 then "answer" end +answer +three +NULL +NULL +explain select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +case when c = 3 then "three" when c = 42 then "answer" else "other" end +answer +three +other +other +explain select case when c = 3 then "three" when c = 42 then "answer" end from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +case when c = 3 then "three" when c = 42 then "answer" end +answer +three +NULL +NULL +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 +# +# end of test pushdown_case +# diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result new file mode 100644 index 00000000000..3acd89127c0 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result @@ -0,0 +1,111 @@ +# +# MDEV-28992 Spider: Push down TIMESTAMPDIFF function +# +for master_1 +for child2 +for child3 +set spider_same_server_link= 1; +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +); +CREATE TABLE t1 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +INSERT INTO t1 (a, b, c) VALUES +(1, 'a', '2018-11-01 10:21:39'), +(2, 'b', '2015-06-30 23:59:59'), +(3, 'c', '2013-11-01 01:01:01'); +interval year +explain select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(year, '2000-01-01 00:00:00', c) +1 a 18 +2 b 15 +3 c 13 +interval quarter +explain select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(quarter, '2000-01-01 00:00:00', c) +1 a 75 +2 b 61 +3 c 55 +interval month +explain select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(month, '2000-01-01 00:00:00', c) +1 a 226 +2 b 185 +3 c 166 +interval week +explain select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(week, '2000-01-01 00:00:00', c) +1 a 982 +2 b 808 +3 c 721 +interval day +explain select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(day, '2000-01-01 00:00:00', c) +1 a 6879 +2 b 5659 +3 c 5053 +internal hour +explain select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(hour, '2000-01-01 00:00:00', c) +1 a 165106 +2 b 135839 +3 c 121273 +internal minute +explain select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(minute, '2000-01-01 00:00:00', c) +1 a 9906381 +2 b 8150399 +3 c 7276381 +internal second +explain select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(second, '2000-01-01 00:00:00', c) +1 a 594382899 +2 b 489023999 +3 c 436582861 +internal microsecond +explain select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +a b timestampdiff(microsecond, '2000-01-01 00:00:00', c) +1 a 594382899000000 +2 b 489023999000000 +3 c 436582861000000 +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_case.test b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test new file mode 100644 index 00000000000..b86edceb615 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test @@ -0,0 +1,50 @@ +--echo # +--echo # MDEV-28993 Spider: Push down CASE statement +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table t2 (c int); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +insert into t1 values (42), (3), (848), (100); + +# everything +let $query= +select case c when 3 then "three" when 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# no else +let $query= +select case c when 3 then "three" when 42 then "answer" end from t1; +eval explain $query; +eval $query; + +# no value +let $query= +select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1; +eval explain $query; +eval $query; + +# neither +let $query= +select case when c = 3 then "three" when c = 42 then "answer" end from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test pushdown_case +--echo # diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test new file mode 100644 index 00000000000..81251860f74 --- /dev/null +++ b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test @@ -0,0 +1,93 @@ +--echo # +--echo # MDEV-28992 Spider: Push down TIMESTAMPDIFF function +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +set spider_same_server_link= 1; +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +create table t2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +); +CREATE TABLE t1 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; + +INSERT INTO t1 (a, b, c) VALUES + (1, 'a', '2018-11-01 10:21:39'), + (2, 'b', '2015-06-30 23:59:59'), + (3, 'c', '2013-11-01 01:01:01'); + +--echo interval year +let $query= +select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval quarter +let $query= +select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval month +let $query= +select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval week +let $query= +select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo interval day +let $query= +select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal hour +let $query= +select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal minute +let $query= +select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal second +let $query= +select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +--echo internal microsecond +let $query= +select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1; +eval explain $query; +eval $query; + +drop table t1, t2; +drop server srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result index 850546fa1e9..3eed8df28bf 100644 --- a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result +++ b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result @@ -86,10 +86,8 @@ SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argum argument select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 -select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1 SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' SELECT value FROM tbl_a ORDER BY value; value diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 4079b383438..f44515234a4 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -18,17 +18,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_table.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -61,7 +56,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_bin; extern LEX_CSTRING spider_unique_id; pthread_mutex_t spider_conn_id_mutex; pthread_mutex_t spider_ipport_conn_mutex; -ulonglong spider_conn_id = 1; +ulonglong spider_conn_id; #ifndef WITHOUT_SPIDER_BG_SEARCH extern pthread_attr_t spider_pt_attr; @@ -102,7 +97,7 @@ extern sql_mode_t pushdown_sql_mode; HASH spider_open_connections; uint spider_open_connections_id; HASH spider_ipport_conns; -long spider_conn_mutex_id = 0; +long spider_conn_mutex_id; const char *spider_open_connections_func_name; const char *spider_open_connections_file_name; @@ -174,12 +169,8 @@ int spider_conn_init( ) { int error_num = HA_ERR_OUT_OF_MEM; DBUG_ENTER("spider_conn_init"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->loop_check_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn_loop_check, &conn->loop_check_mutex, MY_MUTEX_INIT_FAST)) -#endif { goto error_loop_check_mutex_init; } @@ -891,12 +882,8 @@ SPIDER_CONN *spider_create_conn( else conn->need_mon = need_mon; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -2472,43 +2459,27 @@ int spider_create_conn_thread( DBUG_ENTER("spider_create_conn_thread"); if (conn && !conn->bg_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_chain, &conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_chain_mutex_init; } conn->bg_conn_chain_mutex_ptr = NULL; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn_sync, &conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_conn, &conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_job_stack, &conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_job_stack_mutex_init; @@ -2525,36 +2496,22 @@ int spider_create_conn_thread( conn->bg_job_stack.max_element * conn->bg_job_stack.size_of_element); conn->bg_job_stack_cur_pos = 0; -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn_sync, &conn->bg_conn_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&conn->bg_conn_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_conn, &conn->bg_conn_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } pthread_mutex_lock(&conn->bg_conn_mutex); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&conn->bg_thread, &spider_pt_attr, - spider_bg_conn_action, (void *) conn) - ) -#else if (mysql_thread_create(spd_key_thd_bg, &conn->bg_thread, &spider_pt_attr, spider_bg_conn_action, (void *) conn) ) -#endif { pthread_mutex_unlock(&conn->bg_conn_mutex); error_num = HA_ERR_OUT_OF_MEM; @@ -3555,35 +3512,21 @@ int spider_create_sts_thread( DBUG_ENTER("spider_create_sts_thread"); if (!share->bg_sts_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts, &share->bg_sts_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_sts_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_sync, &share->bg_sts_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_sts_thread, &spider_pt_attr, - spider_bg_sts_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_sts, &share->bg_sts_thread, &spider_pt_attr, spider_bg_sts_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -3922,35 +3865,21 @@ int spider_create_crd_thread( DBUG_ENTER("spider_create_crd_thread"); if (!share->bg_crd_init) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd, &share->bg_crd_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&share->bg_crd_sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_sync, &share->bg_crd_sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_crd_thread, &spider_pt_attr, - spider_bg_crd_action, (void *) share) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crd, &share->bg_crd_thread, &spider_pt_attr, spider_bg_crd_action, (void *) share) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -4369,13 +4298,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_mutex_init(&share->bg_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST) -#else mysql_mutex_init(spd_key_mutex_bg_mon, &share->bg_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4387,12 +4311,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon, &share->bg_mon_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4404,12 +4324,8 @@ int spider_create_mon_threads( { if ( share->monitoring_bg_kind[roop_count] && -#if MYSQL_VERSION_ID < 50500 - pthread_cond_init(&share->bg_mon_sleep_conds[roop_count], NULL) -#else mysql_cond_init(spd_key_cond_bg_mon_sleep, &share->bg_mon_sleep_conds[roop_count], NULL) -#endif ) { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4424,16 +4340,10 @@ int spider_create_mon_threads( { link_pack.link_idx = roop_count; pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&share->bg_mon_threads[roop_count], - &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) - ) -#else if (mysql_thread_create(spd_key_thd_bg_mon, &share->bg_mon_threads[roop_count], &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; my_afree(buf); @@ -4687,17 +4597,9 @@ int spider_conn_first_link_idx( my_afree(link_idxs); DBUG_RETURN(-1); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 DBUG_PRINT("info",("spider server_id=%lu", thd->variables.server_id)); -#else - DBUG_PRINT("info",("spider server_id=%u", thd->server_id)); -#endif DBUG_PRINT("info",("spider thread_id=%lu", thd_get_thread_id(thd))); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); -#else - rand_val = spider_rand(thd->server_id + thd_get_thread_id(thd)); -#endif DBUG_PRINT("info",("spider rand_val=%f", rand_val)); balance_val = (longlong) (rand_val * balance_total); DBUG_PRINT("info",("spider balance_val=%lld", balance_val)); @@ -5225,21 +5127,13 @@ SPIDER_IP_PORT_CONN* spider_create_ipport_conn(SPIDER_CONN *conn) goto err_return_direct; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&ret->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn_i, &ret->mutex, MY_MUTEX_INIT_FAST)) -#endif { //error goto err_malloc_key; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&ret->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_conn_i, &ret->cond, NULL)) -#endif { pthread_mutex_destroy(&ret->mutex); goto err_malloc_key; diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index 520c1f63c05..c2463ce30df 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -18,17 +18,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_base.h" #include "sql_partition.h" #include "transaction.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -307,7 +302,7 @@ int spider_udf_get_copy_tgt_tables( if ( (error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, mem_root)) || + table_tables, tmp_share, mem_root)) || (error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, mem_root)) || (error_num = spider_get_sys_tables_link_idx( @@ -745,13 +740,8 @@ long long spider_copy_tables_body( thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -774,18 +764,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -797,7 +775,6 @@ long long spider_copy_tables_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } @@ -889,9 +866,6 @@ long long spider_copy_tables_body( copy_tables->trx->trx_start = TRUE; copy_tables->trx->updated_in_this_trx = FALSE; DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); -#if MYSQL_VERSION_ID < 50500 - if (open_and_lock_tables(thd, table_list)) -#else MDL_REQUEST_INIT(&table_list->mdl_request, MDL_key::TABLE, SPIDER_TABLE_LIST_db_str(table_list), @@ -900,7 +874,6 @@ long long spider_copy_tables_body( MDL_TRANSACTION ); if (open_and_lock_tables(thd, table_list, FALSE, 0)) -#endif { thd->m_reprepare_observer = reprepare_observer_backup; copy_tables->trx->trx_start = FALSE; @@ -1003,7 +976,12 @@ long long spider_copy_tables_body( all_link_cnt = copy_tables->link_idx_count[0] + copy_tables->link_idx_count[1]; if ( - !(tmp_sql = new spider_string[all_link_cnt]) || + !(tmp_sql = new spider_string[all_link_cnt]) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + if ( !(spider = new ha_spider[all_link_cnt]) ) { my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); @@ -1032,13 +1010,6 @@ long long spider_copy_tables_body( tmp_spider->share = table_conn->share; tmp_spider->wide_handler = wide_handler; wide_handler->trx = copy_tables->trx; -/* - if (spider_db_append_set_names(table_conn->share)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); - goto error_append_set_names; - } -*/ tmp_spider->conns = &table_conn->conn; tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_3); tmp_sql[roop_count].set_charset(copy_tables->access_charset); @@ -1078,13 +1049,6 @@ long long spider_copy_tables_body( tmp_spider->share = table_conn->share; tmp_spider->wide_handler = wide_handler; wide_handler->trx = copy_tables->trx; -/* - if (spider_db_append_set_names(table_conn->share)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); - goto error_append_set_names; - } -*/ tmp_spider->conns = &table_conn->conn; tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_5); tmp_sql[roop_count].set_charset(copy_tables->access_charset); @@ -1111,21 +1075,9 @@ long long spider_copy_tables_body( bulk_insert_rows))) goto error_db_udf_copy_tables; -/* - for (table_conn = copy_tables->table_conn[0]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); - for (table_conn = copy_tables->table_conn[1]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); -*/ if (table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) @@ -1143,8 +1095,7 @@ long long spider_copy_tables_body( } delete [] spider; } - if (tmp_sql) - delete [] tmp_sql; + delete [] tmp_sql; spider_udf_free_copy_tables_alloc(copy_tables); DBUG_RETURN(1); @@ -1152,17 +1103,6 @@ long long spider_copy_tables_body( error_db_udf_copy_tables: error_create_dbton_handler: error_init_dbton_handler: -/* -error_append_set_names: -*/ -/* - for (table_conn = copy_tables->table_conn[0]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); - for (table_conn = copy_tables->table_conn[1]; - table_conn; table_conn = table_conn->next) - spider_db_free_set_names(table_conn->share); -*/ error: if (spider) { @@ -1183,11 +1123,7 @@ error: } if (table_list && table_list->table) { -#if MYSQL_VERSION_ID < 50500 - ha_autocommit_or_rollback(thd, 0); -#else (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); -#endif close_thread_tables(thd); } if (spider) diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 72c84657930..5333b31fcd1 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -33,7 +29,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include "spd_err.h" @@ -72,7 +67,7 @@ pthread_mutex_t spider_open_conn_mutex; const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* UTC time zone for timestamp columns */ -Time_zone *UTC = 0; +Time_zone *UTC; int spider_db_connect( const SPIDER_SHARE *share, @@ -1947,10 +1942,8 @@ int spider_db_append_key_where_internal( DBUG_PRINT("info", ("spider start_key->flag=%d", start_key->flag)); switch (start_key->flag) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 case HA_READ_PREFIX_LAST: result_list->desc_flg = TRUE; -#endif /* fall through */ case HA_READ_KEY_EXACT: if (sql_kind == SPIDER_SQL_KIND_SQL) @@ -2186,12 +2179,6 @@ int spider_db_append_key_where_internal( } #endif break; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - case HA_READ_PREFIX_LAST: - result_list->limit_num = 1; - /* fall through */ -#endif case HA_READ_KEY_OR_PREV: case HA_READ_PREFIX_LAST_OR_PREV: result_list->desc_flg = TRUE; @@ -3057,13 +3044,8 @@ int spider_db_get_row_from_tmp_tbl( current->result_tmp_tbl_inited = 1; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = current->result_tmp_tbl->file->ha_rnd_next( current->result_tmp_tbl->record[0])) -#else - (error_num = current->result_tmp_tbl->file->rnd_next( - current->result_tmp_tbl->record[0])) -#endif ) { DBUG_RETURN(error_num); } @@ -3091,13 +3073,8 @@ int spider_db_get_row_from_tmp_tbl_pos( result->result_tmp_tbl_inited = 2; } if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = tmp_tbl->file->ha_rnd_pos(tmp_tbl->record[0], (uchar *) &pos->tmp_tbl_pos)) -#else - (error_num = tmp_tbl->file->rnd_pos(tmp_tbl->record[0], - (uchar *) &pos->tmp_tbl_pos)) -#endif ) { DBUG_RETURN(error_num); } @@ -7076,11 +7053,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { if ( spider->check_partitioned() && @@ -7109,11 +7082,7 @@ int spider_db_update_auto_increment( if ( table->s->next_number_keypart == 0 && mysql_bin_log.is_open() && -#if MYSQL_VERSION_ID < 50500 - !thd->current_stmt_binlog_row_based -#else !thd->is_current_stmt_binlog_format_row() -#endif ) { for (roop_count = 0; roop_count < (int) affected_rows; roop_count++) push_warning_printf(thd, SPIDER_WARN_LEVEL_NOTE, @@ -7352,9 +7321,7 @@ int spider_db_update( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->wide_handler->ignore_dup_key; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) @@ -9498,11 +9465,7 @@ int spider_db_print_item_type_default( { if (spider->share->access_charset->cset == system_charset_info->cset) { -#if MYSQL_VERSION_ID < 50500 - item->print(str->get_str(), QT_IS); -#else item->print(str->get_str(), QT_TO_SYSTEM_CHARSET); -#endif } else { item->print(str->get_str(), QT_ORDINARY); } @@ -10699,13 +10662,8 @@ int spider_db_udf_direct_sql( spider_param_ping_interval_at_trx_start(thd); time_t tmp_time = (time_t) time((time_t*) 0); bool need_trx_end, need_all_commit, insert_start = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else enum_sql_command sql_command_backup; -#endif DBUG_ENTER("spider_db_udf_direct_sql"); -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { if (spider_sys_open_and_lock_tables(c_thd, &direct_sql->table_list_first, @@ -10724,7 +10682,6 @@ int spider_db_udf_direct_sql( direct_sql->open_tables_thd = c_thd; roop_count = 0; } -#endif if (c_thd != thd) { @@ -10732,21 +10689,15 @@ int spider_db_udf_direct_sql( need_trx_end = TRUE; } else { need_all_commit = FALSE; -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used) { need_trx_end = TRUE; } else { -#endif if (c_thd->transaction->stmt.ha_list) need_trx_end = FALSE; else need_trx_end = TRUE; -#if MYSQL_VERSION_ID < 50500 -#else } -#endif } if (!conn->disable_reconnect) @@ -10766,11 +10717,8 @@ int spider_db_udf_direct_sql( DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); } -#if MYSQL_VERSION_ID < 50500 -#else sql_command_backup = c_thd->lex->sql_command; c_thd->lex->sql_command = SQLCOM_INSERT; -#endif pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); @@ -10796,10 +10744,7 @@ int spider_db_udf_direct_sql( if ((error_num = conn->db_conn->append_sql( direct_sql->sql, direct_sql->sql_length, &request_key))) { -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } } @@ -10873,9 +10818,6 @@ int spider_db_udf_direct_sql( for (; roop_count2 < set_off; roop_count2++) bitmap_clear_bit(table->write_set, (uint) roop_count2); -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { THR_LOCK_DATA *to[2]; table->file->store_lock(table->in_use, to, @@ -10886,8 +10828,6 @@ int spider_db_udf_direct_sql( table->file->print_error(error_num, MYF(0)); break; } -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10909,7 +10849,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } if (direct_sql->iop) @@ -10971,13 +10910,8 @@ int spider_db_udf_direct_sql( else if (direct_sql->iop[roop_count] == 2) table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); } -#if MYSQL_VERSION_ID < 50500 - if (table->file->has_transactions()) -#endif { table->file->ha_external_unlock(table->in_use); -#if MYSQL_VERSION_ID < 50500 -#else if ( table->s->tmp_table == NO_TMP_TABLE && table->pos_in_table_list @@ -10993,7 +10927,6 @@ int spider_db_udf_direct_sql( next_tables = next_tables->next_global; } } -#endif } table->file->ha_reset(); table->in_use = thd; @@ -11056,10 +10989,7 @@ int spider_db_udf_direct_sql( } } } -#if MYSQL_VERSION_ID < 50500 -#else c_thd->lex->sql_command = sql_command_backup; -#endif DBUG_RETURN(error_num); } diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index e5b4607d6b0..97cc8e60091 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -17,14 +17,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_analyse.h" -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #include "spd_err.h" @@ -3188,14 +3183,13 @@ int spider_db_handlersocket_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3267,9 +3261,6 @@ int spider_db_handlersocket_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { @@ -3313,11 +3304,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3453,11 +3440,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3611,11 +3594,7 @@ int spider_db_handlersocket_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3750,11 +3729,7 @@ int spider_db_handlersocket_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc index aebd5ac91b6..f604a930963 100644 --- a/storage/spider/spd_db_include.cc +++ b/storage/spider/spd_db_include.cc @@ -18,14 +18,9 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" -#endif #include "sql_common.h" #include #include diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index cfeac844bf4..4c7fb23c85c 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -28,56 +28,31 @@ #define SPIDER_DB_WRAPPER_MYSQL "mysql" #define SPIDER_DB_WRAPPER_MARIADB "mariadb" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204 #define PLUGIN_VAR_CAN_MEMALLOC /* -#define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define HASH_UPDATE_WITH_HASH_VALUE */ -#else -#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS -#define HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE #define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE #define SPIDER_HAS_SHOW_SIMPLE_FUNC #define SPIDER_HAS_JT_HASH_INDEX_MERGE #define SPIDER_HAS_EXPR_CACHE_ITEM -#else -#define SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100007 #define SPIDER_ITEM_HAS_CMP_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_HAS_TIME_STATUS #define SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100014 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY_AND_THDPTR -#endif -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_HAS_GROUP_BY_HANDLER -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_ORDER_HAS_ENUM_ORDER -#endif -#if defined(MARIADB_BASE_VERSION) #define SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR #define SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR -#endif class spider_db_conn; typedef spider_db_conn SPIDER_DB_CONN; @@ -139,7 +114,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_HS_LTEQUAL_STR "<=" #define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1) -#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC #define SPIDER_SQL_CASE_STR "case " #define SPIDER_SQL_CASE_LEN (sizeof(SPIDER_SQL_CASE_STR) - 1) #define SPIDER_SQL_WHEN_STR " when " @@ -150,7 +124,6 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_ELSE_LEN (sizeof(SPIDER_SQL_ELSE_STR) - 1) #define SPIDER_SQL_END_STR " end" #define SPIDER_SQL_END_LEN (sizeof(SPIDER_SQL_END_STR) - 1) -#endif #define SPIDER_SQL_USING_STR " using " #define SPIDER_SQL_USING_LEN (sizeof(SPIDER_SQL_USING_STR) - 1) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 17a9da05079..3d0bc8bf29c 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -32,7 +28,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #include "sql_common.h" #include #include @@ -824,11 +819,7 @@ int spider_db_mbase_result::fetch_table_status( int error_num; MYSQL_ROW mysql_row; MYSQL_TIME mysql_time; -#ifdef MARIADB_BASE_VERSION uint not_used_uint; -#else - my_bool not_used_my_bool; -#endif #ifdef SPIDER_HAS_TIME_STATUS MYSQL_TIME_STATUS time_status; #else @@ -906,13 +897,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[11], strlen(mysql_row[11]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -931,13 +917,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[12], strlen(mysql_row[12]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifndef DBUG_OFF @@ -956,13 +937,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[13], strlen(mysql_row[13]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1035,13 +1011,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[6], strlen(mysql_row[6]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.create_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1060,13 +1031,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[7], strlen(mysql_row[7]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.update_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1085,13 +1051,8 @@ int spider_db_mbase_result::fetch_table_status( #endif SPIDER_str_to_datetime(mysql_row[8], strlen(mysql_row[8]), &mysql_time, 0, &time_status); -#ifdef MARIADB_BASE_VERSION stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, ¬_used_long, ¬_used_uint); -#else - stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, - ¬_used_long, ¬_used_my_bool); -#endif } else stat.check_time = (time_t) 0; #ifdef DBUG_TRACE @@ -1240,7 +1201,7 @@ int spider_db_mbase_result::fetch_table_cardinality( uint num_fields = this->num_fields(); if (num_fields < 12 || num_fields > 14) { - DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 13")); + DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 14")); DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); } @@ -2428,11 +2389,7 @@ int spider_db_mbase::next_result() strmov(db_conn->net.sqlstate, "00000"); db_conn->affected_rows = ~(my_ulonglong) 0; -#if MYSQL_VERSION_ID < 50500 - if (db_conn->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) -#else if (db_conn->server_status & SERVER_MORE_RESULTS_EXISTS) -#endif { if ((status = db_conn->methods->read_query_result(db_conn)) > 0) DBUG_RETURN(spider_db_errorno(conn)); @@ -2446,11 +2403,7 @@ uint spider_db_mbase::affected_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::affected_rows"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->affected_rows); } @@ -2459,11 +2412,7 @@ uint spider_db_mbase::matched_rows() MYSQL *last_used_con; DBUG_ENTER("spider_db_mysql::matched_rows"); DBUG_PRINT("info", ("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Rows matched: 65 Changed: 65 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2488,11 +2437,7 @@ bool spider_db_mbase::inserted_info( { DBUG_RETURN(TRUE); } -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif /* Records: 10 Duplicates: 4 Warnings: 0 */ const char *info = last_used_con->info; if (!info) @@ -2534,11 +2479,7 @@ ulonglong spider_db_mbase::last_insert_id() MYSQL *last_used_con; DBUG_ENTER("spider_db_mbase::last_insert_id"); DBUG_PRINT("info",("spider this=%p", this)); -#if MYSQL_VERSION_ID < 50500 - last_used_con = db_conn->last_used_con; -#else last_used_con = db_conn; -#endif DBUG_RETURN((uint) last_used_con->insert_id); } @@ -5613,14 +5554,6 @@ int spider_db_mbase_util::open_item_func( alias_length, use_fields, fields)); } -static bool item_func_is_timestampdiff( - const char *func_name, - int func_name_length -) { - return func_name_length == 13 && - !strncasecmp("timestampdiff", func_name, func_name_length); -} - static bool not_func_should_be_skipped( Item_func *item_func ){ @@ -5690,16 +5623,10 @@ int spider_db_mbase_util::check_item_func( Item_func::Functype func_type = item_func->functype(); DBUG_PRINT("info",("spider functype = %d", func_type)); - const char *func_name = (char*) item_func->func_name(); - int func_name_length = strlen(func_name); - DBUG_PRINT("info",("spider func_name = %s", func_name)); - /* The blacklist of the functions that cannot be pushed down */ switch (func_type) { case Item_func::TRIG_COND_FUNC: - case Item_func::CASE_SEARCHED_FUNC: - case Item_func::CASE_SIMPLE_FUNC: DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::NOT_FUNC: /* Why the following check is necessary? */ @@ -5708,13 +5635,6 @@ int spider_db_mbase_util::check_item_func( break; case Item_func::FUNC_SP: case Item_func::UDF_FUNC: - /* Notes on merging regarding MDEV-29447: please refer to the - following commits for build error or merge conflicts: - 10.6: 1ed20b993b0dd4e95450cab2e8347e5bf4617a69 - 10.9: dd316b6e20265cfd832bb5585cb4c96e716387c8 - 10.10-11: 3f67f110ba1b23a89c5ede0fbeeb203cf5e164f4 - 11.0-1: 17ba6748afa8834df5658361088e6c8e65aca16f - Please remove this comment after merging. */ use_pushdown_udf= spider_param_use_pushdown_udf( spider->wide_handler->trx->thd, spider->share->use_pushdown_udf); if (!use_pushdown_udf) @@ -5724,12 +5644,18 @@ int spider_db_mbase_util::check_item_func( if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); break; -#ifndef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC - case Item_func::UNKNOWN_FUNC: - if (item_func_is_timestampdiff(func_name, func_name_length)) - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); - break; -#endif + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->wide_handler->trx->thd, SPIDER_WARN_LEVEL_WARN, + ER_INTERNAL_ERROR, + ER_THD(spider->wide_handler->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: break; } @@ -5771,7 +5697,7 @@ int spider_db_mbase_util::print_item_func( Item *item, **item_list = item_func->arguments(); Field *field; spider_string tmp_str; - uint roop_count, item_count = item_func->argument_count(), start_item = 0; + uint i, item_count = item_func->argument_count(), start_item = 0; LEX_CSTRING org_func_name= {SPIDER_SQL_NULL_CHAR_STR, SPIDER_SQL_NULL_CHAR_LEN}; const char *func_name = SPIDER_SQL_NULL_CHAR_STR, @@ -5780,8 +5706,8 @@ int spider_db_mbase_util::print_item_func( int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, separator_str_length = SPIDER_SQL_NULL_CHAR_LEN, last_str_length = SPIDER_SQL_NULL_CHAR_LEN; - int use_pushdown_udf; - bool merge_func = FALSE; + int use_pushdown_udf, case_when_start, case_when_count; + bool merge_func = FALSE, case_with_else; DBUG_ENTER("spider_db_mbase_util::print_item_func"); DBUG_ASSERT(!check_item_func(item_func, spider, alias, alias_length, use_fields, fields)); @@ -6099,12 +6025,11 @@ int spider_db_mbase_util::print_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -6155,7 +6080,7 @@ int spider_db_mbase_util::print_item_func( str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); str->q_append(interval_str, interval_len); str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); - + if ((error_num = spider_db_print_item_type(item_list[0], NULL, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); @@ -6176,9 +6101,6 @@ int spider_db_mbase_util::print_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { @@ -6671,7 +6593,83 @@ int spider_db_mbase_util::print_item_func( DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); case Item_func::CASE_SEARCHED_FUNC: case Item_func::CASE_SIMPLE_FUNC: - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + /* + Arrangement of arguments: + - Item_func_case_searched: + when1 when2 ... whenk then1 then2 .. thenk [else] + - Item_func_case_simple: + value when1 when2 ... whenk then1 then2 .. thenk [else] + */ + if (item_func->functype() == Item_func::CASE_SEARCHED_FUNC) + { + case_when_start= 0; + case_when_count= item_count / 2; + case_with_else= item_count % 2; + } + else + { + case_when_start= 1; + case_when_count= (item_count - 1) / 2; + case_with_else= item_count % 2 == 0; + } + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (case_when_start > 0) + { + if ((error_num = spider_db_print_item_type( + item_list[0], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + for (i = 0; i < (uint) case_when_count; i++) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[i + case_when_start], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[i + case_when_start + case_when_count], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (case_with_else) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_count - 1], NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); case Item_func::JSON_EXTRACT_FUNC: func_name = (char*) item_func->func_name(); func_name_length = strlen(func_name); @@ -6686,6 +6684,18 @@ int spider_db_mbase_util::print_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; + case Item_func::MULT_EQUAL_FUNC: + /* If there is still Item_equal by the time of + JOIN::make_aggr_tables_info() where the spider group by handler + is created, it indicates a bug in the optimizer, because there + shouldn't be any. */ + push_warning_printf( + spider->wide_handler->trx->thd, + SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR, + ER_THD(spider->wide_handler->trx->thd, ER_INTERNAL_ERROR), + "Spider group by handler: Encountered multiple equalities, likely " + "an optimizer bug"); + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); default: THD *thd = spider->wide_handler->trx->thd; SPIDER_SHARE *share = spider->share; @@ -6715,13 +6725,13 @@ int spider_db_mbase_util::print_item_func( Loop through the items of the current function expression to print its portion of the statement */ - for (roop_count = start_item; roop_count < item_count; roop_count++) + for (i = start_item; i < item_count; i++) { - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); - if (roop_count == 1) + if (i == 1) { /* Remaining operands need to be preceded by the separator */ func_name = separator_str; @@ -6735,7 +6745,7 @@ int spider_db_mbase_util::print_item_func( } /* Print the last operand value */ - item = item_list[roop_count]; + item = item_list[i]; if ((error_num = spider_db_print_item_type(item, field, spider, str, alias, alias_length, dbton_id, use_fields, fields))) DBUG_RETURN(error_num); @@ -7375,11 +7385,9 @@ int spider_mbase_share::init() DBUG_RETURN(HA_ERR_OUT_OF_MEM); } - if (keys > 0 && - !(key_hint = new spider_string[keys]) - ) { - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } + if (keys > 0) + if (!(key_hint = new spider_string[keys])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); for (roop_count = 0; roop_count < keys; roop_count++) { key_hint[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_INIT_2); @@ -7387,12 +7395,12 @@ int spider_mbase_share::init() } DBUG_PRINT("info",("spider key_hint=%p", key_hint)); - if ( - !(table_select = new spider_string[1]) || - (keys > 0 && - !(key_select = new spider_string[keys]) - ) || - (error_num = create_table_names_str()) || + if (!(table_select = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (keys > 0) + if (!(key_select = new spider_string[keys])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if ((error_num = create_table_names_str()) || (table_share && ( (error_num = create_column_name_str()) || @@ -7543,11 +7551,18 @@ int spider_mbase_share::create_table_names_str() table_names_str = NULL; db_names_str = NULL; db_table_str = NULL; - if ( - !(table_names_str = new spider_string[spider_share->all_link_count]) || - !(db_names_str = new spider_string[spider_share->all_link_count]) || - !(db_table_str = new spider_string[spider_share->all_link_count]) - ) { + if (!(table_names_str = new spider_string[spider_share->all_link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (!(db_names_str = new spider_string[spider_share->all_link_count])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (!(db_table_str = new spider_string[spider_share->all_link_count])) + { error_num = HA_ERR_OUT_OF_MEM; goto error; } @@ -7698,11 +7713,9 @@ int spider_mbase_share::create_column_name_str() Field **field; TABLE_SHARE *table_share = spider_share->table_share; DBUG_ENTER("spider_mbase_share::create_column_name_str"); - if ( - table_share->fields && - !(column_name_str = new spider_string[table_share->fields]) - ) - DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (table_share->fields) + if (!(column_name_str = new spider_string[table_share->fields])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); for (field = table_share->field, str = column_name_str; *field; field++, str++) { @@ -13319,11 +13332,7 @@ int spider_mbase_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_mbase_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index a5b46710418..5d00c5a570a 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_partition.h" @@ -29,7 +25,6 @@ #ifdef HANDLER_HAS_DIRECT_AGGREGATE #include "sql_select.h" #endif -#endif #ifdef HAVE_ORACLE_OCI #if (defined(WIN32) || defined(_WIN32) || defined(WINDOWS) || defined(_WINDOWS)) @@ -3436,14 +3431,13 @@ int spider_db_oracle_util::open_item_func( alias, alias_length, dbton_id, use_fields, fields)); } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) { -#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC Item_func_timestamp_diff *item_func_timestamp_diff = (Item_func_timestamp_diff *) item_func; if (str) { const char *interval_str; uint interval_len; - switch (item_func_timestamp_diff->int_type) + switch (item_func_timestamp_diff->get_int_type()) { case INTERVAL_YEAR: interval_str = SPIDER_SQL_YEAR_STR; @@ -3515,9 +3509,6 @@ int spider_db_oracle_util::open_item_func( SPIDER_SQL_CLOSE_PAREN_LEN); } DBUG_RETURN(0); -#else - DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); -#endif } } else if (func_name_length == 14) { @@ -3561,11 +3552,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3701,11 +3688,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -3995,11 +3978,7 @@ int spider_db_oracle_util::open_item_func( DBUG_RETURN(HA_ERR_OUT_OF_MEM); str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); } -#if MYSQL_VERSION_ID < 50500 - item_func->print(tmp_str.get_str(), QT_IS); -#else item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); -#endif tmp_str.mem_calc(); if (tmp_str.reserve(1)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); @@ -4135,11 +4114,7 @@ int spider_db_oracle_util::open_item_func( last_str = SPIDER_SQL_CLOSE_PAREN_STR; last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; break; -#ifdef MARIADB_BASE_VERSION case Item_func::XOR_FUNC: -#else - case Item_func::COND_XOR_FUNC: -#endif if (str) str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); DBUG_RETURN( @@ -10488,11 +10463,7 @@ int spider_oracle_handler::bulk_tmp_table_rnd_next() int error_num; DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_next"); DBUG_PRINT("info",("spider this=%p", this)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); -#else - error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); -#endif if (!error_num) { error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index 423a4b62fbf..de40930f117 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" @@ -29,7 +25,6 @@ #include "sql_base.h" #include "sql_servers.h" #include "tztime.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -44,9 +39,7 @@ #include "spd_udf.h" #include "spd_malloc.h" -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE -#endif extern const char **spd_defaults_extra_file; extern const char **spd_defaults_file; @@ -115,21 +108,6 @@ int spider_udf_direct_sql_create_table_list( } else break; } -#if MYSQL_VERSION_ID < 50500 - if (!(direct_sql->db_names = (char**) - spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_1, MYF(MY_WME | MY_ZEROFILL), - &direct_sql->db_names, (uint) (sizeof(char*) * table_count), - &direct_sql->table_names, (uint) (sizeof(char*) * table_count), - &direct_sql->tables, (uint) (sizeof(TABLE*) * table_count), - &tmp_name_ptr, (uint) (sizeof(char) * ( - table_name_list_length + - thd->db_length * table_count + - 2 * table_count - )), - &direct_sql->iop, (uint) (sizeof(int) * table_count), - NullS)) - ) -#else if (!(direct_sql->db_names = (char**) spider_bulk_malloc(spider_current_trx, SPD_MID_UDF_DIRECT_SQL_CREATE_TABLE_LIST_2, MYF(MY_WME | MY_ZEROFILL), &direct_sql->db_names, (uint) (sizeof(char*) * table_count), @@ -146,7 +124,6 @@ int spider_udf_direct_sql_create_table_list( (uint) (sizeof(uchar) * ((table_count + 7) / 8)), NullS)) ) -#endif DBUG_RETURN(HA_ERR_OUT_OF_MEM); tmp_ptr = table_name_list; @@ -635,12 +612,8 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn( } #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_mta_conn_mutex_init; @@ -1142,10 +1115,7 @@ static void spider_minus_1(SPIDER_DIRECT_SQL *direct_sql) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) direct_sql->access_mode = -1; #endif -#if MYSQL_VERSION_ID < 50500 -#else direct_sql->use_real_table = -1; -#endif direct_sql->error_rw_mode = -1; for (int i = 0; i < direct_sql->table_count; i++) direct_sql->iop[i] = -1; @@ -1216,10 +1186,7 @@ int spider_udf_parse_direct_sql_param( SPIDER_PARAM_STR("srv", server_name); SPIDER_PARAM_INT_WITH_MAX("svc", tgt_ssl_vsc, 0, 1); SPIDER_PARAM_INT_WITH_MAX("tlm", table_loop_mode, 0, 2); -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("urt", use_real_table, 0, 1); -#endif SPIDER_PARAM_INT("wto", net_write_timeout, 0); error_num= parse.fail(true); goto error; @@ -1272,10 +1239,7 @@ int spider_udf_parse_direct_sql_param( error_num= parse.fail(true); goto error; case 14: -#if MYSQL_VERSION_ID < 50500 -#else SPIDER_PARAM_INT_WITH_MAX("use_real_table", use_real_table, 0, 1); -#endif error_num= parse.fail(true); goto error; case 15: @@ -1583,14 +1547,11 @@ void spider_udf_free_direct_sql_alloc( pthread_mutex_unlock(direct_sql->bg_mutex); } #endif -#if MYSQL_VERSION_ID < 50500 -#else if (direct_sql->real_table_used && direct_sql->open_tables_thd) { spider_sys_close_table(direct_sql->open_tables_thd, &direct_sql->open_tables_backup); } -#endif if (direct_sql->server_name) { spider_free(spider_current_trx, direct_sql->server_name, MYF(0)); @@ -1686,11 +1647,8 @@ long long spider_direct_sql_body( char *sql; TABLE_LIST table_list; SPIDER_BG_DIRECT_SQL *bg_direct_sql; -#if MYSQL_VERSION_ID < 50500 -#else TABLE_LIST *real_table_list_last = NULL; uint use_real_table = 0; -#endif DBUG_ENTER("spider_direct_sql_body"); SPIDER_BACKUP_DASTATUS; if (!(direct_sql = (SPIDER_DIRECT_SQL *) @@ -1781,11 +1739,8 @@ long long spider_direct_sql_body( #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } #endif -#if MYSQL_VERSION_ID < 50500 -#else use_real_table = spider_param_udf_ds_use_real_table(thd, direct_sql->use_real_table); -#endif for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) { #ifdef SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE @@ -1816,19 +1771,14 @@ long long spider_direct_sql_body( if (!(direct_sql->tables[roop_count] = spider_find_temporary_table(thd, &table_list))) { -#if MYSQL_VERSION_ID < 50500 -#else if (!use_real_table) { -#endif error_num = ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM; my_printf_error(ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM, ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR, MYF(0), SPIDER_TABLE_LIST_db_str(&table_list), SPIDER_TABLE_LIST_table_name_str(&table_list)); goto error; -#if MYSQL_VERSION_ID < 50500 -#else } TABLE_LIST *tables = &direct_sql->table_list[roop_count]; MDL_REQUEST_INIT(&tables->mdl_request, MDL_key::TABLE, @@ -1844,7 +1794,6 @@ long long spider_direct_sql_body( real_table_list_last = tables; spider_set_bit(direct_sql->real_table_bitmap, roop_count); direct_sql->real_table_used = TRUE; -#endif } } if ((error_num = spider_udf_direct_sql_create_conn_key(direct_sql))) @@ -1961,22 +1910,14 @@ my_bool spider_direct_sql_init_body( strcpy(message, "spider_bg_direct_sql() out of memory"); goto error; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_direct_sql, &bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&bg_direct_sql->bg_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_direct_sql, &bg_direct_sql->bg_cond, NULL)) -#endif { strcpy(message, "spider_bg_direct_sql() out of memory"); goto error_cond_init; diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h index 320b0edeb30..826362d24c4 100644 --- a/storage/spider/spd_environ.h +++ b/storage/spider/spd_environ.h @@ -20,42 +20,27 @@ #ifndef SPD_ENVIRON_INCLUDED -#if (defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000) #define SPIDER_HANDLER_START_BULK_INSERT_HAS_FLAGS -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE #define SPIDER_NET_HAS_THD -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100211 #define HANDLER_HAS_TOP_TABLE_FIELDS #define HANDLER_HAS_DIRECT_UPDATE_ROWS #define HANDLER_HAS_DIRECT_AGGREGATE -#define PARTITION_HAS_GET_CHILD_HANDLERS #define PARTITION_HAS_GET_PART_SPEC #define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN #define HANDLER_HAS_NEED_INFO_FOR_AUTO_INC #define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100300 #define SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100309 #define SPIDER_MDEV_16246 -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_USE_CONST_ITEM_FOR_STRING_INT_REAL_DECIMAL_DATE_ITEM #define SPIDER_SQL_CACHE_IS_IN_LEX #define SPIDER_LIKE_FUNC_HAS_GET_NEGATED #define HA_HAS_CHECKSUM_EXTENDED -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 #define SPIDER_I_S_USE_SHOW_FOR_COLUMN -#endif #endif /* SPD_ENVIRON_INCLUDED */ diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index b260bde8b57..b01a57d42e5 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -18,17 +18,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_select.h" #include "ha_partition.h" -#endif #include "sql_common.h" #include #include "spd_err.h" @@ -1441,38 +1436,32 @@ group_by_handler *spider_create_group_by_handler( break; } -#ifdef WITH_PARTITION_STORAGE_ENGINE from = query->from; do { DBUG_PRINT("info",("spider from=%p", from)); ++table_count; +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { DBUG_PRINT("info",("spider partition handler")); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) partition_info *part_info = from->table->part_info; uint bits = bitmap_bits_set(&part_info->read_partitions); DBUG_PRINT("info",("spider bits=%u", bits)); if (bits != 1) { DBUG_PRINT("info",("spider using multiple partitions is not supported by this feature yet")); -#else - DBUG_PRINT("info",("spider partition is not supported by this feature yet")); -#endif DBUG_RETURN(NULL); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } -#endif } - } while ((from = from->next_local)); #endif + } while ((from = from->next_local)); if (!(table_holder= spider_create_table_holder(table_count))) DBUG_RETURN(NULL); table_idx = 0; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1481,9 +1470,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1507,7 +1494,7 @@ group_by_handler *spider_create_group_by_handler( } while ((from = from->next_local)) { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1516,9 +1503,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1549,7 +1534,7 @@ group_by_handler *spider_create_group_by_handler( from = query->from; do { -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1558,9 +1543,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1692,7 +1675,7 @@ group_by_handler *spider_create_group_by_handler( goto skip_free_table_holder; from = query->from; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1701,9 +1684,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; @@ -1771,7 +1752,7 @@ group_by_handler *spider_create_group_by_handler( { fields->clear_conn_holder_from_conn(); -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) +#ifdef WITH_PARTITION_STORAGE_ENGINE if (from->table->part_info) { partition_info *part_info = from->table->part_info; @@ -1780,9 +1761,7 @@ group_by_handler *spider_create_group_by_handler( handler **handlers = partition->get_child_handlers(); spider = (ha_spider *) handlers[part]; } else { -#endif spider = (ha_spider *) from->table->file; -#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) } #endif share = spider->share; diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc index 24000f3e6c1..22cd8eb0f15 100644 --- a/storage/spider/spd_i_s.cc +++ b/storage/spider/spd_i_s.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_show.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_table.h" @@ -162,12 +157,9 @@ struct st_mysql_plugin spider_i_s_alloc_mem = NULL, NULL, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }; -#ifdef MARIADB_BASE_VERSION struct st_maria_plugin spider_i_s_alloc_mem_maria = { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -184,7 +176,6 @@ struct st_maria_plugin spider_i_s_alloc_mem_maria = "1.0", MariaDB_PLUGIN_MATURITY_STABLE, }; -#endif extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; @@ -286,12 +277,9 @@ struct st_mysql_plugin spider_i_s_wrapper_protocols = NULL, NULL, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }; -#ifdef MARIADB_BASE_VERSION struct st_maria_plugin spider_i_s_wrapper_protocols_maria = { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -308,4 +296,3 @@ struct st_maria_plugin spider_i_s_wrapper_protocols_maria = "1.0", MariaDB_PLUGIN_MATURITY_STABLE, }; -#endif diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 25cef483fd0..f0567ee5a9e 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -17,11 +17,6 @@ #define SPIDER_DETAIL_VERSION "3.3.15" #define SPIDER_HEX_VERSION 0x0303 -#if MYSQL_VERSION_ID < 50500 -#define spider_my_free(A,B) my_free(A,B) -#define pthread_mutex_assert_owner(A) -#define pthread_mutex_assert_not_owner(A) -#else #define spider_my_free(A,B) my_free(A) #ifdef pthread_mutex_t #undef pthread_mutex_t @@ -70,129 +65,50 @@ #endif #define pthread_cond_destroy mysql_cond_destroy #define my_sprintf(A,B) sprintf B -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004 #define spider_stmt_da_message(A) thd_get_error_message(A) #define spider_stmt_da_sql_errno(A) thd_get_error_number(A) #define spider_user_defined_key_parts(A) (A)->user_defined_key_parts #define spider_join_table_count(A) (A)->table_count #define SPIDER_CAN_BG_UPDATE (1LL << 39) -#if MYSQL_VERSION_ID >= 100304 #define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD #define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP #define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE #define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE #define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG #define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD -#else -#define SPIDER_ALTER_PARTITION_ADD Alter_info::ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP Alter_info::ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE Alter_info::ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE Alter_info::ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG Alter_info::ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD Alter_info::ALTER_REBUILD_PARTITION -#endif #define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN #define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE #define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION -#else -#if MYSQL_VERSION_ID < 50500 -#define spider_stmt_da_message(A) (A)->main_da.message() -#define spider_stmt_da_sql_errno(A) (A)->main_da.sql_errno() -#else -#if MYSQL_VERSION_ID < 50600 -#define spider_stmt_da_message(A) (A)->stmt_da->message() -#define spider_stmt_da_sql_errno(A) (A)->stmt_da->sql_errno() -#else -#define spider_stmt_da_message(A) (A)->get_stmt_da()->message() -#define spider_stmt_da_sql_errno(A) (A)->get_stmt_da()->sql_errno() -#endif -#endif -#define spider_user_defined_key_parts(A) (A)->key_parts -#define spider_join_table_count(A) (A)->tables -#define SPIDER_ALTER_PARTITION_ADD ALTER_ADD_PARTITION -#define SPIDER_ALTER_PARTITION_DROP ALTER_DROP_PARTITION -#define SPIDER_ALTER_PARTITION_COALESCE ALTER_COALESCE_PARTITION -#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_REORGANIZE_PARTITION -#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_TABLE_REORG -#define SPIDER_ALTER_PARTITION_REBUILD ALTER_REBUILD_PARTITION -#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN -#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE -#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100005 #define SPIDER_HAS_EXPLAIN_QUERY -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009 #define SPIDER_TEST(A) MY_TEST(A) -#else -#define SPIDER_TEST(A) test(A) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100 #define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR #define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #define SPIDER_XID_USES_xid_cache_iterate -#else -#define SPIDER_XID_STATE_HAS_in_thd -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 #define SPIDER_Item_args_arg_count_IS_PROTECTED -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100112 #define SPIDER_Item_func_conv_charset_conv_charset collation.collation -#else -#define SPIDER_Item_func_conv_charset_conv_charset conv_charset -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 #define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT #define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H) #define SPIDER_HAS_NEXT_THREAD_ID #define SPIDER_new_THD(A) (new THD(A)) #define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC) -#else -#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,F,G,H) -#define SPIDER_new_THD(A) (new THD()) -#define SPIDER_order_direction_is_asc(A) (A->asc) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100201 #define SPIDER_HAS_MY_CHARLEN #define SPIDER_open_temporary_table -#endif -#if defined(MARIADB_BASE_VERSION) -#if MYSQL_VERSION_ID >= 100209 #define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G) -#elif MYSQL_VERSION_ID >= 100200 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,D,E,F,G,H) -#elif MYSQL_VERSION_ID >= 100007 -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G,H) -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G) -#endif -#else -#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100209 #define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F) #define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F) #define SPIDER_free_part_syntax(A,B) -#else -#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,C,D,E,F) -#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,C,D,E,F) -#define SPIDER_free_part_syntax(A,B) spider_my_free(A,B) -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100306 #define SPIDER_read_record_read_record(A) read_record() #define SPIDER_has_Item_with_subquery #define SPIDER_use_LEX_CSTRING_for_KEY_Field_name @@ -211,46 +127,15 @@ #define SPIDER_item_name_str(A) (A)->name.str #define SPIDER_item_name_length(A) (A)->name.length const LEX_CSTRING SPIDER_empty_string = {"", 0}; -#else -#define SPIDER_read_record_read_record(A) read_record(A) -#define SPIDER_THD_db_str(A) (A)->db -#define SPIDER_THD_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_db_str(A) (A)->db -#define SPIDER_TABLE_LIST_db_length(A) (A)->db_length -#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name -#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name_length -#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias -#define SPIDER_TABLE_LIST_alias_length(A) strlen((A)->alias) -#define SPIDER_field_name_str(A) (A)->field_name -#define SPIDER_field_name_length(A) strlen((A)->field_name) -#define SPIDER_item_name_str(A) (A)->name -#define SPIDER_item_name_length(A) strlen((A)->name) -const char SPIDER_empty_string = ""; -#endif -#if MYSQL_VERSION_ID >= 50500 #define SPIDER_HAS_HASH_VALUE_TYPE -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400 #define SPIDER_date_mode_t(A) date_mode_t(A) #define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E) #define SPIDER_get_linkage(A) A->get_linkage() -#else -#define SPIDER_date_mode_t(A) A -#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime(A,B,C,D,E) -#define SPIDER_get_linkage(A) A->linkage -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 typedef start_new_trans *SPIDER_Open_tables_backup; -#elif MYSQL_VERSION_ID < 50500 -typedef Open_tables_state SPIDER_Open_tables_backup; -#else -typedef Open_tables_backup SPIDER_Open_tables_backup; -#endif -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100500 #define SPIDER_reset_n_backup_open_tables_state(A,B,C) do { \ if (!(*(B) = new start_new_trans(A))) \ { \ @@ -262,12 +147,6 @@ typedef Open_tables_backup SPIDER_Open_tables_backup; delete *(B); \ } while (0) #define SPIDER_sys_close_thread_tables(A) (A)->commit_whole_transaction_and_close_tables() -#else -#define SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP -#define SPIDER_reset_n_backup_open_tables_state(A,B,C) (A)->reset_n_backup_open_tables_state(B) -#define SPIDER_restore_backup_open_tables_state(A,B) (A)->restore_backup_open_tables_state(B) -#define SPIDER_sys_close_thread_tables(A) close_thread_tables(A) -#endif #define spider_bitmap_size(A) ((A + 7) / 8) #define spider_set_bit(BITMAP, BIT) \ @@ -1652,8 +1531,6 @@ typedef struct st_spider_direct_sql TABLE **tables; int *iop; -#if MYSQL_VERSION_ID < 50500 -#else /* for using real table */ bool real_table_used; TABLE_LIST *table_list_first; @@ -1661,7 +1538,6 @@ typedef struct st_spider_direct_sql uchar *real_table_bitmap; SPIDER_Open_tables_backup open_tables_backup; THD *open_tables_thd; -#endif char *sql; ulong sql_length; @@ -1681,10 +1557,7 @@ typedef struct st_spider_direct_sql #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) int access_mode; #endif -#if MYSQL_VERSION_ID < 50500 -#else int use_real_table; -#endif int error_rw_mode; char *server_name; @@ -1763,6 +1636,7 @@ typedef struct st_spider_table_mon st_spider_table_mon *next; } SPIDER_TABLE_MON; +/* List of `SPIDER_TABLE_MON's */ typedef struct st_spider_table_mon_list { char *key; diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h index e593f47ad79..fcc060e7e8c 100644 --- a/storage/spider/spd_init_query.h +++ b/storage/spider/spd_init_query.h @@ -20,8 +20,10 @@ */ static LEX_STRING spider_init_queries[] = { + /* Use the default SQL_MODE for this connection. */ {C_STRING_WITH_LEN( - "SET @@SQL_MODE = REGEXP_REPLACE(@@SQL_MODE, '(ORACLE|NO_ZERO_DATE)', '');" + "SET @@SQL_MODE = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO," + "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';" )}, {C_STRING_WITH_LEN( "SET @@OLD_MODE = CONCAT(@@OLD_MODE, ',UTF8_IS_UTF8MB3');" diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc index 3d9e8f271e3..5a7ef4048a6 100644 --- a/storage/spider/spd_malloc.cc +++ b/storage/spider/spd_malloc.cc @@ -18,15 +18,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_analyse.h" -#endif #include "spd_db_include.h" #include "spd_include.h" #include "spd_malloc.h" diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc index 9023f119bf2..4f5ed91eebe 100644 --- a/storage/spider/spd_param.cc +++ b/storage/spider/spd_param.cc @@ -38,15 +38,10 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" -#endif #include #include "spd_err.h" #include "spd_db_include.h" @@ -57,10 +52,8 @@ extern struct st_mysql_plugin spider_i_s_alloc_mem; extern struct st_mysql_plugin spider_i_s_wrapper_protocols; -#ifdef MARIADB_BASE_VERSION extern struct st_maria_plugin spider_i_s_alloc_mem_maria; extern struct st_maria_plugin spider_i_s_wrapper_protocols_maria; -#endif extern volatile ulonglong spider_mon_table_cache_version; extern volatile ulonglong spider_mon_table_cache_version_req; @@ -226,13 +219,8 @@ struct st_mysql_show_var spider_status_variables[] = }; typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int); -#if MYSQL_VERSION_ID < 50500 -extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, - const char *name, long long val); -#else extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsignd, longlong v); -#endif static my_bool spider_support_xa; static MYSQL_SYSVAR_BOOL( @@ -695,14 +683,9 @@ static int spider_param_semi_table_lock_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -753,14 +736,9 @@ static int spider_param_semi_table_lock_connection_check( (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; options.arg_type = REQUIRED_ARG; *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); -#if MYSQL_VERSION_ID < 50500 - DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, - ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); -#else DBUG_RETURN(throw_bounds_warning(thd, ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, (longlong) tmp)); -#endif } /* @@ -1738,7 +1716,6 @@ SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_table_loop_mode) static char *spider_remote_access_charset; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_access_charset, spider_remote_access_charset, @@ -1749,30 +1726,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_access_charset, - spider_remote_access_charset, - PLUGIN_VAR_RQCMDARG, - "Set remote access charset at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char*, remote_access_charset) @@ -1800,7 +1753,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_autocommit) static char *spider_remote_time_zone; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_time_zone, spider_remote_time_zone, @@ -1811,30 +1763,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_time_zone, - spider_remote_time_zone, - PLUGIN_VAR_RQCMDARG, - "Set remote time_zone at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_time_zone) @@ -1885,7 +1813,6 @@ SPIDER_SYSVAR_VALUE_FUNC(int, remote_trx_isolation) static char *spider_remote_default_database; /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_SYSVAR_STR( remote_default_database, spider_remote_default_database, @@ -1896,30 +1823,6 @@ static MYSQL_SYSVAR_STR( NULL, NULL ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#else -static MYSQL_SYSVAR_STR( - remote_default_database, - spider_remote_default_database, - PLUGIN_VAR_RQCMDARG, - "Set remote database at connecting for improvement performance of connection if you know", - NULL, - NULL, - NULL -); -#endif -#endif SPIDER_SYSVAR_VALUE_FUNC(char *, remote_default_database) @@ -1973,7 +1876,6 @@ int spider_param_connect_retry_count( /* */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 static MYSQL_THDVAR_STR( bka_engine, /* name */ PLUGIN_VAR_MEMALLOC | @@ -1983,28 +1885,6 @@ static MYSQL_THDVAR_STR( NULL, /* update */ NULL /* def */ ); -#else -#ifdef PLUGIN_VAR_CAN_MEMALLOC -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_MEMALLOC | - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#else -static MYSQL_THDVAR_STR( - bka_engine, /* name */ - PLUGIN_VAR_RQCMDARG, - "Temporary table's engine for BKA", /* comment */ - NULL, /* check */ - NULL, /* update */ - NULL /* def */ -); -#endif -#endif char *spider_param_bka_engine( THD *thd, @@ -2345,8 +2225,6 @@ static MYSQL_SYSVAR_INT( SPIDER_SYSVAR_OVERRIDE_VALUE_FUN(int, bulk_access_free) #endif -#if MYSQL_VERSION_ID < 50500 -#else /* -1 :fallback to default 0 :can not use @@ -2365,7 +2243,6 @@ static MYSQL_THDVAR_INT( ); SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, udf_ds_use_real_table) -#endif static my_bool spider_general_log; static MYSQL_SYSVAR_BOOL( @@ -2966,10 +2843,7 @@ static struct st_mysql_sys_var* spider_system_variables[] = { #ifdef HA_CAN_BULK_ACCESS MYSQL_SYSVAR(bulk_access_free), #endif -#if MYSQL_VERSION_ID < 50500 -#else MYSQL_SYSVAR(udf_ds_use_real_table), -#endif MYSQL_SYSVAR(general_log), MYSQL_SYSVAR(index_hint_pushdown), MYSQL_SYSVAR(max_connections), @@ -3011,15 +2885,12 @@ mysql_declare_plugin(spider) spider_status_variables, spider_system_variables, NULL, -#if MYSQL_VERSION_ID >= 50600 0, -#endif }, spider_i_s_alloc_mem, spider_i_s_wrapper_protocols mysql_declare_plugin_end; -#ifdef MARIADB_BASE_VERSION maria_declare_plugin(spider) { MYSQL_STORAGE_ENGINE_PLUGIN, @@ -3039,4 +2910,3 @@ maria_declare_plugin(spider) spider_i_s_alloc_mem_maria, spider_i_s_wrapper_protocols_maria maria_declare_plugin_end; -#endif diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h index 6b786685ced..e4ea26c610f 100644 --- a/storage/spider/spd_param.h +++ b/storage/spider/spd_param.h @@ -375,13 +375,10 @@ int spider_param_bulk_access_free( int bulk_access_free ); #endif -#if MYSQL_VERSION_ID < 50500 -#else int spider_param_udf_ds_use_real_table( THD *thd, int udf_ds_use_real_table ); -#endif my_bool spider_param_general_log(); my_bool spider_param_index_hint_pushdown( THD *thd diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc index 2ec00d77b31..8327a2c9fea 100644 --- a/storage/spider/spd_ping_table.cc +++ b/storage/spider/spd_ping_table.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "sql_acl.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -55,6 +50,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status; extern PSI_mutex_key spd_key_mutex_mon_table_cache; #endif +/* Array (of size `spider_udf_table_mon_mutex_count') of hashes of +`SPIDER_TABLE_MON_LIST'. */ HASH *spider_udf_table_mon_list_hash; uint spider_udf_table_mon_list_hash_id; const char *spider_udf_table_mon_list_hash_func_name; @@ -64,23 +61,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes; pthread_cond_t *spider_udf_table_mon_conds; pthread_mutex_t spider_mon_table_cache_mutex; +/* A cache to store distinct SPIDER_MON_KEYs with db name, table name +and link id read from mysql.spider_link_mon_servers table. Initialised +and populated in spider_init_ping_table_mon_cache(), and used in +spider_ping_table_cache_compare(). The udf +spider_flush_table_mon_cache is used to flag a initialisation. */ DYNAMIC_ARRAY spider_mon_table_cache; uint spider_mon_table_cache_id; const char *spider_mon_table_cache_func_name; const char *spider_mon_table_cache_file_name; ulong spider_mon_table_cache_line_no; -volatile ulonglong spider_mon_table_cache_version = 0; -volatile ulonglong spider_mon_table_cache_version_req = 1; +/* The mon table cache version, initialised at 0, and always no +greater than spider_mon_table_cache_version_req. When the inequality +is strict, an initialisation of spider_mon_table_cache will be +triggered. */ +volatile ulonglong spider_mon_table_cache_version; +/* The required mon table cache version, incremented by one by the +udf spider_flush_table_mon_cache */ +volatile ulonglong spider_mon_table_cache_version_req; + /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( SPIDER_TRX *trx, THD *thd, - spider_string *str, + spider_string *str, /* The key to search in + `spider_udf_table_mon_list_hash', + usually in the format of + "./$db_name/$table_name000000000$link_idx" */ uint conv_name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, + uint32 server_id, /* The server id of the monitor + server, used for creating a new + table mon list having a + `SPIDER_TABLE_MON' corresponding to + the server id as the `current' + field */ bool need_lock, int *error_num ) { @@ -92,6 +109,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( my_hash_value_type hash_value; #endif DBUG_ENTER("spider_get_ping_table_mon_list"); + /* Reset the cache if the version does not match the requirement */ if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) { SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); @@ -104,6 +122,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( free_root(&mem_root, MYF(0)); } + /* Search for the table mon list in the hash, if one is not found or + if it is found but has the wrong cache version, create and + initialise a new one. */ mutex_hash = spider_udf_calc_hash(str->c_ptr(), spider_param_udf_table_mon_mutex_count()); DBUG_PRINT("info",("spider hash key=%s", str->c_ptr())); @@ -130,12 +151,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( ) #endif { + /* If table_mon_list is found but the cache version does not + match, remove it from the hash and free it. */ if ( table_mon_list && table_mon_list->mon_table_cache_version != mon_table_cache_version ) spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); - + /* create and initialise `table_mon_list' and insert it into the + hash */ if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(), conv_name_length, link_idx, static_link_id, static_link_id_length, server_id, str, need_lock, error_num))) @@ -278,6 +302,14 @@ int spider_release_ping_table_mon_list( DBUG_RETURN(0); } +/* + Look for a `SPIDER_MON_KEY` in `spider_mon_table_cache' whose db and + table name and link_idx matching `name' and `link_idx' with wild + card matching. If a match is found, create `SPIDER_TABLE_MON's from + all rows in mysql.spider_link_mon_servers that match the info in the + `SPIDER_MON_KEY' and populate the `table_mon_list' with these + `SPIDER_TABLE_MON's. +*/ int spider_get_ping_table_mon( THD *thd, SPIDER_TABLE_MON_LIST *table_mon_list, @@ -354,6 +386,8 @@ int spider_get_ping_table_mon( goto error; create_table_mon: + /* Find the first row in mysql.spider_link_mon_servers matching the + db name, table name and link_idx */ if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key, table_link_mon->s->primary_key, 3))) { @@ -361,6 +395,9 @@ create_table_mon: goto error; } + /* create one `SPIDER_TABLE_MON' per row in + mysql.spider_link_mon_servers with matching db name, table name and + link_idx, and add it to `table_mon_list'. */ do { if (!(table_mon = (SPIDER_TABLE_MON *) spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL), @@ -394,7 +431,7 @@ create_table_mon: (error_num = spider_get_sys_link_mon_server_id( table_link_mon, &table_mon->server_id, mem_root)) || (error_num = spider_get_sys_link_mon_connect_info( - table_link_mon, tmp_share, 0, mem_root)) + table_link_mon, tmp_share, mem_root)) ) { table_link_mon->file->print_error(error_num, MYF(0)); spider_sys_index_end(table_link_mon); @@ -458,15 +495,21 @@ error: DBUG_RETURN(error_num); } +/* + creates and return table_mon_list associated with table with `name' + and `link_idx'th link. +*/ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( THD *thd, - char *name, + char *name, /* The table name, usually fully qualified */ uint name_length, int link_idx, char *static_link_id, uint static_link_id_length, - uint32 server_id, - spider_string *str, + uint32 server_id, /* The server_id will determine the + `current' field of the returned + `SPIDER_TABLE_MON_LIST'. */ + spider_string *str, /* str->c_ptr() == name */ bool need_lock, int *error_num ) { @@ -511,6 +554,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( memcpy(key_str, str->ptr(), table_mon_list->key_length); tmp_share->access_charset = thd->variables.character_set_client; + /* Open mysql.spider_tables */ if ( !(table_tables = spider_open_sys_table( thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, @@ -520,6 +564,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( my_error(*error_num, MYF(0)); goto error; } + /* store db and table names and link idx in mysql.spider_tables for + reading */ spider_store_tables_name(table_tables, name, name_length); if (static_link_id) { @@ -543,9 +589,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( goto error; } } + /* Populate tmp_share with info read from mysql.spider_tables */ if ( (*error_num = spider_get_sys_tables_connect_info( - table_tables, tmp_share, 0, &mem_root)) || + table_tables, tmp_share, &mem_root)) || (*error_num = spider_get_sys_tables_link_status( table_tables, tmp_share, 0, &mem_root)) ) { @@ -569,9 +616,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( tmp_share, name, name_length )) || (*error_num = spider_create_conn_keys(tmp_share)) || -/* - (*error_num = spider_db_create_table_names_str(tmp_share)) || -*/ + /* Pinally, populate `table_mon_list' with newly created + `SPIDER_TABLE_MON's */ (*error_num = spider_get_ping_table_mon( thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root, need_lock)) @@ -581,43 +627,26 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) table_mon_list->mon_status = SPIDER_LINK_MON_NG; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_caller, &table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_caller_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_receptor, &table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_receptor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_monitor, &table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_monitor_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&table_mon_list->update_status_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_list_update_status, &table_mon_list->update_status_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_update_status_mutex_init; @@ -878,6 +907,11 @@ error_open_table_tables: DBUG_RETURN(error_num); } +/* + Initialise `spider_mon_table_cache' by scanning the + mysql.spider_link_mon_servers table, creating distinct + `SPIDER_MON_KEY's with the info and inserting them into the cache. +*/ int spider_init_ping_table_mon_cache( THD *thd, MEM_ROOT *mem_root, @@ -906,6 +940,7 @@ int spider_init_ping_table_mon_cache( /* reset */ spider_mon_table_cache.elements = 0; + /* start at the first row */ if ((error_num = spider_sys_index_first(table_link_mon, table_link_mon->s->primary_key))) { @@ -922,10 +957,16 @@ int spider_init_ping_table_mon_cache( mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1; mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1; do { + /* update content of `mon_key' */ if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key, mem_root, &same))) goto error_get_sys_link_mon_key; + /* `mon_key' has changed content. since + mysql.spider_link_mon_servers is indexed by db_name, + table_name, link_idx, and server_id, it is possible that + different server_ids share the same mon_key which only has + db_name, table_name, link_idx */ if (!same) { mon_key.sort = spider_calc_for_sort(3, mon_key.db_name, @@ -996,6 +1037,13 @@ error_open_sys_table: DBUG_RETURN(error_num); } +/* + Read from msyql.spider_link_mon_servers table fields the db name, + table name and link_id and search for them with wild card matching + in `spider_mon_table_cache'. store the db name, table name, and + link_id of the matching `SPIDER_MON_KEY' back to the table field on + success. +*/ int spider_ping_table_cache_compare( TABLE *table, MEM_ROOT *mem_root @@ -1086,23 +1134,14 @@ long long spider_ping_table_body( conv_name.init_calc_mem(SPD_MID_PING_TABLE_BODY_1); tmp_str.init_calc_mem(SPD_MID_PING_TABLE_BODY_2); conv_name.length(0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 server_id = global_system_variables.server_id; -#else - server_id = thd->server_id; -#endif if ( thd->open_tables != 0 || thd->handler_tables_hash.records != 0 || thd->derived_tables != 0 || thd->lock != 0 || -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables != 0 || - thd->prelocked_mode != NON_PRELOCKED -#else thd->locked_tables_list.locked_tables() || thd->locked_tables_mode != LTM_NONE -#endif ) { if (thd->open_tables != 0) { @@ -1125,18 +1164,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), "thd->lock", thd->lock); -#if MYSQL_VERSION_ID < 50500 - } else if (thd->locked_tables != 0) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), - "thd->locked_tables", thd->locked_tables); - } else if (thd->prelocked_mode != NON_PRELOCKED) - { - my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, - ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), - "thd->prelocked_mode", (longlong) thd->prelocked_mode); -#else } else if (thd->locked_tables_list.locked_tables()) { my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, @@ -1148,7 +1175,6 @@ long long spider_ping_table_body( my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); -#endif } goto error; } @@ -1294,9 +1320,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1311,9 +1334,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1367,9 +1387,6 @@ long long spider_ping_table_body( DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3")); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1384,9 +1401,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1430,9 +1444,6 @@ long long spider_ping_table_body( mon_table_result->result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1447,9 +1458,6 @@ long long spider_ping_table_body( conv_name.c_ptr(), conv_name_length, link_idx, TRUE); status_changed_to_ng = TRUE; } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (status_changed_to_ng) { @@ -1620,9 +1628,9 @@ int spider_ping_table_mon_from_table( SPIDER_SHARE *share, int base_link_idx, uint32 server_id, - char *conv_name, + char *conv_name, /* Usually fully qualified table name */ uint conv_name_length, - int link_idx, + int link_idx, /* The link id to ping */ char *where_clause, uint where_clause_length, long monitoring_kind, @@ -1632,9 +1640,6 @@ int spider_ping_table_mon_from_table( ) { int error_num = 0, current_mon_count, flags; uint32 first_sid; -/* - THD *thd = trx->thd; -*/ SPIDER_TABLE_MON_LIST *table_mon_list; SPIDER_TABLE_MON *table_mon; SPIDER_MON_TABLE_RESULT mon_table_result; @@ -1703,6 +1708,7 @@ int spider_ping_table_mon_from_table( if (monitoring_flag & 1) flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES; + /* Get or create `table_mon_list' for `conv_name_str'. */ if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, &conv_name_str, conv_name_length, link_idx, share->static_link_ids[link_idx], @@ -1734,6 +1740,8 @@ int spider_ping_table_mon_from_table( table_mon = table_mon_list->current; first_sid = table_mon->server_id; current_mon_count = 1; + /* Call spider_ping_table on each table_mon of `table_mon_list', + until one succeeds */ while (TRUE) { DBUG_PRINT("info",("spider thd->killed=%s", @@ -1778,16 +1786,13 @@ int spider_ping_table_mon_from_table( if (!spider_db_udf_ping_table_mon_next( thd, table_mon, mon_conn, &mon_table_result, conv_name, conv_name_length, link_idx, - where_clause, where_clause_length, -1, table_mon_list->list_size, + where_clause, where_clause_length, /*first_sid=*/-1, table_mon_list->list_size, 0, 0, 0, flags, monitoring_limit)) { if ( mon_table_result.result_status == SPIDER_LINK_MON_NG && table_mon_list->mon_status != SPIDER_LINK_MON_NG ) { -/* - pthread_mutex_lock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) { @@ -1802,9 +1807,6 @@ int spider_ping_table_mon_from_table( spider_sys_log_tables_link_failed(thd, conv_name, conv_name_length, link_idx, need_lock); } -/* - pthread_mutex_unlock(&table_mon_list->update_status_mutex); -*/ pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); } table_mon_list->last_caller_result = mon_table_result.result_status; diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index 82f921bdafc..e585323bd72 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -17,17 +17,12 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "key.h" #include "sql_base.h" #include "tztime.h" -#endif #include "sql_select.h" #include "spd_err.h" #include "spd_param.h" @@ -245,22 +240,8 @@ TABLE *spider_open_sys_table( ) { TABLE *table; TABLE_LIST tables; -#if MYSQL_VERSION_ID < 50500 - TABLE_SHARE *table_share; - char table_key[MAX_DBKEY_LENGTH]; - uint table_key_length; -#endif DBUG_ENTER("spider_open_sys_table"); -#if MYSQL_VERSION_ID < 50500 - memset(&tables, 0, sizeof(TABLE_LIST)); - SPIDER_TABLE_LIST_db_str(&tables) = (char*)"mysql"; - SPIDER_TABLE_LIST_db_length(&tables) = sizeof("mysql") - 1; - SPIDER_TABLE_LIST_alias_str(&tables) = - SPIDER_TABLE_LIST_table_name_str(&tables) = (char *) table_name; - SPIDER_TABLE_LIST_table_name_length(&tables) = table_name_length; - tables.lock_type = (write ? TL_WRITE : TL_READ); -#else #ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias LEX_CSTRING db_name = { @@ -278,18 +259,8 @@ TABLE *spider_open_sys_table( "mysql", sizeof("mysql") - 1, table_name, table_name_length, table_name, (write ? TL_WRITE : TL_READ)); #endif -#endif -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { -#endif -#if MYSQL_VERSION_ID < 50500 - if (!(table = open_performance_schema_table(thd, &tables, - open_tables_backup))) -#else if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup))) -#endif { my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), @@ -297,38 +268,6 @@ TABLE *spider_open_sys_table( *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; DBUG_RETURN(NULL); } -#if MYSQL_VERSION_ID < 50500 - } else { - SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, NULL); - - if (!(table = (TABLE*) spider_malloc(spider_current_trx, SPD_MID_OPEN_SYS_TABLE_1, - sizeof(*table), MYF(MY_WME)))) - { - *error_num = HA_ERR_OUT_OF_MEM; - goto error_malloc; - } - - table_key_length = - create_table_def_key(thd, table_key, &tables, FALSE); - - if (!(table_share = get_table_share(thd, - &tables, table_key, table_key_length, 0, error_num))) - goto error; - if (open_table_from_share(thd, table_share, tables.alias, - (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), - READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, - (uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER, - table, FALSE) - ) { - release_table_share(table_share, RELEASE_NORMAL); - my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, - ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), - "mysql", table_name); - *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; - goto error; - } - } -#endif switch (table_name_length) { case 9: @@ -470,12 +409,6 @@ TABLE *spider_open_sys_table( } DBUG_RETURN(table); -#if MYSQL_VERSION_ID < 50500 -error: - spider_free(spider_current_trx, table, MYF(0)); -error_malloc: - SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); -#endif error_col_num_chk: DBUG_RETURN(NULL); } @@ -487,24 +420,10 @@ void spider_close_sys_table( bool need_lock ) { DBUG_ENTER("spider_close_sys_table"); -#if MYSQL_VERSION_ID < 50500 - if (need_lock) - { - close_performance_schema_table(thd, open_tables_backup); - } else { - table->file->ha_reset(); - closefrm(table, TRUE); - spider_free(spider_current_trx, table, MYF(0)); - SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); - } -#else spider_sys_close_table(thd, open_tables_backup); -#endif DBUG_VOID_RETURN; } -#if MYSQL_VERSION_ID < 50500 -#else bool spider_sys_open_and_lock_tables( THD *thd, TABLE_LIST **tables, @@ -572,7 +491,6 @@ void spider_sys_close_table( } DBUG_VOID_RETURN; } -#endif int spider_sys_index_init( TABLE *table, @@ -617,15 +535,9 @@ int spider_check_sys_table( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } int spider_check_sys_table_with_find_flag( @@ -641,15 +553,9 @@ int spider_check_sys_table_with_find_flag( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[0], 0, (uchar *) table_key, HA_WHOLE_KEY, find_flag)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[0], 0, (uchar *) table_key, - HA_WHOLE_KEY, find_flag)); -#endif } int spider_check_sys_table_for_update_all_columns( @@ -664,17 +570,16 @@ int spider_check_sys_table_for_update_all_columns( table->key_info, table->key_info->key_length); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_read_idx_map( table->record[1], 0, (uchar *) table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#else - DBUG_RETURN(table->file->index_read_idx_map( - table->record[1], 0, (uchar *) table_key, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)); -#endif } +/* + Creates a key (`table_key') consisting of `col_count' key parts of + `idx'th index of the table, then positions an index cursor to that + key. +*/ int spider_get_sys_table_by_idx( TABLE *table, char *table_key, @@ -707,26 +612,9 @@ int spider_get_sys_table_by_idx( key_length); if ( -/* -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 - (error_num = table->file->ha_index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_idx_map( - table->record[0], idx, (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif -*/ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_read_map( table->record[0], (uchar *) table_key, make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#else - (error_num = table->file->index_read_map( - table->record[0], (uchar *) table_key, - make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -739,22 +627,15 @@ int spider_sys_index_next_same( char *table_key ) { DBUG_ENTER("spider_sys_index_next_same"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next_same( table->record[0], (const uchar*) table_key, table->key_info->key_length)); -#else - DBUG_RETURN(table->file->index_next_same( - table->record[0], - (const uchar*) table_key, - table->key_info->key_length)); -#endif } int spider_sys_index_first( TABLE *table, - const int idx + const int idx /* which index to use */ ) { int error_num; DBUG_ENTER("spider_sys_index_first"); @@ -762,11 +643,7 @@ int spider_sys_index_first( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_first(table->record[0])) -#else - (error_num = table->file->index_first(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -784,11 +661,7 @@ int spider_sys_index_last( DBUG_RETURN(error_num); if ( -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 (error_num = table->file->ha_index_last(table->record[0])) -#else - (error_num = table->file->index_last(table->record[0])) -#endif ) { spider_sys_index_end(table); DBUG_RETURN(error_num); @@ -800,11 +673,7 @@ int spider_sys_index_next( TABLE *table ) { DBUG_ENTER("spider_sys_index_next"); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 DBUG_RETURN(table->file->ha_index_next(table->record[0])); -#else - DBUG_RETURN(table->file->index_next(table->record[0])); -#endif } void spider_store_xa_pk( @@ -1008,6 +877,10 @@ void spider_store_xa_member_info( DBUG_VOID_RETURN; } +/* + Store db and table names from `name' to `table's corresponding + fields +*/ void spider_store_tables_name( TABLE *table, const char *name, @@ -1589,12 +1462,6 @@ int spider_log_tables_link_failed( table->use_all_columns(); spider_store_tables_name(table, name, name_length); spider_store_tables_link_idx(table, link_idx); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[SPIDER_LINK_FAILED_LOG_FAILED_TIME_POS] == - table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -1628,12 +1495,6 @@ int spider_log_xa_failed( (uint) strlen(status), system_charset_info); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 -#else - if (table->field[SPIDER_XA_FAILED_LOG_FAILED_TIME_POS] == - table->timestamp_field) - table->timestamp_field->set_time(); -#endif if ((error_num = spider_write_sys_table_row(table))) { DBUG_RETURN(error_num); @@ -2298,14 +2159,16 @@ int spider_get_sys_tables( DBUG_RETURN(0); } +/* Read table info from mysql.spider_tables into a `SPIDER_SHARE' */ int spider_get_sys_tables_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to + update info */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_tables_connect_info"); DBUG_PRINT("info",("spider link_idx:%d", link_idx)); if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_PRIORITY_POS]))) @@ -2580,9 +2443,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing( DBUG_RETURN(error_num); } +/* + Read the link status from mysql.spider_tables into a `SPIDER_SHARE' + with default value 1 (`SPIDER_LINK_STATUS_OK') +*/ int spider_get_sys_tables_link_status( - TABLE *table, - SPIDER_SHARE *share, + TABLE *table, /* The mysql.spider_tables table */ + SPIDER_SHARE *share, /* The share to read link + status into */ int link_idx, MEM_ROOT *mem_root ) { @@ -2756,11 +2624,17 @@ error: DBUG_RETURN(error_num); } +/* Populate `mon_key' from the current row in `table' */ int spider_get_sys_link_mon_key( - TABLE *table, - SPIDER_MON_KEY *mon_key, + TABLE *table, /* the mysql.spider_link_mon_servers + table */ + SPIDER_MON_KEY *mon_key, /* output, to be populated in this + function */ MEM_ROOT *mem_root, - int *same + int *same /* output, true if the data from the + current row in the table agrees with + existing data in `mon_key' and false + otherwise */ ) { char *db_name, *table_name, *link_id; uint db_name_length, table_name_length, link_id_length; @@ -2776,6 +2650,7 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); } + /* get data for `mon_key' from the table record */ if (!(db_name= get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_DB_NAME_POS]))) @@ -2827,9 +2702,12 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(0); } +/* Get the server id from the spider_link_mon_servers table field */ int spider_get_sys_link_mon_server_id( - TABLE *table, - uint32 *server_id, + TABLE *table, /* the + mysql.spider_link_mon_servers + table */ + uint32 *server_id, /* output to server_id */ MEM_ROOT *mem_root ) { char *ptr; @@ -2843,14 +2721,17 @@ int spider_get_sys_link_mon_server_id( DBUG_RETURN(error_num); } +/* Get connect info from the spider_link_mon_servers table fields */ int spider_get_sys_link_mon_connect_info( - TABLE *table, - SPIDER_SHARE *share, - int link_idx, + TABLE *table, /* The + mysql.spider_link_mon_servers + table */ + SPIDER_SHARE *share, /* The output spider_share */ MEM_ROOT *mem_root ) { char *ptr; int error_num = 0; + const int link_idx= 0; DBUG_ENTER("spider_get_sys_link_mon_connect_info"); if ( !table->field[SPIDER_LINK_MON_SERVERS_SERVER_POS]->is_null() && @@ -3079,9 +2960,6 @@ int spider_get_link_statuses( if ( (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) ) { -/* - table->file->print_error(error_num, MYF(0)); -*/ DBUG_RETURN(error_num); } } else if ((error_num = @@ -3113,12 +2991,8 @@ int spider_sys_replace( if (table->file->ha_table_flags() & HA_DUPLICATE_POS) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_rnd_pos(table->record[1], table->file->dup_ref); -#else - error_num = table->file->rnd_pos(table->record[1], table->file->dup_ref); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) @@ -3131,13 +3005,8 @@ int spider_sys_replace( key_copy((uchar*)table_key, table->record[0], table->key_info + key_num, 0); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 error_num = table->file->ha_index_read_idx_map(table->record[1], key_num, (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#else - error_num = table->file->index_read_idx_map(table->record[1], key_num, - (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); -#endif if (error_num) { if (error_num == HA_ERR_RECORD_DELETED) diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h index 0ac21322bbf..ce3897c7382 100644 --- a/storage/spider/spd_sys_table.h +++ b/storage/spider/spd_sys_table.h @@ -56,6 +56,7 @@ #define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64 #define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64 +/* For insertion into `spider_mon_table_cache'. */ class SPIDER_MON_KEY: public SPIDER_SORT { public: @@ -84,8 +85,6 @@ void spider_close_sys_table( bool need_lock ); -#if MYSQL_VERSION_ID < 50500 -#else bool spider_sys_open_and_lock_tables( THD *thd, TABLE_LIST **tables, @@ -102,7 +101,6 @@ void spider_sys_close_table( THD *thd, SPIDER_Open_tables_backup *open_tables_backup ); -#endif int spider_sys_index_init( TABLE *table, @@ -404,7 +402,6 @@ int spider_get_sys_tables( int spider_get_sys_tables_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); @@ -481,7 +478,6 @@ int spider_get_sys_link_mon_server_id( int spider_get_sys_link_mon_connect_info( TABLE *table, SPIDER_SHARE *share, - int link_idx, MEM_ROOT *mem_root ); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 27f11a8d96c..26f292fde5e 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -18,10 +18,6 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "my_getopt.h" @@ -31,7 +27,6 @@ #include "sql_select.h" #include "tztime.h" #include "sql_parse.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -144,6 +139,11 @@ extern SPIDER_DBTON spider_dbton_oracle; SPIDER_THREAD *spider_table_sts_threads; SPIDER_THREAD *spider_table_crd_threads; #endif +extern volatile ulonglong spider_mon_table_cache_version; +extern volatile ulonglong spider_mon_table_cache_version_req; +extern ulonglong spider_conn_id; +extern Time_zone *UTC; +extern ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE PSI_mutex_key spd_key_mutex_tbl; @@ -3668,13 +3668,15 @@ error_alloc_conn_string: DBUG_RETURN(error_num); } +/* Set default connect info of a SPIDER_SHARE if needed */ int spider_set_connect_info_default( - SPIDER_SHARE *share, + SPIDER_SHARE *share, /* The `SPIDER_SHARE' to set + default connect info */ #ifdef WITH_PARTITION_STORAGE_ENGINE - partition_element *part_elem, - partition_element *sub_elem, + partition_element *part_elem, /* partition info used as input */ + partition_element *sub_elem, /* subpartition info used as input */ #endif - TABLE_SHARE *table_share + TABLE_SHARE *table_share /* table share info used as input */ ) { bool check_socket; bool check_database; @@ -3913,22 +3915,6 @@ int spider_set_connect_info_default( } } -/* - if (!share->static_link_ids[roop_count]) - { - DBUG_PRINT("info",("spider create default static_link_ids")); - share->static_link_ids_lengths[roop_count] = - SPIDER_DB_STATIC_LINK_ID_LEN; - if ( - !(share->static_link_ids[roop_count] = spider_create_string( - SPIDER_DB_STATIC_LINK_ID_STR, - share->static_link_ids_lengths[roop_count])) - ) { - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } - } -*/ - if (port_has_default_value) { share->tgt_ports[roop_count] = MYSQL_PORT; @@ -3979,11 +3965,7 @@ int spider_set_connect_info_default( if (share->monitoring_limit[roop_count] == -1) share->monitoring_limit[roop_count] = 1; if (share->monitoring_sid[roop_count] == -1) -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 share->monitoring_sid[roop_count] = global_system_variables.server_id; -#else - share->monitoring_sid[roop_count] = current_thd->server_id; -#endif #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (share->hs_read_ports[roop_count] == -1) @@ -4058,6 +4040,11 @@ int spider_set_connect_info_default( DBUG_RETURN(0); } +/* + This function is a no-op if all share->tgt_dbs and + share->tgt_table_names are non-null, otherwise it may assign them + with db_name and table_name +*/ int spider_set_connect_info_default_db_table( SPIDER_SHARE *share, const char *db_name, @@ -4143,6 +4130,11 @@ int spider_set_connect_info_default_db_table( DBUG_RETURN(0); } +/* + Parse `dbtable_name' into db name and table name, and call + spider_set_connect_info_default_db_table() to set the db/table name + values of `share' if needed +*/ int spider_set_connect_info_default_dbtable( SPIDER_SHARE *share, const char *dbtable_name, @@ -4684,12 +4676,12 @@ SPIDER_SHARE *spider_create_share( share->table.read_set = &table_share->all_set; #endif - if (table_share->keys > 0 && - !(share->key_hint = new spider_string[table_share->keys]) - ) { - *error_num = HA_ERR_OUT_OF_MEM; - goto error_init_hint_string; - } + if (table_share->keys > 0) + if (!(share->key_hint = new spider_string[table_share->keys])) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_hint_string; + } for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++) share->key_hint[roop_count].init_calc_mem(SPD_MID_CREATE_SHARE_2); DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint)); @@ -4728,34 +4720,22 @@ SPIDER_SHARE *spider_create_share( if (share->table_count_mode & 2) share->additional_table_flags |= HA_HAS_RECORDS; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share, &share->mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_sts, &share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_crd, &share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; @@ -6221,13 +6201,8 @@ SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( lgtm_tblhnd_share->table_path_hash_value = hash_value; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_share_auto_increment, &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_auto_increment_mutex; @@ -6337,23 +6312,15 @@ SPIDER_WIDE_SHARE *spider_get_wide_share( wide_share->crd_get_time = wide_share->sts_get_time = share->crd_get_time; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&wide_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_wide_share_sts, &wide_share->sts_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_sts_mutex; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&wide_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_wide_share_crd, &wide_share->crd_mutex, MY_MUTEX_INIT_FAST)) -#endif { *error_num = HA_ERR_OUT_OF_MEM; goto error_init_crd_mutex; @@ -6524,7 +6491,7 @@ int spider_open_all_tables( (error_num = spider_get_sys_tables( table_tables, &db_name, &table_name, &mem_root)) || (error_num = spider_get_sys_tables_connect_info( - table_tables, &tmp_share, 0, &mem_root)) || + table_tables, &tmp_share, &mem_root)) || (error_num = spider_set_connect_info_default( &tmp_share, #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -7146,6 +7113,12 @@ int spider_db_init( handlerton *spider_hton = (handlerton *)p; DBUG_ENTER("spider_db_init"); + spider_mon_table_cache_version= 0; + spider_mon_table_cache_version_req= 1; + spider_conn_id= 1; + spider_conn_mutex_id= 0; + UTC = 0; + spider_thread_id = 1; const LEX_CSTRING aria_name={STRING_WITH_LEN("Aria")}; if (!plugin_is_ready(&aria_name, MYSQL_STORAGE_ENGINE_PLUGIN)) DBUG_RETURN(HA_ERR_RETRY_INIT); @@ -7230,117 +7203,61 @@ int spider_db_init( goto error_pt_attr_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_tbl, &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_tbl_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_thread_id, &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_thread_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_conn_id, &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_id_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_ipport_count, &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_ipport_count_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_init_error_tbl, &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_init_error_tbl_mutex_init; #ifdef WITH_PARTITION_STORAGE_ENGINE -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_wide_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_wide_share, &spider_wide_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_wide_share_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share, &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_lgtm_tblhnd_share_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_conn, &spider_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_open_conn, &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_open_conn_mutex_init; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_r_conn, &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_r_conn_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_hs_w_conn, &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_hs_w_conn_mutex_init; #endif -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_allocated_thds, &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_allocated_thds_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mon_table_cache, &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mon_table_cache_mutex_init; -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_mem_calc, &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) -#endif goto error_mem_calc_mutex_init; if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_tables, spd_charset_utf8mb3_bin, 32, 0, 0, @@ -7454,25 +7371,16 @@ int spider_db_init( roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table_mon, &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mon_mutex; } for (roop_count = 0; roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL)) -#else if (mysql_cond_init(spd_key_cond_udf_table_mon, &spider_udf_table_mon_conds[roop_count], NULL)) -#endif goto error_init_udf_table_mon_cond; } for (roop_count = 0; @@ -8946,10 +8854,8 @@ bool spider_check_direct_order_limit( spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); bool first_check = TRUE; DBUG_PRINT("info",("spider select_lex=%p", select_lex)); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 DBUG_PRINT("info",("spider leaf_tables.elements=%u", select_lex ? select_lex->leaf_tables.elements : 0)); -#endif if (select_lex && (select_lex->options & SELECT_DISTINCT)) { @@ -8962,22 +8868,16 @@ bool spider_check_direct_order_limit( DBUG_PRINT("info",("spider select_limit=%lld", select_limit)); DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || #endif -#endif #ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT !spider->condition || #endif !select_lex || -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 select_lex->leaf_tables.elements != 1 || -#endif select_lex->table_list.elements != 1 ) { DBUG_PRINT("info",("spider first_check is FALSE")); @@ -9244,14 +9144,10 @@ int spider_set_direct_limit_offset( // contain where if ( -#if MYSQL_VERSION_ID < 50500 - !thd->variables.engine_condition_pushdown || -#else #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON #else !(thd->variables.optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || -#endif #endif // conditions is null may be no where condition in rand_init spider->wide_handler->condition @@ -9398,20 +9294,11 @@ ulong spider_calc_for_sort( double spider_rand( uint32 rand_source ) { -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 struct my_rnd_struct rand; -#else - struct rand_struct rand; -#endif DBUG_ENTER("spider_rand"); /* generate same as rand function for applications */ -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), (uint32) (rand_source * 268435457L)); -#else - randominit(&rand, (uint32) (rand_source * 65537L + 55555555L), - (uint32) (rand_source * 268435457L)); -#endif DBUG_RETURN(my_rnd(&rand)); } @@ -9948,46 +9835,27 @@ int spider_create_sts_threads( ) { int error_num; DBUG_ENTER("spider_create_sts_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_stss, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_stss, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_sts_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_sts_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread, &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; @@ -10035,46 +9903,27 @@ int spider_create_crd_threads( ) { int error_num; DBUG_ENTER("spider_create_crd_threads"); -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&spider_thread->mutex, - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_bg_crds, &spider_thread->mutex, MY_MUTEX_INIT_FAST)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_mutex_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crds, &spider_thread->cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_cond_init(&spider_thread->sync_cond, NULL)) -#else if (mysql_cond_init(spd_key_cond_bg_crd_syncs, &spider_thread->sync_cond, NULL)) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_sync_cond_init; } -#if MYSQL_VERSION_ID < 50500 - if (pthread_create(&spider_thread->thread, &spider_pt_attr, - spider_table_bg_crd_action, (void *) spider_thread) - ) -#else if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread, &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread) ) -#endif { error_num = HA_ERR_OUT_OF_MEM; goto error_thread_create; diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 4c60ef14703..25fa4ae1bcd 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -18,16 +18,11 @@ #include #include "mysql_version.h" #include "spd_environ.h" -#if MYSQL_VERSION_ID < 50500 -#include "mysql_priv.h" -#include -#else #include "sql_priv.h" #include "probes_mysql.h" #include "sql_class.h" #include "sql_partition.h" #include "records.h" -#endif #include "spd_err.h" #include "spd_param.h" #include "spd_db_include.h" @@ -54,7 +49,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_bin; extern handlerton *spider_hton_ptr; extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; pthread_mutex_t spider_thread_id_mutex; -ulonglong spider_thread_id = 1; +ulonglong spider_thread_id; #ifdef HAVE_PSI_INTERFACE extern PSI_mutex_key spd_key_mutex_udf_table; @@ -1209,13 +1204,8 @@ SPIDER_TRX *spider_get_trx( roop_count < (int) spider_param_udf_table_lock_mutex_count(); roop_count++) { -#if MYSQL_VERSION_ID < 50500 - if (pthread_mutex_init(&trx->udf_table_mutexes[roop_count], - MY_MUTEX_INIT_FAST)) -#else if (mysql_mutex_init(spd_key_mutex_udf_table, &trx->udf_table_mutexes[roop_count], MY_MUTEX_INIT_FAST)) -#endif goto error_init_udf_table_mutex; } @@ -1893,17 +1883,10 @@ int spider_internal_start_trx( (trx->xid.data, "%lx%016llx", thd_get_thread_id(thd), thd->query_id)); } -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 trx->xid.bqual_length = my_sprintf(trx->xid.data + trx->xid.gtrid_length, (trx->xid.data + trx->xid.gtrid_length, "%lx", thd->variables.server_id)); -#else - trx->xid.bqual_length - = my_sprintf(trx->xid.data + trx->xid.gtrid_length, - (trx->xid.data + trx->xid.gtrid_length, "%x", - thd->server_id)); -#endif #ifdef SPIDER_XID_STATE_HAS_in_thd trx->internal_xid_state.in_thd = 1; @@ -4083,19 +4066,8 @@ THD *spider_create_tmp_thd() DBUG_ENTER("spider_create_tmp_thd"); if (!(thd = SPIDER_new_THD((my_thread_id) 0))) DBUG_RETURN(NULL); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->killed = NOT_KILLED; -#else - thd->killed = THD::NOT_KILLED; -#endif -#if MYSQL_VERSION_ID < 50500 - thd->locked_tables = FALSE; -#endif thd->proc_info = ""; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 -#else - thd->thread_id = thd->variables.pseudo_thread_id = 0; -#endif thd->thread_stack = (char*) &thd; thd->store_globals(); lex_start(thd); @@ -4107,11 +4079,7 @@ void spider_free_tmp_thd( ) { DBUG_ENTER("spider_free_tmp_thd"); thd->cleanup(); -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 thd->reset_globals(); -#else - thd->restore_globals(); -#endif delete thd; DBUG_VOID_RETURN; } diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 4e613c92df5..f0637044639 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -252,10 +252,10 @@ class thread_pool_generic : public thread_pool OFF, ON }; timer_state_t m_timer_state= timer_state_t::OFF; - void switch_timer(timer_state_t state,std::unique_lock &lk); + void switch_timer(timer_state_t state); /* Updates idle_since, and maybe switches the timer off */ - void check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk); + void check_idle(std::chrono::system_clock::time_point now); /** time point when timer last ran, used as a coarse clock. */ std::chrono::system_clock::time_point m_timestamp; @@ -289,9 +289,9 @@ class thread_pool_generic : public thread_pool { ((thread_pool_generic *)arg)->maintenance(); } - bool add_thread(std::unique_lock &lk); + bool add_thread(); bool wake(worker_wake_reason reason, task *t = nullptr); - void maybe_wake_or_create_thread(std::unique_lock &lk); + void maybe_wake_or_create_thread(); bool too_many_active_threads(); bool get_task(worker_data *thread_var, task **t); bool wait_for_tasks(std::unique_lock &lk, @@ -600,11 +600,11 @@ void thread_pool_generic::worker_main(worker_data *thread_var) */ static const auto invalid_timestamp= std::chrono::system_clock::time_point::max(); -constexpr auto max_idle_time= std::chrono::seconds(20); +constexpr auto max_idle_time= std::chrono::minutes(1); /* Time since maintenance timer had nothing to do */ static std::chrono::system_clock::time_point idle_since= invalid_timestamp; -void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now, std::unique_lock &lk) +void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) { DBUG_ASSERT(m_task_queue.empty()); @@ -628,10 +628,10 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now, } /* Switch timer off after 1 minute of idle time */ - if (now - idle_since > max_idle_time) + if (now - idle_since > max_idle_time && m_active_threads.empty()) { idle_since= invalid_timestamp; - switch_timer(timer_state_t::OFF,lk); + switch_timer(timer_state_t::OFF); } } @@ -665,7 +665,7 @@ void thread_pool_generic::maintenance() if (m_task_queue.empty()) { - check_idle(m_timestamp, lk); + check_idle(m_timestamp); m_last_activity = m_tasks_dequeued + m_wakeups; return; } @@ -685,7 +685,7 @@ void thread_pool_generic::maintenance() } } - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); size_t thread_cnt = (int)thread_count(); if (m_last_activity == m_tasks_dequeued + m_wakeups && @@ -693,7 +693,7 @@ void thread_pool_generic::maintenance() { // no progress made since last iteration. create new // thread - add_thread(lk); + add_thread(); } m_last_activity = m_tasks_dequeued + m_wakeups; m_last_thread_count= thread_cnt; @@ -720,7 +720,7 @@ static int throttling_interval_ms(size_t n_threads,size_t concurrency) } /* Create a new worker.*/ -bool thread_pool_generic::add_thread(std::unique_lock &lk) +bool thread_pool_generic::add_thread() { if (m_thread_creation_pending.test_and_set()) return false; @@ -729,7 +729,14 @@ bool thread_pool_generic::add_thread(std::unique_lock &lk) if (n_threads >= m_max_threads) return false; - if (n_threads >= m_min_threads && m_min_threads != m_max_threads) + + /* + Deadlock danger exists, so monitor pool health + with maintenance timer. + */ + switch_timer(timer_state_t::ON); + + if (n_threads >= m_min_threads) { auto now = std::chrono::system_clock::now(); if (now - m_last_thread_creation < @@ -739,8 +746,6 @@ bool thread_pool_generic::add_thread(std::unique_lock &lk) Throttle thread creation and wakeup deadlock detection timer, if is it off. */ - switch_timer(timer_state_t::ON, lk); - return false; } } @@ -801,6 +806,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : m_tasks_dequeued(), m_wakeups(), m_spurious_wakeups(), + m_timer_state(timer_state_t::ON), m_in_shutdown(), m_timestamp(), m_long_tasks_count(), @@ -813,10 +819,13 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : m_maintenance_timer(thread_pool_generic::maintenance_func, this, nullptr) { set_concurrency(); + + // start the timer + m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); } -void thread_pool_generic::maybe_wake_or_create_thread(std::unique_lock &lk) +void thread_pool_generic::maybe_wake_or_create_thread() { if (m_task_queue.empty()) return; @@ -829,7 +838,7 @@ void thread_pool_generic::maybe_wake_or_create_thread(std::unique_lockadd_ref(); m_tasks_enqueued++; m_task_queue.push(task); - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); } @@ -885,7 +894,7 @@ void thread_pool_generic::wait_begin() m_waiting_task_count++; /* Maintain concurrency */ - maybe_wake_or_create_thread(lk); + maybe_wake_or_create_thread(); } @@ -900,30 +909,26 @@ void thread_pool_generic::wait_end() } -void thread_pool_generic::switch_timer(timer_state_t state, std::unique_lock &lk) +void thread_pool_generic::switch_timer(timer_state_t state) { if (m_timer_state == state) return; - /* No maintenance timer for fixed threadpool size.*/ - DBUG_ASSERT(m_min_threads != m_max_threads); - DBUG_ASSERT(lk.owns_lock()); + /* + We can't use timer::set_time, because mysys timers are deadlock + prone. + Instead, to switch off we increase the timer period + and decrease period to switch on. + + This might introduce delays in thread creation when needed, + as period will only be changed when timer fires next time. + For this reason, we can't use very long periods for the "off" state. + */ m_timer_state= state; - if(state == timer_state_t::OFF) - { - m_maintenance_timer.set_period(0); - } - else - { - /* - It is necessary to unlock the thread_pool::m_mtx - to avoid the deadlock with thr_timer's LOCK_timer. - Otherwise, lock order would be violated. - */ - lk.unlock(); - m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); - lk.lock(); - } + long long period= (state == timer_state_t::OFF) ? + m_timer_interval.count()*10: m_timer_interval.count(); + + m_maintenance_timer.set_period((int)period); } diff --git a/unittest/mysys/my_getopt-t.c b/unittest/mysys/my_getopt-t.c index 6ffbfb20789..a71c4676d63 100644 --- a/unittest/mysys/my_getopt-t.c +++ b/unittest/mysys/my_getopt-t.c @@ -378,10 +378,10 @@ int main(int argc __attribute__((unused)), char **argv) "res:%d, argc:%d, opt_ull:%llu", res, arg_c, opt_ull); run("--ull=-100", NULL); - ok(res==9 && arg_c==1 && opt_ull==0ULL, + ok(res==13 && arg_c==0 && opt_ull==0ULL, "res:%d, argc:%d, opt_ull:%llu", res, arg_c, opt_ull); run("--ul=-100", NULL); - ok(res==9 && arg_c==1 && opt_ul==0UL, + ok(res==13 && arg_c==0 && opt_ul==0UL, "res:%d, argc:%d, opt_ul:%lu", res, arg_c, opt_ul); my_end(0);