final class LeadingUnion
    implements Node
    uses Snapshot
Public API: explicitly declared with @visibility public.

The operands of a 5.x union before a later UNION, when the last of them is a SELECT that keeps its own LIMIT or locking clauses.

A 5.x union is a list of query blocks, each with its own clauses. A SELECT written without parentheses before another UNION keeps its own locking clauses (select_lock_type sets the lock of the tables of that block) and, in 5.6, its own LIMIT (mysql_new_select refuses only an ORDER BY there; 5.7 LEX::new_union_query refuses the LIMIT too). The same SELECT written last would give its clauses to the whole union, so this form is not a query on its own: it is only the left operand of a further UNION (SetOperation, OrderedSetOperation or another leading union), never a body, a subquery or a statement. The operands are combined to the left like every set operation.

Rule: MYSQL-LEADING-UNION-001. The output is derived by MYSQL-SET-FACTS-001 for the operation that continues it; the form needs MySQL 5.6 or 5.7, and its own LIMIT needs 5.6. Source: https://dev.mysql.com/doc/refman/5.6/en/union.html, 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.

Reading the LIMIT a 5.6 SELECT keeps before a later UNIONdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics('mysql-5.6.51'))->analyze('SELECT a FROM t UNION SELECT b FROM u LIMIT 1 UNION SELECT c FROM v');
    [$query->statement->left::class, $query->statement->left->right->limit !== null] // => [\SqlSemantics\Platform\MySql\Statement\Query\Set\LeadingUnion::class, true]
Refusing a last operand without clauses of its owndoctest
$one = new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1'))]);
    $two = new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('2'))]);
    new \SqlSemantics\Platform\MySql\Statement\Query\Set\LeadingUnion($one, null, $two) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public SetQuantifier|null $quantifier
public Select $right

Methods§

public function __construct(
    public Query|LeadingUnion $left,
    public SetQuantifier|null $quantifier,
    public Select $right,
)

Parameters

$leftQuery|LeadingUnionThe operands before the last one
$quantifierSetQuantifier|nullThe written DISTINCT or ALL
$rightSelectThe last operand, with its own LIMIT or locking clauses and nothing else after its items

Throws

InvalidConstruction When the last operand keeps no such clause or another one, or the left operand is written in parentheses as a set operand
Calls 3
public function render(Output $out): void

Writes the operands around UNION.

Parameters

$outOutput
Calls 3

Test cases 7§

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

Dedicated tests 4
Other tests reaching this symbol 3

Relations§

Instantiated in 1
Type checks 8
Type declarations 7