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
|
SET @org_slow_query_log= @@global.slow_query_log;
SET @org_log_output= @@global.log_output;
SET @org_log_slow_admin_statements= @@global.log_slow_admin_statements;
SET @@GLOBAL.slow_query_log=OFF;
SET @@GLOBAL.log_output='TABLE';
FLUSH SLOW LOGS;
SET @@GLOBAL.slow_query_log=ON;
SET @@GLOBAL.log_slow_admin_statements=ON;
SET @saved_dbug = @@debug_dbug;
SET SESSION debug_dbug="+d,simulate_slow_query";
CREATE PROCEDURE show_slow_log()
BEGIN
SELECT CONCAT('[slow] ', sql_text) AS sql_text
FROM mysql.slow_log
WHERE sql_text NOT LIKE '%debug_dbug%';
END
$$
#
# Expect all admin statements in the slow log (ON,DEFAULT)
#
SET @@SESSION.log_slow_admin_statements=ON;
SET log_slow_filter=DEFAULT;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE INDEX t1a ON t1 (a);
DROP INDEX t1a ON t1;
DROP TABLE t1;
CREATE TABLE t2 (a INT);
ALTER TABLE t2 RENAME t2;
RENAME TABLE t2 TO t3;
DROP TABLE t3;
CREATE TABLE t4 (a INT);
PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t4;
CREATE SEQUENCE s4;
ALTER SEQUENCE s4 MAXVALUE 100;
PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP SEQUENCE s4;
CALL show_slow_log();
sql_text
[slow] TRUNCATE TABLE mysql.slow_log
[slow] CREATE TABLE t1 (a INT)
[slow] CREATE INDEX t1a ON t1 (a)
[slow] DROP INDEX t1a ON t1
[slow] DROP TABLE t1
[slow] CREATE TABLE t2 (a INT)
[slow] ALTER TABLE t2 RENAME t2
[slow] RENAME TABLE t2 TO t3
[slow] DROP TABLE t3
[slow] CREATE TABLE t4 (a INT)
[slow] PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1'
[slow] ALTER TABLE t4 MODIFY a INT DEFAULT 1
[slow] DEALLOCATE PREPARE stmt
[slow] DROP TABLE t4
[slow] CREATE SEQUENCE s4
[slow] ALTER SEQUENCE s4 MAXVALUE 100
[slow] PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101'
[slow] ALTER SEQUENCE s4 MAXVALUE=101
[slow] DEALLOCATE PREPARE stmt
[slow] DROP SEQUENCE s4
#
# Expect all admin statements in the slow log (ON,admin)
#
SET @@SESSION.log_slow_admin_statements=ON;
SET log_slow_filter=admin;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE INDEX t1a ON t1 (a);
DROP INDEX t1a ON t1;
DROP TABLE t1;
CREATE TABLE t2 (a INT);
ALTER TABLE t2 RENAME t2;
RENAME TABLE t2 TO t3;
DROP TABLE t3;
CREATE TABLE t4 (a INT);
PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t4;
CREATE SEQUENCE s4;
ALTER SEQUENCE s4 MAXVALUE 100;
PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP SEQUENCE s4;
CALL show_slow_log();
sql_text
[slow] CREATE INDEX t1a ON t1 (a)
[slow] DROP INDEX t1a ON t1
[slow] ALTER TABLE t2 RENAME t2
[slow] RENAME TABLE t2 TO t3
[slow] ALTER TABLE t4 MODIFY a INT DEFAULT 1
[slow] ALTER SEQUENCE s4 MAXVALUE 100
[slow] ALTER SEQUENCE s4 MAXVALUE=101
#
# Expect none of admin DDL statements in the slow log (ON,filesort)
#
SET @@SESSION.log_slow_admin_statements=ON;
SET log_slow_filter=filesort;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE INDEX t1a ON t1 (a);
DROP INDEX t1a ON t1;
DROP TABLE t1;
CREATE TABLE t2 (a INT);
ALTER TABLE t2 RENAME t2;
RENAME TABLE t2 TO t3;
DROP TABLE t3;
CREATE TABLE t4 (a INT);
PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t4;
CREATE SEQUENCE s4;
ALTER SEQUENCE s4 MAXVALUE 100;
PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP SEQUENCE s4;
CALL show_slow_log();
sql_text
#
# Expect none of admin statements in the slow log (OFF,DEFAULT)
#
SET @@SESSION.log_slow_admin_statements=OFF;
SET log_slow_filter=DEFAULT;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE INDEX t1a ON t1 (a);
DROP INDEX t1a ON t1;
DROP TABLE t1;
CREATE TABLE t2 (a INT);
ALTER TABLE t2 RENAME t2;
RENAME TABLE t2 TO t3;
DROP TABLE t3;
CREATE TABLE t4 (a INT);
PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t4;
CREATE SEQUENCE s4;
ALTER SEQUENCE s4 MAXVALUE 100;
PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP SEQUENCE s4;
CALL show_slow_log();
sql_text
[slow] TRUNCATE TABLE mysql.slow_log
[slow] CREATE TABLE t1 (a INT)
[slow] DROP TABLE t1
[slow] CREATE TABLE t2 (a INT)
[slow] DROP TABLE t3
[slow] CREATE TABLE t4 (a INT)
[slow] PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1'
[slow] DEALLOCATE PREPARE stmt
[slow] DROP TABLE t4
[slow] CREATE SEQUENCE s4
[slow] PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101'
[slow] DEALLOCATE PREPARE stmt
[slow] DROP SEQUENCE s4
#
# Expect all admin statements in the slow log (GLOBAL OFF,LOCAL ON,DEFAULT)
# In the original implementation, this combination disabled slow log for admin commands.
# However, instead of this exception in GLOBAL vs LOCAL variable behaviour,
# we should make max_system_variables.log_slow_admin_statements=0
# prevent enabling globally suppressed logging by setting the session variable to ON.
#
SET @@GLOBAL.log_slow_admin_statements=OFF;
SET @@SESSION.log_slow_admin_statements=ON;
SET log_slow_filter=DEFAULT;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (a INT);
CREATE INDEX t1a ON t1 (a);
DROP INDEX t1a ON t1;
DROP TABLE t1;
CREATE TABLE t2 (a INT);
ALTER TABLE t2 RENAME t2;
RENAME TABLE t2 TO t3;
DROP TABLE t3;
CREATE TABLE t4 (a INT);
PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t4;
CREATE SEQUENCE s4;
ALTER SEQUENCE s4 MAXVALUE 100;
PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP SEQUENCE s4;
CALL show_slow_log();
sql_text
[slow] TRUNCATE TABLE mysql.slow_log
[slow] CREATE TABLE t1 (a INT)
[slow] CREATE INDEX t1a ON t1 (a)
[slow] DROP INDEX t1a ON t1
[slow] DROP TABLE t1
[slow] CREATE TABLE t2 (a INT)
[slow] ALTER TABLE t2 RENAME t2
[slow] RENAME TABLE t2 TO t3
[slow] DROP TABLE t3
[slow] CREATE TABLE t4 (a INT)
[slow] PREPARE stmt FROM 'ALTER TABLE t4 MODIFY a INT DEFAULT 1'
[slow] ALTER TABLE t4 MODIFY a INT DEFAULT 1
[slow] DEALLOCATE PREPARE stmt
[slow] DROP TABLE t4
[slow] CREATE SEQUENCE s4
[slow] ALTER SEQUENCE s4 MAXVALUE 100
[slow] PREPARE stmt FROM 'ALTER SEQUENCE s4 MAXVALUE=101'
[slow] ALTER SEQUENCE s4 MAXVALUE=101
[slow] DEALLOCATE PREPARE stmt
[slow] DROP SEQUENCE s4
#
# Start of 10.6 tests
#
#
# MDEV-32203 Raise notes when an index cannot be used on data type
# mismatch
#
CREATE TABLE t1 (a VARCHAR(10), KEY(a));
insert into t1 select seq from seq_0_to_31;
SET note_verbosity=all;
SET log_slow_verbosity=all;
SET global log_output='FILE';
set @org_slow_query_log_file=@@global.slow_query_log_file;
set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-1.log';
FLUSH SLOW LOGS;
SELECT * FROM t1 WHERE a=10;
a
10
Warnings:
Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int`
EXPLAIN SELECT * FROM t1 WHERE a=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index
Warnings:
Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int`
FOUND 2 /# Warnings/ in log_slow_debug-1.log
FOUND 1 /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-1.log
set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-2.log';
SET note_verbosity="explain";
FLUSH SLOW LOGS;
EXPLAIN SELECT * FROM t1 WHERE a=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index
Warnings:
Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int`
FOUND 1 /# Warnings/ in log_slow_debug-2.log
FOUND 1 /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-2.log
set global slow_query_log_file='MYSQLTEST_VARDIR/tmp/log_slow_debug-3.log';
SET log_slow_verbosity=replace(@@log_slow_verbosity, "warnings", "");
SET log_slow_verbosity=replace(@@log_slow_verbosity, "full", "");
SET note_verbosity=all;
FLUSH SLOW LOGS;
SELECT * FROM t1 WHERE a=10;
a
10
Warnings:
Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int`
EXPLAIN SELECT * FROM t1 WHERE a=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 32 Using where; Using index
Warnings:
Note 1105 Cannot use key `a` part[0] for lookup: `test`.`t1`.`a` of type `varchar` = "10" of type `int`
NOT FOUND /# Warnings/ in log_slow_debug-3.log
NOT FOUND /# Note.*Cannot use key.*varchar.*10.*int/ in log_slow_debug-3.log
set @@global.slow_query_log_file= @org_slow_query_log_file;
DROP TABLE t1;
#
# MDEV-30820: slow log Rows_examined out of range
#
CREATE TABLE `tab_MDEV_30820` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`A` int(11),
PRIMARY KEY(ID)
);
insert into tab_MDEV_30820 values (null, 0),(null, 0);
SET @old_slow_query_log= @@global.slow_query_log;
SET @old_log_output= @@global.log_output;
SET @old_long_query_time= @@long_query_time;
SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL log_output= "TABLE";
SET GLOBAL slow_query_log= ON;
SET SESSION long_query_time= 0;
SET GLOBAL debug_dbug="+d,debug_huge_number_of_examined_rows";
SELECT * FROM tab_MDEV_30820 ORDER BY 1;
ID A
1 0
2 0
SET GLOBAL debug_dbug=@old_dbug;
SET @@long_query_time= @old_long_query_time;
SET @@global.log_output= @old_log_output;
SET @@global.slow_query_log= @old_slow_query_log;
drop table tab_MDEV_30820;
#
# End of 10.4 test
#
#
# Clean up
#
SET SESSION debug_dbug=@saved_dbug;
TRUNCATE mysql.slow_log;
SET @@global.slow_query_log= @org_slow_query_log;
SET @@global.log_output= @org_log_output;
SET @@global.log_slow_admin_statements= @org_log_slow_admin_statements;
DROP PROCEDURE show_slow_log;
|