1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
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;
|