22#ifndef QUERY_NODE_INCLUDED
23#define QUERY_NODE_INCLUDED
277 virtual void cleanup(
bool full [[maybe_unused]]) {
291 int level [[maybe_unused]]) {
391 template <Visit_order order, Visit_leaves visit_leaves>
437 if (b ==
nullptr)
return true;
445 void cleanup(
bool full)
override;
449 child->destroy_tree();
468 bool calc_found_rows);
563template <Visit_order visit_order, Visit_leaves visit_leaves>
645 return !((*this) == other);
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1153
Definition: sql_union.h:39
Definition: query_result.h:53
Node type for n-ary EXCEPT.
Definition: query_term.h:507
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:515
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:514
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:239
Query_term_except(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:513
Node type for n-ary INTERSECT.
Definition: query_term.h:494
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:502
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:234
Query_term_intersect(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:500
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:501
Common base class for n-ary set operations, including unary.
Definition: query_term.h:396
int64_t m_last_distinct
Index of last query expression which has <set-op> DISTINCT on its left.
Definition: query_term.h:417
mem_root_deque< Query_term * > m_children
Tree structure.
Definition: query_term.h:409
void destroy_tree() override
Destroy the query term tree structure.
Definition: query_term.h:446
void cleanup(bool full) override
Reset resources used.
Definition: query_term.cc:215
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:424
void print(int level, std::ostringstream &buf, const char *type) const
Common printing minion for set operations.
Definition: query_term.cc:184
bool has_mixed_distinct_operators()
Check if this set operation has a mix of DISTINCT and ALL.
Definition: query_term.cc:179
bool set_block(Query_block *b)
Setter for m_block, q.v.
Definition: query_term.h:435
Query_term_set_op(MEM_ROOT *mem_root)
Definition: query_term.h:404
bool is_unary() const
Check if this term is a unary set operation.
Definition: query_term.h:462
Query_block * query_block() const override
Getter for m_block, q.v.
Definition: query_term.h:432
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:201
bool m_is_materialized
true if the result of this set operation is materialized.
Definition: query_term.h:429
size_t child_count() const override
Get the number of children this node has.
Definition: query_term.h:443
Query_block * m_block
Replaces the old "fake" query block for post processing result set with ORDER BY, LIMIT.
Definition: query_term.h:401
Mem_root_array< MaterializePathParameters::QueryBlock > 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:1379
A <query primary> which is a parenthesized query expression (aka qe) body with order by clause and/or...
Definition: query_term.h:540
Query_term_unary(MEM_ROOT *mem_root, Query_term *t)
Constructor.
Definition: query_term.h:547
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:415
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:553
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:552
Node type for n-ary UNION.
Definition: query_term.h:481
void debugPrint(int level, std::ostringstream &buf) const override
Print the tree rooted at this node to buf.
Definition: query_term.cc:230
const char * operator_string() const override
Get the node type description.
Definition: query_term.h:489
Query_term_union(MEM_ROOT *mem_root)
Constructor.
Definition: query_term.h:487
Query_term_type term_type() const override
Get the node tree type.
Definition: query_term.h:488
Query term tree structure.
Definition: query_term.h:208
Query_term * pushdown_limit_order_by(Query_term_set_op *parent=nullptr)
Called after contextualization to simplify query, c.f.
Definition: query_term.cc:73
virtual Query_block * query_block() const =0
The query_block which holds the ORDER BY and LIMIT information for this set operation.
void cleanup_query_result(bool full)
Cleanup m_setop_query_result, q.v.
Definition: query_term.cc:168
Query_term_set_op * m_parent
Back pointer to the node whose child we are, or nullptr (root term).
Definition: query_term.h:266
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:290
Query_result * m_setop_query_result
The query result for this term.
Definition: query_term.h:345
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:366
void set_setop_query_result(Query_result *rs)
Setter for m_setop_query_result, q.v.
Definition: query_term.h:362
Query_result * setop_query_result()
Getter for m_setop_query_result, q.v.
Definition: query_term.h:364
void set_fields(mem_root_deque< Item * > *fields)
Definition: query_term.h:383
virtual Query_term_type term_type() const =0
Get the node tree type.
Table_ref & result_table()
Getter for m_result_table, q.v.
Definition: query_term.h:380
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:375
mem_root_deque< Item * > * fields()
Definition: query_term.h:385
void set_owning_operand()
Setter for m_owning_operand, q.v.
Definition: query_term.h:373
Query_term_set_op * parent() const
Getter for m_parent, q.v.
Definition: query_term.h:270
void set_result_table(Table_ref *tl)
Setter for m_result_table, q.v.
Definition: query_term.h:378
virtual void cleanup(bool full)
Reset resources used.
Definition: query_term.h:277
virtual size_t child_count() const
Get the number of children this node has.
Definition: query_term.h:260
virtual ~Query_term()=default
Node destructor.
Table_ref * m_result_table
Result temporary table for the set operation, if applicable.
Definition: query_term.h:354
uint m_curr_id
class Query_terms iterator traversal state variable, hence friend declaration immediately below
Definition: query_term.h:390
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:42
bool validate_structure(const Query_term *parent, int depth=0) const
Return true if structure is too deep, i.e.
Definition: query_term.cc:152
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:350
void printPointers(std::ostringstream &buf) const
Print the pointer of this node and its parent to buf.
Definition: query_term.cc:224
static void indent(int level, std::ostringstream &buf)
Print blank space indentation (unit: two) to buf according to level.
Definition: query_term.cc:220
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:32
mem_root_deque< Item * > * m_fields
Used only when streaming, i.e.
Definition: query_term.h:358
The iterator class itself is private.
Definition: query_term.h:569
bool operator!=(const Query_term_iterator &other) const
Definition: query_term.h:644
Query_term_iterator & operator++()
Definition: query_term.h:597
bool operator==(const Query_term_iterator &other) const
Definition: query_term.h:640
Query_term * m_current
Iterator state consists of this and Query_term::m_curr_id.
Definition: query_term.h:648
Query_term * operator*()
Definition: query_term.h:638
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:580
Query_term_iterator()=default
Containing class for iterator over the query term tree.
Definition: query_term.h:564
Query_term_iterator end()
Definition: query_term.h:656
Query_terms(Query_term *root)
Construct an iterator starting at root.
Definition: query_term.h:653
Query_term * m_root
Definition: query_term.h:659
Query_term_iterator begin()
Definition: query_term.h:655
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
Definition: buf0block_hint.cc:29
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2868
Query_term_type
This class hierarchy is used to represent SQL structures between <query expression> and <query specif...
Definition: query_term.h:88
@ QT_UNARY
Represents a query primary with parentesized query expression body with order by clause and/or limit/...
Definition: query_term.h:95
@ QT_EXCEPT
Definition: query_term.h:99
@ QT_UNION
Definition: query_term.h:100
@ QT_INTERSECT
Represents the three set operations.
Definition: query_term.h:98
@ QT_QUERY_BLOCK
Represents Query specification, table value constructor and explicit table.
Definition: query_term.h:91
Visit_leaves
Query term iterator template argument type: whether to visit leaf nodes.
Definition: query_term.h:106
@ VL_SKIP_LEAVES
Definition: query_term.h:106
@ VL_VISIT_LEAVES
Definition: query_term.h:106
Visit_order
Query term iterator template argument type: how to visit nodes in tree.
Definition: query_term.h:104
@ QTC_PRE_ORDER
Definition: query_term.h:104
@ QTC_POST_ORDER
Definition: query_term.h:104
required string type
Definition: replication_group_member_actions.proto:33
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
unsigned int uint
Definition: uca-dump.cc:29