MySQL 8.4.2
Source Code Documentation
|
Select. More...
#include "row0sel.h"
#include <sys/types.h>
#include "btr0btr.h"
#include "btr0cur.h"
#include "btr0sea.h"
#include "buf0lru.h"
#include "dict0boot.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "eval0eval.h"
#include "gis0rtree.h"
#include "ha_innodb.h"
#include "ha_prototypes.h"
#include "handler.h"
#include "lob0lob.h"
#include "lob0undo.h"
#include "lock0lock.h"
#include "mach0data.h"
#include "pars0pars.h"
#include "pars0sym.h"
#include "que0que.h"
#include "read0read.h"
#include "record_buffer.h"
#include "rem0cmp.h"
#include "row0mysql.h"
#include "row0row.h"
#include "row0upd.h"
#include "row0vers.h"
#include "srv0mon.h"
#include "trx0trx.h"
#include "trx0undo.h"
#include "ut0new.h"
#include "my_dbug.h"
Classes | |
class | Row_sel_get_clust_rec_for_mysql |
Helper class to cache clust_rec and old_ver. More... | |
struct | row_to_range_relation_t |
The return type of row_compare_row_to_range() which summarizes information about the relation between the row being processed, and the range of the scan. More... | |
Functions | |
static bool | row_sel_sec_rec_is_for_blob (trx_t *trx, ulint mtype, ulint prtype, ulint mbminmaxlen, const byte *clust_field, ulint clust_len, const byte *sec_field, ulint sec_len, ulint prefix_len, dict_table_t *table) |
Returns true if the user-defined column in a secondary index record is alphabetically the same as the corresponding BLOB column in the clustered index record. More... | |
static dberr_t | row_sel_sec_rec_is_for_clust_rec (const rec_t *sec_rec, dict_index_t *sec_index, const rec_t *clust_rec, dict_index_t *clust_index, que_thr_t *thr, bool &is_equal) |
Returns true if the user-defined column values in a secondary index record are alphabetically the same as the corresponding columns in the clustered index record. More... | |
sel_node_t * | sel_node_create (mem_heap_t *heap) |
Creates a select node struct. More... | |
void | sel_node_free_private (sel_node_t *node) |
Frees the memory private to a select node when a query graph is freed, does not free the heap where the node was originally created. More... | |
static void | sel_eval_select_list (sel_node_t *node) |
Evaluates the values in a select list. More... | |
static void | sel_assign_into_var_values (sym_node_t *var, sel_node_t *node) |
Assigns the values in the select list to the possible into-variables in SELECT ... INTO ... More... | |
static void | sel_reset_aggregate_vals (sel_node_t *node) |
Resets the aggregate value totals in the select list of an aggregate type query. More... | |
static void | row_sel_copy_input_variable_vals (sel_node_t *node) |
Copies the input variable values when an explicit cursor is opened. More... | |
static void | row_sel_fetch_columns (trx_t *trx, dict_index_t *index, const rec_t *rec, const ulint *offsets, sym_node_t *column, bool allow_null_lob=false) |
Fetches the column values from a record. More... | |
static void | sel_col_prefetch_buf_alloc (sym_node_t *column) |
Allocates a prefetch buffer for a column when prefetch is first time done. More... | |
void | sel_col_prefetch_buf_free (sel_buf_t *prefetch_buf) |
Frees a prefetch buffer for a column, including the dynamically allocated memory for data stored there. More... | |
static void | sel_dequeue_prefetched_row (plan_t *plan) |
Pops the column values for a prefetched, cached row from the column prefetch buffers and places them to the val fields in the column nodes. More... | |
static void | sel_enqueue_prefetched_row (plan_t *plan) |
Pushes the column values for a prefetched, cached row to the column prefetch buffers from the val fields in the column nodes. More... | |
static dberr_t | row_sel_build_prev_vers (ReadView *read_view, dict_index_t *index, rec_t *rec, ulint **offsets, mem_heap_t **offset_heap, mem_heap_t **old_vers_heap, rec_t **old_vers, mtr_t *mtr) |
Builds a previous version of a clustered index record for a consistent read. More... | |
static void | row_sel_build_committed_vers_for_mysql (dict_index_t *clust_index, row_prebuilt_t *prebuilt, const rec_t *rec, ulint **offsets, mem_heap_t **offset_heap, const rec_t **old_vers, const dtuple_t **vrow, mtr_t *mtr) |
Builds the last committed version of a clustered index record for a semi-consistent read. More... | |
static bool | row_sel_test_end_conds (plan_t *plan) |
Tests the conditions which determine when the index segment we are searching through has been exhausted. More... | |
static bool | row_sel_test_other_conds (plan_t *plan) |
Tests the other conditions. More... | |
static dberr_t | row_sel_get_clust_rec (sel_node_t *node, plan_t *plan, rec_t *rec, que_thr_t *thr, rec_t **out_rec, mtr_t *mtr) |
Retrieves the clustered index record corresponding to a record in a non-clustered index. More... | |
static dberr_t | sel_set_rtr_rec_lock (btr_pcur_t *pcur, const rec_t *first_rec, dict_index_t *index, const ulint *offsets, select_mode sel_mode, ulint mode, ulint type, que_thr_t *thr, mtr_t *mtr) |
Sets a lock on a page of R-Tree record. More... | |
static dberr_t | sel_set_rec_lock (btr_pcur_t *pcur, const rec_t *rec, dict_index_t *index, const ulint *offsets, select_mode sel_mode, ulint mode, ulint type, que_thr_t *thr, mtr_t *mtr) |
Sets a lock on a record. More... | |
static void | row_sel_open_pcur (plan_t *plan, bool search_latch_locked, mtr_t *mtr) |
Opens a pcur to a table index. More... | |
static bool | row_sel_restore_pcur_pos (plan_t *plan, mtr_t *mtr) |
Restores a stored pcur position to a table index. More... | |
static void | plan_reset_cursor (plan_t *plan) |
Resets a plan cursor to a closed state. More... | |
static ulint | row_sel_try_search_shortcut (trx_t *trx, sel_node_t *node, plan_t *plan, bool search_latch_locked, mtr_t *mtr) |
Tries to do a shortcut to fetch a clustered index record with a unique key, using the hash index if possible (not always). More... | |
static dberr_t | row_sel (sel_node_t *node, que_thr_t *thr) |
Performs a select step. More... | |
que_thr_t * | row_sel_step (que_thr_t *thr) |
Performs a select step. More... | |
que_thr_t * | fetch_step (que_thr_t *thr) |
Performs a fetch for a cursor. More... | |
void | row_sel_convert_mysql_key_to_innobase (dtuple_t *tuple, byte *buf, ulint buf_len, dict_index_t *index, const byte *key_ptr, ulint key_len) |
Converts a key value stored in MySQL format to an Innobase dtuple. More... | |
static void | row_sel_store_row_id_to_prebuilt (row_prebuilt_t *prebuilt, const rec_t *index_rec, const dict_index_t *index, const ulint *offsets) |
Stores the row id to the prebuilt struct. More... | |
void | row_sel_field_store_in_mysql_format_func (byte *dest, const mysql_row_templ_t *templ, const dict_index_t *index, ulint field_no, const byte *data, ulint len, ulint sec_field) |
Stores a non-SQL-NULL field in the MySQL format. More... | |
static bool | row_sel_store_mysql_field (byte *mysql_rec, row_prebuilt_t *prebuilt, const rec_t *rec, const dict_index_t *rec_index, const dict_index_t *prebuilt_index, const ulint *offsets, ulint field_no, const mysql_row_templ_t *templ, ulint sec_field_no, lob::undo_vers_t *lob_undo, mem_heap_t *&blob_heap) |
Convert a field in the Innobase format to a field in the MySQL format. More... | |
bool | row_sel_store_mysql_rec (byte *mysql_rec, row_prebuilt_t *prebuilt, const rec_t *rec, const dtuple_t *vrow, bool rec_clust, const dict_index_t *rec_index, const dict_index_t *prebuilt_index, const ulint *offsets, bool clust_templ_for_sec, lob::undo_vers_t *lob_undo, mem_heap_t *&blob_heap) |
Convert a row in the Innobase format to a row in the MySQL format. More... | |
static dberr_t | row_sel_build_prev_vers_for_mysql (ReadView *read_view, dict_index_t *clust_index, row_prebuilt_t *prebuilt, const rec_t *rec, ulint **offsets, mem_heap_t **offset_heap, rec_t **old_vers, const dtuple_t **vrow, mtr_t *mtr, lob::undo_vers_t *lob_undo) |
Builds a previous version of a clustered index record for a consistent read. More... | |
static bool | sel_restore_position_for_mysql (bool *same_user_rec, ulint latch_mode, btr_pcur_t *pcur, bool moves_up, mtr_t *mtr) |
Restores cursor position after it has been stored. More... | |
static void | row_sel_copy_cached_field_for_mysql (byte *buf, const byte *cache, const mysql_row_templ_t *templ) |
Copies a cached field for MySQL from the fetch cache. More... | |
void | row_sel_copy_cached_fields_for_mysql (byte *buf, const byte *cached_rec, row_prebuilt_t *prebuilt) |
Copy used fields from cached row. More... | |
static Record_buffer * | row_sel_get_record_buffer (const row_prebuilt_t *prebuilt) |
Get the record buffer provided by the server, if there is one. More... | |
static void | row_sel_dequeue_cached_row_for_mysql (byte *buf, row_prebuilt_t *prebuilt) |
Pops a cached row for MySQL from the fetch cache. More... | |
static void | row_sel_prefetch_cache_init (row_prebuilt_t *prebuilt) |
Initialise the prefetch cache. More... | |
static byte * | row_sel_fetch_last_buf (row_prebuilt_t *prebuilt) |
Get the last fetch cache buffer from the queue. More... | |
static void | row_sel_enqueue_cache_row_for_mysql (byte *mysql_rec, row_prebuilt_t *prebuilt) |
Pushes a row for MySQL to the fetch cache. More... | |
static ulint | row_sel_try_search_shortcut_for_mysql (const rec_t **out_rec, row_prebuilt_t *prebuilt, ulint **offsets, mem_heap_t **heap, mtr_t *mtr) |
Tries to do a shortcut to fetch a clustered index record with a unique key, using the hash index if possible (not always). More... | |
static ICP_RESULT | row_search_idx_cond_check (byte *mysql_rec, row_prebuilt_t *prebuilt, const rec_t *rec, const ulint *offsets) |
Check a pushed-down index condition. More... | |
static bool | row_search_end_range_check (byte *mysql_rec, const rec_t *rec, row_prebuilt_t *prebuilt, bool clust_templ_for_sec, const ulint *offsets, Record_buffer *record_buffer) |
Check the pushed-down end-range condition to avoid extra traversal if records are not with in view and also to avoid prefetching too many records into the record buffer. More... | |
static dberr_t | row_search_traverse (bool moves_up, ulint match_mode, btr_pcur_t *pcur, mtr_t *mtr) |
Traverse to next/previous record. More... | |
dberr_t | row_search_no_mvcc (byte *buf, page_cur_mode_t mode, row_prebuilt_t *prebuilt, ulint match_mode, ulint direction) |
Searches for rows in the database using cursor. More... | |
static void | row_sel_fill_vrow (const rec_t *rec, dict_index_t *index, const dtuple_t **vrow, mem_heap_t *heap) |
Extract virtual column data from a virtual index record and fill a dtuple. More... | |
static row_to_range_relation_t | row_compare_row_to_range (const bool set_also_gap_locks, const trx_t *const trx, const bool unique_search, const dict_index_t *const index, const dict_index_t *const clust_index, const rec_t *const rec, const bool comp, const page_cur_mode_t mode, const ulint direction, const dtuple_t *search_tuple, const ulint *const offsets, const bool moves_up, const row_prebuilt_t *const prebuilt) |
A helper function extracted from row_search_mvcc() which compares the row being processed with the range of the scan. More... | |
static rec_t * | row_search_debug_copy_rec_order_prefix (const btr_pcur_t *pcur, const dict_index_t *index, const rec_t *rec, ulint *n_fields, byte **buf, size_t *buf_size) |
If the record is not old version, copies an initial segment of a physical record to be compared later for debug assertion code. More... | |
dberr_t | row_search_mvcc (byte *buf, page_cur_mode_t mode, row_prebuilt_t *prebuilt, ulint match_mode, const ulint direction) |
Searches for rows in the database using cursor. More... | |
dberr_t | row_count_rtree_recs (row_prebuilt_t *prebuilt, ulint *n_rows, ulint *n_dups) |
Count rows in a R-Tree leaf level. More... | |
static uint64_t | row_search_autoinc_read_column (dict_index_t *index, const rec_t *rec, ulint col_no, ulint mtype, bool unsigned_type) |
Read the AUTOINC column from the current row. More... | |
static const rec_t * | row_search_get_max_rec (dict_index_t *index, mtr_t *mtr) |
Get the maximum and non-delete-marked record in an index. More... | |
dberr_t | row_search_max_autoinc (dict_index_t *index, const char *col_name, uint64_t *value) |
Read the max AUTOINC value from an index. More... | |
static void | convert_to_table_stats_record (rec_t *clust_rec, dict_index_t *clust_index, ulint *clust_offsets, TableStatsRecord &tbl_stats) |
Convert the innodb_table_stats clustered index record to table_stats format. More... | |
bool | row_search_table_stats (const char *db_name, const char *tbl_name, TableStatsRecord &table_stats) |
Search the record present in innodb_table_stats table using db_name, table_name and fill it in table stats structure. More... | |
bool | row_search_index_stats (const char *db_name, const char *tbl_name, const char *index_name, ulint col_offset, ulonglong *cardinality) |
Search the record present in innodb_index_stats using db_name, table name and index_name and fill the cardinality for the each column. More... | |
Variables | |
constexpr uint32_t | SEL_MAX_N_PREFETCH = 16 |
Maximum number of rows to prefetch; MySQL interface has another parameter. More... | |
constexpr uint32_t | SEL_PREFETCH_LIMIT = 1 |
Number of rows fetched, after which to start prefetching; MySQL interface has another parameter. More... | |
constexpr uint32_t | SEL_COST_LIMIT = 100 |
When a select has accessed about this many pages, it returns control back to que_run_threads: this is to allow canceling runaway queries. More... | |
constexpr uint32_t | SEL_FOUND = 0 |
Flags for search shortcut. More... | |
constexpr uint32_t | SEL_EXHAUSTED = 1 |
constexpr uint32_t | SEL_RETRY = 2 |
Select.
Created 12/19/1997 Heikki Tuuri
|
static |
Convert the innodb_table_stats clustered index record to table_stats format.
[in] | clust_rec | clustered index record |
[in] | clust_index | clustered index |
[in] | clust_offsets | offsets of the clustered index record |
[out] | tbl_stats | table_stats information to be filled. |
Performs a fetch for a cursor.
thr | in: query thread |
|
inlinestatic |
Resets a plan cursor to a closed state.
plan | in: plan |
|
static |
A helper function extracted from row_search_mvcc() which compares the row being processed with the range of the scan.
It does not modify any of it's arguments and returns a summary of situation. All the arguments are named the same way as local variables at place of call, and have same values.
dberr_t row_count_rtree_recs | ( | row_prebuilt_t * | prebuilt, |
ulint * | n_rows, | ||
ulint * | n_dups | ||
) |
Count rows in a R-Tree leaf level.
prebuilt | in: prebuilt struct for the table handle; this contains the info of search_tuple, index; if search tuple contains 0 fields then we position the cursor at the start or the end of the index, depending on 'mode' |
n_rows | out: number of entries seen in the consistent read |
n_dups | out: number of dup entries |
|
static |
Read the AUTOINC column from the current row.
If the value is less than 0 and the type is not unsigned then we reset the value to 0.
index | in: index to read from |
rec | in: current rec |
col_no | in: column number |
mtype | in: column main type |
unsigned_type | in: signed or unsigned flag |
|
inlinestatic |
If the record is not old version, copies an initial segment of a physical record to be compared later for debug assertion code.
[in] | pcur | cursor whose position has been stored |
[in] | index | index |
[in] | rec | record for which to copy prefix |
[out] | n_fields | number of fields copied |
[in,out] | buf | memory buffer for the copied prefix, or nullptr |
[in,out] | buf_size | buffer size |
|
static |
Check the pushed-down end-range condition to avoid extra traversal if records are not with in view and also to avoid prefetching too many records into the record buffer.
[in] | mysql_rec | record in MySQL format |
[in] | rec | InnoDB record |
[in] | prebuilt | prebuilt struct |
[in] | clust_templ_for_sec | true if rec belongs to the secondary index but the prebuilt template is in clustered index format |
[in] | offsets | information about column offsets in the secondary index, if virtual columns need to be copied into mysql_rec |
[in,out] | record_buffer | the record buffer we are reading into, or nullptr if there is no buffer |
true | if the row in mysql_rec is out of range |
false | if the row in mysql_rec is in range |
|
static |
Get the maximum and non-delete-marked record in an index.
[in] | index | Index tree |
[in,out] | mtr | Mini-transaction (may be committed and restarted) |
NULL | if there are no records, or if all of them are delete-marked |
|
static |
Check a pushed-down index condition.
mysql_rec | out: record in MySQL format (invalid unless prebuilt->idx_cond == true and we return ICP_MATCH) |
prebuilt | in/out: prebuilt struct for the table handle |
rec | in: InnoDB record |
offsets | in: rec_get_offsets() |
bool row_search_index_stats | ( | const char * | db_name, |
const char * | tbl_name, | ||
const char * | index_name, | ||
ulint | col_offset, | ||
ulonglong * | cardinality | ||
) |
Search the record present in innodb_index_stats using db_name, table name and index_name and fill the cardinality for the each column.
[in] | db_name | database name |
[in] | tbl_name | table name |
[in] | index_name | index name |
[in] | col_offset | offset of the column in the index |
[out] | cardinality | cardinality of the column. |
Number of fields to search in the table.
Column number of innodb_index_stats.database_name.
Column number of innodb_index_stats.table_name.
Column number of innodb_index_stats.index_name.
Column number of innodb_index_stats.stat_value.
Search the innodb_index_stats table using (database_name, table_name, index_name).
dberr_t row_search_max_autoinc | ( | dict_index_t * | index, |
const char * | col_name, | ||
uint64_t * | value | ||
) |
Read the max AUTOINC value from an index.
index | in: index to search |
col_name | in: name of autoinc column |
value | out: AUTOINC value read |
dberr_t row_search_mvcc | ( | byte * | buf, |
page_cur_mode_t | mode, | ||
row_prebuilt_t * | prebuilt, | ||
ulint | match_mode, | ||
const ulint | direction | ||
) |
Searches for rows in the database using cursor.
Function is mainly used for tables that are shared accorss connection and so it employs technique that can help re-construct the rows that transaction is suppose to see. It also has optimization such as pre-caching the rows, using AHI, etc.
[out] | buf | buffer for the fetched row in MySQL format |
[in] | mode | search mode PAGE_CUR_L |
[in,out] | prebuilt | prebuilt struct for the table handler; this contains the info to search_tuple, index; if search tuple contains 0 field then we position the cursor at start or the end of index, depending on 'mode' |
[in] | match_mode | 0 or ROW_SEL_EXACT or ROW_SEL_EXACT_PREFIX |
[in] | direction | 0 or ROW_SEL_NEXT or ROW_SEL_PREV; Note: if this is != 0, then prebuilt must has a pcur with stored position! In opening of a cursor 'direction' should be 0. |
Compare the last record of the page with end range passed to InnoDB when there is no ICP and number of loops in row_search_mvcc for rows found but not reporting due to search views etc.
Secondary index record but the template based on PK.
Create offsets based on prebuilt index.
In case of prebuilt->fetch, set the error in prebuilt->end_range.
dberr_t row_search_no_mvcc | ( | byte * | buf, |
page_cur_mode_t | mode, | ||
row_prebuilt_t * | prebuilt, | ||
ulint | match_mode, | ||
ulint | direction | ||
) |
Searches for rows in the database using cursor.
Function is for temporary tables that are not shared across connections and so lot of complexity is reduced especially locking and transaction related. The cursor is an iterator over the table/index.
[out] | buf | buffer for the fetched row in MySQL format |
[in] | mode | search mode PAGE_CUR_L |
[in,out] | prebuilt | prebuilt struct for the table handler; this contains the info to search_tuple, index; if search tuple contains 0 field then we position the cursor at start or the end of index, depending on 'mode' |
[in] | match_mode | 0 or ROW_SEL_EXACT or ROW_SEL_EXACT_PREFIX |
[in] | direction | 0 or ROW_SEL_NEXT or ROW_SEL_PREV; Note: if this is != 0, then prebuilt must has a pcur with stored position! In opening of a cursor 'direction' should be 0. |
bool row_search_table_stats | ( | const char * | db_name, |
const char * | tbl_name, | ||
TableStatsRecord & | table_stats | ||
) |
Search the record present in innodb_table_stats table using db_name, table_name and fill it in table stats structure.
[in] | db_name | database name |
[in] | tbl_name | table name |
[out] | table_stats | stats table structure. |
|
static |
Traverse to next/previous record.
[in] | moves_up | If true, move to next record else previous |
[in] | match_mode | 0 or ROW_SEL_EXACT or ROW_SEL_EXACT_PREFIX |
[in,out] | pcur | Cursor to record |
[in] | mtr | Mini-transaction |
|
static |
Performs a select step.
node | in: select node |
thr | in: query thread |
|
static |
Builds the last committed version of a clustered index record for a semi-consistent read.
clust_index | in: clustered index |
prebuilt | in: prebuilt struct |
rec | in: record in a clustered index |
offsets | in/out: offsets returned by rec_get_offsets(rec, clust_index) |
offset_heap | in/out: memory heap from which the offsets are allocated |
old_vers | out: old version, or NULL if the record does not exist in the view: i.e., it was freshly inserted afterwards |
vrow | out: to be filled with old virtual column version if any |
mtr | in: mtr |
|
static |
Builds a previous version of a clustered index record for a consistent read.
read_view | in: read view |
index | in: plan node for table |
rec | in: record in a clustered index |
offsets | in/out: offsets returned by rec_get_offsets(rec, plan->index) |
offset_heap | in/out: memory heap from which the offsets are allocated |
old_vers_heap | out: old version heap to use |
old_vers | out: old version, or NULL if the record does not exist in the view: i.e., it was freshly inserted afterwards |
mtr | in: mtr |
|
static |
Builds a previous version of a clustered index record for a consistent read.
[in] | read_view | read view |
[in] | clust_index | clustered index |
[in] | prebuilt | prebuilt struct |
[in] | rec | record in clustered index |
[in,out] | offsets | offsets returned by rec_get_offsets(rec, clust_index) |
[in,out] | offset_heap | memory heap from which the offsets are allocated |
[out] | old_vers | old version, or NULL if the record does not exist in the view: i.e., it was freshly inserted afterwards |
[out] | vrow | dtuple to hold old virtual column data |
[in] | mtr | the mini-transaction context. |
[in,out] | lob_undo | Undo information for BLOBs. |
void row_sel_convert_mysql_key_to_innobase | ( | dtuple_t * | tuple, |
byte * | buf, | ||
ulint | buf_len, | ||
dict_index_t * | index, | ||
const byte * | key_ptr, | ||
ulint | key_len | ||
) |
Converts a key value stored in MySQL format to an Innobase dtuple.
The last field of the key value may be just a prefix of a fixed length field: hence the parameter key_len. But currently we do not allow search keys where the last field is only a prefix of the full key field len and print a warning if such appears.
[in,out] | tuple | Tuple where to build; NOTE: we assume that the type info in the tuple is already according to index! |
[in] | buf | Buffer to use in field conversions; NOTE that dtuple->data may end up pointing inside buf so do not discard that buffer while the tuple is being used. See row_mysql_store_col_in_innobase_format() in the case of DATA_INT. |
[in] | buf_len | Buffer length. |
[in] | index | Index of the key value. |
[in] | key_ptr | MySQL key value |
[in] | key_len | MySQL key value length |
|
static |
Copies a cached field for MySQL from the fetch cache.
buf | in/out: row buffer |
cache | in: cached row |
templ | in: column template |
void row_sel_copy_cached_fields_for_mysql | ( | byte * | buf, |
const byte * | cached_rec, | ||
row_prebuilt_t * | prebuilt | ||
) |
Copy used fields from cached row.
Copy cache record field by field, don't touch fields that are not covered by current key.
[out] | buf | Where to copy the MySQL row. |
[in] | cached_rec | What to copy (in MySQL row format). |
[in] | prebuilt | prebuilt struct. |
|
inlinestatic |
Copies the input variable values when an explicit cursor is opened.
node | in: select node |
|
inlinestatic |
Pops a cached row for MySQL from the fetch cache.
buf | in/out: buffer where to copy the row |
prebuilt | in: prebuilt struct |
|
inlinestatic |
Pushes a row for MySQL to the fetch cache.
mysql_rec | in/out: MySQL record |
prebuilt | in/out: prebuilt struct |
|
static |
Fetches the column values from a record.
[in] | trx | the current transaction or nullptr |
[in] | index | record index |
[in] | rec | record in a clustered or non-clustered index; must be protected by a page latch |
[in] | offsets | rec_get_offsets(rec, index) |
[in] | column | first column in a column list, or NULL |
[in] | allow_null_lob | allow null lob if true. default is false. |
|
inlinestatic |
Get the last fetch cache buffer from the queue.
prebuilt | in/out: prebuilt struct |
void row_sel_field_store_in_mysql_format_func | ( | byte * | dest, |
const mysql_row_templ_t * | templ, | ||
const dict_index_t * | index, | ||
ulint | field_no, | ||
const byte * | data, | ||
ulint | len, | ||
ulint | sec_field | ||
) |
Stores a non-SQL-NULL field in the MySQL format.
The counterpart of this function is row_mysql_store_col_in_innobase_format() in row0mysql.cc.
[in,out] | dest | buffer where to store; NOTE that BLOBs are not in themselves stored here: the caller must allocate and copy the BLOB into buffer before, and pass the pointer to the BLOB in 'data' |
[in] | templ | MySQL column template. Its following fields are referenced: type, is_unsigned, mysql_col_len, mbminlen, mbmaxlen |
[in] | index | InnoDB index |
[in] | field_no | templ->rec_field_no or templ->clust_rec_field_no or templ->icp_rec_field_no |
[in] | data | data to store |
[in] | len | length of the data |
[in] | sec_field | secondary index field no if the secondary index record but the prebuilt template is in clustered index format and used only for end range comparison. |
|
static |
Extract virtual column data from a virtual index record and fill a dtuple.
[in] | rec | the virtual (secondary) index record |
[in] | index | the virtual index |
[in,out] | vrow | the dtuple where data extract to |
[in] | heap | memory heap to allocate memory |
|
static |
Retrieves the clustered index record corresponding to a record in a non-clustered index.
Does the necessary locking.
node | in: select_node |
plan | in: plan node for table |
rec | in: record in a non-clustered index |
thr | in: query thread |
out_rec | out: clustered record or an old version of it, NULL if the old version did not exist in the read view, i.e., it was a fresh inserted version |
mtr | in: mtr used to get access to the non-clustered record; the same mtr is used to access the clustered index |
|
static |
Get the record buffer provided by the server, if there is one.
prebuilt | prebuilt struct |
Opens a pcur to a table index.
plan | in: table plan |
search_latch_locked | in: true if the thread currently has the search latch locked in s-mode |
mtr | in: mtr |
|
inlinestatic |
Initialise the prefetch cache.
prebuilt | in/out: prebuilt struct |
Restores a stored pcur position to a table index.
plan | in: table plan |
mtr | in: mtr |
|
static |
Returns true if the user-defined column in a secondary index record is alphabetically the same as the corresponding BLOB column in the clustered index record.
NOTE: the comparison is NOT done as a binary comparison, but character fields are compared with collation!
trx | in: the operating transaction |
mtype | in: main type |
prtype | in: precise type |
mbminmaxlen | in: minimum and maximum length of a multi-byte character |
clust_field | in: the locally stored part of the clustered index column, including the BLOB pointer; the clustered index record must be covered by a lock or a page latch to protect it against deletion (rollback or purge) |
clust_len | in: length of clust_field |
sec_field | in: column in secondary index |
sec_len | in: length of sec_field |
prefix_len | in: index column prefix length in bytes |
table | in: table |
|
static |
Returns true if the user-defined column values in a secondary index record are alphabetically the same as the corresponding columns in the clustered index record.
NOTE: the comparison is NOT done as a binary comparison, but character fields are compared with collation!
[in] | sec_rec | secondary index record |
[in] | sec_index | secondary index |
[in] | clust_rec | clustered index record; must be protected by a page s-latch |
[in] | clust_index | clustered index |
[in] | thr | query thread |
[out] | is_equal | set to true if the secondary record is equal to the corresponding fields in the clustered record, when compared with collation; false if not equal or if the clustered record has been marked for deletion; only valid if DB_SUCCESS was returned |
Performs a select step.
This is a high-level function used in SQL execution graphs.
thr | in: query thread |
|
static |
Convert a field in the Innobase format to a field in the MySQL format.
[out] | mysql_rec | Record in the MySQL format |
[in,out] | prebuilt | Prebuilt struct |
[in] | rec | InnoDB record; must be protected by a page latch |
[in] | rec_index | Index of rec |
[in] | prebuilt_index | prebuilt->index |
[in] | offsets | Array returned by rec_get_offsets() |
[in] | field_no | templ->rec_field_no or templ->clust_rec_field_no or templ->icp_rec_field_no or sec field no if clust_templ_for_sec is true |
[in] | templ | row template |
[in] | sec_field_no | Secondary index field no if the secondary index record but the prebuilt template is in clustered index format and used only for end range comparison. |
[in] | lob_undo | the LOB undo information. |
[in,out] | blob_heap | If not null then use this heap for BLOBs |
bool row_sel_store_mysql_rec | ( | byte * | mysql_rec, |
row_prebuilt_t * | prebuilt, | ||
const rec_t * | rec, | ||
const dtuple_t * | vrow, | ||
bool | rec_clust, | ||
const dict_index_t * | rec_index, | ||
const dict_index_t * | prebuilt_index, | ||
const ulint * | offsets, | ||
bool | clust_templ_for_sec, | ||
lob::undo_vers_t * | lob_undo, | ||
mem_heap_t *& | blob_heap | ||
) |
Convert a row in the Innobase format to a row in the MySQL format.
Note that the template in prebuilt may advise us to copy only a few columns to mysql_rec, other columns are left blank. All columns may not be needed in the query.
[out] | mysql_rec | row in the MySQL format |
[in,out] | prebuilt | prebuilt structure |
[in] | rec | Innobase record in the index which was described in prebuilt's template, or in the clustered index; must be protected by a page latch |
[in] | vrow | virtual columns |
[in] | rec_clust | true if rec is in the clustered index instead of index which could belong to prebuilt->index |
[in] | rec_index | index of rec |
[in] | prebuilt_index | prebuilt->index |
[in] | offsets | array returned by rec_get_offsets(rec) |
[in] | clust_templ_for_sec | true if rec belongs to secondary index but the prebuilt->template is in clustered index format and it is used only for end range comparison |
[in] | lob_undo | the LOB undo information. |
[in,out] | blob_heap | If not null then use this heap for BLOBs |
|
static |
Stores the row id to the prebuilt struct.
prebuilt | in/out: prebuilt |
index_rec | in: record |
index | in: index of the record |
offsets | in: rec_get_offsets (index_rec, index) |
|
inlinestatic |
Tests the conditions which determine when the index segment we are searching through has been exhausted.
plan | in: plan for the table; the column values must already have been retrieved and the right sides of comparisons evaluated |
|
inlinestatic |
Tests the other conditions.
plan | in: plan for the table; the column values must already have been retrieved |
|
static |
Tries to do a shortcut to fetch a clustered index record with a unique key, using the hash index if possible (not always).
trx | in: trx doing the operation. |
node | in: select node for a consistent read |
plan | in: plan for a unique search in clustered index |
search_latch_locked | in: whether the search holds latch on search system. |
mtr | in: mtr |
|
static |
Tries to do a shortcut to fetch a clustered index record with a unique key, using the hash index if possible (not always).
We assume that the search mode is PAGE_CUR_GE, it is a consistent read, there is a read view in trx, btr search latch has been locked in S-mode if AHI is enabled.
out_rec | out: record if found |
prebuilt | in: prebuilt struct |
offsets | in/out: for rec_get_offsets(*out_rec) |
heap | in/out: heap for rec_get_offsets() |
mtr | in: started mtr |
|
inlinestatic |
Assigns the values in the select list to the possible into-variables in SELECT ... INTO ...
var | in: first variable in a list of variables |
node | in: select node |
|
static |
Allocates a prefetch buffer for a column when prefetch is first time done.
column | in: symbol table node for a column |
void sel_col_prefetch_buf_free | ( | sel_buf_t * | prefetch_buf | ) |
Frees a prefetch buffer for a column, including the dynamically allocated memory for data stored there.
in, own: prefetch buffer
prefetch_buf | in, own: prefetch buffer |
|
static |
Pops the column values for a prefetched, cached row from the column prefetch buffers and places them to the val fields in the column nodes.
plan | in: plan node for a table |
|
inlinestatic |
Pushes the column values for a prefetched, cached row to the column prefetch buffers from the val fields in the column nodes.
plan | in: plan node for a table |
|
inlinestatic |
Evaluates the values in a select list.
If there are aggregate functions, their argument value is added to the aggregate total.
node | in: select node |
sel_node_t * sel_node_create | ( | mem_heap_t * | heap | ) |
Creates a select node struct.
heap | in: memory heap where created |
void sel_node_free_private | ( | sel_node_t * | node | ) |
Frees the memory private to a select node when a query graph is freed, does not free the heap where the node was originally created.
in: select node struct
node | in: select node struct |
|
inlinestatic |
Resets the aggregate value totals in the select list of an aggregate type query.
node | in: select node |
|
static |
Restores cursor position after it has been stored.
We have to take into account that the record cursor was positioned on may have been deleted. Then we may have to move the cursor one step up or down.
same_user_rec | out: true if we were able to restore the cursor on a user record with the same ordering prefix in in the B-tree index |
latch_mode | in: latch mode wished in restoration |
pcur | in: cursor whose position has been stored |
moves_up | in: true if the cursor moves up in the index |
mtr | in: mtr; CAUTION: may commit mtr temporarily! |
|
inlinestatic |
Sets a lock on a record.
mostly due to we cannot reposition a record in R-Tree (with the nature of splitting)
[in] | pcur | cursor |
[in] | rec | record |
[in] | index | index |
[in] | offsets | rec_get_offsets(rec, index) |
[in] | sel_mode | select mode: SELECT_ORDINARY, SELECT_SKIP_LOKCED, or SELECT_NO_WAIT |
[in] | mode | lock mode |
[in] | type | LOCK_ORDINARY, LOCK_GAP, or LOC_REC_NOT_GAP |
[in] | thr | query thread |
[in] | mtr | mtr |
|
inlinestatic |
Sets a lock on a page of R-Tree record.
This is all or none action, mostly due to we cannot reposition a record in R-Tree (with the nature of splitting)
[in] | pcur | cursor |
[in] | first_rec | record |
[in] | index | index |
[in] | offsets | rec_get_offsets(rec, index) |
[in] | sel_mode | select mode: SELECT_ORDINARY, SELECT_SKIP_LOKCED, or SELECT_NO_WAIT |
[in] | mode | lock mode |
[in] | type | LOCK_ORDINARY, LOCK_GAP, or LOC_REC_NOT_GAP |
[in] | thr | query thread |
[in] | mtr | mtr |
|
constexpr |
When a select has accessed about this many pages, it returns control back to que_run_threads: this is to allow canceling runaway queries.
|
constexpr |
|
constexpr |
Flags for search shortcut.
|
constexpr |
Maximum number of rows to prefetch; MySQL interface has another parameter.
|
constexpr |
Number of rows fetched, after which to start prefetching; MySQL interface has another parameter.
|
constexpr |