gpt4 book ai didi

sql - PostgreSQL - 存储永不改变的数据

转载 作者:行者123 更新时间:2023-12-02 01:58:17 25 4
gpt4 key购买 nike

PostgreSQL 有没有办法将一个表标记为存储插入后永远不会改变的数据,从而提高性能?这可能有所帮助的一个例子是 Index-Only Scans and Covering Indexes :

However, for seldom-changing data there is a way around this problem.PostgreSQL tracks, for each page in a table's heap, whether all rowsstored in that page are old enough to be visible to all current andfuture transactions. This information is stored in a bit in thetable's visibility map. An index-only scan, after finding a candidateindex entry, checks the visibility map bit for the corresponding heappage. If it's set, the row is known visible and so the data can bereturned with no further work. If it's not set, the heap entry must bevisited to find out whether it's visible, so no performance advantageis gained over a standard index scan

如果 PostgreSQL 知道表中的数据永远不会改变,那么在仅索引扫描中就永远不必访问堆条目。

最佳答案

如果您拥有真正永不更改的数据,请在表上运行 VACUUM (FREEZE)。如果没有并发的长时间运行的事务,这会将可见性图中的所有 block 标记为“全部卡住”和“全部可见”。然后您将获得仅索引扫描,并且反环绕 autovacuum 无需在表上做任何工作。

关于sql - PostgreSQL - 存储永不改变的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69329566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com