Debian Codegraph @

www/bytecodevtab.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>The Bytecode() And Tables_Used() Table-Valued Functions</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.svg" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 The Bytecode() And Tables_Used() Table-Valued Functions
122 </div>
123 <details class="fancy_toc">
124 <summary>Table Of Contents</summary>
125 <div id="toc_sub"><div class="fancy-toc1"><a href="#overview">1. Overview</a></div>
126 <div class="fancy-toc1"><a href="#usage">2. Usage</a></div>
127 <div class="fancy-toc2"><a href="#schema_for_bytecode">2.1. Schema For bytecode</a></div>
128 <div class="fancy-toc2"><a href="#schema_for_tables_used">2.2. Schema For tables_used</a></div>
129 </div>
130 </details>
131 </div>
132
133
134
135
136 <h1 id="overview"><span>1. </span>Overview</h1>
137
138 <p>
139 Bytecode and tables_used are <a href="vtab.html">virtual tables</a> built into SQLite that
140 access information about <a href="c3ref/stmt.html">prepared statements</a>.
141 Both bytecode and tables_used operate as <a href="vtab.html#tabfunc2">table-valued functions</a>.
142 They take a single required argument which is either the text of
143 an SQL statement, or a pointer to an existing prepared statement.
144 The bytecode function returns one row of result for each <a href="opcode.html">bytecode</a>
145 operation in the prepared statement. The tables_used function returns
146 one row for each persistent btree (either a table or an index) accessed
147 by the prepared statement.
148
149 </p><h1 id="usage"><span>2. </span>Usage</h1>
150
151 <p>
152 The bytecode and tables_used tables are only available if SQLite has
153 been compiled with the <a href="compile.html#enable_bytecode_vtab">-DSQLITE_ENABLE_BYTECODE_VTAB</a> compile-time option.
154 The <a href="cli.html">CLI</a> has been compiled that way, and so you can use the standard
155 <a href="cli.html">CLI</a> as a test platform to experiment.
156
157 </p><p>
158 Both virtual tables are read-only <a href="vtab.html#epoonlyvtab">eponymous-only virtual tables</a>. You use them
159 by mentioning them directly in the FROM clause of a SELECT statement.
160 They both require a single argument which is the SQL statement to be
161 analyzed. For example:
162
163 </p><div class="codeblock"><pre>SELECT * FROM bytecode('SELECT * FROM bytecode(?1)');
164 </pre></div>
165
166 <p>
167 The argument can be either the text of an SQL statement, in which case
168 the bytecode (or tables_used) for that statement is returned, or the
169 argument can be a parameter such as ?1 or $stmt that is later bound
170 to a <a href="c3ref/stmt.html">prepared statement</a> object using the
171 <a href="c3ref/bind_blob.html">sqlite3_bind_pointer()</a> interface. Use a pointer type of
172 "stmt-pointer" for the <a href="c3ref/bind_blob.html">sqlite3_bind_pointer()</a> interface.
173
174 </p><h2 id="schema_for_bytecode"><span>2.1. </span>Schema For bytecode</h2>
175
176 <p>
177 The schema of the bytecode virtual table is:
178
179 </p><div class="codeblock"><pre>CREATE TABLE bytecode(
180 addr INT,
181 opcode TEXT,
182 p1 INT,
183 p2 INT,
184 p3 INT,
185 p4 TEXT,
186 p5 INT,
187 comment TEXT,
188 subprog TEXT,
189 nexec INT,
190 ncycle INT,
191 stmt HIDDEN
192 );
193 </pre></div>
194
195 <p>
196 The first eight columns are the address, opcode, and operands for a
197 single <a href="opcode.html">bytecode</a> in the virtual machine that implements the statement.
198 These columns are the same columns output when using EXPLAIN.
199
200 </p><p> The bytecode virtual tables shows all operations in the prepared
201 statement, both the main body of the prepared statement and in
202 subprograms used to implement triggers or foreign key actions.
203 The "subprog" field is NULL for the main body of the prepared statement,
204 or is the trigger name or the string "(FK)" for triggers and foreign
205 key actions, respectively.
206
207 <a name="nexec"></a>
208
209 </p><p> The "nexec" and "ncycle" columns show the number of times
210 each opcode has been executed, and the total number of CPU cycles used
211 by that opcode, respectively. These fields always have a value of 0
212 unless SQLite has been compiled with <a href="compile.html#enable_stmt_scanstatus">SQLITE_ENABLE_STMT_SCANSTATUS</a>
213 compile-time options and scan-status statistics are enabled using the
214 <a href="c3ref/db_config.html">sqlite3_db_config</a>(db,<a href="c3ref/c_dbconfig_defensive.html#sqlitedbconfigstmtscanstatus">SQLITE_DBCONFIG_STMT_SCANSTATUS</a>,...)
215 interface. The values for nexec and ncycle are cumulative, until
216 reset using <a href="c3ref/stmt_scanstatus_reset.html">sqlite3_stmt_scanstatus_reset()</a>.
217 </p><p>
218 The "ncycle" column currently always returns 0 unless SQLite is compiled
219 for X86_64 or AARCH64 processors using GCC, Clang, or MSVC, or
220 compiled for PPC processors using GCC or Clang.
221
222 </p><h2 id="schema_for_tables_used"><span>2.2. </span>Schema For tables_used</h2>
223
224 <p>
225 The schema for the tables_used table is:
226
227 </p><div class="codeblock"><pre>CREATE TABLE tables_used(
228 type TEXT,
229 schema TEXT,
230 name TEXT,
231 wr INT,
232 subprog TEXT,
233 stmt HIDDEN
234 );
235 </pre></div>
236
237 <p>
238 The tables_used table is intended to show which btrees of the database file
239 are read or written by a prepared statement, both by the main statement
240 itself but also by related triggers and foreign key actions. The columns
241 are as follows:
242
243 </p><ul>
244 <li><p><b>type</b> &rarr; Either "table" or "index", depending on what role
245 the btree is serving.
246
247 </p></li><li><p><b>schema</b> &rarr; Which database file the btree is located in.
248 This will be "main" for the main database (the usual case), or "temp" for
249 TEMP tables and indexes, or the name assigned to <a href="lang_attach.html">attached</a> databases by
250 the <a href="lang_attach.html">ATTACH</a> statement.
251
252 </p></li><li><p><b>name</b> &rarr; The name of the table or index
253
254 </p></li><li><p><b>wr</b> &rarr; 0 if the object is read, 1 if the object is written
255
256 </p></li><li><p><b>subprog</b> &rarr; The sub-program in which the object is
257 accessed. NULL means the main body of the prepared statement. Otherwise
258 this field is the name of a trigger or "(FK)" for a foreign key action.
259 </p></li></ul>
260 <p align="center"><small><i>This page was last updated on 2025-11-13 07:12:58Z </small></i></p>
261