classAlterTable
final class AlterTable
implements Statement, Relation
uses Snapshot
@visibility public.ALTER [IGNORE] TABLE t action, …: a request to change the structure of a table.
Mirrors PT_alter_table_stmt and PT_alter_table_standalone_stmt. Rule: MYSQL-ALTER-TABLE-001. The actions are kept in the order written, modifiers (ALGORITHM, LOCK, VALIDATION) among them; a standalone action (a partition or tablespace operation) is the last one and only modifiers precede it; PARTITION BY and REMOVE PARTITIONING are the last one and follow the others without a comma. The table resolves by MYSQL-CHANGE-TARGET-001; a declared view is refused (MYSQL-RELATION-KIND-001). The statement node is the relation occurrence the expressions of the actions see: its relation fact holds the resolution of the table and the row shape of the visible columns the table has after the column actions; its invisible columns are found by name only (MYSQL-COLUMN-CHANGES-001), which also reports a changed, dropped, renamed or altered column the completely known table does not have and a column name the table would have twice. The statement changes no declaration and provides none. IGNORE exists in 5.6 only. Source: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html, https://dev.mysql.com/doc/refman/5.6/en/alter-table.html. Status: Implemented.
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
$table = $semantics->analyze('CREATE TABLE t (a INT)');
$semantics->analyze('ALTER TABLE t DROP COLUMN b, ALGORITHM = INPLACE', [$table]) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\SemanticException: Column b does not exist in the table.Properties§
public list<AlterCommand> $commandspublic QualifiedName $tablepublic bool $ignore = falseMethods§
public function __construct(
public QualifiedName $table,
list<AlterCommand> $commands,
public bool $ignore = false,
)Parameters
$table | QualifiedName | The table with its optional database |
$commands | list<AlterCommand> | The actions in the order written |
$ignore | bool | Whether IGNORE is written (5.6) |
Calls 4
- static-call Check::input() line 69
- static-call Check::listOf() line 70
- class-const AlterCommand::class() line 70
- function-call
countline 71
public function deriveStatement(Derivation $derivation): voidDerives the table and every action in the scope of the table as the statement leaves it.
Parameters
$derivation | Derivation |
Calls 12
- method-call Targets::target() line 87
- new Targets line 87
- method-call RelationKinds::require() line 88
- new RelationKinds line 88
- class-const RelationKind::BaseTable() line 88
- new ColumnChanges line 89
- method-call Derivation::target() line 90
- new RelationFact line 90
- method-call ColumnChanges::apply() line 90
- new Environment line 91
- new VisibleRelation line 91
- method-call ColumnChanges::implicit() line 91
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the table and answers the row shape of its visible columns after the column actions.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 5
- method-call Targets::target() line 102
- new Targets line 102
- new RelationFact line 104
- method-call ColumnChanges::apply() line 104
- new ColumnChanges line 104
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 6
- method-call Output::keyword() line 112
- method-call Output::name() line 118
- class-const NameUse::Qualifier() line 118
- class-const NameUse::Relation() line 120
- method-call Output::symbol() line 123
- method-call Output::node() line 125
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
AlterTableTestcalls
Other tests reaching this symbol 3
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Lowering\TableChange\Alter\AlterRule::statement() packages/sql-semantics-mysql/src/Lowering/TableChange/Alter/AlterRule.php:87
- new SqlSemantics\Platform\MySql\Lowering\TableChange\Alter\AlterRule::statement() packages/sql-semantics-mysql/src/Lowering/TableChange/Alter/AlterRule.php:94