我试图通过限制连接前的第一个表的大小来加快查询速度。
原始代码似乎需要花费很长时间才能运行
bash
我在下面加入之前尝试限制日期,但是我得到vouchers.f表不存在。我可以做什么?
SELECT
f.store_id,
f.promotion_sku,
dt.calendar_month_end,
SUM(redemption_voucher_count),
SUM(redemption_voucher_value),
SUM(redemption_customer_is_new),
pt.promotion_super_type
FROM
(((vouchers.redemptions f
INNER JOIN retail.stores rs ON f.store_id = rs.store_id)
INNER JOIN vouchers.promotions p ON p.promotion_sku = f.promotion_sku
AND p.country_id = rs.country_id)
INNER JOIN vouchers.promotion_types pt ON pt.promotion_type_id = p.promotion_type_id),
retail_analysis.date_d dt
WHERE
f.date_id >= 20181201
AND f.date_id <= 20190131
AND TRUE
AND redemption_date = dt.date_full
AND f.store_id IS NOT NULL
AND f.promotion_sku IS NOT NULL
GROUP BY f.store_id , f.promotion_sku , dt.calendar_month_end , pt.promotion_super_type