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

A query expression: a WITH clause, or an ORDER BY and LIMIT that apply to a whole set operation or parenthesized query.

It exists only when it holds a WITH clause, an ordering or a limit. Over a single query block the ordering and the limit belong to the block itself, so a body that is a selection takes no ordering or limit here, unless an ORDER BY follows a block that orders or limits its rows itself: a 5.6 subquery accepts that, and the server orders the rows of the block in a query level of their own (the order_clause action adds a fake query block). The body is not itself a query expression or a query statement, which are merged into or wrapped around this one.

Rule: MYSQL-QUERY-EXPRESSION-001. The facts are derived by MYSQL-QUERY-EXPRESSION-FACTS-001. Source: https://dev.mysql.com/doc/refman/8.4/en/union.html, https://dev.mysql.com/doc/refman/8.4/en/with.html. Status: Implemented.

Reading the ordering of a uniondoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t UNION SELECT b FROM u ORDER BY 1 LIMIT 2');
    [count($query->statement->orderBy), $query->statement->limit !== null] // => [1, true]
Refusing a wrapper that adds nothingdoctest
new \SqlSemantics\Platform\MySql\Statement\Query\QueryExpression(null, new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1'))])) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public list<OrderItem> $orderBy
public WithClause|null $with
public Query $body
public Limit|null $limit = null

Methods§

public function __construct(
    public WithClause|null $with,
    public Query $body,
    list<OrderItem> $orderBy = [],
    public Limit|null $limit = null,
)

Parameters

$withWithClause|nullThe WITH clause
$bodyQueryThe query the clauses apply to
$orderBylist<OrderItem>The ORDER BY items
$limitLimit|nullThe LIMIT clause
Calls 5
public function deriveStatement(Derivation $derivation): void

Derives the query expression as a statement root and records its rows as the output.

Parameters

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

Binds the common tables and derives the body, the ordering and the limit.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the clauses in grammar order.

Parameters

$outOutput
Calls 3

Test cases 17§

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

Dedicated tests 6
Other tests reaching this symbol 11

Relations§

Instantiated in 3
Type checks 11
Type declarations 2