Viewing programs generated by QDB
For every SQL statement, QDB generates a program for the virtual machine.
If you precede the SQL statement with the keyword EXPLAIN, the
virtual machine doesn't execute the program. Instead, the program instructions are
returned like a query result. This feature is useful for debugging and learning how
the virtual machine operates, and for profiling an SQL statement. The following example
shows the output from the statement EXPLAIN DELETE FROM tbl1 WHERE
two<20;:
| addr | opcode | p1 | p2 | p3 |
|---|---|---|---|---|
| 0 | Transaction | 0 | 0 | |
| 1 | VerifyCookie | 219 | 0 | |
| 2 | ListOpen | 0 | 0 | |
| 3 | Open | 0 | 3 | tbl1 |
| 4 | Rewind | 0 | 0 | |
| 5 | Next | 0 | 12 | |
| 6 | Column | 0 | 1 | |
| 7 | Integer | 20 | 0 | |
| 8 | Ge | 0 | 5 | |
| 9 | Recno | 0 | 0 | |
| 10 | ListWrite | 0 | 0 | |
| 11 | Goto | 0 | 5 | |
| 12 | Close | 0 | 0 | |
| 13 | ListRewind | 0 | 0 | |
| 14 | OpenWrite | 0 | 3 | |
| 15 | ListRead | 0 | 19 | |
| 16 | MoveTo | 0 | 0 | |
| 17 | Delete | 0 | 0 | |
| 18 | Goto | 0 | 15 | |
| 19 | ListClose | 0 | 0 | |
| 20 | Commit | 0 | 0 |
Note:
You can make the program output more readable by first issuing the
.explain command to qdb, to enable output mode.
You can trace the execution of the QDB virtual machine by making it write messages to
standard output. This is done using the non-standard SQL PRAGMA
command. You can turn tracing on with this command:
PRAGMA vdbe_trace=on;
To turn tracing off again, enter a similar statement but with on
changed to off.
Page updated:
