0

我有一个相当大的 postgres 表,有几十亿行。

但是,该表可以按一列 ( type)分区

我们应该更喜欢:

具有两列的索引

create nonclustered index ix_index1 on table1(type, string_urn_id)

或条件索引

create nonclustered index ix_index1_alternative on table1(string_urn_id) WHERE type = 'type1'
create nonclustered index ix_index1_alternative2 on table1(string_urn_id) WHERE type = 'type2'
create nonclustered index ix_index1_alternative3 on table1(string_urn_id) WHERE type = 'type3'
....
4

1 回答 1

1

PostgreSQL中没有声明create nonclustered index

什么更好取决于“更好”的定义。从维护的角度来看,单一索引更好,因为您不必在每次添加新的type.

从性能的角度来看,只有具有真实数据的基准才能判断。计划时间会随着索引的增加而增加,但查询性能可能会好一些。

如果对表进行分区,查询性能会降低,但您可以在string_urn_id.

于 2021-10-27T07:02:43.340 回答