classSelectFacts
final class SelectFacts
Derives the facts of a selection and of a TABLE query.
Rule: PG-SELECT-SCOPE-001. The FROM items are derived in the environment of the enclosing query (PG-FROM-SCOPE-001). WHERE, the select list, GROUP BY, HAVING, the named windows, DISTINCT ON and ORDER BY see the relations of the FROM items and, beyond them, the enclosing queries; the select list does not see its own output names, and GROUP BY, DISTINCT ON and ORDER BY follow PG-ORDERING-001. LIMIT and OFFSET see only the enclosing queries (PG-LIMIT-001). The ORDER BY and locking clauses written after parentheses around the selection are its own (PG-QUERY-OPTIONS-001). With grouping sets a grouped column is NULL in the rows of the sets that do not group it, so every output field can be NULL. Locking is reported with DISTINCT, GROUP BY and HAVING. The output fields follow PG-TARGET-001 and PG-STAR-001. Terminates: every clause is a strict part of the selection. Source: https://www.postgresql.org/docs/17/sql-select.html, https://www.postgresql.org/docs/17/queries-table-expressions.html#QUERIES-GROUPING-SETS. Status: Implemented.
Methods§
public function derive(Select $select, Derivation $derivation, Environment $outer): QueryFactDerives every part of the selection and answers its output.
Parameters
$select | Select | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 24
- method-call Carriers::take() line 60
- new Carriers line 60
- method-call FromScope::open() line 61
- new FromScope line 61
- new Environment line 62
- method-call Derivation::scalar() line 64
- function-call
array_pushline 68 - function-call
countline 68 - new Ordering line 70
- method-call Ordering::group() line 71
- method-call Ordering::sort() line 79
- class-const OrderingClause::DistinctOn() line 79
- method-call SelectFacts::layers() line 81
- method-call SelectFacts::options() line 82
- method-call DistinctOrdering::check() line 89
- new DistinctOrdering line 89
- method-call SelectFacts::locks() line 90
- class-const QueryMisuseRule::LockingWithDistinct() line 91
- class-const QueryMisuseRule::LockingWithGroupBy() line 91
- class-const QueryMisuseRule::LockingWithHaving() line 91
- method-call Derivation::report() line 93
- new QueryMisuse line 93
- new QueryFact line 98
- method-call SelectFacts::grouped() line 98
public function table(TableQuery $query, Derivation $derivation, Environment $outer): QueryFactDerives the TABLE query and answers its output: every column of the table.
Parameters
$query | TableQuery | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 10
- method-call Carriers::take() line 106
- new Carriers line 106
- method-call FromScope::open() line 107
- new FromScope line 107
- new Environment line 108
- method-call StarExpansion::all() line 109
- new StarExpansion line 109
- method-call SelectFacts::options() line 110
- method-call SelectFacts::layers() line 110
- new QueryFact line 112
public function options(
list<SelectOptions> $layers,
list<Field|OpenStar> $items,
list<VisibleRelation> $visible,
Derivation $derivation,
Environment $rows,
Environment $base,
?SelectOptions $own,
?Relation $from = null,
): voidDerives the ORDER BY items and checks the locking clauses of every layer, and derives the own limit.
Parameters
$layers | list<SelectOptions> | |
$items | list<Field|OpenStar> | |
$visible | list<VisibleRelation> | |
$derivation | Derivation | |
$rows | Environment | |
$base | Environment | |
$own | ?SelectOptions | |
$from | ?Relation |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:82
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::table() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:110
Calls 10
- new Limits line 124
- method-call Ordering::sort() line 126
- new Ordering line 126
- function-call
array_mapline 126 - class-const OrderingClause::OrderBy() line 126
- method-call Limits::locked() line 127
- method-call Locking::check() line 128
- new Locking line 128
- method-call Limits::derive() line 130
- method-call Limits::ties() line 131
public function layers(
?SelectOptions $own,
list<QueryExpression> $carriers,
): list<SelectOptions>Answers the options that apply to a query, its own first and then those of the carriers.
Parameters
$own | ?SelectOptions | |
$carriers | list<QueryExpression> |
Returns
list<SelectOptions>Test cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::derive() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:81
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::table() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:110
Calls 1
- function-call
array_reverseline 143
public function locks(list<SelectOptions> $layers): boolAnswers the output with every field able to be NULL when GROUP BY has grouping sets.
Called from 1
Calls 4
- class-const Nullability::NotNull() line 185
- new Field line 186
- new OutputSlot line 186
- class-const Nullability::Nullable() line 186
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Relations§
Instantiated in 2
Method calls 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Query\Select::deriveQuery() packages/sql-semantics-postgres/src/Statement/Query/Select.php:135
- method-call SqlSemantics\Platform\PostgreSql\Statement\Query\TableQuery::deriveQuery() packages/sql-semantics-postgres/src/Statement/Query/TableQuery.php:81