I have a table with posts, which are categorized by:

* type
* tag
* language

All of those "categories" are stored in next tables (posts\_types) and connected via next tables (posts\_types\_assignment).

[COUNTing in PostgreSQL is really slow](http://wiki.postgresql.org/wiki/Slow_Counting) (i have more than 500k records in that table) and i need to get the number of posts categorized by any combination of type/tag/lang.

If i would solve it through triggers, it would be full of many multi-level loops, which really doesn't look like nice and is hard to maintenance.

Is there any other solution how to effectively get actual number of posts categorized in any type/tag/language?