WL#7200: True bottom-up server parser: refactoring of the SELECT statement

Affects: Parser-Prototype Only   —   Status: Complete

This WL is intended to refactor the SELECT statement-related parser grammar
rules in a pure bottom-up style to make it (grammar) context-independent for the
better maintainability and extendability at the first place.

This WL uses the framework and the methodology of the refactoring from the
WL#7199 "True bottom-up server parser: common framework for the refactoring".

The SELECT grammar rules ("expr", "subselect") are extensively shared with may
other SQL statements, including the whole DML and some DDL ("CREATE TABLE ...
SELECT" and so on). Thus it's logical to mark other statement refactoring WLs as
dependent on this WL and implement/push this WL first.

No functional requirements.

Non-functional requirements:
* no query result changes;
* no performance degradation is expected (some additional overhead is expected
due to added allocation (cheap) and processing of parse nodes, however the
parser rules become simpler and should compensate for other degradation. Also we
eliminate a number of _current_thd() function calls -- that seems profitable.)
See the WL#7199 "True bottom-up server parser: common framework for the
refactoring" for design principles: the current WL uses its framework and
methodology to refactor the SELECT statement parser (the "select" grammar rule).
The target for this WL is the "select" grammar rule.

After the refactoring the statement entry for SET clause in the grammar calls
the PT_select::contextualize() function at the top level:

statement:
...
  | select                { CONTEXTUALIZE($1); }

This WL introduces a number of parse tree node classes.
The most important classes are:

PT_select_lex
-------------
This class is a base class of a few parse tree node classes.
Child classes:
* PT_subselect (wraps the "subselect" grammar rule),
* PT_query_specification_select and PT_query_specification_parenthesis
  ("query_specification" rule).
All off this classes wrap allocation of/deferred operations on the
st_select_lex (query block) class object.
After the contextualization of these class object the resulting st_select_lex
object is available at PT_select_lex::value.

PT_subselect
------------
This class wraps the "subselect" grammar rule (the rule for subqueries).
After the contextualization the resulting query block object
(or the object of the first query block in the query expression)
is available at PT_subselect::value.

PT_order_expr
-------------
PT_order_expr is a class for parse tree nodes of the order_expr grammar rule.
That rule products "ORDER BY" clause expression with an optional sort direction.
This class is a wrapper for execution-time ORDER class.

PT_order_list
-------------
This class wraps both "order_list" and "group_list" grammar rules, i.e.
the whole "ORDER BY" and "GROUP BY" clauses respectively.
There is a PT_order_expr::push_back() function to link ordering/grouping
expressions into a list in place in the parser (before the contextualization).
The resulting list of ORDER objects is available at PT_order_list::value,
that list is reused by the execution phase.

PT_table_list
-------------
This class is a base class of a few parse tree node classes.
The result of its contextualization is the TABLE_LIST object.
Child classes:
* PT_derived_table_list, PT_join_table_list and PT_select_derived:
  represents varieties of derived tables lists, see derived_table_list,
  join_table_list and select_derived grammar rules respectively.
* PT_select_derived_union_select: same as above with optional ORDER BY
  and/or LIMIT clauses.
* PT_select_derived_union_union: represents the UNION query expression;
* PT_table_factor_parenthesis: query expression in parentheses that is
  optionally followed by a table alias;
* PT_table_factor_select_sym: represents derived table;
* PT_table_factor_table_ident: represents simple table factor with optional
  alias, partitioning options and index hints;
* PT_table_ref_join_table: represents table reference that consists of JOIN
  expressions, see table_ref grammar rule.

PT_join_table, PT_join_table_on and PT_join_table_using
-------------------------------------------------------
Instances of these template classes implement all supported
varieties of JOIN expression:
* PT_join_table: simple inner "a JOIN b";
* PT_join_table_on: the same with ON clause;
* PT_join_table_using: inner "a JOIN b USING...";

* PT_join_table: "a STRAIGHT_JOIN b"
* PT_join_table_on: the same as above with ON clause;

* PT_join_table: inner natural join;
* PT_join_table: left outer natural join;
* PT_join_table: right outer natural join;

* PT_join_table_on: left outer join with ON clause;
* PT_join_table_usingleft outer join with USING clause;
* PT_join_table_on: right outer join with ON clause;
* PT_join_table_using: right outer join with USING  clause.

PT_table_expression
-------------------
This class represents the table_expression grammar rule.

PT_query_specification_select and PT_query_specification_parenthesis
--------------------------------------------------------------------
These classes represent parse tree nodes for query specification, without
and without parentheses respectively.

PT_query_expression_body_union
------------------------------
Represents subquery query expressions.

PT_select
---------
Represents top-level query expression.