English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SQLite Explain (Explanation)

The SQLite statement can be prefixed with the keyword 'EXPLAIN' or the phrase 'EXPLAIN QUERY PLAN' to describe the detailed information of the table.

Both modifications will cause the SQLite statement to behave as a query and return information about how the SQLite statement will run if the EXPLAIN keyword or phrase is omitted.

  • The output of EXPLAIN and EXPLAIN QUERY PLAN is only used for interactive analysis and troubleshooting.

  • The details of the output format may change from one version of SQLite to the next.

  • Applications should not use EXPLAIN or EXPLAIN QUERY PLAN, as their exact behavior is variable and only part of it will be recorded.

Syntax

EXPLAINThe syntax is as follows:

EXPLAIN [SQLite Query]

EXPLAIN QUERY PLANThe syntax is as follows:

EXPLAIN QUERY PLAN [SQLite Query]

Online Example

Consider the COMPANY table with the following records-

ID NAME AGE ADDRESS SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0

Now, let's use the SELECT statement to check the following subquery-

sqlite> EXPLAIN SELECT * FROM COMPANY WHERE Salary >= 20000;

This will produce the following result.

addr opcode p1          p2          p3
----------  ----------  ----------  ----------  ----------
0 Goto 0           19
1           Integer 0
2           OpenRead 0           8
3           SetNumColu 0           5
4           Rewind 0           17
5           Column           4
6           RealAffini 0
7           Integer     20000 0
8           Lt          357         16          collseq(BI
9           Rowid 0
10          Column           1
11          Column           2
12          Column           3
13          Column           4
14          RealAffini 0
15          Callback    5           0
16          Next           5
17          Close 0
18          Halt 0
19          Transactio 0
20 VerifyCook 0           38
21          Goto           1
22          Noop        0           0

Now, let's check the usage of Explain Query Plan in the SELECT statement:

SQLite> EXPLAIN QUERY PLAN SELECT * FROM COMPANY WHERE Salary >= 20000;
order       from        detail
----------  ----------  -------------
0           0           TABLE COMPANY