classIndexDefinition
final class IndexDefinition
implements TableElement
uses Snapshot
@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.
$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> $partspublic list<IndexOption> $optionspublic IndexKind $kindpublic ColumnName|null $name = nullpublic IndexAlgorithm|null $algorithm = nullpublic ConstraintName|null $constraint = nullpublic bool $keyword = falseMethods§
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
$kind | IndexKind | The kind of index |
$parts | list<KeyPart> | The key parts in order; at least one |
$name | ColumnName|null | The index name, when written |
$algorithm | IndexAlgorithm|null | The USING clause written before the key parts |
$options | list<IndexOption> | The options after the key parts, in written order |
$constraint | ConstraintName|null | The CONSTRAINT clause of a PRIMARY KEY or UNIQUE index |
$keyword | bool | Whether INDEX or KEY is written after UNIQUE, FULLTEXT or SPATIAL |
Calls 8
- static-call Check::listOf() line 67
- class-const KeyPart::class() line 67
- class-const IndexOption::class() line 68
- static-call Check::input() line 69
- class-const IndexKind::Primary() line 69
- class-const IndexKind::Unique() line 69
- class-const IndexKind::FullText() line 70
- class-const IndexKind::Spatial() line 70
public function deriveElement(Derivation $derivation, Environment $scope): voidDerives the functional key parts at the position of the table.
Parameters
$derivation | Derivation | |
$scope | Environment |
public function render(Output $out): voidWrites the constraint, the kind, the name, the algorithm, the key parts and the options.
Parameters
$out | Output |
Calls 4
- method-call Output::node() line 89
- function-call
explodeline 89 - method-call Output::keyword() line 91
- method-call Output::symbol() line 97
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
ElementRuleTest::testElementsLowersTheElementListcallsColumnPartTest::testDeriveKeyPartDerivesNothingcallsExpressionPartTest::testDeriveKeyPartResolvesTheExpressionInTheTablecallsIndexCommentTest::testRenderWritesTheOptioncallsIndexEngineAttributeTest::testRenderWritesTheOptioncallsIndexParserTest::testRenderWritesTheOptioncallsIndexUsingTest::testRenderWritesTheOptioncallsIndexVisibilityTest::testRenderWritesTheOptioncallsKeyBlockSizeTest::testRenderWritesTheOptioncalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Key\KeyRule::index() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Key/KeyRule.php:114
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\Key\KeyRule::constrained() packages/sql-semantics-mysql/src/Lowering/TableDefinition/Key/KeyRule.php:141
Type checks 3
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\TableDeclaration::primaryColumns() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableDeclaration.php:88
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:72
- instanceof SqlSemantics\Platform\MySql\Rules\TableDefinition\TableProblems::report() packages/sql-semantics-mysql/src/Rules/TableDefinition/TableProblems.php:73