| 1 |
# |
| 2 |
# Reinstalls the plugin while keeping the rules table. |
| 3 |
# |
| 4 |
CREATE TABLE t1 ( c1 VARCHAR(10), c2 VARCHAR(10) ); |
| 5 |
INSERT INTO t1 VALUES ( 'abc', 'def' ), ( 'ghi', 'klm' ), ( 'nop', 'qrs' ); |
| 6 |
CREATE TABLE t2 ( c1 VARCHAR(10) ); |
| 7 |
INSERT INTO t2 VALUES ( 'abc' ), ( 'klm' ); |
| 8 |
# Query rewrite plugin was installed. |
| 9 |
# Insert some rewrite rules in the plugin |
| 10 |
INSERT INTO query_rewrite.rewrite_rules ( pattern, replacement ) |
| 11 |
VALUES ( 'SELECT * FROM test.t2', |
| 12 |
'SELECT * FROM test.t1 JOIN test.t2 ON test.t1.c1 = test.t2.c1' ); |
| 13 |
CALL query_rewrite.flush_rewrite_rules(); |
| 14 |
# Check a query that doesn't have a rewrite rule doesn't get rewritten. |
| 15 |
SELECT c2 FROM test.t1; |
| 16 |
c2 |
| 17 |
def |
| 18 |
klm |
| 19 |
qrs |
| 20 |
# Check that we can execute a rewrite rule. |
| 21 |
SELECT * FROM test.t2; |
| 22 |
c1 c2 c1 |
| 23 |
abc def abc |
| 24 |
Warnings: |
| 25 |
Note 1105 Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON test.t1.c1 = test.t2.c1' by a query rewrite plugin |
| 26 |
DROP PROCEDURE query_rewrite.flush_rewrite_rules; |
| 27 |
DROP FUNCTION load_rewrite_rules; |
| 28 |
UNINSTALL PLUGIN rewriter; |
| 29 |
Warnings: |
| 30 |
Warning 1620 Plugin is busy and will be uninstalled on shutdown |
| 31 |
# Check that the table is still present and didn't get dropped. |
| 32 |
SELECT pattern, replacement FROM query_rewrite.rewrite_rules; |
| 33 |
pattern replacement |
| 34 |
SELECT * FROM test.t2 SELECT * FROM test.t1 JOIN test.t2 ON test.t1.c1 = test.t2.c1 |
| 35 |
# Check that when the plugin is inactive the queries don't get rewritten. |
| 36 |
SELECT * FROM test.t2; |
| 37 |
c1 |
| 38 |
abc |
| 39 |
klm |
| 40 |
# Reinstall the plugin. All the rules should still be here from the |
| 41 |
# previous installation. |
| 42 |
Warnings: |
| 43 |
Note 1007 Can't create database 'query_rewrite'; database exists |
| 44 |
Warnings: |
| 45 |
Note 1050 Table 'rewrite_rules' already exists |
| 46 |
# Query rewrite plugin was installed. |
| 47 |
# Check that a query that doesn't have a rewrite rule doesn't get |
| 48 |
# rewritten. |
| 49 |
SELECT c2 FROM test.t1; |
| 50 |
c2 |
| 51 |
def |
| 52 |
klm |
| 53 |
qrs |
| 54 |
# Check that we can still execute a rewrite rule. |
| 55 |
SELECT * FROM test.t2; |
| 56 |
c1 c2 c1 |
| 57 |
abc def abc |
| 58 |
Warnings: |
| 59 |
Note 1105 Query 'SELECT * FROM test.t2' rewritten to 'SELECT * FROM test.t1 JOIN test.t2 ON test.t1.c1 = test.t2.c1' by a query rewrite plugin |
| 60 |
DROP TABLE t1, t2; |
| 61 |
Warnings: |
| 62 |
Warning 1620 Plugin is busy and will be uninstalled on shutdown |
| 63 |
# Query rewrite plugin was queued for uninstalling. |