classHavingScope
final class HavingScope
Builds the environment of a HAVING clause, and the environment of the set functions written in it.
Rule: MYSQL-HAVING-SCOPE-001. The parser reads a column name written in HAVING outside the arguments of a set function as a reference to the grouped result row (Item_ref), and every other column name as a column (Item_field): PTI_simple_ident_ident, PTI_simple_ident_q_3d and PTI_simple_ident_nospvar_ident in parse_tree_items.cc, and the simple_ident actions of the 5.x grammars, test parsing_place != CTX_HAVING || in_sum_expr > 0; a set function written without OVER raises in_sum_expr while its arguments are read (Item_sum::itemize, PTI_in_sum_expr). The HAVING environment is the environment of the clause with a GroupedRow entry; a set function without OVER reads its arguments, its ORDER BY and its nested queries in the same environment without the entry. A nested query is a query block of its own and starts outside HAVING, but it sees the entry as part of its enclosing position. Terminates: one pass over the visible relations. Source: https://dev.mysql.com/doc/refman/8.4/en/select.html. Status: Implemented.
Methods§
public function enter(Environment $environment, GroupedRow $row): EnvironmentAnswers the environment of a HAVING clause: the given one with the grouped row of the block.
Parameters
$environment | Environment | |
$row | GroupedRow |
Returns
Test cases 3
Called from 1
Calls 3
- new Environment line 46
- new VisibleRelation line 46
- new RowShape line 46
public function grouping(
list<ScalarFact> $items,
list<VisibleRelation> $visible,
list<VisibleRelation> $output,
): list<Field>Answers the GROUP BY items that are columns, each with its column as the HAVING position sees it.
An item is a column when it is a column name, or an alias or a position of a select list item that is a column name (its value is then that column, real_item() in the server). The HAVING position of a block that aggregates or groups with a modifier sees the columns as they may be NULL there; the given lists hold each occurrence before and after that extension, in the same order.
Parameters
$items | list<ScalarFact> | The facts of the GROUP BY items, in order |
$visible | list<VisibleRelation> | The occurrences of the FROM clause |
$output | list<VisibleRelation> | The same occurrences as the HAVING position sees them |
Returns
list<Field>Called from 1
public function undecided(
list<ScalarFact> $items,
list<Field|OpenStar> $selected,
): list<ConditionalColumn>Answers the GROUP BY items and the select list items that are columns no known occurrence decides.
Such a column belongs to an incompletely known occurrence, so the server may find a HAVING name among the GROUP BY columns or the select list items that this analysis cannot see.
Parameters
$items | list<ScalarFact> | The facts of the GROUP BY items, in order |
$selected | list<Field|OpenStar> | The output fields of the select list, in order |
Returns
list<ConditionalColumn>public function leave(Environment $environment): EnvironmentAnswers the environment of the arguments of a set function: the given one without a grouped row.
Parameters
$environment | Environment |
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\Aggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/Aggregate.php:92
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:90
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\JsonObjectAggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/JsonObjectAggregate.php:71
Calls 4
- method-call HavingScope::row() line 118
- function-call
array_valuesline 121 - function-call
array_filterline 121 - new Environment line 123
public function row(Environment $environment): ?GroupedRowAnswers the grouped row an environment carries, or null outside HAVING.
Parameters
$environment | Environment |
Returns
Test cases 1
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
HavingScopeTest::testEnterAddsTheGroupedRowAsAnOccurrenceWithoutColumnscallsHavingScopeTest::testLeaveLetsTheArgumentsOfASetFunctionSeeTheColumnscallsHavingScopeTest::testRowAnswersTheGroupedRowOfAHavingEnvironmentOnlycallsHavingScopeTest::testUndecidedAnswersTheColumnsOfIncompletelyKnownOccurrencescalls
Relations§
Instantiated in 5
- new SqlSemantics\Platform\MySql\Rules\ColumnResolver::find() packages/sql-semantics-mysql/src/Rules/ColumnResolver.php:78
- new SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:75
- new SqlSemantics\Platform\MySql\Statement\Call\Aggregate\Aggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/Aggregate.php:92
- new SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:90
- new SqlSemantics\Platform\MySql\Statement\Call\Aggregate\JsonObjectAggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/JsonObjectAggregate.php:71
Method calls 7
- method-call SqlSemantics\Platform\MySql\Rules\ColumnResolver::find() packages/sql-semantics-mysql/src/Rules/ColumnResolver.php:78
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:76
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:76
- method-call SqlSemantics\Platform\MySql\Rules\Query\SelectFacts::derive() packages/sql-semantics-mysql/src/Rules/Query/SelectFacts.php:77
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\Aggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/Aggregate.php:92
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\GroupConcat::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/GroupConcat.php:90
- method-call SqlSemantics\Platform\MySql\Statement\Call\Aggregate\JsonObjectAggregate::deriveScalar() packages/sql-semantics-mysql/src/Statement/Call/Aggregate/JsonObjectAggregate.php:71