CREATE INDEX

用于创建索引的 SQL 命令

CREATE INDEX 是用于创建索引的 DDL 命令。

CREATE INDEX 一直存在于 PostgreSQL 中。

用法

进度跟踪

PostgreSQL 12 开始,可以通过视图 pg_stat_progress_create_index 来跟踪索引的创建。

变更历史

示例

CREATE INDEX 的基本用法示例

postgres=# CREATE INDEX ON foo (bar_id);
CREATE INDEX

postgres=# \d foo
                Table "public.foo"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           | not null |
 bar_id | integer |           | not null |
Indexes:
    "foo_pkey" PRIMARY KEY, btree (id)
    "foo_bar_id_idx" btree (bar_id)
Foreign-key constraints:
    "foo_bar_id_fkey" FOREIGN KEY (bar_id) REFERENCES bar(id)

分类

DDL, 索引, SQL 命令

另请参阅

ALTER INDEX, DROP INDEX, REINDEX

反馈

提交任何关于“CREATE INDEX”的评论、建议或更正,请点击此处