CreateBtree
Allocate a new b-tree in the main database file if P1==0 or in the TEMP database file if P1==1 or in an attached database if P1>1.
An example
7 of the 178 statements we compiled against the sample database use CreateBtree. This is the one with the shortest program; the rows that use CreateBtree are highlighted.
CREATE TEMP TABLE scratch (x)
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 28 | 0 | 0 | |
| 1 | ReadCookie | 1 | 3 | 2 | 0 | |
| 2 | If | 3 | 5 | 0 | 0 | |
| 3 | SetCookie | 1 | 2 | 4 | 0 | |
| 4 | SetCookie | 1 | 5 | 1 | 0 | |
| 5 | CreateBtree | 1 | 2 | 1 | 0 | |
| 6 | OpenWrite | 0 | 1 | 1 | 5 | 0 |
| 7 | NewRowid | 0 | 1 | 0 | 0 | |
| 8 | Blob | 6 | 3 | 0 | 0 | |
| 9 | Insert | 0 | 3 | 1 | 8 | |
| 10 | Close | 0 | 0 | 0 | 0 | |
| 11 | Close | 0 | 0 | 0 | 0 | |
| 12 | Null | 0 | 4 | 5 | 0 | |
| 13 | Noop | 2 | 0 | 4 | 0 | |
| 14 | OpenWrite | 1 | 1 | 1 | 5 | 0 |
| 15 | SeekRowid | 1 | 17 | 1 | 0 | |
| 16 | Rowid | 1 | 5 | 0 | 0 | |
| 17 | IsNull | 5 | 25 | 0 | 0 | |
| 18 | String8 | 0 | 6 | 0 | table | 0 |
| 19 | String8 | 0 | 7 | 0 | scratch | 0 |
| 20 | String8 | 0 | 8 | 0 | scratch | 0 |
| 21 | Copy | 2 | 9 | 0 | 0 | |
| 22 | String8 | 0 | 10 | 0 | CREATE TABLE scratch (x) | 0 |
| 23 | MakeRecord | 6 | 5 | 4 | BBBDB | 0 |
| 24 | Insert | 1 | 4 | 5 | 0 | |
| 25 | SetCookie | 1 | 1 | 1 | 0 | |
| 26 | ParseSchema | 1 | 0 | 0 | tbl_name='scratch' AND type!='trigger' | 0 |
| 27 | Halt | 0 | 0 | 0 | 0 | |
| 28 | Transaction | 1 | 1 | 0 | 0 | 1 |
| 29 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: Blob, Close, Copy, Goto, Halt, If, Init, Insert, IsNull, MakeRecord, NewRowid, Noop, Null, OpenWrite, ParseSchema, ReadCookie, Rowid, SeekRowid, SetCookie, String8, Transaction.
What the SQLite documentation says
Allocate a new b-tree in the main database file if P1==0 or in the TEMP database file if P1==1 or in an attached database if P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table. The root page number of the new b-tree is stored in register P2.
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.
← Count · CursorHint →