小编Kar*_*son的帖子

PostgrSQL 中大表的预缓​​存索引

我有一个包含大约 1000 万行的表,其中包含一个主键和一个定义在其上的索引:

create table test.test_table(
    date_info date not null,
    string_data varchar(64) not null,
    data bigint
    primary key(date_info, string_data));
    create index test_table_idx 
    on test.test_table(string_data);
Run Code Online (Sandbox Code Playgroud)

我有一个使用了的查询test_table_idx

select distinct date_info from test.test_table where string_data = 'some_val';
Run Code Online (Sandbox Code Playgroud)

问题是第一次运行查询最多可能需要 20 秒,而在任何后续运行中都需要 < 2 秒。

有没有办法将整个索引加载到内存中,而不是在第一次访问时获取数据库加载信息?

postgresql index cache postgresql-12

4
推荐指数
1
解决办法
425
查看次数

标签 统计

cache ×1

index ×1

postgresql ×1

postgresql-12 ×1