classDerivedTable
final class DerivedTable
implements Relation
uses Snapshot
@visibility public.A derived table: [LATERAL] (query) [AS] alias [(columns)].
The query is the one inside the parentheses the syntax requires.
Rule: MYSQL-DERIVED-TABLE-001. The query sees the enclosing queries and, when LATERAL is written, the tables to its left in the same FROM clause (MYSQL-FROM-SCOPE-001). The columns are those of the query, renamed by the column list (MYSQL-DERIVED-SHAPES-001). A derived table without alias is reported. Source: https://dev.mysql.com/doc/refman/8.4/en/derived-tables.html, https://dev.mysql.com/doc/refman/8.4/en/lateral-derived-tables.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT x FROM (SELECT 1) AS d (x)');
[$query->statement->from->alias?->value, $query->statement->from->columns[0]->value] // => ['d', 'x']Properties§
public list<Name> $columnspublic Query $querypublic Name|null $alias = nullpublic bool $lateral = falsepublic AliasMark $mark = AliasMark::AsMethods§
public function __construct(
public Query $query,
public Name|null $alias = null,
list<Name> $columns = [],
public bool $lateral = false,
public AliasMark $mark = AliasMark::As,
)Parameters
Calls 4
- class-const AliasMark::As() line 56
- static-call Check::input() line 58
- static-call Check::listOf() line 59
- class-const Name::class() line 59
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactDerives the query and the row shape of the derived table.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 7
- method-call Derivation::report() line 68
- new Misuse line 68
- class-const MisuseRule::DerivedWithoutAlias() line 68
- new RelationFact line 71
- method-call DerivedShapes::shape() line 71
- new DerivedShapes line 71
- method-call Derivation::query() line 71
public function render(Output $out): voidWrites the derived table.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 80
- method-call Output::symbol() line 82
- method-call AliasMark::write() line 84
- method-call Output::name() line 85
- class-const NameUse::Alias() line 85
- class-const NameUse::Column() line 93
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
DerivedTableTestcalls
Other tests reaching this symbol 2
Relations§
Instantiated in 3
- new SqlSemantics\Platform\MySql\Lowering\Query\Legacy\FactorRule::factor() packages/sql-semantics-mysql/src/Lowering/Query/Legacy/FactorRule.php:79
- new SqlSemantics\Platform\MySql\Lowering\Query\Legacy\FactorRule::parens() packages/sql-semantics-mysql/src/Lowering/Query/Legacy/FactorRule.php:125
- new SqlSemantics\Platform\MySql\Lowering\Query\Modern\FactorRule::derived() packages/sql-semantics-mysql/src/Lowering/Query/Modern/FactorRule.php:96
Type checks 4
- instanceof SqlSemantics\Platform\MySql\Rules\Dml\ChangeFacts::updatable() packages/sql-semantics-mysql/src/Rules/Dml/ChangeFacts.php:118
- instanceof SqlSemantics\Platform\MySql\Rules\Dml\SourceRelations::visible() packages/sql-semantics-mysql/src/Rules/Dml/SourceRelations.php:62
- instanceof SqlSemantics\Platform\MySql\Rules\Query\From\FromScope::open() packages/sql-semantics-mysql/src/Rules/Query/From/FromScope.php:59
- instanceof SqlSemantics\Platform\MySql\Rules\Query\From\FromScope::open() packages/sql-semantics-mysql/src/Rules/Query/From/FromScope.php:63