Question

Is there a way to get an execution plan of a parametrized query without binding actual values?

I'm using System.Data.SQLite in my application and I'm trying to get an execution plan of a query for debugging and profiling purposes. The idea was to add a EXPLAIN QUERY PLAN string before the actual statement, execute and dump results to the debugging console.

This strategy works just fine with non-parametrized queries, but fails on parametrized ones.

Is there any way to overcome this problem? Isn't SQLite supposed to prepare an execution plan before parameter binding occurs?

Was it helpful?

Solution

SQLite itself does not require that every parameter is bound explicitly; the default value is NULL.

If the database driver you're using forces you to set all parameters, just set them to NULL.

If index statistics are enabled, SQLite can recompile statements whenever new parameters have been set. In this case, the execution plan might not be the same as you would get for actual parameter values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top