MySQL  8.0.20
Source Code Documentation
sql_optimizer.h File Reference

Classes used for query optimizations. More...

#include <string.h>
#include <sys/types.h>
#include <memory>
#include <utility>
#include "field_types.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_table_map.h"
#include "sql/field.h"
#include "sql/item.h"
#include "sql/mem_root_array.h"
#include "sql/opt_explain_format.h"
#include "sql/row_iterator.h"
#include "sql/sql_array.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_opt_exec_shared.h"
#include "sql/sql_select.h"
#include "sql/table.h"
#include "sql/temp_table_param.h"

Go to the source code of this file.

Classes

struct  SARGABLE_PARAM
 
struct  ROLLUP
 
class  ORDER_with_src
 Wrapper for ORDER* pointer to trace origins of ORDER list. More...
 
struct  ORDER_with_src::null
 Private empty class to implement type-safe NULL assignment. More...
 
class  JOIN
 
class  Switch_ref_item_slice
 RAII class to ease the temporary switching to a different slice of the ref item array. More...
 
class  Prepare_error_tracker
 RAII class to ease the call of LEX::mark_broken() if error. More...
 
class  Deps_of_remaining_lateral_derived_tables
 RAII class to manage JOIN::deps_of_remaining_lateral_derived_tables. More...
 
class  Candidate_table_order
 Class which presents a view of the current candidate table order for a JOIN. More...
 

Macros

#define ASSERT_BEST_REF_IN_JOIN_ORDER(join)
 Use this in a function which depends on best_ref listing tables in the final join order. More...
 

Typedefs

typedef Bounds_checked_array< Item_null_result * > Item_null_array
 
typedef Mem_root_array< Key_useKey_use_array
 

Functions

bool uses_index_fields_only (Item *item, TABLE *tbl, uint keyno, bool other_tbls_ok)
 Check if given expression only uses fields covered by index keyno in the table tbl. More...
 
bool remove_eq_conds (THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
 Removes const and eq items. More...
 
bool optimize_cond (THD *thd, Item **conds, COND_EQUAL **cond_equal, mem_root_deque< TABLE_LIST *> *join_list, Item::cond_result *cond_value)
 Optimize conditions by. More...
 
Itemsubstitute_for_best_equal_field (THD *thd, Item *cond, COND_EQUAL *cond_equal, JOIN_TAB **table_join_idx)
 Substitute every field reference in a condition by the best equal field and eliminate all multiple equality predicates. More...
 
bool build_equal_items (THD *thd, Item *cond, Item **retcond, COND_EQUAL *inherited, bool do_inherit, mem_root_deque< TABLE_LIST *> *join_list, COND_EQUAL **cond_equal_ref)
 Build multiple equalities for a WHERE condition and all join conditions that inherit these multiple equalities. More...
 
bool is_indexed_agg_distinct (JOIN *join, List< Item_field > *out_args)
 Check for the presence of AGGFN(DISTINCT a) queries that may be subject to loose index scan. More...
 
Key_use_arraycreate_keyuse_for_table (THD *thd, uint keyparts, Item_field **fields, List< Item > outer_exprs)
 Create a keyuse array for a table with a primary key. More...
 
Item_fieldget_best_field (Item_field *item_field, COND_EQUAL *cond_equal)
 Get the best field substitution for a given field. More...
 
Itemmake_cond_for_table (THD *thd, Item *cond, table_map tables, table_map used_table, bool exclude_expensive_cond)
 Extract a condition that can be checked after reading given table. More...
 
uint build_bitmap_for_nested_joins (mem_root_deque< TABLE_LIST *> *join_list, uint first_unused)
 Assign each nested join structure a bit in nested_join_map. More...
 
ORDERcreate_order_from_distinct (THD *thd, Ref_item_array ref_item_array, ORDER *order_list, List< Item > &fields, bool skip_aggregates, bool convert_bit_fields_to_long, bool *all_order_by_fields_used)
 Create an order list that consists of all non-const fields and items. More...
 
bool field_time_cmp_date (const Field *f, const Item *v)
 Returns true if arguments are a temporal Field having no date, part and a temporal expression having a date part. More...
 
bool substitute_gc (THD *thd, SELECT_LEX *select_lex, Item *where_cond, ORDER *group_list, ORDER *order)
 Substitute all expressions in the WHERE condition and ORDER/GROUP lists that match generated columns (GC) expressions with GC fields, if any. More...
 
double calculate_subquery_executions (const Item_subselect *subquery, Opt_trace_context *trace)
 Estimates how many times a subquery will be executed as part of a query execution. More...
 
bool evaluate_during_optimization (const Item *item, const SELECT_LEX *select)
 Checks if an Item, which is constant for execution, can be evaluated during optimization. More...
 
Item_equalfind_item_equal (COND_EQUAL *cond_equal, const Item_field *item_field, bool *inherited_fl)
 Find the multiple equality predicate containing a field. More...
 

Variables

const char * antijoin_null_cond
 

Detailed Description

Classes used for query optimizations.

Macro Definition Documentation

◆ ASSERT_BEST_REF_IN_JOIN_ORDER

#define ASSERT_BEST_REF_IN_JOIN_ORDER (   join)
Value:
do { \
DBUG_ASSERT((join)->tables == 0 || \
((join)->best_ref && !(join)->join_tab)); \
} while (0)
std::string join(Container cont, const std::string &delim)
join elements of an container into a string seperated by a delimiter.
Definition: string.h:144

Use this in a function which depends on best_ref listing tables in the final join order.

If 'tables==0', one is not expected to consult best_ref cells, and best_ref may not even have been allocated.

Typedef Documentation

◆ Item_null_array

◆ Key_use_array

Function Documentation

◆ evaluate_during_optimization()

bool evaluate_during_optimization ( const Item item,
const SELECT_LEX select 
)

Checks if an Item, which is constant for execution, can be evaluated during optimization.

It cannot be evaluated if it contains a subquery and the OPTION_NO_SUBQUERY_DURING_OPTIMIZATION query option is active.

Parameters
itemthe Item to check
selectthe query block that contains the Item
Returns
false if this Item contains a subquery and subqueries cannot be evaluated during optimization, or true otherwise

◆ field_time_cmp_date()

bool field_time_cmp_date ( const Field f,
const Item v 
)
inline

Returns true if arguments are a temporal Field having no date, part and a temporal expression having a date part.

Parameters
fField
vExpression