I have been reading about "COUNT(*) without where clause" being incredibly slow in PostgreSQL. And coming from MySQL, I don't know if I'm going to be able to live without ever using it again. I have also read that even if you add a "where" clause, it will have to scan each row from the result, which will be slow unless you have very few results. I have seen there are crazy hacks using triggers and extra tables, but I don't like how it looks. I mean I'm new to this RDBMS, just starting to use the basic functionality, and already have to use workarounds?
An example of what I need to do is to create a flood protection mechanism. Something like if "count(id) where ip = 1.2.3.4" > 100, fail instead of insert
.
So my questions are:
- Is this still an unsolved problem?
- Will it make any difference if I use COUNT(id) instead, or add some clause like DISTINCT?
- How do PostgreSQL users survive without counting?