classColumnResolver
final class ColumnResolver
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 find(
Environment $environment,
Name $column,
?QualifiedName $qualifier = null,
): ResolutionResolves a column name written with an optional relation qualifier.
Parameters
$environment | Environment | |
$column | Name | |
$qualifier | ?QualifiedName |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\ColumnResolver::fact() packages/sql-semantics-mysql/src/Rules/ColumnResolver.php:122
- method-call SqlSemantics\Platform\MySql\Rules\Routine\ProgramScope::variable() packages/sql-semantics-mysql/src/Rules/Routine/ProgramScope.php:79
- method-call SqlSemantics\Platform\MySql\Rules\Routine\TriggerAssignments::check() packages/sql-semantics-mysql/src/Rules/Routine/TriggerAssignments.php:60
Calls 16
- new ColumnLookup line 74
- method-call HavingScope::row() line 78
- new HavingScope line 78
- method-call ResultReferences::find() line 80
- new ResultReferences line 80
- method-call ColumnResolver::undecided() line 82
- method-call ColumnLookup::conditional() line 85
- method-call ColumnResolver::unlisted() line 87
- new LookupLevel line 93
- method-call LookupLevel::found() line 94
- method-call LookupLevel::open() line 95
- function-call
countline 101 - new AmbiguousColumn line 101
- method-call ColumnResolver::unnamed() line 103
- method-call ColumnResolver::alias() line 109
- new MissingColumn line 114
public function fact(
Environment $environment,
Name $column,
?QualifiedName $qualifier = null,
): ScalarFactAnswers the facts of a column name: those of the column or select list item it resolves to, else the outcome as the cause.
Parameters
$environment | Environment | |
$column | Name | |
$qualifier | ?QualifiedName |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Statement\Name\ColumnUse::deriveScalar() packages/sql-semantics-mysql/src/Statement/Name/ColumnUse.php:64
- method-call SqlSemantics\Platform\MySql\Statement\Utility\Set\BareName::deriveScalar() packages/sql-semantics-mysql/src/Statement/Utility/Set/BareName.php:71
Calls 6
- method-call ColumnResolver::find() line 122
- new ScalarFact line 124
- new Dependent line 130
- class-const Nullability::Dependent() line 130
- static-call Check::invariant() line 132
- new Invalid line 134
public function row(Environment $environment, QualifiedName $qualifier): boolTells 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
$environment | Environment | |
$qualifier | QualifiedName |
Returns
boolTest cases 1
Called from 1
Calls 1
- function-call
strcasecmpline 146
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
$row | GroupedRow | |
$scope | Environment | |
$column | Name |
Returns
list<VisibleRelation>Test cases 1
Called from 1
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
$fields | list<Field> |
Returns
list<MissingInput>Test cases 1
Called from 1
Calls 1
- function-call
array_pushline 204
public function undecided(
Name $column,
list<ResolvedColumn> $candidates,
list<VisibleRelation> $open,
list<MissingInput> $unnamed,
): ConditionalColumnBuilds the conditional outcome of a name that incompletely known occurrences or undecided item names may own.
Parameters
$column | Name | |
$candidates | list<ResolvedColumn> | |
$open | list<VisibleRelation> | |
$unnamed | list<MissingInput> | The inputs the names of select list items depend on |
Returns
Called from 2
Calls 3
- function-call
array_pushline 223 - static-call LookupLevel::undecided() line 223
- new ConditionalColumn line 226
public function alias(Name $column, non-empty-list<Field> $fields): AliasTarget|AmbiguousAliasChooses the select list item an alias names: the only one, or the first of items that compute the same expression.
Returns
Test cases 1
Called from 1
Calls 5
- new Equivalence line 237
- method-call Equivalence::difference() line 239
- function-call
countline 240 - new AliasTarget line 240
- new AmbiguousAlias line 240
Test cases 7§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
ColumnResolverTest::testAliasTreatsItemsComputingTheSameExpressionAsOnecallsColumnResolverTest::testFactAnswersTheFactsOfTheColumnOrTheProblemcallsColumnResolverTest::testFindIgnoresAliasesForAQualifiedNamecallsColumnResolverTest::testRowTellsWhetherATriggerRowIsVisiblecallsColumnResolverTest::testUndecidedJoinsTheInputsOfOpenOccurrencesAndUnnamedItemscallsColumnResolverTest::testUnlistedAnswersTheOccurrencesThatMayGiveAHavingPositionTheNamecallsColumnResolverTest::testUnnamedAnswersTheInputsTheItemNamesDependOncalls
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Rules\Routine\ProgramScope::variable() packages/sql-semantics-mysql/src/Rules/Routine/ProgramScope.php:79
- new SqlSemantics\Platform\MySql\Rules\Routine\TriggerAssignments::check() packages/sql-semantics-mysql/src/Rules/Routine/TriggerAssignments.php:60
- new SqlSemantics\Platform\MySql\Statement\Name\ColumnUse::deriveScalar() packages/sql-semantics-mysql/src/Statement/Name/ColumnUse.php:64
- new SqlSemantics\Platform\MySql\Statement\Utility\Set\BareName::deriveScalar() packages/sql-semantics-mysql/src/Statement/Utility/Set/BareName.php:69
Method calls 5
- method-call SqlSemantics\Platform\MySql\Rules\Routine\ProgramScope::variable() packages/sql-semantics-mysql/src/Rules/Routine/ProgramScope.php:79
- method-call SqlSemantics\Platform\MySql\Rules\Routine\TriggerAssignments::check() packages/sql-semantics-mysql/src/Rules/Routine/TriggerAssignments.php:60
- method-call SqlSemantics\Platform\MySql\Statement\Name\ColumnUse::deriveScalar() packages/sql-semantics-mysql/src/Statement/Name/ColumnUse.php:64
- method-call SqlSemantics\Platform\MySql\Statement\Utility\Set\BareName::deriveScalar() packages/sql-semantics-mysql/src/Statement/Utility/Set/BareName.php:70
- method-call SqlSemantics\Platform\MySql\Statement\Utility\Set\BareName::deriveScalar() packages/sql-semantics-mysql/src/Statement/Utility/Set/BareName.php:71