[MDEV-29944] [Question] ANALYZE or EXPLAIN for previous query Created: 2022-11-03 Updated: 2022-11-04 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Server |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Nuno | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Hello, `EXPLAIN SELECT ...` shows the EXPLAIN for a query that never runs. `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 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) Thank you very much! |
| Comments |
| Comment by Daniel Black [ 2022-11-04 ] |
|
Yes, I see your desired functionality. I tried a few dead ends like mysql.slow_log as innodb with FK constraint on the query. You'd maybe like a auto-enable/store on optimizer trace for specific queries: https://mariadb.com/kb/en/optimizer-trace-guide/ I'd suggest searching existing feature requests and if those don't cover it, extend this issue to cover all of the desired functionality. |