MySQL 8.0.39
Source Code Documentation
rewriter.h
Go to the documentation of this file.
1#ifndef REWRITER_INCLUDED
2#define REWRITER_INCLUDED
3/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include "my_config.h"
27
28#include <memory>
29#include <string>
30
31#include "map_helpers.h"
32#include "my_inttypes.h"
34
35/**
36 @file rewriter.h
37
38 Facade for the query rewriter. Provides the Rewriter class which performs
39 all of the functionality. A query rewriter plugin needs only include this
40 file.
41*/
42
43class Persisted_rule;
44
45/**
46 Implementation of the post parse query rewriter. The public interface
47 consists of two operations: refresh(), which loads the rules from the disk
48 table, and rewrite_query(), which rewrites a query if applicable.
49*/
50class Rewriter {
51 public:
53
54 /**
55 The number of rules currently loaded in the hash table. In case of rules
56 that fail to load, this number will be lower than the number of rows in
57 the database.
58 */
59 int get_number_loaded_rules() const { return m_digests.size(); }
60
62
63 /**
64 Attempts to rewrite thd's current query with digest in 'key'.
65
66 @return A Rewrite_result object.
67 */
69
70 /// Empty the hashtable and reload all rules from disk table.
72
73 /**
74 Implementation of the loading procedure. The server doesn't handle
75 different sessions in the same thread, so we load the rules into the hash
76 table in this function, intended to be run in a new thread. The main
77 thread will do join().
78
79 @param session_thd The session to be used for loading rules.
80 */
81 void do_refresh(MYSQL_THD session_thd);
82
83 private:
85
86 /// The in-memory rules hash table.
89
90 /// Loads the rule retrieved from the database in the hash table.
91 bool load_rule(MYSQL_THD thd, Persisted_rule *diskrule);
92};
93
94#endif /* REWRITER_INCLUDED */
#define MYSQL_THD
Definition: backup_page_tracker.h:38
A rule as persisted on disk.
Definition: persisted_rule.h:42
Implementation of the post parse query rewriter.
Definition: rewriter.h:50
malloc_unordered_multimap< std::string, std::unique_ptr< Rule > > m_digests
The in-memory rules hash table.
Definition: rewriter.h:87
longlong m_refresh_status
Definition: rewriter.h:84
void do_refresh(MYSQL_THD session_thd)
Implementation of the loading procedure.
Definition: rewriter.cc:120
bool load_rule(MYSQL_THD thd, Persisted_rule *diskrule)
Loads the rule retrieved from the database in the hash table.
Definition: rewriter.cc:67
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
int get_number_loaded_rules() const
The number of rules currently loaded in the hash table.
Definition: rewriter.h:59
longlong refresh(MYSQL_THD thd)
Empty the hashtable and reload all rules from disk table.
Definition: rewriter.cc:172
std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory k...
Definition: map_helpers.h:189
static constexpr unsigned PSI_INSTRUMENT_ME
Definition: psi_bits.h:43
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
required string key
Definition: replication_asynchronous_connection_failover.proto:60
The results of an attempt to rewrite a query parse tree.
Definition: rule.h:37