xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_vtab_in.3 (revision b9988867a8ad969c45a52aa7628bc932ec98d46b)
1*b9988867Schristos.Dd January 24, 2024
2f3c4d887Schristos.Dt SQLITE3_VTAB_IN 3
3f3c4d887Schristos.Os
4f3c4d887Schristos.Sh NAME
5f3c4d887Schristos.Nm sqlite3_vtab_in
6f3c4d887Schristos.Nd identify and handle IN constraints in xBestIndex
7f3c4d887Schristos.Sh SYNOPSIS
8f3c4d887Schristos.In sqlite3.h
9f3c4d887Schristos.Ft int
10f3c4d887Schristos.Fo sqlite3_vtab_in
11f3c4d887Schristos.Fa "sqlite3_index_info*"
12f3c4d887Schristos.Fa "int iCons"
13f3c4d887Schristos.Fa "int bHandle"
14f3c4d887Schristos.Fc
15f3c4d887Schristos.Sh DESCRIPTION
16f3c4d887SchristosThis interface may only be used from within an xBestIndex() method
17f3c4d887Schristosof a virtual table implementation.
18f3c4d887SchristosThe result of invoking this interface from any other context is undefined
19f3c4d887Schristosand probably harmful.
20f3c4d887Schristos.Pp
21f3c4d887SchristosA constraint on a virtual table of the form "column IN (...)"
22f3c4d887Schristosis communicated to the xBestIndex method as a SQLITE_INDEX_CONSTRAINT_EQ
23f3c4d887Schristosconstraint.
24f3c4d887SchristosIf xBestIndex wants to use this constraint, it must set the corresponding
25f3c4d887SchristosaConstraintUsage[].argvIndex to a positive integer.
26f3c4d887SchristosThen, under the usual mode of handling IN operators, SQLite generates
27f3c4d887Schristosbytecode that invokes the xFilter() method
28f3c4d887Schristosonce for each value on the right-hand side of the IN operator.
29f3c4d887SchristosThus the virtual table only sees a single value from the right-hand
30f3c4d887Schristosside of the IN operator at a time.
31f3c4d887Schristos.Pp
32f3c4d887SchristosIn some cases, however, it would be advantageous for the virtual table
33f3c4d887Schristosto see all values on the right-hand of the IN operator all at once.
34f3c4d887SchristosThe sqlite3_vtab_in() interfaces facilitates this in two ways:
35f3c4d887Schristos.Bl -enum
36f3c4d887Schristos.It
37f3c4d887Schristos.Pp
38f3c4d887SchristosA call to sqlite3_vtab_in(P,N,-1) will return true (non-zero) if and
39f3c4d887Schristosonly if the P->aConstraintN constraint is an IN operator
40f3c4d887Schristosthat can be processed all at once.
41f3c4d887SchristosIn other words, sqlite3_vtab_in() with -1 in the third argument is
42f3c4d887Schristosa mechanism by which the virtual table can ask SQLite if all-at-once
43f3c4d887Schristosprocessing of the IN operator is even possible.
44f3c4d887Schristos.It
45f3c4d887Schristos.Pp
46f3c4d887SchristosA call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates to SQLite
47f3c4d887Schristosthat the virtual table does or does not want to process the IN operator
48f3c4d887Schristosall-at-once, respectively.
49f3c4d887SchristosThus when the third parameter (F) is non-negative, this interface is
50f3c4d887Schristosthe mechanism by which the virtual table tells SQLite how it wants
51f3c4d887Schristosto process the IN operator.
52f3c4d887Schristos.El
53f3c4d887Schristos.Pp
54f3c4d887SchristosThe sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
55f3c4d887Schristoswithin the same xBestIndex method call.
56f3c4d887SchristosFor any given P,N pair, the return value from sqlite3_vtab_in(P,N,F)
57f3c4d887Schristoswill always be the same within the same xBestIndex call.
58f3c4d887SchristosIf the interface returns true (non-zero), that means that the constraint
59f3c4d887Schristosis an IN operator that can be processed all-at-once.
60f3c4d887SchristosIf the constraint is not an IN operator or cannot be processed all-at-once,
61f3c4d887Schristosthen the interface returns false.
62f3c4d887Schristos.Pp
63f3c4d887SchristosAll-at-once processing of the IN operator is selected if both of the
64f3c4d887Schristosfollowing conditions are met:
65f3c4d887Schristos.Bl -enum
66f3c4d887Schristos.It
67f3c4d887Schristos.Pp
68f3c4d887SchristosThe P->aConstraintUsageN.argvIndex value is set to a positive integer.
69f3c4d887SchristosThis is how the virtual table tells SQLite that it wants to use the
70f3c4d887SchristosN-th constraint.
71f3c4d887Schristos.It
72f3c4d887Schristos.Pp
73f3c4d887SchristosThe last call to sqlite3_vtab_in(P,N,F) for which F was non-negative
74f3c4d887Schristoshad F>=1.
75f3c4d887Schristos.El
76f3c4d887Schristos.Pp
77f3c4d887SchristosIf either or both of the conditions above are false, then SQLite uses
78f3c4d887Schristosthe traditional one-at-a-time processing strategy for the IN constraint.
79f3c4d887SchristosIf both conditions are true, then the argvIndex-th parameter to the
80f3c4d887SchristosxFilter method will be an sqlite3_value that appears to
81f3c4d887Schristosbe NULL, but which can be passed to
82f3c4d887Schristos.Fn sqlite3_vtab_in_first
83f3c4d887Schristosand
84f3c4d887Schristos.Fn sqlite3_vtab_in_next
85f3c4d887Schristosto find all values on the right-hand side of the IN constraint.
86f3c4d887Schristos.Sh IMPLEMENTATION NOTES
87f3c4d887SchristosThese declarations were extracted from the
88*b9988867Schristosinterface documentation at line 9962.
89f3c4d887Schristos.Bd -literal
90f3c4d887SchristosSQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
91f3c4d887Schristos.Ed
92f3c4d887Schristos.Sh SEE ALSO
93f3c4d887Schristos.Xr sqlite3_index_info 3 ,
94f3c4d887Schristos.Xr sqlite3_value 3 ,
95f3c4d887Schristos.Xr sqlite3_vtab_in_first 3 ,
96f3c4d887Schristos.Xr SQLITE_INDEX_CONSTRAINT_EQ 3
97