classResultReferences
final class ResultReferences
Resolves a name against the GROUP BY columns and the select list of a grouped row.
Rule: MYSQL-HAVING-REFERENCE-001, after resolve_ref_in_select_and_group, find_field_in_group_list (sql/item.cc) and find_item_in_list (sql/sql_base.cc). A name in HAVING outside set functions, and a name of a nested query that reaches the HAVING position outwards, is searched first among the GROUP BY items that are columns and then in the select list; a GROUP BY column wins over a select list item. In GROUP BY a column matches by its column name, and a qualified name also by the occurrence the column belongs to: a column of another occurrence ends the search without a match, and two equally good columns that differ are ambiguous. In the select list an unqualified name matches the first item that is not a column and is named so, else the column items named so (two different ones are ambiguous), else the column items whose column has the name under another alias (likewise); a qualified name matches only column items of an occurrence it admits. An item that is not a column and whose name depends on missing inputs (OutputSlot::$unnamed) may be the item named so: the outcome is conditional. A column item resolves to its column, another item to the item (an alias target). Names of columns are compared by the context's column comparison. Terminates: one pass over each list. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html ("MySQL permits HAVING to refer to columns in the SELECT list and columns in outer subqueries"), https://dev.mysql.com/doc/refman/8.4/en/group-by-handling.html. Status: Implemented.
Methods§
public function find(
GroupedRow $row,
Environment $scope,
Name $column,
?QualifiedName $qualifier,
int $depth,
): ?ResolutionResolves a name at a HAVING position of a query that lies a number of queries outwards; null when neither list has it.
Parameters
$row | GroupedRow | |
$scope | Environment | |
$column | Name | |
$qualifier | ?QualifiedName | |
$depth | int |
Returns
Called from 1
Calls 2
- method-call ResultReferences::grouping() line 56
- method-call ResultReferences::selected() line 56
public function grouping(
GroupedRow $row,
Environment $scope,
Name $column,
?QualifiedName $qualifier,
int $depth,
): ?ResolutionSearches the GROUP BY columns; null when none has the name.
Parameters
$row | GroupedRow | |
$scope | Environment | |
$column | Name | |
$qualifier | ?QualifiedName | |
$depth | int |
Returns
Called from 1
Calls 5
- method-call ResultReferences::named() line 68
- method-call ResultReferences::admitted() line 71
- method-call ResultReferences::same() line 75
- new AmbiguousColumn line 76
- method-call ResultReferences::deeper() line 76
public function selected(
GroupedRow $row,
Environment $scope,
Name $column,
?QualifiedName $qualifier,
int $depth,
): ?ResolutionSearches the select list; null when no item has the name.
Parameters
$row | GroupedRow | |
$scope | Environment | |
$column | Name | |
$qualifier | ?QualifiedName | |
$depth | int |
Returns
Called from 1
Calls 8
- method-call ResultReferences::unnamed() line 92
- method-call ResultReferences::undecided() line 98
- new AliasTarget line 98
- method-call ResultReferences::same() line 104
- new AmbiguousColumn line 105
- method-call ResultReferences::deeper() line 105
- method-call ResultReferences::unaliased() line 108
- method-call ResultReferences::chosen() line 114
public function undecided(
Name $column,
?Resolution $match,
list<MissingInput> $unnamed,
): ?ResolutionAnswers a select list match, or the conditional outcome while items whose names depend on missing inputs could be the match instead.
Parameters
$column | Name | |
$match | ?Resolution | |
$unnamed | list<MissingInput> | The inputs the names of those items depend on |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::selected() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:98
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::selected() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:114
Calls 1
public function unnamed(
GroupedRow $row,
Environment $scope,
Name $column,
?QualifiedName $qualifier,
): list<MissingInput>Answers the inputs the names of the items that are not columns depend on, up to the first such item an unqualified name names.
Parameters
$row | GroupedRow | |
$scope | Environment | |
$column | Name | |
$qualifier | ?QualifiedName |
Returns
list<MissingInput>Test cases 1
Called from 1
Calls 1
- function-call
array_pushline 146
public function unaliased(
Environment $scope,
ResolvedColumn $resolution,
Name $column,
?QualifiedName $qualifier,
): boolTells whether a column item of the select list matches a name by its column rather than by its alias.
Parameters
$scope | Environment | |
$resolution | ResolvedColumn | |
$column | Name | |
$qualifier | ?QualifiedName |
Returns
boolTest cases 1
Called from 1
Calls 2
- method-call ResultReferences::named() line 157
- method-call ResultReferences::admitted() line 157
public function chosen(
Name $column,
?ResolvedColumn $aliased,
?ResolvedColumn $unaliased,
?ResolvedColumn $other,
int $depth,
): ?ResolutionChooses among the select list matches: the item matched by its alias, else the only column matched by its own name.
Parameters
$column | Name | |
$aliased | ?ResolvedColumn | |
$unaliased | ?ResolvedColumn | |
$other | ?ResolvedColumn | |
$depth | int |
Returns
Test cases 1
Called from 1
Calls 2
- new AmbiguousColumn line 166
- method-call ResultReferences::deeper() line 166
public function named(Environment $scope, ResolvedColumn $resolution, Name $column): boolTells whether the column of a resolution has a name.
Parameters
$scope | Environment | |
$resolution | ResolvedColumn | |
$column | Name |
Returns
boolTest cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::grouping() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:68
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::unaliased() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:157
public function admitted(
Environment $scope,
ResolvedColumn $resolution,
Name $column,
QualifiedName $qualifier,
): boolTells whether a qualified name finds a resolved column in the occurrences of a position.
Parameters
$scope | Environment | |
$resolution | ResolvedColumn | |
$column | Name | |
$qualifier | QualifiedName |
Returns
boolTest cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::grouping() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:71
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::unaliased() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:157
Calls 3
- method-call LookupLevel::found() line 186
- new LookupLevel line 186
- method-call ResultReferences::same() line 187
public function same(ResolvedColumn $left, ResolvedColumn $right): boolTells whether two resolutions denote the same column of the same occurrence.
Parameters
$left | ResolvedColumn | |
$right | ResolvedColumn |
Returns
boolTest cases 1
Called from 4
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::grouping() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:75
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::selected() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:104
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::selected() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:109
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::admitted() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:187
public function deeper(ResolvedColumn $resolution, int $depth): ResolvedColumnAnswers a resolution as seen from a use a number of queries further in.
Parameters
$resolution | ResolvedColumn | |
$depth | int |
Returns
Called from 5
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::grouping() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:76
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::grouping() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:83
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::selected() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:105
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::chosen() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:166
- method-call SqlSemantics\Platform\MySql\Rules\Query\Having\ResultReferences::chosen() packages/sql-semantics-mysql/src/Rules/Query/Having/ResultReferences.php:170
Calls 1
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
ResultReferencesTest::testAdmittedTellsWhetherTheQualifierFindsTheColumncallsResultReferencesTest::testChosenPrefersTheAliasedMatchAndReportsTwoDifferentUnaliasedOnescallsResultReferencesTest::testDeeperCountsTheQueriesBetweenTheUseAndTheColumncallsResultReferencesTest::testNamedComparesTheColumnNameByTheColumnComparisonOfTheContextcallsResultReferencesTest::testSameComparesTheOccurrenceAndTheSlotcallsResultReferencesTest::testUnaliasedMatchesAColumnItemByItsColumnInAnAdmittedOccurrencecallsResultReferencesTest::testUndecidedKeepsAResolvedMatchAsCandidatecallsResultReferencesTest::testUnnamedStopsAtTheItemTheNameNamescalls