classOrdering
final class Ordering
Derives ORDER BY, DISTINCT ON and GROUP BY terms in the environment PostgreSQL resolves each of them in.
Rule: PG-ORDERING-001. An output position denotes the output field at that position (PG-OUTPUT-POSITION-002); any other constant is reported. In ORDER BY and DISTINCT ON, a term that is one unqualified name, possibly in parentheses, and equals the name of output fields denotes that field before any input column; output fields with the name that compute different expressions make it ambiguous. In GROUP BY such a name denotes an input column when the query level has one, and an output field otherwise. Every other term is an expression over the input columns of the selection. After a set operation or VALUES, ORDER BY sees only the output fields; after a set operation a term that is not an output name or position is reported. Terminates: one pass over the terms; grouping sets are walked with a work list. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-ORDERBY, https://www.postgresql.org/docs/17/sql-select.html#SQL-GROUPBY, https://www.postgresql.org/docs/17/queries-union.html. Status: Implemented.
Methods§
public function sort(
list<Scalar> $terms,
list<Field|OpenStar> $projection,
Derivation $derivation,
Environment $rows,
OrderingClause $clause,
): voidDerives the ORDER BY or DISTINCT ON terms of a selection.
Parameters
$terms | list<Scalar> | |
$projection | list<Field|OpenStar> | |
$derivation | Derivation | |
$rows | Environment | |
$clause | OrderingClause |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:126
Calls 5
- method-call Ordering::bare() line 58
- method-call Ordering::named() line 59
- method-call Derivation::scalar() line 61
- new Environment line 61
- method-call Ordering::term() line 64
public function group(
list<Scalar|GroupingRow|GroupingSet> $items,
list<Field|OpenStar> $projection,
Derivation $derivation,
Environment $rows,
): voidDerives the GROUP BY items of a selection, the members of grouping sets included.
Parameters
$items | list<Scalar|GroupingRow|GroupingSet> | |
$projection | list<Field|OpenStar> | |
$derivation | Derivation | |
$rows | Environment |
Called from 1
Calls 13
- function-call
array_reverseline 76 - function-call
array_popline 78 - function-call
array_pushline 80 - method-call Ordering::bare() line 83
- new Environment line 84
- method-call ColumnLookup::find() line 85
- new ColumnLookup line 85
- method-call Visibility::unqualified() line 85
- new Visibility line 85
- method-call Ordering::named() line 85
- method-call Derivation::scalar() line 87
- method-call Ordering::term() line 90
- class-const OrderingClause::GroupBy() line 90
public function outputs(
list<Scalar> $terms,
list<Field|OpenStar> $projection,
Derivation $derivation,
Environment $outer,
bool $setOperation,
): voidDerives the ORDER BY terms written after a set operation or VALUES, which see the output fields only.
Parameters
$terms | list<Scalar> | |
$projection | list<Field|OpenStar> | |
$derivation | Derivation | |
$outer | Environment | |
$setOperation | bool |
Called from 1
Calls 13
- method-call Ordering::known() line 102
- method-call Derivation::scalar() line 105
- method-call Ordering::positions() line 105
- new Environment line 105
- method-call Positions::misused() line 108
- new Positions line 108
- method-call Derivation::report() line 109
- new QueryMisuse line 109
- class-const QueryMisuseRule::NonIntegerConstant() line 109
- new Name line 109
- class-const OrderingClause::OrderBy() line 109
- method-call Ordering::bare() line 110
- class-const QueryMisuseRule::SetOperationOrderByExpression() line 111
public function term(
Scalar $term,
list<Field|OpenStar> $projection,
Derivation $derivation,
Environment $rows,
OrderingClause $clause,
): voidDerives one term that is not an output name: a position, a misused constant or an expression over the input columns.
Parameters
$term | Scalar | |
$projection | list<Field|OpenStar> | |
$derivation | Derivation | |
$rows | Environment | |
$clause | OrderingClause |
Called from 2
Calls 8
- method-call Derivation::scalar() line 125
- method-call Ordering::positions() line 125
- method-call Positions::misused() line 129
- new Positions line 129
- method-call Derivation::report() line 130
- new QueryMisuse line 130
- class-const QueryMisuseRule::NonIntegerConstant() line 130
- new Name line 130
public function positions(list<Field|OpenStar> $projection, Environment $rows): EnvironmentAnswers the environment an output position is derived in: the known fields, and the relations of an unexpanded star.
Parameters
$projection | list<Field|OpenStar> | |
$rows | Environment |
Returns
Test cases 1
Called from 2
Calls 3
- method-call Ordering::known() line 142
- function-call
countline 143 - new Environment line 145
Answers the fields before the first star that could not be expanded.
Returns
list<Field>Test cases 1
public function named(
list<Field|OpenStar> $projection,
Name $name,
Derivation $derivation,
): list<Field>Answers the output fields with a name, keeping one of those that compute the same expression.
Parameters
$projection | list<Field|OpenStar> | |
$name | Name | |
$derivation | Derivation |
Returns
list<Field>Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:80
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::sort() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:59
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::group() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:85
Calls 1
- method-call Ordering::same() line 182
Tells whether two output fields compute the same expression.
Returns
boolTest cases 1
Called from 1
Calls 2
- method-call Equivalence::difference() line 201
- new Equivalence line 201
Answers the name a term consists of when it is one unqualified name, possibly in parentheses.
Parameters
$term | Scalar |
Returns
?NameTest cases 1
Called from 4
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::sort() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:58
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::group() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:83
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Ordering::outputs() packages/sql-semantics-postgres/src/Rules/Query/Ordering.php:110
Calls 1
- function-call
countline 213
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Relations§
Instantiated in 5
- new SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:79
- new SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:80
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:58
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:70
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:126
Method calls 6
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\DistinctOrdering::key() packages/sql-semantics-postgres/src/Rules/Query/DistinctOrdering.php:80
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:58
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:71
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:79
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:126