Skip to content

Instantly share code, notes, and snippets.

@mattrco
Created October 10, 2012 20:02
Show Gist options
  • Save mattrco/3868058 to your computer and use it in GitHub Desktop.
Save mattrco/3868058 to your computer and use it in GitHub Desktop.
VDBE opcodes for adding an index to an integer column
sqlite> EXPLAIN CREATE INDEX IF NOT EXISTS exampleidx ON names (id);
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Trace 0 0 0 00
1 Goto 0 34 0 00
2 CreateIndex 0 1 0 00
3 OpenWrite 0 1 0 5 00
4 NewRowid 0 2 0 00
5 String8 0 3 0 index 00
6 String8 0 4 0 exampleidx 00
7 String8 0 5 0 names 00
8 Copy 1 6 0 00
9 String8 0 7 0 CREATE INDEX exampleidx ON names (id) 00
10 MakeRecord 3 5 8 aaada 00
11 Insert 0 8 2 18
12 Close 0 0 0 00
13 OpenWrite 2 1 0 keyinfo(1,BINARY) 01
14 SorterOpen 3 0 0 keyinfo(1,BINARY) 00
15 OpenRead 1 2 0 2 00
16 Rewind 1 22 0 00
17 Rowid 1 11 0 00
18 Column 1 0 10 00
19 MakeRecord 10 2 9 db 00
20 SorterInsert 3 9 0 00
21 Next 1 17 0 00
22 SorterSort 3 26 0 00
23 SorterData 3 9 0 00
24 IdxInsert 2 9 1 10
25 SorterNext 3 23 0 00
26 Close 1 0 0 00
27 Close 2 0 0 00
28 Close 3 0 0 00
29 Integer 2 9 0 00
30 SetCookie 0 1 9 00
31 ParseSchema 0 0 0 name='exampleidx' AND type='index' 00
32 Expire 0 0 0 00
33 Halt 0 0 0 00
34 Transaction 0 1 0 00
35 VerifyCookie 0 1 0 00
36 TableLock 0 1 1 sqlite_master 00
37 TableLock 0 2 1 names 00
38 Goto 0 2 0 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment