SQLite VDBE opcode

FkIfZero

This opcode tests if a foreign key constraint-counter is currently zero.

Jumps: P2 is an instruction address. In the listings here, a jump is drawn as an arc and the address is a link.

An example

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

INSERT INTO artists (name) SELECT title FROM albums
addropcodep1p2p3p4p5
0Init03700
1InitCoroutine5820
2OpenRead03030
3Rewind0700
4Column0260
5Yield5000
6Next0401
7EndCoroutine5000
8OpenWrite12030
9OpenWrite270k(2,,)0
10OpenWrite360k(2,,)0
11Yield53600
12SoftNull2000
13SCopy6300
14NewRowid1100
15HaltIfNull129923artists.name1
16Affinity230DBB0
17SCopy31400
18PureFunc0148lower(1)32
19IntCopy1900
20MakeRecord8270
21SCopy31100
22IntCopy11200
23MakeRecord112100
24MakeRecord23130
25FkIfZero03200
26OpenRead43020
27Rewind43200
28Column41140
29Ne13114BINARY-883
30FkCounter0-100
31Next42801
32IdxInsert278216
33IdxInsert31011216
34Insert1131artists57
35Goto01100
36Halt0000
37Transaction01101
38Null0400
39Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Affinity, Column, EndCoroutine, FkCounter, Goto, Halt, HaltIfNull, IdxInsert, Init, InitCoroutine, Insert, IntCopy, MakeRecord, Ne, NewRowid, Next, Null, OpenRead, OpenWrite, PureFunc, Rewind, SCopy, SoftNull, Transaction, Yield.

What the SQLite documentation says

This opcode tests if a foreign key constraint-counter is currently zero. If so, jump to instruction P2. Otherwise, fall through to the next instruction.

If P1 is non-zero, then the jump is taken if the database constraint-counter is zero (the one that counts deferred constraint violations). If P1 is zero, the jump is taken if the statement constraint-counter is zero (immediate foreign key constraint violations).

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.

← FkCounter · Found →