classCreateIndex
final class CreateIndex
implements SchemaElement, Relation
uses Snapshot
@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.
$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> $elementspublic list<IndexElement> $includedpublic list<Definition> $optionspublic Name|null $namepublic RelationReference $tablepublic bool $unique = falsepublic bool $concurrently = falsepublic bool $ifNotExists = falsepublic Name|null $method = nullpublic bool|null $nullsDistinct = nullpublic Name|null $tablespace = nullpublic Scalar|null $where = nullMethods§
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
$name | Name|null | The index name; required with IF NOT EXISTS |
$table | RelationReference | The indexed table |
$elements | list<IndexElement> | The keys; at least one |
$unique | bool | Whether UNIQUE is written |
$concurrently | bool | Whether CONCURRENTLY is written |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
$method | Name|null | The access method |
$included | list<IndexElement> | The included columns |
$nullsDistinct | bool|null | True for NULLS DISTINCT, false for NULLS NOT DISTINCT, null when not written |
$options | list<Definition> | The storage parameters |
$tablespace | Name|null | The tablespace |
$where | Scalar|null | The predicate of a partial index |
Calls 4
- static-call Check::listOf() line 87
- class-const IndexElement::class() line 87
- class-const Definition::class() line 89
- static-call Check::input() line 90
public function deriveStatement(Derivation $derivation): voidResolves the table and derives the keys and the predicate against it.
Parameters
$derivation | Derivation |
Calls 2
- method-call Indexes::derive() line 106
- new Indexes line 106
public function deriveElement(Derivation $derivation, Name $schema): voidDerives the statement inside CREATE SCHEMA: an unqualified table is in that schema.
Parameters
$derivation | Derivation | |
$schema | Name |
Calls 2
- method-call Indexes::derive() line 114
- new Indexes line 114
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactResolves the indexed table as written and answers its facts.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 2
- method-call Targets::resolve() line 122
- new Targets line 122
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
CreateIndexTest::testCreatedSchemaIsTheSchemaOfTheTablecallsCreateIndexTest::testDeriveElementLocatesTheTableInTheSchemacallsCreateIndexTest::testDeriveRelationResolvesTheTableAsWrittencallsCreateIndexTest::testDeriveStatementResolvesTheTablecallsCreateIndexTest::testRefusesIfNotExistsWithoutANamecalls
Relations§
Instantiated in 1
Constant reads 1
Type declarations 3
- type SqlSemantics\Platform\PostgreSql\Lowering\Table\IndexRule packages/sql-semantics-postgres/src/Lowering/Table/IndexRule.php:47
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Indexes packages/sql-semantics-postgres/src/Rules/Table/Definition/Indexes.php:40
- type SqlSemantics\Platform\PostgreSql\Rules\Table\Definition\Indexes packages/sql-semantics-postgres/src/Rules/Table/Definition/Indexes.php:70