1#ifndef SQL_OPTIMIZER_INCLUDED
2#define SQL_OPTIMIZER_INCLUDED
110 bool const_optimized_arg =
false)
629 bool optimize(
bool finalize_access_paths);
635 bool before_group_by,
bool recompute =
false);
646 assert(dst_arr.
size() >= src_arr.
size());
647 void *dest = dst_arr.
array();
648 const void *src = src_arr.
array();
670 assert((
int)sliceno >= 1);
673 DBUG_PRINT(
"info", (
"JOIN %p ref slice %u -> %u",
this,
729 Item *join_cond,
bool is_sj_mat_cond);
734 bool sort_before_group);
865 bool save_sum_fields,
866 const char *alias =
nullptr);
919 tab->key_dependent = tab->dependent;
1088#define ASSERT_BEST_REF_IN_JOIN_ORDER(join) \
1090 assert((join)->tables == 0 || ((join)->best_ref && !(join)->join_tab)); \
1110 bool include_hidden,
bool can_skip_aggs);
1112 bool other_tbls_ok);
1128 table_map used_table,
bool exclude_expensive_cond);
1145 bool skip_aggregates,
1146 bool convert_bit_fields_to_long,
1147 bool *all_order_by_fields_used);
1238 bool *inherited_fl);
1247 double table_scan_cost);
1265 bool can_evaluate,
bool *subsumes);
bool is_null() const
Definition: sql_array.h:157
Element_type * array() const
Definition: sql_array.h:165
size_t size() const
Definition: sql_array.h:154
size_t element_size() const
Definition: sql_array.h:153
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:54
virtual enum_field_types type() const =0
Base class for the equality comparison operators = and <=>.
Definition: item_cmpfunc.h:995
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2573
Base class that is common to all subqueries and subquery predicates.
Definition: item_subselect.h:80
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:399
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
bool is_temporal_with_date() const
Definition: item.h:3312
cond_result
Definition: item.h:993
@ COND_FALSE
Definition: item.h:993
Query optimization plan node.
Definition: sql_select.h:602
Definition: sql_optimizer.h:133
const Cost_model_server * cost_model() const
Retrieve the cost model object to be used for this join.
Definition: sql_optimizer.cc:11453
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:405
Table_ref * tables_list
Pointer set to query_block->get_table_list() at the start of optimization.
Definition: sql_optimizer.h:518
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:8706
void set_root_access_path(AccessPath *path)
Definition: sql_optimizer.h:788
bool calc_found_rows
If true, calculate found rows for this query block.
Definition: sql_optimizer.h:602
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:620
void mark_const_table(JOIN_TAB *table, Key_use *key)
Move const tables first in the position array.
Definition: sql_optimizer.cc:8537
JOIN_TAB * join_tab
Optimal query execution plan.
Definition: sql_optimizer.h:154
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:305
Item_sum ** sum_funcs
Definition: sql_optimizer.h:351
List< Cached_item > group_fields
Definition: sql_optimizer.h:345
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:467
MYSQL_LOCK * lock
Definition: sql_optimizer.h:359
bool executed
Set by exec(), reset by reset().
Definition: sql_optimizer.h:830
QEP_TAB * qep_tab
Array of QEP_TABs.
Definition: sql_optimizer.h:156
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:715
ha_rows found_records
Definition: sql_optimizer.h:291
uint recursive_iteration_count
Used only if this query block is recursive.
Definition: sql_optimizer.h:568
void copy_ref_item_slice(Ref_item_array dst_arr, Ref_item_array src_arr)
Definition: sql_optimizer.h:645
bool child_subquery_can_materialize
True if, at this stage of processing, subquery materialization is allowed for children subqueries of ...
Definition: sql_optimizer.h:586
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
Definition: sql_optimizer.h:453
COND_EQUAL * cond_equal
Definition: sql_optimizer.h:519
JOIN_TAB ** map2table
mapping between table indexes and JOIN_TABs
Definition: sql_optimizer.h:166
ha_rows m_select_limit
Definition: sql_optimizer.h:295
POSITION * positions
Definition: sql_optimizer.h:317
uint current_ref_item_slice
The slice currently stored in ref_items[0].
Definition: sql_optimizer.h:561
bool is_executed() const
Definition: sql_optimizer.h:755
uint tables
Before plan has been created, "tables" denote number of input tables in the query block and "primary_...
Definition: sql_optimizer.h:215
bool has_lateral
If JOIN has lateral derived tables (is set at start of planning)
Definition: sql_optimizer.h:415
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:412
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
Definition: sql_optimizer.h:455
uint tmp_tables
Number of temporary tables used by query.
Definition: sql_optimizer.h:218
int error
set in optimize(), exec(), prepare_result()
Definition: sql_optimizer.h:437
bool plan_is_const() const
True if plan is const, ie it will return zero or one rows.
Definition: sql_optimizer.h:614
table_map const_table_map
Set of tables found to be const.
Definition: sql_optimizer.h:242
Prealloced_array< TemporaryTableToCleanup, 1 > temp_tables
Definition: sql_optimizer.h:184
Query_block *const query_block
Query block that is optimized and executed using this JOIN.
Definition: sql_optimizer.h:145
bool select_distinct
At construction time, set if SELECT DISTINCT.
Definition: sql_optimizer.h:369
RollupState
Definition: sql_optimizer.h:361
List< TABLE > sj_tmp_tables
Definition: sql_optimizer.h:595
table_map found_const_table_map
Const tables which are either:
Definition: sql_optimizer.h:249
bool simple_order
Definition: sql_optimizer.h:387
void set_executed()
Definition: sql_optimizer.h:756
List< Window > m_windows
Any window definitions.
Definition: sql_optimizer.h:461
Explain_format_flags explain_flags
Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN.
Definition: sql_optimizer.h:475
mem_root_deque< Item * > * tmp_fields
Array of pointers to lists of expressions.
Definition: sql_optimizer.h:435
uint const_tables
Number of primary tables deemed constant.
Definition: sql_optimizer.h:217
Prealloced_array< Filesort *, 1 > filesorts_to_cleanup
Definition: sql_optimizer.h:189
ha_rows examined_rows
Definition: sql_optimizer.h:292
ha_rows row_limit
Definition: sql_optimizer.h:293
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:592
JOIN_TAB ** best_ref
Array of plan operators representing the current (partial) best plan.
Definition: sql_optimizer.h:164
Item * having_for_explain
Saved optimized HAVING for EXPLAIN.
Definition: sql_optimizer.h:512
RollupState rollup_state
Definition: sql_optimizer.h:362
AccessPath * root_access_path() const
Definition: sql_optimizer.h:787
ha_rows send_records
Definition: sql_optimizer.h:290
Override_executor_func override_executor_func
Definition: sql_optimizer.h:326
plan_idx return_tab
Definition: sql_optimizer.h:527
enum_plan_state plan_state
Final execution plan state. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:833
Item * having_cond
Optimized HAVING clause item tree (valid for one single execution).
Definition: sql_optimizer.h:511
void make_outerjoin_info()
Fill in outer join related info for the execution plan structure.
Definition: sql_optimizer.cc:8566
mem_root_deque< Item * > * fields
Definition: sql_optimizer.h:344
Temp_table_param tmp_table_param
Describes a temporary table.
Definition: sql_optimizer.h:358
bool select_count
Definition: sql_optimizer.h:843
bool m_windowing_steps
If we have set up tmp tables for windowing,.
Definition: sql_optimizer.h:470
bool finalize_table_conditions(THD *thd)
Remove redundant predicates and cache constant expressions.
Definition: sql_optimizer.cc:9221
bool fts_index_access(JOIN_TAB *tab)
Check if FTS index only access is possible.
Definition: sql_optimizer.cc:10960
void optimize_keyuse()
Update some values in keyuse for faster choose_table_order() loop.
Definition: sql_optimizer.cc:10862
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:611
uint send_group_parts
Definition: sql_optimizer.h:219
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:1080
ORDER_with_src group_list
Definition: sql_optimizer.h:449
double sort_cost
Expected cost of filesort.
Definition: sql_optimizer.h:341
bool generate_derived_keys()
Add keys to derived tables'/views' result tables in a list.
Definition: sql_optimizer.cc:9300
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:10901
enum_plan_state
State of execution plan. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:745
@ NO_TABLES
Plan has no tables.
Definition: sql_optimizer.h:748
@ NO_PLAN
No plan is ready yet.
Definition: sql_optimizer.h:746
@ ZERO_RESULT
Zero result cause is set.
Definition: sql_optimizer.h:747
@ PLAN_READY
Plan is ready.
Definition: sql_optimizer.h:749
Key_use_array keyuse_array
Used and updated by JOIN::make_join_plan() and optimize_keyuse()
Definition: sql_optimizer.h:418
bool group_sent
Exec time only: true <=> current group has been sent.
Definition: sql_optimizer.h:600
bool needs_finalize
Whether this query block needs finalization (see FinalizePlanForQueryBlock()) before it can be actual...
Definition: sql_optimizer.h:819
void init_key_dependencies()
Initialize key dependencies for join tables.
Definition: sql_optimizer.h:916
void set_ref_item_slice(uint sliceno)
Overwrite the base slice of ref_items with the slice supplied as argument.
Definition: sql_optimizer.h:669
List< Cached_item > group_fields_cache
Definition: sql_optimizer.h:346
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:10994
enum JOIN::@186 ORDERED_INDEX_VOID
bool streaming_aggregation
Indicates that the data will be aggregated (typically GROUP BY), and that it is already processed in ...
Definition: sql_optimizer.h:235
void set_optimized()
Definition: sql_optimizer.h:754
uint primary_tables
Number of primary input tables in query block.
Definition: sql_optimizer.h:216
bool optimize_rollup()
Optimize rollup specification.
Definition: sql_optimizer.cc:11410
THD *const thd
Thread handler.
Definition: sql_optimizer.h:147
table_map all_table_map
Set of tables contained in query.
Definition: sql_optimizer.h:241
bool attach_join_conditions(plan_idx last_tab)
Attach outer join conditions to generated table conditions in an optimal way.
Definition: sql_optimizer.cc:8817
bool decide_subquery_strategy()
Decides between EXISTS and materialization; performs last steps to set up the chosen strategy.
Definition: sql_optimizer.cc:11124
List< Semijoin_mat_exec > sjm_exec_list
Definition: sql_optimizer.h:596
JOIN(const JOIN &rhs)=delete
TABLE * sort_by_table
Definition: sql_optimizer.h:172
Ref_item_array * ref_items
ref_items is an array of 4+ slices, each containing an array of Item pointers.
Definition: sql_optimizer.h:553
bool do_send_rows
If true, send produced rows using query_result.
Definition: sql_optimizer.h:239
double windowing_cost
Expected cost of windowing;.
Definition: sql_optimizer.h:343
enum_plan_state get_plan_state() const
See enum_plan_state.
Definition: sql_optimizer.h:752
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:449
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:378
double best_read
The cost of best complete join plan found so far during optimization, after optimization phase - cost...
Definition: sql_optimizer.h:335
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:10231
bool implicit_grouping
True if aggregated but no GROUP BY.
Definition: sql_optimizer.h:363
@ ORDERED_INDEX_GROUP_BY
Definition: sql_optimizer.h:397
@ ORDERED_INDEX_VOID
Definition: sql_optimizer.h:396
@ ORDERED_INDEX_ORDER_BY
Definition: sql_optimizer.h:398
POSITION * best_positions
This is the result of join optimization.
Definition: sql_optimizer.h:312
void finalize_derived_keys()
For each materialized derived table/view, informs every TABLE of the key it will (not) use,...
Definition: sql_optimizer.cc:9320
bool optimized
flag to avoid double optimization in EXPLAIN
Definition: sql_optimizer.h:822
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:11185
bool is_optimized() const
Definition: sql_optimizer.h:753
const char * zero_result_cause
<> NULL if optimization has determined that execution will produce an empty result before aggregation...
Definition: sql_optimizer.h:578
Query_expression * query_expression() const
Query expression referring this query block.
Definition: sql_optimizer.h:140
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:11447
bool(*)(JOIN *, Query_result *) Override_executor_func
A hook that secondary storage engines can use to override the executor completely.
Definition: sql_optimizer.h:325
void clear_hash_tables()
Definition: sql_optimizer.h:741
uint get_ref_item_slice() const
Definition: sql_optimizer.h:680
List< Cached_item > semijoin_deduplication_fields
Definition: sql_optimizer.h:349
bool grouped
If query contains GROUP BY clause.
Definition: sql_optimizer.h:237
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:11421
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:1073
ha_rows best_rowcount
The estimated row count of the plan with best read time (see above).
Definition: sql_optimizer.h:339
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:501
bool simple_group
Definition: sql_optimizer.h:388
uint64_t hash_table_generation
Incremented each time clear_hash_tables() is run, signaling to HashJoinIterators that they cannot kee...
Definition: sql_optimizer.h:444
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:287
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:642
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:177
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:96
bool empty() const
Definition: sql_optimizer.h:116
bool is_const_optimized() const
Definition: sql_optimizer.h:130
ORDER_with_src(ORDER *order_arg, Explain_sort_clause src_arg, bool const_optimized_arg=false)
Definition: sql_optimizer.h:109
int get_flags() const
Definition: sql_optimizer.h:125
bool m_const_optimized
Definition: sql_optimizer.h:104
void clean()
Definition: sql_optimizer.h:118
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:98
ORDER_with_src()
Definition: sql_optimizer.h:107
Explain_sort_clause src
origin of order list
Definition: sql_optimizer.h:99
int flags
bitmap of Explain_sort_property
Definition: sql_optimizer.h:102
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:94
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
Definition: sql_executor.h:256
enum_op_type
Definition: sql_executor.h:403
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1159
Item::cond_result having_value
Definition: sql_lex.h:2079
Query_expression * master_query_expression() const
Definition: sql_lex.h:1270
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:627
Definition: query_result.h:58
RAII class to ease the temporary switching to a different slice of the ref item array.
Definition: sql_optimizer.h:1097
Switch_ref_item_slice(JOIN *join_arg, uint new_v)
Definition: sql_optimizer.h:1102
uint saved
Definition: sql_optimizer.h:1099
JOIN * join
Definition: sql_optimizer.h:1098
~Switch_ref_item_slice()
Definition: sql_optimizer.h:1106
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class restores a table_map object to its original value when '*this' is destroyed.
Definition: sql_optimizer.h:1168
Table_map_restorer(table_map *map)
Constructor.
Definition: sql_optimizer.h:1179
Table_map_restorer & operator=(const Table_map_restorer &)=delete
table_map *const m_location
The location to be restored.
Definition: sql_optimizer.h:1170
~Table_map_restorer()
Definition: sql_optimizer.h:1186
const table_map m_saved_value
The original value to restore.
Definition: sql_optimizer.h:1172
void restore()
Definition: sql_optimizer.h:1187
void assert_unchanged() const
Definition: sql_optimizer.h:1188
Table_map_restorer(const Table_map_restorer &)=delete
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:97
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:134
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:110
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:115
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:156
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:55
void optimize_distinct()
Optimize distinct when used on a subset of the tables.
Definition: sql_executor.cc:409
AccessPath * create_root_access_path_for_join()
Definition: sql_executor.cc:3149
AccessPath * attach_access_paths_for_having_and_limit(AccessPath *path) const
Definition: sql_executor.cc:3492
AccessPath * attach_access_path_for_update_or_delete(AccessPath *path) const
Definition: sql_executor.cc:3083
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, const char *alias=nullptr)
Create a temporary table to be used for processing DISTINCT/ORDER BY/GROUP BY.
Definition: sql_executor.cc:242
void restore_fields(table_map save_nullinfo)
Restore all result fields for all tables specified in save_nullinfo.
Definition: sql_executor.cc:4809
QEP_TAB::enum_op_type get_end_select_func()
Definition: sql_executor.cc:637
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:3120
void create_access_paths_for_index_subquery()
Definition: sql_executor.cc:3531
bool clear_fields(table_map *save_nullinfo)
Set all column values from all input tables to NULL.
Definition: sql_executor.cc:4786
bool clear_corr_derived_tmp_tables()
Empties all correlated materialized derived tables.
Definition: sql_select.cc:1877
bool alloc_func_list()
Make an array of pointers to sum_functions to speed up sum_func calculation.
Definition: sql_select.cc:4149
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:3775
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:5889
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:5064
bool clear_sj_tmp_tables()
Remove all rows from all temp tables used by NL-semijoin runtime.
Definition: sql_select.cc:1867
bool alloc_qep(uint n)
Definition: sql_optimizer.cc:1330
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:1129
void unplug_join_tabs()
Definition: sql_select.cc:5036
uint get_tmp_table_rec_length(const mem_root_deque< Item * > &items, bool include_hidden, bool can_skip_aggs)
Definition: sql_optimizer.cc:6311
bool push_to_engines()
Handle offloading of query parts to the underlying engines, when such is supported by their implement...
Definition: sql_optimizer.cc:1165
void assign_fields_to_slice(int sliceno)
Similar to refresh_base_slice(), but refreshes only the specified slice.
Definition: sql_select.cc:5024
bool make_tmp_tables_info()
Init tmp tables usage info.
Definition: sql_select.cc:4433
bool make_join_plan()
Calculate best possible join order and initialize the join structure.
Definition: sql_optimizer.cc:5337
void set_semijoin_embedding()
Set semi-join embedding join nest pointers.
Definition: sql_optimizer.cc:6062
bool optimize_distinct_group_order()
Optimize DISTINCT, GROUP BY, ORDER BY clauses.
Definition: sql_optimizer.cc:1477
JOIN(THD *thd_arg, Query_block *select)
Definition: sql_optimizer.cc:170
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:3326
void set_prefix_tables()
Assign set of available (prefix) tables to all tables in query block.
Definition: sql_optimizer.cc:5230
void cleanup()
Cleanup this JOIN.
Definition: sql_select.cc:3792
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:6550
Item_multi_eq * 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:3741
void test_skip_sort()
Test if an index could be used to replace filesort for ORDER BY/GROUP BY.
Definition: sql_optimizer.cc:1663
bool propagate_dependencies()
Propagate dependencies between tables due to outer join relations.
Definition: sql_optimizer.cc:5586
void adjust_access_methods()
An utility function - apply heuristics and optimize access methods to tables.
Definition: sql_optimizer.cc:2975
bool estimate_rowcount()
Estimate the number of matched rows for each joined table.
Definition: sql_optimizer.cc:5927
bool prune_table_partitions()
Prune partitions for all tables of a join (query block).
Definition: sql_optimizer.cc:2824
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:5055
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:5011
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:1135
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:210
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:3188
void join_free()
Release memory and, if possible, the open tables held by this execution plan (and nested plans).
Definition: sql_select.cc:3724
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:4197
bool extract_func_dependent_tables()
Extract const tables based on functional dependencies.
Definition: sql_optimizer.cc:5731
bool init_planner_arrays()
Initialize scratch arrays for the join order optimization.
Definition: sql_optimizer.cc:5467
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:1211
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:2320
bool prepare_result()
Prepare join result.
Definition: sql_select.cc:1963
void destroy()
Clean up and destroy join object.
Definition: sql_select.cc:1981
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:4276
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:4802
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:5905
const char * antijoin_null_cond
Definition: sql_optimizer.cc:127
bool alloc_indirection_slices()
Definition: sql_optimizer.cc:220
void reset()
Reset the state of this join object so that it is ready for a new execution.
Definition: sql_select.cc:1898
bool optimize(bool finalize_access_paths)
Optimizes one query block into a query execution plan (QEP.)
Definition: sql_optimizer.cc:343
bool init_ref_access()
Initialize ref access for all tables that use it.
Definition: sql_select.cc:2297
bool get_best_combination()
Set up JOIN_TAB structs according to the picked join order in best_positions.
Definition: sql_optimizer.cc:3095
bool extract_const_tables()
Extract const tables based on row counts.
Definition: sql_optimizer.cc:5637
bool update_equalities_for_sjm()
Update equalities and keyuse references after semi-join materialization strategy is chosen.
Definition: sql_optimizer.cc:5166
void set_plan_state(enum_plan_state plan_state_arg)
Sets the plan's state of the JOIN.
Definition: sql_optimizer.cc:1302
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:260
void cleanup_item_list(const mem_root_deque< Item * > &items) const
Definition: sql_select.cc:2079
int replace_index_subquery()
Check whether this is a subquery that can be evaluated by index look-ups.
Definition: sql_optimizer.cc:1410
void update_depend_map()
Update the dependency map for the tables.
Definition: sql_optimizer.cc:5097
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:426
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:1141
#define HA_POS_ERROR
Definition: my_base.h:1143
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
uint64_t table_map
Definition: my_table_map.h:30
static char * path
Definition: mysqldump.cc:149
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
required string key
Definition: replication_asynchronous_connection_failover.proto:60
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:54
@ REF_SLICE_ACTIVE
The slice which is used during evaluation of expressions; Item_ref::ref points there.
Definition: sql_opt_exec_shared.h:621
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:11492
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:11795
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:9536
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:11295
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:8500
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:11635
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:10749
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:1155
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:8081
bool IteratorsAreNeeded(const THD *thd, AccessPath *root_path)
Checks if we need to create iterators for this query.
Definition: sql_optimizer.cc:11526
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:10380
bool remove_eq_conds(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
Removes const and eq items.
Definition: sql_optimizer.cc:10496
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:8944
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227
Definition: item_cmpfunc.h:2726
Definition: sql_optimizer.h:177
Temp_table_param * temp_table_param
Definition: sql_optimizer.h:182
TABLE * table
Definition: sql_optimizer.h:178
A position of table within a join order.
Definition: sql_select.h:355
Definition: sql_optimizer.h:83
Item ** arg_value
Definition: sql_optimizer.h:85
Field * field
Definition: sql_optimizer.h:84
uint num_values
Definition: sql_optimizer.h:86
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:44
int n
Definition: xcom_base.cc:509