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
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 31 | 0 | 0 | |
| 1 | OpenRead | 2 | 6 | 0 | k(2,,) | 0 |
| 2 | OpenRead | 1 | 3 | 0 | 4 | 0 |
| 3 | Rewind | 2 | 30 | 1 | 0 | 0 |
| 4 | Once | 0 | 16 | 0 | 0 | |
| 5 | OpenAutoindex | 3 | 3 | 0 | k(3,B,,) | 0 |
| 6 | Explain | 6 | 0 | 0 | BLOOM FILTER ON b (artist_id=?) | 0 |
| 7 | Blob | 10000 | 1 | 0 | 0 | |
| 8 | Rewind | 1 | 16 | 0 | 0 | |
| 9 | Column | 1 | 1 | 3 | 0 | |
| 10 | Column | 1 | 2 | 4 | 0 | |
| 11 | Rowid | 1 | 5 | 0 | 0 | |
| 12 | MakeRecord | 3 | 3 | 2 | 0 | |
| 13 | FilterAdd | 1 | 0 | 3 | 1 | 0 |
| 14 | IdxInsert | 3 | 2 | 0 | 16 | |
| 15 | Next | 1 | 9 | 0 | 3 | |
| 16 | Integer | 0 | 6 | 0 | 0 | |
| 17 | IdxRowid | 2 | 7 | 0 | 0 | |
| 18 | Filter | 1 | 26 | 7 | 1 | 0 |
| 19 | SeekGE | 3 | 26 | 7 | 1 | 0 |
| 20 | IdxGT | 3 | 26 | 7 | 1 | 0 |
| 21 | Integer | 1 | 6 | 0 | 0 | |
| 22 | Column | 2 | 0 | 8 | 0 | |
| 23 | Column | 3 | 1 | 9 | 0 | |
| 24 | ResultRow | 8 | 2 | 0 | 0 | |
| 25 | Next | 3 | 20 | 0 | 0 | |
| 26 | IfPos | 6 | 29 | 0 | 0 | |
| 27 | NullRow | 3 | 0 | 0 | 0 | |
| 28 | Goto | 0 | 21 | 0 | 0 | |
| 29 | Next | 2 | 4 | 0 | 1 | |
| 30 | Halt | 0 | 0 | 0 | 0 | |
| 31 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 32 | Goto | 0 | 1 | 0 | 0 |
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.