File: session_tracker_trx_state_myisam.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (393 lines) | stat: -rw-r--r-- 9,186 bytes parent folder | download
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
#
# WL#6631: Detect transaction boundaries
#
########################################################################
#
# set up: save settings
#
SET autocommit=1;
# if we track CHARACTERISTICS, we must also track the tx_* sysvars!
SELECT @@session.session_track_system_variables INTO @old_track_list;
SET @track_list= CONCAT(@old_track_list, ",transaction_isolation,
                                           transaction_read_only");
SET SESSION session_track_system_variables=@track_list;
SELECT @@session.session_track_state_change INTO @old_track_enable;
SET SESSION session_track_state_change=TRUE;
SELECT @@session.session_track_transaction_info INTO @old_track_tx;
FLUSH STATUS;
########################################################################
#
# test "STATE" tracking: transaction state reporting
#
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
# We don't report when in autocommit mode and outside a transaction:
INSERT INTO t1 VALUES(1);
SELECT 1 FROM DUAL;
1
1
DELETE FROM t1;
START TRANSACTION;
# add "unsafe stmt" to the set:
SET @x=UUID();
# next stmt is safe, but unsafe flag should stick:
SET @x=1;
# however, after C/A/C, the status should revert to "empty trx":
COMMIT AND CHAIN;
# SELECT with no tables gives us just a result set
SELECT 1 FROM DUAL;
1
1
COMMIT AND CHAIN;
# SELECT with no tables and no result set
SELECT 1 FROM DUAL INTO OUTFILE 'VARDIR/tmp/wl6631.csv';
COMMIT AND CHAIN;
# SELECT with trx tables but no result set
SELECT f1 FROM t1 INTO OUTFILE 'VARDIR/tmp/wl6631.csv';;
COMMIT AND CHAIN;
# SELECT with non-trx tables but no result set
SELECT f1 FROM t2 INTO OUTFILE 'VARDIR/tmp/wl6631.csv';;
# show that "unsafe read" sticks (isn't cleared by the dummy SELECT)
SELECT 1 FROM DUAL INTO @x;
# clear state
COMMIT;
DROP TABLE t1;
DROP TABLE t2;

# states: read + write; transactional + non-transactional
# state should be "no transaction":
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
# resulting state should be "T", transaction started, no data modified:
START TRANSACTION;
# resulting state should be "W", transactional write pending:
INSERT INTO t1 VALUES (1);
# resulting state should be "wW", both safe and unsafe writes happened:
INSERT INTO t2 VALUES (1);
# resulting state should STILL be "wW"!
INSERT INTO t1 VALUES (1);
ROLLBACK;
Warnings:
Warning	1196	Some non-transactional changed tables couldn't be rolled back
START TRANSACTION;
# resulting state should be "w", unsafe non-transaction write happened:
INSERT INTO t2 VALUES (1);
# resulting state should be "wW", both safe and unsafe writes happened:
INSERT INTO t1 VALUES (1);
# resulting state should be  "RwW" (adding transactional read):
SELECT f1 FROM t1;
f1
1
# resulting state should be "rRwW" (adding non-transactional read):
SELECT f1 FROM t2;
f1
1
1
ROLLBACK;
Warnings:
Warning	1196	Some non-transactional changed tables couldn't be rolled back
DROP TABLE t1, t2;

# autocommit (0)
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
SET autocommit=0;
SET @x=UUID();
SET @x=1;
SET @x=UUID();
# SET TRANSACTION one-shot should generate a tracker item when
# tracking statements. Transaction state however should not change.
# We can still set chistics here because in_active_multi_stmt_transaction()
# is still false (!SERVER_STATUS_IN_TRANS).
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
INSERT INTO t1 VALUES(1);
# Now that we've involved tables in the implicit transaction, we're
# no longer allowed to change its chistics:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
ERROR 25001: Transaction characteristics can't be changed while a transaction is in progress
BEGIN;
INSERT INTO t1 VALUES(3);
DROP TABLE t1;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
SELECT 1 FROM DUAL;
1
1
SELECT 1 FROM DUAL INTO @dummy;
COMMIT;
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
SELECT f1 FROM t2;
f1
DROP TABLE t2;
SET autocommit=1;

########################################################################
#
# show that table access reporting works in multi-statements
#
# multi-stmt #1
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;
COMMIT; INSERT INTO t2 VALUES (1); BEGIN; |
COMMIT;
DROP TABLE t2;
# multi-stmt #2
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;
COMMIT; INSERT INTO t2 VALUES (1); BEGIN; INSERT INTO t1 VALUES (99); |
COMMIT;
DROP TABLE t1;
DROP TABLE t2;

########################################################################
#
# show that reporting works for Stored Procedures (SP)
#
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
CREATE PROCEDURE proc1()
BEGIN
SET @dummy = 0;
IF (SELECT f1 FROM t1) THEN
SET @dummy = 1;
END IF;
END|
CREATE PROCEDURE proc2()
BEGIN
CALL proc1();
UPDATE t1 SET f1=4;
END|
CREATE PROCEDURE proc3()
BEGIN
DECLARE x CHAR(36);
SET x=UUID();
END|
CREATE PROCEDURE proc4(x CHAR(36))
BEGIN
END|
CREATE PROCEDURE proc5()
BEGIN
SELECT f1 FROM t1;
SELECT f1 FROM t2;
END|
CREATE PROCEDURE proc6a()
BEGIN
IF (SELECT f1 FROM t1) THEN
SET @dummy = 1;
END IF;
ALTER TABLE t1 ADD COLUMN f2 INT;
IF (SELECT f1 FROM t2) THEN
SET @dummy = 1;
END IF;
END|
CREATE PROCEDURE proc6b()
BEGIN
SELECT f1 FROM t1;
ALTER TABLE t1 ADD COLUMN f3 INT;
SELECT f1 FROM t2;
END|
CREATE PROCEDURE proc7(x INT)
BEGIN
SELECT f1   FROM t1;
SELECT f1*2 FROM t1;
END|
CREATE PROCEDURE proc8(x INT)
BEGIN
SELECT f1   FROM t1;
IF (SELECT f1 FROM t2) THEN
SET @dummy = 1;
END IF;
END|
CREATE PROCEDURE proc9(x INT)
BEGIN
SELECT f1   FROM t1;
IF (SELECT f1 FROM t1) THEN
SET @dummy = 1;
END IF;
END|
BEGIN;
# example unsafe call:
CALL proc3();
# report on tables accessed within SP:
CALL proc1();
# report on tables accessed within all (nested) SP:
CALL proc2();
COMMIT;
BEGIN;
CALL proc4(UUID());
COMMIT;
# multiple result sets:
# autocommit=1, not in a transaction, no tracker item:
CALL proc5();
f1
4
f1
2

BEGIN;
# first  SELECT adds R/S to present T and renders a tracker item;
# second SELECT add r flag and renders another tracker item
CALL proc5();
f1
4
f1
2
COMMIT;
SET autocommit=0;
# first  SELECT renders I/R/S tracker item;
# second SELECT add r flag and renders another tracker item
CALL proc5();
f1
4
f1
2
COMMIT;

BEGIN;
# first  SELECT adds R/S to present T and renders a tracker item;
# second SELECT add r flag and renders another tracker item
CALL proc5();
f1
4
f1
2
COMMIT;

# multiple result sets; implicit commit between them
BEGIN;
# first  SELECT adds R/S to present T and renders a tracker item;
# second SELECT add r flag and renders another tracker item
CALL proc6b();
f1
4
f1
2
COMMIT;
BEGIN;
# first  SELECT adds R/S to present T and renders a tracker item;
# second SELECT add r flag and renders another tracker item
CALL proc6a();
COMMIT;

# multiple result sets; sub-query as argument, autocommit==0
BEGIN;
SELECT 1 FROM DUAL;
1
1
CALL proc7((SELECT f1 FROM t2));
f1
4
f1*2
8
COMMIT;
SET autocommit=1;
# multiple result sets; sub-query as argument, autocommit==1
BEGIN;
SELECT 1 FROM DUAL;
1
1
CALL proc7((SELECT f1 FROM t2));
f1
4
f1*2
8
COMMIT;
# not in a transaction, no tracking
CALL proc8((SELECT f1 FROM t2));
f1
4

BEGIN;
# body sets R/S in select, and r in sub-select
CALL proc8((SELECT f1 FROM t2));
f1
4
COMMIT;

BEGIN;
# argument sets r, body sets R
CALL proc9((SELECT f1 FROM t2));
f1
4
COMMIT;

DROP PROCEDURE proc1;
DROP PROCEDURE proc2;
DROP PROCEDURE proc3;
DROP PROCEDURE proc4;
DROP PROCEDURE proc5;
DROP PROCEDURE proc6a;
DROP PROCEDURE proc6b;
DROP PROCEDURE proc7;
DROP PROCEDURE proc8;
DROP PROCEDURE proc9;
DROP TABLE t1;
DROP TABLE t2;
########################################################################
#
# interaction with system tables
#
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;
SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
CONVERT_TZ('2004-01-01 12:00:00','GMT','MET')
NULL
COMMIT;
DROP TABLE t2;
########################################################################
#
#
# show that table access reporting works with LOCK TABLES
#
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
SET autocommit=0;
SELECT 1  FROM DUAL;
1
1
SELECT f1 FROM t1;
f1
# no LOCK held this time, so no implicit commit:
UNLOCK TABLES;
# LOCK TABLES pre-commits:
LOCK TABLES t1 WRITE;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
SELECT f1 FROM t1;
f1
1
2
COMMIT;
SET TRANSACTION READ ONLY;
SET TRANSACTION READ WRITE;
UNLOCK TABLES;

SET autocommit=1;
LOCK TABLE t1 WRITE, t2 WRITE;
INSERT INTO t2 VALUES (3);
INSERT INTO t1 VALUES (3);
SELECT f1 FROM t1 WHERE f1 > 2;
f1
3
UNLOCK TABLES;
# don't report chistics for autocommits while LOCK is held
SET SESSION session_track_transaction_info="CHARACTERISTICS";
LOCK TABLE t1 WRITE;
INSERT INTO t1 VALUES (3);
SELECT f1 FROM t1 WHERE f1 > 2;
f1
3
3
UNLOCK TABLES;
SET session_track_transaction_info="STATE";
DROP TABLE t1;
DROP TABLE t2;
########################################################################
#
# cleanup
#
SET SESSION session_track_system_variables= @old_track_list;
SET SESSION session_track_state_change=@old_track_enable;
SET SESSION session_track_transaction_info=@old_track_tx;