1#ifndef SQL_OPTIMIZER_INCLUDED
2#define SQL_OPTIMIZER_INCLUDED
612 bool optimize(
bool finalize_access_paths);
618 bool before_group_by,
bool recompute =
false);
629 assert(dst_arr.
size() >= src_arr.
size());
630 void *dest = dst_arr.
array();
631 const void *src = src_arr.
array();
653 assert((
int)sliceno >= 1);
656 DBUG_PRINT(
"info", (
"JOIN %p ref slice %u -> %u",
this,
710 Item *join_cond,
bool is_sj_mat_cond);
715 bool sort_before_group);
841 bool save_sum_fields);
867 tab->key_dependent = tab->dependent;
1034#define ASSERT_BEST_REF_IN_JOIN_ORDER(join) \
1036 assert((join)->tables == 0 || ((join)->best_ref && !(join)->join_tab)); \
1056 bool other_tbls_ok);
1076 table_map used_table,
bool exclude_expensive_cond);
1093 bool skip_aggregates,
1094 bool convert_bit_fields_to_long,
1095 bool *all_order_by_fields_used);
1185 const Item_field *item_field,
bool *inherited_fl);
1194 double table_scan_cost);
bool is_null() const
Definition: sql_array.h:134
Element_type * array() const
Definition: sql_array.h:142
size_t size() const
Definition: sql_array.h:131
size_t element_size() const
Definition: sql_array.h:130
Definition: item_cmpfunc.h:2633
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:51
virtual enum_field_types type() const =0
Definition: item_cmpfunc.h:2495
Definition: item_subselect.h:79
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:398
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
bool is_temporal_with_date() const
Definition: item.h:3018
cond_result
Definition: item.h:871
@ COND_FALSE
Definition: item.h:871
Query optimization plan node.
Definition: sql_select.h:598
Definition: sql_optimizer.h:125
const Cost_model_server * cost_model() const
Retrieve the cost model object to be used for this join.
Definition: sql_optimizer.cc:11095
bool skip_sort_order
Is set if we have a GROUP BY and we have ORDER BY on a constant or when sorting isn't required.
Definition: sql_optimizer.h:395
bool attach_join_condition_to_nest(plan_idx first_inner, plan_idx last_tab, Item *join_cond, bool is_sj_mat_cond)
Helper for JOIN::attach_join_conditions().
Definition: sql_optimizer.cc:8448
void set_root_access_path(AccessPath *path)
Definition: sql_optimizer.h:769
bool calc_found_rows
If true, calculate found rows for this query block.
Definition: sql_optimizer.h:592
bool plan_is_single_table()
True if plan contains one non-const primary table (ie not including tables taking part in semi-join m...
Definition: sql_optimizer.h:610
void mark_const_table(JOIN_TAB *table, Key_use *key)
Move const tables first in the position array.
Definition: sql_optimizer.cc:8279
JOIN_TAB * join_tab
Optimal query execution plan.
Definition: sql_optimizer.h:146
ha_rows fetch_limit
Used to fetch no more than given amount of rows per one fetch operation of server side cursor.
Definition: sql_optimizer.h:297
Item_sum ** sum_funcs
Definition: sql_optimizer.h:341
List< Cached_item > group_fields
Definition: sql_optimizer.h:335
bool m_windows_sort
True if a window requires a certain order of rows, which implies that any order of rows coming out of...
Definition: sql_optimizer.h:457
MYSQL_LOCK * lock
Definition: sql_optimizer.h:349
bool executed
Set by exec(), reset by reset().
Definition: sql_optimizer.h:806
QEP_TAB * qep_tab
Array of QEP_TABs.
Definition: sql_optimizer.h:148
bool send_row_on_empty_set() const
Return whether the caller should send a row even if the join produced no rows if:
Definition: sql_optimizer.h:697
ha_rows found_records
Definition: sql_optimizer.h:283
uint recursive_iteration_count
Used only if this query block is recursive.
Definition: sql_optimizer.h:558
void copy_ref_item_slice(Ref_item_array dst_arr, Ref_item_array src_arr)
Definition: sql_optimizer.h:628
bool child_subquery_can_materialize
True if, at this stage of processing, subquery materialization is allowed for children subqueries of ...
Definition: sql_optimizer.h:576
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
Definition: sql_optimizer.h:443
COND_EQUAL * cond_equal
Definition: sql_optimizer.h:509
JOIN_TAB ** map2table
mapping between table indexes and JOIN_TABs
Definition: sql_optimizer.h:158
ha_rows m_select_limit
Definition: sql_optimizer.h:287
POSITION * positions
Definition: sql_optimizer.h:309
uint current_ref_item_slice
The slice currently stored in ref_items[0].
Definition: sql_optimizer.h:551
bool is_executed() const
Definition: sql_optimizer.h:736
uint tables
Before plan has been created, "tables" denote number of input tables in the query block and "primary_...
Definition: sql_optimizer.h:207
bool has_lateral
If JOIN has lateral derived tables (is set at start of planning)
Definition: sql_optimizer.h:405
bool need_tmp_before_win
If true we need a temporary table on the result set before any windowing steps, e....
Definition: sql_optimizer.h:402
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
Definition: sql_optimizer.h:445
uint tmp_tables
Number of temporary tables used by query.
Definition: sql_optimizer.h:210
int error
set in optimize(), exec(), prepare_result()
Definition: sql_optimizer.h:427
bool plan_is_const() const
True if plan is const, ie it will return zero or one rows.
Definition: sql_optimizer.h:604
table_map const_table_map
Set of tables found to be const.
Definition: sql_optimizer.h:234
Prealloced_array< TemporaryTableToCleanup, 1 > temp_tables
Definition: sql_optimizer.h:176
Query_block *const query_block
Query block that is optimized and executed using this JOIN.
Definition: sql_optimizer.h:137
bool select_distinct
At construction time, set if SELECT DISTINCT.
Definition: sql_optimizer.h:359
RollupState
Definition: sql_optimizer.h:351
List< TABLE > sj_tmp_tables
Definition: sql_optimizer.h:585
table_map found_const_table_map
Const tables which are either:
Definition: sql_optimizer.h:241
bool simple_order
Definition: sql_optimizer.h:377
void set_executed()
Definition: sql_optimizer.h:737
List< Window > m_windows
Any window definitions.
Definition: sql_optimizer.h:451
Explain_format_flags explain_flags
Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN.
Definition: sql_optimizer.h:465
mem_root_deque< Item * > * tmp_fields
Array of pointers to lists of expressions.
Definition: sql_optimizer.h:425
uint const_tables
Number of primary tables deemed constant.
Definition: sql_optimizer.h:209
Prealloced_array< Filesort *, 1 > filesorts_to_cleanup
Definition: sql_optimizer.h:181
ha_rows examined_rows
Definition: sql_optimizer.h:284
ha_rows row_limit
Definition: sql_optimizer.h:285
bool allow_outer_refs
True if plan search is allowed to use references to expressions outer to this JOIN (for example may s...
Definition: sql_optimizer.h:582
JOIN_TAB ** best_ref
Array of plan operators representing the current (partial) best plan.
Definition: sql_optimizer.h:156
Item * having_for_explain
Saved optimized HAVING for EXPLAIN.
Definition: sql_optimizer.h:502
RollupState rollup_state
Definition: sql_optimizer.h:352
AccessPath * root_access_path() const
Definition: sql_optimizer.h:768
ha_rows send_records
Definition: sql_optimizer.h:282
Override_executor_func override_executor_func
Definition: sql_optimizer.h:318
plan_idx return_tab
Definition: sql_optimizer.h:517
enum_plan_state plan_state
Final execution plan state. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:809
Item * having_cond
Optimized HAVING clause item tree (valid for one single execution).
Definition: sql_optimizer.h:501
void make_outerjoin_info()
Fill in outer join related info for the execution plan structure.
Definition: sql_optimizer.cc:8308
TABLE_LIST * tables_list
Pointer set to query_block->get_table_list() at the start of optimization.
Definition: sql_optimizer.h:508
mem_root_deque< Item * > * fields
Definition: sql_optimizer.h:334
Temp_table_param tmp_table_param
Describes a temporary table.
Definition: sql_optimizer.h:348
bool select_count
Definition: sql_optimizer.h:819
@ ORDERED_INDEX_GROUP_BY
Definition: sql_optimizer.h:387
@ ORDERED_INDEX_VOID
Definition: sql_optimizer.h:386
@ ORDERED_INDEX_ORDER_BY
Definition: sql_optimizer.h:388
bool m_windowing_steps
If we have set up tmp tables for windowing,.
Definition: sql_optimizer.h:460
bool fts_index_access(JOIN_TAB *tab)
Check if FTS index only access is possible.
Definition: sql_optimizer.cc:10612
void optimize_keyuse()
Update some values in keyuse for faster choose_table_order() loop.
Definition: sql_optimizer.cc:10514
bool with_json_agg
This will force tmp table to NOT use index + update for group operation as it'll cause [de]serializat...
Definition: sql_optimizer.h:601
uint send_group_parts
Definition: sql_optimizer.h:211
bool finalize_table_conditions()
Remove redundant predicates and cache constant expressions.
Definition: sql_optimizer.cc:8902
AccessPath * m_root_access_path_no_in2exists
If this query block contains conditions synthesized during IN-to-EXISTS conversion: A second query pl...
Definition: sql_optimizer.h:1026
ORDER_with_src group_list
Definition: sql_optimizer.h:439
double sort_cost
Expected cost of filesort.
Definition: sql_optimizer.h:331
bool generate_derived_keys()
Add keys to derived tables'/views' result tables in a list.
Definition: sql_optimizer.cc:8979
bool optimize_fts_query()
Function sets FT hints, initializes FT handlers and checks if FT index can be used as covered.
Definition: sql_optimizer.cc:10553
enum_plan_state
State of execution plan. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:726
@ NO_TABLES
Plan has no tables.
Definition: sql_optimizer.h:729
@ NO_PLAN
No plan is ready yet.
Definition: sql_optimizer.h:727
@ ZERO_RESULT
Zero result cause is set.
Definition: sql_optimizer.h:728
@ PLAN_READY
Plan is ready.
Definition: sql_optimizer.h:730
Key_use_array keyuse_array
Used and updated by JOIN::make_join_plan() and optimize_keyuse()
Definition: sql_optimizer.h:408
bool group_sent
Exec time only: true <=> current group has been sent.
Definition: sql_optimizer.h:590
bool needs_finalize
Whether this query block needs finalization (see FinalizePlanForQueryBlock()) before it can be actual...
Definition: sql_optimizer.h:795
void init_key_dependencies()
Initialize key dependencies for join tables.
Definition: sql_optimizer.h:864
void set_ref_item_slice(uint sliceno)
Overwrite the base slice of ref_items with the slice supplied as argument.
Definition: sql_optimizer.h:652
List< Cached_item > group_fields_cache
Definition: sql_optimizer.h:336
bool streaming_aggregation
Indicates that the data will be aggregated (typically GROUP BY), and that it is already processed in ...
Definition: sql_optimizer.h:227
void set_optimized()
Definition: sql_optimizer.h:735
uint primary_tables
Number of primary input tables in query block.
Definition: sql_optimizer.h:208
bool optimize_rollup()
Optimize rollup specification.
Definition: sql_optimizer.cc:11052
THD *const thd
Thread handler.
Definition: sql_optimizer.h:139
table_map all_table_map
Set of tables contained in query.
Definition: sql_optimizer.h:233
bool attach_join_conditions(plan_idx last_tab)
Attach outer join conditions to generated table conditions in an optimal way.
Definition: sql_optimizer.cc:8559
bool decide_subquery_strategy()
Decides between EXISTS and materialization; performs last steps to set up the chosen strategy.
Definition: sql_optimizer.cc:10766
List< Semijoin_mat_exec > sjm_exec_list
Definition: sql_optimizer.h:586
JOIN(const JOIN &rhs)=delete
TABLE * sort_by_table
Definition: sql_optimizer.h:164
Ref_item_array * ref_items
ref_items is an array of 4+ slices, each containing an array of Item pointers.
Definition: sql_optimizer.h:543
bool do_send_rows
If true, send produced rows using query_result.
Definition: sql_optimizer.h:231
double windowing_cost
Expected cost of windowing;.
Definition: sql_optimizer.h:333
enum_plan_state get_plan_state() const
See enum_plan_state.
Definition: sql_optimizer.h:733
JOIN & operator=(const JOIN &rhs)=delete
ORDER_with_src order
ORDER BY and GROUP BY lists, to transform with prepare,optimize and exec.
Definition: sql_optimizer.h:439
bool group_optimized_away
If we have the GROUP BY statement in the query, but the group_list was emptied by optimizer,...
Definition: sql_optimizer.h:368
double best_read
The cost of best complete join plan found so far during optimization, after optimization phase - cost...
Definition: sql_optimizer.h:325
ORDER * remove_const(ORDER *first_order, Item *cond, bool change_list, bool *simple_order, bool group_by)
Remove all constants and check if ORDER only contains simple expressions.
Definition: sql_optimizer.cc:9886
enum JOIN::@171 ORDERED_INDEX_VOID
bool implicit_grouping
True if aggregated but no GROUP BY.
Definition: sql_optimizer.h:353
POSITION * best_positions
This is the result of join optimization.
Definition: sql_optimizer.h:304
void finalize_derived_keys()
For each materialized derived table/view, informs every TABLE of the key it will (not) use,...
Definition: sql_optimizer.cc:8999
bool optimized
flag to avoid double optimization in EXPLAIN
Definition: sql_optimizer.h:798
bool compare_costs_of_subquery_strategies(Subquery_strategy *method)
Tells what is the cheapest between IN->EXISTS and subquery materialization, in terms of cost,...
Definition: sql_optimizer.cc:10827
bool is_optimized() const
Definition: sql_optimizer.h:734
const char * zero_result_cause
<> NULL if optimization has determined that execution will produce an empty result before aggregation...
Definition: sql_optimizer.h:568
Query_expression * query_expression() const
Query expression referring this query block.
Definition: sql_optimizer.h:132
mem_root_deque< Item * > * get_current_fields()
Returns the clone of fields_list which is appropriate for evaluating expressions at the current stage...
Definition: sql_optimizer.cc:11089
bool(*)(JOIN *, Query_result *) Override_executor_func
A hook that secondary storage engines can use to override the executor completely.
Definition: sql_optimizer.h:317
void clear_hash_tables()
Definition: sql_optimizer.h:722
uint get_ref_item_slice() const
Definition: sql_optimizer.h:663
List< Cached_item > semijoin_deduplication_fields
Definition: sql_optimizer.h:339
bool grouped
If query contains GROUP BY clause.
Definition: sql_optimizer.h:229
void refine_best_rowcount()
Refine the best_rowcount estimation based on what happens after tables have been joined: LIMIT and ty...
Definition: sql_optimizer.cc:11063
AccessPath * m_root_access_path
An access path you can read from to get all records for this query (after you create an iterator from...
Definition: sql_optimizer.h:1019
ha_rows best_rowcount
The estimated row count of the plan with best read time (see above).
Definition: sql_optimizer.h:329
Item * where_cond
JOIN::having_cond is initially equal to query_block->having_cond, but may later be changed by optimiz...
Definition: sql_optimizer.h:491
bool simple_group
Definition: sql_optimizer.h:378
uint64_t hash_table_generation
Incremented each time clear_hash_tables() is run, signaling to HashJoinIterators that they cannot kee...
Definition: sql_optimizer.h:434
table_map deps_of_remaining_lateral_derived_tables
This is the bitmap of all tables which are dependencies of lateral derived tables which are not (yet)...
Definition: sql_optimizer.h:279
void copy_ref_item_slice(uint dst_slice, uint src_slice)
Overwrites one slice of ref_items with the contents of another slice.
Definition: sql_optimizer.h:625
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:173
Definition: sql_list.h:433
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:421
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:95
bool empty() const
Definition: sql_optimizer.h:111
int get_flags() const
Definition: sql_optimizer.h:119
void clean()
Definition: sql_optimizer.h:113
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:97
ORDER_with_src()
Definition: sql_optimizer.h:104
Explain_sort_clause src
origin of order list
Definition: sql_optimizer.h:98
int flags
bitmap of Explain_sort_property
Definition: sql_optimizer.h:101
ORDER_with_src(ORDER *order_arg, Explain_sort_clause src_arg)
Definition: sql_optimizer.h:106
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:89
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:70
Definition: sql_executor.h:259
enum_op_type
Definition: sql_executor.h:406
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1124
Item::cond_result having_value
Definition: sql_lex.h:2003
Query_expression * master_query_expression() const
Definition: sql_lex.h:1200
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:629
Definition: query_result.h:55
RAII class to ease the temporary switching to a different slice of the ref item array.
Definition: sql_optimizer.h:1043
Switch_ref_item_slice(JOIN *join_arg, uint new_v)
Definition: sql_optimizer.h:1048
uint saved
Definition: sql_optimizer.h:1045
JOIN * join
Definition: sql_optimizer.h:1044
~Switch_ref_item_slice()
Definition: sql_optimizer.h:1052
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
This class restores a table_map object to its original value when '*this' is destroyed.
Definition: sql_optimizer.h:1116
Table_map_restorer(table_map *map)
Constructor.
Definition: sql_optimizer.h:1127
Table_map_restorer & operator=(const Table_map_restorer &)=delete
table_map *const m_location
The location to be restored.
Definition: sql_optimizer.h:1118
~Table_map_restorer()
Definition: sql_optimizer.h:1134
const table_map m_saved_value
The original value to restore.
Definition: sql_optimizer.h:1120
void restore()
Definition: sql_optimizer.h:1135
void assert_unchanged() const
Definition: sql_optimizer.h:1136
Table_map_restorer(const Table_map_restorer &)=delete
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:98
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:135
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:104
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:114
bool is_temporal_type_with_date(enum_field_types type)
Tests if field type is temporal and has date part, i.e.
Definition: field_common_properties.h:155
This file contains the field type.
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
void optimize_distinct()
Optimize distinct when used on a subset of the tables.
Definition: sql_executor.cc:344
AccessPath * create_root_access_path_for_join()
Definition: sql_executor.cc:2821
void restore_fields(table_map save_nullinfo)
Restore all result fields for all tables specified in save_nullinfo.
Definition: sql_executor.cc:4429
bool create_intermediate_table(QEP_TAB *tab, const mem_root_deque< Item * > &tmp_table_fields, ORDER_with_src &tmp_table_group, bool save_sum_fields)
Create a temporary table to be used for processing DISTINCT/ORDER BY/GROUP BY.
Definition: sql_executor.cc:176
AccessPath * attach_access_paths_for_having_and_limit(AccessPath *path)
Definition: sql_executor.cc:3155
QEP_TAB::enum_op_type get_end_select_func()
Definition: sql_executor.cc:572
AccessPath * attach_access_path_for_delete(AccessPath *path)
Definition: sql_executor.cc:2775
void create_access_paths()
Convert the executor structures to a set of access paths, storing the result in m_root_access_path.
Definition: sql_executor.cc:2791
void create_access_paths_for_index_subquery()
Definition: sql_executor.cc:3188
bool clear_fields(table_map *save_nullinfo)
Set all column values from all input tables to NULL.
Definition: sql_executor.cc:4408
bool clear_corr_derived_tmp_tables()
Empties all correlated materialized derived tables.
Definition: sql_select.cc:1592
Item_equal * find_item_equal(COND_EQUAL *cond_equal, const Item_field *item_field, bool *inherited_fl)
Find the multiple equality predicate containing a field.
Definition: sql_optimizer.cc:3579
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.
Definition: sql_optimizer.cc:4859
bool alloc_func_list()
Make an array of pointers to sum_functions to speed up sum_func calculation.
Definition: sql_select.cc:3896
Item_field * get_best_field(Item_field *item_field, COND_EQUAL *cond_equal)
Get the best field substitution for a given field.
Definition: sql_optimizer.cc:3612
void update_sargable_from_const(SARGABLE_PARAM *sargables)
Update info on indexes that can be used for search lookups as reading const tables may has added new ...
Definition: sql_optimizer.cc:5708
bool add_sorting_to_table(uint idx, ORDER_with_src *order, bool sort_before_group)
Add Filesort object to the given table to sort if with filesort.
Definition: sql_select.cc:4809
bool clear_sj_tmp_tables()
Remove all rows from all temp tables used by NL-semijoin runtime.
Definition: sql_select.cc:1582
bool alloc_qep(uint n)
Definition: sql_optimizer.cc:1262
void change_to_access_path_without_in2exists()
If this query block was planned twice, once with and once without conditions added by in2exists,...
Definition: sql_optimizer.cc:1062
void unplug_join_tabs()
Definition: sql_select.cc:4781
bool push_to_engines()
Handle offloading of query parts to the underlying engines, when such is supported by their implement...
Definition: sql_optimizer.cc:1097
bool make_tmp_tables_info()
Init tmp tables usage info.
Definition: sql_select.cc:4179
bool make_join_plan()
Calculate best possible join order and initialize the join structure.
Definition: sql_optimizer.cc:5141
void set_semijoin_embedding()
Set semi-join embedding join nest pointers.
Definition: sql_optimizer.cc:5856
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 e...
Definition: sql_optimizer.cc:4301
bool optimize_distinct_group_order()
Optimize DISTINCT, GROUP BY, ORDER BY clauses.
Definition: sql_optimizer.cc:1409
JOIN(THD *thd_arg, Query_block *select)
Definition: sql_optimizer.cc:157
table_map calculate_deps_of_remaining_lateral_derived_tables(table_map plan_tables, uint idx) const
Finds the dependencies of the remaining lateral derived tables.
Definition: sql_optimizer.cc:3198
void set_prefix_tables()
Assign set of available (prefix) tables to all tables in query block.
Definition: sql_optimizer.cc:5034
void cleanup()
Cleanup this JOIN.
Definition: sql_select.cc:3534
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.
Definition: sql_optimizer.cc:6309
void test_skip_sort()
Test if an index could be used to replace filesort for ORDER BY/GROUP BY.
Definition: sql_optimizer.cc:1602
void create_access_paths_for_zero_rows()
Create access paths with the knowledge that there are going to be zero rows coming from tables (befor...
Definition: sql_optimizer.cc:1068
bool propagate_dependencies()
Propagate dependencies between tables due to outer join relations.
Definition: sql_optimizer.cc:5406
void adjust_access_methods()
An utility function - apply heuristics and optimize access methods to tables.
Definition: sql_optimizer.cc:2856
bool estimate_rowcount()
Estimate the number of matched rows for each joined table.
Definition: sql_optimizer.cc:5744
bool prune_table_partitions()
Prune partitions for all tables of a join (query block).
Definition: sql_optimizer.cc:2708
void refresh_base_slice()
In the case of rollup (only): After the base slice list was made, we may have modified the field list...
Definition: sql_select.cc:4756
bool alloc_ref_item_slice(THD *thd_arg, int sliceno)
Allocate a ref_item slice, assume that slice size is in ref_items[0].
Definition: sql_optimizer.cc:197
bool setup_semijoin_materialized_table(JOIN_TAB *tab, uint tableno, POSITION *inner_pos, POSITION *sjm_pos)
Setup the materialized table for a semi-join nest.
Definition: sql_select.cc:2883
void join_free()
Release memory and, if possible, the open tables held by this execution plan (and nested plans).
Definition: sql_select.cc:3464
bool make_sum_func_list(const mem_root_deque< Item * > &fields, bool before_group_by, bool recompute=false)
Initialize 'sum_funcs' array with all Item_sum objects.
Definition: sql_select.cc:3944
bool extract_func_dependent_tables()
Extract const tables based on functional dependencies.
Definition: sql_optimizer.cc:5551
bool init_planner_arrays()
Initialize scratch arrays for the join order optimization.
Definition: sql_optimizer.cc:5279
bool substitute_gc(THD *thd, Query_block *query_block, Item *where_cond, ORDER *group_list, ORDER *order)
Substitute all expressions in the WHERE condition and ORDER/GROUP lists that match generated columns ...
Definition: sql_optimizer.cc:1143
void set_semijoin_info()
Set the first_sj_inner_tab and last_sj_inner_tab fields for all tables inside the semijoin nests of t...
Definition: sql_select.cc:2026
bool prepare_result()
Prepare join result.
Definition: sql_select.cc:1676
void destroy()
Clean up and destroy join object.
Definition: sql_select.cc:1694
bool add_having_as_tmp_table_cond(uint curr_tmp_table)
Add having condition as a filter condition, which is applied when reading from the temp table.
Definition: sql_select.cc:4024
Item * substitute_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 eq...
Definition: sql_optimizer.cc:4607
double find_worst_seeks(const TABLE *table, double num_rows, double table_scan_cost)
Find an artificial cap for ref access.
Definition: sql_optimizer.cc:5724
const char * antijoin_null_cond
Definition: sql_optimizer.cc:115
bool alloc_indirection_slices()
Definition: sql_optimizer.cc:207
void reset()
Reset the state of this join object so that it is ready for a new execution.
Definition: sql_select.cc:1613
bool optimize(bool finalize_access_paths)
Optimizes one query block into a query execution plan (QEP.)
Definition: sql_optimizer.cc:281
bool init_ref_access()
Initialize ref access for all tables that use it.
Definition: sql_select.cc:2003
bool get_best_combination()
Set up JOIN_TAB structs according to the picked join order in best_positions.
Definition: sql_optimizer.cc:2974
bool extract_const_tables()
Extract const tables based on row counts.
Definition: sql_optimizer.cc:5457
bool update_equalities_for_sjm()
Update equalities and keyuse references after semi-join materialization strategy is chosen.
Definition: sql_optimizer.cc:4970
void set_plan_state(enum_plan_state plan_state_arg)
Sets the plan's state of the JOIN.
Definition: sql_optimizer.cc:1234
void cleanup_item_list(const mem_root_deque< Item * > &items) const
Definition: sql_select.cc:1788
int replace_index_subquery()
Check whether this is a subquery that can be evaluated by index look-ups.
Definition: sql_optimizer.cc:1342
void update_depend_map()
Update the dependency map for the tables.
Definition: sql_optimizer.cc:4901
Subquery_strategy
Strategy which will be used to handle this subquery: flattening to a semi-join, conversion to a deriv...
Definition: item_subselect.h:390
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1139
#define HA_POS_ERROR
Definition: my_base.h:1141
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:180
uint64_t table_map
Definition: my_table_map.h:29
static char * path
Definition: mysqldump.cc:130
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:150
required string key
Definition: replication_asynchronous_connection_failover.proto:59
Classes for query execution.
Common types of the Optimizer, used by optimization and execution.
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:53
@ REF_SLICE_ACTIVE
The slice which is used during evaluation of expressions; Item_ref::ref points there.
Definition: sql_opt_exec_shared.h:612
bool evaluate_during_optimization(const Item *item, const Query_block *select)
Checks if an Item, which is constant for execution, can be evaluated during optimization.
Definition: sql_optimizer.cc:11134
Item * make_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.
Definition: sql_optimizer.cc:9205
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.
Definition: sql_optimizer.cc:10937
Key_use_array * create_keyuse_for_table(THD *thd, uint keyparts, Item_field **fields, const mem_root_deque< Item * > &outer_exprs)
Create a keyuse array for a table with a primary key.
Definition: sql_optimizer.cc:8242
ORDER * create_order_from_distinct(THD *thd, Ref_item_array ref_item_array, ORDER *order_list, mem_root_deque< 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.
Definition: sql_optimizer.cc:10401
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 ...
Definition: sql_optimizer.h:1103
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.
Definition: sql_optimizer.cc:10035
bool ref_lookup_subsumes_comparison(Field *field, Item *right_item)
Whether a ref lookup of “right_item” on “field” will give an exact comparison in all cases,...
Definition: sql_optimizer.cc:8677
bool is_indexed_agg_distinct(JOIN *join, mem_root_deque< Item_field * > *out_args)
Check for the presence of AGGFN(DISTINCT a) queries that may be subject to loose index scan.
Definition: sql_optimizer.cc:7837
bool remove_eq_conds(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
Removes const and eq items.
Definition: sql_optimizer.cc:10154
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:188
Definition: sql_optimizer.h:169
Temp_table_param * temp_table_param
Definition: sql_optimizer.h:174
TABLE * table
Definition: sql_optimizer.h:170
A position of table within a join order.
Definition: sql_select.h:351
Definition: sql_optimizer.h:82
Item ** arg_value
Definition: sql_optimizer.h:84
Field * field
Definition: sql_optimizer.h:83
uint num_values
Definition: sql_optimizer.h:85
unsigned int uint
Definition: uca-dump.cc:29
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:39
int n
Definition: xcom_base.cc:505