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

A set operation of a 5.6 subquery whose ORDER BY or LIMIT is written after the clauses of its last SELECT.

In a 5.6 subquery or derived table the ORDER BY and LIMIT written inside the last unparenthesized SELECT of a union apply to the union, unless an ORDER BY or LIMIT follows that SELECT (opt_union_order_or_limit): then the server makes its fake query block the global parameters of the union, the last SELECT keeps its own ORDER BY, LIMIT and locking clauses, and the clauses written after it order and limit the result of the union. This node holds that form: the operation, its last SELECT with its own clauses, and the ORDER BY and LIMIT of the result. Nothing follows it in the 5.6 grammar, so it is never an operand or a body itself.

Rule: MYSQL-ORDERED-SET-OPERATION-001. Both operands are derived by MYSQL-SET-FACTS-001; the ORDER BY and LIMIT see the output columns of the operation as MYSQL-QUERY-EXPRESSION-FACTS-001 does. 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_yacc.yy (union_order_or_limit). Status: Implemented.

Reading the ordering of a 5.6 union written after the locking clause of its last SELECTdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics('mysql-5.6.51'))->analyze('SELECT (SELECT 1 UNION SELECT a FROM t FOR UPDATE ORDER BY 1)');
    $union = $query->statement->items[0]->expression->query;
    [count($union->right->locking), count($union->orderBy)] // => [1, 1]
Refusing a last SELECT 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\OrderedSetOperation($one, \SqlSemantics\Platform\MySql\Statement\Query\Set\SetOperator::Union, null, $two, [], new \SqlSemantics\Platform\MySql\Statement\Query\Clause\RowLimit(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1'))) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public list<OrderItem> $orderBy
public SetOperator $operator
public SetQuantifier|null $quantifier
public Select $right
public Limit|null $limit = null

Methods§

public function __construct(
    public Query|LeadingUnion $left,
    public SetOperator $operator,
    public SetQuantifier|null $quantifier,
    public Select $right,
    list<OrderItem> $orderBy = [],
    public Limit|null $limit = null,
)

Parameters

$leftQuery|LeadingUnionThe operands before the last SELECT
$operatorSetOperatorThe operator before the last SELECT
$quantifierSetQuantifier|nullThe written DISTINCT or ALL
$rightSelectThe last SELECT with its own ORDER BY, LIMIT or locking clauses
$orderBylist<OrderItem>The ORDER BY items of the result
$limitLimit|nullThe LIMIT of the result
Calls 8
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFact

Derives both operands, the output columns, the ordering and the limit.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the operands around the operator, then the ORDER BY and LIMIT of the result.

Parameters

$outOutput
Calls 2

Test cases 5§

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 1

Relations§

Instantiated in 1
Type checks 6