MySQL 8.0.39
Source Code Documentation
|
After parsing, a Common Table Expression is accessed through a Table_ref. More...
#include <table.h>
Public Member Functions | |
Common_table_expr (MEM_ROOT *mem_root) | |
TABLE * | clone_tmp_table (THD *thd, Table_ref *tl) |
Produces, from the first tmp TABLE object, a clone TABLE object for Table_ref 'tl', to have a single materialization of multiple references to a CTE. More... | |
bool | substitute_recursive_reference (THD *thd, Query_block *sl) |
Replaces the recursive reference in query block 'sl' with a clone of the first tmp table. More... | |
void | remove_table (Table_ref *tr) |
Remove one table reference. More... | |
bool | clear_all_references () |
Empties the materialized CTE and informs all of its clones. More... | |
Public Attributes | |
Mem_root_array< Table_ref * > | references |
All references to this CTE in the statement, except those inside the query expression defining this CTE. More... | |
bool | recursive |
True if it's a recursive CTE. More... | |
Mem_root_array< Table_ref * > | tmp_tables |
List of all TABLE_LISTSs reading/writing to the tmp table created to materialize this CTE. More... | |
LEX_STRING | name |
Name of the WITH block. Used only for EXPLAIN FORMAT=tree. More... | |
After parsing, a Common Table Expression is accessed through a Table_ref.
This class contains all information about the CTE which the Table_ref needs.
|
inline |
bool Common_table_expr::clear_all_references | ( | ) |
Empties the materialized CTE and informs all of its clones.
Produces, from the first tmp TABLE object, a clone TABLE object for Table_ref 'tl', to have a single materialization of multiple references to a CTE.
There are several scenarios. (1) Non-recursive CTE referenced only once: nothing special. (2) Non-recursive CTE referenced more than once:
The storage engine needs to take measures so that inserts and reads don't corrupt each other's behaviour. In InnoDB that means two things (
The internal tmp table must support a phase where table scans and insertions happen interlaced, either issued from a single TABLE or from multiple TABLE clones. If from a single TABLE, that object does repetitions of {"write rows" then "init scan / read rows / close scan"}. If from multiple TABLEs, one does "write rows", every other one does "init scan / read rows / close scan". During this, neither updates, nor deletes, nor any other type of read access than table scans, are allowed on this table (they are allowed after the phase's end). Any started table scan on this table:
See create_ondisk_from_heap(). A requirement is that InnoDB is able to start a scan like this: rnd_init, rnd_pos(some PK value), rnd_next.
thd | Thread handler |
tl | Table reference wanting the copy |
void Common_table_expr::remove_table | ( | Table_ref * | tr | ) |
Remove one table reference.
bool Common_table_expr::substitute_recursive_reference | ( | THD * | thd, |
Query_block * | sl | ||
) |
Replaces the recursive reference in query block 'sl' with a clone of the first tmp table.
thd | Thread handler |
sl | Query block |
LEX_STRING Common_table_expr::name |
Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
bool Common_table_expr::recursive |
True if it's a recursive CTE.
Mem_root_array<Table_ref *> Common_table_expr::references |
All references to this CTE in the statement, except those inside the query expression defining this CTE.
In other words, all non-recursive references.
Mem_root_array<Table_ref *> Common_table_expr::tmp_tables |
List of all TABLE_LISTSs reading/writing to the tmp table created to materialize this CTE.
Due to shared materialization, only the first one has a TABLE generated by create_tmp_table(); other ones have a TABLE generated by open_table_from_share().