MySQL 8.0.31
Source Code Documentation
row0ins.h File Reference

Insert into a table. More...

#include "data0data.h"
#include "dict0types.h"
#include "que0types.h"
#include "row0types.h"
#include "trx0types.h"
#include "univ.i"

Go to the source code of this file.

Classes

struct  ins_node_t
 

Functions

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...
 
ins_node_tins_node_create (ulint ins_type, dict_table_t *table, mem_heap_t *heap)
 Creates an insert node struct. 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...
 
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...
 
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_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...
 
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...
 
que_thr_trow_ins_step (que_thr_t *thr)
 Inserts a row to a table. More...
 

Variables

constexpr uint32_t INS_NODE_MAGIC_N = 15849075
 
constexpr uint32_t INS_SEARCHED = 0
 INSERT INTO ... SELECT ... More...
 
constexpr uint32_t INS_VALUES = 1
 INSERT INTO ... VALUES ... More...
 
constexpr uint32_t INS_DIRECT = 2
 this is for internal use in dict0crea: insert the row directly More...
 
constexpr uint32_t INS_NODE_SET_IX_LOCK = 1
 we should set an IX lock on table More...
 
constexpr uint32_t INS_NODE_ALLOC_ROW_ID = 2
 row id should be allocated More...
 
constexpr uint32_t INS_NODE_INSERT_ENTRIES = 3
 index entries should be built and inserted 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 in: mem heap where created
own: insert node struct
Parameters
ins_typein: INS_VALUES, ...
tablein: table where to insert
heapin: mem heap where created

◆ 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. in: new row (or first row) for the 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_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_foreign_key_check_lock.

Returns
DB_SUCCESS, DB_LOCK_WAIT, DB_NO_REFERENCED_ROW, or DB_ROW_IS_REFERENCED in: query thread

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_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 in: if true, just do duplicate check and return. don't execute actual insert.

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_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_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_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 in: if true, just do duplicate check and return. don't execute actual insert.

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_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_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 in: query thread

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

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

Variable Documentation

◆ INS_DIRECT

constexpr uint32_t INS_DIRECT = 2
constexpr

this is for internal use in dict0crea: insert the row directly

◆ INS_NODE_ALLOC_ROW_ID

constexpr uint32_t INS_NODE_ALLOC_ROW_ID = 2
constexpr

row id should be allocated

◆ INS_NODE_INSERT_ENTRIES

constexpr uint32_t INS_NODE_INSERT_ENTRIES = 3
constexpr

index entries should be built and inserted

◆ INS_NODE_MAGIC_N

constexpr uint32_t INS_NODE_MAGIC_N = 15849075
constexpr

◆ INS_NODE_SET_IX_LOCK

constexpr uint32_t INS_NODE_SET_IX_LOCK = 1
constexpr

we should set an IX lock on table

◆ INS_SEARCHED

constexpr uint32_t INS_SEARCHED = 0
constexpr

INSERT INTO ... SELECT ...

◆ INS_VALUES

constexpr uint32_t INS_VALUES = 1
constexpr

INSERT INTO ... VALUES ...