SQLite VDBE opcode

SeekGE

If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as the 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

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

SELECT name FROM artists WHERE name BETWEEN 'A' AND 'F'
addropcodep1p2p3p4p5
0Init01000
1OpenRead160k(2,,)0
2String8010A0
3SeekGE19110
4String8010F0
5IdxGT19110
6Column1020
7ResultRow2100
8Next1500
9Halt0000
10Transaction00101
11Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Goto, Halt, IdxGT, Init, Next, OpenRead, 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 the 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 smallest entry that is greater than or equal to the key value. If there are no records greater than or equal to the key and P2 is not zero, then jump to P2.

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 IdxGT opcode will be skipped if this opcode succeeds, but the IdxGT 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.

This opcode leaves the cursor configured to move in forward order, from the beginning toward the end. In other words, the cursor is configured to use Next, not Prev.

See also: Found, NotFound, SeekLt, SeekGt, SeekLe

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.

← SeekEnd · SeekGT →