首页 > 解决方案 > 需要在 PostgreSQL 中的外部表上并行追加

问题描述

我们开发了一个基于 postgres_fdw 的 fdw,它在保持数据压缩的大存储库(大数据)中实现搜索。我们正在尝试使用 postgres 分区表的概念,以便我们可以同时在多个分区上并行搜索。对于外部数据包装器,我们需要“并行追加”。

有人知道这是否会在 Postgres 11 中得到解决?

如果我的查询导致在本地分区搜索,postgres 使用并行性,但如果它导致外部扫描,则不会。

本地分区:

explain select * from precio where fecha >= '2017-01-20' and fecha <= '2017-01-21' and plusalesprice < 1

Gather (cost=1000.00..969527.35 rows=81568 width=60)
 Workers Planned: 2
 -> Parallel Append  (cost=0.00..960370.55 rows=33986 width=60)
    -> Parallel Seq Scan on precio_20170121  (cost=0.00..589086.00 rows=19293 width=60)
       Filter: ((fecha >= '2017-01-20'::date) AND (fecha <= '2017-01-21'::date) AND (plusalesprice < '1'::numeric))
    -> Parallel Seq Scan on precio_20170120 (cost=0.00..371114.62 rows=14693 width=60)
       Filter: ((fecha >= '2017-01-20'::date) AND (fecha <= '2017-01-21'::date) AND (plusalesprice < '1'::numeric))

国外分区:

explain select * from precio where fecha >= '2017-01-01' and fecha <= '2017-01-02' and plusalesprice < 1

Append (cost=200.00..2650400.00 rows=20000000 width=60)
 -> Foreign Scan on precio_xdr20170101  (cost=200.00..1275200.00 rows=10000000 width=60)
    Filter: ((fecha >= '2017-01-01'::date) AND (fecha <= '2017-01-02'::date) AND (plusalesprice < '1'::numeric))
 -> Foreign Scan on precio_xdr20170102  (cost=200.00..1275200.00 rows=10000000 width=60)
    Filter: ((fecha >= '2017-01-01'::date) AND (fecha <= '2017-01-02'::date) AND (plusalesprice < '1'::numeric))

PostgreSQL 11 中外部表的并行追加

标签: postgresqlpostgres-fdwpostgresql-11

解决方案


为了能够使用Parallel Append,所有的孩子都需要安全地在并行工作者中运行。 还不能保证安全性(即使从 PostgreSQL 11 开始),因此无法并行扫描postgres_fdw由管理的任何子表。postgres_fdw


推荐阅读