MySQL 9.1.0
Source Code Documentation
row0row.cc File Reference

General row routines. More...

#include "row0row.h"
#include <sys/types.h>
#include "btr0btr.h"
#include "data0type.h"
#include "dict0boot.h"
#include "dict0dict.h"
#include "ha_prototypes.h"
#include "lob0lob.h"
#include "mach0data.h"
#include "que0que.h"
#include "read0read.h"
#include "rem0cmp.h"
#include "row0ext.h"
#include "row0mysql.h"
#include "row0upd.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0roll.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "trx0undo.h"
#include "ut0mem.h"

Functions

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_low (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_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...
 
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_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...
 
static ulint row_raw_format_int (const char *data, ulint data_len, ulint prtype, char *buf, ulint buf_size, bool *format_in_hex)
 Formats the raw data in "data" (in InnoDB on-disk format) that is of type DATA_INT using "prtype" and writes the result to "buf". More...
 
static ulint row_raw_format_str (const char *data, ulint data_len, ulint prtype, char *buf, ulint buf_size, bool *format_in_hex)
 Formats the raw data in "data" (in InnoDB on-disk format) that is of type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "prtype" and writes the result to "buf". 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...
 

Detailed Description

General row routines.

Created 4/20/1996 Heikki Tuuri

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_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_low()

static dtuple_t * row_build_low ( 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 
)
inlinestatic

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_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!
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_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
Parameters
modein: BTR_MODIFY_LEAF, ...
recin: record in a secondary index
indexin: secondary index
clust_indexout: clustered index
mtrin: mtr

◆ 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
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_raw_format_int()

static ulint row_raw_format_int ( const char *  data,
ulint  data_len,
ulint  prtype,
char *  buf,
ulint  buf_size,
bool *  format_in_hex 
)
static

Formats the raw data in "data" (in InnoDB on-disk format) that is of type DATA_INT using "prtype" and writes the result to "buf".

If the data is in unknown format, then nothing is written to "buf", 0 is returned and "format_in_hex" is set to true, otherwise "format_in_hex" is left untouched. Not more than "buf_size" bytes are written to "buf". The result is always '\0'-terminated (provided buf_size > 0) and the number of bytes that were written to "buf" is returned (including the terminating '\0').

Returns
number of bytes that were written
Parameters
datain: raw data
data_lenin: raw data length in bytes
prtypein: precise type
bufout: output buffer
buf_sizein: output buffer size in bytes
format_in_hexout: should the data be formatted in hex

◆ row_raw_format_str()

static ulint row_raw_format_str ( const char *  data,
ulint  data_len,
ulint  prtype,
char *  buf,
ulint  buf_size,
bool *  format_in_hex 
)
static

Formats the raw data in "data" (in InnoDB on-disk format) that is of type DATA_(CHAR|VARCHAR|MYSQL|VARMYSQL) using "prtype" and writes the result to "buf".

If the data is in binary format, then nothing is written to "buf", 0 is returned and "format_in_hex" is set to true, otherwise "format_in_hex" is left untouched. Not more than "buf_size" bytes are written to "buf". The result is always '\0'-terminated (provided buf_size > 0) and the number of bytes that were written to "buf" is returned (including the terminating '\0').

Returns
number of bytes that were written
Parameters
datain: raw data
data_lenin: raw data length in bytes
prtypein: precise type
bufout: output buffer
buf_sizein: output buffer size in bytes
format_in_hexout: should the data be formatted in hex

◆ 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
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
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
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
Parameters
pcurout: persistent cursor, which must be closed by the caller
modein: BTR_MODIFY_LEAF, ...
tablein: table
refin: row reference
mtrin/out: mtr