MySQL 8.0.40
Source Code Documentation
row0ins.cc File Reference

Insert into a table. More...

#include <sys/types.h>
#include "btr0btr.h"
#include "btr0cur.h"
#include "buf0lru.h"
#include "current_thd.h"
#include "data0data.h"
#include "dict0boot.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "eval0eval.h"
#include "fts0fts.h"
#include "fts0types.h"
#include "gis0geo.h"
#include "ha_prototypes.h"
#include "lob0lob.h"
#include "lock0lock.h"
#include "log0chkp.h"
#include "m_string.h"
#include "mach0data.h"
#include "que0que.h"
#include "rem0cmp.h"
#include "row0ins.h"
#include "row0log.h"
#include "row0row.h"
#include "row0sel.h"
#include "row0upd.h"
#include "trx0rec.h"
#include "trx0undo.h"
#include "usr0sess.h"
#include <debug_sync.h>
#include "my_dbug.h"

Classes

class  ib_dec_in_dtor
 

Functions

ins_node_tins_node_create (ulint ins_type, dict_table_t *table, mem_heap_t *heap)
 Creates an insert node struct. More...
 
static void ins_node_create_entry_list (ins_node_t *node)
 Creates an entry template for each index of a table. More...
 
static void row_ins_alloc_sys_fields (ins_node_t *node)
 Adds system field buffers to a row. More...
 
void ins_node_set_new_row (ins_node_t *node, dtuple_t *row)
 Sets a new row to insert for an INS_DIRECT node. More...
 
static dberr_t row_ins_sec_index_entry_by_modify (ulint flags, ulint mode, btr_cur_t *cursor, ulint **offsets, mem_heap_t *offsets_heap, mem_heap_t *heap, const dtuple_t *entry, que_thr_t *thr, mtr_t *mtr)
 Does an insert operation by updating a delete-marked existing record in the index. More...
 
static dberr_t row_ins_clust_index_entry_by_modify (btr_pcur_t *pcur, ulint flags, ulint mode, ulint **offsets, mem_heap_t **offsets_heap, mem_heap_t *heap, const dtuple_t *entry, que_thr_t *thr, mtr_t *mtr)
 Does an insert operation by delete unmarking and updating a delete marked existing record in the index. More...
 
static bool row_ins_cascade_ancestor_updates_table (que_node_t *node, dict_table_t *table)
 Returns true if in a cascaded update/delete an ancestor node of node updates (not DELETE, but UPDATE) table. More...
 
static ulint row_ins_cascade_n_ancestors (que_node_t *node)
 Returns the number of ancestor UPDATE or DELETE nodes of a cascaded update/delete node. More...
 
static ulint row_ins_cascade_calc_update_vec (upd_node_t *node, dict_foreign_t *foreign, mem_heap_t *heap, trx_t *trx, bool *fts_col_affected)
 Calculates the update vector node->cascade->update for a child table in a cascaded update. More...
 
static void row_ins_set_detailed (trx_t *trx, dict_foreign_t *foreign)
 Set detailed error message associated with foreign key errors for the given transaction. More...
 
static void row_ins_foreign_trx_print (trx_t *trx)
 Acquires dict_foreign_err_mutex, rewinds dict_foreign_err_file and displays information about the given transaction. More...
 
static void row_ins_foreign_report_err (const char *errstr, que_thr_t *thr, dict_foreign_t *foreign, const rec_t *rec, const dtuple_t *entry)
 Reports a foreign key error associated with an update or a delete of a parent table index entry. More...
 
static void row_ins_foreign_report_add_err (trx_t *trx, dict_foreign_t *foreign, const rec_t *rec, const dtuple_t *entry)
 Reports a foreign key error to dict_foreign_err_file when we are trying to add an index entry to a child table. More...
 
static void row_ins_foreign_fill_virtual (upd_node_t *cascade, const rec_t *rec, dict_index_t *index, upd_node_t *node, dict_foreign_t *foreign, dberr_t *err)
 Fill virtual column information in cascade node for the child table. More...
 
static NO_INLINE dberr_t row_ins_foreign_check_on_constraint (que_thr_t *thr, dict_foreign_t *foreign, btr_pcur_t *pcur, dtuple_t *entry, mtr_t *mtr)
 Perform referential actions or checks when a parent row is deleted or updated and the constraint had an ON DELETE or ON UPDATE condition which was not RESTRICT. More...
 
static dberr_t row_ins_set_rec_lock (lock_mode mode, ulint type, const buf_block_t *block, const rec_t *rec, dict_index_t *index, const ulint *offsets, que_thr_t *thr)
 Sets a lock on a record. More...
 
dberr_t row_ins_check_foreign_constraint (bool check_ref, dict_foreign_t *foreign, dict_table_t *table, dtuple_t *entry, que_thr_t *thr)
 Checks if foreign key constraint fails for an index entry. More...
 
static dberr_t row_ins_check_foreign_constraints (dict_table_t *table, dict_index_t *index, dtuple_t *entry, que_thr_t *thr)
 Checks if foreign key constraints fail for an index entry. More...
 
static bool row_ins_dupl_error_with_rec (const rec_t *rec, const dtuple_t *entry, dict_index_t *index, const ulint *offsets)
 Checks if a unique key violation to rec would occur at the index entry insert. More...
 
static bool row_allow_duplicates (que_thr_t *thr)
 Determines if the query is REPLACE or ON DUPLICATE KEY UPDATE in which case duplicate values should be allowed (and further processed) instead of causing an error. More...
 
static dberr_t row_ins_scan_sec_index_for_duplicate (ulint flags, dict_index_t *index, dtuple_t *entry, que_thr_t *thr, bool s_latch, mtr_t *mtr, mem_heap_t *offsets_heap)
 Scans a unique non-clustered index at a given index entry to determine whether a uniqueness violation has occurred for the key value of the entry. More...
 
static dberr_t row_ins_duplicate_online (ulint n_uniq, const dtuple_t *entry, const rec_t *rec, const dict_index_t *index, ulint *offsets)
 Checks for a duplicate when the table is being rebuilt online. More...
 
static dberr_t row_ins_duplicate_error_in_clust_online (ulint n_uniq, const dtuple_t *entry, const btr_cur_t *cursor, ulint **offsets, mem_heap_t **heap)
 Checks for a duplicate when the table is being rebuilt online. More...
 
static dberr_t row_ins_duplicate_error_in_clust (ulint flags, btr_cur_t *cursor, const dtuple_t *entry, que_thr_t *thr, mtr_t *mtr)
 Checks if a unique key violation error would occur at an index entry insert. More...
 
static bool row_ins_must_modify_rec (const btr_cur_t *cursor)
 Checks if an index entry has long enough common prefix with an existing record so that the intended insert of the entry must be changed to a modify of the existing record. More...
 
static dberr_t row_ins_index_entry_big_rec_func (trx_t *trx, const dtuple_t *entry, const big_rec_t *big_rec, ulint *offsets, mem_heap_t **heap, const THD *thd, dict_index_t *index)
 Insert the externally stored fields (off-page columns) of a clustered index entry. More...
 
static dberr_t row_ins_index_entry_big_rec (trx_t *trx, const dtuple_t *e, const big_rec_t *big, ulint *ofs, mem_heap_t **heap, dict_index_t *index, const THD *thd)
 
static void row_ins_temp_prebuilt_tree_modified (dict_table_t *table)
 Update all the prebuilts working on this temporary table. More...
 
dberr_t row_ins_clust_index_entry_low (uint32_t flags, ulint mode, dict_index_t *index, ulint n_uniq, dtuple_t *entry, que_thr_t *thr, bool dup_chk_only)
 Tries to insert an entry into a clustered index, ignoring foreign key constraints. More...
 
static dberr_t row_ins_sorted_clust_index_entry (ulint mode, dict_index_t *index, dtuple_t *entry, que_thr_t *thr)
 This is a specialized function meant for direct insertion to auto-generated clustered index based on cached position from last successful insert. More...
 
static bool row_ins_sec_mtr_start_and_check_if_aborted (mtr_t *mtr, dict_index_t *index, bool check, ulint search_mode)
 Start a mini-transaction and check if the index will be dropped. More...
 
dberr_t row_ins_sec_index_entry_low (uint32_t flags, ulint mode, dict_index_t *index, mem_heap_t *offsets_heap, mem_heap_t *heap, dtuple_t *entry, trx_id_t trx_id, que_thr_t *thr, bool dup_chk_only)
 Tries to insert an entry into a secondary index. More...
 
dberr_t row_ins_clust_index_entry (dict_index_t *index, dtuple_t *entry, que_thr_t *thr, bool dup_chk_only)
 Inserts an entry into a clustered index. More...
 
dberr_t row_ins_sec_index_entry (dict_index_t *index, dtuple_t *entry, que_thr_t *thr, bool dup_chk_only)
 Inserts an entry into a secondary index. More...
 
static dberr_t row_ins_sec_index_multi_value_entry (dict_index_t *index, dtuple_t *entry, uint32_t &multi_val_pos, que_thr_t *thr)
 Inserts an entry into a secondary index, which is created for multi-value field. More...
 
static dberr_t row_ins_index_entry (dict_index_t *index, dtuple_t *entry, uint32_t &multi_val_pos, que_thr_t *thr)
 Inserts an index entry to index. More...
 
static void row_ins_spatial_index_entry_set_mbr_field (dfield_t *field, const dfield_t *row_field, uint32_t *srid, const dd::Spatial_reference_system *srs)
 This function generate MBR (Minimum Bounding Box) for spatial objects and set it to spatial index field. More...
 
dberr_t row_ins_index_entry_set_vals (const dict_index_t *index, dtuple_t *entry, const dtuple_t *row)
 Sets the values of the dtuple fields in entry from the values of appropriate columns in row. More...
 
static dberr_t row_ins_index_entry_step (ins_node_t *node, que_thr_t *thr)
 Inserts a single index entry to the table. More...
 
static void row_ins_alloc_row_id_step (ins_node_t *node)
 Allocates a row id for row and inits the node->index field. More...
 
static void row_ins_get_row_from_values (ins_node_t *node)
 Gets a row to insert from the values list. More...
 
static void row_ins_get_row_from_query_block (ins_node_t *node)
 Gets a row to insert from the select list. More...
 
static dberr_t row_ins (ins_node_t *node, que_thr_t *thr)
 Inserts a row to a table. More...
 
que_thr_trow_ins_step (que_thr_t *thr)
 Inserts a row to a table. More...
 

Detailed Description

Insert into a table.

Created 4/20/1996 Heikki Tuuri

Function Documentation

◆ ins_node_create()

ins_node_t * ins_node_create ( ulint  ins_type,
dict_table_t table,
mem_heap_t heap 
)

Creates an insert node struct.

Returns
own: insert node struct
Parameters
ins_typein: INS_VALUES, ...
tablein: table where to insert
heapin: mem heap where created

◆ ins_node_create_entry_list()

static void ins_node_create_entry_list ( ins_node_t node)
static

Creates an entry template for each index of a table.

Parameters
nodein: row insert node

◆ ins_node_set_new_row()

void ins_node_set_new_row ( ins_node_t node,
dtuple_t row 
)

Sets a new row to insert for an INS_DIRECT node.

This function is only used if we have constructed the row separately, which is a rare case; this function is quite slow.

Parameters
nodein: insert node
rowin: new row (or first row) for the node

◆ row_allow_duplicates()

static bool row_allow_duplicates ( que_thr_t thr)
static

Determines if the query is REPLACE or ON DUPLICATE KEY UPDATE in which case duplicate values should be allowed (and further processed) instead of causing an error.

Parameters
thrThe query thread running the query
Returns
true iff duplicated values should be allowed

◆ row_ins()

static dberr_t row_ins ( ins_node_t node,
que_thr_t thr 
)
static

Inserts a row to a table.

Returns
DB_SUCCESS if operation successfully completed, else error code or DB_LOCK_WAIT
Parameters
nodein: row insert node
thrin: query thread

◆ row_ins_alloc_row_id_step()

static void row_ins_alloc_row_id_step ( ins_node_t node)
inlinestatic

Allocates a row id for row and inits the node->index field.

Parameters
nodein: row insert node

◆ row_ins_alloc_sys_fields()

static void row_ins_alloc_sys_fields ( ins_node_t node)
static

Adds system field buffers to a row.

Parameters
nodein: insert node

◆ row_ins_cascade_ancestor_updates_table()

static bool row_ins_cascade_ancestor_updates_table ( que_node_t node,
dict_table_t table 
)
static

Returns true if in a cascaded update/delete an ancestor node of node updates (not DELETE, but UPDATE) table.

Returns
true if an ancestor updates table
Parameters
nodein: node in a query graph
tablein: table

◆ row_ins_cascade_calc_update_vec()

static ulint row_ins_cascade_calc_update_vec ( upd_node_t node,
dict_foreign_t foreign,
mem_heap_t heap,
trx_t trx,
bool *  fts_col_affected 
)
static

Calculates the update vector node->cascade->update for a child table in a cascaded update.

Returns
number of fields in the calculated update vector; the value can also be 0 if no foreign key fields changed; the returned value is ULINT_UNDEFINED if the column type in the child table is too short to fit the new value in the parent table: that means the update fails
Parameters
nodein: update node of the parent table
foreignin: foreign key constraint whose type is != 0
heapin: memory heap to use as temporary storage
trxin: update transaction
fts_col_affectedout: is FTS column affected

◆ row_ins_cascade_n_ancestors()

static ulint row_ins_cascade_n_ancestors ( que_node_t node)
static

Returns the number of ancestor UPDATE or DELETE nodes of a cascaded update/delete node.

Returns
number of ancestors
Parameters
nodein: node in a query graph

◆ row_ins_check_foreign_constraint()

dberr_t row_ins_check_foreign_constraint ( bool  check_ref,
dict_foreign_t foreign,
dict_table_t table,
dtuple_t entry,
que_thr_t thr 
)

Checks if foreign key constraint fails for an index entry.

Sets shared locks which lock either the success or the failure of the constraint. NOTE that the caller must have a shared latch on dict_operation_lock.

Returns
DB_SUCCESS, DB_NO_REFERENCED_ROW, or DB_ROW_IS_REFERENCED
Parameters
check_refin: true if we want to check that the referenced table is ok, false if we want to check the foreign key table
foreignin: foreign constraint; NOTE that the tables mentioned in it must be in the dictionary cache if they exist at all
tablein: if check_ref is true, then the foreign table, else the referenced table
entryin: index entry for index
thrin: query thread

◆ row_ins_check_foreign_constraints()

static dberr_t row_ins_check_foreign_constraints ( dict_table_t table,
dict_index_t index,
dtuple_t entry,
que_thr_t thr 
)
static

Checks if foreign key constraints fail for an index entry.

If index is not mentioned in any constraint, this function does nothing, Otherwise does searches to the indexes of referenced tables and sets shared locks which lock either the success or the failure of a constraint.

Returns
DB_SUCCESS or error code
Parameters
tablein: table
indexin: index
entryin: index entry for index
thrin: query thread

◆ row_ins_clust_index_entry()

dberr_t row_ins_clust_index_entry ( dict_index_t index,
dtuple_t entry,
que_thr_t thr,
bool  dup_chk_only 
)

Inserts an entry into a clustered index.

Tries first optimistic, then pessimistic descent down the tree. If the entry matches enough to a delete marked record, performs the insert by updating or delete unmarking the delete marked record.

Returns
DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code
Parameters
indexin: clustered index
entryin/out: index entry to insert
thrin: query thread
dup_chk_onlyin: if true, just do duplicate check and return. don't execute actual insert.

◆ row_ins_clust_index_entry_by_modify()

static dberr_t row_ins_clust_index_entry_by_modify ( btr_pcur_t pcur,
ulint  flags,
ulint  mode,
ulint **  offsets,
mem_heap_t **  offsets_heap,
mem_heap_t heap,
const dtuple_t entry,
que_thr_t thr,
mtr_t mtr 
)
static

Does an insert operation by delete unmarking and updating a delete marked existing record in the index.

This situation can occur if the delete marked record is kept in the index for consistent reads.

Returns
DB_SUCCESS, DB_FAIL, or error code
Parameters
pcurin/out: a persistent cursor pointing to the clust_rec that is being modified.
flagsin: undo logging and locking flags
modein: BTR_MODIFY_LEAF or BTR_MODIFY_TREE, depending on whether mtr holds just a leaf latch or also a tree latch
offsetsout: offsets on cursor->page_cur.rec
offsets_heapin/out: pointer to memory heap that can be emptied, or NULL
heapin/out: memory heap
entryin: index entry to insert
thrin: query thread
mtrin: mtr; must be committed before latching any further pages

◆ row_ins_clust_index_entry_low()

dberr_t row_ins_clust_index_entry_low ( uint32_t  flags,
ulint  mode,
dict_index_t index,
ulint  n_uniq,
dtuple_t entry,
que_thr_t thr,
bool  dup_chk_only 
)

Tries to insert an entry into a clustered index, ignoring foreign key constraints.

If a record with the same unique key is found, the other record is necessarily marked deleted by a committed transaction, or a unique key violation error occurs. The delete marked record is then updated to an existing record, and we must write an undo log record on the delete marked record.

Parameters
[in]flagsUndo logging and locking flags.
[in]modeBTR_MODIFY_LEAF or BTR_MODIFY_TREE, depending on whether we wish optimistic or pessimistic descent down the index tree.
[in]indexClustered index.
[in]n_uniq0 or index->n_uniq.
[in]entryIndex entry to insert.
[in]thrQuery thread, or nullptr if flags & (BTR_NO_LOCKING_FLAG | BTR_NO_UNDO_LOG_FLAG) and a duplicate can't occur.
[in]dup_chk_onlyIf true, just do duplicate check and return. don't execute actual insert.
Return values
DB_SUCCESSon success
DB_LOCK_WAITon lock wait when !(flags & BTR_NO_LOCKING_FLAG)
DB_FAILif retry with BTR_MODIFY_TREE is needed
Returns
error code

◆ row_ins_dupl_error_with_rec()

static bool row_ins_dupl_error_with_rec ( const rec_t rec,
const dtuple_t entry,
dict_index_t index,
const ulint offsets 
)
static

Checks if a unique key violation to rec would occur at the index entry insert.

Returns
true if error
Parameters
recin: user record; NOTE that we assume that the caller already has a record lock on the record!
entryin: entry to insert
indexin: index
offsetsin: rec_get_offsets(rec, index)

◆ row_ins_duplicate_error_in_clust()

static dberr_t row_ins_duplicate_error_in_clust ( ulint  flags,
btr_cur_t cursor,
const dtuple_t entry,
que_thr_t thr,
mtr_t mtr 
)
static

Checks if a unique key violation error would occur at an index entry insert.

Sets shared locks on possible duplicate records. Works only for a clustered index!

Return values
DB_SUCCESSif no error
DB_DUPLICATE_KEYif error,
DB_LOCK_WAITif we have to wait for a lock on a possible duplicate record
DB_SUCCESS_LOCKED_RECif an exact match of the record was found in online table rebuild (flags & (BTR_KEEP_SYS_FLAG | BTR_NO_LOCKING_FLAG))
Parameters
flagsin: undo logging and locking flags
cursorin: B-tree cursor
entryin: entry to insert
thrin: query thread
mtrin: mtr

◆ row_ins_duplicate_error_in_clust_online()

static dberr_t row_ins_duplicate_error_in_clust_online ( ulint  n_uniq,
const dtuple_t entry,
const btr_cur_t cursor,
ulint **  offsets,
mem_heap_t **  heap 
)
static

Checks for a duplicate when the table is being rebuilt online.

Return values
DB_SUCCESSwhen no duplicate is detected
DB_SUCCESS_LOCKED_RECwhen rec is an exact match of entry or a newer version of entry (the entry should not be inserted)
DB_DUPLICATE_KEYwhen entry is a duplicate of rec
Parameters
n_uniqin: offset of DB_TRX_ID
entryin: entry that is being inserted
cursorin: cursor on insert position
offsetsin/out: rec_get_offsets(rec)
heapin/out: heap for offsets

◆ row_ins_duplicate_online()

static dberr_t row_ins_duplicate_online ( ulint  n_uniq,
const dtuple_t entry,
const rec_t rec,
const dict_index_t index,
ulint offsets 
)
static

Checks for a duplicate when the table is being rebuilt online.

Parameters
[in]n_uniqoffset of DB_TRX_ID
[in]entryentry being inserted
[in]recclustered index record at insert position
[in]indexclustered index
[in,out]offsetsrec_get_offsets(rec)
Return values
DB_SUCCESSwhen no duplicate is detected
DB_SUCCESS_LOCKED_RECwhen rec is an exact match of entry or a newer version of entry (the entry should not be inserted)
DB_DUPLICATE_KEYwhen entry is a duplicate of rec

◆ row_ins_foreign_check_on_constraint()

static NO_INLINE dberr_t row_ins_foreign_check_on_constraint ( que_thr_t thr,
dict_foreign_t foreign,
btr_pcur_t pcur,
dtuple_t entry,
mtr_t mtr 
)
static

Perform referential actions or checks when a parent row is deleted or updated and the constraint had an ON DELETE or ON UPDATE condition which was not RESTRICT.

Returns
DB_SUCCESS, DB_LOCK_WAIT, or error code Disable inlining because of a bug in gcc8 which may lead to stack exhaustion.
Parameters
thrin: query thread whose run_node is an update node
foreignin: foreign key constraint whose type is != 0
pcurin: cursor placed on a matching index record in the child table
entryin: index entry in the parent table
mtrin: mtr holding the latch of pcur page

◆ row_ins_foreign_fill_virtual()

static void row_ins_foreign_fill_virtual ( upd_node_t cascade,
const rec_t rec,
dict_index_t index,
upd_node_t node,
dict_foreign_t foreign,
dberr_t err 
)
static

Fill virtual column information in cascade node for the child table.

Parameters
[out]cascadechild update node
[in]recclustered rec of child table
[in]indexclustered index of child table
[in]nodeparent update node
[in]foreignforeign key information.
[out]errerror code.

This can occur when there is a cascading delete or update after restart.

◆ row_ins_foreign_report_add_err()

static void row_ins_foreign_report_add_err ( trx_t trx,
dict_foreign_t foreign,
const rec_t rec,
const dtuple_t entry 
)
static

Reports a foreign key error to dict_foreign_err_file when we are trying to add an index entry to a child table.

Note that the adding may be the result of an update, too.

Parameters
trxin: transaction
foreignin: foreign key constraint
recin: a record in the parent table: it does not match entry because we have an error!
entryin: index entry to insert in the child table

◆ row_ins_foreign_report_err()

static void row_ins_foreign_report_err ( const char *  errstr,
que_thr_t thr,
dict_foreign_t foreign,
const rec_t rec,
const dtuple_t entry 
)
static

Reports a foreign key error associated with an update or a delete of a parent table index entry.

Parameters
errstrin: error string from the viewpoint of the parent table
thrin: query thread whose run_node is an update node
foreignin: foreign key constraint
recin: a matching index record in the child table
entryin: index entry in the parent table

◆ row_ins_foreign_trx_print()

static void row_ins_foreign_trx_print ( trx_t trx)
static

Acquires dict_foreign_err_mutex, rewinds dict_foreign_err_file and displays information about the given transaction.

The caller must release dict_foreign_err_mutex.

lock_number_of_rows_locked() requires global exclusive latch, and so does accessing trx_locks with trx->mutex

Parameters
trxin: transaction

◆ row_ins_get_row_from_query_block()

static void row_ins_get_row_from_query_block ( ins_node_t node)
inlinestatic

Gets a row to insert from the select list.

Parameters
nodein: row insert node

◆ row_ins_get_row_from_values()

static void row_ins_get_row_from_values ( ins_node_t node)
inlinestatic

Gets a row to insert from the values list.

Parameters
nodein: row insert node

◆ row_ins_index_entry()

static dberr_t row_ins_index_entry ( dict_index_t index,
dtuple_t entry,
uint32_t &  multi_val_pos,
que_thr_t thr 
)
static

Inserts an index entry to index.

Tries first optimistic, then pessimistic descent down the tree. If the entry matches enough to a delete marked record, performs the insert by updating or delete unmarking the delete marked record.

Parameters
[in]indexindex to insert the entry
[in,out]entryentry to insert
[in,out]multi_val_posif multi-value index, the start position to insert next multi-value data, and the returned value should be either 0 if all are done, or the position where the insert failed. So return value of 0 could be a bit ambiguous, however the return error can help to see which case it is
[in]thrquery thread
Returns
DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code

◆ row_ins_index_entry_big_rec()

static dberr_t row_ins_index_entry_big_rec ( trx_t trx,
const dtuple_t e,
const big_rec_t big,
ulint ofs,
mem_heap_t **  heap,
dict_index_t index,
const THD thd 
)
inlinestatic

◆ row_ins_index_entry_big_rec_func()

static dberr_t row_ins_index_entry_big_rec_func ( trx_t trx,
const dtuple_t entry,
const big_rec_t big_rec,
ulint offsets,
mem_heap_t **  heap,
const THD thd,
dict_index_t index 
)
static

Insert the externally stored fields (off-page columns) of a clustered index entry.

Parameters
[in]trxcurrent transaction
[in]entryindex entry to insert
[in]big_recexternally stored fields
[in,out]offsetsrec_get_offsets()
[in,out]heapmemory heap
[in]thdclient connection, or NULL
[in]indexclustered index
Returns
error code
Return values
DB_SUCCESS
DB_OUT_OF_FILE_SPACE

◆ row_ins_index_entry_set_vals()

dberr_t row_ins_index_entry_set_vals ( const dict_index_t index,
dtuple_t entry,
const dtuple_t row 
)

Sets the values of the dtuple fields in entry from the values of appropriate columns in row.

Parameters
[in]indexindex handler
[out]entryindex entry to make
[in]rowrow
Returns
DB_SUCCESS if the set is successful

◆ row_ins_index_entry_step()

static dberr_t row_ins_index_entry_step ( ins_node_t node,
que_thr_t thr 
)
static

Inserts a single index entry to the table.

Returns
DB_SUCCESS if operation successfully completed, else error code or DB_LOCK_WAIT
Parameters
nodein: row insert node
thrin: query thread

◆ row_ins_must_modify_rec()

static bool row_ins_must_modify_rec ( const btr_cur_t cursor)
inlinestatic

Checks if an index entry has long enough common prefix with an existing record so that the intended insert of the entry must be changed to a modify of the existing record.

In the case of a clustered index, the prefix must be n_unique fields long. In the case of a secondary index, all fields must be equal. InnoDB never updates secondary index records in place, other than clearing or setting the delete-mark flag. We could be able to update the non-unique fields of a unique secondary index record by checking the cursor->up_match, but we do not do so, because it could have some locking implications.

Returns
true if the existing record should be updated; false if not
Parameters
cursorin: B-tree cursor

◆ row_ins_scan_sec_index_for_duplicate()

static dberr_t row_ins_scan_sec_index_for_duplicate ( ulint  flags,
dict_index_t index,
dtuple_t entry,
que_thr_t thr,
bool  s_latch,
mtr_t mtr,
mem_heap_t offsets_heap 
)
static

Scans a unique non-clustered index at a given index entry to determine whether a uniqueness violation has occurred for the key value of the entry.

Set shared locks on possible duplicate records.

Returns
DB_SUCCESS, DB_DUPLICATE_KEY, or DB_LOCK_WAIT
Parameters
flagsin: undo logging and locking flags
indexin: non-clustered unique index
entryin: index entry
thrin: query thread
s_latchin: whether index->lock is being held
mtrin/out: mini-transaction
offsets_heapin/out: memory heap that can be emptied

◆ row_ins_sec_index_entry()

dberr_t row_ins_sec_index_entry ( dict_index_t index,
dtuple_t entry,
que_thr_t thr,
bool  dup_chk_only 
)

Inserts an entry into a secondary index.

Tries first optimistic, then pessimistic descent down the tree. If the entry matches enough to a delete marked record, performs the insert by updating or delete unmarking the delete marked record.

Returns
DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code
Parameters
indexin: secondary index
entryin/out: index entry to insert
thrin: query thread
dup_chk_onlyin: if true, just do duplicate check and return. don't execute actual insert.

◆ row_ins_sec_index_entry_by_modify()

static dberr_t row_ins_sec_index_entry_by_modify ( ulint  flags,
ulint  mode,
btr_cur_t cursor,
ulint **  offsets,
mem_heap_t offsets_heap,
mem_heap_t heap,
const dtuple_t entry,
que_thr_t thr,
mtr_t mtr 
)
static

Does an insert operation by updating a delete-marked existing record in the index.

This situation can occur if the delete-marked record is kept in the index for consistent reads.

Returns
DB_SUCCESS or error code
Parameters
flagsin: undo logging and locking flags
modein: BTR_MODIFY_LEAF or BTR_MODIFY_TREE, depending on whether mtr holds just a leaf latch or also a tree latch
cursorin: B-tree cursor
offsetsin/out: offsets on cursor->page_cur.rec
offsets_heapin/out: memory heap that can be emptied
heapin/out: memory heap
entryin: index entry to insert
thrin: query thread
mtrin: mtr; must be committed before latching any further pages

◆ row_ins_sec_index_entry_low()

dberr_t row_ins_sec_index_entry_low ( uint32_t  flags,
ulint  mode,
dict_index_t index,
mem_heap_t offsets_heap,
mem_heap_t heap,
dtuple_t entry,
trx_id_t  trx_id,
que_thr_t thr,
bool  dup_chk_only 
)

Tries to insert an entry into a secondary index.

If a record with exactly the same fields is found, the other record is necessarily marked deleted. It is then unmarked. Otherwise, the entry is just inserted to the index.

Parameters
[in]flagsundo logging and locking flags
[in]modeBTR_MODIFY_LEAF or BTR_MODIFY_TREE, depending on whether we wish optimistic or pessimistic descent down the index tree
[in]indexsecondary index
[in,out]offsets_heapmemory heap that can be emptied
[in,out]heapmemory heap
[in,out]entryindex entry to insert
[in]trx_idPAGE_MAX_TRX_ID during row_log_table_apply(), or trx_id when undo log is disabled during alter copy operation or 0
[in]thrquery thread
[in]dup_chk_onlytrue, just do duplicate check and return. don't execute actual insert
Return values
DB_SUCCESSon success
DB_LOCK_WAITon lock wait when !(flags & BTR_NO_LOCKING_FLAG)
DB_FAILif retry with BTR_MODIFY_TREE is needed
Returns
error code

◆ row_ins_sec_index_multi_value_entry()

static dberr_t row_ins_sec_index_multi_value_entry ( dict_index_t index,
dtuple_t entry,
uint32_t &  multi_val_pos,
que_thr_t thr 
)
static

Inserts an entry into a secondary index, which is created for multi-value field.

For each value to be inserted, it tries first optimistic, then pessimistic descent down the tree. If the entry matches enough to a delete marked record, performs the insert by updating or delete unmarking the delete marked record.

Parameters
[in]indexsecondary index which is for multi-value field
[in,out]entryindex entry to insert
[in,out]multi_val_posthe start position to insert next multi-value data, and the returned value should be either 0 if all are done, or the position where the insert failed. So return value of 0 could be a bit ambiguous, however the return error can help to see which case it is
[in]thrquery thread
Returns
DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code

◆ row_ins_sec_mtr_start_and_check_if_aborted()

static bool row_ins_sec_mtr_start_and_check_if_aborted ( mtr_t mtr,
dict_index_t index,
bool  check,
ulint  search_mode 
)
static

Start a mini-transaction and check if the index will be dropped.

Parameters
[in,out]mtrMini-transaction
[in,out]indexSecondary index
[in]checkWhether to check
[in]search_modeFlags
Returns
true if the index is to be dropped

◆ row_ins_set_detailed()

static void row_ins_set_detailed ( trx_t trx,
dict_foreign_t foreign 
)
static

Set detailed error message associated with foreign key errors for the given transaction.

Parameters
trxin: transaction
foreignin: foreign key constraint

◆ row_ins_set_rec_lock()

static dberr_t row_ins_set_rec_lock ( lock_mode  mode,
ulint  type,
const buf_block_t block,
const rec_t rec,
dict_index_t index,
const ulint offsets,
que_thr_t thr 
)
static

Sets a lock on a record.

Used in locking possible duplicate key records and also in checking foreign key constraints.

Parameters
[in]moderequested lock type: LOCK_S or LOCK_X mode
[in]typeLOCK_ORDINARY, LOCK_GAP, or LOCK_REC_NOT_GAP type lock
[in]blockbuffer block of rec
[in]recrecord
[in]indexindex
[in]offsetsrec_get_offsets(rec, index)
[in]thrquery thread
Returns
DB_SUCCESS, DB_SUCCESS_LOCKED_REC, or error code

◆ row_ins_sorted_clust_index_entry()

static dberr_t row_ins_sorted_clust_index_entry ( ulint  mode,
dict_index_t index,
dtuple_t entry,
que_thr_t thr 
)
static

This is a specialized function meant for direct insertion to auto-generated clustered index based on cached position from last successful insert.

To be used when data is sorted.

Parameters
[in]modeBTR_MODIFY_LEAF or BTR_MODIFY_TREE. depending on whether we wish optimistic or pessimistic descent down the index tree
[in,out]indexclustered index
[in,out]entryindex entry to insert
[in]thrquery thread
Returns
error code

◆ row_ins_spatial_index_entry_set_mbr_field()

static void row_ins_spatial_index_entry_set_mbr_field ( dfield_t field,
const dfield_t row_field,
uint32_t *  srid,
const dd::Spatial_reference_system srs 
)
static

This function generate MBR (Minimum Bounding Box) for spatial objects and set it to spatial index field.

Parameters
fieldin/out: mbr field
row_fieldin: row field
sridin/out: spatial reference id
srsin: SRS of row_field

◆ row_ins_step()

que_thr_t * row_ins_step ( que_thr_t thr)

Inserts a row to a table.

This is a high-level function used in SQL execution graphs.

Returns
query thread to run next or NULL
Parameters
thrin: query thread

◆ row_ins_temp_prebuilt_tree_modified()

static void row_ins_temp_prebuilt_tree_modified ( dict_table_t table)
static

Update all the prebuilts working on this temporary table.

Parameters
[in,out]tabledict_table_t for the table