SQLite VDBE opcode

IFindKey

This instruction always follows an Found with the same P1, P2 and P3 values as this instruction and a non-zero P4 value.

Jumps: P2 is an instruction address. In the listings here, a jump is drawn as an arc and the address is a link.

An example

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

PRAGMA integrity_check
addropcodep1p2p3p4p5
0Init07357320
1Expire1100
2Integer99100
3Null08310
4IntegrityCk1238[22,0,16,23,24,15,11,13,14,9,8,1,21,17,18,2,7,6,3,0,4,19,5]0
5IsNull21100
6String8030*** in database main *** 0
7Concat2330
8ResultRow3100
9IfPos11110
10Halt0000
11String8020wrong # of entries in index 0
12Eq1018100
13String8040sqlite_autoindex_playlist_tracks_10
14Concat4230
15ResultRow3100
16IfPos11810
17Halt0000
18Eq1224110
19String8040sqlite_autoindex_lyrics_segdir_10
20Concat4230
21ResultRow3100
22IfPos12410
23Halt0000
24Eq1630150
25String8040sqlite_autoindex_playlists_10
26Concat4230
27ResultRow3100
28IfPos13010
29Halt0000
30Eq1736170
31String8040sqlite_autoindex_genres_10
32Concat4230
33ResultRow3100
34IfPos13610
35Halt0000
36Eq2442230
37String8040artists_lower0
38Concat4230
39ResultRow3100
40IfPos14210
41Halt0000
42Eq2548230
43String8040artists_name0
44Concat4230
45ResultRow3100
46IfPos14810
47Halt0000
48Eq2954280
49String8040tracks_minutes0
50Concat4230
51ResultRow3100
52IfPos15410
53Halt0000
54Eq3060280
55String8040tracks_album0
56Concat4230
57ResultRow3100
58IfPos16010
59Halt0000
60OpenRead122020
61Integer0700
62Rewind16600
63AddImm7100
64Column113128
65Next16300
66Null132330
67OpenRead2160k(2,,)0
68Integer0700
69Integer0800
70Rewind211600
71AddImm7100
72Column223128
73IdxGT2793220
74IsNull327900
75String8030row not in PRIMARY KEY order for playlist_tracks0
76ResultRow3100
77IfPos17910
78Halt0000
79Column20320
80Column21330
81IsType2860513
82Column2030
83NotNull38600
84String8030NULL value in playlist_tracks.playlist_id0
85Goto09100
86IsType2940527
87Column2030
88Affinity310C0
89IsType-1943528
90String8030TEXT value in playlist_tracks.playlist_id0
91ResultRow3100
92IfPos19410
93Halt0000
94IsType2991513
95Column2130
96NotNull39900
97String8030NULL value in playlist_tracks.track_id0
98Goto010400
99IsType21071527
100Column2130
101Affinity310C0
102IsType-11073528
103String8030TEXT value in playlist_tracks.track_id0
104ResultRow3100
105IfPos110710
106Halt0000
107IsType21152527
108Column2230
109Affinity310C0
110IsType-11153528
111String8030TEXT value in playlist_tracks.position0
112ResultRow3100
113IfPos111510
114Halt0000
115Next27100
116OpenRead123060
117OpenRead2240k(3,,,)0
118Integer0700
119Integer0800
120Rewind119800
121AddImm7100
122Column153128
123IsType11310527
124Column1030
125Affinity310C0
126IsType-11313528
127String8030TEXT value in lyrics_segdir.level0
128ResultRow3100
129IfPos113110
130Halt0000
131IsType11391527
132Column1130
133Affinity310C0
134IsType-11393528
135String8030TEXT value in lyrics_segdir.idx0
136ResultRow3100
137IfPos113910
138Halt0000
139IsType11472527
140Column1230
141Affinity310C0
142IsType-11473528
143String8030TEXT value in lyrics_segdir.start_block0
144ResultRow3100
145IfPos114710
146Halt0000
147IsType11553527
148Column1330
149Affinity310C0
150IsType-11553528
151String8030TEXT value in lyrics_segdir.leaves_end_block0
152ResultRow3100
153IfPos115510
154Halt0000
155IsType11634527
156Column1430
157Affinity310C0
158IsType-11633528
159String8030TEXT value in lyrics_segdir.end_block0
160ResultRow3100
161IfPos116310
162Halt0000
163Column10340
164Column11350
165Rowid13600
166AddImm8100
167Found21843430
168IFindKey217534sqlite_autoindex_lyrics_segdir_10
169String8030index sqlite_autoindex_lyrics_segdir_1 stores an imprecise floating-point value for row 0
170Concat7330
171ResultRow3100
172IfPos117410
173Halt0000
174Goto018400
175String8030row 0
176Concat7330
177String8040 missing from index 0
178Concat4330
179String8040sqlite_autoindex_lyrics_segdir_10
180Concat4330
181ResultRow3100
182IfPos119710
183Halt0000
184IdxRowid2300
185Eq3190360
186String8030rowid not at end-of-record for row 0
187Concat7330
188String8040 of index 0
189Goto017800
190IsNull3419700
191IsNull3519700
192Next219400
193Goto019700
194IdxGT21973420
195String8030non-unique entry in index 0
196Goto017900
197Next112100
198OpenRead115020
199Integer0700
200Rewind120400
201AddImm7100
202Column113128
203Next120100
204OpenRead111040
205Integer0700
206Rewind122300
207AddImm7100
208Column133128
209IsType12171527
210Column1130
211Affinity310C0
212IsType-12173528
213String8030TEXT value in notes.album_id0
214ResultRow3100
215IfPos121710
216Halt0000
217IsType12222528
218String8030NUMERIC value in notes.body0
219ResultRow3100
220IfPos122210
221Halt0000
222Next120700
223OpenRead113030
224OpenRead2140k(1,)0
225Integer0700
226Integer0800
227Rewind127700
228AddImm7100
229Column123128
230IsType12351513
231Column1130
232NotNull323500
233String8030NULL value in playlists.name0
234Goto023700
235IsType12401528
236String8030NUMERIC value in playlists.name0
237ResultRow3100
238IfPos124010
239Halt0000
240IsType12452528
241String8030NUMERIC value in playlists.created0
242ResultRow3100
243IfPos124510
244Halt0000
245Column11340
246Rowid13500
247AddImm8100
248Found22653420
249IFindKey225634sqlite_autoindex_playlists_10
250String8030index sqlite_autoindex_playlists_1 stores an imprecise floating-point value for row 0
251Concat7330
252ResultRow3100
253IfPos125510
254Halt0000
255Goto026500
256String8030row 0
257Concat7330
258String8040 missing from index 0
259Concat4330
260String8040sqlite_autoindex_playlists_10
261Concat4330
262ResultRow3100
263IfPos127610
264Halt0000
265IdxRowid2300
266Eq3271350
267String8030rowid not at end-of-record for row 0
268Concat7330
269String8040 of index 0
270Goto025900
271Next227300
272Goto027600
273IdxGT22763410
274String8030non-unique entry in index 0
275Goto026000
276Next122800
277Null137370
278OpenRead290k(1,)0
279Integer0700
280Integer0800
281Rewind230700
282AddImm7100
283Column213128
284IdxGT22903710
285IsNull3729000
286String8030row not in PRIMARY KEY order for genres0
287ResultRow3100
288IfPos129010
289Halt0000
290Column20370
291IsType22960513
292Column2030
293NotNull329600
294String8030NULL value in genres.name0
295Goto029800
296IsType23010528
297String8030NUMERIC value in genres.name0
298ResultRow3100
299IfPos130110
300Halt0000
301IsType23061528
302String8030NUMERIC value in genres.description0
303ResultRow3100
304IfPos130610
305Halt0000
306Next228200
307OpenRead18030
308Integer0700
309Rewind132800
310AddImm7100
311Column123128
312IsType13171513
313Column1130
314NotNull331700
315String8030NULL value in artists_archive.name0
316Goto031900
317IsType13221528
318String8030NUMERIC value in artists_archive.name0
319ResultRow3100
320IfPos132210
321Halt0000
322IsType13272528
323String8030NUMERIC value in artists_archive.country0
324ResultRow3100
325IfPos132710
326Halt0000
327Next131000
328OpenRead11050
329Integer0700
330Rewind136200
331AddImm7100
332Column143128
333IsType13380528
334String8030NUMERIC value in sqlite_master.type0
335ResultRow3100
336IfPos133810
337Halt0000
338IsType13431528
339String8030NUMERIC value in sqlite_master.name0
340ResultRow3100
341IfPos134310
342Halt0000
343IsType13482528
344String8030NUMERIC value in sqlite_master.tbl_name0
345ResultRow3100
346IfPos134810
347Halt0000
348IsType13563527
349Column1330
350Affinity310C0
351IsType-13563528
352String8030TEXT value in sqlite_master.rootpage0
353ResultRow3100
354IfPos135610
355Halt0000
356IsType13614528
357String8030NUMERIC value in sqlite_master.sql0
358ResultRow3100
359IfPos136110
360Halt0000
361Next133100
362OpenRead121030
363Integer0700
364Rewind136800
365AddImm7100
366Column123128
367Next136500
368OpenRead117040
369OpenRead2180k(2,,)0
370Integer0700
371Integer0800
372Rewind145400
373AddImm7100
374Column133128
375IsType13801513
376Column1130
377NotNull338000
378String8030NULL value in sales.track_id0
379Goto038200
380IsType13851517
381String8030non-INTEGER value in sales.track_id0
382ResultRow3100
383IfPos138510
384Halt0000
385IsType13902513
386Column1230
387NotNull339000
388String8030NULL value in sales.quantity0
389Goto039200
390IsType13952517
391String8030non-INTEGER value in sales.quantity0
392ResultRow3100
393IfPos139510
394Halt0000
395IsType14013513
396Column1330
397RealAffinity3000
398NotNull340100
399String8030NULL value in sales.unit_price0
400Goto040300
401IsType14063519
402String8030non-REAL value in sales.unit_price0
403ResultRow3100
404IfPos140610
405Halt0000
406IfNullRow141230
407Column12370
408Column13380
409RealAffinity38000
410Multiply383730
411TypeCheck316sales0
412IsType-14173519
413String8030non-REAL value in sales.total0
414ResultRow3100
415IfPos141710
416Halt0000
417Column12380
418Integer03700
419Gt3742438BINARY-884
420String8030CHECK constraint failed in sales0
421ResultRow3100
422IfPos142410
423Halt0000
424Column12370
425Integer103800
426Le3845337BINARY-884
427Column11340
428Rowid13500
429AddImm8100
430Found24473420
431IFindKey243834sales_big0
432String8030index sales_big stores an imprecise floating-point value for row 0
433Concat7330
434ResultRow3100
435IfPos143710
436Halt0000
437Goto044700
438String8030row 0
439Concat7330
440String8040 missing from index 0
441Concat4330
442String8040sales_big0
443Concat4330
444ResultRow3100
445IfPos145310
446Halt0000
447IdxRowid2300
448Eq3453350
449String8030rowid not at end-of-record for row 0
450Concat7330
451String8040 of index 0
452Goto044100
453Next137300
454OpenRead12030
455OpenRead270k(2,,)0
456OpenRead360k(2,,)0
457Integer0700
458Integer0800
459Integer0900
460Rewind153100
461AddImm7100
462Column123128
463IsType14681513
464Column1130
465NotNull346800
466String8030NULL value in artists.name0
467Goto047000
468IsType14731528
469String8030NUMERIC value in artists.name0
470ResultRow3100
471IfPos147310
472Halt0000
473IsType14782528
474String8030NUMERIC value in artists.country0
475ResultRow3100
476IfPos147810
477Halt0000
478Column11380
479PureFunc03834lower(1)32
480Rowid13500
481AddImm8100
482Found24993420
483IFindKey249034artists_lower0
484String8030index artists_lower stores an imprecise floating-point value for row 0
485Concat7330
486ResultRow3100
487IfPos148910
488Halt0000
489Goto049900
490String8030row 0
491Concat7330
492String8040 missing from index 0
493Concat4330
494String8040artists_lower0
495Concat4330
496ResultRow3100
497IfPos150510
498Halt0000
499IdxRowid2300
500Eq3505350
501String8030rowid not at end-of-record for row 0
502Concat7330
503String8040 of index 0
504Goto049300
505Column11340
506AddImm9100
507Found35243420
508IFindKey351534artists_name0
509String8030index artists_name stores an imprecise floating-point value for row 0
510Concat7330
511ResultRow3100
512IfPos151410
513Halt0000
514Goto052400
515String8030row 0
516Concat7330
517String8040 missing from index 0
518Concat4330
519String8040artists_name0
520Concat4330
521ResultRow3100
522IfPos153010
523Halt0000
524IdxRowid3300
525Eq3530350
526String8030rowid not at end-of-record for row 0
527Concat7330
528String8040 of index 0
529Goto051800
530Next146100
531OpenRead13040
532Integer0700
533Rewind156800
534AddImm7100
535Column133128
536IsType15411513
537Column1130
538NotNull354100
539String8030NULL value in albums.artist_id0
540Goto054600
541IsType15491527
542Column1130
543Affinity310C0
544IsType-15493528
545String8030TEXT value in albums.artist_id0
546ResultRow3100
547IfPos154910
548Halt0000
549IsType15542513
550Column1230
551NotNull355400
552String8030NULL value in albums.title0
553Goto055600
554IsType15592528
555String8030NUMERIC value in albums.title0
556ResultRow3100
557IfPos155910
558Halt0000
559IsType15673527
560Column1330
561Affinity310C0
562IsType-15673528
563String8030TEXT value in albums.year0
564ResultRow3100
565IfPos156710
566Halt0000
567Next153400
568OpenRead14060
569OpenRead2190k(2,,)0
570OpenRead350k(2,,)0
571Integer0700
572Integer0800
573Integer0900
574Rewind167900
575AddImm7100
576Column153128
577IsType15821513
578Column1130
579NotNull358200
580String8030NULL value in tracks.album_id0
581Goto058700
582IsType15901527
583Column1130
584Affinity310C0
585IsType-15903528
586String8030TEXT value in tracks.album_id0
587ResultRow3100
588IfPos159010
589Halt0000
590IsType15952513
591Column1230
592NotNull359500
593String8030NULL value in tracks.name0
594Goto059700
595IsType16002528
596String8030NUMERIC value in tracks.name0
597ResultRow3100
598IfPos160010
599Halt0000
600IsType16083527
601Column1330
602Affinity310C0
603IsType-16083528
604String8030TEXT value in tracks.ms0
605ResultRow3100
606IfPos160810
607Halt0000
608IsType16164527
609Column1430
610Affinity310C0
611IsType-16163528
612String8030TEXT value in tracks.bytes0
613ResultRow3100
614IfPos161610
615Halt0000
616IsType16255527
617Column1530
618RealAffinity3000
619Affinity310C0
620IsType-16253528
621String8030TEXT value in tracks.price0
622ResultRow3100
623IfPos162510
624Halt0000
625Column13380
626Integer600003700
627Divide3738340
628Rowid13500
629AddImm8100
630Found26473420
631IFindKey263834tracks_minutes0
632String8030index tracks_minutes stores an imprecise floating-point value for row 0
633Concat7330
634ResultRow3100
635IfPos163710
636Halt0000
637Goto064700
638String8030row 0
639Concat7330
640String8040 missing from index 0
641Concat4330
642String8040tracks_minutes0
643Concat4330
644ResultRow3100
645IfPos165310
646Halt0000
647IdxRowid2300
648Eq3653350
649String8030rowid not at end-of-record for row 0
650Concat7330
651String8040 of index 0
652Goto064100
653Column11340
654AddImm9100
655Found36723420
656IFindKey366334tracks_album0
657String8030index tracks_album stores an imprecise floating-point value for row 0
658Concat7330
659ResultRow3100
660IfPos166210
661Halt0000
662Goto067200
663String8030row 0
664Concat7330
665String8040 missing from index 0
666Concat4330
667String8040tracks_album0
668Concat4330
669ResultRow3100
670IfPos167810
671Halt0000
672IdxRowid3300
673Eq3678350
674String8030rowid not at end-of-record for row 0
675Concat7330
676String8040 of index 0
677Goto066600
678Next157500
679VCheck030��R0
680IsNull368400
681ResultRow3100
682IfPos168410
683Halt0000
684Null0890
685IntegrityCk118[1]1
686IsNull269200
687String8030*** in database temp *** 0
688Concat2330
689ResultRow3100
690IfPos169210
691Halt0000
692String8020wrong # of entries in index 0
693OpenRead11150
694Integer0700
695Rewind172700
696AddImm7100
697Column143128
698IsType17030528
699String8030NUMERIC value in sqlite_temp_master.type0
700ResultRow3100
701IfPos170310
702Halt0000
703IsType17081528
704String8030NUMERIC value in sqlite_temp_master.name0
705ResultRow3100
706IfPos170810
707Halt0000
708IsType17132528
709String8030NUMERIC value in sqlite_temp_master.tbl_name0
710ResultRow3100
711IfPos171310
712Halt0000
713IsType17213527
714Column1330
715Affinity310C0
716IsType-17213528
717String8030TEXT value in sqlite_temp_master.rootpage0
718ResultRow3100
719IfPos172110
720Halt0000
721IsType17264528
722String8030NUMERIC value in sqlite_temp_master.sql0
723ResultRow3100
724IfPos172610
725Halt0000
726Next169600
727AddImm1-9900
728IfNotZero173100
729String8030ok0
730ResultRow3100
731Halt0000
732String8030database disk image is malformed0
733Goto073000
734Halt0000
735Transaction00101
736Transaction10001
737Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: AddImm, Affinity, Column, Concat, Divide, Eq, Expire, Found, Goto, Gt, Halt, IdxGT, IdxRowid, IfNotZero, IfNullRow, IfPos, Init, Integer, IntegrityCk, IsNull, IsType, Le, Multiply, Next, NotNull, Null, OpenRead, PureFunc, RealAffinity, ResultRow, Rewind, Rowid, String8, Transaction, TypeCheck, VCheck.

What the SQLite documentation says

This instruction always follows an Found with the same P1, P2 and P3 values as this instruction and a non-zero P4 value. The P4 value to this opcode is of type P4_INDEX and contains a pointer to the Index object of for the index being searched.

This opcode uses sqlite3VdbeFindIndexKey() to search around the current cursor location for an index key that exactly matches all fields that are not indexed expressions or references to VIRTUAL generated columns, and either exactly match or are real numbers that are within 2 ULPs of each other if the don't match.

To put it another way, this opcode looks for nearby index entries that are very close to the search key, but which might have small differences in floating-point values that come via an expression.

If no nearby alternative entry is found in cursor P1, then jump to P2. But if a close match is found, fall through.

This opcode is used by PRAGMA integrity_check to help distinguish between truely corrupt indexes and expression indexes that are holding floating-point values that are off by one or two ULPs.

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.

← IfEmpty · IfNoHope →