1#ifndef SQL_SELECT_INCLUDED
2#define SQL_SELECT_INCLUDED
100#define LOWER_BITS(type, A) ((type)(((type)1 << (A)) - 1))
103#define KEY_OPTIMIZE_EXISTS 1
104#define KEY_OPTIMIZE_REF_OR_NULL 2
105#define FT_KEYPART (MAX_REF_PARTS + 10)
196 bool null_rejecting_arg,
bool *cond_guard_arg,
uint sj_pred_no_arg)
310#define SJ_OPT_DUPS_WEEDOUT 1
311#define SJ_OPT_LOOSE_SCAN 2
312#define SJ_OPT_FIRST_MATCH 3
313#define SJ_OPT_MATERIALIZE_LOOKUP 4
314#define SJ_OPT_MATERIALIZE_SCAN 5
762 quick_order_tested(),
773 reversed_access(false) {}
778 bool reset_with_sum_func,
bool save_sum_fields);
796extern "C" int refpos_order_cmp(
const void *arg,
const void *a,
const void *b);
817 virtual const char *
name()
const {
856 const char *
name()
const override {
return "func"; }
869 uint *p_used_fieldlength);
873 const Field *order_field =
nullptr,
874 Item **const_item =
nullptr);
899 assert(item !=
nullptr);
905 assert(item !=
nullptr);
917 uint *used_key_parts,
bool *skip_quick);
921 int *new_key_direction,
ha_rows *new_select_limit,
922 uint *new_used_key_parts =
nullptr,
923 uint *saved_best_key_parts =
nullptr,
924 double *new_read_time =
nullptr);
944 uint *length_out,
uint *keyparts_out,
961 bool null_rejecting,
table_map const_tables,
1017 const Item *item1,
const Item *item2);
uint32_t Access_bitmask
Definition: auth_acls.h:34
Definition: sql_bitmap.h:138
void clear_all()
Definition: sql_bitmap.h:164
Definition: item_cmpfunc.h:2701
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:52
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:95
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:48
Definition: item_cmpfunc.h:295
Definition: item_cmpfunc.h:2711
Item_func_comparison is a class for comparison functions that take two arguments and return a boolean...
Definition: item_cmpfunc.h:688
Definition: item_func.h:102
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
@ FIELD_ITEM
Definition: item.h:891
virtual const char * full_name() const
Definition: item.h:2194
virtual enum Type type() const =0
Query optimization plan node.
Definition: sql_select.h:599
Key_map needed_reg
Definition: sql_select.h:680
enum quick_type use_quick
Definition: sql_select.h:715
uint m_use_join_cache
Join buffering strategy.
Definition: sql_select.h:721
Table_ref * table_ref
points to table reference
Definition: sql_select.h:631
void set_condition(Item *to)
Set the combined condition for a table (may be performed several times)
Definition: sql_select.h:618
JOIN_TAB(const JOIN_TAB &)
void set_keyuse(Key_use *k)
Definition: sql_select.h:629
double read_time
Definition: sql_select.h:702
Table_ref * emb_sj_nest
Definition: sql_select.h:729
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:690
Key_map const_keys
Keys with constant part.
Definition: sql_select.h:669
table_map dependent
The set of tables that this table depends on.
Definition: sql_select.h:707
void set_use_join_cache(uint u)
Definition: sql_select.h:627
Key_use * keyuse() const
Definition: sql_select.h:628
Key_map skip_scan_keys
Keys which can be used for skip scan access.
Definition: sql_select.h:679
bool reversed_access
true <=> AM will scan backward
Definition: sql_select.h:738
Item * join_cond() const
Definition: sql_select.h:609
void set_join_cond(Item *cond)
Sets join condition.
Definition: sql_select.h:615
table_map key_dependent
The set of tables that are referenced by key from this table.
Definition: sql_select.h:711
double worst_seeks
The maximum value for the cost of seek operations for key lookup during ref access.
Definition: sql_select.h:667
uint join_cache_flags
Flags from SE's MRR implementation, to be used by JOIN_CACHE.
Definition: sql_select.h:735
COND_EQUAL * cond_equal
multiple equalities for the on expression
Definition: sql_select.h:650
ha_rows found_records
Definition: sql_select.h:696
JOIN_TAB()
Definition: sql_select.h:751
Key_map checked_keys
Keys checked.
Definition: sql_select.h:670
Item ** m_join_cond_ref
Pointer to the associated join condition:
Definition: sql_select.h:647
Key_use * m_keyuse
pointer to first used key
Definition: sql_select.h:634
nested_join_map embedding_map
Definition: sql_select.h:732
JOIN_TAB & operator=(const JOIN_TAB &)
uint use_join_cache() const
Definition: sql_select.h:626
uint used_fieldlength
Definition: sql_select.h:714
Definition: sql_optimizer.h:133
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:174
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:278
Item * val
Value used for lookup into key.
Definition: sql_select.h:219
double read_cost
Cost of the ref access path for the current join prefix, i.e.
Definition: sql_select.h:300
uint optimize
0, or KEY_OPTIMIZE_*
Definition: sql_select.h:232
Table_ref * table_ref
table owning the index
Definition: sql_select.h:212
key_part_map keypart_map
like keypart, but as a bitmap
Definition: sql_select.h:233
ha_rows ref_table_rows
Estimate of how many rows for a key value.
Definition: sql_select.h:234
uint sj_pred_no
0..63 <=> This was created from semi-join IN-equality # sj_pred_no.
Definition: sql_select.h:265
uint keypart
used part of the index
Definition: sql_select.h:231
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:193
uint key
number of index
Definition: sql_select.h:230
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:241
Key_use()
Definition: sql_select.h:177
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:255
table_map used_tables
All tables used in val, that is all tables that provide bindings for the expression val.
Definition: sql_select.h:229
double fanout
Fanout of the ref access path for this index, in the current join prefix.
Definition: sql_select.h:285
Definition: sql_list.h:434
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
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:98
Definition: sql_executor.h:260
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:478
QEP_shared * m_qs
Definition: sql_opt_exec_shared.h:574
Item * condition() const
Definition: sql_opt_exec_shared.h:526
void set_condition(Item *c)
Definition: sql_opt_exec_shared.h:298
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1156
Definition: query_result.h:54
Definition: sql_executor.h:104
Abstract base class for traversing the Query_block tree.
Definition: select_lex_visitor.h:40
Definition: sql_cmd_dml.h:35
Definition: sql_select.h:74
Sql_cmd_select(Query_result *result_arg)
Definition: sql_select.h:76
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_select.h:80
bool may_use_cursor() const override
Definition: sql_select.h:89
bool is_data_change_stmt() const override
Definition: sql_select.h:82
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:95
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:105
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
Definition: sql_select.h:847
const char * name() const override
Definition: sql_select.h:856
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:851
ulonglong * hash
Definition: sql_select.h:848
class to copying an field/item to a key struct
Definition: sql_select.h:810
Field * to_field
Definition: sql_select.h:835
virtual ~store_key()=default
bool null_key
Definition: sql_select.h:812
virtual const char * name() const
Definition: sql_select.h:817
Item * item
Definition: sql_select.h:836
store_key_result
Definition: sql_select.h:813
@ STORE_KEY_OK
Definition: sql_select.h:813
@ STORE_KEY_FATAL
Definition: sql_select.h:813
@ STORE_KEY_CONV
Definition: sql_select.h:813
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
bool accept(THD *thd, Select_lex_visitor *visitor) override
Definition: sql_select.cc:601
enum store_key_result copy_inner() override
Definition: sql_select.cc:2637
bool make_join_readinfo(JOIN *join, uint no_jbuf_after)
Plan refinement stage: do various setup things for the executor.
Definition: sql_select.cc:3267
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:3748
void set_external_engine_fail_reason(const LEX *lex, const char *reason)
Sets the reason of failure for the statement to the external engine.
Definition: sql_select.cc:370
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:1320
const handlerton * get_secondary_engine_handlerton(const LEX *lex)
Returns secondary_engine handler for the statement.
Definition: sql_select.cc:345
void reset_statement_timer(THD *thd)
Deactivate the timer associated with the statement that was executed.
Definition: sql_select.cc:230
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:872
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:2404
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:3895
bool types_allow_materialization(Item *outer, Item *inner)
Check if two items are compatible wrt.
Definition: sql_select.cc:1221
void init_join_cond_ref(Table_ref *tl)
Sets the pointer to the join condition of Table_ref.
Definition: sql_select.cc:3485
bool test_if_subpart(ORDER *a, ORDER *b)
Return 1 if second is a subpart of first argument.
Definition: sql_select.cc:3960
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:1794
void free_underlaid_joins(Query_block *select)
Free joins of subselect of this select.
Definition: sql_select.cc:4136
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, double *new_read_time=nullptr)
Find a cheaper access key than a given key.
Definition: sql_select.cc:5066
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:2256
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:4245
store_key_result copy()
sets ignore truncation warnings mode and calls the real copy method
Definition: sql_select.cc:2619
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:5401
uint find_shortest_key(TABLE *table, const Key_map *usable_keys)
Find shortest key suitable for full table scan.
Definition: sql_optimizer.cc:1960
bool check_privileges_for_list(THD *thd, const mem_root_deque< Item * > &items, Access_bitmask privileges)
Check privileges for all columns referenced from an expression list.
Definition: sql_select.cc:2115
bool set_statement_timer(THD *thd)
Set the time until the currently running statement is aborted.
Definition: sql_select.cc:203
join_type calc_join_type(AccessPath *path)
Definition: sql_select.cc:5415
bool precheck(THD *thd) override
Perform an authorization precheck for an unprepared SELECT statement.
Definition: sql_select.cc:1098
virtual enum store_key_result copy_inner()
Definition: sql_select.cc:2704
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:3764
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:605
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:2302
store_key(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg)
Definition: sql_select.cc:2595
bool optimize_secondary_engine(THD *thd)
Perform query optimizations that are specific to a secondary storage engine.
Definition: sql_select.cc:956
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:5312
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:3835
void set_table(TABLE *t)
Definition: sql_select.cc:3480
void calc_group_buffer(JOIN *join, ORDER *group)
calc how big buffer we need for comparing group entries.
Definition: sql_select.cc:3980
uint actual_key_flags(const KEY *key_info)
Returns key flags depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
Definition: sql_select.cc:5408
uint get_sj_strategy() const
Definition: sql_optimizer.cc:1378
bool check_privileges(THD *thd) override
Perform an authorization check for a prepared SELECT statement.
Definition: sql_select.cc:1139
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:2088
bool and_conditions(Item **e1, Item *e2)
Extend e1 by AND'ing e2 to the condition e1 points to.
Definition: sql_select.cc:2737
bool prepare_inner(THD *thd) override
Prepare a SELECT statement.
Definition: sql_select.cc:614
bool validate_use_secondary_engine(const LEX *lex)
Validates a query that uses the secondary engine.
Definition: sql_select.cc:438
void cleanup()
Clean up associated table after query execution, including resources.
Definition: sql_select.cc:3493
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:2322
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:3782
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:2155
This file includes constants used by all storage engines.
ulong key_part_map
Definition: my_base.h:1007
my_off_t ha_rows
Definition: my_base.h:1140
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_SELECT
Definition: my_sqlcommand.h:47
uint64_t table_map
Definition: my_table_map.h:30
static ulong select_limit
Definition: mysql.cc:203
static char * path
Definition: mysqldump.cc:137
static char * where
Definition: mysqldump.cc:140
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
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:76
RangeReverse< Range > reverse(Range &x)
Iterate over a range in reverse.
Definition: utilities.h:132
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:151
ulonglong nested_join_map
Definition: nested_join.h:37
required string key
Definition: replication_asynchronous_connection_failover.proto:60
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:186
bool sj_is_materialize_strategy(uint strategy)
Definition: sql_select.h:316
#define SJ_OPT_MATERIALIZE_LOOKUP
Definition: sql_select.h:313
aggregate_evaluated
Definition: sql_select.h:784
@ AGGR_COMPLETE
Definition: sql_select.h:785
@ AGGR_EMPTY
Definition: sql_select.h:788
@ AGGR_REGULAR
Definition: sql_select.h:786
@ AGGR_DELAYED
Definition: sql_select.h:787
#define SJ_OPT_NONE
Definition: sql_select.h:309
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:276
constexpr const char * STORE_KEY_CONST_NAME
The name of store_key instances that represent constant items.
Definition: sql_select.h:799
quick_type
Bits describing quick select type.
Definition: sql_select.h:323
@ QS_DYNAMIC_RANGE
Definition: sql_select.h:323
@ QS_NONE
Definition: sql_select.h:323
@ QS_RANGE
Definition: sql_select.h:323
ulonglong nested_join_map
Definition: sql_select.h:69
Mem_root_array< Func_ptr > Func_ptr_array
Definition: sql_select.h:72
int refpos_order_cmp(const void *arg, const void *a, const void *b)
Definition: sql_delete.cc:910
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:636
static Item * and_items(Item *cond, Item *item)
Create a AND item of two existing items.
Definition: sql_select.h:898
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:67
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3710
Definition: mysql_lex_string.h:40
A position of table within a join order.
Definition: sql_select.h:352
table_map m_suffix_lateral_deps
The lateral dependendencies of 'table' and all subsequent JOIN_TABs in the join plan.
Definition: sql_select.h:586
uint first_loosescan_table
Definition: sql_select.h:479
uint sjm_scan_last_inner
Definition: sql_select.h:528
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:416
table_map loosescan_need_tables
Definition: sql_select.h:484
double read_cost
Cost of accessing the table in course of the entire complete join execution, i.e.
Definition: sql_select.h:382
JOIN_TAB * table
Definition: sql_select.h:437
uint first_dupsweedout_table
Definition: sql_select.h:519
table_map sjm_scan_need_tables
Definition: sql_select.h:534
bool use_join_buffer
Definition: sql_select.h:447
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:505
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:551
table_map ref_depend_map
If ref-based access is used: bitmap of tables this table depends on
Definition: sql_select.h:446
table_map dupsweedout_tables
Definition: sql_select.h:524
uint sj_strategy
Current optimization state: Semi-join strategy to be used for this and preceding join tables.
Definition: sql_select.h:461
table_map get_suffix_lateral_deps() const
Definition: sql_select.h:579
table_map firstmatch_need_tables
Definition: sql_select.h:515
uint n_sj_tables
Valid only after fix_semijoin_strategies_for_picked_join_order() call: if sj_strategy!...
Definition: sql_select.h:467
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:540
void set_suffix_lateral_deps(table_map deps)
Definition: sql_select.h:577
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:474
Key_use * key
NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
Definition: sql_select.h:443
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:565
uint loosescan_parts
Definition: sql_select.h:493
double prefix_cost
Definition: sql_select.h:435
table_map first_firstmatch_rtbl
Definition: sql_select.h:510
uint loosescan_key
Definition: sql_select.h:492
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:371
uint first_firstmatch_table
Definition: sql_select.h:500
double prefix_rowcount
prefix_rowcount and prefix_cost form a stack of partial join order costs and output sizes
Definition: sql_select.h:434
Definition: sql_executor.h:80
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
unsigned int uint
Definition: uca9-dump.cc:75