MySQL 8.4.2
Source Code Documentation
|
#include <parse_tree_nodes.h>
Public Member Functions | |
PT_query_expression (const POS &pos, PT_with_clause *with_clause, PT_query_expression_body *body, PT_order *order, PT_limit_clause *limit) | |
PT_query_expression (const POS &pos, PT_query_expression_body *body, PT_order *order, PT_limit_clause *limit) | |
PT_query_expression (const POS &pos, PT_query_expression_body *body) | |
bool | do_contextualize (Parse_context *pc) override |
bool | is_set_operation () const override |
bool | has_into_clause () const override |
bool | has_trailing_into_clause () const override |
bool | can_absorb_order_and_limit (bool order, bool limit) const override |
True if this query expression can absorb an extraneous order by/limit clause. More... | |
bool | is_table_value_constructor () const override |
PT_insert_values_list * | get_row_value_list () const override |
Public Member Functions inherited from PT_query_expression_body | |
PT_query_expression_body (const POS &pos) | |
Public Member Functions inherited from Parse_tree_node_tmpl< Context > | |
virtual | ~Parse_tree_node_tmpl ()=default |
bool | is_contextualized () const |
virtual bool | contextualize (Context *pc) final |
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 Member Functions | |
bool | contextualize_order_and_limit (Parse_context *pc) |
Contextualizes the order and limit clauses, re-interpreting them according to the rules. More... | |
Private Attributes | |
PT_query_expression_body * | m_body |
PT_order * | m_order |
PT_limit_clause * | m_limit |
PT_with_clause * | m_with_clause |
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 |
Public Attributes inherited from Parse_tree_node_tmpl< Context > | |
POS | m_pos |
Protected Member Functions inherited from Parse_tree_node_tmpl< Context > | |
Parse_tree_node_tmpl ()=delete | |
Parse_tree_node_tmpl (const POS &pos) | |
Parse_tree_node_tmpl (const POS &start_pos, const POS &end_pos) | |
bool | begin_parse_tree (Show_parse_tree *tree) |
bool | end_parse_tree (Show_parse_tree *tree) |
virtual bool | do_contextualize (Context *pc) |
Do all context-sensitive things and mark the node as contextualized. More... | |
virtual void | add_json_info (Json_object *json_obj) |
Add all the node-specific json fields. More... | |
|
inline |
|
inline |
|
inlineexplicit |
|
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.
order | True if the outer query block has the ORDER BY clause. |
limit | True if the outer query block has the LIMIT clause. |
Implements PT_query_expression_body.
|
private |
Contextualizes the order and limit clauses, re-interpreting them according to the rules.
If the <query expression body>
can absorb the clauses, they are simply contextualized into the current Query_block. If not, we have to create the "fake" Query_block unless there is one already (Query_expression::new_set_operation_query() is known to do this.)
|
override |
|
inlineoverridevirtual |
Implements PT_query_expression_body.
|
inlineoverridevirtual |
Implements PT_query_expression_body.
|
inlineoverridevirtual |
Implements PT_query_expression_body.
|
inlineoverridevirtual |
Implements PT_query_expression_body.
|
inlineoverridevirtual |
Implements PT_query_expression_body.
|
private |
|
private |
|
private |
|
private |