final class IndexDefinition
    implements TableElement
    uses Snapshot
Public API: explicitly declared with @visibility public.

An index or key of a table definition: INDEX, PRIMARY KEY, UNIQUE, FULLTEXT or SPATIAL with its parts and options.

Rule: MYSQL-INDEX-DEFINITION-001. KEY and INDEX are synonyms. After UNIQUE, FULLTEXT and SPATIAL the word INDEX (or KEY) is optional and changes nothing; whether it is written is kept so the statement is written back with the same words. A USING clause can stand before the key parts and among the options; both are kept where written. The name of a PRIMARY KEY is ignored by the server (the primary key is always named PRIMARY). A CONSTRAINT clause is accepted before PRIMARY KEY and UNIQUE only. The functional key parts see the columns of the table (MYSQL-DEFINITION-SCOPE-001). Source: https://dev.mysql.com/doc/refman/8.4/en/create-table.html#create-table-indexes-keys, https://dev.mysql.com/doc/refman/8.4/en/create-index.html. Status: Implemented.

Reading an index definitiondoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TABLE t (a INT, b INT, UNIQUE KEY ab (a, b))');
    [$create->statement->elements[2]->kind, $create->statement->elements[2]->name->column->value, count($create->statement->elements[2]->parts)] // => [\SqlSemantics\Platform\MySql\Statement\Table\Key\IndexKind::Unique, 'ab', 2]

Properties§

public non-empty-list<KeyPart> $parts
public list<IndexOption> $options
public IndexKind $kind
public ColumnName|null $name = null
public IndexAlgorithm|null $algorithm = null
public ConstraintName|null $constraint = null
public bool $keyword = false

Methods§

public function __construct(
    public IndexKind $kind,
    list<KeyPart> $parts,
    public ColumnName|null $name = null,
    public IndexAlgorithm|null $algorithm = null,
    list<IndexOption> $options = [],
    public ConstraintName|null $constraint = null,
    public bool $keyword = false,
)

Parameters

$kindIndexKindThe kind of index
$partslist<KeyPart>The key parts in order; at least one
$nameColumnName|nullThe index name, when written
$algorithmIndexAlgorithm|nullThe USING clause written before the key parts
$optionslist<IndexOption>The options after the key parts, in written order
$constraintConstraintName|nullThe CONSTRAINT clause of a PRIMARY KEY or UNIQUE index
$keywordboolWhether INDEX or KEY is written after UNIQUE, FULLTEXT or SPATIAL
Calls 8
public function deriveElement(Derivation $derivation, Environment $scope): void

Derives the functional key parts at the position of the table.

Parameters

$derivationDerivation
$scopeEnvironment
public function render(Output $out): void

Writes the constraint, the kind, the name, the algorithm, the key parts and the options.

Parameters

$outOutput
Calls 4

Test cases 10§

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

Dedicated tests 1
Other tests reaching this symbol 9

Relations§

Instantiated in 2
Type checks 3
Type declarations 2