MySQL 9.1.0
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>

Inheritance diagram for Query_block:
[legend]

Public Types

enum  Resolve_place {
  RESOLVE_NONE , RESOLVE_JOIN_NEST , RESOLVE_CONDITION , RESOLVE_HAVING ,
  RESOLVE_QUALIFY , 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...
 
void debugPrint (int level, std::ostringstream &buf) const override
 Query_term methods overridden. More...
 
void qbPrint (int level, std::ostringstream &buf) const
 Minion of debugPrint. More...
 
bool prepare_query_term (THD *thd, Query_expression *qe, Change_current_query_block *save_query_block, mem_root_deque< Item * > *insert_field_list, Query_result *common_result, ulonglong added_options, ulonglong removed_options, ulonglong create_option) override
 a) Prepare query blocks, both leaf blocks and blocks reresenting order by/limit in query primaries with parentesized query expression body with order by clause and/or limit/offset clause (unary query terms). More...
 
bool optimize_query_term (THD *, Query_expression *) override
 Optimize the non-leaf query blocks. More...
 
AccessPathmake_set_op_access_path (THD *thd, Query_term_set_op *parent, Mem_root_array< AppendPathParameters > *union_all_subpaths, bool calc_found_rows) override
 Recursively constructs the access path of the set operation, possibly materializing in a tmp table if needed, cf. More...
 
mem_root_deque< Item * > * types_array () override
 
Query_term_type term_type () const override
 Get the node tree type. More...
 
const char * operator_string () const override
 Get the node type description. More...
 
Query_blockquery_block () const override
 The query_block which holds the ORDER BY and LIMIT information for this set operation. More...
 
void label_children () override
 Set the correct value of Query_term::m_sibling_idx recursively for set operations. More...
 
void destroy_tree () override
 Destroy the query term tree structure. More...
 
bool open_result_tables (THD *, int) override
 Open tmp tables for the tree of set operation query results, by recursing. More...
 
bool absorb_limit_of (Query_block *block)
 end of overridden methods from Query_term 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)
 
Itemqualify_cond () const
 
Item ** qualify_cond_ref ()
 
void set_qualify_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
 
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_reffind_table_by_name (const Table_ident *ident)
 Finds a (possibly unresolved) table reference in the from clause by name. More...
 
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 has_tables () const
 
bool is_explicitly_grouped () const
 
bool is_implicitly_grouped () const
 
bool is_non_primitive_grouped () const
 
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
 
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)
 
Table_refadd_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_refget_table_list () const
 
bool init_nested_join (THD *thd)
 Initialize a new table list for a nested join. More...
 
Table_refend_nested_join ()
 End a nested join table list. More...
 
Table_refnest_last_join (THD *thd, size_t table_cnt=2)
 Nest last join operations. More...
 
bool add_joined_table (Table_ref *table)
 Add a table to the current join list. More...
 
mem_root_deque< Item * > * get_fields_list ()
 
VisibleFieldsIterator 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
 
VisibleFieldsIterator types_iterator () override
 Abstract over visible column types: if query block, we offer an iterator over visible fields, for binary set operators we offer an iterator over m_types, for unary we just call the child's. More...
 
size_t visible_column_count () const override
 Return the number of visible columns of the query term. More...
 
bool check_view_privileges (THD *thd, Access_bitmask want_privilege_first, Access_bitmask 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_ref *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_ref *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)
 
void add_subquery_transform_candidate (Item_exists_subselect *predicate)
 
bool has_sj_candidates () const
 
bool has_subquery_transforms () 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_ref *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 (const THD *thd) const
 Get offset for LIMIT. More...
 
ha_rows get_limit (const THD *thd) const
 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_ref *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_qualify (const THD *thd, String *str, enum_query_type query_type) const
 Print list of items in QUALIFY 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) const
 Print list of items in ORDER BY clause. More...
 
void print_limit (const THD *thd, String *str, enum_query_type query_type) const
 
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 (bool full) override
 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_simple_query_block () const
 
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 () const
 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)
 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_ref * > *join_list=nullptr)
 Set NESTED_JOIN::counter=0 in all nested joins in passed list. More...
 
Itemsingle_visible_field () const
 
size_t num_visible_fields () const
 
bool field_list_is_empty () const
 
Itemclone_expression (THD *thd, Item *item, Table_ref *derived_table)
 Creates a clone for the given expression by re-parsing the expression. More...
 
Itemget_derived_expr (uint expr_index)
 Returns an expression from the select list of the query block using the field's index in a derived table. More...
 
MaterializePathParameters::Operand setup_materialize_query_block (AccessPath *child_path, TABLE *dst_table) const
 Make materialization parameters for a query block given its input path and destination table,. More...
 
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...
 
bool is_row_count_valid_for_semi_join ()
 Check if the offset and limit are valid for a semijoin. More...
 
bool allocate_grouping_sets (THD *thd)
 Initializes the grouping set if the query block includes GROUP BY modifiers. More...
 
bool populate_grouping_sets (THD *thd)
 Populates the grouping sets if the query block includes non-primitive grouping. More...
 
int get_number_of_grouping_sets () const
 
- Public Member Functions inherited from Query_term
Query_termpushdown_limit_order_by (Query_term_set_op *parent=nullptr)
 Called after contextualization to simplify query, c.f. More...
 
bool validate_structure (const Query_term *parent, int depth=0) const
 Return true if structure is too deep, i.e. More...
 
std::pair< bool, bool > redundant_order_by (Query_block *block, int level)
 Determine if we have a redundant ORDER BY in block. More...
 
virtual ~Query_term ()=default
 Node destructor. More...
 
virtual size_t child_count () const
 Get the number of children this node has. More...
 
bool create_tmp_table (THD *thd, ulonglong create_options)
 Create a temporary table for a set operation. More...
 
Query_term_set_opparent () const
 Getter for m_parent, q.v. More...
 
void set_sibling_idx (uint idx)
 Setter for m_sibling_idx, q.v. More...
 
uint sibling_idx ()
 Getter for m_sibling_idx, q.v. More...
 
void printPointers (std::ostringstream &buf) const
 Print the pointer of this node and its parent to buf. More...
 
void set_setop_query_result (Query_result *rs)
 Setter for m_setop_query_result, q.v. More...
 
Query_resultsetop_query_result ()
 Getter for m_setop_query_result, q.v. More...
 
Query_result_unionsetop_query_result_union ()
 Getter for m_setop_query_result, q.v. Use only if we can down cast. More...
 
void cleanup_query_result (bool full)
 Cleanup m_setop_query_result, q.v. More...
 
void set_owning_operand ()
 Setter for m_owning_operand, q.v. More...
 
bool owning_operand ()
 Getter for m_owning_operand, q.v. More...
 
void set_result_table (Table_ref *tl)
 Setter for m_result_table, q.v. More...
 
Table_refresult_table ()
 Getter for m_result_table, q.v. More...
 
void set_fields (mem_root_deque< Item * > *fields)
 
mem_root_deque< Item * > * fields ()
 

Static Public Member Functions

static const char * get_type_str (enum_explain_type type)
 
- Static Public Member Functions inherited from Query_term
static void indent (int level, std::ostringstream &buf)
 Print blank space indentation (unit: two) to buf according to level. More...
 
static void print_order (const THD *thd, String *str, ORDER *ord, enum_query_type query_type)
 Print into str the order indicated in ord, using standard print_for_order Used by traditional explain. More...
 

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
 A pointer to ftfunc_list_alloc, list of full text search functions. 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_ref * > sj_nests
 List of semi-join nests generated for this query block. More...
 
SQL_I_List< Table_refm_table_list {}
 List of tables in FROM clause - use Table_ref::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}
 
decltype(SQL_I_List< ORDER >::elements) m_no_of_added_exprs {0}
 For an explicitly grouped, correlated, scalar subquery which is transformed to join with derived tables: the number of added non-column expressions. More...
 
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_refrecursive_reference {nullptr}
 If this query block is a recursive member of a recursive unit: the Table_ref, 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_ref * > m_table_nest
 Set of table references contained in outer-most join nest. More...
 
mem_root_deque< Table_ref * > * m_current_table_nest
 Pointer to the set of table references in the currently active join. More...
 
Table_refembedding {nullptr}
 table embedding the above list More...
 
Table_refleaf_tables {nullptr}
 Points to first leaf table of query block. More...
 
Table_refend_lateral_table {nullptr}
 Last table for LATERAL join, used by table functions. More...
 
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...
 
bool m_limit_1 {false}
 Whether we have LIMIT 1 and no OFFSET. 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...
 
uint in_window_expr {0}
 Parse context: is inside a window 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 the select list, HAVING clause, QUALIFY clause and ORDER BY clause. More...
 
uint saved_cond_count {0}
 Number of arguments of and/or/xor in where/having/on. More...
 
uint cond_count {0}
 Number of predicates after preparation. More...
 
uint between_count {0}
 Number of between predicates in where/having/on. More...
 
uint max_equal_elems {0}
 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 non-primitive grouping (such as ROLLUP). 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...
 
Table_refresolve_nest
 Used when resolving outer join condition. 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_ref * > *tables)
 Record join nest info in the select block. More...
 
bool simplify_joins (THD *thd, mem_root_deque< Table_ref * > *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, bool *simple_const)
 Build semijoin condition for th query block. More...
 
bool decorrelate_condition (Semijoin_decorrelation &sj_decor, Table_ref *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_ref semi-join nest. More...
 
Table_refsynthesize_derived (THD *thd, Query_expression *unit, Item *join_cond, bool left_outer, bool use_inner_join)
 Create a new Table_ref 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_ref **out_tl, Query_expression *subs_query_expression, Item_subselect *subq, bool use_inner_join, bool reject_multiple_rows, Item::Css_info *subquery, 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 setup_counts_over_partitions (THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_expressions, mem_root_deque< Item * > &exprs_added_to_group_by, uint hidden_fields)
 Add all COUNT(0) to SELECT list of the derived table to be used for cardinality checking of the transformed subquery. More...
 
bool add_inner_fields_to_select_list (THD *thd, Lifted_expressions_map *lifted_exprs, Item *selected_field_or_ref, const uint first_non_hidden)
 Minion of decorrelate_derived_scalar_subquery_pre. More...
 
bool add_inner_func_calls_to_select_list (THD *thd, Lifted_expressions_map *lifted_exprs)
 
bool add_inner_exprs_to_group_by (THD *thd, List_iterator< Item > &inner_exprs, Item *selected_item, bool *selected_expr_added_to_group_by, mem_root_deque< Item * > *exprs_added_to_group_by)
 Run through the inner expressions and add them to the block's GROUP BY if not already present. More...
 
bool decorrelate_derived_scalar_subquery_pre (THD *thd, Table_ref *derived, Item::Css_info *subquery, Item *lifted_where, Lifted_expressions_map *lifted_where_expressions, bool *added_card_check, size_t *added_window_card_checks)
 We have a correlated scalar subquery, so we must do several things: More...
 
bool decorrelate_derived_scalar_subquery_post (THD *thd, Table_ref *derived, Lifted_expressions_map *lifted_exprs, bool added_card_check, size_t added_window_card_checks)
 See explanation in companion method decorrelate_derived_scalar_subquery_pre. More...
 
bool replace_first_item_with_min_max (THD *thd, int item_no, bool use_min)
 Replace the first visible item in the select list with a wrapping MIN or MAX aggregate function. More...
 
void replace_referenced_item (Item *const old_item, Item *const new_item)
 Replace item in select list and preserve its reference count. More...
 
void remap_tables (THD *thd)
 Re-map table numbers for all tables in a query block. More...
 
void mark_item_as_maybe_null_if_non_primitive_grouped (Item *item) const
 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)
 
bool remove_redundant_subquery_clauses (THD *thd)
 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_ref * > join_list)
 Go through a list of tables and join nests, recursively, and repoint its query_block pointer. More...
 
bool empty_order_list (Query_block *sl)
 Empty the ORDER list. More...
 
bool setup_join_cond (THD *thd, mem_root_deque< Table_ref * > *tables, bool in_update)
 Resolve join conditions for a join nest. More...
 
bool find_common_table_expr (THD *thd, Table_ident *table_id, Table_ref *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 replace_item_in_expression (Item **expr, bool was_hidden, Item::Item_replacement *info, Item_transformer transformer)
 Minion of transform_grouped_to_derived. 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_ref *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_ref * > *join_list, Table_ref *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_ref * > *tables)
 Delete unused columns from merged tables. 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 lift_fulltext_from_having_to_select_list (THD *thd)
 Copies all non-aggregated calls to the full-text search MATCH function from the HAVING clause to the SELECT list (as hidden items), so that we can materialize their result and not only their input. 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 linked list of all query blocks within the same query expression. More...
 
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...
 
int m_num_grouping_sets {0}
 If the query block includes non-primitive grouping, then these modifiers are represented as grouping sets. 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...
 
Itemm_qualify_cond {nullptr}
 Condition to be evaluated after window functions. More...
 
int hidden_group_field_count
 Number of GROUP BY expressions added to all_fields. More...
 
Ref_item_array m_saved_base_items
 A backup of the items in base_ref_items at the end of preparation, so that base_ref_items can be restored between executions of prepared statements. 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
 

Additional Inherited Members

- Protected Attributes inherited from Query_term
Query_term_set_opm_parent {nullptr}
 Back pointer to the node whose child we are, or nullptr (root term). More...
 
uint m_sibling_idx {0}
 If parent is non-null, this holds the index of the current sibling. More...
 
Query_resultm_setop_query_result {nullptr}
 The query result for this term. More...
 
bool m_owning_operand {false}
 The operand of a n-ary set operation (that owns the common query result) has this set to true. More...
 
Table_refm_result_table {nullptr}
 Result temporary table for the set operation, if applicable. More...
 
mem_root_deque< Item * > * m_fields {nullptr}
 Used only when streaming, i.e. More...
 

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_QUALIFY 
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

◆ absorb_limit_of()

bool Query_block::absorb_limit_of ( Query_block block)

end of overridden methods from Query_term

◆ 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_subquery_transform_candidate()

void Query_block::add_subquery_transform_candidate ( Item_exists_subselect predicate)
inline

◆ 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.

◆ cleanup()

void Query_block::cleanup ( bool  full)
overridevirtual

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

Cleanup after preparation of one round of execution.

Parameters
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.

Reimplemented from Query_term.

◆ cleanup_all_joins()

void Query_block::cleanup_all_joins ( )

◆ clone_expression()

Item * Query_block::clone_expression ( THD thd,
Item item,
Table_ref derived_table 
)

Creates a clone for the given expression by re-parsing the expression.

Clone an expression.

Used in condition pushdown to derived tables.

This clone will be used for pushing conditions down to a materialized derived table. Cloning of an expression is done for two purposes:

  1. When the derived table has a query expression with multiple query blocks, each query block involved will be getting a clone of the condition that is being pushed down.
  2. When pushing a condition down to a derived table (with or without unions), columns in the condition are replaced with the derived table's expressions. If there are nested derived tables, these columns will be replaced again with another derived table's expression when the condition is pushed further down. If the derived table expressions are simple columns, we would just keep replacing the original columns with derived table columns. However if the derived table expressions are not simple column references E.g. functions, then columns will be replaced with functions, and arguments to these functions would get replaced when the condition is pushed further down. However, arguments to a function are part of both the SELECT clause of one derived table and the WHERE clause of another derived table where the condition is pushed down (Example below). To keep the sanity of the derived table's expression, a clone is created and used before pushing a condition down.

Ex: Where cloned objects become necessary even when the derived table does not have a UNION.

Consider a query like this one: SELECT * FROM (SELECT i+10 AS n FROM (SELECT a+7 AS i FROM t1) AS dt1 ) AS dt2 WHERE n > 100;

The first call to Query_block::push_conditions_to_derived_tables would result in the following query. "n" in the where clause is replaced with (i+10). SELECT * FROM (SELECT i+10 AS n FROM (SELECT a+7 AS i FROM t1) AS dt1 WHERE (dt1.i+10) > 100) as dt2;

The next call to Query_block::push_conditions_to_derived_tables should result in the following query. "i" is replaced with "a+7". SELECT * FROM (SELECT i+10 AS n FROM (SELECT a+7 AS i FROM t1 WHERE ((t1.a+7)+10) > 100) AS dt1) as dt2;

However without cloned expressions, it would be

SELECT * FROM (SELECT ((t1.a+7)+10) AS n FROM (SELECT a+7 AS i FROM t1 WHERE ((t1.a+7)+10) > 100) AS dt1) as dt2;

Notice that the column "i" in derived table dt2 is getting replaced with (a+7) because the argument of the function in Item_func_plus in (i+10) is replaced with (a+7). The arguments to the function (i+10) need to be different so as to be able to replace them with some other expressions later.

To clone an expression, we re-parse the expression to get another copy and resolve it against the tables of the query block where it will be placed.

Parameters
thdCurrent thread
itemItem for which clone is requested
derived_tablederived table to which the item belongs to.
Returns
Cloned object for the item.

◆ cut_subtree()

void Query_block::cut_subtree ( )
inline

◆ debugPrint()

void Query_block::debugPrint ( int  level,
std::ostringstream &  buf 
) const
overridevirtual

Query_term methods overridden.

Implements Query_term.

◆ destroy()

void Query_block::destroy ( )

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

◆ destroy_tree()

void Query_block::destroy_tree ( )
inlineoverridevirtual

Destroy the query term tree structure.

Implements Query_term.

◆ find_table_by_name()

Table_ref * 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

◆ get_derived_expr()

Item * Query_block::get_derived_expr ( uint  field_index)

Returns an expression from the select list of the query block using the field's index in a derived table.

Get the expression from this query block using its position in the fields list of the derived table this query block is part of.

Note that the field's position in a derived table does not always reflect the position in the visible field list of the query block. Creation of temporary table for a materialized derived table alters the field position whenever the temporary table adds a hidden field.

Parameters
[in]field_indexposition in the fields list of the derived table.
Returns
expression from the derived table's query block.

◆ 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 ( const THD thd) const

Get limit.

Evaluate limit item if necessary.

Returns
Limit of rows in result.

◆ get_number_of_grouping_sets()

int Query_block::get_number_of_grouping_sets ( ) const
inline

◆ get_offset()

ha_rows Query_block::get_offset ( const THD thd) const

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_ref::m_join_cond_optim.

Returns
true if OOM

◆ get_table_list()

Table_ref * 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_subquery_transforms()

bool Query_block::has_subquery_transforms ( ) const
inline

◆ has_tables()

bool Query_block::has_tables ( ) const
inline
Returns
true if query block references any tables

◆ 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)

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.

◆ 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_non_primitive_grouped()

bool Query_block::is_non_primitive_grouped ( ) const
inline
Returns
true if this query block has GROUP BY modifier.

◆ 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_recursive()

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

◆ is_simple_query_block()

bool Query_block::is_simple_query_block ( ) const
inline
Returns
true when query block is not part of a set operation and is not a parenthesized query expression.

◆ json_agg_func_used()

bool Query_block::json_agg_func_used ( ) const
inline

◆ label_children()

void Query_block::label_children ( )
inlineoverridevirtual

Set the correct value of Query_term::m_sibling_idx recursively for set operations.

For Query_term_unary, this is done in its constructor. A no-op for Query_block. See also set_sibling_idx.

Implements Query_term.

◆ 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

◆ make_set_op_access_path()

AccessPath * Query_block::make_set_op_access_path ( THD thd,
Query_term_set_op parent,
Mem_root_array< AppendPathParameters > *  union_all_subpaths,
bool  calc_found_rows 
)
overridevirtual

Recursively constructs the access path of the set operation, possibly materializing in a tmp table if needed, cf.

Query_term_set_op::m_is_materialized

Parameters
thdsession context
parentthe parent for which we want to create a materialized access path, or nullptr
union_all_subpathsif not nullptr, we are part of a UNION all, add constructed access to it.
calc_found_rowsif true, do allow for calculation of number of found rows even in presence of LIMIT.
Returns
access path, if nullptr, this is an error

Implements Query_term.

◆ 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

◆ open_result_tables()

bool Query_block::open_result_tables ( THD thd,
int  level 
)
overridevirtual

Open tmp tables for the tree of set operation query results, by recursing.

Parameters
thdsession context
levellevel in the tree, top should be called with 0.
Returns
true on error

Reimplemented from Query_term.

◆ operator_string()

const char * Query_block::operator_string ( ) const
inlineoverridevirtual

Get the node type description.

Returns
descriptive string for each node type.

Implements Query_term.

◆ optimize_query_term()

bool Query_block::optimize_query_term ( THD thd,
Query_expression qe 
)
inlineoverridevirtual

Optimize the non-leaf query blocks.

Parameters
thdsession context
qeowning query expression (of this term)
Returns
true on error, else false

Implements Query_term.

◆ outer_query_block()

Query_block * Query_block::outer_query_block ( ) const
inline

◆ prepare_query_term()

bool Query_block::prepare_query_term ( THD thd,
Query_expression qe,
Change_current_query_block save_query_block,
mem_root_deque< Item * > *  insert_field_list,
Query_result common_result,
ulonglong  added_options,
ulonglong  removed_options,
ulonglong  create_options 
)
overridevirtual

a) Prepare query blocks, both leaf blocks and blocks reresenting order by/limit in query primaries with parentesized query expression body with order by clause and/or limit/offset clause (unary query terms).

Establish types for all query terms, and set up tmp table for CTE if present and for any materialized tmp tables for unary query terms.

Types for set operations are calculated bottom-up, so for a unary tmp table, we use the base block's types and names for proper resolution in cases like:

SELECT column_a FROM t1 UNION ( (SELECT column_b FROM t2 ORDER BY column_b LIMIT 3) ORDER BY column_b DESC LIMIT 2 ) ORDER BY column_a;

The second ORDER BY's column_b should resolve to its nested column_b selected from t2. This also means that the second order by operation does sorting using the type of column_b, not using the common type of t1.column_a and t2.column_b.

If the inner SELECT above were a binary set operation, we would order by the joined types of the binary (sub)operation, recursively.

This function constructs the m_types array for each binary set operation query term. Unary terms just use their child's type information.

We have a nested set operation structure where the leaf nodes are inner query blocks, typically SELECT clauses. These are prepared with Query_block::prepare, called by Query_block::prepare_query_term. We also need to prepare the nodes representing the binary set and unary operations. We have already merged nested set operation of the same kind into multi op form, so at any level the child and parent will usually be of another kind(1). We a priori create temporary tables marked with an asterisk below, modulo ALL optimizations, to consolidate the result of each multi set and unary operations. E.g.

               UNION*
                 |
      +----------------+----------+
      |                |          |
 INTERSECT*     UNARY TERM*   EXCEPT*
      |                |          |
  +---+---+            QB      +--+-+
  |   |   |                    |    |
 QB  QB  UNION*                QB   QB
         QB QB

(1) an exception is that we do not merge top level trailing UNION ALL nodes with preceding UNION DISTINCT in order that they can be streamed efficiently.

Note that the Query_result is owned by the first sibling participating in the set operations, so the owning nodes of the above example are actually:

               UNION
                 |
      +----------------+----------+
      |                |          |
 INTERSECT*     UNARY TERM   EXCEPT
      |                |          |
  +---+---+            QB*     +--+-+
  |   |   |                    |    |
 QB* QB  UNION                QB*   QB
         QB* QB
Parameters
thdsession context
qequery expression query expression directly containing this query term
save_query_blockcopy of thd->lex->current_query_block() when Query_expression::prepare was called.
insert_field_listpointer to field list if INSERT op, NULL otherwise.
common_resultfor the top node, this is not used: we use query_result() instead. Otherwise, if it is empty, we create a query result on behalf of this node and its siblings. This node is then the designated owning operand, and is responsible for releasing it after execution. The siblings will see that common_result is not empty and use that.
added_optionsthese options will be added to the query blocks.
removed_optionsoptions that cannot be used for this query
create_optionsoptions to use for creating tmp table
Returns
false on success, true on error

Implements Query_term.

◆ 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 
) const

◆ print_order_by()

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

Print list of items in ORDER BY clause.

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

◆ print_qualify()

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

Print list of items in QUALIFY 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_ref table_list,
enum_query_type  query_type 
)

Print list of tables.

Parameters
thdThread handler
[out]strString of output
table_listTable_ref 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

◆ qbPrint()

void Query_block::qbPrint ( int  level,
std::ostringstream &  buf 
) const

Minion of debugPrint.

◆ qualify_cond()

Item * Query_block::qualify_cond ( ) const
inline

◆ qualify_cond_ref()

Item ** Query_block::qualify_cond_ref ( )
inline

◆ query_block()

Query_block * Query_block::query_block ( ) const
inlineoverridevirtual

The query_block which holds the ORDER BY and LIMIT information for this set operation.

Note that for the case where the root is a simple query block, this will return self.

Returns
the query block

Implements Query_term.

◆ 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_ref 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_qualify_cond()

void Query_block::set_qualify_cond ( Item cond)
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.

◆ setup_materialize_query_block()

MaterializePathParameters::Operand Query_block::setup_materialize_query_block ( AccessPath child_path,
TABLE dst_table 
) const

Make materialization parameters for a query block given its input path and destination table,.

Parameters
child_paththe input access path
dst_tablethe table to materialize into
Returns
materialization parameter

◆ 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

◆ term_type()

Query_term_type Query_block::term_type ( ) const
inlineoverridevirtual

Get the node tree type.

Returns
the tree node type

Implements Query_term.

◆ test_limit()

bool Query_block::test_limit ( )

◆ type()

enum_explain_type Query_block::type ( ) const

Lookup for Query_block type.

◆ types_array()

mem_root_deque< Item * > * Query_block::types_array ( )
overridevirtual

Implements Query_term.

◆ types_iterator()

VisibleFieldsIterator Query_block::types_iterator ( )
inlineoverridevirtual

Abstract over visible column types: if query block, we offer an iterator over visible fields, for binary set operators we offer an iterator over m_types, for unary we just call the child's.

See also the accompanying visible_column_count.

Implements Query_term.

◆ 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_column_count()

size_t Query_block::visible_column_count ( ) const
inlineoverridevirtual

Return the number of visible columns of the query term.

For query blocks this is in general a subset of Query_block::fields

Implements Query_term.

◆ visible_fields() [1/2]

VisibleFieldsIterator 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 predicates after preparation.

◆ 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_ref* Query_block::embedding {nullptr}

table embedding the above list

◆ end_lateral_table

Table_ref* Query_block::end_lateral_table {nullptr}

Last table for LATERAL join, used by table functions.

◆ 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 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

A pointer to ftfunc_list_alloc, list of full text search functions.

◆ 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() in the old optimizer or by RemoveRedundantOrderElements() in the hypergraph optimizer), 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. The list can also be temporarily pruned and restored by Group_check (if transform done, cf. Query_block::m_gl_size_orig).

◆ 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.

◆ in_window_expr

uint Query_block::in_window_expr {0}

Parse context: is inside a window 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.

◆ leaf_table_count

uint Query_block::leaf_table_count {0}

Number of leaf tables in this query block.

◆ leaf_tables

Table_ref* 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_ref::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_current_table_nest

mem_root_deque<Table_ref *>* Query_block::m_current_table_nest

Pointer to the set of table references in the currently active join.

◆ 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_limit_1

bool Query_block::m_limit_1 {false}

Whether we have LIMIT 1 and no OFFSET.

◆ m_no_of_added_exprs

decltype(SQL_I_List<ORDER>::elements) Query_block::m_no_of_added_exprs {0}

For an explicitly grouped, correlated, scalar subquery which is transformed to join with derived tables: the number of added non-column expressions.

Used for better functional dependency analysis since this is checked during prepare after transformations. Transforms will append inner expressions to the group by list, rendering the check too optimistic. To remedy this, we temporarily remove the added compound (i.e. not simple column) expressions when doing the full group by check. This is bit too pessimistic: we can get occasionally false positives (full group by check error). The underlying problem is that we do not perform full group by checking before transformations. See also Group_check's ctor and dtor.

◆ m_num_grouping_sets

int Query_block::m_num_grouping_sets {0}
private

If the query block includes non-primitive grouping, then these modifiers are represented as grouping sets.

The variable 'm_num_grouping_sets' holds the count of grouping sets.

◆ m_qualify_cond

Item* Query_block::m_qualify_cond {nullptr}
private

Condition to be evaluated after window functions.

◆ 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_saved_base_items

Ref_item_array Query_block::m_saved_base_items
private

A backup of the items in base_ref_items at the end of preparation, so that base_ref_items can be restored between executions of prepared statements.

Empty if it's a regular statement.

◆ m_table_list

SQL_I_List<Table_ref> Query_block::m_table_list {}

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

◆ m_table_nest

mem_root_deque<Table_ref *> Query_block::m_table_nest

Set of table references contained in outer-most join nest.

◆ 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 {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 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 non-primitive grouping (such as ROLLUP).

◆ 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() in the old optimizer or by RemoveRedundantOrderElements() in the hypergraph optimizer), 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.

◆ recursive_reference

Table_ref* Query_block::recursive_reference {nullptr}

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

◆ resolve_nest

Table_ref* Query_block::resolve_nest
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:2093

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:44

◆ 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.

◆ saved_cond_count

uint Query_block::saved_cond_count {0}

Number of arguments of and/or/xor in where/having/on.

◆ 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 the select list, HAVING clause, QUALIFY clause and ORDER BY clause.

It is used to reserve space in the base_ref_items array so that it is big enough to hold hidden items for any of the expressions or sub-expressions in those clauses.

◆ 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_ref *> 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.

◆ type_str

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

◆ 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: