SQLite VDBE opcode

RowSetTest

Register P3 is assumed to hold a 64-bit integer value.

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

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

SELECT * FROM tracks WHERE album_id = 3 OR id = 9
addropcodep1p2p3p4p5
0Init02900
1OpenRead04060
2Null0200
3Integer18100
4ReopenIdx150k(2,,)2
5Integer3400
6SeekGE113410
7IdxGT113410
8DeferredSeek100[0,1,0,0,0,0]0
9IdxRowid1300
10RowSetTest212300
11Gosub11900
12Next1710
13Integer9500
14SeekRowid01850
15Rowid0300
16RowSetTest2183-10
17Gosub11900
18Goto02800
19Rowid0600
20Column0170
21Column0280
22Column0390
23Column04100
24Column05110
25RealAffinity11000
26ResultRow6600
27Return11900
28Halt0000
29Transaction00101
30Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, DeferredSeek, Gosub, Goto, Halt, IdxGT, IdxRowid, Init, Integer, Next, Null, OpenRead, RealAffinity, ReopenIdx, ResultRow, Return, Rowid, SeekGE, SeekRowid, Transaction.

What the SQLite documentation says

Register P3 is assumed to hold a 64-bit integer value. If register P1 contains a RowSet object and that RowSet object contains the value held in P3, jump to register P2. Otherwise, insert the integer in P3 into the RowSet and continue on to the next opcode.

The RowSet object is optimized for the case where sets of integers are inserted in distinct phases, which each set contains no duplicates. Each set is identified by a unique P4 value. The first set must have P4==0, the final set must have P4==-1, and for all other sets must have P4>0.

This allows optimizations: (a) when P4==0 there is no need to test the RowSet object for P3, as it is guaranteed not to contain it, (b) when P4==-1 there is no need to insert the value, as it will never be tested for, and (c) when a value that is part of set X is inserted, there is no need to search to see if the same value was previously inserted as part of set X (only if it was previously inserted as part of some other set).

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.

← RowSetRead · Savepoint →