23#ifndef QUERY_NODE_INCLUDED
24#define QUERY_NODE_INCLUDED
290 virtual void cleanup(
bool full [[maybe_unused]]) {
304 int level [[maybe_unused]]) {
443 if (b ==
nullptr)
return true;
452 child->set_sibling_idx(idx++);
453 child->label_children();
459 void cleanup(
bool full)
override;
463 child->destroy_tree();
481 THD *thd,
TABLE *dst_table,
bool union_distinct_only,
482 bool calc_found_rows);
578template <Visit_order visit_order, Visit_leaves visit_leaves>
597 if (root ==
nullptr)
return;
627 if (m_child_idx < m_current->child_count()) {
648 return !((*this) == other);
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1163
Definition: sql_union.h:40
Definition: query_result.h:58
Node type for n-ary EXCEPT.
Definition: query_term.h:521
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:529
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:528
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:249
Query_term_except(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:527
Node type for n-ary INTERSECT.
Definition: query_term.h:508
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:516
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:244
Query_term_intersect(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:514
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:515
Common base class for n-ary set operations, including unary.
Definition: query_term.h:402
int64_t m_last_distinct
Index of last query expression which has <set-op> DISTINCT on its left.
Definition: query_term.h:423
mem_root_deque< Query_term * > m_children
Tree structure.
Definition: query_term.h:415
void destroy_tree() override
Destroy the query term tree structure.
Definition: query_term.h:460
void cleanup(bool full) override
Reset resources used.
Definition: query_term.cc:225
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:430
void print(int level, std::ostringstream &buf, const char *type) const
Common printing minion for set operations.
Definition: query_term.cc:194
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:1388
bool has_mixed_distinct_operators()
Check if this set operation has a mix of DISTINCT and ALL.
Definition: query_term.cc:189
bool set_block(Query_block *b)
Setter for m_block, q.v.
Definition: query_term.h:441
Query_term_set_op(MEM_ROOT *mem_root)
Definition: query_term.h:410
bool is_unary() const
Check if this term is a unary set operation.
Definition: query_term.h:476
Query_block * query_block() const override
Getter for m_block, q.v.
Definition: query_term.h:438
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:211
bool m_is_materialized
true if the result of this set operation is materialized.
Definition: query_term.h:435
size_t child_count() const override
Get the number of children this node has.
Definition: query_term.h:457
Query_block * m_block
Replaces the old "fake" query block for post processing result set with ORDER BY, LIMIT.
Definition: query_term.h:407
void label_children() override
Set the correct value of Query_term::m_sibling_idx recursively for set operations.
Definition: query_term.h:449
A <query primary> which is a parenthesized query expression (aka qe) body with order by clause and/or...
Definition: query_term.h:554
Query_term_unary(MEM_ROOT *mem_root, Query_term *t)
Constructor.
Definition: query_term.h:561
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:426
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:568
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:567
Node type for n-ary UNION.
Definition: query_term.h:495
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:240
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:503
Query_term_union(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:501
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:502
Query term tree structure.
Definition: query_term.h:209
Query_term * pushdown_limit_order_by(Query_term_set_op *parent=nullptr)
Called after contextualization to simplify query, c.f.
Definition: query_term.cc:74
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:284
void cleanup_query_result(bool full)
Cleanup m_setop_query_result, q.v.
Definition: query_term.cc:178
Query_term_set_op * m_parent
Back pointer to the node whose child we are, or nullptr (root term).
Definition: query_term.h:272
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:303
Query_result * m_setop_query_result
The query result for this term.
Definition: query_term.h:358
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:379
void set_setop_query_result(Query_result *rs)
Setter for m_setop_query_result, q.v.
Definition: query_term.h:375
Query_result * setop_query_result()
Getter for m_setop_query_result, q.v.
Definition: query_term.h:377
void set_fields(mem_root_deque< Item * > *fields)
Definition: query_term.h:396
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:282
Table_ref & result_table()
Getter for m_result_table, q.v.
Definition: query_term.h:393
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:388
mem_root_deque< Item * > * fields()
Definition: query_term.h:398
void set_owning_operand()
Setter for m_owning_operand, q.v.
Definition: query_term.h:386
Query_term_set_op * parent() const
Getter for m_parent, q.v.
Definition: query_term.h:280
void set_result_table(Table_ref *tl)
Setter for m_result_table, q.v.
Definition: query_term.h:391
virtual void cleanup(bool full)
Reset resources used.
Definition: query_term.h:290
virtual size_t child_count() const
Get the number of children this node has.
Definition: query_term.h:261
virtual ~Query_term()=default
Node destructor.
uint m_sibling_idx
If parent is non-null, this holds the index of the current sibling.
Definition: query_term.h:276
Table_ref * m_result_table
Result temporary table for the set operation, if applicable.
Definition: query_term.h:367
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:43
bool validate_structure(const Query_term *parent, int depth=0) const
Return true if structure is too deep, i.e.
Definition: query_term.cc:162
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:363
void printPointers(std::ostringstream &buf) const
Print the pointer of this node and its parent to buf.
Definition: query_term.cc:234
static void indent(int level, std::ostringstream &buf)
Print blank space indentation (unit: two) to buf according to level.
Definition: query_term.cc:230
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:33
mem_root_deque< Item * > * m_fields
Used only when streaming, i.e.
Definition: query_term.h:371
The iterator class itself is private.
Definition: query_term.h:584
bool operator!=(const Query_term_iterator &other) const
Definition: query_term.h:647
Query_term_iterator & operator++()
Definition: query_term.h:607
bool operator==(const Query_term_iterator &other) const
Definition: query_term.h:643
Query_term * m_current
Iterator state consists of the next two member variables.
Definition: query_term.h:653
uint m_child_idx
Used to find next child node to dive into, see set_next_child_idx.
Definition: query_term.h:656
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:675
Query_term * operator*()
Definition: query_term.h:641
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:595
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:663
Query_term_iterator()=default
Containing class for iterator over the query term tree.
Definition: query_term.h:579
Query_term_iterator end()
Definition: query_term.h:694
Query_terms(Query_term *root)
Construct an iterator starting at root.
Definition: query_term.h:691
Query_term * m_root
Definition: query_term.h:697
Query_term_iterator begin()
Definition: query_term.h:693
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
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
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1081
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:2871
Query_term_type
This class hierarchy is used to represent SQL structures between <query expression> and <query specif...
Definition: query_term.h:89
@ QT_UNARY
Represents a query primary with parentesized query expression body with order by clause and/or limit/...
Definition: query_term.h:96
@ QT_EXCEPT
Definition: query_term.h:100
@ QT_UNION
Definition: query_term.h:101
@ QT_INTERSECT
Represents the three set operations.
Definition: query_term.h:99
@ QT_QUERY_BLOCK
Represents Query specification, table value constructor and explicit table.
Definition: query_term.h:92
Visit_leaves
Query term iterator template argument type: whether to visit leaf nodes.
Definition: query_term.h:107
@ VL_SKIP_LEAVES
Definition: query_term.h:107
@ VL_VISIT_LEAVES
Definition: query_term.h:107
Visit_order
Query term iterator template argument type: how to visit nodes in tree.
Definition: query_term.h:105
@ QTC_PRE_ORDER
Definition: query_term.h:105
@ QTC_POST_ORDER
Definition: query_term.h:105
required string type
Definition: replication_group_member_actions.proto:34
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83