SorterNext
This opcode works just like Next except that P1 must be a sorter object for which the SorterSort opcode has been invoked.
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
15 of the 178 statements we compiled against the sample database use SorterNext. This is the one with the shortest program; the rows that use SorterNext are highlighted.
SELECT name FROM artists ORDER BY name COLLATE NOCASE
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 16 | 0 | 0 | |
| 1 | SorterOpen | 1 | 3 | 0 | k(1,NOCASE) | 0 |
| 2 | OpenRead | 2 | 6 | 0 | k(2,,) | 0 |
| 3 | Rewind | 2 | 9 | 1 | 0 | 0 |
| 4 | Column | 2 | 0 | 2 | 0 | |
| 5 | Column | 2 | 0 | 1 | 0 | |
| 6 | MakeRecord | 1 | 2 | 3 | 0 | |
| 7 | SorterInsert | 1 | 3 | 1 | 2 | 0 |
| 8 | Next | 2 | 4 | 0 | 1 | |
| 9 | OpenPseudo | 3 | 4 | 3 | 0 | |
| 10 | SorterSort | 1 | 15 | 0 | 0 | |
| 11 | SorterData | 1 | 4 | 3 | 0 | |
| 12 | Column | 3 | 1 | 2 | 0 | |
| 13 | ResultRow | 2 | 1 | 0 | 0 | |
| 14 | SorterNext | 1 | 11 | 0 | 0 | |
| 15 | Halt | 0 | 0 | 0 | 0 | |
| 16 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 17 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, Goto, Halt, Init, MakeRecord, Next, OpenPseudo, OpenRead, ResultRow, Rewind, SorterData, SorterInsert, SorterOpen, SorterSort, Transaction.
What the SQLite documentation says
This opcode works just like Next except that P1 must be a sorter object for which the SorterSort opcode has been invoked. This opcode advances the cursor to the next sorted record, or jumps to P2 if there are no more sorted records.
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.
← SorterInsert · SorterOpen →