8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

7.6.4 重写器查询重写插件7.6.4 The Rewriter Query Rewrite Plugin

MySQL 支持查询重写插件,这些插件可以在服务器执行收到的 SQL 语句之前检查并可能修改这些语句。请参见 查询重写插件。MySQL supports query rewrite plugins that can examine and possibly modify SQL statements received by the server before the server executes them. See Query Rewrite Plugins.

MySQL 发行版包括一个名为 Rewriter 的后解析查询重写插件以及用于安装该插件及其相关元素的脚本。这些元素协同工作以提供语句重写功能:MySQL distributions include a postparse query rewrite plugin named Rewriter and scripts for installing the plugin and its associated elements. These elements work together to provide statement-rewriting capability:

  • 一个名为Rewriter的服务器端插件会检查语句,并可能基于其内存中的重写规则缓存对它们进行重写。A server-side plugin named Rewriter examines statements and may rewrite them, based on its in-memory cache of rewrite rules.

  • 这些语句可能会被重写:SELECT、INSERT、REPLACE、UPDATE 和 DELETE。These statements are subject to rewriting: SELECT, INSERT, REPLACE, UPDATE, and DELETE.

    独立语句和预处理语句可以被重写。发生在视图定义或存储程序中的语句不受重写的影响。Standalone statements and prepared statements are subject to rewriting. Statements occurring within view definitions or stored programs are not subject to rewriting.

  • Rewriter 插件使用一个名为 query_rewrite 的数据库,其中包含一个名为 rewrite_rules 的表。该表为插件用于决定是否重写语句的规则提供持久存储。用户通过修改存储在此表中的规则集合与插件进行通信。插件通过设置表行的 message 列与用户通信。The Rewriter plugin uses a database named query_rewrite containing a table named rewrite_rules. The table provides persistent storage for the rules that the plugin uses to decide whether to rewrite statements. Users communicate with the plugin by modifying the set of rules stored in this table. The plugin communicates with users by setting the message column of table rows.

  • query_rewrite 数据库包含一个名为 flush_rewrite_rules() 的存储过程,用于将规则表的内容加载到插件中。The query_rewrite database contains a stored procedure named flush_rewrite_rules() that loads the contents of the rules table into the plugin.

  • 一个可加载的函数,名为 load_rewrite_rules(),被 flush_rewrite_rules() 存储过程使用。A loadable function named load_rewrite_rules() is used by the flush_rewrite_rules() stored procedure.

  • Rewriter 插件公开系统变量,用于插件配置,以及提供运行时操作信息的状态变量。该插件还支持一个特权 (SKIP_QUERY_REWRITE),可以保护指定用户的查询不被重写。The Rewriter plugin exposes system variables that enable plugin configuration and status variables that provide runtime operational information. This plugin also supports a privilege (SKIP_QUERY_REWRITE) that protects a given user's queries from being rewritten.

下面的部分介绍如何安装和使用 Rewriter 插件,并提供其相关元素的参考信息。The following sections describe how to install and use the Rewriter plugin, and provide reference information for its associated elements.