MySQL  8.0.17
Source Code Documentation
sql_select.cc File Reference

Evaluate query expressions, throughout resolving, optimization and execution. More...

#include "sql/sql_select.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <atomic>
#include <memory>
#include <new>
#include <vector>
#include "lex_string.h"
#include "limits.h"
#include "my_alloc.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_macros.h"
#include "my_pointer_arithmetic.h"
#include "my_sys.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/composite_iterators.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/enum_query_type.h"
#include "sql/error_handler.h"
#include "sql/filesort.h"
#include "sql/handler.h"
#include "sql/item_func.h"
#include "sql/item_json_func.h"
#include "sql/item_subselect.h"
#include "sql/item_sum.h"
#include "sql/key.h"
#include "sql/key_spec.h"
#include "sql/lock.h"
#include "sql/my_decimal.h"
#include "sql/mysqld.h"
#include "sql/nested_join.h"
#include "sql/opt_explain.h"
#include "sql/opt_explain_format.h"
#include "sql/opt_hints.h"
#include "sql/opt_range.h"
#include "sql/opt_trace.h"
#include "sql/query_options.h"
#include "sql/query_result.h"
#include "sql/records.h"
#include "sql/row_iterator.h"
#include "sql/set_var.h"
#include "sql/sorting_iterator.h"
#include "sql/sql_base.h"
#include "sql/sql_cmd.h"
#include "sql/sql_do.h"
#include "sql/sql_executor.h"
#include "sql/sql_join_buffer.h"
#include "sql/sql_list.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_planner.h"
#include "sql/sql_show.h"
#include "sql/sql_test.h"
#include "sql/sql_timer.h"
#include "sql/sql_tmp_table.h"
#include "sql/temp_table_param.h"
#include "sql/window.h"
#include "template_utils.h"
#include "thr_lock.h"

Functions

static store_keyget_store_key (THD *thd, Key_use *keyuse, table_map used_tables, KEY_PART_INFO *key_part, uchar *key_buff, uint maybe_null)
 
static uint actual_key_flags (KEY *key_info)
 Returns key flags depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag. More...
 
bool const_expression_in_where (Item *conds, Item *item, Item **comp_item)
 
bool handle_query (THD *thd, LEX *lex, Query_result *result, ulonglong added_options, ulonglong removed_options)
 Handle data manipulation query which is not represented by Sql_cmd_dml class. More...
 
static ulong get_max_execution_time (THD *thd)
 Get the maximum execution time for a statement. More...
 
static bool is_timer_applicable_to_statement (THD *thd)
 Check whether max statement time is applicable to statement or not. More...
 
bool set_statement_timer (THD *thd)
 Set the time until the currently running statement is aborted. More...
 
void reset_statement_timer (THD *thd)
 Deactivate the timer associated with the statement that was executed. More...
 
static bool reads_not_secondary_columns (const LEX *lex)
 Checks if a query reads a column that is not available in the secondary engine (i.e. More...
 
static bool validate_use_secondary_engine (const LEX *lex)
 Validates a query that uses the secondary engine. More...
 
static double accumulate_statement_cost (const LEX *lex)
 Calculates the cost of executing a statement, including all its subqueries. More...
 
static bool retry_with_secondary_engine (const THD *thd)
 Checks if a query should be retried using a secondary storage engine. More...
 
static bool optimize_secondary_engine (THD *thd)
 Perform query optimizations that are specific to a secondary storage engine. More...
 
static bool check_locking_clause_access (THD *thd, Global_tables_list tables)
 Performs access check for the locking clause, if present. More...
 
bool types_allow_materialization (Item *outer, Item *inner)
 Check if two items are compatible wrt. More...
 
static bool sj_table_is_included (JOIN *join, JOIN_TAB *join_tab)
 
SJ_TMP_TABLEcreate_sj_tmp_table (THD *thd, JOIN *join, SJ_TMP_TABLE::TAB *first_tab, SJ_TMP_TABLE::TAB *last_tab)
 Set up the support structures (NULL bits, row offsets, etc.) for a semijoin duplicate weedout table. More...
 
static bool setup_semijoin_dups_elimination (JOIN *join, uint no_jbuf_after)
 Setup the strategies to eliminate semi-join duplicates. More...
 
static void destroy_sj_tmp_tables (JOIN *join)
 
static int clear_sj_tmp_tables (JOIN *join)
 Remove all rows from all temp tables used by NL-semijoin runtime. More...
 
void calc_used_field_length (TABLE *table, bool keep_current_rowid, uint *p_used_fields, uint *p_used_fieldlength, uint *p_used_blobs, bool *p_used_null_fields, bool *p_used_uneven_bit_fields)
 Find how much space the prevous read not const tables takes in cache. More...
 
void calc_length_and_keyparts (Key_use *keyuse, JOIN_TAB *tab, const uint key, table_map used_tables, Key_use **chosen_keyuses, uint *length_out, uint *keyparts_out, table_map *dep_map, bool *maybe_null)
 Calculate properties of ref key: key length, number of used key parts, dependency map, possibility of null. More...
 
bool create_ref_for_key (JOIN *join, JOIN_TAB *j, Key_use *org_keyuse, table_map used_tables)
 Setup a ref access for looking up rows via an index (a key). More...
 
bool and_conditions (Item **e1, Item *e2)
 Extend e1 by AND'ing e2 to the condition e1 points to. More...
 
static Itemmake_cond_for_index (Item *cond, TABLE *table, uint keyno, bool other_tbls_ok)
 
static Itemmake_cond_remainder (Item *cond, bool exclude_index)
 
bool make_join_readinfo (JOIN *join, uint no_jbuf_after)
 Plan refinement stage: do various setup things for the executor. More...
 
bool error_if_full_join (JOIN *join)
 Give error if we some tables are done with a full join. More...
 
ORDERsimple_remove_const (ORDER *order, Item *where)
 Filter out ORDER items those are equal to constants in WHERE. More...
 
static bool test_if_equality_guarantees_uniqueness (Item *l, Item *r)
 
static bool equal (Item *i1, Item *i2, Field *f2)
 
bool const_expression_in_where (Item *cond, Item *comp_item, Field *comp_field, Item **const_item)
 Test if a field or an item is equal to a constant value in WHERE. More...
 
void count_field_types (SELECT_LEX *select_lex, Temp_table_param *param, List< Item > &fields, bool reset_with_sum_func, bool save_sum_fields)
 Update TMP_TABLE_PARAM with count of the different type of fields. More...
 
bool test_if_subpart (ORDER *a, ORDER *b)
 Return 1 if second is a subpart of first argument. More...
 
void calc_group_buffer (JOIN *join, ORDER *group)
 calc how big buffer we need for comparing group entries. More...
 
void free_underlaid_joins (THD *thd, SELECT_LEX *select)
 Free joins of subselect of this select. More...
 
bool test_if_cheaper_ordering (const JOIN_TAB *tab, ORDER_with_src *order, TABLE *table, Key_map usable_keys, int ref_key, ha_rows select_limit, int *new_key, int *new_key_direction, ha_rows *new_select_limit, uint *new_used_key_parts, uint *saved_best_key_parts)
 Find a cheaper access key than a given key. More...
 
uint get_index_for_order (ORDER_with_src *order, QEP_TAB *tab, ha_rows limit, bool *need_sort, bool *reverse)
 Find a key to apply single table UPDATE/DELETE by a given ORDER. More...
 
uint actual_key_parts (const KEY *key_info)
 Returns number of key parts depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag. More...
 
join_type calc_join_type (int quick_type)
 

Detailed Description

Evaluate query expressions, throughout resolving, optimization and execution.