Viewing programs generated by QDB

Every SQL statement that QDB interprets results in a program for the virtual machine. However, if you precede the SQL statement with the keyword EXPLAIN, the virtual machine doesn't execute the program. Instead, the instructions of the program are returned like a query result. This feature is useful for debugging and for learning how the virtual machine operates, and for profiling an SQL statement. The following is an example of 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  

All you have to do is add the EXPLAIN keyword to the front of the SQL statement. But if you use the .explain command to qdb first, it will set up the output mode to make the program more easily viewable.

You can put the QDB virtual machine in a mode where it will trace its execution by writing messages to standard output; and you can use the non-standard SQL PRAGMA, comments to turn tracing on and off. To turn tracing on, enter:

PRAGMA vdbe_trace=on;

You can turn tracing back off by entering a similar statement but changing the value on to off.