1
by brian
clean slate |
1 |
#
|
2 |
# Basic log tables test |
|
3 |
#
|
|
4 |
||
5 |
# check that CSV engine was compiled in |
|
6 |
--source include/have_csv.inc
|
|
7 |
||
8 |
--disable_ps_protocol
|
|
9 |
use mysql; |
|
10 |
||
11 |
#
|
|
12 |
# Check that log tables work and we can do basic selects. This also |
|
13 |
# tests truncate, which works in a special mode with the log tables |
|
14 |
#
|
|
15 |
||
16 |
truncate table general_log; |
|
17 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
18 |
select * from general_log; |
|
19 |
truncate table slow_log; |
|
20 |
--replace_column 1 TIMESTAMP 2 USER_HOST
|
|
21 |
select * from slow_log; |
|
22 |
||
23 |
#
|
|
24 |
# We want to check that a record newly written to a log table shows up for |
|
25 |
# the query: since log tables use concurrent insert machinery and log tables |
|
26 |
# are always locked by artificial THD, this feature requires additional |
|
27 |
# check in ha_tina::write_row. This simple test should prove that the |
|
28 |
# log table flag in the table handler is triggered and working. |
|
29 |
#
|
|
30 |
||
31 |
truncate table general_log; |
|
32 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
33 |
select * from general_log where argument like '%general_log%'; |
|
34 |
||
35 |
||
36 |
#
|
|
37 |
# Check some basic queries interfering with the log tables. |
|
38 |
# In our test we'll use a tbale with verbose comments to the short |
|
39 |
# command type names, used in the tables
|
|
40 |
#
|
|
41 |
||
42 |
create table join_test (verbose_comment varchar (80), command_type varchar(64));
|
|
43 |
||
44 |
insert into join_test values ("User performed a usual SQL query", "Query");
|
|
45 |
insert into join_test values ("New DB connection was registered", "Connect");
|
|
46 |
insert into join_test values ("Get the table info", "Field List");
|
|
47 |
||
48 |
--replace_column 2 USER_HOST
|
|
49 |
select verbose_comment, user_host, argument
|
|
50 |
from mysql.general_log join join_test
|
|
51 |
on (mysql.general_log.command_type = join_test.command_type);
|
|
52 |
||
53 |
drop table join_test;
|
|
54 |
||
55 |
#
|
|
56 |
# check that flush of the log table work fine
|
|
57 |
#
|
|
58 |
||
59 |
flush logs;
|
|
60 |
||
61 |
#
|
|
62 |
# check locking of the log tables
|
|
63 |
#
|
|
64 |
||
65 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
66 |
lock tables mysql.general_log WRITE;
|
|
67 |
||
68 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
69 |
lock tables mysql.slow_log WRITE;
|
|
70 |
||
71 |
#
|
|
72 |
# This attemts to get TL_READ_NO_INSERT lock, which is incompatible with
|
|
73 |
# TL_WRITE_CONCURRENT_INSERT. This should fail. We issue this error as log
|
|
74 |
# tables are always opened and locked by the logger.
|
|
75 |
#
|
|
76 |
||
77 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
78 |
lock tables mysql.general_log READ;
|
|
79 |
||
80 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
81 |
lock tables mysql.slow_log READ;
|
|
82 |
||
83 |
#
|
|
84 |
# This call should result in TL_READ lock on the log table.
|
|
85 |
# This is not ok and should fail.
|
|
86 |
#
|
|
87 |
||
88 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
89 |
lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL;
|
|
90 |
||
91 |
# Misc locking tests
|
|
92 |
||
93 |
show create table mysql.general_log;
|
|
94 |
show fields from mysql.general_log;
|
|
95 |
||
96 |
show create table mysql.slow_log;
|
|
97 |
show fields from mysql.slow_log;
|
|
98 |
||
99 |
#
|
|
100 |
# check that FLUSH LOGS does not flush the log tables
|
|
101 |
#
|
|
102 |
||
103 |
flush logs;
|
|
104 |
flush tables;
|
|
105 |
||
106 |
SET GLOBAL GENERAL_LOG=ON;
|
|
107 |
SET GLOBAL SLOW_QUERY_LOG=ON;
|
|
108 |
||
109 |
show open tables;
|
|
110 |
flush logs;
|
|
111 |
show open tables;
|
|
112 |
||
113 |
#
|
|
114 |
# check that FLUSH TABLES does flush the log tables
|
|
115 |
#
|
|
116 |
||
117 |
flush tables;
|
|
118 |
# Since the flush is logged, mysql.general_log will be in the cache
|
|
119 |
show open tables;
|
|
120 |
||
121 |
SET GLOBAL GENERAL_LOG=OFF;
|
|
122 |
SET GLOBAL SLOW_QUERY_LOG=OFF;
|
|
123 |
||
124 |
flush tables;
|
|
125 |
# Here the table cache is empty
|
|
126 |
show open tables;
|
|
127 |
||
128 |
SET GLOBAL GENERAL_LOG=ON;
|
|
129 |
SET GLOBAL SLOW_QUERY_LOG=ON;
|
|
130 |
||
131 |
#
|
|
132 |
# Bug#23924 general_log truncates queries with character set introducers.
|
|
133 |
#
|
|
134 |
truncate table mysql.general_log;
|
|
135 |
set names binary;
|
|
136 |
select _koi8r'ÔÅÓÔ' as test; |
|
137 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
138 |
select * from mysql.general_log;
|
|
139 |
set names utf8;
|
|
140 |
||
141 |
#
|
|
142 |
# Bug #16905 Log tables: unicode statements are logged incorrectly
|
|
143 |
#
|
|
144 |
||
145 |
truncate table mysql.general_log;
|
|
146 |
set names utf8;
|
|
147 |
create table bug16905 (s char(15) character set utf8 default 'пÑÑÑП'); |
|
148 |
insert into bug16905 values ('МПвПе'); |
|
149 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
150 |
select * from mysql.general_log;
|
|
151 |
drop table bug16905;
|
|
152 |
||
153 |
#
|
|
154 |
# Bug #17600: Invalid data logged into mysql.slow_log
|
|
155 |
#
|
|
156 |
||
157 |
truncate table mysql.slow_log;
|
|
158 |
set session long_query_time=1;
|
|
159 |
select sleep(2);
|
|
160 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
|
|
161 |
select * from mysql.slow_log;
|
|
162 |
||
163 |
#
|
|
164 |
# Bug #18559 log tables cannot change engine, and gets deadlocked when
|
|
165 |
# dropping w/ log on
|
|
166 |
#
|
|
167 |
||
168 |
# check that appropriate error messages are given when one attempts to alter
|
|
169 |
# or drop a log tables, while corresponding logs are enabled
|
|
170 |
--error ER_BAD_LOG_STATEMENT
|
|
171 |
alter table mysql.general_log engine=myisam;
|
|
172 |
--error ER_BAD_LOG_STATEMENT
|
|
173 |
alter table mysql.slow_log engine=myisam;
|
|
174 |
||
175 |
--error ER_BAD_LOG_STATEMENT
|
|
176 |
drop table mysql.general_log;
|
|
177 |
--error ER_BAD_LOG_STATEMENT
|
|
178 |
drop table mysql.slow_log;
|
|
179 |
||
180 |
# check that one can alter log tables to MyISAM
|
|
181 |
set global general_log='OFF'; |
|
182 |
||
183 |
# cannot convert another log table
|
|
184 |
--error ER_BAD_LOG_STATEMENT
|
|
185 |
alter table mysql.slow_log engine=myisam;
|
|
186 |
||
187 |
# alter both tables
|
|
188 |
set global slow_query_log='OFF'; |
|
189 |
# check that both tables use CSV engine
|
|
190 |
show create table mysql.general_log;
|
|
191 |
show create table mysql.slow_log;
|
|
192 |
||
193 |
alter table mysql.general_log engine=myisam;
|
|
194 |
alter table mysql.slow_log engine=myisam;
|
|
195 |
||
196 |
# check that the tables were converted
|
|
197 |
show create table mysql.general_log;
|
|
198 |
show create table mysql.slow_log;
|
|
199 |
||
200 |
# enable log tables and chek that new tables indeed work
|
|
201 |
set global general_log='ON'; |
|
202 |
set global slow_query_log='ON'; |
|
203 |
||
204 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
205 |
select * from mysql.general_log;
|
|
206 |
||
207 |
# check that flush of myisam-based log tables work fine
|
|
208 |
flush logs;
|
|
209 |
||
210 |
# check locking of myisam-based log tables
|
|
211 |
||
212 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
213 |
lock tables mysql.general_log WRITE;
|
|
214 |
||
215 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
216 |
lock tables mysql.slow_log WRITE;
|
|
217 |
||
218 |
#
|
|
219 |
# This attemts to get TL_READ_NO_INSERT lock, which is incompatible with
|
|
220 |
# TL_WRITE_CONCURRENT_INSERT. This should fail. We issue this error as log
|
|
221 |
# tables are always opened and locked by the logger.
|
|
222 |
#
|
|
223 |
||
224 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
225 |
lock tables mysql.general_log READ;
|
|
226 |
||
227 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
228 |
lock tables mysql.slow_log READ;
|
|
229 |
||
230 |
# check that we can drop them
|
|
231 |
set global general_log='OFF'; |
|
232 |
set global slow_query_log='OFF'; |
|
233 |
||
234 |
# check that alter table doesn't work for other engines |
|
235 |
set @save_storage_engine= @@session.storage_engine; |
|
236 |
set storage_engine= MEMORY; |
|
237 |
--error ER_UNSUPORTED_LOG_ENGINE
|
|
238 |
alter table mysql.slow_log engine=ndb; |
|
239 |
--error ER_UNSUPORTED_LOG_ENGINE
|
|
240 |
alter table mysql.slow_log engine=innodb; |
|
241 |
--error ER_UNSUPORTED_LOG_ENGINE
|
|
242 |
alter table mysql.slow_log engine=archive; |
|
243 |
--error ER_UNSUPORTED_LOG_ENGINE
|
|
244 |
alter table mysql.slow_log engine=blackhole; |
|
245 |
set storage_engine= @save_storage_engine; |
|
246 |
||
247 |
drop table mysql.slow_log; |
|
248 |
drop table mysql.general_log; |
|
249 |
||
250 |
# check that table share cleanup is performed correctly (double drop) |
|
251 |
||
252 |
--error ER_BAD_TABLE_ERROR
|
|
253 |
drop table mysql.general_log; |
|
254 |
--error ER_BAD_TABLE_ERROR
|
|
255 |
drop table mysql.slow_log; |
|
256 |
||
257 |
# recreate tables and enable logs |
|
258 |
||
259 |
use mysql; |
|
260 |
||
261 |
CREATE TABLE `general_log` ( |
|
262 |
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP |
|
263 |
ON UPDATE CURRENT_TIMESTAMP, |
|
264 |
`user_host` mediumtext NOT NULL, |
|
265 |
`thread_id` int(11) NOT NULL, |
|
266 |
`server_id` int(11) NOT NULL, |
|
267 |
`command_type` varchar(64) NOT NULL, |
|
268 |
`argument` mediumtext NOT NULL |
|
269 |
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'; |
|
270 |
||
271 |
CREATE TABLE `slow_log` ( |
|
272 |
`start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP |
|
273 |
ON UPDATE CURRENT_TIMESTAMP, |
|
274 |
`user_host` mediumtext NOT NULL, |
|
275 |
`query_time` time NOT NULL, |
|
276 |
`lock_time` time NOT NULL, |
|
277 |
`rows_sent` int(11) NOT NULL, |
|
278 |
`rows_examined` int(11) NOT NULL, |
|
279 |
`db` varchar(512) NOT NULL, |
|
280 |
`last_insert_id` int(11) NOT NULL, |
|
281 |
`insert_id` int(11) NOT NULL, |
|
282 |
`server_id` int(11) NOT NULL, |
|
283 |
`sql_text` mediumtext NOT NULL |
|
284 |
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'; |
|
285 |
||
286 |
set global general_log='ON'; |
|
287 |
set global slow_query_log='ON'; |
|
288 |
use test; |
|
289 |
||
290 |
#
|
|
291 |
# Bug #20139 Infinite loop after "FLUSH" and "LOCK tabX, general_log" |
|
292 |
#
|
|
293 |
||
294 |
flush tables with read lock; |
|
295 |
unlock tables; |
|
296 |
use mysql; |
|
297 |
--error ER_CANT_LOCK_LOG_TABLE
|
|
298 |
lock tables general_log read local, help_category read local; |
|
299 |
unlock tables; |
|
300 |
||
301 |
#
|
|
302 |
# Bug #17544 Cannot do atomic log rotate and |
|
303 |
# Bug #21785 Server crashes after rename of the log table |
|
304 |
#
|
|
305 |
||
306 |
--disable_warnings
|
|
307 |
drop table if exists mysql.renamed_general_log; |
|
308 |
drop table if exists mysql.renamed_slow_log; |
|
309 |
drop table if exists mysql.general_log_new; |
|
310 |
drop table if exists mysql.slow_log_new; |
|
311 |
--enable_warnings
|
|
312 |
||
313 |
use mysql; |
|
314 |
# Should result in error |
|
315 |
--error ER_CANT_RENAME_LOG_TABLE
|
|
316 |
RENAME TABLE general_log TO renamed_general_log; |
|
317 |
--error ER_CANT_RENAME_LOG_TABLE
|
|
318 |
RENAME TABLE slow_log TO renamed_slow_log; |
|
319 |
||
320 |
#check rotate logs |
|
321 |
truncate table general_log; |
|
322 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
323 |
select * from general_log; |
|
324 |
||
325 |
truncate table slow_log; |
|
326 |
--replace_column 1 TIMESTAMP 2 USER_HOST
|
|
327 |
select * from slow_log; |
|
328 |
||
329 |
create table general_log_new like general_log; |
|
330 |
rename table general_log TO renamed_general_log, general_log_new TO general_log; |
|
331 |
||
332 |
create table slow_log_new like slow_log; |
|
333 |
rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log; |
|
334 |
||
335 |
# check that rename checks more then first table in the list |
|
336 |
--error ER_CANT_RENAME_LOG_TABLE
|
|
337 |
rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log; |
|
338 |
||
339 |
# now check the content of tables |
|
340 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
341 |
select * from general_log; |
|
342 |
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
|
|
343 |
select * from renamed_general_log; |
|
344 |
||
345 |
# the content of the slow log is empty, but we will try a select anyway |
|
346 |
--replace_column 1 TIMESTAMP 2 USER_HOST
|
|
347 |
select * from slow_log; |
|
348 |
--replace_column 1 TIMESTAMP 2 USER_HOST
|
|
349 |
select * from renamed_slow_log; |
|
350 |
||
351 |
# check that we can do whatever we want with disabled log |
|
352 |
set global general_log='OFF'; |
|
353 |
RENAME TABLE general_log TO general_log2; |
|
354 |
||
355 |
set global slow_query_log='OFF'; |
|
356 |
RENAME TABLE slow_log TO slow_log2; |
|
357 |
||
358 |
# this should fail |
|
359 |
--error ER_NO_SUCH_TABLE
|
|
360 |
set global general_log='ON'; |
|
361 |
--error ER_NO_SUCH_TABLE
|
|
362 |
set global slow_query_log='ON'; |
|
363 |
||
364 |
RENAME TABLE general_log2 TO general_log; |
|
365 |
RENAME TABLE slow_log2 TO slow_log; |
|
366 |
||
367 |
# this should work |
|
368 |
set global general_log='ON'; |
|
369 |
set global slow_query_log='ON'; |
|
370 |
# now check flush logs |
|
371 |
flush logs; |
|
372 |
flush logs; |
|
373 |
drop table renamed_general_log, renamed_slow_log; |
|
374 |
use test; |
|
375 |
||
376 |
#
|
|
377 |
# Bug#27858 (Failing to log to a log table doesn't log anything to error log) |
|
378 |
#
|
|
379 |
# This test works as expected, it's a negative test. |
|
380 |
# The message "[ERROR] Failed to write to mysql.general_log" |
|
381 |
# is printed to master.err when writing to the table mysql.general_log |
|
382 |
# failed. |
|
383 |
# However, this message is picked up by mysql-test-run.pl, |
|
384 |
# and reported as a test failure, which is a false negative. |
|
385 |
# There is no current way to *selectively* filter out these expected error conditions |
|
386 |
# (see mysql-test/lib/mtr_report.pl, mtr_report_stats()). |
|
387 |
# Instead of filtering all occurences of "Failed to write to |
|
388 |
# mysql.general_log", which could hide bugs when the error is not expected, |
|
389 |
# this test case is commented instead. |
|
390 |
# TODO: improve filtering of expected errors in master.err in |
|
391 |
# mysql-test-run.pl (based on the test name ?), and uncomment this test. |
|
392 |
||
393 |
# --disable_warnings |
|
394 |
# drop table if exists mysql.bad_general_log; |
|
395 |
# drop table if exists mysql.bad_slow_log; |
|
396 |
# drop table if exists mysql.general_log_hide; |
|
397 |
# drop table if exists mysql.slow_log_hide; |
|
398 |
# --enable_warnings |
|
399 |
#
|
|
400 |
# create table mysql.bad_general_log (a int) engine= CSV; |
|
401 |
# create table mysql.bad_slow_log (a int) engine= CSV; |
|
402 |
#
|
|
403 |
# # Rename does not perform checks on the table structure, |
|
404 |
# # exploiting this to force a failure to log |
|
405 |
# rename table mysql.general_log to mysql.general_log_hide, mysql.bad_general_log TO mysql.general_log; |
|
406 |
# rename table mysql.slow_log to mysql.slow_log_hide, mysql.bad_slow_log TO mysql.slow_log; |
|
407 |
#
|
|
408 |
# # The following message should be printed in master.log: |
|
409 |
# # [ERROR] Failed to write to mysql.general_log |
|
410 |
# # TODO: See how verifying this could be automated |
|
411 |
#
|
|
412 |
# flush tables; |
|
413 |
# select "logging this should fail"; |
|
414 |
#
|
|
415 |
# # Restore the log tables |
|
416 |
#
|
|
417 |
# rename table mysql.general_log to mysql.bad_general_log, mysql.general_log_hide TO mysql.general_log; |
|
418 |
# rename table mysql.slow_log to mysql.bad_slow_log, mysql.slow_log_hide TO mysql.slow_log; |
|
419 |
#
|
|
420 |
# flush tables; |
|
421 |
#
|
|
422 |
# drop table mysql.bad_general_log; |
|
423 |
# drop table mysql.bad_slow_log; |
|
424 |
||
425 |
#
|
|
426 |
# Bug #21966 Strange warnings on repair of the log tables |
|
427 |
#
|
|
428 |
||
429 |
use mysql; |
|
430 |
# check that no warning occurs on repair of the log tables |
|
431 |
repair table general_log; |
|
432 |
repair table slow_log; |
|
433 |
# check that no warning occurs on "create like" for the log tables |
|
434 |
create table general_log_new like general_log; |
|
435 |
create table slow_log_new like slow_log; |
|
436 |
show tables like "%log%"; |
|
437 |
drop table slow_log_new, general_log_new; |
|
438 |
use test; |
|
439 |
||
440 |
#
|
|
441 |
# Bug#27857 (Log tables supplies the wrong value for generating |
|
442 |
# AUTO_INCREMENT numbers) |
|
443 |
#
|
|
444 |
||
445 |
SET GLOBAL LOG_OUTPUT = 'TABLE'; |
|
446 |
||
447 |
## test the general log |
|
448 |
||
449 |
SET GLOBAL general_log = 0; |
|
450 |
FLUSH LOGS; |
|
451 |
||
452 |
TRUNCATE TABLE mysql.general_log; |
|
453 |
ALTER TABLE mysql.general_log ENGINE = MyISAM; |
|
454 |
ALTER TABLE mysql.general_log |
|
455 |
ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY; |
|
456 |
||
457 |
SET GLOBAL general_log = 1; |
|
458 |
FLUSH LOGS; |
|
459 |
||
460 |
--replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
|
|
461 |
SELECT * FROM mysql.general_log; |
|
462 |
--replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
|
|
463 |
SELECT * FROM mysql.general_log; |
|
464 |
SELECT "My own query 1"; |
|
465 |
SELECT "My own query 2"; |
|
466 |
--replace_column 1 EVENT_TIME 2 USER_HOST 3 THREAD_ID 4 SERVER_ID
|
|
467 |
SELECT * FROM mysql.general_log; |
|
468 |
||
469 |
SET GLOBAL general_log = 0; |
|
470 |
FLUSH LOGS; |
|
471 |
||
472 |
ALTER TABLE mysql.general_log DROP COLUMN seq; |
|
473 |
ALTER TABLE mysql.general_log ENGINE = CSV; |
|
474 |
||
475 |
## test the slow query log |
|
476 |
||
477 |
SET @old_long_query_time:=@@long_query_time; |
|
478 |
||
479 |
SET GLOBAL slow_query_log = 0; |
|
480 |
FLUSH LOGS; |
|
481 |
||
482 |
TRUNCATE TABLE mysql.slow_log; |
|
483 |
ALTER TABLE mysql.slow_log ENGINE = MyISAM; |
|
484 |
||
485 |
ALTER TABLE mysql.slow_log |
|
486 |
ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY; |
|
487 |
||
488 |
SET SESSION long_query_time = 1; |
|
489 |
SET GLOBAL slow_query_log = 1; |
|
490 |
FLUSH LOGS; |
|
491 |
||
492 |
## FLUSH LOGS above might be slow, so the following is |
|
493 |
## logged as either seq 1-4 or seq 2-5 |
|
494 |
SELECT "My own slow query", sleep(2); |
|
495 |
SELECT "My own slow query", sleep(2); |
|
496 |
SELECT "My own slow query", sleep(2); |
|
497 |
SELECT "My own slow query", sleep(2); |
|
498 |
||
499 |
## So we look for seq 2-4 |
|
500 |
--replace_column 1 START_TIME 2 USER_HOST 3 QUERY_TIME
|
|
501 |
SELECT * FROM mysql.slow_log WHERE seq >= 2 LIMIT 3; |
|
502 |
||
503 |
SET GLOBAL slow_query_log = 0; |
|
504 |
SET SESSION long_query_time =@old_long_query_time; |
|
505 |
FLUSH LOGS; |
|
506 |
||
507 |
ALTER TABLE mysql.slow_log DROP COLUMN seq; |
|
508 |
ALTER TABLE mysql.slow_log ENGINE = CSV; |
|
509 |
||
510 |
#
|
|
511 |
# Bug#25422 (Hang with log tables) |
|
512 |
#
|
|
513 |
||
514 |
--disable_warnings
|
|
515 |
drop procedure if exists proc25422_truncate_slow; |
|
516 |
drop procedure if exists proc25422_truncate_general; |
|
517 |
drop procedure if exists proc25422_alter_slow; |
|
518 |
drop procedure if exists proc25422_alter_general; |
|
519 |
--enable_warnings
|
|
520 |
||
521 |
delimiter //; |
|
522 |
||
523 |
use test// |
|
524 |
create procedure proc25422_truncate_slow (loops int) |
|
525 |
begin
|
|
526 |
declare v1 int default 0; |
|
527 |
declare continue handler for sqlexception /* errors from truncate */ |
|
528 |
begin end; |
|
529 |
while v1 < loops do |
|
530 |
truncate mysql.slow_log; |
|
531 |
set v1 = v1 + 1; |
|
532 |
end while; |
|
533 |
end// |
|
534 |
||
535 |
create procedure proc25422_truncate_general (loops int) |
|
536 |
begin
|
|
537 |
declare v1 int default 0; |
|
538 |
declare continue handler for sqlexception /* errors from truncate */ |
|
539 |
begin end; |
|
540 |
while v1 < loops do |
|
541 |
truncate mysql.general_log; |
|
542 |
set v1 = v1 + 1; |
|
543 |
end while; |
|
544 |
end// |
|
545 |
||
546 |
create procedure proc25422_alter_slow (loops int) |
|
547 |
begin
|
|
548 |
declare v1 int default 0; |
|
549 |
declare ER_BAD_LOG_STATEMENT condition for 1575; |
|
550 |
declare continue handler for ER_BAD_LOG_STATEMENT begin end; |
|
551 |
||
552 |
while v1 < loops do |
|
553 |
set @old_log_state = @@global.slow_query_log; |
|
554 |
set global slow_query_log = 'OFF'; |
|
555 |
alter table mysql.slow_log engine = CSV; |
|
556 |
set global slow_query_log = @old_log_state; |
|
557 |
set v1 = v1 + 1; |
|
558 |
end while; |
|
559 |
end// |
|
560 |
||
561 |
create procedure proc25422_alter_general (loops int) |
|
562 |
begin
|
|
563 |
declare v1 int default 0; |
|
564 |
declare ER_BAD_LOG_STATEMENT condition for 1575; |
|
565 |
declare continue handler for ER_BAD_LOG_STATEMENT begin end; |
|
566 |
||
567 |
while v1 < loops do |
|
568 |
set @old_log_state = @@global.general_log; |
|
569 |
set global general_log = 'OFF'; |
|
570 |
alter table mysql.general_log engine = CSV; |
|
571 |
set global general_log = @old_log_state; |
|
572 |
set v1 = v1 + 1; |
|
573 |
end while; |
|
574 |
end// |
|
575 |
||
576 |
delimiter ;// |
|
577 |
||
578 |
set @iterations=100; |
|
579 |
||
580 |
--echo "Serial test (proc25422_truncate_slow)"
|
|
581 |
call proc25422_truncate_slow(@iterations); |
|
582 |
--echo "Serial test (proc25422_truncate_general)"
|
|
583 |
call proc25422_truncate_general(@iterations); |
|
584 |
--echo "Serial test (proc25422_alter_slow)"
|
|
585 |
call proc25422_alter_slow(@iterations); |
|
586 |
--echo "Serial test (proc25422_alter_general)"
|
|
587 |
call proc25422_alter_general(@iterations); |
|
588 |
||
589 |
--echo "Parallel test"
|
|
590 |
||
591 |
# ER_BAD_LOG_STATEMENT errors will occur, |
|
592 |
# since concurrent threads do SET GLOBAL general_log= ... |
|
593 |
# This is silenced by handlers and will not affect the test |
|
594 |
||
595 |
connect (addconroot1, localhost, root,,); |
|
596 |
connect (addconroot2, localhost, root,,); |
|
597 |
connect (addconroot3, localhost, root,,); |
|
598 |
connect (addconroot4, localhost, root,,); |
|
599 |
connect (addconroot5, localhost, root,,); |
|
600 |
connect (addconroot6, localhost, root,,); |
|
601 |
connect (addconroot7, localhost, root,,); |
|
602 |
connect (addconroot8, localhost, root,,); |
|
603 |
||
604 |
connection addconroot1; |
|
605 |
send call proc25422_truncate_slow(@iterations); |
|
606 |
connection addconroot2; |
|
607 |
send call proc25422_truncate_slow(@iterations); |
|
608 |
||
609 |
connection addconroot3; |
|
610 |
send call proc25422_truncate_general(@iterations); |
|
611 |
connection addconroot4; |
|
612 |
send call proc25422_truncate_general(@iterations); |
|
613 |
||
614 |
connection addconroot5; |
|
615 |
send call proc25422_alter_slow(@iterations); |
|
616 |
connection addconroot6; |
|
617 |
send call proc25422_alter_slow(@iterations); |
|
618 |
||
619 |
connection addconroot7; |
|
620 |
send call proc25422_alter_general(@iterations); |
|
621 |
connection addconroot8; |
|
622 |
send call proc25422_alter_general(@iterations); |
|
623 |
||
624 |
connection addconroot1; |
|
625 |
reap; |
|
626 |
connection addconroot2; |
|
627 |
reap; |
|
628 |
connection addconroot3; |
|
629 |
reap; |
|
630 |
connection addconroot4; |
|
631 |
reap; |
|
632 |
connection addconroot5; |
|
633 |
reap; |
|
634 |
connection addconroot6; |
|
635 |
reap; |
|
636 |
connection addconroot7; |
|
637 |
reap; |
|
638 |
connection addconroot8; |
|
639 |
reap; |
|
640 |
||
641 |
connection default; |
|
642 |
||
643 |
disconnect addconroot1; |
|
644 |
disconnect addconroot2; |
|
645 |
disconnect addconroot3; |
|
646 |
disconnect addconroot4; |
|
647 |
disconnect addconroot5; |
|
648 |
disconnect addconroot6; |
|
649 |
disconnect addconroot7; |
|
650 |
disconnect addconroot8; |
|
651 |
||
652 |
drop procedure proc25422_truncate_slow; |
|
653 |
drop procedure proc25422_truncate_general; |
|
654 |
drop procedure proc25422_alter_slow; |
|
655 |
drop procedure proc25422_alter_general; |
|
656 |
||
657 |
--enable_ps_protocol
|
|
658 |
||
659 |
||
660 |
#
|
|
661 |
# Bug#23044 (Warnings on flush of a log table) |
|
662 |
#
|
|
663 |
||
664 |
FLUSH TABLE mysql.general_log; |
|
665 |
show warnings; |
|
666 |
||
667 |
FLUSH TABLE mysql.slow_log; |
|
668 |
show warnings; |
|
669 |
||
670 |
#
|
|
671 |
# Bug#17876 (Truncating mysql.slow_log in a SP after using cursor locks the |
|
672 |
# thread) |
|
673 |
#
|
|
674 |
||
675 |
--disable_warnings
|
|
676 |
DROP TABLE IF EXISTS `db_17876.slow_log_data`; |
|
677 |
DROP TABLE IF EXISTS `db_17876.general_log_data`; |
|
678 |
DROP PROCEDURE IF EXISTS `db_17876.archiveSlowLog`; |
|
679 |
DROP PROCEDURE IF EXISTS `db_17876.archiveGeneralLog`; |
|
680 |
DROP DATABASE IF EXISTS `db_17876`; |
|
681 |
--enable_warnings
|
|
682 |
||
683 |
CREATE DATABASE db_17876; |
|
684 |
||
685 |
CREATE TABLE `db_17876.slow_log_data` ( |
|
686 |
`start_time` timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, |
|
687 |
`user_host` mediumtext , |
|
688 |
`query_time` time , |
|
689 |
`lock_time` time , |
|
690 |
`rows_sent` int(11) , |
|
691 |
`rows_examined` int(11) , |
|
692 |
`db` varchar(512) default NULL, |
|
693 |
`last_insert_id` int(11) default NULL, |
|
694 |
`insert_id` int(11) default NULL, |
|
695 |
`server_id` int(11) default NULL, |
|
696 |
`sql_text` mediumtext |
|
697 |
);
|
|
698 |
||
699 |
CREATE TABLE `db_17876.general_log_data` ( |
|
700 |
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
|
701 |
`user_host` mediumtext, |
|
702 |
`thread_id` int(11) DEFAULT NULL, |
|
703 |
`server_id` int(11) DEFAULT NULL, |
|
704 |
`command_type` varchar(64) DEFAULT NULL, |
|
705 |
`argument` mediumtext |
|
706 |
);
|
|
707 |
||
708 |
DELIMITER //; |
|
709 |
||
710 |
CREATE procedure `db_17876.archiveSlowLog`() |
|
711 |
BEGIN
|
|
712 |
DECLARE start_time, query_time, lock_time CHAR(20); |
|
713 |
DECLARE user_host MEDIUMTEXT; |
|
714 |
DECLARE rows_set, rows_examined, last_insert_id, insert_id, server_id INT; |
|
715 |
DECLARE dbname MEDIUMTEXT; |
|
716 |
DECLARE sql_text BLOB; |
|
717 |
DECLARE done INT DEFAULT 0; |
|
718 |
DECLARE ER_SP_FETCH_NO_DATA CONDITION for 1329; |
|
719 |
||
720 |
DECLARE cur1 CURSOR FOR SELECT * FROM mysql.slow_log; |
|
721 |
||
722 |
OPEN cur1; |
|
723 |
||
724 |
REPEAT
|
|
725 |
BEGIN
|
|
726 |
BEGIN
|
|
727 |
DECLARE CONTINUE HANDLER FOR ER_SP_FETCH_NO_DATA SET done = 1; |
|
728 |
||
729 |
FETCH cur1 INTO |
|
730 |
start_time, user_host, query_time, lock_time, |
|
731 |
rows_set, rows_examined, dbname, last_insert_id, |
|
732 |
insert_id, server_id, sql_text; |
|
733 |
END; |
|
734 |
||
735 |
IF NOT done THEN |
|
736 |
BEGIN
|
|
737 |
INSERT INTO |
|
738 |
`db_17876.slow_log_data` |
|
739 |
VALUES(start_time, user_host, query_time, lock_time, rows_set, rows_examined, |
|
740 |
dbname, last_insert_id, insert_id, server_id, sql_text); |
|
741 |
END; |
|
742 |
END IF; |
|
743 |
END; |
|
744 |
UNTIL done END REPEAT; |
|
745 |
||
746 |
CLOSE cur1; |
|
747 |
TRUNCATE mysql.slow_log; |
|
748 |
END // |
|
749 |
||
750 |
CREATE procedure `db_17876.archiveGeneralLog`() |
|
751 |
BEGIN
|
|
752 |
DECLARE event_time CHAR(20); |
|
753 |
DECLARE user_host, argument MEDIUMTEXT; |
|
754 |
DECLARE thread_id, server_id INT; |
|
755 |
DECLARE sql_text BLOB; |
|
756 |
DECLARE done INT DEFAULT 0; |
|
757 |
DECLARE command_type VARCHAR(64); |
|
758 |
DECLARE ER_SP_FETCH_NO_DATA CONDITION for 1329; |
|
759 |
||
760 |
DECLARE cur1 CURSOR FOR SELECT * FROM mysql.general_log; |
|
761 |
||
762 |
OPEN cur1; |
|
763 |
||
764 |
REPEAT
|
|
765 |
BEGIN
|
|
766 |
BEGIN
|
|
767 |
DECLARE CONTINUE HANDLER FOR ER_SP_FETCH_NO_DATA SET done = 1; |
|
768 |
||
769 |
FETCH cur1 INTO |
|
770 |
event_time, user_host, thread_id, server_id, |
|
771 |
command_type, argument; |
|
772 |
END; |
|
773 |
||
774 |
IF NOT done THEN |
|
775 |
BEGIN
|
|
776 |
INSERT INTO |
|
777 |
`db_17876.general_log_data` |
|
778 |
VALUES(event_time, user_host, thread_id, server_id, |
|
779 |
command_type, argument); |
|
780 |
END; |
|
781 |
END IF; |
|
782 |
END; |
|
783 |
UNTIL done END REPEAT; |
|
784 |
||
785 |
CLOSE cur1; |
|
786 |
TRUNCATE mysql.general_log; |
|
787 |
END // |
|
788 |
||
789 |
DELIMITER ;// |
|
790 |
||
791 |
SET @old_general_log_state = @@global.general_log; |
|
792 |
SET @old_slow_log_state = @@global.slow_query_log; |
|
793 |
||
794 |
SET GLOBAL general_log = ON; |
|
795 |
SET GLOBAL slow_query_log = ON; |
|
796 |
||
797 |
select "put something into general_log"; |
|
798 |
select "... and something more ..."; |
|
799 |
||
800 |
call `db_17876.archiveSlowLog`(); |
|
801 |
call `db_17876.archiveGeneralLog`(); |
|
802 |
||
803 |
SET GLOBAL general_log = OFF; |
|
804 |
SET GLOBAL slow_query_log = OFF; |
|
805 |
||
806 |
call `db_17876.archiveSlowLog`(); |
|
807 |
call `db_17876.archiveGeneralLog`(); |
|
808 |
||
809 |
DROP TABLE `db_17876.slow_log_data`; |
|
810 |
DROP TABLE `db_17876.general_log_data`; |
|
811 |
DROP PROCEDURE IF EXISTS `db_17876.archiveSlowLog`; |
|
812 |
DROP PROCEDURE IF EXISTS `db_17876.archiveGeneralLog`; |
|
813 |
DROP DATABASE IF EXISTS `db_17876`; |
|
814 |
||
815 |
SET GLOBAL general_log = @old_general_log_state; |
|
816 |
SET GLOBAL slow_query_log = @old_slow_log_state; |
|
817 |
||
818 |
#
|
|
819 |
# Bug#21557 entries in the general query log truncated at 1000 characters. |
|
820 |
#
|
|
821 |
||
822 |
select CONNECTION_ID() into @thread_id; |
|
823 |
truncate table mysql.general_log; |
|
824 |
set @old_general_log_state = @@global.general_log; |
|
825 |
set global general_log = on; |
|
826 |
--disable_result_log
|
|
827 |
set @lparam = "000 001 002 003 004 005 006 007 008 009" |
|
828 |
"010 011 012 013 014 015 016 017 018 019"
|
|
829 |
"020 021 022 023 024 025 026 027 028 029"
|
|
830 |
"030 031 032 033 034 035 036 037 038 039"
|
|
831 |
"040 041 042 043 044 045 046 047 048 049"
|
|
832 |
"050 051 052 053 054 055 056 057 058 059"
|
|
833 |
"060 061 062 063 064 065 066 067 068 069"
|
|
834 |
"070 071 072 073 074 075 076 077 078 079"
|
|
835 |
"080 081 082 083 084 085 086 087 088 089"
|
|
836 |
"090 091 092 093 094 095 096 097 098 099"
|
|
837 |
"100 101 102 103 104 105 106 107 108 109"
|
|
838 |
"110 111 112 113 114 115 116 117 118 119"
|
|
839 |
"120 121 122 123 124 125 126 127 128 129"
|
|
840 |
"130 131 132 133 134 135 136 137 138 139"
|
|
841 |
"140 141 142 143 144 145 146 147 148 149"
|
|
842 |
"150 151 152 153 154 155 156 157 158 159"
|
|
843 |
"160 161 162 163 164 165 166 167 168 169"
|
|
844 |
"170 171 172 173 174 175 176 177 178 179"
|
|
845 |
"180 181 182 183 184 185 186 187 188 189"
|
|
846 |
"190 191 192 193 194 195 196 197 198 199"
|
|
847 |
"200 201 202 203 204 205 206 207 208 209"
|
|
848 |
"210 211 212 213 214 215 216 217 218 219"
|
|
849 |
"220 221 222 223 224 225 226 227 228 229"
|
|
850 |
"230 231 232 233 234 235 236 237 238 239"
|
|
851 |
"240 241 242 243 244 245 246 247 248 249"
|
|
852 |
"250 251 252 253 254 255 256 257 258 259"
|
|
853 |
"260 261 262 263 264 265 266 267 268 269"
|
|
854 |
"270 271 272 273 274 275 276 277 278 279"
|
|
855 |
"280 281 282 283 284 285 286 287 288 289"
|
|
856 |
"290 291 292 293 294 295 296 297 298 299"
|
|
857 |
"300 301 302 303 304 305 306 307 308 309"
|
|
858 |
"310 311 312 313 314 315 316 317 318 319"
|
|
859 |
"320 321 322 323 324 325 326 327 328 329"
|
|
860 |
"330 331 332 333 334 335 336 337 338 339"
|
|
861 |
"340 341 342 343 344 345 346 347 348 349"
|
|
862 |
"350 351 352 353 354 355 356 357 358 359"
|
|
863 |
"360 361 362 363 364 365 366 367 368 369"
|
|
864 |
"370 371 372 373 374 375 376 377 378 379"
|
|
865 |
"380 381 382 383 384 385 386 387 388 389"
|
|
866 |
"390 391 392 393 394 395 396 397 398 399"
|
|
867 |
"400 401 402 403 404 405 406 407 408 409"
|
|
868 |
"410 411 412 413 414 415 416 417 418 419"
|
|
869 |
"420 421 422 423 424 425 426 427 428 429"
|
|
870 |
"430 431 432 433 434 435 436 437 438 439"
|
|
871 |
"440 441 442 443 444 445 446 447 448 449"
|
|
872 |
"450 451 452 453 454 455 456 457 458 459"
|
|
873 |
"460 461 462 463 464 465 466 467 468 469"
|
|
874 |
"470 471 472 473 474 475 476 477 478 479"
|
|
875 |
"480 481 482 483 484 485 486 487 488 489"
|
|
876 |
"490 491 492 493 494 495 496 497 498 499"
|
|
877 |
"500 501 502 503 504 505 506 507 508 509"
|
|
878 |
"510 511 512 513 514 515 516 517 518 519"
|
|
879 |
"520 521 522 523 524 525 526 527 528 529"
|
|
880 |
"530 531 532 533 534 535 536 537 538 539"
|
|
881 |
"540 541 542 543 544 545 546 547 548 549"
|
|
882 |
"550 551 552 553 554 555 556 557 558 559"
|
|
883 |
"560 561 562 563 564 565 566 567 568 569"
|
|
884 |
"570 571 572 573 574 575 576 577 578 579"
|
|
885 |
"580 581 582 583 584 585 586 587 588 589"
|
|
886 |
"590 591 592 593 594 595 596 597 598 599"
|
|
887 |
"600 601 602 603 604 605 606 607 608 609"
|
|
888 |
"610 611 612 613 614 615 616 617 618 619"
|
|
889 |
"620 621 622 623 624 625 626 627 628 629"
|
|
890 |
"630 631 632 633 634 635 636 637 638 639"
|
|
891 |
"640 641 642 643 644 645 646 647 648 649"
|
|
892 |
"650 651 652 653 654 655 656 657 658 659"
|
|
893 |
"660 661 662 663 664 665 666 667 668 669"
|
|
894 |
"670 671 672 673 674 675 676 677 678 679"
|
|
895 |
"680 681 682 683 684 685 686 687 688 689"
|
|
896 |
"690 691 692 693 694 695 696 697 698 699"
|
|
897 |
"700 701 702 703 704 705 706 707 708 709"
|
|
898 |
"710 711 712 713 714 715 716 717 718 719"
|
|
899 |
"720 721 722 723 724 725 726 727 728 729"
|
|
900 |
"730 731 732 733 734 735 736 737 738 739"
|
|
901 |
"740 741 742 743 744 745 746 747 748 749"
|
|
902 |
"750 751 752 753 754 755 756 757 758 759"
|
|
903 |
"760 761 762 763 764 765 766 767 768 769"
|
|
904 |
"770 771 772 773 774 775 776 777 778 779"
|
|
905 |
"780 781 782 783 784 785 786 787 788 789"
|
|
906 |
"790 791 792 793 794 795 796 797 798 799"
|
|
907 |
"800 801 802 803 804 805 806 807 808 809"
|
|
908 |
"810 811 812 813 814 815 816 817 818 819"
|
|
909 |
"820 821 822 823 824 825 826 827 828 829"
|
|
910 |
"830 831 832 833 834 835 836 837 838 839"
|
|
911 |
"840 841 842 843 844 845 846 847 848 849"
|
|
912 |
"850 851 852 853 854 855 856 857 858 859"
|
|
913 |
"860 861 862 863 864 865 866 867 868 869"
|
|
914 |
"870 871 872 873 874 875 876 877 878 879"
|
|
915 |
"880 881 882 883 884 885 886 887 888 889"
|
|
916 |
"890 891 892 893 894 895 896 897 898 899"
|
|
917 |
"900 901 902 903 904 905 906 907 908 909"
|
|
918 |
"910 911 912 913 914 915 916 917 918 919"
|
|
919 |
"920 921 922 923 924 925 926 927 928 929"
|
|
920 |
"930 931 932 933 934 935 936 937 938 939"
|
|
921 |
"940 941 942 943 944 945 946 947 948 949"
|
|
922 |
"950 951 952 953 954 955 956 957 958 959"
|
|
923 |
"960 961 962 963 964 965 966 967 968 969"
|
|
924 |
"970 971 972 973 974 975 976 977 978 979"
|
|
925 |
"980 981 982 983 984 985 986 987 988 989"
|
|
926 |
"990 991 992 993 994 995 996 997 998 999"; |
|
927 |
--enable_result_log
|
|
928 |
prepare long_query from "select ? as long_query"; |
|
929 |
--disable_result_log
|
|
930 |
execute long_query using @lparam; |
|
931 |
--enable_result_log
|
|
932 |
set global general_log = off; |
|
933 |
select command_type, argument from mysql.general_log where thread_id = @thread_id; |
|
934 |
deallocate prepare long_query; |
|
935 |
set global general_log = @old_general_log_state; |
|
936 |
||
937 |
#
|
|
938 |
# Bug #31700: thd->examined_row_count not incremented for 'const' type queries |
|
939 |
#
|
|
940 |
SET @old_slow_log_state = @@global.slow_query_log; |
|
941 |
||
942 |
SET SESSION long_query_time = 0; |
|
943 |
SET GLOBAL slow_query_log = ON; |
|
944 |
FLUSH LOGS; |
|
945 |
TRUNCATE TABLE mysql.slow_log; |
|
946 |
||
947 |
# Let there be three columns, unique, non-unique, and non-indexed: |
|
948 |
CREATE TABLE t1 (f1 SERIAL,f2 INT, f3 INT, PRIMARY KEY(f1), KEY(f2)); |
|
949 |
INSERT INTO t1 VALUES (1,1,1); |
|
950 |
INSERT INTO t1 VALUES (2,2,2); |
|
951 |
INSERT INTO t1 VALUES (3,3,3); |
|
952 |
INSERT INTO t1 VALUES (4,4,4); |
|
953 |
||
954 |
SELECT SQL_NO_CACHE 'Bug#31700 - SCAN',f1,f2,f3,SLEEP(1.1) FROM t1 WHERE f3=4; |
|
955 |
SELECT SQL_NO_CACHE 'Bug#31700 - KEY', f1,f2,f3,SLEEP(1.1) FROM t1 WHERE f2=3; |
|
956 |
SELECT SQL_NO_CACHE 'Bug#31700 - PK', f1,f2,f3,SLEEP(1.1) FROM t1 WHERE f1=2; |
|
957 |
||
958 |
--replace_column 1 TIMESTAMP
|
|
959 |
SELECT start_time, rows_examined, rows_sent, sql_text FROM mysql.slow_log WHERE sql_text LIKE '%Bug#31700%' ORDER BY start_time; |
|
960 |
||
961 |
DROP TABLE t1; |
|
962 |
||
963 |
TRUNCATE TABLE mysql.slow_log; |
|
964 |
||
965 |
SET GLOBAL slow_query_log = @old_slow_log_state; |
|
966 |
SET SESSION long_query_time =@old_long_query_time; |