Debian Codegraph @

storage/innobase/include/api0api.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2008, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/api0api.h
29 InnoDB Native API
30
31 2008-08-01 Created by Sunny Bains.
32 3/20/2011 Jimmy Yang extracted from Embedded InnoDB
33 *******************************************************/
34
35 #ifndef api0api_h
36 #define api0api_h
37
38 #include <stdint.h>
39 #include <stdio.h>
40
41 #include "my_config.h"
42
43 #include "db0err.h"
44
45 #if defined(WITH_INNODB_MEMCACHED) && !defined(NDEBUG)
46 #define UNIV_MEMCACHED_SDI
47 #endif
48
49 /** Page number */
50 typedef uint32_t page_no_t;
51 /** Tablespace identifier */
52 typedef uint32_t space_id_t;
53
54 typedef struct ib_sdi_key ib_sdi_key_t;
55 typedef struct ib_sdi_vector ib_sdi_vector_t;
56
57 /* Basic types used by the InnoDB API. */
58 /** All InnoDB error codes are represented by ib_err_t */
59 typedef enum dberr_t ib_err_t;
60 /** Representation of a byte within InnoDB */
61 typedef unsigned char ib_byte_t;
62
63 /** Representation of an unsigned long int within InnoDB */
64 #ifdef _WIN64
65 typedef unsigned __int64 ib_ulint_t;
66 #else
67 typedef unsigned long int ib_ulint_t;
68 #endif /* _WIN64 */
69
70 typedef void *ib_opaque_t;
71 typedef ib_opaque_t ib_charset_t;
72 typedef uint64_t ib_id_u64_t;
73
74 /** @enum ib_cfg_type_t Possible types for a configuration variable. */
75 typedef enum {
76 IB_CFG_BOOL, /*!< The configuration parameter is
77 of type bool */
78
79 /* XXX Can we avoid having different types for ulint and ulong?
80 - On Win64 "unsigned long" is 32 bits
81 - ulong is always defined as "unsigned long"
82 - On Win64 ulint is defined as 64 bit integer
83 => On Win64 ulint != ulong.
84 If we typecast all ulong and ulint variables to the smaller type
85 ulong, then we will cut the range of the ulint variables.
86 This is not a problem for most ulint variables because their max
87 allowed values do not exceed 2^32-1 (e.g. log_groups is ulint
88 but its max allowed value is 10). BUT buffer_pool_size and
89 log_file_size allow up to 2^64-1. */
90
91 IB_CFG_ULINT, /*!< The configuration parameter is
92 of type ulint */
93
94 IB_CFG_ULONG, /*!< The configuration parameter is
95 of type ulong */
96
97 IB_CFG_TEXT, /*!< The configuration parameter is
98 of type char* */
99
100 IB_CFG_CB /*!< The configuration parameter is
101 a callback parameter */
102 } ib_cfg_type_t;
103
104 /** @enum ib_col_type_t column types that are supported. */
105 typedef enum {
106 IB_VARCHAR = 1, /*!< Character varying length. The
107 column is not padded. */
108
109 IB_CHAR = 2, /*!< Fixed length character string. The
110 column is padded to the right. */
111
112 IB_BINARY = 3, /*!< Fixed length binary, similar to
113 IB_CHAR but the column is not padded
114 to the right. */
115
116 IB_VARBINARY = 4, /*!< Variable length binary */
117
118 IB_BLOB = 5, /*!< Binary large object, or
119 a TEXT type */
120
121 IB_INT = 6, /*!< Integer: can be any size
122 from 1 - 8 bytes. If the size is
123 1, 2, 4 and 8 bytes then you can use
124 the typed read and write functions. For
125 other sizes you will need to use the
126 ib_col_get_value() function and do the
127 conversion yourself. */
128
129 IB_SYS = 8, /*!< System column, this column can
130 be one of DATA_TRX_ID, DATA_ROLL_PTR
131 or DATA_ROW_ID. */
132
133 IB_FLOAT = 9, /*!< C (float) floating point value. */
134
135 IB_DOUBLE = 10, /*!> C (double) floating point value. */
136
137 IB_DECIMAL = 11, /*!< Decimal stored as an ASCII
138 string */
139
140 IB_VARCHAR_ANYCHARSET = 12, /*!< Any charset, varying length */
141
142 IB_CHAR_ANYCHARSET = 13 /*!< Any charset, fixed length */
143
144 } ib_col_type_t;
145
146 /** @enum ib_tbl_fmt_t InnoDB table format types */
147 typedef enum {
148 IB_TBL_REDUNDANT, /*!< Redundant row format, the column
149 type and length is stored in the row.*/
150
151 IB_TBL_COMPACT, /*!< Compact row format, the column
152 type is not stored in the row. The
153 length is stored in the row but the
154 storage format uses a compact format
155 to store the length of the column data
156 and record data storage format also
157 uses less storage. */
158
159 IB_TBL_DYNAMIC, /*!< Compact row format. BLOB prefixes
160 are not stored in the clustered index */
161
162 IB_TBL_COMPRESSED /*!< Similar to dynamic format but
163 with pages compressed */
164 } ib_tbl_fmt_t;
165
166 /** @enum ib_col_attr_t InnoDB column attributes */
167 typedef enum {
168 IB_COL_NONE = 0, /*!< No special attributes. */
169
170 IB_COL_NOT_NULL = 1, /*!< Column data can't be NULL. */
171
172 IB_COL_UNSIGNED = 2, /*!< Column is IB_INT and unsigned. */
173
174 IB_COL_NOT_USED = 4, /*!< Future use, reserved. */
175
176 IB_COL_CUSTOM1 = 8, /*!< Custom precision type, this is
177 a bit that is ignored by InnoDB and so
178 can be set and queried by users. */
179
180 IB_COL_CUSTOM2 = 16, /*!< Custom precision type, this is
181 a bit that is ignored by InnoDB and so
182 can be set and queried by users. */
183
184 IB_COL_CUSTOM3 = 32 /*!< Custom precision type, this is
185 a bit that is ignored by InnoDB and so
186 can be set and queried by users. */
187 } ib_col_attr_t;
188
189 /* Note: must match lock0types.h */
190 /** @enum ib_lck_mode_t InnoDB lock modes. */
191 typedef enum {
192 IB_LOCK_IS = 0, /*!< Intention shared, an intention
193 lock should be used to lock tables */
194
195 IB_LOCK_IX, /*!< Intention exclusive, an intention
196 lock should be used to lock tables */
197
198 IB_LOCK_S, /*!< Shared locks should be used to
199 lock rows */
200
201 IB_LOCK_X, /*!< Exclusive locks should be used to
202 lock rows*/
203
204 IB_LOCK_TABLE_X, /*!< exclusive table lock */
205
206 IB_LOCK_NONE, /*!< This is used internally to note
207 consistent read */
208
209 IB_LOCK_NUM = IB_LOCK_NONE /*!< number of lock modes */
210 } ib_lck_mode_t;
211
212 typedef enum {
213 IB_CLUSTERED = 1, /*!< clustered index */
214 IB_UNIQUE = 2 /*!< unique index */
215 } ib_index_type_t;
216
217 /** @enum ib_srch_mode_t InnoDB cursor search modes for ib_cursor_moveto().
218 Note: Values must match those found in page0cur.h */
219 typedef enum {
220 IB_CUR_G = 1, /*!< If search key is not found then
221 position the cursor on the row that
222 is greater than the search key */
223
224 IB_CUR_GE = 2, /*!< If the search key not found then
225 position the cursor on the row that
226 is greater than or equal to the search
227 key */
228
229 IB_CUR_L = 3, /*!< If search key is not found then
230 position the cursor on the row that
231 is less than the search key */
232
233 IB_CUR_LE = 4 /*!< If search key is not found then
234 position the cursor on the row that
235 is less than or equal to the search
236 key */
237 } ib_srch_mode_t;
238
239 /** @enum ib_match_mode_t Various match modes used by ib_cursor_moveto() */
240 typedef enum {
241 IB_CLOSEST_MATCH, /*!< Closest match possible */
242
243 IB_EXACT_MATCH, /*!< Search using a complete key
244 value */
245
246 IB_EXACT_PREFIX /*!< Search using a key prefix which
247 must match to rows: the prefix may
248 contain an incomplete field (the
249 last field in prefix may be just
250 a prefix of a fixed length column) */
251 } ib_match_mode_t;
252
253 /** InnoDB column meta data. */
254 typedef struct {
255 ib_col_type_t type; /*!< Type of the column */
256
257 ib_col_attr_t attr; /*!< Column attributes */
258
259 uint32_t type_len; /*!< Length of type */
260
261 uint16_t client_type; /*!< 16 bits of data relevant only to
262 the client. InnoDB doesn't care */
263
264 ib_charset_t *charset; /*!< Column charset */
265 } ib_col_meta_t;
266
267 /* Note: Must be in sync with trx0trx.h */
268 /** @enum ib_trx_level_t Transaction isolation levels */
269 typedef enum {
270 IB_TRX_READ_UNCOMMITTED = 0, /*!< Dirty read: non-locking SELECTs are
271 performed so that we do not look at a
272 possible earlier version of a record;
273 thus they are not 'consistent' reads
274 under this isolation level; otherwise
275 like level 2 */
276
277 IB_TRX_READ_COMMITTED = 1, /*!< Somewhat Oracle-like isolation,
278 except that in range UPDATE and DELETE
279 we must block phantom rows with
280 next-key locks; SELECT ... FOR UPDATE
281 and ... LOCK IN SHARE MODE only lock
282 the index records, NOT the gaps before
283 them, and thus allow free inserting;
284 each consistent read reads its own
285 snapshot */
286
287 IB_TRX_REPEATABLE_READ = 2, /*!< All consistent reads in the same
288 trx read the same snapshot; full
289 next-key locking used in locking reads
290 to block insertions into gaps */
291
292 IB_TRX_SERIALIZABLE = 3 /*!< All plain SELECTs are converted to
293 LOCK IN SHARE MODE reads */
294 } ib_trx_level_t;
295
296 /** Generical InnoDB callback prototype. */
297 typedef void (*ib_cb_t)(void);
298
299 constexpr uint32_t IB_CFG_BINLOG_ENABLED = 0x1;
300 constexpr uint32_t IB_CFG_MDL_ENABLED = 0x2;
301 constexpr uint32_t IB_CFG_DISABLE_ROWLOCK = 0x4;
302
303 /** Used by ib_read_tuple to determine number of bytes to allocate for new slot
304 if needed */
305 static const size_t REC_BUF_SLOT_SIZE = 16384;
306
307 /** The first argument to the InnoDB message logging function. By default
308 it's set to stderr. You should treat ib_msg_stream_t as a void*, since
309 it will probably change in the future. */
310 typedef FILE *ib_msg_stream_t;
311
312 /** All log messages are written to this function.It should have the same
313 behavior as fprintf(3). */
314 typedef int (*ib_msg_log_t)(ib_msg_stream_t, const char *, ...);
315
316 /* Note: This is to make it easy for API users to have type
317 checking for arguments to our functions. Making it ib_opaque_t
318 by itself will result in pointer decay resulting in subverting
319 of the compiler's type checking. */
320
321 /** InnoDB tuple handle. This handle can refer to either a cluster index
322 tuple or a secondary index tuple. There are two types of tuples for each
323 type of index, making a total of four types of tuple handles. There
324 is a tuple for reading the entire row contents and another for searching
325 on the index key. */
326 typedef struct ib_tuple_t *ib_tpl_t;
327
328 /** InnoDB transaction handle, all database operations need to be covered
329 by transactions. This handle represents a transaction. The handle can be
330 created with ib_trx_begin(), you commit your changes with ib_trx_commit()
331 and undo your changes using ib_trx_rollback(). If the InnoDB deadlock
332 monitor rolls back the transaction then you need to free the transaction
333 using the function ib_trx_release(). You can query the state of an InnoDB
334 transaction by calling ib_trx_state(). */
335 typedef struct trx_t *ib_trx_t;
336
337 /** InnoDB cursor handle */
338 typedef struct ib_cursor_t *ib_crsr_t;
339
340 /** This function is used to compare two data fields for which the data type
341 is such that we must use the client code to compare them.
342
343 @param col_meta column meta data
344 @param p1 key
345 @param p1_len key length
346 @param p2 second key
347 @param p2_len second key length
348 @return 1, 0, -1, if a is greater, equal, less than b, respectively */
349
350 typedef int (*ib_client_cmp_t)(const ib_col_meta_t *col_meta,
351 const ib_byte_t *p1, uint64_t p1_len,
352 const ib_byte_t *p2, uint64_t p2_len);
353
354 /* This should be the same as univ.i */
355 /** Represents SQL_NULL length */
356 constexpr uint32_t IB_SQL_NULL = 0xFFFFFFFF;
357
358 /** Start a transaction that's been rolled back. This special function
359 exists for the case when InnoDB's deadlock detector has rolledack
360 a transaction. While the transaction has been rolled back the handle
361 is still valid and can be reused by calling this function. If you
362 don't want to reuse the transaction handle then you can free the handle
363 by calling ib_trx_release().
364 @return innobase txn handle */
365 ib_err_t ib_trx_start(
366 ib_trx_t ib_trx, /*!< in: transaction to restart */
367 ib_trx_level_t ib_trx_level, /*!< in: trx isolation level */
368 bool read_write, /*!< in: true if read write
369 transaction */
370 bool auto_commit, /*!< in: auto commit after each
371 single DML */
372 void *thd); /*!< in: THD */
373
374 /** Begin a transaction. This will allocate a new transaction handle and
375 put the transaction in the active state.
376 @param[in] ib_trx_level trx isolation level
377 @param[in] read_write true if read write transaction
378 @param[in] auto_commit auto commit after each single DML
379 @param[in,out] thd MySQL THD
380 @return innobase txn handle */
381 ib_trx_t ib_trx_begin(ib_trx_level_t ib_trx_level, bool read_write,
382 bool auto_commit, void *thd);
383
384 /** Check if the transaction is read_only */
385 uint32_t ib_trx_read_only(ib_trx_t ib_trx); /*!< in: trx handle */
386
387 /** Release the resources of the transaction. If the transaction was
388 selected as a victim by InnoDB and rolled back then use this function
389 to free the transaction handle.
390 @return DB_SUCCESS or err code */
391 ib_err_t ib_trx_release(ib_trx_t ib_trx); /*!< in: trx handle */
392
393 /** Commit a transaction. This function will release the schema latches too.
394 It will also free the transaction handle.
395 @return DB_SUCCESS or err code */
396 ib_err_t ib_trx_commit(ib_trx_t ib_trx); /*!< in: trx handle */
397
398 /** Rollback a transaction. This function will release the schema latches too.
399 It will also free the transaction handle.
400 @return DB_SUCCESS or err code */
401 ib_err_t ib_trx_rollback(ib_trx_t ib_trx); /*!< in: trx handle */
402
403 /** Open an InnoDB secondary index cursor and return a cursor handle to it.
404 @return DB_SUCCESS or err code */
405 ib_err_t ib_cursor_open_index_using_name(
406 ib_crsr_t ib_open_crsr, /*!< in: open/active cursor */
407 const char *index_name, /*!< in: secondary index name */
408 ib_crsr_t *ib_crsr, /*!< out,own: InnoDB index cursor */
409 int *idx_type, /*!< out: index is cluster index */
410 ib_id_u64_t *idx_id); /*!< out: index id */
411
412 /** Open an InnoDB table by name and return a cursor handle to it.
413 @return DB_SUCCESS or err code */
414 ib_err_t ib_cursor_open_table(
415 const char *name, /*!< in: table name */
416 ib_trx_t ib_trx, /*!< in: Current transaction handle
417 can be NULL */
418 ib_crsr_t *ib_crsr); /*!< out,own: InnoDB cursor */
419
420 /** Reset the cursor.
421 @return DB_SUCCESS or err code */
422 ib_err_t ib_cursor_reset(ib_crsr_t ib_crsr); /*!< in/out: InnoDB cursor */
423
424 /** Close an InnoDB table and free the cursor.
425 @return DB_SUCCESS or err code */
426 ib_err_t ib_cursor_close(ib_crsr_t ib_crsr); /*!< in/out: InnoDB cursor */
427
428 /** update the cursor with new transactions and also reset the cursor
429 @return DB_SUCCESS or err code */
430 ib_err_t ib_cursor_new_trx(ib_crsr_t ib_crsr, /*!< in/out: InnoDB cursor */
431 ib_trx_t ib_trx); /*!< in: transaction */
432
433 /** Commit the transaction in a cursor
434 @return DB_SUCCESS or err code */
435 ib_err_t ib_cursor_commit_trx(ib_crsr_t ib_crsr, /*!< in/out: InnoDB cursor */
436 ib_trx_t ib_trx); /*!< in: transaction */
437
438 /** Insert a row to a table.
439 @return DB_SUCCESS or err code */
440 ib_err_t ib_cursor_insert_row(
441 ib_crsr_t ib_crsr, /*!< in/out: InnoDB cursor instance */
442 const ib_tpl_t ib_tpl); /*!< in: tuple to insert */
443
444 /** Update a row in a table.
445 @return DB_SUCCESS or err code */
446 ib_err_t ib_cursor_update_row(
447 ib_crsr_t ib_crsr, /*!< in: InnoDB cursor instance */
448 const ib_tpl_t ib_old_tpl, /*!< in: Old tuple in table */
449 const ib_tpl_t ib_new_tpl); /*!< in: New tuple to update */
450
451 /** Delete a row in a table.
452 @return DB_SUCCESS or err code */
453 ib_err_t ib_cursor_delete_row(ib_crsr_t ib_crsr); /*!< in: cursor instance */
454
455 /** Read current row.
456 @return DB_SUCCESS or err code */
457 ib_err_t ib_cursor_read_row(
458 ib_crsr_t ib_crsr, /*!< in: InnoDB cursor instance */
459 ib_tpl_t ib_tpl, /*!< out: read cols into this tuple */
460 ib_tpl_t cmp_tpl, /*!< in: tuple to compare and stop
461 reading */
462 int mode, /*!< in: mode determine when to
463 stop read */
464 void **row_buf, /*!< in/out: row buffer */
465 uint64_t *row_len, /*!< in/out: row buffer len */
466 uint64_t *used_len); /*!< in/out: row buffer len used */
467
468 /** Move cursor to the first record in the table.
469 @return DB_SUCCESS or err code */
470 ib_err_t ib_cursor_first(ib_crsr_t ib_crsr); /*!< in: InnoDB cursor instance */
471
472 /** Move cursor to the next record in the table.
473 @return DB_SUCCESS or err code */
474 ib_err_t ib_cursor_next(ib_crsr_t ib_crsr); /*!< in: InnoDB cursor instance */
475
476 /** Search for key.
477 @return DB_SUCCESS or err code */
478 ib_err_t ib_cursor_moveto(ib_crsr_t ib_crsr, /*!< in: InnoDB cursor instance */
479 ib_tpl_t ib_tpl, /*!< in: Key to search for */
480 ib_srch_mode_t ib_srch_mode, /*!< in: search mode */
481 uint64_t direction); /*!< in: search direction */
482
483 /** Set the match mode for ib_cursor_move().
484 @param[in] ib_crsr Cursor instance
485 @param[in] match_mode ib_cursor_moveto match mode*/
486 void ib_cursor_set_match_mode(ib_crsr_t ib_crsr, ib_match_mode_t match_mode);
487
488 /** Set a column of the tuple. Make a copy using the tuple's heap.
489 @param[in] ib_tpl tuple instance
490 @param[in] col_no column index in tuple
491 @param[in] src data value
492 @param[in] len data value len
493 @param[in] need_cpy if need memcpy
494 @return DB_SUCCESS or error code */
495 ib_err_t ib_col_set_value(ib_tpl_t ib_tpl, ib_ulint_t col_no, const void *src,
496 uint64_t len, bool need_cpy);
497
498 /** Get the size of the data available in the column the tuple.
499 @param[in] ib_tpl tuple instance
500 @param[in] i column index in tuple
501 @return bytes avail or IB_SQL_NULL */
502 uint64_t ib_col_get_len(ib_tpl_t ib_tpl, ib_ulint_t i);
503
504 /** Copy a column value from the tuple.
505 @param[in] ib_tpl tuple instance
506 @param[in] i in column index in tuple
507 @param[out] dst copied data value
508 @param[in] len max data value len to copy
509 @return bytes copied or IB_SQL_NULL */
510 uint64_t ib_col_copy_value(ib_tpl_t ib_tpl, ib_ulint_t i, void *dst,
511 uint32_t len);
512
513 /** Read a signed int 8 bit column from an InnoDB tuple.
514 @param[in] ib_tpl InnoDB tuple
515 @param[in] i column number
516 @param[out] ival integer value
517 @return DB_SUCCESS or error */
518 ib_err_t ib_tuple_read_i8(ib_tpl_t ib_tpl, ib_ulint_t i, int8_t *ival);
519
520 /** Read an unsigned int 8 bit column from an InnoDB tuple.
521 @param[in] ib_tpl InnoDB tuplr
522 @param[in] i column number
523 @param[out] ival integer value
524 @return DB_SUCCESS or error */
525 ib_err_t ib_tuple_read_u8(ib_tpl_t ib_tpl, ib_ulint_t i, uint8_t *ival);
526
527 /** Read a signed int 16 bit column from an InnoDB tuple.
528 @param[in] ib_tpl InnoDB tuple
529 @param[in] i column number
530 @param[out] ival integer value
531 @return DB_SUCCESS or error */
532 ib_err_t ib_tuple_read_i16(ib_tpl_t ib_tpl, ib_ulint_t i, int16_t *ival);
533
534 /** Read an unsigned int 16 bit column from an InnoDB tuple.
535 @param[in] ib_tpl InnoDB tuple
536 @param[in] i column number
537 @param[out] ival integer value
538 @return DB_SUCCESS or error */
539 ib_err_t ib_tuple_read_u16(ib_tpl_t ib_tpl, ib_ulint_t i, uint16_t *ival);
540
541 /** Read a signed int 32 bit column from an InnoDB tuple.
542 @param[in] ib_tpl InnoDB tuple
543 @param[in] i column number
544 @param[out] ival integer value
545 @return DB_SUCCESS or error */
546 ib_err_t ib_tuple_read_i32(ib_tpl_t ib_tpl, ib_ulint_t i, int32_t *ival);
547
548 /** Read an unsigned int 32 bit column from an InnoDB tuple.
549 @param[in] ib_tpl InnoDB tuple
550 @param[in] i column number
551 @param[out] ival integer value
552 @return DB_SUCCESS or error */
553 ib_err_t ib_tuple_read_u32(ib_tpl_t ib_tpl, ib_ulint_t i, uint32_t *ival);
554
555 /** Read a signed int 64 bit column from an InnoDB tuple.
556 @param[in] ib_tpl InnoDB tuple
557 @param[in] i column number
558 @param[out] ival integer value
559 @return DB_SUCCESS or error */
560 ib_err_t ib_tuple_read_i64(ib_tpl_t ib_tpl, ib_ulint_t i, int64_t *ival);
561
562 /** Read an unsigned int 64 bit column from an InnoDB tuple.
563 @param[in] ib_tpl InnoDB tuple
564 @param[in] i column number
565 @param[out] ival integer value
566 @return DB_SUCCESS or error */
567 ib_err_t ib_tuple_read_u64(ib_tpl_t ib_tpl, ib_ulint_t i, uint64_t *ival);
568
569 /** Get a column value pointer from the tuple.
570 @param[in] ib_tpl tuple instance
571 @param[in] i column index in tuple
572 @return NULL or pointer to buffer */
573 const void *ib_col_get_value(ib_tpl_t ib_tpl, ib_ulint_t i);
574
575 /** Get a column type, length and attributes from the tuple.
576 @param[in] ib_tpl InnoDB tuple
577 @param[in] i column number
578 @param[out] ib_col_meta column meta data
579 @return len of column data */
580 uint64_t ib_col_get_meta(ib_tpl_t ib_tpl, ib_ulint_t i,
581 ib_col_meta_t *ib_col_meta);
582
583 /** "Clear" or reset an InnoDB tuple. We free the heap and recreate the tuple.
584 @return new tuple, or NULL */
585 ib_tpl_t ib_tuple_clear(ib_tpl_t ib_tpl); /*!< in: InnoDB tuple */
586
587 /** Create a new cluster key search tuple and copy the contents of the
588 secondary index key tuple columns that refer to the cluster index record
589 to the cluster key. It does a deep copy of the column data.
590 @param[in] ib_crsr secondary index cursor
591 @param[out] ib_dst_tpl destination tuple
592 @param[in] ib_src_tpl source tuple
593 @return DB_SUCCESS or error code */
594 ib_err_t ib_tuple_get_cluster_key(ib_crsr_t ib_crsr, ib_tpl_t *ib_dst_tpl,
595 const ib_tpl_t ib_src_tpl);
596
597 /** Create an InnoDB tuple used for index/table search.
598 @param[in] ib_crsr Cursor instance
599 @return tuple for current index */
600 ib_tpl_t ib_sec_search_tuple_create(ib_crsr_t ib_crsr);
601
602 /** Create an InnoDB tuple used for index/table search.
603 @param[in] ib_crsr Cursor instance
604 @return tuple for current index */
605 ib_tpl_t ib_sec_read_tuple_create(ib_crsr_t ib_crsr);
606
607 /** Create an InnoDB tuple used for table key operations.
608 * @param[in] ib_crsr Cursor instance
609 @return tuple for current table */
610 ib_tpl_t ib_clust_search_tuple_create(ib_crsr_t ib_crsr);
611
612 /** Create an InnoDB tuple for table row operations.
613 @param[in] ib_crsr Cursor instance
614 @return tuple for current table */
615 ib_tpl_t ib_clust_read_tuple_create(ib_crsr_t ib_crsr);
616
617 /** Return the number of user columns in the tuple definition.
618 @param[in] ib_tpl Tuple for current table
619 @return number of user columns */
620 uint64_t ib_tuple_get_n_user_cols(const ib_tpl_t ib_tpl);
621
622 /** Return the number of columns in the tuple definition.
623 @param[in] ib_tpl Tuple for current table
624 @return number of columns */
625 uint64_t ib_tuple_get_n_cols(const ib_tpl_t ib_tpl);
626
627 /** Destroy an InnoDB tuple.
628 @param[in] ib_tpl Tuple for current table*/
629 void ib_tuple_delete(ib_tpl_t ib_tpl);
630
631 /** Get a table id.
632 @param[in] table_name table_to_find
633 @param[out] table_id table id if found
634 @return DB_SUCCESS if found */
635 ib_err_t ib_table_get_id(const char *table_name, ib_id_u64_t *table_id);
636
637 /** Check if cursor is positioned.
638 @param[in] ib_crsr InnoDB cursor instance
639 @return IB_true if positioned */
640 bool ib_cursor_is_positioned(const ib_crsr_t ib_crsr);
641
642 /** Checks if the data dictionary is latched in exclusive mode by a
643 user transaction.
644 @param[in] ib_trx transaction
645 @return true if exclusive latch */
646 bool ib_schema_lock_is_exclusive(const ib_trx_t ib_trx);
647
648 /** Lock an InnoDB cursor/table.
649 @param[in,out] ib_crsr InnoDB cursor
650 @param[in] ib_lck_mode InnoDB lock mode
651 @return DB_SUCCESS or error code */
652 ib_err_t ib_cursor_lock(ib_crsr_t ib_crsr, ib_lck_mode_t ib_lck_mode);
653
654 /** Set the Lock mode of the cursor.
655 @param[in,out] ib_crsr InnoDB cursor
656 @param[in] ib_lck_mode InnoDB lock mode
657 @return DB_SUCCESS or error code */
658 ib_err_t ib_cursor_set_lock_mode(ib_crsr_t ib_crsr, ib_lck_mode_t ib_lck_mode);
659
660 /** Set need to access clustered index record flag.
661 @param[in,out] ib_crsr InnoDB cursor */
662 void ib_cursor_set_cluster_access(ib_crsr_t ib_crsr);
663
664 /** Inform the cursor that it's the start of an SQL statement.
665 @param[in,out] ib_crsr InnoDB cursor */
666 void ib_cursor_stmt_begin(ib_crsr_t ib_crsr);
667
668 /** Write a double value to a column.
669 @param[in] ib_tpl InnoDB tuple
670 @param[in] col_no column number
671 @param[in] val value to write
672 @return DB_SUCCESS or error */
673 ib_err_t ib_tuple_write_double(ib_tpl_t ib_tpl, int col_no, double val);
674
675 /** Read a double column value from an InnoDB tuple.
676 @param[in] ib_tpl InnoDB tuple
677 @param[in] col_no column number
678 @param[out] dval double value
679 @return DB_SUCCESS or error */
680 ib_err_t ib_tuple_read_double(ib_tpl_t ib_tpl, uint64_t col_no, double *dval);
681
682 /** Write a float value to a column.
683 @param[in,out] ib_tpl tuple to write to
684 @param[in] col_no column number
685 @param[in] val value to write
686 @return DB_SUCCESS or error */
687 ib_err_t ib_tuple_write_float(ib_tpl_t ib_tpl, int col_no, float val);
688
689 /** Read a float value from an InnoDB tuple.
690 @param[in] ib_tpl InnoDB tuple
691 @param[in] col_no column number
692 @param[out] fval float value
693 @return DB_SUCCESS or error */
694 ib_err_t ib_tuple_read_float(ib_tpl_t ib_tpl, uint64_t col_no, float *fval);
695
696 /** Get a column type, length and attributes from the tuple.
697 @param[in] ib_crsr InnoDB cursor instance
698 @param[in] i column index in tuple
699 @return len of column data */
700 const char *ib_col_get_name(ib_crsr_t ib_crsr, ib_ulint_t i);
701
702 /** Get an index field name from the cursor.
703 @param[in] ib_crsr InnoDB cursor instance
704 @param[in] i column index in tuple
705 @return name of the field */
706 const char *ib_get_idx_field_name(ib_crsr_t ib_crsr, ib_ulint_t i);
707
708 /** Get generic configure status
709 @return configure status*/
710 int ib_cfg_get_cfg();
711
712 /** Return isolation configuration set by "innodb_api_trx_level"
713 @return trx isolation level*/
714 ib_trx_level_t ib_cfg_trx_level();
715
716 /** Return configure value for background commit interval (in seconds)
717 @return background commit interval (in seconds) */
718 uint64_t ib_cfg_bk_commit_interval();
719
720 /** Get a trx start time.
721 @return trx start_time */
722 uint64_t ib_trx_get_start_time(ib_trx_t ib_trx); /*!< in: transaction */
723
724 /** Wrapper of ut_strerr() which converts an InnoDB error number to a
725 human readable text message.
726 @return string, describing the error */
727 const char *ib_ut_strerr(ib_err_t num); /*!< in: error number */
728
729 /** Get the SDI keys in a tablespace into vector.
730 @param[in] tablespace_id tablespace id
731 @param[in,out] ib_sdi_vector vector to hold objects with tablespace types
732 and ids
733 @param[in,out] trx data dictionary transaction
734 @return DB_SUCCESS if SDI keys retrieval is successful, else error */
735 ib_err_t ib_sdi_get_keys(uint32_t tablespace_id, ib_sdi_vector_t *ib_sdi_vector,
736 ib_trx_t trx);
737
738 /** Retrieve SDI from tablespace
739 @param[in] tablespace_id tablespace id
740 @param[in] ib_sdi_key SDI key
741 @param[in,out] comp_sdi in: buffer to hold the SDI BLOB
742 out: compressed SDI retrieved from tablespace
743 @param[in,out] comp_sdi_len in: Size of memory allocated
744 out: compressed length of SDI
745 @param[out] uncomp_sdi_len out: uncompressed length of SDI
746 @param[in,out] trx innodb transaction
747 @return DB_SUCCESS if SDI retrieval is successful, else error
748 in case the passed buffer length is smaller than the actual SDI
749 DB_OUT_OF_MEMORY is thrown and uncompressed length is set in
750 uncomp_sdi_len */
751 ib_err_t ib_sdi_get(uint32_t tablespace_id, const ib_sdi_key_t *ib_sdi_key,
752 void *comp_sdi, uint32_t *comp_sdi_len,
753 uint32_t *uncomp_sdi_len, ib_trx_t trx);
754
755 /** Insert/Update SDI in tablespace
756 @param[in] tablespace_id tablespace id
757 @param[in] sdi_key SDI key to uniquely identify the tablespace
758 object
759 @param[in] uncomp_len uncompressed length of SDI
760 @param[in] comp_len compressed length of SDI
761 @param[in] sdi compressed SDI to be stored in tablespace
762 @param[in,out] trx innodb transaction
763 @return DB_SUCCESS if SDI Insert/Update is successful, else error */
764 ib_err_t ib_sdi_set(uint32_t tablespace_id, const ib_sdi_key_t *sdi_key,
765 uint32_t uncomp_len, uint32_t comp_len, const void *sdi,
766 ib_trx_t trx);
767
768 /** Delete SDI from tablespace.
769 @param[in] tablespace_id tablespace id
770 @param[in] sdi_key SDI key to uniquely identify the tablespace
771 object
772 @param[in,out] trx innodb transaction
773 @return DB_SUCCESS if SDI deletion is successful, else error */
774 ib_err_t ib_sdi_delete(uint32_t tablespace_id, const ib_sdi_key_t *sdi_key,
775 ib_trx_t trx);
776
777 /** Create SDI in a tablespace
778 @param[in] tablespace_id InnoDB tablespace id
779 @return DB_SUCCESS if SDI index creation is successful, else error */
780 ib_err_t ib_sdi_create(space_id_t tablespace_id);
781
782 /** Drop SDI Index from tablespace. This should be used only when SDI
783 is corrupted.
784 @param[in] tablespace_id InnoDB tablespace id
785 @return DB_SUCCESS if dropping of SDI indexes is successful, else error */
786 ib_err_t ib_sdi_drop(space_id_t tablespace_id);
787
788 /** Flush SDI in a tablespace. The pages of a SDI Index modified by the
789 transaction will be flushed to disk.
790 @param[in] space_id tablespace id
791 @return DB_SUCCESS always */
792 ib_err_t ib_sdi_flush(space_id_t space_id);
793
794 #ifdef UNIV_MEMCACHED_SDI
795 /** Wrapper function to retrieve SDI from tablespace.
796 @param[in] crsr Memcached cursor
797 @param[in] key Memcached key
798 @param[in,out] sdi SDI data retrieved
799 @param[in,out] sdi_len in: Size of allocated memory
800 out: Actual SDI length
801 @return DB_SUCCESS if SDI retrieval is successful, else error */
802 ib_err_t ib_memc_sdi_get(ib_crsr_t crsr, const char *key, void *sdi,
803 uint64_t *sdi_len);
804
805 /** Wrapper function to delete SDI from tablespace.
806 @param[in,out] crsr Memcached cursor
807 @param[in] key Memcached key
808 @return DB_SUCCESS if SDI deletion is successful, else error */
809 ib_err_t ib_memc_sdi_delete(ib_crsr_t crsr, const char *key);
810
811 /** Wrapper function to insert SDI into tablespace.
812 @param[in] crsr Memcached cursor
813 @param[in] key Memcached key
814 @param[in] sdi SDI to be stored in tablespace
815 @param[in] sdi_len SDI length
816 @return DB_SUCCESS if SDI insertion is successful, else error */
817 ib_err_t ib_memc_sdi_set(ib_crsr_t crsr, const char *key, const void *sdi,
818 uint64_t *sdi_len);
819
820 /** Wrapper function to create SDI in a tablespace.
821 @param[in,out] crsr Memcached cursor
822 @return DB_SUCCESS if SDI creation is successful, else error */
823 ib_err_t ib_memc_sdi_create(ib_crsr_t crsr);
824
825 /** Wrapper function to drop SDI in a tablespace.
826 @param[in,out] crsr Memcached cursor
827 @return DB_SUCCESS if dropping of SDI is successful, else error */
828 ib_err_t ib_memc_sdi_drop(ib_crsr_t crsr);
829
830 /* Wrapper function to retrieve list of SDI keys into the buffer
831 The SDI keys are copied in the from x:y and separated by '|'.
832 @param[in,out] crsr Memcached cursor
833 @param[in] key Memcached key
834 @param[out] sdi The keys are copies into this buffer
835 @return DB_SUCCESS if SDI keys retrieval is successful, else error */
836 ib_err_t ib_memc_sdi_get_keys(ib_crsr_t crsr, const char *key, void *sdi,
837 uint64_t list_buf_len);
838 #endif /* UNIV_MEMCACHED_SDI */
839
840 /** Check the table whether it contains virtual columns.
841 @param[in] crsr InnoDB Cursor
842 @return true if the table contains virtual column else failure. */
843 bool ib_is_virtual_table(ib_crsr_t crsr);
844
845 #ifdef UNIV_MEMCACHED_SDI
846 #define ONLY_FOR_MEMCACHED_SDI(x) x
847 #else
848 #define ONLY_FOR_MEMCACHED_SDI(x)
849 #endif
850
851 #define FOR_EACH_API_METHOD_NAME_STEM(transform) \
852 transform(cursor_open_table) /**/ \
853 transform(cursor_read_row) /**/ \
854 transform(cursor_insert_row) /**/ \
855 transform(cursor_delete_row) /**/ \
856 transform(cursor_update_row) /**/ \
857 transform(cursor_moveto) /**/ \
858 transform(cursor_first) /**/ \
859 transform(cursor_next) /**/ \
860 transform(cursor_set_match_mode) /**/ \
861 transform(sec_search_tuple_create) /**/ \
862 transform(clust_read_tuple_create) /**/ \
863 transform(tuple_delete) /**/ \
864 transform(tuple_read_u8) /**/ \
865 transform(tuple_read_u16) /**/ \
866 transform(tuple_read_u32) /**/ \
867 transform(tuple_read_u64) /**/ \
868 transform(tuple_read_i8) /**/ \
869 transform(tuple_read_i16) /**/ \
870 transform(tuple_read_i32) /**/ \
871 transform(tuple_read_i64) /**/ \
872 transform(tuple_get_n_cols) /**/ \
873 transform(col_set_value) /**/ \
874 transform(col_get_value) /**/ \
875 transform(col_get_meta) /**/ \
876 transform(trx_begin) /**/ \
877 transform(trx_commit) /**/ \
878 transform(trx_rollback) /**/ \
879 transform(trx_start) /**/ \
880 transform(trx_release) /**/ \
881 transform(cursor_lock) /**/ \
882 transform(cursor_close) /**/ \
883 transform(cursor_new_trx) /**/ \
884 transform(cursor_reset) /**/ \
885 transform(col_get_name) /**/ \
886 transform(cursor_open_index_using_name) /**/ \
887 transform(cfg_get_cfg) /**/ \
888 transform(cursor_set_cluster_access) /**/ \
889 transform(cursor_commit_trx) /**/ \
890 transform(cfg_trx_level) /**/ \
891 transform(tuple_get_n_user_cols) /**/ \
892 transform(cursor_set_lock_mode) /**/ \
893 transform(get_idx_field_name) /**/ \
894 transform(trx_get_start_time) /**/ \
895 transform(cfg_bk_commit_interval) /**/ \
896 transform(ut_strerr) /**/ \
897 transform(cursor_stmt_begin) /**/ \
898 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_get)) /**/ \
899 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_delete)) /**/ \
900 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_set)) /**/ \
901 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_create)) /**/ \
902 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_drop)) /**/ \
903 ONLY_FOR_MEMCACHED_SDI(transform(memc_sdi_get_keys)) /**/ \
904 transform(trx_read_only) /**/ \
905 transform(is_virtual_table) /**/
906
907 #endif /* api0api_h */