【发布时间】:2021-09-15 09:31:00
【问题描述】:
我正在为我的公司建立一个粗略的数据仓库,并且我已成功地将联系人、公司、交易和关联数据从我们的 CRM 提取到 bigquery 中,但是当我将这些数据合并到一个主表中以通过我们的 BI 进行分析时平台,我不断收到错误:
Query exceeded resource limits. This query used 22602 CPU seconds but would charge only 40M Analysis bytes. This exceeds the ratio supported by the on-demand pricing model. Please consider moving this workload to the flat-rate reservation pricing model, which does not have this limit. 22602 CPU seconds were used, and this query must use less than 10200 CPU seconds.
因此,我希望优化我的查询。我已经删除了所有GROUP BY 和ORDER BY 命令,并尝试使用WHERE 命令进行额外过滤,但这对我来说似乎不合逻辑,因为它会增加处理需求。
我目前的查询是:
SELECT
coy.company_id,
cont.contact_id,
deals.deal_id,
{another 52 fields}
FROM `{contacts}` AS cont
LEFT JOIN `{assoc-contact}` AS ac
ON cont.contact_id = ac.to_id
LEFT JOIN `{companies}` AS coy
ON CAST(ac.from_id AS int64) = coy.company_id
LEFT JOIN `{assoc-deal}` AS ad
ON coy.company_id = CAST(ad.from_id AS int64)
LEFT JOIN `{deals}` AS deals
ON ad.to_id = deals.deal_id;
仅供参考 {assoc-contact} 和 {assoc-deal} 都是我从关联表创建的单独视图,以便更轻松地将这些表关联到公司表。
还应注意,此查询偶尔会成功运行,所以我知道它确实有效,但由于查询太大,大约 90% 的时间它都会失败。
【问题讨论】:
-
尝试优化您的查询,如果您认为优化得很好,您需要让您的项目管理员为您的大查询配置添加更多槽
标签: sql google-bigquery query-optimization etl