Fossil SCM

Update the built-in SQLite to the latest 3.38.0 beta.

drh 2022-02-05 01:21 trunk
Commit 82bbde8d0f3d600526b51536114d5ec9dd386b6d1e81f0ed82720abf56c9d52f
2 files changed +349 -49 +123 -1
+349 -49
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2022-02-01 13:17:11 00b1b7020a564976da3237532434e47ccf17eb5d620e6ac45f3e70b5d5739200"
457
+#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -9908,10 +9908,132 @@
99089908
** valid to do so, on the other hand, might cause SQLite to return incorrect
99099909
** results.
99109910
*/
99119911
SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
99129912
9913
+/*
9914
+** CAPI3REF: Identify and handle IN constraints in xBestIndex
9915
+**
9916
+** This interface may only be used from within an
9917
+** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9918
+** The result of invoking this interface from any other context is
9919
+** undefined and probably harmful.
9920
+**
9921
+** ^(A constraint on a virtual table of the form
9922
+** "[IN operator|column IN (...)]" is
9923
+** communicated to the xBestIndex method as a
9924
+** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9925
+** this constraint, it must set the corresponding
9926
+** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9927
+** the usual mode of handling IN operators, SQLite generates [bytecode]
9928
+** that invokes the [xFilter|xFilter() method] once for each value
9929
+** on the right-hand side of the IN operator.)^ Thus the virtual table
9930
+** only sees a single value from the right-hand side of the IN operator
9931
+** at a time.
9932
+**
9933
+** In some cases, however, it would be advantageous for the virtual
9934
+** table to see all values on the right-hand of the IN operator all at
9935
+** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9936
+**
9937
+** <ol>
9938
+** <li><p>
9939
+** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9940
+** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9941
+** is an [IN operator] that can be processed all at once. ^In other words,
9942
+** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9943
+** by which the virtual table can ask SQLite if all-at-once processing
9944
+** of the IN operator is even possible.
9945
+**
9946
+** <li><p>
9947
+** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9948
+** to SQLite that the virtual table does or does not want to process
9949
+** the IN operator all-at-once, respectively. ^Thus when the third
9950
+** parameter (F) is non-negative, this interface is the mechanism by
9951
+** which the virtual table tells SQLite how it wants to process the
9952
+** IN operator.
9953
+** </ol>
9954
+**
9955
+** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9956
+** within the same xBestIndex method call. ^For any given P,N pair,
9957
+** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9958
+** within the same xBestIndex call. ^If the interface returns true
9959
+** (non-zero), that means that the constraint is an IN operator
9960
+** that can be processed all-at-once. ^If the constraint is not an IN
9961
+** operator or cannot be processed all-at-once, then the interface returns
9962
+** false.
9963
+**
9964
+** ^(All-at-once processing of the IN operator is selected if both of the
9965
+** following conditions are met:
9966
+**
9967
+** <ol>
9968
+** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9969
+** integer. This is how the virtual table tells SQLite that it wants to
9970
+** use the N-th constraint.
9971
+**
9972
+** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9973
+** non-negative had F>=1.
9974
+** </ol>)^
9975
+**
9976
+** ^If either or both of the conditions above are false, then SQLite uses
9977
+** the traditional one-at-a-time processing strategy for the IN constraint.
9978
+** ^If both conditions are true, then the argvIndex-th parameter to the
9979
+** xFilter method will be an [sqlite3_value] that appears to be NULL,
9980
+** but which can be passed to [sqlite3_vtab_in_first()] and
9981
+** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9982
+** of the IN constraint.
9983
+*/
9984
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9985
+
9986
+/*
9987
+** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9988
+**
9989
+** These interfaces are only useful from within the
9990
+** [xFilter|xFilter() method] of a [virtual table] implementation.
9991
+** The result of invoking these interfaces from any other context
9992
+** is undefined and probably harmful.
9993
+**
9994
+** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9995
+** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9996
+** xFilter method which invokes these routines, and specifically
9997
+** a parameter that was previously selected for all-at-once IN constraint
9998
+** processing use the [sqlite3_vtab_in()] interface in the
9999
+** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10000
+** an xFilter argument that was selected for all-at-once IN constraint
10001
+** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
10002
+** exhibit some other undefined or harmful behavior.
10003
+**
10004
+** ^(Use these routines to access all values on the right-hand side
10005
+** of the IN constraint using code like the following:
10006
+**
10007
+** <blockquote><pre>
10008
+** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
10009
+** &nbsp; rc==SQLITE_OK && pVal
10010
+** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
10011
+** &nbsp; ){
10012
+** &nbsp; // do something with pVal
10013
+** &nbsp; }
10014
+** &nbsp; if( rc!=SQLITE_OK ){
10015
+** &nbsp; // an error has occurred
10016
+** &nbsp; }
10017
+** </pre></blockquote>)^
10018
+**
10019
+** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
10020
+** routines return SQLITE_OK and set *P to point to the first or next value
10021
+** on the RHS of the IN constraint. ^If there are no more values on the
10022
+** right hand side of the IN constraint, then *P is set to NULL and these
10023
+** routines return [SQLITE_DONE]. ^The return value might be
10024
+** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
10025
+**
10026
+** The *ppOut values returned by these routines are only valid until the
10027
+** next call to either of these routines or until the end of the xFilter
10028
+** method from which these routines were called. If the virtual table
10029
+** implementation needs to retain the *ppOut values for longer, it must make
10030
+** copies. The *ppOut values are [protected sqlite3_value|protected].
10031
+*/
10032
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
10033
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
10034
+
991310035
/*
991410036
** CAPI3REF: Constraint values in xBestIndex()
991510037
** METHOD: sqlite3_index_info
991610038
**
991710039
** This API may only be used from within the [xBestIndex|xBestIndex method]
@@ -14517,14 +14639,15 @@
1451714639
#define BMS ((int)(sizeof(Bitmask)*8))
1451814640
1451914641
/*
1452014642
** A bit in a Bitmask
1452114643
*/
14522
-#define MASKBIT(n) (((Bitmask)1)<<(n))
14523
-#define MASKBIT64(n) (((u64)1)<<(n))
14524
-#define MASKBIT32(n) (((unsigned int)1)<<(n))
14525
-#define ALLBITS ((Bitmask)-1)
14644
+#define MASKBIT(n) (((Bitmask)1)<<(n))
14645
+#define MASKBIT64(n) (((u64)1)<<(n))
14646
+#define MASKBIT32(n) (((unsigned int)1)<<(n))
14647
+#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
14648
+#define ALLBITS ((Bitmask)-1)
1452614649
1452714650
/* A VList object records a mapping between parameters/variables/wildcards
1452814651
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
1452914652
** variable number associated with that parameter. See the format description
1453014653
** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15546,21 +15669,22 @@
1554615669
#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
1554715670
#define OP_VBegin 169
1554815671
#define OP_VCreate 170
1554915672
#define OP_VDestroy 171
1555015673
#define OP_VOpen 172
15551
-#define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */
15552
-#define OP_VRename 174
15553
-#define OP_Pagecount 175
15554
-#define OP_MaxPgcnt 176
15555
-#define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */
15556
-#define OP_Trace 178
15557
-#define OP_CursorHint 179
15558
-#define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */
15559
-#define OP_Noop 181
15560
-#define OP_Explain 182
15561
-#define OP_Abortable 183
15674
+#define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */
15675
+#define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */
15676
+#define OP_VRename 175
15677
+#define OP_Pagecount 176
15678
+#define OP_MaxPgcnt 177
15679
+#define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */
15680
+#define OP_Trace 179
15681
+#define OP_CursorHint 180
15682
+#define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */
15683
+#define OP_Noop 182
15684
+#define OP_Explain 183
15685
+#define OP_Abortable 184
1556215686
1556315687
/* Properties such as "out2" or "jump" that are specified in
1556415688
** comments following the "case" for each opcode in the vdbe.c
1556515689
** are encoded into bitvectors as follows:
1556615690
*/
@@ -15590,13 +15714,13 @@
1559015714
/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
1559115715
/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
1559215716
/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
1559315717
/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
1559415718
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15595
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15596
-/* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15597
-}
15719
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\
15720
+/* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15721
+/* 184 */ 0x00,}
1559815722
1559915723
/* The resolve3P2Values() routine is able to run faster if it knows
1560015724
** the value of the largest JUMP opcode. The smaller the maximum
1560115725
** JUMP opcode the better, so the mkopcodeh.tcl script that
1560215726
** generated this include file strives to group all JUMP opcodes
@@ -22364,10 +22488,28 @@
2236422488
i64 iKey2; /* Second key value passed to hook */
2236522489
Mem *aNew; /* Array of new.* values */
2236622490
Table *pTab; /* Schema object being upated */
2236722491
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2236822492
};
22493
+
22494
+/*
22495
+** An instance of this object is used to pass an vector of values into
22496
+** OP_VFilter, the xFilter method of a virtual table. The vector is the
22497
+** set of values on the right-hand side of an IN constraint.
22498
+**
22499
+** The value as passed into xFilter is an sqlite3_value with a "pointer"
22500
+** type, such as is generated by sqlite3_result_pointer() and read by
22501
+** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
22502
+** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
22503
+** know how to use this object to step through all the values in the
22504
+** right operand of the IN constraint.
22505
+*/
22506
+typedef struct ValueList ValueList;
22507
+struct ValueList {
22508
+ BtCursor *pCsr; /* An ephemeral table holding all values */
22509
+ sqlite3_value *pOut; /* Register to hold each decoded output value */
22510
+};
2236922511
2237022512
/*
2237122513
** Function prototypes
2237222514
*/
2237322515
SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -34503,21 +34645,22 @@
3450334645
/* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
3450434646
/* 169 */ "VBegin" OpHelp(""),
3450534647
/* 170 */ "VCreate" OpHelp(""),
3450634648
/* 171 */ "VDestroy" OpHelp(""),
3450734649
/* 172 */ "VOpen" OpHelp(""),
34508
- /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34509
- /* 174 */ "VRename" OpHelp(""),
34510
- /* 175 */ "Pagecount" OpHelp(""),
34511
- /* 176 */ "MaxPgcnt" OpHelp(""),
34512
- /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34513
- /* 178 */ "Trace" OpHelp(""),
34514
- /* 179 */ "CursorHint" OpHelp(""),
34515
- /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34516
- /* 181 */ "Noop" OpHelp(""),
34517
- /* 182 */ "Explain" OpHelp(""),
34518
- /* 183 */ "Abortable" OpHelp(""),
34650
+ /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34651
+ /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34652
+ /* 175 */ "VRename" OpHelp(""),
34653
+ /* 176 */ "Pagecount" OpHelp(""),
34654
+ /* 177 */ "MaxPgcnt" OpHelp(""),
34655
+ /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34656
+ /* 179 */ "Trace" OpHelp(""),
34657
+ /* 180 */ "CursorHint" OpHelp(""),
34658
+ /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34659
+ /* 182 */ "Noop" OpHelp(""),
34660
+ /* 183 */ "Explain" OpHelp(""),
34661
+ /* 184 */ "Abortable" OpHelp(""),
3451934662
};
3452034663
return azName[i];
3452134664
}
3452234665
#endif
3452334666
@@ -85604,10 +85747,74 @@
8560485747
*/
8560585748
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
8560685749
assert( p );
8560785750
return sqlite3_value_nochange(p->pOut);
8560885751
}
85752
+
85753
+/*
85754
+** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
85755
+** sqlite3_vtab_in_next() (if bNext!=0).
85756
+*/
85757
+static int valueFromValueList(
85758
+ sqlite3_value *pVal, /* Pointer to the ValueList object */
85759
+ sqlite3_value **ppOut, /* Store the next value from the list here */
85760
+ int bNext /* 1 for _next(). 0 for _first() */
85761
+){
85762
+ int rc;
85763
+ ValueList *pRhs;
85764
+
85765
+ *ppOut = 0;
85766
+ if( pVal==0 ) return SQLITE_MISUSE;
85767
+ pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
85768
+ if( pRhs==0 ) return SQLITE_MISUSE;
85769
+ if( bNext ){
85770
+ rc = sqlite3BtreeNext(pRhs->pCsr, 0);
85771
+ }else{
85772
+ int dummy = 0;
85773
+ rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy);
85774
+ assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) );
85775
+ if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE;
85776
+ }
85777
+ if( rc==SQLITE_OK ){
85778
+ u32 sz; /* Size of current row in bytes */
85779
+ Mem sMem; /* Raw content of current row */
85780
+ memset(&sMem, 0, sizeof(sMem));
85781
+ sz = sqlite3BtreePayloadSize(pRhs->pCsr);
85782
+ rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem);
85783
+ if( rc==SQLITE_OK ){
85784
+ u8 *zBuf = (u8*)sMem.z;
85785
+ u32 iSerial;
85786
+ sqlite3_value *pOut = pRhs->pOut;
85787
+ int iOff = 1 + getVarint32(&zBuf[1], iSerial);
85788
+ sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut);
85789
+ pOut->enc = ENC(pOut->db);
85790
+ if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
85791
+ rc = SQLITE_NOMEM;
85792
+ }else{
85793
+ *ppOut = pOut;
85794
+ }
85795
+ }
85796
+ sqlite3VdbeMemRelease(&sMem);
85797
+ }
85798
+ return rc;
85799
+}
85800
+
85801
+/*
85802
+** Set the iterator value pVal to point to the first value in the set.
85803
+** Set (*ppOut) to point to this value before returning.
85804
+*/
85805
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){
85806
+ return valueFromValueList(pVal, ppOut, 0);
85807
+}
85808
+
85809
+/*
85810
+** Set the iterator value pVal to point to the next value in the set.
85811
+** Set (*ppOut) to point to this value before returning.
85812
+*/
85813
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
85814
+ return valueFromValueList(pVal, ppOut, 1);
85815
+}
8560985816
8561085817
/*
8561185818
** Return the current time for a statement. If the current time
8561285819
** is requested more than once within the same run of a single prepared
8561385820
** statement, the exact same time is returned for each invocation regardless
@@ -94761,10 +94968,38 @@
9476194968
goto no_mem;
9476294969
}
9476394970
break;
9476494971
}
9476594972
#endif /* SQLITE_OMIT_VIRTUALTABLE */
94973
+
94974
+#ifndef SQLITE_OMIT_VIRTUALTABLE
94975
+/* Opcode: VInitIn P1 P2 P3 * *
94976
+** Synopsis: r[P2]=ValueList(P1,P3)
94977
+**
94978
+** Set register P2 to be a pointer to a ValueList object for cursor P1
94979
+** with cache register P3 and output register P3+1. This ValueList object
94980
+** can be used as the first argument to sqlite3_vtab_in_first() and
94981
+** sqlite3_vtab_in_next() to extract all of the values stored in the P1
94982
+** cursor. Register P3 is used to hold the values returned by
94983
+** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
94984
+*/
94985
+case OP_VInitIn: { /* out2 */
94986
+ VdbeCursor *pC; /* The cursor containing the RHS values */
94987
+ ValueList *pRhs; /* New ValueList object to put in reg[P2] */
94988
+
94989
+ pC = p->apCsr[pOp->p1];
94990
+ pRhs = sqlite3_malloc64( sizeof(*pRhs) );
94991
+ if( pRhs==0 ) goto no_mem;
94992
+ pRhs->pCsr = pC->uc.pCursor;
94993
+ pRhs->pOut = &aMem[pOp->p3];
94994
+ pOut = out2Prerelease(p, pOp);
94995
+ pOut->flags = MEM_Null;
94996
+ sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
94997
+ break;
94998
+}
94999
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
95000
+
9476695001
9476795002
#ifndef SQLITE_OMIT_VIRTUALTABLE
9476895003
/* Opcode: VFilter P1 P2 P3 P4 *
9476995004
** Synopsis: iplan=r[P3] zplan='P4'
9477095005
**
@@ -101005,11 +101240,11 @@
101005101240
&& (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
101006101241
){
101007101242
/* Internal-use-only functions are disallowed unless the
101008101243
** SQL is being compiled using sqlite3NestedParse() or
101009101244
** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
101010
- ** used to activate internal functionsn for testing purposes */
101245
+ ** used to activate internal functions for testing purposes */
101011101246
no_such_func = 1;
101012101247
pDef = 0;
101013101248
}else
101014101249
if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
101015101250
&& !IN_RENAME_OBJECT
@@ -105562,11 +105797,10 @@
105562105797
if( destIfNull==destIfFalse ){
105563105798
destStep2 = destIfFalse;
105564105799
}else{
105565105800
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105566105801
}
105567
-// if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105568105802
for(i=0; i<nVector; i++){
105569105803
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105570105804
if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105571105805
if( sqlite3ExprCanBeNull(p) ){
105572105806
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
@@ -120729,10 +120963,11 @@
120729120963
static void subtypeFunc(
120730120964
sqlite3_context *context,
120731120965
int argc,
120732120966
sqlite3_value **argv
120733120967
){
120968
+ UNUSED_PARAMETER(argc);
120734120969
sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120735120970
}
120736120971
120737120972
/*
120738120973
** Implementation of the length() function
@@ -128130,10 +128365,13 @@
128130128365
void*, void(*)(void*));
128131128366
/* Version 3.38.0 and later */
128132128367
int (*error_offset)(sqlite3*);
128133128368
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128134128369
int (*vtab_distinct)(sqlite3_index_info*);
128370
+ int (*vtab_in)(sqlite3_index_info*,int,int);
128371
+ int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128372
+ int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
128135128373
};
128136128374
128137128375
/*
128138128376
** This is the function signature used for all extension entry points. It
128139128377
** is also defined in the file "loadext.c".
@@ -128445,10 +128683,13 @@
128445128683
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128446128684
/* Version 3.38.0 and later */
128447128685
#define sqlite3_error_offset sqlite3_api->error_offset
128448128686
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128449128687
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128688
+#define sqlite3_vtab_in sqlite3_api->vtab_in
128689
+#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
128690
+#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
128450128691
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128451128692
128452128693
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128453128694
/* This case when the file really is being compiled as a loadable
128454128695
** extension */
@@ -128938,10 +129179,13 @@
128938129179
sqlite3_autovacuum_pages,
128939129180
/* Version 3.38.0 and later */
128940129181
sqlite3_error_offset,
128941129182
sqlite3_vtab_rhs_value,
128942129183
sqlite3_vtab_distinct,
129184
+ sqlite3_vtab_in,
129185
+ sqlite3_vtab_in_first,
129186
+ sqlite3_vtab_in_next
128943129187
};
128944129188
128945129189
/* True if x is the directory separator character
128946129190
*/
128947129191
#if SQLITE_OS_WIN
@@ -146506,15 +146750,16 @@
146506146750
u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146507146751
Index *pIndex; /* Index used, or NULL */
146508146752
} btree;
146509146753
struct { /* Information for virtual tables */
146510146754
int idxNum; /* Index number */
146511
- u8 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146512
- u8 bOmitOffset : 1; /* True to let virtual table handle offset */
146755
+ u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146756
+ u32 bOmitOffset : 1; /* True to let virtual table handle offset */
146513146757
i8 isOrdered; /* True if satisfies ORDER BY */
146514146758
u16 omitMask; /* Terms that may be omitted */
146515146759
char *idxStr; /* Index identifier string */
146760
+ u32 mHandleIn; /* Terms to handle as IN(...) instead of == */
146516146761
} vtab;
146517146762
} u;
146518146763
u32 wsFlags; /* WHERE_* flags describing the plan */
146519146764
u16 nLTerm; /* Number of entries in aLTerm[] */
146520146765
u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146667,10 +146912,11 @@
146667146912
#ifdef SQLITE_ENABLE_STAT4
146668146913
# define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146669146914
#else
146670146915
# define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146671146916
#endif
146917
+#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
146672146918
146673146919
/*
146674146920
** An instance of the WhereScan object is used as an iterator for locating
146675146921
** terms in the WHERE clause that are useful to the query planner.
146676146922
*/
@@ -148515,12 +148761,19 @@
148515148761
for(j=0; j<nConstraint; j++){
148516148762
int iTarget = iReg+j+2;
148517148763
pTerm = pLoop->aLTerm[j];
148518148764
if( NEVER(pTerm==0) ) continue;
148519148765
if( pTerm->eOperator & WO_IN ){
148520
- codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148521
- addrNotFound = pLevel->addrNxt;
148766
+ if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
148767
+ int iTab = pParse->nTab++;
148768
+ int iCache = ++pParse->nMem;
148769
+ sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
148770
+ sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
148771
+ }else{
148772
+ codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148773
+ addrNotFound = pLevel->addrNxt;
148774
+ }
148522148775
}else{
148523148776
Expr *pRight = pTerm->pExpr->pRight;
148524148777
codeExprOrVector(pParse, pRight, iTarget, 1);
148525148778
if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET
148526148779
&& pLoop->u.vtab.bOmitOffset
@@ -148551,17 +148804,23 @@
148551148804
iIn = pLevel->u.in.nIn;
148552148805
}else{
148553148806
iIn = 0;
148554148807
}
148555148808
for(j=nConstraint-1; j>=0; j--){
148809
+ int bIn; /* True to generate byte code to loop over RHS IN values */
148556148810
pTerm = pLoop->aLTerm[j];
148557
- if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
148811
+ if( (pTerm->eOperator & WO_IN)!=0
148812
+ && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
148813
+ ){
148814
+ bIn = 1;
148815
+ }else{
148816
+ bIn = 0;
148817
+ }
148818
+ if( bIn ) iIn--;
148558148819
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148559148820
disableTerm(pLevel, pTerm);
148560
- }else if( (pTerm->eOperator & WO_IN)!=0
148561
- && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1
148562
- ){
148821
+ }else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){
148563148822
Expr *pCompare; /* The comparison operator */
148564148823
Expr *pRight; /* RHS of the comparison */
148565148824
VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148566148825
148567148826
/* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149287,11 +149546,11 @@
149287149546
regRowid = ++pParse->nMem;
149288149547
}
149289149548
iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149290149549
149291149550
/* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149292
- ** Then for every term xN, evaluate as the subexpression: xN AND z
149551
+ ** Then for every term xN, evaluate as the subexpression: xN AND y
149293149552
** That way, terms in y that are factored into the disjunction will
149294149553
** be picked up by the recursive calls to sqlite3WhereBegin() below.
149295149554
**
149296149555
** Actually, each subexpression is converted to "xN AND w" where w is
149297149556
** the "interesting" terms of z - terms that did not originate in the
@@ -149299,19 +149558,28 @@
149299149558
** indices.
149300149559
**
149301149560
** This optimization also only applies if the (x1 OR x2 OR ...) term
149302149561
** is not contained in the ON clause of a LEFT JOIN.
149303149562
** See ticket http://www.sqlite.org/src/info/f2369304e4
149563
+ **
149564
+ ** 2022-02-04: Do not push down slices of a row-value comparison.
149565
+ ** In other words, "w" or "y" may not be a slice of a vector. Otherwise,
149566
+ ** the initialization of the right-hand operand of the vector comparison
149567
+ ** might not occur, or might occur only in an OR branch that is not
149568
+ ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
149304149569
*/
149305149570
if( pWC->nTerm>1 ){
149306149571
int iTerm;
149307149572
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149308149573
Expr *pExpr = pWC->a[iTerm].pExpr;
149309149574
if( &pWC->a[iTerm] == pTerm ) continue;
149310149575
testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149311149576
testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149312
- if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
149577
+ testcase( pWC->a[iTerm].wtFlags & TERM_SLICE );
149578
+ if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
149579
+ continue;
149580
+ }
149313149581
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149314149582
testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149315149583
pExpr = sqlite3ExprDup(db, pExpr, 0);
149316149584
pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149317149585
}
@@ -150090,11 +150358,11 @@
150090150358
void *pNotUsed;
150091150359
pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
150092150360
assert( pVtab!=0 );
150093150361
assert( pVtab->pModule!=0 );
150094150362
assert( !ExprHasProperty(pExpr, EP_IntValue) );
150095
- pMod = (sqlite3_module *)pVtab->pModule;
150363
+ pMod = (sqlite3_module *)pVtab->pModule;
150096150364
if( pMod->xFindFunction!=0 ){
150097150365
i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
150098150366
if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
150099150367
*peOp2 = i;
150100150368
*ppRight = pList->a[1].pExpr;
@@ -151067,11 +151335,11 @@
151067151335
Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
151068151336
Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
151069151337
151070151338
pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
151071151339
transferJoinMarkings(pNew, pExpr);
151072
- idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
151340
+ idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
151073151341
exprAnalyze(pSrc, pWC, idxNew);
151074151342
}
151075151343
pTerm = &pWC->a[idxTerm];
151076151344
pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
151077151345
pTerm->eOperator = 0;
@@ -151541,10 +151809,12 @@
151541151809
typedef struct HiddenIndexInfo HiddenIndexInfo;
151542151810
struct HiddenIndexInfo {
151543151811
WhereClause *pWC; /* The Where clause being analyzed */
151544151812
Parse *pParse; /* The parsing context */
151545151813
int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151814
+ u32 mIn; /* Mask of terms that are <col> IN (...) */
151815
+ u32 mHandleIn; /* Terms that vtab will handle as <col> IN (...) */
151546151816
sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151547151817
** because extra space is allocated to hold up
151548151818
** to nTerm such values */
151549151819
};
151550151820
@@ -152651,10 +152921,11 @@
152651152921
testcase( pTerm->eOperator & WO_ISNULL );
152652152922
testcase( pTerm->eOperator & WO_IS );
152653152923
testcase( pTerm->eOperator & WO_ALL );
152654152924
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152655152925
if( pTerm->wtFlags & TERM_VNULL ) continue;
152926
+
152656152927
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152657152928
assert( pTerm->u.x.leftColumn>=XN_ROWID );
152658152929
assert( pTerm->u.x.leftColumn<pTab->nCol );
152659152930
152660152931
/* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152712,11 +152983,11 @@
152712152983
}
152713152984
152714152985
/* No matches cause a break out of the loop */
152715152986
break;
152716152987
}
152717
- if( i==n){
152988
+ if( i==n ){
152718152989
nOrderBy = n;
152719152990
if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152720152991
eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152721152992
}
152722152993
}
@@ -152740,17 +153011,21 @@
152740153011
pIdxInfo->aOrderBy = pIdxOrderBy;
152741153012
pIdxInfo->aConstraintUsage = pUsage;
152742153013
pHidden->pWC = pWC;
152743153014
pHidden->pParse = pParse;
152744153015
pHidden->eDistinct = eDistinct;
153016
+ pHidden->mIn = 0;
152745153017
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152746153018
u16 op;
152747153019
if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152748153020
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152749153021
pIdxCons[j].iTermOffset = i;
152750153022
op = pTerm->eOperator & WO_ALL;
152751
- if( op==WO_IN ) op = WO_EQ;
153023
+ if( op==WO_IN ){
153024
+ pHidden->mIn |= SMASKBIT32(j);
153025
+ op = WO_EQ;
153026
+ }
152752153027
if( op==WO_AUX ){
152753153028
pIdxCons[j].op = pTerm->eMatchOp;
152754153029
}else if( op & (WO_ISNULL|WO_IS) ){
152755153030
if( op==WO_ISNULL ){
152756153031
pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152836,11 +153111,13 @@
152836153111
static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
152837153112
sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
152838153113
int rc;
152839153114
152840153115
whereTraceIndexInfoInputs(p);
153116
+ pParse->db->nSchemaLock++;
152841153117
rc = pVtab->pModule->xBestIndex(pVtab, p);
153118
+ pParse->db->nSchemaLock--;
152842153119
whereTraceIndexInfoOutputs(p);
152843153120
152844153121
if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
152845153122
if( rc==SQLITE_NOMEM ){
152846153123
sqlite3OomFault(pParse->db);
@@ -155007,10 +155284,11 @@
155007155284
u16 mNoOmit, /* Do not omit these constraints */
155008155285
int *pbIn, /* OUT: True if plan uses an IN(...) op */
155009155286
int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */
155010155287
){
155011155288
WhereClause *pWC = pBuilder->pWC;
155289
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155012155290
struct sqlite3_index_constraint *pIdxCons;
155013155291
struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
155014155292
int i;
155015155293
int mxTerm;
155016155294
int rc = SQLITE_OK;
@@ -155045,10 +155323,11 @@
155045155323
pIdxInfo->orderByConsumed = 0;
155046155324
pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
155047155325
pIdxInfo->estimatedRows = 25;
155048155326
pIdxInfo->idxFlags = 0;
155049155327
pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
155328
+ pHidden->mHandleIn = 0;
155050155329
155051155330
/* Invoke the virtual table xBestIndex() method */
155052155331
rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
155053155332
if( rc ){
155054155333
if( rc==SQLITE_CONSTRAINT ){
@@ -155101,11 +155380,13 @@
155101155380
}
155102155381
if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){
155103155382
pNew->u.vtab.bOmitOffset = 1;
155104155383
}
155105155384
}
155106
- if( (pTerm->eOperator & WO_IN)!=0 ){
155385
+ if( SMASKBIT32(i) & pHidden->mHandleIn ){
155386
+ pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm);
155387
+ }else if( (pTerm->eOperator & WO_IN)!=0 ){
155107155388
/* A virtual table that is constrained by an IN clause may not
155108155389
** consume the ORDER BY clause because (1) the order of IN terms
155109155390
** is not necessarily related to the order of output terms and
155110155391
** (2) Multiple outputs from a single IN value will not merge
155111155392
** together. */
@@ -155198,10 +155479,29 @@
155198155479
}
155199155480
zRet = (pC ? pC->zName : sqlite3StrBINARY);
155200155481
}
155201155482
return zRet;
155202155483
}
155484
+
155485
+/*
155486
+** Return true if constraint iCons is really an IN(...) constraint, or
155487
+** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
155488
+** or clear (if bHandle==0) the flag to handle it using an iterator.
155489
+*/
155490
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){
155491
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155492
+ u32 m = SMASKBIT32(iCons);
155493
+ if( m & pHidden->mIn ){
155494
+ if( bHandle==0 ){
155495
+ pHidden->mHandleIn &= ~m;
155496
+ }else if( bHandle>0 ){
155497
+ pHidden->mHandleIn |= m;
155498
+ }
155499
+ return 1;
155500
+ }
155501
+ return 0;
155502
+}
155203155503
155204155504
/*
155205155505
** This interface is callable from within the xBestIndex callback only.
155206155506
**
155207155507
** If possible, set (*ppVal) to point to an object containing the value
@@ -195222,11 +195522,11 @@
195222195522
sqlite3_module *pModule;
195223195523
} aMod[] = {
195224195524
{ "json_each", &jsonEachModule },
195225195525
{ "json_tree", &jsonTreeModule },
195226195526
};
195227
- int i;
195527
+ unsigned int i;
195228195528
for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
195229195529
rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
195230195530
}
195231195531
return rc;
195232195532
}
@@ -233819,11 +234119,11 @@
233819234119
int nArg, /* Number of args */
233820234120
sqlite3_value **apUnused /* Function arguments */
233821234121
){
233822234122
assert( nArg==0 );
233823234123
UNUSED_PARAM2(nArg, apUnused);
233824
- sqlite3_result_text(pCtx, "fts5: 2022-02-01 12:28:17 1b528e31f8c62797e0814568b520c0680ff23a2ee877ca6aa70a167d40ebdf80", -1, SQLITE_TRANSIENT);
234124
+ sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
233825234125
}
233826234126
233827234127
/*
233828234128
** Return true if zName is the extension on one of the shadow tables used
233829234129
** by this module.
233830234130
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-01 13:17:11 00b1b7020a564976da3237532434e47ccf17eb5d620e6ac45f3e70b5d5739200"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -9908,10 +9908,132 @@
9908 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9909 ** results.
9910 */
9911 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9912
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9913 /*
9914 ** CAPI3REF: Constraint values in xBestIndex()
9915 ** METHOD: sqlite3_index_info
9916 **
9917 ** This API may only be used from within the [xBestIndex|xBestIndex method]
@@ -14517,14 +14639,15 @@
14517 #define BMS ((int)(sizeof(Bitmask)*8))
14518
14519 /*
14520 ** A bit in a Bitmask
14521 */
14522 #define MASKBIT(n) (((Bitmask)1)<<(n))
14523 #define MASKBIT64(n) (((u64)1)<<(n))
14524 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14525 #define ALLBITS ((Bitmask)-1)
 
14526
14527 /* A VList object records a mapping between parameters/variables/wildcards
14528 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
14529 ** variable number associated with that parameter. See the format description
14530 ** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15546,21 +15669,22 @@
15546 #define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
15547 #define OP_VBegin 169
15548 #define OP_VCreate 170
15549 #define OP_VDestroy 171
15550 #define OP_VOpen 172
15551 #define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */
15552 #define OP_VRename 174
15553 #define OP_Pagecount 175
15554 #define OP_MaxPgcnt 176
15555 #define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */
15556 #define OP_Trace 178
15557 #define OP_CursorHint 179
15558 #define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */
15559 #define OP_Noop 181
15560 #define OP_Explain 182
15561 #define OP_Abortable 183
 
15562
15563 /* Properties such as "out2" or "jump" that are specified in
15564 ** comments following the "case" for each opcode in the vdbe.c
15565 ** are encoded into bitvectors as follows:
15566 */
@@ -15590,13 +15714,13 @@
15590 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15591 /* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
15592 /* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15593 /* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
15594 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15595 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15596 /* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15597 }
15598
15599 /* The resolve3P2Values() routine is able to run faster if it knows
15600 ** the value of the largest JUMP opcode. The smaller the maximum
15601 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15602 ** generated this include file strives to group all JUMP opcodes
@@ -22364,10 +22488,28 @@
22364 i64 iKey2; /* Second key value passed to hook */
22365 Mem *aNew; /* Array of new.* values */
22366 Table *pTab; /* Schema object being upated */
22367 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
22368 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22369
22370 /*
22371 ** Function prototypes
22372 */
22373 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -34503,21 +34645,22 @@
34503 /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34504 /* 169 */ "VBegin" OpHelp(""),
34505 /* 170 */ "VCreate" OpHelp(""),
34506 /* 171 */ "VDestroy" OpHelp(""),
34507 /* 172 */ "VOpen" OpHelp(""),
34508 /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34509 /* 174 */ "VRename" OpHelp(""),
34510 /* 175 */ "Pagecount" OpHelp(""),
34511 /* 176 */ "MaxPgcnt" OpHelp(""),
34512 /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34513 /* 178 */ "Trace" OpHelp(""),
34514 /* 179 */ "CursorHint" OpHelp(""),
34515 /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34516 /* 181 */ "Noop" OpHelp(""),
34517 /* 182 */ "Explain" OpHelp(""),
34518 /* 183 */ "Abortable" OpHelp(""),
 
34519 };
34520 return azName[i];
34521 }
34522 #endif
34523
@@ -85604,10 +85747,74 @@
85604 */
85605 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
85606 assert( p );
85607 return sqlite3_value_nochange(p->pOut);
85608 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85609
85610 /*
85611 ** Return the current time for a statement. If the current time
85612 ** is requested more than once within the same run of a single prepared
85613 ** statement, the exact same time is returned for each invocation regardless
@@ -94761,10 +94968,38 @@
94761 goto no_mem;
94762 }
94763 break;
94764 }
94765 #endif /* SQLITE_OMIT_VIRTUALTABLE */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94766
94767 #ifndef SQLITE_OMIT_VIRTUALTABLE
94768 /* Opcode: VFilter P1 P2 P3 P4 *
94769 ** Synopsis: iplan=r[P3] zplan='P4'
94770 **
@@ -101005,11 +101240,11 @@
101005 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
101006 ){
101007 /* Internal-use-only functions are disallowed unless the
101008 ** SQL is being compiled using sqlite3NestedParse() or
101009 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
101010 ** used to activate internal functionsn for testing purposes */
101011 no_such_func = 1;
101012 pDef = 0;
101013 }else
101014 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
101015 && !IN_RENAME_OBJECT
@@ -105562,11 +105797,10 @@
105562 if( destIfNull==destIfFalse ){
105563 destStep2 = destIfFalse;
105564 }else{
105565 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105566 }
105567 // if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105568 for(i=0; i<nVector; i++){
105569 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105570 if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105571 if( sqlite3ExprCanBeNull(p) ){
105572 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
@@ -120729,10 +120963,11 @@
120729 static void subtypeFunc(
120730 sqlite3_context *context,
120731 int argc,
120732 sqlite3_value **argv
120733 ){
 
120734 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120735 }
120736
120737 /*
120738 ** Implementation of the length() function
@@ -128130,10 +128365,13 @@
128130 void*, void(*)(void*));
128131 /* Version 3.38.0 and later */
128132 int (*error_offset)(sqlite3*);
128133 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128134 int (*vtab_distinct)(sqlite3_index_info*);
 
 
 
128135 };
128136
128137 /*
128138 ** This is the function signature used for all extension entry points. It
128139 ** is also defined in the file "loadext.c".
@@ -128445,10 +128683,13 @@
128445 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128446 /* Version 3.38.0 and later */
128447 #define sqlite3_error_offset sqlite3_api->error_offset
128448 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128449 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
 
 
 
128450 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128451
128452 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128453 /* This case when the file really is being compiled as a loadable
128454 ** extension */
@@ -128938,10 +129179,13 @@
128938 sqlite3_autovacuum_pages,
128939 /* Version 3.38.0 and later */
128940 sqlite3_error_offset,
128941 sqlite3_vtab_rhs_value,
128942 sqlite3_vtab_distinct,
 
 
 
128943 };
128944
128945 /* True if x is the directory separator character
128946 */
128947 #if SQLITE_OS_WIN
@@ -146506,15 +146750,16 @@
146506 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146507 Index *pIndex; /* Index used, or NULL */
146508 } btree;
146509 struct { /* Information for virtual tables */
146510 int idxNum; /* Index number */
146511 u8 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146512 u8 bOmitOffset : 1; /* True to let virtual table handle offset */
146513 i8 isOrdered; /* True if satisfies ORDER BY */
146514 u16 omitMask; /* Terms that may be omitted */
146515 char *idxStr; /* Index identifier string */
 
146516 } vtab;
146517 } u;
146518 u32 wsFlags; /* WHERE_* flags describing the plan */
146519 u16 nLTerm; /* Number of entries in aLTerm[] */
146520 u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146667,10 +146912,11 @@
146667 #ifdef SQLITE_ENABLE_STAT4
146668 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146669 #else
146670 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146671 #endif
 
146672
146673 /*
146674 ** An instance of the WhereScan object is used as an iterator for locating
146675 ** terms in the WHERE clause that are useful to the query planner.
146676 */
@@ -148515,12 +148761,19 @@
148515 for(j=0; j<nConstraint; j++){
148516 int iTarget = iReg+j+2;
148517 pTerm = pLoop->aLTerm[j];
148518 if( NEVER(pTerm==0) ) continue;
148519 if( pTerm->eOperator & WO_IN ){
148520 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148521 addrNotFound = pLevel->addrNxt;
 
 
 
 
 
 
 
148522 }else{
148523 Expr *pRight = pTerm->pExpr->pRight;
148524 codeExprOrVector(pParse, pRight, iTarget, 1);
148525 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET
148526 && pLoop->u.vtab.bOmitOffset
@@ -148551,17 +148804,23 @@
148551 iIn = pLevel->u.in.nIn;
148552 }else{
148553 iIn = 0;
148554 }
148555 for(j=nConstraint-1; j>=0; j--){
 
148556 pTerm = pLoop->aLTerm[j];
148557 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
 
 
 
 
 
 
 
148558 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148559 disableTerm(pLevel, pTerm);
148560 }else if( (pTerm->eOperator & WO_IN)!=0
148561 && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1
148562 ){
148563 Expr *pCompare; /* The comparison operator */
148564 Expr *pRight; /* RHS of the comparison */
148565 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148566
148567 /* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149287,11 +149546,11 @@
149287 regRowid = ++pParse->nMem;
149288 }
149289 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149290
149291 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149292 ** Then for every term xN, evaluate as the subexpression: xN AND z
149293 ** That way, terms in y that are factored into the disjunction will
149294 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
149295 **
149296 ** Actually, each subexpression is converted to "xN AND w" where w is
149297 ** the "interesting" terms of z - terms that did not originate in the
@@ -149299,19 +149558,28 @@
149299 ** indices.
149300 **
149301 ** This optimization also only applies if the (x1 OR x2 OR ...) term
149302 ** is not contained in the ON clause of a LEFT JOIN.
149303 ** See ticket http://www.sqlite.org/src/info/f2369304e4
 
 
 
 
 
 
149304 */
149305 if( pWC->nTerm>1 ){
149306 int iTerm;
149307 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149308 Expr *pExpr = pWC->a[iTerm].pExpr;
149309 if( &pWC->a[iTerm] == pTerm ) continue;
149310 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149311 testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149312 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
 
 
 
149313 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149314 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149315 pExpr = sqlite3ExprDup(db, pExpr, 0);
149316 pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149317 }
@@ -150090,11 +150358,11 @@
150090 void *pNotUsed;
150091 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
150092 assert( pVtab!=0 );
150093 assert( pVtab->pModule!=0 );
150094 assert( !ExprHasProperty(pExpr, EP_IntValue) );
150095 pMod = (sqlite3_module *)pVtab->pModule;
150096 if( pMod->xFindFunction!=0 ){
150097 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
150098 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
150099 *peOp2 = i;
150100 *ppRight = pList->a[1].pExpr;
@@ -151067,11 +151335,11 @@
151067 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
151068 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
151069
151070 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
151071 transferJoinMarkings(pNew, pExpr);
151072 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
151073 exprAnalyze(pSrc, pWC, idxNew);
151074 }
151075 pTerm = &pWC->a[idxTerm];
151076 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
151077 pTerm->eOperator = 0;
@@ -151541,10 +151809,12 @@
151541 typedef struct HiddenIndexInfo HiddenIndexInfo;
151542 struct HiddenIndexInfo {
151543 WhereClause *pWC; /* The Where clause being analyzed */
151544 Parse *pParse; /* The parsing context */
151545 int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
 
 
151546 sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151547 ** because extra space is allocated to hold up
151548 ** to nTerm such values */
151549 };
151550
@@ -152651,10 +152921,11 @@
152651 testcase( pTerm->eOperator & WO_ISNULL );
152652 testcase( pTerm->eOperator & WO_IS );
152653 testcase( pTerm->eOperator & WO_ALL );
152654 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152655 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
152656 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152657 assert( pTerm->u.x.leftColumn>=XN_ROWID );
152658 assert( pTerm->u.x.leftColumn<pTab->nCol );
152659
152660 /* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152712,11 +152983,11 @@
152712 }
152713
152714 /* No matches cause a break out of the loop */
152715 break;
152716 }
152717 if( i==n){
152718 nOrderBy = n;
152719 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152720 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152721 }
152722 }
@@ -152740,17 +153011,21 @@
152740 pIdxInfo->aOrderBy = pIdxOrderBy;
152741 pIdxInfo->aConstraintUsage = pUsage;
152742 pHidden->pWC = pWC;
152743 pHidden->pParse = pParse;
152744 pHidden->eDistinct = eDistinct;
 
152745 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152746 u16 op;
152747 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152748 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152749 pIdxCons[j].iTermOffset = i;
152750 op = pTerm->eOperator & WO_ALL;
152751 if( op==WO_IN ) op = WO_EQ;
 
 
 
152752 if( op==WO_AUX ){
152753 pIdxCons[j].op = pTerm->eMatchOp;
152754 }else if( op & (WO_ISNULL|WO_IS) ){
152755 if( op==WO_ISNULL ){
152756 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152836,11 +153111,13 @@
152836 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
152837 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
152838 int rc;
152839
152840 whereTraceIndexInfoInputs(p);
 
152841 rc = pVtab->pModule->xBestIndex(pVtab, p);
 
152842 whereTraceIndexInfoOutputs(p);
152843
152844 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
152845 if( rc==SQLITE_NOMEM ){
152846 sqlite3OomFault(pParse->db);
@@ -155007,10 +155284,11 @@
155007 u16 mNoOmit, /* Do not omit these constraints */
155008 int *pbIn, /* OUT: True if plan uses an IN(...) op */
155009 int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */
155010 ){
155011 WhereClause *pWC = pBuilder->pWC;
 
155012 struct sqlite3_index_constraint *pIdxCons;
155013 struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
155014 int i;
155015 int mxTerm;
155016 int rc = SQLITE_OK;
@@ -155045,10 +155323,11 @@
155045 pIdxInfo->orderByConsumed = 0;
155046 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
155047 pIdxInfo->estimatedRows = 25;
155048 pIdxInfo->idxFlags = 0;
155049 pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
 
155050
155051 /* Invoke the virtual table xBestIndex() method */
155052 rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
155053 if( rc ){
155054 if( rc==SQLITE_CONSTRAINT ){
@@ -155101,11 +155380,13 @@
155101 }
155102 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){
155103 pNew->u.vtab.bOmitOffset = 1;
155104 }
155105 }
155106 if( (pTerm->eOperator & WO_IN)!=0 ){
 
 
155107 /* A virtual table that is constrained by an IN clause may not
155108 ** consume the ORDER BY clause because (1) the order of IN terms
155109 ** is not necessarily related to the order of output terms and
155110 ** (2) Multiple outputs from a single IN value will not merge
155111 ** together. */
@@ -155198,10 +155479,29 @@
155198 }
155199 zRet = (pC ? pC->zName : sqlite3StrBINARY);
155200 }
155201 return zRet;
155202 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155203
155204 /*
155205 ** This interface is callable from within the xBestIndex callback only.
155206 **
155207 ** If possible, set (*ppVal) to point to an object containing the value
@@ -195222,11 +195522,11 @@
195222 sqlite3_module *pModule;
195223 } aMod[] = {
195224 { "json_each", &jsonEachModule },
195225 { "json_tree", &jsonTreeModule },
195226 };
195227 int i;
195228 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
195229 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
195230 }
195231 return rc;
195232 }
@@ -233819,11 +234119,11 @@
233819 int nArg, /* Number of args */
233820 sqlite3_value **apUnused /* Function arguments */
233821 ){
233822 assert( nArg==0 );
233823 UNUSED_PARAM2(nArg, apUnused);
233824 sqlite3_result_text(pCtx, "fts5: 2022-02-01 12:28:17 1b528e31f8c62797e0814568b520c0680ff23a2ee877ca6aa70a167d40ebdf80", -1, SQLITE_TRANSIENT);
233825 }
233826
233827 /*
233828 ** Return true if zName is the extension on one of the shadow tables used
233829 ** by this module.
233830
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -9908,10 +9908,132 @@
9908 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9909 ** results.
9910 */
9911 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9912
9913 /*
9914 ** CAPI3REF: Identify and handle IN constraints in xBestIndex
9915 **
9916 ** This interface may only be used from within an
9917 ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9918 ** The result of invoking this interface from any other context is
9919 ** undefined and probably harmful.
9920 **
9921 ** ^(A constraint on a virtual table of the form
9922 ** "[IN operator|column IN (...)]" is
9923 ** communicated to the xBestIndex method as a
9924 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9925 ** this constraint, it must set the corresponding
9926 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9927 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9928 ** that invokes the [xFilter|xFilter() method] once for each value
9929 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9930 ** only sees a single value from the right-hand side of the IN operator
9931 ** at a time.
9932 **
9933 ** In some cases, however, it would be advantageous for the virtual
9934 ** table to see all values on the right-hand of the IN operator all at
9935 ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9936 **
9937 ** <ol>
9938 ** <li><p>
9939 ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9940 ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9941 ** is an [IN operator] that can be processed all at once. ^In other words,
9942 ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9943 ** by which the virtual table can ask SQLite if all-at-once processing
9944 ** of the IN operator is even possible.
9945 **
9946 ** <li><p>
9947 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9948 ** to SQLite that the virtual table does or does not want to process
9949 ** the IN operator all-at-once, respectively. ^Thus when the third
9950 ** parameter (F) is non-negative, this interface is the mechanism by
9951 ** which the virtual table tells SQLite how it wants to process the
9952 ** IN operator.
9953 ** </ol>
9954 **
9955 ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9956 ** within the same xBestIndex method call. ^For any given P,N pair,
9957 ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9958 ** within the same xBestIndex call. ^If the interface returns true
9959 ** (non-zero), that means that the constraint is an IN operator
9960 ** that can be processed all-at-once. ^If the constraint is not an IN
9961 ** operator or cannot be processed all-at-once, then the interface returns
9962 ** false.
9963 **
9964 ** ^(All-at-once processing of the IN operator is selected if both of the
9965 ** following conditions are met:
9966 **
9967 ** <ol>
9968 ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9969 ** integer. This is how the virtual table tells SQLite that it wants to
9970 ** use the N-th constraint.
9971 **
9972 ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9973 ** non-negative had F>=1.
9974 ** </ol>)^
9975 **
9976 ** ^If either or both of the conditions above are false, then SQLite uses
9977 ** the traditional one-at-a-time processing strategy for the IN constraint.
9978 ** ^If both conditions are true, then the argvIndex-th parameter to the
9979 ** xFilter method will be an [sqlite3_value] that appears to be NULL,
9980 ** but which can be passed to [sqlite3_vtab_in_first()] and
9981 ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9982 ** of the IN constraint.
9983 */
9984 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9985
9986 /*
9987 ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9988 **
9989 ** These interfaces are only useful from within the
9990 ** [xFilter|xFilter() method] of a [virtual table] implementation.
9991 ** The result of invoking these interfaces from any other context
9992 ** is undefined and probably harmful.
9993 **
9994 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9995 ** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9996 ** xFilter method which invokes these routines, and specifically
9997 ** a parameter that was previously selected for all-at-once IN constraint
9998 ** processing use the [sqlite3_vtab_in()] interface in the
9999 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10000 ** an xFilter argument that was selected for all-at-once IN constraint
10001 ** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
10002 ** exhibit some other undefined or harmful behavior.
10003 **
10004 ** ^(Use these routines to access all values on the right-hand side
10005 ** of the IN constraint using code like the following:
10006 **
10007 ** <blockquote><pre>
10008 ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
10009 ** &nbsp; rc==SQLITE_OK && pVal
10010 ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
10011 ** &nbsp; ){
10012 ** &nbsp; // do something with pVal
10013 ** &nbsp; }
10014 ** &nbsp; if( rc!=SQLITE_OK ){
10015 ** &nbsp; // an error has occurred
10016 ** &nbsp; }
10017 ** </pre></blockquote>)^
10018 **
10019 ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
10020 ** routines return SQLITE_OK and set *P to point to the first or next value
10021 ** on the RHS of the IN constraint. ^If there are no more values on the
10022 ** right hand side of the IN constraint, then *P is set to NULL and these
10023 ** routines return [SQLITE_DONE]. ^The return value might be
10024 ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
10025 **
10026 ** The *ppOut values returned by these routines are only valid until the
10027 ** next call to either of these routines or until the end of the xFilter
10028 ** method from which these routines were called. If the virtual table
10029 ** implementation needs to retain the *ppOut values for longer, it must make
10030 ** copies. The *ppOut values are [protected sqlite3_value|protected].
10031 */
10032 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
10033 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
10034
10035 /*
10036 ** CAPI3REF: Constraint values in xBestIndex()
10037 ** METHOD: sqlite3_index_info
10038 **
10039 ** This API may only be used from within the [xBestIndex|xBestIndex method]
@@ -14517,14 +14639,15 @@
14639 #define BMS ((int)(sizeof(Bitmask)*8))
14640
14641 /*
14642 ** A bit in a Bitmask
14643 */
14644 #define MASKBIT(n) (((Bitmask)1)<<(n))
14645 #define MASKBIT64(n) (((u64)1)<<(n))
14646 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14647 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
14648 #define ALLBITS ((Bitmask)-1)
14649
14650 /* A VList object records a mapping between parameters/variables/wildcards
14651 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
14652 ** variable number associated with that parameter. See the format description
14653 ** on the sqlite3VListAdd() routine for more information. A VList is really
@@ -15546,21 +15669,22 @@
15669 #define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
15670 #define OP_VBegin 169
15671 #define OP_VCreate 170
15672 #define OP_VDestroy 171
15673 #define OP_VOpen 172
15674 #define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */
15675 #define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */
15676 #define OP_VRename 175
15677 #define OP_Pagecount 176
15678 #define OP_MaxPgcnt 177
15679 #define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */
15680 #define OP_Trace 179
15681 #define OP_CursorHint 180
15682 #define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */
15683 #define OP_Noop 182
15684 #define OP_Explain 183
15685 #define OP_Abortable 184
15686
15687 /* Properties such as "out2" or "jump" that are specified in
15688 ** comments following the "case" for each opcode in the vdbe.c
15689 ** are encoded into bitvectors as follows:
15690 */
@@ -15590,13 +15714,13 @@
15714 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15715 /* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
15716 /* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15717 /* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
15718 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15719 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\
15720 /* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15721 /* 184 */ 0x00,}
15722
15723 /* The resolve3P2Values() routine is able to run faster if it knows
15724 ** the value of the largest JUMP opcode. The smaller the maximum
15725 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15726 ** generated this include file strives to group all JUMP opcodes
@@ -22364,10 +22488,28 @@
22488 i64 iKey2; /* Second key value passed to hook */
22489 Mem *aNew; /* Array of new.* values */
22490 Table *pTab; /* Schema object being upated */
22491 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
22492 };
22493
22494 /*
22495 ** An instance of this object is used to pass an vector of values into
22496 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
22497 ** set of values on the right-hand side of an IN constraint.
22498 **
22499 ** The value as passed into xFilter is an sqlite3_value with a "pointer"
22500 ** type, such as is generated by sqlite3_result_pointer() and read by
22501 ** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
22502 ** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
22503 ** know how to use this object to step through all the values in the
22504 ** right operand of the IN constraint.
22505 */
22506 typedef struct ValueList ValueList;
22507 struct ValueList {
22508 BtCursor *pCsr; /* An ephemeral table holding all values */
22509 sqlite3_value *pOut; /* Register to hold each decoded output value */
22510 };
22511
22512 /*
22513 ** Function prototypes
22514 */
22515 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
@@ -34503,21 +34645,22 @@
34645 /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34646 /* 169 */ "VBegin" OpHelp(""),
34647 /* 170 */ "VCreate" OpHelp(""),
34648 /* 171 */ "VDestroy" OpHelp(""),
34649 /* 172 */ "VOpen" OpHelp(""),
34650 /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34651 /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34652 /* 175 */ "VRename" OpHelp(""),
34653 /* 176 */ "Pagecount" OpHelp(""),
34654 /* 177 */ "MaxPgcnt" OpHelp(""),
34655 /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34656 /* 179 */ "Trace" OpHelp(""),
34657 /* 180 */ "CursorHint" OpHelp(""),
34658 /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34659 /* 182 */ "Noop" OpHelp(""),
34660 /* 183 */ "Explain" OpHelp(""),
34661 /* 184 */ "Abortable" OpHelp(""),
34662 };
34663 return azName[i];
34664 }
34665 #endif
34666
@@ -85604,10 +85747,74 @@
85747 */
85748 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
85749 assert( p );
85750 return sqlite3_value_nochange(p->pOut);
85751 }
85752
85753 /*
85754 ** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
85755 ** sqlite3_vtab_in_next() (if bNext!=0).
85756 */
85757 static int valueFromValueList(
85758 sqlite3_value *pVal, /* Pointer to the ValueList object */
85759 sqlite3_value **ppOut, /* Store the next value from the list here */
85760 int bNext /* 1 for _next(). 0 for _first() */
85761 ){
85762 int rc;
85763 ValueList *pRhs;
85764
85765 *ppOut = 0;
85766 if( pVal==0 ) return SQLITE_MISUSE;
85767 pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
85768 if( pRhs==0 ) return SQLITE_MISUSE;
85769 if( bNext ){
85770 rc = sqlite3BtreeNext(pRhs->pCsr, 0);
85771 }else{
85772 int dummy = 0;
85773 rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy);
85774 assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) );
85775 if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE;
85776 }
85777 if( rc==SQLITE_OK ){
85778 u32 sz; /* Size of current row in bytes */
85779 Mem sMem; /* Raw content of current row */
85780 memset(&sMem, 0, sizeof(sMem));
85781 sz = sqlite3BtreePayloadSize(pRhs->pCsr);
85782 rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem);
85783 if( rc==SQLITE_OK ){
85784 u8 *zBuf = (u8*)sMem.z;
85785 u32 iSerial;
85786 sqlite3_value *pOut = pRhs->pOut;
85787 int iOff = 1 + getVarint32(&zBuf[1], iSerial);
85788 sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut);
85789 pOut->enc = ENC(pOut->db);
85790 if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){
85791 rc = SQLITE_NOMEM;
85792 }else{
85793 *ppOut = pOut;
85794 }
85795 }
85796 sqlite3VdbeMemRelease(&sMem);
85797 }
85798 return rc;
85799 }
85800
85801 /*
85802 ** Set the iterator value pVal to point to the first value in the set.
85803 ** Set (*ppOut) to point to this value before returning.
85804 */
85805 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){
85806 return valueFromValueList(pVal, ppOut, 0);
85807 }
85808
85809 /*
85810 ** Set the iterator value pVal to point to the next value in the set.
85811 ** Set (*ppOut) to point to this value before returning.
85812 */
85813 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){
85814 return valueFromValueList(pVal, ppOut, 1);
85815 }
85816
85817 /*
85818 ** Return the current time for a statement. If the current time
85819 ** is requested more than once within the same run of a single prepared
85820 ** statement, the exact same time is returned for each invocation regardless
@@ -94761,10 +94968,38 @@
94968 goto no_mem;
94969 }
94970 break;
94971 }
94972 #endif /* SQLITE_OMIT_VIRTUALTABLE */
94973
94974 #ifndef SQLITE_OMIT_VIRTUALTABLE
94975 /* Opcode: VInitIn P1 P2 P3 * *
94976 ** Synopsis: r[P2]=ValueList(P1,P3)
94977 **
94978 ** Set register P2 to be a pointer to a ValueList object for cursor P1
94979 ** with cache register P3 and output register P3+1. This ValueList object
94980 ** can be used as the first argument to sqlite3_vtab_in_first() and
94981 ** sqlite3_vtab_in_next() to extract all of the values stored in the P1
94982 ** cursor. Register P3 is used to hold the values returned by
94983 ** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
94984 */
94985 case OP_VInitIn: { /* out2 */
94986 VdbeCursor *pC; /* The cursor containing the RHS values */
94987 ValueList *pRhs; /* New ValueList object to put in reg[P2] */
94988
94989 pC = p->apCsr[pOp->p1];
94990 pRhs = sqlite3_malloc64( sizeof(*pRhs) );
94991 if( pRhs==0 ) goto no_mem;
94992 pRhs->pCsr = pC->uc.pCursor;
94993 pRhs->pOut = &aMem[pOp->p3];
94994 pOut = out2Prerelease(p, pOp);
94995 pOut->flags = MEM_Null;
94996 sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
94997 break;
94998 }
94999 #endif /* SQLITE_OMIT_VIRTUALTABLE */
95000
95001
95002 #ifndef SQLITE_OMIT_VIRTUALTABLE
95003 /* Opcode: VFilter P1 P2 P3 P4 *
95004 ** Synopsis: iplan=r[P3] zplan='P4'
95005 **
@@ -101005,11 +101240,11 @@
101240 && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0
101241 ){
101242 /* Internal-use-only functions are disallowed unless the
101243 ** SQL is being compiled using sqlite3NestedParse() or
101244 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
101245 ** used to activate internal functions for testing purposes */
101246 no_such_func = 1;
101247 pDef = 0;
101248 }else
101249 if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0
101250 && !IN_RENAME_OBJECT
@@ -105562,11 +105797,10 @@
105797 if( destIfNull==destIfFalse ){
105798 destStep2 = destIfFalse;
105799 }else{
105800 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105801 }
 
105802 for(i=0; i<nVector; i++){
105803 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105804 if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105805 if( sqlite3ExprCanBeNull(p) ){
105806 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
@@ -120729,10 +120963,11 @@
120963 static void subtypeFunc(
120964 sqlite3_context *context,
120965 int argc,
120966 sqlite3_value **argv
120967 ){
120968 UNUSED_PARAMETER(argc);
120969 sqlite3_result_int(context, sqlite3_value_subtype(argv[0]));
120970 }
120971
120972 /*
120973 ** Implementation of the length() function
@@ -128130,10 +128365,13 @@
128365 void*, void(*)(void*));
128366 /* Version 3.38.0 and later */
128367 int (*error_offset)(sqlite3*);
128368 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128369 int (*vtab_distinct)(sqlite3_index_info*);
128370 int (*vtab_in)(sqlite3_index_info*,int,int);
128371 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128372 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
128373 };
128374
128375 /*
128376 ** This is the function signature used for all extension entry points. It
128377 ** is also defined in the file "loadext.c".
@@ -128445,10 +128683,13 @@
128683 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128684 /* Version 3.38.0 and later */
128685 #define sqlite3_error_offset sqlite3_api->error_offset
128686 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128687 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128688 #define sqlite3_vtab_in sqlite3_api->vtab_in
128689 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
128690 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
128691 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128692
128693 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128694 /* This case when the file really is being compiled as a loadable
128695 ** extension */
@@ -128938,10 +129179,13 @@
129179 sqlite3_autovacuum_pages,
129180 /* Version 3.38.0 and later */
129181 sqlite3_error_offset,
129182 sqlite3_vtab_rhs_value,
129183 sqlite3_vtab_distinct,
129184 sqlite3_vtab_in,
129185 sqlite3_vtab_in_first,
129186 sqlite3_vtab_in_next
129187 };
129188
129189 /* True if x is the directory separator character
129190 */
129191 #if SQLITE_OS_WIN
@@ -146506,15 +146750,16 @@
146750 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
146751 Index *pIndex; /* Index used, or NULL */
146752 } btree;
146753 struct { /* Information for virtual tables */
146754 int idxNum; /* Index number */
146755 u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
146756 u32 bOmitOffset : 1; /* True to let virtual table handle offset */
146757 i8 isOrdered; /* True if satisfies ORDER BY */
146758 u16 omitMask; /* Terms that may be omitted */
146759 char *idxStr; /* Index identifier string */
146760 u32 mHandleIn; /* Terms to handle as IN(...) instead of == */
146761 } vtab;
146762 } u;
146763 u32 wsFlags; /* WHERE_* flags describing the plan */
146764 u16 nLTerm; /* Number of entries in aLTerm[] */
146765 u16 nSkip; /* Number of NULL aLTerm[] entries */
@@ -146667,10 +146912,11 @@
146912 #ifdef SQLITE_ENABLE_STAT4
146913 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */
146914 #else
146915 # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */
146916 #endif
146917 #define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */
146918
146919 /*
146920 ** An instance of the WhereScan object is used as an iterator for locating
146921 ** terms in the WHERE clause that are useful to the query planner.
146922 */
@@ -148515,12 +148761,19 @@
148761 for(j=0; j<nConstraint; j++){
148762 int iTarget = iReg+j+2;
148763 pTerm = pLoop->aLTerm[j];
148764 if( NEVER(pTerm==0) ) continue;
148765 if( pTerm->eOperator & WO_IN ){
148766 if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){
148767 int iTab = pParse->nTab++;
148768 int iCache = ++pParse->nMem;
148769 sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab);
148770 sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache);
148771 }else{
148772 codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget);
148773 addrNotFound = pLevel->addrNxt;
148774 }
148775 }else{
148776 Expr *pRight = pTerm->pExpr->pRight;
148777 codeExprOrVector(pParse, pRight, iTarget, 1);
148778 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET
148779 && pLoop->u.vtab.bOmitOffset
@@ -148551,17 +148804,23 @@
148804 iIn = pLevel->u.in.nIn;
148805 }else{
148806 iIn = 0;
148807 }
148808 for(j=nConstraint-1; j>=0; j--){
148809 int bIn; /* True to generate byte code to loop over RHS IN values */
148810 pTerm = pLoop->aLTerm[j];
148811 if( (pTerm->eOperator & WO_IN)!=0
148812 && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
148813 ){
148814 bIn = 1;
148815 }else{
148816 bIn = 0;
148817 }
148818 if( bIn ) iIn--;
148819 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
148820 disableTerm(pLevel, pTerm);
148821 }else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){
 
 
148822 Expr *pCompare; /* The comparison operator */
148823 Expr *pRight; /* RHS of the comparison */
148824 VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
148825
148826 /* Reload the constraint value into reg[iReg+j+2]. The same value
@@ -149287,11 +149546,11 @@
149546 regRowid = ++pParse->nMem;
149547 }
149548 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
149549
149550 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
149551 ** Then for every term xN, evaluate as the subexpression: xN AND y
149552 ** That way, terms in y that are factored into the disjunction will
149553 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
149554 **
149555 ** Actually, each subexpression is converted to "xN AND w" where w is
149556 ** the "interesting" terms of z - terms that did not originate in the
@@ -149299,19 +149558,28 @@
149558 ** indices.
149559 **
149560 ** This optimization also only applies if the (x1 OR x2 OR ...) term
149561 ** is not contained in the ON clause of a LEFT JOIN.
149562 ** See ticket http://www.sqlite.org/src/info/f2369304e4
149563 **
149564 ** 2022-02-04: Do not push down slices of a row-value comparison.
149565 ** In other words, "w" or "y" may not be a slice of a vector. Otherwise,
149566 ** the initialization of the right-hand operand of the vector comparison
149567 ** might not occur, or might occur only in an OR branch that is not
149568 ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
149569 */
149570 if( pWC->nTerm>1 ){
149571 int iTerm;
149572 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
149573 Expr *pExpr = pWC->a[iTerm].pExpr;
149574 if( &pWC->a[iTerm] == pTerm ) continue;
149575 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
149576 testcase( pWC->a[iTerm].wtFlags & TERM_CODED );
149577 testcase( pWC->a[iTerm].wtFlags & TERM_SLICE );
149578 if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
149579 continue;
149580 }
149581 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
149582 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
149583 pExpr = sqlite3ExprDup(db, pExpr, 0);
149584 pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
149585 }
@@ -150090,11 +150358,11 @@
150358 void *pNotUsed;
150359 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
150360 assert( pVtab!=0 );
150361 assert( pVtab->pModule!=0 );
150362 assert( !ExprHasProperty(pExpr, EP_IntValue) );
150363 pMod = (sqlite3_module *)pVtab->pModule;
150364 if( pMod->xFindFunction!=0 ){
150365 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
150366 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
150367 *peOp2 = i;
150368 *ppRight = pList->a[1].pExpr;
@@ -151067,11 +151335,11 @@
151335 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft);
151336 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft);
151337
151338 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
151339 transferJoinMarkings(pNew, pExpr);
151340 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
151341 exprAnalyze(pSrc, pWC, idxNew);
151342 }
151343 pTerm = &pWC->a[idxTerm];
151344 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
151345 pTerm->eOperator = 0;
@@ -151541,10 +151809,12 @@
151809 typedef struct HiddenIndexInfo HiddenIndexInfo;
151810 struct HiddenIndexInfo {
151811 WhereClause *pWC; /* The Where clause being analyzed */
151812 Parse *pParse; /* The parsing context */
151813 int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151814 u32 mIn; /* Mask of terms that are <col> IN (...) */
151815 u32 mHandleIn; /* Terms that vtab will handle as <col> IN (...) */
151816 sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151817 ** because extra space is allocated to hold up
151818 ** to nTerm such values */
151819 };
151820
@@ -152651,10 +152921,11 @@
152921 testcase( pTerm->eOperator & WO_ISNULL );
152922 testcase( pTerm->eOperator & WO_IS );
152923 testcase( pTerm->eOperator & WO_ALL );
152924 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
152925 if( pTerm->wtFlags & TERM_VNULL ) continue;
152926
152927 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152928 assert( pTerm->u.x.leftColumn>=XN_ROWID );
152929 assert( pTerm->u.x.leftColumn<pTab->nCol );
152930
152931 /* tag-20191211-002: WHERE-clause constraints are not useful to the
@@ -152712,11 +152983,11 @@
152983 }
152984
152985 /* No matches cause a break out of the loop */
152986 break;
152987 }
152988 if( i==n ){
152989 nOrderBy = n;
152990 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152991 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152992 }
152993 }
@@ -152740,17 +153011,21 @@
153011 pIdxInfo->aOrderBy = pIdxOrderBy;
153012 pIdxInfo->aConstraintUsage = pUsage;
153013 pHidden->pWC = pWC;
153014 pHidden->pParse = pParse;
153015 pHidden->eDistinct = eDistinct;
153016 pHidden->mIn = 0;
153017 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
153018 u16 op;
153019 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
153020 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
153021 pIdxCons[j].iTermOffset = i;
153022 op = pTerm->eOperator & WO_ALL;
153023 if( op==WO_IN ){
153024 pHidden->mIn |= SMASKBIT32(j);
153025 op = WO_EQ;
153026 }
153027 if( op==WO_AUX ){
153028 pIdxCons[j].op = pTerm->eMatchOp;
153029 }else if( op & (WO_ISNULL|WO_IS) ){
153030 if( op==WO_ISNULL ){
153031 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
@@ -152836,11 +153111,13 @@
153111 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
153112 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
153113 int rc;
153114
153115 whereTraceIndexInfoInputs(p);
153116 pParse->db->nSchemaLock++;
153117 rc = pVtab->pModule->xBestIndex(pVtab, p);
153118 pParse->db->nSchemaLock--;
153119 whereTraceIndexInfoOutputs(p);
153120
153121 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
153122 if( rc==SQLITE_NOMEM ){
153123 sqlite3OomFault(pParse->db);
@@ -155007,10 +155284,11 @@
155284 u16 mNoOmit, /* Do not omit these constraints */
155285 int *pbIn, /* OUT: True if plan uses an IN(...) op */
155286 int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */
155287 ){
155288 WhereClause *pWC = pBuilder->pWC;
155289 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155290 struct sqlite3_index_constraint *pIdxCons;
155291 struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
155292 int i;
155293 int mxTerm;
155294 int rc = SQLITE_OK;
@@ -155045,10 +155323,11 @@
155323 pIdxInfo->orderByConsumed = 0;
155324 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
155325 pIdxInfo->estimatedRows = 25;
155326 pIdxInfo->idxFlags = 0;
155327 pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
155328 pHidden->mHandleIn = 0;
155329
155330 /* Invoke the virtual table xBestIndex() method */
155331 rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
155332 if( rc ){
155333 if( rc==SQLITE_CONSTRAINT ){
@@ -155101,11 +155380,13 @@
155380 }
155381 if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){
155382 pNew->u.vtab.bOmitOffset = 1;
155383 }
155384 }
155385 if( SMASKBIT32(i) & pHidden->mHandleIn ){
155386 pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm);
155387 }else if( (pTerm->eOperator & WO_IN)!=0 ){
155388 /* A virtual table that is constrained by an IN clause may not
155389 ** consume the ORDER BY clause because (1) the order of IN terms
155390 ** is not necessarily related to the order of output terms and
155391 ** (2) Multiple outputs from a single IN value will not merge
155392 ** together. */
@@ -155198,10 +155479,29 @@
155479 }
155480 zRet = (pC ? pC->zName : sqlite3StrBINARY);
155481 }
155482 return zRet;
155483 }
155484
155485 /*
155486 ** Return true if constraint iCons is really an IN(...) constraint, or
155487 ** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0)
155488 ** or clear (if bHandle==0) the flag to handle it using an iterator.
155489 */
155490 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){
155491 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155492 u32 m = SMASKBIT32(iCons);
155493 if( m & pHidden->mIn ){
155494 if( bHandle==0 ){
155495 pHidden->mHandleIn &= ~m;
155496 }else if( bHandle>0 ){
155497 pHidden->mHandleIn |= m;
155498 }
155499 return 1;
155500 }
155501 return 0;
155502 }
155503
155504 /*
155505 ** This interface is callable from within the xBestIndex callback only.
155506 **
155507 ** If possible, set (*ppVal) to point to an object containing the value
@@ -195222,11 +195522,11 @@
195522 sqlite3_module *pModule;
195523 } aMod[] = {
195524 { "json_each", &jsonEachModule },
195525 { "json_tree", &jsonTreeModule },
195526 };
195527 unsigned int i;
195528 for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){
195529 rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0);
195530 }
195531 return rc;
195532 }
@@ -233819,11 +234119,11 @@
234119 int nArg, /* Number of args */
234120 sqlite3_value **apUnused /* Function arguments */
234121 ){
234122 assert( nArg==0 );
234123 UNUSED_PARAM2(nArg, apUnused);
234124 sqlite3_result_text(pCtx, "fts5: 2022-01-25 16:28:57 6e4154d414afe2562b488149b10c175d1f15bd1d5060ee479d5ae9386a2e277e", -1, SQLITE_TRANSIENT);
234125 }
234126
234127 /*
234128 ** Return true if zName is the extension on one of the shadow tables used
234129 ** by this module.
234130
+123 -1
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2022-02-01 13:17:11 00b1b7020a564976da3237532434e47ccf17eb5d620e6ac45f3e70b5d5739200"
151
+#define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -9602,10 +9602,132 @@
96029602
** valid to do so, on the other hand, might cause SQLite to return incorrect
96039603
** results.
96049604
*/
96059605
SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
96069606
9607
+/*
9608
+** CAPI3REF: Identify and handle IN constraints in xBestIndex
9609
+**
9610
+** This interface may only be used from within an
9611
+** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9612
+** The result of invoking this interface from any other context is
9613
+** undefined and probably harmful.
9614
+**
9615
+** ^(A constraint on a virtual table of the form
9616
+** "[IN operator|column IN (...)]" is
9617
+** communicated to the xBestIndex method as a
9618
+** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9619
+** this constraint, it must set the corresponding
9620
+** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9621
+** the usual mode of handling IN operators, SQLite generates [bytecode]
9622
+** that invokes the [xFilter|xFilter() method] once for each value
9623
+** on the right-hand side of the IN operator.)^ Thus the virtual table
9624
+** only sees a single value from the right-hand side of the IN operator
9625
+** at a time.
9626
+**
9627
+** In some cases, however, it would be advantageous for the virtual
9628
+** table to see all values on the right-hand of the IN operator all at
9629
+** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9630
+**
9631
+** <ol>
9632
+** <li><p>
9633
+** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9634
+** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9635
+** is an [IN operator] that can be processed all at once. ^In other words,
9636
+** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9637
+** by which the virtual table can ask SQLite if all-at-once processing
9638
+** of the IN operator is even possible.
9639
+**
9640
+** <li><p>
9641
+** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9642
+** to SQLite that the virtual table does or does not want to process
9643
+** the IN operator all-at-once, respectively. ^Thus when the third
9644
+** parameter (F) is non-negative, this interface is the mechanism by
9645
+** which the virtual table tells SQLite how it wants to process the
9646
+** IN operator.
9647
+** </ol>
9648
+**
9649
+** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9650
+** within the same xBestIndex method call. ^For any given P,N pair,
9651
+** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9652
+** within the same xBestIndex call. ^If the interface returns true
9653
+** (non-zero), that means that the constraint is an IN operator
9654
+** that can be processed all-at-once. ^If the constraint is not an IN
9655
+** operator or cannot be processed all-at-once, then the interface returns
9656
+** false.
9657
+**
9658
+** ^(All-at-once processing of the IN operator is selected if both of the
9659
+** following conditions are met:
9660
+**
9661
+** <ol>
9662
+** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9663
+** integer. This is how the virtual table tells SQLite that it wants to
9664
+** use the N-th constraint.
9665
+**
9666
+** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9667
+** non-negative had F>=1.
9668
+** </ol>)^
9669
+**
9670
+** ^If either or both of the conditions above are false, then SQLite uses
9671
+** the traditional one-at-a-time processing strategy for the IN constraint.
9672
+** ^If both conditions are true, then the argvIndex-th parameter to the
9673
+** xFilter method will be an [sqlite3_value] that appears to be NULL,
9674
+** but which can be passed to [sqlite3_vtab_in_first()] and
9675
+** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9676
+** of the IN constraint.
9677
+*/
9678
+SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9679
+
9680
+/*
9681
+** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9682
+**
9683
+** These interfaces are only useful from within the
9684
+** [xFilter|xFilter() method] of a [virtual table] implementation.
9685
+** The result of invoking these interfaces from any other context
9686
+** is undefined and probably harmful.
9687
+**
9688
+** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9689
+** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9690
+** xFilter method which invokes these routines, and specifically
9691
+** a parameter that was previously selected for all-at-once IN constraint
9692
+** processing use the [sqlite3_vtab_in()] interface in the
9693
+** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
9694
+** an xFilter argument that was selected for all-at-once IN constraint
9695
+** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
9696
+** exhibit some other undefined or harmful behavior.
9697
+**
9698
+** ^(Use these routines to access all values on the right-hand side
9699
+** of the IN constraint using code like the following:
9700
+**
9701
+** <blockquote><pre>
9702
+** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
9703
+** &nbsp; rc==SQLITE_OK && pVal
9704
+** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
9705
+** &nbsp; ){
9706
+** &nbsp; // do something with pVal
9707
+** &nbsp; }
9708
+** &nbsp; if( rc!=SQLITE_OK ){
9709
+** &nbsp; // an error has occurred
9710
+** &nbsp; }
9711
+** </pre></blockquote>)^
9712
+**
9713
+** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
9714
+** routines return SQLITE_OK and set *P to point to the first or next value
9715
+** on the RHS of the IN constraint. ^If there are no more values on the
9716
+** right hand side of the IN constraint, then *P is set to NULL and these
9717
+** routines return [SQLITE_DONE]. ^The return value might be
9718
+** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
9719
+**
9720
+** The *ppOut values returned by these routines are only valid until the
9721
+** next call to either of these routines or until the end of the xFilter
9722
+** method from which these routines were called. If the virtual table
9723
+** implementation needs to retain the *ppOut values for longer, it must make
9724
+** copies. The *ppOut values are [protected sqlite3_value|protected].
9725
+*/
9726
+SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
9727
+SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
9728
+
96079729
/*
96089730
** CAPI3REF: Constraint values in xBestIndex()
96099731
** METHOD: sqlite3_index_info
96109732
**
96119733
** This API may only be used from within the [xBestIndex|xBestIndex method]
96129734
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-01 13:17:11 00b1b7020a564976da3237532434e47ccf17eb5d620e6ac45f3e70b5d5739200"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -9602,10 +9602,132 @@
9602 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9603 ** results.
9604 */
9605 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9607 /*
9608 ** CAPI3REF: Constraint values in xBestIndex()
9609 ** METHOD: sqlite3_index_info
9610 **
9611 ** This API may only be used from within the [xBestIndex|xBestIndex method]
9612
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-05 01:01:07 1ec747d1c34ced9877709dd306e674376e79145de08b9c316d12bc5e06efc03e"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -9602,10 +9602,132 @@
9602 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9603 ** results.
9604 */
9605 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9606
9607 /*
9608 ** CAPI3REF: Identify and handle IN constraints in xBestIndex
9609 **
9610 ** This interface may only be used from within an
9611 ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
9612 ** The result of invoking this interface from any other context is
9613 ** undefined and probably harmful.
9614 **
9615 ** ^(A constraint on a virtual table of the form
9616 ** "[IN operator|column IN (...)]" is
9617 ** communicated to the xBestIndex method as a
9618 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9619 ** this constraint, it must set the corresponding
9620 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9621 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9622 ** that invokes the [xFilter|xFilter() method] once for each value
9623 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9624 ** only sees a single value from the right-hand side of the IN operator
9625 ** at a time.
9626 **
9627 ** In some cases, however, it would be advantageous for the virtual
9628 ** table to see all values on the right-hand of the IN operator all at
9629 ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:
9630 **
9631 ** <ol>
9632 ** <li><p>
9633 ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
9634 ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
9635 ** is an [IN operator] that can be processed all at once. ^In other words,
9636 ** sqlite3_vtab_in() with -1 in the third argument is a mechanism
9637 ** by which the virtual table can ask SQLite if all-at-once processing
9638 ** of the IN operator is even possible.
9639 **
9640 ** <li><p>
9641 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
9642 ** to SQLite that the virtual table does or does not want to process
9643 ** the IN operator all-at-once, respectively. ^Thus when the third
9644 ** parameter (F) is non-negative, this interface is the mechanism by
9645 ** which the virtual table tells SQLite how it wants to process the
9646 ** IN operator.
9647 ** </ol>
9648 **
9649 ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
9650 ** within the same xBestIndex method call. ^For any given P,N pair,
9651 ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
9652 ** within the same xBestIndex call. ^If the interface returns true
9653 ** (non-zero), that means that the constraint is an IN operator
9654 ** that can be processed all-at-once. ^If the constraint is not an IN
9655 ** operator or cannot be processed all-at-once, then the interface returns
9656 ** false.
9657 **
9658 ** ^(All-at-once processing of the IN operator is selected if both of the
9659 ** following conditions are met:
9660 **
9661 ** <ol>
9662 ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
9663 ** integer. This is how the virtual table tells SQLite that it wants to
9664 ** use the N-th constraint.
9665 **
9666 ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
9667 ** non-negative had F>=1.
9668 ** </ol>)^
9669 **
9670 ** ^If either or both of the conditions above are false, then SQLite uses
9671 ** the traditional one-at-a-time processing strategy for the IN constraint.
9672 ** ^If both conditions are true, then the argvIndex-th parameter to the
9673 ** xFilter method will be an [sqlite3_value] that appears to be NULL,
9674 ** but which can be passed to [sqlite3_vtab_in_first()] and
9675 ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
9676 ** of the IN constraint.
9677 */
9678 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9679
9680 /*
9681 ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
9682 **
9683 ** These interfaces are only useful from within the
9684 ** [xFilter|xFilter() method] of a [virtual table] implementation.
9685 ** The result of invoking these interfaces from any other context
9686 ** is undefined and probably harmful.
9687 **
9688 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9689 ** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9690 ** xFilter method which invokes these routines, and specifically
9691 ** a parameter that was previously selected for all-at-once IN constraint
9692 ** processing use the [sqlite3_vtab_in()] interface in the
9693 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
9694 ** an xFilter argument that was selected for all-at-once IN constraint
9695 ** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
9696 ** exhibit some other undefined or harmful behavior.
9697 **
9698 ** ^(Use these routines to access all values on the right-hand side
9699 ** of the IN constraint using code like the following:
9700 **
9701 ** <blockquote><pre>
9702 ** &nbsp; for(rc=sqlite3_vtab_in_first(pList, &pVal);
9703 ** &nbsp; rc==SQLITE_OK && pVal
9704 ** &nbsp; rc=sqlite3_vtab_in_next(pList, &pVal)
9705 ** &nbsp; ){
9706 ** &nbsp; // do something with pVal
9707 ** &nbsp; }
9708 ** &nbsp; if( rc!=SQLITE_OK ){
9709 ** &nbsp; // an error has occurred
9710 ** &nbsp; }
9711 ** </pre></blockquote>)^
9712 **
9713 ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
9714 ** routines return SQLITE_OK and set *P to point to the first or next value
9715 ** on the RHS of the IN constraint. ^If there are no more values on the
9716 ** right hand side of the IN constraint, then *P is set to NULL and these
9717 ** routines return [SQLITE_DONE]. ^The return value might be
9718 ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
9719 **
9720 ** The *ppOut values returned by these routines are only valid until the
9721 ** next call to either of these routines or until the end of the xFilter
9722 ** method from which these routines were called. If the virtual table
9723 ** implementation needs to retain the *ppOut values for longer, it must make
9724 ** copies. The *ppOut values are [protected sqlite3_value|protected].
9725 */
9726 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
9727 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
9728
9729 /*
9730 ** CAPI3REF: Constraint values in xBestIndex()
9731 ** METHOD: sqlite3_index_info
9732 **
9733 ** This API may only be used from within the [xBestIndex|xBestIndex method]
9734

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button