首页 > 解决方案 > Google-Bigquery:查询扫描整个表而不是分区表中的给定范围

问题描述

我有一个事实表,其中包含 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

标签: google-bigquery

解决方案


修剪分区表,您需要在 where 子句中使用时间戳:

标准SQL

SELECT t1.name, t2.category FROM table1 t1 INNER JOIN table2 t2 ON t1.id_field = t2 field2 WHERE t1.ts = CURRENT_TIMESTAMP()

据说BigQuery 在非规范化数据方面表现更好。


推荐阅读