SQLite VDBE opcode

Lt

Compare the values in register P1 and 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

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

SELECT * FROM tracks WHERE (album_id, id) < (5, 10)
addropcodep1p2p3p4p5
0Init02800
1OpenRead04060
2OpenRead150k(2,,)0
3Rewind127100
4Integer5100
5IsNull12700
6IdxGT127110
7DeferredSeek1000
8Integer1200
9Column1030
10Lt4173BINARY-868
11ElseEq01400
12ZeroOrNull3240
13Goto01700
14IdxRowid1300
15Lt517368
16ZeroOrNull3250
17IfNot22610
18IdxRowid1600
19Column1070
20Column0280
21Column0390
22Column04100
23Column05110
24RealAffinity11000
25ResultRow6600
26Next1600
27Halt0000
28Transaction00101
29Integer5400
30Integer10500
31Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, DeferredSeek, ElseEq, Goto, Halt, IdxGT, IdxRowid, IfNot, Init, Integer, IsNull, Next, OpenRead, RealAffinity, ResultRow, Rewind, Transaction, ZeroOrNull.

What the SQLite documentation says

Compare the values in register P1 and P3. If reg(P3)<reg(P1) then jump to address P2.

If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL bit is clear then fall through if either operand is NULL.

The SQLITE_AFF_MASK portion of P5 must be an affinity character - SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made to coerce both inputs according to this affinity before the comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric affinity is used. Note that the affinity conversions are stored back into the input registers P1 and P3. So this opcode can cause persistent changes to registers P1 and P3.

Once any conversions have taken place, and neither value is NULL, the values are compared. If both values are blobs then memcmp() is used to determine the results of the comparison. If both values are text, then the appropriate collating function specified in P4 is used to do the comparison. If P4 is not specified then memcmp() is used to compare text string. If both values are numeric, then a numeric comparison is used. If the two values are of different types, then numbers are considered less than strings and strings are considered less than blobs.

This opcode saves the result of comparison for use by the new Jump opcode.

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.

← LoadAnalysis · MakeRecord →