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

标签 sql postgresql

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/

相关文章:

postgresql - 使用 SSH 堡垒将 dbt 连接到 Postgres

java - 使用 Ant 进行 JDBC COPY

ruby-on-rails - PG::InsufficientPrivilege: 错误:创建数据库 Ruby on Rails 应用程序的权限被拒绝

SQL Server 2008 : sp_RENAME table disappeared

c# - 只选择一个时间间隔内的第一条记录

mysql - 我需要在我的 sql 请求中添加一个选项 "where"

postgresql - PostgreSQL 哈希索引的时间复杂度是多少?

sql - 将 Postgres 上的查询更改为仅使用标准 SQL 子句

sql - 如何将sql查询结果转换为csv格式

php - 从 ip2location_db11 数据库中查找 ip