Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / MySQL Server Administration  / MySQL Server Plugins  /  The Rewriter Query Rewrite Plugin

7.6.4 The Rewriter Query Rewrite Plugin

MySQL supports query rewrite plugins that can examine and possibly modify SQL statements received by the server before the server executes them. SeeQuery Rewrite Plugins.

MySQL distributions include a postparse query rewrite plugin namedRewriter and scripts for installing the plugin and its associated elements. These elements work together to provide statement-rewriting capability:

  • A server-side plugin namedRewriter examines statements and may rewrite them, based on its in-memory cache of rewrite rules.

  • These statements are subject to rewriting:SELECT,INSERT,REPLACE,UPDATE, andDELETE.

    Standalone statements and prepared statements are subject to rewriting. Statements occurring within view definitions or stored programs are not subject to rewriting.

  • TheRewriter plugin uses a database namedquery_rewrite containing a table namedrewrite_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 themessage column of table rows.

  • Thequery_rewrite database contains a stored procedure namedflush_rewrite_rules() that loads the contents of the rules table into the plugin.

  • A loadable function namedload_rewrite_rules() is used by theflush_rewrite_rules() stored procedure.

  • TheRewriter 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.

The following sections describe how to install and use theRewriter plugin, and provide reference information for its associated elements.