SQLite VDBE opcode

Delete

Delete the record at which the P1 cursor is currently pointing.

An example

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

DELETE FROM genres WHERE name < ?
addropcodep1p2p3p4p5
0Init01200
1Noop2100
2OpenWrite190k(1,)0
3Rewind111200
4Variable1200
5IsNull21100
6Affinity210B0
7IdxGE111210
8Column1010
9Delete110genres2
10Next1700
11Halt0000
12Transaction01101
13Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Affinity, Column, Goto, Halt, IdxGE, Init, IsNull, Next, Noop, OpenWrite, Rewind, Transaction, Variable.

What the SQLite documentation says

Delete the record at which the P1 cursor is currently pointing.

If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then the cursor will be left pointing at either the next or the previous record in the table. If it is left pointing at the next record, then the next Next instruction will be a no-op. As a result, in this case it is ok to delete a record from within a Next loop. If OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be left in an undefined state.

If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this delete is one of several associated with deleting a table row and all its associated index entries. Exactly one of those deletes is the "primary" delete. The others are all on OPFLAG_FORDELETE cursors or else are marked with the AUXDELETE flag.

If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then the row change count is incremented (otherwise not).

If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the pre-update-hook for deletes is run, but the btree is otherwise unchanged. This happens when the Delete is to be shortly followed by an Insert with the same key, causing the btree entry to be overwritten.

P1 must not be pseudo-table. It has to be a real table with multiple rows.

If P4 is not NULL then it points to a Table object. In this case either the update or pre-update hook, or both, may be invoked. The P1 cursor must have been positioned using NotFound prior to invoking this opcode in this case. Specifically, if one is configured, the pre-update hook is invoked if P4 is not NULL. The update-hook is invoked if one is configured, P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.

If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address of the memory cell that contains the value that the rowid of the row will be set to by the update.

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.

← DeferredSeek · Destroy →