MySQL 8.4.2
Source Code Documentation
sql_executor.h File Reference

Classes for query execution. More...

#include <sys/types.h>
#include <string>
#include <vector>
#include "my_alloc.h"
#include "my_inttypes.h"
#include "my_table_map.h"
#include "sql/sql_lex.h"
#include "sql/sql_opt_exec_shared.h"
#include "sql/table.h"
#include "sql/temp_table_param.h"

Go to the source code of this file.

Classes

struct  SJ_TMP_TABLE_TAB
 
class  SJ_TMP_TABLE
 
class  Semijoin_mat_exec
 Executor structure for the materialized semi-join info, which contains. More...
 
class  QEP_TAB
 
struct  PendingCondition
 
struct  PendingInvalidator
 Cache invalidator iterators we need to apply, but cannot yet due to outer joins. More...
 

Enumerations

enum  Copy_func_type : int {
  CFT_ALL , CFT_WF_FRAMING , CFT_WF_NON_FRAMING , CFT_WF_NEEDS_PARTITION_CARDINALITY ,
  CFT_WF_USES_ONLY_ONE_ROW , CFT_HAS_NO_WF , CFT_HAS_WF , CFT_WF ,
  CFT_FIELDS
}
 
enum  CallingContext { TOP_LEVEL , DIRECTLY_UNDER_SEMIJOIN , DIRECTLY_UNDER_OUTER_JOIN , DIRECTLY_UNDER_WEEDOUT }
 

Functions

void setup_tmptable_write_func (QEP_TAB *tab, Opt_trace_object *trace)
 Setup write_func of QEP_tmp_table object. More...
 
bool copy_fields (Temp_table_param *param, const THD *thd, bool reverse_copy=false)
 Make a copy of all simple SELECT'ed fields. More...
 
bool copy_funcs (Temp_table_param *, const THD *thd, Copy_func_type type=CFT_ALL)
 Copy result of functions to record in tmp_table. More...
 
bool construct_lookup (THD *thd, TABLE *table, Index_lookup *ref)
 Copy the lookup key into the table ref's key buffer. More...
 
int report_handler_error (TABLE *table, int error)
 Help function when we get some an error from the table handler. More...
 
int join_read_const_table (JOIN_TAB *tab, POSITION *pos)
 Reads content of constant table. More...
 
int do_sj_dups_weedout (THD *thd, SJ_TMP_TABLE *sjtbl)
 SemiJoinDuplicateElimination: Weed out duplicate row combinations. More...
 
int update_item_cache_if_changed (List< Cached_item > &list)
 
bool change_to_use_tmp_fields (mem_root_deque< Item * > *fields, THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *res_fields, size_t added_non_hidden_fields, bool windowing=false)
 Change all funcs and sum_funcs to fields in tmp table, and create new list of all items. More...
 
bool change_to_use_tmp_fields_except_sums (mem_root_deque< Item * > *fields, THD *thd, Query_block *select, Ref_item_array ref_item_array, mem_root_deque< Item * > *res_fields, size_t added_non_hidden_fields)
 Change all sum_func refs to fields to point at fields in tmp table. More...
 
bool prepare_sum_aggregators (Item_sum **func_ptr, bool need_distinct)
 
bool setup_sum_funcs (THD *thd, Item_sum **func_ptr)
 Call setup() for all sum functions. More...
 
bool make_group_fields (JOIN *main_join, JOIN *curr_join)
 allocate group fields or take prepared (cached). More...
 
bool check_unique_fields (TABLE *table)
 Check whether a row is already present in the tmp table. More...
 
ulonglong calc_row_hash (TABLE *table)
 Generate hash for unique_constraint for all visible fields of a table. More...
 
ulonglong calc_field_hash (const Field *field, ulonglong *hash)
 Generate hash for a field. More...
 
int read_const (TABLE *table, Index_lookup *ref)
 
bool table_rec_cmp (TABLE *table)
 Compare GROUP BY in from tmp table's record[0] and record[1]. More...
 
bool set_record_buffer (TABLE *table, double expected_rows_to_fetch)
 Allocate a data buffer that the storage engine can use for fetching batches of records. More...
 
void init_tmptable_sum_functions (Item_sum **func_ptr)
 
void update_tmptable_sum_func (Item_sum **func_ptr, TABLE *tmp_table)
 Update record 0 in tmp_table from record 1. More...
 
bool has_rollup_result (Item *item)
 Checks if an item has a ROLLUP NULL which needs to be written to temp table. More...
 
bool is_rollup_group_wrapper (const Item *item)
 
Itemunwrap_rollup_group (Item *item)
 
ItemCreateConjunction (List< Item > *items)
 Create an AND conjunction of all given items. More...
 
unique_ptr_destroy_only< RowIteratorPossiblyAttachFilterIterator (unique_ptr_destroy_only< RowIterator > iterator, const std::vector< Item * > &conditions, THD *thd)
 
void SplitConditions (Item *condition, QEP_TAB *current_table, std::vector< Item * > *predicates_below_join, std::vector< PendingCondition > *predicates_above_join, std::vector< PendingCondition > *join_conditions, plan_idx semi_join_table_idx, qep_tab_map left_tables)
 
AccessPathMoveCompositeIteratorsFromTablePath (THD *thd, AccessPath *path, const Query_block &query_block)
 For a MATERIALIZE access path, move any non-basic iterators (e.g. More...
 
AccessPathGetAccessPathForDerivedTable (THD *thd, Table_ref *table_ref, TABLE *table, bool rematerialize, Mem_root_array< const AccessPath * > *invalidators, bool need_rowid, AccessPath *table_path)
 
void ConvertItemsToCopy (const mem_root_deque< Item * > &items, Field **fields, Temp_table_param *param)
 For historical reasons, derived table materialization and temporary table materialization didn't specify the fields to materialize in the same way. More...
 
std::string RefToString (const Index_lookup &ref, const KEY &key, bool include_nulls)
 
bool MaterializeIsDoingDeduplication (TABLE *table)
 (end of group Query_Executor) More...
 
bool ExtractConditions (Item *condition, Mem_root_array< Item * > *condition_parts)
 Split AND conditions into their constituent parts, recursively. More...
 
AccessPathcreate_table_access_path (THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref, POSITION *position, bool count_examined_rows)
 create_table_access_path is used to scan by using a number of different methods. More...
 
unique_ptr_destroy_only< RowIteratorinit_table_iterator (THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref, POSITION *position, bool ignore_not_found_rows, bool count_examined_rows)
 Creates an iterator for the given table, then calls Init() on the resulting iterator. More...
 
unique_ptr_destroy_only< RowIteratorinit_table_iterator (THD *thd, TABLE *table, bool ignore_not_found_rows, bool count_examined_rows)
 A short form for when there's no range scan, recursive CTEs or cost information; just a unique_result or a simple table scan. More...
 
AccessPathConnectJoins (plan_idx upper_first_idx, plan_idx first_idx, plan_idx last_idx, QEP_TAB *qep_tabs, THD *thd, CallingContext calling_context, std::vector< PendingCondition > *pending_conditions, std::vector< PendingInvalidator > *pending_invalidators, std::vector< PendingCondition > *pending_join_conditions, qep_tab_map *unhandled_duplicates, table_map *conditions_depend_on_outer_tables)
 

Detailed Description

Classes for query execution.

Enumeration Type Documentation

◆ CallingContext

Enumerator
TOP_LEVEL 
DIRECTLY_UNDER_SEMIJOIN 
DIRECTLY_UNDER_OUTER_JOIN 
DIRECTLY_UNDER_WEEDOUT 

◆ Copy_func_type

enum Copy_func_type : int
Enumerator
CFT_ALL 

In non-windowing step, copies functions.

CFT_WF_FRAMING 

In windowing step, copies framing window function, including all grouping aggregates, e.g.

SUM, AVG and FIRST_VALUE, LAST_VALUE.

CFT_WF_NON_FRAMING 

In windowing step, copies non framing window function, e.g.

ROW_NUMBER, RANK, DENSE_RANK, except those that are two_pass cf. copy_two_pass_window_functions which are treated separately.

CFT_WF_NEEDS_PARTITION_CARDINALITY 

In windowing step, copies window functions that need frame cardinality, that is we need to read all rows of a partition before we can compute the wf's value for the the first row in the partition.

CFT_WF_USES_ONLY_ONE_ROW 

In windowing step, copies framing window functions that read only one row per frame.

CFT_HAS_NO_WF 

In first windowing step, copies non-window functions which do not rely on window functions, i.e.

those that have Item::has_wf() == false.

CFT_HAS_WF 

In final windowing step, copies all non-wf functions.

Must be called after all wfs have been evaluated, as non-wf functions may reference wf, e.g. 1+RANK.

CFT_WF 

Copies all window functions.

CFT_FIELDS 

Copies Item_field only (typically because other functions might depend on those fields).

Function Documentation

◆ ConnectJoins()

AccessPath * ConnectJoins ( plan_idx  upper_first_idx,
plan_idx  first_idx,
plan_idx  last_idx,
QEP_TAB qep_tabs,
THD thd,
CallingContext  calling_context,
std::vector< PendingCondition > *  pending_conditions,
std::vector< PendingInvalidator > *  pending_invalidators,
std::vector< PendingCondition > *  pending_join_conditions,
qep_tab_map unhandled_duplicates,
table_map conditions_depend_on_outer_tables 
)

◆ create_table_access_path()

AccessPath * create_table_access_path ( THD thd,
TABLE table,
AccessPath range_scan,
Table_ref table_ref,
POSITION position,
bool  count_examined_rows 
)

create_table_access_path is used to scan by using a number of different methods.

Which method to use is set-up in this call so that you can create an iterator from the returned access path and fetch rows through said iterator afterwards.

Parameters
thdThread handle
tableTable the data [originally] comes from
range_scanAccessPath to scan the table with, or nullptr
table_refPosition for the table, must be non-nullptr for WITH RECURSIVE
positionPlace to get cost information from, or nullptr
count_examined_rowsSee AccessPath::count_examined_rows.

◆ init_table_iterator() [1/2]

unique_ptr_destroy_only< RowIterator > init_table_iterator ( THD thd,
TABLE table,
AccessPath range_scan,
Table_ref table_ref,
POSITION position,
bool  ignore_not_found_rows,
bool  count_examined_rows 
)

Creates an iterator for the given table, then calls Init() on the resulting iterator.

Unlike create_table_iterator(), this can create iterators for sort buffer results (which are set in the TABLE object during query execution). Returns nullptr on failure.

◆ init_table_iterator() [2/2]

unique_ptr_destroy_only< RowIterator > init_table_iterator ( THD thd,
TABLE table,
bool  ignore_not_found_rows,
bool  count_examined_rows 
)
inline

A short form for when there's no range scan, recursive CTEs or cost information; just a unique_result or a simple table scan.

Normally, you should prefer just instantiating an iterator yourself – this is for legacy use only.

◆ MaterializeIsDoingDeduplication()

bool MaterializeIsDoingDeduplication ( TABLE table)

(end of group Query_Executor)

◆ PossiblyAttachFilterIterator()

unique_ptr_destroy_only< RowIterator > PossiblyAttachFilterIterator ( unique_ptr_destroy_only< RowIterator iterator,
const std::vector< Item * > &  conditions,
THD thd 
)

◆ SplitConditions()

void SplitConditions ( Item condition,
QEP_TAB current_table,
std::vector< Item * > *  predicates_below_join,
std::vector< PendingCondition > *  predicates_above_join,
std::vector< PendingCondition > *  join_conditions,
plan_idx  semi_join_table_idx,
qep_tab_map  left_tables 
)