<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="rewriter-query-rewrite-plugin-usage">
      </a>
      7.6.4.2 Using the Rewriter Query Rewrite Plugin
     </h4>
    </div>
   </div>
  </div>
  <p>
   To enable or disable the plugin, enable or disable the
   <a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled">
    <code class="literal">
     rewriter_enabled
    </code>
   </a>
   system
        variable. By default, the
   <code class="literal">
    Rewriter
   </code>
   plugin is
        enabled when you install it (see
   <a class="xref" href="rewriter-query-rewrite-plugin-installation.html" title="7.6.4.1 Installing or Uninstalling the Rewriter Query Rewrite Plugin">
    Section 7.6.4.1, “Installing or Uninstalling the Rewriter Query Rewrite Plugin”
   </a>
   ).
        To set the initial plugin state explicitly, you can set the
        variable at server startup. For example, to enable the plugin in
        an option file, use these lines:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa54808730"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">rewriter_enabled</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre>
  </div>
  <p>
   It is also possible to enable or disable the plugin at runtime:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa61373254"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> rewriter_enabled <span class="token operator">=</span> <span class="token keyword">ON</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token keyword">GLOBAL</span> rewriter_enabled <span class="token operator">=</span> <span class="token keyword">OFF</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Assuming that the
   <code class="literal">
    Rewriter
   </code>
   plugin is enabled,
        it examines and possibly modifies each rewritable statement
        received by the server. The plugin determines whether to rewrite
        statements based on its in-memory cache of rewriting rules,
        which are loaded from the
   <code class="literal">
    rewrite_rules
   </code>
   table
        in the
   <code class="literal">
    query_rewrite
   </code>
   database.
  </p>
  <p>
   These statements are subject to rewriting:
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   ,
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
    </code>
   </a>
   ,
   <a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
    <code class="literal">
     REPLACE
    </code>
   </a>
   ,
   <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
    <code class="literal">
     UPDATE
    </code>
   </a>
   , and
   <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
    <code class="literal">
     DELETE
    </code>
   </a>
   .
  </p>
  <p>
   Standalone statements and prepared statements are subject to
        rewriting. Statements occurring within view definitions or
        stored programs are not subject to rewriting.
  </p>
  <p>
   Statements run by users with the
   <a class="link" href="privileges-provided.html#priv_skip-query-rewrite">
    <code class="literal">
     SKIP_QUERY_REWRITE
    </code>
   </a>
   privilege are
        not subject to rewriting, provided that the
   <a class="link" href="rewriter-query-rewrite-plugin-reference.html#sysvar_rewriter_enabled_for_threads_without_privilege_checks">
    <code class="literal">
     rewriter_enabled_for_threads_without_privilege_checks
    </code>
   </a>
   system variable is set to
   <code class="literal">
    OFF
   </code>
   (default
   <code class="literal">
    ON
   </code>
   ). This can be used for control statements
        and statements that should be replicated unchanged, such as
        those from the
   <code class="literal">
    SOURCE_USER
   </code>
   specified by
   <a class="link" href="change-replication-source-to.html" title="15.4.2.2 CHANGE REPLICATION SOURCE TO Statement">
    <code class="literal">
     CHANGE REPLICATION SOURCE TO
    </code>
   </a>
   .
        This is also true for statements executed by MySQL client
        programs including
   <a class="link" href="mysqlbinlog.html" title="6.6.9 mysqlbinlog — Utility for Processing Binary Log Files">
    <span class="command">
     <strong>
      mysqlbinlog
     </strong>
    </span>
   </a>
   ,
   <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
    <span class="command">
     <strong>
      mysqladmin
     </strong>
    </span>
   </a>
   , and
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   ;
        for this reason, you should grant
   <code class="literal">
    SKIP_QUERY_REWRITE
   </code>
   to the user account or
        accounts used by these utilities to connect to MySQL.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="rewriter-query-rewrite-plugin-usage.html#rewriter-query-rewrite-plugin-adding-rewrite-rules" title="Adding Rewrite Rules">
       Adding Rewrite Rules
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="rewriter-query-rewrite-plugin-usage.html#rewriter-query-rewrite-plugin-how-statement-matching-works" title="How Statement Matching Works">
       How Statement Matching Works
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="rewriter-query-rewrite-plugin-usage.html#rewriter-query-rewrite-plugin-rewriting-prepared-statements" title="Rewriting Prepared Statements">
       Rewriting Prepared Statements
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="rewriter-query-rewrite-plugin-usage.html#rewriter-query-rewrite-plugin-operational-information" title="Rewriter Plugin Operational Information">
       Rewriter Plugin Operational Information
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="rewriter-query-rewrite-plugin-usage.html#rewriter-query-rewrite-plugin-use-of-character-sets" title="Rewriter Plugin Use of Character Sets">
       Rewriter Plugin Use of Character Sets
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="rewriter-query-rewrite-plugin-adding-rewrite-rules">
       </a>
       Adding Rewrite Rules
      </h5>
     </div>
    </div>
   </div>
   <p>
    To add rules for the
    <code class="literal">
     Rewriter
    </code>
    plugin, add
          rows to the
    <code class="literal">
     rewrite_rules
    </code>
    table, then
          invoke the
    <code class="literal">
     flush_rewrite_rules()
    </code>
    stored
          procedure to load the rules from the table into the plugin.
          The following example creates a simple rule to match
          statements that select a single literal value:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa3812899"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules <span class="token punctuation">(</span>pattern<span class="token punctuation">,</span> replacement<span class="token punctuation">)</span>
<span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">'SELECT ?'</span><span class="token punctuation">,</span> <span class="token string">'SELECT ? + 1'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The resulting table contents look like this:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42413294"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
                id<span class="token punctuation">:</span> 1
           pattern<span class="token punctuation">:</span> SELECT ?
  pattern_database<span class="token punctuation">:</span> NULL
       replacement<span class="token punctuation">:</span> SELECT ? + 1
           enabled<span class="token punctuation">:</span> YES
           message<span class="token punctuation">:</span> NULL
    pattern_digest<span class="token punctuation">:</span> NULL
normalized_pattern<span class="token punctuation">:</span> NULL</span></code></pre>
   </div>
   <p>
    The rule specifies a pattern template indicating which
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    statements to match, and
          a replacement template indicating how to rewrite matching
          statements. However, adding the rule to the
    <code class="literal">
     rewrite_rules
    </code>
    table is not sufficient to
          cause the
    <code class="literal">
     Rewriter
    </code>
    plugin to use the rule.
          You must invoke
    <code class="literal">
     flush_rewrite_rules()
    </code>
    to
          load the table contents into the plugin in-memory cache:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa96933289"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Tip
    </div>
    <p>
     If your rewrite rules seem not to be working properly, make
            sure that you have reloaded the rules table by calling
     <code class="literal">
      flush_rewrite_rules()
     </code>
     .
    </p>
   </div>
   <p>
    When the plugin reads each rule from the rules table, it
          computes a normalized (statement digest) form from the pattern
          and a digest hash value, and uses them to update the
    <code class="literal">
     normalized_pattern
    </code>
    and
    <code class="literal">
     pattern_digest
    </code>
    columns:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47603929"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
                id<span class="token punctuation">:</span> 1
           pattern<span class="token punctuation">:</span> SELECT ?
  pattern_database<span class="token punctuation">:</span> NULL
       replacement<span class="token punctuation">:</span> SELECT ? + 1
           enabled<span class="token punctuation">:</span> YES
           message<span class="token punctuation">:</span> NULL
    pattern_digest<span class="token punctuation">:</span> d1b44b0c19af710b5a679907e284acd2ddc285201794bc69a2389d77baedddae
normalized_pattern<span class="token punctuation">:</span> select ?</span></code></pre>
   </div>
   <p>
    For information about statement digesting, normalized
          statements, and digest hash values, see
    <a class="xref" href="performance-schema-statement-digests.html" title="29.10 Performance Schema Statement Digests and Sampling">
     Section 29.10, “Performance Schema Statement Digests and Sampling”
    </a>
    .
   </p>
   <p>
    If a rule cannot be loaded due to some error, calling
    <code class="literal">
     flush_rewrite_rules()
    </code>
    produces an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa21291253"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1644 (45000)<span class="token punctuation">:</span> Loading of some rule(s) failed.</span></code></pre>
   </div>
   <p>
    When this occurs, the plugin writes an error message to the
    <code class="literal">
     message
    </code>
    column of the rule row to
          communicate the problem. Check the
    <code class="literal">
     rewrite_rules
    </code>
    table for rows with
          non-
    <code class="literal">
     NULL
    </code>
    <code class="literal">
     message
    </code>
    column
          values to see what problems exist.
   </p>
   <p>
    Patterns use the same syntax as prepared statements (see
    <a class="xref" href="prepare.html" title="15.5.1 PREPARE Statement">
     Section 15.5.1, “PREPARE Statement”
    </a>
    ). Within a pattern template,
    <code class="literal">
     ?
    </code>
    characters act as parameter markers that
          match data values. The
    <code class="literal">
     ?
    </code>
    characters should
          not be enclosed within quotation marks. Parameter markers can
          be used only where data values should appear, and they cannot
          be used for SQL keywords, identifiers, functions, and so on.
          The plugin parses a statement to identify the literal values
          (as defined in
    <a class="xref" href="literals.html" title="11.1 Literal Values">
     Section 11.1, “Literal Values”
    </a>
    ), so you can put a
          parameter marker in place of any literal value.
   </p>
   <p>
    Like the pattern, the replacement can contain
    <code class="literal">
     ?
    </code>
    characters. For a statement that matches
          a pattern template, the plugin rewrites it, replacing
    <code class="literal">
     ?
    </code>
    parameter markers in the replacement
          using data values matched by the corresponding markers in the
          pattern. The result is a complete statement string. The plugin
          asks the server to parse it, and returns the result to the
          server as the representation of the rewritten statement.
   </p>
   <p>
    After adding and loading the rule, check whether rewriting
          occurs according to whether statements match the rule pattern:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa75652750"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">PI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> PI()     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 3.141593 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.01 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 10 <span class="token punctuation">+</span> 1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>     11 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set, 1 warning (0.00 sec)</span></code></pre>
   </div>
   <p>
    No rewriting occurs for the first
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    statement, but does for
          the second. The second statement illustrates that when the
    <code class="literal">
     Rewriter
    </code>
    plugin rewrites a statement, it
          produces a warning message. To view the message, use
    <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
     <code class="literal">
      SHOW WARNINGS
     </code>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99112774"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
  Level<span class="token punctuation">:</span> Note
   Code<span class="token punctuation">:</span> 1105
Message<span class="token punctuation">:</span> Query 'SELECT 10' rewritten to 'SELECT 10 + 1' by a query rewrite plugin</span></code></pre>
   </div>
   <p>
    A statement need not be rewritten to a statement of the same
          type. The following example loads a rule that rewrites
    <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
     <code class="literal">
      DELETE
     </code>
    </a>
    statements to
    <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
     <code class="literal">
      UPDATE
     </code>
    </a>
    statements:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40598111"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules <span class="token punctuation">(</span>pattern<span class="token punctuation">,</span> replacement<span class="token punctuation">)</span>
<span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token string">'DELETE FROM db1.t1 WHERE col = ?'</span><span class="token punctuation">,</span>
       <span class="token string">'UPDATE db1.t1 SET col = NULL WHERE col = ?'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    To enable or disable an existing rule, modify its
    <code class="literal">
     enabled
    </code>
    column and reload the table into
          the plugin. To disable rule 1:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32335112"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">UPDATE</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules <span class="token keyword">SET</span> enabled <span class="token operator">=</span> <span class="token string">'NO'</span> <span class="token keyword">WHERE</span> id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    This enables you to deactivate a rule without removing it from
          the table.
   </p>
   <p>
    To re-enable rule 1:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa76374328"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">UPDATE</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules <span class="token keyword">SET</span> enabled <span class="token operator">=</span> <span class="token string">'YES'</span> <span class="token keyword">WHERE</span> id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The
    <code class="literal">
     rewrite_rules
    </code>
    table contains a
    <code class="literal">
     pattern_database
    </code>
    column that
    <code class="literal">
     Rewriter
    </code>
    uses for matching table names that
          are not qualified with a database name:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Qualified table names in statements match qualified names
              in the pattern if corresponding database and table names
              are identical.
      </p>
     </li>
     <li class="listitem">
      <p>
       Unqualified table names in statements match unqualified
              names in the pattern only if the default database is the
              same as
       <code class="literal">
        pattern_database
       </code>
       and the table
              names are identical.
      </p>
     </li>
    </ul>
   </div>
   <p>
    Suppose that a table named
    <code class="literal">
     appdb.users
    </code>
    has
          a column named
    <code class="literal">
     id
    </code>
    and that applications are
          expected to select rows from the table using a query of one of
          these forms, where the second can be used when
    <code class="literal">
     appdb
    </code>
    is the default database:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa69960966"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> users <span class="token keyword">WHERE</span> appdb<span class="token punctuation">.</span>id <span class="token operator">=</span> <em class="replaceable">id_value</em><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> users <span class="token keyword">WHERE</span> id <span class="token operator">=</span> <em class="replaceable">id_value</em><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Suppose also that the
    <code class="literal">
     id
    </code>
    column is renamed
          to
    <code class="literal">
     user_id
    </code>
    (perhaps the table must be
          modified to add another type of ID and it is necessary to
          indicate more specifically what type of ID the
    <code class="literal">
     id
    </code>
    column represents).
   </p>
   <p>
    The change means that applications must refer to
    <code class="literal">
     user_id
    </code>
    rather than
    <code class="literal">
     id
    </code>
    in the
    <code class="literal">
     WHERE
    </code>
    clause, but old applications
          that cannot be updated no longer work properly. The
    <code class="literal">
     Rewriter
    </code>
    plugin can solve this problem by
          matching and rewriting problematic statements. To match the
          statement
    <code class="literal">
     SELECT * FROM appdb.users WHERE id =
     <em class="replaceable">
      <code>
       value
      </code>
     </em>
    </code>
    and rewrite it as
    <code class="literal">
     SELECT * FROM appdb.users WHERE user_id =
     <em class="replaceable">
      <code>
       value
      </code>
     </em>
    </code>
    , you can insert a
          row representing a replacement rule into the rewrite rules
          table. If you also want to match this
    <code class="literal">
     SELECT
    </code>
    using the unqualified table name, it
          is also necessary to add an explicit rule. Using
    <code class="literal">
     ?
    </code>
    as a value placeholder, the two
    <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
     <code class="literal">
      INSERT
     </code>
    </a>
    statements needed look
          like this:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa45974196"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules
    <span class="token punctuation">(</span>pattern<span class="token punctuation">,</span> replacement<span class="token punctuation">)</span> <span class="token keyword">VALUES</span><span class="token punctuation">(</span>
    <span class="token string">'SELECT * FROM appdb.users WHERE id = ?'</span><span class="token punctuation">,</span>
    <span class="token string">'SELECT * FROM appdb.users WHERE user_id = ?'</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> query_rewrite<span class="token punctuation">.</span>rewrite_rules
    <span class="token punctuation">(</span>pattern<span class="token punctuation">,</span> replacement<span class="token punctuation">,</span> pattern_database<span class="token punctuation">)</span> <span class="token keyword">VALUES</span><span class="token punctuation">(</span>
    <span class="token string">'SELECT * FROM users WHERE id = ?'</span><span class="token punctuation">,</span>
    <span class="token string">'SELECT * FROM users WHERE user_id = ?'</span><span class="token punctuation">,</span>
    <span class="token string">'appdb'</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    After adding the two new rules, execute the following
          statement to cause them to take effect:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa39166423"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    <code class="literal">
     Rewriter
    </code>
    uses the first rule to match
          statements that use the qualified table name, and the second
          to match statements that use the unqualified name. The second
          rule works only when
    <code class="literal">
     appdb
    </code>
    is the default
          database.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="rewriter-query-rewrite-plugin-how-statement-matching-works">
       </a>
       How Statement Matching Works
      </h5>
     </div>
    </div>
   </div>
   <p>
    The
    <code class="literal">
     Rewriter
    </code>
    plugin uses statement digests
          and digest hash values to match incoming statements against
          rewrite rules in stages. The
    <code class="literal">
     max_digest_length
    </code>
    system variable
          determines the size of the buffer used for computing statement
          digests. Larger values enable computation of digests that
          distinguish longer statements. Smaller values use less memory
          but increase the likelihood of longer statements colliding
          with the same digest value.
   </p>
   <p>
    The plugin matches each statement to the rewrite rules as
          follows:
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Compute the statement digest hash value and compare it to
              the rule digest hash values. This is subject to false
              positives, but serves as a quick rejection test.
      </p>
     </li>
     <li class="listitem">
      <p>
       If the statement digest hash value matches any pattern
              digest hash values, match the normalized (statement
              digest) form of the statement to the normalized form of
              the matching rule patterns.
      </p>
     </li>
     <li class="listitem">
      <p>
       If the normalized statement matches a rule, compare the
              literal values in the statement and the pattern. A
       <code class="literal">
        ?
       </code>
       character in the pattern matches any
              literal value in the statement. If the statement prepares
              a statement,
       <code class="literal">
        ?
       </code>
       in the pattern also
              matches
       <code class="literal">
        ?
       </code>
       in the statement. Otherwise,
              corresponding literals must be the same.
      </p>
     </li>
    </ol>
   </div>
   <p>
    If multiple rules match a statement, it is nondeterministic
          which one the plugin uses to rewrite the statement.
   </p>
   <p>
    If a pattern contains more markers than the replacement, the
          plugin discards excess data values. If a pattern contains
          fewer markers than the replacement, it is an error. The plugin
          notices this when the rules table is loaded, writes an error
          message to the
    <code class="literal">
     message
    </code>
    column of the rule
          row to communicate the problem, and sets the
    <a class="link" href="rewriter-query-rewrite-plugin-reference.html#statvar_Rewriter_reload_error">
     <code class="literal">
      Rewriter_reload_error
     </code>
    </a>
    status
          variable to
    <code class="literal">
     ON
    </code>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="rewriter-query-rewrite-plugin-rewriting-prepared-statements">
       </a>
       Rewriting Prepared Statements
      </h5>
     </div>
    </div>
   </div>
   <p>
    Prepared statements are rewritten at parse time (that is, when
          they are prepared), not when they are executed later.
   </p>
   <p>
    Prepared statements differ from nonprepared statements in that
          they may contain
    <code class="literal">
     ?
    </code>
    characters as parameter
          markers. To match a
    <code class="literal">
     ?
    </code>
    in a prepared
          statement, a
    <code class="literal">
     Rewriter
    </code>
    pattern must contain
    <code class="literal">
     ?
    </code>
    in the same location. Suppose that a
          rewrite rule has this pattern:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa23066619"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> ?<span class="token punctuation">,</span> <span class="token number">3</span></code></pre>
   </div>
   <p>
    The following table shows several prepared
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    statements and whether
          the rule pattern matches them.
   </p>
   <div class="informaltable">
    <table summary="How the Rewriter plugin matches prepared statements against the pattern SELECT ?,3.">
     <colgroup>
      <col style="width: 50%"/>
      <col style="width: 50%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Prepared Statement
       </th>
       <th>
        Whether Pattern Matches Statement
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <code class="literal">
         PREPARE s AS 'SELECT 3, 3'
        </code>
       </td>
       <td>
        Yes
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         PREPARE s AS 'SELECT ?, 3'
        </code>
       </td>
       <td>
        Yes
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         PREPARE s AS 'SELECT 3, ?'
        </code>
       </td>
       <td>
        No
       </td>
      </tr>
      <tr>
       <td>
        <code class="literal">
         PREPARE s AS 'SELECT ?, ?'
        </code>
       </td>
       <td>
        No
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="rewriter-query-rewrite-plugin-operational-information">
       </a>
       Rewriter Plugin Operational Information
      </h5>
     </div>
    </div>
   </div>
   <p>
    The
    <code class="literal">
     Rewriter
    </code>
    plugin makes information
          available about its operation by means of several status
          variables:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa54628287"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">GLOBAL</span> <span class="token keyword">STATUS</span> <span class="token operator">LIKE</span> <span class="token string">'Rewriter%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Variable_name                     <span class="token punctuation">|</span> Value <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Rewriter_number_loaded_rules      <span class="token punctuation">|</span> 1     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Rewriter_number_reloads           <span class="token punctuation">|</span> 5     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Rewriter_number_rewritten_queries <span class="token punctuation">|</span> 1     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Rewriter_reload_error             <span class="token punctuation">|</span> ON    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    For descriptions of these variables, see
    <a class="xref" href="rewriter-query-rewrite-plugin-reference.html#rewriter-query-rewrite-plugin-status-variables" title="7.6.4.3.4 Rewriter Query Rewrite Plugin Status Variables">
     Section 7.6.4.3.4, “Rewriter Query Rewrite Plugin Status Variables”
    </a>
    .
   </p>
   <p>
    When you load the rules table by calling the
    <code class="literal">
     flush_rewrite_rules()
    </code>
    stored procedure, if
          an error occurs for some rule, the
    <code class="literal">
     CALL
    </code>
    statement produces an error, and the plugin sets the
    <code class="literal">
     Rewriter_reload_error
    </code>
    status variable to
    <code class="literal">
     ON
    </code>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59479728"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">CALL</span> query_rewrite<span class="token punctuation">.</span>flush_rewrite_rules<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1644 (45000)<span class="token punctuation">:</span> Loading of some rule(s) failed.
</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">GLOBAL</span> <span class="token keyword">STATUS</span> <span class="token operator">LIKE</span> <span class="token string">'Rewriter_reload_error'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Variable_name         <span class="token punctuation">|</span> Value <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Rewriter_reload_error <span class="token punctuation">|</span> ON    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    In this case, check the
    <code class="literal">
     rewrite_rules
    </code>
    table
          for rows with non-
    <code class="literal">
     NULL
    </code>
    <code class="literal">
     message
    </code>
    column values to see what problems
          exist.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="rewriter-query-rewrite-plugin-use-of-character-sets">
       </a>
       Rewriter Plugin Use of Character Sets
      </h5>
     </div>
    </div>
   </div>
   <p>
    When the
    <code class="literal">
     rewrite_rules
    </code>
    table is loaded into
          the
    <code class="literal">
     Rewriter
    </code>
    plugin, the plugin interprets
          statements using the current global value of the
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    system
          variable. If the global
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    value is
          changed subsequently, the rules table must be reloaded.
   </p>
   <p>
    A client must have a session
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    value
          identical to what the global value was when the rules table
          was loaded or rule matching does not work for that client.
   </p>
  </div>
 </div>
 <br/>
</div>
