Is there any way to let Postgres know it can filter results and then calculate aggregations?
0
votes
1
answer
1086
views
Given a table A with 10 million records and another table B with child items (one-to-many), I have to provide a consumable view with totals from several fields in B grouped by the FK of A.
None of the filtering or sorting I'm doing are reliant upon the aggregated totals, but the performance is poor even when I'm doing a simple filter on a column that is in table A such as a smallint (status_id, etc.). The analyzer appears to try to perform aggregations on the total result set before applying my filter.
Because I have to use max(id), etc. on all of my columns in table A even though I know they are distinct, I'm wondering if that's causing an issue because I'm technically filtering on an aggregate value? If that's the case, I would expect subqueries to perform better.
Asked by Dane
(1 rep)
Jan 27, 2022, 05:45 AM
Last activity: Jan 27, 2022, 07:00 AM
Last activity: Jan 27, 2022, 07:00 AM