MySQL 8.0.39
Source Code Documentation
|
Select. More...
#include "univ.i"
#include "btr0pcur.h"
#include "data0data.h"
#include "dict0stats.h"
#include "dict0types.h"
#include "pars0sym.h"
#include "que0types.h"
#include "read0types.h"
#include "row0mysql.h"
#include "row0types.h"
#include "trx0types.h"
#include "row0sel.ic"
Go to the source code of this file.
Classes | |
struct | sel_buf_t |
A structure for caching column values for prefetched rows. More... | |
struct | plan_t |
Query plan. More... | |
struct | sel_node_t |
Select statement node. More... | |
struct | fetch_node_t |
Fetch statement node. More... | |
struct | open_node_t |
Open or close cursor statement node. More... | |
Enumerations | |
enum | sel_node_state { SEL_NODE_CLOSED , SEL_NODE_OPEN , SEL_NODE_FETCH , SEL_NODE_NO_MORE_ROWS } |
Select node states. More... | |
enum | open_node_op { ROW_SEL_OPEN_CURSOR , ROW_SEL_CLOSE_CURSOR } |
Open or close cursor operation type. More... | |
enum | row_sel_direction { ROW_SEL_NEXT = 1 , ROW_SEL_PREV = 2 } |
Search direction for the MySQL interface. More... | |
enum | row_sel_match_mode { ROW_SEL_EXACT = 1 , ROW_SEL_EXACT_PREFIX } |
Match mode for the MySQL interface. More... | |
Functions | |
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... | |
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 plan_t * | sel_node_get_nth_plan (sel_node_t *node, ulint i) |
Gets the plan node for the nth table in a join. More... | |
que_thr_t * | row_sel_step (que_thr_t *thr) |
Performs a select step. More... | |
static que_thr_t * | open_step (que_thr_t *thr) |
Performs an execution step of an open or close cursor statement node. More... | |
que_thr_t * | fetch_step (que_thr_t *thr) |
Performs a fetch for a cursor. 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... | |
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... | |
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 dberr_t | row_search_for_mysql (byte *buf, page_cur_mode_t mode, row_prebuilt_t *prebuilt, ulint match_mode, ulint direction) |
Searches for rows in the database. 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... | |
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... | |
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... | |
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 void | row_sel_field_store_in_mysql_format (byte *dest, const mysql_row_templ_t *templ, const dict_index_t *idx, ulint field, const byte *src, ulint len, ulint sec) |
Convert a non-SQL-NULL field from Innobase format to MySQL 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... | |
Select.
Created 12/19/1997 Heikki Tuuri
enum open_node_op |
enum row_sel_direction |
enum row_sel_match_mode |
enum sel_node_state |
Performs a fetch for a cursor.
thr | in: query thread |
Performs an execution step of an open or close cursor statement node.
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 |
|
inlinestatic |
Searches for rows in the database.
This is used in the interface to MySQL. This function opens a cursor, and also implements fetch next and fetch prev. NOTE that if we do a search with a full key value from a unique index (ROW_SEL_EXACT), then we will not store the cursor position and fetch next or fetch prev must not be tried to the cursor!
[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_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. |
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 |
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 |
Convert a non-SQL-NULL field from Innobase format to MySQL format.
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. |
Performs a select step.
This is a high-level function used in SQL execution graphs.
This is a high-level function used in SQL execution graphs.
thr | in: query thread |
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 |
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 |
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 |
Gets the plan node for the nth table in a join.
[in] | node | select node |
[in] | i | get ith plan node |