SQLite VDBE opcode

Filter

Compute a hash on the key contained in the P4 registers starting with r[P3].

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

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

SELECT a.name, b.title FROM artists a LEFT JOIN albums b ON b.artist_id = a.id
addropcodep1p2p3p4p5
0Init03100
1OpenRead260k(2,,)0
2OpenRead13040
3Rewind230100
4Once01600
5OpenAutoindex330k(3,B,,)0
6Explain600BLOOM FILTER ON b (artist_id=?)0
7Blob10000100
8Rewind11600
9Column1130
10Column1240
11Rowid1500
12MakeRecord3320
13FilterAdd10310
14IdxInsert32016
15Next1903
16Integer0600
17IdxRowid2700
18Filter126710
19SeekGE326710
20IdxGT326710
21Integer1600
22Column2080
23Column3190
24ResultRow8200
25Next32000
26IfPos62900
27NullRow3000
28Goto02100
29Next2401
30Halt0000
31Transaction00101
32Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Blob, Column, Explain, FilterAdd, Goto, Halt, IdxGT, IdxInsert, IdxRowid, IfPos, Init, Integer, MakeRecord, Next, NullRow, Once, OpenAutoindex, OpenRead, ResultRow, Rewind, Rowid, SeekGE, Transaction.

What the SQLite documentation says

Compute a hash on the key contained in the P4 registers starting with r[P3]. Check to see if that hash is found in the bloom filter hosted by register P1. If it is not present then maybe jump to P2. Otherwise fall through.

False negatives are harmless. It is always safe to fall through, even if the value is in the bloom filter. A false negative causes more CPU cycles to be used, but it should still yield the correct answer. However, an incorrect answer may well arise from a false positive - if the jump is taken when it should fall through.

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.

← Explain · FilterAdd →