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