Differences From
Artifact [21f9a00f]:
- File
src/sqlite3.c
— part of check-in
[d79ddfac]
at
2012-12-11 01:05:15
on branch trunk
— Import the SQLite fix for integer to floating-point overflow from upstream.
Fossil does not really need this. The import is for testing SQLite.
(user:
drh
size: 4860027)
[more...]
- File
src/sqlite3.c
— part of check-in
[df0d0d04]
at
2012-12-15 15:03:38
on branch trunk
— Update the built-in SQLite to the latest from upstream. The latest SQLite
has some changes that stress the difference engine. This upgrade is to
pull those changes into the source tree so that they can be added to the
diff-test page.
(user:
drh
size: 4862067)
1 1 /******************************************************************************
2 2 ** This file is an amalgamation of many separate C source files from SQLite
3 -** version 3.7.15. By combining all the individual C code files into this
3 +** version 3.7.16. By combining all the individual C code files into this
4 4 ** single large file, the entire code can be compiled as a single translation
5 5 ** unit. This allows many compilers to do optimizations that would not be
6 6 ** possible if the files were compiled separately. Performance improvements
7 7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 8 ** translation unit.
9 9 **
10 10 ** This file is all you need to compile SQLite. To use SQLite in other
................................................................................
669 669 ** string contains the date and time of the check-in (UTC) and an SHA1
670 670 ** hash of the entire source tree.
671 671 **
672 672 ** See also: [sqlite3_libversion()],
673 673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 674 ** [sqlite_version()] and [sqlite_source_id()].
675 675 */
676 -#define SQLITE_VERSION "3.7.15"
677 -#define SQLITE_VERSION_NUMBER 3007015
678 -#define SQLITE_SOURCE_ID "2012-12-10 22:19:14 bd7aeeb691fee69dd6a562138a7aba8e8e192272"
676 +#define SQLITE_VERSION "3.7.16"
677 +#define SQLITE_VERSION_NUMBER 3007016
678 +#define SQLITE_SOURCE_ID "2012-12-14 17:54:38 3d65c70343196b8f69c5293e7703839846fade85"
679 679
680 680 /*
681 681 ** CAPI3REF: Run-Time Library Version Numbers
682 682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 683 **
684 684 ** These interfaces provide the same information as the [SQLITE_VERSION],
685 685 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
2154 2154 ** connection is opened. If it is globally disabled, filenames are
2155 2155 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2156 2156 ** database connection is opened. By default, URI handling is globally
2157 2157 ** disabled. The default value may be changed by compiling with the
2158 2158 ** [SQLITE_USE_URI] symbol defined.
2159 2159 **
2160 2160 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2161 -** <dd> This option taks a single integer argument which is interpreted as
2161 +** <dd> This option takes a single integer argument which is interpreted as
2162 2162 ** a boolean in order to enable or disable the use of covering indices for
2163 2163 ** full table scans in the query optimizer. The default setting is determined
2164 2164 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2165 2165 ** if that compile-time option is omitted.
2166 2166 ** The ability to disable the use of covering indices for full table scans
2167 2167 ** is because some incorrectly coded legacy applications might malfunction
2168 2168 ** malfunction when the optimization is enabled. Providing the ability to
................................................................................
56332 56332 if( !sCheck.aPgRef ){
56333 56333 *pnErr = 1;
56334 56334 sqlite3BtreeLeave(p);
56335 56335 return 0;
56336 56336 }
56337 56337 i = PENDING_BYTE_PAGE(pBt);
56338 56338 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
56339 - sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
56339 + sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
56340 56340 sCheck.errMsg.useMalloc = 2;
56341 56341
56342 56342 /* Check the integrity of the freelist
56343 56343 */
56344 56344 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
56345 56345 get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");
56346 56346
................................................................................
97443 97443 sqlite3SelectDelete(db, pSub1);
97444 97444
97445 97445 return 1;
97446 97446 }
97447 97447 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
97448 97448
97449 97449 /*
97450 -** Analyze the SELECT statement passed as an argument to see if it
97451 -** is a min() or max() query. Return WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX if
97452 -** it is, or 0 otherwise. At present, a query is considered to be
97453 -** a min()/max() query if:
97454 -**
97455 -** 1. There is a single object in the FROM clause.
97456 -**
97457 -** 2. There is a single expression in the result set, and it is
97458 -** either min(x) or max(x), where x is a column reference.
97459 -*/
97460 -static u8 minMaxQuery(Select *p){
97461 - Expr *pExpr;
97462 - ExprList *pEList = p->pEList;
97463 -
97464 - if( pEList->nExpr!=1 ) return WHERE_ORDERBY_NORMAL;
97465 - pExpr = pEList->a[0].pExpr;
97466 - if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
97467 - if( NEVER(ExprHasProperty(pExpr, EP_xIsSelect)) ) return 0;
97468 - pEList = pExpr->x.pList;
97469 - if( pEList==0 || pEList->nExpr!=1 ) return 0;
97470 - if( pEList->a[0].pExpr->op!=TK_AGG_COLUMN ) return WHERE_ORDERBY_NORMAL;
97471 - assert( !ExprHasProperty(pExpr, EP_IntValue) );
97472 - if( sqlite3StrICmp(pExpr->u.zToken,"min")==0 ){
97473 - return WHERE_ORDERBY_MIN;
97474 - }else if( sqlite3StrICmp(pExpr->u.zToken,"max")==0 ){
97475 - return WHERE_ORDERBY_MAX;
97476 - }
97477 - return WHERE_ORDERBY_NORMAL;
97450 +** Based on the contents of the AggInfo structure indicated by the first
97451 +** argument, this function checks if the following are true:
97452 +**
97453 +** * the query contains just a single aggregate function,
97454 +** * the aggregate function is either min() or max(), and
97455 +** * the argument to the aggregate function is a column value.
97456 +**
97457 +** If all of the above are true, then WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX
97458 +** is returned as appropriate. Also, *ppMinMax is set to point to the
97459 +** list of arguments passed to the aggregate before returning.
97460 +**
97461 +** Or, if the conditions above are not met, *ppMinMax is set to 0 and
97462 +** WHERE_ORDERBY_NORMAL is returned.
97463 +*/
97464 +static u8 minMaxQuery(AggInfo *pAggInfo, ExprList **ppMinMax){
97465 + int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
97466 +
97467 + *ppMinMax = 0;
97468 + if( pAggInfo->nFunc==1 ){
97469 + Expr *pExpr = pAggInfo->aFunc[0].pExpr; /* Aggregate function */
97470 + ExprList *pEList = pExpr->x.pList; /* Arguments to agg function */
97471 +
97472 + assert( pExpr->op==TK_AGG_FUNCTION );
97473 + if( pEList && pEList->nExpr==1 && pEList->a[0].pExpr->op==TK_AGG_COLUMN ){
97474 + const char *zFunc = pExpr->u.zToken;
97475 + if( sqlite3StrICmp(zFunc, "min")==0 ){
97476 + eRet = WHERE_ORDERBY_MIN;
97477 + *ppMinMax = pEList;
97478 + }else if( sqlite3StrICmp(zFunc, "max")==0 ){
97479 + eRet = WHERE_ORDERBY_MAX;
97480 + *ppMinMax = pEList;
97481 + }
97482 + }
97483 + }
97484 +
97485 + assert( *ppMinMax==0 || (*ppMinMax)->nExpr==1 );
97486 + return eRet;
97478 97487 }
97479 97488
97480 97489 /*
97481 97490 ** The select statement passed as the first argument is an aggregate query.
97482 97491 ** The second argment is the associated aggregate-info object. This
97483 97492 ** function tests if the SELECT is of the form:
97484 97493 **
................................................................................
98810 98819 **
98811 98820 ** + The optimizer code in where.c (the thing that decides which
98812 98821 ** index or indices to use) should place a different priority on
98813 98822 ** satisfying the 'ORDER BY' clause than it does in other cases.
98814 98823 ** Refer to code and comments in where.c for details.
98815 98824 */
98816 98825 ExprList *pMinMax = 0;
98817 - u8 flag = minMaxQuery(p);
98826 + u8 flag = WHERE_ORDERBY_NORMAL;
98827 +
98828 + assert( p->pGroupBy==0 );
98829 + assert( flag==0 );
98830 + if( p->pHaving==0 ){
98831 + flag = minMaxQuery(&sAggInfo, &pMinMax);
98832 + }
98833 + assert( flag==0 || (pMinMax!=0 && pMinMax->nExpr==1) );
98834 +
98818 98835 if( flag ){
98819 - assert( !ExprHasProperty(p->pEList->a[0].pExpr, EP_xIsSelect) );
98820 - assert( p->pEList->a[0].pExpr->x.pList->nExpr==1 );
98821 - pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0);
98836 + pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
98822 98837 pDel = pMinMax;
98823 98838 if( pMinMax && !db->mallocFailed ){
98824 98839 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
98825 98840 pMinMax->a[0].pExpr->op = TK_COLUMN;
98826 98841 }
98827 98842 }
98828 98843
................................................................................
102702 102717 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */
102703 102718 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
102704 102719 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
102705 102720 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
102706 102721 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
102707 102722 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
102708 102723 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */
102709 -#define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
102724 +#define WHERE_IN_ABLE 0x080f1000 /* Able to support an IN operator */
102710 102725 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
102711 102726 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
102712 102727 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */
102713 102728 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
102714 102729 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
102715 102730 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */
102716 102731 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */
................................................................................
104505 104520 /* Count the number of possible WHERE clause constraints referring
104506 104521 ** to this virtual table */
104507 104522 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104508 104523 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104509 104524 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104510 104525 testcase( pTerm->eOperator==WO_IN );
104511 104526 testcase( pTerm->eOperator==WO_ISNULL );
104512 - if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104527 + if( pTerm->eOperator & (WO_ISNULL) ) continue;
104513 104528 if( pTerm->wtFlags & TERM_VNULL ) continue;
104514 104529 nTerm++;
104515 104530 }
104516 104531
104517 104532 /* If the ORDER BY clause contains only columns in the current
104518 104533 ** virtual table then allocate space for the aOrderBy part of
104519 104534 ** the sqlite3_index_info structure.
................................................................................
104553 104568 *(int*)&pIdxInfo->nOrderBy = nOrderBy;
104554 104569 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
104555 104570 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
104556 104571 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
104557 104572 pUsage;
104558 104573
104559 104574 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104575 + u8 op;
104560 104576 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104561 104577 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104562 104578 testcase( pTerm->eOperator==WO_IN );
104563 104579 testcase( pTerm->eOperator==WO_ISNULL );
104564 - if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104580 + if( pTerm->eOperator & (WO_ISNULL) ) continue;
104565 104581 if( pTerm->wtFlags & TERM_VNULL ) continue;
104566 104582 pIdxCons[j].iColumn = pTerm->u.leftColumn;
104567 104583 pIdxCons[j].iTermOffset = i;
104568 - pIdxCons[j].op = (u8)pTerm->eOperator;
104584 + op = (u8)pTerm->eOperator;
104585 + if( op==WO_IN ) op = WO_EQ;
104586 + pIdxCons[j].op = op;
104569 104587 /* The direct assignment in the previous line is possible only because
104570 104588 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
104571 104589 ** following asserts verify this fact. */
104572 104590 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
104573 104591 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
104574 104592 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
104575 104593 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
104576 104594 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
104577 104595 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
104578 - assert( pTerm->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
104596 + assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
104579 104597 j++;
104580 104598 }
104581 104599 for(i=0; i<nOrderBy; i++){
104582 104600 Expr *pExpr = pOrderBy->a[i].pExpr;
104583 104601 pIdxOrderBy[i].iColumn = pExpr->iColumn;
104584 104602 pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;
104585 104603 }
................................................................................
104657 104675 Table *pTab = pSrc->pTab;
104658 104676 sqlite3_index_info *pIdxInfo;
104659 104677 struct sqlite3_index_constraint *pIdxCons;
104660 104678 struct sqlite3_index_constraint_usage *pUsage;
104661 104679 WhereTerm *pTerm;
104662 104680 int i, j;
104663 104681 int nOrderBy;
104682 + int bAllowIN; /* Allow IN optimizations */
104664 104683 double rCost;
104665 104684
104666 104685 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
104667 104686 ** malloc in allocateIndexInfo() fails and this function returns leaving
104668 104687 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
104669 104688 */
104670 104689 memset(&p->cost, 0, sizeof(p->cost));
................................................................................
104691 104710 /* The module name must be defined. Also, by this point there must
104692 104711 ** be a pointer to an sqlite3_vtab structure. Otherwise
104693 104712 ** sqlite3ViewGetColumnNames() would have picked up the error.
104694 104713 */
104695 104714 assert( pTab->azModuleArg && pTab->azModuleArg[0] );
104696 104715 assert( sqlite3GetVTable(pParse->db, pTab) );
104697 104716
104698 - /* Set the aConstraint[].usable fields and initialize all
104699 - ** output variables to zero.
104700 - **
104701 - ** aConstraint[].usable is true for constraints where the right-hand
104702 - ** side contains only references to tables to the left of the current
104703 - ** table. In other words, if the constraint is of the form:
104704 - **
104705 - ** column = expr
104706 - **
104707 - ** and we are evaluating a join, then the constraint on column is
104708 - ** only valid if all tables referenced in expr occur to the left
104709 - ** of the table containing column.
104710 - **
104711 - ** The aConstraints[] array contains entries for all constraints
104712 - ** on the current table. That way we only have to compute it once
104713 - ** even though we might try to pick the best index multiple times.
104714 - ** For each attempt at picking an index, the order of tables in the
104715 - ** join might be different so we have to recompute the usable flag
104716 - ** each time.
104717 - */
104718 - pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
104719 - pUsage = pIdxInfo->aConstraintUsage;
104720 - for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
104721 - j = pIdxCons->iTermOffset;
104722 - pTerm = &pWC->a[j];
104723 - pIdxCons->usable = (pTerm->prereqRight&p->notReady) ? 0 : 1;
104724 - }
104725 - memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint);
104726 - if( pIdxInfo->needToFreeIdxStr ){
104727 - sqlite3_free(pIdxInfo->idxStr);
104728 - }
104729 - pIdxInfo->idxStr = 0;
104730 - pIdxInfo->idxNum = 0;
104731 - pIdxInfo->needToFreeIdxStr = 0;
104732 - pIdxInfo->orderByConsumed = 0;
104733 - /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */
104734 - pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2);
104735 - nOrderBy = pIdxInfo->nOrderBy;
104736 - if( !p->pOrderBy ){
104737 - pIdxInfo->nOrderBy = 0;
104738 - }
104739 -
104740 - if( vtabBestIndex(pParse, pTab, pIdxInfo) ){
104741 - return;
104742 - }
104743 -
104744 - pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
104745 - for(i=0; i<pIdxInfo->nConstraint; i++){
104746 - if( pUsage[i].argvIndex>0 ){
104747 - p->cost.used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
104748 - }
104749 - }
104750 -
104717 + /* Try once or twice. On the first attempt, allow IN optimizations.
104718 + ** If an IN optimization is accepted by the virtual table xBestIndex
104719 + ** method, but the pInfo->aConstrainUsage.omit flag is not set, then
104720 + ** the query will not work because it might allow duplicate rows in
104721 + ** output. In that case, run the xBestIndex method a second time
104722 + ** without the IN constraints. Usually this loop only runs once.
104723 + ** The loop will exit using a "break" statement.
104724 + */
104725 + for(bAllowIN=1; 1; bAllowIN--){
104726 + assert( bAllowIN==0 || bAllowIN==1 );
104727 +
104728 + /* Set the aConstraint[].usable fields and initialize all
104729 + ** output variables to zero.
104730 + **
104731 + ** aConstraint[].usable is true for constraints where the right-hand
104732 + ** side contains only references to tables to the left of the current
104733 + ** table. In other words, if the constraint is of the form:
104734 + **
104735 + ** column = expr
104736 + **
104737 + ** and we are evaluating a join, then the constraint on column is
104738 + ** only valid if all tables referenced in expr occur to the left
104739 + ** of the table containing column.
104740 + **
104741 + ** The aConstraints[] array contains entries for all constraints
104742 + ** on the current table. That way we only have to compute it once
104743 + ** even though we might try to pick the best index multiple times.
104744 + ** For each attempt at picking an index, the order of tables in the
104745 + ** join might be different so we have to recompute the usable flag
104746 + ** each time.
104747 + */
104748 + pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
104749 + pUsage = pIdxInfo->aConstraintUsage;
104750 + for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
104751 + j = pIdxCons->iTermOffset;
104752 + pTerm = &pWC->a[j];
104753 + if( (pTerm->prereqRight&p->notReady)==0
104754 + && (bAllowIN || pTerm->eOperator!=WO_IN)
104755 + ){
104756 + pIdxCons->usable = 1;
104757 + }else{
104758 + pIdxCons->usable = 0;
104759 + }
104760 + }
104761 + memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint);
104762 + if( pIdxInfo->needToFreeIdxStr ){
104763 + sqlite3_free(pIdxInfo->idxStr);
104764 + }
104765 + pIdxInfo->idxStr = 0;
104766 + pIdxInfo->idxNum = 0;
104767 + pIdxInfo->needToFreeIdxStr = 0;
104768 + pIdxInfo->orderByConsumed = 0;
104769 + /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */
104770 + pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2);
104771 + nOrderBy = pIdxInfo->nOrderBy;
104772 + if( !p->pOrderBy ){
104773 + pIdxInfo->nOrderBy = 0;
104774 + }
104775 +
104776 + if( vtabBestIndex(pParse, pTab, pIdxInfo) ){
104777 + return;
104778 + }
104779 +
104780 + pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
104781 + for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
104782 + if( pUsage[i].argvIndex>0 ){
104783 + j = pIdxCons->iTermOffset;
104784 + pTerm = &pWC->a[j];
104785 + p->cost.used |= pTerm->prereqRight;
104786 + if( pTerm->eOperator==WO_IN && pUsage[i].omit==0 ){
104787 + /* Do not attempt to use an IN constraint if the virtual table
104788 + ** says that the equivalent EQ constraint cannot be safely omitted.
104789 + ** If we do attempt to use such a constraint, some rows might be
104790 + ** repeated in the output. */
104791 + break;
104792 + }
104793 + }
104794 + }
104795 + if( i>=pIdxInfo->nConstraint ) break;
104796 + }
104797 +
104751 104798 /* If there is an ORDER BY clause, and the selected virtual table index
104752 104799 ** does not satisfy it, increase the cost of the scan accordingly. This
104753 104800 ** matches the processing for non-virtual tables in bestBtreeIndex().
104754 104801 */
104755 104802 rCost = pIdxInfo->estimatedCost;
104756 104803 if( p->pOrderBy && pIdxInfo->orderByConsumed==0 ){
104757 104804 rCost += estLog(rCost)*rCost;
................................................................................
106512 106559
106513 106560 #ifndef SQLITE_OMIT_VIRTUALTABLE
106514 106561 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106515 106562 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106516 106563 ** to access the data.
106517 106564 */
106518 106565 int iReg; /* P3 Value for OP_VFilter */
106566 + int addrNotFound;
106519 106567 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
106520 106568 int nConstraint = pVtabIdx->nConstraint;
106521 106569 struct sqlite3_index_constraint_usage *aUsage =
106522 106570 pVtabIdx->aConstraintUsage;
106523 106571 const struct sqlite3_index_constraint *aConstraint =
106524 106572 pVtabIdx->aConstraint;
106525 106573
106526 106574 sqlite3ExprCachePush(pParse);
106527 106575 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
106576 + addrNotFound = pLevel->addrBrk;
106528 106577 for(j=1; j<=nConstraint; j++){
106529 106578 for(k=0; k<nConstraint; k++){
106530 106579 if( aUsage[k].argvIndex==j ){
106531 - int iTerm = aConstraint[k].iTermOffset;
106532 - sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1);
106580 + WhereTerm *pTerm = &pWC->a[aConstraint[k].iTermOffset];
106581 + int iTarget = iReg+j+1;
106582 + if( pTerm->eOperator & WO_IN ){
106583 + codeEqualityTerm(pParse, pTerm, pLevel, iTarget);
106584 + addrNotFound = pLevel->addrNxt;
106585 + }else{
106586 + sqlite3ExprCode(pParse, pTerm->pExpr->pRight, iTarget);
106587 + }
106533 106588 break;
106534 106589 }
106535 106590 }
106536 106591 if( k==nConstraint ) break;
106537 106592 }
106538 106593 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
106539 106594 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
106540 - sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr,
106595 + sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, pVtabIdx->idxStr,
106541 106596 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
106542 106597 pVtabIdx->needToFreeIdxStr = 0;
106543 106598 for(j=0; j<nConstraint; j++){
106544 106599 if( aUsage[j].omit ){
106545 106600 int iTerm = aConstraint[j].iTermOffset;
106546 106601 disableTerm(pLevel, &pWC->a[iTerm]);
106547 106602 }