Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon redshift 即使使用排序键也可以在红移表上扫描表_Amazon Redshift - Fatal编程技术网

Amazon redshift 即使使用排序键也可以在红移表上扫描表

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

我们有一个红移的大表,在那里我们存储我们的AWS账单文件并查询它们。我们使用交错排序键,因为并非所有查询都具有所有过滤器

运行此查询

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)。看起来很合理。对,我们的理解是,若列被指定为排序键,那个么就并没有表扫描,范围限制扫描是有意义的。谢谢