SQLite VDBE opcode

NotExists

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

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

INSERT INTO artists_archive SELECT * FROM artists
addropcodep1p2p3p4p5
0Init01400
1Null0100
2OpenWrite18030
3OpenRead02030
4Rewind01300
5Rowid0200
6NotExists1820
7Halt155520artists_archive.id2
8RowCell1020
9Insert112artists_archive169
10Next0500
11Close0000
12Close1000
13Halt0000
14Transaction01101
15Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Close, Goto, Halt, Init, Insert, Next, Null, OpenRead, OpenWrite, Rewind, RowCell, Rowid, Transaction.

What the SQLite documentation says

P1 is the index of a cursor open on an SQL table btree (with integer keys). P3 is an integer rowid. 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 SeekRowid opcode performs the same operation but also allows the P3 register to contain a non-integer value, in which case the jump is always taken. This opcode requires that P3 always 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.

← Not · NotFound →