23#ifndef QUERY_NODE_INCLUDED
24#define QUERY_NODE_INCLUDED
395 bool calc_found_rows) = 0;
433 virtual void cleanup(
bool full [[maybe_unused]]) {
447 int level [[maybe_unused]]) {
575 if (b ==
nullptr)
return true;
591 void cleanup(
bool full)
override;
613 THD *thd,
TABLE *dst_table,
bool union_distinct_only,
614 bool calc_found_rows);
628 bool calc_found_rows)
override;
696 template <Visit_order visit_order, Visit_leaves visit_leaves>
787 bool calc_found_rows)
override;
806template <Visit_order visit_order, Visit_leaves visit_leaves>
825 if (root ==
nullptr)
return;
855 if (m_child_idx < m_current->child_count()) {
876 return !((*this) == other);
RAII class to automate saving/restoring of current_query_block()
Definition: sql_lex.h:5058
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Definition: parse_tree_nodes.h:1793
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1159
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:627
Definition: sql_union.h:40
Definition: query_result.h:58
Node type for n-ary EXCEPT.
Definition: query_term.h:729
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:737
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:736
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:756
Query_term_except(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:735
Node type for n-ary INTERSECT.
Definition: query_term.h:716
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:724
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:751
Query_term_intersect(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:722
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:723
Common base class for n-ary set operations, including unary.
Definition: query_term.h:555
int64_t m_last_distinct
Index of last query expression which has <set-op> DISTINCT on its left.
Definition: query_term.h:675
mem_root_deque< Item * > * m_types
List of aggregated type holder items for the set operation query term.
Definition: query_term.h:693
bool in_right_side_in_except_or_intersect(Query_term *qt)
Definition: query_term.h:635
Query_term * child(size_t idx) const
Get child at given index.
Definition: query_term.h:560
mem_root_deque< Query_term * > m_children
Tree structure.
Definition: query_term.h:660
void destroy_tree() override
Destroy the query term tree structure.
Definition: query_term.h:592
bool check_joined_types()
On top level, check that it was possible to aggregate all collations together for set operation.
Definition: query_term.cc:382
bool is_materialized() const
Getter for m_is_materialized, q.v.
Definition: query_term.h:566
void cleanup(bool full) override
Reset resources used.
Definition: query_term.cc:426
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 wi...
Definition: query_term.cc:431
int64_t first_distinct() const
Getter for m_first_distinct, q.v.
Definition: query_term.h:564
size_t visible_column_count() const override
Return the number of visible columns of the query term.
Definition: query_term.h:633
int64_t m_first_distinct
Presently only needed by EXCEPT set operator: the index of the first DISTINCT set operand: minimum le...
Definition: query_term.h:682
void print(int level, std::ostringstream &buf, const char *type) const
Common printing minion for set operations.
Definition: query_term.cc:395
Mem_root_array< MaterializePathParameters::Operand > setup_materialize_set_op(THD *thd, TABLE *dst_table, bool union_distinct_only, bool calc_found_rows)
Sets up each(*) query block in this query expression for materialization into the given table by maki...
Definition: sql_union.cc:726
bool has_mixed_distinct_operators()
Check if this set operation has a mix of DISTINCT and ALL.
Definition: query_term.cc:377
bool set_block(Query_block *b)
Setter for m_block, q.v.
Definition: query_term.h:573
Query_term_set_op(MEM_ROOT *mem_root)
Definition: query_term.h:641
bool is_unary() const
Check if this term is a unary set operation.
Definition: query_term.h:608
Query_block * query_block() const override
Getter for m_block, q.v.
Definition: query_term.h:570
VisibleFieldsIterator types_iterator() override
Abstract over visible column types: if query block, we offer an iterator over visible fields,...
Definition: query_term.h:630
mem_root_deque< Item * > * types_array() override
Definition: query_term.h:557
bool open_result_tables(THD *thd, int level) override
Open tmp tables for the tree of set operation query results, by recursing.
Definition: query_term.cc:412
void set_is_materialized(bool mat)
Setter for m_is_materialized, q.v.
Definition: query_term.h:568
bool optimize_query_term(THD *thd, Query_expression *qe) override
Optimize the non-leaf query blocks.
Definition: query_term.cc:663
bool m_is_materialized
true if the result of this set operation is materialized.
Definition: query_term.h:666
size_t child_count() const override
Get the number of children this node has.
Definition: query_term.h:589
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...
Definition: query_term.cc:680
int64_t last_distinct() const
Getter for m_last_distinct, q.v.
Definition: query_term.h:562
Query_block * m_block
Query block for post processing result set with ORDER BY, LIMIT for unary and binary set operations.
Definition: query_term.h:687
void label_children() override
Set the correct value of Query_term::m_sibling_idx recursively for set operations.
Definition: query_term.h:581
A <query primary> which is a parenthesized query expression (aka qe) body with order by clause and/or...
Definition: query_term.h:762
mem_root_deque< Item * > * types_array() override
Definition: query_term.h:789
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...
Definition: query_term.cc:346
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_options) override
a) Prepare query blocks, both leaf blocks and blocks reresenting order by/limit in query primaries wi...
Definition: query_term.cc:262
Query_term_unary(MEM_ROOT *mem_root, Query_term *t)
Constructor.
Definition: query_term.h:769
VisibleFieldsIterator types_iterator() override
Abstract over visible column types: if query block, we offer an iterator over visible fields,...
Definition: query_term.h:795
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:364
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:776
size_t visible_column_count() const override
Return the number of visible columns of the query term.
Definition: query_term.h:792
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:775
Node type for n-ary UNION.
Definition: query_term.h:703
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:747
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:711
Query_term_union(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:709
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:710
Query term tree structure.
Definition: query_term.h:216
Query_term * pushdown_limit_order_by(Query_term_set_op *parent=nullptr)
Called after contextualization to simplify query, c.f.
Definition: query_term.cc:94
virtual void label_children()=0
Set the correct value of Query_term::m_sibling_idx recursively for set operations.
virtual Query_block * query_block() const =0
The query_block which holds the ORDER BY and LIMIT information for this set operation.
uint sibling_idx()
Getter for m_sibling_idx, q.v.
Definition: query_term.h:427
void cleanup_query_result(bool full)
Cleanup m_setop_query_result, q.v.
Definition: query_term.cc:241
Query_term_set_op * m_parent
Back pointer to the node whose child we are, or nullptr (root term).
Definition: query_term.h:527
virtual bool open_result_tables(THD *thd, int level)
Open tmp tables for the tree of set operation query results, by recursing.
Definition: query_term.h:446
virtual AccessPath * make_set_op_access_path(THD *thd, Query_term_set_op *parent, Mem_root_array< AppendPathParameters > *union_all_subpaths, bool calc_found_rows)=0
Recursively constructs the access path of the set operation, possibly materializing in a tmp table if...
virtual size_t visible_column_count() const =0
Return the number of visible columns of the query term.
Query_result * m_setop_query_result
The query result for this term.
Definition: query_term.h:538
Query_result_union * setop_query_result_union()
Getter for m_setop_query_result, q.v. Use only if we can down cast.
Definition: query_term.h:502
void set_setop_query_result(Query_result *rs)
Setter for m_setop_query_result, q.v.
Definition: query_term.h:498
Query_result * setop_query_result()
Getter for m_setop_query_result, q.v.
Definition: query_term.h:500
void set_fields(mem_root_deque< Item * > *fields)
Definition: query_term.h:519
virtual Query_term_type term_type() const =0
Get the node tree type.
void set_sibling_idx(uint idx)
Setter for m_sibling_idx, q.v.
Definition: query_term.h:425
Table_ref & result_table()
Getter for m_result_table, q.v.
Definition: query_term.h:516
virtual const char * operator_string() const =0
Get the node type description.
bool owning_operand()
Getter for m_owning_operand, q.v.
Definition: query_term.h:511
virtual bool optimize_query_term(THD *thd, Query_expression *qe)=0
Optimize the non-leaf query blocks.
mem_root_deque< Item * > * fields()
Definition: query_term.h:521
void set_owning_operand()
Setter for m_owning_operand, q.v.
Definition: query_term.h:509
Query_term_set_op * parent() const
Getter for m_parent, q.v.
Definition: query_term.h:423
void set_result_table(Table_ref *tl)
Setter for m_result_table, q.v.
Definition: query_term.h:514
virtual void cleanup(bool full)
Reset resources used.
Definition: query_term.h:433
bool create_tmp_table(THD *thd, ulonglong create_options)
Create a temporary table for a set operation.
Definition: query_term.cc:198
virtual mem_root_deque< Item * > * types_array()=0
virtual size_t child_count() const
Get the number of children this node has.
Definition: query_term.h:268
virtual ~Query_term()=default
Node destructor.
virtual 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_options)=0
a) Prepare query blocks, both leaf blocks and blocks reresenting order by/limit in query primaries wi...
uint m_sibling_idx
If parent is non-null, this holds the index of the current sibling.
Definition: query_term.h:531
Table_ref * m_result_table
Result temporary table for the set operation, if applicable.
Definition: query_term.h:547
std::pair< bool, bool > redundant_order_by(Query_block *block, int level)
Determine if we have a redundant ORDER BY in block.
Definition: query_term.cc:63
bool validate_structure(const Query_term *parent, int depth=0) const
Return true if structure is too deep, i.e.
Definition: query_term.cc:182
virtual void debugPrint(int level, std::ostringstream &buf) const =0
Print the tree rooted at this node to buf.
bool m_owning_operand
The operand of a n-ary set operation (that owns the common query result) has this set to true.
Definition: query_term.h:543
virtual VisibleFieldsIterator types_iterator()=0
Abstract over visible column types: if query block, we offer an iterator over visible fields,...
void printPointers(std::ostringstream &buf) const
Print the pointer of this node and its parent to buf.
Definition: query_term.cc:256
static void indent(int level, std::ostringstream &buf)
Print blank space indentation (unit: two) to buf according to level.
Definition: query_term.cc:252
virtual void destroy_tree()=0
Destroy the query term tree structure.
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...
Definition: query_term.cc:53
mem_root_deque< Item * > * m_fields
Used only when streaming, i.e.
Definition: query_term.h:551
The iterator class itself is private.
Definition: query_term.h:812
bool operator!=(const Query_term_iterator &other) const
Definition: query_term.h:875
Query_term_iterator & operator++()
Definition: query_term.h:835
bool operator==(const Query_term_iterator &other) const
Definition: query_term.h:871
Query_term * m_current
Iterator state consists of the next two member variables.
Definition: query_term.h:881
uint m_child_idx
Used to find next child node to dive into, see set_next_child_idx.
Definition: query_term.h:884
void prepare_for_next_sibling()
Find the index of the next sibling, if any, of m_current qua child of its parent, so we can visit it:...
Definition: query_term.h:903
Query_term * operator*()
Definition: query_term.h:869
Query_term_iterator(Query_term *root)
Construct an iterator over the query term tree rooted in root, optionally skipping the leaves.
Definition: query_term.h:823
void dive_to_leftmost_leaf_of_child()
Starting at m_current->m_children[m_child_index], dive down through any left-most (index == 0) furthe...
Definition: query_term.h:891
Query_term_iterator()=default
Containing class for iterator over the query term tree.
Definition: query_term.h:807
Query_term_iterator end()
Definition: query_term.h:922
Query_terms(Query_term *root)
Construct an iterator starting at root.
Definition: query_term.h:919
Query_term * m_root
Definition: query_term.h:925
Query_term_iterator begin()
Definition: query_term.h:921
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: visible_fields.h:98
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
static bool create_options
Definition: mysqldump.cc:126
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
Definition: buf0block_hint.cc:30
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2872
Query_term_type
This class hierarchy is used to represent SQL structures between <query expression> and <query specif...
Definition: query_term.h:96
@ QT_UNARY
Represents a query primary with parentesized query expression body with order by clause and/or limit/...
Definition: query_term.h:103
@ QT_EXCEPT
Definition: query_term.h:107
@ QT_UNION
Definition: query_term.h:108
@ QT_INTERSECT
Represents the three set operations.
Definition: query_term.h:106
@ QT_QUERY_BLOCK
Represents Query specification, table value constructor and explicit table.
Definition: query_term.h:99
Visit_leaves
Query term iterator template argument type: whether to visit leaf nodes.
Definition: query_term.h:114
@ VL_SKIP_LEAVES
Definition: query_term.h:114
@ VL_VISIT_LEAVES
Definition: query_term.h:114
Visit_order
Query term iterator template argument type: how to visit nodes in tree.
Definition: query_term.h:112
@ QTC_PRE_ORDER
Definition: query_term.h:112
@ QTC_POST_ORDER
Definition: query_term.h:112
required string type
Definition: replication_group_member_actions.proto:34
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
An adapter class to support iteration over an iterator of Item * (typically mem_root_deque<Item *>),...
VisibleFieldsIterator VisibleFields(mem_root_deque< Item * > &fields)
Definition: visible_fields.h:119