Answer the question
In order to leave comments, you need to log in
What is the fastest way to get the number of records in a large mysql table??
A site with 200,000 pages began to noticeably slow down. I'm sure that the way to get the number of records like below is bad:
$result = mysql_query("SELECT COUNT(*) FROM cache");
$total_records = mysql_result($result,0,0);
Answer the question
In order to leave comments, you need to log in
Alternatively, one of: https://habrahabr.ru/post/126233/
They
also pull through cursors: https://habrahabr.ru/post/30046/. I think mysql also has this feature.
But(!) if your number of records rarely changes, then perhaps it makes sense to simply cache the request before any event occurs.
Everything depends on the situation. Maybe one of the suggestions will work.
all normal people consider this on triggers or do not consider it at all
I ran into the same situation two days ago.
Caching didn't work for me. I was told to use indexes.
True, it was already too late, I cleaned the database, now I'm waiting for 150 thousand records again, I'll try. But if you haven't cleared it, then try with indexes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question