1#ifndef SQL_SELECT_INCLUDED
2#define SQL_SELECT_INCLUDED
99#define LOWER_BITS(type, A) ((type)(((type)1 << (A)) - 1))
102#define KEY_OPTIMIZE_EXISTS 1
103#define KEY_OPTIMIZE_REF_OR_NULL 2
104#define FT_KEYPART (MAX_REF_PARTS + 10)
195 bool null_rejecting_arg,
bool *cond_guard_arg,
uint sj_pred_no_arg)
309#define SJ_OPT_DUPS_WEEDOUT 1
310#define SJ_OPT_LOOSE_SCAN 2
311#define SJ_OPT_FIRST_MATCH 3
312#define SJ_OPT_MATERIALIZE_LOOKUP 4
313#define SJ_OPT_MATERIALIZE_SCAN 5
761 quick_order_tested(),
772 reversed_access(false) {}
777 bool reset_with_sum_func,
bool save_sum_fields);
795extern "C" int refpos_order_cmp(
const void *arg,
const void *a,
const void *b);
816 virtual const char *
name()
const {
855 const char *
name()
const override {
return "func"; }
868 uint *p_used_fieldlength);
872 const Field *order_field =
nullptr,
873 Item **const_item =
nullptr);
898 assert(item !=
nullptr);
904 assert(item !=
nullptr);
916 uint *used_key_parts,
bool *skip_quick);
920 int *new_key_direction,
ha_rows *new_select_limit,
921 uint *new_used_key_parts =
nullptr,
922 uint *saved_best_key_parts =
nullptr);
942 uint *length_out,
uint *keyparts_out,
959 bool null_rejecting,
table_map const_tables,
1015 const Item *item1,
const Item *item2);
Definition: sql_bitmap.h:137
void clear_all()
Definition: sql_bitmap.h:163
Definition: item_cmpfunc.h:2696
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:51
double row_evaluate_cost(double rows) const
Cost of processing a number of records and evaluating the query condition on the records.
Definition: opt_costmodel.h:94
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:47
Definition: item_cmpfunc.h:292
Definition: item_cmpfunc.h:2706
Item_func_comparison is a class for comparison functions that take two arguments and return a boolean...
Definition: item_cmpfunc.h:685
Definition: item_func.h:93
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
@ FIELD_ITEM
Definition: item.h:888
virtual const char * full_name() const
Definition: item.h:2184
virtual enum Type type() const =0
Query optimization plan node.
Definition: sql_select.h:598
Key_map needed_reg
Definition: sql_select.h:679
enum quick_type use_quick
Definition: sql_select.h:714
uint m_use_join_cache
Join buffering strategy.
Definition: sql_select.h:720
Table_ref * table_ref
points to table reference
Definition: sql_select.h:630
void set_condition(Item *to)
Set the combined condition for a table (may be performed several times)
Definition: sql_select.h:617
JOIN_TAB(const JOIN_TAB &)
void set_keyuse(Key_use *k)
Definition: sql_select.h:628
double read_time
Definition: sql_select.h:701
Table_ref * emb_sj_nest
Definition: sql_select.h:728
Key_map quick_order_tested
Used to avoid repeated range analysis for the same key in test_if_skip_sort_order().
Definition: sql_select.h:689
Key_map const_keys
Keys with constant part.
Definition: sql_select.h:668
table_map dependent
The set of tables that this table depends on.
Definition: sql_select.h:706
void set_use_join_cache(uint u)
Definition: sql_select.h:626
Key_use * keyuse() const
Definition: sql_select.h:627
Key_map skip_scan_keys
Keys which can be used for skip scan access.
Definition: sql_select.h:678
bool reversed_access
true <=> AM will scan backward
Definition: sql_select.h:737
Item * join_cond() const
Definition: sql_select.h:608
void set_join_cond(Item *cond)
Sets join condition.
Definition: sql_select.h:614
table_map key_dependent
The set of tables that are referenced by key from this table.
Definition: sql_select.h:710
double worst_seeks
The maximum value for the cost of seek operations for key lookup during ref access.
Definition: sql_select.h:666
uint join_cache_flags
Flags from SE's MRR implementation, to be used by JOIN_CACHE.
Definition: sql_select.h:734
COND_EQUAL * cond_equal
multiple equalities for the on expression
Definition: sql_select.h:649
ha_rows found_records
Definition: sql_select.h:695
JOIN_TAB()
Definition: sql_select.h:750
Key_map checked_keys
Keys checked.
Definition: sql_select.h:669
Item ** m_join_cond_ref
Pointer to the associated join condition:
Definition: sql_select.h:646
Key_use * m_keyuse
pointer to first used key
Definition: sql_select.h:633
nested_join_map embedding_map
Definition: sql_select.h:731
JOIN_TAB & operator=(const JOIN_TAB &)
uint use_join_cache() const
Definition: sql_select.h:625
uint used_fieldlength
Definition: sql_select.h:713
Definition: sql_optimizer.h:132
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:173
key_part_map bound_keyparts
The key columns which are equal to expressions depending only of earlier tables of the current join p...
Definition: sql_select.h:277
Item * val
Value used for lookup into key.
Definition: sql_select.h:218
double read_cost
Cost of the ref access path for the current join prefix, i.e.
Definition: sql_select.h:299
uint optimize
0, or KEY_OPTIMIZE_*
Definition: sql_select.h:231
Table_ref * table_ref
table owning the index
Definition: sql_select.h:211
key_part_map keypart_map
like keypart, but as a bitmap
Definition: sql_select.h:232
ha_rows ref_table_rows
Estimate of how many rows for a key value.
Definition: sql_select.h:233
uint sj_pred_no
0..63 <=> This was created from semi-join IN-equality # sj_pred_no.
Definition: sql_select.h:264
uint keypart
used part of the index
Definition: sql_select.h:230
Key_use(Table_ref *table_ref_arg, Item *val_arg, table_map used_tables_arg, uint key_arg, uint keypart_arg, uint optimize_arg, key_part_map keypart_map_arg, ha_rows ref_table_rows_arg, bool null_rejecting_arg, bool *cond_guard_arg, uint sj_pred_no_arg)
Definition: sql_select.h:192
uint key
number of index
Definition: sql_select.h:229
bool null_rejecting
If true, the comparison this value was created from will not be satisfied if val has NULL 'value' (un...
Definition: sql_select.h:240
Key_use()
Definition: sql_select.h:176
bool * cond_guard
!NULL - This Key_use was created from an equality that was wrapped into an Item_func_trig_cond.
Definition: sql_select.h:254
table_map used_tables
All tables used in val, that is all tables that provide bindings for the expression val.
Definition: sql_select.h:228
double fanout
Fanout of the ref access path for this index, in the current join prefix.
Definition: sql_select.h:284
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
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:97
Definition: sql_executor.h:259
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:477
QEP_shared * m_qs
Definition: sql_opt_exec_shared.h:573
Item * condition() const
Definition: sql_opt_exec_shared.h:525
void set_condition(Item *c)
Definition: sql_opt_exec_shared.h:297
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1155
Definition: query_result.h:53
Definition: sql_executor.h:103
Abstract base class for traversing the Query_block tree.
Definition: select_lex_visitor.h:39
Definition: sql_cmd_dml.h:34
Definition: sql_select.h:73
Sql_cmd_select(Query_result *result_arg)
Definition: sql_select.h:75
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_select.h:79
bool may_use_cursor() const override
Definition: sql_select.h:88
bool is_data_change_stmt() const override
Definition: sql_select.h:81
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
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
Definition: sql_select.h:846
const char * name() const override
Definition: sql_select.h:855
store_key_hash_item(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg, ulonglong *hash_arg)
Definition: sql_select.h:850
ulonglong * hash
Definition: sql_select.h:847
class to copying an field/item to a key struct
Definition: sql_select.h:809
Field * to_field
Definition: sql_select.h:834
virtual ~store_key()=default
bool null_key
Definition: sql_select.h:811
virtual const char * name() const
Definition: sql_select.h:816
Item * item
Definition: sql_select.h:835
store_key_result
Definition: sql_select.h:812
@ STORE_KEY_OK
Definition: sql_select.h:812
@ STORE_KEY_FATAL
Definition: sql_select.h:812
@ STORE_KEY_CONV
Definition: sql_select.h:812
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
bool test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER_with_src *order, TABLE *table, Key_map usable_keys, int key, ha_rows select_limit, int *new_key, int *new_key_direction, ha_rows *new_select_limit, uint *new_used_key_parts=nullptr, uint *saved_best_key_parts=nullptr)
Find a cheaper access key than a given key.
Definition: sql_select.cc:4907
bool accept(THD *thd, Select_lex_visitor *visitor) override
Definition: sql_select.cc:420
enum store_key_result copy_inner() override
Definition: sql_select.cc:2470
bool make_join_readinfo(JOIN *join, uint no_jbuf_after)
Plan refinement stage: do various setup things for the executor.
Definition: sql_select.cc:3100
ORDER * simple_remove_const(ORDER *order, Item *where)
Filter out ORDER BY items that are equal to constants in WHERE condition.
Definition: sql_select.cc:3592
SJ_TMP_TABLE * create_sj_tmp_table(THD *thd, JOIN *join, SJ_TMP_TABLE_TAB *first_tab, SJ_TMP_TABLE_TAB *last_tab)
Set up the support structures (NULL bits, row offsets, etc.) for a semijoin duplicate weedout table.
Definition: sql_select.cc:1148
void reset_statement_timer(THD *thd)
Deactivate the timer associated with the statement that was executed.
Definition: sql_select.cc:229
void accumulate_statement_cost(const LEX *lex)
Calculates the cost of executing a statement, including all its subqueries and stores it in thd->m_cu...
Definition: sql_select.cc:646
bool create_ref_for_key(JOIN *join, JOIN_TAB *j, Key_use *org_keyuse, table_map used_tables)
Setup a ref access for looking up rows via an index (a key).
Definition: sql_select.cc:2237
void count_field_types(const Query_block *query_block, Temp_table_param *param, const mem_root_deque< Item * > &fields, bool reset_with_sum_func, bool save_sum_fields)
Update TMP_TABLE_PARAM with count of the different type of fields.
Definition: sql_select.cc:3739
bool types_allow_materialization(Item *outer, Item *inner)
Check if two items are compatible wrt.
Definition: sql_select.cc:1049
void init_join_cond_ref(Table_ref *tl)
Sets the pointer to the join condition of Table_ref.
Definition: sql_select.cc:3313
bool test_if_subpart(ORDER *a, ORDER *b)
Return 1 if second is a subpart of first argument.
Definition: sql_select.cc:3804
int test_if_order_by_key(ORDER_with_src *order, TABLE *table, uint idx, uint *used_key_parts, bool *skip_quick)
Test if one can use the key to resolve ordering.
Definition: sql_optimizer.cc:1792
void free_underlaid_joins(Query_block *select)
Free joins of subselect of this select.
Definition: sql_select.cc:3980
void calc_length_and_keyparts(Key_use *keyuse, JOIN_TAB *tab, const uint key, table_map used_tables, Key_use **chosen_keyuses, uint *length_out, uint *keyparts_out, table_map *dep_map, bool *maybe_null)
Calculate properties of ref key: key length, number of used key parts, dependency map,...
Definition: sql_select.cc:2089
bool CreateFramebufferTable(THD *thd, const Temp_table_param &tmp_table_param, const Query_block &query_block, const mem_root_deque< Item * > &source_fields, const mem_root_deque< Item * > &window_output_fields, Func_ptr_array *mapping_from_source_to_window_output, Window *window)
Definition: sql_select.cc:4089
store_key_result copy()
sets ignore truncation warnings mode and calls the real copy method
Definition: sql_select.cc:2452
uint actual_key_parts(const KEY *key_info)
Returns number of key parts depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
Definition: sql_select.cc:5238
uint find_shortest_key(TABLE *table, const Key_map *usable_keys)
Find shortest key suitable for full table scan.
Definition: sql_optimizer.cc:1954
bool set_statement_timer(THD *thd)
Set the time until the currently running statement is aborted.
Definition: sql_select.cc:202
join_type calc_join_type(AccessPath *path)
Definition: sql_select.cc:5252
bool precheck(THD *thd) override
Perform an authorization precheck for an unprepared SELECT statement.
Definition: sql_select.cc:882
virtual enum store_key_result copy_inner()
Definition: sql_select.cc:2537
bool equality_determines_uniqueness(const Item_func_comparison *func, const Item *v, const Item *c)
Check if equality can be used to remove sub-clause of GROUP BY/ORDER BY.
Definition: sql_select.cc:3608
const MYSQL_LEX_CSTRING * eligible_secondary_storage_engine() const override
Is this statement of a type and on a form that makes it eligible for execution in a secondary storage...
Definition: sql_select.cc:424
bool init_ref(THD *thd, unsigned keyparts, unsigned length, unsigned keyno, Index_lookup *ref)
Initialize the given TABLE_REF; setting basic fields and allocating memory for arrays.
Definition: sql_select.cc:2135
store_key(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg)
Definition: sql_select.cc:2428
bool optimize_secondary_engine(THD *thd)
Perform query optimizations that are specific to a secondary storage engine.
Definition: sql_select.cc:741
uint get_index_for_order(ORDER_with_src *order, TABLE *table, ha_rows limit, AccessPath *range_scan, bool *need_sort, bool *reverse)
Find a key to apply single table UPDATE/DELETE by a given ORDER.
Definition: sql_select.cc:5149
bool check_field_is_const(Item *cond, const Item *order_item, const Field *order_field=nullptr, Item **const_item=nullptr)
Check if a field is equal to a constant value in a condition.
Definition: sql_select.cc:3679
void set_table(TABLE *t)
Definition: sql_select.cc:3308
void calc_group_buffer(JOIN *join, ORDER *group)
calc how big buffer we need for comparing group entries.
Definition: sql_select.cc:3824
bool check_privileges_for_list(THD *thd, const mem_root_deque< Item * > &items, ulong privileges)
Check privileges for all columns referenced from an expression list.
Definition: sql_select.cc:1948
uint actual_key_flags(const KEY *key_info)
Returns key flags depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
Definition: sql_select.cc:5245
uint get_sj_strategy() const
Definition: sql_optimizer.cc:1377
bool check_privileges(THD *thd) override
Perform an authorization check for a prepared SELECT statement.
Definition: sql_select.cc:923
bool check_privileges_for_join(THD *thd, mem_root_deque< Table_ref * > *tables)
Check privileges for all columns referenced from join expression.
Definition: sql_select.cc:1921
bool and_conditions(Item **e1, Item *e2)
Extend e1 by AND'ing e2 to the condition e1 points to.
Definition: sql_select.cc:2570
bool prepare_inner(THD *thd) override
Prepare a SELECT statement.
Definition: sql_select.cc:433
bool validate_use_secondary_engine(const LEX *lex)
Validates a query that uses the secondary engine.
Definition: sql_select.cc:277
void cleanup()
Clean up associated table after query execution, including resources.
Definition: sql_select.cc:3321
bool init_ref_part(THD *thd, unsigned part_no, Item *val, bool *cond_guard, bool null_rejecting, table_map const_tables, table_map used_tables, bool nullable, const KEY_PART_INFO *key_part_info, uchar *key_buff, Index_lookup *ref)
Initialize a given keypart in the table ref.
Definition: sql_select.cc:2155
bool equality_has_no_implicit_casts(const Item_func_comparison *func, const Item *item1, const Item *item2)
Check whether equality between two items is exact, ie., there are no implicit casts involved.
Definition: sql_select.cc:3626
void calc_used_field_length(TABLE *table, bool needs_rowid, uint *p_used_fieldlength)
Find how much space the previous read not const tables takes in cache.
Definition: sql_select.cc:1988
This file includes constants used by all storage engines.
ulong key_part_map
Definition: my_base.h:1006
my_off_t ha_rows
Definition: my_base.h:1139
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_SELECT
Definition: my_sqlcommand.h:46
uint64_t table_map
Definition: my_table_map.h:29
static ulong select_limit
Definition: mysql.cc:202
static char * path
Definition: mysqldump.cc:133
static char * where
Definition: mysqldump.cc:136
PT & ref(PT *tp)
Definition: tablespace_impl.cc:358
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
RangeReverse< Range > reverse(Range &x)
Iterate over a range in reverse.
Definition: utilities.h:131
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
ulonglong nested_join_map
Definition: nested_join.h:36
required string key
Definition: replication_asynchronous_connection_failover.proto:59
File containing constants that can be used throughout the server.
Common types of the Optimizer, used by optimization and execution.
join_type
Definition: sql_opt_exec_shared.h:185
bool sj_is_materialize_strategy(uint strategy)
Definition: sql_select.h:315
#define SJ_OPT_MATERIALIZE_LOOKUP
Definition: sql_select.h:312
aggregate_evaluated
Definition: sql_select.h:783
@ AGGR_COMPLETE
Definition: sql_select.h:784
@ AGGR_EMPTY
Definition: sql_select.h:787
@ AGGR_REGULAR
Definition: sql_select.h:785
@ AGGR_DELAYED
Definition: sql_select.h:786
#define SJ_OPT_NONE
Definition: sql_select.h:308
bool optimize_aggregated_query(THD *thd, Query_block *select, const mem_root_deque< Item * > &all_fields, Item *conds, aggregate_evaluated *decision)
Substitute constants for some COUNT(), MIN() and MAX() functions in an aggregated (implicitly grouped...
Definition: opt_sum.cc:275
constexpr const char * STORE_KEY_CONST_NAME
The name of store_key instances that represent constant items.
Definition: sql_select.h:798
quick_type
Bits describing quick select type.
Definition: sql_select.h:322
@ QS_DYNAMIC_RANGE
Definition: sql_select.h:322
@ QS_NONE
Definition: sql_select.h:322
@ QS_RANGE
Definition: sql_select.h:322
ulonglong nested_join_map
Definition: sql_select.h:68
Mem_root_array< Func_ptr > Func_ptr_array
Definition: sql_select.h:71
int refpos_order_cmp(const void *arg, const void *a, const void *b)
Definition: sql_delete.cc:909
bool is_simple_predicate(Item_func *func_item, Item **args, bool *inv_order)
Test if the predicate compares a field with constants.
Definition: opt_sum.cc:634
static Item * and_items(Item *cond, Item *item)
Create a AND item of two existing items.
Definition: sql_select.h:897
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:192
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:66
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3701
Definition: mysql_lex_string.h:39
A position of table within a join order.
Definition: sql_select.h:351
table_map m_suffix_lateral_deps
The lateral dependendencies of 'table' and all subsequent JOIN_TABs in the join plan.
Definition: sql_select.h:585
uint first_loosescan_table
Definition: sql_select.h:478
uint sjm_scan_last_inner
Definition: sql_select.h:527
float filter_effect
The fraction of the 'rows_fetched' rows that will pass the table conditions that were NOT used by the...
Definition: sql_select.h:415
table_map loosescan_need_tables
Definition: sql_select.h:483
double read_cost
Cost of accessing the table in course of the entire complete join execution, i.e.
Definition: sql_select.h:381
JOIN_TAB * table
Definition: sql_select.h:436
uint first_dupsweedout_table
Definition: sql_select.h:518
table_map sjm_scan_need_tables
Definition: sql_select.h:533
bool use_join_buffer
Definition: sql_select.h:446
nested_join_map cur_embedding_map
Value of Optimize_table_order::cur_embedding_map after this table has been added to the plan.
Definition: sql_select.h:504
void set_prefix_cost(double cost, double rowcount)
Set complete estimated cost and produced rowcount for the prefix of tables up to and including this t...
Definition: sql_select.h:550
table_map ref_depend_map
If ref-based access is used: bitmap of tables this table depends on
Definition: sql_select.h:445
table_map dupsweedout_tables
Definition: sql_select.h:523
uint sj_strategy
Current optimization state: Semi-join strategy to be used for this and preceding join tables.
Definition: sql_select.h:460
table_map get_suffix_lateral_deps() const
Definition: sql_select.h:578
table_map firstmatch_need_tables
Definition: sql_select.h:514
uint n_sj_tables
Valid only after fix_semijoin_strategies_for_picked_join_order() call: if sj_strategy!...
Definition: sql_select.h:466
void no_semijoin()
Even if the query has no semijoin, two sj-related members are read and must thus have been set,...
Definition: sql_select.h:539
void set_suffix_lateral_deps(table_map deps)
Definition: sql_select.h:576
table_map dups_producing_tables
Bitmap of semi-join inner tables that are in the join prefix and for which there's no provision yet f...
Definition: sql_select.h:473
Key_use * key
NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
Definition: sql_select.h:442
void set_prefix_join_cost(uint idx, const Cost_model_server *cm)
Set complete estimated cost and produced rowcount for the prefix of tables up to and including this t...
Definition: sql_select.h:564
uint loosescan_parts
Definition: sql_select.h:492
double prefix_cost
Definition: sql_select.h:434
table_map first_firstmatch_rtbl
Definition: sql_select.h:509
uint loosescan_key
Definition: sql_select.h:491
double rows_fetched
The number of rows that will be fetched by the chosen access method per each row combination of previ...
Definition: sql_select.h:370
uint first_firstmatch_table
Definition: sql_select.h:499
double prefix_rowcount
prefix_rowcount and prefix_cost form a stack of partial join order costs and output sizes
Definition: sql_select.h:433
Definition: sql_executor.h:79
unsigned int uint
Definition: uca9-dump.cc:74