MySQL 9.1.0
Source Code Documentation
rule.cc File Reference

Implementation of rewrite rule execution. More...

#include "plugin/rewriter/rule.h"
#include "my_config.h"
#include <assert.h>
#include <stddef.h>
#include <string>
#include <vector>
#include "mysqld_error.h"
#include "plugin/rewriter/query_builder.h"
#include "plugin/rewriter/services.h"

Classes

class  Parse_error_recorder
 A Condition_handler that silences and records parse errors. More...
 
class  Literal_collector
 Class that collects literals from a parse tree in an std::vector. More...
 

Detailed Description

Implementation of rewrite rule execution.

Details on parameter extraction: It is important to understand that in the case of a rewrite the tree of the original query and of the pattern have been found to be similar (by comparing the normalized strings,) except that instead of parameter markers there may be actual literals. Therefore, the parameters to extract are at the exact same positions as the parameter markers in the pattern. Example with the where clause of a query:

          Pattern                 Original Query

            AND                       AND
          /     \                   /     \
        EQ      NEQ               EQ      NEQ
      /   \   /     \           /   \    /    \
     A     ? C       ?         A     3  C      5

When loading a rule, we will traverse the tree and keep each literal we encounter. We later reuse these literals to do the third phase of matching: either a literal in the query matches a parameter marker in the pattern, or an identical literal.