| 1 |
--echo # |
| 2 |
--echo # Test of rewrites of queries where the database (a.k.a. schema) is not |
| 3 |
--echo # specified in the pattern. |
| 4 |
--echo # |
| 5 |
--echo # MySQL behaves in the most peculiar way in this respect. Some |
| 6 |
--echo # explanation is order here: When a query is parsed, the |
| 7 |
--echo # parser injects the current database when parsing a table name, i.e. |
| 8 |
--echo # 'table' is _parsed_ as '<current database>.table'. |
| 9 |
--echo # |
| 10 |
--echo # The session that loads the rules has no current database, so the rule |
| 11 |
--echo # has to specify it if there are unqualified table names in the pattern. |
| 12 |
--echo # |
| 13 |
|
| 14 |
CALL mtr.add_suppression("Plugin rewriter reported: 'Some rules failed to load.'"); |
| 15 |
|
| 16 |
--source suite/query_rewrite_plugins/include/have_plugin_rewriter.inc |
| 17 |
|
| 18 |
CREATE DATABASE db1; |
| 19 |
CREATE DATABASE db2; |
| 20 |
|
| 21 |
CREATE TABLE t1 ( a VARCHAR(23) ); |
| 22 |
INSERT INTO t1 VALUES ( 'This was not rewritten.' ); |
| 23 |
|
| 24 |
--source suite/query_rewrite_plugins/include/install_rewriter.inc |
| 25 |
|
| 26 |
INSERT |
| 27 |
INTO query_rewrite.rewrite_rules ( pattern, pattern_database, replacement ) |
| 28 |
VALUES ( 'SELECT * FROM db1.nonexistent_table1', NULL, 'SELECT "Rule #1"' ), |
| 29 |
( 'SELECT * FROM db2.nonexistent_table2', NULL, 'SELECT "Rule #2"' ), |
| 30 |
( 'SELECT * FROM nonexistent_table_db1', 'db1', 'SELECT "Rule #3"' ), |
| 31 |
( 'SELECT * FROM nonexistent_table_db2', 'db2', 'SELECT "Rule #4"' ), |
| 32 |
( 'SELECT * FROM nonexistent_table', NULL, 'SELECT "Rule #5"' ), |
| 33 |
( 'SELECT * FROM test.t1', 'test', 'SELECT "Rule #6"' ), |
| 34 |
( 'SELECT 1 FROM t1', 'test', 'SELECT 4 FROM t1' ), |
| 35 |
( 'SELECT 2 FROM t1', NULL, 'SELECT 5 FROM t1' ), |
| 36 |
( 'SELECT 3 FROM test.t1', NULL, 'SELECT 6 FROM t1' ); |
| 37 |
|
| 38 |
--error ER_SIGNAL_EXCEPTION |
| 39 |
CALL query_rewrite.flush_rewrite_rules(); |
| 40 |
|
| 41 |
SELECT * FROM query_rewrite.rewrite_rules; |
| 42 |
|
| 43 |
USE test; |
| 44 |
|
| 45 |
SELECT * FROM db1.nonexistent_table1; |
| 46 |
SELECT * FROM db2.nonexistent_table2; |
| 47 |
--error ER_NO_SUCH_TABLE |
| 48 |
SELECT * FROM nonexistent_table_db1; |
| 49 |
--error ER_NO_SUCH_TABLE |
| 50 |
SELECT * FROM nonexistent_table_db2; |
| 51 |
SELECT * FROM test.t1; |
| 52 |
SELECT 1 FROM t1; |
| 53 |
|
| 54 |
USE db1; |
| 55 |
|
| 56 |
SELECT * FROM db1.nonexistent_table1; |
| 57 |
SELECT * FROM db2.nonexistent_table2; |
| 58 |
SELECT * FROM nonexistent_table_db1; |
| 59 |
--error ER_NO_SUCH_TABLE |
| 60 |
SELECT * FROM nonexistent_table_db2; |
| 61 |
SELECT * FROM test.t1; |
| 62 |
--error ER_NO_SUCH_TABLE |
| 63 |
SELECT 1 FROM t1; |
| 64 |
|
| 65 |
USE db2; |
| 66 |
|
| 67 |
SELECT * FROM db1.nonexistent_table1; |
| 68 |
SELECT * FROM db2.nonexistent_table2; |
| 69 |
--error ER_NO_SUCH_TABLE |
| 70 |
SELECT * FROM nonexistent_table_db1; |
| 71 |
SELECT * FROM nonexistent_table_db2; |
| 72 |
SELECT * FROM test.t1; |
| 73 |
--error ER_NO_SUCH_TABLE |
| 74 |
SELECT 1 FROM t1; |
| 75 |
|
| 76 |
DROP DATABASE db1; |
| 77 |
DROP DATABASE db2; |
| 78 |
USE test; |
| 79 |
DROP TABLE t1; |
| 80 |
--source suite/query_rewrite_plugins/include/uninstall_rewriter.inc |