MySQL 8.0 Query Rewrite support SELECT INSERT UPDETE DELETE REPLACE statement rewrite
This feature points praise, such as the development of on-line, there is a SQL query forget to add a field index, directly to the online CPU played, this time, you can SQL rewrite, so business first error, do not kill the database, and then immediately inform the development of rollback, and other on-line index after the completion of the addition.
Install plug
mysql -S /tmp/mysql_hcy.sock -p123456 <./install_rewriter.sql
Check whether the entry into force
SHOW GLOBAL VARIABLES LIKE 'rewriter_enabled';
Write rewrite rules
insert into query_rewrite.rewrite_rules(pattern, replacement, pattern_database) values ( "SELECT * from sbtest1 limit ?", "SELECT k,c from sbtest1 limit ?", "test");
Meaning:
The following statement
SELECT * from sbtest1 limit ?;
Rewritten as:
SELECT k,c from sbtest1 limit ?;
Note: Question mark ? Variable
Implementation of the rules to take effect
CALL query_rewrite.flush_rewrite_rules();
Show
mysql> SELECT * from sbtest1 limit 1\G; *************************** 1. row *************************** k: 499284 c: 83868641912-28773972837-60736120486-75162659906-27563526494-20381887404-41576422241-93426793964-56405065102-33518432330 1 row in set, 1 warning (0.00 sec) ERROR: No query specified mysql> show warnings\G *************************** 1. row *************************** Level: Note Code: 1105 Message: Query 'SELECT * from sbtest1 limit 1' rewritten to 'SELECT k,c from sbtest1 limit 1' by a query rewrite plugin 1 row in set (0.00 sec)