Index conditional aggregate query on PostgreSQL
1
vote
2
answers
412
views
How does one optimize a conditional aggregate query on PostgreSQL?
A example of such query would be:
SELECT SUM(score) FROM "games" WHERE "PlayerId" = 23 AND "status" = 'FINAL';
Indexing (PlayerId, status)
would help the filter, any tricks or ideas to optimize the aggregation post filtration?
What would be ideal would be no external caching mechanism involved, and a save mechanism to keep a running SUM every time "games" table is updated – similar to how a cache works but a more reliable one.
Asked by uzyn
(111 rep)
Mar 11, 2020, 07:24 AM
Last activity: Jun 3, 2025, 10:04 PM
Last activity: Jun 3, 2025, 10:04 PM