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.
| Abortable | Verify that an Abort can happen. | |
| Add | Add the value in register P1 to the value in register P2 and store the result in register P3. | 5 |
| AddImm | Add the constant P2 to the value in register P1. | 9 |
| Affinity | Apply affinities to a range of P2 registers starting with P1. | 29 |
| AggFinal | P1 is the memory location that is the accumulator for an aggregate or window function. | 16 |
| AggInverse | Execute the xInverse function for an aggregate. | 2 |
| AggStep | Execute the xStep function for an aggregate. | 19 |
| AggStep1 | Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an aggregate. | |
| AggValue | Invoke the xValue() function and store the result in register P3. | 4 |
| And | Take the logical AND of the values in registers P1 and P2 and write the result into register P3. | 1 |
| AutoCommit | Set the database auto-commit flag to P1 (1 or 0). | 4 |
| BeginSubrtn | Mark the beginning of a subroutine that can be entered in-line or that can be called using Gosub. | 12 |
| BitAnd | Take the bit-wise AND of the values in register P1 and P2 and store the result in register P3. | 1 |
| BitNot | Interpret the content of register P1 as an integer. | 1 |
| BitOr | Take the bit-wise OR of the values in register P1 and P2 and store the result in register P3. | 1 |
| Blob | P4 points to a blob of data P1 bytes long. | 17 |
| Cast | Force the value in register P1 to be the type defined by P2. | 1 |
| Checkpoint | Checkpoint database P1. | 1 |
| Clear | Delete all contents of the database table or index whose root page in the database file is given by P1. | 2 |
| Close | Close a cursor previously opened as P1. | 18 |
| ClrSubtype | Clear the subtype from register P1. | |
| CollSeq | P4 is a pointer to a CollSeq object. | 6 |
| Column | Interpret the data that cursor P1 points to as a structure built using the MakeRecord instruction. | 118 |
| ColumnsUsed | This opcode (which only exists if SQLite was compiled with SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of… | |
| Compare | Compare 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 |
| Concat | Add the text in register P1 onto the end of the text in register P2 and store the result in register P3. | 6 |
| Copy | Make a copy of registers P1..P1+P3 into registers P2..P2+P3. | 51 |
| Count | Store the number of entries (an integer value) in the table or index opened by cursor P1 in register P2. | 3 |
| CreateBtree | Allocate 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 |
| CursorHint | Provide a hint to cursor P1. | |
| CursorLock | Lock the btree to which cursor P1 is pointing so that the btree cannot be written by an other cursor. | |
| CursorUnlock | Unlock the btree to which cursor P1 is pointing so that it can be written by other cursors. | |
| DecrJumpZero | Register P1 must hold an integer. | 4 |
| DeferredSeek | P1 is an open index cursor and P3 is a cursor on the corresponding table. | 23 |
| Delete | Delete the record at which the P1 cursor is currently pointing. | 16 |
| Destroy | Delete an entire database table or index whose root page in the database file is given by P1. | 2 |
| Divide | Divide the value in register P1 by the value in register P2 and store the result in register P3 (P3=P2/P1). | 3 |
| DropIndex | Remove the internal (in-memory) data structures that describe the index named P4 in database P1. | 1 |
| DropTable | Remove the internal (in-memory) data structures that describe the table named P4 in database P1. | 3 |
| DropTrigger | Remove the internal (in-memory) data structures that describe the trigger named P4 in database P1. | 1 |
| ElseEq | This opcode must follow an Lt or Gt comparison operator. | 2 |
| EndCoroutine | The instruction at the address in register P1 is a Yield. | 16 |
| Eq | Compare the values in register P1 and P3. | 9 |
| Expire | Cause precompiled statements to expire. | 18 |
| Explain | This is the same as Noop during normal query execution. | 5 |
| Filter | Compute a hash on the key contained in the P4 registers starting with r[P3]. | 8 |
| FilterAdd | Compute a hash on the P4 registers starting with r[P3] and add that hash to the bloom filter contained in r[P1]. | 9 |
| FinishSeek | If cursor P1 was previously moved via DeferredSeek, complete that seek operation now, without further delay. | |
| FkCheck | Halt with an SQLITE_CONSTRAINT error if there are any unresolved foreign key constraint violations. | 1 |
| FkCounter | Increment a "constraint counter" by P2 (P2 may be negative or positive). | 7 |
| FkIfZero | This opcode tests if a foreign key constraint-counter is currently zero. | 6 |
| Found | If P4==0 then register P3 holds a blob constructed by MakeRecord. | 7 |
| Function | Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run)… | 25 |
| Ge | This works just like the Lt opcode except that the jump is taken if the content of register P3 is greater than or equal… | 6 |
| GetSubtype | Extract the subtype value from register P1 and write that subtype into register P2. | |
| Gosub | Write the current address onto register P1 and then jump to address P2. | 19 |
| Goto | An unconditional jump to address P2. | 178 |
| Gt | This works just like the Lt opcode except that the jump is taken if the content of register P3 is greater than the… | 6 |
| Halt | Exit immediately. All open cursors, etc are closed automatically. | 178 |
| HaltIfNull | Check the value in register P3. | 12 |
| IdxDelete | The content of P5 registers starting at register P2 form an unpacked index key. | 5 |
| IdxGE | The P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY. | 2 |
| IdxGT | The P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY. | 31 |
| IdxInsert | Register P2 holds an SQL index key made using the MakeRecord instructions. | 37 |
| IdxLE | The P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY or ROWID. | 3 |
| IdxLT | The P4 register values beginning with P3 form an unpacked index key that omits the PRIMARY KEY or ROWID. | 1 |
| IdxRowid | Write into register P2 an integer which is the last entry in the record at the end of the index key pointed to by… | 24 |
| If | Jump to P2 if the value in register P1 is true. | 17 |
| IfEmpty | Check to see if the b-tree table that cursor P1 references is empty and jump to P2 if it is. | |
| IFindKey | This instruction always follows an Found with the same P1, P2 and P3 values as this instruction and a non-zero P4 value. | 1 |
| IfNoHope | Register P3 is the first of P4 registers that form an unpacked record. | |
| IfNot | Jump to P2 if the value in register P1 is False. | 16 |
| IfNotZero | Register P1 must contain an integer. | 4 |
| IfNullRow | Check the cursor P1 to see if it is currently pointing at a NULL row. | 5 |
| IfPos | Register P1 must contain an integer. | 14 |
| IfSizeBetween | Let 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… | |
| IncrVacuum | Perform a single step of the incremental vacuum procedure on the P1 database. | 1 |
| Init | Programs contain a single instance of this opcode as the very first opcode. | 178 |
| InitCoroutine | Set up register P1 so that it will Yield to the coroutine located at address P3. | 16 |
| Insert | Write an entry into the table of cursor P1. | 38 |
| Int64 | Combine P1 and P3 into a signed 64-bit integer. | 1 |
| IntCopy | Transfer the integer value held in register P1 into register P2. | 9 |
| Integer | The 32-bit integer value P1 is written into register P2. | 82 |
| IntegrityCk | Do an analysis of the currently open database. | 2 |
| IsNull | Jump to P2 if the value in register P1 is NULL. | 40 |
| IsTrue | This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and IS NOT FALSE operators. | 1 |
| IsType | Jump to P2 if the type of a column in a btree is one of the types specified by the P5 bitmask. | 2 |
| JournalMode | Change the journal mode of database P1 to P3. | 1 |
| Jump | Jump to the instruction at address P1, P2, or P3 depending on whether in the most recent Compare instruction the P1… | 13 |
| Last | The next use of the Rowid or Column or Prev instruction for P1 will refer to the last entry in the database table or… | 6 |
| Le | This 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 |
| LoadAnalysis | Read the sqlite_stat1 table for database P1 and load the content of that table into the internal index hash table. | 2 |
| Lt | Compare the values in register P1 and P3. | 1 |
| MakeRecord | Convert P2 registers beginning with P1 into the record format use as a data record in a database table or as a key in… | 68 |
| MaxPgcnt | Try to set the maximum page count for database P1 to the value in P3. | 1 |
| MemMax | P1 is a register in the root frame of this VM (the root frame is different from the current frame if this instruction… | 2 |
| Move | Move the P3 values in register P1..P1+P3-1 over into registers P2..P2+P3-1. | 6 |
| Multiply | Multiply the value in register P1 by the value in register P2 and store the result in register P3. | 8 |
| MustBeInt | Force the value in register P1 to be an integer. | 8 |
| Ne | This works just like the Eq opcode except that the jump is taken if the operands in registers P1 and P3 are not equal. | 28 |
| NewRowid | Get a new integer record number (a.k.a "rowid") used as the key to a table. | 26 |
| Next | Advance cursor P1 so that it points to the next key/data pair in its table or index. | 112 |
| NoConflict | If P4==0 then register P3 holds a blob constructed by MakeRecord. | 4 |
| Noop | Do nothing. Continue downward to the next opcode. | 33 |
| Not | Interpret the value in register P1 as a boolean value. | 1 |
| NotExists | P1 is the index of a cursor open on an SQL table btree (with integer keys). | 15 |
| NotFound | If P4==0 then register P3 holds a blob constructed by MakeRecord. | 2 |
| NotNull | Jump to P2 if the value in register P1 is not NULL. | 8 |
| Null | Write a NULL into registers P2. | 66 |
| NullRow | Move the cursor P1 to a null row if P2 is 0. | 13 |
| Offset | Store in register r[P3] the byte offset into the database file that is the start of the payload for the record at which… | |
| OffsetLimit | This opcode performs a commonly used computation associated with LIMIT and OFFSET processing. | 1 |
| Once | Fall through to the next instruction the first time this opcode is encountered on each invocation of the byte-code… | 21 |
| OpenAutoindex | This opcode works the same as OpenEphemeral. | 5 |
| OpenDup | Open a new cursor P1 that points to the same ephemeral table as cursor P2. | 5 |
| OpenEphemeral | Open a new cursor P1 to a transient table. | 33 |
| OpenPseudo | Open a new cursor that points to a fake table that contains a single row of data. | 13 |
| OpenRead | Open a read-only cursor for the database table whose root page is P2 in a database file. | 117 |
| OpenWrite | Open 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 |
| Or | Take the logical OR of the values in register P1 and P2 and store the answer in register P3. | 1 |
| Pagecount | Write the current number of pages in database P1 to memory cell P2. | 1 |
| Param | This opcode is only ever present in sub-programs called via the Program instruction. | 3 |
| ParseSchema | Read and parse all entries from the schema table of database P1 that match the WHERE clause P4. | 15 |
| Permutation | Set the permutation used by the Compare operator in the next instruction. | 1 |
| Prev | Back up cursor P1 so that it points to the previous key/data pair in its table or index. | 6 |
| Program | Execute the trigger program passed as P4 (type P4_SUBPROGRAM). | 3 |
| PureFunc | Invoke a user function (P4 is a pointer to an sqlite3_context object that contains a pointer to the function to be run)… | 8 |
| ReadCookie | Read cookie number P3 from database P1 and write it into register P2. | 11 |
| Real | P1 and P3 are combined to 64 bits with P1 being the lower the P3 the upper. | 3 |
| RealAffinity | If register P1 holds an integer convert it to a real value. | 25 |
| ReleaseReg | Release registers from service. | |
| Remainder | Compute the remainder after integer register P2 is divided by register P1 and store the result in register P3. | 1 |
| ReopenIdx | The ReopenIdx opcode works like OpenRead except that it first checks to see if the cursor on P1 is already open on the… | 1 |
| ResetCount | The value of the change counter is copied to the database handle change counter (returned by subsequent calls to… | 3 |
| ResetSorter | Delete all contents from the ephemeral table or sorter that is open on cursor P1. | 4 |
| ResultRow | The registers P1 through P1+P2-1 contain a single row of results. | 125 |
| Return | Jump to the address stored in register P1. | 29 |
| Rewind | The next use of the Rowid or Column or Next instruction for P1 will refer to the first entry in the database table or… | 101 |
| RowCell | P1 and P2 are both open cursors. | 1 |
| RowData | Write into register P2 the complete row content for the row at which cursor P1 is currently pointing. | 2 |
| Rowid | Store in register P2 an integer which is the key of the table entry that P1 is currently point to. | 59 |
| RowSetAdd | Insert the integer value held by register P2 into a RowSet object held in register P1. | 2 |
| RowSetRead | Extract the smallest value from the RowSet object in P1 and put that value into register P3. | 2 |
| RowSetTest | Register P3 is assumed to hold a 64-bit integer value. | 1 |
| Savepoint | Open, release or rollback the savepoint named by parameter P4, depending on the value of P1. | 2 |
| SCopy | Make a shallow copy of register P1 into register P2. | 19 |
| SeekEnd | Position cursor P1 at the end of the btree for the purpose of appending a new entry onto the btree. | 3 |
| SeekGE | If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as the key. | 28 |
| SeekGT | If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key. | 5 |
| SeekHit | Increase or decrease the seekHit value for cursor P1, if necessary, so that it is no less than P2 and no greater than… | |
| SeekLE | If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key. | 1 |
| SeekLT | If cursor P1 refers to an SQL table (B-Tree that uses integer keys), use the value in register P3 as a key. | 1 |
| SeekRowid | P1 is the index of a cursor open on an SQL table btree (with integer keys). | 20 |
| SeekScan | This opcode is a prefix opcode to SeekGE. | |
| Sequence | Find the next available sequence number for cursor P1. | 2 |
| SequenceTest | P1 is a sorter cursor. | |
| SetCookie | Write the integer value P3 into cookie number P2 of database P1. | 21 |
| SetSubtype | Set the subtype value of register P2 to the integer from register P1. | |
| ShiftLeft | Shift the integer value in register P2 to the left by the number of bits specified by the integer in register P1. | 1 |
| ShiftRight | Shift the integer value in register P2 to the right by the number of bits specified by the integer in register P1. | 1 |
| SoftNull | Set register P1 to have the value NULL as seen by the MakeRecord instruction, but do not free any string or blob memory… | 9 |
| Sort | This opcode does exactly the same thing as Rewind except that it increments an undocumented global variable used for… | 2 |
| SorterCompare | P1 is a sorter cursor. | 1 |
| SorterData | Write into register P2 the current sorter data for sorter cursor P1. | 15 |
| SorterInsert | Register P2 holds an SQL index key made using the MakeRecord instructions. | 15 |
| SorterNext | This opcode works just like Next except that P1 must be a sorter object for which the SorterSort opcode has been… | 15 |
| SorterOpen | This opcode works like OpenEphemeral except that it opens a transient index that is specifically designed to sort large… | 15 |
| SorterSort | After all records have been inserted into the Sorter object identified by P1, invoke this opcode to actually do the… | 15 |
| SqlExec | Run the SQL statement or statements specified in the P4 string. | 1 |
| String | The string value P4 of length P1 (bytes) is stored in register P2. | |
| String8 | P4 points to a nul terminated UTF-8 string. | 57 |
| Subtract | Subtract the value in register P1 from the value in register P2 and store the result in register P3. | 1 |
| TableLock | Obtain a lock on a particular table. | |
| Trace | Write P4 on the statement trace output if statement tracing is enabled. | 2 |
| Transaction | Begin a transaction on database P1 if a transaction is not already active. | 151 |
| TypeCheck | Apply affinities to the range of P2 registers beginning with P1. | 6 |
| Vacuum | Vacuum the entire database P1. | 2 |
| Variable | Transfer the values of bound parameter P1 into register P2 | 10 |
| VBegin | P4 may be a pointer to an sqlite3_vtab structure. | 4 |
| VCheck | P4 is a pointer to a Table object that is a virtual table in schema P1 that supports the xIntegrity() method. | 2 |
| VColumn | Store in register P3 the value of the P2-th column of the current row of the virtual-table of cursor P1. | 5 |
| VCreate | P2 is a register that holds the name of a virtual table in database P1. | 1 |
| VDestroy | P4 is the name of a virtual table in database P1. | 1 |
| VFilter | P1 is a cursor opened using VOpen. | 5 |
| VInitIn | Set register P2 to be a pointer to a ValueList object for cursor P1 with cache register P3 and output register P3+1. | |
| VNext | Advance virtual table P1 to the next row in its result set and jump to instruction P2. | 5 |
| VOpen | P4 is a pointer to a virtual table object, an sqlite3_vtab structure. | 5 |
| VRename | P4 is a pointer to a virtual table object, an sqlite3_vtab structure. | 1 |
| VUpdate | P4 is a pointer to a virtual table object, an sqlite3_vtab structure. | 2 |
| Yield | Swap the program counter with the value in register P1. | 16 |
| ZeroOrNull | If both registers P1 and P3 are NOT NULL, then store a zero in register P2. | 4 |