mysql> SELECT PI(); +----------+ | PI() | +----------+ | 3.141593 | +----------+ 1 row in set (0.01 sec) mysql> SELECT 10; +--------+ | 10 + 1 | +--------+ | 11 | +--------+ 1 row in set, 1 warning (0.00 sec) 

No rewriting occurs for the first SELECT  statement, but does for the second. The second statement illustrates that when the Rewriter  plugin rewrites a statement, it produces a warning message. To view the message, use SHOW WARNINGS : 

mysql> SHOW WARNINGS\G *************************** 1. row *************************** Level: Note Code: 1105 Message: Query ’SELECT 10’ rewritten to ’SELECT 10 + 1’ by a query rewrite plugin 

A statement need not be rewritten to a statement of the same type. The following example loads a rule that rewrites DELETE  statements to UPDATE  statements: 

INSERT INTO query_rewrite.rewrite_rules (pattern, replacement) VALUES(’DELETE FROM db1.t1 WHERE col = ?’, ’UPDATE db1.t1 SET col = NULL WHERE col = ?’); CALL query_rewrite.flush_rewrite_rules(); 

To enable or disable an existing rule, modify its enabled  column and reload the table into the plugin. To disable rule 1: 

UPDATE query_rewrite.rewrite_rules SET enabled = ’NO’ WHERE id = 1; CALL query_rewrite.flush_rewrite_rules(); 

This enables you to deactivate a rule without removing it from the table. 

To re-enable rule 1: 

UPDATE query_rewrite.rewrite_rules SET enabled = ’YES’ WHERE id = 1; CALL query_rewrite.flush_rewrite_rules(); 

The rewrite_rules  table contains a pattern_database  column that Rewriter  uses for matching table names that are not qualified with a database name: 

•Qualified table names in statements match qualified names in the pattern if corresponding database and table names are identical. 

•Unqualified table names in statements match unqualified names in the pattern only if the default database is the same as pattern_database  and the table names are identical. 

Suppose that a table named appdb.users  has a column named id  and that applications are expected to select rows from the table using a query of one of these forms, where the second can be used only if appdb  is the default database: 

SELECT * FROM users WHERE appdb.id = id_value ; SELECT * FROM users WHERE id = id_value ; 

