Я пытаюсь сократить время ответа для нижеприведенного запроса postgresql с текущих 5 секунд до 1 ... присоединение плана объяснения к этому запросу .. просьба помочь ...
(
SELECT
1 AS RowNumber
,'Total Countries' AS RowLabel
,COUNT(DISTINCT ITS.abc CountryTrading) AS Aggregation
FROM ObjectViews.abc InstnTradeSummary AS ITS
WHERE ITS.KeyInstn = 7402194
AND ITS.TradeDataMonthYearPublish >= date_trunc('month', current_date) + interval '-5 years'
AND ITS.TradeDataMonthYearPublish <= date_trunc('month', current_date)
AND ITS.abc CountryTrading IS NOT NULL
GROUP BY ITS.KeyInstn
UNION
SELECT
2 AS RowNumber
,'Total Shipments' AS RowLabel
,SUM(ITS.ShipmentCount) AS TotalShipments
FROM ObjectViews.abc InstnTradeSummary AS ITS
WHERE ITS.KeyInstn = 7402194
AND ITS.TradeDataMonthYearPublish >= date_trunc('month', current_date) + interval '-5 years'
AND ITS.TradeDataMonthYearPublish <= date_trunc('month', current_date)
GROUP BY ITS.KeyInstn
UNION
SELECT
3 AS RowNumber
,'Total Weight in kg' AS RowLabel
,SUM(COALESCE(ITS.ShipmentWeightAR, ITS.ShipmentWeightEst)) AS TotalShipmentWeight
FROM ObjectViews.abc InstnTradeSummary AS ITS
WHERE ITS.KeyInstn = 7402194
AND ITS.TradeDataMonthYearPublish >= date_trunc('month', current_date) + interval '-5 years'
AND ITS.TradeDataMonthYearPublish <= date_trunc('month', current_date)
GROUP BY ITS.KeyInstn
UNION
SELECT
4 AS RowNumber
,'Total Volume in TEU' AS RowLabel
,SUM(COALESCE(ITS.ShipmentVolumeAR, ITS.ShipmentVolumeEst)) AS TotalShipmentVolume
FROM ObjectViews.abc InstnTradeSummary AS ITS
WHERE ITS.KeyInstn = 7402194
AND ITS.TradeDataMonthYearPublish >= date_trunc('month', current_date) + interval '-5 years'
AND ITS.TradeDataMonthYearPublish <= date_trunc('month', current_date)
GROUP BY ITS.KeyInstn
) ORDER BY RowNumber
Ниже приведен план объяснения запроса ...
https://explain.depesz.com/s/xgC2