SQLite VDBE opcode

Return

Jump to the address stored in register P1.

An example

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

SELECT title, (SELECT count(*) FROM tracks t WHERE t.album_id = a.id) FROM albums a
addropcodep1p2p3p4p5
0Init02200
1OpenRead03030
2Rewind02100
3Column0210
4BeginSubrtn0300
5Null0440
6Integer1500
7Null0660
8OpenRead250k(2,,)2
9Rowid0700
10SeekGE214710
11IdxGT214710
12AggStep006count(0)0
13Next21110
14AggFinal600count(0)0
15Copy6400
16DecrJumpZero51700
17Return3510
18Copy4200
19ResultRow1200
20Next0301
21Halt0000
22Transaction00101
23Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: AggFinal, AggStep, BeginSubrtn, Column, Copy, DecrJumpZero, Goto, Halt, IdxGT, Init, Integer, Next, Null, OpenRead, ResultRow, Rewind, Rowid, SeekGE, Transaction.

What the SQLite documentation says

Jump to the address stored in register P1. If P1 is a return address register, then this accomplishes a return from a subroutine.

If P3 is 1, then the jump is only taken if register P1 holds an integer values, otherwise execution falls through to the next opcode, and the Return becomes a no-op. If P3 is 0, then register P1 must hold an integer or else an assert() is raised. P3 should be set to 1 when this opcode is used in combination with BeginSubrtn, and set to 0 otherwise.

The value in register P1 is unchanged by this opcode.

P2 is not used by the byte-code engine. However, if P2 is positive and also less than the current address, then the "EXPLAIN" output formatter in the CLI will indent all opcodes from the P2 opcode up to be not including the current Return. P2 should be the first opcode in the subroutine from which this opcode is returning. Thus the P2 value is a byte-code indentation hint. See tag-20220407a in wherecode.c and shell.c.

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.

← ResultRow · Rewind →