SQLite VDBE opcode

SeekRowid

P1 is the index of a cursor open on an SQL table btree (with integer keys).

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

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

SELECT name FROM artists WHERE id = 7
addropcodep1p2p3p4p5
0Init0700
1OpenRead02020
2Integer7100
3SeekRowid0610
4Column0120
5ResultRow2100
6Halt0000
7Transaction00101
8Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Goto, Halt, Init, Integer, OpenRead, ResultRow, Transaction.

What the SQLite documentation says

P1 is the index of a cursor open on an SQL table btree (with integer keys). If register P3 does not contain an integer or if P1 does not contain a record with rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then leave the cursor pointing at that record and fall through to the next instruction.

The NotExists opcode performs the same operation, but with NotExists the P3 register must be guaranteed to contain an integer value. With this opcode, register P3 might not contain an integer.

The NotFound opcode performs the same operation on index btrees (with arbitrary multi-value keys).

This opcode leaves the cursor in a state where it cannot be advanced in either direction. In other words, the Next and Prev opcodes will not work following this opcode.

See also: Found, NotFound, NoConflict, SeekRowid

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.

← SeekLT · SeekScan →