SQLite VDBE opcode

IdxInsert

Register P2 holds an SQL index key made using the MakeRecord instructions.

An example

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

SELECT DISTINCT country FROM artists
addropcodep1p2p3p4p5
0Init01100
1OpenEphemeral100k(1,B)8
2OpenRead02030
3Rewind01000
4Column0210
5Found19110
6MakeRecord1120
7IdxInsert121116
8ResultRow1100
9Next0401
10Halt0000
11Transaction00101
12Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Found, Goto, Halt, Init, MakeRecord, Next, OpenEphemeral, OpenRead, ResultRow, Rewind, Transaction.

What the SQLite documentation says

Register P2 holds an SQL index key made using the MakeRecord instructions. This opcode writes that key into the index P1. Data for the entry is nil.

If P4 is not zero, then it is the number of values in the unpacked key of reg(P2). In that case, P3 is the index of the first register for the unpacked key. The availability of the unpacked key can sometimes be an optimization.

If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer that this insert is likely to be an append.

If P5 has the OPFLAG_NCHANGE bit set, then the change counter is incremented by this instruction. If the OPFLAG_NCHANGE bit is clear, then the change counter is unchanged.

If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might run faster by avoiding an unnecessary seek on cursor P1. However, the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior seeks on the cursor or if the most recent seek used a key equivalent to P2.

This instruction only works for indices. The equivalent instruction for tables is Insert.

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.

← IdxGT · IdxLE →