SQLite VDBE opcode

Permutation

Set the permutation used by the Compare operator in the next instruction.

An example

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

SELECT name, country FROM artists UNION SELECT title, year FROM albums ORDER BY 2
addropcodep1p2p3p4p5
0Init06800
1Integer0100
2InitCoroutine41930
3SorterOpen250k(2,B,B)0
4OpenRead12030
5Rewind11100
6Column1280
7Column1190
8MakeRecord82120
9SorterInsert212820
10Next1601
11OpenPseudo31350
12SorterSort21800
13SorterData21330
14Column30110
15Column31100
16Yield4000
17SorterNext21300
18EndCoroutine4000
19InitCoroutine562200
20SorterOpen450k(2,B,B)0
21OpenRead03040
22Rewind02800
23Column03140
24Column02150
25MakeRecord142180
26SorterInsert4181420
27Next02301
28OpenPseudo51950
29SorterSort43500
30SorterData41950
31Column50170
32Column51160
33Yield5000
34SorterNext43000
35EndCoroutine5000
36IfNot13900
37Compare1022k(2,B,B)0
38Jump3942390
39Copy10210
40Integer1100
41ResultRow10200
42Return6000
43IfNot14600
44Compare1622k(2,B,B)0
45Jump4649460
46Copy16210
47Integer1100
48ResultRow16200
49Return7000
50Gosub74300
51Yield56700
52Goto05000
53Gosub63600
54Yield46700
55Goto05300
56Gosub63600
57Yield45000
58Goto06500
59Gosub74300
60Yield55300
61Goto06500
62Yield45100
63Yield55300
64Permutation000[1,0]0
65Compare10162k(3,B,B,)1
66Jump5657590
67Halt0000
68Transaction00101
69Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Compare, Copy, EndCoroutine, Gosub, Goto, Halt, IfNot, Init, InitCoroutine, Integer, Jump, MakeRecord, Next, OpenPseudo, OpenRead, ResultRow, Return, Rewind, SorterData, SorterInsert, SorterNext, SorterOpen, SorterSort, Transaction, Yield.

What the SQLite documentation says

Set the permutation used by the Compare operator in the next instruction. The permutation is stored in the P4 operand.

The permutation is only valid for the next opcode which must be an Compare that has the OPFLAG_PERMUTE bit set in P5.

The first integer in the P4 integer array is the length of the array and does not become part of the permutation.

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.

← ParseSchema · Prev →