classCreateIndex
final class CreateIndex
implements Statement, Relation
uses Snapshot
@visibility public.A request to add an index to an existing table: CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX.
Rule: MYSQL-CREATE-INDEX-001. The statement node is the one occurrence of the indexed table: its relation fact is the resolution of the table name (MYSQL-DEFINITION-SCOPE-001), which is no declared view (MYSQL-RELATION-KIND-001), and the functional key parts are derived at a position whose only visible relation is that table. A key column the declared table lacks is a diagnostic (ER_KEY_COLUMN_DOES_NOT_EXITS). The ALGORITHM and LOCK clauses come from the table change family. Indexes are not part of a declaration context: the statement provides no declaration. Source: https://dev.mysql.com/doc/refman/8.4/en/create-index.html. Status: Implemented.
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
$table = $semantics->analyze('CREATE TABLE t (a INT, b INT)');
$index = $semantics->analyze('CREATE UNIQUE INDEX i ON t (b DESC, (a + b))', [$table]);
[$index->facts->relation($index->statement)->table->table === $table->declarations()[0], $index->facts->diagnostics] // => [true, []]Properties§
public non-empty-list<KeyPart> $partspublic list<IndexOption> $optionspublic list<AlterOption> $alterOptionspublic Name $namepublic QualifiedName $tablepublic IndexKind $kind = IndexKind::Indexpublic IndexAlgorithm|null $algorithm = nullMethods§
public function __construct(
public Name $name,
public QualifiedName $table,
list<KeyPart> $parts,
public IndexKind $kind = IndexKind::Index,
public IndexAlgorithm|null $algorithm = null,
list<IndexOption> $options = [],
list<AlterOption> $alterOptions = [],
)Parameters
$name | Name | The index name |
$table | QualifiedName | The indexed table |
$parts | list<KeyPart> | The key parts in order; at least one |
$kind | IndexKind | INDEX, UNIQUE, FULLTEXT or SPATIAL |
$algorithm | IndexAlgorithm|null | The USING clause written before ON |
$options | list<IndexOption> | The options after the key parts, in written order |
$alterOptions | list<AlterOption> | The ALGORITHM and LOCK clauses in written order |
Calls 8
- class-const IndexKind::Index() line 82
- static-call Check::input() line 87
- class-const IndexKind::Primary() line 88
- class-const IndexKind::Unique() line 89
- static-call Check::listOf() line 90
- class-const KeyPart::class() line 90
- class-const IndexOption::class() line 91
- class-const AlterOption::class() line 92
public function deriveStatement(Derivation $derivation): voidResolves the indexed table, derives the key parts against it and checks the ALGORITHM and LOCK clauses.
Parameters
$derivation | Derivation |
Calls 11
- new TableTargets line 100
- method-call Derivation::relation() line 101
- method-call Derivation::environment() line 101
- method-call RelationKinds::require() line 102
- new RelationKinds line 102
- class-const RelationKind::BaseTable() line 102
- method-call TableTargets::scope() line 104
- new QualifiedName line 104
- method-call TableTargets::implicit() line 104
- method-call Derivation::report() line 108
- new UnknownKeyColumn line 108
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the indexed table and answers its row shape.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call TableTargets::existing() line 121
- new TableTargets line 121
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 7
- method-call Output::keyword() line 129
- class-const IndexKind::Index() line 130
- class-const NameUse::Label() line 133
- method-call Output::name() line 139
- class-const NameUse::Qualifier() line 139
- class-const NameUse::Relation() line 141
- method-call Output::node() line 143
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.