Fossil SCM

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.

drh 2012-12-15 15:03 trunk
Commit df0d0d04d18dc41a96bd42bb4d53f76bbc510cb8
2 files changed +154 -99 +4 -4
+154 -99
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** 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
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -671,13 +671,13 @@
671671
**
672672
** See also: [sqlite3_libversion()],
673673
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674674
** [sqlite_version()] and [sqlite_source_id()].
675675
*/
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"
679679
680680
/*
681681
** CAPI3REF: Run-Time Library Version Numbers
682682
** KEYWORDS: sqlite3_version, sqlite3_sourceid
683683
**
@@ -2156,11 +2156,11 @@
21562156
** database connection is opened. By default, URI handling is globally
21572157
** disabled. The default value may be changed by compiling with the
21582158
** [SQLITE_USE_URI] symbol defined.
21592159
**
21602160
** [[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
21622162
** a boolean in order to enable or disable the use of covering indices for
21632163
** full table scans in the query optimizer. The default setting is determined
21642164
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
21652165
** if that compile-time option is omitted.
21662166
** The ability to disable the use of covering indices for full table scans
@@ -56334,11 +56334,11 @@
5633456334
sqlite3BtreeLeave(p);
5633556335
return 0;
5633656336
}
5633756337
i = PENDING_BYTE_PAGE(pBt);
5633856338
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);
5634056340
sCheck.errMsg.useMalloc = 2;
5634156341
5634256342
/* Check the integrity of the freelist
5634356343
*/
5634456344
checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -97445,38 +97445,47 @@
9744597445
return 1;
9744697446
}
9744797447
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
9744897448
9744997449
/*
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;
9747897487
}
9747997488
9748097489
/*
9748197490
** The select statement passed as the first argument is an aggregate query.
9748297491
** The second argment is the associated aggregate-info object. This
@@ -98812,15 +98821,21 @@
9881298821
** index or indices to use) should place a different priority on
9881398822
** satisfying the 'ORDER BY' clause than it does in other cases.
9881498823
** Refer to code and comments in where.c for details.
9881598824
*/
9881698825
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
+
9881898835
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);
9882298837
pDel = pMinMax;
9882398838
if( pMinMax && !db->mallocFailed ){
9882498839
pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
9882598840
pMinMax->a[0].pExpr->op = TK_COLUMN;
9882698841
}
@@ -102704,11 +102719,11 @@
102704102719
#define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
102705102720
#define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
102706102721
#define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
102707102722
#define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
102708102723
#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 */
102710102725
#define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
102711102726
#define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
102712102727
#define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */
102713102728
#define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
102714102729
#define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
@@ -104507,11 +104522,11 @@
104507104522
for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104508104523
if( pTerm->leftCursor != pSrc->iCursor ) continue;
104509104524
assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104510104525
testcase( pTerm->eOperator==WO_IN );
104511104526
testcase( pTerm->eOperator==WO_ISNULL );
104512
- if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104527
+ if( pTerm->eOperator & (WO_ISNULL) ) continue;
104513104528
if( pTerm->wtFlags & TERM_VNULL ) continue;
104514104529
nTerm++;
104515104530
}
104516104531
104517104532
/* If the ORDER BY clause contains only columns in the current
@@ -104555,29 +104570,32 @@
104555104570
*(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
104556104571
*(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
104557104572
pUsage;
104558104573
104559104574
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104575
+ u8 op;
104560104576
if( pTerm->leftCursor != pSrc->iCursor ) continue;
104561104577
assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104562104578
testcase( pTerm->eOperator==WO_IN );
104563104579
testcase( pTerm->eOperator==WO_ISNULL );
104564
- if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104580
+ if( pTerm->eOperator & (WO_ISNULL) ) continue;
104565104581
if( pTerm->wtFlags & TERM_VNULL ) continue;
104566104582
pIdxCons[j].iColumn = pTerm->u.leftColumn;
104567104583
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;
104569104587
/* The direct assignment in the previous line is possible only because
104570104588
** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
104571104589
** following asserts verify this fact. */
104572104590
assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
104573104591
assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
104574104592
assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
104575104593
assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
104576104594
assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
104577104595
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) );
104579104597
j++;
104580104598
}
104581104599
for(i=0; i<nOrderBy; i++){
104582104600
Expr *pExpr = pOrderBy->a[i].pExpr;
104583104601
pIdxOrderBy[i].iColumn = pExpr->iColumn;
@@ -104659,10 +104677,11 @@
104659104677
struct sqlite3_index_constraint *pIdxCons;
104660104678
struct sqlite3_index_constraint_usage *pUsage;
104661104679
WhereTerm *pTerm;
104662104680
int i, j;
104663104681
int nOrderBy;
104682
+ int bAllowIN; /* Allow IN optimizations */
104664104683
double rCost;
104665104684
104666104685
/* Make sure wsFlags is initialized to some sane value. Otherwise, if the
104667104686
** malloc in allocateIndexInfo() fails and this function returns leaving
104668104687
** wsFlags in an uninitialized state, the caller may behave unpredictably.
@@ -104693,63 +104712,91 @@
104693104712
** sqlite3ViewGetColumnNames() would have picked up the error.
104694104713
*/
104695104714
assert( pTab->azModuleArg && pTab->azModuleArg[0] );
104696104715
assert( sqlite3GetVTable(pParse->db, pTab) );
104697104716
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
+
104751104798
/* If there is an ORDER BY clause, and the selected virtual table index
104752104799
** does not satisfy it, increase the cost of the scan accordingly. This
104753104800
** matches the processing for non-virtual tables in bestBtreeIndex().
104754104801
*/
104755104802
rCost = pIdxInfo->estimatedCost;
@@ -106514,32 +106561,40 @@
106514106561
if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106515106562
/* Case 0: The table is a virtual-table. Use the VFilter and VNext
106516106563
** to access the data.
106517106564
*/
106518106565
int iReg; /* P3 Value for OP_VFilter */
106566
+ int addrNotFound;
106519106567
sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
106520106568
int nConstraint = pVtabIdx->nConstraint;
106521106569
struct sqlite3_index_constraint_usage *aUsage =
106522106570
pVtabIdx->aConstraintUsage;
106523106571
const struct sqlite3_index_constraint *aConstraint =
106524106572
pVtabIdx->aConstraint;
106525106573
106526106574
sqlite3ExprCachePush(pParse);
106527106575
iReg = sqlite3GetTempRange(pParse, nConstraint+2);
106576
+ addrNotFound = pLevel->addrBrk;
106528106577
for(j=1; j<=nConstraint; j++){
106529106578
for(k=0; k<nConstraint; k++){
106530106579
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
+ }
106533106588
break;
106534106589
}
106535106590
}
106536106591
if( k==nConstraint ) break;
106537106592
}
106538106593
sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
106539106594
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,
106541106596
pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
106542106597
pVtabIdx->needToFreeIdxStr = 0;
106543106598
for(j=0; j<nConstraint; j++){
106544106599
if( aUsage[j].omit ){
106545106600
int iTerm = aConstraint[j].iTermOffset;
106546106601
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
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
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -671,13 +671,13 @@
671 **
672 ** See also: [sqlite3_libversion()],
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
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"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -2156,11 +2156,11 @@
2156 ** database connection is opened. By default, URI handling is globally
2157 ** disabled. The default value may be changed by compiling with the
2158 ** [SQLITE_USE_URI] symbol defined.
2159 **
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
2162 ** a boolean in order to enable or disable the use of covering indices for
2163 ** full table scans in the query optimizer. The default setting is determined
2164 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2165 ** if that compile-time option is omitted.
2166 ** The ability to disable the use of covering indices for full table scans
@@ -56334,11 +56334,11 @@
56334 sqlite3BtreeLeave(p);
56335 return 0;
56336 }
56337 i = PENDING_BYTE_PAGE(pBt);
56338 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
56339 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
56340 sCheck.errMsg.useMalloc = 2;
56341
56342 /* Check the integrity of the freelist
56343 */
56344 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -97445,38 +97445,47 @@
97445 return 1;
97446 }
97447 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
97448
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;
 
 
 
 
 
 
 
 
 
97478 }
97479
97480 /*
97481 ** The select statement passed as the first argument is an aggregate query.
97482 ** The second argment is the associated aggregate-info object. This
@@ -98812,15 +98821,21 @@
98812 ** index or indices to use) should place a different priority on
98813 ** satisfying the 'ORDER BY' clause than it does in other cases.
98814 ** Refer to code and comments in where.c for details.
98815 */
98816 ExprList *pMinMax = 0;
98817 u8 flag = minMaxQuery(p);
 
 
 
 
 
 
 
 
98818 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);
98822 pDel = pMinMax;
98823 if( pMinMax && !db->mallocFailed ){
98824 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
98825 pMinMax->a[0].pExpr->op = TK_COLUMN;
98826 }
@@ -102704,11 +102719,11 @@
102704 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
102705 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
102706 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
102707 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
102708 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */
102709 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
102710 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
102711 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
102712 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */
102713 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
102714 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
@@ -104507,11 +104522,11 @@
104507 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104508 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104509 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104510 testcase( pTerm->eOperator==WO_IN );
104511 testcase( pTerm->eOperator==WO_ISNULL );
104512 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104513 if( pTerm->wtFlags & TERM_VNULL ) continue;
104514 nTerm++;
104515 }
104516
104517 /* If the ORDER BY clause contains only columns in the current
@@ -104555,29 +104570,32 @@
104555 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
104556 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
104557 pUsage;
104558
104559 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
 
104560 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104561 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104562 testcase( pTerm->eOperator==WO_IN );
104563 testcase( pTerm->eOperator==WO_ISNULL );
104564 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue;
104565 if( pTerm->wtFlags & TERM_VNULL ) continue;
104566 pIdxCons[j].iColumn = pTerm->u.leftColumn;
104567 pIdxCons[j].iTermOffset = i;
104568 pIdxCons[j].op = (u8)pTerm->eOperator;
 
 
104569 /* The direct assignment in the previous line is possible only because
104570 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
104571 ** following asserts verify this fact. */
104572 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
104573 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
104574 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
104575 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
104576 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
104577 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
104578 assert( pTerm->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
104579 j++;
104580 }
104581 for(i=0; i<nOrderBy; i++){
104582 Expr *pExpr = pOrderBy->a[i].pExpr;
104583 pIdxOrderBy[i].iColumn = pExpr->iColumn;
@@ -104659,10 +104677,11 @@
104659 struct sqlite3_index_constraint *pIdxCons;
104660 struct sqlite3_index_constraint_usage *pUsage;
104661 WhereTerm *pTerm;
104662 int i, j;
104663 int nOrderBy;
 
104664 double rCost;
104665
104666 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
104667 ** malloc in allocateIndexInfo() fails and this function returns leaving
104668 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
@@ -104693,63 +104712,91 @@
104693 ** sqlite3ViewGetColumnNames() would have picked up the error.
104694 */
104695 assert( pTab->azModuleArg && pTab->azModuleArg[0] );
104696 assert( sqlite3GetVTable(pParse->db, pTab) );
104697
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104751 /* If there is an ORDER BY clause, and the selected virtual table index
104752 ** does not satisfy it, increase the cost of the scan accordingly. This
104753 ** matches the processing for non-virtual tables in bestBtreeIndex().
104754 */
104755 rCost = pIdxInfo->estimatedCost;
@@ -106514,32 +106561,40 @@
106514 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106515 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106516 ** to access the data.
106517 */
106518 int iReg; /* P3 Value for OP_VFilter */
 
106519 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
106520 int nConstraint = pVtabIdx->nConstraint;
106521 struct sqlite3_index_constraint_usage *aUsage =
106522 pVtabIdx->aConstraintUsage;
106523 const struct sqlite3_index_constraint *aConstraint =
106524 pVtabIdx->aConstraint;
106525
106526 sqlite3ExprCachePush(pParse);
106527 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
 
106528 for(j=1; j<=nConstraint; j++){
106529 for(k=0; k<nConstraint; k++){
106530 if( aUsage[k].argvIndex==j ){
106531 int iTerm = aConstraint[k].iTermOffset;
106532 sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1);
 
 
 
 
 
 
106533 break;
106534 }
106535 }
106536 if( k==nConstraint ) break;
106537 }
106538 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
106539 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
106540 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr,
106541 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
106542 pVtabIdx->needToFreeIdxStr = 0;
106543 for(j=0; j<nConstraint; j++){
106544 if( aUsage[j].omit ){
106545 int iTerm = aConstraint[j].iTermOffset;
106546
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
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
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -671,13 +671,13 @@
671 **
672 ** See also: [sqlite3_libversion()],
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
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"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -2156,11 +2156,11 @@
2156 ** database connection is opened. By default, URI handling is globally
2157 ** disabled. The default value may be changed by compiling with the
2158 ** [SQLITE_USE_URI] symbol defined.
2159 **
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
2162 ** a boolean in order to enable or disable the use of covering indices for
2163 ** full table scans in the query optimizer. The default setting is determined
2164 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2165 ** if that compile-time option is omitted.
2166 ** The ability to disable the use of covering indices for full table scans
@@ -56334,11 +56334,11 @@
56334 sqlite3BtreeLeave(p);
56335 return 0;
56336 }
56337 i = PENDING_BYTE_PAGE(pBt);
56338 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
56339 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
56340 sCheck.errMsg.useMalloc = 2;
56341
56342 /* Check the integrity of the freelist
56343 */
56344 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
@@ -97445,38 +97445,47 @@
97445 return 1;
97446 }
97447 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
97448
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;
97487 }
97488
97489 /*
97490 ** The select statement passed as the first argument is an aggregate query.
97491 ** The second argment is the associated aggregate-info object. This
@@ -98812,15 +98821,21 @@
98821 ** index or indices to use) should place a different priority on
98822 ** satisfying the 'ORDER BY' clause than it does in other cases.
98823 ** Refer to code and comments in where.c for details.
98824 */
98825 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
98835 if( flag ){
98836 pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
 
 
98837 pDel = pMinMax;
98838 if( pMinMax && !db->mallocFailed ){
98839 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
98840 pMinMax->a[0].pExpr->op = TK_COLUMN;
98841 }
@@ -102704,11 +102719,11 @@
102719 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
102720 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
102721 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
102722 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
102723 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */
102724 #define WHERE_IN_ABLE 0x080f1000 /* Able to support an IN operator */
102725 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
102726 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
102727 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */
102728 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */
102729 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */
@@ -104507,11 +104522,11 @@
104522 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104523 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104524 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104525 testcase( pTerm->eOperator==WO_IN );
104526 testcase( pTerm->eOperator==WO_ISNULL );
104527 if( pTerm->eOperator & (WO_ISNULL) ) continue;
104528 if( pTerm->wtFlags & TERM_VNULL ) continue;
104529 nTerm++;
104530 }
104531
104532 /* If the ORDER BY clause contains only columns in the current
@@ -104555,29 +104570,32 @@
104570 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
104571 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
104572 pUsage;
104573
104574 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
104575 u8 op;
104576 if( pTerm->leftCursor != pSrc->iCursor ) continue;
104577 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 );
104578 testcase( pTerm->eOperator==WO_IN );
104579 testcase( pTerm->eOperator==WO_ISNULL );
104580 if( pTerm->eOperator & (WO_ISNULL) ) continue;
104581 if( pTerm->wtFlags & TERM_VNULL ) continue;
104582 pIdxCons[j].iColumn = pTerm->u.leftColumn;
104583 pIdxCons[j].iTermOffset = i;
104584 op = (u8)pTerm->eOperator;
104585 if( op==WO_IN ) op = WO_EQ;
104586 pIdxCons[j].op = op;
104587 /* The direct assignment in the previous line is possible only because
104588 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
104589 ** following asserts verify this fact. */
104590 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
104591 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
104592 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
104593 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
104594 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
104595 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) );
104597 j++;
104598 }
104599 for(i=0; i<nOrderBy; i++){
104600 Expr *pExpr = pOrderBy->a[i].pExpr;
104601 pIdxOrderBy[i].iColumn = pExpr->iColumn;
@@ -104659,10 +104677,11 @@
104677 struct sqlite3_index_constraint *pIdxCons;
104678 struct sqlite3_index_constraint_usage *pUsage;
104679 WhereTerm *pTerm;
104680 int i, j;
104681 int nOrderBy;
104682 int bAllowIN; /* Allow IN optimizations */
104683 double rCost;
104684
104685 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
104686 ** malloc in allocateIndexInfo() fails and this function returns leaving
104687 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
@@ -104693,63 +104712,91 @@
104712 ** sqlite3ViewGetColumnNames() would have picked up the error.
104713 */
104714 assert( pTab->azModuleArg && pTab->azModuleArg[0] );
104715 assert( sqlite3GetVTable(pParse->db, pTab) );
104716
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
104798 /* If there is an ORDER BY clause, and the selected virtual table index
104799 ** does not satisfy it, increase the cost of the scan accordingly. This
104800 ** matches the processing for non-virtual tables in bestBtreeIndex().
104801 */
104802 rCost = pIdxInfo->estimatedCost;
@@ -106514,32 +106561,40 @@
106561 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106562 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106563 ** to access the data.
106564 */
106565 int iReg; /* P3 Value for OP_VFilter */
106566 int addrNotFound;
106567 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx;
106568 int nConstraint = pVtabIdx->nConstraint;
106569 struct sqlite3_index_constraint_usage *aUsage =
106570 pVtabIdx->aConstraintUsage;
106571 const struct sqlite3_index_constraint *aConstraint =
106572 pVtabIdx->aConstraint;
106573
106574 sqlite3ExprCachePush(pParse);
106575 iReg = sqlite3GetTempRange(pParse, nConstraint+2);
106576 addrNotFound = pLevel->addrBrk;
106577 for(j=1; j<=nConstraint; j++){
106578 for(k=0; k<nConstraint; k++){
106579 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 }
106588 break;
106589 }
106590 }
106591 if( k==nConstraint ) break;
106592 }
106593 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg);
106594 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1);
106595 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, pVtabIdx->idxStr,
106596 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
106597 pVtabIdx->needToFreeIdxStr = 0;
106598 for(j=0; j<nConstraint; j++){
106599 if( aUsage[j].omit ){
106600 int iTerm = aConstraint[j].iTermOffset;
106601
+4 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.15"
111
-#define SQLITE_VERSION_NUMBER 3007015
112
-#define SQLITE_SOURCE_ID "2012-12-10 22:19:14 bd7aeeb691fee69dd6a562138a7aba8e8e192272"
110
+#define SQLITE_VERSION "3.7.16"
111
+#define SQLITE_VERSION_NUMBER 3007016
112
+#define SQLITE_SOURCE_ID "2012-12-14 17:54:38 3d65c70343196b8f69c5293e7703839846fade85"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1590,11 +1590,11 @@
15901590
** database connection is opened. By default, URI handling is globally
15911591
** disabled. The default value may be changed by compiling with the
15921592
** [SQLITE_USE_URI] symbol defined.
15931593
**
15941594
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1595
-** <dd> This option taks a single integer argument which is interpreted as
1595
+** <dd> This option takes a single integer argument which is interpreted as
15961596
** a boolean in order to enable or disable the use of covering indices for
15971597
** full table scans in the query optimizer. The default setting is determined
15981598
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
15991599
** if that compile-time option is omitted.
16001600
** The ability to disable the use of covering indices for full table scans
16011601
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.15"
111 #define SQLITE_VERSION_NUMBER 3007015
112 #define SQLITE_SOURCE_ID "2012-12-10 22:19:14 bd7aeeb691fee69dd6a562138a7aba8e8e192272"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1590,11 +1590,11 @@
1590 ** database connection is opened. By default, URI handling is globally
1591 ** disabled. The default value may be changed by compiling with the
1592 ** [SQLITE_USE_URI] symbol defined.
1593 **
1594 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1595 ** <dd> This option taks a single integer argument which is interpreted as
1596 ** a boolean in order to enable or disable the use of covering indices for
1597 ** full table scans in the query optimizer. The default setting is determined
1598 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1599 ** if that compile-time option is omitted.
1600 ** The ability to disable the use of covering indices for full table scans
1601
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.16"
111 #define SQLITE_VERSION_NUMBER 3007016
112 #define SQLITE_SOURCE_ID "2012-12-14 17:54:38 3d65c70343196b8f69c5293e7703839846fade85"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1590,11 +1590,11 @@
1590 ** database connection is opened. By default, URI handling is globally
1591 ** disabled. The default value may be changed by compiling with the
1592 ** [SQLITE_USE_URI] symbol defined.
1593 **
1594 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1595 ** <dd> This option takes a single integer argument which is interpreted as
1596 ** a boolean in order to enable or disable the use of covering indices for
1597 ** full table scans in the query optimizer. The default setting is determined
1598 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1599 ** if that compile-time option is omitted.
1600 ** The ability to disable the use of covering indices for full table scans
1601

Keyboard Shortcuts

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