我在以下查询中遇到了一些性能问题,它需要花费1小时58分钟才能运行10分钟(没有最后一次加入)...是否有更好的加入方式?
SELECT A.day_est,A.campaign_name,A.campaign_start,A.campaign_end,A.PID,A.placement_name,A.imp,A.imp_d,A.clk,A.clk_d, IFNULL(A.ads_cost+C.ads_cost,IFNULL(A.ads_cost,C.ads_cost)) as adserve_cost, COALESCE(E.est_spend,IFNULL(A.est_spend+C.est_spend,IFNULL(A.est_spend,C.est_spend)) ) as est_spend, (A.ads_cost + C.ads_cost + A.est_spend+C.est_spend) as total_est_spend, (B.PC_total + B.PV_total) as total_conversions, B.PC_total, B.PV_Total,B.uniq_AG_apps_appnid,D.external_id,B.C1_Matched,B.C1_Approved,B.GHR_TOTAL, B.GHR_PV
FROM (SELECT day_est, PID,AID,campaign_name, placement_name,campaign_start,campaign_end,SUM(impressions) as imp, SUM(impressions_dropped) as imp_d,
SUM(clicks) as clk, SUM(clicks_dropped) as clk_d, SUM(adserving_cost) as ads_cost, SUM(estimated_spend) as est_spend
FROM weekly_table
WHERE source='delivery'
GROUP BY 1,2,3 ) as A LEFT JOIN
(SELECT conv_day_est, PID,AID, SUM(postview_total) as PV_total, SUM(postclick_total) as PC_total, SUM(postview_approval) as PV_approval,SUM(postclick_approval_aml) PC_approval,Count(Distinct appn_id) As uniq_AG_apps_appnid, SUM(appn_id_match) as C1_Matched,SUM(approval_flag) as C1_Approved, COUNT(IF(product_name='GHR',appn_id,NULL)) as GHR_TOTAL, SUM(IF(product_name='GHR',product_pv,0)) as GHR_PV
FROM weekly_table
WHERE source='attribution'
GROUP BY 1,2,3) as B on A.day_est=B.conv_day_est AND A.PID=B.PID AND A.AID=B.AID
LEFT JOIN
(SELECT day_est,PID,AID,SUM(adserving_cost) as ads_cost, SUM(estimated_spend) as est_spend
FROM weekly_table
WHERE source='attribution'
GROUP BY 1,2,3 ) as C on A.day_est=C.day_est AND A.PID=C.PID AND A.AID=C.AID
LEFT JOIN
(SELECT PID,AID,external_id
FROM map_external_id
) as D on A.PID=D.PID AND A.AID=D.AID
LEFT JOIN
(SELECT day_est,PID,AID, SUM(estimated_spend) as est_spend
FROM weekly_table
WHERE source='publisher_spend'
GROUP BY 1,2,3 ) as E on A.day_est=E.day_est AND A.PID=E.PID AND A.AID=E.AID
INTO OUTFILE '/tmp/weekly_report.csv';