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
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 50 | 0 | 0 | |
| 1 | Goto | 0 | 20 | 0 | 0 | |
| 2 | Once | 0 | 19 | 0 | 0 | |
| 3 | OpenEphemeral | 0 | 6 | 0 | 0 | |
| 4 | OpenRead | 2 | 4 | 0 | 6 | 0 |
| 5 | Rewind | 2 | 19 | 0 | 0 | |
| 6 | Column | 2 | 3 | 2 | 0 | |
| 7 | Le | 3 | 18 | 2 | BINARY-8 | 84 |
| 8 | Rowid | 2 | 4 | 0 | 0 | |
| 9 | Column | 2 | 1 | 5 | 0 | |
| 10 | Column | 2 | 2 | 6 | 0 | |
| 11 | Column | 2 | 3 | 7 | 0 | |
| 12 | Column | 2 | 4 | 8 | 0 | |
| 13 | Column | 2 | 5 | 9 | 0 | |
| 14 | RealAffinity | 9 | 0 | 0 | 0 | |
| 15 | MakeRecord | 4 | 6 | 2 | 0 | |
| 16 | NewRowid | 0 | 10 | 0 | 0 | |
| 17 | Insert | 0 | 2 | 10 | 8 | |
| 18 | Next | 2 | 6 | 0 | 1 | |
| 19 | Return | 1 | 2 | 0 | 0 | |
| 20 | Gosub | 1 | 2 | 0 | 0 | |
| 21 | OpenDup | 1 | 0 | 0 | 0 | |
| 22 | Null | 0 | 11 | 11 | 0 | |
| 23 | Once | 0 | 25 | 0 | 0 | |
| 24 | Gosub | 1 | 2 | 0 | 0 | |
| 25 | Rewind | 0 | 46 | 0 | 0 | |
| 26 | Once | 0 | 37 | 0 | 0 | |
| 27 | OpenAutoindex | 4 | 2 | 0 | k(2,B,) | 0 |
| 28 | Explain | 28 | 0 | 0 | BLOOM FILTER ON b (album_id=?) | 0 |
| 29 | Blob | 10000 | 12 | 0 | 0 | |
| 30 | Rewind | 1 | 46 | 0 | 0 | |
| 31 | Column | 1 | 1 | 14 | 0 | |
| 32 | Rowid | 1 | 15 | 0 | 0 | |
| 33 | MakeRecord | 14 | 2 | 13 | 0 | |
| 34 | FilterAdd | 12 | 0 | 14 | 1 | 0 |
| 35 | IdxInsert | 4 | 13 | 0 | 16 | |
| 36 | Next | 1 | 31 | 0 | 3 | |
| 37 | Column | 0 | 1 | 16 | 0 | |
| 38 | IsNull | 16 | 45 | 0 | 0 | |
| 39 | Affinity | 16 | 1 | 0 | C | 0 |
| 40 | Filter | 12 | 45 | 16 | 1 | 0 |
| 41 | SeekGE | 4 | 45 | 16 | 1 | 0 |
| 42 | IdxGT | 4 | 45 | 16 | 1 | 0 |
| 43 | AggStep | 0 | 0 | 11 | count(0) | 0 |
| 44 | Next | 4 | 42 | 0 | 0 | |
| 45 | Next | 0 | 26 | 0 | 1 | |
| 46 | AggFinal | 11 | 0 | 0 | count(0) | 0 |
| 47 | Copy | 11 | 17 | 0 | 0 | |
| 48 | ResultRow | 17 | 1 | 0 | 0 | |
| 49 | Halt | 0 | 0 | 0 | 0 | |
| 50 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 51 | Integer | 300000 | 3 | 0 | 0 | |
| 52 | Goto | 0 | 1 | 0 | 0 |
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 →