Differences From
Artifact [d5c4ff0532]:
- File
src/sqlite3.c
— part of check-in
[df0d0d04d1]
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)
- File
src/sqlite3.c
— part of check-in
[d79ddface9]
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...]
1 1 /******************************************************************************
2 2 ** This file is an amalgamation of many separate C source files from SQLite
3 -** version 3.7.16. By combining all the individual C code files into this
3 +** version 3.7.15. 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.16"
677 -#define SQLITE_VERSION_NUMBER 3007016
678 -#define SQLITE_SOURCE_ID "2012-12-14 17:54:38 3d65c70343196b8f69c5293e7703839846fade85"
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"
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 takes a single integer argument which is interpreted as
2161 +** <dd> This option taks 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), SQLITE_MAX_LENGTH);
56339 + sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
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 -** 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;
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;
97487 97478 }
97488 97479
97489 97480 /*
97490 97481 ** The select statement passed as the first argument is an aggregate query.
97491 97482 ** The second argment is the associated aggregate-info object. This
97492 97483 ** function tests if the SELECT is of the form:
97493 97484 **
................................................................................
98819 98810 **
98820 98811 ** + The optimizer code in where.c (the thing that decides which
98821 98812 ** index or indices to use) should place a different priority on
98822 98813 ** satisfying the 'ORDER BY' clause than it does in other cases.
98823 98814 ** Refer to code and comments in where.c for details.
98824 98815 */
98825 98816 ExprList *pMinMax = 0;
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 -
98817 + u8 flag = minMaxQuery(p);
98835 98818 if( flag ){
98836 - pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
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);
98837 98822 pDel = pMinMax;
98838 98823 if( pMinMax && !db->mallocFailed ){
98839 98824 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
98840 98825 pMinMax->a[0].pExpr->op = TK_COLUMN;
98841 98826 }
98842 98827 }
98843 98828
................................................................................
102717 102702 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */
102718 102703 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
102719 102704 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
102720 102705 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
102721 102706 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
102722 102707 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
102723 102708 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */
102724 -#define WHERE_IN_ABLE 0x080f1000 /* Able to support an IN operator */
102709 +#define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
102725 102710 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
102726 102711 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
102727 102712 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */
102728 102713 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
102729 102714 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
102730 102715 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */
102731 102716 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */
................................................................................
104520 104505 /* Count the number of possible WHERE clause constraints referring
104521 104506 ** to this virtual table */
104522 104507 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104523 104508 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104524 104509 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104525 104510 testcase( pTerm->eOperator==WO_IN );
104526 104511 testcase( pTerm->eOperator==WO_ISNULL );
104527 - if( pTerm->eOperator & (WO_ISNULL) ) continue;
104512 + if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104528 104513 if( pTerm->wtFlags & TERM_VNULL ) continue;
104529 104514 nTerm++;
104530 104515 }
104531 104516
104532 104517 /* If the ORDER BY clause contains only columns in the current
104533 104518 ** virtual table then allocate space for the aOrderBy part of
104534 104519 ** the sqlite3_index_info structure.
................................................................................
104568 104553 *(int*)&pIdxInfo->nOrderBy = nOrderBy;
104569 104554 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
104570 104555 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
104571 104556 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
104572 104557 pUsage;
104573 104558
104574 104559 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104575 - u8 op;
104576 104560 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104577 104561 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104578 104562 testcase( pTerm->eOperator==WO_IN );
104579 104563 testcase( pTerm->eOperator==WO_ISNULL );
104580 - if( pTerm->eOperator & (WO_ISNULL) ) continue;
104564 + if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104581 104565 if( pTerm->wtFlags & TERM_VNULL ) continue;
104582 104566 pIdxCons[j].iColumn = pTerm->u.leftColumn;
104583 104567 pIdxCons[j].iTermOffset = i;
104584 - op = (u8)pTerm->eOperator;
104585 - if( op==WO_IN ) op = WO_EQ;
104586 - pIdxCons[j].op = op;
104568 + pIdxCons[j].op = (u8)pTerm->eOperator;
104587 104569 /* The direct assignment in the previous line is possible only because
104588 104570 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
104589 104571 ** following asserts verify this fact. */
104590 104572 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
104591 104573 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
104592 104574 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
104593 104575 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
104594 104576 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
104595 104577 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
104596 - assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
104578 + assert( pTerm->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
104597 104579 j++;
104598 104580 }
104599 104581 for(i=0; i<nOrderBy; i++){
104600 104582 Expr *pExpr = pOrderBy->a[i].pExpr;
104601 104583 pIdxOrderBy[i].iColumn = pExpr->iColumn;
104602 104584 pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;
104603 104585 }
................................................................................
104675 104657 Table *pTab = pSrc->pTab;
104676 104658 sqlite3_index_info *pIdxInfo;
104677 104659 struct sqlite3_index_constraint *pIdxCons;
104678 104660 struct sqlite3_index_constraint_usage *pUsage;
104679 104661 WhereTerm *pTerm;
104680 104662 int i, j;
104681 104663 int nOrderBy;
104682 - int bAllowIN; /* Allow IN optimizations */
104683 104664 double rCost;
104684 104665
104685 104666 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
104686 104667 ** malloc in allocateIndexInfo() fails and this function returns leaving
104687 104668 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
104688 104669 */
104689 104670 memset(&p->cost, 0, sizeof(p->cost));
................................................................................
104710 104691 /* The module name must be defined. Also, by this point there must
104711 104692 ** be a pointer to an sqlite3_vtab structure. Otherwise
104712 104693 ** sqlite3ViewGetColumnNames() would have picked up the error.
104713 104694 */
104714 104695 assert( pTab->azModuleArg && pTab->azModuleArg[0] );
104715 104696 assert( sqlite3GetVTable(pParse->db, pTab) );
104716 104697
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 -
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 +
104798 104751 /* If there is an ORDER BY clause, and the selected virtual table index
104799 104752 ** does not satisfy it, increase the cost of the scan accordingly. This
104800 104753 ** matches the processing for non-virtual tables in bestBtreeIndex().
104801 104754 */
104802 104755 rCost = pIdxInfo->estimatedCost;
104803 104756 if( p->pOrderBy && pIdxInfo->orderByConsumed==0 ){
104804 104757 rCost += estLog(rCost)*rCost;
................................................................................
106559 106512
106560 106513 #ifndef SQLITE_OMIT_VIRTUALTABLE
106561 106514 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106562 106515 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106563 106516 ** to access the data.
106564 106517 */
106565 106518 int iReg; /* P3 Value for OP_VFilter */
106566 - int addrNotFound;
106567 106519 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
106568 106520 int nConstraint = pVtabIdx->nConstraint;
106569 106521 struct sqlite3_index_constraint_usage *aUsage =
106570 106522 pVtabIdx->aConstraintUsage;
106571 106523 const struct sqlite3_index_constraint *aConstraint =
106572 106524 pVtabIdx->aConstraint;
106573 106525
106574 106526 sqlite3ExprCachePush(pParse);
106575 106527 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
106576 - addrNotFound = pLevel->addrBrk;
106577 106528 for(j=1; j<=nConstraint; j++){
106578 106529 for(k=0; k<nConstraint; k++){
106579 106530 if( aUsage[k].argvIndex==j ){
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 - }
106531 + int iTerm = aConstraint[k].iTermOffset;
106532 + sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1);
106588 106533 break;
106589 106534 }
106590 106535 }
106591 106536 if( k==nConstraint ) break;
106592 106537 }
106593 106538 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
106594 106539 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
106595 - sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, pVtabIdx->idxStr,
106540 + sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr,
106596 106541 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
106597 106542 pVtabIdx->needToFreeIdxStr = 0;
106598 106543 for(j=0; j<nConstraint; j++){
106599 106544 if( aUsage[j].omit ){
106600 106545 int iTerm = aConstraint[j].iTermOffset;
106601 106546 disableTerm(pLevel, &pWC->a[iTerm]);
106602 106547 }