MySQL  8.0.18
Source Code Documentation
sql_executor.h File Reference

Classes for query execution. More...

#include <string.h>
#include <sys/types.h>
#include "my_base.h"
#include "my_compiler.h"
#include "my_inttypes.h"
#include "sql/item.h"
#include "sql/row_iterator.h"
#include "sql/sql_class.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

class  List< T >
 
class  SJ_TMP_TABLE
 
class  SJ_TMP_TABLE::TAB
 
class  Semijoin_mat_exec
 
Executor structure for the materialized semi-join info, which contains More...
 
class  QEP_operation
 QEP_operation is an interface class for operations in query execution plan. More...
 
class  QEP_tmp_table
 Class for accumulating join result in a tmp table, grouping them if necessary, and sending further. More...
 
class  QEP_TAB
 
class  QEP_TAB_standalone
 Use this class when you need a QEP_TAB not connected to any JOIN_TAB. More...
 
struct  PendingCondition
 

Macros

#define QEP_AT(qtab, member)   (qtab->join()->qep_tab[qtab->member])
 

Typedefs

typedef enum_nested_loop_state(* Next_select_func) (JOIN *, class QEP_TAB *, bool)
 

Enumerations

enum  enum_nested_loop_state {
  NESTED_LOOP_KILLED = -2, NESTED_LOOP_ERROR = -1, NESTED_LOOP_OK = 0, NESTED_LOOP_QUERY_LIMIT = 3,
  NESTED_LOOP_CURSOR_LIMIT = 4
}
 Possible status of a "nested loop" operation (Next_select_func family of functions). More...
 
enum  Copy_func_type {
  CFT_ALL, CFT_WF_FRAMING, CFT_WF_NON_FRAMING, CFT_WF_NEEDS_CARD,
  CFT_WF_USES_ONLY_ONE_ROW, CFT_HAS_NO_WF, CFT_HAS_WF, CFT_WF,
  CFT_DEPENDING_ON_AGGREGATE
}
 

Functions

void setup_tmptable_write_func (QEP_TAB *tab, Opt_trace_object *trace)
 Setup write_func of QEP_tmp_table object. More...
 
enum_nested_loop_state sub_select_op (JOIN *join, QEP_TAB *qep_tab, bool end_of_records)
 Accumulate full or partial join result in operation and send operation's result further. More...
 
enum_nested_loop_state end_send_group (JOIN *join, QEP_TAB *qep_tab, bool end_of_records)
 
enum_nested_loop_state end_write_group (JOIN *join, QEP_TAB *qep_tab, bool end_of_records)
 
enum_nested_loop_state sub_select (JOIN *join, QEP_TAB *qep_tab, bool end_of_records)
 Retrieve records ends with a given beginning from the result of a join. More...
 
enum_nested_loop_state evaluate_join_record (JOIN *join, QEP_TAB *qep_tab, int error)
 
enum_nested_loop_state end_send_count (JOIN *join, QEP_TAB *qep_tab)
 
bool copy_fields (Temp_table_param *param, const THD *thd)
 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 copy_fields_and_funcs (Temp_table_param *param, const THD *thd, Copy_func_type type=CFT_ALL)
 
bool cp_buffer_from_ref (THD *thd, TABLE *table, TABLE_REF *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 safe_index_read (QEP_TAB *tab)
 
int join_read_const_table (JOIN_TAB *tab, POSITION *pos)
 Reads content of constant table. More...
 
void join_setup_iterator (QEP_TAB *tab)
 Prepare table for reading rows and read first record. More...
 
int join_materialize_derived (QEP_TAB *tab)
 
int join_materialize_table_function (QEP_TAB *tab)
 
int join_materialize_semijoin (QEP_TAB *tab)
 
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 (List< Item > &all_fields, size_t num_select_elements, THD *thd, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_fields)
 Change all funcs and sum_funcs to fields in tmp table, and create new list of all items. More...
 
bool change_refs_to_tmp_fields (List< Item > &all_fields, size_t num_select_elements, THD *thd, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_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 setup_copy_fields (List< Item > &all_fields, size_t num_select_elements, THD *thd, Temp_table_param *param, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_fields)
 Sets up caches for holding the values of non-aggregated expressions. More...
 
bool check_unique_constraint (TABLE *table)
 Check unique_constraint. More...
 
ulonglong unique_hash (Field *field, ulonglong *hash)
 Generate hash for a field. More...
 
void copy_sum_funcs (Item_sum **func_ptr, Item_sum **end_ptr)
 Copy result of sum functions to record in tmp_table. More...
 
bool set_record_buffer (const QEP_TAB *tab)
 Allocate a data buffer that the storage engine can use for fetching batches of records. More...
 
bool init_sum_functions (Item_sum **func_ptr, Item_sum **end_ptr)
 
void init_tmptable_sum_functions (Item_sum **func_ptr)
 
bool update_sum_func (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...
 
unique_ptr_destroy_only< RowIteratorPossiblyAttachFilterIterator (unique_ptr_destroy_only< RowIterator > iterator, const std::vector< Item *> &conditions, THD *thd)
 Return a new iterator that wraps "iterator" and that tests all of the given conditions (if any), ANDed together. More...
 
void SplitConditions (Item *condition, std::vector< Item *> *predicates_below_join, std::vector< PendingCondition > *predicates_above_join)
 
bool process_buffered_windowing_record (THD *thd, Temp_table_param *param, const bool new_partition_or_eof, bool *output_row_ready)
 While there are more unprocessed rows ready to process given the current partition/frame state, process such buffered rows by evaluating/aggregating the window functions defined over this window on the current frame, moving the frame if required. More...
 
bool buffer_windowing_record (THD *thd, Temp_table_param *param, bool *new_partition)
 If we cannot evaluate all window functions for a window on the fly, buffer the current row for later processing by process_buffered_windowing_record. More...
 
bool bring_back_frame_row (THD *thd, Window &w, Temp_table_param *out_param, int64 rowno, enum Window::retrieve_cached_row_reason reason, int fno=0)
 Bring back buffered data to the record of qep_tab-1 [1], and optionally execute copy_fields() to the OUT table. More...
 
void ConvertItemsToCopy (List< Item > *items, Field **fields, Temp_table_param *param, JOIN *join)
 For historical reasons, derived table materialization and temporary table materialization didn't specify the fields to materialize in the same way. More...
 

Detailed Description

Classes for query execution.

Macro Definition Documentation

◆ QEP_AT

#define QEP_AT (   qtab,
  member 
)    (qtab->join()->qep_tab[qtab->member])
Returns
a pointer to the QEP_TAB whose index is qtab->member. For example, QEP_AT(x,first_inner) is the first_inner table of x.

Typedef Documentation

◆ Next_select_func

typedef enum_nested_loop_state(* Next_select_func) (JOIN *, class QEP_TAB *, bool)

Enumeration Type Documentation

◆ Copy_func_type

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_CARD 

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_DEPENDING_ON_AGGREGATE 

Copies all items that are expressions containing aggregates, but are not themselves aggregates.

Such expressions are typically split into their constituent parts during setup_fields(), such that the parts that are not aggregates are replaced by Item_refs that point into a slice. See AggregateIterator::Read() for more details.

◆ enum_nested_loop_state

Possible status of a "nested loop" operation (Next_select_func family of functions).

All values except NESTED_LOOP_OK abort the nested loop.

Enumerator
NESTED_LOOP_KILLED 

Thread shutdown was requested while processing the record.

NESTED_LOOP_ERROR 

A fatal error (like table corruption) was detected.

NESTED_LOOP_OK 

Record has been successfully handled.

NESTED_LOOP_QUERY_LIMIT 

Record has been successfully handled; additionally, the nested loop produced the number of rows specified in the LIMIT clause for the query.

NESTED_LOOP_CURSOR_LIMIT 

Record has been successfully handled; additionally, there is a cursor and the nested loop algorithm produced the number of rows that is specified for current cursor fetch operation.

Function Documentation

◆ evaluate_join_record()

enum_nested_loop_state evaluate_join_record ( JOIN join,
QEP_TAB qep_tab,
int  error 
)