PostGresql并行查询

233 阅读1分钟

配置文件

image-20220721140513942开启并行查询后速度反而更慢了 ?

-- 创建表 test_big1
create table test_big1
(
  id          int4,
  name        character varying(32),
  create_time timestamp without time zone default clock_timestamp()
);
​
-- 插入5千万条数据
insert into test_big1(id, name)
select n, n || '_test'
from generate_series(1, 50000000) n;
​
-- 会话级别关闭并行查询
set max_parallel_workers_per_gather = 0;
explain analyze select count(*) from test_big1;
​
-- 会话级别开启并行查询
set max_parallel_workers_per_gather = 2;
explain analyze select count(*) from test_big1;

  • 会话级别关闭并行查询, 如图:

image-20220722100654625

  • 会话级别开启并行查询, 如图:

image-20220722100712635