天天看点

PostgreSQL 10.0 preview 性能增强 - 间接索引(secondary index)

postgresql , 10.0 , 间接索引 , 第二索引

我们知道,postgresql的mvcc是多版本来实现的,当更新数据时,产生新的版本。

那么如果新版本不在同一个数据块的时候,索引也要随之变化,当新版本在同一个堆表的块里面时,则发生hot update,不需要变更没有发生值改变的索引。

但是hot总不能覆盖100%的更新,所以还是有索引更新的可能存在。

为了解决这个问题,postgresql 10.0引入了第二索引(间接索引)的概念,即在pk或者uk之上,构建其他索引。

那么只要uk或者pk的值不变,其他索引都不需要变更。

间接索引的好处,不言而喻,可以减少表的dml带来的索引变更。

间接索引的缺陷,通过间接索引查询堆表数据时,需要扫描两个索引(间接索引,以及第一索引),还需要扫描堆表定位数据。

详情

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

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

<a href="https://commitfest.postgresql.org/13/874/">https://commitfest.postgresql.org/13/874/</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>

<a href="https://github.com/digoal/blog/blob/master/201605/20160528_01.md">《深入浅出postgresql b-tree索引结构》</a>

<a href="https://github.com/digoal/blog/blob/master/201606/20160610_01.md">《b-tree和b+tree》</a>

<a href="https://github.com/digoal/blog/blob/master/201607/20160728_01.md">《为postgresql讨说法 - 浅析《uber engineering switched from postgres to mysql》》</a>