final class CreateIndex
    implements Statement, Relation
    uses Snapshot
Public API: explicitly declared with @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.

Resolving the indexed tabledoctest
$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> $parts
public list<IndexOption> $options
public list<AlterOption> $alterOptions
public Name $name
public QualifiedName $table
public IndexKind $kind = IndexKind::Index
public IndexAlgorithm|null $algorithm = null

Methods§

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

$nameNameThe index name
$tableQualifiedNameThe indexed table
$partslist<KeyPart>The key parts in order; at least one
$kindIndexKindINDEX, UNIQUE, FULLTEXT or SPATIAL
$algorithmIndexAlgorithm|nullThe USING clause written before ON
$optionslist<IndexOption>The options after the key parts, in written order
$alterOptionslist<AlterOption>The ALGORITHM and LOCK clauses in written order
Calls 8
public function deriveStatement(Derivation $derivation): void

Resolves the indexed table, derives the key parts against it and checks the ALGORITHM and LOCK clauses.

Parameters

$derivationDerivation
Calls 11
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Resolves the indexed table and answers its row shape.

Parameters

$derivationDerivation
$environmentEnvironment
Calls 2
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 7

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 2
Other tests reaching this symbol 1

Relations§

Instantiated in 1
Type declarations 2