final class CreateIndex
    implements SchemaElement, Relation
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create an index.

Mirrors PostgreSQL's IndexStmt (unique, concurrent, if_not_exists, idxname, relation, accessMethod, indexParams, indexIncludingParams, nulls_not_distinct, options, tableSpace, whereClause). Rule PG-INDEX-001: the indexed table is resolved (PG-TABLE-TARGET-001) and is the relation fact of the statement; the keys, the included columns and the predicate are derived where that table is the only visible relation, the predicate as a condition (PG-TABLE-CONDITION-001). An index declares nothing a query can read. Source: https://www.postgresql.org/docs/17/sql-createindex.html.

Reading an indexdoctest
$index = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS i ON ONLY t USING btree (a) INCLUDE (b) NULLS NOT DISTINCT WITH (fillfactor = 70) TABLESPACE x WHERE a > 0');
    [$index->statement->unique, $index->statement->table->only, $index->toString()] // => [true, true, 'CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS i ON ONLY t USING btree (a) INCLUDE (b) NULLS NOT DISTINCT WITH (fillfactor = 70) TABLESPACE x WHERE a > 0']

Properties§

public non-empty-list<IndexElement> $elements
public list<IndexElement> $included
public list<Definition> $options
public Name|null $name
public bool $unique = false
public bool $concurrently = false
public bool $ifNotExists = false
public Name|null $method = null
public bool|null $nullsDistinct = null
public Name|null $tablespace = null
public Scalar|null $where = null

Methods§

public function __construct(
    public Name|null $name,
    public RelationReference $table,
    list<IndexElement> $elements,
    public bool $unique = false,
    public bool $concurrently = false,
    public bool $ifNotExists = false,
    public Name|null $method = null,
    list<IndexElement> $included = [],
    public bool|null $nullsDistinct = null,
    list<Definition> $options = [],
    public Name|null $tablespace = null,
    public Scalar|null $where = null,
)

Parameters

$nameName|nullThe index name; required with IF NOT EXISTS
$tableRelationReferenceThe indexed table
$elementslist<IndexElement>The keys; at least one
$uniqueboolWhether UNIQUE is written
$concurrentlyboolWhether CONCURRENTLY is written
$ifNotExistsboolWhether IF NOT EXISTS is written
$methodName|nullThe access method
$includedlist<IndexElement>The included columns
$nullsDistinctbool|nullTrue for NULLS DISTINCT, false for NULLS NOT DISTINCT, null when not written
$optionslist<Definition>The storage parameters
$tablespaceName|nullThe tablespace
$whereScalar|nullThe predicate of a partial index
Calls 4
public function createdSchema(): ?Name

Answers the schema written on the indexed table.

Returns

public function deriveStatement(Derivation $derivation): void

Resolves the table and derives the keys and the predicate against it.

Parameters

$derivationDerivation
Calls 2
public function deriveElement(Derivation $derivation, Name $schema): void

Derives the statement inside CREATE SCHEMA: an unqualified table is in that schema.

Parameters

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

Resolves the indexed table as written and answers its facts.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 2

Test cases 9§

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

Dedicated tests 5
Other tests reaching this symbol 4

Relations§

Instantiated in 1
Constant reads 1
Type declarations 3