MySQL  8.0.19
Source Code Documentation
rewriter.h
Go to the documentation of this file.
1 #ifndef REWRITER_INCLUDED
2 #define REWRITER_INCLUDED
3 /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation. The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24 
25 #include "my_config.h"
26 
27 #include <memory>
28 #include <string>
29 
30 #include "map_helpers.h"
31 #include "my_inttypes.h"
32 #include "plugin/rewriter/rule.h"
33 
34 /**
35  @file rewriter.h
36 
37  Facade for the query rewriter. Provides the Rewriter class which performs
38  all of the functionality. A query rewriter plugin needs only include this
39  file.
40 */
41 
42 class Persisted_rule;
43 
44 /**
45  Implementation of the post parse query rewriter. The public interface
46  consists of two operations: refresh(), which loads the rules from the disk
47  table, and rewrite_query(), which rewrites a query if applicable.
48 */
49 class Rewriter {
50  public:
51  Rewriter();
52 
53  /**
54  The number of rules currently loaded in the hash table. In case of rules
55  that fail to load, this number will be lower than the number of rows in
56  the database.
57  */
58  int get_number_loaded_rules() const { return m_digests.size(); }
59 
60  ~Rewriter();
61 
62  /**
63  Attempts to rewrite thd's current query with digest in 'key'.
64 
65  @return A Rewrite_result object.
66  */
68 
69  /// Empty the hashtable and reload all rules from disk table.
71 
72  /**
73  Implementation of the loading procedure. The server doesn't handle
74  different sessions in the same thread, so we load the rules into the hash
75  table in this function, intended to be run in a new thread. The main
76  thread will do join().
77 
78  @param session_thd The session to be used for loading rules.
79  */
80  void do_refresh(MYSQL_THD session_thd);
81 
82  private:
84 
85  /// The in-memory rules hash table.
88 
89  /// Loads the rule retrieved from the database in the hash table.
90  bool load_rule(MYSQL_THD thd, Persisted_rule *diskrule);
91 };
92 
93 #endif /* REWRITER_INCLUDED */
Rewriter::do_refresh
void do_refresh(MYSQL_THD session_thd)
Implementation of the loading procedure.
Definition: rewriter.cc:120
longlong
long long int longlong
Definition: my_inttypes.h:54
PSI_INSTRUMENT_ME
#define PSI_INSTRUMENT_ME
Definition: psi_base.h:44
Rewrite_result
The results of an attempt to rewrite a query parse tree.
Definition: rule.h:36
key
static const char * key
Definition: suite_stubs.c:14
my_inttypes.h
Rewriter::~Rewriter
~Rewriter()
Definition: rewriter.cc:65
Rewriter::load_rule
bool load_rule(MYSQL_THD thd, Persisted_rule *diskrule)
Loads the rule retrieved from the database in the hash table.
Definition: rewriter.cc:67
Rewriter::m_refresh_status
longlong m_refresh_status
Definition: rewriter.h:83
map_helpers.h
rule.h
Rewriter::Rewriter
Rewriter()
Definition: rewriter.cc:63
uchar
unsigned char uchar
Definition: my_inttypes.h:51
Persisted_rule
A rule as persisted on disk.
Definition: persisted_rule.h:41
MYSQL_THD
#define MYSQL_THD
Definition: backup_page_tracker.h:15
Rewriter::get_number_loaded_rules
int get_number_loaded_rules() const
The number of rules currently loaded in the hash table.
Definition: rewriter.h:58
malloc_unordered_multimap
std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory k...
Definition: map_helpers.h:215
Rewriter::rewrite_query
Rewrite_result rewrite_query(MYSQL_THD thd, const uchar *key)
Attempts to rewrite thd's current query with digest in 'key'.
Definition: rewriter.cc:187
Rewriter::refresh
longlong refresh(MYSQL_THD thd)
Empty the hashtable and reload all rules from disk table.
Definition: rewriter.cc:172
Rewriter
Implementation of the post parse query rewriter.
Definition: rewriter.h:49
Rewriter::m_digests
malloc_unordered_multimap< std::string, std::unique_ptr< Rule > > m_digests
The in-memory rules hash table.
Definition: rewriter.h:86