Fast and accurate statistical MySQL large table rows and the total number of pages

Have always been a headache how the total number of statistical problems, and sometimes actually want a big table for 10-15 minutes (count (1) and count (id) are required so long), to get a view into the system, there are about 1% to 3% error, simply can not accept.
(Really makes people miss sp_spaceused SQL Server, ah!) Later used this method for the following:

SELECT SQL_CALC_FOUND_ROWS 1 FROM tableName limit 1;
SELECT found_rows() AS rowcount;

It is basically a spike.
In addition, this statement is the total number of statistical records in addition to the open, this is very useful for adding a number of conditions statistics, it can be removed from the page write count this far, in theory, can improve the performance of 1/3.

reference:

Click on the link to open

Click on the link to open

Published 447 original articles · won praise 71 · Views 400,000 +

Guess you like

Origin blog.csdn.net/w892824196/article/details/103972827