天天看點

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>

繼續閱讀