SQLite VDBE opcode

Count

Store the number of entries (an integer value) in the table or index opened by cursor P1 in register P2.

An example

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

SELECT count(*) FROM tracks
addropcodep1p2p3p4p5
0Init0700
1OpenRead1190k(2,,)0
2Count1100
3Close1000
4Copy1200
5ResultRow2100
6Halt0000
7Transaction00101
8Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Close, Copy, Goto, Halt, Init, OpenRead, ResultRow, Transaction.

What the SQLite documentation says

Store the number of entries (an integer value) in the table or index opened by cursor P1 in register P2.

If P3==0, then an exact count is obtained, which involves visiting every btree page of the table. But if P3 is non-zero, an estimate is returned based on the current cursor position.

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.

← Copy · CreateBtree →