I am trying to speed up the following query, which currently takes 14 seconds:
SELECT COUNT(*) AS employee_count, e.jurisdiction_id, e.year FROM employee_employee e GROUP BY e.jurisdiction_id, e.year ORDER BY employee_count ASC;
I add an index by running: CREATE INDEX ON employee_employee (jurisdiction_id, year);
But that did very little to improve the timing because the GROUP BY is taking the longest to execute. Is there a way to index a GROUP BY function?