SQLite VDBE opcode

Next

Advance cursor P1 so that it points to the next key/data pair in its table or index.

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

112 of the 178 statements we compiled against the sample database use Next. This is the one with the shortest program; the rows that use Next are highlighted.

SELECT id IS TRUE FROM tracks
addropcodep1p2p3p4p5
0Init0800
1OpenRead1190k(2,,)0
2Rewind17100
3IdxRowid1200
4IsTrue21000
5ResultRow1100
6Next1301
7Halt0000
8Transaction00101
9Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Goto, Halt, IdxRowid, Init, IsTrue, OpenRead, ResultRow, Rewind, Transaction.

What the SQLite documentation says

Advance cursor P1 so that it points to the next key/data pair in its table or index. If there are no more key/value pairs then fall through to the following instruction. But if the cursor advance was successful, jump immediately to P2.

The Next opcode is only valid following an SeekGT, SeekGE, or Rewind opcode used to position the cursor. Next is not allowed to follow SeekLT, SeekLE, or Last.

The P1 cursor must be for a real table, not a pseudo-table. P1 must have been opened prior to this opcode or the program will segfault.

The P3 value is a hint to the btree implementation. If P3==1, that means P1 is an SQL index and that this instruction could have been omitted if that index had been unique. P3 is usually 0. P3 is always either 0 or 1.

If P5 is positive and the jump is taken, then event counter number P5-1 in the prepared statement is incremented.

See also: Prev

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.

← NewRowid · NoConflict →