Sample Header Ad - 728x90

ANALYZE or EXPLAIN for previous query

0 votes
1 answer
542 views
EXPLAIN SELECT ... shows the EXPLAIN for a query (without actually running it). SHOW EXPLAIN FOR conn_id shows the EXPLAIN for a query that is currently running. Is it possible to get the EXPLAIN for the last query that ran on a connection? For example, if my application detected that a specific query took over 2 seconds to run for a user, I'd like to log the EXPLAIN or ANALYZE with the query plan of that query. I'm not sure that re-running the query with EXPLAIN or ANALYZE will give me the exact query plan that was used on its previous run, as MySQL/MariaDB could potentially use another query plan on the re-run. (I am aware of log_slow_verbosity=query_plan,explain, but I don't want to log this for every query that takes over 1 second - only this specific query)
Asked by Nuno (829 rep)
Nov 3, 2022, 11:50 PM
Last activity: Apr 25, 2025, 04:07 AM