Sequence
Find the next available sequence number for cursor P1.
An example
2 of the 178 statements we compiled against the sample database use Sequence. This is the one with the shortest program; the rows that use Sequence are highlighted.
SELECT * FROM tracks ORDER BY ms DESC LIMIT 10 OFFSET 20
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 35 | 0 | 0 | |
| 1 | OpenEphemeral | 1 | 8 | 0 | k(1,-B) | 0 |
| 2 | Integer | 10 | 1 | 0 | 0 | |
| 3 | Integer | 20 | 2 | 0 | 0 | |
| 4 | MustBeInt | 2 | 0 | 0 | 0 | |
| 5 | OffsetLimit | 1 | 3 | 2 | 0 | |
| 6 | OpenRead | 0 | 4 | 0 | 6 | 0 |
| 7 | Rewind | 0 | 23 | 0 | 0 | |
| 8 | Column | 0 | 3 | 4 | 0 | |
| 9 | Sequence | 1 | 5 | 0 | 0 | |
| 10 | IfNotZero | 3 | 14 | 0 | 0 | |
| 11 | Last | 1 | 0 | 0 | 0 | |
| 12 | IdxLE | 1 | 22 | 4 | 1 | 0 |
| 13 | Delete | 1 | 0 | 0 | 0 | |
| 14 | Rowid | 0 | 6 | 0 | 0 | |
| 15 | Column | 0 | 1 | 7 | 0 | |
| 16 | Column | 0 | 2 | 8 | 0 | |
| 17 | Column | 0 | 4 | 9 | 0 | |
| 18 | Column | 0 | 5 | 10 | 0 | |
| 19 | RealAffinity | 10 | 0 | 0 | 0 | |
| 20 | MakeRecord | 4 | 7 | 12 | 0 | |
| 21 | IdxInsert | 1 | 12 | 4 | 7 | 0 |
| 22 | Next | 0 | 8 | 0 | 1 | |
| 23 | Sort | 1 | 34 | 0 | 0 | |
| 24 | IfPos | 2 | 33 | 1 | 0 | |
| 25 | AddImm | 1 | -1 | 0 | 0 | |
| 26 | Column | 1 | 6 | 11 | 0 | |
| 27 | Column | 1 | 5 | 10 | 0 | |
| 28 | Column | 1 | 0 | 9 | 0 | |
| 29 | Column | 1 | 4 | 8 | 0 | |
| 30 | Column | 1 | 3 | 7 | 0 | |
| 31 | Column | 1 | 2 | 6 | 0 | |
| 32 | ResultRow | 6 | 6 | 0 | 0 | |
| 33 | Next | 1 | 24 | 0 | 0 | |
| 34 | Halt | 0 | 0 | 0 | 0 | |
| 35 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 36 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: AddImm, Column, Delete, Goto, Halt, IdxInsert, IdxLE, IfNotZero, IfPos, Init, Integer, Last, MakeRecord, MustBeInt, Next, OffsetLimit, OpenEphemeral, OpenRead, RealAffinity, ResultRow, Rewind, Rowid, Sort, Transaction.
What the SQLite documentation says
Find the next available sequence number for cursor P1. Write the sequence number into register P2. The sequence number on the cursor is incremented after this instruction.
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.
← SeekScan · SequenceTest →