MySQL  8.0.27
Source Code Documentation
Query_block Class Reference

This class represents a query block, aka a query specification, which is a query consisting of a SELECT keyword, followed by a table list, optionally followed by a WHERE clause, a GROUP BY, etc. More...

#include <sql_lex.h>

Public Types

enum  Resolve_place {
  RESOLVE_NONE , RESOLVE_JOIN_NEST , RESOLVE_CONDITION , RESOLVE_HAVING ,
  RESOLVE_SELECT_LIST
}
 Three fields used by semi-join transformations to know when semi-join is possible, and in which condition tree the subquery predicate is located. More...
 

Public Member Functions

 Query_block (MEM_ROOT *mem_root, Item *where, Item *having)
 Construct and initialize Query_block object. More...
 
Itemwhere_cond () const
 
Item ** where_cond_ref ()
 
void set_where_cond (Item *cond)
 
Itemhaving_cond () const
 
Item ** having_cond_ref ()
 
void set_having_cond (Item *cond)
 
void set_query_result (Query_result *result)
 
Query_resultquery_result () const
 
bool change_query_result (THD *thd, Query_result_interceptor *new_result, Query_result_interceptor *old_result)
 Change the Query_result object of the query block. More...
 
void set_base_options (ulonglong options_arg)
 Set base options for a query block (and active options too) More...
 
void add_base_options (ulonglong options)
 Add base options to a query block, also update active options. More...
 
void remove_base_options (ulonglong options)
 Remove base options from a query block. More...
 
void make_active_options (ulonglong added_options, ulonglong removed_options)
 Make active options from base options, supplied options and environment: More...
 
void add_active_options (ulonglong options)
 Adjust the active option set. More...
 
ulonglong active_options () const
 
void set_tables_readonly ()
 Set associated tables as read_only, ie. More...
 
table_map all_tables_map () const
 
void remove_derived (THD *thd, TABLE_LIST *tl)
 Remove a derived table we added previously as part of transform_scalar_subqueries_to_join_with_derived. More...
 
bool remove_aggregates (THD *thd, Query_block *select)
 A minion of transform_grouped_to_derived. More...
 
Query_expressionmaster_query_expression () const
 
Query_expressionfirst_inner_query_expression () const
 
Query_blockouter_query_block () const
 
Query_blocknext_query_block () const
 
TABLE_LISTfind_table_by_name (const Table_ident *ident)
 Finds a (possibly unresolved) table reference in the from clause by name. More...
 
bool is_straight_join ()
 
Query_blocklast_query_block ()
 
Query_blocknext_select_in_list () const
 
void mark_as_dependent (Query_block *last, bool aggregate)
 Mark all query blocks from this to 'last' as dependent. More...
 
bool is_explicitly_grouped () const
 
bool is_implicitly_grouped () const
 
bool is_single_grouped () const
 True if this query block is implicitly grouped. More...
 
bool is_grouped () const
 
bool is_distinct () const
 
bool is_ordered () const
 
bool can_skip_distinct () const
 Based on the structure of the query at resolution time, it is possible to conclude that DISTINCT is useless and remove it. More...
 
bool has_limit () const
 
bool has_ft_funcs () const
 
bool is_recursive () const
 
bool is_in_select_list (Item *i)
 
ORDERfind_in_group_list (Item *item, int *rollup_level) const
 Finds a group expression matching the given item, or nullptr if none. More...
 
int group_list_size () const
 
bool has_windows () const
 
void invalidate ()
 Invalidate by nulling out pointers to other Query_expressions and Query_blockes. More...
 
uint get_in_sum_expr () const
 
bool add_item_to_list (Item *item)
 
bool add_ftfunc_to_list (Item_func_match *func)
 
void add_order_to_list (ORDER *order)
 
TABLE_LISTadd_table_to_list (THD *thd, Table_ident *table, const char *alias, ulong table_options, thr_lock_type flags=TL_UNLOCK, enum_mdl_type mdl_type=MDL_SHARED_READ, List< Index_hint > *hints=nullptr, List< String > *partition_names=nullptr, LEX_STRING *option=nullptr, Parse_context *pc=nullptr)
 Add a table to list of used tables. More...
 
Item ** add_hidden_item (Item *item)
 Add item to the hidden part of select list. More...
 
void remove_hidden_items ()
 Remove hidden items from select list. More...
 
TABLE_LISTget_table_list () const
 
bool init_nested_join (THD *thd)
 Initialize a new table list for a nested join. More...
 
TABLE_LISTend_nested_join ()
 End a nested join table list. More...
 
TABLE_LISTnest_last_join (THD *thd, size_t table_cnt=2)
 Nest last join operations. More...
 
bool add_joined_table (TABLE_LIST *table)
 Add a table to the current join list. More...
 
mem_root_deque< Item * > * get_fields_list ()
 
auto visible_fields ()
 Wrappers over fields / get_fields_list() that hide items where item->hidden, meant for range-based for loops. More...
 
auto visible_fields () const
 
bool check_view_privileges (THD *thd, ulong want_privilege_first, ulong want_privilege_next)
 Check privileges for views that are merged into query block. More...
 
bool check_column_privileges (THD *thd)
 Check privileges for all columns referenced from query block. More...
 
bool check_privileges_for_subqueries (THD *thd)
 Check privileges for column references in subqueries of a query block. More...
 
bool setup_tables (THD *thd, TABLE_LIST *tables, bool select_insert)
 Resolve and prepare information about tables for one query block. More...
 
bool resolve_limits (THD *thd)
 Resolve OFFSET and LIMIT clauses. More...
 
bool resolve_placeholder_tables (THD *thd, bool apply_semijoin)
 Resolve derived table, view, table function information for a query block. More...
 
void propagate_unique_test_exclusion ()
 Propagate exclusion from table uniqueness test into subqueries. More...
 
void merge_contexts (Query_block *inner)
 Merge name resolution context objects of a subquery into its parent. More...
 
bool merge_derived (THD *thd, TABLE_LIST *derived_table)
 Merge derived table into query block. More...
 
bool flatten_subqueries (THD *thd)
 Convert semi-join subquery predicates into semi-join join nests. More...
 
void update_semijoin_strategies (THD *thd)
 Update available semijoin strategies for semijoin nests. More...
 
Subquery_strategy subquery_strategy (const THD *thd) const
 Returns which subquery execution strategies can be used for this query block. More...
 
bool semijoin_enabled (const THD *thd) const
 Returns whether semi-join is enabled for this query block. More...
 
void set_sj_candidates (Mem_root_array< Item_exists_subselect * > *sj_cand)
 
bool has_sj_candidates () const
 
bool add_ftfunc_list (List< Item_func_match > *ftfuncs)
 Add full-text function elements from a list into this query block. More...
 
void set_lock_for_table (const Lock_descriptor &descriptor, TABLE_LIST *table)
 
void set_lock_for_tables (thr_lock_type lock_type)
 Set lock for all tables in current query block. More...
 
void init_order ()
 
void cut_subtree ()
 
bool test_limit ()
 
ha_rows get_offset (THD *thd)
 Get offset for LIMIT. More...
 
ha_rows get_limit (THD *thd)
 Get limit. More...
 
bool set_context (Name_resolution_context *outer_context)
 Assign a default name resolution object for this query block. More...
 
bool setup_base_ref_items (THD *thd)
 Setup the array containing references to base items. More...
 
void print (const THD *thd, String *str, enum_query_type query_type)
 
void print_query_block (const THD *thd, String *str, enum_query_type query_type)
 Print detail of the Query_block object. More...
 
void print_update (const THD *thd, String *str, enum_query_type query_type)
 Print detail of the UPDATE statement. More...
 
void print_delete (const THD *thd, String *str, enum_query_type query_type)
 Print detail of the DELETE statement. More...
 
void print_insert (const THD *thd, String *str, enum_query_type query_type)
 Print detail of the INSERT statement. More...
 
void print_hints (const THD *thd, String *str, enum_query_type query_type)
 Print detail of Hints. More...
 
bool print_error (const THD *thd, String *str)
 Print error. More...
 
void print_select_options (String *str)
 Print select options. More...
 
void print_update_options (String *str)
 Print UPDATE options. More...
 
void print_delete_options (String *str)
 Print DELETE options. More...
 
void print_insert_options (String *str)
 Print INSERT options. More...
 
void print_table_references (const THD *thd, String *str, TABLE_LIST *table_list, enum_query_type query_type)
 Print list of tables. More...
 
void print_item_list (const THD *thd, String *str, enum_query_type query_type)
 Print list of items in Query_block object. More...
 
void print_update_list (const THD *thd, String *str, enum_query_type query_type, const mem_root_deque< Item * > &fields, const mem_root_deque< Item * > &values)
 Print assignments list. More...
 
void print_insert_fields (const THD *thd, String *str, enum_query_type query_type)
 Print column list to be inserted into. More...
 
void print_values (const THD *thd, String *str, enum_query_type query_type, const mem_root_deque< mem_root_deque< Item * > * > &values, const char *prefix)
 Print list of values, used in INSERT and for general VALUES clause. More...
 
void print_from_clause (const THD *thd, String *str, enum_query_type query_type)
 Print list of tables in FROM clause. More...
 
void print_where_cond (const THD *thd, String *str, enum_query_type query_type)
 Print list of conditions in WHERE clause. More...
 
void print_group_by (const THD *thd, String *str, enum_query_type query_type)
 Print list of items in GROUP BY clause. More...
 
void print_having (const THD *thd, String *str, enum_query_type query_type)
 Print list of items in HAVING clause. More...
 
void print_windows (const THD *thd, String *str, enum_query_type query_type)
 Print details of Windowing functions. More...
 
void print_order_by (const THD *thd, String *str, enum_query_type query_type)
 Print list of items in ORDER BY clause. More...
 
void print_limit (const THD *thd, String *str, enum_query_type query_type)
 
bool save_properties (THD *thd)
 Save properties of a prepared statement needed for repeated optimization. More...
 
bool accept (Select_lex_visitor *visitor)
 Accept function for SELECT and DELETE. More...
 
void cleanup (THD *thd, bool full)
 Cleanup this subtree (this Query_block and all nested Query_blockes and Query_expressions). More...
 
void cleanup_all_joins ()
 
void destroy ()
 Destroy contained objects, in particular temporary tables which may have their own mem_roots. More...
 
bool is_part_of_union () const
 Return true if this query block is part of a UNION. More...
 
bool is_empty_query () const
 
void set_empty_query ()
 Set query block as returning no data. More...
 
bool agg_func_used () const
 
bool json_agg_func_used () const
 
void set_agg_func_used (bool val)
 
void set_json_agg_func_used (bool val)
 
bool right_joins () const
 
void set_right_joins ()
 
enum_explain_type type ()
 Lookup for Query_block type. More...
 
const char * get_type_str ()
 Lookup for a type string. More...
 
bool is_dependent () const
 
bool is_cacheable () const
 
bool source_table_is_one_row () const
 
void include_down (LEX *lex, Query_expression *outer)
 Include query block inside a query expression. More...
 
void include_neighbour (LEX *lex, Query_block *before)
 Include a query block next to another query block. More...
 
void include_standalone (Query_expression *sel, Query_block **ref)
 Include query block inside a query expression, but do not link. More...
 
void include_in_global (Query_block **plink)
 Include query block into global list. More...
 
void include_chain_in_global (Query_block **start)
 Include chain of query blocks into global list. More...
 
void renumber (LEX *lex)
 Renumber query blocks of contained query expressions. More...
 
bool apply_local_transforms (THD *thd, bool prune)
 Does permanent transformations which are local to a query block (which do not merge it to another block). More...
 
bool push_conditions_to_derived_tables (THD *thd)
 Pushes parts of the WHERE condition of this query block to materialized derived tables. More...
 
bool get_optimizable_conditions (THD *thd, Item **new_where, Item **new_having)
 Returns disposable copies of WHERE/HAVING/ON conditions. More...
 
bool validate_outermost_option (LEX *lex, const char *wrong_option) const
 Check if an option that can be used only for an outer-most query block is applicable to this query block. More...
 
bool validate_base_options (LEX *lex, ulonglong options) const
 Validate base options for a query block. More...
 
bool walk (Item_processor processor, enum_walk walk, uchar *arg)
 
bool add_tables (THD *thd, const Mem_root_array< Table_ident * > *tables, ulong table_options, thr_lock_type lock_type, enum_mdl_type mdl_type)
 Add tables from an array to a list of used tables. More...
 
bool resolve_rollup_wfs (THD *thd)
 Replace group by field references inside window functions with references in the presence of ROLLUP. More...
 
bool setup_conds (THD *thd)
 Resolve WHERE condition and join conditions. More...
 
bool prepare (THD *thd, mem_root_deque< Item * > *insert_field_list)
 Prepare query block for optimization. More...
 
bool optimize (THD *thd, bool finalize_access_paths)
 Optimize a query block and all inner query expressions. More...
 
void reset_nj_counters (mem_root_deque< TABLE_LIST * > *join_list=nullptr)
 Set NESTED_JOIN::counter=0 in all nested joins in passed list. More...
 
bool change_group_ref_for_func (THD *thd, Item *func, bool *changed)
 
bool change_group_ref_for_cond (THD *thd, Item_cond *cond, bool *changed)
 
Itemsingle_visible_field () const
 
size_t num_visible_fields () const
 
bool field_list_is_empty () const
 
void remove_hidden_fields ()
 
void update_used_tables ()
 Update used tables information for all local expressions. More...
 
void restore_cmd_properties ()
 Restore prepared statement properties for this query block and all underlying query expressions so they are ready for optimization. More...
 
bool save_cmd_properties (THD *thd)
 Save prepared statement properties for a query block and underlying query expressions. More...
 

Static Public Member Functions

static void print_order (const THD *thd, String *str, ORDER *order, enum_query_type query_type)
 
static const char * get_type_str (enum_explain_type type)
 

Public Attributes

size_t m_added_non_hidden_fields {0}
 
mem_root_deque< Item * > fields
 All expressions needed after join and filtering, ie., select list, group by list, having clause, window clause, order by clause, including hidden fields. More...
 
List< Windowm_windows
 All windows defined on the select, both named and inlined. More...
 
List< Item_func_match > * ftfunc_list
 Usually a pointer to ftfunc_list_alloc, but in UNION this is used to create fake query_block that consolidates result fields of UNION. More...
 
List< Item_func_matchftfunc_list_alloc {}
 
mem_root_deque< mem_root_deque< Item * > * > * row_value_list {nullptr}
 The VALUES items of a table value constructor. More...
 
mem_root_deque< TABLE_LIST * > sj_nests
 List of semi-join nests generated for this query block. More...
 
SQL_I_List< TABLE_LISTtable_list {}
 List of tables in FROM clause - use TABLE_LIST::next_local to traverse. More...
 
SQL_I_List< ORDERorder_list {}
 ORDER BY clause. More...
 
Group_list_ptrsorder_list_ptrs {nullptr}
 
SQL_I_List< ORDERgroup_list {}
 GROUP BY clause. More...
 
Group_list_ptrsgroup_list_ptrs {nullptr}
 
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
 
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
 
Opt_hints_qbopt_hints_qb {nullptr}
 Query-block-level hints, for this query block. More...
 
char * db {nullptr}
 
TABLE_LISTrecursive_reference {nullptr}
 If this query block is a recursive member of a recursive unit: the TABLE_LIST, in this recursive member, referencing the query name. More...
 
LEXparent_lex {nullptr}
 Reference to LEX that this query block belongs to. More...
 
table_map select_list_tables {0}
 The set of those tables whose fields are referenced in the select list of this select level. More...
 
table_map outer_join {0}
 Bitmap of all inner tables from outer joins. More...
 
Name_resolution_context context {}
 Context for name resolution for all column references except columns from joined tables. More...
 
Name_resolution_contextfirst_context
 Pointer to first object in list of Name res context objects that have this query block as the base query block. More...
 
JOINjoin {nullptr}
 After optimization it is pointer to corresponding JOIN. More...
 
mem_root_deque< TABLE_LIST * > top_join_list
 join list of the top level More...
 
mem_root_deque< TABLE_LIST * > * join_list
 list for the currently parsed join More...
 
TABLE_LISTembedding {nullptr}
 table embedding the above list More...
 
TABLE_LISTleaf_tables {nullptr}
 Points to first leaf table of query block. More...
 
TABLE_LISTend_lateral_table {nullptr}
 
Itemselect_limit {nullptr}
 LIMIT clause, NULL if no limit is given. More...
 
Itemoffset_limit {nullptr}
 LIMIT ... OFFSET clause, NULL if no offset is given. More...
 
Item_suminner_sum_func_list {nullptr}
 Circular linked list of aggregate functions in nested query blocks. More...
 
Ref_item_array base_ref_items
 Array of pointers to "base" items; one each for every selected expression and referenced item in the query block. More...
 
uint select_number {0}
 Query block number (used for EXPLAIN) More...
 
Item::cond_result cond_value {Item::COND_UNDEF}
 Saved values of the WHERE and HAVING clauses. More...
 
Item::cond_result having_value {Item::COND_UNDEF}
 
enum_parsing_context parsing_place {CTX_NONE}
 Parse context: indicates where the current expression is being parsed. More...
 
uint in_sum_expr {0}
 Parse context: is inside a set function if this is positive. More...
 
Resolve_place resolve_place
 Indicates part of query being resolved. More...
 
uint select_n_where_fields {0}
 Number of fields used in select list or where clause of current select and all inner subselects. More...
 
uint select_n_having_items {0}
 number of items in select_list and HAVING clause used to get number bigger then can be number of entries that will be added to all item list during split_sum_func More...
 
uint cond_count {0}
 number of arguments of and/or/xor in where/having/on More...
 
uint between_count {0}
 number of between predicates in where/having/on More...
 
uint max_equal_elems
 maximal number of elements in multiple equalities More...
 
uint n_sum_items {0}
 Number of Item_sum-derived objects in this SELECT. More...
 
uint n_child_sum_items {0}
 Number of Item_sum-derived objects in children and descendant SELECTs. More...
 
uint n_scalar_subqueries {0}
 Keep track for allocation of base_ref_items: scalar subqueries may be replaced by a field during scalar_to_derived transformation. More...
 
uint materialized_derived_table_count {0}
 Number of materialized derived tables and views in this query block. More...
 
uint partitioned_table_count {0}
 Number of partitioned tables. More...
 
uint with_wild {0}
 Number of wildcards used in the SELECT list. More...
 
uint leaf_table_count {0}
 Number of leaf tables in this query block. More...
 
uint derived_table_count {0}
 Number of derived tables and views in this query block. More...
 
uint table_func_count {0}
 Number of table functions in this query block. More...
 
int nest_level {0}
 Nesting level of query block, outer-most query block has level 0, its subqueries have level 1, etc. More...
 
olap_type olap {UNSPECIFIED_OLAP_TYPE}
 Indicates whether this query block contains the WITH ROLLUP clause. More...
 
enum_condition_context condition_context {enum_condition_context::ANDS}
 
bool is_table_value_constructor {false}
 If set, the query block is of the form VALUES row_list. More...
 
sub_select_type linkage {UNSPECIFIED_TYPE}
 Describes context of this query block (e.g if it is a derived table). More...
 
uint8 uncacheable {0}
 result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCACHEABLE_SIDEEFFECT More...
 
bool first_execution {true}
 This variable is required to ensure proper work of subqueries and stored procedures. More...
 
bool sj_pullout_done {false}
 True when semi-join pull-out processing is complete. More...
 
bool m_was_implicitly_grouped {false}
 Used by nested scalar_to_derived transformations. More...
 
bool skip_local_transforms {false}
 True: skip local transformations during prepare() call (used by INSERT) More...
 
bool is_item_list_lookup {false}
 
bool having_fix_field {false}
 true when having fix field called in processing of this query block More...
 
bool group_fix_field {false}
 true when GROUP BY fix field called in processing of this query block More...
 
bool with_sum_func {false}
 True if contains or aggregates set functions. More...
 
bool subquery_in_having {false}
 HAVING clause contains subquery => we can't close tables before query processing end even if we use temporary table. More...
 
bool m_use_select_limit {false}
 If true, use select_limit to limit number of rows selected. More...
 
bool m_internal_limit {false}
 If true, limit object is added internally. More...
 
bool exclude_from_table_unique_test {false}
 exclude this query block from unique_table() check More...
 
bool no_table_names_allowed {false}
 used for global order by More...
 
uint hidden_items_from_optimization {0}
 Hidden items added during optimization. More...
 

Private Member Functions

bool save_order_properties (THD *thd, SQL_I_List< ORDER > *list, Group_list_ptrs **list_ptrs)
 Helper for save_properties() More...
 
bool record_join_nest_info (mem_root_deque< TABLE_LIST * > *tables)
 Record join nest info in the select block. More...
 
bool simplify_joins (THD *thd, mem_root_deque< TABLE_LIST * > *join_list, bool top, bool in_sj, Item **new_conds, uint *changelog=nullptr)
 Simplify joins replacing outer joins by inner joins whenever it's possible. More...
 
void clear_sj_expressions (NESTED_JOIN *nested_join)
 Remove semijoin condition for this query block. More...
 
bool build_sj_cond (THD *thd, NESTED_JOIN *nested_join, Query_block *subq_query_block, table_map outer_tables_map, Item **sj_cond)
 Build semijoin condition for th query block. More...
 
bool decorrelate_condition (Semijoin_decorrelation &sj_decor, TABLE_LIST *join_nest)
 Decorrelate the WHERE clause or a join condition of a subquery used in an IN or EXISTS predicate. More...
 
bool convert_subquery_to_semijoin (THD *thd, Item_exists_subselect *subq_pred)
 Convert a subquery predicate of this query block into a TABLE_LIST semi-join nest. More...
 
TABLE_LISTsynthesize_derived (THD *thd, Query_expression *unit, Item *join_cond, bool left_outer, bool use_inner_join)
 Create a new TABLE_LIST object for this query block, for either: 1) a derived table which will replace the subquery, or 2) an extra derived table for handling grouping, if necessary, cf. More...
 
bool transform_subquery_to_derived (THD *thd, TABLE_LIST **out_tl, Query_expression *subs_query_expression, Item_subselect *subq, bool use_inner_join, bool reject_multiple_rows, Item *join_condition, Item *lifted_where_cond)
 Converts a subquery to a derived table and inserts it into the FROM clause of the owning query block. More...
 
bool transform_table_subquery_to_join_with_derived (THD *thd, Item_exists_subselect *subq_pred)
 Replace a table subquery ([NOT] {IN, EXISTS}) with a join to a derived table. More...
 
bool decorrelate_derived_scalar_subquery_pre (THD *thd, TABLE_LIST *derived, Item *lifted_where, Lifted_fields_map *lifted_where_fields, bool *added_card_check)
 We have a correlated scalar subquery, so we must do several things: More...
 
bool decorrelate_derived_scalar_subquery_post (THD *thd, TABLE_LIST *derived, Lifted_fields_map *lifted_where_fields, bool added_card_check)
 See explanation in companion method decorrelate_derived_scalar_subquery_pre. More...
 
void remap_tables (THD *thd)
 Re-map table numbers for all tables in a query block. More...
 
bool resolve_subquery (THD *thd)
 Resolve predicate involving subquery. More...
 
void mark_item_as_maybe_null_if_rollup_item (Item *item)
 Marks occurrences of group by fields in a function's arguments as nullable, so that we do not optimize them away before we get to add the rollup wrappers. More...
 
Itemresolve_rollup_item (THD *thd, Item *item)
 Resolve an item (and its tree) for rollup processing by replacing items matching grouped expressions with Item_rollup_group_items and updating properties (m_nullable, PROP_ROLLUP_FIELD). More...
 
bool resolve_rollup (THD *thd)
 Resolve items in SELECT list and ORDER BY list for rollup processing. More...
 
bool setup_wild (THD *thd)
 Expand all '*' in list of expressions with the matching column references. More...
 
bool setup_order_final (THD *thd)
 Do final setup of ORDER BY clause, after the query block is fully resolved. More...
 
bool setup_group (THD *thd)
 Resolve and set up the GROUP BY list. More...
 
void fix_after_pullout (Query_block *parent_query_block, Query_block *removed_query_block)
 
void remove_redundant_subquery_clauses (THD *thd, int hidden_group_field_count)
 For a table subquery predicate (IN/ANY/ALL/EXISTS/etc): since it does not support LIMIT the following clauses are redundant: More...
 
void repoint_contexts_of_join_nests (mem_root_deque< TABLE_LIST * > join_list)
 Go through a list of tables and join nests, recursively, and repoint its query_block pointer. More...
 
void empty_order_list (Query_block *sl)
 Empty the ORDER list. More...
 
bool setup_join_cond (THD *thd, mem_root_deque< TABLE_LIST * > *tables, bool in_update)
 Resolve join conditions for a join nest. More...
 
bool find_common_table_expr (THD *thd, Table_ident *table_id, TABLE_LIST *tl, Parse_context *pc, bool *found)
 Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl', and the matched with-list-element. More...
 
bool transform_scalar_subqueries_to_join_with_derived (THD *thd)
 Transform eligible scalar subqueries in the SELECT list, WHERE condition, HAVING condition or JOIN conditions of a query block[*] to an equivalent derived table of a LEFT OUTER join, e.g. More...
 
bool supported_correlated_scalar_subquery (THD *thd, Item::Css_info *subquery, Item **lifted_where)
 Called when the scalar subquery is correlated. More...
 
bool transform_grouped_to_derived (THD *thd, bool *break_off)
 Minion of transform_scalar_subqueries_to_join_with_derived. More...
 
bool replace_subquery_in_expr (THD *thd, Item::Css_info *subquery, TABLE_LIST *tr, Item **expr)
 A minion of transform_scalar_subqueries_to_join_with_derived. More...
 
bool nest_derived (THD *thd, Item *join_cond, mem_root_deque< TABLE_LIST * > *join_list, TABLE_LIST *new_derived_table)
 Push the generated derived table to the correct location inside a join nest. More...
 
bool resolve_table_value_constructor_values (THD *thd)
 Resolve the rows of a table value constructor and aggregate the type of each column across rows. More...
 
void delete_unused_merged_columns (mem_root_deque< TABLE_LIST * > *tables)
 Delete unused columns from merged tables. More...
 
void fix_prepare_information_for_order (THD *thd, SQL_I_List< ORDER > *list, Group_list_ptrs **list_ptrs)
 Helper for fix_prepare_information() More...
 
bool prepare_values (THD *thd)
 Prepare a table value constructor query block for optimization. More...
 
bool check_only_full_group_by (THD *thd)
 Runs checks mandated by ONLY_FULL_GROUP_BY. More...
 
bool is_row_count_valid_for_semi_join ()
 Check if the offset and limit are valid for a semijoin. More...
 

Private Attributes

Mem_root_array< Item_exists_subselect * > * sj_candidates {nullptr}
 Pointer to collection of subqueries candidate for semi/antijoin conversion. More...
 
int hidden_order_field_count {0}
 How many expressions are part of the order by but not select list. More...
 
Query_blocknext {nullptr}
 Intrusive double-linked list of all query blocks within the same query expression. More...
 
Query_block ** prev {nullptr}
 
Query_expressionmaster {nullptr}
 The query expression containing this query block. More...
 
Query_expressionslave {nullptr}
 The first query expression contained within this query block. More...
 
Query_blocklink_next {nullptr}
 Intrusive double-linked global list of query blocks. More...
 
Query_block ** link_prev {nullptr}
 
Query_resultm_query_result {nullptr}
 Result of this query block. More...
 
ulonglong m_base_options {0}
 Options assigned from parsing and throughout resolving, should not be modified after resolving is done. More...
 
ulonglong m_active_options {0}
 Active options. More...
 
TABLE_LISTresolve_nest
 Used when resolving outer join condition. More...
 
Itemm_where_cond
 Condition to be evaluated after all tables in a query block are joined. More...
 
Itemm_having_cond
 Condition to be evaluated on grouped rows after grouping. More...
 
int hidden_group_field_count
 Number of GROUP BY expressions added to all_fields. More...
 
bool has_sj_nests {false}
 True if query block has semi-join nests merged into it. More...
 
bool has_aj_nests {false}
 
bool m_right_joins {false}
 True if query block has right joins. More...
 
bool allow_merge_derived {true}
 Allow merge of immediate unnamed derived tables. More...
 
bool m_agg_func_used {false}
 
bool m_json_agg_func_used {false}
 
bool m_empty_query {false}
 True if query block does not generate any rows before aggregation, determined during preparation (not optimization). More...
 

Static Private Attributes

static const char * type_str [static_cast< int >(enum_explain_type::EXPLAIN_total)]
 

Friends

class Query_expression
 
class Condition_context
 

Detailed Description

This class represents a query block, aka a query specification, which is a query consisting of a SELECT keyword, followed by a table list, optionally followed by a WHERE clause, a GROUP BY, etc.

Member Enumeration Documentation

◆ Resolve_place

Three fields used by semi-join transformations to know when semi-join is possible, and in which condition tree the subquery predicate is located.

Enumerator
RESOLVE_NONE 
RESOLVE_JOIN_NEST 
RESOLVE_CONDITION 
RESOLVE_HAVING 
RESOLVE_SELECT_LIST 

Constructor & Destructor Documentation

◆ Query_block()

Query_block::Query_block ( MEM_ROOT mem_root,
Item where,
Item having 
)

Construct and initialize Query_block object.

@note the group_by and order_by lists below will probably be added to the
      constructor when the parser is converted into a true bottom-up design.

SQL_I_LIST<ORDER> *group_by, SQL_I_LIST<ORDER> order_by

Member Function Documentation

◆ accept()

bool Query_block::accept ( Select_lex_visitor visitor)

Accept function for SELECT and DELETE.

Parameters
visitorSelect_lex_visitor Object

◆ active_options()

ulonglong Query_block::active_options ( ) const
inline
Returns
the active query options

◆ add_active_options()

void Query_block::add_active_options ( ulonglong  options)
inline

Adjust the active option set.

◆ add_base_options()

void Query_block::add_base_options ( ulonglong  options)
inline

Add base options to a query block, also update active options.

◆ add_ftfunc_to_list()

bool Query_block::add_ftfunc_to_list ( Item_func_match func)

◆ add_item_to_list()

bool Query_block::add_item_to_list ( Item item)

◆ add_order_to_list()

void Query_block::add_order_to_list ( ORDER order)

◆ add_tables()

bool Query_block::add_tables ( THD thd,
const Mem_root_array< Table_ident * > *  tables,
ulong  table_options,
thr_lock_type  lock_type,
enum_mdl_type  mdl_type 
)

Add tables from an array to a list of used tables.

Parameters
thdCurrent session.
tablesTables to add.
table_optionsA set of the following bits:
  • TL_OPTION_UPDATING : Table will be updated,
  • TL_OPTION_FORCE_INDEX : Force usage of index,
  • TL_OPTION_ALIAS : an alias in multi table DELETE.
lock_typeHow table should be locked.
mdl_typeType of metadata lock to acquire on the table.
Returns
true if error (reported), otherwise false.

◆ agg_func_used()

bool Query_block::agg_func_used ( ) const
inline

◆ all_tables_map()

table_map Query_block::all_tables_map ( ) const
inline
Returns
a map of all tables references in the query block

◆ can_skip_distinct()

bool Query_block::can_skip_distinct ( ) const
inline

Based on the structure of the query at resolution time, it is possible to conclude that DISTINCT is useless and remove it.

This is the case if:

  • all GROUP BY expressions are in SELECT list, so resulting group rows are distinct,
  • and ROLLUP is not specified, so it adds no row for NULLs.
Returns
true if we can remove DISTINCT.

◆ change_group_ref_for_cond()

bool Query_block::change_group_ref_for_cond ( THD thd,
Item_cond cond,
bool *  changed 
)

◆ change_group_ref_for_func()

bool Query_block::change_group_ref_for_func ( THD thd,
Item func,
bool *  changed 
)

◆ cleanup()

void Query_block::cleanup ( THD thd,
bool  full 
)

Cleanup this subtree (this Query_block and all nested Query_blockes and Query_expressions).

Cleanup after preparation of one round of execution.

Parameters
thdthread handle
fullif false only partial cleanup is done, JOINs and JOIN_TABs are kept to provide info for EXPLAIN CONNECTION; if true, complete cleanup is done, all JOINs are freed.
Returns
false if previous execution was successful, and true otherwise

◆ cleanup_all_joins()

void Query_block::cleanup_all_joins ( )

◆ cut_subtree()

void Query_block::cut_subtree ( )
inline

◆ destroy()

void Query_block::destroy ( )

Destroy contained objects, in particular temporary tables which may have their own mem_roots.

◆ find_table_by_name()

TABLE_LIST * Query_block::find_table_by_name ( const Table_ident ident)

Finds a (possibly unresolved) table reference in the from clause by name.

There is a hack in the parser which adorns table references with the current database. This function piggy-backs on that hack to find fully qualified table references without having to resolve the name.

Parameters
identThe table name, may be qualified or unqualified.
Return values
NULLIf not found.

◆ first_inner_query_expression()

Query_expression* Query_block::first_inner_query_expression ( ) const
inline

◆ fix_prepare_information_for_order()

void Query_block::fix_prepare_information_for_order ( THD thd,
SQL_I_List< ORDER > *  list,
Group_list_ptrs **  list_ptrs 
)
private

Helper for fix_prepare_information()

◆ get_fields_list()

mem_root_deque<Item *>* Query_block::get_fields_list ( )
inline

◆ get_in_sum_expr()

uint Query_block::get_in_sum_expr ( ) const
inline

◆ get_limit()

ha_rows Query_block::get_limit ( THD thd)

Get limit.

Evaluate limit item if necessary.

Returns
Limit of rows in result.

◆ get_offset()

ha_rows Query_block::get_offset ( THD thd)

Get offset for LIMIT.

Evaluate offset item if necessary.

Returns
Number of rows to skip.

◆ get_optimizable_conditions()

bool Query_block::get_optimizable_conditions ( THD thd,
Item **  new_where,
Item **  new_having 
)

Returns disposable copies of WHERE/HAVING/ON conditions.

This function returns a copy which can be thrashed during this execution of the statement. Only AND/OR items are trashable! If in conventional execution, no copy is created, the permanent clauses are returned instead, as trashing them is no problem.

Parameters
thdthread handle
[out]new_wherecopy of WHERE
[out]new_havingcopy of HAVING (if passed pointer is not NULL)

Copies of join (ON) conditions are placed in TABLE_LIST::m_join_cond_optim.

Returns
true if OOM

◆ get_table_list()

TABLE_LIST* Query_block::get_table_list ( ) const
inline

◆ get_type_str() [1/2]

const char* Query_block::get_type_str ( )
inline

Lookup for a type string.

◆ get_type_str() [2/2]

static const char* Query_block::get_type_str ( enum_explain_type  type)
inlinestatic

◆ has_ft_funcs()

bool Query_block::has_ft_funcs ( ) const
inline
Returns
true if query block references full-text functions

◆ has_limit()

bool Query_block::has_limit ( ) const
inline
Returns
true if this query block has a LIMIT clause

◆ has_sj_candidates()

bool Query_block::has_sj_candidates ( ) const
inline

◆ has_windows()

bool Query_block::has_windows ( ) const
inline
Returns
true if query block contains window functions

◆ having_cond()

Item* Query_block::having_cond ( ) const
inline

◆ having_cond_ref()

Item** Query_block::having_cond_ref ( )
inline

◆ include_chain_in_global()

void Query_block::include_chain_in_global ( Query_block **  start)

Include chain of query blocks into global list.

Parameters
start- Pointer to start of list

◆ include_down()

void Query_block::include_down ( LEX lex,
Query_expression outer 
)

Include query block inside a query expression.

Add this query block below the specified query expression.

Parameters
lexContaining LEX object
outerQuery expression that query block is added to.
Note
that this query block can never have any underlying query expressions, hence it is not necessary to e.g. renumber those, like e.g. Query_expression::include_down() does.

◆ include_in_global()

void Query_block::include_in_global ( Query_block **  plink)

Include query block into global list.

Parameters
plink- Pointer to start of list

◆ include_neighbour()

void Query_block::include_neighbour ( LEX lex,
Query_block before 
)

Include a query block next to another query block.

Add this query block after the specified query block.

Parameters
lexContaining LEX object
beforeQuery block that this object is added after.

◆ include_standalone()

void Query_block::include_standalone ( Query_expression outer,
Query_block **  ref 
)

Include query block inside a query expression, but do not link.

Include query block within the supplied unit.

Do not link the query block into the global chain of query blocks.

This function is exclusive for Query_expression::add_fake_query_block() - use it with caution.

Parameters
outerQuery expression this node is included below.
refHandle to the caller's pointer to this node.

◆ init_order()

void Query_block::init_order ( )
inline

◆ invalidate()

void Query_block::invalidate ( )

Invalidate by nulling out pointers to other Query_expressions and Query_blockes.

◆ is_cacheable()

bool Query_block::is_cacheable ( ) const
inline

◆ is_dependent()

bool Query_block::is_dependent ( ) const
inline

◆ is_distinct()

bool Query_block::is_distinct ( ) const
inline
Returns
true if this query block contains DISTINCT at start of select list

◆ is_empty_query()

bool Query_block::is_empty_query ( ) const
inline
Returns
true if query block is found during preparation to produce no data. Notice that if query is implicitly grouped, an aggregation row will still be returned.

◆ is_explicitly_grouped()

bool Query_block::is_explicitly_grouped ( ) const
inline
Returns
true if query block is explicitly grouped (non-empty GROUP BY)

◆ is_grouped()

bool Query_block::is_grouped ( ) const
inline
Returns
true if this query block is explicitly or implicitly grouped.
Note
a query with DISTINCT is not considered to be aggregated.
in standard SQL, a query with HAVING is defined as grouped, however MySQL allows HAVING without any aggregation to be the same as WHERE.

◆ is_implicitly_grouped()

bool Query_block::is_implicitly_grouped ( ) const
inline
Returns
true if this query block is implicitly grouped, ie it is not explicitly grouped but contains references to set functions. The query will return max. 1 row (
See also
also is_single_grouped()).

◆ is_ordered()

bool Query_block::is_ordered ( ) const
inline
Returns
true if this query block contains an ORDER BY clause.
Note
returns false if ORDER BY has been eliminated, e.g if the query can return max. 1 row.

◆ is_part_of_union()

bool Query_block::is_part_of_union ( ) const
inline

Return true if this query block is part of a UNION.

◆ is_recursive()

bool Query_block::is_recursive ( ) const
inline
Returns
true if query block is a recursive member of a recursive unit

◆ is_single_grouped()

bool Query_block::is_single_grouped ( ) const
inline

True if this query block is implicitly grouped.

Note
Not reliable before name resolution.
Returns
true if this query block is implicitly grouped and returns exactly one row, which happens when it does not have a HAVING clause.
Remarks
This function is currently unused.

◆ is_straight_join()

bool Query_block::is_straight_join ( )
inline
Returns
true If STRAIGHT_JOIN applies to all tables.
false Else.

false for exmaple in t1 STRAIGHT_JOIN t2 JOIN t3.

◆ json_agg_func_used()

bool Query_block::json_agg_func_used ( ) const
inline

◆ last_query_block()

Query_block* Query_block::last_query_block ( )
inline

◆ make_active_options()

void Query_block::make_active_options ( ulonglong  added_options,
ulonglong  removed_options 
)

Make active options from base options, supplied options and environment:

Make active options from base options, supplied options, any statement options and the environment.

Parameters
added_optionsOptions that are added to the active options
removed_optionsOptions that are removed from the active options

◆ mark_as_dependent()

void Query_block::mark_as_dependent ( Query_block last,
bool  aggregate 
)

Mark all query blocks from this to 'last' as dependent.

Parameters
lastPointer to last Query_block struct, before which all Query_block are marked as as dependent.
aggregatetrue if the dependency is due to a set function, such as COUNT(*), which is aggregated within the query block 'last'. Such functions must have a dependency on all tables of the aggregating query block.
Note
last should be reachable from this Query_block

◆ master_query_expression()

Query_expression* Query_block::master_query_expression ( ) const
inline

◆ next_query_block()

Query_block* Query_block::next_query_block ( ) const
inline

◆ next_select_in_list()

Query_block* Query_block::next_select_in_list ( ) const
inline

◆ outer_query_block()

Query_block* Query_block::outer_query_block ( ) const
inline

◆ print()

void Query_block::print ( const THD thd,
String str,
enum_query_type  query_type 
)

◆ print_delete()

void Query_block::print_delete ( const THD thd,
String str,
enum_query_type  query_type 
)

Print detail of the DELETE statement.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

◆ print_delete_options()

void Query_block::print_delete_options ( String str)

Print DELETE options.

Parameters
[out]strString of output

◆ print_error()

bool Query_block::print_error ( const THD thd,
String str 
)

Print error.

Parameters
thdThread handler
[out]strString of output
Return values
falseIf there is no error
trueelse

◆ print_from_clause()

void Query_block::print_from_clause ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of tables in FROM clause.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

◆ print_group_by()

void Query_block::print_group_by ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of items in GROUP BY clause.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output

◆ print_having()

void Query_block::print_having ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of items in HAVING clause.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output

◆ print_hints()

void Query_block::print_hints ( const THD thd,
String str,
enum_query_type  query_type 
)

Print detail of Hints.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

◆ print_insert()

void Query_block::print_insert ( const THD thd,
String str,
enum_query_type  query_type 
)

Print detail of the INSERT statement.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

USES: 'INSERT INTO table (fields) VALUES values' syntax over 'INSERT INTO table SET field = value, ...'

◆ print_insert_fields()

void Query_block::print_insert_fields ( const THD thd,
String str,
enum_query_type  query_type 
)

Print column list to be inserted into.

Used in INSERT.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output

◆ print_insert_options()

void Query_block::print_insert_options ( String str)

Print INSERT options.

Parameters
[out]strString of output

◆ print_item_list()

void Query_block::print_item_list ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of items in Query_block object.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output
Note
that 'INTO variable' clauses are not printed

◆ print_limit()

void Query_block::print_limit ( const THD thd,
String str,
enum_query_type  query_type 
)

◆ print_order()

void Query_block::print_order ( const THD thd,
String str,
ORDER order,
enum_query_type  query_type 
)
static

◆ print_order_by()

void Query_block::print_order_by ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of items in ORDER BY clause.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output

◆ print_query_block()

void Query_block::print_query_block ( const THD thd,
String str,
enum_query_type  query_type 
)

Print detail of the Query_block object.

Parameters
thdThread handler
query_typeOptions to print out string output
[out]strString of output.

◆ print_select_options()

void Query_block::print_select_options ( String str)

Print select options.

Parameters
[out]strString of output

◆ print_table_references()

void Query_block::print_table_references ( const THD thd,
String str,
TABLE_LIST table_list,
enum_query_type  query_type 
)

Print list of tables.

Parameters
thdThread handler
[out]strString of output
table_listTABLE_LIST object
query_typeOptions to print out string output

◆ print_update()

void Query_block::print_update ( const THD thd,
String str,
enum_query_type  query_type 
)

Print detail of the UPDATE statement.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

◆ print_update_list()

void Query_block::print_update_list ( const THD thd,
String str,
enum_query_type  query_type,
const mem_root_deque< Item * > &  fields,
const mem_root_deque< Item * > &  values 
)

Print assignments list.

Used in UPDATE and INSERT ... ON DUPLICATE KEY UPDATE ...

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output
fieldsList columns to be assigned.
valuesList of values.

◆ print_update_options()

void Query_block::print_update_options ( String str)

Print UPDATE options.

Parameters
[out]strString of output

◆ print_values()

void Query_block::print_values ( const THD thd,
String str,
enum_query_type  query_type,
const mem_root_deque< mem_root_deque< Item * > * > &  values,
const char *  prefix 
)

Print list of values, used in INSERT and for general VALUES clause.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output
valuesList of values
prefixPrefix to print before each row in value list = nullptr: No prefix wanted

◆ print_where_cond()

void Query_block::print_where_cond ( const THD thd,
String str,
enum_query_type  query_type 
)

Print list of conditions in WHERE clause.

Parameters
thdThread handle
[out]strString of output
query_typeOptions to print out string output

◆ print_windows()

void Query_block::print_windows ( const THD thd,
String str,
enum_query_type  query_type 
)

Print details of Windowing functions.

Parameters
thdThread handler
[out]strString of output
query_typeOptions to print out string output

◆ query_result()

Query_result* Query_block::query_result ( ) const
inline

◆ remove_base_options()

void Query_block::remove_base_options ( ulonglong  options)
inline

Remove base options from a query block.

Active options are also updated, and we assume here that "extra" options cannot override removed base options.

◆ renumber()

void Query_block::renumber ( LEX lex)

Renumber query blocks of contained query expressions.

Renumber query_block object, and apply renumbering recursively to contained objects.

Parameters
lexContaining LEX object

◆ restore_cmd_properties()

void Query_block::restore_cmd_properties ( )

Restore prepared statement properties for this query block and all underlying query expressions so they are ready for optimization.

Restores properties saved in TABLE_LIST objects into corresponding TABLEs. Restores ORDER BY and GROUP by clauses, and window definitions, so they are ready for optimization.

◆ right_joins()

bool Query_block::right_joins ( ) const
inline

◆ save_cmd_properties()

bool Query_block::save_cmd_properties ( THD thd)

Save prepared statement properties for a query block and underlying query expressions.

Required for repeated optimizations of the command.

Parameters
thdthread handler
Returns
false if success, true if error (out of memory)

◆ save_order_properties()

bool Query_block::save_order_properties ( THD thd,
SQL_I_List< ORDER > *  list,
Group_list_ptrs **  list_ptrs 
)
private

Helper for save_properties()

Save properties for ORDER clauses so that they can be reconstructed for a new optimization of the query block.

Parameters
thdthread handler
listlist of ORDER elements to be saved
[out]list_ptrsSaved list of ORDER elements
Returns
false if success, true if error (out of memory)

◆ save_properties()

bool Query_block::save_properties ( THD thd)

Save properties of a prepared statement needed for repeated optimization.

Saves the chain of ORDER::next in group_list and order_list, in case the list is modified by remove_const().

Parameters
thdthread handler
Returns
false if success, true if error (out of memory)

◆ semijoin_enabled()

bool Query_block::semijoin_enabled ( const THD thd) const

Returns whether semi-join is enabled for this query block.

See also
Opt_hints_qb::semijoin_enabled for details on how hints affect this decision. If there are no hints for this query block, optimizer_switch setting determines whether semi-join is used.
Parameters
thdPointer to THD object for session. Used to access optimizer_switch
Returns
true if semijoin is enabled, false otherwise

◆ set_agg_func_used()

void Query_block::set_agg_func_used ( bool  val)
inline

◆ set_base_options()

void Query_block::set_base_options ( ulonglong  options_arg)
inline

Set base options for a query block (and active options too)

◆ set_context()

bool Query_block::set_context ( Name_resolution_context outer_context)

Assign a default name resolution object for this query block.

Set the name resolution context for the specified query block.

Parameters
outer_contextOuter name resolution context. NULL if none or it will be set later.

◆ set_empty_query()

void Query_block::set_empty_query ( )
inline

Set query block as returning no data.

◆ set_having_cond()

void Query_block::set_having_cond ( Item cond)
inline

◆ set_json_agg_func_used()

void Query_block::set_json_agg_func_used ( bool  val)
inline

◆ set_query_result()

void Query_block::set_query_result ( Query_result result)
inline

◆ set_right_joins()

void Query_block::set_right_joins ( )
inline

◆ set_sj_candidates()

void Query_block::set_sj_candidates ( Mem_root_array< Item_exists_subselect * > *  sj_cand)
inline

◆ set_tables_readonly()

void Query_block::set_tables_readonly ( )
inline

Set associated tables as read_only, ie.

they cannot be inserted into, updated or deleted from during this statement. Commonly used for query blocks that are part of derived tables or views that are materialized.

◆ set_where_cond()

void Query_block::set_where_cond ( Item cond)
inline

◆ setup_base_ref_items()

bool Query_block::setup_base_ref_items ( THD thd)

Setup the array containing references to base items.

◆ source_table_is_one_row()

bool Query_block::source_table_is_one_row ( ) const
inline
Returns
true if this query block outputs at most one row.

◆ subquery_strategy()

Subquery_strategy Query_block::subquery_strategy ( const THD thd) const

Returns which subquery execution strategies can be used for this query block.

Parameters
thdPointer to THD object for session. Used to access optimizer_switch
Return values
SUBQ_MATERIALIZATIONSubquery Materialization should be used
SUBQ_EXISTSIn-to-exists execution should be used
CANDIDATE_FOR_IN2EXISTS_OR_MATA cost-based decision should be made

◆ test_limit()

bool Query_block::test_limit ( )

◆ type()

enum_explain_type Query_block::type ( )

Lookup for Query_block type.

◆ update_semijoin_strategies()

void Query_block::update_semijoin_strategies ( THD thd)

Update available semijoin strategies for semijoin nests.

Available semijoin strategies needs to be updated on every execution since optimizer_switch setting may have changed.

Parameters
thdPointer to THD object for session. Used to access optimizer_switch

◆ validate_base_options()

bool Query_block::validate_base_options ( LEX lex,
ulonglong  options_arg 
) const

Validate base options for a query block.

Parameters
lexLEX of current statement
options_argbase options for a SELECT statement.
Returns
false if success, true if validation failed

These options are supported, per DML statement:

SELECT: SELECT_STRAIGHT_JOIN SELECT_HIGH_PRIORITY SELECT_DISTINCT SELECT_ALL SELECT_SMALL_RESULT SELECT_BIG_RESULT OPTION_BUFFER_RESULT OPTION_FOUND_ROWS OPTION_SELECT_FOR_SHOW DELETE: OPTION_QUICK LOW_PRIORITY INSERT: LOW_PRIORITY HIGH_PRIORITY UPDATE: LOW_PRIORITY

Note that validation is only performed for SELECT statements.

◆ validate_outermost_option()

bool Query_block::validate_outermost_option ( LEX lex,
const char *  option 
) const

Check if an option that can be used only for an outer-most query block is applicable to this query block.

Parameters
lexLEX of current statement
optionoption name to output within the error message
Returns
false if valid, true if invalid, error is sent to client

◆ visible_fields() [1/2]

auto Query_block::visible_fields ( )
inline

Wrappers over fields / get_fields_list() that hide items where item->hidden, meant for range-based for loops.

See sql/visible_fields.h.

◆ visible_fields() [2/2]

auto Query_block::visible_fields ( ) const
inline

◆ walk()

bool Query_block::walk ( Item_processor  processor,
enum_walk  walk,
uchar arg 
)

◆ where_cond()

Item* Query_block::where_cond ( ) const
inline

◆ where_cond_ref()

Item** Query_block::where_cond_ref ( )
inline

Friends And Related Function Documentation

◆ Condition_context

friend class Condition_context
friend

◆ Query_expression

friend class Query_expression
friend

Member Data Documentation

◆ allow_merge_derived

bool Query_block::allow_merge_derived {true}
private

Allow merge of immediate unnamed derived tables.

◆ base_ref_items

Ref_item_array Query_block::base_ref_items

Array of pointers to "base" items; one each for every selected expression and referenced item in the query block.

All references to fields are to buffers associated with the primary input tables.

◆ between_count

uint Query_block::between_count {0}

number of between predicates in where/having/on

◆ cond_count

uint Query_block::cond_count {0}

number of arguments of and/or/xor in where/having/on

◆ cond_value

Item::cond_result Query_block::cond_value {Item::COND_UNDEF}

Saved values of the WHERE and HAVING clauses.

Allowed values are:

  • COND_UNDEF if the condition was not specified in the query or if it has not been optimized yet
  • COND_TRUE if the condition is always true
  • COND_FALSE if the condition is impossible
  • COND_OK otherwise

◆ condition_context

enum_condition_context Query_block::condition_context {enum_condition_context::ANDS}
See also
enum_condition_context

◆ context

Name_resolution_context Query_block::context {}

Context for name resolution for all column references except columns from joined tables.

◆ db

char* Query_block::db {nullptr}

◆ derived_table_count

uint Query_block::derived_table_count {0}

Number of derived tables and views in this query block.

◆ embedding

TABLE_LIST* Query_block::embedding {nullptr}

table embedding the above list

◆ end_lateral_table

TABLE_LIST* Query_block::end_lateral_table {nullptr}

◆ exclude_from_table_unique_test

bool Query_block::exclude_from_table_unique_test {false}

exclude this query block from unique_table() check

◆ fields

mem_root_deque<Item *> Query_block::fields

All expressions needed after join and filtering, ie., select list, group by list, having clause, window clause, order by clause, including hidden fields.

Does not include join conditions nor where clause.

This should ideally be changed into Mem_root_array<Item *>, but find_order_in_list() depends on pointer stability (it stores a pointer to an element in referenced_by[]). Similarly, there are some instances of thd->change_item_tree() that store pointers to elements in this list.

Because of this, adding or removing elements in the middle is not allowed; std::deque guarantees pointer stability only in the face of adding or removing elements from either end, ie., {push,pop}_{front_back}.

Currently, all hidden items must be before all visible items. This is primarily due to the requirement for pointer stability (remove_hidden_fields() runs during cleanup), but also because change_to_use_tmp_fields() depends on it when mapping items to ref_item_array indexes. It would be good to get rid of this requirement in the future.

◆ first_context

Name_resolution_context* Query_block::first_context

Pointer to first object in list of Name res context objects that have this query block as the base query block.

Includes field "context" which is embedded in this query block.

◆ first_execution

bool Query_block::first_execution {true}

This variable is required to ensure proper work of subqueries and stored procedures.

Generally, one should use the states of Query_arena to determine if it's a statement prepare or first execution of a stored procedure. However, in case when there was an error during the first execution of a stored procedure, the SP body is not expelled from the SP cache. Therefore, a deeply nested subquery might be left unoptimized. So we need this per-subquery variable to inidicate the optimization/execution state of every subquery. Prepared statements work OK in that regard, as in case of an error during prepare the PS is not created.

◆ ftfunc_list

List<Item_func_match>* Query_block::ftfunc_list

Usually a pointer to ftfunc_list_alloc, but in UNION this is used to create fake query_block that consolidates result fields of UNION.

◆ ftfunc_list_alloc

List<Item_func_match> Query_block::ftfunc_list_alloc {}

◆ group_fix_field

bool Query_block::group_fix_field {false}

true when GROUP BY fix field called in processing of this query block

◆ group_list

SQL_I_List<ORDER> Query_block::group_list {}

GROUP BY clause.

This list may be mutated during optimization (by remove_const()), so for prepared statements, we keep a copy of the ORDER.next pointers in group_list_ptrs, and re-establish the original list before each execution.

◆ group_list_ptrs

Group_list_ptrs* Query_block::group_list_ptrs {nullptr}

◆ has_aj_nests

bool Query_block::has_aj_nests {false}
private
See also
has_sj_nests; counts antijoin nests.

◆ has_sj_nests

bool Query_block::has_sj_nests {false}
private

True if query block has semi-join nests merged into it.

Notice that this is updated earlier than sj_nests, so check this if info is needed before the full resolver process is complete.

◆ having_fix_field

bool Query_block::having_fix_field {false}

true when having fix field called in processing of this query block

◆ having_value

Item::cond_result Query_block::having_value {Item::COND_UNDEF}

◆ hidden_group_field_count

int Query_block::hidden_group_field_count
private

Number of GROUP BY expressions added to all_fields.

◆ hidden_items_from_optimization

uint Query_block::hidden_items_from_optimization {0}

Hidden items added during optimization.

Note
that using this means we modify resolved data during optimization

◆ hidden_order_field_count

int Query_block::hidden_order_field_count {0}
private

How many expressions are part of the order by but not select list.

◆ in_sum_expr

uint Query_block::in_sum_expr {0}

Parse context: is inside a set function if this is positive.

◆ inner_sum_func_list

Item_sum* Query_block::inner_sum_func_list {nullptr}

Circular linked list of aggregate functions in nested query blocks.

This is needed if said aggregate functions depend on outer values from this query block; if so, we want to add them as hidden items in our own field list, to be able to evaluate them.

See also
Item_sum::check_sum_func

◆ is_item_list_lookup

bool Query_block::is_item_list_lookup {false}

◆ is_table_value_constructor

bool Query_block::is_table_value_constructor {false}

If set, the query block is of the form VALUES row_list.

◆ join

JOIN* Query_block::join {nullptr}

After optimization it is pointer to corresponding JOIN.

This member should be changed only when THD::LOCK_query_plan mutex is taken.

◆ join_list

mem_root_deque<TABLE_LIST *>* Query_block::join_list

list for the currently parsed join

◆ leaf_table_count

uint Query_block::leaf_table_count {0}

Number of leaf tables in this query block.

◆ leaf_tables

TABLE_LIST* Query_block::leaf_tables {nullptr}

Points to first leaf table of query block.

After setup_tables() is done, this is a list of base tables and derived tables. After derived tables processing is done, this is a list of base tables only. Use TABLE_LIST::next_leaf to traverse the list.

◆ link_next

Query_block* Query_block::link_next {nullptr}
private

Intrusive double-linked global list of query blocks.

◆ link_prev

Query_block** Query_block::link_prev {nullptr}
private

◆ linkage

sub_select_type Query_block::linkage {UNSPECIFIED_TYPE}

Describes context of this query block (e.g if it is a derived table).

◆ m_active_options

ulonglong Query_block::m_active_options {0}
private

Active options.

Derived from base options, modifiers added during resolving and values from session variable option_bits. Since the latter may change, active options are refreshed per execution of a statement.

◆ m_added_non_hidden_fields

size_t Query_block::m_added_non_hidden_fields {0}

◆ m_agg_func_used

bool Query_block::m_agg_func_used {false}
private

◆ m_base_options

ulonglong Query_block::m_base_options {0}
private

Options assigned from parsing and throughout resolving, should not be modified after resolving is done.

◆ m_empty_query

bool Query_block::m_empty_query {false}
private

True if query block does not generate any rows before aggregation, determined during preparation (not optimization).

◆ m_having_cond

Item* Query_block::m_having_cond
private

Condition to be evaluated on grouped rows after grouping.

◆ m_internal_limit

bool Query_block::m_internal_limit {false}

If true, limit object is added internally.

◆ m_json_agg_func_used

bool Query_block::m_json_agg_func_used {false}
private

◆ m_query_result

Query_result* Query_block::m_query_result {nullptr}
private

Result of this query block.

◆ m_right_joins

bool Query_block::m_right_joins {false}
private

True if query block has right joins.

◆ m_use_select_limit

bool Query_block::m_use_select_limit {false}

If true, use select_limit to limit number of rows selected.

Applicable when no explicit limit is supplied, and only for the outermost query block of a SELECT statement.

◆ m_was_implicitly_grouped

bool Query_block::m_was_implicitly_grouped {false}

Used by nested scalar_to_derived transformations.

◆ m_where_cond

Item* Query_block::m_where_cond
private

Condition to be evaluated after all tables in a query block are joined.

After all permanent transformations have been conducted by Query_block::prepare(), this condition is "frozen", any subsequent changes to it must be done with change_item_tree(), unless they only modify AND/OR items and use a copy created by Query_block::get_optimizable_conditions(). Same is true for 'having_cond'.

◆ m_windows

List<Window> Query_block::m_windows

All windows defined on the select, both named and inlined.

◆ master

Query_expression* Query_block::master {nullptr}
private

The query expression containing this query block.

◆ materialized_derived_table_count

uint Query_block::materialized_derived_table_count {0}

Number of materialized derived tables and views in this query block.

◆ max_equal_elems

uint Query_block::max_equal_elems
Initial value:
{
0}

maximal number of elements in multiple equalities

◆ n_child_sum_items

uint Query_block::n_child_sum_items {0}

Number of Item_sum-derived objects in children and descendant SELECTs.

◆ n_scalar_subqueries

uint Query_block::n_scalar_subqueries {0}

Keep track for allocation of base_ref_items: scalar subqueries may be replaced by a field during scalar_to_derived transformation.

◆ n_sum_items

uint Query_block::n_sum_items {0}

Number of Item_sum-derived objects in this SELECT.

Keeps count of aggregate functions and window functions(to allocate items in ref array). See Query_block::setup_base_ref_items.

◆ nest_level

int Query_block::nest_level {0}

Nesting level of query block, outer-most query block has level 0, its subqueries have level 1, etc.

See also
also sql/item_sum.h.

◆ next

Query_block* Query_block::next {nullptr}
private

Intrusive double-linked list of all query blocks within the same query expression.

◆ no_table_names_allowed

bool Query_block::no_table_names_allowed {false}

used for global order by

◆ offset_limit

Item* Query_block::offset_limit {nullptr}

LIMIT ... OFFSET clause, NULL if no offset is given.

◆ olap

olap_type Query_block::olap {UNSPECIFIED_OLAP_TYPE}

Indicates whether this query block contains the WITH ROLLUP clause.

◆ opt_hints_qb

Opt_hints_qb* Query_block::opt_hints_qb {nullptr}

Query-block-level hints, for this query block.

◆ order_list

SQL_I_List<ORDER> Query_block::order_list {}

ORDER BY clause.

This list may be mutated during optimization (by remove_const()), so for prepared statements, we keep a copy of the ORDER.next pointers in order_list_ptrs, and re-establish the original list before each execution.

◆ order_list_ptrs

Group_list_ptrs* Query_block::order_list_ptrs {nullptr}

◆ outer_join

table_map Query_block::outer_join {0}

Bitmap of all inner tables from outer joins.

◆ parent_lex

LEX* Query_block::parent_lex {nullptr}

Reference to LEX that this query block belongs to.

◆ parsing_place

enum_parsing_context Query_block::parsing_place {CTX_NONE}

Parse context: indicates where the current expression is being parsed.

◆ partitioned_table_count

uint Query_block::partitioned_table_count {0}

Number of partitioned tables.

◆ prev

Query_block** Query_block::prev {nullptr}
private

◆ recursive_reference

TABLE_LIST* Query_block::recursive_reference {nullptr}

If this query block is a recursive member of a recursive unit: the TABLE_LIST, in this recursive member, referencing the query name.

◆ resolve_nest

TABLE_LIST* Query_block::resolve_nest
private
Initial value:
{
nullptr}

Used when resolving outer join condition.

◆ resolve_place

Resolve_place Query_block::resolve_place
Initial value:
{
@ RESOLVE_NONE
Definition: sql_lex.h:2008

Indicates part of query being resolved.

◆ rollup_group_items

Prealloced_array<Item_rollup_group_item *, 4> Query_block::rollup_group_items
Initial value:
{
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:39

◆ rollup_sums

Prealloced_array<Item_rollup_sum_switcher *, 4> Query_block::rollup_sums
Initial value:

◆ row_value_list

mem_root_deque<mem_root_deque<Item *> *>* Query_block::row_value_list {nullptr}

The VALUES items of a table value constructor.

◆ select_limit

Item* Query_block::select_limit {nullptr}

LIMIT clause, NULL if no limit is given.

◆ select_list_tables

table_map Query_block::select_list_tables {0}

The set of those tables whose fields are referenced in the select list of this select level.

◆ select_n_having_items

uint Query_block::select_n_having_items {0}

number of items in select_list and HAVING clause used to get number bigger then can be number of entries that will be added to all item list during split_sum_func

◆ select_n_where_fields

uint Query_block::select_n_where_fields {0}

Number of fields used in select list or where clause of current select and all inner subselects.

◆ select_number

uint Query_block::select_number {0}

Query block number (used for EXPLAIN)

◆ sj_candidates

Mem_root_array<Item_exists_subselect *>* Query_block::sj_candidates {nullptr}
private

Pointer to collection of subqueries candidate for semi/antijoin conversion.

Template parameter is "true": no need to run DTORs on pointers.

◆ sj_nests

mem_root_deque<TABLE_LIST *> Query_block::sj_nests

List of semi-join nests generated for this query block.

◆ sj_pullout_done

bool Query_block::sj_pullout_done {false}

True when semi-join pull-out processing is complete.

◆ skip_local_transforms

bool Query_block::skip_local_transforms {false}

True: skip local transformations during prepare() call (used by INSERT)

◆ slave

Query_expression* Query_block::slave {nullptr}
private

The first query expression contained within this query block.

◆ subquery_in_having

bool Query_block::subquery_in_having {false}

HAVING clause contains subquery => we can't close tables before query processing end even if we use temporary table.

◆ table_func_count

uint Query_block::table_func_count {0}

Number of table functions in this query block.

◆ table_list

SQL_I_List<TABLE_LIST> Query_block::table_list {}

List of tables in FROM clause - use TABLE_LIST::next_local to traverse.

◆ top_join_list

mem_root_deque<TABLE_LIST *> Query_block::top_join_list

join list of the top level

◆ type_str

const char * Query_block::type_str
staticprivate
Initial value:
= {
"NONE", "PRIMARY", "SIMPLE", "DERIVED",
"SUBQUERY", "UNION", "UNION RESULT", "MATERIALIZED"}
Note
The order of the elements of this array must correspond to the order of elements in type_enum

◆ uncacheable

uint8 Query_block::uncacheable {0}

result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCACHEABLE_SIDEEFFECT

◆ with_sum_func

bool Query_block::with_sum_func {false}

True if contains or aggregates set functions.

Note
this is wrong when a locally found set function is aggregated in an outer query block.

◆ with_wild

uint Query_block::with_wild {0}

Number of wildcards used in the SELECT list.

For example, SELECT *, t1.*, catalog.t2.* FROM t0, t1, t2; has 3 wildcards.


The documentation for this class was generated from the following files: