Sqlite Explain
# SQLite Explain (Explanation)
Before an SQLite statement, you can use the "EXPLAIN" keyword or the "EXPLAIN QUERY PLAN" phrase to describe details about the table.
If the EXPLAIN keyword or phrase is omitted, any modification will cause the SQLite statement to execute its query behavior and return information about how the SQLite statement operates.
* The output from EXPLAIN and EXPLAIN QUERY PLAN is intended for interactive analysis and troubleshooting only.
* The details of the output format may vary between different versions of SQLite.
* Applications should not use EXPLAIN or EXPLAIN QUERY PLAN, as its exact behavior is variable and only partially documented.
## Syntax
The syntax for **EXPLAIN** is as follows:
EXPLAIN
The syntax for **EXPLAIN QUERY PLAN** is as follows:
EXPLAIN QUERY PLAN
## Example
Assume the COMPANY table has the following records:
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ----------1 Paul 32 California 20000.02 Allen 25 Texas 15000.03 Teddy 23 Norway 20000.04 Mark 25 Rich-Mond 65000.05 David 27 Texas 85000.06 Kim 22 South-Hall 45000.07 James 24 Houston 10000.0
Now, let's check the use of **Explain** in the SELECT statement:
sqlite> EXPLAIN SELECT * FROM COMPANY WHERE Salary >= 20000;
This will produce the following result:
addr opcode p1 p2 p3 ---------- ---------- ---------- ---------- ----------0 Goto 0 191 Integer 0 02 OpenRead 0 83 SetNumColu 0 54 Rewind 0 175 Column 0 46 RealAffini 0 07 Integer 20000 08 Lt 357 16 collseq(BI 9 Rowid 0 010 Column 0 111 Column 0 212 Column 0 313 Column 0 414 RealAffini 0 015 Callback 5 016 Next 0 517 Close 0 018 Halt 0 019 Transactio 0 020 VerifyCook 0 3821 Goto 0 122 Noop 0 0
Now, let's check the use 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
YouTip