Fastest Way To Check How Many Posts Are In A Thread With MySQL And PHP
I was wondering if it which is faster when trying to, for example, check how many posts are in a particular thread on a forum. Should I...
(a) Go through each post in the database with the particular thread ID, and count how many rows
(b) Add one to a separate column in the threads database every time a thread is made, and then query that single row
What's wrong with having an index for the thread ID? Wouldn't a simple COUNT expression grouped by the thread ID field suffice?
With any caching at all, this would be plenty fast from what I can tell.
--This will provide counts for all threads SELECT COUNT(threadID) FROM Posts GROUP BY threadID; --This will provide count for one thread SELECT COUNT(threadID) FROM Posts WHERE threadID=123 GROUP BY threadID;
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?