MySQL 9.1.0
Source Code Documentation
|
This class represents a query block, aka a query specification, which is a query consisting of a SELECT keyword, followed by a table list, optionally followed by a WHERE clause, a GROUP BY, etc. More...
#include <sql_lex.h>
Public Types | |
enum | Resolve_place { RESOLVE_NONE , RESOLVE_JOIN_NEST , RESOLVE_CONDITION , RESOLVE_HAVING , RESOLVE_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... | |
AccessPath * | make_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_block * | query_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... | |
Item * | where_cond () const |
Item ** | where_cond_ref () |
void | set_where_cond (Item *cond) |
Item * | having_cond () const |
Item ** | having_cond_ref () |
void | set_having_cond (Item *cond) |
Item * | qualify_cond () const |
Item ** | qualify_cond_ref () |
void | set_qualify_cond (Item *cond) |
void | set_query_result (Query_result *result) |
Query_result * | query_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_expression * | master_query_expression () const |
Query_expression * | first_inner_query_expression () const |
Query_block * | outer_query_block () const |
Query_block * | next_query_block () const |
Table_ref * | find_table_by_name (const Table_ident *ident) |
Finds a (possibly unresolved) table reference in the from clause by name. More... | |
Query_block * | next_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 |
ORDER * | find_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_ref * | add_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_ref * | get_table_list () const |
bool | init_nested_join (THD *thd) |
Initialize a new table list for a nested join. More... | |
Table_ref * | end_nested_join () |
End a nested join table list. More... | |
Table_ref * | nest_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... | |
Item * | single_visible_field () const |
size_t | num_visible_fields () const |
bool | field_list_is_empty () const |
Item * | clone_expression (THD *thd, Item *item, Table_ref *derived_table) |
Creates a clone for the given expression by re-parsing the expression. More... | |
Item * | get_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_term * | pushdown_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_op * | parent () 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_result * | setop_query_result () |
Getter for m_setop_query_result, q.v. More... | |
Query_result_union * | setop_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_ref & | result_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< Window > | m_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_match > | ftfunc_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_ref > | m_table_list {} |
List of tables in FROM clause - use Table_ref::next_local to traverse. More... | |
SQL_I_List< ORDER > | order_list {} |
ORDER BY clause. More... | |
Group_list_ptrs * | order_list_ptrs {nullptr} |
SQL_I_List< ORDER > | group_list {} |
GROUP BY clause. More... | |
Group_list_ptrs * | group_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_qb * | opt_hints_qb {nullptr} |
Query-block-level hints, for this query block. More... | |
char * | db {nullptr} |
Table_ref * | 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. More... | |
LEX * | parent_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_context * | first_context |
Pointer to first object in list of Name res context objects that have this query block as the base query block. More... | |
JOIN * | join {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_ref * | embedding {nullptr} |
table embedding the above list More... | |
Table_ref * | leaf_tables {nullptr} |
Points to first leaf table of query block. More... | |
Table_ref * | end_lateral_table {nullptr} |
Last table for LATERAL join, used by table functions. More... | |
Item * | select_limit {nullptr} |
LIMIT clause, NULL if no limit is given. More... | |
Item * | offset_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_sum * | inner_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_ref * | resolve_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_ref * | synthesize_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... | |
Item * | resolve_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_block * | next {nullptr} |
Intrusive linked list of all query blocks within the same query expression. More... | |
Query_expression * | master {nullptr} |
The query expression containing this query block. More... | |
Query_expression * | slave {nullptr} |
The first query expression contained within this query block. More... | |
Query_block * | link_next {nullptr} |
Intrusive double-linked global list of query blocks. More... | |
Query_block ** | link_prev {nullptr} |
Query_result * | m_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... | |
Item * | m_where_cond |
Condition to be evaluated after all tables in a query block are joined. More... | |
Item * | m_having_cond |
Condition to be evaluated on grouped rows after grouping. More... | |
Item * | m_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_op * | m_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_result * | m_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_ref * | m_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... | |
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.
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
bool Query_block::absorb_limit_of | ( | Query_block * | block | ) |
end of overridden methods from Query_term
bool Query_block::accept | ( | Select_lex_visitor * | visitor | ) |
Accept function for SELECT and DELETE.
visitor | Select_lex_visitor Object |
|
inline |
|
inline |
Adjust the active option set.
|
inline |
Add base options to a query block, also update active options.
bool Query_block::add_ftfunc_to_list | ( | Item_func_match * | func | ) |
bool Query_block::add_item_to_list | ( | Item * | item | ) |
|
inline |
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.
thd | Current session. |
tables | Tables to add. |
table_options | A set of the following bits:
|
lock_type | How table should be locked. |
mdl_type | Type of metadata lock to acquire on the table. |
|
inline |
|
inline |
|
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:
|
overridevirtual |
Cleanup this subtree (this Query_block and all nested Query_blockes and Query_expressions).
Cleanup after preparation of one round of execution.
full | if 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.
void Query_block::cleanup_all_joins | ( | ) |
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:
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.
thd | Current thread |
item | Item for which clone is requested |
derived_table | derived table to which the item belongs to. |
|
inline |
|
overridevirtual |
Query_term methods overridden.
Implements Query_term.
void Query_block::destroy | ( | ) |
Destroy contained objects, in particular temporary tables which may have their own mem_roots.
|
inlineoverridevirtual |
Destroy the query term tree structure.
Implements Query_term.
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.
ident | The table name, may be qualified or unqualified. |
NULL | If not found. |
|
inline |
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.
[in] | field_index | position in the fields list of the derived table. |
|
inline |
|
inline |
Get limit.
Evaluate limit item if necessary.
|
inline |
Get offset for LIMIT.
Evaluate offset item if necessary.
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.
thd | thread handle | |
[out] | new_where | copy of WHERE |
[out] | new_having | copy of HAVING (if passed pointer is not NULL) |
Copies of join (ON) conditions are placed in Table_ref::m_join_cond_optim.
|
inline |
|
inline |
Lookup for a type string.
|
inlinestatic |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void Query_block::include_chain_in_global | ( | Query_block ** | start | ) |
Include chain of query blocks into global list.
start | - Pointer to start of list |
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.
lex | Containing LEX object |
outer | Query expression that query block is added to. |
void Query_block::include_in_global | ( | Query_block ** | plink | ) |
Include query block into global list.
plink | - Pointer to start of list |
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.
lex | Containing LEX object |
before | Query block that this object is added after. |
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.
outer | Query expression this node is included below. |
|
inline |
void Query_block::invalidate | ( | ) |
Invalidate by nulling out pointers to other Query_expressions and Query_blockes.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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 from base options, supplied options and environment:
Make active options from base options, supplied options, any statement options and the environment.
added_options | Options that are added to the active options |
removed_options | Options that are removed from the active options |
|
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
thd | session context |
parent | the parent for which we want to create a materialized access path, or nullptr |
union_all_subpaths | if not nullptr, we are part of a UNION all, add constructed access to it. |
calc_found_rows | if true, do allow for calculation of number of found rows even in presence of LIMIT. |
Implements Query_term.
void Query_block::mark_as_dependent | ( | Query_block * | last, |
bool | aggregate | ||
) |
Mark all query blocks from this to 'last' as dependent.
last | Pointer to last Query_block struct, before which all Query_block are marked as as dependent. |
aggregate | true 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. |
|
inline |
|
inline |
|
inline |
|
overridevirtual |
Open tmp tables for the tree of set operation query results, by recursing.
thd | session context |
level | level in the tree, top should be called with 0. |
Reimplemented from Query_term.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Optimize the non-leaf query blocks.
thd | session context |
qe | owning query expression (of this term) |
Implements Query_term.
|
inline |
|
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
thd | session context |
qe | query expression query expression directly containing this query term |
save_query_block | copy of thd->lex->current_query_block() when Query_expression::prepare was called. |
insert_field_list | pointer to field list if INSERT op, NULL otherwise. |
common_result | for 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_options | these options will be added to the query blocks. |
removed_options | options that cannot be used for this query |
create_options | options to use for creating tmp table |
Implements Query_term.
void Query_block::print | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
void Query_block::print_delete | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print detail of the DELETE statement.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_delete_options | ( | String * | str | ) |
Print DELETE options.
[out] | str | String of output |
Print error.
thd | Thread handler | |
[out] | str | String of output |
false | If there is no error |
true | else |
void Query_block::print_from_clause | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print list of tables in FROM clause.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_group_by | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print list of items in GROUP BY clause.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_having | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print list of items in HAVING clause.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_hints | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print detail of Hints.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_insert | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print detail of the INSERT statement.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
USES: 'INSERT INTO table (fields) VALUES values' syntax over 'INSERT INTO table SET field = value, ...'
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.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_insert_options | ( | String * | str | ) |
Print INSERT options.
[out] | str | String of output |
void Query_block::print_item_list | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print list of items in Query_block object.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_limit | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) | const |
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.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_qualify | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) | const |
Print list of items in QUALIFY clause.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_query_block | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print detail of the Query_block object.
thd | Thread handler | |
query_type | Options to print out string output | |
[out] | str | String of output. |
void Query_block::print_select_options | ( | String * | str | ) |
Print select options.
[out] | str | String of output |
void Query_block::print_table_references | ( | const THD * | thd, |
String * | str, | ||
Table_ref * | table_list, | ||
enum_query_type | query_type | ||
) |
Print list of tables.
thd | Thread handler | |
[out] | str | String of output |
table_list | Table_ref object | |
query_type | Options to print out string output |
void Query_block::print_update | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print detail of the UPDATE statement.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
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 ...
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output | |
fields | List columns to be assigned. | |
values | List of values. |
void Query_block::print_update_options | ( | String * | str | ) |
Print UPDATE options.
[out] | str | String of output |
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.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output | |
values | List of values | |
prefix | Prefix to print before each row in value list = nullptr: No prefix wanted |
void Query_block::print_where_cond | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print list of conditions in WHERE clause.
thd | Thread handle | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::print_windows | ( | const THD * | thd, |
String * | str, | ||
enum_query_type | query_type | ||
) |
Print details of Windowing functions.
thd | Thread handler | |
[out] | str | String of output |
query_type | Options to print out string output |
void Query_block::qbPrint | ( | int | level, |
std::ostringstream & | buf | ||
) | const |
Minion of debugPrint.
|
inline |
|
inline |
|
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.
Implements Query_term.
|
inline |
|
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.
void Query_block::renumber | ( | LEX * | lex | ) |
Renumber query blocks of contained query expressions.
Renumber query_block object, and apply renumbering recursively to contained objects.
lex | Containing LEX object |
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.
|
inline |
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.
thd | thread handler |
|
private |
Helper for save_properties()
Save properties for ORDER clauses so that they can be reconstructed for a new optimization of the query block.
thd | thread handler | |
list | list of ORDER elements to be saved | |
[out] | list_ptrs | Saved list of ORDER elements |
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().
thd | thread handler |
bool Query_block::semijoin_enabled | ( | const THD * | thd | ) | const |
Returns whether semi-join is enabled for this query block.
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.thd | Pointer to THD object for session. Used to access optimizer_switch |
|
inline |
|
inline |
Set base options for a query block (and active options too)
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.
outer_context | Outer name resolution context. NULL if none or it will be set later. |
|
inline |
Set query block as returning no data.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
|
inline |
bool Query_block::setup_base_ref_items | ( | THD * | thd | ) |
Setup the array containing references to base items.
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,.
child_path | the input access path |
dst_table | the table to materialize into |
|
inline |
Subquery_strategy Query_block::subquery_strategy | ( | const THD * | thd | ) | const |
Returns which subquery execution strategies can be used for this query block.
thd | Pointer to THD object for session. Used to access optimizer_switch |
SUBQ_MATERIALIZATION | Subquery Materialization should be used |
SUBQ_EXISTS | In-to-exists execution should be used |
CANDIDATE_FOR_IN2EXISTS_OR_MAT | A cost-based decision should be made |
|
inlineoverridevirtual |
bool Query_block::test_limit | ( | ) |
enum_explain_type Query_block::type | ( | ) | const |
Lookup for Query_block type.
|
overridevirtual |
Implements Query_term.
|
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.
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.
thd | Pointer to THD object for session. Used to access optimizer_switch |
Validate base options for a query block.
lex | LEX of current statement |
options_arg | base options for a SELECT statement. |
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.
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.
lex | LEX of current statement |
option | option name to output within the error message |
|
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.
|
inline |
Wrappers over fields / get_fields_list()
that hide items where item->hidden, meant for range-based for loops.
See sql/visible_fields.h
.
|
inline |
bool Query_block::walk | ( | Item_processor | processor, |
enum_walk | walk, | ||
uchar * | arg | ||
) |
|
inline |
|
inline |
|
friend |
|
friend |
|
private |
Allow merge of immediate unnamed derived tables.
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.
uint Query_block::between_count {0} |
Number of between predicates in where/having/on.
uint Query_block::cond_count {0} |
Number of predicates after preparation.
Item::cond_result Query_block::cond_value {Item::COND_UNDEF} |
Saved values of the WHERE and HAVING clauses.
Allowed values are:
enum_condition_context Query_block::condition_context {enum_condition_context::ANDS} |
Name_resolution_context Query_block::context {} |
Context for name resolution for all column references except columns from joined tables.
char* Query_block::db {nullptr} |
uint Query_block::derived_table_count {0} |
Number of derived tables and views in this query block.
Last table for LATERAL join, used by table functions.
bool Query_block::exclude_from_table_unique_test {false} |
exclude this query block from unique_table() check
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.
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.
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.
List<Item_func_match>* Query_block::ftfunc_list |
A pointer to ftfunc_list_alloc, list of full text search functions.
List<Item_func_match> Query_block::ftfunc_list_alloc {} |
bool Query_block::group_fix_field {false} |
true when GROUP BY fix field called in processing of this query block
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* Query_block::group_list_ptrs {nullptr} |
|
private |
|
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.
bool Query_block::having_fix_field {false} |
true when having fix field called in processing of this query block
Item::cond_result Query_block::having_value {Item::COND_UNDEF} |
|
private |
Number of GROUP BY expressions added to all_fields.
uint Query_block::hidden_items_from_optimization {0} |
Hidden items added during optimization.
|
private |
How many expressions are part of the order by but not select list.
uint Query_block::in_sum_expr {0} |
Parse context: is inside a set function if this is positive.
uint Query_block::in_window_expr {0} |
Parse context: is inside a window function if this is positive.
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.
bool Query_block::is_item_list_lookup {false} |
bool Query_block::is_table_value_constructor {false} |
If set, the query block is of the form VALUES row_list.
After optimization it is pointer to corresponding JOIN.
This member should be changed only when THD::LOCK_query_plan mutex is taken.
uint Query_block::leaf_table_count {0} |
Number of leaf tables in this query block.
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.
|
private |
Intrusive double-linked global list of query blocks.
|
private |
sub_select_type Query_block::linkage {UNSPECIFIED_TYPE} |
Describes context of this query block (e.g if it is a derived table).
|
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.
size_t Query_block::m_added_non_hidden_fields {0} |
|
private |
|
private |
Options assigned from parsing and throughout resolving, should not be modified after resolving is done.
mem_root_deque<Table_ref *>* Query_block::m_current_table_nest |
Pointer to the set of table references in the currently active join.
|
private |
True if query block does not generate any rows before aggregation, determined during preparation (not optimization).
|
private |
Condition to be evaluated on grouped rows after grouping.
bool Query_block::m_internal_limit {false} |
If true, limit object is added internally.
|
private |
bool Query_block::m_limit_1 {false} |
Whether we have LIMIT 1 and no OFFSET.
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.
|
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.
Condition to be evaluated after window functions.
|
private |
Result of this query block.
|
private |
True if query block has right joins.
|
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.
SQL_I_List<Table_ref> Query_block::m_table_list {} |
List of tables in FROM clause - use Table_ref::next_local to traverse.
mem_root_deque<Table_ref *> Query_block::m_table_nest |
Set of table references contained in outer-most join nest.
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.
bool Query_block::m_was_implicitly_grouped {false} |
Used by nested scalar_to_derived transformations.
|
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'.
|
private |
The query expression containing this query block.
uint Query_block::materialized_derived_table_count {0} |
Number of materialized derived tables and views in this query block.
uint Query_block::max_equal_elems {0} |
Maximal number of elements in multiple equalities.
uint Query_block::n_child_sum_items {0} |
Number of Item_sum-derived objects in children and descendant SELECTs.
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.
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.
int Query_block::nest_level {0} |
Nesting level of query block, outer-most query block has level 0, its subqueries have level 1, etc.
|
private |
Intrusive linked list of all query blocks within the same query expression.
bool Query_block::no_table_names_allowed {false} |
used for global order by
olap_type Query_block::olap {UNSPECIFIED_OLAP_TYPE} |
Indicates whether this query block contains non-primitive grouping (such as ROLLUP).
Opt_hints_qb* Query_block::opt_hints_qb {nullptr} |
Query-block-level hints, for this query block.
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.
Group_list_ptrs* Query_block::order_list_ptrs {nullptr} |
table_map Query_block::outer_join {0} |
Bitmap of all inner tables from outer joins.
enum_parsing_context Query_block::parsing_place {CTX_NONE} |
Parse context: indicates where the current expression is being parsed.
uint Query_block::partitioned_table_count {0} |
Number of partitioned tables.
If this query block is a recursive member of a recursive unit: the Table_ref, in this recursive member, referencing the query name.
Table_ref* Query_block::resolve_nest |
Used when resolving outer join condition.
Resolve_place Query_block::resolve_place |
Indicates part of query being resolved.
Prealloced_array<Item_rollup_group_item *, 4> Query_block::rollup_group_items |
Prealloced_array<Item_rollup_sum_switcher *, 4> Query_block::rollup_sums |
mem_root_deque<mem_root_deque<Item *> *>* Query_block::row_value_list {nullptr} |
The VALUES items of a table value constructor.
uint Query_block::saved_cond_count {0} |
Number of arguments of and/or/xor in where/having/on.
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.
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.
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.
uint Query_block::select_number {0} |
Query block number (used for EXPLAIN)
|
private |
Pointer to collection of subqueries candidate for semi/antijoin conversion.
Template parameter is "true": no need to run DTORs on pointers.
mem_root_deque<Table_ref *> Query_block::sj_nests |
List of semi-join nests generated for this query block.
bool Query_block::sj_pullout_done {false} |
True when semi-join pull-out processing is complete.
bool Query_block::skip_local_transforms {false} |
True: skip local transformations during prepare() call (used by INSERT)
|
private |
The first query expression contained within this query block.
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.
uint Query_block::table_func_count {0} |
Number of table functions in this query block.
|
staticprivate |
uint8 Query_block::uncacheable {0} |
result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCACHEABLE_SIDEEFFECT
bool Query_block::with_sum_func {false} |
True if contains or aggregates set functions.
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.