4 ms·
> How often do you design a database query to get the count of all rows from a table? Any time I paginate a list, so it can show the "x of y pages"?
by ceejayoz 8y ago
> How often do you design a database query to get the count of all rows from a table?
Any time I paginate a list, so it can show the "x of y pages"?
- omouse 8y agoYou aren't keeping the count somewhere else, in a cache, let's say?
- ceejayoz 8y agoSure, but even if you're caching, you're presumably populating that "how many users do we have" widget's cache at least once a day or so.
- ars 8y agoSpecifically in this case, there's no reason to show a list of all of the users in the system. What would you do with a list with millions of rows? A search makes more sense here.
- ceejayoz 8y ago> What would you do with a list with millions of rows? Not much, but that doesn't mean folks won't. https://stackoverflow.com/questions https://stackoverflow.com/questions says "17,335,212 questions " and the pagination goes "1 2 3 4 5 … 346705", if you want a real-world example.
- bradjohnson 8y agoDoesn't make sense to query the db for a count of the number of records that are returned. You can figure that out from the result set inside your application.
- ceejayoz 8y agoIf the result set is "all users", you probably don't want to pull tens or hundreds of millions of records just to count them up if you're showing 100 per page.
- bradjohnson 8y agoI think that something like a query for hundreds of millions of records that also required pagination for the exact number of records returned is anomalous and not something that their application would do.