summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/r/transaction.result
blob: c516a4543c274f050faeb7a08f154b93dd39445b (plain)
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
set global binlog_format=ROW;
#
# ========================================================================
# STEP 1 - SETUP
# ========================================================================
#
# Control thread
#
connection default;
SET SESSION AUTOCOMMIT= 1;
SELECT thread_id INTO @my_thread_id
FROM performance_schema.threads
WHERE processlist_id = connection_id();
#
# Connection 1
#
connect con1, localhost, root,,;
SET SESSION AUTOCOMMIT= 0;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE;
connection default;
#
# Create test tables, one transactional and one non-transactional
#
connection default;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS nt1;
CREATE TABLE t1 (s1 int, s2 varchar(64)) ENGINE=INNODB;
CREATE TABLE nt1 (s1 int, s2 varchar(64)) ENGINE=MYISAM;
#
# Disable all events from the control thread
#
#
# Clear transaction tables
#
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 2 - BASIC TRANSACTION
# ========================================================================
#
connection con1;
SELECT @@global.transaction_isolation;
@@global.transaction_isolation
REPEATABLE-READ
SELECT @@global.autocommit;
@@global.autocommit
1
SELECT @@global.binlog_format;
@@global.binlog_format
ROW
SELECT @@transaction_isolation;
@@transaction_isolation
REPEATABLE-READ
SELECT @@autocommit;
@@autocommit
0
SELECT @@binlog_format;
@@binlog_format
ROW
#
# STEP 2.1 - START/COMMIT
#
START TRANSACTION;
INSERT INTO t1 VALUES (101, 'COMMITTED');
COMMIT;
#
# STEP 2.2 - ROLLBACK
#
START TRANSACTION;
INSERT INTO t1 VALUES (102, 'ROLLED BACK');
ROLLBACK;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# STEP 2.3 - COMMIT AND CHAIN
#
connection con1;
START TRANSACTION;
INSERT INTO t1 VALUES (103, 'COMMIT AND CHAIN');
COMMIT AND CHAIN;
INSERT INTO t1 VALUES (104, 'COMMIT AND CHAIN');
COMMIT;
#
## 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);
ACTUAL	EXPECTED
     2	       2
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 3 - ISOLATION LEVEL
# ========================================================================
#
# 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;
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;
#
connection default;
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'SERIALIZABLE', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'REPEATABLE READ', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'READ COMMITTED', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', 'READ UNCOMMITTED', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 4 - ACCESS MODE
# ========================================================================
#
# STEP 4.1 - READ ONLY, TIMING ENABLED
#
#
# 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;
s1	s2
101	COMMITTED
103	COMMIT AND CHAIN
104	COMMIT AND CHAIN
301	SERIALIZABLE
302	REPEATABLE READ
303	READ COMMITTED
304	READ UNCOMMITTED
410	READ ONLY
411	READ ONLY
412	READ ONLY
413	READ ONLY
COMMIT;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
#
# STEP 4.2 - READ ONLY, TIMING DISABLED
#
#
## Disable timing stats for 'transaction'
UPDATE performance_schema.setup_instruments SET timed = 'NO' WHERE name = 'transaction';
#
TRUNCATE performance_schema.events_transactions_summary_global_by_event_name;
# connection con1
connection con1;
START TRANSACTION;
SELECT * FROM t1 ORDER BY s1;
s1	s2
101	COMMITTED
103	COMMIT AND CHAIN
104	COMMIT AND CHAIN
301	SERIALIZABLE
302	REPEATABLE READ
303	READ COMMITTED
304	READ UNCOMMITTED
410	READ ONLY
411	READ ONLY
412	READ ONLY
413	READ ONLY
COMMIT;
#
SET SESSION TRANSACTION READ WRITE;
connection default;
#
## Expect 1 event, 0 stats
SELECT * FROM performance_schema.events_transactions_summary_global_by_event_name;
EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT	COUNT_READ_WRITE	SUM_TIMER_READ_WRITE	MIN_TIMER_READ_WRITE	AVG_TIMER_READ_WRITE	MAX_TIMER_READ_WRITE	COUNT_READ_ONLY	SUM_TIMER_READ_ONLY	MIN_TIMER_READ_ONLY	AVG_TIMER_READ_ONLY	MAX_TIMER_READ_ONLY
transaction	1	0	0	0	0	0	0	0	0	0	1	0	0	0	0
#
## Restore setup_instruments
UPDATE performance_schema.setup_instruments SET enabled = 'YES' WHERE name = 'transaction';
#
# ========================================================================
# STEP 5 - IMPLICIT START
# ========================================================================
# When AUTOCOMMIT is disabled, the first statement following a committed
# transaction marks the start of a new transaction. Subsequent statements will
# be part of the transaction until it is committed.
#
connection con1;
SET SESSION AUTOCOMMIT = 0;
INSERT INTO t1 VALUES (501, 'IMPLICIT START');
#
## 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);
ACTUAL	EXPECTED
     1	       1
connection con1;
INSERT INTO t1 VALUES (502, 'IMPLICIT START');
COMMIT;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 6 - IMPLICIT COMMIT (DDL, ETC)
# ========================================================================
# Transactions are implicitly ended by DDL statements, locking statements
# and server administration commands.
#
connection con1;
SET SESSION AUTOCOMMIT = 0;
INSERT INTO t1 VALUES (601, 'IMPLICIT COMMIT');
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', 'NO', 0, 0, 0, 0);
ACTUAL	EXPECTED
     0	       0
connection con1;
INSERT INTO t1 VALUES (602, 'IMPLICIT COMMIT');
## Issue a DDL statement to force a commmit
CREATE TABLE t2 (s1 INT, s2 VARCHAR(64)) ENGINE=INNODB;
#
## 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);
ACTUAL	EXPECTED
     0	       0
CALL transaction_verifier(0, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
DROP TABLE test.t2;
#
# ========================================================================
# STEP 7 - XA TRANSACTIONS
# ========================================================================
#
# STEP 7.1 - XA START
#
connection con1;
XA START 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
# STEP 7.2 - XA END
#
connection con1;
INSERT INTO t1 VALUES (701, 'XA');
XA END 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
#
# STEP 7.3 - XA PREPARE
#
connection con1;
XA PREPARE 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
#
# STEP 7.4 - XA COMMIT
#
connection con1;
XA COMMIT 'XA_CON1_GTRID_001', 'XA_CON1_BQUAL_001', 1234567890;
#
## 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);
ACTUAL	EXPECTED
     1	       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);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
#
# STEP 7.5 - XA ROLLBACK
#
connection con1;
XA START 'XA_CON1_002';
INSERT INTO t1 VALUES (702, 'XA');
XA END 'XA_CON1_002';
XA PREPARE 'XA_CON1_002';
#
## 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);
ACTUAL	EXPECTED
     1	       1
connection con1;
XA ROLLBACK 'XA_CON1_002';
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, 'XA_CON1_002', '', 'ROLLBACK ONLY', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
SELECT * FROM performance_schema.events_transactions_current ORDER BY event_id;
THREAD_ID	EVENT_ID	END_EVENT_ID	EVENT_NAME	STATE	TRX_ID	GTID	XID_FORMAT_ID	XID_GTRID	XID_BQUAL	XA_STATE	SOURCE	TIMER_START	TIMER_END	TIMER_WAIT	ACCESS_MODE	ISOLATION_LEVEL	AUTOCOMMIT	NUMBER_OF_SAVEPOINTS	NUMBER_OF_ROLLBACK_TO_SAVEPOINT	NUMBER_OF_RELEASE_SAVEPOINT	OBJECT_INSTANCE_BEGIN	NESTING_EVENT_ID	NESTING_EVENT_TYPE
#
# STEP 7.6 - XA TRANSACTION - LONG GTRID AND BQUAL
#
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;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', 'BQUAL_6789012345678901234567890123456789012345678901234567890123', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# STEP 7.7 - XA TRANSACTION - LONG GTRID AND BINARY BQUAL
#
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;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 1234567890, 'GTRID_6789012345678901234567890123456789012345678901234567890123', '0x425155414C5FA5A53839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233', 'COMMITTED', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 8 - TRANSACTIONAL AND NON-TRANSACTIONAL TABLES
# ========================================================================
#
## MariaDB bug: MDEV-6012? MDEV-14436?
set @mariadb_bug=1;
connection con1;
SET SESSION AUTOCOMMIT = 0;
SELECT * FROM performance_schema.events_transactions_current ORDER BY event_id;
THREAD_ID	EVENT_ID	END_EVENT_ID	EVENT_NAME	STATE	TRX_ID	GTID	XID_FORMAT_ID	XID_GTRID	XID_BQUAL	XA_STATE	SOURCE	TIMER_START	TIMER_END	TIMER_WAIT	ACCESS_MODE	ISOLATION_LEVEL	AUTOCOMMIT	NUMBER_OF_SAVEPOINTS	NUMBER_OF_ROLLBACK_TO_SAVEPOINT	NUMBER_OF_RELEASE_SAVEPOINT	OBJECT_INSTANCE_BEGIN	NESTING_EVENT_ID	NESTING_EVENT_TYPE
#
#
# STEP 8.1 - UPDATE NON-TRANSACTIONAL TABLE
#
INSERT INTO nt1 VALUES (801, 'NON-TRANSACTIONAL');
#
## Expect 0 transactions in events_transactions_current
connection default;
CALL transaction_verifier(0, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug);
ACTUAL	EXPECTED
     1	       1
connection con1;
COMMIT;
#
## Expect 0 transactions in events_transactions_history
connection default;
CALL transaction_verifier(1, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug);
ACTUAL	EXPECTED
     1	       1
#
#
# STEP 8.2 - UPDATE TRANSACTIONAL AND NON-TRANSACTIONAL TABLES
#
#
## First non-transactional...
#
connection con1;
INSERT INTO nt1 VALUES (802, 'NON-TRANSACTIONAL');
#
## Expect 0 transactions in events_transactions_current
connection default;
CALL transaction_verifier(0, @con1_thread_id, 'transaction', '', 0, '', '', '', '', '', '', '', 0, 0, 0, @mariadb_bug);
ACTUAL	EXPECTED
     1	       1
#
## Now transactional. Transaction should be started.
connection con1;
INSERT INTO t1 VALUES (802, 'TRANSACTIONAL');
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
connection con1;
COMMIT;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', 'READ WRITE', '', 'NO', 0, 0, 0, 1+@mariadb_bug);
ACTUAL	EXPECTED
     2	       2
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 9 - SAVEPOINTS
# ========================================================================
#
# STEP 9.1 - SAVEPOINT 1
#
connection con1;
START TRANSACTION;
INSERT INTO t1 VALUES (901, 'SAVEPOINT');
SAVEPOINT SVP001;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
#
# STEP 9.2 - SAVEPOINTS 2 and 3
#
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;
COUNT(*)
4
#
#
# STEP 9.3 - ROLLBACK TO SAVEPOINT 2
#
connection con1;
ROLLBACK TO SVP002;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
#
# STEP 9.4 - RELEASE SAVEPOINT 1
#
connection con1;
RELEASE SAVEPOINT SVP001;
#
## 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);
ACTUAL	EXPECTED
     1	       1
#
# STEP 9.5 - COMMIT
#
connection con1;
COMMIT;
#
## 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);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
# ========================================================================
# STEP 10 - GTIDs
# ========================================================================
# GTIDs are tested in transaction_gtid.test.
#
# ========================================================================
# STEP 11 - MISCELLANY
# ========================================================================
#
# STEP 11.1 - TRUNCATE DURING ACTIVE TRANSACTION
#
#
# Verify that truncating events_transactions_current during an active transaction
# does not leave an orphaned transaction event, and that the row index to
# events_transactions_history is reset to 0.
#
connection con1;
START TRANSACTION;
INSERT INTO t1 VALUES (1110, 'INSERT 1110');
connection default;
TRUNCATE performance_schema.events_transactions_current;
connection con1;
#
COMMIT;
#
START TRANSACTION;
INSERT INTO t1 VALUES (1111, 'INSERT 1111');
COMMIT;
#
## Expect 1 transaction for connection 1
connection default;
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', '', '', '', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_transaction_tables();
#
#
# STEP 11.2 - DISABLE THREAD INSTRUMENTATION
#
connection default;
UPDATE performance_schema.setup_consumers
SET enabled = 'NO'
  WHERE name = 'thread_instrumentation';
#
TRUNCATE performance_schema.events_transactions_summary_global_by_event_name;
connection con1;
#
START TRANSACTION;
INSERT INTO t1 VALUES (1120, 'INSERT 1120');
COMMIT;
connection default;
#
## Expect 1 event with non-zero summary stats
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;
EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	COUNT_READ_WRITE
#
## Disable timing stats for 'transaction'
UPDATE performance_schema.setup_instruments SET timed = 'NO' WHERE name = 'transaction';
#
TRUNCATE performance_schema.events_transactions_summary_global_by_event_name;
connection default;
#
START TRANSACTION;
INSERT INTO t1 VALUES (1121, 'INSERT 1121');
COMMIT;
connection default;
#
## Expect 1 event, 0 stats
SELECT * FROM performance_schema.events_transactions_summary_global_by_event_name;
EVENT_NAME	COUNT_STAR	SUM_TIMER_WAIT	MIN_TIMER_WAIT	AVG_TIMER_WAIT	MAX_TIMER_WAIT	COUNT_READ_WRITE	SUM_TIMER_READ_WRITE	MIN_TIMER_READ_WRITE	AVG_TIMER_READ_WRITE	MAX_TIMER_READ_WRITE	COUNT_READ_ONLY	SUM_TIMER_READ_ONLY	MIN_TIMER_READ_ONLY	AVG_TIMER_READ_ONLY	MAX_TIMER_READ_ONLY
transaction	1	0	0	0	0	1	0	0	0	0	0	0	0	0	0
#
## 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';
#
DELETE FROM t1;
CALL clear_history();
#
#
# STEP 11.3 - STATEMENT ROLLBACK - AUTOCOMMIT OFF - BINLOG FORMAT 'STATEMENT'
#
connection con1;
SET SESSION binlog_format = STATEMENT;
SET SESSION AUTOCOMMIT = 0;
#
START TRANSACTION;
INSERT INTO t1 VALUES (1130, 'INSERT 1130');
#
## Expect binlog statement mode error
UPDATE t1, performance_schema.setup_instruments pfs
SET t1.s1 = 1, pfs.timed = 'NO';
#
COMMIT;
#
SET SESSION AUTOCOMMIT = 1;
#
## Expect 1 committed transaction
connection default;
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'COMMITTED', 0, '', '', '', '', '', '', 'NO', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
#
DELETE FROM t1;
CALL clear_history();
#
#
# STEP 11.4 - STATEMENT ROLLBACK - AUTOCOMMIT ON - BINLOG FORMAT 'STATEMENT'
#
connection con1;
SET SESSION binlog_format = STATEMENT;
SET SESSION AUTOCOMMIT = 1;
#
## Expect binlog statement mode error
UPDATE t1, performance_schema.setup_instruments pfs
SET t1.s1 = 1, pfs.timed = 'NO';
#
## Expect 1 rolled back transaction
connection default;
CALL transaction_verifier(1, @con1_thread_id, 'transaction', 'ROLLED BACK', 0, '', '', '', '', '', '', 'YES', 0, 0, 0, 1);
ACTUAL	EXPECTED
     1	       1
CALL clear_history();
#
# ========================================================================
# CLEAN UP
# ========================================================================
#
disconnect con1;
connection default;
DROP TABLE t1;
DROP TABLE nt1;
DROP PROCEDURE clear_transaction_tables;
DROP PROCEDURE clear_transaction_history;
DROP PROCEDURE clear_statement_history;
DROP PROCEDURE clear_history;
DROP PROCEDURE transaction_verifier;
set global binlog_format=default;