I'm trying to reduce response time for below postgresql query from current 5 seconds to 1...attaching explain plan too for this query..please help...
(
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
Below is explain plan for the query...