比较AntDB Cluster Plan与PGXC Remote Query Plan的区别
AntDB 3.1版本引入Cluster Plan,区别于原PGXC的执行计划,通过Reduce Plan支持数据的实时动态分布,将原本PGXC无法下沉到Datanode执行的执行计划做了优化,使得执行计划的执行压力分散到各个Datanode节点,一方面减轻Coordinator节点的性能压力,另一方面提高了SQL的执行效率。
鉴于表的实际情况,Cluster Plan不一定是最优的执行计划,本文仅列举部分用例以示Cluster Plan与Remote Query Plan的区别
select从句、agg
SQL
SELECT unique2
, (
SELECT COUNT(1)
FROM onek
WHERE odd > 10
) AS cnt
FROM tenk1;
Cluster Plan
QUERY PLAN
--------------------------------------------------------------------------------------------
Cluster Gather (cost=974.46..4089.21 rows=10000 width=12)
Plan id: 0
-> Seq Scan on tenk1 (cost=0.00..114.75 rows=2500 width=12)
Plan id: 1
InitPlan 1 (returns $0)
-> Cluster Reduce (cost=10.25..11.76 rows=1 width=8)
Plan id: 2
-> Finalize Aggregate (cost=18.51..18.52 rows=1 width=8)
Plan id: 3
-> Cluster Reduce (cost=17.89..18.50 rows=4 width=8)
Plan id: 4
-> Partial Aggregate (cost=21.11..21.12 rows=1 width=8)
Plan id: 5
-> Seq Scan on onek (cost=0.00..20.88 rows=95 width=0)
Plan id: 6
Filter: (odd > 10)
(16 rows)
Remote Query Plan
QUERY PLAN
-----------------------------------------------------------------------------------------------------
Result (cost=974.46..10433.46 rows=10000 width=12)
Plan id: 0
InitPlan 1 (returns $0)
-> Aggregate (cost=974.45..974.46 rows=1 width=8)
Plan id: 2
-> Data Node Scan on onek "_REMOTE_TABLE_QUERY__1" (cost=0.00..973.50 rows=379 width=0)
Plan id: 3
Node/s: dn1, dn2, dn3, dn4
-> Data Node Scan on tenk1 "_REMOTE_TABLE_QUERY_" (cost=0.00..9359.00 rows=10000 width=4)
Plan id: 1
Node/s: dn1, dn2, dn3, dn4
(11 rows)
select从句、agg、not in
SQL
SELECT unique2
, (
SELECT COUNT(1)
FROM onek
WHERE odd > 10
) AS cnt
FROM tenk1
WHERE even NOT IN (
SELECT COUNT(1)
FROM tenk2
WHERE even < 100
);
Cluster Plan
QUERY PLAN
--------------------------------------------------------------------------------------------
Cluster Gather (cost=975.64..7458.39 rows=20000 width=12)
Plan id: 0
-> Seq Scan on tenk1 (cost=1.18..483.93 rows=5000 width=12)
Plan id: 1
Filter: (NOT (hashed SubPlan 2))
InitPlan 1 (returns $0)
-> Cluster Reduce (cost=10.25..11.76 rows=1 width=8)
Plan id: 2
-> Finalize Aggregate (cost=18.51..18.52 rows=1 width=8)
Plan id: 3
-> Cluster Reduce (cost=17.89..18.50 rows=4 width=8)
Plan id: 4
-> Partial Aggregate (cost=21.11..21.12 rows=1 width=8)
Plan id: 5
-> Seq Scan on onek (cost=0.00..20.88 rows=95 width=0)
Plan id: 6
Filter: (odd > 10)
SubPlan 2
-> Cluster Reduce (cost=3.21..4.71 rows=1 width=