MySQL 8.0.32
Source Code Documentation
Query_expression Class Reference

This class represents a query expression (one query block or several query blocks combined with UNION). More...

#include <sql_lex.h>

Public Types

enum  enum_clean_state { UC_DIRTY , UC_PART_CLEAN , UC_CLEAN }
 Values for Query_expression::cleaned. More...
 

Public Member Functions

Query_termquery_term () const
 Getter for m_query_term, q.v. More...
 
void set_query_term (Query_term *qt)
 Setter for m_query_term, q.v. More...
 
Query_term_set_opset_operation () const
 Convenience method to avoid down casting, i.e. More...
 
Query_blocknon_simple_result_query_block () const
 Return the query block iff !is_simple() holds. More...
 
bool is_leaf_block (Query_block *qb)
 
Query_termfind_blocks_query_term (const Query_block *qb) const
 
template<Visit_order order = QTC_POST_ORDER, Visit_leaves visit_leaves = VL_VISIT_LEAVES>
Query_terms< order, visit_leaves > query_terms () const
 Return iterator object over query terms rooted in m_query_term, using either post order visiting (default) or pre order, optionally skipping leaf nodes (query blocks corresponding to SELECTs or table constructors). More...
 
Query_blocklast_distinct () const
 Return the Query_block of the last query term in a n-ary set operation that is the right side of the last DISTINCT set operation in that n_ary set operation: E.e. More...
 
bool has_top_level_distinct () const
 
 Query_expression (enum_parsing_context parsing_context)
 Construct and initialize Query_expression object. More...
 
bool is_simple () const
 
Query_blockglobal_parameters () const
 Return the query block holding the top level ORDER BY, LIMIT and OFFSET. More...
 
bool is_mergeable () const
 Return true if query expression can be merged into an outer query, based on technical constraints. More...
 
bool merge_heuristic (const LEX *lex) const
 True if heuristics suggest to merge this query expression. More...
 
Query_blockouter_query_block () const
 
Query_blockfirst_query_block () const
 
Query_expressionnext_query_expression () const
 
Query_resultquery_result () const
 
RowIteratorroot_iterator () const
 
unique_ptr_destroy_only< RowIteratorrelease_root_iterator ()
 
AccessPathroot_access_path () const
 
void change_to_access_path_without_in2exists (THD *thd)
 
void clear_root_access_path ()
 
bool force_create_iterators (THD *thd)
 Ensures that there are iterators created for the access paths created by optimize(), even if it was called with create_access_paths = false. More...
 
bool unfinished_materialization () const
 See optimize(). More...
 
Mem_root_array< MaterializePathParameters::QueryBlockrelease_query_blocks_to_materialize ()
 See optimize(). More...
 
void set_query_result (Query_result *res)
 Set new query result object for this query expression. More...
 
bool can_materialize_directly_into_result () const
 Whether there is a chance that optimize() is capable of materializing directly into a result table if given one. More...
 
bool prepare (THD *thd, Query_result *result, mem_root_deque< Item * > *insert_field_list, ulonglong added_options, ulonglong removed_options)
 Prepares all query blocks of a query expression, including fake_query_block. More...
 
bool optimize (THD *thd, TABLE *materialize_destination, bool create_iterators, bool finalize_access_paths)
 If and only if materialize_destination is non-nullptr, it means that the caller intends to materialize our result into the given table. More...
 
bool finalize (THD *thd)
 For any non-finalized query block, finalize it so that we are allowed to create iterators. More...
 
bool ClearForExecution ()
 Do everything that would be needed before running Init() on the root iterator. More...
 
bool ExecuteIteratorQuery (THD *thd)
 
bool execute (THD *thd)
 Execute a query expression that may be a UNION and/or have an ordered result. More...
 
bool explain (THD *explain_thd, const THD *query_thd)
 Explain query starting from this unit. More...
 
bool explain_query_term (THD *explain_thd, const THD *query_thd, Query_term *qt)
 
void cleanup (bool full)
 Cleanup this query expression object after preparation or one round of execution. More...
 
void destroy ()
 Destroy contained objects, in particular temporary tables which may have their own mem_roots. More...
 
void print (const THD *thd, String *str, enum_query_type query_type)
 
bool accept (Select_lex_visitor *visitor)
 
Query_blockcreate_post_processing_block ()
 Create a block to be used for ORDERING and LIMIT/OFFSET processing of a query term, which isn't itself a query specification or table value constructor. More...
 
bool prepare_query_term (THD *thd, Query_term *qts, Query_result *common_result, ulonglong added_options, ulonglong create_options, int level, Mem_root_array< bool > &nullable)
 Prepare the query term nodes and their associated post processing query blocks (i.e. More...
 
void set_prepared ()
 
void set_optimized ()
 
void set_executed ()
 
void reset_executed ()
 Reset this query expression for repeated evaluation within same execution. More...
 
void clear_execution ()
 Clear execution state, needed before new execution of prepared statement. More...
 
bool is_prepared () const
 Check state of preparation of the contained query expression. More...
 
bool is_optimized () const
 Check state of optimization of the contained query expression. More...
 
bool is_executed () const
 Check state of execution of the contained query expression. More...
 
bool change_query_result (THD *thd, Query_result_interceptor *result, Query_result_interceptor *old_result)
 Change the query result object used to return the final result of the unit, replacing occurrences of old_result with new_result. More...
 
bool set_limit (THD *thd, Query_block *provider)
 Set limit and offset for query expression object. More...
 
bool has_any_limit () const
 Checks if this query expression has limit defined. More...
 
bool is_union () const
 
bool is_set_operation () const
 
void include_down (LEX *lex, Query_block *outer)
 Include a query expression below a query block. More...
 
void exclude_level ()
 Exclude this unit and immediately contained query_block objects. More...
 
void exclude_tree ()
 Exclude subtree of current unit from tree of SELECTs. More...
 
void renumber_selects (LEX *lex)
 Renumber query blocks of a query expression according to supplied LEX. More...
 
void restore_cmd_properties ()
 Loop over all query blocks and restore information needed for optimization, including binding data for all associated tables. More...
 
bool save_cmd_properties (THD *thd)
 Save prepared statement properties for a query expression and underlying query blocks. More...
 
mem_root_deque< Item * > * get_unit_column_types ()
 Get column type information for this query expression. More...
 
mem_root_deque< Item * > * get_field_list ()
 Get field list for this query expression. More...
 
size_t num_visible_fields () const
 
enum_parsing_context get_explain_marker (const THD *thd) const
 
void set_explain_marker (THD *thd, enum_parsing_context m)
 
void set_explain_marker_from (THD *thd, const Query_expression *u)
 
void assert_not_fully_clean ()
 Asserts that none of {this unit and its children units} is fully cleaned up. More...
 
void invalidate ()
 Invalidate by nulling out pointers to other Query expressions and Query blocks. More...
 
bool is_recursive () const
 
bool check_materialized_derived_query_blocks (THD *thd)
 Sets up query blocks belonging to the query expression of a materialized derived table. More...
 
bool clear_correlated_query_blocks ()
 Empties all correlated query blocks defined within the query expression; that is, correlated CTEs defined in the expression's WITH clause, and correlated derived tables. More...
 
void fix_after_pullout (Query_block *parent_query_block, Query_block *removed_query_block)
 Fix used tables information for a subquery after query transformations. More...
 
void accumulate_used_tables (table_map map)
 If unit is a subquery, which forms an object of the upper level (an Item_subselect, a derived Table_ref), adds to this object a map of tables of the upper level which the unit references. More...
 
enum_parsing_context place () const
 If unit is a subquery, which forms an object of the upper level (an Item_subselect, a derived Table_ref), returns the place of this object in the upper level query block. More...
 
bool walk (Item_processor processor, enum_walk walk, uchar *arg)
 

Public Attributes

uint8 uncacheable
 result of this query can't be cached, bit field, can be : UNCACHEABLE_DEPENDENT UNCACHEABLE_RAND UNCACHEABLE_SIDEEFFECT More...
 
enum_clean_state cleaned
 cleanliness state More...
 
ha_rows select_limit_cnt
 
ha_rows offset_limit_cnt
 
Item_subselectitem
 Points to subquery if this query expression is used in one, otherwise NULL. More...
 
PT_with_clausem_with_clause
 The WITH clause which is the first part of this query expression. More...
 
Table_refderived_table
 If this query expression is underlying of a derived table, the derived table. More...
 
Query_blockfirst_recursive
 First query block (in this UNION) which references the CTE. More...
 
table_map m_lateral_deps
 If 'this' is body of lateral derived table: map of tables in the same FROM clause as this derived table, and to which the derived table's body makes references. More...
 
bool m_reject_multiple_rows {false}
 This query expression represents a scalar subquery and we need a run-time check that the cardinality doesn't exceed 1. More...
 
ha_rows send_records
 

Private Member Functions

void create_access_paths (THD *thd)
 Convert the executor structures to a set of access paths, storing the result in m_root_access_path. More...
 

Private Attributes

Query_expressionnext
 Intrusive double-linked list of all query expressions immediately contained within the same query block. More...
 
Query_expression ** prev
 
Query_blockmaster
 The query block wherein this query expression is contained, NULL if the query block is the outer-most one. More...
 
Query_blockslave
 The first query block in this query expression. More...
 
Query_termm_query_term {nullptr}
 
enum_parsing_context explain_marker
 Marker for subqueries in WHERE, HAVING, ORDER BY, GROUP BY and SELECT item lists. More...
 
bool prepared
 All query blocks in query expression are prepared. More...
 
bool optimized
 All query blocks in query expression are optimized. More...
 
bool executed
 Query expression has been executed. More...
 
Query_resultm_query_result
 Object to which the result for this query expression is sent. More...
 
unique_ptr_destroy_only< RowIteratorm_root_iterator
 An iterator you can read from to get all records for this query. More...
 
AccessPathm_root_access_path = nullptr
 
Mem_root_array< MaterializePathParameters::QueryBlockm_query_blocks_to_materialize
 If there is an unfinished materialization (see optimize()), contains one element for each query block in this query expression. More...
 
mem_root_deque< Item * > types
 

Friends

class Query_block
 
bool parse_view_definition (THD *thd, Table_ref *view_ref)
 Parse a view definition. More...
 

Detailed Description

This class represents a query expression (one query block or several query blocks combined with UNION).

Member Enumeration Documentation

◆ enum_clean_state

Values for Query_expression::cleaned.

Enumerator
UC_DIRTY 

Unit isn't cleaned.

UC_PART_CLEAN 

Unit were cleaned, except JOIN and JOIN_TABs were kept for possible EXPLAIN.

UC_CLEAN 

Unit completely cleaned, all underlying JOINs were freed.

Constructor & Destructor Documentation

◆ Query_expression()

Query_expression::Query_expression ( enum_parsing_context  parsing_context)
explicit

Construct and initialize Query_expression object.

Member Function Documentation

◆ accept()

bool Query_expression::accept ( Select_lex_visitor visitor)

◆ accumulate_used_tables()

void Query_expression::accumulate_used_tables ( table_map  map)

If unit is a subquery, which forms an object of the upper level (an Item_subselect, a derived Table_ref), adds to this object a map of tables of the upper level which the unit references.

◆ assert_not_fully_clean()

void Query_expression::assert_not_fully_clean ( )

Asserts that none of {this unit and its children units} is fully cleaned up.

◆ can_materialize_directly_into_result()

bool Query_expression::can_materialize_directly_into_result ( ) const

Whether there is a chance that optimize() is capable of materializing directly into a result table if given one.

Note that even if this function returns true, optimize() can choose later not to do so, since it depends on information (in particular, whether the query blocks can run under the iterator executor or not) that is not available before optimize time.

TODO(sgunders): Now that all query blocks can run under the iterator executor, the above may no longer be true. This needs investigation.

◆ change_query_result()

bool Query_expression::change_query_result ( THD thd,
Query_result_interceptor new_result,
Query_result_interceptor old_result 
)

Change the query result object used to return the final result of the unit, replacing occurrences of old_result with new_result.

Parameters
thdThread handle
new_resultNew query result object
old_resultOld query result object
Return values
falseSuccess
trueError

◆ change_to_access_path_without_in2exists()

void Query_expression::change_to_access_path_without_in2exists ( THD thd)

◆ check_materialized_derived_query_blocks()

bool Query_expression::check_materialized_derived_query_blocks ( THD thd_arg)

Sets up query blocks belonging to the query expression of a materialized derived table.

Parameters
thd_argTHD pointer
Returns
false if successful, true if error

◆ cleanup()

void Query_expression::cleanup ( bool  full)

Cleanup this query expression object after preparation or one round of execution.

After the cleanup, the object can be reused for a new round of execution, but a new optimization will be needed before the execution.

◆ clear_correlated_query_blocks()

bool Query_expression::clear_correlated_query_blocks ( )

Empties all correlated query blocks defined within the query expression; that is, correlated CTEs defined in the expression's WITH clause, and correlated derived tables.

◆ clear_execution()

void Query_expression::clear_execution ( )
inline

Clear execution state, needed before new execution of prepared statement.

◆ clear_root_access_path()

void Query_expression::clear_root_access_path ( )
inline

◆ ClearForExecution()

bool Query_expression::ClearForExecution ( )

Do everything that would be needed before running Init() on the root iterator.

In particular, clear out data from previous execution iterations, if needed.

◆ create_access_paths()

void Query_expression::create_access_paths ( THD thd)
private

Convert the executor structures to a set of access paths, storing the result in m_root_access_path.

◆ create_post_processing_block()

Query_block * Query_expression::create_post_processing_block ( )

Create a block to be used for ORDERING and LIMIT/OFFSET processing of a query term, which isn't itself a query specification or table value constructor.

Such blocks are not included in the list starting in Query_Expression::first_query_block, and Query_block::next_query_block(). They blocks are accessed via Query_term::query_block().

Returns
a query block

◆ destroy()

void Query_expression::destroy ( )

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

◆ exclude_level()

void Query_expression::exclude_level ( )

Exclude this unit and immediately contained query_block objects.

Exclude this query expression and its immediately contained query terms and query blocks from AST.

Note
Query expressions that belong to the query_block objects of the current query expression will be brought up one level and will replace the current query expression in the list inside the outer query block.

◆ exclude_tree()

void Query_expression::exclude_tree ( )

Exclude subtree of current unit from tree of SELECTs.

Exclude current query expression with all underlying query terms, query blocks and query expressions from AST.

◆ execute()

bool Query_expression::execute ( THD thd)

Execute a query expression that may be a UNION and/or have an ordered result.

Parameters
thdthread handle
Returns
false if success, true if error

◆ ExecuteIteratorQuery()

bool Query_expression::ExecuteIteratorQuery ( THD thd)

◆ explain()

bool Query_expression::explain ( THD explain_thd,
const THD query_thd 
)

Explain query starting from this unit.

Parameters
explain_thdthread handle for the connection doing explain
query_thdthread handle for the connection being explained
Returns
false if success, true if error

◆ explain_query_term()

bool Query_expression::explain_query_term ( THD explain_thd,
const THD query_thd,
Query_term qt 
)

◆ finalize()

bool Query_expression::finalize ( THD thd)

For any non-finalized query block, finalize it so that we are allowed to create iterators.

Must be called after the final access path is chosen (ie., after any calls to change_to_access_path_without_in2exists()).

◆ find_blocks_query_term()

Query_term * Query_expression::find_blocks_query_term ( const Query_block qb) const
inline

◆ first_query_block()

Query_block * Query_expression::first_query_block ( ) const
inline
Returns
the first query block inside this query expression

◆ force_create_iterators()

bool Query_expression::force_create_iterators ( THD thd)

Ensures that there are iterators created for the access paths created by optimize(), even if it was called with create_access_paths = false.

If there are already iterators, it is a no-op. optimize() must have been called earlier.

The use case for this is if we have a query block that's not top-level, but we figure out after the fact that we wanted to run it anyway. The typical case would be that we notice that the query block can return at most one row (a so-called const table), and want to run it during optimization.

◆ get_explain_marker()

enum_parsing_context Query_expression::get_explain_marker ( const THD thd) const

◆ get_field_list()

mem_root_deque< Item * > * Query_expression::get_field_list ( )

Get field list for this query expression.

For a UNION of query blocks, return the field list generated during prepare. For a single query block, return the field list after all possible intermediate query processing steps are done (optimization is complete).

Returns
List containing fields of the query expression.

◆ get_unit_column_types()

mem_root_deque< Item * > * Query_expression::get_unit_column_types ( )

Get column type information for this query expression.

For a single query block the column types are taken from the list of selected items of this block.

For a union this function assumes that the type holders were created for unioned column types of all query blocks, by Query_expression::prepare().

Note
The implementation of this function should be in sync with Query_expression::prepare()
Returns
List of items as specified in function description. May contain hidden fields (item->hidden = true), so the caller needs to be able to filter them out.

◆ global_parameters()

Query_block * Query_expression::global_parameters ( ) const
inline

Return the query block holding the top level ORDER BY, LIMIT and OFFSET.

If the query is not a set operation (UNION, INTERSECT or EXCEPT, and the query expression has no multi-level ORDER BY/LIMIT, this represents the single query block of the query itself, cf. documentation for class Query_term.

Returns
query block containing the global parameters

◆ has_any_limit()

bool Query_expression::has_any_limit ( ) const

Checks if this query expression has limit defined.

For a query expression with set operation it checks if any of the query blocks has limit defined.

Returns
true if the query expression has limit. false otherwise.

◆ has_top_level_distinct()

bool Query_expression::has_top_level_distinct ( ) const
inline

◆ include_down()

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

Include a query expression below a query block.

Parameters
lexContaining LEX object
outerThe query block that this query expression is included below.

◆ invalidate()

void Query_expression::invalidate ( )

Invalidate by nulling out pointers to other Query expressions and Query blocks.

◆ is_executed()

bool Query_expression::is_executed ( ) const
inline

Check state of execution of the contained query expression.

Should not be used to check the state of a complete statement, use LEX::is_exec_completed() instead.

◆ is_leaf_block()

bool Query_expression::is_leaf_block ( Query_block qb)

◆ is_mergeable()

bool Query_expression::is_mergeable ( ) const

Return true if query expression can be merged into an outer query, based on technical constraints.

Returns
true if query expression can be merged into an outer query

Being mergeable also means that derived table/view is updatable.

A view/derived table is not mergeable if it is one of the following:

  • A set operation (implementation restriction).
  • An aggregated query, or has HAVING, or has DISTINCT (A general aggregated query cannot be merged with a non-aggregated one).
  • A table-less query (unimportant special case).
  • A query with a LIMIT (limit applies to subquery, so the implementation strategy is to materialize this subquery, including row count constraint).
  • It has windows

◆ is_optimized()

bool Query_expression::is_optimized ( ) const
inline

Check state of optimization of the contained query expression.

◆ is_prepared()

bool Query_expression::is_prepared ( ) const
inline

Check state of preparation of the contained query expression.

◆ is_recursive()

bool Query_expression::is_recursive ( ) const
inline

◆ is_simple()

bool Query_expression::is_simple ( ) const
inline
Returns
true for a query expression without UNION/INTERSECT/EXCEPT or multi-level ORDER, i.e. we have a "simple table".

◆ last_distinct()

Query_block * Query_expression::last_distinct ( ) const
inline

Return the Query_block of the last query term in a n-ary set operation that is the right side of the last DISTINCT set operation in that n_ary set operation: E.e.

for A UNION B UNION ALL C, B's block will be returned. If no DISTINCT is present or not a set operation, return nullptr.

Returns
query block of last distinct right operand

◆ merge_heuristic()

bool Query_expression::merge_heuristic ( const LEX lex) const

True if heuristics suggest to merge this query expression.

Returns
true if query expression is recommended to be merged

A view/derived table is not suggested for merging if it contains subqueries in the SELECT list that depend on columns from itself. Merging such objects is possible, but we assume they are made derived tables because the user wants them to be materialized, for performance reasons.

One possible case is a derived table with dependent subqueries in the select list, used as the inner table of a left outer join. Such tables will always be read as many times as there are qualifying rows in the outer table, and the select list subqueries are evaluated for each row combination. The select list subqueries are evaluated the same number of times also with join buffering enabled, even though the table then only will be read once.

Another case is, a query that modifies variables: then try to preserve the original structure of the query. This is less likely to cause changes in variable assignment order.

◆ next_query_expression()

Query_expression * Query_expression::next_query_expression ( ) const
inline
Returns
the next query expression within same query block (next subquery)

◆ non_simple_result_query_block()

Query_block * Query_expression::non_simple_result_query_block ( ) const
inline

Return the query block iff !is_simple() holds.

◆ num_visible_fields()

size_t Query_expression::num_visible_fields ( ) const

◆ optimize()

bool Query_expression::optimize ( THD thd,
TABLE materialize_destination,
bool  create_iterators,
bool  finalize_access_paths 
)

If and only if materialize_destination is non-nullptr, it means that the caller intends to materialize our result into the given table.

If it is advantageous (in particular, if this query expression is a UNION DISTINCT), optimize() will not create an iterator by itself, but rather do an unfinished materialize. This means that it will collect iterators for all the query blocks and prepare them for materializing into the given table, but not actually create a root iterator for this query expression; the caller is responsible for calling release_query_blocks_to_materialize() and creating the iterator itself.

Even if materialize_destination is non-nullptr, this function may choose to make a regular iterator. The caller is responsible for checking unfinished_materialization() if it has given a non-nullptr table.

Parameters
thdThread handle.
materialize_destinationWhat table to try to materialize into, or nullptr if the caller does not intend to materialize the result.
create_iteratorsIf false, only access paths are created, not iterators. Only top level query blocks (these that we are to call exec() on) should have iterators. See also force_create_iterators().
finalize_access_pathsRelevant for the hypergraph optimizer only. If false, the given access paths will not be finalized, so you cannot create iterators from it before finalize() is called (see FinalizePlanForQueryBlock()), and create_iterators must also be false. This is relevant only if you are potentially optimizing multiple times (see change_to_access_path_without_in2exists()), since you are only allowed to finalize a query block once. "Fake" query blocks (see query_term.h) are always finalized.

◆ outer_query_block()

Query_block * Query_expression::outer_query_block ( ) const
inline
Returns
the query block this query expression belongs to as subquery

◆ place()

enum_parsing_context Query_expression::place ( ) const

If unit is a subquery, which forms an object of the upper level (an Item_subselect, a derived Table_ref), returns the place of this object in the upper level query block.

◆ prepare()

bool Query_expression::prepare ( THD thd,
Query_result sel_result,
mem_root_deque< Item * > *  insert_field_list,
ulonglong  added_options,
ulonglong  removed_options 
)

Prepares all query blocks of a query expression, including fake_query_block.

If a recursive query expression, this also creates the materialized temporary table.

Parameters
thdThread handler
sel_resultResult object where the unit's output should go.
insert_field_listPointer to field list if INSERT op, NULL otherwise.
added_optionsThese options will be added to the query blocks.
removed_optionsOptions that cannot be used for this query
Returns
false if success, true if error

◆ prepare_query_term()

bool Query_expression::prepare_query_term ( THD thd,
Query_term qt,
Query_result common_result,
ulonglong  added_options,
ulonglong  create_options,
int  level,
Mem_root_array< bool > &  nullable 
)

Prepare the query term nodes and their associated post processing query blocks (i.e.

not the ones representing the query specifications), but rather ORDER BY/LIMIT processing (old "fake" query blocks). Also create temporary tables to consolidate set operations as needed, recursively.

Parameters
thdsession context
qtthe query term at the current level in the tree
common_resultFor the top node, this is not used: we use query_result() instead. Otherwise, if it is empty, we create one a query result 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_optionsoptions to add for the post processing query block
create_optionsoptions to use for creating tmp table
levelthe current level in the query expression's query term tree
[in,out]nullablecomputed nullability for the query's result set columns
Returns
false on success, true on error

We are part of upper level set op

◆ print()

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

◆ query_result()

Query_result * Query_expression::query_result ( ) const
inline
Returns
the query result object in use for this query expression

◆ query_term()

Query_term * Query_expression::query_term ( ) const
inline

Getter for m_query_term, q.v.

◆ query_terms()

template<Visit_order order = QTC_POST_ORDER, Visit_leaves visit_leaves = VL_VISIT_LEAVES>
Query_terms< order, visit_leaves > Query_expression::query_terms ( ) const
inline

Return iterator object over query terms rooted in m_query_term, using either post order visiting (default) or pre order, optionally skipping leaf nodes (query blocks corresponding to SELECTs or table constructors).

By default, we visit all nodes. Usage: for (auto qt : query_terms<..>() { ... } E.g. for (auto qt : query_terms<>()) { } Visit all nodes, post order for (auto qt : query_terms<QTC_PRE_ORDER, false>()) { } Skip leaves, pre order

Template Parameters
order== QTC_POST_ORDER if post order traversal is desired;default == QTC_PRE_ORDER pre-order traversal
visit_leaves== VL_VISIT_LEAVES: if we want the traversal to include leaf nodes i.e. the SELECTs or table constructors == VL_SKIP_LEAVES: leaves will be skipped
Returns
iterator object

◆ release_query_blocks_to_materialize()

Mem_root_array< MaterializePathParameters::QueryBlock > Query_expression::release_query_blocks_to_materialize ( )
inline

See optimize().

◆ release_root_iterator()

unique_ptr_destroy_only< RowIterator > Query_expression::release_root_iterator ( )
inline

◆ renumber_selects()

void Query_expression::renumber_selects ( LEX lex)

Renumber query blocks of a query expression according to supplied LEX.

Renumber contained query_block objects.

Parameters
lexContaining LEX object

◆ reset_executed()

void Query_expression::reset_executed ( )
inline

Reset this query expression for repeated evaluation within same execution.

◆ restore_cmd_properties()

void Query_expression::restore_cmd_properties ( )

Loop over all query blocks and restore information needed for optimization, including binding data for all associated tables.

◆ root_access_path()

AccessPath * Query_expression::root_access_path ( ) const
inline

◆ root_iterator()

RowIterator * Query_expression::root_iterator ( ) const
inline

◆ save_cmd_properties()

bool Query_expression::save_cmd_properties ( THD thd)

Save prepared statement properties for a query expression and underlying query blocks.

Required for repeated optimizations of the command.

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

◆ set_executed()

void Query_expression::set_executed ( )
inline

◆ set_explain_marker()

void Query_expression::set_explain_marker ( THD thd,
enum_parsing_context  m 
)

◆ set_explain_marker_from()

void Query_expression::set_explain_marker_from ( THD thd,
const Query_expression u 
)

◆ set_limit()

bool Query_expression::set_limit ( THD thd,
Query_block provider 
)

Set limit and offset for query expression object.

Parameters
thdthread handler
providerQuery_block to get offset and limit from.
Returns
false if success, true if error

◆ set_operation()

Query_term_set_op * Query_expression::set_operation ( ) const
inline

Convenience method to avoid down casting, i.e.

interpret m_query_term as a Query_term_set_op.

Return values
anon-null node iff !is_simple
nullptrif is_simple() holds.

◆ set_optimized()

void Query_expression::set_optimized ( )
inline

◆ set_prepared()

void Query_expression::set_prepared ( )
inline

◆ set_query_result()

void Query_expression::set_query_result ( Query_result res)
inline

Set new query result object for this query expression.

◆ set_query_term()

void Query_expression::set_query_term ( Query_term qt)
inline

Setter for m_query_term, q.v.

◆ unfinished_materialization()

bool Query_expression::unfinished_materialization ( ) const
inline

See optimize().

◆ walk()

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

Friends And Related Function Documentation

◆ parse_view_definition

bool parse_view_definition ( THD thd,
Table_ref view_ref 
)
friend

Parse a view definition.

Among other effects, it adds underlying tables to the global list of tables, so the next iteration in open_tables() will open them.

Parameters
[in]thdThread handler
[in,out]view_refTable_ref structure for view reference
Returns
false-in case of success, true-in case of error.
Note
In case true value returned an error has been already set in DA.

◆ Query_block

friend class Query_block
friend

Member Data Documentation

◆ cleaned

enum_clean_state Query_expression::cleaned

cleanliness state

◆ derived_table

Table_ref* Query_expression::derived_table

If this query expression is underlying of a derived table, the derived table.

NULL if none.

◆ executed

bool Query_expression::executed
private

Query expression has been executed.

◆ explain_marker

enum_parsing_context Query_expression::explain_marker
private

Marker for subqueries in WHERE, HAVING, ORDER BY, GROUP BY and SELECT item lists.

Must be read/written when holding LOCK_query_plan.

See Item_subselect::explain_subquery_checker

◆ first_recursive

Query_block* Query_expression::first_recursive

First query block (in this UNION) which references the CTE.

NULL if not the query expression of a recursive CTE.

◆ item

Item_subselect* Query_expression::item

Points to subquery if this query expression is used in one, otherwise NULL.

◆ m_lateral_deps

table_map Query_expression::m_lateral_deps

If 'this' is body of lateral derived table: map of tables in the same FROM clause as this derived table, and to which the derived table's body makes references.

In pre-resolution stages, this is OUTER_REF_TABLE_BIT, just to indicate that this has LATERAL; after resolution, which has found references in the body, this is the proper map (with no PSEUDO_TABLE_BITS anymore).

◆ m_query_blocks_to_materialize

Mem_root_array<MaterializePathParameters::QueryBlock> Query_expression::m_query_blocks_to_materialize
private

If there is an unfinished materialization (see optimize()), contains one element for each query block in this query expression.

◆ m_query_result

Query_result* Query_expression::m_query_result
private

Object to which the result for this query expression is sent.

Not used if we materialize directly into a parent query expression's result table (see optimize()).

◆ m_query_term

Query_term* Query_expression::m_query_term {nullptr}
private

◆ m_reject_multiple_rows

bool Query_expression::m_reject_multiple_rows {false}

This query expression represents a scalar subquery and we need a run-time check that the cardinality doesn't exceed 1.

◆ m_root_access_path

AccessPath* Query_expression::m_root_access_path = nullptr
private

◆ m_root_iterator

unique_ptr_destroy_only<RowIterator> Query_expression::m_root_iterator
private

An iterator you can read from to get all records for this query.

May be nullptr even after create_access_paths(), or in the case of an unfinished materialization (see optimize()).

◆ m_with_clause

PT_with_clause* Query_expression::m_with_clause

The WITH clause which is the first part of this query expression.

NULL if none.

◆ master

Query_block* Query_expression::master
private

The query block wherein this query expression is contained, NULL if the query block is the outer-most one.

◆ next

Query_expression* Query_expression::next
private

Intrusive double-linked list of all query expressions immediately contained within the same query block.

◆ offset_limit_cnt

ha_rows Query_expression::offset_limit_cnt

◆ optimized

bool Query_expression::optimized
private

All query blocks in query expression are optimized.

◆ prepared

bool Query_expression::prepared
private

All query blocks in query expression are prepared.

◆ prev

Query_expression** Query_expression::prev
private

◆ select_limit_cnt

ha_rows Query_expression::select_limit_cnt

◆ send_records

ha_rows Query_expression::send_records

◆ slave

Query_block* Query_expression::slave
private

The first query block in this query expression.

◆ types

mem_root_deque<Item *> Query_expression::types
private

◆ uncacheable

uint8 Query_expression::uncacheable

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


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