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
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 29 | 0 | 0 | |
| 1 | OpenRead | 0 | 4 | 0 | 6 | 0 |
| 2 | Null | 0 | 2 | 0 | 0 | |
| 3 | Integer | 18 | 1 | 0 | 0 | |
| 4 | ReopenIdx | 1 | 5 | 0 | k(2,,) | 2 |
| 5 | Integer | 3 | 4 | 0 | 0 | |
| 6 | SeekGE | 1 | 13 | 4 | 1 | 0 |
| 7 | IdxGT | 1 | 13 | 4 | 1 | 0 |
| 8 | DeferredSeek | 1 | 0 | 0 | [0,1,0,0,0,0] | 0 |
| 9 | IdxRowid | 1 | 3 | 0 | 0 | |
| 10 | RowSetTest | 2 | 12 | 3 | 0 | 0 |
| 11 | Gosub | 1 | 19 | 0 | 0 | |
| 12 | Next | 1 | 7 | 1 | 0 | |
| 13 | Integer | 9 | 5 | 0 | 0 | |
| 14 | SeekRowid | 0 | 18 | 5 | 0 | |
| 15 | Rowid | 0 | 3 | 0 | 0 | |
| 16 | RowSetTest | 2 | 18 | 3 | -1 | 0 |
| 17 | Gosub | 1 | 19 | 0 | 0 | |
| 18 | Goto | 0 | 28 | 0 | 0 | |
| 19 | Rowid | 0 | 6 | 0 | 0 | |
| 20 | Column | 0 | 1 | 7 | 0 | |
| 21 | Column | 0 | 2 | 8 | 0 | |
| 22 | Column | 0 | 3 | 9 | 0 | |
| 23 | Column | 0 | 4 | 10 | 0 | |
| 24 | Column | 0 | 5 | 11 | 0 | |
| 25 | RealAffinity | 11 | 0 | 0 | 0 | |
| 26 | ResultRow | 6 | 6 | 0 | 0 | |
| 27 | Return | 1 | 19 | 0 | 0 | |
| 28 | Halt | 0 | 0 | 0 | 0 | |
| 29 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 30 | Goto | 0 | 1 | 0 | 0 |
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:
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 →