0

Postgres-XL 9.5r1.6 由一个 gtm、一个协调器和两个数据节点组成。

共有三个表a,它们实现bc多对多关系:

create table a(id int, name text, uid int) distribute by hash(uid);
create table b(id int, name text, uid int) distribute by hash(uid);
create table c(id int, aname text, bname text, uid int) distribute by hash(uid);

协调器上运行以下查询时,它需要莫名其妙的20000 毫秒时间!但在任一数据节点上,执行时间几乎不超过20 毫秒

select a.name, b.name

from 
       a left join c
       on a.name=c.aname

          left join b
          on c.bname=b.name
where
       a.name='cf82c96b77b8aa5277da6d55c4e4e66e';

解释协调员计划:

Remote Subquery Scan on all (dn_1,dn_2)  (cost=8.33..17.78 rows=1 width=66)


 ->  Nested Loop Left Join  (cost=8.33..17.78 rows=1 width=66)
         Join Filter: ((a.name)::text = (c.aname)::text)
         ->  Remote Subquery Scan on all (dn_1,dn_2)  (cost=100.15..108.21 rows=1 width=33)
               Distribute results by H: name
               ->  Index Only Scan using code_idx on a  (cost=0.15..8.17 rows=1 width=33)
                     Index Cond: (name = 'cf82c96b77b8aa5277da6d55c4e4e66e'::text)
         ->  Materialize  (cost=108.18..109.72 rows=1 width=115)
               ->  Remote Subquery Scan on all (dn_1,dn_2)  (cost=108.18..109.72 rows=1 width=115)
                     Distribute results by H: aname
                     ->  Hash Right Join  (cost=8.18..9.60 rows=1 width=115)
                           Hash Cond: ((b.name)::text = (c.bname)::text)
                           ->  Remote Subquery Scan on all (dn_1,dn_2)  (cost=100.00..102.44 rows=30 width=33)
                                 Distribute results by H: name
                                 ->  Seq Scan on b  (cost=0.00..1.30 rows=30 width=33)
                           ->  Hash  (cost=108.41..108.41 rows=1 width=244)
                                 ->  Remote Subquery Scan on all (dn_1,dn_2)  (cost=100.15..108.41 rows=1 width=244)
                                       Distribute results by H: bname
                                       ->  Index Only Scan using code_idxcfc on c  (cost=0.15..8.17 rows=1 width=244)
                                             Index Cond: (aname = 'cf82c96b77b8aa5277da6d55c4e4e66e'::text)

其他一些人已经遇到了这个问题并在这里问但没有答案或提示。我只是希望这次这个问题能得到一些见解。

aps:我尝试以相关行来自和b表单表c仅来自同一个数据节点的方式填充三个表。但执行时间没有改善。另一点值得注意的是,当where子句(a.name='cf82c96b77b8aa5277da6d55c4e4e66e')中的条件总是为假时,执行时间会下降到不到几毫秒。

4

2 回答 2

0

对于此查询:

select a.name, b.name
from a left join
     c
     on a.name = c.aname left join
     b
     on c.bname = b.name
where a.name = 'cf82c96b77b8aa5277da6d55c4e4e66e';

a(name)您需要、b(name)和上的索引c(name)。你的分区不会帮助这个查询,你应该只在表很大时才保留它们。

于 2018-07-10T14:19:35.097 回答
0

这是由于嵌套循环,将其设置为 false。XL 将使用哈希连接,然后它会快速返回结果

于 2020-03-30T21:26:27.840 回答