Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the query plan from a prepared statment

I don't remember ever seeing a way to use prepared statements from the console and somehow don't think running an explain query thought as a prepared statement from the API will get what I want.

This is related to this old question of mine.

I'm primarily interested in MySQL but would be interested in other DBs as well.

like image 987
BCS Avatar asked Aug 24 '09 03:08

BCS


People also ask

How do I obtain a query execution plan in MySQL?

To view a visual explain execution plan, execute your query from the SQL editor and then select Execution Plan within the query results tab. The execution plan defaults to Visual Explain , but it also includes a Tabular Explain view that is similar to what you see when executing EXPLAIN in the MySQL client.

How do I view a query plan in SQL Server?

On the SQL Server Management Studio toolbar, click Database Engine Query. You can also open an existing query and display the estimated execution plan by clicking the Open File toolbar button and locating the existing query. Enter the query for which you would like to display the actual execution plan.


1 Answers

According to the brief research that I conducted, I don't see a way to get it. Ideally, the real execution plan would be generated once the variables are provided. Lookup tables can quickly eliminate actually running the query if a constant is not present. The ideal execution plan would take into account the frequency of occurrence. My understanding is that MySQL at least used to prepare an execution plan when the statement is prepared in order to validate the expression. Then, when you execute it, it generates another explain plan.

I believe the explain plan is temporarily housed in a table in MySQL but is quickly removed after it is used.

I would suggest asking on the MySQL internals list.

Good Luck,

Jacob

like image 155
TheJacobTaylor Avatar answered Nov 15 '22 12:11

TheJacobTaylor