Postgres-XL 9.5r1.6由一个gtm、一个协调器和两个datanodes组成。
有三个表a、b和c实现了多到多的关系:
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)其他一些人已经碰到了这个问题,并问了here,但没有任何回答或暗示。我只是希望这次这个问题能得到一些启发。
ps:我试图用一种来自a和b的相关行的方式填充这三个表,这两个表形成了表c,它们只来自同一个datanode。但执行时间没有改善。值得注意的另一点是,当where子句(a.name='cf82c96b77b8aa5277da6d55c4e4e66e')中的条件始终为false时,执行时间会下降不到几毫秒。
发布于 2018-07-10 14:19:35
对于此查询:
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)上的索引。分区不会对此查询有所帮助,只有当表非常大时,才应该保留分区。
发布于 2020-03-30 21:26:27
这是由于嵌套循环,将其设置为false。XL将使用散列连接,然后它将快速返回结果。
https://stackoverflow.com/questions/51266342
复制相似问题