利用函数 statement_digest_text 来定制这条 SQL 的重写规则。
mysql> INSERT INTO query_rewrite.rewrite_rules (pattern, replacement,pattern_database)
-> VALUES(
-> statement_digest_text('delete from p1 where id = 1000') ,
-> statement_digest_text('delete from p1 where id = -1'),
-> 'ytt'
-> );
Query OK, 1 row affected (0.01 sec)
mysql> CALL query_rewrite.flush_rewrite_rules();
Query OK, 1 row affected (0.02 sec)
mysql> select * from query_rewrite.rewrite_rules\G
*************************** 1. row ***************************
id: 1
pattern: DELETE FROM `p1` WHERE `id` = ?
pattern_database: ytt
replacement: DELETE FROM `p1` WHERE `id` = - ?
enabled: YES
message: NULL
pattern_digest: a09b20197de495d603324d6ed617cb5d05fa0e3011bea8e9db7d2939df22940a
normalized_pattern: delete from `ytt`.`p1` where (`id` = ?)
1 row in set (0.00 sec)