Search code examples
mysqldatabase-performancerowcount

Explain MySQL query without changing row_count() from previous query


In an application, sometimes queries are slow, and I "explain" them after the fact (if they are slow) and log them, so I can improve the application over time.

However, if I run an "explain " after, row_count() no longer reflects the number of rows affected by the original query, which I don't want. Is there a way to run an explain query (or perhaps any query), and not change row_count()?

Note: What I am currently doing is to open a separate link to the database, and explain using that link. That works, but I am unable to explain queries using temporary tables in that way. I am looking for a different solution that will preserve row_count() and work with temporary tables.


Solution

  • Capture row_count() into a variable, if you need it later. You should probably be doing this anyway, since the scope of validity of this value is very limited.

    The value is tied to the specific connection, and is reset with each query you execute... and EXPLAIN ... is a query.

    There's not a way to change this behavior.