SQLite VDBE opcode

Compare

Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this vector "A") and in reg(P2)..reg(P2+P3-1) ("B").

An example

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

SELECT album_id, count(*), sum(ms) FROM tracks GROUP BY album_id
addropcodep1p2p3p4p5
0Init03900
1Noop1200
2Integer0200
3Null0550
4Gosub43500
5OpenRead04040
6OpenRead250k(2,,)0
7Rewind223700
8DeferredSeek2000
9Column2060
10Compare561k(1,B)0
11Jump1216120
12Gosub32700
13Move6510
14IfPos23800
15Gosub43500
16AggStep009count(0)0
17Column03110
18AggStep01110sum(1)1
19If12100
20Column2070
21Integer1100
22Next2801
23Gosub32700
24Goto03800
25Integer1200
26Return3000
27IfPos12900
28Return3000
29AggFinal900count(0)0
30AggFinal1010sum(1)0
31Copy71200
32Copy91310
33ResultRow12300
34Return3000
35Null07100
36Integer0100
37Return4000
38Halt0000
39Transaction00101
40Null0550
41Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: AggFinal, AggStep, Column, Copy, DeferredSeek, Gosub, Goto, Halt, If, IfPos, Init, Integer, Jump, Move, Next, Noop, Null, OpenRead, ResultRow, Return, Rewind, Transaction.

What the SQLite documentation says

Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of the comparison for use by the next Jump instruct.

If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is determined by the most recent Permutation operator. If the OPFLAG_PERMUTE bit is clear, then register are compared in sequential order.

P4 is a KeyInfo structure that defines collating sequences and sort orders for the comparison. The permutation applies to registers only. The KeyInfo elements are used sequentially.

The comparison is a sort comparison, so NULLs compare equal, NULLs are less than numbers, numbers are less than strings, and strings are less than blobs.

This opcode must be immediately followed by an 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.

← ColumnsUsed · Concat →