I have an INSERT INTO... SELECT ... FROM
SQL statement that runs acceptably fast when executed from SQLite's
command line shell.
However, if I execute the same statement (copy/pasted) with Perl's DBI::SQLite
, the statement becomes slow.
The reason must be the execution plan: when I let the statement be explained from the shell and from within DBI::SQLite
, they're different: the fast version uses the optimal indexes and table order, the slow version chooses to access the tables in a less than optimal way.
So, I have two questions.
- Why is the plan different?
- How can I make the plan used in the Perl environment the same as in the shell?