AggValue
Invoke the xValue() function and store the result in register P3.
An example
4 of the 178 statements we compiled against the sample database use AggValue. This is the one with the shortest program; the rows that use AggValue are highlighted.
SELECT name, row_number() OVER (ORDER BY ms) FROM tracks
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 59 | 0 | 0 | |
| 1 | Null | 0 | 1 | 0 | 0 | |
| 2 | InitCoroutine | 3 | 19 | 3 | 0 | |
| 3 | SorterOpen | 6 | 4 | 0 | k(1,B) | 0 |
| 4 | OpenRead | 0 | 4 | 0 | 4 | 0 |
| 5 | Rewind | 0 | 11 | 0 | 0 | |
| 6 | Column | 0 | 2 | 5 | 0 | |
| 7 | Column | 0 | 3 | 4 | 0 | |
| 8 | MakeRecord | 4 | 2 | 7 | 0 | |
| 9 | SorterInsert | 6 | 7 | 4 | 2 | 0 |
| 10 | Next | 0 | 6 | 0 | 1 | |
| 11 | OpenPseudo | 7 | 8 | 4 | 0 | |
| 12 | SorterSort | 6 | 18 | 0 | 0 | |
| 13 | SorterData | 6 | 8 | 7 | 0 | |
| 14 | Column | 7 | 0 | 6 | 0 | |
| 15 | Column | 7 | 1 | 5 | 0 | |
| 16 | Yield | 3 | 0 | 0 | 0 | |
| 17 | SorterNext | 6 | 13 | 0 | 0 | |
| 18 | EndCoroutine | 3 | 0 | 0 | 0 | |
| 19 | OpenEphemeral | 1 | 2 | 0 | 0 | |
| 20 | OpenDup | 2 | 1 | 0 | 0 | |
| 21 | OpenDup | 3 | 1 | 0 | 0 | |
| 22 | OpenDup | 4 | 1 | 0 | 0 | |
| 23 | Integer | 1 | 9 | 0 | 0 | |
| 24 | InitCoroutine | 3 | 0 | 3 | 0 | |
| 25 | Yield | 3 | 43 | 0 | 0 | |
| 26 | Copy | 5 | 11 | 0 | 2 | |
| 27 | Copy | 6 | 12 | 0 | 2 | |
| 28 | MakeRecord | 11 | 2 | 13 | 0 | |
| 29 | NewRowid | 2 | 14 | 0 | 0 | |
| 30 | Insert | 2 | 13 | 14 | 0 | |
| 31 | Ne | 9 | 36 | 14 | 0 | |
| 32 | Null | 0 | 1 | 0 | 0 | |
| 33 | Rewind | 1 | 0 | 0 | 0 | |
| 34 | Rewind | 4 | 0 | 0 | 0 | |
| 35 | Goto | 0 | 42 | 0 | 0 | |
| 36 | AggStep | 0 | 15 | 1 | row_number(0) | 0 |
| 37 | Next | 4 | 38 | 0 | 0 | |
| 38 | AggValue | 1 | 0 | 2 | row_number(0) | 0 |
| 39 | Gosub | 10 | 54 | 0 | 0 | |
| 40 | Delete | 1 | 0 | 0 | 2 | |
| 41 | Next | 1 | 42 | 0 | 0 | |
| 42 | Goto | 0 | 25 | 0 | 0 | |
| 43 | Rewind | 2 | 52 | 0 | 0 | |
| 44 | AggStep | 0 | 15 | 1 | row_number(0) | 0 |
| 45 | Next | 4 | 46 | 0 | 0 | |
| 46 | AggValue | 1 | 0 | 2 | row_number(0) | 0 |
| 47 | Gosub | 10 | 54 | 0 | 0 | |
| 48 | Delete | 1 | 0 | 0 | 2 | |
| 49 | Next | 1 | 51 | 0 | 0 | |
| 50 | Goto | 0 | 52 | 0 | 0 | |
| 51 | Goto | 0 | 46 | 0 | 0 | |
| 52 | ResetSorter | 1 | 0 | 0 | 0 | |
| 53 | Goto | 0 | 58 | 0 | 0 | |
| 54 | Column | 1 | 0 | 15 | 0 | |
| 55 | Copy | 2 | 16 | 0 | 0 | |
| 56 | ResultRow | 15 | 2 | 0 | 0 | |
| 57 | Return | 10 | 0 | 0 | 0 | |
| 58 | Halt | 0 | 0 | 0 | 0 | |
| 59 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 60 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: AggStep, Column, Copy, Delete, EndCoroutine, Gosub, Goto, Halt, Init, InitCoroutine, Insert, Integer, MakeRecord, Ne, NewRowid, Next, Null, OpenDup, OpenEphemeral, OpenPseudo, OpenRead, ResetSorter, ResultRow, Return, Rewind, SorterData, SorterInsert, SorterNext, SorterOpen, SorterSort, Transaction, Yield.
What the SQLite documentation says
Invoke the xValue() function and store the result in register P3.
P2 is the number of arguments that the step function takes and P4 is a pointer to the FuncDef for this function. The P2 argument is not used by this opcode. It is only there to disambiguate functions that can take varying numbers of arguments. The P4 argument is only needed for the case where the step function was not previously called.
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.