diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 241dbf3e29b..19afd7df277 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -9702,7 +9702,7 @@ void init_re(void) //"[[:space:]]*CALL[[:space:]]|" // XXX run_query_stmt doesn't read multiple result sets "[[:space:]]*CHANGE[[:space:]]|" "[[:space:]]*CHECKSUM[[:space:]]|" - "[[:space:]]*COMMIT[[:space:]]|" + "[[:space:]]*COMMIT[[:space:]]*|" "[[:space:]]*COMPOUND[[:space:]]|" "[[:space:]]*CREATE[[:space:]]+DATABASE[[:space:]]|" "[[:space:]]*CREATE[[:space:]]+INDEX[[:space:]]|" diff --git a/include/my_attribute.h b/include/my_attribute.h index 25d21d5e787..44b677de66e 100644 --- a/include/my_attribute.h +++ b/include/my_attribute.h @@ -70,6 +70,17 @@ # endif /* GNUC >= 3.1 */ #endif +/* gcc 7.5.0 does not support __attribute__((no_sanitize("undefined")) */ +#ifndef ATTRIBUTE_NO_UBSAN +# if (GCC_VERSION >= 8000) || defined(__clang__) +# define ATTRIBUTE_NO_UBSAN __attribute__((no_sanitize("undefined"))) +# elif (GCC_VERSION >= 6001) +# define ATTRIBUTE_NO_UBSAN __attribute__((no_sanitize_undefined)) +# else +# define ATTRIBUTE_NO_UBSAN +# endif +#endif + /* Define pragmas to disable warnings for stack frame checking */ #if defined(__clang__) diff --git a/mysql-test/include/show_rpl_debug_info.inc b/mysql-test/include/show_rpl_debug_info.inc index 7ee674df115..c77f0c2e3ef 100644 --- a/mysql-test/include/show_rpl_debug_info.inc +++ b/mysql-test/include/show_rpl_debug_info.inc @@ -91,12 +91,12 @@ while ($_rpl_server) --echo **** SHOW BINLOG EVENTS on $CURRENT_CONNECTION **** let $binlog_name= query_get_value("SHOW MASTER STATUS", File, 1); --echo binlog_name = '$binlog_name' - eval SHOW BINLOG EVENTS IN '$binlog_name'; + eval SHOW BINLOG EVENTS IN '$binlog_name' LIMIT 200; --echo --echo **** SHOW RELAYLOG EVENTS on $CURRENT_CONNECTION **** let $relaylog_name= query_get_value(SHOW SLAVE STATUS, Relay_Log_File, 1); --echo relaylog_name = '$relaylog_name' - eval SHOW RELAYLOG EVENTS IN '$relaylog_name'; + eval SHOW RELAYLOG EVENTS IN '$relaylog_name' LIMIT 200; --let $_rpl_is_first_server= 0 diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 974e419cefc..f37c447b171 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -19080,4 +19080,58 @@ f a c 0 0 -1 DROP VIEW v; DROP TABLE t1; +# +# MDEV-32395: update_depend_map_for_order: SEGV at +# /mariadb-11.3.0/sql/sql_select.cc:16583 +# +create table t1 (c1 int); +insert into t1 values (1), (2); +create table t2 (c2 int); +insert into t2 values (1), (2); +create table t3 (c3 int); +insert into t3 values (1), (2); +set statement optimizer_switch='condition_pushdown_for_derived=off,condition_pushdown_for_subquery=off,condition_pushdown_from_having=off' for +select t1.c1 as a from t2, t1 where t1.c1=t2.c2 +order by (select c3 from t3 group by a having a=2); +a +1 +2 +drop table t1, t2, t3; +# Test case 2 +CREATE TABLE t1 ( x BOOLEAN NOT NULL ); +INSERT INTO t1 ( x ) VALUES ( 1 ) ; +UPDATE t1 SET x = 1 WHERE x = 1 ; +INSERT INTO t1 ( x ) VALUES ( 1 ) , ( x IN ( SELECT x FROM ( SELECT ( SELECT EXISTS ( SELECT * FROM ( SELECT DISTINCT ( - CASE WHEN x = 1 THEN 1 ELSE x + 1 END >= x IS NOT NULL = 1 AND x = 1 ) OR x = x OR x = 'x' FROM t1 AS x GROUP BY x ) AS x WHERE 1 / x GROUP BY x HAVING ( 1 = 1 AND x = 1 ) ) FROM t1 GROUP BY EXISTS ( SELECT 1 ) ) FROM t1 UNION SELECT x FROM t1 ) AS x ) ) ; +DROP TABLE t1; +# Test case 3 +CREATE TABLE t0 ( c6 INT , c21 INT ) ; +INSERT INTO t0 VALUES ( 55 , -95 ) , ( 9 , 90 ) ; +ALTER TABLE t0 ADD COLUMN c37 INT AFTER c6 ; +INSERT INTO t0 VALUES ( ) , ( ) ; +SELECT t0 . c6 AS c42 FROM ( SELECT t0 . c6 = TRIM( TRAILING FROM 96 ) SOUNDS LIKE CONVERT ( t0 . c6 , UNSIGNED ) >> PI ( ) AS c49 FROM t0 ) AS t1 JOIN t0 ON RTRIM ( - RAND ( -66 ) BETWEEN FIND_IN_SET ( 20 , UNHEX ( -80 ) IS NULL OR IF ( 85 , -83 , -113 ) ) AND -125 ) / EXP ( c21 ) = t1 . c49 ORDER BY c42 , ( c42 + ( SELECT c21 AS c61 FROM t0 WHERE t0 . c37 >= -19.601384 = RAND ( ) / TRIM( t0 . c21 FROM 'C@rG3D(#9*17(a.,rV' ) = -106 GROUP BY c21 , c42 HAVING c42 = -73 LIMIT 1 ) ) ; +c42 +9 +9 +55 +55 +drop table t0; +# +# MDEV-32329 pushdown from having into where: Server crashes at sub_select +# +WITH RECURSIVE cte AS ( SELECT 1 as x UNION SELECT x FROM cte) +SELECT ( SELECT 1 FROM ( SELECT 1 FROM cte) dt GROUP BY x HAVING x= 1 ) +FROM cte +GROUP BY 1 ; +( SELECT 1 FROM ( SELECT 1 FROM cte) dt GROUP BY x HAVING x= 1 ) +1 +# Test case 2 +WITH +cte1 AS ( SELECT 1 as x UNION SELECT 1), +cte2 AS ( SELECT 1 as x UNION SELECT 1) +SELECT +( SELECT 1 FROM ( SELECT 1 FROM cte1) dt GROUP BY x HAVING x= 1 ) +FROM cte2 +GROUP BY 1 ; +( SELECT 1 FROM ( SELECT 1 FROM cte1) dt GROUP BY x HAVING x= 1 ) +1 # End of 10.5 tests diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index a46788b3de0..de173ec12be 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -4218,5 +4218,57 @@ SELECT * FROM v,t1 WHERE f = DEFAULT(c); DROP VIEW v; DROP TABLE t1; +--echo # +--echo # MDEV-32395: update_depend_map_for_order: SEGV at +--echo # /mariadb-11.3.0/sql/sql_select.cc:16583 +--echo # + +create table t1 (c1 int); +insert into t1 values (1), (2); +create table t2 (c2 int); +insert into t2 values (1), (2); +create table t3 (c3 int); +insert into t3 values (1), (2); + +set statement optimizer_switch='condition_pushdown_for_derived=off,condition_pushdown_for_subquery=off,condition_pushdown_from_having=off' for +select t1.c1 as a from t2, t1 where t1.c1=t2.c2 + order by (select c3 from t3 group by a having a=2); +drop table t1, t2, t3; + +--echo # Test case 2 + +CREATE TABLE t1 ( x BOOLEAN NOT NULL ); +INSERT INTO t1 ( x ) VALUES ( 1 ) ; +UPDATE t1 SET x = 1 WHERE x = 1 ; +INSERT INTO t1 ( x ) VALUES ( 1 ) , ( x IN ( SELECT x FROM ( SELECT ( SELECT EXISTS ( SELECT * FROM ( SELECT DISTINCT ( - CASE WHEN x = 1 THEN 1 ELSE x + 1 END >= x IS NOT NULL = 1 AND x = 1 ) OR x = x OR x = 'x' FROM t1 AS x GROUP BY x ) AS x WHERE 1 / x GROUP BY x HAVING ( 1 = 1 AND x = 1 ) ) FROM t1 GROUP BY EXISTS ( SELECT 1 ) ) FROM t1 UNION SELECT x FROM t1 ) AS x ) ) ; +DROP TABLE t1; + +--echo # Test case 3 + +CREATE TABLE t0 ( c6 INT , c21 INT ) ; +INSERT INTO t0 VALUES ( 55 , -95 ) , ( 9 , 90 ) ; +ALTER TABLE t0 ADD COLUMN c37 INT AFTER c6 ; +INSERT INTO t0 VALUES ( ) , ( ) ; +SELECT t0 . c6 AS c42 FROM ( SELECT t0 . c6 = TRIM( TRAILING FROM 96 ) SOUNDS LIKE CONVERT ( t0 . c6 , UNSIGNED ) >> PI ( ) AS c49 FROM t0 ) AS t1 JOIN t0 ON RTRIM ( - RAND ( -66 ) BETWEEN FIND_IN_SET ( 20 , UNHEX ( -80 ) IS NULL OR IF ( 85 , -83 , -113 ) ) AND -125 ) / EXP ( c21 ) = t1 . c49 ORDER BY c42 , ( c42 + ( SELECT c21 AS c61 FROM t0 WHERE t0 . c37 >= -19.601384 = RAND ( ) / TRIM( t0 . c21 FROM 'C@rG3D(#9*17(a.,rV' ) = -106 GROUP BY c21 , c42 HAVING c42 = -73 LIMIT 1 ) ) ; +drop table t0; + +--echo # +--echo # MDEV-32329 pushdown from having into where: Server crashes at sub_select +--echo # + +WITH RECURSIVE cte AS ( SELECT 1 as x UNION SELECT x FROM cte) + SELECT ( SELECT 1 FROM ( SELECT 1 FROM cte) dt GROUP BY x HAVING x= 1 ) + FROM cte + GROUP BY 1 ; + +--echo # Test case 2 + +WITH + cte1 AS ( SELECT 1 as x UNION SELECT 1), + cte2 AS ( SELECT 1 as x UNION SELECT 1) +SELECT + ( SELECT 1 FROM ( SELECT 1 FROM cte1) dt GROUP BY x HAVING x= 1 ) +FROM cte2 + GROUP BY 1 ; --echo # End of 10.5 tests diff --git a/mysql-test/main/mysqlbinlog.result b/mysql-test/main/mysqlbinlog.result index 1ca22f42277..1d4df621ebb 100644 --- a/mysql-test/main/mysqlbinlog.result +++ b/mysql-test/main/mysqlbinlog.result @@ -1286,3 +1286,49 @@ ERROR: Bad syntax in rewrite-db: empty FROM db ERROR: Bad syntax in rewrite-db: empty FROM db +# +# MDEV-31761: mariadb-binlog prints fractional timestamp part incorrectly +# +SET SESSION binlog_format= MIXED; +RESET MASTER; +SET time_zone= '+02:00'; +CREATE TABLE t (a INT, +b TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +set SESSION timestamp= 1689978980.012345; +INSERT INTO t (a) VALUES (1); +SELECT * from t; +a b +1 2023-07-22 00:36:20.012345 +FLUSH BINARY LOGS; +SET SESSION timestamp= 1689978980.567890; +SET SESSION binlog_format= ROW; +UPDATE t SET a = 2; +FLUSH BINARY LOGS; +SET SESSION binlog_format= STATEMENT; +DROP TABLE t; +SELECT * FROM t; +a b +1 2023-07-22 00:36:20.012345 +SELECT * FROM t; +a b +2 2023-07-22 00:36:20.567890 +DROP TABLE t; +SET time_zone= default; +# +# MDEV-24959: ER_BINLOG_ROW_LOGGING_FAILED (1534: Writing one row to the row-based binary log failed) +# +SET SESSION binlog_format= ROW; +SET SESSION binlog_row_image= MINIMAL; +RESET MASTER; +CREATE TABLE t1 (a INT NOT NULL DEFAULT 0 PRIMARY KEY); +REPLACE INTO t1 () VALUES (),(); +DROP TABLE t1; +FLUSH BINARY LOGS; +SET SESSION binlog_format= STATEMENT; +SET SESSION binlog_row_image= default; +FOUND 1 /Number of rows: 2/ in mdev24959_1.txt +FOUND 1 /DROP TABLE/ in mdev24959_1.txt +FOUND 1 /Number of rows: 2/ in mdev24959_2.txt +FOUND 1 /DROP TABLE/ in mdev24959_2.txt +FOUND 1 /INSERT INTO .* VALUES/ in mdev24959_2.txt +FOUND 1 /SET /[*] no columns [*]// in mdev24959_2.txt diff --git a/mysql-test/main/mysqlbinlog.test b/mysql-test/main/mysqlbinlog.test index 22a85393a35..ceb6ff2eee6 100644 --- a/mysql-test/main/mysqlbinlog.test +++ b/mysql-test/main/mysqlbinlog.test @@ -637,3 +637,82 @@ FLUSH LOGS; --exec $MYSQL_BINLOG --rewrite-db=" ->" --short-form $MYSQLD_DATADIR/master-bin.000001 2>&1 --exec $MYSQL_BINLOG --rewrite-db=" test -> foo " --short-form $MYSQLD_DATADIR/master-bin.000001 > /dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn + + +--echo # +--echo # MDEV-31761: mariadb-binlog prints fractional timestamp part incorrectly +--echo # + +SET SESSION binlog_format= MIXED; + +RESET MASTER; +SET time_zone= '+02:00'; +CREATE TABLE t (a INT, + b TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +set SESSION timestamp= 1689978980.012345; +INSERT INTO t (a) VALUES (1); +SELECT * from t; +FLUSH BINARY LOGS; +SET SESSION timestamp= 1689978980.567890; +SET SESSION binlog_format= ROW; +UPDATE t SET a = 2; +FLUSH BINARY LOGS; +SET SESSION binlog_format= STATEMENT; + +# Replay to see that timestamps are applied correctly. +# The bug was that leading zeros on the fractional part were not included in +# the mysqlbinlog output, so 1689978980.012345 was applied as 1689978980.12345. + +DROP TABLE t; +--let $datadir= `select @@datadir` +--exec $MYSQL_BINLOG $datadir/master-bin.000001 | $MYSQL test +SELECT * FROM t; +--exec $MYSQL_BINLOG $datadir/master-bin.000002 | $MYSQL test +SELECT * FROM t; +DROP TABLE t; +SET time_zone= default; + + +--echo # +--echo # MDEV-24959: ER_BINLOG_ROW_LOGGING_FAILED (1534: Writing one row to the row-based binary log failed) +--echo # + +SET SESSION binlog_format= ROW; +SET SESSION binlog_row_image= MINIMAL; + +RESET MASTER; +CREATE TABLE t1 (a INT NOT NULL DEFAULT 0 PRIMARY KEY); +REPLACE INTO t1 () VALUES (),(); +DROP TABLE t1; +FLUSH BINARY LOGS; +SET SESSION binlog_format= STATEMENT; +SET SESSION binlog_row_image= default; + +--exec $MYSQL_BINLOG --base64-output=decode-rows $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mdev24959_1.txt +--exec $MYSQL_BINLOG --base64-output=decode-rows --verbose $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mdev24959_2.txt + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mdev24959_1.txt +--let SEARCH_ABORT= NOT FOUND +--let SEARCH_PATTERN= Number of rows: 2 +--source include/search_pattern_in_file.inc + +# There was a bug that mysqlbinlog would get an error while decoding the +# update rows event with no after image and abort the dump; test that now +# the dump is complete and includes the final DROP TABLE. +--let SEARCH_PATTERN= DROP TABLE +--source include/search_pattern_in_file.inc + +--let SEARCH_FILE= $MYSQLTEST_VARDIR/tmp/mdev24959_2.txt +--let SEARCH_PATTERN= Number of rows: 2 +--source include/search_pattern_in_file.inc + +--let SEARCH_PATTERN= DROP TABLE +--source include/search_pattern_in_file.inc + +--let SEARCH_PATTERN= INSERT INTO .* VALUES +--source include/search_pattern_in_file.inc +--let SEARCH_PATTERN= SET /[*] no columns [*]/ +--source include/search_pattern_in_file.inc + +--remove_file $MYSQLTEST_VARDIR/tmp/mdev24959_1.txt +--remove_file $MYSQLTEST_VARDIR/tmp/mdev24959_2.txt diff --git a/mysql-test/suite/galera/r/MDEV-35446.result b/mysql-test/suite/galera/r/MDEV-35446.result new file mode 100644 index 00000000000..30f3b2d591c --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-35446.result @@ -0,0 +1,22 @@ +connection node_2; +connection node_1; +connect bf_trx, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connect victim_trx, 127.0.0.1, root, , test, $NODE_MYPORT_2; +connect node_2_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_2; +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; +connection victim_trx; +START TRANSACTION; +INSERT INTO t1 VALUES (2), (1); +connection node_2_ctrl; +SET GLOBAL debug_dbug = '+d,sync.wsrep_apply_cb'; +connection bf_trx; +INSERT INTO t1 VALUES (1), (2); +connection node_2_ctrl; +SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; +SET GLOBAL debug_dbug = ''; +connection victim_trx; +SET DEBUG_SYNC = "wsrep_at_dispatch_end_before_result SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort"; +COMMIT; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +SET DEBUG_SYNC = 'RESET'; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/r/galera_as_slave_parallel_retry.result b/mysql-test/suite/galera/r/galera_as_slave_parallel_retry.result new file mode 100644 index 00000000000..f292a4d48e5 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_as_slave_parallel_retry.result @@ -0,0 +1,22 @@ +connection node_2; +connection node_1; +connect master, 127.0.0.1, root, , test, $NODE_MYPORT_3; +connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1; +connection node_1; +START SLAVE; +connection master; +CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB; +connection node_1; +SET GLOBAL debug_dbug = '+d,rpl_parallel_simulate_temp_err_xid,sync.wsrep_retry_event_group'; +connection master; +INSERT INTO t1 VALUES (1); +connection node_1_ctrl; +SET debug_sync = 'now WAIT_FOR sync.wsrep_retry_event_group_reached'; +SET GLOBAL debug_dbug = ''; +SET debug_sync = 'now SIGNAL signal.wsrep_retry_event_group'; +connection node_1; +SET debug_sync = 'RESET'; +connection master; +DROP TABLE t1; +connection node_1; +STOP SLAVE; diff --git a/mysql-test/suite/galera/t/MDEV-35446.cnf b/mysql-test/suite/galera/t/MDEV-35446.cnf new file mode 100644 index 00000000000..ee365a18340 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-35446.cnf @@ -0,0 +1,4 @@ +!include ../galera_2nodes.cnf + +[mysqltest] +ps-protocol diff --git a/mysql-test/suite/galera/t/MDEV-35446.test b/mysql-test/suite/galera/t/MDEV-35446.test new file mode 100644 index 00000000000..49b82adcd01 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-35446.test @@ -0,0 +1,57 @@ +# +# MDEV-35446 +# +# Test BF abort of a transaction under PS protocol, after +# a statement is prepared (and the diagnostics area is +# disabled). +# + +--source include/have_debug_sync.inc +--source include/galera_cluster.inc + +# +# Setup: bf_trx executes in node_1 and will BF abort victim_trx. +# +--connect bf_trx, 127.0.0.1, root, , test, $NODE_MYPORT_1 +--connect victim_trx, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--connect node_2_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_2 + +CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB; + +--connection victim_trx +START TRANSACTION; +INSERT INTO t1 VALUES (2), (1); + +--connection node_2_ctrl +SET GLOBAL debug_dbug = '+d,sync.wsrep_apply_cb'; + +--connection bf_trx +INSERT INTO t1 VALUES (1), (2); + +--connection node_2_ctrl +SET DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached"; +SET GLOBAL debug_dbug = ''; + +# +# COMMIT the victim_trx and expect a deadlock error. +# Here we park the client in a sync point at the end of prepare +# command (COM_STMT_PREPARE), where the diagnostics area of the +# client has already been disabled. The client signals the +# applier to continue and will be BF aborted. +# If bug is present, the transaction is aborted, but the COMMIT +# statement succeeds (instead of returning deadlock error). +# +--connection victim_trx + +--disable_ps_protocol +SET DEBUG_SYNC = "wsrep_at_dispatch_end_before_result SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort"; +--enable_ps_protocol + +--error ER_LOCK_DEADLOCK +COMMIT; + +# +# Cleanup +# +SET DEBUG_SYNC = 'RESET'; +DROP TABLE t1; diff --git a/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.cnf b/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.cnf new file mode 100644 index 00000000000..59e4c5ffba2 --- /dev/null +++ b/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.cnf @@ -0,0 +1,10 @@ +!include ../galera_2nodes_as_slave.cnf + +[mysqld] +log-bin=mysqld-bin +log-slave-updates +binlog-format=ROW + +[mysqld.1] +slave-parallel-threads=2 +slave-parallel-mode=optimistic diff --git a/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.test b/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.test new file mode 100644 index 00000000000..0d499f22fcd --- /dev/null +++ b/mysql-test/suite/galera/t/galera_as_slave_parallel_retry.test @@ -0,0 +1,52 @@ +# MDEV-35465 Async replication stops working on Galera async replica node +# when parallel replication is enabled + +--source include/have_innodb.inc +--source include/have_log_bin.inc +--source include/galera_cluster.inc +--source include/have_debug_sync.inc + +# Node 3 is not a Galera node, use it as a master +--connect master, 127.0.0.1, root, , test, $NODE_MYPORT_3 +--connect node_1_ctrl, 127.0.0.1, root, , test, $NODE_MYPORT_1 + +--connection node_1 +--disable_query_log +--eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_PORT=$NODE_MYPORT_3; +--enable_query_log +START SLAVE; + +--connection master +CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB; + +--connection node_1 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' +--source include/wait_condition.inc + +# +--let debug_dbug_orig = `SELECT @@GLOBAL.debug_dbug` +SET GLOBAL debug_dbug = '+d,rpl_parallel_simulate_temp_err_xid,sync.wsrep_retry_event_group'; + +--connection master +INSERT INTO t1 VALUES (1); + +--connection node_1_ctrl +SET debug_sync = 'now WAIT_FOR sync.wsrep_retry_event_group_reached'; +--eval SET GLOBAL debug_dbug = '$debug_dbug_orig' +SET debug_sync = 'now SIGNAL signal.wsrep_retry_event_group'; + +--let $wait_condition = SELECT COUNT(*) = 1 FROM t1; +--source include/wait_condition.inc + + +--connection node_1 +SET debug_sync = 'RESET'; + +--connection master +DROP TABLE t1; + +--connection node_1 +--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' +--source include/wait_condition.inc + +STOP SLAVE; diff --git a/mysql-test/suite/rpl/include/rpl_partition.inc b/mysql-test/suite/rpl/include/rpl_partition.inc index 9f16f769f54..509ae2d88a8 100644 --- a/mysql-test/suite/rpl/include/rpl_partition.inc +++ b/mysql-test/suite/rpl/include/rpl_partition.inc @@ -95,6 +95,33 @@ SELECT * FROM test.regular_tbl ORDER BY fkid LIMIT 2; --replace_column 2 date-time 3 USER 4 UUID SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2; + +--echo *** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION +--connection master +eval CREATE TABLE t1 (a INT) +ENGINE=$engine_type +PARTITION BY LIST(a) ( + PARTITION p0 VALUES IN (9, NULL), + PARTITION p1 VALUES IN (8, 2, 7), + PARTITION p2 VALUES IN (6, 4, 5), + PARTITION p3 VALUES IN (3, 1, 0) +); +ALTER TABLE t1 DROP PARTITION p0; + +# This failed statement leaves ALTER_PARTITION_TRUNCATE set in +# thd->lex->alter_info.partition_flags +--error ER_NO_SUCH_TABLE +ALTER TABLE non_existent TRUNCATE PARTITION p1,p2; + +# The bug was that the code would wrongly look at the (now stale) value of +# thd->lex->alter_info.partition_flags and give the wrong error code +# ER_WRONG_PARTITION_NAME. +--error ER_NO_PARTITION_FOR_GIVEN_VALUE +INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9); + +--sync_slave_with_master + + ###### CLEAN UP SECTION ############## connection master; @@ -102,3 +129,4 @@ DROP PROCEDURE test.proc_norm; DROP PROCEDURE test.proc_byrange; DROP TABLE test.regular_tbl; DROP TABLE test.byrange_tbl; +DROP TABLE test.t1; diff --git a/mysql-test/suite/rpl/r/rpl_partition_archive.result b/mysql-test/suite/rpl/r/rpl_partition_archive.result index 4dfd38bcbc6..5c0374bd5af 100644 --- a/mysql-test/suite/rpl/r/rpl_partition_archive.result +++ b/mysql-test/suite/rpl/r/rpl_partition_archive.result @@ -140,8 +140,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2; id dt user uuidf fkid filler 1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL 2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL +*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION +connection master; +CREATE TABLE t1 (a INT) +ENGINE='Archive' +PARTITION BY LIST(a) ( +PARTITION p0 VALUES IN (9, NULL), +PARTITION p1 VALUES IN (8, 2, 7), +PARTITION p2 VALUES IN (6, 4, 5), +PARTITION p3 VALUES IN (3, 1, 0) +); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE non_existent TRUNCATE PARTITION p1,p2; +ERROR 42S02: Table 'test.non_existent' doesn't exist +INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9); +ERROR HY000: Table has no partition for value 9 +connection slave; +connection master; DROP PROCEDURE test.proc_norm; DROP PROCEDURE test.proc_byrange; DROP TABLE test.regular_tbl; DROP TABLE test.byrange_tbl; +DROP TABLE test.t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_partition_innodb.result b/mysql-test/suite/rpl/r/rpl_partition_innodb.result index 4b717d8b46c..599d0edf414 100644 --- a/mysql-test/suite/rpl/r/rpl_partition_innodb.result +++ b/mysql-test/suite/rpl/r/rpl_partition_innodb.result @@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2; id dt user uuidf fkid filler 1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL 2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL +*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION +connection master; +CREATE TABLE t1 (a INT) +ENGINE='InnoDB' +PARTITION BY LIST(a) ( +PARTITION p0 VALUES IN (9, NULL), +PARTITION p1 VALUES IN (8, 2, 7), +PARTITION p2 VALUES IN (6, 4, 5), +PARTITION p3 VALUES IN (3, 1, 0) +); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE non_existent TRUNCATE PARTITION p1,p2; +ERROR 42S02: Table 'test.non_existent' doesn't exist +INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9); +ERROR HY000: Table has no partition for value 9 +connection slave; connection master; DROP PROCEDURE test.proc_norm; DROP PROCEDURE test.proc_byrange; DROP TABLE test.regular_tbl; DROP TABLE test.byrange_tbl; +DROP TABLE test.t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_partition_memory.result b/mysql-test/suite/rpl/r/rpl_partition_memory.result index d37973b0d80..291fdfa33fd 100644 --- a/mysql-test/suite/rpl/r/rpl_partition_memory.result +++ b/mysql-test/suite/rpl/r/rpl_partition_memory.result @@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2; id dt user uuidf fkid filler 1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL 2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL +*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION +connection master; +CREATE TABLE t1 (a INT) +ENGINE='Memory' +PARTITION BY LIST(a) ( +PARTITION p0 VALUES IN (9, NULL), +PARTITION p1 VALUES IN (8, 2, 7), +PARTITION p2 VALUES IN (6, 4, 5), +PARTITION p3 VALUES IN (3, 1, 0) +); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE non_existent TRUNCATE PARTITION p1,p2; +ERROR 42S02: Table 'test.non_existent' doesn't exist +INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9); +ERROR HY000: Table has no partition for value 9 +connection slave; connection master; DROP PROCEDURE test.proc_norm; DROP PROCEDURE test.proc_byrange; DROP TABLE test.regular_tbl; DROP TABLE test.byrange_tbl; +DROP TABLE test.t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_partition_myisam.result b/mysql-test/suite/rpl/r/rpl_partition_myisam.result index 57c06a7cbec..678548ddb34 100644 --- a/mysql-test/suite/rpl/r/rpl_partition_myisam.result +++ b/mysql-test/suite/rpl/r/rpl_partition_myisam.result @@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2; id dt user uuidf fkid filler 1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL 2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL +*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION +connection master; +CREATE TABLE t1 (a INT) +ENGINE='MyISAM' +PARTITION BY LIST(a) ( +PARTITION p0 VALUES IN (9, NULL), +PARTITION p1 VALUES IN (8, 2, 7), +PARTITION p2 VALUES IN (6, 4, 5), +PARTITION p3 VALUES IN (3, 1, 0) +); +ALTER TABLE t1 DROP PARTITION p0; +ALTER TABLE non_existent TRUNCATE PARTITION p1,p2; +ERROR 42S02: Table 'test.non_existent' doesn't exist +INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9); +ERROR HY000: Table has no partition for value 9 +connection slave; connection master; DROP PROCEDURE test.proc_norm; DROP PROCEDURE test.proc_byrange; DROP TABLE test.regular_tbl; DROP TABLE test.byrange_tbl; +DROP TABLE test.t1; include/rpl_end.inc diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 6b0ff438b91..293e0f5cec4 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -10307,7 +10307,8 @@ void ha_partition::print_error(int error, myf errflag) /* Should probably look for my own errors first */ if ((error == HA_ERR_NO_PARTITION_FOUND) && - ! (thd->lex->alter_info.partition_flags & ALTER_PARTITION_TRUNCATE)) + ! (thd->lex->sql_command == SQLCOM_ALTER_TABLE && + (thd->lex->alter_info.partition_flags & ALTER_PARTITION_TRUNCATE))) { m_part_info->print_no_partition_found(table, errflag); DBUG_VOID_RETURN; diff --git a/sql/item.h b/sql/item.h index 9a51e017b21..9ae92ecac99 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2719,12 +2719,6 @@ public: */ virtual void under_not(Item_func_not * upper __attribute__((unused))) {}; - /* - If Item_field is wrapped in Item_direct_wrep remove this Item_direct_ref - wrapper. - */ - virtual Item *remove_item_direct_ref() { return this; } - void register_in(THD *thd); @@ -6016,11 +6010,6 @@ public: } Item *field_transformer_for_having_pushdown(THD *thd, uchar *arg) override { return (*ref)->field_transformer_for_having_pushdown(thd, arg); } - Item *remove_item_direct_ref() override - { - *ref= (*ref)->remove_item_direct_ref(); - return this; - } }; @@ -6068,8 +6057,6 @@ public: Ref_Type ref_type() override { return DIRECT_REF; } Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } - Item *remove_item_direct_ref() override - { return (*ref)->remove_item_direct_ref(); } /* Should be called if ref is changed */ inline void ref_changed() @@ -6453,7 +6440,6 @@ public: { return get_item_copy(thd, this); } Item *field_transformer_for_having_pushdown(THD *, uchar *) override { return this; } - Item *remove_item_direct_ref() override { return this; } }; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ea998b93483..06433c25b80 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -7890,10 +7890,11 @@ bool Item_equal::create_pushable_equalities(THD *thd, while ((item=it++)) { - left_item= item; - if (checker && !((item->*checker) (arg))) - continue; - break; + if (!checker || ((item->*checker)(arg))) + { + left_item= item; + break; + } } if (!left_item) diff --git a/sql/log_event.h b/sql/log_event.h index 03a02687dd3..e4bda624e0c 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -5136,7 +5136,7 @@ public: */ bool is_valid() const override { - return m_rows_buf && m_cols.bitmap; + return m_cols.bitmap; } uint m_row_count; /* The number of rows added to the event */ diff --git a/sql/log_event_client.cc b/sql/log_event_client.cc index 13b3b3e68c1..0b431dc5bed 100644 --- a/sql/log_event_client.cc +++ b/sql/log_event_client.cc @@ -1384,6 +1384,13 @@ void Rows_log_event::count_row_events(PRINT_EVENT_INFO *print_event_info) switch (general_type_code) { case WRITE_ROWS_EVENT: + /* + A write rows event containing no after image (can happen for REPLACE + INTO t() VALUES ()), count this correctly as 1 row and no 0. + */ + if (unlikely(m_rows_buf == m_rows_end)) + print_event_info->row_events++; + /* Fall through. */ case DELETE_ROWS_EVENT: row_events= 1; break; @@ -1510,6 +1517,7 @@ bool Rows_log_event::print_verbose(IO_CACHE *file, /* If the write rows event contained no values for the AI */ if (((general_type_code == WRITE_ROWS_EVENT) && (m_rows_buf==m_rows_end))) { + print_event_info->row_events++; if (my_b_printf(file, "### INSERT INTO %`s.%`s VALUES ()\n", map->get_db_name(), map->get_table_name())) goto err; @@ -1543,9 +1551,16 @@ bool Rows_log_event::print_verbose(IO_CACHE *file, /* Print the second image (for UPDATE only) */ if (sql_clause2) { - if (!(length= print_verbose_one_row(file, td, print_event_info, - &m_cols_ai, value, - (const uchar*) sql_clause2))) + /* If the update rows event contained no values for the AI */ + if (unlikely(bitmap_is_clear_all(&m_cols_ai))) + { + length= (bitmap_bits_set(&m_cols_ai) + 7) / 8; + if (my_b_printf(file, "### SET /* no columns */\n")) + goto err; + } + else if (!(length= print_verbose_one_row(file, td, print_event_info, + &m_cols_ai, value, + (const uchar*) sql_clause2))) goto err; value+= length; } @@ -1853,8 +1868,11 @@ bool Query_log_event::print_query_header(IO_CACHE* file, end=int10_to_str((long) when, strmov(buff,"SET TIMESTAMP="),10); if (when_sec_part && when_sec_part <= TIME_MAX_SECOND_PART) { - *end++= '.'; - end=int10_to_str(when_sec_part, end, 10); + char buff2[1 + 6 + 1]; + /* Ensure values < 100000 are printed with leading zeros, MDEV-31761. */ + snprintf(buff2, sizeof(buff2), ".%06lu", when_sec_part); + DBUG_ASSERT(strlen(buff2) == 1 + 6); + end= strmov(end, buff2); } end= strmov(end, print_event_info->delimiter); *end++='\n'; diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 90de190439f..cd974ce0466 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -5598,7 +5598,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) if (unlikely(open_and_lock_tables(thd, rgi->tables_to_lock, FALSE, 0))) { #ifdef WITH_WSREP - if (WSREP(thd)) + if (WSREP(thd) && !thd->slave_thread) { WSREP_WARN("BF applier thread=%lu failed to open_and_lock_tables for " "%s, fatal: %d " diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index e59c1de7a7c..3669ed3768e 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -832,8 +832,12 @@ do_retry: err= 0; errmsg= NULL; #ifdef WITH_WSREP - thd->wsrep_cs().reset_error(); - WSREP_DEBUG("retrying async replication event"); + DBUG_EXECUTE_IF("sync.wsrep_retry_event_group", { + const char act[]= "now " + "SIGNAL sync.wsrep_retry_event_group_reached " + "WAIT_FOR signal.wsrep_retry_event_group"; + debug_sync_set_action(thd, STRING_WITH_LEN(act)); + };); #endif /* WITH_WSREP */ /* @@ -983,15 +987,20 @@ do_retry: */ thd->reset_killed(); #ifdef WITH_WSREP - if (wsrep_before_command(thd)) + if (WSREP(thd)) { - WSREP_WARN("Parallel slave worker failed at wsrep_before_command() hook"); - err= 1; - goto err; + /* Exec after statement hook to make sure that the failed transaction + * gets cleared and reset error state. */ + if (wsrep_after_statement(thd)) + { + WSREP_WARN("Parallel slave worker failed at wsrep_after_statement() hook"); + err= 1; + goto err; + } + thd->wsrep_cs().reset_error(); + wsrep_start_trx_if_not_started(thd); + WSREP_DEBUG("parallel slave retry, after trx start"); } - wsrep_start_trx_if_not_started(thd); - WSREP_DEBUG("parallel slave retry, after trx start"); - #endif /* WITH_WSREP */ strmake_buf(log_name, ir->name); if ((fd= open_binlog(&rlog, log_name, &errmsg)) <0) diff --git a/sql/set_var.h b/sql/set_var.h index 416993e5c34..58b23e14bf7 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -26,6 +26,7 @@ #endif #include +#include class sys_var; class set_var; @@ -247,11 +248,11 @@ protected: Typically it's the same as session_value_ptr(), but it's different, for example, for ENUM, that is printed as a string, but stored as a number. */ - __attribute__((no_sanitize("undefined"))) + ATTRIBUTE_NO_UBSAN uchar *session_var_ptr(THD *thd) const { return ((uchar*)&(thd->variables)) + offset; } - __attribute__((no_sanitize("undefined"))) + ATTRIBUTE_NO_UBSAN uchar *global_var_ptr() const { return ((uchar*)&global_system_variables) + offset; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index dbfa7cb4951..a712971dc33 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -78,7 +78,7 @@ const char *safe_vio_type_name(Vio *vio) return vio_type_name(vio_type(vio), &unused); } -#include "sql_acl_getsort.ic" +#include "sql_acl_getsort.inl" static LEX_CSTRING native_password_plugin_name= { STRING_WITH_LEN("mysql_native_password") diff --git a/sql/sql_acl_getsort.ic b/sql/sql_acl_getsort.inl similarity index 100% rename from sql/sql_acl_getsort.ic rename to sql/sql_acl_getsort.inl diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index bfb1720d077..bc5bf04591d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1157,7 +1157,8 @@ static bool wsrep_command_no_result(char command) { return (command == COM_STMT_FETCH || command == COM_STMT_SEND_LONG_DATA || - command == COM_STMT_CLOSE); + command == COM_STMT_CLOSE || + command == COM_STMT_PREPARE); } #endif /* WITH_WSREP */ #ifndef EMBEDDED_LIBRARY @@ -2397,6 +2398,10 @@ resume: { WSREP_DEBUG("THD is killed at dispatch_end"); } + if (thd->lex->sql_command != SQLCOM_SET_OPTION) + { + DEBUG_SYNC(thd, "wsrep_at_dispatch_end_before_result"); + } wsrep_after_command_before_result(thd); if (wsrep_current_error(thd) && !wsrep_command_no_result(command)) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a8861e4c89d..4fe6b421403 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -17390,9 +17390,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, */ Item *head_item= (!item_const && current_sjm && current_sjm_head != field_item) ? current_sjm_head: head; - eq_item= new (thd->mem_root) Item_func_eq(thd, - field_item->remove_item_direct_ref(), - head_item->remove_item_direct_ref()); + eq_item= new (thd->mem_root) Item_func_eq(thd, field_item, head_item); if (!eq_item || eq_item->set_cmp_func(thd)) return 0; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 34457ade0b1..6997e5b7770 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -3825,11 +3825,16 @@ enum wsrep::streaming_context::fragment_unit wsrep_fragment_unit(ulong unit) bool THD::wsrep_parallel_slave_wait_for_prior_commit() { - if (rgi_slave && rgi_slave->is_parallel_exec && wait_for_prior_commit()) + if (rgi_slave && rgi_slave->is_parallel_exec) { - return 1; + wait_for_pending_deadlock_kill(this, rgi_slave); + if (rgi_slave->killed_for_retry) { + my_error(ER_LOCK_DEADLOCK, MYF(0)); + return true; + } + return wait_for_prior_commit(); } - return 0; + return false; } /***** callbacks for wsrep service ************/