我将我的 postgresql 从 9.5 升级到 9.6,以便使用并行执行来提高我的性能。但是,我没有成功使用它。在我的主数据库中,几乎所有的选择看起来都像:外表
select * from foreign_table
是一个位于 oracle 数据库上的外表。有些表是 10G+ 和 1,000,000+ 条记录,因此在这种选择情况下,并行查询应该对我有很大帮助。
我配置的参数:
min_parallel_relation_size = 200MB
max_parallel_workers_per_gather = 2
max_worker_processes = 8
当我尝试从她的大小为 1.5G 并且有 5,000,000 条记录的大表中使用解释分析选择 * 时,我只看到外部扫描:
Foreign Scan on customer_prod (cost=10000.00..20000.00 rows=1000
width=2438) (actual time=6.337..231408.085 rows=5770616 loops
=1)
Oracle query: ......
Planning time: 2.827 ms
Execution time: 232198.137 ms
*我还尝试了 select * from foreign_table where 1=1 但仍然是相同的结果。
另一方面,下一个代码有效:
postgres=# CREATE TABLE people_mariel_test (id int PRIMARY KEY NOT NULL, age int NOT NULL);
CREATE TABLE
postgres=# INSERT INTO people_mariel_test SELECT id, (random()*100)::integer AS age FROM generate_series(1,10000000) AS id;
INSERT 0 10000000
postgres=# explain analyze select * from people_mariel_test where age=6;
QUERY PLAN
--------------------------------------------------------------------------------
------------------------------------------------
----------
Gather (cost=1000.00..123777.76 rows=50000 width=8) (actual time=0.239..771.801 rows=99409 loops=1)
Workers Planned: 1
Workers Launched: 1
-> Parallel Seq Scan on people_mariel_test (cost=0.00..117777.76 rows=29412 width=8) (actual time=0.045..748.213 rows=49704
loops=2)
Filter: (age = 6)
Rows Removed by Filter: 4950296
Planning time: 0.261 ms
Execution time: 785.924 ms
(8 rows)
知道如何继续吗?