Fossil SCM
Update the built-in SQLite to the latest 3.38.0 beta.
Commit
82bbde8d0f3d600526b51536114d5ec9dd386b6d1e81f0ed82720abf56c9d52f
Parent
9e420127423fb7c…
2 files changed
+349
-49
+123
-1
+349
-49
| --- extsrc/sqlite3.c | ||
| +++ extsrc/sqlite3.c | ||
| @@ -452,11 +452,11 @@ | ||
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.38.0" |
| 456 | 456 | #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" | |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| @@ -9908,10 +9908,132 @@ | ||
| 9908 | 9908 | ** valid to do so, on the other hand, might cause SQLite to return incorrect |
| 9909 | 9909 | ** results. |
| 9910 | 9910 | */ |
| 9911 | 9911 | SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); |
| 9912 | 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 | +** for(rc=sqlite3_vtab_in_first(pList, &pVal); | |
| 10009 | +** rc==SQLITE_OK && pVal | |
| 10010 | +** rc=sqlite3_vtab_in_next(pList, &pVal) | |
| 10011 | +** ){ | |
| 10012 | +** // do something with pVal | |
| 10013 | +** } | |
| 10014 | +** if( rc!=SQLITE_OK ){ | |
| 10015 | +** // an error has occurred | |
| 10016 | +** } | |
| 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 | + | |
| 9913 | 10035 | /* |
| 9914 | 10036 | ** CAPI3REF: Constraint values in xBestIndex() |
| 9915 | 10037 | ** METHOD: sqlite3_index_info |
| 9916 | 10038 | ** |
| 9917 | 10039 | ** This API may only be used from within the [xBestIndex|xBestIndex method] |
| @@ -14517,14 +14639,15 @@ | ||
| 14517 | 14639 | #define BMS ((int)(sizeof(Bitmask)*8)) |
| 14518 | 14640 | |
| 14519 | 14641 | /* |
| 14520 | 14642 | ** A bit in a Bitmask |
| 14521 | 14643 | */ |
| 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) | |
| 14526 | 14649 | |
| 14527 | 14650 | /* A VList object records a mapping between parameters/variables/wildcards |
| 14528 | 14651 | ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer |
| 14529 | 14652 | ** variable number associated with that parameter. See the format description |
| 14530 | 14653 | ** on the sqlite3VListAdd() routine for more information. A VList is really |
| @@ -15546,21 +15669,22 @@ | ||
| 15546 | 15669 | #define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15547 | 15670 | #define OP_VBegin 169 |
| 15548 | 15671 | #define OP_VCreate 170 |
| 15549 | 15672 | #define OP_VDestroy 171 |
| 15550 | 15673 | #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 | |
| 15562 | 15686 | |
| 15563 | 15687 | /* Properties such as "out2" or "jump" that are specified in |
| 15564 | 15688 | ** comments following the "case" for each opcode in the vdbe.c |
| 15565 | 15689 | ** are encoded into bitvectors as follows: |
| 15566 | 15690 | */ |
| @@ -15590,13 +15714,13 @@ | ||
| 15590 | 15714 | /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ |
| 15591 | 15715 | /* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\ |
| 15592 | 15716 | /* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15593 | 15717 | /* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\ |
| 15594 | 15718 | /* 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,} | |
| 15598 | 15722 | |
| 15599 | 15723 | /* The resolve3P2Values() routine is able to run faster if it knows |
| 15600 | 15724 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 15601 | 15725 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 15602 | 15726 | ** generated this include file strives to group all JUMP opcodes |
| @@ -22364,10 +22488,28 @@ | ||
| 22364 | 22488 | i64 iKey2; /* Second key value passed to hook */ |
| 22365 | 22489 | Mem *aNew; /* Array of new.* values */ |
| 22366 | 22490 | Table *pTab; /* Schema object being upated */ |
| 22367 | 22491 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 22368 | 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 | +}; | |
| 22369 | 22511 | |
| 22370 | 22512 | /* |
| 22371 | 22513 | ** Function prototypes |
| 22372 | 22514 | */ |
| 22373 | 22515 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| @@ -34503,21 +34645,22 @@ | ||
| 34503 | 34645 | /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 34504 | 34646 | /* 169 */ "VBegin" OpHelp(""), |
| 34505 | 34647 | /* 170 */ "VCreate" OpHelp(""), |
| 34506 | 34648 | /* 171 */ "VDestroy" OpHelp(""), |
| 34507 | 34649 | /* 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(""), | |
| 34519 | 34662 | }; |
| 34520 | 34663 | return azName[i]; |
| 34521 | 34664 | } |
| 34522 | 34665 | #endif |
| 34523 | 34666 | |
| @@ -85604,10 +85747,74 @@ | ||
| 85604 | 85747 | */ |
| 85605 | 85748 | SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){ |
| 85606 | 85749 | assert( p ); |
| 85607 | 85750 | return sqlite3_value_nochange(p->pOut); |
| 85608 | 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 | +} | |
| 85609 | 85816 | |
| 85610 | 85817 | /* |
| 85611 | 85818 | ** Return the current time for a statement. If the current time |
| 85612 | 85819 | ** is requested more than once within the same run of a single prepared |
| 85613 | 85820 | ** statement, the exact same time is returned for each invocation regardless |
| @@ -94761,10 +94968,38 @@ | ||
| 94761 | 94968 | goto no_mem; |
| 94762 | 94969 | } |
| 94763 | 94970 | break; |
| 94764 | 94971 | } |
| 94765 | 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 | + | |
| 94766 | 95001 | |
| 94767 | 95002 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 94768 | 95003 | /* Opcode: VFilter P1 P2 P3 P4 * |
| 94769 | 95004 | ** Synopsis: iplan=r[P3] zplan='P4' |
| 94770 | 95005 | ** |
| @@ -101005,11 +101240,11 @@ | ||
| 101005 | 101240 | && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 101006 | 101241 | ){ |
| 101007 | 101242 | /* Internal-use-only functions are disallowed unless the |
| 101008 | 101243 | ** SQL is being compiled using sqlite3NestedParse() or |
| 101009 | 101244 | ** 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 */ | |
| 101011 | 101246 | no_such_func = 1; |
| 101012 | 101247 | pDef = 0; |
| 101013 | 101248 | }else |
| 101014 | 101249 | if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 101015 | 101250 | && !IN_RENAME_OBJECT |
| @@ -105562,11 +105797,10 @@ | ||
| 105562 | 105797 | if( destIfNull==destIfFalse ){ |
| 105563 | 105798 | destStep2 = destIfFalse; |
| 105564 | 105799 | }else{ |
| 105565 | 105800 | destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse); |
| 105566 | 105801 | } |
| 105567 | -// if( pParse->nErr ) goto sqlite3ExprCodeIN_finished; | |
| 105568 | 105802 | for(i=0; i<nVector; i++){ |
| 105569 | 105803 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 105570 | 105804 | if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; |
| 105571 | 105805 | if( sqlite3ExprCanBeNull(p) ){ |
| 105572 | 105806 | sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); |
| @@ -120729,10 +120963,11 @@ | ||
| 120729 | 120963 | static void subtypeFunc( |
| 120730 | 120964 | sqlite3_context *context, |
| 120731 | 120965 | int argc, |
| 120732 | 120966 | sqlite3_value **argv |
| 120733 | 120967 | ){ |
| 120968 | + UNUSED_PARAMETER(argc); | |
| 120734 | 120969 | sqlite3_result_int(context, sqlite3_value_subtype(argv[0])); |
| 120735 | 120970 | } |
| 120736 | 120971 | |
| 120737 | 120972 | /* |
| 120738 | 120973 | ** Implementation of the length() function |
| @@ -128130,10 +128365,13 @@ | ||
| 128130 | 128365 | void*, void(*)(void*)); |
| 128131 | 128366 | /* Version 3.38.0 and later */ |
| 128132 | 128367 | int (*error_offset)(sqlite3*); |
| 128133 | 128368 | int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**); |
| 128134 | 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**); | |
| 128135 | 128373 | }; |
| 128136 | 128374 | |
| 128137 | 128375 | /* |
| 128138 | 128376 | ** This is the function signature used for all extension entry points. It |
| 128139 | 128377 | ** is also defined in the file "loadext.c". |
| @@ -128445,10 +128683,13 @@ | ||
| 128445 | 128683 | #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages |
| 128446 | 128684 | /* Version 3.38.0 and later */ |
| 128447 | 128685 | #define sqlite3_error_offset sqlite3_api->error_offset |
| 128448 | 128686 | #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value |
| 128449 | 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 | |
| 128450 | 128691 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 128451 | 128692 | |
| 128452 | 128693 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 128453 | 128694 | /* This case when the file really is being compiled as a loadable |
| 128454 | 128695 | ** extension */ |
| @@ -128938,10 +129179,13 @@ | ||
| 128938 | 129179 | sqlite3_autovacuum_pages, |
| 128939 | 129180 | /* Version 3.38.0 and later */ |
| 128940 | 129181 | sqlite3_error_offset, |
| 128941 | 129182 | sqlite3_vtab_rhs_value, |
| 128942 | 129183 | sqlite3_vtab_distinct, |
| 129184 | + sqlite3_vtab_in, | |
| 129185 | + sqlite3_vtab_in_first, | |
| 129186 | + sqlite3_vtab_in_next | |
| 128943 | 129187 | }; |
| 128944 | 129188 | |
| 128945 | 129189 | /* True if x is the directory separator character |
| 128946 | 129190 | */ |
| 128947 | 129191 | #if SQLITE_OS_WIN |
| @@ -146506,15 +146750,16 @@ | ||
| 146506 | 146750 | u16 nDistinctCol; /* Index columns used to sort for DISTINCT */ |
| 146507 | 146751 | Index *pIndex; /* Index used, or NULL */ |
| 146508 | 146752 | } btree; |
| 146509 | 146753 | struct { /* Information for virtual tables */ |
| 146510 | 146754 | 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 */ | |
| 146513 | 146757 | i8 isOrdered; /* True if satisfies ORDER BY */ |
| 146514 | 146758 | u16 omitMask; /* Terms that may be omitted */ |
| 146515 | 146759 | char *idxStr; /* Index identifier string */ |
| 146760 | + u32 mHandleIn; /* Terms to handle as IN(...) instead of == */ | |
| 146516 | 146761 | } vtab; |
| 146517 | 146762 | } u; |
| 146518 | 146763 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 146519 | 146764 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 146520 | 146765 | u16 nSkip; /* Number of NULL aLTerm[] entries */ |
| @@ -146667,10 +146912,11 @@ | ||
| 146667 | 146912 | #ifdef SQLITE_ENABLE_STAT4 |
| 146668 | 146913 | # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */ |
| 146669 | 146914 | #else |
| 146670 | 146915 | # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ |
| 146671 | 146916 | #endif |
| 146917 | +#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */ | |
| 146672 | 146918 | |
| 146673 | 146919 | /* |
| 146674 | 146920 | ** An instance of the WhereScan object is used as an iterator for locating |
| 146675 | 146921 | ** terms in the WHERE clause that are useful to the query planner. |
| 146676 | 146922 | */ |
| @@ -148515,12 +148761,19 @@ | ||
| 148515 | 148761 | for(j=0; j<nConstraint; j++){ |
| 148516 | 148762 | int iTarget = iReg+j+2; |
| 148517 | 148763 | pTerm = pLoop->aLTerm[j]; |
| 148518 | 148764 | if( NEVER(pTerm==0) ) continue; |
| 148519 | 148765 | 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 | + } | |
| 148522 | 148775 | }else{ |
| 148523 | 148776 | Expr *pRight = pTerm->pExpr->pRight; |
| 148524 | 148777 | codeExprOrVector(pParse, pRight, iTarget, 1); |
| 148525 | 148778 | if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET |
| 148526 | 148779 | && pLoop->u.vtab.bOmitOffset |
| @@ -148551,17 +148804,23 @@ | ||
| 148551 | 148804 | iIn = pLevel->u.in.nIn; |
| 148552 | 148805 | }else{ |
| 148553 | 148806 | iIn = 0; |
| 148554 | 148807 | } |
| 148555 | 148808 | for(j=nConstraint-1; j>=0; j--){ |
| 148809 | + int bIn; /* True to generate byte code to loop over RHS IN values */ | |
| 148556 | 148810 | 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--; | |
| 148558 | 148819 | if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ |
| 148559 | 148820 | 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 ){ | |
| 148563 | 148822 | Expr *pCompare; /* The comparison operator */ |
| 148564 | 148823 | Expr *pRight; /* RHS of the comparison */ |
| 148565 | 148824 | VdbeOp *pOp; /* Opcode to access the value of the IN constraint */ |
| 148566 | 148825 | |
| 148567 | 148826 | /* Reload the constraint value into reg[iReg+j+2]. The same value |
| @@ -149287,11 +149546,11 @@ | ||
| 149287 | 149546 | regRowid = ++pParse->nMem; |
| 149288 | 149547 | } |
| 149289 | 149548 | iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn); |
| 149290 | 149549 | |
| 149291 | 149550 | /* 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 | |
| 149293 | 149552 | ** That way, terms in y that are factored into the disjunction will |
| 149294 | 149553 | ** be picked up by the recursive calls to sqlite3WhereBegin() below. |
| 149295 | 149554 | ** |
| 149296 | 149555 | ** Actually, each subexpression is converted to "xN AND w" where w is |
| 149297 | 149556 | ** the "interesting" terms of z - terms that did not originate in the |
| @@ -149299,19 +149558,28 @@ | ||
| 149299 | 149558 | ** indices. |
| 149300 | 149559 | ** |
| 149301 | 149560 | ** This optimization also only applies if the (x1 OR x2 OR ...) term |
| 149302 | 149561 | ** is not contained in the ON clause of a LEFT JOIN. |
| 149303 | 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. | |
| 149304 | 149569 | */ |
| 149305 | 149570 | if( pWC->nTerm>1 ){ |
| 149306 | 149571 | int iTerm; |
| 149307 | 149572 | for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 149308 | 149573 | Expr *pExpr = pWC->a[iTerm].pExpr; |
| 149309 | 149574 | if( &pWC->a[iTerm] == pTerm ) continue; |
| 149310 | 149575 | testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); |
| 149311 | 149576 | 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 | + } | |
| 149313 | 149581 | if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 149314 | 149582 | testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); |
| 149315 | 149583 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 149316 | 149584 | pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr); |
| 149317 | 149585 | } |
| @@ -150090,11 +150358,11 @@ | ||
| 150090 | 150358 | void *pNotUsed; |
| 150091 | 150359 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| 150092 | 150360 | assert( pVtab!=0 ); |
| 150093 | 150361 | assert( pVtab->pModule!=0 ); |
| 150094 | 150362 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 150095 | - pMod = (sqlite3_module *)pVtab->pModule; | |
| 150363 | + pMod = (sqlite3_module *)pVtab->pModule; | |
| 150096 | 150364 | if( pMod->xFindFunction!=0 ){ |
| 150097 | 150365 | i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); |
| 150098 | 150366 | if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){ |
| 150099 | 150367 | *peOp2 = i; |
| 150100 | 150368 | *ppRight = pList->a[1].pExpr; |
| @@ -151067,11 +151335,11 @@ | ||
| 151067 | 151335 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft); |
| 151068 | 151336 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft); |
| 151069 | 151337 | |
| 151070 | 151338 | pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); |
| 151071 | 151339 | transferJoinMarkings(pNew, pExpr); |
| 151072 | - idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); | |
| 151340 | + idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE); | |
| 151073 | 151341 | exprAnalyze(pSrc, pWC, idxNew); |
| 151074 | 151342 | } |
| 151075 | 151343 | pTerm = &pWC->a[idxTerm]; |
| 151076 | 151344 | pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ |
| 151077 | 151345 | pTerm->eOperator = 0; |
| @@ -151541,10 +151809,12 @@ | ||
| 151541 | 151809 | typedef struct HiddenIndexInfo HiddenIndexInfo; |
| 151542 | 151810 | struct HiddenIndexInfo { |
| 151543 | 151811 | WhereClause *pWC; /* The Where clause being analyzed */ |
| 151544 | 151812 | Parse *pParse; /* The parsing context */ |
| 151545 | 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 (...) */ | |
| 151546 | 151816 | sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST |
| 151547 | 151817 | ** because extra space is allocated to hold up |
| 151548 | 151818 | ** to nTerm such values */ |
| 151549 | 151819 | }; |
| 151550 | 151820 | |
| @@ -152651,10 +152921,11 @@ | ||
| 152651 | 152921 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 152652 | 152922 | testcase( pTerm->eOperator & WO_IS ); |
| 152653 | 152923 | testcase( pTerm->eOperator & WO_ALL ); |
| 152654 | 152924 | if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 152655 | 152925 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 152926 | + | |
| 152656 | 152927 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 152657 | 152928 | assert( pTerm->u.x.leftColumn>=XN_ROWID ); |
| 152658 | 152929 | assert( pTerm->u.x.leftColumn<pTab->nCol ); |
| 152659 | 152930 | |
| 152660 | 152931 | /* tag-20191211-002: WHERE-clause constraints are not useful to the |
| @@ -152712,11 +152983,11 @@ | ||
| 152712 | 152983 | } |
| 152713 | 152984 | |
| 152714 | 152985 | /* No matches cause a break out of the loop */ |
| 152715 | 152986 | break; |
| 152716 | 152987 | } |
| 152717 | - if( i==n){ | |
| 152988 | + if( i==n ){ | |
| 152718 | 152989 | nOrderBy = n; |
| 152719 | 152990 | if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){ |
| 152720 | 152991 | eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0); |
| 152721 | 152992 | } |
| 152722 | 152993 | } |
| @@ -152740,17 +153011,21 @@ | ||
| 152740 | 153011 | pIdxInfo->aOrderBy = pIdxOrderBy; |
| 152741 | 153012 | pIdxInfo->aConstraintUsage = pUsage; |
| 152742 | 153013 | pHidden->pWC = pWC; |
| 152743 | 153014 | pHidden->pParse = pParse; |
| 152744 | 153015 | pHidden->eDistinct = eDistinct; |
| 153016 | + pHidden->mIn = 0; | |
| 152745 | 153017 | for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 152746 | 153018 | u16 op; |
| 152747 | 153019 | if( (pTerm->wtFlags & TERM_OK)==0 ) continue; |
| 152748 | 153020 | pIdxCons[j].iColumn = pTerm->u.x.leftColumn; |
| 152749 | 153021 | pIdxCons[j].iTermOffset = i; |
| 152750 | 153022 | 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 | + } | |
| 152752 | 153027 | if( op==WO_AUX ){ |
| 152753 | 153028 | pIdxCons[j].op = pTerm->eMatchOp; |
| 152754 | 153029 | }else if( op & (WO_ISNULL|WO_IS) ){ |
| 152755 | 153030 | if( op==WO_ISNULL ){ |
| 152756 | 153031 | pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL; |
| @@ -152836,11 +153111,13 @@ | ||
| 152836 | 153111 | static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ |
| 152837 | 153112 | sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; |
| 152838 | 153113 | int rc; |
| 152839 | 153114 | |
| 152840 | 153115 | whereTraceIndexInfoInputs(p); |
| 153116 | + pParse->db->nSchemaLock++; | |
| 152841 | 153117 | rc = pVtab->pModule->xBestIndex(pVtab, p); |
| 153118 | + pParse->db->nSchemaLock--; | |
| 152842 | 153119 | whereTraceIndexInfoOutputs(p); |
| 152843 | 153120 | |
| 152844 | 153121 | if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ |
| 152845 | 153122 | if( rc==SQLITE_NOMEM ){ |
| 152846 | 153123 | sqlite3OomFault(pParse->db); |
| @@ -155007,10 +155284,11 @@ | ||
| 155007 | 155284 | u16 mNoOmit, /* Do not omit these constraints */ |
| 155008 | 155285 | int *pbIn, /* OUT: True if plan uses an IN(...) op */ |
| 155009 | 155286 | int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */ |
| 155010 | 155287 | ){ |
| 155011 | 155288 | WhereClause *pWC = pBuilder->pWC; |
| 155289 | + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; | |
| 155012 | 155290 | struct sqlite3_index_constraint *pIdxCons; |
| 155013 | 155291 | struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage; |
| 155014 | 155292 | int i; |
| 155015 | 155293 | int mxTerm; |
| 155016 | 155294 | int rc = SQLITE_OK; |
| @@ -155045,10 +155323,11 @@ | ||
| 155045 | 155323 | pIdxInfo->orderByConsumed = 0; |
| 155046 | 155324 | pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2; |
| 155047 | 155325 | pIdxInfo->estimatedRows = 25; |
| 155048 | 155326 | pIdxInfo->idxFlags = 0; |
| 155049 | 155327 | pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed; |
| 155328 | + pHidden->mHandleIn = 0; | |
| 155050 | 155329 | |
| 155051 | 155330 | /* Invoke the virtual table xBestIndex() method */ |
| 155052 | 155331 | rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo); |
| 155053 | 155332 | if( rc ){ |
| 155054 | 155333 | if( rc==SQLITE_CONSTRAINT ){ |
| @@ -155101,11 +155380,13 @@ | ||
| 155101 | 155380 | } |
| 155102 | 155381 | if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){ |
| 155103 | 155382 | pNew->u.vtab.bOmitOffset = 1; |
| 155104 | 155383 | } |
| 155105 | 155384 | } |
| 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 ){ | |
| 155107 | 155388 | /* A virtual table that is constrained by an IN clause may not |
| 155108 | 155389 | ** consume the ORDER BY clause because (1) the order of IN terms |
| 155109 | 155390 | ** is not necessarily related to the order of output terms and |
| 155110 | 155391 | ** (2) Multiple outputs from a single IN value will not merge |
| 155111 | 155392 | ** together. */ |
| @@ -155198,10 +155479,29 @@ | ||
| 155198 | 155479 | } |
| 155199 | 155480 | zRet = (pC ? pC->zName : sqlite3StrBINARY); |
| 155200 | 155481 | } |
| 155201 | 155482 | return zRet; |
| 155202 | 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 | +} | |
| 155203 | 155503 | |
| 155204 | 155504 | /* |
| 155205 | 155505 | ** This interface is callable from within the xBestIndex callback only. |
| 155206 | 155506 | ** |
| 155207 | 155507 | ** If possible, set (*ppVal) to point to an object containing the value |
| @@ -195222,11 +195522,11 @@ | ||
| 195222 | 195522 | sqlite3_module *pModule; |
| 195223 | 195523 | } aMod[] = { |
| 195224 | 195524 | { "json_each", &jsonEachModule }, |
| 195225 | 195525 | { "json_tree", &jsonTreeModule }, |
| 195226 | 195526 | }; |
| 195227 | - int i; | |
| 195527 | + unsigned int i; | |
| 195228 | 195528 | for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){ |
| 195229 | 195529 | rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0); |
| 195230 | 195530 | } |
| 195231 | 195531 | return rc; |
| 195232 | 195532 | } |
| @@ -233819,11 +234119,11 @@ | ||
| 233819 | 234119 | int nArg, /* Number of args */ |
| 233820 | 234120 | sqlite3_value **apUnused /* Function arguments */ |
| 233821 | 234121 | ){ |
| 233822 | 234122 | assert( nArg==0 ); |
| 233823 | 234123 | 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); | |
| 233825 | 234125 | } |
| 233826 | 234126 | |
| 233827 | 234127 | /* |
| 233828 | 234128 | ** Return true if zName is the extension on one of the shadow tables used |
| 233829 | 234129 | ** by this module. |
| 233830 | 234130 |
| --- 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 | ** for(rc=sqlite3_vtab_in_first(pList, &pVal); |
| 10009 | ** rc==SQLITE_OK && pVal |
| 10010 | ** rc=sqlite3_vtab_in_next(pList, &pVal) |
| 10011 | ** ){ |
| 10012 | ** // do something with pVal |
| 10013 | ** } |
| 10014 | ** if( rc!=SQLITE_OK ){ |
| 10015 | ** // an error has occurred |
| 10016 | ** } |
| 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 @@ | ||
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | 149 | #define SQLITE_VERSION "3.38.0" |
| 150 | 150 | #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" | |
| 152 | 152 | |
| 153 | 153 | /* |
| 154 | 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | 156 | ** |
| @@ -9602,10 +9602,132 @@ | ||
| 9602 | 9602 | ** valid to do so, on the other hand, might cause SQLite to return incorrect |
| 9603 | 9603 | ** results. |
| 9604 | 9604 | */ |
| 9605 | 9605 | SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); |
| 9606 | 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 | +** for(rc=sqlite3_vtab_in_first(pList, &pVal); | |
| 9703 | +** rc==SQLITE_OK && pVal | |
| 9704 | +** rc=sqlite3_vtab_in_next(pList, &pVal) | |
| 9705 | +** ){ | |
| 9706 | +** // do something with pVal | |
| 9707 | +** } | |
| 9708 | +** if( rc!=SQLITE_OK ){ | |
| 9709 | +** // an error has occurred | |
| 9710 | +** } | |
| 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 | + | |
| 9607 | 9729 | /* |
| 9608 | 9730 | ** CAPI3REF: Constraint values in xBestIndex() |
| 9609 | 9731 | ** METHOD: sqlite3_index_info |
| 9610 | 9732 | ** |
| 9611 | 9733 | ** This API may only be used from within the [xBestIndex|xBestIndex method] |
| 9612 | 9734 |
| --- 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 | ** for(rc=sqlite3_vtab_in_first(pList, &pVal); |
| 9703 | ** rc==SQLITE_OK && pVal |
| 9704 | ** rc=sqlite3_vtab_in_next(pList, &pVal) |
| 9705 | ** ){ |
| 9706 | ** // do something with pVal |
| 9707 | ** } |
| 9708 | ** if( rc!=SQLITE_OK ){ |
| 9709 | ** // an error has occurred |
| 9710 | ** } |
| 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 |