SQLite VDBE opcode

DeferredSeek

P1 is an open index cursor and P3 is a cursor on the corresponding table.

An example

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

SELECT * FROM artists WHERE name < 'M' ORDER BY name DESC
addropcodep1p2p3p4p5
0Init01300
1Noop1500
2OpenRead02030
3OpenRead260k(2,,)0
4String8010M0
5SeekLT212110
6DeferredSeek2000
7IdxRowid2200
8Column2030
9Column0240
10ResultRow2300
11Prev2600
12Halt0000
13Transaction00101
14Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Goto, Halt, IdxRowid, Init, Noop, OpenRead, Prev, ResultRow, SeekLT, String8, Transaction.

What the SQLite documentation says

P1 is an open index cursor and P3 is a cursor on the corresponding table. This opcode does a deferred seek of the P3 table cursor to the row that corresponds to the current row of P1.

This is a deferred seek. Nothing actually happens until the cursor is used to read a record. That way, if no reads occur, no unnecessary I/O happens.

P4 may be an array of integers (type P4_INTARRAY) containing one entry for each column in the P3 table. If array entry a(i) is non-zero, then reading column a(i)-1 from cursor P3 is equivalent to performing the deferred seek and then reading column i from P1. This information is stored in P3 and used to redirect reads against P3 over to P1, thus possibly avoiding the need to seek and read cursor P3.

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.

← DecrJumpZero · Delete →