sqliteHow do I read a SQLite query plan?
Reading a SQLite query plan is a great way to identify which parts of a query are taking the most time to execute. To read a query plan, use the EXPLAIN QUERY PLAN
command. This command will return a tree structure that describes the query plan.
Here is an example of the EXPLAIN QUERY PLAN
command being used on a simple query:
sqlite> EXPLAIN QUERY PLAN SELECT * FROM tbl_name;
0|0|0|SEARCH TABLE tbl_name USING INTEGER PRIMARY KEY (rowid=?)
The output of the command consists of four parts:
- The first part is the estimated cost of the query.
- The second part is the estimated number of rows returned by the query.
- The third part is the estimated number of columns returned by the query.
- The fourth part is the query plan itself, which describes the steps that the query will take to execute.
In this example, the query plan is SEARCH TABLE tbl_name USING INTEGER PRIMARY KEY (rowid=?)
, which means that the query will search the table tbl_name
using the rowid as the primary key.
For more information on reading query plans, see the SQLite documentation.
More of Sqlite
- How to configure SQLite with XAMPP on Windows?
- How do I use SQLite with Visual Studio?
- How do I use the SQLite sequence feature?
- How do I use the SQLite round function?
- How do I use regular expressions to query a SQLite database?
- How do I install SQLite using Python?
- How do I extract the year from a datetime value in SQLite?
- How do I use the SQLite ZIP VFS to compress a database?
- How can I get the year from a date in SQLite?
- How can I use SQLite to query for records between two specific dates?
See more codes...