MySQL  8.0.18
Source Code Documentation
PT_union Class Reference

#include <parse_tree_nodes.h>

Inheritance diagram for PT_union:
PT_query_expression_body Parse_tree_node_tmpl< Context >

Public Member Functions

 PT_union (PT_query_expression *lhs, const POS &lhs_pos, bool is_distinct, PT_query_primary *rhs)
 
bool contextualize (Parse_context *pc) override
 
bool is_union () const override
 
bool has_into_clause () const override
 
bool can_absorb_order_and_limit () const override
 True if this query expression can absorb an extraneous order by/limit clause. More...
 
- Public Member Functions inherited from Parse_tree_node_tmpl< Context >
virtual ~Parse_tree_node_tmpl ()
 
bool is_contextualized () const
 
virtual bool contextualize (Context *pc)
 Do all context-sensitive things and mark the node as contextualized. More...
 
virtual bool contextualize_ (Context *)
 
Intermediate version of the contextualize() function More...
 
void error (Context *pc, const POS &pos) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void error (Context *pc, const POS &pos, const char *msg) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 
void errorf (Context *pc, const POS &pos, const char *format,...) const
 syntax_error() function replacement for deferred reporting of syntax errors More...
 

Private Attributes

PT_query_expressionm_lhs
 
POS m_lhs_pos
 
bool m_is_distinct
 
PT_query_primarym_rhs
 
PT_into_destinationm_into
 

Additional Inherited Members

- Public Types inherited from Parse_tree_node_tmpl< Context >
typedef Context context_t
 
- Static Public Member Functions inherited from Parse_tree_node_tmpl< Context >
static void * operator new (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 
static void operator delete (void *ptr, size_t size)
 
static void operator delete (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
- Protected Member Functions inherited from Parse_tree_node_tmpl< Context >
 Parse_tree_node_tmpl ()
 

Constructor & Destructor Documentation

◆ PT_union()

PT_union::PT_union ( PT_query_expression lhs,
const POS lhs_pos,
bool  is_distinct,
PT_query_primary rhs 
)
inline

Member Function Documentation

◆ can_absorb_order_and_limit()

bool PT_union::can_absorb_order_and_limit ( ) const
inlineoverridevirtual

True if this query expression can absorb an extraneous order by/limit clause.

The ORDER BY/LIMIT syntax is mostly consistestent, i.e. a trailing clause may not refer to the tables in the <query primary>, with one glaring exception:

(...( SELECT ... )...) ORDER BY ...

If the nested query expression doesn't contain ORDER BY, the statement is interpreted as if the ORDER BY was absorbed by the innermost query expression, i.e.:

(...( SELECT ... ORDER BY ... )...)

There is no rewriting of the parse tree nor AST happening here, the transformation is done by the contextualizer (see PT_query_expression::contextualize_order_and_limit), which interprets the parse tree, and builds the AST according to this interpretation. This interpretation is governed by the following rule: An ORDER BY can be absorbed if none the nested query expressions contains an ORDER BY or LIMIT. The rule is complex, so here are some examples for illustration:

In these cases the ORDER BY is absorbed:

( SELECT * FROM t1 ) ORDER BY t1.a;
(( SELECT * FROM t1 )) ORDER BY t1.a;

In these cases the ORDER BY is not absorbed:

( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
(( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
(( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;

The same happens with LIMIT, obviously, but the optimizer is freeer to choose when to apply the limit, and there are name no resolution issues involved.

Implements PT_query_expression_body.

◆ contextualize()

bool PT_union::contextualize ( Parse_context pc)
override

◆ has_into_clause()

bool PT_union::has_into_clause ( ) const
inlineoverridevirtual

◆ is_union()

bool PT_union::is_union ( ) const
inlineoverridevirtual

Member Data Documentation

◆ m_into

PT_into_destination* PT_union::m_into
private

◆ m_is_distinct

bool PT_union::m_is_distinct
private

◆ m_lhs

PT_query_expression* PT_union::m_lhs
private

◆ m_lhs_pos

POS PT_union::m_lhs_pos
private

◆ m_rhs

PT_query_primary* PT_union::m_rhs
private

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