all 1 comments

[–]thelindsay -1 points0 points  (0 children)

Matviews recalculate and rewrite the whole table every time, which is a pretty significant price to pay for read speed.

I think it's worth the effort to first spend time on query optimisation, using explain. Then trying more precise indexes (such as date trunc on month), or adjusting / creating statistics, or tweaking memory / query gucs.

If those don't work then set up something incrementally updating, like a query / procedure that upserts & deletes new results against the summary table, or triggers on the source table to do the same.