SQLite VDBE opcodes

SQLite runs every SQL statement by compiling it to a program for its virtual machine, the VDBE, and running that program. These are the 191 instructions of SQLite 3.54.1. Each page has the official description and, for 170 of them, a real statement whose program uses it.

To see the program for your own SQL, use the EXPLAIN visualizer. The number after a name is how many of our 178 example statements use it.

AbortableVerify that an Abort can happen.
AddAdd the value in register P1 to the value in register P2 and store the result in register P3.5
AddImmAdd the constant P2 to the value in register P1.9
AffinityApply affinities to a range of P2 registers starting with P1.29
AggFinalP1 is the memory location that is the accumulator for an aggregate or window function.16
AggInverseExecute the xInverse function for an aggregate.2
AggStepExecute the xStep function for an aggregate.19
AggStep1Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an aggregate.
AggValueInvoke the xValue() function and store the result in register P3.4
AndTake the logical AND of the values in registers P1 and P2 and write the result into register P3.1
AutoCommitSet the database auto-commit flag to P1 (1 or 0).4
BeginSubrtnMark the beginning of a subroutine that can be entered in-line or that can be called using Gosub.12
BitAndTake the bit-wise AND of the values in register P1 and P2 and store the result in register P3.1
BitNotInterpret the content of register P1 as an integer.1
BitOrTake the bit-wise OR of the values in register P1 and P2 and store the result in register P3.1
BlobP4 points to a blob of data P1 bytes long.17
CastForce the value in register P1 to be the type defined by P2.1
CheckpointCheckpoint database P1.1
ClearDelete all contents of the database table or index whose root page in the database file is given by P1.2
CloseClose a cursor previously opened as P1.18
ClrSubtypeClear the subtype from register P1.
CollSeqP4 is a pointer to a CollSeq object.6
ColumnInterpret the data that cursor P1 points to as a structure built using the MakeRecord instruction.118
ColumnsUsedThis opcode (which only exists if SQLite was compiled with SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of…
CompareCompare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this vector "A") and in reg(P2)..reg(P2+P3-1) ("B").13
ConcatAdd the text in register P1 onto the end of the text in register P2 and store the result in register P3.6
CopyMake a copy of registers P1..P1+P3 into registers P2..P2+P3.51
CountStore the number of entries (an integer value) in the table or index opened by cursor P1 in register P2.3
CreateBtreeAllocate 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…7
CursorHintProvide a hint to cursor P1.
CursorLockLock the btree to which cursor P1 is pointing so that the btree cannot be written by an other cursor.
CursorUnlockUnlock the btree to which cursor P1 is pointing so that it can be written by other cursors.
DecrJumpZeroRegister P1 must hold an integer.4
DeferredSeekP1 is an open index cursor and P3 is a cursor on the corresponding table.23
DeleteDelete the record at which the P1 cursor is currently pointing.16
DestroyDelete an entire database table or index whose root page in the database file is given by P1.2
DivideDivide the value in register P1 by the value in register P2 and store the result in register P3 (P3=P2/P1).3
DropIndexRemove the internal (in-memory) data structures that describe the index named P4 in database P1.1
DropTableRemove the internal (in-memory) data structures that describe the table named P4 in database P1.3
DropTriggerRemove the internal (in-memory) data structures that describe the trigger named P4 in database P1.1
ElseEqThis opcode must follow an Lt or Gt comparison operator.2
EndCoroutineThe instruction at the address in register P1 is a Yield.16
EqCompare the values in register P1 and P3.9
ExpireCause precompiled statements to expire.18
ExplainThis is the same as Noop during normal query execution.5
FilterCompute a hash on the key contained in the P4 registers starting with r[P3].8
FilterAddCompute a hash on the P4 registers starting with r[P3] and add that hash to the bloom filter contained in r[P1].9
FinishSeekIf cursor P1 was previously moved via DeferredSeek, complete that seek operation now, without further delay.
FkCheckHalt with an SQLITE_CONSTRAINT error if there are any unresolved foreign key constraint violations.1
FkCounterIncrement a "constraint counter" by P2 (P2 may be negative or positive).7
FkIfZeroThis opcode tests if a foreign key constraint-counter is currently zero.6
FoundIf P4==0 then register P3 holds a blob constructed by MakeRecord.7
FunctionInvoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run)…25
GeThis works just like the Lt opcode except that the jump is taken if the content of register P3 is greater than or equal…6
GetSubtypeExtract the subtype value from register P1 and write that subtype into register P2.
GosubWrite the current address onto register P1 and then jump to address P2.19
GotoAn unconditional jump to address P2.178
GtThis works just like the Lt opcode except that the jump is taken if the content of register P3 is greater than the…6
HaltExit immediately. All open cursors, etc are closed automatically.178
HaltIfNullCheck the value in register P3.12
IdxDeleteThe content of P5 registers starting at register P2 form an unpacked index key.5
IdxGEThe P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY.2
IdxGTThe P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY.31
IdxInsertRegister P2 holds an SQL index key made using the MakeRecord instructions.37
IdxLEThe P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY or ROWID.3
IdxLTThe P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY or ROWID.1
IdxRowidWrite into register P2 an integer which is the last entry in the record at the end of the index key pointed to by…24
IfJump to P2 if the value in register P1 is true.17
IfEmptyCheck to see if the b-tree table that cursor P1 references is empty and jump to P2 if it is.
IFindKeyThis instruction always follows an Found with the same P1, P2 and P3 values as this instruction and a non-zero P4 value.1
IfNoHopeRegister P3 is the first of P4 registers that form an unpacked record.
IfNotJump to P2 if the value in register P1 is False.16
IfNotZeroRegister P1 must contain an integer.4
IfNullRowCheck the cursor P1 to see if it is currently pointing at a NULL row.5
IfPosRegister P1 must contain an integer.14
IfSizeBetweenLet N be the approximate number of rows in the table or index with cursor P1 and let X be 10*log2(N) if N is positive…
IncrVacuumPerform a single step of the incremental vacuum procedure on the P1 database.1
InitPrograms contain a single instance of this opcode as the very first opcode.178
InitCoroutineSet up register P1 so that it will Yield to the coroutine located at address P3.16
InsertWrite an entry into the table of cursor P1.38
Int64Combine P1 and P3 into a signed 64-bit integer.1
IntCopyTransfer the integer value held in register P1 into register P2.9
IntegerThe 32-bit integer value P1 is written into register P2.82
IntegrityCkDo an analysis of the currently open database.2
IsNullJump to P2 if the value in register P1 is NULL.40
IsTrueThis opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and IS NOT FALSE operators.1
IsTypeJump to P2 if the type of a column in a btree is one of the types specified by the P5 bitmask.2
JournalModeChange the journal mode of database P1 to P3.1
JumpJump to the instruction at address P1, P2, or P3 depending on whether in the most recent Compare instruction the P1…13
LastThe next use of the Rowid or Column or Prev instruction for P1 will refer to the last entry in the database table or…6
LeThis works just like the Lt opcode except that the jump is taken if the content of register P3 is less than or equal to…12
LoadAnalysisRead the sqlite_stat1 table for database P1 and load the content of that table into the internal index hash table.2
LtCompare the values in register P1 and P3.1
MakeRecordConvert P2 registers beginning with P1 into the record format use as a data record in a database table or as a key in…68
MaxPgcntTry to set the maximum page count for database P1 to the value in P3.1
MemMaxP1 is a register in the root frame of this VM (the root frame is different from the current frame if this instruction…2
MoveMove the P3 values in register P1..P1+P3-1 over into registers P2..P2+P3-1.6
MultiplyMultiply the value in register P1 by the value in register P2 and store the result in register P3.8
MustBeIntForce the value in register P1 to be an integer.8
NeThis works just like the Eq opcode except that the jump is taken if the operands in registers P1 and P3 are not equal.28
NewRowidGet a new integer record number (a.k.a "rowid") used as the key to a table.26
NextAdvance cursor P1 so that it points to the next key/data pair in its table or index.112
NoConflictIf P4==0 then register P3 holds a blob constructed by MakeRecord.4
NoopDo nothing. Continue downward to the next opcode.33
NotInterpret the value in register P1 as a boolean value.1
NotExistsP1 is the index of a cursor open on an SQL table btree (with integer keys).15
NotFoundIf P4==0 then register P3 holds a blob constructed by MakeRecord.2
NotNullJump to P2 if the value in register P1 is not NULL.8
NullWrite a NULL into registers P2.66
NullRowMove the cursor P1 to a null row if P2 is 0.13
OffsetStore in register r[P3] the byte offset into the database file that is the start of the payload for the record at which…
OffsetLimitThis opcode performs a commonly used computation associated with LIMIT and OFFSET processing.1
OnceFall through to the next instruction the first time this opcode is encountered on each invocation of the byte-code…21
OpenAutoindexThis opcode works the same as OpenEphemeral.5
OpenDupOpen a new cursor P1 that points to the same ephemeral table as cursor P2.5
OpenEphemeralOpen a new cursor P1 to a transient table.33
OpenPseudoOpen a new cursor that points to a fake table that contains a single row of data.13
OpenReadOpen a read-only cursor for the database table whose root page is P2 in a database file.117
OpenWriteOpen a read/write cursor named P1 on the table or index whose root page is P2 (or whose root page is held in register…43
OrTake the logical OR of the values in register P1 and P2 and store the answer in register P3.1
PagecountWrite the current number of pages in database P1 to memory cell P2.1
ParamThis opcode is only ever present in sub-programs called via the Program instruction.3
ParseSchemaRead and parse all entries from the schema table of database P1 that match the WHERE clause P4.15
PermutationSet the permutation used by the Compare operator in the next instruction.1
PrevBack up cursor P1 so that it points to the previous key/data pair in its table or index.6
ProgramExecute the trigger program passed as P4 (type P4_SUBPROGRAM).3
PureFuncInvoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run)…8
ReadCookieRead cookie number P3 from database P1 and write it into register P2.11
RealP1 and P3 are combined to 64 bits with P1 being the lower the P3 the upper.3
RealAffinityIf register P1 holds an integer convert it to a real value.25
ReleaseRegRelease registers from service.
RemainderCompute the remainder after integer register P2 is divided by register P1 and store the result in register P3.1
ReopenIdxThe ReopenIdx opcode works like OpenRead except that it first checks to see if the cursor on P1 is already open on the…1
ResetCountThe value of the change counter is copied to the database handle change counter (returned by subsequent calls to…3
ResetSorterDelete all contents from the ephemeral table or sorter that is open on cursor P1.4
ResultRowThe registers P1 through P1+P2-1 contain a single row of results.125
ReturnJump to the address stored in register P1.29
RewindThe next use of the Rowid or Column or Next instruction for P1 will refer to the first entry in the database table or…101
RowCellP1 and P2 are both open cursors.1
RowDataWrite into register P2 the complete row content for the row at which cursor P1 is currently pointing.2
RowidStore in register P2 an integer which is the key of the table entry that P1 is currently point to.59
RowSetAddInsert the integer value held by register P2 into a RowSet object held in register P1.2
RowSetReadExtract the smallest value from the RowSet object in P1 and put that value into register P3.2
RowSetTestRegister P3 is assumed to hold a 64-bit integer value.1
SavepointOpen, release or rollback the savepoint named by parameter P4, depending on the value of P1.2
SCopyMake a shallow copy of register P1 into register P2.19
SeekEndPosition cursor P1 at the end of the btree for the purpose of appending a new entry onto the btree.3
SeekGEIf cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as the key.28
SeekGTIf cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key.5
SeekHitIncrease or decrease the seekHit value for cursor P1, if necessary, so that it is no less than P2 and no greater than…
SeekLEIf cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key.1
SeekLTIf cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key.1
SeekRowidP1 is the index of a cursor open on an SQL table btree (with integer keys).20
SeekScanThis opcode is a prefix opcode to SeekGE.
SequenceFind the next available sequence number for cursor P1.2
SequenceTestP1 is a sorter cursor.
SetCookieWrite the integer value P3 into cookie number P2 of database P1.21
SetSubtypeSet the subtype value of register P2 to the integer from register P1.
ShiftLeftShift the integer value in register P2 to the left by the number of bits specified by the integer in register P1.1
ShiftRightShift the integer value in register P2 to the right by the number of bits specified by the integer in register P1.1
SoftNullSet register P1 to have the value NULL as seen by the MakeRecord instruction, but do not free any string or blob memory…9
SortThis opcode does exactly the same thing as Rewind except that it increments an undocumented global variable used for…2
SorterCompareP1 is a sorter cursor.1
SorterDataWrite into register P2 the current sorter data for sorter cursor P1.15
SorterInsertRegister P2 holds an SQL index key made using the MakeRecord instructions.15
SorterNextThis opcode works just like Next except that P1 must be a sorter object for which the SorterSort opcode has been…15
SorterOpenThis opcode works like OpenEphemeral except that it opens a transient index that is specifically designed to sort large…15
SorterSortAfter all records have been inserted into the Sorter object identified by P1, invoke this opcode to actually do the…15
SqlExecRun the SQL statement or statements specified in the P4 string.1
StringThe string value P4 of length P1 (bytes) is stored in register P2.
String8P4 points to a nul terminated UTF-8 string.57
SubtractSubtract the value in register P1 from the value in register P2 and store the result in register P3.1
TableLockObtain a lock on a particular table.
TraceWrite P4 on the statement trace output if statement tracing is enabled.2
TransactionBegin a transaction on database P1 if a transaction is not already active.151
TypeCheckApply affinities to the range of P2 registers beginning with P1.6
VacuumVacuum the entire database P1.2
VariableTransfer the values of bound parameter P1 into register P210
VBeginP4 may be a pointer to an sqlite3_vtab structure.4
VCheckP4 is a pointer to a Table object that is a virtual table in schema P1 that supports the xIntegrity() method.2
VColumnStore in register P3 the value of the P2-th column of the current row of the virtual-table of cursor P1.5
VCreateP2 is a register that holds the name of a virtual table in database P1.1
VDestroyP4 is the name of a virtual table in database P1.1
VFilterP1 is a cursor opened using VOpen.5
VInitInSet register P2 to be a pointer to a ValueList object for cursor P1 with cache register P3 and output register P3+1.
VNextAdvance virtual table P1 to the next row in its result set and jump to instruction P2.5
VOpenP4 is a pointer to a virtual table object, an sqlite3_vtab structure.5
VRenameP4 is a pointer to a virtual table object, an sqlite3_vtab structure.1
VUpdateP4 is a pointer to a virtual table object, an sqlite3_vtab structure.2
YieldSwap the program counter with the value in register P1.16
ZeroOrNullIf both registers P1 and P3 are NOT NULL, then store a zero in register P2.4