SeekLE
If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key.
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
1 of the 178 statements we compiled against the sample database use SeekLE. This is the one with the shortest program; the rows that use SeekLE are highlighted.
SELECT * FROM artists WHERE name <= 'M' ORDER BY name DESC
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 13 | 0 | 0 | |
| 1 | Noop | 1 | 5 | 0 | 0 | |
| 2 | OpenRead | 0 | 2 | 0 | 3 | 0 |
| 3 | OpenRead | 2 | 6 | 0 | k(2,,) | 0 |
| 4 | String8 | 0 | 1 | 0 | M | 0 |
| 5 | SeekLE | 2 | 12 | 1 | 1 | 0 |
| 6 | DeferredSeek | 2 | 0 | 0 | 0 | |
| 7 | IdxRowid | 2 | 2 | 0 | 0 | |
| 8 | Column | 2 | 0 | 3 | 0 | |
| 9 | Column | 0 | 2 | 4 | 0 | |
| 10 | ResultRow | 2 | 3 | 0 | 0 | |
| 11 | Prev | 2 | 6 | 0 | 0 | |
| 12 | Halt | 0 | 0 | 0 | 0 | |
| 13 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 14 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Column, DeferredSeek, Goto, Halt, IdxRowid, Init, Noop, OpenRead, Prev, ResultRow, String8, Transaction.
What the SQLite documentation says
If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key. If cursor P1 refers to an SQL index, then P3 is the first in an array of P4 registers that are used as an unpacked index key.
Reposition cursor P1 so that it points to the largest entry that is less than or equal to the key value. If there are no records less than or equal to the key and P2 is not zero, then jump to P2.
This opcode leaves the cursor configured to move in reverse order, from the end toward the beginning. In other words, the cursor is configured to use Prev, not Next.
If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this opcode will either land on a record that exactly matches the key, or else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ, this opcode must be followed by an IdxLE opcode with the same arguments. The IdxGE opcode will be skipped if this opcode succeeds, but the IdxGE opcode will be used on subsequent loop iterations. The OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this is an equality search.
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.