File: optional_columns.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (861 lines) | stat: -rw-r--r-- 34,392 bytes parent folder | download
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
#
# Tests that the optional column columns work both of they are present
# and absent. PATTERN_DIGEST and NORMALIZED_PATTERN are optional write-
# only columns that are not present by default. The MESSAGE column is
# optional, but included in the install script by default.
#
# Query rewrite plugin was installed.
#
# Testing with PATTERN_DIGEST and NORMALIZED_PATTERN columns.
#
CREATE TABLE t1 ( a VARCHAR(10), b VARCHAR(10) );
INSERT INTO t1 VALUES ( 'abc', 'def' ), ( 'ghi', 'klm' ), ( 'nop', 'qrs' );
CREATE TABLE t2 ( a VARCHAR(10) );
INSERT INTO t2 VALUES ( 'abc' ), ( 'klm' );
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT ?', 'SELECT "literal"' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
1	SELECT ?	NULL	SELECT "literal"	YES	NULL	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
1	SELECT ?	NULL	SELECT "literal"	YES	NULL	d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae	select ?
SELECT NULL;
literal
literal
Warnings:
Note	1105	Query 'SELECT NULL' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 'abc';
literal
literal
Warnings:
Note	1105	Query 'SELECT 'abc'' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1.1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1.1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 123456789123456789123456789123456789123456789123456789;
literal
literal
Warnings:
Note	1105	Query 'SELECT 123456789123456789123456789123456789123456789123456789' rewritten to 'SELECT "literal"' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	1
Rewriter_number_reloads	2
Rewriter_number_rewritten_queries	5
Rewriter_reload_error	OFF
DELETE FROM query_rewrite.rewrite_rules;
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?',
'SELECT a FROM test.t1 WHERE a = ?' ),
( 'SELECT a FROM test.t1',
'SELECT * FROM test.t1 WHERE a = \'abc\'' ),
( 'SELECT a FROM test.t1 WHERE b = ?',
'SELECT * FROM test.t1 WHERE b = ?' ),
( 'SELECT * FROM test.t2',
'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' ),
( 'SELECT * FROM test.t1 WHERE a = ? OR b = ?',
'SELECT * FROM test.t1 WHERE b = ? OR a = ?' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
2	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	NULL	NULL	NULL
3	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL	NULL	NULL
4	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL	NULL	NULL
5	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	NULL	NULL	NULL
6	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
2	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	NULL	013244d601fea8fdb057f1a6fcf1222b6fe0214597fe5ef4aaf96aeabe09069f	select `*` from `test`.`t1` where (((`a` = ?) and true) or (`b` = ?))
3	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL	28939802f16d07e5b5ba42bded44d5bab1108022d2541e345a29040a323b01c8	select `a` from `test`.`t1`
4	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL	07f316122bd78ef48f419a40d301b7ade32dda8162ba40a11711ca428d16a02b	select `a` from `test`.`t1` where (`b` = ?)
5	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	NULL	666794284a40552eef7ab3173f130f1eec095c1fd1d5412c2d63dbc3a9f3a0b1	select `*` from `test`.`t2`
6	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL	9e2f0e4b7156eda97bdab476e09da81907bde37c25ebd8e1ada5b4a1b39db71e	select `*` from `test`.`t1` where ((`a` = ?) or (`b` = ?))
# Check a query that doesn't have a rewrite rule doesn't get rewritten.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check a query with just one parameter.
SELECT a FROM test.t1 WHERE b = 'qrs';
a	b
nop	qrs
Warnings:
Note	1105	Query 'SELECT a FROM test.t1 WHERE b = 'qrs'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'qrs'' by a query rewrite plugin
# Check a rule with parameter truncation (fewer parameters in the
# output query than in the input query);
SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm';
a
abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm'' rewritten to 'SELECT a FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
SELECT * FROM test.t1 WHERE ( a = 'abc' AND FALSE ) OR b = 'klm';
a	b
ghi	klm
# Check a non parameterized query.
SELECT * from t1 WHERE a = 'abc';
a	b
abc	def
# Check that a non-rewritten query does not yield a warning.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check that a query is not rewritten if the query corresponds to a
# replacement.
SELECT a FROM test.t1;
a	b
abc	def
Warnings:
Note	1105	Query 'SELECT a FROM test.t1' rewritten to 'SELECT * FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
# Check that we can execute a rewrite more than once.
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
# Remove the warnings.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check parameter switching in a query rewrite
SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with whitespace.
SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with comments.
SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	5
Rewriter_number_reloads	3
Rewriter_number_rewritten_queries	13
Rewriter_reload_error	OFF
DROP TABLE t1;
DROP TABLE t2;
DELETE FROM query_rewrite.rewrite_rules;
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT 1, ?', 'SELECT "rewritten w/rule 1"' ),
( 'SELECT 2, ?', 'SELECT "rewritten w/rule 2"' ),
( 'SELECT "The_original_query"', 'SELECT "The_rewritten_query"');
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
7	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	NULL	NULL	NULL
8	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL	NULL	NULL
9	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
7	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	NULL	efb26d6aca0766da4a6d37f3e3aa5332542ff42893ff98fbb393da4e8cbd6a10	select ?,?
8	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL	efb26d6aca0766da4a6d37f3e3aa5332542ff42893ff98fbb393da4e8cbd6a10	select ?,?
9	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL	d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae	select ?
SELECT 1, 1;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 1' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 1, 2;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 2' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 2, 1;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 1' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 2, 2;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 2' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 3, 1;
3	1
3	1
SELECT 3, 2;
3	2
3	2
SELECT 'The_original_query';
The_rewritten_query
The_rewritten_query
Warnings:
Note	1105	Query 'SELECT 'The_original_query'' rewritten to 'SELECT "The_rewritten_query"' by a query rewrite plugin
DELETE FROM query_rewrite.rewrite_rules;
DELETE FROM query_rewrite.rewrite_rules;
#
# Testing with a NORMALIZED_PATTERN column.
#
ALTER TABLE query_rewrite.rewrite_rules DROP COLUMN pattern_digest;
CREATE TABLE t1 ( a VARCHAR(10), b VARCHAR(10) );
INSERT INTO t1 VALUES ( 'abc', 'def' ), ( 'ghi', 'klm' ), ( 'nop', 'qrs' );
CREATE TABLE t2 ( a VARCHAR(10) );
INSERT INTO t2 VALUES ( 'abc' ), ( 'klm' );
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT ?', 'SELECT "literal"' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
10	SELECT ?	NULL	SELECT "literal"	YES	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
10	SELECT ?	NULL	SELECT "literal"	YES	NULL	select ?
SELECT NULL;
literal
literal
Warnings:
Note	1105	Query 'SELECT NULL' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 'abc';
literal
literal
Warnings:
Note	1105	Query 'SELECT 'abc'' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1.1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1.1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 123456789123456789123456789123456789123456789123456789;
literal
literal
Warnings:
Note	1105	Query 'SELECT 123456789123456789123456789123456789123456789123456789' rewritten to 'SELECT "literal"' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	1
Rewriter_number_reloads	5
Rewriter_number_rewritten_queries	23
Rewriter_reload_error	OFF
DELETE FROM query_rewrite.rewrite_rules;
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?',
'SELECT a FROM test.t1 WHERE a = ?' ),
( 'SELECT a FROM test.t1',
'SELECT * FROM test.t1 WHERE a = \'abc\'' ),
( 'SELECT a FROM test.t1 WHERE b = ?',
'SELECT * FROM test.t1 WHERE b = ?' ),
( 'SELECT * FROM test.t2',
'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' ),
( 'SELECT * FROM test.t1 WHERE a = ? OR b = ?',
'SELECT * FROM test.t1 WHERE b = ? OR a = ?' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
11	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	NULL	NULL
12	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL	NULL
13	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL	NULL
14	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	NULL	NULL
15	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
11	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	NULL	select `*` from `test`.`t1` where (((`a` = ?) and true) or (`b` = ?))
12	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL	select `a` from `test`.`t1`
13	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL	select `a` from `test`.`t1` where (`b` = ?)
14	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	NULL	select `*` from `test`.`t2`
15	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL	select `*` from `test`.`t1` where ((`a` = ?) or (`b` = ?))
# Check a query that doesn't have a rewrite rule doesn't get rewritten.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check a query with just one parameter.
SELECT a FROM test.t1 WHERE b = 'qrs';
a	b
nop	qrs
Warnings:
Note	1105	Query 'SELECT a FROM test.t1 WHERE b = 'qrs'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'qrs'' by a query rewrite plugin
# Check a rule with parameter truncation (fewer parameters in the
# output query than in the input query);
SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm';
a
abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm'' rewritten to 'SELECT a FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
SELECT * FROM test.t1 WHERE ( a = 'abc' AND FALSE ) OR b = 'klm';
a	b
ghi	klm
# Check a non parameterized query.
SELECT * from t1 WHERE a = 'abc';
a	b
abc	def
# Check that a non-rewritten query does not yield a warning.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check that a query is not rewritten if the query corresponds to a
# replacement.
SELECT a FROM test.t1;
a	b
abc	def
Warnings:
Note	1105	Query 'SELECT a FROM test.t1' rewritten to 'SELECT * FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
# Check that we can execute a rewrite more than once.
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
# Remove the warnings.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check parameter switching in a query rewrite
SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with whitespace.
SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with comments.
SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	5
Rewriter_number_reloads	6
Rewriter_number_rewritten_queries	31
Rewriter_reload_error	OFF
DROP TABLE t1;
DROP TABLE t2;
DELETE FROM query_rewrite.rewrite_rules;
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT 1, ?', 'SELECT "rewritten w/rule 1"' ),
( 'SELECT 2, ?', 'SELECT "rewritten w/rule 2"' ),
( 'SELECT "The_original_query"', 'SELECT "The_rewritten_query"');
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
16	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	NULL	NULL
17	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL	NULL
18	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	normalized_pattern
16	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	NULL	select ?,?
17	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL	select ?,?
18	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL	select ?
SELECT 1, 1;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 1' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 1, 2;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 2' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 2, 1;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 1' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 2, 2;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 2' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 3, 1;
3	1
3	1
SELECT 3, 2;
3	2
3	2
SELECT 'The_original_query';
The_rewritten_query
The_rewritten_query
Warnings:
Note	1105	Query 'SELECT 'The_original_query'' rewritten to 'SELECT "The_rewritten_query"' by a query rewrite plugin
DELETE FROM query_rewrite.rewrite_rules;
DELETE FROM query_rewrite.rewrite_rules;
#
# Testing with a NORMALIZED_PATTERN column but no MESSAGE column.
#
ALTER TABLE query_rewrite.rewrite_rules DROP COLUMN message;
CREATE TABLE t1 ( a VARCHAR(10), b VARCHAR(10) );
INSERT INTO t1 VALUES ( 'abc', 'def' ), ( 'ghi', 'klm' ), ( 'nop', 'qrs' );
CREATE TABLE t2 ( a VARCHAR(10) );
INSERT INTO t2 VALUES ( 'abc' ), ( 'klm' );
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT ?', 'SELECT "literal"' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
19	SELECT ?	NULL	SELECT "literal"	YES	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
19	SELECT ?	NULL	SELECT "literal"	YES	select ?
SELECT NULL;
literal
literal
Warnings:
Note	1105	Query 'SELECT NULL' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 'abc';
literal
literal
Warnings:
Note	1105	Query 'SELECT 'abc'' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1.1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1.1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 123456789123456789123456789123456789123456789123456789;
literal
literal
Warnings:
Note	1105	Query 'SELECT 123456789123456789123456789123456789123456789123456789' rewritten to 'SELECT "literal"' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	1
Rewriter_number_reloads	8
Rewriter_number_rewritten_queries	41
Rewriter_reload_error	OFF
DELETE FROM query_rewrite.rewrite_rules;
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?',
'SELECT a FROM test.t1 WHERE a = ?' ),
( 'SELECT a FROM test.t1',
'SELECT * FROM test.t1 WHERE a = \'abc\'' ),
( 'SELECT a FROM test.t1 WHERE b = ?',
'SELECT * FROM test.t1 WHERE b = ?' ),
( 'SELECT * FROM test.t2',
'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' ),
( 'SELECT * FROM test.t1 WHERE a = ? OR b = ?',
'SELECT * FROM test.t1 WHERE b = ? OR a = ?' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
20	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	NULL
21	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL
22	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL
23	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	NULL
24	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
20	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES	select `*` from `test`.`t1` where (((`a` = ?) and true) or (`b` = ?))
21	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	select `a` from `test`.`t1`
22	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	select `a` from `test`.`t1` where (`b` = ?)
23	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES	select `*` from `test`.`t2`
24	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	select `*` from `test`.`t1` where ((`a` = ?) or (`b` = ?))
# Check a query that doesn't have a rewrite rule doesn't get rewritten.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check a query with just one parameter.
SELECT a FROM test.t1 WHERE b = 'qrs';
a	b
nop	qrs
Warnings:
Note	1105	Query 'SELECT a FROM test.t1 WHERE b = 'qrs'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'qrs'' by a query rewrite plugin
# Check a rule with parameter truncation (fewer parameters in the
# output query than in the input query);
SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm';
a
abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm'' rewritten to 'SELECT a FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
SELECT * FROM test.t1 WHERE ( a = 'abc' AND FALSE ) OR b = 'klm';
a	b
ghi	klm
# Check a non parameterized query.
SELECT * from t1 WHERE a = 'abc';
a	b
abc	def
# Check that a non-rewritten query does not yield a warning.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check that a query is not rewritten if the query corresponds to a
# replacement.
SELECT a FROM test.t1;
a	b
abc	def
Warnings:
Note	1105	Query 'SELECT a FROM test.t1' rewritten to 'SELECT * FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
# Check that we can execute a rewrite more than once.
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
# Remove the warnings.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check parameter switching in a query rewrite
SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with whitespace.
SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with comments.
SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	5
Rewriter_number_reloads	9
Rewriter_number_rewritten_queries	49
Rewriter_reload_error	OFF
DROP TABLE t1;
DROP TABLE t2;
DELETE FROM query_rewrite.rewrite_rules;
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT 1, ?', 'SELECT "rewritten w/rule 1"' ),
( 'SELECT 2, ?', 'SELECT "rewritten w/rule 2"' ),
( 'SELECT "The_original_query"', 'SELECT "The_rewritten_query"');
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
25	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	NULL
26	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL
27	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	normalized_pattern
25	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES	select ?,?
26	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	select ?,?
27	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	select ?
SELECT 1, 1;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 1' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 1, 2;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 2' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 2, 1;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 1' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 2, 2;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 2' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 3, 1;
3	1
3	1
SELECT 3, 2;
3	2
3	2
SELECT 'The_original_query';
The_rewritten_query
The_rewritten_query
Warnings:
Note	1105	Query 'SELECT 'The_original_query'' rewritten to 'SELECT "The_rewritten_query"' by a query rewrite plugin
DELETE FROM query_rewrite.rewrite_rules;
DELETE FROM query_rewrite.rewrite_rules;
#
# Testing with no optional columns.
#
ALTER TABLE query_rewrite.rewrite_rules DROP COLUMN normalized_pattern;
CREATE TABLE t1 ( a VARCHAR(10), b VARCHAR(10) );
INSERT INTO t1 VALUES ( 'abc', 'def' ), ( 'ghi', 'klm' ), ( 'nop', 'qrs' );
CREATE TABLE t2 ( a VARCHAR(10) );
INSERT INTO t2 VALUES ( 'abc' ), ( 'klm' );
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT ?', 'SELECT "literal"' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
28	SELECT ?	NULL	SELECT "literal"	YES
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
28	SELECT ?	NULL	SELECT "literal"	YES
SELECT NULL;
literal
literal
Warnings:
Note	1105	Query 'SELECT NULL' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 'abc';
literal
literal
Warnings:
Note	1105	Query 'SELECT 'abc'' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 1.1;
literal
literal
Warnings:
Note	1105	Query 'SELECT 1.1' rewritten to 'SELECT "literal"' by a query rewrite plugin
SELECT 123456789123456789123456789123456789123456789123456789;
literal
literal
Warnings:
Note	1105	Query 'SELECT 123456789123456789123456789123456789123456789123456789' rewritten to 'SELECT "literal"' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	1
Rewriter_number_reloads	11
Rewriter_number_rewritten_queries	59
Rewriter_reload_error	OFF
DELETE FROM query_rewrite.rewrite_rules;
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?',
'SELECT a FROM test.t1 WHERE a = ?' ),
( 'SELECT a FROM test.t1',
'SELECT * FROM test.t1 WHERE a = \'abc\'' ),
( 'SELECT a FROM test.t1 WHERE b = ?',
'SELECT * FROM test.t1 WHERE b = ?' ),
( 'SELECT * FROM test.t2',
'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' ),
( 'SELECT * FROM test.t1 WHERE a = ? OR b = ?',
'SELECT * FROM test.t1 WHERE b = ? OR a = ?' );
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
29	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES
30	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES
31	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES
32	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES
33	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
29	SELECT * FROM test.t1 WHERE ( a = ? AND TRUE ) OR b = ?	NULL	SELECT a FROM test.t1 WHERE a = ?	YES
30	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES
31	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES
32	SELECT * FROM test.t2	NULL	SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a	YES
33	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES
# Check a query that doesn't have a rewrite rule doesn't get rewritten.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check a query with just one parameter.
SELECT a FROM test.t1 WHERE b = 'qrs';
a	b
nop	qrs
Warnings:
Note	1105	Query 'SELECT a FROM test.t1 WHERE b = 'qrs'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'qrs'' by a query rewrite plugin
# Check a rule with parameter truncation (fewer parameters in the
# output query than in the input query);
SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm';
a
abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE ( a = 'abc' AND TRUE ) OR b = 'klm'' rewritten to 'SELECT a FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
SELECT * FROM test.t1 WHERE ( a = 'abc' AND FALSE ) OR b = 'klm';
a	b
ghi	klm
# Check a non parameterized query.
SELECT * from t1 WHERE a = 'abc';
a	b
abc	def
# Check that a non-rewritten query does not yield a warning.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check that a query is not rewritten if the query corresponds to a
# replacement.
SELECT a FROM test.t1;
a	b
abc	def
Warnings:
Note	1105	Query 'SELECT a FROM test.t1' rewritten to 'SELECT * FROM test.t1 WHERE a = 'abc'' by a query rewrite plugin
# Check that we can execute a rewrite more than once.
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
SELECT * FROM test.t2;
a	b	a
abc	def	abc
Warnings:
Note	1105	Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON t1.a = t2.a' by a query rewrite plugin
# Remove the warnings.
SELECT b FROM test.t1;
b
def
klm
qrs
# Check parameter switching in a query rewrite
SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a = 'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with whitespace.
SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1   WHERE   a  = 'def' OR b  =  'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Verify with comments.
SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi';
a	b
abc	def
ghi	klm
Warnings:
Note	1105	Query 'SELECT * FROM test.t1 WHERE a =/* 'def' ? */'def' OR b = 'ghi'' rewritten to 'SELECT * FROM test.t1 WHERE b = 'def' OR a = 'ghi'' by a query rewrite plugin
# Check our status variables.
SHOW STATUS LIKE 'Rewriter%';
Variable_name	Value
Rewriter_number_loaded_rules	5
Rewriter_number_reloads	12
Rewriter_number_rewritten_queries	67
Rewriter_reload_error	OFF
DROP TABLE t1;
DROP TABLE t2;
DELETE FROM query_rewrite.rewrite_rules;
# Test of literals matching.
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement )
VALUES ( 'SELECT 1, ?', 'SELECT "rewritten w/rule 1"' ),
( 'SELECT 2, ?', 'SELECT "rewritten w/rule 2"' ),
( 'SELECT "The_original_query"', 'SELECT "The_rewritten_query"');
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
34	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES
35	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES
36	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES
CALL query_rewrite.flush_rewrite_rules();
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled
34	SELECT 1, ?	NULL	SELECT "rewritten w/rule 1"	YES
35	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES
36	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES
SELECT 1, 1;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 1' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 1, 2;
rewritten w/rule 1
rewritten w/rule 1
Warnings:
Note	1105	Query 'SELECT 1, 2' rewritten to 'SELECT "rewritten w/rule 1"' by a query rewrite plugin
SELECT 2, 1;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 1' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 2, 2;
rewritten w/rule 2
rewritten w/rule 2
Warnings:
Note	1105	Query 'SELECT 2, 2' rewritten to 'SELECT "rewritten w/rule 2"' by a query rewrite plugin
SELECT 3, 1;
3	1
3	1
SELECT 3, 2;
3	2
3	2
SELECT 'The_original_query';
The_rewritten_query
The_rewritten_query
Warnings:
Note	1105	Query 'SELECT 'The_original_query'' rewritten to 'SELECT "The_rewritten_query"' by a query rewrite plugin
DELETE FROM query_rewrite.rewrite_rules;
DELETE FROM query_rewrite.rewrite_rules;
Warnings:
Warning	1620	Plugin is busy and will be uninstalled on shutdown
# Query rewrite plugin was queued for uninstalling.