【问题标题】:Google-Bigquery: Query scans whole table instead of given range in partition tableGoogle-Bigquery:查询扫描整个表而不是分区表中的给定范围
【发布时间】:2018-08-30 12:27:40
【问题描述】:

我有一个包含 5000 万条记录的事实表,名为 AccountLines,按 Posting_Date_New 分区。当我过滤特定分区列上的记录时,我的查询工作正常并且只扫描给定范围之间的有限数据。但是,当我根据 Posting_Date_New 列加入 Dimension 表并在 Financial Year 上进行过滤时,它会扫描整个表。我怎么解决这个问题?我需要将我的事实表与维度表连接起来,并在不扫描整个表的情况下过滤维度表的列。请帮忙。

我的查询如下。

--查询完成(经过 5.542 秒,已处理 244.37 MB)

select ah.ChargeGroup, sum(Amount) Amount from SSIS_STAGING.AccountLine acc
inner join SSIS_STAGING.Dim_Times_BI_Clustering dd on dd.Posting_Date_New = acc.Posting_Date_New
inner join SSIS_STAGING.BranchHierarchy br on br.CostCenterId = acc.BookingBranchID
inner join SSIS_STAGING.Accounts_Hierarchy ah on ah.Account = acc.G_L
where acc.Posting_Date_New between '2018-04-01' and '2019-03-31' and ZoneName = 'BU-North'
group by ah.ChargeGroup

--查询完成(经过 16.530 秒,已处理 5.51 GB)

select ah.ChargeGroup, sum(Amount) Amount from SSIS_STAGING.AccountLine acc
inner join SSIS_STAGING.Dim_Times_BI_Clustering dd on dd.Posting_Date_New = acc.Posting_Date_New
inner join SSIS_STAGING.BranchHierarchy br on br.CostCenterId = acc.BookingBranchID
inner join SSIS_STAGING.Accounts_Hierarchy ah on ah.Account = acc.G_L
where dd.FinancialYear = '2018-19' and ZoneName = 'BU-North'
group by ah.ChargeGroup

【问题讨论】:

  • 您是否尝试过将AND acc.Posting_Date_New between '2018-04-01' and '2019-03-31' 添加到 WHERE 子句中 - 所以您实际上明确说明了仅扫描哪些分区?因为现在 - 您的查询不知道您需要特定的分区!

标签: google-bigquery


【解决方案1】:

prune partitioned table 需要在 where 子句中使用时间戳:

标准SQL

选择 t1.name, t2.类别 从 表 1 t1 内部联接 表2 t2 ON t1.id_field = t2 field2 在哪里 t1.ts = CURRENT_TIMESTAMP()

这被称为BigQuery is performs better with denormalize 数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多