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

One query block: SELECT with its modifiers, select list, FROM clause, filters, grouping, windows, ordering, limit, INTO and locking clauses.

It is the query specification of every grammar generation. The ORDER BY, LIMIT, INTO and locking clauses written after a single query block belong to it, as the server attaches them; written after a set operation or a parenthesized query they belong to a query expression or a query statement instead. An ORDER BY or GROUP BY item that is an unsigned integer is a select list position (MYSQL-ORDINAL-001) and must be given as one. An INTO clause after the query clauses needs one of them, because otherwise it is written as the INTO after the select list. A block of a 5.6 subquery may write its ORDER BY and LIMIT after its locking clauses, or a LIMIT after its own LIMIT that replaces it (LateOrdering).

Rule: MYSQL-SELECT-001. The facts are derived by MYSQL-SELECT-FACTS-001. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html, https://dev.mysql.com/doc/refman/5.7/en/select.html. Status: Implemented.

Reading the parts of a selectiondoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a, b FROM t WHERE a > 1 GROUP BY a, b HAVING a > 2 ORDER BY a LIMIT 3');
    [count($query->statement->items), $query->statement->where !== null, $query->statement->having !== null, count($query->statement->orderBy)] // => [2, true, true, 1]
Depending on a table the context does not declaredoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t');
    $query->field('a')->type instanceof \SqlSemantics\Platform\MySql\Model\Statement\Type\Dependent // => true
Refusing a star after the first itemdoctest
new \SqlSemantics\Platform\MySql\Statement\Query\Select([], [new \SqlSemantics\Platform\MySql\Statement\Query\SelectExpression(new \SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral('1')), new \SqlSemantics\Platform\MySql\Statement\Query\Star()]) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\InvalidConstruction

Properties§

public list<SelectOption> $options
public non-empty-list<SelectExpression|Star|TableWildcard> $items
public list<WindowDefinition> $windows
public list<OrderItem> $orderBy
public list<LockingClause> $locking
public Relation|null $from = null
public Scalar|null $where = null
public Grouping|null $groupBy = null
public Scalar|null $having = null
public Scalar|null $qualify = null
public Limit|null $limit = null
public ProcedureAnalyse|null $procedure = null
public IntoDestination|null $into = null
public IntoPosition|null $intoPosition = null
public LateOrdering|null $late = null

Methods§

public function __construct(
    list<SelectOption> $options,
    list<Node> $items,
    public Relation|null $from = null,
    public Scalar|null $where = null,
    public Grouping|null $groupBy = null,
    public Scalar|null $having = null,
    list<WindowDefinition> $windows = [],
    public Scalar|null $qualify = null,
    list<OrderItem> $orderBy = [],
    public Limit|null $limit = null,
    public ProcedureAnalyse|null $procedure = null,
    list<LockingClause> $locking = [],
    public IntoDestination|null $into = null,
    public IntoPosition|null $intoPosition = null,
    public LateOrdering|null $late = null,
)

Parameters

$optionslist<SelectOption>The modifiers in written order
$itemslist<Node>The select list of expressions and qualified stars; at least one item, an unqualified star only first
$fromRelation|nullThe FROM clause
$whereScalar|nullThe row predicate
$groupByGrouping|nullThe GROUP BY clause
$havingScalar|nullThe group predicate
$windowslist<WindowDefinition>The named windows
$qualifyScalar|nullThe window predicate of QUALIFY
$orderBylist<OrderItem>The ORDER BY items
$limitLimit|nullThe LIMIT clause
$procedureProcedureAnalyse|nullThe PROCEDURE ANALYSE clause of the 5.x grammars
$lockinglist<LockingClause>The locking clauses
$intoIntoDestination|nullThe INTO destination
$intoPositionIntoPosition|nullWhere INTO is written; given exactly when there is a destination
$lateLateOrdering|nullThe ORDER BY and LIMIT a 5.6 subquery writes after the locking clauses or the LIMIT of the block
Calls 12
public function clauses(): bool

Tells whether a clause after the select list and before INTO is written.

Returns

bool
Called from 1
public function trailed(): bool
public function input(): ?Relation

Answers the input relation.

Returns

public function deriveStatement(Derivation $derivation): void

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

Parameters

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

Derives the input, every clause and the output fields.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the clauses in grammar order.

Parameters

$outOutput
Calls 7

Test cases 198§

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

Dedicated tests 16
Other tests reaching this symbol 182

Relations§

Instantiated in 1
Method calls 2
Type checks 8
Type declarations 8