Home >Database >Mysql Tutorial >MySQL Query Rewrite Plugin使用

MySQL Query Rewrite Plugin使用

黄舟
黄舟Original
2017-02-07 11:45:261728browse

Here is a brief introduction:

This feature will be officially introduced after MySQL 5.7.6. , it can be rewritten and executed after receiving the SQL on the server side.

•Only works for standard SELECT statements, and cannot rewrite SELECT statements in view definitions and stored procedures

•Rewrite rules are recorded in memory, and actually correspond to: rewrite_rules under the query_rewrite library Table

•Use the stored procedure under query_rewrite: flush_rewrite_rules() and DML statements to load change rules


Think about it and need to add:

In this PPT, I talked about an example of using subquery to optimize inner join, and using subquery to reduce the removal of the previous part. There is a requirement here, that is, the first query needs to be a primary key or a unique index. Look at the picture:

MySQL Query Rewrite Plugin使用

By the way, the execution logic of this piece: For 5.6 and later, subqueries are equivalent to using materialized views later. In the query logic, it is judged IN Whether the previous option is at the back (so we don’t care if there is a duplication in the back, we only ask whether there is one), so if the front is a primary key or a unique index, it will have the effect of deduplication and reduce Group by operations. A small tip.

The above is the content used by MySQL Query Rewrite Plugin. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn