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