SQLite VDBE opcode

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
addropcodep1p2p3p4p5
0Init01100
1Null0120
2OpenRead160k(2,,)0
3Rewind17300
4Column1030
5AggStep032group_concat(1)1
6Next1401
7AggFinal210group_concat(1)0
8Copy2400
9ResultRow4100
10Halt0000
11Transaction00101
12Goto0100

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 →