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)
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 28 | 0 | 0 | |
| 1 | OpenRead | 0 | 4 | 0 | 6 | 0 |
| 2 | OpenRead | 1 | 5 | 0 | k(2,,) | 0 |
| 3 | Rewind | 1 | 27 | 1 | 0 | 0 |
| 4 | Integer | 5 | 1 | 0 | 0 | |
| 5 | IsNull | 1 | 27 | 0 | 0 | |
| 6 | IdxGT | 1 | 27 | 1 | 1 | 0 |
| 7 | DeferredSeek | 1 | 0 | 0 | 0 | |
| 8 | Integer | 1 | 2 | 0 | 0 | |
| 9 | Column | 1 | 0 | 3 | 0 | |
| 10 | Lt | 4 | 17 | 3 | BINARY-8 | 68 |
| 11 | ElseEq | 0 | 14 | 0 | 0 | |
| 12 | ZeroOrNull | 3 | 2 | 4 | 0 | |
| 13 | Goto | 0 | 17 | 0 | 0 | |
| 14 | IdxRowid | 1 | 3 | 0 | 0 | |
| 15 | Lt | 5 | 17 | 3 | 68 | |
| 16 | ZeroOrNull | 3 | 2 | 5 | 0 | |
| 17 | IfNot | 2 | 26 | 1 | 0 | |
| 18 | IdxRowid | 1 | 6 | 0 | 0 | |
| 19 | Column | 1 | 0 | 7 | 0 | |
| 20 | Column | 0 | 2 | 8 | 0 | |
| 21 | Column | 0 | 3 | 9 | 0 | |
| 22 | Column | 0 | 4 | 10 | 0 | |
| 23 | Column | 0 | 5 | 11 | 0 | |
| 24 | RealAffinity | 11 | 0 | 0 | 0 | |
| 25 | ResultRow | 6 | 6 | 0 | 0 | |
| 26 | Next | 1 | 6 | 0 | 0 | |
| 27 | Halt | 0 | 0 | 0 | 0 | |
| 28 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 29 | Integer | 5 | 4 | 0 | 0 | |
| 30 | Integer | 10 | 5 | 0 | 0 | |
| 31 | Goto | 0 | 1 | 0 | 0 |
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 →