MySQL 8.0.39
Source Code Documentation
row0mysql.cc File Reference

Interface between Innobase row operations and MySQL. More...

#include <debug_sync.h>
#include <gstream.h>
#include <spatial.h>
#include <sql_class.h>
#include <sql_const.h>
#include <sys/types.h>
#include <algorithm>
#include <deque>
#include <new>
#include <vector>
#include "btr0sea.h"
#include "ddl0ddl.h"
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "dict0load.h"
#include "dict0priv.h"
#include "dict0stats.h"
#include "dict0stats_bg.h"
#include "fil0fil.h"
#include "fsp0file.h"
#include "fsp0sysspace.h"
#include "fts0fts.h"
#include "fts0types.h"
#include "ha_prototypes.h"
#include "ibuf0ibuf.h"
#include "lock0lock.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "pars0pars.h"
#include "que0que.h"
#include "rem0cmp.h"
#include "row0ext.h"
#include "row0import.h"
#include "row0ins.h"
#include "row0mysql.h"
#include "row0pread.h"
#include "row0row.h"
#include "row0sel.h"
#include "row0upd.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0roll.h"
#include "trx0undo.h"
#include "ut0cpu_cache.h"
#include "ut0new.h"
#include "current_thd.h"
#include "my_dbug.h"
#include "my_io.h"

Classes

struct  row_mysql_drop_t
 Chain node of the list of tables to drop in the background. More...
 
class  ib_dec_counter
 

Macros

#define PREBUILT_HEAP_INITIAL_SIZE
 

Typedefs

typedef std::vector< btr_pcur_t, ut::allocator< btr_pcur_t > > cursors_t
 

Functions

static UT_LIST_BASE_NODE_T (row_mysql_drop_t, row_mysql_drop_list) row_mysql_drop_list
 List of tables we should drop in background. More...
 
static bool row_add_table_to_background_drop_list (const char *name)
 If a table is not yet in the drop list, adds the table to the list of tables which the master thread drops in background. More...
 
void row_wait_for_background_drop_list_empty ()
 Wait for the background drop list to become empty. More...
 
static void row_mysql_delay_if_needed (void)
 Delays an INSERT, DELETE or UPDATE operation if the purge is lagging. More...
 
void row_mysql_prebuilt_free_blob_heap (row_prebuilt_t *prebuilt)
 Frees the blob heap in prebuilt when no longer needed. More...
 
byterow_mysql_store_true_var_len (byte *dest, ulint len, ulint lenlen)
 Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row format. More...
 
const byterow_mysql_read_true_varchar (ulint *len, const byte *field, ulint lenlen)
 Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and returns a pointer to the data. More...
 
void row_mysql_store_blob_ref (byte *dest, ulint col_len, const void *data, ulint len)
 Stores a reference to a BLOB in the MySQL format. More...
 
const byterow_mysql_read_blob_ref (ulint *len, const byte *ref, ulint col_len)
 Reads a reference to a BLOB in the MySQL format. More...
 
void row_mysql_store_geometry (byte *dest, ulint dest_len, const byte *src, ulint src_len)
 Converting InnoDB geometry data format to MySQL data format. More...
 
static const byterow_mysql_read_geometry (ulint *len, const byte *ref, ulint col_len)
 Read geometry data in the MySQL format. More...
 
void row_mysql_pad_col (ulint mbminlen, byte *pad, ulint len)
 Pad a column with spaces. More...
 
byterow_mysql_store_col_in_innobase_format (dfield_t *dfield, byte *buf, bool row_format_col, const byte *mysql_data, ulint col_len, ulint comp)
 Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format. More...
 
static void row_mysql_convert_row_to_innobase (dtuple_t *row, row_prebuilt_t *prebuilt, const byte *mysql_rec, mem_heap_t **heap)
 Convert a row in the MySQL format to a row in the Innobase format. More...
 
bool row_mysql_handle_errors (dberr_t *new_err, trx_t *trx, que_thr_t *thr, trx_savept_t *savept)
 Handles user errors and lock waits detected by the database engine. More...
 
row_prebuilt_trow_create_prebuilt (dict_table_t *table, ulint mysql_row_len)
 Create a prebuilt struct for a MySQL table handle. More...
 
void row_prebuilt_free (row_prebuilt_t *prebuilt, bool dict_locked)
 Free a prebuilt struct for a MySQL table handle. More...
 
void row_update_prebuilt_trx (row_prebuilt_t *prebuilt, trx_t *trx)
 Updates the transaction pointers in query graphs stored in the prebuilt struct. More...
 
static dtuple_trow_get_prebuilt_insert_row (row_prebuilt_t *prebuilt)
 Gets pointer to a prebuilt dtuple used in insertions. More...
 
static void row_update_statistics_if_needed (dict_table_t *table)
 Updates the table modification counter and calculates new estimates for table and index statistics if necessary. More...
 
dberr_t row_lock_table_autoinc_for_mysql (row_prebuilt_t *prebuilt)
 Sets an AUTO_INC type lock on the table mentioned in prebuilt. More...
 
dberr_t row_lock_table (row_prebuilt_t *prebuilt)
 Sets a table lock on the table mentioned in prebuilt. More...
 
static dberr_t row_explicit_rollback (dict_index_t *index, const dtuple_t *entry, que_thr_t *thr, mtr_t *mtr)
 Perform explicit rollback in absence of UNDO logs. More...
 
static void row_mysql_to_innobase (dtuple_t *row, row_prebuilt_t *prebuilt, const byte *mysql_rec)
 Convert a row in the MySQL format to a row in the Innobase format. More...
 
static dberr_t row_insert_for_mysql_using_cursor (const byte *mysql_rec, row_prebuilt_t *prebuilt)
 Does an insert for MySQL using cursor interface. More...
 
static dberr_t row_insert_for_mysql_using_ins_graph (const byte *mysql_rec, row_prebuilt_t *prebuilt)
 Does an insert for MySQL using INSERT graph. More...
 
dberr_t row_insert_for_mysql (const byte *mysql_rec, row_prebuilt_t *prebuilt)
 Does an insert for MySQL. More...
 
void row_prebuild_sel_graph (row_prebuilt_t *prebuilt)
 Builds a dummy query graph used in selects. More...
 
upd_node_trow_create_update_node_for_mysql (dict_table_t *table, mem_heap_t *heap)
 Creates an query graph node of 'update' type to be used in the MySQL interface. More...
 
upd_trow_get_prebuilt_update_vector (row_prebuilt_t *prebuilt)
 Gets pointer to a prebuilt update vector used in updates. More...
 
static void row_fts_do_update (trx_t *trx, dict_table_t *table, doc_id_t old_doc_id, doc_id_t new_doc_id)
 
static dberr_t row_fts_update_or_delete (row_prebuilt_t *prebuilt)
 
static void init_fts_doc_id_for_ref (dict_table_t *table, ulint *depth)
 Initialize the Doc ID system for FK table with FTS index. More...
 
static dberr_t row_update_inplace_for_intrinsic (const upd_node_t *node)
 Do an in-place update in the intrinsic table. More...
 
static dberr_t row_delete_for_mysql_using_cursor (const upd_node_t *node, cursors_t &delete_entries, const bool restore_delete)
 Delete row from table (corresponding entries from all the indexes). More...
 
static dberr_t row_update_for_mysql_using_cursor (const upd_node_t *node, cursors_t &delete_entries, que_thr_t *thr)
 Does an update of a row for MySQL by inserting new entry with update values. More...
 
static dberr_t row_del_upd_for_mysql_using_cursor (row_prebuilt_t *prebuilt)
 Does an update or delete of a row for MySQL. More...
 
static dberr_t row_update_for_mysql_using_upd_graph (const byte *mysql_rec, row_prebuilt_t *prebuilt)
 Does an update or delete of a row for MySQL. More...
 
dberr_t row_update_for_mysql (const byte *mysql_rec, row_prebuilt_t *prebuilt)
 Does an update or delete of a row for MySQL. More...
 
void row_delete_all_rows (dict_table_t *table)
 Delete all rows for the given table by freeing/truncating indexes. More...
 
dberr_t row_update_cascade_for_mysql (que_thr_t *thr, upd_node_t *node, dict_table_t *table)
 Does a cascaded delete or set null in a foreign key operation. More...
 
bool row_table_got_default_clust_index (const dict_table_t *table)
 Checks if a table is such that we automatically created a clustered index on it (on row id). More...
 
void row_mysql_freeze_data_dictionary (trx_t *trx, ut::Location location)
 Locks the data dictionary in shared mode from modifications, for performing foreign key check, rollback, or other operation invisible to MySQL. More...
 
void row_mysql_unfreeze_data_dictionary (trx_t *trx)
 Unlocks the data dictionary shared lock. More...
 
void row_mysql_lock_data_dictionary (trx_t *trx, ut::Location location)
 Locks the data dictionary exclusively for performing a table create or other data dictionary modification operation. More...
 
void row_mysql_unlock_data_dictionary (trx_t *trx)
 Unlocks the data dictionary exclusive lock. More...
 
dberr_t row_create_table_for_mysql (dict_table_t *&table, const char *compression, const HA_CREATE_INFO *create_info, trx_t *trx, mem_heap_t *heap)
 Creates a table for MySQL. More...
 
dberr_t row_create_index_for_mysql (dict_index_t *index, trx_t *trx, const ulint *field_lengths, dict_table_t *handler)
 Does an index creation operation for MySQL. More...
 
dberr_t row_table_load_foreign_constraints (trx_t *trx, const char *name, const dd::Table *dd_table)
 Loads foreign key constraints for the table being created. More...
 
static dberr_t row_drop_table_for_mysql_in_background (const char *name)
 Drops a table for MySQL as a background operation. More...
 
ulint row_drop_tables_for_mysql_in_background (void)
 TODO: NewDD: Need to check if there is need to keep background drop, in such case, the thd would be NULL (no MDL can be acquired) The master thread in srv0srv.cc calls this regularly to drop tables which we must drop in background after queries to them have ended. More...
 
static bool row_add_table_to_background_drop_list (const char *name[[maybe_unused]])
 If a table is not yet in the drop list, adds the table to the list of tables which the master thread drops in background. More...
 
static dberr_t row_mysql_table_id_reassign (dict_table_t *table, table_id_t *new_id)
 Reassigns the table identifier of a table. More...
 
static dict_table_trow_discard_tablespace_begin (const char *name, trx_t *trx)
 Setup the pre-requisites for DISCARD TABLESPACE. More...
 
static dberr_t row_discard_tablespace_foreign_key_checks (const trx_t *trx, const dict_table_t *table)
 Do the foreign key constraint checks. More...
 
static dberr_t row_discard_tablespace_end (trx_t *trx, dict_table_t *table, dberr_t err, aux_name_vec_t *aux_vec)
 Cleanup after the DISCARD TABLESPACE operation. More...
 
static dberr_t row_discard_tablespace (trx_t *trx, dict_table_t *table, aux_name_vec_t *aux_vec)
 Do the DISCARD TABLESPACE operation. More...
 
dberr_t row_discard_tablespace_for_mysql (const char *name, trx_t *trx)
 Discards the tablespace of a table which stored in an .ibd file. More...
 
dberr_t row_mysql_lock_table (trx_t *trx, dict_table_t *table, enum lock_mode mode, const char *op_info)
 Sets an exclusive lock on a table. More...
 
static dberr_t row_drop_ancillary_fts_tables (dict_table_t *table, aux_name_vec_t *aux_vec, trx_t *trx)
 Drop ancillary FTS tables as part of dropping a table. More...
 
static dberr_t row_drop_table_from_cache (dict_table_t *table, trx_t *trx)
 Drop a table from the memory cache as part of dropping a table. More...
 
dberr_t row_drop_tablespace (space_id_t space_id, const char *filepath)
 Drop a tablespace as part of dropping or renaming a table. More...
 
dberr_t row_drop_table_for_mysql (const char *name, trx_t *trx, bool nonatomic, dict_table_t *handler)
 Drop a table for MySQL. More...
 
bool row_is_mysql_tmp_table_name (const char *name)
 Checks if a table name contains the string "/#sql" which denotes temporary tables in MySQL. More...
 
dberr_t row_rename_table_for_mysql (const char *old_name, const char *new_name, const dd::Table *dd_table, trx_t *trx, bool replay)
 Renames a table for MySQL. More...
 
dberr_t row_mysql_parallel_select_count_star (trx_t *trx, std::vector< dict_index_t * > &indexes, size_t n_threads, ulint *n_rows)
 Read the total number of records in a consistent view. More...
 
static dberr_t parallel_check_table (trx_t *trx, dict_index_t *index, size_t n_threads, ulint *n_rows)
 
dberr_t row_scan_index_for_mysql (row_prebuilt_t *prebuilt, dict_index_t *index, size_t max_threads, bool check_keys, ulint *n_rows)
 Scans an index for either COUNT(*) or CHECK TABLE. More...
 
void row_mysql_init (void)
 Initialize this module. More...
 
void row_mysql_close (void)
 Close this module. More...
 

Variables

static const char * MODIFICATIONS_NOT_ALLOWED_MSG_FORCE_RECOVERY
 
bool row_rollback_on_timeout = false
 Provide optional 4.x backwards compatibility for 5.0 and above. More...
 
static ib_mutex_t row_drop_list_mutex
 Mutex protecting the background table drop list. More...
 
static bool row_mysql_drop_list_inited = false
 Flag: has row_mysql_drop_list been initialized? More...
 
constexpr uint32_t MAX_SRCH_KEY_VAL_BUFFER = 2 * 8 * MAX_REF_PARTS
 

Detailed Description

Interface between Innobase row operations and MySQL.

Contains also create table and other data dictionary operations.

Created 9/17/2000 Heikki Tuuri

Macro Definition Documentation

◆ PREBUILT_HEAP_INITIAL_SIZE

#define PREBUILT_HEAP_INITIAL_SIZE
Value:
(sizeof(*prebuilt) /* allocd in this function */ \
+ DTUPLE_EST_ALLOC(search_tuple_n_fields) /* search_tuple */ \
+ DTUPLE_EST_ALLOC(search_tuple_n_fields) /* m_stop_tuple */ \
+ DTUPLE_EST_ALLOC(ref_len) /* allocd in row_prebuild_sel_graph() */ \
+ sizeof(sel_node_t) + sizeof(que_fork_t) + \
sizeof(que_thr_t) /* allocd in row_get_prebuilt_update_vector() */ \
+ sizeof(upd_node_t) + sizeof(upd_t) + \
sizeof(upd_field_t) * table->get_n_cols() + sizeof(que_fork_t) + \
sizeof(que_thr_t) /* allocd in row_get_prebuilt_insert_row() */ \
+ sizeof(ins_node_t) /* mysql_row_len could be huge and we are not \
sure if this prebuilt instance is going to be \
used in inserts */ \
+ (mysql_row_len < 256 ? mysql_row_len : 0) + \
DTUPLE_EST_ALLOC(table->get_n_cols() + dict_table_get_n_v_cols(table)) + \
sizeof(que_fork_t) + sizeof(que_thr_t) + sizeof(*prebuilt->pcur) + \
sizeof(*prebuilt->clust_pcur))
#define DTUPLE_EST_ALLOC(n_fields)
Definition: data0data.h:219
static ulint dict_table_get_n_v_cols(const dict_table_t *table)
Gets the number of virtual columns in a table in the dictionary cache.
Definition: row0ins.h:162
Definition: que0que.h:301
Definition: que0que.h:242
Select statement node.
Definition: row0sel.h:329
Definition: row0upd.h:467
Definition: row0upd.h:701
Definition: row0upd.h:565

Typedef Documentation

◆ cursors_t

typedef std::vector<btr_pcur_t, ut::allocator<btr_pcur_t> > cursors_t

Function Documentation

◆ init_fts_doc_id_for_ref()

static void init_fts_doc_id_for_ref ( dict_table_t table,
ulint depth 
)
static

Initialize the Doc ID system for FK table with FTS index.

Parameters
tablein: table
depthin: recursive call depth

◆ parallel_check_table()

static dberr_t parallel_check_table ( trx_t trx,
dict_index_t index,
size_t  n_threads,
ulint n_rows 
)
static

◆ row_add_table_to_background_drop_list() [1/2]

static bool row_add_table_to_background_drop_list ( const char *  name)
static

If a table is not yet in the drop list, adds the table to the list of tables which the master thread drops in background.

We need this on Unix because in ALTER TABLE MySQL may call drop table even if the table has running queries on it. Also, if there are running foreign key checks on the table, we drop the table lazily.

Returns
true if the table was not yet in the drop list, and was added there in: table name

◆ row_add_table_to_background_drop_list() [2/2]

static bool row_add_table_to_background_drop_list ( const char *name [[maybe_unused])
static

If a table is not yet in the drop list, adds the table to the list of tables which the master thread drops in background.

We need this on Unix because in ALTER TABLE MySQL may call drop table even if the table has running queries on it. Also, if there are running foreign key checks on the table, we drop the table lazily.

Returns
true if the table was not yet in the drop list, and was added there

◆ row_create_index_for_mysql()

dberr_t row_create_index_for_mysql ( dict_index_t index,
trx_t trx,
const ulint field_lengths,
dict_table_t handler 
)

Does an index creation operation for MySQL.

TODO: currently failure to create an index results in dropping the whole table! This is no problem currently as all indexes must be created at the same time as the table.

Returns
error number or DB_SUCCESS
Parameters
indexin, own: index definition (will be freed)
trxin: transaction handle
field_lengthsin: if not NULL, must contain dict_index_get_n_fields(index) actual field lengths for the index columns, which are then checked for not being too large.
handlerin/out: table handler.

◆ row_create_prebuilt()

row_prebuilt_t * row_create_prebuilt ( dict_table_t table,
ulint  mysql_row_len 
)

Create a prebuilt struct for a MySQL table handle.

Returns
own: a prebuilt struct
Parameters
tablein: Innobase table handle
mysql_row_lenin: length in bytes of a row in the MySQL format

◆ row_create_table_for_mysql()

dberr_t row_create_table_for_mysql ( dict_table_t *&  table,
const char *  compression,
const HA_CREATE_INFO create_info,
trx_t trx,
mem_heap_t heap 
)

Creates a table for MySQL.

On success the in-memory table could be kept in non-LRU list while on failure the 'table' object will be freed.

Parameters
[in,out]tabletable definition(will be freed, or on DB_SUCCESS added to the data dictionary cache)
[in]compressioncompression algorithm to use, can be nullptr
[in]create_infoHA_CREATE_INFO object
[in,out]trxtransaction
[in]heaptemp memory heap or nullptr
Returns
error code or DB_SUCCESS

◆ row_create_update_node_for_mysql()

upd_node_t * row_create_update_node_for_mysql ( dict_table_t table,
mem_heap_t heap 
)

Creates an query graph node of 'update' type to be used in the MySQL interface.

Returns
own: update node
Parameters
tablein: table to update
heapin: mem heap from which allocated

◆ row_del_upd_for_mysql_using_cursor()

static dberr_t row_del_upd_for_mysql_using_cursor ( row_prebuilt_t prebuilt)
static

Does an update or delete of a row for MySQL.

Parameters
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_delete_all_rows()

void row_delete_all_rows ( dict_table_t table)

Delete all rows for the given table by freeing/truncating indexes.

Parameters
[in,out]tabletable handler

◆ row_delete_for_mysql_using_cursor()

static dberr_t row_delete_for_mysql_using_cursor ( const upd_node_t node,
cursors_t delete_entries,
const bool  restore_delete 
)
static

Delete row from table (corresponding entries from all the indexes).

Function will maintain cursor to the entries to invoke explicitly rollback just in case update action following delete fails.

Parameters
[in]nodeupdate node carrying information to delete.
[out]delete_entriesvector of cursor to deleted entries.
[in]restore_deleteif true, then restore DELETE records by unmarking delete.
Returns
error code or DB_SUCCESS

◆ row_discard_tablespace()

static dberr_t row_discard_tablespace ( trx_t trx,
dict_table_t table,
aux_name_vec_t aux_vec 
)
static

Do the DISCARD TABLESPACE operation.

Parameters
[in,out]trxtransaction handle
[in,out]tabletable to be discarded
[in,out]aux_vecfts aux table name vector
Returns
DB_SUCCESS or error code.

◆ row_discard_tablespace_begin()

static dict_table_t * row_discard_tablespace_begin ( const char *  name,
trx_t trx 
)
static

Setup the pre-requisites for DISCARD TABLESPACE.

It will start the transaction, acquire the data dictionary lock in X mode and open the table.

Returns
table instance or 0 if not found.
Parameters
namein: table name
trxin: transaction handle

◆ row_discard_tablespace_end()

static dberr_t row_discard_tablespace_end ( trx_t trx,
dict_table_t table,
dberr_t  err,
aux_name_vec_t aux_vec 
)
static

Cleanup after the DISCARD TABLESPACE operation.

Parameters
[in,out]trxtransaction handle
[in,out]tabletable to be discarded
[in]errerror code
[in,out]aux_vecfts aux table name vector
Returns
error code.

◆ row_discard_tablespace_for_mysql()

dberr_t row_discard_tablespace_for_mysql ( const char *  name,
trx_t trx 
)

Discards the tablespace of a table which stored in an .ibd file.

Discarding means that this function renames the .ibd file and assigns a new table id for the table. Also the flag table->ibd_file_missing is set to true.

Returns
error code or DB_SUCCESS
Parameters
namein: table name
trxin: transaction handle

◆ row_discard_tablespace_foreign_key_checks()

static dberr_t row_discard_tablespace_foreign_key_checks ( const trx_t trx,
const dict_table_t table 
)
static

Do the foreign key constraint checks.

Returns
DB_SUCCESS or error code.
Parameters
trxin: transaction handle
tablein: table to be discarded

◆ row_drop_ancillary_fts_tables()

static dberr_t row_drop_ancillary_fts_tables ( dict_table_t table,
aux_name_vec_t aux_vec,
trx_t trx 
)
inlinestatic

Drop ancillary FTS tables as part of dropping a table.

Parameters
[in,out]tableTable cache entry
[in,out]aux_vecFts aux table name vector
[in,out]trxTransaction handle
Returns
error code or DB_SUCCESS

◆ row_drop_table_for_mysql()

dberr_t row_drop_table_for_mysql ( const char *  name,
trx_t trx,
bool  nonatomic,
dict_table_t handler 
)

Drop a table for MySQL.

If the data dictionary was not already locked by the transaction, the transaction will be committed. Otherwise, the data dictionary will remain locked.

Parameters
[in]nameTable name
[in]trxTransaction handle
[in]nonatomicWhether it is permitted to release and reacquire dict_operation_lock
[in,out]handlerTable handler or NULL
Returns
error code or DB_SUCCESS

◆ row_drop_table_for_mysql_in_background()

static dberr_t row_drop_table_for_mysql_in_background ( const char *  name)
static

Drops a table for MySQL as a background operation.

MySQL relies on Unix in ALTER TABLE to the fact that the table handler does not remove the table before all handles to it has been removed. Furthermore, the MySQL's call to drop table must be non-blocking. Therefore we do the drop table as a background operation, which is taken care of by the master thread in srv0srv.cc.

Returns
error code or DB_SUCCESS
Parameters
namein: table name

◆ row_drop_table_from_cache()

static dberr_t row_drop_table_from_cache ( dict_table_t table,
trx_t trx 
)
inlinestatic

Drop a table from the memory cache as part of dropping a table.

Parameters
[in,out]tableTable cache entry
[in,out]trxTransaction handle
Returns
error code or DB_SUCCESS

◆ row_drop_tables_for_mysql_in_background()

ulint row_drop_tables_for_mysql_in_background ( void  )

TODO: NewDD: Need to check if there is need to keep background drop, in such case, the thd would be NULL (no MDL can be acquired) The master thread in srv0srv.cc calls this regularly to drop tables which we must drop in background after queries to them have ended.

The master thread in srv0srv.cc calls this regularly to drop tables which we must drop in background after queries to them have ended.

Such lazy dropping of tables is needed in ALTER TABLE on Unix.

Returns
how many tables dropped + remaining tables in list

◆ row_drop_tablespace()

dberr_t row_drop_tablespace ( space_id_t  space_id,
const char *  filepath 
)

Drop a tablespace as part of dropping or renaming a table.

This deletes the fil_space_t if found and the file on disk.

Parameters
[in]space_idTablespace ID
[in]filepathFile path of tablespace to delete
Returns
error code or DB_SUCCESS

◆ row_explicit_rollback()

static dberr_t row_explicit_rollback ( dict_index_t index,
const dtuple_t entry,
que_thr_t thr,
mtr_t mtr 
)
static

Perform explicit rollback in absence of UNDO logs.

Parameters
[in]indexApply rollback action on this index
[in]entryEntry to remove/rollback.
[in,out]thrThread handler.
[in,out]mtrMini-transaction.
Returns
error code or DB_SUCCESS

◆ row_fts_do_update()

static void row_fts_do_update ( trx_t trx,
dict_table_t table,
doc_id_t  old_doc_id,
doc_id_t  new_doc_id 
)
static

◆ row_fts_update_or_delete()

static dberr_t row_fts_update_or_delete ( row_prebuilt_t prebuilt)
static

◆ row_get_prebuilt_insert_row()

static dtuple_t * row_get_prebuilt_insert_row ( row_prebuilt_t prebuilt)
static

Gets pointer to a prebuilt dtuple used in insertions.

If the insert graph has not yet been built in the prebuilt struct, then this function first builds it.

Returns
prebuilt dtuple; the column type information is also set in it
Parameters
prebuiltin: prebuilt struct in MySQL handle

◆ row_get_prebuilt_update_vector()

upd_t * row_get_prebuilt_update_vector ( row_prebuilt_t prebuilt)

Gets pointer to a prebuilt update vector used in updates.

If the update graph has not yet been built in the prebuilt struct, then this function first builds it.

Returns
prebuilt update vector
Parameters
prebuiltin: prebuilt struct in MySQL handle

◆ row_insert_for_mysql()

dberr_t row_insert_for_mysql ( const byte mysql_rec,
row_prebuilt_t prebuilt 
)

Does an insert for MySQL.

Parameters
[in]mysql_recrow in the MySQL format
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_insert_for_mysql_using_cursor()

static dberr_t row_insert_for_mysql_using_cursor ( const byte mysql_rec,
row_prebuilt_t prebuilt 
)
static

Does an insert for MySQL using cursor interface.

Cursor interface is low level interface that directly interacts at Storage Level by-passing all the locking and transaction semantics. For InnoDB case, this will also by-pass hidden column generation.

Parameters
[in]mysql_recrow in the MySQL format
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_insert_for_mysql_using_ins_graph()

static dberr_t row_insert_for_mysql_using_ins_graph ( const byte mysql_rec,
row_prebuilt_t prebuilt 
)
static

Does an insert for MySQL using INSERT graph.

This function will run/execute INSERT graph.

Parameters
[in]mysql_recrow in the MySQL format
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_is_mysql_tmp_table_name()

bool row_is_mysql_tmp_table_name ( const char *  name)

Checks if a table name contains the string "/#sql" which denotes temporary tables in MySQL.

Returns
true if temporary table in: table name in the form 'database/tablename'

◆ row_lock_table()

dberr_t row_lock_table ( row_prebuilt_t prebuilt)

Sets a table lock on the table mentioned in prebuilt.

Parameters
[in,out]prebuilttable handle
Returns
error code or DB_SUCCESS

◆ row_lock_table_autoinc_for_mysql()

dberr_t row_lock_table_autoinc_for_mysql ( row_prebuilt_t prebuilt)

Sets an AUTO_INC type lock on the table mentioned in prebuilt.

The AUTO_INC lock gives exclusive access to the auto-inc counter of the table. The lock is reserved only for the duration of an SQL statement. It is not compatible with another AUTO_INC or exclusive lock on the table.

Returns
error code or DB_SUCCESS
Parameters
prebuiltin: prebuilt struct in the MySQL table handle

◆ row_mysql_close()

void row_mysql_close ( void  )

Close this module.

◆ row_mysql_convert_row_to_innobase()

static void row_mysql_convert_row_to_innobase ( dtuple_t row,
row_prebuilt_t prebuilt,
const byte mysql_rec,
mem_heap_t **  heap 
)
static

Convert a row in the MySQL format to a row in the Innobase format.

Note that the function to convert a MySQL format key value to an InnoDB dtuple is row_sel_convert_mysql_key_to_innobase() in row0sel.cc.

Parameters
rowin/out: Innobase row where the field type information is already copied there!
prebuiltin: prebuilt struct where template must be of type ROW_MYSQL_WHOLE_ROW
mysql_recin: row in the MySQL format; NOTE: do not discard as long as row is used, as row may contain pointers to this record!
heapin: heap will be used to duplicate multi_value & blob data

◆ row_mysql_delay_if_needed()

static void row_mysql_delay_if_needed ( void  )
static

Delays an INSERT, DELETE or UPDATE operation if the purge is lagging.

◆ row_mysql_freeze_data_dictionary()

void row_mysql_freeze_data_dictionary ( trx_t trx,
ut::Location  location 
)

Locks the data dictionary in shared mode from modifications, for performing foreign key check, rollback, or other operation invisible to MySQL.

Parameters
[in,out]trxTransaction
[in]locationLocation

◆ row_mysql_handle_errors()

bool row_mysql_handle_errors ( dberr_t new_err,
trx_t trx,
que_thr_t thr,
trx_savept_t savept 
)

Handles user errors and lock waits detected by the database engine.

Returns
true if it was a lock wait and we should continue running the query thread and in that case the thr is ALREADY in the running state.
Parameters
new_errout: possible new error encountered in lock wait, or if no new error, the value of trx->error_state at the entry of this function
trxin: transaction
thrin: query thread, or NULL
saveptin: savepoint, or NULL

◆ row_mysql_init()

void row_mysql_init ( void  )

Initialize this module.

◆ row_mysql_lock_data_dictionary()

void row_mysql_lock_data_dictionary ( trx_t trx,
ut::Location  location 
)

Locks the data dictionary exclusively for performing a table create or other data dictionary modification operation.

Parameters
[in,out]trxTransaction
[in]locationLocation

◆ row_mysql_lock_table()

dberr_t row_mysql_lock_table ( trx_t trx,
dict_table_t table,
enum lock_mode  mode,
const char *  op_info 
)

Sets an exclusive lock on a table.

Returns
error code or DB_SUCCESS
Parameters
trxin/out: transaction
tablein: table to lock
modein: LOCK_X or LOCK_S
op_infoin: string for trx->op_info

◆ row_mysql_pad_col()

void row_mysql_pad_col ( ulint  mbminlen,
byte pad,
ulint  len 
)

Pad a column with spaces.

Parameters
[in]mbminlenMinimum size of a character, in bytes
[out]padPadded buffer
[in]lenNumber of bytes to pad

◆ row_mysql_parallel_select_count_star()

dberr_t row_mysql_parallel_select_count_star ( trx_t trx,
std::vector< dict_index_t * > &  indexes,
size_t  max_threads,
ulint n_rows 
)

Read the total number of records in a consistent view.

Parameters
[in,out]trxCovering transaction.
[in]indexesIndexes to scan.
[in]max_threadsMaximum number of threads to use.
[out]n_rowsNumber of rows seen.
Returns
DB_SUCCESS or error code.

◆ row_mysql_prebuilt_free_blob_heap()

void row_mysql_prebuilt_free_blob_heap ( row_prebuilt_t prebuilt)

Frees the blob heap in prebuilt when no longer needed.

in: prebuilt struct of a ha_innobase:: table handle

◆ row_mysql_read_blob_ref()

const byte * row_mysql_read_blob_ref ( ulint len,
const byte ref,
ulint  col_len 
)

Reads a reference to a BLOB in the MySQL format.

Parameters
[out]lenBLOB length.
[in]refBLOB reference in the MySQL format.
[in]col_lenBLOB reference length (not BLOB length).
Returns
pointer to BLOB data

◆ row_mysql_read_geometry()

static const byte * row_mysql_read_geometry ( ulint len,
const byte ref,
ulint  col_len 
)
static

Read geometry data in the MySQL format.

Returns
pointer to geometry data

Show the meaning of geometry data.

Parameters
lenout: data length
refin: geometry data in the MySQL format
col_lenin: MySQL format length

◆ row_mysql_read_true_varchar()

const byte * row_mysql_read_true_varchar ( ulint len,
const byte field,
ulint  lenlen 
)

Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and returns a pointer to the data.

Returns
pointer to the data, we skip the 1 or 2 bytes at the start that are used to store the len
Parameters
lenout: variable-length field length
fieldin: field in the MySQL format
lenlenin: storage length of len: either 1 or 2 bytes

◆ row_mysql_store_blob_ref()

void row_mysql_store_blob_ref ( byte dest,
ulint  col_len,
const void *  data,
ulint  len 
)

Stores a reference to a BLOB in the MySQL format.

Parameters
[in]destWhere to store
[in,out]col_lenDest buffer size: determines into how many bytes the blob length is stored, the space for the length may vary from 1 to 4 bytes
[in]dataBlob data; if the value to store is sql null this should be null pointer
[in]lenBlob length; if the value to store is sql null this should be 0; remember also to set the null bit in the mysql record header!

◆ row_mysql_store_col_in_innobase_format()

byte * row_mysql_store_col_in_innobase_format ( dfield_t dfield,
byte buf,
bool  row_format_col,
const byte mysql_data,
ulint  col_len,
ulint  comp 
)

Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.

The counterpart of this function is row_sel_field_store_in_mysql_format() in row0sel.cc.

Returns
up to which byte we used buf in the conversion
Parameters
dfieldin/out: dfield where dtype information must be already set when this function is called!
bufin/out: buffer for a converted integer value; this must be at least col_len long then! NOTE that dfield may also get a pointer to 'buf', therefore do not discard this as long as dfield is used!
row_format_coltrue if the mysql_data is from a MySQL row, false if from a MySQL key value; in MySQL, a true VARCHAR storage format differs in a row and in a key value: in a key value the length is always stored in 2 bytes!
mysql_datain: MySQL column value, not SQL NULL; NOTE that dfield may also get a pointer to mysql_data, therefore do not discard this as long as dfield is used!
col_lenin: MySQL column length; NOTE that this is the storage length of the column in the MySQL format row, not necessarily the length of the actual payload data; if the column is a true VARCHAR then this is irrelevant
compin: nonzero=compact format

◆ row_mysql_store_geometry()

void row_mysql_store_geometry ( byte dest,
ulint  dest_len,
const byte src,
ulint  src_len 
)

Converting InnoDB geometry data format to MySQL data format.

Converts InnoDB geometry data format to MySQL data format.

Show the meaning of geometry data.

Parameters
destin/out: where to store
dest_lenin: dest buffer size: determines into how many bytes the GEOMETRY length is stored, the space for the length may vary from 1 to 4 bytes
srcin: GEOMETRY data; if the value to store is SQL NULL this should be NULL pointer
src_lenin: GEOMETRY length; if the value to store is SQL NULL this should be 0; remember also to set the NULL bit in the MySQL record header!

◆ row_mysql_store_true_var_len()

byte * row_mysql_store_true_var_len ( byte dest,
ulint  len,
ulint  lenlen 
)

Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row format.

Returns
pointer to the data, we skip the 1 or 2 bytes at the start that are used to store the len
Parameters
destin: where to store
lenin: length, must fit in two bytes
lenlenin: storage length of len: either 1 or 2 bytes

◆ row_mysql_table_id_reassign()

static dberr_t row_mysql_table_id_reassign ( dict_table_t table,
table_id_t new_id 
)
static

Reassigns the table identifier of a table.

Parameters
[in,out]tabletable
[out]new_idnew table id
Returns
error code or DB_SUCCESS

◆ row_mysql_to_innobase()

static void row_mysql_to_innobase ( dtuple_t row,
row_prebuilt_t prebuilt,
const byte mysql_rec 
)
static

Convert a row in the MySQL format to a row in the Innobase format.

This is specialized function used for intrinsic table with reduce branching.

Parameters
[in,out]rowrow where field values are copied.
[in]prebuiltprebuilt handler
[in]mysql_recrow in mysql format.

◆ row_mysql_unfreeze_data_dictionary()

void row_mysql_unfreeze_data_dictionary ( trx_t trx)

Unlocks the data dictionary shared lock.

in/out: transaction

Parameters
trxin/out: transaction

◆ row_mysql_unlock_data_dictionary()

void row_mysql_unlock_data_dictionary ( trx_t trx)

Unlocks the data dictionary exclusive lock.

in/out: transaction

Parameters
trxin/out: transaction

◆ row_prebuild_sel_graph()

void row_prebuild_sel_graph ( row_prebuilt_t prebuilt)

Builds a dummy query graph used in selects.

in: prebuilt struct in MySQL handle

◆ row_prebuilt_free()

void row_prebuilt_free ( row_prebuilt_t prebuilt,
bool  dict_locked 
)

Free a prebuilt struct for a MySQL table handle.

Parameters
[in,out]prebuiltPrebuilt struct
[in]dict_lockedTrue=data dictionary locked

◆ row_rename_table_for_mysql()

dberr_t row_rename_table_for_mysql ( const char *  old_name,
const char *  new_name,
const dd::Table dd_table,
trx_t trx,
bool  replay 
)

Renames a table for MySQL.

Parameters
[in]old_nameold table name
[in]new_namenew table name
[in]dd_tabledd::Table for new table
[in,out]trxtransaction
[in]replaywhether in replay stage
Returns
error code or DB_SUCCESS

◆ row_scan_index_for_mysql()

dberr_t row_scan_index_for_mysql ( row_prebuilt_t prebuilt,
dict_index_t index,
size_t  n_threads,
bool  check_keys,
ulint n_rows 
)

Scans an index for either COUNT(*) or CHECK TABLE.

If CHECK TABLE; Checks that the index contains entries in an ascending order, unique constraint is not broken, and calculates the number of index entries in the read view of the current transaction.

Parameters
[in,out]prebuiltPrebuilt struct in MySQL handle.
[in,out]indexIndex to scan.
[in]n_threadsNumber of threads to use for the scan
[in]check_keysTrue if called form check table.
[out]n_rowsNumber of entries seen in the consistent read.
Returns
DB_SUCCESS or other error

◆ row_table_got_default_clust_index()

bool row_table_got_default_clust_index ( const dict_table_t table)

Checks if a table is such that we automatically created a clustered index on it (on row id).

Returns
true if the clustered index was generated automatically
Parameters
tablein: table

◆ row_table_load_foreign_constraints()

dberr_t row_table_load_foreign_constraints ( trx_t trx,
const char *  name,
const dd::Table dd_table 
)

Loads foreign key constraints for the table being created.

This function should be called after the indexes for a table have been created. Each foreign key constraint must be accompanied with indexes in both participating tables. The indexes are allowed to contain more fields than mentioned in the constraint.

Parameters
[in]trxtransaction
[in]nametable full name in normalized form
[in]dd_tableMySQL dd::Table for the table
Returns
error code or DB_SUCCESS

◆ row_update_cascade_for_mysql()

dberr_t row_update_cascade_for_mysql ( que_thr_t thr,
upd_node_t node,
dict_table_t table 
)

Does a cascaded delete or set null in a foreign key operation.

Returns
error code or DB_SUCCESS
Parameters
thrin: query thread
nodein: update node used in the cascade or set null operation
tablein: table where we do the operation

◆ row_update_for_mysql()

dberr_t row_update_for_mysql ( const byte mysql_rec,
row_prebuilt_t prebuilt 
)

Does an update or delete of a row for MySQL.

Parameters
[in]mysql_recrow in the MySQL format
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_update_for_mysql_using_cursor()

static dberr_t row_update_for_mysql_using_cursor ( const upd_node_t node,
cursors_t delete_entries,
que_thr_t thr 
)
static

Does an update of a row for MySQL by inserting new entry with update values.

Parameters
[in]nodeupdate node carrying information to delete.
[out]delete_entriesvector of cursor to deleted entries.
[in]thrthread handler
Returns
error code or DB_SUCCESS

◆ row_update_for_mysql_using_upd_graph()

static dberr_t row_update_for_mysql_using_upd_graph ( const byte mysql_rec,
row_prebuilt_t prebuilt 
)
static

Does an update or delete of a row for MySQL.

Parameters
[in]mysql_recrow in the MySQL format
[in,out]prebuiltprebuilt struct in MySQL handle
Returns
error code or DB_SUCCESS

◆ row_update_inplace_for_intrinsic()

static dberr_t row_update_inplace_for_intrinsic ( const upd_node_t node)
static

Do an in-place update in the intrinsic table.

The update should not modify any of the keys and it should not change the size of any fields.

Parameters
[in]nodethe update node.
Returns
DB_SUCCESS on success, an error code on failure.

◆ row_update_prebuilt_trx()

void row_update_prebuilt_trx ( row_prebuilt_t prebuilt,
trx_t trx 
)

Updates the transaction pointers in query graphs stored in the prebuilt struct.

Parameters
[in,out]prebuiltPrebuilt struct in MySQL handle.
[in,out]trxTransaction handle.

◆ row_update_statistics_if_needed()

static void row_update_statistics_if_needed ( dict_table_t table)
inlinestatic

Updates the table modification counter and calculates new estimates for table and index statistics if necessary.

Parameters
tablein: table

◆ row_wait_for_background_drop_list_empty()

void row_wait_for_background_drop_list_empty ( )

Wait for the background drop list to become empty.

◆ UT_LIST_BASE_NODE_T()

static UT_LIST_BASE_NODE_T ( row_mysql_drop_t  ,
row_mysql_drop_list   
)
static

List of tables we should drop in background.

ALTER TABLE in MySQL requires that the table handler can drop the table in background when there are no queries to it any more. Protected by row_drop_list_mutex.

Variable Documentation

◆ MAX_SRCH_KEY_VAL_BUFFER

constexpr uint32_t MAX_SRCH_KEY_VAL_BUFFER = 2 * 8 * MAX_REF_PARTS
constexpr

◆ MODIFICATIONS_NOT_ALLOWED_MSG_FORCE_RECOVERY

const char* MODIFICATIONS_NOT_ALLOWED_MSG_FORCE_RECOVERY
static
Initial value:
=
"innodb_force_recovery is on. We do not allow database modifications"
" by the user. Shut down mysqld and edit my.cnf to set"
" innodb_force_recovery=0"

◆ row_drop_list_mutex

ib_mutex_t row_drop_list_mutex
static

Mutex protecting the background table drop list.

◆ row_mysql_drop_list_inited

bool row_mysql_drop_list_inited = false
static

Flag: has row_mysql_drop_list been initialized?

◆ row_rollback_on_timeout

bool row_rollback_on_timeout = false

Provide optional 4.x backwards compatibility for 5.0 and above.