From a6b7203d6564728089df66231739e0cc77b039d7 Mon Sep 17 00:00:00 2001 From: Denis Protivensky Date: Tue, 7 May 2024 16:42:13 +0300 Subject: [PATCH 01/25] MDEV-33952: Fix flaky galera_create_table_as_select test with debug sync The test that triggers multi-master conflict between two CTAS commands uses LOCK/UNLOCK TABLES to block local CTAS from progress. It could result in a race when UNLOCK TABLES command is issued a bit earlier then needed, causing local CTAS to run further and change wsrep transaction state, so that a different code path is taken later and the original error gets overridden, causing the test to fail. The solution is to replace LOCK/UNLOCK TABLES with debug sync points. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/disabled.def | 1 - .../r/galera_create_table_as_select.result | 13 +++++------ .../t/galera_create_table_as_select.test | 22 +++++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def index 84229dd4e2c..45c04bdfd4b 100644 --- a/mysql-test/suite/galera/disabled.def +++ b/mysql-test/suite/galera/disabled.def @@ -19,4 +19,3 @@ galera_slave_replay : MDEV-32780 galera_as_slave_replay: assertion in the wsrep: galera_sst_mysqldump_with_key : MDEV-32782 galera_sst_mysqldump_with_key test failed galera_var_ignore_apply_errors : MENT-1997 galera_var_ignore_apply_errors test freezes galera_desync_overlapped : MDEV-21538 galera_desync_overlapped MTR failed: Result content mismatch -galera_create_table_as_select : MDEV-33952 fails sporadically diff --git a/mysql-test/suite/galera/r/galera_create_table_as_select.result b/mysql-test/suite/galera/r/galera_create_table_as_select.result index beda5f30fe2..4ee313fd683 100644 --- a/mysql-test/suite/galera/r/galera_create_table_as_select.result +++ b/mysql-test/suite/galera/r/galera_create_table_as_select.result @@ -76,22 +76,21 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; connection node_1; +SET GLOBAL DEBUG_DBUG = 'd,sync.wsrep_apply_cb'; CREATE TABLE t2 (f1 INTEGER) ENGINE=InnoDB; INSERT INTO t2 VALUES (1),(2),(3),(4),(5); -connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1; -LOCK TABLE t2 WRITE; -connection node_1; +SET DEBUG_SYNC = 'create_table_select_before_create WAIT_FOR sync.wsrep_apply_cb_reached'; +SET DEBUG_SYNC = 'create_table_select_before_lock SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort'; CREATE TABLE t1 AS SELECT * FROM t2;; -connection node_1a; connection node_2; SELECT COUNT(*) = 5 FROM t2; COUNT(*) = 5 1 CREATE TABLE t1 AS SELECT * FROM t2; -connection node_1a; -UNLOCK TABLES; connection node_1; -Got one of the listed errors +ERROR 70100: Query execution was interrupted +SET GLOBAL DEBUG_DBUG = ''; +SET DEBUG_SYNC = 'RESET'; DROP TABLE t1, t2; CREATE TABLE t2 (f1 INTEGER) ENGINE=InnoDB; INSERT INTO t2 VALUES (1),(2),(3),(4),(5); diff --git a/mysql-test/suite/galera/t/galera_create_table_as_select.test b/mysql-test/suite/galera/t/galera_create_table_as_select.test index cfee63e5e27..63af9b552e0 100644 --- a/mysql-test/suite/galera/t/galera_create_table_as_select.test +++ b/mysql-test/suite/galera/t/galera_create_table_as_select.test @@ -3,6 +3,8 @@ # --source include/galera_cluster.inc +--source include/have_debug_sync.inc +--source include/have_debug.inc --connection node_1 SET SESSION default_storage_engine=InnoDB; @@ -103,31 +105,27 @@ DROP TABLE t1, t2; # --connection node_1 +# Pause applying CTAS command from the other node +SET GLOBAL DEBUG_DBUG = 'd,sync.wsrep_apply_cb'; CREATE TABLE t2 (f1 INTEGER) ENGINE=InnoDB; INSERT INTO t2 VALUES (1),(2),(3),(4),(5); ---connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1 -LOCK TABLE t2 WRITE; - ---connection node_1 +# Wait until local CTAS grabs MDL lock and let applied CTAS BF-abort it +SET DEBUG_SYNC = 'create_table_select_before_create WAIT_FOR sync.wsrep_apply_cb_reached'; +SET DEBUG_SYNC = 'create_table_select_before_lock SIGNAL signal.wsrep_apply_cb WAIT_FOR bf_abort'; --send CREATE TABLE t1 AS SELECT * FROM t2; ---connection node_1a ---let $wait_condition = SELECT COUNT(*) = 1 FROM information_schema.processlist WHERE STATE LIKE 'Waiting for table metadata lock%' ---source include/wait_condition.inc - --connection node_2 SELECT COUNT(*) = 5 FROM t2; CREATE TABLE t1 AS SELECT * FROM t2; ---connection node_1a -UNLOCK TABLES; - --connection node_1 ---error ER_TABLE_EXISTS_ERROR,ER_QUERY_INTERRUPTED +--error ER_QUERY_INTERRUPTED --reap +SET GLOBAL DEBUG_DBUG = ''; +SET DEBUG_SYNC = 'RESET'; DROP TABLE t1, t2; # From 0cc9b49751fc86f7942e19fe6ed8f7227f847c02 Mon Sep 17 00:00:00 2001 From: Denis Protivensky Date: Mon, 25 Mar 2024 14:40:55 +0100 Subject: [PATCH 02/25] MDEV-32633: Fix Galera cluster <-> native replication interaction It's possible to establish Galera multi-cluster setups connected through the native replication when every Galera cluster is configured to have a separate domain ID. For this setup to work, we need to replace domain ID values in generated GTID events when they are written at transaction commit to the values configured by Wsrep replication. At the same time, it's possible that the GTID event already contains a correct domain ID if it comes through the native replication from another Galera cluster. In this case, when such an event is applied either through a native replication slave thread or through Wsrep applier, we write GTID event on transaction start and avoid writing it during transaction commit. The code contained multiple problems that were fixed: - applying GTID events didn't work because it's applied without a running server transaction and Wsrep transaction was not started - GTID event generation on transaction start didn't contain proper "standalone" and "is_transactional" flags that the original applied GTID event contained - condition determining that GTID event is written on transaction start to avoid writing it on commit relied on the fact that the GTID event is the first found in transaction/statement caches, which wasn't the case and resulted in duplicate GTID events written - instead of relying on the caches to find a GTID event, a simple check is introduced that follows the exact rules for checking if event is written at transaction start as described above - the test case is improved to check that exact GTID events are applied after two Galera clusters have synced. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera_3nodes/disabled.def | 1 - .../r/galera_gtid_2_cluster.result | 68 ++++++++++++++++--- .../t/galera_gtid_2_cluster.test | 12 +++- sql/log.cc | 24 +++++-- sql/rpl_gtid.cc | 2 + sql/wsrep_mysqld.cc | 9 ++- 6 files changed, 98 insertions(+), 18 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/disabled.def b/mysql-test/suite/galera_3nodes/disabled.def index de7d8e755c7..f2e6f9802ce 100644 --- a/mysql-test/suite/galera_3nodes/disabled.def +++ b/mysql-test/suite/galera_3nodes/disabled.def @@ -11,7 +11,6 @@ ############################################################################## galera_2_cluster : MDEV-32631 galera_2_cluster: before_rollback(): Assertion `0' failed -galera_gtid_2_cluster : MDEV-32633 galera_gtid_2_cluster: Assertion `thd->wsrep_next_trx_id() != (0x7fffffffffffffffLL * 2ULL + 1)' galera_ssl_reload : MDEV-32778 galera_ssl_reload failed with warning message galera_ipv6_mariabackup : temporarily disabled at the request of Codership galera_pc_bootstrap : temporarily disabled at the request of Codership diff --git a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result index 7d4751e79af..ee622ba23c8 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result +++ b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result @@ -75,15 +75,15 @@ insert into t1 values (2, 21, 1); select @@gtid_binlog_state; @@gtid_binlog_state 1-11-2,2-21-1 -select * from t1; -cluster_domain_id node_server_id seq_no -1 11 2 -2 21 1 #wait for sync cluster 1 and 2 connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +2 21 1 cluster 1 node 2 connection node_2; select @@gtid_binlog_state; @@ -98,6 +98,11 @@ connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +2 21 1 cluster 1 node 3 connection node_3; select @@gtid_binlog_state; @@ -112,6 +117,12 @@ connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 cluster 2 node 2 connection node_5; select @@gtid_binlog_state; @@ -126,6 +137,13 @@ connection node_4; include/save_master_gtid.inc connection node_1; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 cluster 2 node 3 connection node_6; select @@gtid_binlog_state; @@ -140,6 +158,14 @@ connection node_4; include/save_master_gtid.inc connection node_1; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 cluster 1 node 1 connection node_1; select @@gtid_binlog_state; @@ -220,15 +246,15 @@ insert into t1 values (2, 21, 1); select @@gtid_binlog_state; @@gtid_binlog_state 1-11-7,2-21-4 -select * from t1; -cluster_domain_id node_server_id seq_no -1 11 2 -2 21 1 #wait for sync cluster 1 and 2 connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +2 21 1 cluster 1 node 2 connection node_2; select @@gtid_binlog_state; @@ -243,6 +269,11 @@ connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +2 21 1 cluster 1 node 3 connection node_3; select @@gtid_binlog_state; @@ -257,6 +288,12 @@ connection node_1; include/save_master_gtid.inc connection node_4; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 cluster 2 node 2 connection node_5; select @@gtid_binlog_state; @@ -271,6 +308,13 @@ connection node_4; include/save_master_gtid.inc connection node_1; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 cluster 2 node 3 connection node_6; select @@gtid_binlog_state; @@ -285,6 +329,14 @@ connection node_4; include/save_master_gtid.inc connection node_1; include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 cluster 1 node 1 connection node_1; select @@gtid_binlog_state; diff --git a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test index 925600ffaa8..efbfad36e35 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test +++ b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test @@ -75,12 +75,12 @@ select @@gtid_binlog_state; select @@gtid_binlog_state; insert into t1 values (2, 21, 1); select @@gtid_binlog_state; -select * from t1; --echo #wait for sync cluster 1 and 2 --connection node_1 --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 2 @@ -94,6 +94,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 3 --connection node_3 @@ -106,6 +107,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 2 node 2 --connection node_5 @@ -118,6 +120,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_1 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 2 node 3 --connection node_6 @@ -130,6 +133,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_1 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 1 @@ -226,13 +230,13 @@ select @@gtid_binlog_state; --connection node_4 insert into t1 values (2, 21, 1); select @@gtid_binlog_state; -select * from t1; --echo #wait for sync cluster 1 and 2 --connection node_1 --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 2 @@ -246,6 +250,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 3 --connection node_3 @@ -258,6 +263,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_4 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 2 node 2 --connection node_5 @@ -270,6 +276,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_1 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 2 node 3 --connection node_6 @@ -282,6 +289,7 @@ select @@gtid_binlog_state; --source include/save_master_gtid.inc --connection node_1 --source include/sync_with_master_gtid.inc +select * from t1 order by 1, 2, 3; --echo cluster 1 node 1 diff --git a/sql/log.cc b/sql/log.cc index 32c8ad46321..cb46fc1230f 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5254,6 +5254,16 @@ MYSQL_BIN_LOG::is_xidlist_idle_nolock() return true; } +#ifdef WITH_WSREP +static bool is_gtid_written_on_trans_start(const THD *thd) +{ + return wsrep_gtid_mode && WSREP(thd) && + (thd->variables.gtid_seq_no || thd->variables.wsrep_gtid_seq_no) && + ((thd->slave_thread && wsrep_thd_is_local(thd)) || + (!thd->slave_thread && (wsrep_thd_is_applying(thd)))); +} +#endif + /** Create a new log file name. @@ -5893,9 +5903,7 @@ THD::binlog_start_trans_and_stmt() Ha_trx_info *ha_info; ha_info= this->ha_data[binlog_hton->slot].ha_info + (mstmt_mode ? 1 : 0); - if (!ha_info->is_started() && - (this->variables.gtid_seq_no || this->variables.wsrep_gtid_seq_no) && - wsrep_on(this) && + if (!ha_info->is_started() && is_gtid_written_on_trans_start(this) && (this->wsrep_cs().mode() == wsrep::client_state::m_local)) { uchar *buf= 0; @@ -5914,8 +5922,14 @@ THD::binlog_start_trans_and_stmt() domain_id= wsrep_gtid_server.domain_id; server_id= wsrep_gtid_server.server_id; } - Gtid_log_event gtid_event(this, seqno, domain_id, true, - LOG_EVENT_SUPPRESS_USE_F, true, 0); + rpl_group_info* rgi = this->slave_thread ? this->rgi_slave : this->wsrep_rgi; + const bool standalone = + rgi->gtid_ev_flags2 & Gtid_log_event::FL_STANDALONE; + const bool is_transactional = + rgi->gtid_ev_flags2 & Gtid_log_event::FL_TRANSACTIONAL; + Gtid_log_event gtid_event(this, seqno, domain_id, + standalone, LOG_EVENT_SUPPRESS_USE_F, + is_transactional, 0); // Replicated events in writeset doesn't have checksum gtid_event.checksum_alg= BINLOG_CHECKSUM_ALG_OFF; gtid_event.server_id= server_id; diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 3f519f67eb6..6177a703383 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -704,6 +704,8 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, { thd->wsrep_ignore_table= false; table->file->row_logging= 1; // replication requires binary logging + if (thd->wsrep_next_trx_id() == WSREP_UNDEFINED_TRX_ID) + thd->set_query_id(next_query_id()); wsrep_start_trx_if_not_started(thd); } else diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index e584c2cc144..6d95ea33acc 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1827,8 +1827,13 @@ int wsrep_to_buf_helper( domain_id= wsrep_gtid_server.domain_id; server_id= wsrep_gtid_server.server_id; } - Gtid_log_event gtid_event(thd, seqno, domain_id, true, - LOG_EVENT_SUPPRESS_USE_F, true, 0); + rpl_group_info* rgi = thd->slave_thread ? thd->rgi_slave : thd->wsrep_rgi; + const bool standalone = + rgi->gtid_ev_flags2 & Gtid_log_event::FL_STANDALONE; + const bool is_transactional = + rgi->gtid_ev_flags2 & Gtid_log_event::FL_TRANSACTIONAL; + Gtid_log_event gtid_event(thd, seqno, domain_id, standalone, + LOG_EVENT_SUPPRESS_USE_F, is_transactional, 0); gtid_event.server_id= server_id; if (!gtid_event.is_valid()) ret= 0; ret= writer.write(>id_event); From a4838721a252ea5570b5fed9ab56e38e5b234865 Mon Sep 17 00:00:00 2001 From: Denis Protivensky Date: Wed, 27 Mar 2024 13:39:59 +0300 Subject: [PATCH 03/25] MDEV-32633: Fix Galera cluster <-> native replication interaction GTID events are applied without a running server transaction, we need to set next transaction ID for Wsrep transaction. The whole Galera cluster now has a single GTID value (including the server ID throughout the cluster), fix the config accordingly. Add force restart so that repeated MTR test execution prints consistent GTID values, otherwise they would have been recovered from the previous run. Signed-off-by: Julius Goryavsky --- .../r/galera_gtid_2_cluster.result | 98 +++++++++++++++++++ .../galera_3nodes/t/galera_gtid_2_cluster.cnf | 8 +- .../t/galera_gtid_2_cluster.test | 27 +++++ 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result index ee622ba23c8..1cb14cd3eff 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result +++ b/mysql-test/suite/galera_3nodes/r/galera_gtid_2_cluster.result @@ -166,6 +166,55 @@ cluster_domain_id node_server_id seq_no 2 21 1 2 22 2 2 23 3 +# check other nodes are consistent +connection node_2; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-4,2-21-3 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_3; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-4,2-21-3 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_5; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-4,2-21-3 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_6; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-4,2-21-3 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 cluster 1 node 1 connection node_1; select @@gtid_binlog_state; @@ -337,6 +386,55 @@ cluster_domain_id node_server_id seq_no 2 21 1 2 22 2 2 23 3 +# check other nodes are consistent +connection node_2; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-9,2-21-6 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_3; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-9,2-21-6 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_5; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-9,2-21-6 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 +connection node_6; +select @@gtid_binlog_state; +@@gtid_binlog_state +1-11-9,2-21-6 +select * from t1 order by 1, 2, 3; +cluster_domain_id node_server_id seq_no +1 11 2 +1 12 3 +1 13 4 +2 21 1 +2 22 2 +2 23 3 cluster 1 node 1 connection node_1; select @@gtid_binlog_state; diff --git a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.cnf b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.cnf index dc5535ef34a..bc64d114275 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.cnf +++ b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.cnf @@ -9,11 +9,11 @@ server-id=11 [mysqld.2] wsrep_gtid_domain_id=1 -server-id=12 +server-id=11 [mysqld.3] wsrep_gtid_domain_id=1 -server-id=13 +server-id=11 [mysqld.4] wsrep_gtid_domain_id=2 @@ -21,8 +21,8 @@ server-id=21 [mysqld.5] wsrep_gtid_domain_id=2 -server-id=22 +server-id=21 [mysqld.6] wsrep_gtid_domain_id=2 -server-id=23 +server-id=21 diff --git a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test index efbfad36e35..c8247f15aba 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test +++ b/mysql-test/suite/galera_3nodes/t/galera_gtid_2_cluster.test @@ -11,6 +11,7 @@ --source include/big_test.inc --source include/galera_cluster.inc --source include/have_innodb.inc +--source include/force_restart.inc --connection node_1 --echo cluster 1 node 1 @@ -135,6 +136,19 @@ select @@gtid_binlog_state; --source include/sync_with_master_gtid.inc select * from t1 order by 1, 2, 3; +--echo # check other nodes are consistent +--connection node_2 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_3 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_5 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_6 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; --echo cluster 1 node 1 --connection node_1 @@ -291,6 +305,19 @@ select @@gtid_binlog_state; --source include/sync_with_master_gtid.inc select * from t1 order by 1, 2, 3; +--echo # check other nodes are consistent +--connection node_2 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_3 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_5 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; +--connection node_6 +select @@gtid_binlog_state; +select * from t1 order by 1, 2, 3; --echo cluster 1 node 1 --connection node_1 From c21aa486a86d9db29ad16ff279380969443df00f Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Tue, 14 May 2024 04:52:53 +0200 Subject: [PATCH 04/25] MDEV-32633: additional post-merge changes for 10.5+ --- sql/log.cc | 18 +++++------------- sql/wsrep_mysqld.cc | 9 ++------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index cb46fc1230f..b065657e9a5 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -5257,10 +5257,9 @@ MYSQL_BIN_LOG::is_xidlist_idle_nolock() #ifdef WITH_WSREP static bool is_gtid_written_on_trans_start(const THD *thd) { - return wsrep_gtid_mode && WSREP(thd) && + return wsrep_on(thd) && (thd->variables.gtid_seq_no || thd->variables.wsrep_gtid_seq_no) && - ((thd->slave_thread && wsrep_thd_is_local(thd)) || - (!thd->slave_thread && (wsrep_thd_is_applying(thd)))); + (thd->wsrep_cs().mode() == wsrep::client_state::m_local); } #endif @@ -5903,8 +5902,7 @@ THD::binlog_start_trans_and_stmt() Ha_trx_info *ha_info; ha_info= this->ha_data[binlog_hton->slot].ha_info + (mstmt_mode ? 1 : 0); - if (!ha_info->is_started() && is_gtid_written_on_trans_start(this) && - (this->wsrep_cs().mode() == wsrep::client_state::m_local)) + if (!ha_info->is_started() && is_gtid_written_on_trans_start(this)) { uchar *buf= 0; size_t len= 0; @@ -5922,14 +5920,8 @@ THD::binlog_start_trans_and_stmt() domain_id= wsrep_gtid_server.domain_id; server_id= wsrep_gtid_server.server_id; } - rpl_group_info* rgi = this->slave_thread ? this->rgi_slave : this->wsrep_rgi; - const bool standalone = - rgi->gtid_ev_flags2 & Gtid_log_event::FL_STANDALONE; - const bool is_transactional = - rgi->gtid_ev_flags2 & Gtid_log_event::FL_TRANSACTIONAL; - Gtid_log_event gtid_event(this, seqno, domain_id, - standalone, LOG_EVENT_SUPPRESS_USE_F, - is_transactional, 0); + Gtid_log_event gtid_event(this, seqno, domain_id, true, + LOG_EVENT_SUPPRESS_USE_F, true, 0); // Replicated events in writeset doesn't have checksum gtid_event.checksum_alg= BINLOG_CHECKSUM_ALG_OFF; gtid_event.server_id= server_id; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 6d95ea33acc..e584c2cc144 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1827,13 +1827,8 @@ int wsrep_to_buf_helper( domain_id= wsrep_gtid_server.domain_id; server_id= wsrep_gtid_server.server_id; } - rpl_group_info* rgi = thd->slave_thread ? thd->rgi_slave : thd->wsrep_rgi; - const bool standalone = - rgi->gtid_ev_flags2 & Gtid_log_event::FL_STANDALONE; - const bool is_transactional = - rgi->gtid_ev_flags2 & Gtid_log_event::FL_TRANSACTIONAL; - Gtid_log_event gtid_event(thd, seqno, domain_id, standalone, - LOG_EVENT_SUPPRESS_USE_F, is_transactional, 0); + Gtid_log_event gtid_event(thd, seqno, domain_id, true, + LOG_EVENT_SUPPRESS_USE_F, true, 0); gtid_event.server_id= server_id; if (!gtid_event.is_valid()) ret= 0; ret= writer.write(>id_event); From 581712b989f47e4cc0206b0b470b8fcd80acbc83 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 10 May 2024 10:01:15 +1000 Subject: [PATCH 05/25] MDEV-33490 MENT-1504 Fix some english strings in spider. --- storage/spider/spd_db_mysql.cc | 4 ++-- storage/spider/spd_db_oracle.cc | 2 +- storage/spider/spd_err.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index d5f693c2cde..232a2b02c25 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -325,7 +325,7 @@ SPIDER_DBTON spider_dbton_mysql = { spider_mysql_create_conn, spider_mysql_support_direct_join, &spider_db_mysql_utility, - "For communicating to MySQL using native protocol", + "For communication with MySQL using the native protocol", "3.4.0", SPIDER_MATURITY_STABLE }; @@ -342,7 +342,7 @@ SPIDER_DBTON spider_dbton_mariadb = { spider_mariadb_create_conn, spider_mariadb_support_direct_join, &spider_db_mariadb_utility, - "For communicating to MariaDB using native protocol", + "For communication with MariaDB using the native protocol", "3.4.0", SPIDER_MATURITY_STABLE }; diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index a452cd2c8dc..362a77536ae 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -332,7 +332,7 @@ SPIDER_DBTON spider_dbton_oracle = { spider_oracle_create_conn, spider_oracle_support_direct_join, &spider_db_oracle_utility, - "For communicating Oracle using native protocol", + "For communication with Oracle using the native protocol", "1.0.0", SPIDER_MATURITY_BETA }; diff --git a/storage/spider/spd_err.h b/storage/spider/spd_err.h index 60b2a084714..368a9789fbd 100644 --- a/storage/spider/spd_err.h +++ b/storage/spider/spd_err.h @@ -80,13 +80,13 @@ #define ER_SPIDER_XA_PREPARED_NUM 12604 #define ER_SPIDER_XA_PREPARED_STR "This xid is prepared" #define ER_SPIDER_XA_EXISTS_NUM 12605 -#define ER_SPIDER_XA_EXISTS_STR "This xid is already exist" +#define ER_SPIDER_XA_EXISTS_STR "This xid already exists" #define ER_SPIDER_XA_MEMBER_EXISTS_NUM 12606 -#define ER_SPIDER_XA_MEMBER_EXISTS_STR "This xid member is already exist" +#define ER_SPIDER_XA_MEMBER_EXISTS_STR "This xid member already exists" #define ER_SPIDER_XA_NOT_EXISTS_NUM 12607 -#define ER_SPIDER_XA_NOT_EXISTS_STR "This xid is not exist" +#define ER_SPIDER_XA_NOT_EXISTS_STR "This xid does not exist" #define ER_SPIDER_XA_MEMBER_NOT_EXISTS_NUM 12608 -#define ER_SPIDER_XA_MEMBER_NOT_EXISTS_STR "This xid member is not exist" +#define ER_SPIDER_XA_MEMBER_NOT_EXISTS_STR "This xid member does not exist" #define ER_SPIDER_SYS_TABLE_VERSION_NUM 12609 #define ER_SPIDER_SYS_TABLE_VERSION_STR "System table %s is different version" #define ER_SPIDER_WRONG_CHARACTER_IN_NAME_NUM 12611 From 5e12d4920557ad7a678bdf41d6c0b4673fca838c Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 4 Jun 2024 15:06:37 +0400 Subject: [PATCH 06/25] MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning Field_string::val_int(), Field_string::val_real(), Field_string::val_decimal() passed the whole buffer of field_length bytes to data type conversion routines. This made conversion routines to print redundant trailing spaces in case of warnings. Adding a method Field_string::to_lex_cstring() and using it inside val_int(), val_real(), val_decimal(), val_str(). After this change conversion routines get the same value with what val_str() returns, and no redundant trailing spaces are displayed. --- mysql-test/main/sp-vars.result | 2 +- mysql-test/main/type_char.result | 40 +++++++++++++++++++ mysql-test/main/type_char.test | 19 +++++++++ mysql-test/main/type_varchar.result | 8 ++-- mysql-test/main/xml.result | 12 +++--- .../suite/funcs_1/r/innodb_func_view.result | 16 ++++---- .../suite/funcs_1/r/memory_func_view.result | 16 ++++---- .../suite/funcs_1/r/myisam_func_view.result | 16 ++++---- sql/field.cc | 40 +++++++++++-------- sql/field.h | 1 + 10 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 mysql-test/main/type_char.result create mode 100644 mysql-test/main/type_char.test diff --git a/mysql-test/main/sp-vars.result b/mysql-test/main/sp-vars.result index f0931ca48ff..e8e7b66b3ab 100644 --- a/mysql-test/main/sp-vars.result +++ b/mysql-test/main/sp-vars.result @@ -1171,7 +1171,7 @@ SET j= 1 + i; END| CALL ctest(); Warnings: -Warning 1292 Truncated incorrect DOUBLE value: 'string ' +Warning 1292 Truncated incorrect DOUBLE value: 'string' DROP PROCEDURE ctest; CREATE PROCEDURE vctest() BEGIN diff --git a/mysql-test/main/type_char.result b/mysql-test/main/type_char.result new file mode 100644 index 00000000000..07dfe7cdc29 --- /dev/null +++ b/mysql-test/main/type_char.result @@ -0,0 +1,40 @@ +# +# Start of 10.5 tests +# +# +# MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning +# +CREATE TABLE t1 (a CHAR(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci); +INSERT INTO t1 VALUES ('1x'), ('x'); +SELECT a, CAST(a AS DOUBLE) FROM t1 ORDER BY a; +a CAST(a AS DOUBLE) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1x' +Warning 1292 Truncated incorrect DOUBLE value: 'x' +SELECT a, CAST(a AS DECIMAL(20,2)) FROM t1 ORDER BY a; +a CAST(a AS DECIMAL(20,2)) +1x 1.00 +x 0.00 +Warnings: +Warning 1292 Truncated incorrect DECIMAL value: '1x' +Warning 1292 Truncated incorrect DECIMAL value: 'x' +SELECT a, CAST(a AS SIGNED) FROM t1 ORDER BY a; +a CAST(a AS SIGNED) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '1x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY a; +a CAST(a AS UNSIGNED) +1x 1 +x 0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '1x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/type_char.test b/mysql-test/main/type_char.test new file mode 100644 index 00000000000..053613c5dad --- /dev/null +++ b/mysql-test/main/type_char.test @@ -0,0 +1,19 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-34295 CAST(char_col AS DOUBLE) prints redundant spaces in a warning +--echo # + +CREATE TABLE t1 (a CHAR(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci); +INSERT INTO t1 VALUES ('1x'), ('x'); +SELECT a, CAST(a AS DOUBLE) FROM t1 ORDER BY a; +SELECT a, CAST(a AS DECIMAL(20,2)) FROM t1 ORDER BY a; +SELECT a, CAST(a AS SIGNED) FROM t1 ORDER BY a; +SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY a; +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/mysql-test/main/type_varchar.result b/mysql-test/main/type_varchar.result index d00531018a4..6c6e95e3721 100644 --- a/mysql-test/main/type_varchar.result +++ b/mysql-test/main/type_varchar.result @@ -465,7 +465,7 @@ a (a + 0) t 0 Warnings: Warning 1292 Truncated incorrect DOUBLE value: '1a' -Warning 1292 Truncated incorrect DOUBLE value: 't ' +Warning 1292 Truncated incorrect DOUBLE value: 't' SELECT a,(a DIV 2) FROM t1 ORDER BY a; a (a DIV 2) 10 5 @@ -476,7 +476,7 @@ a (a DIV 2) t 0 Warnings: Warning 1292 Truncated incorrect DECIMAL value: '1a' -Warning 1292 Truncated incorrect DECIMAL value: 't ' +Warning 1292 Truncated incorrect DECIMAL value: 't' SELECT a,CAST(a AS SIGNED) FROM t1 ORDER BY a; a CAST(a AS SIGNED) 10 10 @@ -508,8 +508,8 @@ SELECT 5 = a FROM t1; 0 0 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 's ' -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: 's' +Warning 1292 Truncated incorrect DECIMAL value: '' DROP TABLE t1; # # MDEV-13530 VARBINARY doesn't convert to to BLOB for sizes 65533, 65534 and 65535 diff --git a/mysql-test/main/xml.result b/mysql-test/main/xml.result index efaca961b4a..d0acb0debf3 100644 --- a/mysql-test/main/xml.result +++ b/mysql-test/main/xml.result @@ -991,20 +991,20 @@ CALL spxml('b1b2', '1 and string'); ExtractValue(xml,'/a/b[$i]') b1 Warnings: -Warning 1292 Truncated incorrect INTEGER value: '1 and string ' -Warning 1292 Truncated incorrect INTEGER value: '1 and string ' +Warning 1292 Truncated incorrect INTEGER value: '1 and string' +Warning 1292 Truncated incorrect INTEGER value: '1 and string' CALL spxml('b1b2', 'string and 1'); ExtractValue(xml,'/a/b[$i]') Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'string and 1 ' -Warning 1292 Truncated incorrect INTEGER value: 'string and 1 ' +Warning 1292 Truncated incorrect INTEGER value: 'string and 1' +Warning 1292 Truncated incorrect INTEGER value: 'string and 1' CALL spxml('b1b2', 'string'); ExtractValue(xml,'/a/b[$i]') Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'string ' -Warning 1292 Truncated incorrect INTEGER value: 'string ' +Warning 1292 Truncated incorrect INTEGER value: 'string' +Warning 1292 Truncated incorrect INTEGER value: 'string' DROP PROCEDURE spxml; select UpdateXML('a',repeat('a b ',1000),''); ERROR HY000: XPATH syntax error: 'b a b a b a b a b a b a b a b...' diff --git a/mysql-test/suite/funcs_1/r/innodb_func_view.result b/mysql-test/suite/funcs_1/r/innodb_func_view.result index e9fa172c321..90f2f3d3dc0 100644 --- a/mysql-test/suite/funcs_1/r/innodb_func_view.result +++ b/mysql-test/suite/funcs_1/r/innodb_func_view.result @@ -2202,9 +2202,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2218,9 +2218,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3523,9 +3523,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3540,9 +3540,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/memory_func_view.result b/mysql-test/suite/funcs_1/r/memory_func_view.result index 744166bb849..74b6206959a 100644 --- a/mysql-test/suite/funcs_1/r/memory_func_view.result +++ b/mysql-test/suite/funcs_1/r/memory_func_view.result @@ -2203,9 +2203,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2219,9 +2219,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3524,9 +3524,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3541,9 +3541,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' DROP VIEW v1; diff --git a/mysql-test/suite/funcs_1/r/myisam_func_view.result b/mysql-test/suite/funcs_1/r/myisam_func_view.result index 744166bb849..74b6206959a 100644 --- a/mysql-test/suite/funcs_1/r/myisam_func_view.result +++ b/mysql-test/suite/funcs_1/r/myisam_func_view.result @@ -2203,9 +2203,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select if(`t1_values`.`my_char_30`,'IS TRUE','IS NOT TRUE') AS `IF(my_char_30, 'IS TRUE', 'IS NOT TRUE')`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -2219,9 +2219,9 @@ IS NOT TRUE <--------30 characters-------> 3 IS NOT TRUE ---äÖüß@µ*$-- 4 IS TRUE -1 5 Warnings: -Warning 1292 Truncated incorrect DOUBLE value: ' ' +Warning 1292 Truncated incorrect DOUBLE value: '' Warning 1292 Truncated incorrect DOUBLE value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DOUBLE value: ' ---äÖüß@µ*$--' DROP VIEW v1; @@ -3524,9 +3524,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' SHOW CREATE VIEW v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(`t1_values`.`my_char_30` as decimal(37,2)) AS `CAST(my_char_30 AS DECIMAL(37,2))`,`t1_values`.`my_char_30` AS `my_char_30`,`t1_values`.`id` AS `id` from `t1_values` latin1 latin1_swedish_ci @@ -3541,9 +3541,9 @@ NULL NULL 1 -1.00 -1 5 -3333.33 -3333.3333 26 Warnings: -Warning 1292 Truncated incorrect DECIMAL value: ' ' +Warning 1292 Truncated incorrect DECIMAL value: '' Warning 1292 Truncated incorrect DECIMAL value: '<--------30 characters------->' -Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$-- ' +Warning 1292 Truncated incorrect DECIMAL value: ' ---äÖüß@µ*$--' DROP VIEW v1; diff --git a/sql/field.cc b/sql/field.cc index f03135a63bc..a423fdd0fa3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7485,11 +7485,11 @@ double Field_string::val_real(void) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); - return Converter_strntod_with_warn(get_thd(), + const LEX_CSTRING str= to_lex_cstring(); + return Converter_strntod_with_warn(thd, Warn_filter_string(thd, this), Field_string::charset(), - (const char *) ptr, - field_length).result(); + str.str, str.length).result(); } @@ -7497,10 +7497,10 @@ longlong Field_string::val_int(void) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); + const LEX_CSTRING str= to_lex_cstring(); return Converter_strntoll_with_warn(thd, Warn_filter_string(thd, this), Field_string::charset(), - (const char *) ptr, - field_length).result(); + str.str, str.length).result(); } @@ -7516,20 +7516,26 @@ sql_mode_t Field_string::can_handle_sql_mode_dependency_on_store() const } -String *Field_string::val_str(String *val_buffer __attribute__((unused)), - String *val_ptr) +LEX_CSTRING Field_string::to_lex_cstring() const { DBUG_ASSERT(marked_for_read()); /* See the comment for Field_long::store(long long) */ DBUG_ASSERT(!table || table->in_use == current_thd); - size_t length; - if (get_thd()->variables.sql_mode & - MODE_PAD_CHAR_TO_FULL_LENGTH) - length= field_charset()->charpos(ptr, ptr + field_length, - Field_string::char_length()); - else - length= field_charset()->lengthsp((const char*) ptr, field_length); - val_ptr->set((const char*) ptr, length, field_charset()); + if (get_thd()->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH) + return Lex_cstring((const char*) ptr, + field_charset()->charpos(ptr, ptr + field_length, + Field_string::char_length())); + return Lex_cstring((const char *) ptr, + field_charset()->lengthsp((const char*) ptr, field_length)); +} + + +String *Field_string::val_str(String *val_buffer __attribute__((unused)), + String *val_ptr) +{ + DBUG_ASSERT(marked_for_read()); + const LEX_CSTRING str= to_lex_cstring(); + val_ptr->set(str.str, str.length, field_charset()); return val_ptr; } @@ -7538,12 +7544,12 @@ my_decimal *Field_string::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(marked_for_read()); THD *thd= get_thd(); + const LEX_CSTRING str= to_lex_cstring(); Converter_str2my_decimal_with_warn(thd, Warn_filter_string(thd, this), E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM, Field_string::charset(), - (const char *) ptr, - field_length, decimal_value); + str.str, str.length, decimal_value); return decimal_value; } diff --git a/sql/field.h b/sql/field.h index 3da30453e1b..2eafb471d4b 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4013,6 +4013,7 @@ class Field_string final :public Field_longstr { field_length >= 4 && orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR; } + LEX_CSTRING to_lex_cstring() const; public: bool can_alter_field_type; Field_string(uchar *ptr_arg, uint32 len_arg,uchar *null_ptr_arg, From e9f4b87e530bc3806062c2b91a25052edd2c4325 Mon Sep 17 00:00:00 2001 From: Tuukka Pasanen Date: Tue, 16 Apr 2024 10:44:00 +0300 Subject: [PATCH 07/25] MDEV-33919: Remove less standard format directive an-trap Few man pages have less standard format directive: .it 1 an-trap which specifying a formatting instruction related to indentation (adds tab in man page in this) There is no traces what an-trap should do and removing it does not affect rendering of man page --- man/myisamchk.1 | 4 ++-- man/mysql_upgrade.1 | 4 ++-- man/mysqladmin.1 | 2 +- man/mysqlbinlog.1 | 8 ++++---- man/mysqlcheck.1 | 2 +- man/mysqld_safe.1 | 2 +- man/mysqldump.1 | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/man/myisamchk.1 b/man/myisamchk.1 index 456ffbbbf5c..612f48d513a 100644 --- a/man/myisamchk.1 +++ b/man/myisamchk.1 @@ -38,7 +38,7 @@ with partitioned tables is not supported\&. .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br @@ -168,7 +168,7 @@ the section called \(lqMYISAMCHK MEMORY USAGE\(rq\&. .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysql_upgrade.1 b/man/mysql_upgrade.1 index 3014ed52df5..312dcd04693 100644 --- a/man/mysql_upgrade.1 +++ b/man/mysql_upgrade.1 @@ -36,7 +36,7 @@ performs a table check\&. If any problems are found, a table repair is attempted .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br @@ -54,7 +54,7 @@ with administrator privileges\&. You can do this by running a Command Prompt as .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysqladmin.1 b/man/mysqladmin.1 index 02cf8b275a3..7756d4347d7 100644 --- a/man/mysqladmin.1 +++ b/man/mysqladmin.1 @@ -396,7 +396,7 @@ shell> \fBmysqladmin password "my new password"\fR .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysqlbinlog.1 b/man/mysqlbinlog.1 index 989749548b0..ca41a7b768a 100644 --- a/man/mysqlbinlog.1 +++ b/man/mysqlbinlog.1 @@ -167,7 +167,7 @@ option is given\&. .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br @@ -424,7 +424,7 @@ USE\&. (In particular, no cross\-database updates should be used\&.) .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br @@ -1307,7 +1307,7 @@ capability enabled\&. .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br @@ -1981,7 +1981,7 @@ shell> \fBmysqlbinlog \-v \-\-base64\-output=DECODE\-ROWS \fR\fB\fIlog_file\fR\f .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysqlcheck.1 b/man/mysqlcheck.1 index 2119e632a4b..a5606080ba3 100644 --- a/man/mysqlcheck.1 +++ b/man/mysqlcheck.1 @@ -101,7 +101,7 @@ with partitioned tables is not supported\&. .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysqld_safe.1 b/man/mysqld_safe.1 index 06e3dbdee0b..56ed00d4360 100644 --- a/man/mysqld_safe.1 +++ b/man/mysqld_safe.1 @@ -733,7 +733,7 @@ If none of these options is given, the default is .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br diff --git a/man/mysqldump.1 b/man/mysqldump.1 index c532228c652..f23c7e2491b 100644 --- a/man/mysqldump.1 +++ b/man/mysqldump.1 @@ -2345,7 +2345,7 @@ file that contains its data\&. The option value is the directory in which to wri .sp .\} .RS 4 -.it 1 an-trap +.it 1 .nr an-no-space-flag 1 .nr an-break-flag 1 .br From 042a0d85ad4f96229ab440cadb4ad3842c928c47 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 9 May 2024 10:28:55 +1000 Subject: [PATCH 08/25] MDEV-27186 spider/partition: Report error on info() failure Like MDEV-28105, spider may attempt to connect to remote server in info(), and it may emit an error upon failure to connect. In this case, the downstream caller ha_partition::open() should return the error to avoid inconsistency. This fixes MDEV-27186, MDEV-27237, MDEV-27334, MDEV-28241, MDEV-34101. --- sql/ha_partition.cc | 3 +- .../spider/bugfix/r/mdev_27186.result | 36 ++++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_27186.opt | 1 + .../spider/bugfix/t/mdev_27186.test | 37 +++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 735d5c4442d..0d2abc7d860 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3854,7 +3854,8 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) m_part_info->part_expr->get_monotonicity_info(); else if (m_part_info->list_of_part_fields) m_part_func_monotonicity_info= MONOTONIC_STRICT_INCREASING; - info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN); + if ((error= info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN))) + goto err_handler; DBUG_RETURN(0); err_handler: diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result new file mode 100644 index 00000000000..2b88b5da34c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result @@ -0,0 +1,36 @@ +INSTALL SONAME 'ha_spider'; +Warnings: +Warning 1105 Cannot enable tc-log at run-time. XA features of SPIDER are disabled +CREATE TABLE t (s INT) ENGINE=SPIDER PARTITION BY HASH (s); +LOAD INDEX INTO CACHE t PARTITION (p,p1); +Table Op Msg_type Msg_text +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys error Corrupt +DROP TABLE t; +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY KEY() PARTITIONS 2; +HANDLER t OPEN AS h; +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY HASH (c) PARTITIONS 2; +CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW INSERT INTO t VALUES(0); +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (b INT) ENGINE=InnoDB; +PREPARE s FROM 'SELECT * FROM t LIMIT 2'; +DROP TABLE t; +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +EXECUTE s; +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (c INT) ENGINE=InnoDB; +LOCK TABLES t WRITE; +CREATE OR REPLACE TABLE t (d INT) ENGINE=Spider PARTITION BY LIST COLUMNS (d) (PARTITION p VALUES IN (0)); +ERROR HY000: Unable to connect to foreign data source: localhost +drop table t; +Warnings: +Warning 1620 Plugin is busy and will be uninstalled on shutdown diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt new file mode 100644 index 00000000000..789275fa25e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt @@ -0,0 +1 @@ +--skip-log-bin diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test new file mode 100644 index 00000000000..67c038009ba --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test @@ -0,0 +1,37 @@ +INSTALL SONAME 'ha_spider'; + +# MDEV-27186 +CREATE TABLE t (s INT) ENGINE=SPIDER PARTITION BY HASH (s); +LOAD INDEX INTO CACHE t PARTITION (p,p1); +DROP TABLE t; + +# MDEV-27237 +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY KEY() PARTITIONS 2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +HANDLER t OPEN AS h; +DROP TABLE t; + +# MDEV-27334 +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY HASH (c) PARTITIONS 2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW INSERT INTO t VALUES(0); +DROP TABLE t; + +# MDEV-28241 +CREATE TABLE t (b INT) ENGINE=InnoDB; +PREPARE s FROM 'SELECT * FROM t LIMIT 2'; +DROP TABLE t; +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +EXECUTE s; +DROP TABLE t; + +# MDEV-34101 +CREATE TABLE t (c INT) ENGINE=InnoDB; +LOCK TABLES t WRITE; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +CREATE OR REPLACE TABLE t (d INT) ENGINE=Spider PARTITION BY LIST COLUMNS (d) (PARTITION p VALUES IN (0)); +drop table t; + +--disable_query_log +--source ../../include/clean_up_spider.inc From 4d38267fc7e886fc36fff66d14877c3f35f10ae4 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 1 Jun 2024 01:11:40 -0700 Subject: [PATCH 09/25] MDEV-29307 Wrong result when joining two derived tables over the same view This bug could affect queries containing a join of derived tables over grouping views such that one of the derived tables contains a window function while another uses view V with dependent subquery DSQ containing a set function aggregated outside of the subquery in the view V. The subquery also refers to the fields from the group clause of the view.Due to this bug execution of such queries could produce wrong result sets. When the fix_fields() method performs context analysis of a set function AF first, at the very beginning the function Item_sum::init_sum_func_check() is called. The function copies the pointer to the embedding set function, if any, stored in THD::LEX::in_sum_func into the corresponding field of the set function AF simultaneously changing the value of THD::LEX::in_sum_func to point to AF. When at the very end of the fix_fields() method the function Item_sum::check_sum_func() is called it is supposed to restore the value of THD::LEX::in_sum_func to point to the embedding set function. And in fact Item_sum::check_sum_func() did it, but only for regular set functions, not for those used in window functions. As a result after the context analysis of AF had finished THD::LEX::in_sum_func still pointed to AF. It confused the further context analysis. In particular it led to wrong resolution of Item_outer_ref objects in the fix_inner_refs() function. This wrong resolution forced reading the values of grouping fields referred in DSQ not from the temporary table used for aggregation from which they were supposed to be read, but from the table used as the source table for aggregation. This patch guarantees that the value of THD::LEX::in_sum_func is properly restored after the call of fix_fields() for any set function. --- mysql-test/main/win.result | 174 ++++++++++++++++++ mysql-test/main/win.test | 93 ++++++++++ .../encryption/r/tempfiles_encrypted.result | 174 ++++++++++++++++++ sql/item_sum.cc | 4 + 4 files changed, 445 insertions(+) diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result index 96b13010516..668f7b793cb 100644 --- a/mysql-test/main/win.result +++ b/mysql-test/main/win.result @@ -4391,3 +4391,177 @@ row_number() OVER (order by a) 2 3 drop table t1; +# +# MDEV-29307: join of 2 derived tables over the same grouping view such +# that the first of the joined tables contains a window +# function and the view's specification contains a subquery +# with a set function aggregated on the top level +# +CREATE TABLE t1 ( +tst int NOT NULL, +flat tinyint unsigned NOT NULL, +type tinyint unsigned NOT NULL, +val int NOT NULL, +PRIMARY KEY (tst,flat,type) +) ENGINE=ARIA; +INSERT INTO t1 VALUES +(5, 20, 2, 100), +(7, 20, 2, 150), +(9, 20, 1, 200); +CREATE VIEW v1 AS ( +SELECT +flat, +type, +( SELECT val FROM t1 sw +WHERE sw.tst = MAX(w.tst) AND sw.flat = w.flat AND sw.type = w.type) +AS total +FROM t1 w +GROUP BY flat, type +); +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY ref key0 key0 1 v1.flat 2 100.00 Using where +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`v1`.`total` AS `w1_total` from `test`.`v1` join `test`.`v1` where `v1`.`flat` = `v1`.`flat` and `v1`.`type` = 2 and `v1`.`type` = 1 +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +w2_total w1_total +150 200 +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY ref key0 key0 1 w1.flat 2 100.00 Using where +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +2 DERIVED ALL NULL NULL NULL NULL 3 100.00 Using where; Using temporary +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`type` order by `v1`.`type`) AS `u` from `test`.`v1` where `v1`.`type` = 1) `w1` join `test`.`v1` where `v1`.`flat` = `w1`.`flat` and `v1`.`type` = 2 +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +w2_total w1_total +150 200 +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total, u +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u +FROM v1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +) AS w2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +2 DERIVED ALL NULL NULL NULL NULL 3 100.00 Using temporary +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total`,`w1`.`u` AS `u` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`flat` order by `v1`.`flat`) AS `u` from `test`.`v1`) `w1` join `test`.`v1` +SELECT w2.total AS w2_total, w1.total AS w1_total, u +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u +FROM v1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +) AS w2; +w2_total w1_total u +150 150 2 +150 200 2 +200 150 2 +200 200 2 +DROP VIEW v1; +DROP TABLE t1; +# End of 10.5 tests diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test index cba6b0fd7af..363bf8f8ad9 100644 --- a/mysql-test/main/win.test +++ b/mysql-test/main/win.test @@ -2873,3 +2873,96 @@ create table t1 (a int); insert into t1 values (1),(2),(3); SELECT row_number() OVER (order by a) FROM t1 order by NAME_CONST('myname',NULL); drop table t1; + +--echo # +--echo # MDEV-29307: join of 2 derived tables over the same grouping view such +--echo # that the first of the joined tables contains a window +--echo # function and the view's specification contains a subquery +--echo # with a set function aggregated on the top level +--echo # + +CREATE TABLE t1 ( + tst int NOT NULL, + flat tinyint unsigned NOT NULL, + type tinyint unsigned NOT NULL, + val int NOT NULL, + PRIMARY KEY (tst,flat,type) +) ENGINE=ARIA; + +INSERT INTO t1 VALUES +(5, 20, 2, 100), +(7, 20, 2, 150), +(9, 20, 1, 200); + +CREATE VIEW v1 AS ( + SELECT + flat, + type, + ( SELECT val FROM t1 sw + WHERE sw.tst = MAX(w.tst) AND sw.flat = w.flat AND sw.type = w.type) + AS total + FROM t1 w + GROUP BY flat, type +); + +let $q1= +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( + SELECT flat, type, total + FROM v1 + WHERE type = 1 +) AS w1 +JOIN +( + SELECT flat, type, total + FROM v1 + WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; + +eval EXPLAIN EXTENDED $q1; +eval $q1; + +let $q2= +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( + SELECT flat, type, total, + COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u + FROM v1 + WHERE type = 1 +) AS w1 +JOIN +( + SELECT flat, type, total + FROM v1 + WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; + +eval EXPLAIN EXTENDED $q2; +eval $q2; + +let $q3= +SELECT w2.total AS w2_total, w1.total AS w1_total, u +FROM +( + SELECT flat, type, total, + COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u + FROM v1 +) AS w1 +JOIN +( + SELECT flat, type, total + FROM v1 +) AS w2; + +eval EXPLAIN EXTENDED $q3; +--sorted_result +eval $q3; + +DROP VIEW v1; +DROP TABLE t1; + +--echo # End of 10.5 tests diff --git a/mysql-test/suite/encryption/r/tempfiles_encrypted.result b/mysql-test/suite/encryption/r/tempfiles_encrypted.result index 5b9dab62c01..b913b295ad3 100644 --- a/mysql-test/suite/encryption/r/tempfiles_encrypted.result +++ b/mysql-test/suite/encryption/r/tempfiles_encrypted.result @@ -4398,6 +4398,180 @@ row_number() OVER (order by a) 3 drop table t1; # +# MDEV-29307: join of 2 derived tables over the same grouping view such +# that the first of the joined tables contains a window +# function and the view's specification contains a subquery +# with a set function aggregated on the top level +# +CREATE TABLE t1 ( +tst int NOT NULL, +flat tinyint unsigned NOT NULL, +type tinyint unsigned NOT NULL, +val int NOT NULL, +PRIMARY KEY (tst,flat,type) +) ENGINE=ARIA; +INSERT INTO t1 VALUES +(5, 20, 2, 100), +(7, 20, 2, 150), +(9, 20, 1, 200); +CREATE VIEW v1 AS ( +SELECT +flat, +type, +( SELECT val FROM t1 sw +WHERE sw.tst = MAX(w.tst) AND sw.flat = w.flat AND sw.type = w.type) +AS total +FROM t1 w +GROUP BY flat, type +); +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY ref key0 key0 1 v1.flat 2 100.00 Using where +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`v1`.`total` AS `w1_total` from `test`.`v1` join `test`.`v1` where `v1`.`flat` = `v1`.`flat` and `v1`.`type` = 2 and `v1`.`type` = 1 +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +w2_total w1_total +150 200 +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY ref key0 key0 1 w1.flat 2 100.00 Using where +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +2 DERIVED ALL NULL NULL NULL NULL 3 100.00 Using where; Using temporary +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using where; Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`type` order by `v1`.`type`) AS `u` from `test`.`v1` where `v1`.`type` = 1) `w1` join `test`.`v1` where `v1`.`flat` = `w1`.`flat` and `v1`.`type` = 2 +SELECT w2.total AS w2_total, w1.total AS w1_total +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY type ORDER BY type) AS u +FROM v1 +WHERE type = 1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +WHERE type = 2 +) AS w2 +ON w1.flat = w2.flat; +w2_total w1_total +150 200 +EXPLAIN EXTENDED SELECT w2.total AS w2_total, w1.total AS w1_total, u +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u +FROM v1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +) AS w2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +6 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort +7 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +2 DERIVED ALL NULL NULL NULL NULL 3 100.00 Using temporary +4 DERIVED w index NULL PRIMARY 6 NULL 3 100.00 Using index; Using temporary; Using filesort +5 DEPENDENT SUBQUERY sw eq_ref PRIMARY PRIMARY 6 func,func,func 1 100.00 Using index condition +Warnings: +Note 1276 Field or reference 'test.w.tst' of SELECT #5 was resolved in SELECT #4 +Note 1981 Aggregate function 'max()' of SELECT #5 belongs to SELECT #4 +Note 1276 Field or reference 'test.w.flat' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.type' of SELECT #5 was resolved in SELECT #4 +Note 1276 Field or reference 'test.w.tst' of SELECT #7 was resolved in SELECT #6 +Note 1981 Aggregate function 'max()' of SELECT #7 belongs to SELECT #6 +Note 1276 Field or reference 'test.w.flat' of SELECT #7 was resolved in SELECT #6 +Note 1276 Field or reference 'test.w.type' of SELECT #7 was resolved in SELECT #6 +Note 1003 /* select#1 */ select `v1`.`total` AS `w2_total`,`w1`.`total` AS `w1_total`,`w1`.`u` AS `u` from (/* select#2 */ select `v1`.`flat` AS `flat`,`v1`.`type` AS `type`,`v1`.`total` AS `total`,count(`v1`.`total`) over ( partition by `v1`.`flat` order by `v1`.`flat`) AS `u` from `test`.`v1`) `w1` join `test`.`v1` +SELECT w2.total AS w2_total, w1.total AS w1_total, u +FROM +( +SELECT flat, type, total, +COUNT(total) OVER (PARTITION BY flat ORDER BY flat) AS u +FROM v1 +) AS w1 +JOIN +( +SELECT flat, type, total +FROM v1 +) AS w2; +w2_total w1_total u +150 150 2 +150 200 2 +200 150 2 +200 200 2 +DROP VIEW v1; +DROP TABLE t1; +# End of 10.5 tests +# # MDEV-23867: select crash in compute_window_func # set @save_sort_buffer_size=@@sort_buffer_size; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 4cf403c1618..a7fae9ea4c0 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -177,7 +177,11 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) } if (window_func_sum_expr_flag) + { + thd->lex->in_sum_func= in_sum_func; return false; + } + /* The value of max_arg_level is updated if an argument of the set function contains a column reference resolved against a subquery whose level is From ecf4a261076c461e467c17d7664c11a885d2babb Mon Sep 17 00:00:00 2001 From: ilyasa1211 Date: Wed, 29 May 2024 13:59:46 +1000 Subject: [PATCH 10/25] Fix Indonesian month name. Noticed on MySQL: https://github.com/mysql/mysql-server/pull/531 Matches https://icu4c-demos.unicode.org/icu-bin/locexp?d_=en&_=in_IN. --- sql/sql_locale.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_locale.cc b/sql/sql_locale.cc index 60e7abc3fa2..ba5c12153c7 100644 --- a/sql/sql_locale.cc +++ b/sql/sql_locale.cc @@ -968,9 +968,9 @@ MY_LOCALE my_locale_hu_HU /***** LOCALE BEGIN id_ID: Indonesian - Indonesia *****/ static const char *my_locale_month_names_id_ID[13] = - {"Januari","Pebruari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember", NullS }; + {"Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember", NullS }; static const char *my_locale_ab_month_names_id_ID[13] = - {"Jan","Peb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des", NullS }; + {"Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des", NullS }; static const char *my_locale_day_names_id_ID[8] = {"Senin","Selasa","Rabu","Kamis","Jumat","Sabtu","Minggu", NullS }; static const char *my_locale_ab_day_names_id_ID[8] = From c6d36c3e7c58a968cc0aaada0b5194cea8e85f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 5 Jun 2024 09:25:20 +0300 Subject: [PATCH 11/25] MDEV-34297 get_rnd_value() of ib_counter_t is unnecessarily complex The shared counter template ib_counter_t uses the function my_timer_cycles() as a source of pseudo-random numbers to pick a shard. On some platforms, my_timer_cycles() could return the constant value 0. get_rnd_value(): Remove. my_pseudo_random(): Implement as an alias of my_timer_cycles() or a wrapper for pthread_self(). Reviewed by: Vladislav Vaintroub --- include/my_rdtsc.h | 13 +++++++++++++ storage/innobase/include/sync0arr.inl | 2 +- storage/innobase/include/ut0counter.h | 26 +------------------------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/include/my_rdtsc.h b/include/my_rdtsc.h index e81015166d2..9729a47d4a5 100644 --- a/include/my_rdtsc.h +++ b/include/my_rdtsc.h @@ -177,10 +177,23 @@ static inline ulonglong my_timer_cycles(void) /* gethrtime may appear as either cycle or nanosecond counter */ return (ulonglong) gethrtime(); #else +# define MY_TIMER_CYCLES_IS_ZERO return 0; #endif } +#ifdef MY_TIMER_CYCLES_IS_ZERO +static inline size_t my_pseudo_random(void) +{ + /* In some platforms, pthread_self() might return a structure + that cannot be converted to a number like this. Possible alternatives + could include gettid() or sched_getcpu(). */ + return ((size_t) pthread_self()) / 16; +} +#else +# define my_pseudo_random my_timer_cycles +#endif + /** A nanosecond timer. @return the current timer value, in nanoseconds. diff --git a/storage/innobase/include/sync0arr.inl b/storage/innobase/include/sync0arr.inl index 962226b4934..e5eb126aea2 100644 --- a/storage/innobase/include/sync0arr.inl +++ b/storage/innobase/include/sync0arr.inl @@ -44,7 +44,7 @@ sync_array_get() return(sync_wait_array[0]); } - return(sync_wait_array[get_rnd_value() % sync_array_size]); + return(sync_wait_array[my_pseudo_random() % sync_array_size]); } /******************************************************************//** diff --git a/storage/innobase/include/ut0counter.h b/storage/innobase/include/ut0counter.h index 646a5f367c2..0083627b91f 100644 --- a/storage/innobase/include/ut0counter.h +++ b/storage/innobase/include/ut0counter.h @@ -41,30 +41,6 @@ Created 2012/04/12 by Sunny Bains /** Default number of slots to use in ib_counter_t */ #define IB_N_SLOTS 64 -/** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles -as a random value. See the comments for my_timer_cycles() */ -/** @return result from RDTSC or similar functions. */ -static inline size_t -get_rnd_value() -{ - size_t c = static_cast(my_timer_cycles()); - - if (c != 0) { - return c; - } - - /* We may go here if my_timer_cycles() returns 0, - so we have to have the plan B for the counter. */ -#if !defined(_WIN32) - return (size_t)os_thread_get_curr_id(); -#else - LARGE_INTEGER cnt; - QueryPerformanceCounter(&cnt); - - return static_cast(cnt.QuadPart); -#endif /* !_WIN32 */ -} - /** Class for using fuzzy counters. The counter is multi-instance relaxed atomic so the results are not guaranteed to be 100% accurate but close enough. Creates an array of counters and separates each element by the @@ -80,7 +56,7 @@ struct ib_counter_t { /** Add to the counter. @param[in] n amount to be added */ - void add(Type n) { add(get_rnd_value(), n); } + void add(Type n) { add(my_pseudo_random(), n); } /** Add to the counter. @param[in] index a reasonably thread-unique identifier From 38cbef8b3f7fac55182009fd141175a062728657 Mon Sep 17 00:00:00 2001 From: Monty Date: Wed, 5 Jun 2024 10:22:27 +0300 Subject: [PATCH 12/25] MDEV-22935 Erroneous Aria Index / Optimizer behaviour The problem was in the Aria part of the range optimizer, maria_records_in_range(), which wrong concluded that there was no rows in the range. This error would happen in the unlikely case when searching for a range on a partial key and there was a match for the first key part in the upper part of the b-tree (node) and also a match in the underlying node page. In other words, for this bug to happen one have to use Aria, have a multi part key with a lot of identical values for the first key part and do a range search on the second part of the key. Fixed by ensuring that we do not stop searching for partial keys found on node. Other things: - Added some comments - Changed a variable name to more clearly explain it's purpose. - Fixed wrong cast in _ma_record_pos() that could cause problems on 32 bit systems. --- mysql-test/suite/maria/range.result | 6 ++++++ mysql-test/suite/maria/range.test | 22 ++++++++++++++++++++++ storage/maria/ma_range.c | 15 ++++++++------- 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 mysql-test/suite/maria/range.result create mode 100644 mysql-test/suite/maria/range.test diff --git a/mysql-test/suite/maria/range.result b/mysql-test/suite/maria/range.result new file mode 100644 index 00000000000..49b8dc0fdc0 --- /dev/null +++ b/mysql-test/suite/maria/range.result @@ -0,0 +1,6 @@ +# +# MDEV-22935 Erroneous Aria Index / Optimizer behaviour +# +create table t1 (a char(255), b datetime, primary key(a,b)) engine=aria transactional=0 pack_keys=0; +insert into t1 select concat("hello world hello world", truncate(seq/100,0)),from_unixtime(seq+1) from seq_1_to_20000; +drop table t1; diff --git a/mysql-test/suite/maria/range.test b/mysql-test/suite/maria/range.test new file mode 100644 index 00000000000..00a74ad30c4 --- /dev/null +++ b/mysql-test/suite/maria/range.test @@ -0,0 +1,22 @@ +--source include/have_sequence.inc + +--echo # +--echo # MDEV-22935 Erroneous Aria Index / Optimizer behaviour +--echo # + +create table t1 (a char(255), b datetime, primary key(a,b)) engine=aria transactional=0 pack_keys=0; +insert into t1 select concat("hello world hello world", truncate(seq/100,0)),from_unixtime(seq+1) from seq_1_to_20000; + +let $i= 200; +--disable_query_log +while ($i) +{ + let $tmp= `select count(*) from t1 where a="hello world hello world$i" and b <= from_unixtime($i*100+1)`; + if (`SELECT $tmp != 1`) + { + --echo "Found $tmp rows, expected 1, for value $i" + } + dec $i; +} +--enable_query_log +drop table t1; diff --git a/storage/maria/ma_range.c b/storage/maria/ma_range.c index 442adc35858..525bf27b90c 100644 --- a/storage/maria/ma_range.c +++ b/storage/maria/ma_range.c @@ -191,8 +191,8 @@ static ha_rows _ma_record_pos(MARIA_HA *info, const uchar *key_data, info->s->state.key_root[inx], final_page); if (pos >= 0.0) { - DBUG_PRINT("exit",("pos: %ld",(ulong) (pos*info->state->records))); - DBUG_RETURN((ulong) (pos*info->state->records+0.5)); + DBUG_PRINT("exit",("pos: %lld",(longlong) (pos*info->state->records))); + DBUG_RETURN((ha_rows) (pos*info->state->records+0.5)); } DBUG_RETURN(HA_POS_ERROR); } @@ -214,7 +214,7 @@ static double _ma_search_pos(MARIA_HA *info, MARIA_KEY *key, { int flag; uint keynr, UNINIT_VAR(max_keynr); - my_bool after_key; + my_bool last_key_on_page; uchar *keypos; double offset; MARIA_KEYDEF *keyinfo= key->keyinfo; @@ -230,7 +230,7 @@ static double _ma_search_pos(MARIA_HA *info, MARIA_KEY *key, goto err; *final_page= pos; flag= (*keyinfo->bin_search)(key, &page, nextflag, &keypos, - info->lastkey_buff, &after_key); + info->lastkey_buff, &last_key_on_page); keynr= _ma_keynr(&page, keypos, &max_keynr); if (flag) @@ -274,7 +274,7 @@ static double _ma_search_pos(MARIA_HA *info, MARIA_KEY *key, There may be identical keys in the tree. Try to match on of those. Matches keynr + [0-1] */ - if ((offset= _ma_search_pos(info, key, SEARCH_FIND, + if ((offset= _ma_search_pos(info, key, nextflag, _ma_kpos(page.node,keypos), final_page)) < 0) DBUG_RETURN(offset); /* Read error */ @@ -290,9 +290,10 @@ err: /* - Get keynummer of current key and max number of keys in nod + Get keynumber of current key and max number of keys in nod - keynr >= 0 && key_nr <= max_key + @return key position on page (0 - (ret_max_key - 1)) + ret_max_key contains how many keys there was on the page */ static uint _ma_keynr(MARIA_PAGE *page, uchar *keypos, uint *ret_max_key) From 40abd973ab3813a7f3ac1ae961ed094ab251f3cf Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 5 Jun 2024 11:54:34 +0200 Subject: [PATCH 13/25] MDEV-34236 Mroonga build with ASAN/UBSAN with GCC 12+ extremely slow. Workaround by disabling sanitizer for single source file. --- storage/mroonga/vendor/groonga/lib/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/storage/mroonga/vendor/groonga/lib/CMakeLists.txt b/storage/mroonga/vendor/groonga/lib/CMakeLists.txt index 4f076458a36..1149458d523 100644 --- a/storage/mroonga/vendor/groonga/lib/CMakeLists.txt +++ b/storage/mroonga/vendor/groonga/lib/CMakeLists.txt @@ -188,3 +188,15 @@ IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "5") ADD_COMPILE_FLAGS(ts/ts_expr_node.c COMPILE_FLAGS "-fno-tree-loop-vectorize") ENDIF() + +# Workaround long compile times with GCC and sanitizers +IF(CMAKE_C_COMPILER_ID STREQUAL "GNU" + AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "11.99") + IF(WITH_UBSAN) + ADD_COMPILE_FLAGS(expr.c COMPILE_FLAGS "-fno-sanitize=undefined") + ENDIF() + IF(WITH_ASAN) + ADD_COMPILE_FLAGS(expr.c COMPILE_FLAGS "-fno-sanitize=address") + ENDIF() +ENDIF() + From b242b44f0ace0fdaf9f63861ca4ad72a36d35937 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 5 Jun 2024 12:13:33 +0200 Subject: [PATCH 14/25] Appveyor build - skip irrelevant commits Since we're only building on Windows, skip changes to debian directory and to shell scripts. --- appveyor.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index b0820784bd9..f7fc71d291d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,4 +27,9 @@ test_script: - set /A parallel=4*%NUMBER_OF_PROCESSORS% - perl mysql-test-run.pl --force --max-test-fail=10 --retry=2 --parallel=%parallel% --testcase-timeout=4 --suite=main --skip-test-list=unstable-tests --mysqld=--loose-innodb-flush-log-at-trx-commit=2 +skip_commits: + files: + - debian/ + - '**/*.sh' + image: Visual Studio 2022 From bfd3f45e8e041a650a32eeca08e506ed70f847a1 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 5 Jun 2024 12:26:46 +0200 Subject: [PATCH 15/25] Appveyor - better filtering for branches to match buildbot --- appveyor.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index f7fc71d291d..c28d9a4d5db 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,4 +32,9 @@ skip_commits: - debian/ - '**/*.sh' +branches: + only: + - /bb-/ + - /d+\.\d+/ + image: Visual Studio 2022 From db9c2d225e1085b5c23f7776ee6936be7952aeb6 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 5 Jun 2024 13:14:20 +0200 Subject: [PATCH 16/25] fix typo --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index c28d9a4d5db..de8f52577f7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -35,6 +35,6 @@ skip_commits: branches: only: - /bb-/ - - /d+\.\d+/ + - /\d+\.\d+$/ image: Visual Studio 2022 From 7d86751de5626d685873bc3c7d9e585a922fc5aa Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Sat, 1 Jun 2024 00:04:45 +0200 Subject: [PATCH 17/25] mtr: run check-testcase client process under debugger --- mysql-test/mysql-test-run.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index d1ad3bdea77..39df025ecbd 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -5526,6 +5526,8 @@ sub start_check_testcase ($$$) { mtr_add_arg($args, "--record"); } my $errfile= "$opt_vardir/tmp/$name.err"; + + My::Debugger::setup_client_args(\$args, \$exe_mysqltest); my $proc= My::SafeProcess->new ( name => $name, From ce9efb4e0223c978dcf4511ed33f5118e3b3c3ce Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 5 Jun 2024 16:34:50 +0200 Subject: [PATCH 18/25] MDEV-34296 tpool - declare thread_local_waiter "static thread_local" --- storage/innobase/log/log0sync.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/innobase/log/log0sync.cc b/storage/innobase/log/log0sync.cc index 2a6e1b8b853..0129ad1e324 100644 --- a/storage/innobase/log/log0sync.cc +++ b/storage/innobase/log/log0sync.cc @@ -186,7 +186,7 @@ void group_commit_lock::set_pending(group_commit_lock::value_type num) } const unsigned int MAX_SPINS = 1; /** max spins in acquire */ -thread_local group_commit_waiter_t thread_local_waiter; +static thread_local group_commit_waiter_t thread_local_waiter; group_commit_lock::lock_return_code group_commit_lock::acquire(value_type num) { From 0406b2a4ed11fd32532eadcc2d78f936b137f0cd Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Wed, 15 May 2024 17:06:20 +0530 Subject: [PATCH 19/25] MDEV-34143: Server crashes when executing JSON_EXTRACT after setting non-default collation_connection Analysis: Due to different collation, the string has nothing to chop off. Fix: Got rid of chop(), only append " ," only when we have more elements to add to the result. --- mysql-test/main/func_json.result | 11 +++++++++++ mysql-test/main/func_json.test | 12 ++++++++++++ sql/item_jsonfunc.cc | 20 +++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 591e8813a0f..50861c4f7cb 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1717,5 +1717,16 @@ SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D'); JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D') {"A": {"B": 1}} # +# MDEV-34143: Server crashes when executing JSON_EXTRACT after setting non-default collation_connection +# +SET @save_collation_connection= @@collation_connection; +SET collation_connection='utf16_bin'; +SELECT JSON_EXTRACT('{"a": 1,"b": 2}','$.a'); +JSON_EXTRACT('{"a": 1,"b": 2}','$.a') +NULL +Warnings: +Warning 4036 Character disallowed in JSON in argument 1 to function 'json_extract' at position 2 +SET @@collation_connection= @save_collation_connection; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index 9f08c30f7cf..9abdded34d2 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -1147,6 +1147,18 @@ SELECT JSON_TYPE(json_value(JSON_OBJECT("id", 1, "name", 'Monty', "date", Cast(' SELECT JSON_REMOVE('{"A": { "B": 1 }}', '$.A.B.C.D'); + +--echo # +--echo # MDEV-34143: Server crashes when executing JSON_EXTRACT after setting non-default collation_connection +--echo # + +SET @save_collation_connection= @@collation_connection; + +SET collation_connection='utf16_bin'; +SELECT JSON_EXTRACT('{"a": 1,"b": 2}','$.a'); + +SET @@collation_connection= @save_collation_connection; + --echo # --echo # End of 10.5 tests --echo # diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 442c4cbed90..f4cf9022ba9 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1003,11 +1003,18 @@ String *Item_func_json_extract::read_json(String *str, je= sav_je; } - for (int count= 0; count < count_path; count++) + if ((not_first_value && str->append(", ", 2))) + goto error; + while(count_path) { - if (str->append((const char *) value, v_len) || - str->append(", ", 2)) - goto error; /* Out of memory. */ + if (str->append((const char *) value, v_len)) + goto error; + count_path--; + if (count_path) + { + if (str->append(", ", 2)) + goto error; + } } not_first_value= 1; @@ -1029,11 +1036,6 @@ String *Item_func_json_extract::read_json(String *str, goto return_null; } - if (str->length()>2) - { - str->chop(); - str->chop(); - } if (possible_multiple_values && str->append("]", 1)) goto error; /* Out of memory. */ From a02773f7c000273dd823df6bb386c4d735c3dcc7 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 6 Jun 2024 19:09:13 +0530 Subject: [PATCH 20/25] MDEV-34057 Inconsistent FTS state in concurrent scenarios Problem: ======= - This commit is a merge of mysql commit 129ee47ef994652081a11ee9040c0488e5275b14. InnoDB FTS can be in inconsistent state when sync operation terminates the server before committing the operation. This could lead to incorrect synced doc id and incorrect query results. Solution: ======== - During sync commit operation, InnoDB should pass the sync transaction to update the max doc id in the config table. fts_read_synced_doc_id() : This function is used to read only synced doc id from the config table. --- .../r/fts_sync_commit_resiliency.result | 63 +++++++ .../t/fts_sync_commit_resiliency.opt | 1 + .../t/fts_sync_commit_resiliency.test | 47 +++++ storage/innobase/fts/fts0fts.cc | 168 ++++++++++-------- 4 files changed, 201 insertions(+), 78 deletions(-) create mode 100644 mysql-test/suite/innodb_fts/r/fts_sync_commit_resiliency.result create mode 100644 mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.opt create mode 100644 mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.test diff --git a/mysql-test/suite/innodb_fts/r/fts_sync_commit_resiliency.result b/mysql-test/suite/innodb_fts/r/fts_sync_commit_resiliency.result new file mode 100644 index 00000000000..1908502c9db --- /dev/null +++ b/mysql-test/suite/innodb_fts/r/fts_sync_commit_resiliency.result @@ -0,0 +1,63 @@ +CREATE TABLE opening_lines ( +id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, +opening_line TEXT(500), +author VARCHAR(200), +title VARCHAR(200) +) ENGINE=InnoDB; +CREATE FULLTEXT INDEX idx ON opening_lines(opening_line); +CREATE FULLTEXT INDEX ft_idx1 ON opening_lines(title); +INSERT INTO opening_lines(opening_line,author,title) VALUES +('Call me Ishmael.','Herman Melville','Moby Dick'), +('A screaming comes across the sky.','Thomas Pynchon','Gravity\'s Rainbow'), + ('I am an invisible man.','Ralph Ellison','Invisible Man'), + ('Where now? Who now? When now?','Samuel Beckett','The Unnamable'), + ('It was love at first sight.','Joseph Heller','Catch-22'), + ('All this happened, more or less.','Kurt Vonnegut','Slaughterhouse-Five'), + ('Mrs. Dalloway said she would buy the flowers herself.','Virginia Woolf','Mrs. Dalloway'), + ('It was a pleasure to burn.','Ray Bradbury','Fahrenheit 451'); +SET GLOBAL innodb_ft_aux_table='test/opening_lines'; +SELECT * FROM information_schema.innodb_ft_config; +KEY VALUE +optimize_checkpoint_limit 180 +synced_doc_id 0 +stopword_table_name +use_stopword 1 +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael'); +id opening_line author title +1 Call me Ishmael. Herman Melville Moby Dick +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('invisible'); +id opening_line author title +3 I am an invisible man. Ralph Ellison Invisible Man +SELECT * FROM opening_lines; +id opening_line author title +1 Call me Ishmael. Herman Melville Moby Dick +2 A screaming comes across the sky. Thomas Pynchon Gravity's Rainbow +3 I am an invisible man. Ralph Ellison Invisible Man +4 Where now? Who now? When now? Samuel Beckett The Unnamable +5 It was love at first sight. Joseph Heller Catch-22 +6 All this happened, more or less. Kurt Vonnegut Slaughterhouse-Five +7 Mrs. Dalloway said she would buy the flowers herself. Virginia Woolf Mrs. Dalloway +8 It was a pleasure to burn. Ray Bradbury Fahrenheit 451 +SET GLOBAL innodb_optimize_fulltext_only=ON; +SET DEBUG_SYNC='fts_crash_before_commit_sync SIGNAL hung WAIT_FOR ever'; +OPTIMIZE TABLE opening_lines; +connect con1,localhost,root,,; +SET DEBUG_SYNC='now WAIT_FOR hung'; +# restart +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael'); +id opening_line author title +1 Call me Ishmael. Herman Melville Moby Dick +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('invisible'); +id opening_line author title +3 I am an invisible man. Ralph Ellison Invisible Man +SELECT * FROM opening_lines; +id opening_line author title +1 Call me Ishmael. Herman Melville Moby Dick +2 A screaming comes across the sky. Thomas Pynchon Gravity's Rainbow +3 I am an invisible man. Ralph Ellison Invisible Man +4 Where now? Who now? When now? Samuel Beckett The Unnamable +5 It was love at first sight. Joseph Heller Catch-22 +6 All this happened, more or less. Kurt Vonnegut Slaughterhouse-Five +7 Mrs. Dalloway said she would buy the flowers herself. Virginia Woolf Mrs. Dalloway +8 It was a pleasure to burn. Ray Bradbury Fahrenheit 451 +DROP TABLE opening_lines; diff --git a/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.opt b/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.opt new file mode 100644 index 00000000000..9e0e66f6620 --- /dev/null +++ b/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.opt @@ -0,0 +1 @@ +--innodb_ft_config diff --git a/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.test b/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.test new file mode 100644 index 00000000000..357d001f6e6 --- /dev/null +++ b/mysql-test/suite/innodb_fts/t/fts_sync_commit_resiliency.test @@ -0,0 +1,47 @@ +# Test database resiliency against scenario where the server crashes +# right before fts_sync_commit commits its transaction +source include/have_innodb.inc; +source include/have_debug.inc; +source include/not_embedded.inc; +source include/have_debug_sync.inc; + +CREATE TABLE opening_lines ( + id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, + opening_line TEXT(500), + author VARCHAR(200), + title VARCHAR(200) + ) ENGINE=InnoDB; + +CREATE FULLTEXT INDEX idx ON opening_lines(opening_line); +CREATE FULLTEXT INDEX ft_idx1 ON opening_lines(title); + +INSERT INTO opening_lines(opening_line,author,title) VALUES + ('Call me Ishmael.','Herman Melville','Moby Dick'), + ('A screaming comes across the sky.','Thomas Pynchon','Gravity\'s Rainbow'), + ('I am an invisible man.','Ralph Ellison','Invisible Man'), + ('Where now? Who now? When now?','Samuel Beckett','The Unnamable'), + ('It was love at first sight.','Joseph Heller','Catch-22'), + ('All this happened, more or less.','Kurt Vonnegut','Slaughterhouse-Five'), + ('Mrs. Dalloway said she would buy the flowers herself.','Virginia Woolf','Mrs. Dalloway'), + ('It was a pleasure to burn.','Ray Bradbury','Fahrenheit 451'); + +SET GLOBAL innodb_ft_aux_table='test/opening_lines'; +SELECT * FROM information_schema.innodb_ft_config; + +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael'); +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('invisible'); +SELECT * FROM opening_lines; + +SET GLOBAL innodb_optimize_fulltext_only=ON; +SET DEBUG_SYNC='fts_crash_before_commit_sync SIGNAL hung WAIT_FOR ever'; +send OPTIMIZE TABLE opening_lines; + +connect(con1,localhost,root,,); +SET DEBUG_SYNC='now WAIT_FOR hung'; +let $shutdown_timeout=0; +--source include/restart_mysqld.inc + +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael'); +SELECT * FROM opening_lines WHERE MATCH(opening_line) AGAINST('invisible'); +SELECT * FROM opening_lines; +DROP TABLE opening_lines; diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 3e57773d32c..ba28eead0b2 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -2607,89 +2607,85 @@ fts_get_next_doc_id( return(DB_SUCCESS); } -/*********************************************************************//** -This function fetch the Doc ID from CONFIG table, and compare with +/** Read the synced document id from the fts configuration table +@param table fts table +@param doc_id document id to be read +@param trx transaction to read from config table +@return DB_SUCCESS in case of success */ +static +dberr_t fts_read_synced_doc_id(const dict_table_t *table, + doc_id_t *doc_id, + trx_t *trx) +{ + dberr_t error; + que_t* graph= NULL; + char table_name[MAX_FULL_NAME_LEN]; + + fts_table_t fts_table; + fts_table.suffix= "CONFIG"; + fts_table.table_id= table->id; + fts_table.type= FTS_COMMON_TABLE; + fts_table.table= table; + ut_a(table->fts->doc_col != ULINT_UNDEFINED); + + trx->op_info = "update the next FTS document id"; + pars_info_t *info= pars_info_create(); + pars_info_bind_function(info, "my_func", fts_fetch_store_doc_id, + doc_id); + + fts_get_table_name(&fts_table, table_name); + pars_info_bind_id(info, "config_table", table_name); + + graph= fts_parse_sql( + &fts_table, info, + "DECLARE FUNCTION my_func;\n" + "DECLARE CURSOR c IS SELECT value FROM $config_table" + " WHERE key = 'synced_doc_id' FOR UPDATE;\n" + "BEGIN\n" + "" + "OPEN c;\n" + "WHILE 1 = 1 LOOP\n" + " FETCH c INTO my_func();\n" + " IF c % NOTFOUND THEN\n" + " EXIT;\n" + " END IF;\n" + "END LOOP;\n" + "CLOSE c;"); + + *doc_id = 0; + error = fts_eval_sql(trx, graph); + fts_que_graph_free_check_lock(&fts_table, NULL, graph); + return error; +} + +/** This function fetch the Doc ID from CONFIG table, and compare with the Doc ID supplied. And store the larger one to the CONFIG table. +@param table fts table +@param cmp_doc_id Doc ID to compare +@param doc_id larger document id after comparing "cmp_doc_id" to + the one stored in CONFIG table +@param trx transaction @return DB_SUCCESS if OK */ -static MY_ATTRIBUTE((nonnull)) +static dberr_t fts_cmp_set_sync_doc_id( -/*====================*/ - const dict_table_t* table, /*!< in: table */ - doc_id_t cmp_doc_id, /*!< in: Doc ID to compare */ - ibool read_only, /*!< in: TRUE if read the - synced_doc_id only */ - doc_id_t* doc_id) /*!< out: larger document id - after comparing "cmp_doc_id" - to the one stored in CONFIG - table */ + const dict_table_t *table, + doc_id_t cmp_doc_id, + doc_id_t *doc_id, + trx_t *trx=nullptr) { - trx_t* trx; - pars_info_t* info; - dberr_t error; - fts_table_t fts_table; - que_t* graph = NULL; - fts_cache_t* cache = table->fts->cache; - char table_name[MAX_FULL_NAME_LEN]; -retry: - ut_a(table->fts->doc_col != ULINT_UNDEFINED); + fts_cache_t* cache= table->fts->cache; + dberr_t error = DB_SUCCESS; + const trx_t* const caller_trx = trx; - fts_table.suffix = "CONFIG"; - fts_table.table_id = table->id; - fts_table.type = FTS_COMMON_TABLE; - fts_table.table = table; - - trx = trx_create(); - if (srv_read_only_mode) { + if (trx == nullptr) { + trx = trx_create(); trx_start_internal_read_only(trx); - } else { - trx_start_internal(trx); } +retry: + error = fts_read_synced_doc_id(table, doc_id, trx); - trx->op_info = "update the next FTS document id"; - - info = pars_info_create(); - - pars_info_bind_function( - info, "my_func", fts_fetch_store_doc_id, doc_id); - - fts_get_table_name(&fts_table, table_name); - pars_info_bind_id(info, "config_table", table_name); - - graph = fts_parse_sql( - &fts_table, info, - "DECLARE FUNCTION my_func;\n" - "DECLARE CURSOR c IS SELECT value FROM $config_table" - " WHERE key = 'synced_doc_id' FOR UPDATE;\n" - "BEGIN\n" - "" - "OPEN c;\n" - "WHILE 1 = 1 LOOP\n" - " FETCH c INTO my_func();\n" - " IF c % NOTFOUND THEN\n" - " EXIT;\n" - " END IF;\n" - "END LOOP;\n" - "CLOSE c;"); - - *doc_id = 0; - - error = fts_eval_sql(trx, graph); - - fts_que_graph_free_check_lock(&fts_table, NULL, graph); - - // FIXME: We need to retry deadlock errors - if (error != DB_SUCCESS) { - goto func_exit; - } - - if (read_only) { - /* InnoDB stores actual synced_doc_id value + 1 in - FTS_CONFIG table. Reduce the value by 1 while reading - after startup. */ - if (*doc_id) *doc_id -= 1; - goto func_exit; - } + if (error != DB_SUCCESS) goto func_exit; if (cmp_doc_id == 0 && *doc_id) { cache->synced_doc_id = *doc_id - 1; @@ -2714,6 +2710,10 @@ retry: func_exit: + if (caller_trx) { + return error; + } + if (UNIV_LIKELY(error == DB_SUCCESS)) { fts_sql_commit(trx); } else { @@ -2721,6 +2721,7 @@ func_exit: ib::error() << "(" << error << ") while getting next doc id " "for table " << table->name; + fts_sql_rollback(trx); if (error == DB_DEADLOCK) { @@ -4201,8 +4202,8 @@ fts_sync_commit( /* After each Sync, update the CONFIG table about the max doc id we just sync-ed to index table */ - error = fts_cmp_set_sync_doc_id(sync->table, sync->max_doc_id, FALSE, - &last_doc_id); + error = fts_cmp_set_sync_doc_id(sync->table, sync->max_doc_id, + &last_doc_id, trx); /* Get the list of deleted documents that are either in the cache or were headed there but were deleted before the add @@ -4228,6 +4229,7 @@ fts_sync_commit( rw_lock_x_unlock(&cache->lock); if (UNIV_LIKELY(error == DB_SUCCESS)) { + DEBUG_SYNC_C("fts_crash_before_commit_sync"); fts_sql_commit(trx); } else { fts_sql_rollback(trx); @@ -4901,7 +4903,7 @@ fts_init_doc_id( /* Then compare this value with the ID value stored in the CONFIG table. The larger one will be our new initial Doc ID */ - fts_cmp_set_sync_doc_id(table, 0, FALSE, &max_doc_id); + fts_cmp_set_sync_doc_id(table, 0, &max_doc_id); /* If DICT_TF2_FTS_ADD_DOC_ID is set, we are in the process of creating index (and add doc id column. No need to recovery @@ -6376,7 +6378,17 @@ fts_init_index( start_doc = cache->synced_doc_id; if (!start_doc) { - fts_cmp_set_sync_doc_id(table, 0, TRUE, &start_doc); + trx_t *trx = trx_create(); + trx_start_internal_read_only(trx); + dberr_t err= fts_read_synced_doc_id(table, &start_doc, trx); + fts_sql_commit(trx); + trx->free(); + if (err != DB_SUCCESS) { + goto func_exit; + } + if (start_doc) { + start_doc--; + } cache->synced_doc_id = start_doc; } From d328705a12139efad45fa42d9c32642069b7820d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 21 May 2024 15:34:13 +0300 Subject: [PATCH 21/25] MDEV-34170 : table gtid_slave_pos entries never been deleted with wsrep_gtid_mode = 0 Problem was that updates to mysql.gtid_slave_pos table were replicated even when they were newer used and because that newer deleted. Avoid replication of mysql.gtid_slave_pos table if wsrep_gtid_mode=OFF. Signed-off-by: Julius Goryavsky --- .../r/galera_as_slave_gtid_myisam.result | 6 - .../galera/r/galera_replica_no_gtid.result | 71 ++++++++++ .../galera/t/galera_as_slave_gtid_myisam.test | 14 +- .../suite/galera/t/galera_replica_no_gtid.cnf | 9 ++ .../galera/t/galera_replica_no_gtid.test | 124 ++++++++++++++++++ sql/log_event_server.cc | 5 + sql/rpl_gtid.cc | 14 +- 7 files changed, 220 insertions(+), 23 deletions(-) create mode 100644 mysql-test/suite/galera/r/galera_replica_no_gtid.result create mode 100644 mysql-test/suite/galera/t/galera_replica_no_gtid.cnf create mode 100644 mysql-test/suite/galera/t/galera_replica_no_gtid.test diff --git a/mysql-test/suite/galera/r/galera_as_slave_gtid_myisam.result b/mysql-test/suite/galera/r/galera_as_slave_gtid_myisam.result index 6559c7828be..5698ebf9fd3 100644 --- a/mysql-test/suite/galera/r/galera_as_slave_gtid_myisam.result +++ b/mysql-test/suite/galera/r/galera_as_slave_gtid_myisam.result @@ -22,12 +22,6 @@ EXPECT_1 1 gtid_binlog_state_equal 0 -connection node_2; -SELECT COUNT(*) AS EXPECT_1 FROM t1; -EXPECT_1 -1 -gtid_binlog_state_equal -0 #cleanup connection node_3; DROP TABLE t1; diff --git a/mysql-test/suite/galera/r/galera_replica_no_gtid.result b/mysql-test/suite/galera/r/galera_replica_no_gtid.result new file mode 100644 index 00000000000..80d713c2348 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_replica_no_gtid.result @@ -0,0 +1,71 @@ +connection node_2; +connection node_1; +connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3; +create user repl@'%' identified by 'repl'; +grant all on *.* to repl@'%'; +flush privileges; +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +connection node_1; +connection node_2; +connection node_2; +START SLAVE; +connection node_3; +CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_2; +SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; +EXPECT_1 +1 +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_2; +# Verify that graceful shutdown succeeds. +# Force SST +connection node_1; +# Waiting until node_2 is not part of cluster anymore +connection node_2; +# Start node_2 again +¤ Wait until node_2 is back on cluster +connection node_2; +call mtr.add_suppression("Slave: Operation CREATE USER failed for .*"); +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_3; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; +EXPECT_10000 +10000 +connection node_2; +STOP SLAVE; +RESET SLAVE ALL; +connection node_3; +RESET MASTER; +drop table t1; +connection node_2; +DROP TABLE t1; +connection node_1; +connection node_1; +disconnect node_3; +disconnect node_2; +disconnect node_1; +# End of test diff --git a/mysql-test/suite/galera/t/galera_as_slave_gtid_myisam.test b/mysql-test/suite/galera/t/galera_as_slave_gtid_myisam.test index 60476bc45a7..e465237dfc3 100644 --- a/mysql-test/suite/galera/t/galera_as_slave_gtid_myisam.test +++ b/mysql-test/suite/galera/t/galera_as_slave_gtid_myisam.test @@ -46,18 +46,8 @@ SELECT LENGTH(@@global.gtid_binlog_state) > 1; SELECT COUNT(*) AS EXPECT_1 FROM t1; ---disable_query_log ---eval SELECT '$gtid_binlog_state_node1' = @@global.gtid_binlog_state AS gtid_binlog_state_equal; ---enable_query_log - ---connection node_2 ---let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; ---source include/wait_condition.inc - ---let $wait_condition = SELECT COUNT(*) = 1 FROM t1; ---source include/wait_condition.inc - -SELECT COUNT(*) AS EXPECT_1 FROM t1; +# Note that MyISAM tables are not replicated by Galera so we do not here +# check node_2 --disable_query_log --eval SELECT '$gtid_binlog_state_node1' = @@global.gtid_binlog_state AS gtid_binlog_state_equal; diff --git a/mysql-test/suite/galera/t/galera_replica_no_gtid.cnf b/mysql-test/suite/galera/t/galera_replica_no_gtid.cnf new file mode 100644 index 00000000000..916c1c1847f --- /dev/null +++ b/mysql-test/suite/galera/t/galera_replica_no_gtid.cnf @@ -0,0 +1,9 @@ +!include ../galera_2nodes_as_slave.cnf + +[mysqld] +wsrep-debug=1 +server_id=15 +wsrep_gtid_mode=OFF +wsrep_gtid_domain_id=16 +gtid_domain_id=11 +gtid_strict_mode=OFF diff --git a/mysql-test/suite/galera/t/galera_replica_no_gtid.test b/mysql-test/suite/galera/t/galera_replica_no_gtid.test new file mode 100644 index 00000000000..8cc88ef211a --- /dev/null +++ b/mysql-test/suite/galera/t/galera_replica_no_gtid.test @@ -0,0 +1,124 @@ +# +# Test Galera as a replica to a MySQL async replication +# +# The galera/galera_2node_slave.cnf describes the setup of the nodes +# +--source include/force_restart.inc +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/have_sequence.inc + +# As node #3 is not a Galera node, and galera_cluster.inc does not open connetion to it +# we open the node_3 connection here +--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3 + +create user repl@'%' identified by 'repl'; +grant all on *.* to repl@'%'; +flush privileges; +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; + +--let $node_1 = node_1 +--let $node_2 = node_2 +--source include/auto_increment_offset_save.inc + +--connection node_2 +--disable_query_log +--eval CHANGE MASTER TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos; +--enable_query_log +START SLAVE; + +--connection node_3 + +CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; +--disable_query_log +INSERT INTO t1 SELECT seq, 'test' from seq_1_to_10000; +--enable_query_log +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +--connection node_2 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; +--source include/wait_condition.inc + +--let $wait_condition = SELECT COUNT(*) = 10000 FROM t1; +--source include/wait_condition.inc + +# +# Node_2 is slave so mysql.gtid_slave_pos table is also replicated +# +SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +--connection node_1 +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; +--source include/wait_condition.inc + +--let $wait_condition = SELECT COUNT(*) = 10000 FROM t1; +--source include/wait_condition.inc + +# +# mysql-gtid_slave_pos table should not be replicated by Galera +# +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +--connection node_2 +--echo # Verify that graceful shutdown succeeds. +--source include/shutdown_mysqld.inc +--echo # Force SST +--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat + +--connection node_1 +--echo # Waiting until node_2 is not part of cluster anymore +--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; +--source include/wait_condition.inc + +--connection node_2 +--echo # Start node_2 again +--source include/start_mysqld.inc + +--echo ¤ Wait until node_2 is back on cluster +--let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; +--source include/wait_condition.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--source include/wait_condition.inc +--let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; +--source include/wait_condition.inc + +--connection node_2 +call mtr.add_suppression("Slave: Operation CREATE USER failed for .*"); +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +--connection node_1 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.gtid_slave_pos; +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +--connection node_3 +SELECT COUNT(*) AS EXPECT_10000 FROM t1; + +# +# Cleanup +# +--connection node_2 +STOP SLAVE; +RESET SLAVE ALL; + +--connection node_3 +RESET MASTER; +drop table t1; + +--connection node_2 +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 + +--connection node_1 +--disconnect node_3 + +--source include/auto_increment_offset_restore.inc +--source include/galera_end.inc +--echo # End of test diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 0a64b45cf49..83bbb4a3285 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1726,6 +1726,11 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, thd->variables.pseudo_thread_id= thread_id; // for temp tables DBUG_PRINT("query",("%s", thd->query())); +#ifdef WITH_WSREP + WSREP_DEBUG("Query_log_event thread=%llu for query=%s", + thd_get_thread_id(thd), wsrep_thd_query(thd)); +#endif + if (unlikely(!(expected_error= error_code)) || ignored_error_code(expected_error) || !unexpected_error_code(expected_error)) diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 6177a703383..70f61b7e300 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -697,10 +697,11 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, #ifdef WITH_WSREP /* - We should replicate local gtid_slave_pos updates to other nodes. + We should replicate local gtid_slave_pos updates to other nodes if + wsrep gtid mode is set. In applier we should not append them to galera writeset. */ - if (WSREP_ON_ && wsrep_thd_is_local(thd)) + if (WSREP_ON_ && wsrep_gtid_mode && wsrep_thd_is_local(thd)) { thd->wsrep_ignore_table= false; table->file->row_logging= 1; // replication requires binary logging @@ -877,10 +878,12 @@ rpl_slave_state::gtid_delete_pending(THD *thd, #ifdef WITH_WSREP /* - We should replicate local gtid_slave_pos updates to other nodes. + We should replicate local gtid_slave_pos updates to other nodes if + wsrep gtid mode is set. In applier we should not append them to galera writeset. */ - if (WSREP_ON_ && wsrep_thd_is_local(thd) && + if (WSREP_ON_ && wsrep_gtid_mode && + wsrep_thd_is_local(thd) && thd->wsrep_cs().state() != wsrep::client_state::s_none) { if (thd->wsrep_trx().active() == false) @@ -891,7 +894,8 @@ rpl_slave_state::gtid_delete_pending(THD *thd, } thd->wsrep_ignore_table= false; } - thd->wsrep_ignore_table= true; + else + thd->wsrep_ignore_table= true; #endif thd_saved_option= thd->variables.option_bits; From c1dc03974b036419925b6ebdd00351dc7222959f Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Thu, 28 Mar 2024 11:24:27 +0100 Subject: [PATCH 22/25] MDEV-33523 Spurious deadlock error when wsrep_on=OFF Avoid starting transactions in wsrep-lib side when wsrep is disabled. It is unnecessary, and causes spurious deadlock errors on transaction clean up. Signed-off-by: Julius Goryavsky --- .../suite/galera/galera_2nodes_as_master.cnf | 3 ++ .../suite/galera/galera_2nodes_as_slave.cnf | 3 ++ mysql-test/suite/galera/galera_2x2nodes.cnf | 6 ++-- .../suite/galera/galera_3nodes_as_slave.cnf | 3 ++ mysql-test/suite/galera/galera_4nodes.cnf | 3 ++ mysql-test/suite/galera/r/MDEV-33523.result | 6 ++++ .../suite/galera/r/galera_bf_kill.result | 11 ++++++-- mysql-test/suite/galera/t/MDEV-33523.test | 11 ++++++++ mysql-test/suite/galera/t/galera_bf_kill.test | 28 +++++++++++++++---- .../suite/galera_3nodes/galera_2x3nodes.cnf | 3 ++ .../suite/galera_3nodes/galera_3nodes.cnf | 3 ++ sql/transaction.cc | 2 +- 12 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 mysql-test/suite/galera/r/MDEV-33523.result create mode 100644 mysql-test/suite/galera/t/MDEV-33523.test diff --git a/mysql-test/suite/galera/galera_2nodes_as_master.cnf b/mysql-test/suite/galera/galera_2nodes_as_master.cnf index ba53d6062c1..11d7401535a 100644 --- a/mysql-test/suite/galera/galera_2nodes_as_master.cnf +++ b/mysql-test/suite/galera/galera_2nodes_as_master.cnf @@ -47,6 +47,9 @@ wsrep_sst_receive_address='127.0.0.1:@mysqld.2.#sst_port' wsrep-on=OFF server-id=3 +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/mysql-test/suite/galera/galera_2nodes_as_slave.cnf b/mysql-test/suite/galera/galera_2nodes_as_slave.cnf index f25c7cc6d48..c6f6299ca92 100644 --- a/mysql-test/suite/galera/galera_2nodes_as_slave.cnf +++ b/mysql-test/suite/galera/galera_2nodes_as_slave.cnf @@ -46,6 +46,9 @@ wsrep_sst_receive_address='127.0.0.1:@mysqld.2.#sst_port' wsrep-on=OFF server-id=3 +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/mysql-test/suite/galera/galera_2x2nodes.cnf b/mysql-test/suite/galera/galera_2x2nodes.cnf index 922906eac6f..a35baed0c32 100644 --- a/mysql-test/suite/galera/galera_2x2nodes.cnf +++ b/mysql-test/suite/galera/galera_2x2nodes.cnf @@ -11,7 +11,6 @@ default-storage-engine=innodb wsrep_gtid_mode=1 gtid_ignore_duplicates auto_increment_increment=3 - wsrep-provider=@ENV.WSREP_PROVIDER # enforce read-committed characteristics across the cluster # wsrep-causal-reads=ON @@ -61,6 +60,9 @@ wsrep_node_address='127.0.0.1:@mysqld.4.#galera_port' wsrep_node_incoming_address=127.0.0.1:@mysqld.4.port wsrep_sst_receive_address='127.0.0.1:@mysqld.4.#sst_port' +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket @@ -73,5 +75,3 @@ NODE_MYSOCK_3= @mysqld.3.socket NODE_MYPORT_4= @mysqld.4.port NODE_MYSOCK_4= @mysqld.4.socket - - diff --git a/mysql-test/suite/galera/galera_3nodes_as_slave.cnf b/mysql-test/suite/galera/galera_3nodes_as_slave.cnf index 0ecf877b5a3..228147c0248 100644 --- a/mysql-test/suite/galera/galera_3nodes_as_slave.cnf +++ b/mysql-test/suite/galera/galera_3nodes_as_slave.cnf @@ -59,6 +59,9 @@ wsrep_sst_receive_address='127.0.0.1:@mysqld.3.#sst_port' wsrep-on=OFF server-id=4 +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/mysql-test/suite/galera/galera_4nodes.cnf b/mysql-test/suite/galera/galera_4nodes.cnf index 3ad1a66b9e6..4be5b496370 100644 --- a/mysql-test/suite/galera/galera_4nodes.cnf +++ b/mysql-test/suite/galera/galera_4nodes.cnf @@ -59,6 +59,9 @@ wsrep_node_incoming_address=127.0.0.1:@mysqld.4.port wsrep_sst_receive_address='127.0.0.1:@mysqld.4.#sst_port' auto-increment-offset=4 +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/mysql-test/suite/galera/r/MDEV-33523.result b/mysql-test/suite/galera/r/MDEV-33523.result new file mode 100644 index 00000000000..3ce8371fc63 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-33523.result @@ -0,0 +1,6 @@ +connection node_2; +connection node_1; +SET SESSION wsrep_on=OFF; +BEGIN; +ROLLBACK; +SET SESSION wsrep_on=OFF; diff --git a/mysql-test/suite/galera/r/galera_bf_kill.result b/mysql-test/suite/galera/r/galera_bf_kill.result index 3738e8c9684..71b0366081b 100644 --- a/mysql-test/suite/galera/r/galera_bf_kill.result +++ b/mysql-test/suite/galera/r/galera_bf_kill.result @@ -49,16 +49,23 @@ a b disconnect node_2a; disconnect node_2b; connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; +connect node_2b, 127.0.0.1, root, , test, $NODE_MYPORT_2; connection node_2a; SET SESSION wsrep_on=OFF; begin; update t1 set a =5, b=2; connection node_2; ALTER TABLE t1 ADD UNIQUE KEY b3(b); +connection node_2b; +SET SESSION wsrep_sync_wait=0; +connection node_2a; select * from t1; a b -2 1 +5 2 +commit; +connection node_2; disconnect node_2a; +disconnect node_2b; connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2; connection node_2a; SET SESSION wsrep_on=OFF; @@ -67,7 +74,7 @@ update t1 set a =5, b=2; connection node_2; select * from t1; a b -2 1 +5 2 disconnect node_2a; connection node_1; drop table t1; diff --git a/mysql-test/suite/galera/t/MDEV-33523.test b/mysql-test/suite/galera/t/MDEV-33523.test new file mode 100644 index 00000000000..5a2463d1973 --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-33523.test @@ -0,0 +1,11 @@ +# +# MDEV-33523: Spurious deadlock error when wsrep_on=OFF +# +--source include/galera_cluster.inc + +SET SESSION wsrep_on=OFF; +BEGIN; +# If bug is present, the following rollback +# results in ER_LOCK_DEADLOCK error. +ROLLBACK; +SET SESSION wsrep_on=OFF; diff --git a/mysql-test/suite/galera/t/galera_bf_kill.test b/mysql-test/suite/galera/t/galera_bf_kill.test index c8564bc9219..1b35b609a96 100644 --- a/mysql-test/suite/galera/t/galera_bf_kill.test +++ b/mysql-test/suite/galera/t/galera_bf_kill.test @@ -94,27 +94,43 @@ select * from t1; --disconnect node_2b # -# Test case 5: Start a transaction on node_2a with wsrep disabled -# and start a DDL on other transaction that will then abort node_2a -# transactions +# Test case 5: Start a transaction on node_2a with wsrep disabled. +# A conflicting DDL on other transaction can't BF abort +# transaction from node_2a (wsrep disabled). # --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 +--connect node_2b, 127.0.0.1, root, , test, $NODE_MYPORT_2 --connection node_2a SET SESSION wsrep_on=OFF; begin; update t1 set a =5, b=2; --connection node_2 -ALTER TABLE t1 ADD UNIQUE KEY b3(b); +--send ALTER TABLE t1 ADD UNIQUE KEY b3(b) +--connection node_2b +SET SESSION wsrep_sync_wait=0; +--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE = 'Waiting for table metadata lock'; +--source include/wait_condition.inc + +--connection node_2a select * from t1; +# We expect that ALTER should not be able to BF abort +# this transaction, it must wait for it to finish. +# Expect commit to succeed. +commit; + +--connection node_2 +--reap + --disconnect node_2a +--disconnect node_2b # -# Test case 6: Start a transaction on node_2a with wsrep disabled -# and kill it from other connection on same node +# Test case 6: Start a transaction on node_2a with wsrep disabled +# and kill it from other connection on same node. # --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2 diff --git a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf index cd7a892f4c9..22e160c21b4 100644 --- a/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf +++ b/mysql-test/suite/galera_3nodes/galera_2x3nodes.cnf @@ -83,6 +83,9 @@ wsrep_node_address='127.0.0.1:@mysqld.6.#galera_port' wsrep_node_incoming_address=127.0.0.1:@mysqld.6.port wsrep_sst_receive_address='127.0.0.1:@mysqld.6.#sst_port' +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/mysql-test/suite/galera_3nodes/galera_3nodes.cnf b/mysql-test/suite/galera_3nodes/galera_3nodes.cnf index a7dd4d21bc7..abd778c482c 100644 --- a/mysql-test/suite/galera_3nodes/galera_3nodes.cnf +++ b/mysql-test/suite/galera_3nodes/galera_3nodes.cnf @@ -46,6 +46,9 @@ wsrep_node_address='127.0.0.1:@mysqld.3.#galera_port' wsrep_node_incoming_address=127.0.0.1:@mysqld.3.port wsrep_sst_receive_address='127.0.0.1:@mysqld.3.#sst_port' +[sst] +sst-log-archive-dir=@ENV.MYSQLTEST_VARDIR/log + [ENV] NODE_MYPORT_1= @mysqld.1.port NODE_MYSOCK_1= @mysqld.1.socket diff --git a/sql/transaction.cc b/sql/transaction.cc index 1e855781f44..e8ac7148334 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -191,7 +191,7 @@ bool trans_begin(THD *thd, uint flags) } #ifdef WITH_WSREP - if (wsrep_thd_is_local(thd)) + if (WSREP(thd) && wsrep_thd_is_local(thd)) { if (wsrep_sync_wait(thd)) DBUG_RETURN(TRUE); From c2d9762011aa74e076390af1500d89dd3146796d Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 6 Jun 2024 19:26:50 +0200 Subject: [PATCH 23/25] =?UTF-8?q?mtr:=20=D1=81hange=20the=20default=20sett?= =?UTF-8?q?ing=20for=20the=20port=20group=20size=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some galera tests starts 6 galera nodes. Each galera node requires three ports: 6*3 = 18. Plus 6 ports are needed for 6 mariadbd servers. Since the number of ports is rounded up to 10 everywhere in mtr, we will take 30 as the default value for the port group size parameter. --- mysql-test/mysql-test-run.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 39df025ecbd..7127bedffdc 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -335,7 +335,11 @@ my $opt_max_test_fail= env_or_val(MTR_MAX_TEST_FAIL => 10); my $opt_core_on_failure= 0; my $opt_parallel= $ENV{MTR_PARALLEL} || 1; -my $opt_port_group_size = $ENV{MTR_PORT_GROUP_SIZE} || 20; +# Some galera tests starts 6 galera nodes. Each galera node requires +# three ports: 6*3 = 18. Plus 6 ports are needed for 6 mariadbd servers. +# Since the number of ports is rounded up to 10 everywhere, we will +# take 30 as the default value: +my $opt_port_group_size = $ENV{MTR_PORT_GROUP_SIZE} || 30; # lock file to stop tests my $opt_stop_file= $ENV{MTR_STOP_FILE}; From 654f6ecec4fbca348b7ebeb04e3c499c6346089b Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 6 Jun 2024 19:37:31 +0200 Subject: [PATCH 24/25] galera: wsrep-lib submodule update --- wsrep-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsrep-lib b/wsrep-lib index dfc4bdb8a5d..31db8476768 160000 --- a/wsrep-lib +++ b/wsrep-lib @@ -1 +1 @@ -Subproject commit dfc4bdb8a5dcbd6fbea007ad3beff899a6b5b7bd +Subproject commit 31db8476768ba68296ad91b6785bb06a6a9abf71 From 238798d978dccaa7c4d47fbb34f36d01d8cb10f0 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 6 Jun 2024 20:24:06 +0200 Subject: [PATCH 25/25] MDEV-32158: wsrep_sst_mariabackup use /tmp dir during SST rather then user defined tmpdir wsrep_sst_mariabackup should use the tmpdir defined by the user under the '[mysqld]' section of the configuration file rather than the default '/tmp' directory. --- scripts/wsrep_sst_mariabackup.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index dd206e38ec2..2cae93ed694 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -714,7 +714,7 @@ cleanup_at_exit() fi # Final cleanup - pgid=$(ps -o pgid= $$ 2>/dev/null | grep -o -E '[0-9]+' || :) + pgid=$(ps -o 'pgid=' $$ 2>/dev/null | grep -o -E '[0-9]+' || :) # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. @@ -1086,17 +1086,19 @@ if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then tmpdir=$(parse_cnf "$encgroups" 'tmpdir') if [ -z "$tmpdir" ]; then xtmpdir="$(mktemp -d)" + itmpdir="$(mktemp -d)" elif [ "$OS" = 'Linux' ]; then - xtmpdir=$(mktemp '-d' "--tmpdir=$tmpdir") + xtmpdir=$(mktemp -d "--tmpdir=$tmpdir") + itmpdir=$(mktemp -d "--tmpdir=$tmpdir") else - xtmpdir=$(TMPDIR="$tmpdir"; mktemp '-d') + xtmpdir=$(TMPDIR="$tmpdir"; mktemp -d) + itmpdir=$(TMPDIR="$tmpdir"; mktemp -d) fi wsrep_log_info "Using '$xtmpdir' as mariadb-backup temporary directory" tmpopts=" --tmpdir='$xtmpdir'" - itmpdir="$(mktemp -d)" - wsrep_log_info "Using '$itmpdir' as mariadb-abackup working directory" + wsrep_log_info "Using '$itmpdir' as mariadb-backup working directory" usrst=0 if [ -n "$WSREP_SST_OPT_USER" ]; then