2
# Basic log tables test
5
# check that CSV engine was compiled in
6
--source include/have_csv.inc
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
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;
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.
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%';
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
42
create table join_test (verbose_comment varchar (80), command_type varchar(64));
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");
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);
56
# check that flush of the log table work fine
62
# check locking of the log tables
65
--error ER_CANT_LOCK_LOG_TABLE
66
lock tables mysql.general_log WRITE;
68
--error ER_CANT_LOCK_LOG_TABLE
69
lock tables mysql.slow_log WRITE;
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.
77
--error ER_CANT_LOCK_LOG_TABLE
78
lock tables mysql.general_log READ;
80
--error ER_CANT_LOCK_LOG_TABLE
81
lock tables mysql.slow_log READ;
84
# This call should result in TL_READ lock on the log table.
85
# This is not ok and should fail.
88
--error ER_CANT_LOCK_LOG_TABLE
89
lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL;
93
show create table mysql.general_log;
94
show fields from mysql.general_log;
96
show create table mysql.slow_log;
97
show fields from mysql.slow_log;
100
# check that FLUSH LOGS does not flush the log tables
106
SET GLOBAL GENERAL_LOG=ON;
107
SET GLOBAL SLOW_QUERY_LOG=ON;
114
# check that FLUSH TABLES does flush the log tables
118
# Since the flush is logged, mysql.general_log will be in the cache
121
SET GLOBAL GENERAL_LOG=OFF;
122
SET GLOBAL SLOW_QUERY_LOG=OFF;
125
# Here the table cache is empty
128
SET GLOBAL GENERAL_LOG=ON;
129
SET GLOBAL SLOW_QUERY_LOG=ON;
132
# Bug#23924 general_log truncates queries with character set introducers.
134
truncate table mysql.general_log;
136
select _koi8r'����' as test;
137
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
138
select * from mysql.general_log;
142
# Bug #16905 Log tables: unicode statements are logged incorrectly
145
truncate table mysql.general_log;
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;
154
# Bug #17600: Invalid data logged into mysql.slow_log
157
truncate table mysql.slow_log;
158
set session long_query_time=1;
160
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
161
select * from mysql.slow_log;
164
# Bug #18559 log tables cannot change engine, and gets deadlocked when
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;
175
--error ER_BAD_LOG_STATEMENT
176
drop table mysql.general_log;
177
--error ER_BAD_LOG_STATEMENT
178
drop table mysql.slow_log;
180
# check that one can alter log tables to MyISAM
181
set global general_log='OFF';
183
# cannot convert another log table
184
--error ER_BAD_LOG_STATEMENT
185
alter table mysql.slow_log engine=myisam;
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;
193
alter table mysql.general_log engine=myisam;
194
alter table mysql.slow_log engine=myisam;
196
# check that the tables were converted
197
show create table mysql.general_log;
198
show create table mysql.slow_log;
200
# enable log tables and chek that new tables indeed work
201
set global general_log='ON';
202
set global slow_query_log='ON';
204
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
205
select * from mysql.general_log;
207
# check that flush of myisam-based log tables work fine
210
# check locking of myisam-based log tables
212
--error ER_CANT_LOCK_LOG_TABLE
213
lock tables mysql.general_log WRITE;
215
--error ER_CANT_LOCK_LOG_TABLE
216
lock tables mysql.slow_log WRITE;
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.
224
--error ER_CANT_LOCK_LOG_TABLE
225
lock tables mysql.general_log READ;
227
--error ER_CANT_LOCK_LOG_TABLE
228
lock tables mysql.slow_log READ;
230
# check that we can drop them
231
set global general_log='OFF';
232
set global slow_query_log='OFF';
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;
247
drop table mysql.slow_log;
248
drop table mysql.general_log;
250
# check that table share cleanup is performed correctly (double drop)
252
--error ER_BAD_TABLE_ERROR
253
drop table mysql.general_log;
254
--error ER_BAD_TABLE_ERROR
255
drop table mysql.slow_log;
257
# recreate tables and enable logs
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';
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';
286
set global general_log='ON';
287
set global slow_query_log='ON';
291
# Bug #20139 Infinite loop after "FLUSH" and "LOCK tabX, general_log"
294
flush tables with read lock;
297
--error ER_CANT_LOCK_LOG_TABLE
298
lock tables general_log read local, help_category read local;
302
# Bug #17544 Cannot do atomic log rotate and
303
# Bug #21785 Server crashes after rename of the log table
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;
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;
321
truncate table general_log;
322
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
323
select * from general_log;
325
truncate table slow_log;
326
--replace_column 1 TIMESTAMP 2 USER_HOST
327
select * from slow_log;
329
create table general_log_new like general_log;
330
rename table general_log TO renamed_general_log, general_log_new TO general_log;
332
create table slow_log_new like slow_log;
333
rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log;
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;
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;
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;
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;
355
set global slow_query_log='OFF';
356
RENAME TABLE slow_log TO slow_log2;
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';
364
RENAME TABLE general_log2 TO general_log;
365
RENAME TABLE slow_log2 TO slow_log;
368
set global general_log='ON';
369
set global slow_query_log='ON';
370
# now check flush logs
373
drop table renamed_general_log, renamed_slow_log;
377
# Bug#27858 (Failing to log to a log table doesn't log anything to error log)
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
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.
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;
400
# create table mysql.bad_general_log (a int) engine= CSV;
401
# create table mysql.bad_slow_log (a int) engine= CSV;
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;
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
413
# select "logging this should fail";
415
# # Restore the log tables
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;
422
# drop table mysql.bad_general_log;
423
# drop table mysql.bad_slow_log;
426
# Bug #21966 Strange warnings on repair of the log tables
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;
441
# Bug#27857 (Log tables supplies the wrong value for generating
442
# AUTO_INCREMENT numbers)
445
SET GLOBAL LOG_OUTPUT = 'TABLE';
447
## test the general log
449
SET GLOBAL general_log = 0;
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;
457
SET GLOBAL general_log = 1;
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;
469
SET GLOBAL general_log = 0;
472
ALTER TABLE mysql.general_log DROP COLUMN seq;
473
ALTER TABLE mysql.general_log ENGINE = CSV;
475
## test the slow query log
477
SET @old_long_query_time:=@@long_query_time;
479
SET GLOBAL slow_query_log = 0;
482
TRUNCATE TABLE mysql.slow_log;
483
ALTER TABLE mysql.slow_log ENGINE = MyISAM;
485
ALTER TABLE mysql.slow_log
486
ADD COLUMN seq BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
488
SET SESSION long_query_time = 1;
489
SET GLOBAL slow_query_log = 1;
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);
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;
503
SET GLOBAL slow_query_log = 0;
504
SET SESSION long_query_time =@old_long_query_time;
507
ALTER TABLE mysql.slow_log DROP COLUMN seq;
508
ALTER TABLE mysql.slow_log ENGINE = CSV;
511
# Bug#25422 (Hang with log tables)
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;
524
create procedure proc25422_truncate_slow (loops int)
526
declare v1 int default 0;
527
declare continue handler for sqlexception /* errors from truncate */
530
truncate mysql.slow_log;
535
create procedure proc25422_truncate_general (loops int)
537
declare v1 int default 0;
538
declare continue handler for sqlexception /* errors from truncate */
541
truncate mysql.general_log;
546
create procedure proc25422_alter_slow (loops int)
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;
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;
561
create procedure proc25422_alter_general (loops int)
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;
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;
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);
589
--echo "Parallel test"
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
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,,);
604
connection addconroot1;
605
send call proc25422_truncate_slow(@iterations);
606
connection addconroot2;
607
send call proc25422_truncate_slow(@iterations);
609
connection addconroot3;
610
send call proc25422_truncate_general(@iterations);
611
connection addconroot4;
612
send call proc25422_truncate_general(@iterations);
614
connection addconroot5;
615
send call proc25422_alter_slow(@iterations);
616
connection addconroot6;
617
send call proc25422_alter_slow(@iterations);
619
connection addconroot7;
620
send call proc25422_alter_general(@iterations);
621
connection addconroot8;
622
send call proc25422_alter_general(@iterations);
624
connection addconroot1;
626
connection addconroot2;
628
connection addconroot3;
630
connection addconroot4;
632
connection addconroot5;
634
connection addconroot6;
636
connection addconroot7;
638
connection addconroot8;
643
disconnect addconroot1;
644
disconnect addconroot2;
645
disconnect addconroot3;
646
disconnect addconroot4;
647
disconnect addconroot5;
648
disconnect addconroot6;
649
disconnect addconroot7;
650
disconnect addconroot8;
652
drop procedure proc25422_truncate_slow;
653
drop procedure proc25422_truncate_general;
654
drop procedure proc25422_alter_slow;
655
drop procedure proc25422_alter_general;
661
# Bug#23044 (Warnings on flush of a log table)
664
FLUSH TABLE mysql.general_log;
667
FLUSH TABLE mysql.slow_log;
671
# Bug#17876 (Truncating mysql.slow_log in a SP after using cursor locks the
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`;
683
CREATE DATABASE db_17876;
685
CREATE TABLE `db_17876.slow_log_data` (
686
`start_time` timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
687
`user_host` mediumtext ,
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
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
710
CREATE procedure `db_17876.archiveSlowLog`()
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;
720
DECLARE cur1 CURSOR FOR SELECT * FROM mysql.slow_log;
727
DECLARE CONTINUE HANDLER FOR ER_SP_FETCH_NO_DATA SET done = 1;
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;
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);
744
UNTIL done END REPEAT;
747
TRUNCATE mysql.slow_log;
750
CREATE procedure `db_17876.archiveGeneralLog`()
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;
760
DECLARE cur1 CURSOR FOR SELECT * FROM mysql.general_log;
767
DECLARE CONTINUE HANDLER FOR ER_SP_FETCH_NO_DATA SET done = 1;
770
event_time, user_host, thread_id, server_id,
771
command_type, argument;
777
`db_17876.general_log_data`
778
VALUES(event_time, user_host, thread_id, server_id,
779
command_type, argument);
783
UNTIL done END REPEAT;
786
TRUNCATE mysql.general_log;
791
SET @old_general_log_state = @@global.general_log;
792
SET @old_slow_log_state = @@global.slow_query_log;
794
SET GLOBAL general_log = ON;
795
SET GLOBAL slow_query_log = ON;
797
select "put something into general_log";
798
select "... and something more ...";
800
call `db_17876.archiveSlowLog`();
801
call `db_17876.archiveGeneralLog`();
803
SET GLOBAL general_log = OFF;
804
SET GLOBAL slow_query_log = OFF;
806
call `db_17876.archiveSlowLog`();
807
call `db_17876.archiveGeneralLog`();
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`;
815
SET GLOBAL general_log = @old_general_log_state;
816
SET GLOBAL slow_query_log = @old_slow_log_state;
819
# Bug#21557 entries in the general query log truncated at 1000 characters.
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;
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";
928
prepare long_query from "select ? as long_query";
930
execute long_query using @lparam;
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;
938
# Bug #31700: thd->examined_row_count not incremented for 'const' type queries
940
SET @old_slow_log_state = @@global.slow_query_log;
942
SET SESSION long_query_time = 0;
943
SET GLOBAL slow_query_log = ON;
945
TRUNCATE TABLE mysql.slow_log;
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);
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;
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;
963
TRUNCATE TABLE mysql.slow_log;
965
SET GLOBAL slow_query_log = @old_slow_log_state;
966
SET SESSION long_query_time =@old_long_query_time;