天天看点

PostgreSQL 10.0 preview 功能增强 - 两段式索引(约束字段+附加字段)

postgresql , 10.0 , 约束覆盖索引

如果我们有这样的查询

select * from tbl where c1=? and c2=? and c3=? and c4=?

我们建立了复合索引达到最好的查询性能

create index idx on tbl(c1,c2,c3,c4);

同时还有这样的约束

create unique index idx on tbl (c1,c2);

那么这样的场景中,我们就有两个索引。

postgresql 10.0提供了一个新的功能,可以将这两个索引合并,只有一个索引的体积,同时支持这两个场景。。

create unique index idx on tbl (c1,c2) including (c3,c4);

这便是唯一约束+附加字段组合功能索引

详见

这个patch的讨论,详见邮件组,本文末尾url。

postgresql社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以postgresql的稳定性也是远近闻名的。

<a href="https://commitfest.postgresql.org/13/961/">https://commitfest.postgresql.org/13/961/</a>

<a href="https://www.postgresql.org/message-id/flat/[email protected]#[email protected]">https://www.postgresql.org/message-id/flat/[email protected]#[email protected]</a>