MySQL Rewriter Query Rewrite Plugin

Posted 雪胖胖?

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL Rewriter Query Rewrite Plugin相关的知识,希望对你有一定的参考价值。

简单的说一下,就是查询重新的插件,和Oracle 物化视图的查询重写还不太一样

Server version: 5.7.19-17-log Percona Server (GPL), Release 17, Revision e19a6b7b73f
OS version: Red Hat Enterprise Linux Server release 6.3 (Santiago)

安装

1. 安装路径
mysql 目录下是 share 目录下,有个install_rewriter.sql 
2. 安装
mysql> source install_rewriter.sql
Query OK, 1 row affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

3. 检查 是否启用
mysql> SHOW GLOBAL VARIABLES LIKE \'rewriter_enabled\';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| rewriter_enabled | ON    |
+------------------+-------+
1 row in set (0.01 sec)
配置文件中增加以下这段
[mysqld]
rewriter_enabled=ON


在线修改
SET GLOBAL rewriter_enabled = ON;
SET GLOBAL rewriter_enabled = OFF;
mysql>   INSERT INTO query_rewrite.rewrite_rules (pattern, replacement) VALUES(\'SELECT ?\', \'SELECT ? + 1\');
Query OK, 1 row affected (0.00 sec)

mysql>  SELECT * FROM query_rewrite.rewrite_rules\\G
*************************** 1. row ***************************
                id: 1
           pattern: SELECT ?
  pattern_database: NULL
       replacement: SELECT ? + 1
           enabled: YES
           message: NULL
    pattern_digest: NULL
normalized_pattern: NULL
1 row in set (0.01 sec)

mysql> CALL query_rewrite.flush_rewrite_rules();
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM query_rewrite.rewrite_rules\\G
*************************** 1. row ***************************
                id: 1
           pattern: SELECT ?
  pattern_database: NULL
       replacement: SELECT ? + 1
           enabled: YES
           message: NULL
    pattern_digest: 512e888765927f4393e9f938df43b1ec
normalized_pattern: select ?
1 row in set (0.00 sec)

mysql> CALL query_rewrite.flush_rewrite_rules();
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM query_rewrite.rewrite_rules\\G
*************************** 1. row ***************************
                id: 1
           pattern: SELECT ?
  pattern_database: NULL
       replacement: SELECT ? + 1
           enabled: YES
           message: NULL
    pattern_digest: 512e888765927f4393e9f938df43b1ec
normalized_pattern: select ?
1 row in set (0.00 sec)

mysql> SELECT PI();
+----------+
| PI()     |
+----------+
| 3.141593 |
+----------+
1 row in set (0.00 sec)

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

mysql> SELECT 11;
+--------+
| 11 + 1 |
+--------+
|     12 |
+--------+
1 row in set, 1 warning (0.00 sec)

mysql> SHOW WARNINGS\\G
*************************** 1. row ***************************
  Level: Note
   Code: 1105
Message: Query \'SELECT 11\' rewritten to \'SELECT 11 + 1\' by a query rewrite plugin
1 row in set (0.00 sec)


关闭规则
UPDATE query_rewrite.rewrite_rules SET enabled = \'NO\' WHERE id = 1;
CALL query_rewrite.flush_rewrite_rules();


mysql> SELECT * FROM query_rewrite.rewrite_rules\\G
*************************** 1. row ***************************
                id: 1
           pattern: SELECT ?
  pattern_database: NULL
       replacement: SELECT ? + 1
           enabled: NO
           message: NULL
    pattern_digest: 512e888765927f4393e9f938df43b1ec
normalized_pattern: select ?
1 row in set (0.00 sec)

mysql> SELECT 11;
+----+
| 11 |
+----+
| 11 |
+----+
1 row in set (0.00 sec)

启用规则
UPDATE query_rewrite.rewrite_rules SET enabled = \'YES\' WHERE id = 1;
CALL query_rewrite.flush_rewrite_rules();

以上是关于MySQL Rewriter Query Rewrite Plugin的主要内容,如果未能解决你的问题,请参考以下文章

Sling Rewriter 更改静态资源 URL

动态网页转伪静态

301 Htaccess 重写规则查询字符串

使用 mod_rewrite 重定向查询字符串(反之亦然)

Tensorflow ValueError: Protocol message RewriterConfig has no "layout_optimizer" field(示例代

来自 KLEE 的 Z3 无限循环