redshift交错排序键的顺序是否重要?

时间:2015-12-08 17:34:38

标签: amazon-redshift

where子句是否以指定的顺序指定交错排序键是否重要?我想是的。如果订单很重要,为什么查询计划程序无法自行解决这个问题呢?

1 个答案:

答案 0 :(得分:1)

我认为订单并不重要。

在第34章Comparing Sort Styles"中,我找到了一些有趣的基准。

表格方案:

create table cust_sales_date_interleaved as
(select c_custkey, c_nation, c_region, c_mktsegment, d_date::date, lo_revenue
from customer, lineorder, dwdate
where lo_custkey = c_custkey 
and lo_orderdate = dwdate.d_datekey
and lo_revenue > 0)
interleaved sortkey (c_custkey, c_region, c_mktsegment, d_date);

查询#1

select max(lo_revenue), min(lo_revenue)
from cust_sales_date_interleaved
where c_region = 'ASIA'
and c_mktsegment = 'FURNITURE';

查询#2

select max(lo_revenue), min(lo_revenue)
from cust_sales_date_interleaved
where d_date between '01/01/1996' and '01/14/1996'
and c_mktsegment = 'FURNITURE'
and c_region = 'ASIA';

我们有结果

查询#1 - 1.46 s

查询#2 - 0.80 s

查询#2更快,因为它有d_date的额外过滤器。