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
ANALYZE with the query plan of that query.
I'm not sure that re-running the query with
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)