Debian Codegraph @

mysql-test/suite/query_rewrite_plugins/r/schema.result

raw
1 #
2 # Test of rewrites of queries where the database (a.k.a. schema) is not
3 # specified in the pattern.
4 #
5 # MySQL behaves in the most peculiar way in this respect. Some
6 # explanation is order here: When a query is parsed, the
7 # parser injects the current database when parsing a table name, i.e.
8 # 'table' is _parsed_ as '<current database>.table'.
9 #
10 # The session that loads the rules has no current database, so the rule
11 # has to specify it if there are unqualified table names in the pattern.
12 #
13 CALL mtr.add_suppression("Plugin rewriter reported: 'Some rules failed to load.'");
14 CREATE DATABASE db1;
15 CREATE DATABASE db2;
16 CREATE TABLE t1 ( a VARCHAR(23) );
17 INSERT INTO t1 VALUES ( 'This was not rewritten.' );
18 # Query rewrite plugin was installed.
19 INSERT
20 INTO query_rewrite.rewrite_rules ( pattern, pattern_database, replacement )
21 VALUES ( 'SELECT * FROM db1.nonexistent_table1', NULL, 'SELECT "Rule #1"' ),
22 ( 'SELECT * FROM db2.nonexistent_table2', NULL, 'SELECT "Rule #2"' ),
23 ( 'SELECT * FROM nonexistent_table_db1', 'db1', 'SELECT "Rule #3"' ),
24 ( 'SELECT * FROM nonexistent_table_db2', 'db2', 'SELECT "Rule #4"' ),
25 ( 'SELECT * FROM nonexistent_table', NULL, 'SELECT "Rule #5"' ),
26 ( 'SELECT * FROM test.t1', 'test', 'SELECT "Rule #6"' ),
27 ( 'SELECT 1 FROM t1', 'test', 'SELECT 4 FROM t1' ),
28 ( 'SELECT 2 FROM t1', NULL, 'SELECT 5 FROM t1' ),
29 ( 'SELECT 3 FROM test.t1', NULL, 'SELECT 6 FROM t1' );
30 CALL query_rewrite.flush_rewrite_rules();
31 ERROR 45000: Loading of some rule(s) failed.
32 SELECT * FROM query_rewrite.rewrite_rules;
33 id pattern pattern_database replacement enabled message
34 1 SELECT * FROM db1.nonexistent_table1 NULL SELECT "Rule #1" YES NULL
35 2 SELECT * FROM db2.nonexistent_table2 NULL SELECT "Rule #2" YES NULL
36 3 SELECT * FROM nonexistent_table_db1 db1 SELECT "Rule #3" YES NULL
37 4 SELECT * FROM nonexistent_table_db2 db2 SELECT "Rule #4" YES NULL
38 5 SELECT * FROM nonexistent_table NULL SELECT "Rule #5" YES Parse error in pattern: >>No database selected<<
39 6 SELECT * FROM test.t1 test SELECT "Rule #6" YES NULL
40 7 SELECT 1 FROM t1 test SELECT 4 FROM t1 YES NULL
41 8 SELECT 2 FROM t1 NULL SELECT 5 FROM t1 YES Parse error in pattern: >>No database selected<<
42 9 SELECT 3 FROM test.t1 NULL SELECT 6 FROM t1 YES Parse error in replacement: >>No database selected<<
43 USE test;
44 SELECT * FROM db1.nonexistent_table1;
45 Rule #1
46 Rule #1
47 Warnings:
48 Note 1105 Query 'SELECT * FROM db1.nonexistent_table1' rewritten to 'SELECT "Rule #1"' by a query rewrite plugin
49 SELECT * FROM db2.nonexistent_table2;
50 Rule #2
51 Rule #2
52 Warnings:
53 Note 1105 Query 'SELECT * FROM db2.nonexistent_table2' rewritten to 'SELECT "Rule #2"' by a query rewrite plugin
54 SELECT * FROM nonexistent_table_db1;
55 ERROR 42S02: Table 'test.nonexistent_table_db1' doesn't exist
56 SELECT * FROM nonexistent_table_db2;
57 ERROR 42S02: Table 'test.nonexistent_table_db2' doesn't exist
58 SELECT * FROM test.t1;
59 Rule #6
60 Rule #6
61 Warnings:
62 Note 1105 Query 'SELECT * FROM test.t1' rewritten to 'SELECT "Rule #6"' by a query rewrite plugin
63 SELECT 1 FROM t1;
64 4
65 4
66 Warnings:
67 Note 1105 Query 'SELECT 1 FROM t1' rewritten to 'SELECT 4 FROM t1' by a query rewrite plugin
68 USE db1;
69 SELECT * FROM db1.nonexistent_table1;
70 Rule #1
71 Rule #1
72 Warnings:
73 Note 1105 Query 'SELECT * FROM db1.nonexistent_table1' rewritten to 'SELECT "Rule #1"' by a query rewrite plugin
74 SELECT * FROM db2.nonexistent_table2;
75 Rule #2
76 Rule #2
77 Warnings:
78 Note 1105 Query 'SELECT * FROM db2.nonexistent_table2' rewritten to 'SELECT "Rule #2"' by a query rewrite plugin
79 SELECT * FROM nonexistent_table_db1;
80 Rule #3
81 Rule #3
82 Warnings:
83 Note 1105 Query 'SELECT * FROM nonexistent_table_db1' rewritten to 'SELECT "Rule #3"' by a query rewrite plugin
84 SELECT * FROM nonexistent_table_db2;
85 ERROR 42S02: Table 'db1.nonexistent_table_db2' doesn't exist
86 SELECT * FROM test.t1;
87 Rule #6
88 Rule #6
89 Warnings:
90 Note 1105 Query 'SELECT * FROM test.t1' rewritten to 'SELECT "Rule #6"' by a query rewrite plugin
91 SELECT 1 FROM t1;
92 ERROR 42S02: Table 'db1.t1' doesn't exist
93 USE db2;
94 SELECT * FROM db1.nonexistent_table1;
95 Rule #1
96 Rule #1
97 Warnings:
98 Note 1105 Query 'SELECT * FROM db1.nonexistent_table1' rewritten to 'SELECT "Rule #1"' by a query rewrite plugin
99 SELECT * FROM db2.nonexistent_table2;
100 Rule #2
101 Rule #2
102 Warnings:
103 Note 1105 Query 'SELECT * FROM db2.nonexistent_table2' rewritten to 'SELECT "Rule #2"' by a query rewrite plugin
104 SELECT * FROM nonexistent_table_db1;
105 ERROR 42S02: Table 'db2.nonexistent_table_db1' doesn't exist
106 SELECT * FROM nonexistent_table_db2;
107 Rule #4
108 Rule #4
109 Warnings:
110 Note 1105 Query 'SELECT * FROM nonexistent_table_db2' rewritten to 'SELECT "Rule #4"' by a query rewrite plugin
111 SELECT * FROM test.t1;
112 Rule #6
113 Rule #6
114 Warnings:
115 Note 1105 Query 'SELECT * FROM test.t1' rewritten to 'SELECT "Rule #6"' by a query rewrite plugin
116 SELECT 1 FROM t1;
117 ERROR 42S02: Table 'db2.t1' doesn't exist
118 DROP DATABASE db1;
119 DROP DATABASE db2;
120 USE test;
121 DROP TABLE t1;
122 Warnings:
123 Warning 1620 Plugin is busy and will be uninstalled on shutdown
124 # Query rewrite plugin was queued for uninstalling.