final class Chain
Restricted visibility: declared "@visibility SqlSemantics\Platform\MySql\Lowering\Query". Code outside that scope must not name this declaration.

The operands of a 5.x UNION in written order, the quantifiers between them and the clauses written after the last one.

Rule: MYSQL-UNION-LEGACY-001. The ORDER BY, LIMIT, INTO and locking clauses written inside the last unparenthesized SELECT of a union apply to the whole union, so they are taken out of that block; with the clauses written after a last parenthesized operand they wrap the union. In a 5.6 subquery an ORDER BY or LIMIT written after the last SELECT applies to the union instead, and the last SELECT keeps its own clauses (the union_order_or_limit action makes the fake query block the global parameters). The server rejects, while parsing, ORDER BY or INTO in an earlier unparenthesized SELECT, LIMIT there in 5.7 (5.6 keeps it as the block's own), an ORDER BY or LIMIT a 5.6 subquery writes after an earlier SELECT other than a LIMIT after the first one, and PROCEDURE ANALYSE in a union. An earlier SELECT keeps its own locking clauses and, in 5.6, its own LIMIT; when it is not the first operand the operands up to it form a leading union (MYSQL-LEADING-UNION-001). The operands are combined left-deep. A lowering-time value. Source: https://dev.mysql.com/doc/refman/5.7/en/union.html ("To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses"; "Only the last SELECT statement can use INTO OUTFILE"), https://github.com/mysql/mysql-server/blob/mysql-5.6.51/sql/sql_parse.cc (mysql_new_select), https://github.com/mysql/mysql-server/blob/mysql-5.7.44/sql/sql_lex.cc (LEX::new_union_query). Status: Implemented.

Properties§

public non-empty-list<array{Block|Query, Trailer}> $operands
public list<SetQuantifier|null> $quantifiers
public GrammarRelease $release
public Trailer $trailer = new \SqlSemantics\Platform\MySql\Lowering\Query\Shared\Trailer()

Methods§

public function __construct(
    public non-empty-list<array{Block|Query, Trailer}> $operands,
    public list<SetQuantifier|null> $quantifiers,
    public GrammarRelease $release,
    public Trailer $trailer = new \SqlSemantics\Platform\MySql\Lowering\Query\Shared\Trailer(),
)

Parameters

$operandsnon-empty-list<array{Block|Query, Trailer}>The operands in written order, each with the clauses written after it
$quantifierslist<SetQuantifier|null>The quantifier written after each UNION
$releaseGrammarReleaseThe grammar release the union is written in
$trailerTrailerThe clauses written after the last operand
Calls 1
public function query(): Query

Combines the operands into one query.

Returns

Throws

AnalysisException When the last SELECT writes PROCEDURE ANALYSE (ER_WRONG_USAGE of the 5.6 `procedure_analyse_clause` action, which refuses any block but the first, and of 5.7 `PT_procedure_analyse::contextualize`), or an earlier operand writes a clause the server rejects there
ImplementationGap When clauses cannot follow their query block
Test cases 3
Called from 3
Calls 9
public function earlier(Block $operand, Trailer $clauses, int $index): Query

Finishes an operand before the last one, rejecting the clauses the server does not accept there.

Parameters

$operandBlock
$clausesTrailer
$indexint

Returns

Throws

AnalysisException When the operand writes such a clause: ER_WRONG_USAGE "UNION and ORDER BY|LIMIT|INTO|PROCEDURE ANALYSE" of `add_select_to_union_list` and `mysql_new_select` (5.6, run by the `union_list` action) and of `LEX::new_union_query` (5.7, run while contextualizing the union), or ER_SYNTAX_ERROR when the clauses written after an earlier SELECT made the fake query block current (`add_select_to_union_list` refuses GLOBAL_OPTIONS_TYPE)
Test cases 3
Called from 1
Calls 4
public function enclosed(Query $operand, Trailer $clauses, int $index): Query

Finishes a parenthesized operand before the last one with the ORDER BY and LIMIT a 5.x subquery writes after it.

After the first operand the clauses belong to the query block in the parentheses, unless an ORDER BY follows a block that orders or limits its rows itself: the order_clause action (5.6) and PT_order::contextualize (5.7) then make a fake query block current. After a later operand the fake query block of the union is current. The next UNION refuses a current fake query block.

Parameters

$operandQuery
$clausesTrailer
$indexint

Returns

Throws

AnalysisException When the clauses made the fake query block current: ER_SYNTAX_ERROR of `add_select_to_union_list` (5.6, GLOBAL_OPTIONS_TYPE) and ER_WRONG_USAGE "UNION and ORDER BY|LIMIT" of `LEX::new_union_query` (5.7)
Test cases 3
Called from 1
Calls 3

Test cases 9§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 9

Relations§

Instantiated in 3
Method calls 3