SQLite VDBE opcode

OpenDup

Open a new cursor P1 that points to the same ephemeral table as cursor P2.

An example

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

WITH big AS MATERIALIZED (SELECT * FROM tracks WHERE ms > 300000) SELECT count(*) FROM big a JOIN big b ON a.album_id = b.album_id
addropcodep1p2p3p4p5
0Init05000
1Goto02000
2Once01900
3OpenEphemeral0600
4OpenRead24060
5Rewind21900
6Column2320
7Le3182BINARY-884
8Rowid2400
9Column2150
10Column2260
11Column2370
12Column2480
13Column2590
14RealAffinity9000
15MakeRecord4620
16NewRowid01000
17Insert02108
18Next2601
19Return1200
20Gosub1200
21OpenDup1000
22Null011110
23Once02500
24Gosub1200
25Rewind04600
26Once03700
27OpenAutoindex420k(2,B,)0
28Explain2800BLOOM FILTER ON b (album_id=?)0
29Blob100001200
30Rewind14600
31Column11140
32Rowid11500
33MakeRecord142130
34FilterAdd1201410
35IdxInsert413016
36Next13103
37Column01160
38IsNull164500
39Affinity1610C0
40Filter12451610
41SeekGE4451610
42IdxGT4451610
43AggStep0011count(0)0
44Next44200
45Next02601
46AggFinal1100count(0)0
47Copy111700
48ResultRow17100
49Halt0000
50Transaction00101
51Integer300000300
52Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Affinity, AggFinal, AggStep, Blob, Column, Copy, Explain, Filter, FilterAdd, Gosub, Goto, Halt, IdxGT, IdxInsert, Init, Insert, Integer, IsNull, Le, MakeRecord, NewRowid, Next, Null, Once, OpenAutoindex, OpenEphemeral, OpenRead, RealAffinity, ResultRow, Return, Rewind, Rowid, SeekGE, Transaction.

What the SQLite documentation says

Open a new cursor P1 that points to the same ephemeral table as cursor P2. The P2 cursor must have been opened by a prior OpenEphemeral opcode. Only ephemeral cursors may be duplicated.

Duplicate ephemeral cursors are used for self-joins of materialized views.

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.

← OpenAutoindex · OpenEphemeral →