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
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 7 | 0 | 0 | |
| 1 | OpenRead | 1 | 19 | 0 | k(2,,) | 0 |
| 2 | Count | 1 | 1 | 0 | 0 | |
| 3 | Close | 1 | 0 | 0 | 0 | |
| 4 | Copy | 1 | 2 | 0 | 0 | |
| 5 | ResultRow | 2 | 1 | 0 | 0 | |
| 6 | Halt | 0 | 0 | 0 | 0 | |
| 7 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 8 | Goto | 0 | 1 | 0 | 0 |
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 →