MySQL 8.4.0
Source Code Documentation
rpl_sys_key_access.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef RPL_SYS_KEY_ACCESS_INCLUDED
25#define RPL_SYS_KEY_ACCESS_INCLUDED
26
27#include "sql/table.h"
28
29/**
30 @class Rpl_sys_table_access
31
32 The class are wrappers for handler index and random scan functions to
33 simplify their usage.
34*/
36 public:
37 /* Index type */
38 enum class enum_key_type {
39 /* Read next row via random scan using handler::ha_rnd_next. */
41 /* Read row via random scan from position using handler::ha_rnd_pos. */
42 RND_POS,
43 /*
44 Read [part of] row via [part of] index using
45 handler::ha_index_read_map.
46 */
48 /* Read all rows of index using handler::ha_index_first. */
50 };
51
52 /**
53 Construction.
54 */
55 Rpl_sys_key_access() = default;
56
57 /**
58 Destruction.
59 Closes all initialized index or random scan during destruction.
60 */
62
63 /**
64 Construction.
65
66 @param[in] table Table object from which row needs to be fetched.
67 @param[in] type The type of scan to use to read row.
68
69 @retval 0 Success
70 @retval !0 Error
71 */
73
74 /**
75 When index type enum_key_type::INDEX_NEXT_SAME needs to be used to read
76 [part of] row via [part of] index.
77
78 @param[in] table Table object from which row needs to be fetched.
79 @param[in] index Index to use
80 @param[in] sorted Use sorted order
81 @param[in] keypart_map Which part of key to use
82 @param[in] find_flag Direction/condition on key usage
83
84 @retval 0 Success
85 @retval !0 Error
86 */
87 int init(TABLE *table, uint index = 0, bool sorted = true,
88 key_part_map keypart_map = 1,
89 enum ha_rkey_function find_flag = HA_READ_KEY_EXACT);
90
91 /**
92 When index type enum_key_type::RND_POS needs to be used to read row via
93 random scan from position.
94
95 @param[in] table Table object from which row needs to be fetched.
96 @param[in] pos The position from where to read row.
97
98 @retval 0 Success
99 @retval !0 Error
100 */
101 int init(TABLE *table, std::string pos);
102
103 /**
104 Closes all initialized index or random scan during destruction.
105
106 @retval true if there is error
107 @retval false if there is no error
108 */
109 bool deinit();
110
111 /**
112 Get next row in the table.
113
114 @retval 0 Success
115 @retval !0 Error
116 */
117 int next();
118
119 /**
120 Verify if error is set, ignores HA_ERR_END_OF_FILE and
121 HA_ERR_KEY_NOT_FOUND.
122
123 @retval true if there is error
124 @retval false if there is no error
125 */
126 bool is_read_error();
127
128 /**
129 Get error set during index initialization or fetching next rows.
130
131 @retval 0 Success
132 @retval !0 Error
133 */
134 int get_error() { return m_error; }
135
136 private:
137 /* TABLE object */
138 TABLE *m_table{nullptr};
139
140 /* The type of index used */
142
143 /* Determine if index is initialized. */
144 bool m_key_init{false};
145
146 /* Determine if index is deinitialized. */
147 bool m_key_deinit{false};
148
149 /* The buffer to store the key */
151
152 /*
153 The variable stores error during index initialization or fetching next
154 rows.
155 */
156 int m_error{1};
157};
158#endif /* RPL_SYS_KEY_ACCESS_INCLUDED */
Definition: rpl_sys_key_access.h:35
bool deinit()
Closes all initialized index or random scan during destruction.
Definition: rpl_sys_key_access.cc:101
enum_key_type m_key_type
Definition: rpl_sys_key_access.h:141
enum_key_type
Definition: rpl_sys_key_access.h:38
bool is_read_error()
Verify if error is set, ignores HA_ERR_END_OF_FILE and HA_ERR_KEY_NOT_FOUND.
Definition: rpl_sys_key_access.cc:155
uchar m_key[MAX_KEY_LENGTH]
Definition: rpl_sys_key_access.h:150
~Rpl_sys_key_access()
Destruction.
Definition: rpl_sys_key_access.cc:99
int m_error
Definition: rpl_sys_key_access.h:156
bool m_key_deinit
Definition: rpl_sys_key_access.h:147
int get_error()
Get error set during index initialization or fetching next rows.
Definition: rpl_sys_key_access.h:134
int init(TABLE *table, enum_key_type type)
Construction.
Definition: rpl_sys_key_access.cc:28
Rpl_sys_key_access()=default
Construction.
bool m_key_init
Definition: rpl_sys_key_access.h:144
TABLE * m_table
Definition: rpl_sys_key_access.h:138
int next()
Get next row in the table.
Definition: rpl_sys_key_access.cc:129
ha_rkey_function
Definition: my_base.h:78
@ HA_READ_KEY_EXACT
Definition: my_base.h:79
ulong key_part_map
Definition: my_base.h:1008
unsigned char uchar
Definition: my_inttypes.h:52
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
required string type
Definition: replication_group_member_actions.proto:34
constexpr const unsigned int MAX_KEY_LENGTH
Definition: sql_const.h:48
Definition: table.h:1405