1#ifndef SQL_OPTIMIZER_INCLUDED
2#define SQL_OPTIMIZER_INCLUDED
109 bool const_optimized_arg =
false)
626 bool optimize(
bool finalize_access_paths);
632 bool before_group_by,
bool recompute =
false);
643 assert(dst_arr.
size() >= src_arr.
size());
644 void *dest = dst_arr.
array();
645 const void *src = src_arr.
array();
667 assert((
int)sliceno >= 1);
670 DBUG_PRINT(
"info", (
"JOIN %p ref slice %u -> %u",
this,
726 Item *join_cond,
bool is_sj_mat_cond);
731 bool sort_before_group);
857 bool save_sum_fields);
910 tab->key_dependent = tab->dependent;
1079#define ASSERT_BEST_REF_IN_JOIN_ORDER(join) \
1081 assert((join)->tables == 0 || ((join)->best_ref && !(join)->join_tab)); \
1101 bool other_tbls_ok);
1121 table_map used_table,
bool exclude_expensive_cond);
1138 bool skip_aggregates,
1139 bool convert_bit_fields_to_long,
1140 bool *all_order_by_fields_used);
1230 const Item_field *item_field,
bool *inherited_fl);
1239 double table_scan_cost);
1257 bool can_evaluate,
bool *subsumes);
bool is_null() const
Definition: sql_array.h:156
Element_type * array() const
Definition: sql_array.h:164
size_t size() const
Definition: sql_array.h:153
size_t element_size() const
Definition: sql_array.h:152
Definition: item_cmpfunc.h:2714
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
Base class for the equality comparison operators = and <=>.
Definition: item_cmpfunc.h:980
Definition: item_cmpfunc.h:2574
Base class that is common to all subqueries and subquery predicates.
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:853
bool is_temporal_with_date() const
Definition: item.h:3165
cond_result
Definition: item.h:922
@ COND_FALSE
Definition: item.h:922
Query optimization plan node.
Definition: sql_select.h:598
Definition: sql_optimizer.h:132
const Cost_model_server * cost_model() const
Retrieve the cost model object to be used for this join.
Definition: sql_optimizer.cc:11327
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:402
Table_ref * tables_list
Pointer set to query_block->get_table_list() at the start of optimization.
Definition: sql_optimizer.h:515
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:8603
void set_root_access_path(AccessPath *path)
Definition: sql_optimizer.h:785
bool calc_found_rows
If true, calculate found rows for this query block.
Definition: sql_optimizer.h:599
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:617
void mark_const_table(JOIN_TAB *table, Key_use *key)
Move const tables first in the position array.
Definition: sql_optimizer.cc:8434
JOIN_TAB * join_tab
Optimal query execution plan.
Definition: sql_optimizer.h:153
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:304
Item_sum ** sum_funcs
Definition: sql_optimizer.h:348
List< Cached_item > group_fields
Definition: sql_optimizer.h:342
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:464
MYSQL_LOCK * lock
Definition: sql_optimizer.h:356
bool executed
Set by exec(), reset by reset().
Definition: sql_optimizer.h:822
QEP_TAB * qep_tab
Array of QEP_TABs.
Definition: sql_optimizer.h:155
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:712
ha_rows found_records
Definition: sql_optimizer.h:290
uint recursive_iteration_count
Used only if this query block is recursive.
Definition: sql_optimizer.h:565
void copy_ref_item_slice(Ref_item_array dst_arr, Ref_item_array src_arr)
Definition: sql_optimizer.h:642
bool child_subquery_can_materialize
True if, at this stage of processing, subquery materialization is allowed for children subqueries of ...
Definition: sql_optimizer.h:583
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
Definition: sql_optimizer.h:450
COND_EQUAL * cond_equal
Definition: sql_optimizer.h:516
JOIN_TAB ** map2table
mapping between table indexes and JOIN_TABs
Definition: sql_optimizer.h:165
ha_rows m_select_limit
Definition: sql_optimizer.h:294
POSITION * positions
Definition: sql_optimizer.h:316
uint current_ref_item_slice
The slice currently stored in ref_items[0].
Definition: sql_optimizer.h:558
bool is_executed() const
Definition: sql_optimizer.h:752
uint tables
Before plan has been created, "tables" denote number of input tables in the query block and "primary_...
Definition: sql_optimizer.h:214
bool has_lateral
If JOIN has lateral derived tables (is set at start of planning)
Definition: sql_optimizer.h:412
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:409
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
Definition: sql_optimizer.h:452
uint tmp_tables
Number of temporary tables used by query.
Definition: sql_optimizer.h:217
int error
set in optimize(), exec(), prepare_result()
Definition: sql_optimizer.h:434
bool plan_is_const() const
True if plan is const, ie it will return zero or one rows.
Definition: sql_optimizer.h:611
table_map const_table_map
Set of tables found to be const.
Definition: sql_optimizer.h:241
Prealloced_array< TemporaryTableToCleanup, 1 > temp_tables
Definition: sql_optimizer.h:183
Query_block *const query_block
Query block that is optimized and executed using this JOIN.
Definition: sql_optimizer.h:144
bool select_distinct
At construction time, set if SELECT DISTINCT.
Definition: sql_optimizer.h:366
RollupState
Definition: sql_optimizer.h:358
List< TABLE > sj_tmp_tables
Definition: sql_optimizer.h:592
table_map found_const_table_map
Const tables which are either:
Definition: sql_optimizer.h:248
bool simple_order
Definition: sql_optimizer.h:384
void set_executed()
Definition: sql_optimizer.h:753
List< Window > m_windows
Any window definitions.
Definition: sql_optimizer.h:458
Explain_format_flags explain_flags
Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN.
Definition: sql_optimizer.h:472
mem_root_deque< Item * > * tmp_fields
Array of pointers to lists of expressions.
Definition: sql_optimizer.h:432
uint const_tables
Number of primary tables deemed constant.
Definition: sql_optimizer.h:216
Prealloced_array< Filesort *, 1 > filesorts_to_cleanup
Definition: sql_optimizer.h:188
ha_rows examined_rows
Definition: sql_optimizer.h:291
ha_rows row_limit
Definition: sql_optimizer.h:292
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:589
JOIN_TAB ** best_ref
Array of plan operators representing the current (partial) best plan.
Definition: sql_optimizer.h:163
Item * having_for_explain
Saved optimized HAVING for EXPLAIN.
Definition: sql_optimizer.h:509
RollupState rollup_state
Definition: sql_optimizer.h:359
AccessPath * root_access_path() const
Definition: sql_optimizer.h:784
ha_rows send_records
Definition: sql_optimizer.h:289
Override_executor_func override_executor_func
Definition: sql_optimizer.h:325
plan_idx return_tab
Definition: sql_optimizer.h:524
enum_plan_state plan_state
Final execution plan state. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:825
Item * having_cond
Optimized HAVING clause item tree (valid for one single execution).
Definition: sql_optimizer.h:508
void make_outerjoin_info()
Fill in outer join related info for the execution plan structure.
Definition: sql_optimizer.cc:8463
mem_root_deque< Item * > * fields
Definition: sql_optimizer.h:341
Temp_table_param tmp_table_param
Describes a temporary table.
Definition: sql_optimizer.h:355
bool select_count
Definition: sql_optimizer.h:835
bool m_windowing_steps
If we have set up tmp tables for windowing,.
Definition: sql_optimizer.h:467
bool finalize_table_conditions(THD *thd)
Remove redundant predicates and cache constant expressions.
Definition: sql_optimizer.cc:9115
bool fts_index_access(JOIN_TAB *tab)
Check if FTS index only access is possible.
Definition: sql_optimizer.cc:10835
void optimize_keyuse()
Update some values in keyuse for faster choose_table_order() loop.
Definition: sql_optimizer.cc:10737
@ ORDERED_INDEX_GROUP_BY
Definition: sql_optimizer.h:394
@ ORDERED_INDEX_VOID
Definition: sql_optimizer.h:393
@ ORDERED_INDEX_ORDER_BY
Definition: sql_optimizer.h:395
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:608
uint send_group_parts
Definition: sql_optimizer.h:218
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:1071
ORDER_with_src group_list
Definition: sql_optimizer.h:446
double sort_cost
Expected cost of filesort.
Definition: sql_optimizer.h:338
bool generate_derived_keys()
Add keys to derived tables'/views' result tables in a list.
Definition: sql_optimizer.cc:9194
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:10776
enum_plan_state
State of execution plan. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:742
@ NO_TABLES
Plan has no tables.
Definition: sql_optimizer.h:745
@ NO_PLAN
No plan is ready yet.
Definition: sql_optimizer.h:743
@ ZERO_RESULT
Zero result cause is set.
Definition: sql_optimizer.h:744
@ PLAN_READY
Plan is ready.
Definition: sql_optimizer.h:746
Key_use_array keyuse_array
Used and updated by JOIN::make_join_plan() and optimize_keyuse()
Definition: sql_optimizer.h:415
bool group_sent
Exec time only: true <=> current group has been sent.
Definition: sql_optimizer.h:597
bool needs_finalize
Whether this query block needs finalization (see FinalizePlanForQueryBlock()) before it can be actual...
Definition: sql_optimizer.h:811
void init_key_dependencies()
Initialize key dependencies for join tables.
Definition: sql_optimizer.h:907
void set_ref_item_slice(uint sliceno)
Overwrite the base slice of ref_items with the slice supplied as argument.
Definition: sql_optimizer.h:666
List< Cached_item > group_fields_cache
Definition: sql_optimizer.h:343
bool contains_non_aggregated_fts() const
Returns true if any of the items in JOIN::fields contains a call to the full-text search function MAT...
Definition: sql_optimizer.cc:10869
bool streaming_aggregation
Indicates that the data will be aggregated (typically GROUP BY), and that it is already processed in ...
Definition: sql_optimizer.h:234
void set_optimized()
Definition: sql_optimizer.h:751
uint primary_tables
Number of primary input tables in query block.
Definition: sql_optimizer.h:215
bool optimize_rollup()
Optimize rollup specification.
Definition: sql_optimizer.cc:11284
THD *const thd
Thread handler.
Definition: sql_optimizer.h:146
table_map all_table_map
Set of tables contained in query.
Definition: sql_optimizer.h:240
bool attach_join_conditions(plan_idx last_tab)
Attach outer join conditions to generated table conditions in an optimal way.
Definition: sql_optimizer.cc:8714
enum JOIN::@178 ORDERED_INDEX_VOID
bool decide_subquery_strategy()
Decides between EXISTS and materialization; performs last steps to set up the chosen strategy.
Definition: sql_optimizer.cc:10998
List< Semijoin_mat_exec > sjm_exec_list
Definition: sql_optimizer.h:593
JOIN(const JOIN &rhs)=delete
TABLE * sort_by_table
Definition: sql_optimizer.h:171
Ref_item_array * ref_items
ref_items is an array of 4+ slices, each containing an array of Item pointers.
Definition: sql_optimizer.h:550
bool do_send_rows
If true, send produced rows using query_result.
Definition: sql_optimizer.h:238
double windowing_cost
Expected cost of windowing;.
Definition: sql_optimizer.h:340
enum_plan_state get_plan_state() const
See enum_plan_state.
Definition: sql_optimizer.h:749
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:446
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:375
double best_read
The cost of best complete join plan found so far during optimization, after optimization phase - cost...
Definition: sql_optimizer.h:332
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:10112
bool implicit_grouping
True if aggregated but no GROUP BY.
Definition: sql_optimizer.h:360
POSITION * best_positions
This is the result of join optimization.
Definition: sql_optimizer.h:311
void finalize_derived_keys()
For each materialized derived table/view, informs every TABLE of the key it will (not) use,...
Definition: sql_optimizer.cc:9214
bool optimized
flag to avoid double optimization in EXPLAIN
Definition: sql_optimizer.h:814
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:11059
bool is_optimized() const
Definition: sql_optimizer.h:750
const char * zero_result_cause
<> NULL if optimization has determined that execution will produce an empty result before aggregation...
Definition: sql_optimizer.h:575
Query_expression * query_expression() const
Query expression referring this query block.
Definition: sql_optimizer.h:139
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:11321
bool(*)(JOIN *, Query_result *) Override_executor_func
A hook that secondary storage engines can use to override the executor completely.
Definition: sql_optimizer.h:324
void clear_hash_tables()
Definition: sql_optimizer.h:738
uint get_ref_item_slice() const
Definition: sql_optimizer.h:677
List< Cached_item > semijoin_deduplication_fields
Definition: sql_optimizer.h:346
bool grouped
If query contains GROUP BY clause.
Definition: sql_optimizer.h:236
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:11295
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:1064
ha_rows best_rowcount
The estimated row count of the plan with best read time (see above).
Definition: sql_optimizer.h:336
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:498
bool simple_group
Definition: sql_optimizer.h:385
uint64_t hash_table_generation
Incremented each time clear_hash_tables() is run, signaling to HashJoinIterators that they cannot kee...
Definition: sql_optimizer.h:441
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:286
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:639
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:425
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:95
bool empty() const
Definition: sql_optimizer.h:115
bool is_const_optimized() const
Definition: sql_optimizer.h:129
ORDER_with_src(ORDER *order_arg, Explain_sort_clause src_arg, bool const_optimized_arg=false)
Definition: sql_optimizer.h:108
int get_flags() const
Definition: sql_optimizer.h:124
bool m_const_optimized
Definition: sql_optimizer.h:103
void clean()
Definition: sql_optimizer.h:117
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:97
ORDER_with_src()
Definition: sql_optimizer.h:106
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
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:91
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:1162
Item::cond_result having_value
Definition: sql_lex.h:2024
Query_expression * master_query_expression() const
Definition: sql_lex.h:1252
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:623
Definition: query_result.h:57
RAII class to ease the temporary switching to a different slice of the ref item array.
Definition: sql_optimizer.h:1088
Switch_ref_item_slice(JOIN *join_arg, uint new_v)
Definition: sql_optimizer.h:1093
uint saved
Definition: sql_optimizer.h:1090
JOIN * join
Definition: sql_optimizer.h:1089
~Switch_ref_item_slice()
Definition: sql_optimizer.h:1097
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
This class restores a table_map object to its original value when '*this' is destroyed.
Definition: sql_optimizer.h:1161
Table_map_restorer(table_map *map)
Constructor.
Definition: sql_optimizer.h:1172
Table_map_restorer & operator=(const Table_map_restorer &)=delete
table_map *const m_location
The location to be restored.
Definition: sql_optimizer.h:1163
~Table_map_restorer()
Definition: sql_optimizer.h:1179
const table_map m_saved_value
The original value to restore.
Definition: sql_optimizer.h:1165
void restore()
Definition: sql_optimizer.h:1180
void assert_unchanged() const
Definition: sql_optimizer.h:1181
Table_map_restorer(const Table_map_restorer &)=delete
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:131
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 Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:54
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:2962
AccessPath * attach_access_paths_for_having_and_limit(AccessPath *path) const
Definition: sql_executor.cc:3302
AccessPath * attach_access_path_for_update_or_delete(AccessPath *path) const
Definition: sql_executor.cc:2915
void restore_fields(table_map save_nullinfo)
Restore all result fields for all tables specified in save_nullinfo.
Definition: sql_executor.cc:4612
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:177
QEP_TAB::enum_op_type get_end_select_func()
Definition: sql_executor.cc:572
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:2952
void create_access_paths_for_index_subquery()
Definition: sql_executor.cc:3338
bool clear_fields(table_map *save_nullinfo)
Set all column values from all input tables to NULL.
Definition: sql_executor.cc:4589
bool clear_corr_derived_tmp_tables()
Empties all correlated materialized derived tables.
Definition: sql_select.cc:1776
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:3679
bool alloc_func_list()
Make an array of pointers to sum_functions to speed up sum_func calculation.
Definition: sql_select.cc:4071
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:3712
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:5825
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:4991
bool clear_sj_tmp_tables()
Remove all rows from all temp tables used by NL-semijoin runtime.
Definition: sql_select.cc:1766
bool alloc_qep(uint n)
Definition: sql_optimizer.cc:1307
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:1106
void unplug_join_tabs()
Definition: sql_select.cc:4963
bool push_to_engines()
Handle offloading of query parts to the underlying engines, when such is supported by their implement...
Definition: sql_optimizer.cc:1142
bool make_tmp_tables_info()
Init tmp tables usage info.
Definition: sql_select.cc:4354
bool make_join_plan()
Calculate best possible join order and initialize the join structure.
Definition: sql_optimizer.cc:5274
void set_semijoin_embedding()
Set semi-join embedding join nest pointers.
Definition: sql_optimizer.cc:5997
bool optimize_distinct_group_order()
Optimize DISTINCT, GROUP BY, ORDER BY clauses.
Definition: sql_optimizer.cc:1454
JOIN(THD *thd_arg, Query_block *select)
Definition: sql_optimizer.cc:163
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:3264
void set_prefix_tables()
Assign set of available (prefix) tables to all tables in query block.
Definition: sql_optimizer.cc:5167
void cleanup()
Cleanup this JOIN.
Definition: sql_select.cc:3702
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:6451
void test_skip_sort()
Test if an index could be used to replace filesort for ORDER BY/GROUP BY.
Definition: sql_optimizer.cc:1646
bool propagate_dependencies()
Propagate dependencies between tables due to outer join relations.
Definition: sql_optimizer.cc:5523
void adjust_access_methods()
An utility function - apply heuristics and optimize access methods to tables.
Definition: sql_optimizer.cc:2919
bool estimate_rowcount()
Estimate the number of matched rows for each joined table.
Definition: sql_optimizer.cc:5863
bool prune_table_partitions()
Prune partitions for all tables of a join (query block).
Definition: sql_optimizer.cc:2768
uint build_bitmap_for_nested_joins(mem_root_deque< Table_ref * > *join_list, uint first_unused)
Assign each nested join structure a bit in nested_join_map.
Definition: sql_optimizer.cc:4992
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:4938
AccessPath * create_access_paths_for_zero_rows() const
Create access paths with the knowledge that there are going to be zero rows coming from tables (befor...
Definition: sql_optimizer.cc:1112
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:203
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:3093
void join_free()
Release memory and, if possible, the open tables held by this execution plan (and nested plans).
Definition: sql_select.cc:3634
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:4119
bool extract_func_dependent_tables()
Extract const tables based on functional dependencies.
Definition: sql_optimizer.cc:5668
bool init_planner_arrays()
Initialize scratch arrays for the join order optimization.
Definition: sql_optimizer.cc:5404
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:1188
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:2225
bool prepare_result()
Prepare join result.
Definition: sql_select.cc:1860
void destroy()
Clean up and destroy join object.
Definition: sql_select.cc:1878
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:4198
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:4740
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:5841
const char * antijoin_null_cond
Definition: sql_optimizer.cc:120
bool alloc_indirection_slices()
Definition: sql_optimizer.cc:213
void reset()
Reset the state of this join object so that it is ready for a new execution.
Definition: sql_select.cc:1797
bool optimize(bool finalize_access_paths)
Optimizes one query block into a query execution plan (QEP.)
Definition: sql_optimizer.cc:336
bool build_equal_items(THD *thd, Item *cond, Item **retcond, COND_EQUAL *inherited, bool do_inherit, mem_root_deque< Table_ref * > *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:4434
bool init_ref_access()
Initialize ref access for all tables that use it.
Definition: sql_select.cc:2202
bool get_best_combination()
Set up JOIN_TAB structs according to the picked join order in best_positions.
Definition: sql_optimizer.cc:3037
bool extract_const_tables()
Extract const tables based on row counts.
Definition: sql_optimizer.cc:5574
bool update_equalities_for_sjm()
Update equalities and keyuse references after semi-join materialization strategy is chosen.
Definition: sql_optimizer.cc:5103
void set_plan_state(enum_plan_state plan_state_arg)
Sets the plan's state of the JOIN.
Definition: sql_optimizer.cc:1279
bool check_access_path_with_fts() const
Checks if the chosen plan suffers from a problem related to full-text search and streaming aggregatio...
Definition: sql_optimizer.cc:253
void cleanup_item_list(const mem_root_deque< Item * > &items) const
Definition: sql_select.cc:1983
int replace_index_subquery()
Check whether this is a subquery that can be evaluated by index look-ups.
Definition: sql_optimizer.cc:1387
void update_depend_map()
Update the dependency map for the tables.
Definition: sql_optimizer.cc:5034
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:396
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:140
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
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
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2891
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:620
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:11366
bool IsHashEquijoinCondition(const Item_eq_base *item, table_map left_side, table_map right_side)
Returns true if "item" can be used as a hash join condition between the tables given by "left_side" a...
Definition: sql_optimizer.cc:11663
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:9430
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:11169
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:8397
double EstimateRowAccesses(const AccessPath *path, double num_evaluations, double limit)
Estimates the number of base table row accesses that will be performed when executing a query using t...
Definition: sql_optimizer.cc:11509
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:10624
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:1148
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:7980
bool IteratorsAreNeeded(const THD *thd, AccessPath *root_path)
Checks if we need to create iterators for this query.
Definition: sql_optimizer.cc:11400
bool optimize_cond(THD *thd, Item **conds, COND_EQUAL **cond_equal, mem_root_deque< Table_ref * > *join_list, Item::cond_result *cond_value)
Optimize conditions by.
Definition: sql_optimizer.cc:10261
bool remove_eq_conds(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
Removes const and eq items.
Definition: sql_optimizer.cc:10377
bool ref_lookup_subsumes_comparison(THD *thd, Field *field, Item *right_item, bool can_evaluate, bool *subsumes)
Whether a ref lookup of “right_item” on “field” will give an exact comparison in all cases,...
Definition: sql_optimizer.cc:8841
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
Definition: sql_optimizer.h:176
Temp_table_param * temp_table_param
Definition: sql_optimizer.h:181
TABLE * table
Definition: sql_optimizer.h:177
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
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:41
int n
Definition: xcom_base.cc:508