Amazon redshift 即使使用排序键也可以在红移表上扫描表
我们有一个红移的大表,在那里我们存储我们的AWS账单文件并查询它们。我们使用交错排序键,因为并非所有查询都具有所有过滤器 运行此查询Amazon redshift 即使使用排序键也可以在红移表上扫描表,amazon-redshift,Amazon Redshift,我们有一个红移的大表,在那里我们存储我们的AWS账单文件并查询它们。我们使用交错排序键,因为并非所有查询都具有所有过滤器 运行此查询 select "column", type, encoding, distkey, sortkey, "notnull" from pg_table_def where tablename = 'accountbillingflat' and sortkey <> 0 order by sortkey; 查询执行的计划是 XN Merge (c
select "column", type, encoding, distkey, sortkey, "notnull"
from pg_table_def
where tablename = 'accountbillingflat'
and sortkey <> 0
order by sortkey;
查询执行的计划是
XN Merge (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN Network (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN Sort (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN HashAggregate (cost=2059217.08..2059217.08 rows=445 width=44)
-> XN Seq Scan on accountbillingflat (cost=0.00..2045174.64 rows=1404244 width=44)
实际执行是
XN Merge (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN Network (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN Sort (cost=1000002059236.65..1000002059237.77 rows=445 width=44)
-> XN HashAggregate (cost=2059217.08..2059217.08 rows=445 width=44)
-> XN Seq Scan on accountbillingflat (cost=0.00..2045174.64 rows=1404244 width=44)
看看我们看到的顺序扫描的细节
这很奇怪,因为linkedaccountid和billingmonth都是排序键。你能澄清什么是奇怪的吗?排序键触发范围限制扫描(check),group by导致本地哈希聚合,因为linkedaccountid是dist键(check),order by导致全局合并排序,因为排序键跨片(check)。看起来很合理。对,我们的理解是,若列被指定为排序键,那个么就并没有表扫描,范围限制扫描是有意义的。谢谢