In the correct configuration (in most cases, the default configuration is good enough) MySQL 5.0+ server caches SUM, COUNT requests, so MySQL processes such requests automatically.
But if you are using an older version (MySQL 4 or less), I recommend storing the COUNT (*) values ββin the database, because it really leads to the execution of large tables.
Edit: The best practice I discovered is making a COUNT (*) request every time a user adds / removes a vote / comment, etc. Modern SQL servers handle group queries very well, t have to worry about performance.
Peter
source share