I know that SQL_CALC_FOUND_ROWS has been deprecated, but I was just wondering if anyone knows why? It was so handy, even if slightly less performant than running the query twice (once with and once without the LIMIT clause).

Recommended Answers

All 7 Replies

Guess I'm going to have to go through all my code now :(

I must also have logs set to only log errors because I'm not seeing the deprecation notices in my log file.

Soooo that totally didn't take as long as I was afraid it would. :)

Luckily I had been already slowly migrating away from SQL_CALC_FOUND_ROWS so there were only about a dozen left to refactor.

Okay, so I've run into a big of a snafu and I'm trying to figure out which is more efficient:

SELECT COUNT(DISTINCT id) AS total_rows
FROM table
LEFT JOIN [...]

or

SELECT COUNT(*) AS total_rows FROM
(
    SELECT 1
    FROM table
    LEFT JOIN [...]
    GROUP BY id
)

In other words, as I now have to do a second query to fetch the total number of records, which is faster: using a COUNT DISTINCT, or a COUNT(*) with GROUP BY and subquery?

Of course, I'm oversimplifying the queries, but that's the trade-off.

I have a feeling that the query optimizer would recognize both as being the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.