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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
|
#
#========================================================================
# STEP 1 - SETUP
#========================================================================
#
## Setup control thread
#
connection default;
SET SESSION AUTOCOMMIT= 1;
USE test;
DROP DATABASE IF EXISTS db;
#
## Create test database, test tables, one transactional and one non-transactional
CREATE DATABASE db;
CREATE TABLE db.t1 (s1 int, s2 varchar(64)) ENGINE=INNODB;
CREATE TABLE db.nt1 (s1 int, s2 varchar(64)) ENGINE=MYISAM;
#
## Setup connection 1
connect con1, localhost, root,,;
USE db;
SET SESSION AUTOCOMMIT = 1;
SELECT thread_id INTO @my_thread_id
FROM performance_schema.threads
WHERE processlist_id = connection_id();
connection default;
#
## Disable events from the control (default) connection
UPDATE performance_schema.threads SET instrumented = 'NO' WHERE processlist_id = CONNECTION_ID();
SET @all_threads= 0;
#
## Enable only transaction and statement instruments
UPDATE performance_schema.setup_instruments SET enabled='NO', timed='NO';
UPDATE performance_schema.setup_instruments SET enabled='YES'
WHERE name LIKE ('statement/%') OR name = 'transaction';
#
## Clear statement and transaction history
CALL test.clear_history();
#
#========================================================================
# STEP 2 - BASIC TRANSACTION
#========================================================================
#
# STEP 2.1 - IMPLICIT
#
connection con1;
INSERT INTO t1 VALUES (210, "INSERT 210");
INSERT INTO t1 VALUES (211, "INSERT 211");
INSERT INTO t1 VALUES (212, "INSERT 212");
UPDATE t1 SET s1 = s1 + 1 WHERE s1 = 212;
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 8 8 transaction COMMITTED READ WRITE REPEATABLE READ YES 7 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 2 transaction COMMITTED READ WRITE REPEATABLE READ YES 1 STATEMENT
thread_id 4 4 transaction COMMITTED READ WRITE REPEATABLE READ YES 3 STATEMENT
thread_id 6 6 transaction COMMITTED READ WRITE REPEATABLE READ YES 5 STATEMENT
thread_id 8 8 transaction COMMITTED READ WRITE REPEATABLE READ YES 7 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/insert NULL NULL NULL 0 INSERT INTO t1 VALUES (210, "INSERT 210")
thread_id 3 4 statement/sql/insert NULL NULL NULL 0 INSERT INTO t1 VALUES (211, "INSERT 211")
thread_id 5 6 statement/sql/insert NULL NULL NULL 0 INSERT INTO t1 VALUES (212, "INSERT 212")
thread_id 7 8 statement/sql/update NULL NULL NULL 0 UPDATE t1 SET s1 = s1 + 1 WHERE s1 = 212
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/insert NULL NULL INSERT INTO t1 VALUES (210, "INSERT 210")
thread_id 2 2 transaction 1 STATEMENT <transaction started>
thread_id 3 4 statement/sql/insert NULL NULL INSERT INTO t1 VALUES (211, "INSERT 211")
thread_id 4 4 transaction 3 STATEMENT <transaction started>
thread_id 5 6 statement/sql/insert NULL NULL INSERT INTO t1 VALUES (212, "INSERT 212")
thread_id 6 6 transaction 5 STATEMENT <transaction started>
thread_id 7 8 statement/sql/update NULL NULL UPDATE t1 SET s1 = s1 + 1 WHERE s1 = 212
thread_id 8 8 transaction 7 STATEMENT <transaction started>
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#
# STEP 2.2 - EXPLICIT
#
connection con1;
START TRANSACTION;
INSERT INTO t1 VALUES (220, "INSERT 220"), (221, "INSERT 221");
UPDATE t1 SET s2 = "UPDATE 221" WHERE s1 = 221;
COMMIT;
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 5 transaction COMMITTED READ WRITE REPEATABLE READ NO 1 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 5 transaction COMMITTED READ WRITE REPEATABLE READ NO 1 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 3 3 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (220, "INSERT 220"), (221, "INSERT 221")
thread_id 4 4 statement/sql/update NULL 2 TRANSACTION 0 UPDATE t1 SET s2 = "UPDATE 221" WHERE s1 = 221
thread_id 5 5 statement/sql/commit NULL 2 TRANSACTION 0 COMMIT
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/begin NULL NULL START TRANSACTION
thread_id 2 5 transaction 1 STATEMENT <transaction started>
thread_id 3 3 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (220, "INSERT 220"), (221, "INSERT 221")
thread_id 4 4 statement/sql/update 2 TRANSACTION UPDATE t1 SET s2 = "UPDATE 221" WHERE s1 = 221
thread_id 5 5 statement/sql/commit 2 TRANSACTION COMMIT
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#========================================================================
# STEP 3 - TRANSACTIONS AND STORED PROCEDURES
#========================================================================
#
# STEP 3.1 - STORED PROCEDURE STARTED WITHIN TRANSACTION
#
connection con1;
CREATE PROCEDURE tp_update() UPDATE t1 SET s1 = s1 + 1;
#
START TRANSACTION;
INSERT INTO t1 VALUES (310, "INSERT 310");
INSERT INTO t1 VALUES (311, "INSERT 311");
INSERT INTO t1 VALUES (312, "INSERT 312");
INSERT INTO t1 VALUES (313, "INSERT 313");
CALL tp_update();
COMMIT;
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 10 12 transaction COMMITTED READ WRITE REPEATABLE READ NO 9 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 2 transaction COMMITTED READ WRITE REPEATABLE READ YES 1 STATEMENT
thread_id 10 10 transaction COMMITTED READ WRITE REPEATABLE READ NO 9 STATEMENT
thread_id 10 12 transaction COMMITTED READ WRITE REPEATABLE READ NO 9 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/create_procedure NULL NULL NULL 0 CREATE PROCEDURE tp_update() UPDATE t1 SET s1 = s1 + 1
thread_id 3 4 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 5 5 statement/sql/insert NULL 4 TRANSACTION 0 INSERT INTO t1 VALUES (310, "INSERT 310")
thread_id 6 6 statement/sql/insert NULL 4 TRANSACTION 0 INSERT INTO t1 VALUES (311, "INSERT 311")
thread_id 7 7 statement/sql/insert NULL 4 TRANSACTION 0 INSERT INTO t1 VALUES (312, "INSERT 312")
thread_id 8 8 statement/sql/insert NULL 4 TRANSACTION 0 INSERT INTO t1 VALUES (313, "INSERT 313")
thread_id 9 11 statement/sql/call_procedure NULL 4 TRANSACTION 0 CALL tp_update()
thread_id 11 11 statement/sp/stmt tp_update 9 STATEMENT 1 UPDATE t1 SET s1 = s1 + 1
thread_id 12 12 statement/sql/commit NULL NULL NULL 0 COMMIT
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/create_proc NULL NULL CREATE PROCEDURE tp_update() UPDATE t1 SET s1 = s1 + 1
thread_id 2 2 transaction 1 STATEMENT <transaction started>
thread_id 3 4 statement/sql/begin NULL NULL START TRANSACTION
thread_id 5 5 statement/sql/insert 4 TRANSACTION INSERT INTO t1 VALUES (310, "INSERT 310")
thread_id 6 6 statement/sql/insert 4 TRANSACTION INSERT INTO t1 VALUES (311, "INSERT 311")
thread_id 7 7 statement/sql/insert 4 TRANSACTION INSERT INTO t1 VALUES (312, "INSERT 312")
thread_id 8 8 statement/sql/insert 4 TRANSACTION INSERT INTO t1 VALUES (313, "INSERT 313")
thread_id 9 11 statement/sql/call_proced 4 TRANSACTION CALL tp_update()
thread_id 10 10 transaction 9 STATEMENT <transaction started>
thread_id 10 12 transaction 9 STATEMENT <transaction started>
thread_id 11 11 statement/sp/stmt 9 STATEMENT UPDATE t1 SET s1 = s1 + 1
thread_id 12 12 statement/sql/commit NULL NULL COMMIT
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#
# STEP 3.2 - TRANSACTION STARTED WITHIN STORED PROCEDURE
#
connection con1;
CREATE PROCEDURE tp_start() START TRANSACTION;
#
CALL tp_start();
INSERT INTO t1 VALUES (320, "INSERT 320"),(321, "INSERT 321");
INSERT INTO t1 VALUES (322, "INSERT 322"),(323, "INSERT 323");
UPDATE t1 SET s1 = s1 + 1 WHERE s1 > 320;
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
320 INSERT 320
322 INSERT 321
323 INSERT 322
324 INSERT 323
COMMIT;
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 6 11 transaction COMMITTED READ WRITE REPEATABLE READ NO 5 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 2 transaction COMMITTED READ WRITE REPEATABLE READ YES 1 STATEMENT
thread_id 4 4 transaction COMMITTED READ WRITE REPEATABLE READ YES 3 STATEMENT
thread_id 6 11 transaction COMMITTED READ WRITE REPEATABLE READ NO 5 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/create_procedure NULL NULL NULL 0 CREATE PROCEDURE tp_start() START TRANSACTION
thread_id 3 6 statement/sql/call_procedure NULL NULL NULL 0 CALL tp_start()
thread_id 5 6 statement/sp/stmt tp_start 3 STATEMENT 1 START TRANSACTION
thread_id 7 7 statement/sql/insert NULL 6 TRANSACTION 0 INSERT INTO t1 VALUES (320, "INSERT 320"),(321, "INSERT 321")
thread_id 8 8 statement/sql/insert NULL 6 TRANSACTION 0 INSERT INTO t1 VALUES (322, "INSERT 322"),(323, "INSERT 323")
thread_id 9 9 statement/sql/update NULL 6 TRANSACTION 0 UPDATE t1 SET s1 = s1 + 1 WHERE s1 > 320
thread_id 10 10 statement/sql/select NULL 6 TRANSACTION 0 SELECT * FROM t1 ORDER BY s1
thread_id 11 11 statement/sql/commit NULL 6 TRANSACTION 0 COMMIT
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/create_proc NULL NULL CREATE PROCEDURE tp_start() START TRANSACTION
thread_id 2 2 transaction 1 STATEMENT <transaction started>
thread_id 3 6 statement/sql/call_proced NULL NULL CALL tp_start()
thread_id 4 4 transaction 3 STATEMENT <transaction started>
thread_id 5 6 statement/sp/stmt 3 STATEMENT START TRANSACTION
thread_id 6 11 transaction 5 STATEMENT <transaction started>
thread_id 7 7 statement/sql/insert 6 TRANSACTION INSERT INTO t1 VALUES (320, "INSERT 320"),(321, "INSERT 321")
thread_id 8 8 statement/sql/insert 6 TRANSACTION INSERT INTO t1 VALUES (322, "INSERT 322"),(323, "INSERT 323")
thread_id 9 9 statement/sql/update 6 TRANSACTION UPDATE t1 SET s1 = s1 + 1 WHERE s1 > 320
thread_id 10 10 statement/sql/select 6 TRANSACTION SELECT * FROM t1 ORDER BY s1
thread_id 11 11 statement/sql/commit 6 TRANSACTION COMMIT
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#
# STEP 3.3 - TRANSACTION ENDED WITHIN STORED PROCEDURE
#
connection con1;
CREATE PROCEDURE tp_rollback() ROLLBACK;
CREATE PROCEDURE tp_commit() COMMIT;
#
## COMMIT within stored procedure
START TRANSACTION;
INSERT INTO t1 VALUES (330, "INSERT 330"),(331, "INSERT 331");
INSERT INTO t1 VALUES (332, "INSERT 332"),(333, "INSERT 333");
DELETE FROM t1 WHERE s1 > 331;
CALL tp_commit();
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
330 INSERT 330
331 INSERT 331
#
## ROLLBACK within stored procedure
START TRANSACTION;
UPDATE t1 SET s1 = s1*2 WHERE s1 > 331;
CALL tp_rollback();
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
330 INSERT 330
331 INSERT 331
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 22 22 transaction COMMITTED READ WRITE REPEATABLE READ YES 21 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 2 transaction COMMITTED READ WRITE REPEATABLE READ YES 1 STATEMENT
thread_id 4 4 transaction COMMITTED READ WRITE REPEATABLE READ YES 3 STATEMENT
thread_id 11 11 transaction COMMITTED READ WRITE REPEATABLE READ NO 10 STATEMENT
thread_id 11 12 transaction COMMITTED READ WRITE REPEATABLE READ NO 10 STATEMENT
thread_id 14 14 transaction COMMITTED READ WRITE REPEATABLE READ YES 13 STATEMENT
thread_id 19 19 transaction COMMITTED READ WRITE REPEATABLE READ NO 18 STATEMENT
thread_id 19 20 transaction ROLLED BACK READ WRITE REPEATABLE READ NO 18 STATEMENT
thread_id 22 22 transaction COMMITTED READ WRITE REPEATABLE READ YES 21 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/create_procedure NULL NULL NULL 0 CREATE PROCEDURE tp_rollback() ROLLBACK
thread_id 3 4 statement/sql/create_procedure NULL NULL NULL 0 CREATE PROCEDURE tp_commit() COMMIT
thread_id 5 6 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 7 7 statement/sql/insert NULL 6 TRANSACTION 0 INSERT INTO t1 VALUES (330, "INSERT 330"),(331, "INSERT 331")
thread_id 8 8 statement/sql/insert NULL 6 TRANSACTION 0 INSERT INTO t1 VALUES (332, "INSERT 332"),(333, "INSERT 333")
thread_id 9 9 statement/sql/delete NULL 6 TRANSACTION 0 DELETE FROM t1 WHERE s1 > 331
thread_id 10 12 statement/sql/call_procedure NULL 6 TRANSACTION 0 CALL tp_commit()
thread_id 12 12 statement/sp/stmt tp_commit 10 STATEMENT 1 COMMIT
thread_id 13 14 statement/sql/select NULL NULL NULL 0 SELECT * FROM t1 ORDER BY s1
thread_id 15 16 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 17 17 statement/sql/update NULL 16 TRANSACTION 0 UPDATE t1 SET s1 = s1*2 WHERE s1 > 331
thread_id 18 20 statement/sql/call_procedure NULL 16 TRANSACTION 0 CALL tp_rollback()
thread_id 20 20 statement/sp/stmt tp_rollback 18 STATEMENT 1 ROLLBACK
thread_id 21 22 statement/sql/select NULL NULL NULL 0 SELECT * FROM t1 ORDER BY s1
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/create_proc NULL NULL CREATE PROCEDURE tp_rollback() ROLLBACK
thread_id 2 2 transaction 1 STATEMENT <transaction started>
thread_id 3 4 statement/sql/create_proc NULL NULL CREATE PROCEDURE tp_commit() COMMIT
thread_id 4 4 transaction 3 STATEMENT <transaction started>
thread_id 5 6 statement/sql/begin NULL NULL START TRANSACTION
thread_id 7 7 statement/sql/insert 6 TRANSACTION INSERT INTO t1 VALUES (330, "INSERT 330"),(331, "INSERT 331")
thread_id 8 8 statement/sql/insert 6 TRANSACTION INSERT INTO t1 VALUES (332, "INSERT 332"),(333, "INSERT 333")
thread_id 9 9 statement/sql/delete 6 TRANSACTION DELETE FROM t1 WHERE s1 > 331
thread_id 10 12 statement/sql/call_proced 6 TRANSACTION CALL tp_commit()
thread_id 11 11 transaction 10 STATEMENT <transaction started>
thread_id 11 12 transaction 10 STATEMENT <transaction started>
thread_id 12 12 statement/sp/stmt 10 STATEMENT COMMIT
thread_id 13 14 statement/sql/select NULL NULL SELECT * FROM t1 ORDER BY s1
thread_id 14 14 transaction 13 STATEMENT <transaction started>
thread_id 15 16 statement/sql/begin NULL NULL START TRANSACTION
thread_id 17 17 statement/sql/update 16 TRANSACTION UPDATE t1 SET s1 = s1*2 WHERE s1 > 331
thread_id 18 20 statement/sql/call_proced 16 TRANSACTION CALL tp_rollback()
thread_id 19 19 transaction 18 STATEMENT <transaction started>
thread_id 19 20 transaction 18 STATEMENT <transaction started>
thread_id 20 20 statement/sp/stmt 18 STATEMENT ROLLBACK
thread_id 21 22 statement/sql/select NULL NULL SELECT * FROM t1 ORDER BY s1
thread_id 22 22 transaction 21 STATEMENT <transaction started>
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#========================================================================
# STEP 4 - TRANSACTIONS AND STORED FUNCTIONS
#========================================================================
#
#
# STEP 4.1 - FUNCTION WITHIN A TRANSACTION
#
connection con1;
CREATE FUNCTION fn_add(x INT, y INT) RETURNS INT
BEGIN
INSERT INTO t1 VALUES (x, "INSERT x"),(y, "INSERT y");
RETURN x+y;
END |
#
## Clear history
connection default;
CALL test.clear_history();
connection con1;
#
START TRANSACTION;
INSERT INTO t1 VALUES (410, "INSERT 410");
INSERT INTO t1 VALUES (411, "INSERT 411");
INSERT INTO t1 VALUES (412, "INSERT 412");
DELETE FROM t1 WHERE s1 > 410;
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
410 INSERT 410
#
SELECT fn_add(413, 414);
fn_add(413, 414)
827
COMMIT;
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
410 INSERT 410
413 INSERT x
414 INSERT y
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 14 14 transaction COMMITTED READ WRITE REPEATABLE READ YES 13 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 9 9 transaction COMMITTED READ WRITE REPEATABLE READ NO 8 STATEMENT
thread_id 9 12 transaction COMMITTED READ WRITE REPEATABLE READ NO 8 STATEMENT
thread_id 14 14 transaction COMMITTED READ WRITE REPEATABLE READ YES 13 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 3 3 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (410, "INSERT 410")
thread_id 4 4 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (411, "INSERT 411")
thread_id 5 5 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (412, "INSERT 412")
thread_id 6 6 statement/sql/delete NULL 2 TRANSACTION 0 DELETE FROM t1 WHERE s1 > 410
thread_id 7 7 statement/sql/select NULL 2 TRANSACTION 0 SELECT * FROM t1 ORDER BY s1
thread_id 8 11 statement/sql/select NULL 2 TRANSACTION 0 SELECT fn_add(413, 414)
thread_id 10 10 statement/sp/stmt fn_add 8 STATEMENT 1 INSERT INTO t1 VALUES (x, "INSERT x"),(y, "INSERT y")
thread_id 11 11 statement/sp/freturn fn_add 8 STATEMENT 1 NULL
thread_id 12 12 statement/sql/commit NULL NULL NULL 0 COMMIT
thread_id 13 14 statement/sql/select NULL NULL NULL 0 SELECT * FROM t1 ORDER BY s1
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/begin NULL NULL START TRANSACTION
thread_id 3 3 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (410, "INSERT 410")
thread_id 4 4 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (411, "INSERT 411")
thread_id 5 5 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (412, "INSERT 412")
thread_id 6 6 statement/sql/delete 2 TRANSACTION DELETE FROM t1 WHERE s1 > 410
thread_id 7 7 statement/sql/select 2 TRANSACTION SELECT * FROM t1 ORDER BY s1
thread_id 8 11 statement/sql/select 2 TRANSACTION SELECT fn_add(413, 414)
thread_id 9 9 transaction 8 STATEMENT <transaction started>
thread_id 9 12 transaction 8 STATEMENT <transaction started>
thread_id 10 10 statement/sp/stmt 8 STATEMENT INSERT INTO t1 VALUES (x, "INSERT x"),(y, "INSERT y")
thread_id 11 11 statement/sp/freturn 8 STATEMENT NULL
thread_id 12 12 statement/sql/commit NULL NULL COMMIT
thread_id 13 14 statement/sql/select NULL NULL SELECT * FROM t1 ORDER BY s1
thread_id 14 14 transaction 13 STATEMENT <transaction started>
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
connection con1;
#
## Again, but this time with a rollback
#
START TRANSACTION;
SELECT fn_add(415, 416);
fn_add(415, 416)
831
#
ROLLBACK;
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 8 8 transaction COMMITTED READ WRITE REPEATABLE READ YES 7 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 6 transaction ROLLED BACK READ WRITE REPEATABLE READ NO 1 STATEMENT
thread_id 8 8 transaction COMMITTED READ WRITE REPEATABLE READ YES 7 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 3 5 statement/sql/select NULL 2 TRANSACTION 0 SELECT fn_add(415, 416)
thread_id 4 4 statement/sp/stmt fn_add 3 STATEMENT 1 INSERT INTO t1 VALUES (x, "INSERT x"),(y, "INSERT y")
thread_id 5 5 statement/sp/freturn fn_add 3 STATEMENT 1 NULL
thread_id 6 6 statement/sql/rollback NULL 2 TRANSACTION 0 ROLLBACK
thread_id 7 8 statement/sql/select NULL NULL NULL 0 SELECT * FROM t1 ORDER BY s1
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/begin NULL NULL START TRANSACTION
thread_id 2 6 transaction 1 STATEMENT <transaction started>
thread_id 3 5 statement/sql/select 2 TRANSACTION SELECT fn_add(415, 416)
thread_id 4 4 statement/sp/stmt 3 STATEMENT INSERT INTO t1 VALUES (x, "INSERT x"),(y, "INSERT y")
thread_id 5 5 statement/sp/freturn 3 STATEMENT NULL
thread_id 6 6 statement/sql/rollback 2 TRANSACTION ROLLBACK
thread_id 7 8 statement/sql/select NULL NULL SELECT * FROM t1 ORDER BY s1
thread_id 8 8 transaction 7 STATEMENT <transaction started>
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
#
# STEP 4.2 - TRANSACTION CANNOT BE STARTED OR ENDED WITHIN FUNCTION
#
connection con1;
CREATE FUNCTION fn_err1() RETURNS VARCHAR(10) BEGIN START TRANSACTION ; RETURN 'invalid' ; END|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
#
## Expect 0 transactions
connection default;
SELECT COUNT(*) FROM performance_schema.events_transactions_history;
COUNT(*)
0
connection con1;
#
## Expect stored function does not exist
#
SELECT fn_err1();
ERROR 42000: FUNCTION db.fn_err1 does not exist
#
## Expect 1 transactions
connection default;
SELECT COUNT(*) FROM performance_schema.events_transactions_history;
COUNT(*)
1
connection con1;
#
CREATE FUNCTION fn_err2() RETURNS VARCHAR(10) BEGIN COMMIT; RETURN 'invalid' ; END|
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger
#
## Expect stored function does not exist
#
START TRANSACTION;
DELETE FROM t1 WHERE s1 > 320;
SELECT fn_err2();
ERROR 42000: FUNCTION db.fn_err2 does not exist
#
## Expect 2 transactions
connection default;
SELECT COUNT(*) FROM performance_schema.events_transactions_history;
COUNT(*)
2
#
## Clear transaction and statement tables
CALL test.clear_history();
#========================================================================
# STEP 5 - TRANSACTIONS AND TRIGGERS
#========================================================================
#
#
# STEP 5.1 - FORCE STATEMENT ROLLBACK FROM TRIGGER
#
connection con1;
## Create a trigger to force statement rollback
#
CREATE TRIGGER trigger_before_update BEFORE UPDATE ON t1
FOR EACH ROW
BEGIN
IF OLD.s1 >= 505 THEN
SIGNAL sqlstate '45001' SET message_text = "FORCE ERROR";
END IF;
END;|
#
## Clear history
connection default;
CALL test.clear_history();
connection con1;
#
## Insert multiple rows, then update. Trigger will force rollback the
## UPDATE statement, but the transaction should not roll back.
#
START TRANSACTION;
INSERT INTO t1 VALUES (500, "INSERT 500");
INSERT INTO t1 VALUES (501, "INSERT 501");
INSERT INTO t1 VALUES (502, "INSERT 502");
INSERT INTO t1 VALUES (503, "INSERT 503");
INSERT INTO t1 VALUES (504, "INSERT 504");
INSERT INTO t1 VALUES (505, "INSERT 505");
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
500 INSERT 500
501 INSERT 501
502 INSERT 502
503 INSERT 503
504 INSERT 504
505 INSERT 505
#
## Expect error when UPDATE hits record 505
#
UPDATE t1 SET s1 = s1 * 2 WHERE s1 >= 500;
ERROR 45001: FORCE ERROR
#
## Verify that INSERT succeeded, UPDATE failed and transaction did not rollback
#
SELECT * FROM t1 ORDER BY s1;
s1 s2
500 INSERT 500
501 INSERT 501
502 INSERT 502
503 INSERT 503
504 INSERT 504
505 INSERT 505
COMMIT;
#
DROP TRIGGER trigger_before_update;
connection default;
#========================================================================
# Verify
#========================================================================
SELECT event_id into @base_tx_event_id
from performance_schema.events_transactions_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
SELECT event_id into @base_stmt_event_id from performance_schema.events_statements_history_long
where (THREAD_ID = @con1_thread_id)
order by event_id limit 1;
select if(@base_tx_event_id < @base_stmt_event_id,
@base_tx_event_id - 1,
@base_stmt_event_id - 1)
into @base_event_id;
#
# EVENTS_TRANSACTIONS_CURRENT
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_current
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 21 21 transaction COMMITTED READ WRITE REPEATABLE READ YES 20 STATEMENT
#
# EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 11, ' ') 'EVENT_NAME ',
RPAD(STATE, 11, ' ') 'STATE ',
RPAD(ACCESS_MODE, 11, ' ') ACCESS_MODE,
RPAD(ISOLATION_LEVEL, 16, ' ') 'ISOLATION_LEVEL ',
RPAD(AUTOCOMMIT, 4, ' ') AUTO,
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE
FROM performance_schema.events_transactions_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME STATE ACCESS_MODE ISOLATION_LEVEL AUTO R_NESTING_EVENT_ID NESTING_EVENT_TYPE
thread_id 2 19 transaction COMMITTED READ WRITE REPEATABLE READ NO 1 STATEMENT
thread_id 21 21 transaction COMMITTED READ WRITE REPEATABLE READ YES 20 STATEMENT
#
# EVENTS_STATEMENTS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 30, ' ') 'EVENT_NAME ',
RPAD(IFNULL(object_name, 'NULL'), 12, ' ') 'OBJECT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
LPAD(NESTING_EVENT_LEVEL, 5, ' ') LEVEL,
SQL_TEXT
FROM performance_schema.events_statements_history_long
WHERE ((THREAD_ID = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME OBJECT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE LEVEL SQL_TEXT
thread_id 1 2 statement/sql/begin NULL NULL NULL 0 START TRANSACTION
thread_id 3 3 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (500, "INSERT 500")
thread_id 4 4 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (501, "INSERT 501")
thread_id 5 5 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (502, "INSERT 502")
thread_id 6 6 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (503, "INSERT 503")
thread_id 7 7 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (504, "INSERT 504")
thread_id 8 8 statement/sql/insert NULL 2 TRANSACTION 0 INSERT INTO t1 VALUES (505, "INSERT 505")
thread_id 9 9 statement/sql/select NULL 2 TRANSACTION 0 SELECT * FROM t1 ORDER BY s1
thread_id 10 17 statement/sql/update NULL 2 TRANSACTION 0 UPDATE t1 SET s1 = s1 * 2 WHERE s1 >= 500
thread_id 11 11 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 12 12 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 13 13 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 14 14 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 15 15 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 16 16 statement/sp/jump_if_not trigger_befo 10 STATEMENT 1 NULL
thread_id 17 17 statement/sp/stmt trigger_befo 10 STATEMENT 1 SIGNAL sqlstate '45001' SET message_text = "FORCE ERROR"
thread_id 18 18 statement/sql/select NULL 2 TRANSACTION 0 SELECT * FROM t1 ORDER BY s1
thread_id 19 19 statement/sql/commit NULL 2 TRANSACTION 0 COMMIT
thread_id 20 21 statement/sql/drop_trigger NULL NULL NULL 0 DROP TRIGGER trigger_before_update
#
### Combined statement and transaction event history ordered by event id
#
#EVENTS_STATEMENTS_HISTORY_LONG + EVENTS_TRANSACTIONS_HISTORY_LONG
#
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(NESTING_EVENT_ID - @base_event_id, 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
'<transaction started>' AS SQL_TXT
FROM performance_schema.events_transactions_history_long t
WHERE (t.thread_id = @con1_thread_id)
UNION
SELECT THREAD_ID,
LPAD(EVENT_ID - @base_event_id, 11, ' ') as R_EVENT_ID,
LPAD(END_EVENT_ID - @base_event_id, 11, ' ') as R_END_EVENT_ID,
RPAD(EVENT_NAME, 25, ' ') 'EVENT_NAME ',
LPAD(IFNULL(NESTING_EVENT_ID - @base_event_id, 'NULL'), 19, ' ') as R_NESTING_EVENT_ID,
RPAD(IFNULL(NESTING_EVENT_TYPE, 'NULL'), 18, ' ') NESTING_EVENT_TYPE,
SQL_TEXT
FROM performance_schema.events_statements_history_long s
WHERE ((s.thread_id = @con1_thread_id) OR (@all_threads = 1))
ORDER BY thread_id, r_event_id;
THREAD_ID R_EVENT_ID R_END_EVENT_ID EVENT_NAME R_NESTING_EVENT_ID NESTING_EVENT_TYPE SQL_TXT
thread_id 1 2 statement/sql/begin NULL NULL START TRANSACTION
thread_id 2 19 transaction 1 STATEMENT <transaction started>
thread_id 3 3 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (500, "INSERT 500")
thread_id 4 4 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (501, "INSERT 501")
thread_id 5 5 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (502, "INSERT 502")
thread_id 6 6 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (503, "INSERT 503")
thread_id 7 7 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (504, "INSERT 504")
thread_id 8 8 statement/sql/insert 2 TRANSACTION INSERT INTO t1 VALUES (505, "INSERT 505")
thread_id 9 9 statement/sql/select 2 TRANSACTION SELECT * FROM t1 ORDER BY s1
thread_id 10 17 statement/sql/update 2 TRANSACTION UPDATE t1 SET s1 = s1 * 2 WHERE s1 >= 500
thread_id 11 11 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 12 12 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 13 13 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 14 14 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 15 15 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 16 16 statement/sp/jump_if_not 10 STATEMENT NULL
thread_id 17 17 statement/sp/stmt 10 STATEMENT SIGNAL sqlstate '45001' SET message_text = "FORCE ERROR"
thread_id 18 18 statement/sql/select 2 TRANSACTION SELECT * FROM t1 ORDER BY s1
thread_id 19 19 statement/sql/commit 2 TRANSACTION COMMIT
thread_id 20 21 statement/sql/drop_trigge NULL NULL DROP TRIGGER trigger_before_update
thread_id 21 21 transaction 20 STATEMENT <transaction started>
#
### Clear statement and transaction history
# CALL test.clear_history();
CALL test.clear_history();
## Reset db.t1
DELETE FROM db.t1;
#
# TODO: Detect statement events from scheduled event
#=======================================================================
# Cleanup
#=======================================================================
connection con1;
disconnect con1;
connection default;
DROP DATABASE db;
UPDATE performance_schema.setup_instruments SET enabled='YES', timed='YES';
DROP PROCEDURE clear_transaction_tables;
DROP PROCEDURE clear_transaction_history;
DROP PROCEDURE clear_statement_history;
DROP PROCEDURE clear_history;
DROP PROCEDURE transaction_verifier;
|