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 P2 of 52 jumps to 50 P2 of 55 jumps to 53 P2 of 36 jumps to 39 P2 of 43 jumps to 46 P2 of 10 jumps to 6 P2 of 17 jumps to 13 P2 of 27 jumps to 23 P2 of 34 jumps to 30 P2 of 38 jumps to 42 P2 of 45 jumps to 49 P2 of 61 jumps to 65 P2 of 5 jumps to 11 P2 of 12 jumps to 18 P2 of 22 jumps to 28 P2 of 29 jumps to 35 P2 of 50 jumps to 43 P2 of 57 jumps to 50 P2 of 58 jumps to 65 P2 of 60 jumps to 53 P3 of 66 jumps to 59 P2 of 66 jumps to 57 P2 of 63 jumps to 53 P1 of 66 jumps to 56 P2 of 62 jumps to 51 P2 of 54 jumps to 67 P2 of 51 jumps to 67 P2 of 59 jumps to 43 P2 of 2 jumps to 19 P2 of 53 jumps to 36 P2 of 56 jumps to 36 P2 of 19 jumps to 62 P2 of 0 jumps to 68 P2 of 69 jumps to 1 addr opcode p1 p2 p3 p4 p5 0 Init 0 68 0 0 1 Integer 0 1 0 0 2 InitCoroutine 4 19 3 0 3 SorterOpen 2 5 0 k(2,B,B) 0 4 OpenRead 1 2 0 3 0 5 Rewind 1 11 0 0 6 Column 1 2 8 0 7 Column 1 1 9 0 8 MakeRecord 8 2 12 0 9 SorterInsert 2 12 8 2 0 10 Next 1 6 0 1 11 OpenPseudo 3 13 5 0 12 SorterSort 2 18 0 0 13 SorterData 2 13 3 0 14 Column 3 0 11 0 15 Column 3 1 10 0 16 Yield 4 0 0 0 17 SorterNext 2 13 0 0 18 EndCoroutine 4 0 0 0 19 InitCoroutine 5 62 20 0 20 SorterOpen 4 5 0 k(2,B,B) 0 21 OpenRead 0 3 0 4 0 22 Rewind 0 28 0 0 23 Column 0 3 14 0 24 Column 0 2 15 0 25 MakeRecord 14 2 18 0 26 SorterInsert 4 18 14 2 0 27 Next 0 23 0 1 28 OpenPseudo 5 19 5 0 29 SorterSort 4 35 0 0 30 SorterData 4 19 5 0 31 Column 5 0 17 0 32 Column 5 1 16 0 33 Yield 5 0 0 0 34 SorterNext 4 30 0 0 35 EndCoroutine 5 0 0 0 36 IfNot 1 39 0 0 37 Compare 10 2 2 k(2,B,B) 0 38 Jump 39 42 39 0 39 Copy 10 2 1 0 40 Integer 1 1 0 0 41 ResultRow 10 2 0 0 42 Return 6 0 0 0 43 IfNot 1 46 0 0 44 Compare 16 2 2 k(2,B,B) 0 45 Jump 46 49 46 0 46 Copy 16 2 1 0 47 Integer 1 1 0 0 48 ResultRow 16 2 0 0 49 Return 7 0 0 0 50 Gosub 7 43 0 0 51 Yield 5 67 0 0 52 Goto 0 50 0 0 53 Gosub 6 36 0 0 54 Yield 4 67 0 0 55 Goto 0 53 0 0 56 Gosub 6 36 0 0 57 Yield 4 50 0 0 58 Goto 0 65 0 0 59 Gosub 7 43 0 0 60 Yield 5 53 0 0 61 Goto 0 65 0 0 62 Yield 4 51 0 0 63 Yield 5 53 0 0 64 Permutation 0 0 0 [1,0] 0 65 Compare 10 16 2 k(3,B,B,) 1 66 Jump 56 57 59 0 67 Halt 0 0 0 0 68 Transaction 0 0 1 0 1 69 Goto 0 1 0 0
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.
By the author of this site
SQLite compiles every statement into a plan and runs it. A SQL front end with a parser, a planner and an executor is the last part of Build a Database in Rust : Pages, B+trees, a write-ahead log and SQL from scratch, the way SQLite is built.
Read Chapter 1 free Paperback on Amazon
If it is the bytecode interpreter you want to write, see Build a JVM in Rust : Class files, an interpreter, objects and invokedynamic from scratch, on the real JDK class library. Chapter 1 free · Paperback
As an Amazon Associate I earn from qualifying purchases.
← ParseSchema · Prev →
SQLite and its documentation are in the public domain. Opcode and pragma descriptions come from sqlite.org (SQLite 3); thank you to the SQLite developers.
This site is not affiliated with or endorsed by the SQLite project, the PostgreSQL Global Development Group or Oracle. SQLite is a registered trademark of Hipp, Wyrick & Company, Inc.; PostgreSQL and MySQL are trademarks of their owners. The names are used only to say which files the site reads.
Sister sites: LLM Anatomy · Distribution Atlas · Notation Decoder · uresk.net
Made by Spencer Uresk · About · Files you open stay on your device.