Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One trick with counts is that you very rarely need a perfectly accurate count for that exact moment in time; doing an explain on an appropriate 'SELECT' and capturing the estimated number of rows returned by that is usually good enough in 98% of the cases.

When you do need an accurate count, phrasing the query so the results can be pulled exclusively from the table index is also usually good enough.



Never thought of using EXPLAIN to get an estimated count... nice trick!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: