![]() |
MySQL
8.0.23
Source Code Documentation
|
Query execution. More...
#include "sql/sql_executor.h"
#include <algorithm>
#include <atomic>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <map>
#include <memory>
#include <new>
#include <string>
#include <utility>
#include <vector>
#include "field_types.h"
#include "lex_string.h"
#include "m_ctype.h"
#include "mem_root_allocator.h"
#include "mem_root_deque.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bit.h"
#include "my_bitmap.h"
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_loglevel.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_table_map.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/basic_row_iterators.h"
#include "sql/bka_iterator.h"
#include "sql/composite_iterators.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/enum_query_type.h"
#include "sql/field.h"
#include "sql/filesort.h"
#include "sql/handler.h"
#include "sql/hash_join_iterator.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/item_sum.h"
#include "sql/join_optimizer/access_path.h"
#include "sql/join_optimizer/bit_utils.h"
#include "sql/join_type.h"
#include "sql/json_dom.h"
#include "sql/key.h"
#include "sql/key_spec.h"
#include "sql/mem_root_array.h"
#include "sql/mysqld.h"
#include "sql/nested_join.h"
#include "sql/opt_costmodel.h"
#include "sql/opt_explain_format.h"
#include "sql/opt_range.h"
#include "sql/opt_trace.h"
#include "sql/opt_trace_context.h"
#include "sql/parse_tree_nodes.h"
#include "sql/query_options.h"
#include "sql/record_buffer.h"
#include "sql/records.h"
#include "sql/ref_row_iterators.h"
#include "sql/row_iterator.h"
#include "sql/sort_param.h"
#include "sql/sorting_iterator.h"
#include "sql/sql_array.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_join_buffer.h"
#include "sql/sql_list.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_resolver.h"
#include "sql/sql_select.h"
#include "sql/sql_tmp_table.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/temp_table_param.h"
#include "sql/timing_iterator.h"
#include "sql/window.h"
#include "sql/window_lex.h"
#include "sql_string.h"
#include "tables_contained_in.h"
#include "template_utils.h"
#include "thr_lock.h"
Classes | |
struct | PendingInvalidator |
Similar to PendingCondition, but for cache invalidator iterators. More... | |
Functions | |
static int | read_system (TABLE *table) |
Read a constant table when there is at most one matching row, using a table scan. More... | |
static int | read_const (TABLE *table, TABLE_REF *ref) |
static bool | alloc_group_fields (JOIN *join, ORDER *group) |
Get a list of buffers for saveing last group. More... | |
static pair< uchar *, key_part_map > | FindKeyBufferAndMap (const TABLE_REF *ref) |
string | RefToString (const TABLE_REF &ref, const KEY *key, bool include_nulls) |
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 (Item *item) |
bool | is_rollup_sum_wrapper (Item *item) |
Item * | unwrap_rollup_group (Item *item) |
bool | prepare_sum_aggregators (Item_sum **sum_funcs, bool need_distinct) |
bool | setup_sum_funcs (THD *thd, Item_sum **func_ptr) |
Call setup() for all sum functions. 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 | copy_funcs (Temp_table_param *param, const THD *thd, Copy_func_type type) |
Copy result of functions to record in tmp_table. More... | |
static bool | update_const_equal_items (THD *thd, Item *cond, JOIN_TAB *tab) |
Check appearance of new constant items in multiple equalities of a condition after reading a constant table. More... | |
void | setup_tmptable_write_func (QEP_TAB *tab, Opt_trace_object *trace) |
Setup write_func of QEP_tmp_table object. More... | |
static size_t | record_prefix_size (const TABLE *table) |
Find out how many bytes it takes to store the smallest prefix which covers all the columns that will be read from a table. 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 | ExtractConditions (Item *condition, Mem_root_array< Item * > *condition_parts) |
Split AND conditions into their constituent parts, recursively. More... | |
AccessPath * | PossiblyAttachFilter (AccessPath *path, const vector< Item * > &conditions, THD *thd, table_map *conditions_depend_on_outer_tables) |
Return a new iterator that wraps "iterator" and that tests all of the given conditions (if any), ANDed together. More... | |
AccessPath * | CreateNestedLoopAccessPath (THD *thd, AccessPath *outer, AccessPath *inner, JoinType join_type, bool pfs_batch_mode) |
static AccessPath * | NewInvalidatorAccessPathForTable (THD *thd, AccessPath *path, QEP_TAB *qep_tab) |
static table_map | ConvertQepTabMapToTableMap (JOIN *join, qep_tab_map tables) |
AccessPath * | CreateBKAAccessPath (THD *thd, JOIN *join, AccessPath *outer_path, qep_tab_map left_tables, AccessPath *inner_path, qep_tab_map right_tables, TABLE *table, TABLE_LIST *table_list, TABLE_REF *ref, JoinType join_type) |
static AccessPath * | PossiblyAttachFilter (AccessPath *path, const vector< PendingCondition > &conditions, THD *thd, table_map *conditions_depend_on_outer_tables) |
static Item_func_trig_cond * | GetTriggerCondOrNull (Item *item) |
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... | |
static bool | IsJoinCondition (const Item *item, const QEP_TAB *qep_tab) |
static Item * | GetInnermostCondition (Item *item) |
void | SplitConditions (Item *condition, QEP_TAB *current_table, vector< Item * > *predicates_below_join, vector< PendingCondition > *predicates_above_join, vector< PendingCondition > *join_conditions) |
static void | MarkUnhandledDuplicates (SJ_TMP_TABLE *weedout, plan_idx weedout_start, plan_idx weedout_end, qep_tab_map *unhandled_duplicates) |
For a given duplicate weedout operation, figure out which tables are supposed to be deduplicated by it, and add those to unhandled_duplicates. More... | |
static AccessPath * | CreateWeedoutOrLimitAccessPath (THD *thd, AccessPath *path, SJ_TMP_TABLE *weedout_table) |
static AccessPath * | NewWeedoutAccessPathForTables (THD *thd, const qep_tab_map tables_to_deduplicate, QEP_TAB *qep_tabs, uint primary_tables, AccessPath *path) |
static Substructure | FindSubstructure (QEP_TAB *qep_tabs, const plan_idx first_idx, const plan_idx this_idx, const plan_idx last_idx, CallingContext calling_context, bool *add_limit_1, plan_idx *substructure_end, qep_tab_map *unhandled_duplicates) |
Given a range of tables (where we assume that we've already handled first_idx..(this_idx-1) as inner joins), figure out whether this is a semijoin, an outer join or a weedout. More... | |
static bool | IsTableScan (AccessPath *path) |
AccessPath * | GetAccessPathForDerivedTable (THD *thd, QEP_TAB *qep_tab, AccessPath *table_path) |
AccessPath * | GetAccessPathForDerivedTable (THD *thd, TABLE_LIST *table_ref, TABLE *table, bool rematerialize, Mem_root_array< const AccessPath * > *invalidators, AccessPath *table_path) |
AccessPath * | GetTableAccessPath (THD *thd, QEP_TAB *qep_tab, QEP_TAB *qep_tabs) |
Get the RowIterator used for scanning the given table, with any required materialization operations done first. More... | |
void | SetCostOnTableAccessPath (const Cost_model_server &cost_model, const POSITION *pos, bool is_after_filter, AccessPath *path) |
void | SetCostOnNestedLoopAccessPath (const Cost_model_server &cost_model, const POSITION *pos_inner, AccessPath *path) |
void | SetCostOnHashJoinAccessPath (const Cost_model_server &cost_model, const POSITION *pos_outer, AccessPath *path) |
static bool | ConditionIsAlwaysTrue (Item *item) |
static bool | ItemRefersToOneSideOnly (Item *item, table_map left_side, table_map right_side) |
static AccessPath * | CreateHashJoinAccessPath (THD *thd, QEP_TAB *qep_tab, AccessPath *build_path, qep_tab_map build_tables, AccessPath *probe_path, qep_tab_map probe_tables, JoinType join_type, vector< Item * > *join_conditions, table_map *conditions_depend_on_outer_tables) |
static void | ExtractJoinConditions (const QEP_TAB *current_table, vector< Item * > *predicates, vector< Item * > *join_conditions) |
static bool | SubtreeHasIncompletePushedJoin (JOIN *join, qep_tab_map subtree) |
static bool | PushedJoinRejectsHashJoin (JOIN *join, qep_tab_map left_subtree, qep_tab_map right_subtree, JoinType join_type) |
static bool | UseHashJoin (QEP_TAB *qep_tab) |
static bool | UseBKA (QEP_TAB *qep_tab) |
static bool | QueryMixesOuterBKAAndBNL (JOIN *join) |
static bool | InsideOuterOrAntiJoin (QEP_TAB *qep_tab) |
template<class T > | |
void | PickOutConditionsForTableIndex (int table_idx, vector< T > *from, vector< T > *to) |
void | PickOutConditionsForTableIndex (int table_idx, vector< PendingCondition > *from, vector< Item * > *to) |
AccessPath * | FinishPendingOperations (THD *thd, AccessPath *path, QEP_TAB *remove_duplicates_loose_scan_qep_tab, const vector< PendingCondition > &pending_conditions, const vector< PendingInvalidator > &pending_invalidators, table_map *conditions_depend_on_outer_tables) |
static AccessPath * | ConnectJoins (plan_idx upper_first_idx, plan_idx first_idx, plan_idx last_idx, QEP_TAB *qep_tabs, THD *thd, CallingContext calling_context, vector< PendingCondition > *pending_conditions, vector< PendingInvalidator > *pending_invalidators, vector< PendingCondition > *pending_join_conditions, qep_tab_map *unhandled_duplicates, table_map *conditions_depend_on_outer_tables) |
For a given slice of the table list, build up the iterator tree corresponding to the tables in that slice. More... | |
int | do_sj_dups_weedout (THD *thd, SJ_TMP_TABLE *sjtbl) |
SemiJoinDuplicateElimination: Weed out duplicate row combinations. More... | |
int | report_handler_error (TABLE *table, int error) |
Help function when we get some an error from the table handler. More... | |
static bool | init_index (TABLE *table, handler *file, uint idx, bool sorted) |
Initialize an index scan. More... | |
int | safe_index_read (QEP_TAB *tab) |
int | join_read_const_table (JOIN_TAB *tab, POSITION *pos) |
Reads content of constant table. More... | |
ulonglong | get_exact_record_count (QEP_TAB *qep_tab, uint table_count, int *error) |
Get exact count of rows in all tables. More... | |
static bool | cmp_field_value (Field *field, ptrdiff_t diff) |
static bool | group_rec_cmp (ORDER *group, uchar *rec0, uchar *rec1) |
Compare GROUP BY in from tmp table's record[0] and record[1]. More... | |
static bool | table_rec_cmp (TABLE *table) |
Compare GROUP BY in from tmp table's record[0] and record[1]. More... | |
ulonglong | unique_hash (const Field *field, ulonglong *hash_val) |
Generate hash for a field. More... | |
static ulonglong | unique_hash_group (ORDER *group) |
Generate hash for unique constraint according to group-by list. More... | |
static ulonglong | unique_hash_fields (TABLE *table) |
bool | check_unique_constraint (TABLE *table) |
Check unique_constraint. More... | |
static void | reset_wf_states (Func_ptr_array *func_ptr, bool framing) |
Minion for reset_framing_wf_states and reset_non_framing_wf_state, q.v. More... | |
static void | reset_framing_wf_states (Func_ptr_array *func_ptr) |
Walk the function calls and reset any framing window function's window state. More... | |
static void | reset_non_framing_wf_state (Func_ptr_array *func_ptr) |
Walk the function calls and reset any non-framing window function's window state. More... | |
static bool | buffer_record_somewhere (THD *thd, Window *w, int64 rowno) |
Save a window frame buffer to frame buffer temporary table. 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... | |
static bool | read_frame_buffer_row (int64 rowno, Window *w, bool for_nth_value) |
Read row rowno from frame buffer tmp file using cached row positions to minimize positioning work. More... | |
static void | dbug_allow_write_all_columns (Temp_table_param *param, std::map< TABLE *, my_bitmap_map * > &map) |
static void | dbug_restore_all_columns (std::map< TABLE *, my_bitmap_map * > &map) |
bool | bring_back_frame_row (THD *thd, Window *w, Temp_table_param *out_param, int64 rowno, Window_retrieve_cached_row_reason reason, int fno) |
Bring back buffered data to the record of qep_tab-1 [1], and optionally execute copy_fields() to the OUT table. More... | |
static bool | process_wfs_needing_card (THD *thd, Temp_table_param *param, const Window::st_nth &have_nth_value, const Window::st_lead_lag &have_lead_lag, const int64 current_row, Window *w, Window_retrieve_cached_row_reason current_row_reason) |
Process window functions that need partition cardinality. More... | |
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 | construct_lookup_ref (THD *thd, TABLE *table, TABLE_REF *ref) |
Copy the lookup key into the table ref's key buffer. More... | |
bool | make_group_fields (JOIN *main_join, JOIN *curr_join) |
allocate group fields or take prepared (cached). More... | |
int | update_item_cache_if_changed (List< Cached_item > &list) |
bool | copy_fields (Temp_table_param *param, const THD *thd, bool reverse_copy) |
Make a copy of all simple SELECT'ed fields. More... | |
bool | copy_fields_and_funcs (Temp_table_param *param, const THD *thd, Copy_func_type type) |
static bool | replace_embedded_rollup_references_with_tmp_fields (THD *thd, Item *item, mem_root_deque< Item * > *fields) |
For each rollup wrapper below the given item, replace it with a temporary field, e.g. More... | |
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) |
Change all funcs and sum_funcs to fields in tmp table, and create new list of all items. More... | |
static bool | replace_contents_of_rollup_wrappers_with_tmp_fields (THD *thd, SELECT_LEX *select, Item *item_arg) |
For each rollup wrapper below the given item, replace its argument with a temporary field, e.g. More... | |
bool | change_to_use_tmp_fields_except_sums (mem_root_deque< Item * > *fields, THD *thd, SELECT_LEX *select, Ref_item_array ref_item_array, mem_root_deque< Item * > *res_fields) |
Change all sum_func refs to fields to point at fields in tmp table. More... | |
bool | MaterializeIsDoingDeduplication (TABLE *table) |
Variables | |
static constexpr size_t | MAX_RECORD_BUFFER_SIZE = 128 * 1024 |
Maximum amount of space (in bytes) to allocate for a Record_buffer. More... | |
Query execution.