Redshift Spectrum 如何扫描数据?
How Redshift Spectrum scans data?
给定 S3 上由时间戳字段分区的 1.4 TB Parquet 数据的数据源(因此分区为 year
- month
- day
)我正在查询特定的天的数据(2.6 GB 的数据)并使用以下查询通过 Redshift Spectrum 检索 Parquet 文件中的所有可用字段:
SELECT *
FROM my_external_schema.my_external_table
WHERE year = '2020' and month = '01' and day = '01'
table 可通过 Glue Crawler that points at the top level "folder" in S3; this creates a Database and then via this command I link the Database to the new external schema:
create external schema my_external_schema from data catalog
database 'my_external_schema'
iam_role 'arn:aws:iam::123456789:role/my_role'
region 'my-region-9';
分析我的 IDE 中的 table 我可以看到 table 是由以下语句生成的:
create external table my_external_schema.my_external_table
(
id string,
my_value string,
my_nice_value string
)
partitioned by (year string, month string, day string)
row format serde 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
with serdeproperties ('serialization.format'='1')
stored as
inputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
location 's3://my-bucket/my/location/'
table properties ('CrawlerSchemaDeserializerVersion'='1.0', 'CrawlerSchemaSerializerVersion'='1.0', 'UPDATED_BY_CRAWLER'='my_crawler');
当我分析来自 Redshift 的查询时,我发现它被扫描了 ~86 GB 的数据。
这怎么可能?这是一个问题,因为 Redshift 根据扫描的数据量计费,看起来服务正在扫描该分区中实际数据量的 40 倍左右。
我也尝试在 Athena 中执行相同的查询,但我只扫描了 2.55 GB 的数据(绝对更合理)。
我无法提供有关集群大小的太多详细信息,但假设这 86GB 的扫描数据适合集群的内存。
问题似乎出在 AWS Redshift 控制台中。
如果我们从 Redshift 控制台中的“查询详细信息”分析查询,我可以看到“扫描的总数据”报告 86GB。正如 Vzarr 提到的,我 运行 在 Athena 上使用相同的查询来比较性能。执行时间基本相同,但扫描的数据量完全不同:2.55GB。
我在使用和不使用分区列的情况下,与 S3 外部架构上的其他查询进行了相同的比较:我发现每次测试中扫描的 GB 总量不同,有时差异很大(Redshift Spectrum 中为 320MB,在 Redshift Spectrum 中为 20GB雅典娜).
我决定查看 Redshift 中的系统 tables 以了解外部架构上的查询是如何工作的。我使用 SVL_S3QUERY:
做了一个非常简单的测试
SELECT (cast(s3_scanned_bytes as double precision) / 1024 / 1024 / 1024) as gb_scanned,
s3_scanned_rows,
query
FROM SVL_S3QUERY
WHERE query = '<my-query-id>'
结果与 AWS Redshift 控制台针对同一查询所说的完全不同。不仅 gb_scanned
是错误的,而且 s3_scanned_rows
也是错误的。查询returns一共扫描了2.55GB的数据,和Athena说的一模一样
为了确认 SVL_S3QUERY 中的数字,我使用 AWS Cost Explorer 仔细检查了一天内扫描的 gb 总量以及我们为 Redshift Spectrum 支付的费用:数字基本相同。
此时,我不知道 AWS Redshift 控制台从哪里或哪个 table 获取查询详细信息,但它们似乎是完全错误的。
给定 S3 上由时间戳字段分区的 1.4 TB Parquet 数据的数据源(因此分区为 year
- month
- day
)我正在查询特定的天的数据(2.6 GB 的数据)并使用以下查询通过 Redshift Spectrum 检索 Parquet 文件中的所有可用字段:
SELECT *
FROM my_external_schema.my_external_table
WHERE year = '2020' and month = '01' and day = '01'
table 可通过 Glue Crawler that points at the top level "folder" in S3; this creates a Database and then via this command I link the Database to the new external schema:
create external schema my_external_schema from data catalog
database 'my_external_schema'
iam_role 'arn:aws:iam::123456789:role/my_role'
region 'my-region-9';
分析我的 IDE 中的 table 我可以看到 table 是由以下语句生成的:
create external table my_external_schema.my_external_table
(
id string,
my_value string,
my_nice_value string
)
partitioned by (year string, month string, day string)
row format serde 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
with serdeproperties ('serialization.format'='1')
stored as
inputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
location 's3://my-bucket/my/location/'
table properties ('CrawlerSchemaDeserializerVersion'='1.0', 'CrawlerSchemaSerializerVersion'='1.0', 'UPDATED_BY_CRAWLER'='my_crawler');
当我分析来自 Redshift 的查询时,我发现它被扫描了 ~86 GB 的数据。
这怎么可能?这是一个问题,因为 Redshift 根据扫描的数据量计费,看起来服务正在扫描该分区中实际数据量的 40 倍左右。
我也尝试在 Athena 中执行相同的查询,但我只扫描了 2.55 GB 的数据(绝对更合理)。
我无法提供有关集群大小的太多详细信息,但假设这 86GB 的扫描数据适合集群的内存。
问题似乎出在 AWS Redshift 控制台中。
如果我们从 Redshift 控制台中的“查询详细信息”分析查询,我可以看到“扫描的总数据”报告 86GB。正如 Vzarr 提到的,我 运行 在 Athena 上使用相同的查询来比较性能。执行时间基本相同,但扫描的数据量完全不同:2.55GB。
我在使用和不使用分区列的情况下,与 S3 外部架构上的其他查询进行了相同的比较:我发现每次测试中扫描的 GB 总量不同,有时差异很大(Redshift Spectrum 中为 320MB,在 Redshift Spectrum 中为 20GB雅典娜).
我决定查看 Redshift 中的系统 tables 以了解外部架构上的查询是如何工作的。我使用 SVL_S3QUERY:
做了一个非常简单的测试SELECT (cast(s3_scanned_bytes as double precision) / 1024 / 1024 / 1024) as gb_scanned,
s3_scanned_rows,
query
FROM SVL_S3QUERY
WHERE query = '<my-query-id>'
结果与 AWS Redshift 控制台针对同一查询所说的完全不同。不仅 gb_scanned
是错误的,而且 s3_scanned_rows
也是错误的。查询returns一共扫描了2.55GB的数据,和Athena说的一模一样
为了确认 SVL_S3QUERY 中的数字,我使用 AWS Cost Explorer 仔细检查了一天内扫描的 gb 总量以及我们为 Redshift Spectrum 支付的费用:数字基本相同。
此时,我不知道 AWS Redshift 控制台从哪里或哪个 table 获取查询详细信息,但它们似乎是完全错误的。