This file is indexed.

/usr/lib/mysql-testsuite/t/flush_table.test is in percona-server-test-5.6 5.6.22-rel71.0-0ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# TODO: Only run this if we have privilege to do flush table

#
# Test of flush table
#

# Should work in embedded server after mysqltest is fixed
-- source include/not_embedded.inc
--disable_warnings
drop table if exists t1,t2;
--enable_warnings
create table t1 (a int not null auto_increment primary key);
insert into t1 values(0);

# Test for with read lock + flush

lock table t1 read;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
flush table t1;
unlock tables;

# Test for with write lock + flush

lock table t1 write;
flush table t1;
check table t1;
unlock tables;

# Test for with a write lock and a waiting read lock + flush

lock table t1 write;
connect (locker,localhost,root,,test);
connection locker;
send lock table t1 read;
connection default;
sleep 2;
flush table t1;
select * from t1;
unlock tables;
connection locker;
reap;
unlock tables;
connection default;

# Test for with a write lock and a waiting write lock + flush

lock table t1 write;
connection locker;
send lock table t1 write;
connection default;
sleep 2;
flush table t1;
select * from t1;
unlock tables;
connection locker;
reap;
unlock tables;
select * from t1;
connection default;
drop table t1;
disconnect locker;

#
# In the following test FLUSH TABLES produces a deadlock
# (hang forever) if the fix for BUG #3565 is missing.
# And it shows that handler tables are re-opened after flush (BUG #4286).
#
create table t1(table_id char(20) primary key);
create table t2(table_id char(20) primary key);
insert into t1 values ('test.t1');
insert into t1 values ('');
insert into t2 values ('test.t2');
insert into t2 values ('');
handler t1 open as a1;
handler t1 open as a2;
handler t2 open;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush tables;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
#
--error 1066
handler t1 open as a1;
--error 1066
handler t1 open as a2;
--error 1066
handler t2 open;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush table t1;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush table t2;
handler t2 close;
drop table t1;
drop table t2;

#
# The fix for BUG #4286 cannot restore the position after a flush.
#
create table t1(table_id char(20) primary key);
insert into t1 values ('Record-01');
insert into t1 values ('Record-02');
insert into t1 values ('Record-03');
insert into t1 values ('Record-04');
insert into t1 values ('Record-05');
handler t1 open;
handler t1 read first limit 1;
handler t1 read next limit 1;
handler t1 read next limit 1;
flush table t1;
handler t1 read next limit 1;
handler t1 read next limit 1;
handler t1 close;
drop table t1;

#
# Bug #11934 Two sequential FLUSH TABLES WITH READ LOCK hangs client
#
FLUSH TABLES WITH READ LOCK ;
FLUSH TABLES WITH READ LOCK ;
UNLOCK TABLES;

# End of 4.1 tests

--echo
--echo #
--echo # WL#6168: FLUSH TABLES ... FOR EXPORT -- parser
--echo #
--echo

--echo # Requires innodb_file_per_table
SET @old_innodb_file_per_table= @@GLOBAL.innodb_file_per_table;
SET GLOBAL innodb_file_per_table= 1;

--echo # new "EXPORT" keyword is a valid user variable name:

SET @export = 10;

--echo # new "EXPORT" keyword is a valid SP parameter name:

CREATE PROCEDURE p1(export INT) BEGIN END;
DROP PROCEDURE p1;

--echo # new "EXPORT" keyword is a valid local variable name:

DELIMITER |;
CREATE PROCEDURE p1()
BEGIN
  DECLARE export INT;
END|
DELIMITER ;|
DROP PROCEDURE p1;

--echo # new "EXPORT" keyword is a valid SP name:

CREATE PROCEDURE export() BEGIN END;
DROP PROCEDURE export;

--echo # new FLUSH TABLES ... FOR EXPORT syntax:

--error ER_PARSE_ERROR
FLUSH TABLES FOR EXPORT;
--error ER_PARSE_ERROR
FLUSH TABLES WITH EXPORT;


CREATE TABLE t1 (i INT) engine=InnoDB;
CREATE TABLE t2 LIKE t1;

--error ER_PARSE_ERROR
FLUSH TABLES t1,t2 WITH EXPORT;

FLUSH TABLES t1, t2 FOR EXPORT;
UNLOCK TABLES;

--echo # case check
FLUSH TABLES t1, t2 for ExPoRt;
UNLOCK TABLES;
--echo # With LOCAL keyword
FLUSH LOCAL TABLES t1, t2 FOR EXPORT;
UNLOCK TABLES;
--echo # Tables with fully qualified names
FLUSH LOCAL TABLES test.t1, test.t2 for ExPoRt;
UNLOCK TABLES;

DROP TABLES t1, t2;

--echo # new "EXPORT" keyword is a valid table name:

CREATE TABLE export (i INT) engine=InnoDB;

--echo # it's ok to lock the "export" table for export:

FLUSH TABLE export FOR EXPORT;
UNLOCK TABLES;

DROP TABLE export;


--echo #
--echo # WL#6169 FLUSH TABLES ... FOR EXPORT -- runtime
--echo #

--echo # Test 1: Views, temporary tables, non-existent tables
--echo #

CREATE VIEW v1 AS SELECT 1;
CREATE TEMPORARY TABLE t1 (a INT);

--error ER_WRONG_OBJECT
FLUSH TABLES v1 FOR EXPORT;
--error ER_NO_SUCH_TABLE
FLUSH TABLES t1 FOR EXPORT;
--error ER_NO_SUCH_TABLE
FLUSH TABLES non_existent FOR EXPORT;

DROP TEMPORARY TABLE t1;
DROP VIEW v1;

--echo # Test 2: Blocked by update transactions, blocks updates.
--echo #

CREATE TABLE t1 (a INT PRIMARY KEY, b INT) engine= InnoDB;
CREATE TABLE t2 (a INT) engine= InnoDB;

--echo # Connection con1
--connect (con1, localhost, root)
START TRANSACTION;
INSERT INTO t1 VALUES (1, 1);

--echo # Connection default
--connection default
--echo # Should be blocked
--echo # Sending:
--send FLUSH TABLES t1 FOR EXPORT

--echo # Connection con1
--connection con1
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "FLUSH TABLES t1 FOR EXPORT";
--source include/wait_condition.inc
COMMIT;

--echo # Connection default
--connection default
--echo # Reaping: FLUSH TABLES t1 FOR EXPORT
--reap

--echo # Connection con1
--connection con1
--echo # Should not be blocked
INSERT INTO t2 VALUES (1);
--echo # Should be blocked
--echo # Sending:
--send INSERT INTO t1 VALUES (2, 2)

--echo # Connection default
--connection default
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "INSERT INTO t1 VALUES (2, 2)";
--source include/wait_condition.inc
UNLOCK TABLES;

--echo # Connection con1
--connection con1
--echo # Reaping: INSERT INTO t1 VALUES (2, 2);
--reap

--echo # Test 3: Read operations should not be affected.
--echo # 

START TRANSACTION;
SELECT * FROM t1;

--echo # Connection default
--connection default
--echo # Should not be blocked
FLUSH TABLES t1 FOR EXPORT;

--echo # Connection con1
--connection con1
COMMIT;
--echo # Should not be blocked
SELECT * FROM t1;

--echo # Connection default
--connection default
UNLOCK TABLES;

--echo # Test 4: Blocked by DDL, blocks DDL.
--echo #

START TRANSACTION;
SELECT * FROM t1;

--echo # Connection con2
--connect (con2, localhost, root)
--echo # Sending:
--send ALTER TABLE t1 ADD INDEX i1(b)

--echo # Connection con1
--connection con1
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "ALTER TABLE t1 ADD INDEX i1(b)";
--source include/wait_condition.inc
--echo # Should be blocked
--send FLUSH TABLE t1 FOR EXPORT

--echo # Connection default
--connection default
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "FLUSH TABLE t1 FOR EXPORT";
--source include/wait_condition.inc
COMMIT;

--echo # Connection con2
--connection con2
--echo # Reaping ALTER TABLE ...
--reap

--echo # Connection con1
--connection con1
--echo # Reaping FLUSH TABLE t1 FOR EXPORT
--reap
UNLOCK TABLES;

--echo # Connection default
--connection default
FLUSH TABLE t1 FOR EXPORT;

--echo # Connection con2
--connection con2
--echo # Should be blocked
--send DROP TABLE t1

--echo # Connection default
--connection default
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "DROP TABLE t1";
--source include/wait_condition.inc
UNLOCK TABLES;

--echo # Connection con2
--connection con2
--echo # Reaping DROP TABLE t1
--reap
--disconnect con2
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default
DROP TABLE t2;

--echo # Test 5: Compatibilty with FLUSH TABLES WITH READ LOCK
--echo #

CREATE TABLE t1(a INT) engine= InnoDB;
FLUSH TABLES WITH READ LOCK;

--echo # Connection con1
--connection con1
--echo # This should not block
FLUSH TABLE t1 FOR EXPORT;
UNLOCK TABLES;

--echo # Connection default
--connection default
UNLOCK TABLES;
DROP TABLE t1;

--echo # Test 6: Unsupported storage engines.
--echo #

CREATE TABLE t1(a INT) engine= MyISAM;
--error ER_ILLEGAL_HA
FLUSH TABLE t1 FOR EXPORT;
DROP TABLE t1;

--echo # Connection con1
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection defalt
--connection default

--echo # Test 7: Check privileges required.
--echo #

CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT) engine= InnoDB;
GRANT RELOAD, SELECT, LOCK TABLES ON *.* TO user1@localhost;
GRANT CREATE, DROP ON *.* TO user2@localhost;
GRANT RELOAD, SELECT ON *.* TO user3@localhost;
GRANT SELECT, LOCK TABLES ON *.* TO user4@localhost;
GRANT RELOAD, LOCK TABLES ON *.* TO user5@localhost;

--echo # Connection con1 as user1
--connect(con1, localhost, user1)
FLUSH TABLE db1.t1 FOR EXPORT;
UNLOCK TABLES;
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default

--echo # Connection con1 as user2
--connect(con1, localhost, user2)
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
FLUSH TABLE db1.t1 FOR EXPORT;
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default

--echo # Connection con1 as user3
--connect(con1, localhost, user3)
--error ER_DBACCESS_DENIED_ERROR
FLUSH TABLE db1.t1 FOR EXPORT;
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default

--echo # Connection con1 as user4
--connect(con1, localhost, user4)
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
FLUSH TABLE db1.t1 FOR EXPORT;
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default

--echo # Connection con1 as user5
--connect(con1, localhost, user5)
--error ER_TABLEACCESS_DENIED_ERROR
FLUSH TABLE db1.t1 FOR EXPORT;
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default
DROP USER user1@localhost, user2@localhost, user3@localhost,
          user4@localhost, user5@localhost;
DROP TABLE db1.t1;
DROP DATABASE db1;

--echo # Test 8: FLUSH TABLE <table_list> FOR EXPORT is incompatible
--echo #         with itself (to avoid race conditions in metadata
--echo #         file handling).
--echo #

CREATE TABLE t1 (a INT) engine= InnoDB;
CREATE TABLE t2 (a INT) engine= InnoDB;

--echo # Connection con1
--connect (con1, localhost, root)
FLUSH TABLE t1 FOR EXPORT;

--echo # Connection default
--connection default
--echo # This should not block
FLUSH TABLE t2 FOR EXPORT;
UNLOCK TABLES;
--echo # This should block
--echo # Sending:
--send FLUSH TABLE t1 FOR EXPORT

--echo # Connection con1
--connection con1
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "FLUSH TABLE t1 FOR EXPORT";
--source include/wait_condition.inc
UNLOCK TABLES;

--echo # Connection default
--connection default
--echo # Reaping: FLUSH TABLE t1 FOR EXPORT
--reap
UNLOCK TABLES;

--echo # Test 9: LOCK TABLES ... READ is not affected
--echo #

LOCK TABLE t1 READ;

--echo # Connection con1
--connection con1
--echo # Should not block
FLUSH TABLE t1 FOR EXPORT;
UNLOCK TABLES;

--echo # Connection default
--connection default
UNLOCK TABLES;
FLUSH TABLE t1 FOR EXPORT;

--echo # Connection con1
--connection con1
--echo # Should not block
LOCK TABLE t1 READ;
UNLOCK TABLES;

--echo # Connection default
--connection default
UNLOCK TABLES;

--echo # Connection con1
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # Connection default
--connection default
DROP TABLE t1, t2;

--echo # Test 10: Lock is released if transaction is started after doing
--echo #          'flush table..' in same session

CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
FLUSH TABLE t1 FOR EXPORT;
--echo # error as active locks already exist
--error ER_LOCK_OR_ACTIVE_TRANSACTION
FLUSH TABLE t1 FOR EXPORT;
--echo # active locks will be released due to start transaction
START TRANSACTION;
--echo # passes as start transaction released ealier locks
FLUSH TABLE t1 FOR EXPORT;
UNLOCK TABLES;
DROP TABLE t1;

--echo # Test 11: Test 'flush table with fully qualified table names
--echo #          and with syntax local/NO_WRITE_TO_BINLOG

--echo # Connection con1
--connect (con1, localhost, root)

--echo # Connection default
--connection default
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
INSERT INTO t1 VALUES (100),(200);
FLUSH LOCAL TABLES test.t1 FOR EXPORT;
--echo # Connection con1
--connection con1
--echo # Should be blocked
--echo # Sending:
--send FLUSH LOCAL TABLES t1 FOR EXPORT

--echo # Connection default
--connection default
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "FLUSH LOCAL TABLES t1 FOR EXPORT";
--source include/wait_condition.inc
UNLOCK TABLE;

--echo # Connection con1
--connection con1
--echo # Reaping: FLUSH LOCAL TABLES t1 FOR EXPORT
--reap
SELECT * FROM t1 ORDER BY i;

--echo # Connection default
--connection default
--echo # Should be blocked
--echo # Sending:
--send FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT

--echo # Connection con1
--connection con1
let $wait_condition=
  SELECT COUNT(*) = 1 FROM information_schema.processlist
  WHERE state = "Waiting for table metadata lock" AND
        info = "FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT";
--source include/wait_condition.inc
UNLOCK TABLES;

--echo # Connection default
--connection default
--echo # Reaping: FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT
--reap
SELECT * FROM t1 ORDER BY i;
UNLOCK TABLE;
DROP TABLE t1;

--echo # Test 12: Active transaction get committed if user execute
--echo #          "FLUSH TABLE ... FOR EXPORT" or "LOCK TABLE.."

--echo # Connection default
--connection default
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
INSERT INTO t1 VALUES (100),(200);
START TRANSACTION;
INSERT INTO t1 VALUES (300);
--echo # 'flush table..' commit active transaction from same session
FLUSH LOCAL TABLES test.t1 FOR EXPORT;
ROLLBACK;
SELECT * FROM t1 ORDER BY i;
START TRANSACTION;
INSERT INTO t1 VALUES (400);
--echo # 'lock table ..' commit active transaction from same session
LOCK TABLES test.t1 READ;
ROLLBACK;
SELECT * FROM t1 ORDER BY i;
UNLOCK TABLES;
DROP TABLE t1;

--echo # Test 13: Verify "FLUSH TABLE ... FOR EXPORT" and "LOCK TABLE.."
--echo #          in same session   
--echo # Connection default

--connection default
CREATE TABLE t1 ( i INT ) ENGINE = Innodb;
--echo # Lock table 
LOCK TABLES test.t1 WRITE;
--echo # 'lock table ..' completes even if table lock is acquired  
--echo # in same session using 'lock table'. Previous locks are released.
LOCK TABLES test.t1 READ;
--echo # 'flush table ..' gives error if table lock is acquired 
--echo # in same session using 'lock table ..'
--error ER_LOCK_OR_ACTIVE_TRANSACTION
FLUSH TABLES test.t1 FOR EXPORT;
--echo # 'lock table ..' completes even if table lock is acquired  
--echo # in same session using 'flush table'. Previous locks are released.
LOCK TABLES test.t1 WRITE;
UNLOCK TABLES;
DROP TABLE t1;

--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection default

--echo # Reset innodb_file_per_table
SET GLOBAL innodb_file_per_table= @old_innodb_file_per_table;

--echo # End of 5.6 tests