1

Using Oracle, having constant values in a query can affect the execution plan the database devises. In Oracle, I would always get an execution plan for a query that included placeholders

In MySQL, I get an error if I have placeholders in a query I try to EXPLAIN:

mysql> explain select * from runs where run_id = ?;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

Similarly, I can't find any way of getting an execution plan for a prepared query.

If having constant values in a query does effect the execution plan, I need to know how I can get an execution plan for a query with placeholders.

Alternatively, can someone explain (or point to documentation explaining) why this would affect the plan?

Makoto
  • 104,088
  • 27
  • 192
  • 230
SpoonMeiser
  • 19,918
  • 8
  • 50
  • 68
  • Preliminary searching doesn't look good ([1](http://stackoverflow.com/a/1323794/477563), [2](http://forums.mysql.com/read.php?115,411248,412035#msg-412035)) but those responses are a bit dated. That being said, you might want to cross-post your question to the [DBA StackExchange](https://dba.stackexchange.com/). – Mr. Llama May 13 '15 at 15:28
  • possible duplicate of [How do I explain a query with parameters in MySQL](http://stackoverflow.com/questions/3055468/how-do-i-explain-a-query-with-parameters-in-mysql) – Makoto May 26 '15 at 01:28
  • You can't, because the evaluation depends upon the exact value (eg, constant removal, index hits, etc.). See also this [duplicate](http://stackoverflow.com/questions/1320416/how-to-get-the-query-plan-from-a-prepared-statment). – bishop May 26 '15 at 01:33

0 Answers0