classTableReference
final class TableReference
implements NamedRelation
uses Snapshot
@visibility public.One occurrence of a named table, view or common table as query input, with its partition selection, index hints and sampling.
Rule: MYSQL-TABLE-REFERENCE-001. The name resolves by MYSQL-TABLE-SHAPES-001. Partition and index names are not checked: the analysis context holds neither. The sampling percentage is derived by the FROM clause that holds the occurrence. Source: https://dev.mysql.com/doc/refman/8.4/en/join.html, https://dev.mysql.com/doc/refman/8.4/en/partitioning-selection.html. Status: Implemented.
$input = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM shop.t AS x')->singleNamedInput();
[$input->name()->schema?->value, $input->name()->name->value, $input->alias()?->value] // => ['shop', 't', 'x']$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t PARTITION (p0, p1)');
count($query->statement->from->partitions) // => 2Properties§
public list<Name> $partitionspublic list<IndexHint> $indexHintspublic QualifiedName $namepublic Name|null $alias = nullpublic TableSample|null $sample = nullpublic AliasMark $mark = AliasMark::Aspublic OptionalWords $dot = OptionalWords::OmittedMethods§
public function __construct(
public QualifiedName $name,
public Name|null $alias = null,
list<Name> $partitions = [],
list<IndexHint> $indexHints = [],
public TableSample|null $sample = null,
public AliasMark $mark = AliasMark::As,
public OptionalWords $dot = OptionalWords::Omitted,
)Parameters
$name | QualifiedName | The table name with its optional database |
$alias | Name|null | The correlation name |
$partitions | list<Name> | The selected partitions |
$indexHints | list<IndexHint> | The index hints |
$sample | TableSample|null | The sampling clause |
$mark | AliasMark | What is written before the alias |
$dot | OptionalWords | Whether the name is written after a leading dot, `.t` (MySQL 5.6 and 5.7) |
Calls 6
- class-const AliasMark::As() line 66
- class-const OptionalWords::Omitted() line 66
- static-call Check::input() line 68
- static-call Check::listOf() line 71
- class-const Name::class() line 71
- class-const IndexHint::class() line 72
public function name(): QualifiedNameAnswers the table name.
Returns
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the name, derives the sampling percentage and the row shape of the occurrence.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 4
- method-call Derivation::scalar() line 97
- new Environment line 97
- method-call TableShapes::named() line 100
- new TableShapes line 100
public function render(Output $out): voidWrites the name, the partitions, the correlation name, the index hints and the sampling clause.
Parameters
$out | Output |
Calls 11
- class-const OptionalWords::Written() line 108
- method-call LeadingDot::write() line 109
- new LeadingDot line 109
- method-call Output::name() line 112
- class-const NameUse::Qualifier() line 112
- class-const NameUse::Relation() line 114
- method-call Output::keyword() line 116
- method-call Output::symbol() line 119
- class-const NameUse::Alias() line 121
- method-call AliasMark::write() line 126
- method-call Output::node() line 130
Test cases 18§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
TableReferenceTest::testACatalogQualifierIsRejectedcallsTableReferenceTest::testDeriveRelationDoesNotFindATableOfAnotherDatabasecallsTableReferenceTest::testDeriveRelationExposesOneSlotPerDeclaredColumncallsTableReferenceTest::testDeriveRelationLeavesTheShapeOpenForAnUndeclaredTablecallsTableReferenceTest::testDeriveRelationReportsAMissingTableWithAnEmptyCompleteShapecallsTableReferenceTest::testDeriveRelationReportsConflictingDeclarationscallsTableReferenceTest::testNameAnswersTheTableNameWithItsDatabasecalls
Other tests reaching this symbol 11
NameRuleTest::testDottedTellsATableNameWrittenAfterALeadingDotcallsNameRuleTest::testQualifiedLowersATableNameWithItsDatabasecallsReferenceRuleTest::testJoinedWalksTheJoinsOnTheLeftcallsFromRuleTest::testTablesAnswersOneReferenceOrAListcallsTableRuleTest::testMarkAnswersWhatIsWrittenBeforeTheAliascallsTableRuleTest::testPartitionsLowersTheNamescallsSelectTest::testANodeUsedAtTwoPositionsIsRejectedcallsSelectTest::testInputAnswersTheTableReferencecallsSelectTest::testRenderBuildsSqlFromAnExplicitStructurecallsEscapedRelationTest::testDeriveRelationDerivesTheEscapedReferencecallsTableSampleTest::testThePercentageIsDerivedWithoutColumnscalls