Skip to content

Commit 127ed74

Browse files
committed
MDEV-22420 DDL on temporary object is prohibited when XA is in prepare state
The parser must reject DDL operations on temporary objects when they may modify or alter such object, including temporary tables and sequences. The rejection is regardless (has been already in place for bin-loggable DML:s) of the binlogging capability of the server or connection. The patch implements the requirement. A binlog test is added.
1 parent 545a619 commit 127ed74

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TEMPORARY SEQUENCE seq_1;
2+
XA START '3';
3+
CREATE TEMPORARY TABLE tmp_1(c INT);
4+
XA END '3';
5+
XA PREPARE '3';
6+
DROP TEMPORARY TABLE tmp_1;
7+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
8+
ALTER TABLE tmp_1 DROP COLUMN c;
9+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
10+
DROP TEMPORARY SEQUENCE seq_1;
11+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
12+
ALTER SEQUENCE seq_1 INCREMENT BY 1;
13+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
14+
CREATE TEMPORARY TABLE tmp_2(c INT);
15+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
16+
CREATE TEMPORARY SEQUENCE seq_2;
17+
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the PREPARED state
18+
XA ROLLBACK '3';
19+
# Proof of correct logging incl empty XA-PREPARE
20+
include/show_binlog_events.inc
21+
Log_name Pos Event_type Server_id End_log_pos Info
22+
master-bin.000001 # Gtid # # GTID #-#-#
23+
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY SEQUENCE seq_1
24+
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
25+
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tmp_1(c INT)
26+
master-bin.000001 # Query # # COMMIT
27+
master-bin.000001 # Gtid # # XA START X'33',X'',1 GTID #-#-#
28+
master-bin.000001 # Query # # XA END X'33',X'',1
29+
master-bin.000001 # XA_prepare # # XA PREPARE X'33',X'',1
30+
master-bin.000001 # Gtid # # GTID #-#-#
31+
master-bin.000001 # Query # # XA ROLLBACK X'33',X'',1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# The test verifies execution and binary logging of user XA that produce empty
2+
# XA-PREPARE group of events.
3+
4+
--source include/have_binlog_format_mixed.inc
5+
--source include/have_innodb.inc
6+
7+
8+
# MDEV-22420 DDL on temporary object is prohibited when XA is in prepare state
9+
10+
# Temporary sequnce may not be created within a transaction
11+
CREATE TEMPORARY SEQUENCE seq_1;
12+
13+
XA START '3';
14+
CREATE TEMPORARY TABLE tmp_1(c INT);
15+
XA END '3';
16+
XA PREPARE '3';
17+
--error ER_XAER_RMFAIL
18+
DROP TEMPORARY TABLE tmp_1;
19+
--error ER_XAER_RMFAIL
20+
ALTER TABLE tmp_1 DROP COLUMN c;
21+
--error ER_XAER_RMFAIL
22+
DROP TEMPORARY SEQUENCE seq_1;
23+
--error ER_XAER_RMFAIL
24+
ALTER SEQUENCE seq_1 INCREMENT BY 1;
25+
26+
--error ER_XAER_RMFAIL
27+
CREATE TEMPORARY TABLE tmp_2(c INT);
28+
--error ER_XAER_RMFAIL
29+
CREATE TEMPORARY SEQUENCE seq_2;
30+
31+
# Cleanup
32+
XA ROLLBACK '3';
33+
34+
--echo # Proof of correct logging incl empty XA-PREPARE
35+
--source include/show_binlog_events.inc

sql/sql_parse.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,6 +4890,8 @@ mysql_execute_command(THD *thd)
48904890
}
48914891
else
48924892
{
4893+
if (thd->transaction->xid_state.check_has_uncommitted_xa())
4894+
goto error;
48934895
status_var_decrement(thd->status_var.com_stat[lex->sql_command]);
48944896
status_var_increment(thd->status_var.com_drop_tmp_table);
48954897

0 commit comments

Comments
 (0)