【发布时间】:2016-03-01 21:46:25
【问题描述】:
我注意到下面的查询运行缓慢,在详细查看后,我想知道为什么 Redshift 首先分别扫描两个表(事件和联系人),然后将它们连接在一起。联系人表中有超过 300,000 行。 我的期望是 Redshift 应该首先根据为其指定的过滤器扫描大型事件表,然后根据 Contact_IDs 列在其中查找联系人。我的期望不正确吗?我还能做些什么来加快查询速度吗?我对所有表执行了清理和分析。
查询:
select c.Segment
, Count (Distinct (CASE WHEN et.Event_ID = 1 THEN et.Contact_ID ELSE null END)) as L1
, Count (Distinct (CASE WHEN et.Event_ID = 2 THEN et.Contact_ID ELSE null END)) as L2
from
Events et
jon contact c on c.Account_ID = et.Account_ID and c.ID = et.Contact_ID
where
et.Account_ID = 5
and et.Event_ID in (1, 2)
and et.IsGuest = 0
and et.dim_date_id >=20151125
and et.dim_date_id <=20160226
group by c.Segment
order by 1
解释:
XN Merge (cost=1000000074927.82..1000000074927.83 rows=1 width=20)
-> XN Network (cost=1000000074927.82..1000000074927.83 rows=1 width=20)
-> XN Sort (cost=1000000074927.82..1000000074927.83 rows=1 width=20)
-> XN HashAggregate (cost=74927.80..74927.81 rows=1 width=20)
-> XN Merge Join DS_DIST_NONE (cost=0.00..74927.57 rows=31 width=20)
-> XN Seq Scan on contact c (cost=0.00..497.56 rows=39805 width=16)
-> XN Seq Scan on eventtransaction et (cost=0.00..6664.84 rows=136 width=20)
【问题讨论】:
-
@ConsiderMe 。 . . Redshift 不支持索引。它使用柱状存储。
-
很高兴知道,谢谢
标签: sql amazon-redshift