classCreateIndex
final class CreateIndex
implements Statement, Relation
uses Snapshot
@visibility public.A request to create an index on a table.
Rule: SQLITE-CREATE-INDEX-001. The table is named without a schema and belongs to the schema of the index name; without one it is found on the search path. Its resolution is the relation fact of the statement node: the node is the one occurrence of the indexed table, and the indexed expressions and the WHERE condition of a partial index are derived at a position whose only visible relation is that table: the condition sees its columns and its row identifier, an indexed expression sees its columns only, as SQLite does not resolve rowid there. A missing or conflicting table, a missing column, and a bound parameter, a subquery, a qualified column reference or a non-deterministic function in an indexed expression, or a bound parameter, a subquery or a non-deterministic function in the condition, are diagnostics (SQLITE-DEFINITION-LIMITS-001). A string literal written as a term, under parentheses and at most one COLLATE clause, is the name of an indexed column (LiteralColumn, SQLITE-LITERAL-COLUMN-001); a plain string literal term is refused at construction. Indexes are not part of a declaration context: the statement provides no declaration, and whether the index name is free is not a fact. Source: https://sqlite.org/lang_createindex.html, https://sqlite.org/partialindex.html, https://sqlite.org/expridx.html. Status: Implemented.
$semantics = new \SqlSemantics\Platform\Sqlite\Semantics();
$table = $semantics->analyze('CREATE TABLE t (a, b)');
$index = $semantics->analyze('CREATE UNIQUE INDEX i ON t (b DESC) WHERE a IS NOT NULL', [$table]);
[$index->facts->relation($index->statement)->table->table === $table->declarations()[0], $index->facts->scalar($index->statement->terms[0]->expression)->resolution->slot->column === $table->declarations()[0]->columns[1]] // => [true, true]Properties§
public non-empty-list<SortTerm> $termspublic QualifiedName $namepublic Name $tablepublic Scalar|null $where = nullpublic bool $unique = falsepublic bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
public Name $table,
list<SortTerm> $terms,
public Scalar|null $where = null,
public bool $unique = false,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The index name; its schema is the schema of the table |
$table | Name | The indexed table |
$terms | list<SortTerm> | The indexed columns and expressions in order; at least one |
$where | Scalar|null | The condition of a partial index |
$unique | bool | Whether UNIQUE is written |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
Calls 5
- static-call Check::input() line 83
- static-call Check::listOf() line 84
- class-const SortTerm::class() line 84
- method-call KeyTerms::string() line 86
- new KeyTerms line 86
public function indexed(): QualifiedNameAnswers the name of the indexed table with the schema the index name gives it.
Returns
Called from 1
Calls 1
- new QualifiedName line 95
public function deriveStatement(Derivation $derivation): voidResolves the indexed table and derives the indexed expressions and the condition against it.
Parameters
$derivation | Derivation |
Calls 14
- new TableShapes line 103
- method-call Derivation::relation() line 104
- method-call Derivation::environment() line 104
- method-call RelationKinds::refuse() line 105
- new RelationKinds line 105
- class-const KindRefusal::CreateIndex() line 105
- method-call TableShapes::scope() line 106
- new QualifiedName line 106
- method-call TableShapes::implicitOf() line 106
- new Limits line 107
- method-call Derivation::scalar() line 109
- method-call Limits::report() line 110
- class-const DefinitionPosition::IndexExpression() line 110
- class-const DefinitionPosition::PartialIndexWhere() line 114
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the indexed table and derives its row shape.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 3
- method-call TableShapes::target() line 123
- new TableShapes line 123
- method-call CreateIndex::indexed() line 123
public function render(Output $out): voidWrites the definition.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 131
- method-call ObjectNames::write() line 139
- new ObjectNames line 139
- class-const NameUse::Relation() line 140
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
Other tests reaching this symbol 5
KeyTermRuleTest::testIndexTermsWrapAStringUnderAtMostOneCollationcallsSchemaRuleTest::testCommandLowersEachSchemaCommandToItsOwnRequestcallsSchemaRuleTest::testIndexKeepsTheFlagsTheTermsAndTheConditioncallsTableShapesTest::testScopeSeesTheRowIdentifierOnlyAtTheRowPositioncallsLiteralColumnTest::testRenderWritesTheLiteralAsWrittencalls