config root man

Current Path : /home/usr.opt/mysql57/mysql-test/suite/query_rewrite_plugins/r/

FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64
Upload File :
Current File : /home/usr.opt/mysql57/mysql-test/suite/query_rewrite_plugins/r/optional_columns.result

#
# 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.
#
Warnings:
Warning	1681	'RESET QUERY CACHE' is deprecated and will be removed in a future release.
Warnings:
Warning	1681	'RESET QUERY CACHE' is deprecated and will be removed in a future release.
# 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();
Warnings:
Warning	1681	'RESET QUERY CACHE' is deprecated and will be removed in a future release.
SELECT * FROM query_rewrite.rewrite_rules;
id	pattern	pattern_database	replacement	enabled	message	pattern_digest	normalized_pattern
1	SELECT ?	NULL	SELECT "literal"	YES	NULL	3d4fc22e33e10d7235eced3c75a84c2c	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	abcc8e5c0ca2b1bd493606aeadb23a78	select `*` from `test`.`t1` where (((`a` = ?) and ?) or (`b` = ?))
3	SELECT a FROM test.t1	NULL	SELECT * FROM test.t1 WHERE a = 'abc'	YES	NULL	a68f8405e383726e9a41295fe1ce5460	select `a` from `test`.`t1`
4	SELECT a FROM test.t1 WHERE b = ?	NULL	SELECT * FROM test.t1 WHERE b = ?	YES	NULL	2500f673a570ddb20ab448b717c49ee4	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	938f59280d6ad2fa2f500aeeae6a5232	select `*` from `test`.`t2`
6	SELECT * FROM test.t1 WHERE a = ? OR b = ?	NULL	SELECT * FROM test.t1 WHERE b = ? OR a = ?	YES	NULL	629ae8152128638e35ea25458b38c94e	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	c99d4aa0a93768bd2b9f1ba0f551af7a	select ?,?
8	SELECT 2, ?	NULL	SELECT "rewritten w/rule 2"	YES	NULL	c99d4aa0a93768bd2b9f1ba0f551af7a	select ?,?
9	SELECT "The_original_query"	NULL	SELECT "The_rewritten_query"	YES	NULL	3d4fc22e33e10d7235eced3c75a84c2c	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 ?) 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 ?) 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.

Man Man