SQLite VDBE opcode

ReopenIdx

The ReopenIdx opcode works like OpenRead except that it first checks to see if the cursor on P1 is already open on the same b-tree and if it is this opcode becomes a no-op.

An example

1 of the 178 statements we compiled against the sample database use ReopenIdx. This is the one with the shortest program; the rows that use ReopenIdx 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, ResultRow, Return, RowSetTest, Rowid, SeekGE, SeekRowid, Transaction.

What the SQLite documentation says

The ReopenIdx opcode works like OpenRead except that it first checks to see if the cursor on P1 is already open on the same b-tree and if it is this opcode becomes a no-op. In other words, if the cursor is already open, do not reopen it.

The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ and with P4 being a P4_KEYINFO object. Furthermore, the P3 value must be the same as every other ReopenIdx or OpenRead for the same cursor number.

Allowed P5 bits:

See also: OpenRead, OpenWrite

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.

← Remainder · ResetCount →