MySQL 9.0.0
Source Code Documentation
table_access_bits.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 COMPONENTS_SERVICES_TABLE_ACCESS_BITS_H
25#define COMPONENTS_SERVICES_TABLE_ACCESS_BITS_H
26
27#ifndef MYSQL_ABI_CHECK
28#include <stddef.h> /* size_t */
29#endif
30
33
34/**
35 @file mysql/components/services/bits/table_access_bits.h
36 Generic table access interface.
37
38 @defgroup group_table_access_services Table Access services
39 @ingroup group_components_services_inventory
40 @{
41*/
42
43/**
44 Table lock type.
45*/
47 /** Table is opened for read. */
49 /** Table is opened for write. */
51};
52
53/**
54 Types of columns supported by the table access service.
55*/
62};
63
64/**
65 Expected field definition.
66*/
68 /** Column ordinal position (0-based). */
69 size_t m_index;
70 /** Column name, in UTF8MB4. */
71 const char *m_name;
72 /** Column name length, in bytes. */
74 /** Column type. */
76 /** Nullable. */
78 /** Column length. */
79 size_t m_length;
80};
81
82/**
83 Expected index definition.
84*/
86 /** Column name, in UTF8MB4. */
87 const char *m_name;
88 /** Column name length, in bytes. */
90 /** Index order. */
92};
93
94/**
95 Table_access.
96 A table access session.
97*/
99
100/**
101 An opened table.
102*/
104
105/**
106 An index key.
107*/
109
110/**
111 Create a table access object.
112 @sa destroy_table_access_v1_t
113
114 @param thd The current session. Pass a null ptr if running from a non-MySQLd
115 thread
116 @param count The maximum number of tables to access.
117
118 @note The table access service will create a child session
119 to perform table read and writes.
120 The following properties from the current session are used
121 to initialize the child session:
122 - @c log_bin
123 - @c transaction_isolation
124 - @c skip_readonly_check
125
126 @warning The table access service will set the current THD thread attribute
127 to the temporary child THD it creates. The current THD will be reset back by
128 @ref destroy_table_access_v1_t. This means that the whole table access
129 routine should happen as fast as possible and without thread switching until
130 its completion and disposal of the thread access attribute.
131 The @ref Table_access handle should not be cached and reused.
132*/
134
135/**
136 Destroy a table access object.
137 @sa create_table_access_v1_t
138*/
140
141/**
142 Add a table to a table access session.
143 This method adds a table to a table access session.
144 It returns a ticket, to use with @ref get_table_v1_t.
145
146 @param ta Table access session
147 @param schema_name Schema name raw buffer, in UTF8MB4.
148 @param schema_name_length Length, in bytes, of schema_name
149 @param table_name Table name raw buffer, in UTF8MB4.
150 @param table_name_length Length, in bytes, of table_name
151 @param lock_type_arg Lock type to use (read or write)
152 @return ticket number for the table added
153*/
154typedef size_t (*add_table_v1_t)(Table_access ta, const char *schema_name,
155 size_t schema_name_length,
156 const char *table_name,
157 size_t table_name_length,
158 TA_lock_type lock_type_arg);
159
160#define TA_ERROR_GRL 1
161#define TA_ERROR_READONLY 2
162#define TA_ERROR_OPEN 3
163
164/**
165 Start a table access transaction.
166 Open all tables from the table access session, and lock them.
167
168 Locking all the tables at once is necessary to prevent
169 deadlocks on table metadata between different sessions.
170 The caller should not own the global read lock when opening
171 tables, as this would also create deadlocks.
172
173 @return An error status
174 @retval 0 success
175 @retval TA_ERROR_GRL Global read lock held by the caller
176 @retval TA_ERROR_OPEN Failed to open and lock tables.
177*/
178typedef int (*begin_v1_t)(Table_access ta);
179
180/**
181 Commit changes.
182*/
183typedef int (*commit_v1_t)(Table_access ta);
184
185/**
186 Rollback changes.
187*/
188typedef int (*rollback_v1_t)(Table_access ta);
189
190/**
191 Get an opened table.
192 Once tables are opened and locked,
193 this method returns the opened table that correspond to
194 the ticket returned by add tables.
195
196 @return An opened table.
197*/
198typedef TA_table (*get_table_v1_t)(Table_access ta, size_t ticket);
199
200/**
201 Check the actual table fields against expected fields.
202
203 @retval 0 success
204*/
206 const TA_table_field_def *fields,
207 size_t fields_count);
208
209/**
210 Open a table index.
211
212 An index is identified by name.
213 The caller lists the columns expected in the index.
214 If the index DDL matches the expected columns and count,
215 the index is opened.
216 Otherwise, an error is returned, and the index is not opened.
217
218 @note The list of columns must contain the ACTUAL columns in the index
219 rather than USER defined (used on SQL level). The actual list depends on
220 engine and current implementation. E.g. InnoDB may add columns to the user
221 defined set.
222
223 @param ta Table access
224 @param table Opened table
225 @param index_name Index name, in UTF8MB4, must match the table DDL.
226 @param index_name_length Length of index_name, in bytes.
227 @param fields Expected fields for the index
228 @param fields_count Expected number of fields for the index
229 @param [out] key Opened index.
230
231 @retval 0 Success
232
233 @sa index_end_v1_t
234*/
236 const char *index_name, size_t index_name_length,
237 const TA_index_field_def *fields,
238 size_t fields_count, TA_key *key);
239
240/**
241 Position a table index at a search key.
242
243 The search key is not passed explicitly in this call.
244 The search key is set by populating columns in the table current record,
245 before invoking this method.
246
247 @param ta Table access
248 @param table Opened table
249 @param num_parts Number of key parts populated in the current record.
250 @param key Opened index
251*/
253 size_t num_parts, TA_key key);
254
255/**
256 Position on index at the beginning.
257*/
259
260/**
261 Advance to the next record in the index.
262*/
264
265/**
266 Advance to the next record that matches the current search key.
267*/
269 TA_key key);
270
271/**
272 Close an index.
273*/
275
276/**
277 Start a full table scan.
278*/
280
281/**
282 Advance to the next record in a table scan.
283*/
285
286/**
287 End a full table scan.
288*/
290
291/**
292 Insert a new row in the table.
293*/
295
296/**
297 Update the current row.
298*/
300
301/**
302 Delete the current row.
303*/
305
306/**
307 Set a column to NULL.
308*/
310 size_t index);
311
312/**
313 Is a column NULL.
314*/
316 size_t index);
317
318/**
319 Can a column be NULL.
320*/
322 size_t index);
323
324/**
325 Write an INTEGER column value.
326*/
328 size_t index, long long v);
329
330/**
331 Read an INTEGER column value.
332*/
334 size_t index, long long *v);
335
336/**
337 Write a VARCHAR column value.
338*/
340 size_t index, my_h_string v);
341
342/**
343 Read a VARCHAR column value.
344*/
346 size_t index, my_h_string v);
347
348/**
349 Write any column value.
350 This is a generic interface.
351 The column value must be expressed in UTF8MB4_bin,
352 and is converted to the column type.
353*/
355 size_t index, my_h_string v);
356
357/**
358 Read any column value.
359 This is a generic interface.
360 The column value is converted to a string,
361 expressed in UTF8MB4_bin.
362*/
364 size_t index, my_h_string v);
365
366/**
367 Turns on or off the binlogging flag for the current thread
368*/
369typedef void (*table_access_binlog_set_t)(Table_access ta, bool is_binlogging);
370/**
371 Gets the binlogging flag for the current thread
372*/
374/** @} (end of group_table_access_services) */
375
376#endif /* COMPONENTS_SERVICES_TABLE_ACCESS_BITS_H */
#define MYSQL_THD
Definition: backup_page_tracker.h:38
int(* index_first_v1_t)(Table_access ta, TA_table table, TA_key key)
Position on index at the beginning.
Definition: table_access_bits.h:258
TA_table(* get_table_v1_t)(Table_access ta, size_t ticket)
Get an opened table.
Definition: table_access_bits.h:198
size_t(* add_table_v1_t)(Table_access ta, const char *schema_name, size_t schema_name_length, const char *table_name, size_t table_name_length, TA_lock_type lock_type_arg)
Add a table to a table access session.
Definition: table_access_bits.h:154
void(* table_access_binlog_set_t)(Table_access ta, bool is_binlogging)
Turns on or off the binlogging flag for the current thread.
Definition: table_access_bits.h:369
int(* delete_row_v1_t)(Table_access ta, TA_table table)
Delete the current row.
Definition: table_access_bits.h:304
int(* index_next_v1_t)(Table_access ta, TA_table table, TA_key key)
Advance to the next record in the index.
Definition: table_access_bits.h:263
int(* index_next_same_v1_t)(Table_access ta, TA_table table, TA_key key)
Advance to the next record that matches the current search key.
Definition: table_access_bits.h:268
int(* update_row_v1_t)(Table_access ta, TA_table table)
Update the current row.
Definition: table_access_bits.h:299
int(* rollback_v1_t)(Table_access ta)
Rollback changes.
Definition: table_access_bits.h:188
int(* rnd_next_v1_t)(Table_access ta, TA_table table)
Advance to the next record in a table scan.
Definition: table_access_bits.h:284
int(* index_end_v1_t)(Table_access ta, TA_table table, TA_key key)
Close an index.
Definition: table_access_bits.h:274
bool(* table_access_binlog_get_t)(Table_access ta)
Gets the binlogging flag for the current thread.
Definition: table_access_bits.h:373
int(* commit_v1_t)(Table_access ta)
Commit changes.
Definition: table_access_bits.h:183
int(* index_init_v1_t)(Table_access ta, TA_table table, const char *index_name, size_t index_name_length, const TA_index_field_def *fields, size_t fields_count, TA_key *key)
Open a table index.
Definition: table_access_bits.h:235
int(* rnd_end_v1_t)(Table_access ta, TA_table table)
End a full table scan.
Definition: table_access_bits.h:289
int(* get_field_integer_value_v1_t)(Table_access ta, TA_table table, size_t index, long long *v)
Read an INTEGER column value.
Definition: table_access_bits.h:333
int(* write_row_v1_t)(Table_access ta, TA_table table)
Insert a new row in the table.
Definition: table_access_bits.h:294
void(* set_field_null_v1_t)(Table_access ta, TA_table table, size_t index)
Set a column to NULL.
Definition: table_access_bits.h:309
void(* destroy_table_access_v1_t)(Table_access ta)
Destroy a table access object.
Definition: table_access_bits.h:139
int(* rnd_init_v1_t)(Table_access ta, TA_table table)
Start a full table scan.
Definition: table_access_bits.h:279
TA_lock_type
Table lock type.
Definition: table_access_bits.h:46
int(* get_field_varchar_value_v1_t)(Table_access ta, TA_table table, size_t index, my_h_string v)
Read a VARCHAR column value.
Definition: table_access_bits.h:345
struct TA_key_imp * TA_key
An index key.
Definition: table_access_bits.h:108
struct Table_access_imp * Table_access
Table_access.
Definition: table_access_bits.h:98
bool(* is_field_null_v1_t)(Table_access ta, TA_table table, size_t index)
Is a column NULL.
Definition: table_access_bits.h:315
int(* check_table_fields_v1_t)(Table_access ta, TA_table table, const TA_table_field_def *fields, size_t fields_count)
Check the actual table fields against expected fields.
Definition: table_access_bits.h:205
Table_access(* create_table_access_v1_t)(MYSQL_THD thd, size_t count)
Create a table access object.
Definition: table_access_bits.h:133
int(* get_field_any_value_v1_t)(Table_access ta, TA_table table, size_t index, my_h_string v)
Read any column value.
Definition: table_access_bits.h:363
int(* set_field_any_value_v1_t)(Table_access ta, TA_table table, size_t index, my_h_string v)
Write any column value.
Definition: table_access_bits.h:354
bool(* maybe_field_null_v1_t)(Table_access ta, TA_table table, size_t index)
Can a column be NULL.
Definition: table_access_bits.h:321
int(* index_read_map_v1_t)(Table_access ta, TA_table table, size_t num_parts, TA_key key)
Position a table index at a search key.
Definition: table_access_bits.h:252
struct TA_table_imp * TA_table
An opened table.
Definition: table_access_bits.h:103
TA_field_type
Types of columns supported by the table access service.
Definition: table_access_bits.h:56
int(* set_field_varchar_value_v1_t)(Table_access ta, TA_table table, size_t index, my_h_string v)
Write a VARCHAR column value.
Definition: table_access_bits.h:339
int(* set_field_integer_value_v1_t)(Table_access ta, TA_table table, size_t index, long long v)
Write an INTEGER column value.
Definition: table_access_bits.h:327
int(* begin_v1_t)(Table_access ta)
Start a table access transaction.
Definition: table_access_bits.h:178
@ TA_READ
Table is opened for read.
Definition: table_access_bits.h:48
@ TA_WRITE
Table is opened for write.
Definition: table_access_bits.h:50
@ TA_TYPE_UNKNOWN
Definition: table_access_bits.h:57
@ TA_TYPE_INTEGER
Definition: table_access_bits.h:58
@ TA_TYPE_JSON
Definition: table_access_bits.h:60
@ TA_TYPE_VARCHAR
Definition: table_access_bits.h:59
@ TA_TYPE_ENUM
Definition: table_access_bits.h:61
static int count
Definition: myisam_ftdump.cc:45
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
const char * table_name
Definition: rules_table_service.cc:56
required string key
Definition: replication_asynchronous_connection_failover.proto:60
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:129
Expected index definition.
Definition: table_access_bits.h:85
const char * m_name
Column name, in UTF8MB4.
Definition: table_access_bits.h:87
bool m_ascending
Index order.
Definition: table_access_bits.h:91
size_t m_name_length
Column name length, in bytes.
Definition: table_access_bits.h:89
Expected field definition.
Definition: table_access_bits.h:67
TA_field_type m_type
Column type.
Definition: table_access_bits.h:75
const char * m_name
Column name, in UTF8MB4.
Definition: table_access_bits.h:71
bool m_nullable
Nullable.
Definition: table_access_bits.h:77
size_t m_length
Column length.
Definition: table_access_bits.h:79
size_t m_index
Column ordinal position (0-based).
Definition: table_access_bits.h:69
size_t m_name_length
Column name length, in bytes.
Definition: table_access_bits.h:73
Definition: mysql_string_service.cc:60