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

Resolving the indexed table and an indexed columndoctest
$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> $terms
public Name $table
public Scalar|null $where = null
public bool $unique = false
public bool $ifNotExists = false

Methods§

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

$nameQualifiedNameThe index name; its schema is the schema of the table
$tableNameThe indexed table
$termslist<SortTerm>The indexed columns and expressions in order; at least one
$whereScalar|nullThe condition of a partial index
$uniqueboolWhether UNIQUE is written
$ifNotExistsboolWhether IF NOT EXISTS is written
Calls 5
public function indexed(): QualifiedName

Answers the name of the indexed table with the schema the index name gives it.

Called from 1
Calls 1
public function deriveStatement(Derivation $derivation): void
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Resolves the indexed table and derives its row shape.

Parameters

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

Writes the definition.

Parameters

$outOutput
Calls 4

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

Relations§

Instantiated in 1
Type declarations 1