final class ResultReferences
Restricted visibility: declared "@visibility SqlSemantics\Platform\MySql". Code outside that scope must not name this declaration.

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,
): ?Resolution

Resolves a name at a HAVING position of a query that lies a number of queries outwards; null when neither list has it.

Parameters

$rowGroupedRow
$scopeEnvironment
$columnName
$qualifier?QualifiedName
$depthint

Returns

Test cases 1
Called from 1
Calls 2
public function grouping(
    GroupedRow $row,
    Environment $scope,
    Name $column,
    ?QualifiedName $qualifier,
    int $depth,
): ?Resolution
public function undecided(
    Name $column,
    ?Resolution $match,
    list<MissingInput> $unnamed,
): ?Resolution

Answers a select list match, or the conditional outcome while items whose names depend on missing inputs could be the match instead.

Parameters

$columnName
$match?Resolution
$unnamedlist<MissingInput>The inputs the names of those items depend on

Returns

Test cases 1
Called from 2
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

$rowGroupedRow
$scopeEnvironment
$columnName
$qualifier?QualifiedName

Returns

Test cases 1
Called from 1
Calls 1
public function unaliased(
    Environment $scope,
    ResolvedColumn $resolution,
    Name $column,
    ?QualifiedName $qualifier,
): bool

Tells whether a column item of the select list matches a name by its column rather than by its alias.

Parameters

$scopeEnvironment
$resolutionResolvedColumn
$columnName
$qualifier?QualifiedName

Returns

bool
Test cases 1
Called from 1
Calls 2
public function chosen(
    Name $column,
    ?ResolvedColumn $aliased,
    ?ResolvedColumn $unaliased,
    ?ResolvedColumn $other,
    int $depth,
): ?Resolution

Chooses among the select list matches: the item matched by its alias, else the only column matched by its own name.

Parameters

$columnName
$aliased?ResolvedColumn
$unaliased?ResolvedColumn
$other?ResolvedColumn
$depthint

Returns

Test cases 1
Called from 1
Calls 2

Test cases 8§

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

Dedicated tests 8

Relations§

Instantiated in 1
Method calls 1