classCommonTables
final class CommonTables
Binds the common table expressions of a WITH clause.
Rule: MYSQL-WITH-001. The expressions are bound in written order; each sees the expressions before it and the enclosing scope, and a name defined twice is reported. Under RECURSIVE an expression whose query refers to its own name also sees itself: its query is a set operation whose leading operands do not refer to it, and the columns are those of these operands, all nullable (MYSQL-SET-FACTS-001 derives the later operands with that shape). A recursive expression whose query is no such set operation is reported, and a reference to it sees columns that depend on the missing nonrecursive part. The shape of every expression is that of its query under its column list (MYSQL-DERIVED-SHAPES-001). The bindings extend the enclosing scope without opening a query level. Terminates: every expression is derived once. Source: https://dev.mysql.com/doc/refman/8.4/en/with.html ("The types of the CTE result columns are inferred from the column types of the nonrecursive SELECT part only, and the columns are all nullable"). Status: Implemented.
Methods§
public function bind(With $with, Derivation $derivation, Environment $outer): EnvironmentDerives the expressions and answers the scope in which the statement that holds the clause sees them.
Parameters
$with | With | |
$derivation | Derivation | |
$outer | Environment |
Returns
Called from 1
Calls 14
- method-call Derivation::report() line 62
- new Misuse line 62
- class-const MisuseRule::DuplicateCommonTable() line 62
- method-call CommonTables::extended() line 65
- method-call CommonTables::refers() line 66
- method-call CommonTables::operands() line 67
- function-call
countline 68 - class-const MisuseRule::RecursiveWithoutAnchor() line 69
- new CommonBinding line 71
- new RowShape line 71
- new RecursiveReference line 71
- method-call DerivedShapes::shape() line 73
- new DerivedShapes line 73
- method-call Derivation::query() line 73
public function extended(Environment $outer, list<CommonBinding> $bindings): EnvironmentAnswers the enclosing scope with further common tables, at the same query level.
Parameters
$outer | Environment | |
$bindings | list<CommonBinding> |
Returns
Test cases 3
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::bind() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:65
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::bind() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:71
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::bind() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:76
Calls 1
- new Environment line 86
public function pending(
Environment $outer,
Query $right,
Derivation $derivation,
): ?CommonBindingAnswers the recursive expression whose self reference a set operand is derived for: a binding of the scope that still waits for its nonrecursive part and that the right operand of a set operation refers to.
Parameters
$outer | Environment | |
$right | Query | |
$derivation | Derivation |
Returns
Test cases 1
Called from 1
Calls 2
- function-call
array_reverseline 94 - method-call CommonTables::refers() line 99
public function anchored(
Environment $outer,
CommonBinding $pending,
QueryFact $anchor,
Derivation $derivation,
): EnvironmentAnswers the scope with a waiting recursive expression bound to the columns of the nonrecursive part.
Parameters
$outer | Environment | |
$pending | CommonBinding | |
$anchor | QueryFact | |
$derivation | Derivation |
Returns
Test cases 1
Called from 1
Calls 3
- new CommonBinding line 114
- method-call CommonTables::shape() line 114
- new Environment line 117
public function shape(
CommonBinding $pending,
QueryFact $anchor,
Derivation $derivation,
): RowShapeAnswers the columns a recursive expression sees itself with: those of the nonrecursive part under its column list, all nullable.
Parameters
$pending | CommonBinding | |
$anchor | QueryFact | |
$derivation | Derivation |
Returns
Test cases 1
Called from 1
Calls 3
- method-call CommonTables::nullable() line 127
- new OutputSlot line 128
- new RowShape line 131
Answers the output of a recursive set operation: the columns of its nonrecursive part, all nullable.
Parameters
$anchor | QueryFact |
Returns
Test cases 1
Called from 2
Calls 4
- new Field line 141
- new OutputSlot line 141
- class-const Nullability::Nullable() line 141
- new QueryFact line 144
public function refers(Query $query, Name $table, Derivation $derivation): boolTells whether a query names a table as an unqualified table reference.
Parameters
$query | Query | |
$table | Name | |
$derivation | Derivation |
Returns
boolTest cases 1
Called from 3
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::bind() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:66
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::bind() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:68
- method-call SqlSemantics\Platform\MySql\Rules\Query\CommonTables::pending() packages/sql-semantics-mysql/src/Rules/Query/CommonTables.php:99
Calls 2
- new ValueGraph line 172
- method-call ValueGraph::objects() line 173
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
CommonTablesTest::testAnchoredBindsTheColumnsOfTheNonrecursivePartcallsCommonTablesTest::testExtendedAddsTablesWithoutAQueryLevelcallsCommonTablesTest::testNullableMakesEveryColumnNullablecallsCommonTablesTest::testOperandsAnswersTheChainInWrittenOrdercallsCommonTablesTest::testOperandsWalksALeadingUnioncallsCommonTablesTest::testPendingFindsTheRecursiveTableARightOperandRefersTocallsCommonTablesTest::testRefersFindsAnUnqualifiedReferencecallsCommonTablesTest::testShapeRenamesTheColumnsByTheColumnListcalls
Relations§
Instantiated in 2
Method calls 4
- method-call SqlSemantics\Platform\MySql\Rules\Query\SetFacts::operands() packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:53
- method-call SqlSemantics\Platform\MySql\Rules\Query\SetFacts::operands() packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:54
- method-call SqlSemantics\Platform\MySql\Rules\Query\SetFacts::operands() packages/sql-semantics-mysql/src/Rules/Query/SetFacts.php:57
- method-call SqlSemantics\Platform\MySql\Statement\Query\With\With::bind() packages/sql-semantics-mysql/src/Statement/Query/With/With.php:51