Gosub
Write the current address onto register P1 and then jump to address P2.
Jumps: P2 is an instruction address. In the listings here, a jump is drawn as an arc and the address is a link.
An example
19 of the 178 statements we compiled against the sample database use Gosub. This is the one with the shortest program; the rows that use Gosub are highlighted.
SELECT * FROM tracks WHERE album_id = 3 OR id = 9
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 29 | 0 | 0 | |
| 1 | OpenRead | 0 | 4 | 0 | 6 | 0 |
| 2 | Null | 0 | 2 | 0 | 0 | |
| 3 | Integer | 18 | 1 | 0 | 0 | |
| 4 | ReopenIdx | 1 | 5 | 0 | k(2,,) | 2 |
| 5 | Integer | 3 | 4 | 0 | 0 | |
| 6 | SeekGE | 1 | 13 | 4 | 1 | 0 |
| 7 | IdxGT | 1 | 13 | 4 | 1 | 0 |
| 8 | DeferredSeek | 1 | 0 | 0 | [0,1,0,0,0,0] | 0 |
| 9 | IdxRowid | 1 | 3 | 0 | 0 | |
| 10 | RowSetTest | 2 | 12 | 3 | 0 | 0 |
| 11 | Gosub | 1 | 19 | 0 | 0 | |
| 12 | Next | 1 | 7 | 1 | 0 | |
| 13 | Integer | 9 | 5 | 0 | 0 | |
| 14 | SeekRowid | 0 | 18 | 5 | 0 | |
| 15 | Rowid | 0 | 3 | 0 | 0 | |
| 16 | RowSetTest | 2 | 18 | 3 | -1 | 0 |
| 17 | Gosub | 1 | 19 | 0 | 0 | |
| 18 | Goto | 0 | 28 | 0 | 0 | |
| 19 | Rowid | 0 | 6 | 0 | 0 | |
| 20 | Column | 0 | 1 | 7 | 0 | |
| 21 | Column | 0 | 2 | 8 | 0 | |
| 22 | Column | 0 | 3 | 9 | 0 | |
| 23 | Column | 0 | 4 | 10 | 0 | |
| 24 | Column | 0 | 5 | 11 | 0 | |
| 25 | RealAffinity | 11 | 0 | 0 | 0 | |
| 26 | ResultRow | 6 | 6 | 0 | 0 | |
| 27 | Return | 1 | 19 | 0 | 0 | |
| 28 | Halt | 0 | 0 | 0 | 0 | |
| 29 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 30 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, DeferredSeek, Goto, Halt, IdxGT, IdxRowid, Init, Integer, Next, Null, OpenRead, RealAffinity, ReopenIdx, ResultRow, Return, RowSetTest, Rowid, SeekGE, SeekRowid, Transaction.
What the SQLite documentation says
Write the current address onto register P1 and then jump to address P2.
From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.
← GetSubtype · Goto →