> thanks for that - I tried it out, fixed the minor typos and it ran at almost
> the same speed! Any other ideas?
Could you post an explain analyze for both queries?
There is always an application change. Add a trigger onto msg that will
bump the date and count on msg_sum when a msg is added. This will
support virtually unlimited msg table growth (any aggregate will
eventually be slow on a large table).
Just be sure to vacuum the msg_sum table regularly (once per 25%
turnover) -- possibly as often as once a minute!