classSortScopes
final class SortScopes
Derives the items of ORDER BY and GROUP BY.
Rule: MYSQL-SORT-SCOPE-001. A select list position (MYSQL-ORDINAL-001) denotes the output field at that position. An ORDER BY item that is a bare unqualified name equal to the alias of a select list item denotes that item, because ORDER BY searches the select list first. Every other item sees the columns of the FROM clause first and the aliases of the select list after them, which is how GROUP BY, HAVING and expressions in ORDER BY resolve. Terminates: one pass over the items. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html ("MySQL resolves an unqualified column or alias reference in ORDER BY clauses by searching in the select_expr values, then in the columns of the tables in the FROM clause. For GROUP BY or HAVING clauses, it searches the FROM clause before searching in the select_expr values"). Status: Implemented.
Methods§
public function check(list<OrderItem> $items): voidRequires every integer literal item to be given as a select list position.
Parameters
$items | list<OrderItem> |
Throws
InvalidConstruction When an integer literal is an ordinary itemTest cases 1
Called from 4
- method-call SqlSemantics\Platform\MySql\Statement\Query\Clause\LateOrdering::__construct() packages/sql-semantics-mysql/src/Statement/Query/Clause/LateOrdering.php:52
- method-call SqlSemantics\Platform\MySql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-mysql/src/Statement/Query/QueryExpression.php:63
- method-call SqlSemantics\Platform\MySql\Statement\Query\Select::__construct() packages/sql-semantics-mysql/src/Statement/Query/Select.php:132
- method-call SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:80
Calls 2
- static-call Check::input() line 52
- class-const NumberForm::Integer() line 52
public function derive(
list<OrderItem> $items,
Derivation $derivation,
Environment $environment,
list<Field|OpenStar> $projection,
bool $aliasFirst,
): list<ScalarFact>Derives the items in the given environment, whose aliases are the aliased output fields.
Parameters
$items | list<OrderItem> | |
$derivation | Derivation | |
$environment | Environment | |
$projection | list<Field|OpenStar> | The output of the query, in order |
$aliasFirst | bool | Whether a bare name looks at the aliases first, as in ORDER BY |
Returns
list<ScalarFact> The facts of the items, in orderCalled from 3
- method-call SqlSemantics\Platform\MySql\Rules\Query\ExpressionFacts::ordering() packages/sql-semantics-mysql/src/Rules/Query/ExpressionFacts.php:57
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:72
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:84
Calls 7
- function-call
countline 73 - method-call SortScopes::word() line 76
- method-call Derivation::scalar() line 78
- new Environment line 78
- method-call Environment::aliased() line 79
- method-call Operands::single() line 82
- new Operands line 82
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 7
- new SqlSemantics\Platform\MySql\Rules\Query\ExpressionFacts::ordering() packages/sql-semantics-mysql/src/Rules/Query/ExpressionFacts.php:57
- new SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:72
- new SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:84
- new SqlSemantics\Platform\MySql\Statement\Query\Clause\LateOrdering::__construct() packages/sql-semantics-mysql/src/Statement/Query/Clause/LateOrdering.php:52
- new SqlSemantics\Platform\MySql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-mysql/src/Statement/Query/QueryExpression.php:63
- new SqlSemantics\Platform\MySql\Statement\Query\Select::__construct() packages/sql-semantics-mysql/src/Statement/Query/Select.php:132
- new SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:80
Method calls 7
- method-call SqlSemantics\Platform\MySql\Rules\Query\ExpressionFacts::ordering() packages/sql-semantics-mysql/src/Rules/Query/ExpressionFacts.php:57
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:72
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:84
- method-call SqlSemantics\Platform\MySql\Statement\Query\Clause\LateOrdering::__construct() packages/sql-semantics-mysql/src/Statement/Query/Clause/LateOrdering.php:52
- method-call SqlSemantics\Platform\MySql\Statement\Query\QueryExpression::__construct() packages/sql-semantics-mysql/src/Statement/Query/QueryExpression.php:63
- method-call SqlSemantics\Platform\MySql\Statement\Query\Select::__construct() packages/sql-semantics-mysql/src/Statement/Query/Select.php:132
- method-call SqlSemantics\Platform\MySql\Statement\Query\Set\OrderedSetOperation::__construct() packages/sql-semantics-mysql/src/Statement/Query/Set/OrderedSetOperation.php:80