AggFinal
P1 is the memory location that is the accumulator for an aggregate or window function.
An example
16 of the 178 statements we compiled against the sample database use AggFinal. This is the one with the shortest program; the rows that use AggFinal are highlighted.
SELECT group_concat(name) FROM artists
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 11 | 0 | 0 | |
| 1 | Null | 0 | 1 | 2 | 0 | |
| 2 | OpenRead | 1 | 6 | 0 | k(2,,) | 0 |
| 3 | Rewind | 1 | 7 | 3 | 0 | 0 |
| 4 | Column | 1 | 0 | 3 | 0 | |
| 5 | AggStep | 0 | 3 | 2 | group_concat(1) | 1 |
| 6 | Next | 1 | 4 | 0 | 1 | |
| 7 | AggFinal | 2 | 1 | 0 | group_concat(1) | 0 |
| 8 | Copy | 2 | 4 | 0 | 0 | |
| 9 | ResultRow | 4 | 1 | 0 | 0 | |
| 10 | Halt | 0 | 0 | 0 | 0 | |
| 11 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 12 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: AggStep, Column, Copy, Goto, Halt, Init, Next, Null, OpenRead, ResultRow, Rewind, Transaction.
What the SQLite documentation says
P1 is the memory location that is the accumulator for an aggregate or window function. Execute the finalizer function for an aggregate and store the result in P1.
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.
← Affinity · AggInverse →