diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
commit | 3f619478f796eddbba6e39502fe941b285dd97b1 (patch) | |
tree | e2c7b5777f728320e5b5542b6213fd3591ba51e2 /mysql-test/suite/perfschema/t/transaction.test | |
parent | Initial commit. (diff) | |
download | mariadb-3f619478f796eddbba6e39502fe941b285dd97b1.tar.xz mariadb-3f619478f796eddbba6e39502fe941b285dd97b1.zip |
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysql-test/suite/perfschema/t/transaction.test')
-rw-r--r-- | mysql-test/suite/perfschema/t/transaction.test | 734 |
1 files changed, 734 insertions, 0 deletions
diff --git a/mysql-test/suite/perfschema/t/transaction.test b/mysql-test/suite/perfschema/t/transaction.test new file mode 100644 index 00000000..b6164603 --- /dev/null +++ b/mysql-test/suite/perfschema/t/transaction.test @@ -0,0 +1,734 @@ +############# suite/perfschema/t/transaction.test #################### +# # +# Test processing of transaction events by the Performance Schema, # +# including explicit/implicit transactions, access modes, isolation # +# levels, statement counts and state transitions. # +# # +# # +###################################################################### + +--source include/have_perfschema.inc +--source include/not_embedded.inc +--source include/have_innodb.inc +--source include/no_protocol.inc +--disable_query_log +--source ../include/transaction_setup.inc +--enable_query_log +set global binlog_format=ROW; + +--echo # +--echo # ======================================================================== +--echo # STEP 1 - SETUP +--echo # ======================================================================== + +--echo # +--echo # Control thread +--echo # +--connection default +SET SESSION AUTOCOMMIT= 1; +eval $get_thread_id; +let $default_thread_id= `SELECT @my_thread_id`; + +--echo # +--echo # Connection 1 +--echo # +connect(con1, localhost, root,,); +--disable_query_log +eval $get_thread_id; +let $con1_thread_id= `SELECT @my_thread_id`; +--enable_query_log +SET SESSION AUTOCOMMIT= 0; +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE; + +--disable_parsing +--echo # +--echo # Connection 2 +--echo # +connect(con2, localhost, root,,); +--disable_query_log +eval $get_thread_id; +let $con2_thread_id= `SELECT @my_thread_id`; +--enable_query_log +SET SESSION AUTOCOMMIT= 0; +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE; +--enable_parsing + +--connection default +--disable_query_log +eval SET @con1_thread_id= $con1_thread_id; +#eval SET @con2_thread_id= $con2_thread_id; +--enable_query_log + +--echo # +--echo # Create test tables, one transactional and one non-transactional +--echo # +--connection default + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS nt1; +--enable_warnings +CREATE TABLE t1 (s1 int, s2 varchar(64)) ENGINE=INNODB; +CREATE TABLE nt1 (s1 int, s2 varchar(64)) ENGINE=MYISAM; + +--echo # +--echo # Disable all events from the control thread +--echo # +--disable_query_log +UPDATE performance_schema.threads + SET instrumented='NO' WHERE processlist_id = CONNECTION_ID(); +--enable_query_log + +--echo # +--echo # Clear transaction tables +--echo # +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 2 - BASIC TRANSACTION +--echo # ======================================================================== +--echo # +--connection con1 +SELECT @@global.tx_isolation; +SELECT @@global.autocommit; +SELECT @@global.binlog_format; +SELECT @@tx_isolation; +SELECT @@autocommit; +SELECT @@binlog_format; + +--echo # +--echo # STEP 2.1 - START/COMMIT +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (101, 'COMMITTED'); +COMMIT; + +--echo # +--echo # STEP 2.2 - ROLLBACK +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (102, 'ROLLED BACK'); +ROLLBACK; + +--echo # +--echo ## Expect 1 committed and 1 rolled back transaction +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # STEP 2.3 - COMMIT AND CHAIN +--echo # +--connection con1 +START TRANSACTION; +INSERT INTO t1 VALUES (103, 'COMMIT AND CHAIN'); +COMMIT AND CHAIN; +INSERT INTO t1 VALUES (104, 'COMMIT AND CHAIN'); +COMMIT; + +--echo # +--echo ## Expect 2 committed transactions +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 2); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 3 - ISOLATION LEVEL +--echo # ======================================================================== +--echo # +--echo # connection con1 +--connection con1 +SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE; +START TRANSACTION; +INSERT INTO t1 VALUES (301, 'SERIALIZABLE'); +COMMIT; + +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; +START TRANSACTION; +INSERT INTO t1 VALUES (302, 'REPEATABLE READ'); +COMMIT; + +## NOTE - InnoDB requires binlog_format = ROW for READ COMMITTED/UNCOMMITTED +SELECT @@binlog_format INTO @binlog_save; +SET SESSION BINLOG_FORMAT=ROW; +SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; +START TRANSACTION; +INSERT INTO t1 VALUES (303, 'READ COMMITTED'); +COMMIT; + +SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +START TRANSACTION; +INSERT INTO t1 VALUES (304, 'READ UNCOMMITTED'); +COMMIT; + +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; +SET binlog_format= @binlog_save; + +--echo # +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'SERIALIZABLE', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'READ COMMITTED', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'READ UNCOMMITTED', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 4 - ACCESS MODE +--echo # ======================================================================== +--echo # +--echo # STEP 4.1 - READ ONLY, TIMING ENABLED +--echo # +--echo # +--echo # connection con1 +--connection con1 +SET SESSION TRANSACTION READ WRITE; +START TRANSACTION; +INSERT INTO t1 VALUES (410, 'READ ONLY'); +INSERT INTO t1 VALUES (411, 'READ ONLY'); +INSERT INTO t1 VALUES (412, 'READ ONLY'); +INSERT INTO t1 VALUES (413, 'READ ONLY'); +COMMIT; + +SET SESSION TRANSACTION READ ONLY; +START TRANSACTION; +SELECT * FROM t1 ORDER BY s1; +COMMIT; + +--echo # +--echo ## Expect 1 read only, committed transaction in events_transactions_history +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ ONLY', 'REPEATABLE READ', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # +--echo # STEP 4.2 - READ ONLY, TIMING DISABLED +--echo # +--echo # +--echo ## Disable timing stats for 'transaction' +UPDATE performance_schema.setup_instruments SET timed = 'NO' WHERE name = 'transaction'; +--echo # +TRUNCATE performance_schema.events_transactions_summary_global_by_event_name; + +--echo # connection con1 +--connection con1 +START TRANSACTION; +SELECT * FROM t1 ORDER BY s1; +COMMIT; +--echo # +SET SESSION TRANSACTION READ WRITE; + +--connection default +--echo # +--echo ## Expect 1 event, 0 stats +SELECT * FROM performance_schema.events_transactions_summary_global_by_event_name; +--echo # +--echo ## Restore setup_instruments +UPDATE performance_schema.setup_instruments SET enabled = 'YES' WHERE name = 'transaction'; + +--echo # +--echo # ======================================================================== +--echo # STEP 5 - IMPLICIT START +--echo # ======================================================================== +--echo # When AUTOCOMMIT is disabled, the first statement following a committed +--echo # transaction marks the start of a new transaction. Subsequent statements will +--echo # be part of the transaction until it is committed. +--echo # +--connection con1 +SET SESSION AUTOCOMMIT = 0; +INSERT INTO t1 VALUES (501, 'IMPLICIT START'); + +--echo # +--echo ## Expect 1 active transaction in events_transactions_current +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--connection con1 +INSERT INTO t1 VALUES (502, 'IMPLICIT START'); +COMMIT; + +--echo # +--echo ## Expect one committed transaction in events_transactions_current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 6 - IMPLICIT COMMIT (DDL, ETC) +--echo # ======================================================================== +--echo # Transactions are implicitly ended by DDL statements, locking statements +--echo # and server administration commands. +--echo # +--connection con1 +SET SESSION AUTOCOMMIT = 0; +INSERT INTO t1 VALUES (601, 'IMPLICIT COMMIT'); + +--echo # +--echo ## Expect one active transaction in events_transactions_current, zero events in history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', 'NO', 0, 0, 0, 0); + +--connection con1 +INSERT INTO t1 VALUES (602, 'IMPLICIT COMMIT'); + +--echo ## Issue a DDL statement to force a commmit +CREATE TABLE t2 (s1 INT, s2 VARCHAR(64)) ENGINE=INNODB; + +--echo # +--echo ## Expect 0 active transactions, 1 committed transaction +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 0); +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); +DROP TABLE test.t2; + +--echo # +--echo # ======================================================================== +--echo # STEP 7 - XA TRANSACTIONS +--echo # ======================================================================== +--echo # +--echo # STEP 7.1 - XA START +--echo # +--connection con1 +XA START 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890; + +--echo # +--echo ## Expect 1 active XA transaction, state ACTIVE +--connection default + +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 1234567890, 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 'ACTIVE', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--echo # +--echo # STEP 7.2 - XA END +--echo # +--connection con1 +INSERT INTO t1 VALUES (701, 'XA'); +XA END 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890; + +--echo # +--echo ## Expect 1 active XA transaction, state IDLE +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 1234567890, 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 'IDLE', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--echo # +--echo # +--echo # STEP 7.3 - XA PREPARE +--echo # +--connection con1 +XA PREPARE 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890; + +--echo # +--echo ## Expect 1 active XA transaction, state PREPARED +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 1234567890, 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 'PREPARED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--echo # +--echo # +--echo # STEP 7.4 - XA COMMIT +--echo # +--connection con1 +XA COMMIT 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890; + +--echo # +--echo ## Expect 1 committed XA transaction, state COMMITTED in current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +CALL clear_transaction_tables(); + +--echo # +--echo # +--echo # STEP 7.5 - XA ROLLBACK +--echo # +--connection con1 +XA START 'XA_CON1_002'; +INSERT INTO t1 VALUES (702, 'XA'); +XA END 'XA_CON1_002'; +XA PREPARE 'XA_CON1_002'; + +--echo # +--echo ## Expect 1 active XA transaction, state PREPARED +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, 'XA_CON1_002', '', 'PREPARED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--connection con1 +XA ROLLBACK 'XA_CON1_002'; + +--echo # +--echo ## Expect 1 XA transaction, state ROLLBACK ONLY in current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, 'XA_CON1_002', '', 'ROLLBACK ONLY', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, 'XA_CON1_002', '', 'ROLLBACK ONLY', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); +SELECT * FROM performance_schema.events_transactions_current ORDER BY event_id; + +--echo # +--echo # STEP 7.6 - XA TRANSACTION - LONG GTRID AND BQUAL +--echo # +--connection con1 +XA START 'GTRID_6789012345678901234567890123456789012345678901234567890123','BQUAL_6789012345678901234567890123456789012345678901234567890123',1234567890; +INSERT INTO t1 VALUES (703, 'XA LONG'); +XA END 'GTRID_6789012345678901234567890123456789012345678901234567890123','BQUAL_6789012345678901234567890123456789012345678901234567890123',1234567890; +XA PREPARE 'GTRID_6789012345678901234567890123456789012345678901234567890123','BQUAL_6789012345678901234567890123456789012345678901234567890123',1234567890; +XA COMMIT 'GTRID_6789012345678901234567890123456789012345678901234567890123','BQUAL_6789012345678901234567890123456789012345678901234567890123',1234567890; + +--echo # +--echo ## Expect 1 committed XA transaction, state COMMITTED in current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', 'BQUAL_6789012345678901234567890123456789012345678901234567890123', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', 'BQUAL_6789012345678901234567890123456789012345678901234567890123', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # STEP 7.7 - XA TRANSACTION - LONG GTRID AND BINARY BQUAL +--echo # +--connection con1 +XA START 'GTRID_6789012345678901234567890123456789012345678901234567890123',0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233,1234567890; +INSERT INTO t1 VALUES (704, 'XA LONG/BINARY'); +XA END 'GTRID_6789012345678901234567890123456789012345678901234567890123',0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233,1234567890; +XA PREPARE 'GTRID_6789012345678901234567890123456789012345678901234567890123',0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233,1234567890; +XA COMMIT 'GTRID_6789012345678901234567890123456789012345678901234567890123',0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233,1234567890; +--echo # +--echo ## Expect 1 committed XA transaction, state COMMITTED in current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', '0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', '0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 8 - TRANSACTIONAL AND NON-TRANSACTIONAL TABLES +--echo # ======================================================================== +--echo # +--echo ## MariaDB bug: MDEV-6012? MDEV-14436? +set @mariadb_bug=1; + +## Statements that work with non-transactional engines have no effect on the +## transaction state of the connection. For implicit transactions, +## the transaction event begins with the first statement that uses a +## transactional engine. This means that statements operating exclusively on +## non-transactional tables will be ignored, even following START TRANSACTION. + +--connection con1 +SET SESSION AUTOCOMMIT = 0; +SELECT * FROM performance_schema.events_transactions_current ORDER BY event_id; + +--echo # +--echo # +--echo # STEP 8.1 - UPDATE NON-TRANSACTIONAL TABLE +--echo # +INSERT INTO nt1 VALUES (801, 'NON-TRANSACTIONAL'); + +--echo # +--echo ## Expect 0 transactions in events_transactions_current +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug); + +--connection con1 +COMMIT; + +--echo # +--echo ## Expect 0 transactions in events_transactions_history +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug); + +--echo # +--echo # +--echo # STEP 8.2 - UPDATE TRANSACTIONAL AND NON-TRANSACTIONAL TABLES +--echo # +--echo # +--echo ## First non-transactional... +--echo # +--connection con1 +INSERT INTO nt1 VALUES (802, 'NON-TRANSACTIONAL'); + +--echo # +--echo ## Expect 0 transactions in events_transactions_current +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug); + +--echo # +--echo ## Now transactional. Transaction should be started. +--connection con1 +INSERT INTO t1 VALUES (802, 'TRANSACTIONAL'); + +--echo # +--echo ## Expect 1 transaction in events_transactions_current +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +## Commit +--echo # +--connection con1 +COMMIT; + +--echo # +--echo ## Expect 1 committed transaction in events_transactions_current and history +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1+@mariadb_bug); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 9 - SAVEPOINTS +--echo # ======================================================================== +--echo # +--echo # STEP 9.1 - SAVEPOINT 1 +--echo # +--connection con1 +START TRANSACTION; +INSERT INTO t1 VALUES (901, 'SAVEPOINT'); +SAVEPOINT SVP001; + +--echo # +--echo ## Expect 1 active transaction with 1 savepoint +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 1, 0, 0, 1); + +--echo # +--echo # +--echo # STEP 9.2 - SAVEPOINTS 2 and 3 +--echo # +--connection con1 +INSERT INTO t1 VALUES (902, 'SAVEPOINT'); +SAVEPOINT SVP002; +INSERT INTO t1 VALUES (903, 'SAVEPOINT'); +SAVEPOINT SVP003; +INSERT INTO t1 VALUES (904, 'SAVEPOINT'); +SELECT COUNT(*) FROM t1 WHERE s1 > 900; + +--echo # +--echo # +--echo # STEP 9.3 - ROLLBACK TO SAVEPOINT 2 +--echo # +--connection con1 +ROLLBACK TO SVP002; + +--echo # +--echo ## Expect 1 active transaction with 3 savepoints, 1 rollback to savepoint +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 3, 1, 0, 1); + +--echo # +--echo # +--echo # STEP 9.4 - RELEASE SAVEPOINT 1 +--echo # +--connection con1 +RELEASE SAVEPOINT SVP001; + +--echo # +--echo ## Expect 1 active transaction with 3 savepoints, 1 rollback to savepoint, 1 release savepoint +--connection default +CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 3, 1, 1, 1); + +--echo # +--echo # STEP 9.5 - COMMIT +--echo # +--connection con1 +COMMIT; + +--echo # +--echo ## Expect 1 committed transaction with 3 savepoints, 1 rollback to savepoint, 1 release savepoint +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 3, 1, 1, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # ======================================================================== +--echo # STEP 10 - GTIDs +--echo # ======================================================================== +--echo # GTIDs are tested in transaction_gtid.test. + +--echo # +--echo # ======================================================================== +--echo # STEP 11 - MISCELLANY +--echo # ======================================================================== +--echo # +--echo # STEP 11.1 - TRUNCATE DURING ACTIVE TRANSACTION +--echo # +--echo # +--echo # Verify that truncating events_transactions_current during an active transaction +--echo # does not leave an orphaned transaction event, and that the row index to +--echo # events_transactions_history is reset to 0. +--echo # +--connection con1 +START TRANSACTION; +INSERT INTO t1 VALUES (1110, 'INSERT 1110'); +--connection default +TRUNCATE performance_schema.events_transactions_current; +--connection con1 +--echo # +COMMIT; +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (1111, 'INSERT 1111'); +COMMIT; + +--echo # +--echo ## Expect 1 transaction for connection 1 +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', '', '', '', 0, 0, 0, 1); +CALL clear_transaction_tables(); + +--echo # +--echo # +--echo # STEP 11.2 - DISABLE THREAD INSTRUMENTATION +--echo # +--connection default +UPDATE performance_schema.setup_consumers + SET enabled = 'NO' + WHERE name = 'thread_instrumentation'; +--echo # +TRUNCATE performance_schema.events_transactions_summary_global_by_event_name; + +--connection con1 +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (1120, 'INSERT 1120'); +COMMIT; + +--connection default +--echo # +--echo ## Expect 1 event with non-zero summary stats +--replace_column 3 sum_timer_wait 4 min_timer_wait 5 avg_timer_wait +SELECT EVENT_NAME, COUNT_STAR, SUM_TIMER_WAIT, MIN_TIMER_WAIT, AVG_TIMER_WAIT, COUNT_READ_WRITE + FROM performance_schema.events_transactions_summary_global_by_event_name + WHERE count_star = 1 and sum_timer_wait != 0; + +--echo # +--echo ## Disable timing stats for 'transaction' +UPDATE performance_schema.setup_instruments SET timed = 'NO' WHERE name = 'transaction'; +--echo # +TRUNCATE performance_schema.events_transactions_summary_global_by_event_name; + +--connection default +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (1121, 'INSERT 1121'); +COMMIT; + +--connection default +--echo # +--echo ## Expect 1 event, 0 stats +SELECT * FROM performance_schema.events_transactions_summary_global_by_event_name; + +--echo # +--echo ## Restore setup_consumers and setup_instruments +UPDATE performance_schema.setup_consumers SET enabled = 'YES' WHERE name = 'thread_instrumentation'; +UPDATE performance_schema.setup_instruments SET enabled = 'YES' WHERE name = 'transaction'; +--echo # +DELETE FROM t1; +CALL clear_history(); + +--echo # +--echo # +--echo # STEP 11.3 - STATEMENT ROLLBACK - AUTOCOMMIT OFF - BINLOG FORMAT 'STATEMENT' +--echo # +--connection con1 +SET SESSION binlog_format = STATEMENT; +SET SESSION AUTOCOMMIT = 0; + +# A transaction with a rolled back statement should not show as rolled back. +# +# Force a statement rollback by attempting to update a transactional table +# and a non-replicatable table with binlog_format = STATEMENT. + +--echo # +START TRANSACTION; +INSERT INTO t1 VALUES (1130, 'INSERT 1130'); +--echo # +--echo ## Expect binlog statement mode error +--error 0, ER_BINLOG_STMT_MODE_AND_NO_REPL_TABLES +UPDATE t1, performance_schema.setup_instruments pfs + SET t1.s1 = 1, pfs.timed = 'NO'; +--echo # +COMMIT; +--echo # +SET SESSION AUTOCOMMIT = 1; + +--echo # +--echo ## Expect 1 committed transaction +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', '', '', 'NO', 0, 0, 0, 1); +--echo # +DELETE FROM t1; +CALL clear_history(); + +--echo # +--echo # +--echo # STEP 11.4 - STATEMENT ROLLBACK - AUTOCOMMIT ON - BINLOG FORMAT 'STATEMENT' +--echo # +--connection con1 +SET SESSION binlog_format = STATEMENT; +SET SESSION AUTOCOMMIT = 1; + +# A rolled back autocommit statement should be recorded as a rolled back transaction +# +# Force a statement rollback by attempting to update a transactional table +# and a non-replicatable table with binlog_format = STATEMENT. +--echo # +--echo ## Expect binlog statement mode error +--error 0, ER_BINLOG_STMT_MODE_AND_NO_REPL_TABLES +UPDATE t1, performance_schema.setup_instruments pfs + SET t1.s1 = 1, pfs.timed = 'NO'; + +--echo # +--echo ## Expect 1 rolled back transaction +--connection default +CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, '', '', '', '', '', '', 'YES', 0, 0, 0, 1); +CALL clear_history(); + +--disable_parsing +# TODO: Add wait timer +--echo # +--echo # +--echo # STEP 11.5 - DROPPED CONNECTION DURING TRANSACTION +--echo # +--connection con2 +START TRANSACTION; +INSERT INTO t1 VALUES (1150, 'DROP CONNECTION'); +--echo # +--echo ## Expect 1 active transaction for connection 2 +--connection default +CALL transaction_verifier(0, @con2_thread_id, 'transaction', 'ACTIVE', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1); + +--echo # +--echo ## Drop connection +--connection con2 +--disconnect con2 +--source include/wait_until_disconnected.inc +--connection default + +--echo # +--echo ## Expect 0 transactions for connection 2 +CALL transaction_verifier(0, @con2_thread_id, '', '', 0, '', '', '', '', '', '', '', 0, 0, 0, 0); +CALL transaction_verifier(1, @con2_thread_id, '', '', 0, '', '', '', '', '', '', '', 0, 0, 0, 0); +CALL clear_transaction_tables(); + +--enable_parsing + +--echo # +--echo # ======================================================================== +--echo # CLEAN UP +--echo # ======================================================================== +--echo # + +--disconnect con1 +##--disconnect con2 + +--connection default +DROP TABLE t1; +DROP TABLE nt1; + +--source ../include/transaction_cleanup.inc +set global binlog_format=default; |