classLeadingUnion
final class LeadingUnion
implements Node
uses Snapshot
@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.
$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]$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\InvalidConstructionProperties§
public Query|LeadingUnion $leftpublic SetQuantifier|null $quantifierpublic Select $rightMethods§
public function __construct(
public Query|LeadingUnion $left,
public SetQuantifier|null $quantifier,
public Select $right,
)Parameters
$left | Query|LeadingUnion | The operands before the last one |
$quantifier | SetQuantifier|null | The written DISTINCT or ALL |
$right | Select | The 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 operandCalls 3
- static-call Check::input() line 60
- method-call Select::trailed() line 60
- class-const SetOperator::Union() line 61
public function render(Output $out): voidWrites the operands around UNION.
Parameters
$out | Output |
Calls 3
- method-call Output::node() line 70
- method-call QueryTails::leading() line 71
- new QueryTails line 71
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
- instanceof SqlSemantics\Platform\MySql\Rules\Query\CommonTables::operands() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:158
- instanceof SqlSemantics\Platform\MySql\Rules\Query\SetFacts::operands() packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:51
- instanceof SqlSemantics\Platform\MySql\Rules\Routine\ProgramRestrictions::into() packages/sql-semantics-mysql/src/Rules/Routine/ProgramRestrictions.php:154
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\EnclosedQuery::accepts() packages/sql-semantics-mysql/src/Rules/TableDefinition/EnclosedQuery.php:44
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\EnclosedQuery::write() packages/sql-semantics-mysql/src/Rules/TableDefinition/EnclosedQuery.php:66
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\ViewColumns::block() packages/sql-semantics-mysql/src/Rules/TableDefinition/ViewColumns.php:135
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:84
- instanceof SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/SetOperation.php:60
Type declarations 7
- type SqlSemantics\Platform\MySql\Rules\Query\QueryTails packages/sql-semantics-mysql/src/Rules/Query/QueryTails.php:47
- type SqlSemantics\Platform\MySql\Rules\Query\SetFacts packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:49
- type SqlSemantics\Platform\MySql\Rules\Query\SetFacts packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:65
- type SqlSemantics\Platform\MySql\Rules\Routine\ProgramRestrictions packages/sql-semantics-mysql/src/Rules/Routine/ProgramRestrictions.php:147
- type SqlSemantics\Platform\MySql\Rules\TableDefinition\EnclosedQuery packages/sql-semantics-mysql/src/Rules/TableDefinition/EnclosedQuery.php:59
- type SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:72
- type SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperation packages/sql-semantics-mysql/src/Statement/Query/Set/SetOperation.php:56