MySQL 8.0.31
Source Code Documentation
row0row.h File Reference

General row routines. More...

#include "btr0types.h"
#include "data0data.h"
#include "dict0types.h"
#include "mtr0mtr.h"
#include "que0types.h"
#include "rem0types.h"
#include "row0types.h"
#include "trx0types.h"
#include "univ.i"
#include "row0row.ic"

Go to the source code of this file.

Classes

class  Multi_value_entry_builder
 Class to build a series of entries based on one multi-value field. More...
 
class  Multi_value_entry_builder_normal
 The subclass of the multi-value entry builder, for non-INSERT cases, With this class, there should be no need to build separate entries for different values in the same multi-value field. More...
 
class  Multi_value_entry_builder_insert
 The subclass of the multi-value row builder, for INSERT cases. More...
 

Enumerations

enum  row_search_result { ROW_FOUND = 0 , ROW_NOT_FOUND , ROW_BUFFERED , ROW_NOT_DELETED_REF }
 Result of row_search_index_entry. More...
 

Functions

static ulint row_get_trx_id_offset (const dict_index_t *index, const ulint *offsets)
 Gets the offset of the DB_TRX_ID field, in bytes relative to the origin of a clustered index record. More...
 
static trx_id_t row_get_rec_trx_id (const rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Reads the trx id field from a clustered index record. More...
 
static roll_ptr_t row_get_rec_roll_ptr (const rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Reads the roll pointer field from a clustered index record. More...
 
dtuple_trow_build_index_entry_low (const dtuple_t *row, const row_ext_t *ext, const dict_index_t *index, mem_heap_t *heap, ulint flag)
 When an insert or purge to a table is performed, this function builds the entry to be inserted into or purged from an index on the table. More...
 
static dtuple_trow_build_index_entry (const dtuple_t *row, const row_ext_t *ext, const dict_index_t *index, mem_heap_t *heap)
 When an insert or purge to a table is performed, this function builds the entry to be inserted into or purged from an index on the table. More...
 
dtuple_trow_build (ulint type, const dict_index_t *index, const rec_t *rec, const ulint *offsets, const dict_table_t *col_table, const dtuple_t *add_cols, const ulint *col_map, row_ext_t **ext, mem_heap_t *heap)
 An inverse function to row_build_index_entry. More...
 
dtuple_trow_build_w_add_vcol (ulint type, const dict_index_t *index, const rec_t *rec, const ulint *offsets, const dict_table_t *col_table, const dtuple_t *add_cols, const dict_add_v_col_t *add_v, const ulint *col_map, row_ext_t **ext, mem_heap_t *heap)
 An inverse function to row_build_index_entry. More...
 
dtuple_trow_rec_to_index_entry_low (const rec_t *rec, const dict_index_t *index, const ulint *offsets, mem_heap_t *heap)
 Converts an index record to a typed data tuple. More...
 
dtuple_trow_rec_to_index_entry (const rec_t *rec, const dict_index_t *index, const ulint *offsets, mem_heap_t *heap)
 Converts an index record to a typed data tuple. More...
 
dtuple_trow_build_row_ref (ulint type, const dict_index_t *index, const rec_t *rec, mem_heap_t *heap)
 Builds from a secondary index record a row reference with which we can search the clustered index record. More...
 
void row_build_row_ref_in_tuple (dtuple_t *ref, const rec_t *rec, const dict_index_t *index, ulint *offsets)
 Builds from a secondary index record a row reference with which we can search the clustered index record. More...
 
static void row_build_row_ref_fast (dtuple_t *ref, const ulint *map, const rec_t *rec, const ulint *offsets)
 Builds from a secondary index record a row reference with which we can search the clustered index record. More...
 
bool row_search_on_row_ref (btr_pcur_t *pcur, ulint mode, dict_table_t *table, const dtuple_t *ref, mtr_t *mtr)
 Searches the clustered index record for a row, if we have the row reference. More...
 
rec_trow_get_clust_rec (ulint mode, const rec_t *rec, const dict_index_t *index, dict_index_t **clust_index, mtr_t *mtr)
 Fetches the clustered index record for a secondary index record. More...
 
uint64_t row_parse_int (const byte *data, ulint len, ulint mtype, bool unsigned_type)
 Parse the integer data from specified data, which could be DATA_INT, DATA_FLOAT or DATA_DOUBLE. More...
 
uint64_t row_parse_int_from_field (const dfield_t *field)
 Parse the integer data from specified field, which could be DATA_INT, DATA_FLOAT or DATA_DOUBLE. More...
 
uint64_t row_get_autoinc_counter (const dtuple_t *row, ulint n)
 Read the autoinc counter from the clustered index row. More...
 
enum row_search_result row_search_index_entry (dict_index_t *index, const dtuple_t *entry, ulint mode, btr_pcur_t *pcur, mtr_t *mtr)
 Searches an index record. More...
 
ulint row_raw_format (const char *data, ulint data_len, const dict_field_t *dict_field, char *buf, ulint buf_size)
 Formats the raw data in "data" (in InnoDB on-disk format) using "dict_field" and writes the result to "buf". More...
 

Variables

constexpr uint32_t ROW_BUILD_NORMAL = 0
 build index row More...
 
constexpr uint32_t ROW_BUILD_FOR_PURGE = 1
 build row for purge. More...
 
constexpr uint32_t ROW_BUILD_FOR_UNDO = 2
 build row for undo. More...
 
constexpr uint32_t ROW_BUILD_FOR_INSERT = 3
 build row for insert. More...
 
constexpr uint32_t ROW_COPY_DATA = 1
 
constexpr uint32_t ROW_COPY_POINTERS = 2
 

Detailed Description

General row routines.

Created 4/20/1996 Heikki Tuuri

Enumeration Type Documentation

◆ row_search_result

Result of row_search_index_entry.

Enumerator
ROW_FOUND 

the record was found

ROW_NOT_FOUND 

record not found

ROW_BUFFERED 

one of BTR_INSERT, BTR_DELETE, or BTR_DELETE_MARK was specified, the secondary index leaf page was not in the buffer pool, and the operation was enqueued in the insert/delete buffer

ROW_NOT_DELETED_REF 

BTR_DELETE was specified, and row_purge_poss_sec() failed.

Function Documentation

◆ row_build()

dtuple_t * row_build ( ulint  type,
const dict_index_t index,
const rec_t rec,
const ulint offsets,
const dict_table_t col_table,
const dtuple_t add_cols,
const ulint col_map,
row_ext_t **  ext,
mem_heap_t heap 
)

An inverse function to row_build_index_entry.

Builds a row from a record in a clustered index.

Parameters
[in]typeROW_COPY_POINTERS or ROW_COPY_DATA; the latter copies also the data fields to heap while the first only places pointers to data fields on the index page, and thus is more efficient.
[in]indexClustered index.
[in]recRecord in the clustered index; NOTE: in the case ROW_COPY_POINTERS the data fields in the row will point directly into this record, therefore, the buffer page of this record must be at least s-latched and the latch held as long as the row dtuple is used!
[in]offsetsrec_get_offsets(rec,index) or nullptr, in which case this function will invoke rec_get_offsets().
[in]col_tableTable, to check which externally stored columns occur in the ordering columns of an index, or nullptr if index->table should be consulted instead; the user columns in this table should be the same columns as in index->table.
[in]add_colsDefault values of added columns, or nullptr.
[in]col_mapMapping of old column numbers to new ones, or nullptr.
[out]extcache of externally stored column prefixes, or nullptr.
[in]heapMemory heap from which the memory needed is allocated.
Returns
own: row built; see the NOTE below!

◆ row_build_index_entry()

static dtuple_t * row_build_index_entry ( const dtuple_t row,
const row_ext_t ext,
const dict_index_t index,
mem_heap_t heap 
)
inlinestatic

When an insert or purge to a table is performed, this function builds the entry to be inserted into or purged from an index on the table.

Returns
index entry which should be inserted or purged, or NULL if the externally stored columns in the clustered index record are unavailable and ext != nullptr
Parameters
[in]rowRow which should be inserted or purged.
[in]extExternally stored column prefixes, or nullptr.
[in]indexIndex on the table.
[in]heapMemory heap from which the memory for the index entry is allocated.

◆ row_build_index_entry_low()

dtuple_t * row_build_index_entry_low ( const dtuple_t row,
const row_ext_t ext,
const dict_index_t index,
mem_heap_t heap,
ulint  flag 
)

When an insert or purge to a table is performed, this function builds the entry to be inserted into or purged from an index on the table.

Parameters
[in]rowRow which should be inserted or purged.
[in]extExternally stored column prefixes, or nullptr.
[in]indexIndex on the table.
[in]heapMemory heap from which the memory for the index entry is allocated.
[in]flagROW_BUILD_NORMAL, ROW_BUILD_FOR_PURGE or ROW_BUILD_FOR_UNDO.
Returns
index entry which should be inserted or purged
Return values
NULLif the externally stored columns in the clustered index record are unavailable and ext != nullptr, or row is missing some needed columns.

◆ row_build_row_ref()

dtuple_t * row_build_row_ref ( ulint  type,
const dict_index_t index,
const rec_t rec,
mem_heap_t heap 
)

Builds from a secondary index record a row reference with which we can search the clustered index record.

Returns
own: row reference built; see the NOTE below! in: memory heap from which the memory needed is allocated
own: row reference built; see the NOTE below!
Parameters
typein: ROW_COPY_DATA, or ROW_COPY_POINTERS: the former copies also the data fields to heap, whereas the latter only places pointers to data fields on the index page
indexin: secondary index
recin: record in the index; NOTE: in the case ROW_COPY_POINTERS the data fields in the row will point directly into this record, therefore, the buffer page of this record must be at least s-latched and the latch held as long as the row reference is used!
heapin: memory heap from which the memory needed is allocated

◆ row_build_row_ref_fast()

static void row_build_row_ref_fast ( dtuple_t ref,
const ulint map,
const rec_t rec,
const ulint offsets 
)
inlinestatic

Builds from a secondary index record a row reference with which we can search the clustered index record.

Parameters
[in,out]reftyped data tuple where the reference is built
[in]maparray of field numbers in rec telling how ref should be built from the fields of rec
[in]recrecord in the index; must be preserved while ref is used, as we do not copy field values to heap
[in]offsetsarray returned by rec_get_offsets()

◆ row_build_row_ref_in_tuple()

void row_build_row_ref_in_tuple ( dtuple_t ref,
const rec_t rec,
const dict_index_t index,
ulint offsets 
)

Builds from a secondary index record a row reference with which we can search the clustered index record.

Parameters
[in,out]refRow reference built; see the note below!
[in,out]recRecord in the index; note: the data fields in ref will point directly into this record, therefore, the buffer page of this record must be at least s-latched and the latch held as long as the row reference is used!
[in]indexSecondary index
[in]offsetsRec_get_offsets(rec, index) or null

◆ row_build_w_add_vcol()

dtuple_t * row_build_w_add_vcol ( ulint  type,
const dict_index_t index,
const rec_t rec,
const ulint offsets,
const dict_table_t col_table,
const dtuple_t add_cols,
const dict_add_v_col_t add_v,
const ulint col_map,
row_ext_t **  ext,
mem_heap_t heap 
)

An inverse function to row_build_index_entry.

Builds a row from a record in a clustered index, with possible indexing on ongoing addition of new virtual columns.

Parameters
[in]typeROW_COPY_POINTERS or ROW_COPY_DATA;
[in]indexclustered index
[in]recrecord in the clustered index
[in]offsetsrec_get_offsets(rec,index) or NULL
[in]col_tabletable, to check which externally stored columns occur in the ordering columns of an index, or NULL if index->table should be consulted instead
[in]add_colsdefault values of added columns, or NULL
[in]add_vnew virtual columns added along with new indexes
[in]col_mapmapping of old column numbers to new ones, or NULL
[in]extcache of externally stored column prefixes, or NULL
[in]heapmemory heap from which the memory needed is allocated
Returns
own: row built

◆ row_get_autoinc_counter()

uint64_t row_get_autoinc_counter ( const dtuple_t row,
ulint  n 
)

Read the autoinc counter from the clustered index row.

Parameters
[in]rowrow to read the autoinc counter
[in]nautoinc counter is in the nth field
Returns
the autoinc counter read

◆ row_get_clust_rec()

rec_t * row_get_clust_rec ( ulint  mode,
const rec_t rec,
const dict_index_t index,
dict_index_t **  clust_index,
mtr_t mtr 
)

Fetches the clustered index record for a secondary index record.

The latches on the secondary index record are preserved.

Returns
record or NULL, if no record found in: mtr

The latches on the secondary index record are preserved.

Returns
record or NULL, if no record found
Parameters
modein: BTR_MODIFY_LEAF, ...
recin: record in a secondary index
indexin: secondary index
clust_indexout: clustered index
mtrin: mtr

◆ row_get_rec_roll_ptr()

static roll_ptr_t row_get_rec_roll_ptr ( const rec_t rec,
const dict_index_t index,
const ulint offsets 
)
inlinestatic

Reads the roll pointer field from a clustered index record.

Parameters
[in]recRecord.
[in]indexClustered index.
[in]offsetsrec_get_offsets(rec, index).
Returns
value of the field

◆ row_get_rec_trx_id()

static trx_id_t row_get_rec_trx_id ( const rec_t rec,
const dict_index_t index,
const ulint offsets 
)
inlinestatic

Reads the trx id field from a clustered index record.

Parameters
[in]recRecord.
[in]indexClustered index.
[in]offsetsrec_get_offsets(rec, index).
Returns
value of the field

◆ row_get_trx_id_offset()

static ulint row_get_trx_id_offset ( const dict_index_t index,
const ulint offsets 
)
inlinestatic

Gets the offset of the DB_TRX_ID field, in bytes relative to the origin of a clustered index record.

Parameters
[in]indexClustered index.
[in]offsetsrec_get_offsets(rec, index).
Returns
offset of DATA_TRX_ID

◆ row_parse_int()

uint64_t row_parse_int ( const byte data,
ulint  len,
ulint  mtype,
bool  unsigned_type 
)
inline

Parse the integer data from specified data, which could be DATA_INT, DATA_FLOAT or DATA_DOUBLE.

If the value is less than 0 and the type is not unsigned then we reset the value to 0

Parameters
[in]datadata to read
[in]lenlength of data
[in]mtypemtype of data
[in]unsigned_typeif the data is unsigned
Returns
the integer value from the data

◆ row_parse_int_from_field()

uint64_t row_parse_int_from_field ( const dfield_t field)

Parse the integer data from specified field, which could be DATA_INT, DATA_FLOAT or DATA_DOUBLE.

We could return 0 if 1) the value is less than 0 and the type is not unsigned or 2) the field is null.

Parameters
[in]fieldfield to read the int value
Returns
the integer value read from the field, 0 for negative signed int or NULL field

◆ row_raw_format()

ulint row_raw_format ( const char *  data,
ulint  data_len,
const dict_field_t dict_field,
char *  buf,
ulint  buf_size 
)

Formats the raw data in "data" (in InnoDB on-disk format) using "dict_field" and writes the result to "buf".

Not more than "buf_size" bytes are written to "buf". The result is always NUL-terminated (provided buf_size is positive) and the number of bytes that were written to "buf" is returned (including the terminating NUL).

Returns
number of bytes that were written in: output buffer size in bytes

Not more than "buf_size" bytes are written to "buf". The result is always NUL-terminated (provided buf_size is positive) and the number of bytes that were written to "buf" is returned (including the terminating NUL).

Returns
number of bytes that were written
Parameters
datain: raw data
data_lenin: raw data length in bytes
dict_fieldin: index field
bufout: output buffer
buf_sizein: output buffer size in bytes

◆ row_rec_to_index_entry()

dtuple_t * row_rec_to_index_entry ( const rec_t rec,
const dict_index_t index,
const ulint offsets,
mem_heap_t heap 
)

Converts an index record to a typed data tuple.

NOTE that externally stored (often big) fields are NOT copied to heap.

Returns
own: index entry built in: memory heap from which the memory needed is allocated

NOTE that externally stored (often big) fields are NOT copied to heap.

Returns
own: index entry built
Parameters
recin: record in the index
indexin: index
offsetsin: rec_get_offsets(rec)
heapin: memory heap from which the memory needed is allocated

◆ row_rec_to_index_entry_low()

dtuple_t * row_rec_to_index_entry_low ( const rec_t rec,
const dict_index_t index,
const ulint offsets,
mem_heap_t heap 
)

Converts an index record to a typed data tuple.

Returns
index entry built; does not set info_bits, and the data fields in the entry will point directly to rec in: memory heap from which the memory needed is allocated
index entry built; does not set info_bits, and the data fields in the entry will point directly to rec
Parameters
recin: record in the index
indexin: index
offsetsin: rec_get_offsets(rec, index)
heapin: memory heap from which the memory needed is allocated

◆ row_search_index_entry()

enum row_search_result row_search_index_entry ( dict_index_t index,
const dtuple_t entry,
ulint  mode,
btr_pcur_t pcur,
mtr_t mtr 
)

Searches an index record.

Returns
whether the record was found or buffered in: mtr
whether the record was found or buffered
Parameters
indexin: index
entryin: index entry
modein: BTR_MODIFY_LEAF, ...
pcurin/out: persistent cursor, which must be closed by the caller
mtrin: mtr

◆ row_search_on_row_ref()

bool row_search_on_row_ref ( btr_pcur_t pcur,
ulint  mode,
dict_table_t table,
const dtuple_t ref,
mtr_t mtr 
)

Searches the clustered index record for a row, if we have the row reference.

Returns
true if found in/out: mtr
true if found
Parameters
pcurout: persistent cursor, which must be closed by the caller
modein: BTR_MODIFY_LEAF, ...
tablein: table
refin: row reference
mtrin/out: mtr

Variable Documentation

◆ ROW_BUILD_FOR_INSERT

constexpr uint32_t ROW_BUILD_FOR_INSERT = 3
constexpr

build row for insert.

◆ ROW_BUILD_FOR_PURGE

constexpr uint32_t ROW_BUILD_FOR_PURGE = 1
constexpr

build row for purge.

◆ ROW_BUILD_FOR_UNDO

constexpr uint32_t ROW_BUILD_FOR_UNDO = 2
constexpr

build row for undo.

◆ ROW_BUILD_NORMAL

constexpr uint32_t ROW_BUILD_NORMAL = 0
constexpr

build index row

◆ ROW_COPY_DATA

constexpr uint32_t ROW_COPY_DATA = 1
constexpr

◆ ROW_COPY_POINTERS

constexpr uint32_t ROW_COPY_POINTERS = 2
constexpr