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

Resolves a column name the way MySQL does: the columns of a query first, then its select list aliases.

Rule: MYSQL-COLUMN-LOOKUP-001. The lookup starts at the innermost query and moves outwards one query at a time. At one query the relation occurrences the qualifier admits are searched as in CORE-COLUMN-LOOKUP-001: one known slot resolves, several are ambiguous, and an incompletely known occurrence at that or a nearer query makes the outcome conditional. When no slot has the name, an unqualified name is searched among the select list aliases the position may use (GROUP BY, HAVING, ORDER BY): one item, or several items computing the same expression, resolve to that item; several different items are ambiguous (ER_NON_UNIQ_ERROR). While an incompletely known occurrence could still own the name, the alias is not chosen and the outcome is conditional; so it is while a select list item whose name depends on missing inputs (OutputSlot::$unnamed) could have the name. Only a name found neither way continues outwards. At a HAVING position (MYSQL-HAVING-SCOPE-001) the GROUP BY columns and the select list are searched first (MYSQL-HAVING-REFERENCE-001); a name written there outside set functions never sees the columns of the FROM clause of its own query (ER_BAD_FIELD_ERROR "in 'having clause'"), and a name of a nested query sees them only when the enclosing block neither groups, aggregates nor is DISTINCT (Item_ref::fix_fields, Item_field::fix_outer_field). A select list star over an incompletely known occurrence, and a GROUP BY or select list column of the name that belongs to such an occurrence, leave a name not found there conditional. Terminates: the scopes form a finite chain. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html ("For GROUP BY or HAVING clauses, it searches the FROM clause before searching in the select_expr values"), https://dev.mysql.com/doc/refman/8.4/en/problems-with-alias.html. Status: Implemented.

Methods§

public function row(Environment $environment, QualifiedName $qualifier): bool

Tells whether a qualifier is NEW or OLD and a trigger body makes that row visible at the position.

The parser reads NEW.x and OLD.x in a trigger body as a column of the row (Item_trigger_field), whatever the position.

Parameters

$environmentEnvironment
$qualifierQualifiedName

Returns

bool
Test cases 1
Called from 1
Calls 1
public function unlisted(
    GroupedRow $row,
    Environment $scope,
    Name $column,
): list<VisibleRelation>

Answers the incompletely known occurrences that may give a HAVING position a column of the name unseen.

They are the occurrences a star of the select list may list, and the occurrences that may own a GROUP BY or select list column of the name that no known occurrence decides.

Parameters

$rowGroupedRow
$scopeEnvironment
$columnName

Returns

Test cases 1
Called from 1
Calls 4
public function unnamed(list<Field> $fields): list<MissingInput>

Answers the inputs the names of select list items depend on: an item without a decided name may be named anything.

Parameters

$fieldslist<Field>

Returns

Test cases 1
Called from 1
Calls 1
public function undecided(
    Name $column,
    list<ResolvedColumn> $candidates,
    list<VisibleRelation> $open,
    list<MissingInput> $unnamed,
): ConditionalColumn

Builds the conditional outcome of a name that incompletely known occurrences or undecided item names may own.

Parameters

$columnName
$candidateslist<ResolvedColumn>
$openlist<VisibleRelation>
$unnamedlist<MissingInput>The inputs the names of select list items depend on
Test cases 1
Called from 2
Calls 3
public function alias(Name $column, non-empty-list<Field> $fields): AliasTarget|AmbiguousAlias

Chooses the select list item an alias names: the only one, or the first of items that compute the same expression.

Parameters

$columnName
$fieldsnon-empty-list<Field>
Test cases 1
Called from 1
Calls 5

Test cases 7§

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

Dedicated tests 7

Relations§

Instantiated in 4
Method calls 5