final class SetOperation
    implements Statement, Query
    uses Snapshot
Public API: explicitly declared with @visibility public.

A set operation: UNION, EXCEPT or INTERSECT of two queries.

Operations of equal binding associate to the left, so a chain is a left-deep tree; an operand that would need parentheses to keep its place is refused: a set operation on the right that binds no more tightly, a looser one on the left of INTERSECT, a query with a WITH clause or with statement-level INTO or locking clauses, and on the right a query whose ORDER BY, LIMIT or other trailing clauses would be read as applying to the whole operation.

Rule: MYSQL-SET-OPERATION-001. The output is derived by MYSQL-SET-FACTS-001. Source: https://dev.mysql.com/doc/refman/8.4/en/set-operations.html, https://dev.mysql.com/doc/refman/8.4/en/union.html. Status: Implemented.

Reading the operands of a uniondoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t UNION SELECT b FROM u');
    [$query->statement->left->from->name->name->value, $query->statement->right->from->name->name->value] // => ['t', 'u']
Refusing a right operand that would associate differently without parenthesesdoctest
$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'))]);
    $three = new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('3'))]);
    new \SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperation($one, \SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperator::Union, null, new \SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperation($two, \SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperator::Union, null, $three)) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public SetOperator $operator
public SetQuantifier|null $quantifier
public Query $right

Methods§

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

Parameters

$leftQuery|LeadingUnionThe left operand: a query, or the operands of a 5.x union before this UNION when the last of them keeps its own clauses
$operatorSetOperatorThe operator
$quantifierSetQuantifier|nullThe written DISTINCT or ALL
$rightQueryThe right operand
Calls 4
public function deriveStatement(Derivation $derivation): void

Derives the set operation as a statement root and records its rows as the output.

Parameters

$derivationDerivation
Calls 3
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFact

Derives both operands and the output columns.

Parameters

$derivationDerivation
$outerEnvironment

Returns

Calls 2
public function render(Output $out): void

Writes the operands around the operator.

Parameters

$outOutput
Calls 3

Test cases 26§

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

Dedicated tests 7
Other tests reaching this symbol 19

Relations§

Instantiated in 4
Type checks 7
Type declarations 2