In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
CREATE INDEX oag_dailyflights_idx_depstn_carcode ON "truesight_data"."oag_dailyflights" ("depStn","carCode");
CREATE INDEX oag_dailyflights_idx_pubdate ON "truesight_data"."oag_dailyflights" ("PubDate");
SELECT
df.carCode,
COUNT(*) AS departures
FROM
truesight_data.oag_dailyflights df
WHERE
df.flowndate <@ '[2016-01-01,2017-10-31]'::daterange
AND (
df.flowndate <= (
(
DATE_TRUNC('MONTH', df.pubDate) + INTERVAL '1 MONTH - 1 day'
)::date
)
OR df.PubDate = (
SELECT
MAX(truesight_data.oag_dailyflights.PubDate)
FROM
truesight_data.oag_dailyflights
)
)
AND df.depStn = 'PIT'
AND (
df.svcType IN (
'cargo', 'combi'
)
OR df.acftClass = 'WB'
)
GROUP BY
df.carCode
ORDER BY
COUNT(*) DESC