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