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 rows stored in that page are old enough to be visible to all current and future transactions. This information is stored in a bit in the table's visibility map. An index-only scan, after finding a candidate index entry, checks the visibility map bit for the corresponding heap page. If it's set, the row is known visible and so the data can be returned with no further work. If it's not set, the heap entry must be visited to find out whether it's visible, so no performance advantage is gained over a standard index scan
如果 PostgreSQL 知道表中的数据永远不会改变,那么在仅索引扫描中就永远不必访问堆条目。
最佳答案
如果您拥有真正永不更改的数据,请在表上运行 VACUUM (FREEZE)
。如果没有并发的长时间运行的事务,这会将可见性图中的所有 block 标记为“全部卡住”和“全部可见”。然后您将获得仅索引扫描,并且反环绕 autovacuum 无需在表上做任何工作。
关于sql - PostgreSQL - 存储永不改变的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69329566/