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