Fossil SCM

Update the build-in SQLite from upstream. The "fossil sql" command now supports the ".shell" meta-command.

drh 2014-05-28 20:24 trunk
Commit f6d3b815136fc0f66c745982ec5a8681662e5812
3 files changed +18 -1 +140 -61 +1 -1
+18 -1
--- src/shell.c
+++ src/shell.c
@@ -1578,11 +1578,11 @@
15781578
" LIKE pattern TABLE.\n"
15791579
".echo ON|OFF Turn command echo on or off\n"
15801580
".exit Exit this program\n"
15811581
".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n"
15821582
" With no args, it turns EXPLAIN on.\n"
1583
- ".header(s) ON|OFF Turn display of headers on or off\n"
1583
+ ".headers ON|OFF Turn display of headers on or off\n"
15841584
".help Show this message\n"
15851585
".import FILE TABLE Import data from FILE into TABLE\n"
15861586
".indices ?TABLE? Show names of all indices\n"
15871587
" If TABLE specified, only show indices for tables\n"
15881588
" matching LIKE pattern TABLE.\n"
@@ -1614,19 +1614,22 @@
16141614
".save FILE Write in-memory database into FILE\n"
16151615
".schema ?TABLE? Show the CREATE statements\n"
16161616
" If TABLE specified, only show tables matching\n"
16171617
" LIKE pattern TABLE.\n"
16181618
".separator STRING Change separator used by output mode and .import\n"
1619
+ ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
16191620
".show Show the current values for various settings\n"
16201621
".stats ON|OFF Turn stats on or off\n"
1622
+ ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
16211623
".tables ?TABLE? List names of tables\n"
16221624
" If TABLE specified, only list tables matching\n"
16231625
" LIKE pattern TABLE.\n"
16241626
".timeout MS Try opening locked tables for MS milliseconds\n"
16251627
".trace FILE|off Output each SQL statement as it is run\n"
16261628
".vfsname ?AUX? Print the name of the VFS stack\n"
16271629
".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
1630
+ " Negative values right-justify\n"
16281631
;
16291632
16301633
static char zTimerHelp[] =
16311634
".timer ON|OFF Turn the CPU timer measurement on or off\n"
16321635
;
@@ -2897,10 +2900,24 @@
28972900
28982901
if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
28992902
sqlite3_snprintf(sizeof(p->separator), p->separator,
29002903
"%.*s", (int)sizeof(p->separator)-1, azArg[1]);
29012904
}else
2905
+
2906
+ if( c=='s'
2907
+ && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2908
+ && nArg>=2
2909
+ ){
2910
+ char *zCmd;
2911
+ int i;
2912
+ zCmd = sqlite3_mprintf("\"%s\"", azArg[1]);
2913
+ for(i=2; i<nArg; i++){
2914
+ zCmd = sqlite3_mprintf("%z \"%s\"", zCmd, azArg[i]);
2915
+ }
2916
+ system(zCmd);
2917
+ sqlite3_free(zCmd);
2918
+ }else
29022919
29032920
if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
29042921
int i;
29052922
fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
29062923
fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
29072924
--- src/shell.c
+++ src/shell.c
@@ -1578,11 +1578,11 @@
1578 " LIKE pattern TABLE.\n"
1579 ".echo ON|OFF Turn command echo on or off\n"
1580 ".exit Exit this program\n"
1581 ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n"
1582 " With no args, it turns EXPLAIN on.\n"
1583 ".header(s) ON|OFF Turn display of headers on or off\n"
1584 ".help Show this message\n"
1585 ".import FILE TABLE Import data from FILE into TABLE\n"
1586 ".indices ?TABLE? Show names of all indices\n"
1587 " If TABLE specified, only show indices for tables\n"
1588 " matching LIKE pattern TABLE.\n"
@@ -1614,19 +1614,22 @@
1614 ".save FILE Write in-memory database into FILE\n"
1615 ".schema ?TABLE? Show the CREATE statements\n"
1616 " If TABLE specified, only show tables matching\n"
1617 " LIKE pattern TABLE.\n"
1618 ".separator STRING Change separator used by output mode and .import\n"
 
1619 ".show Show the current values for various settings\n"
1620 ".stats ON|OFF Turn stats on or off\n"
 
1621 ".tables ?TABLE? List names of tables\n"
1622 " If TABLE specified, only list tables matching\n"
1623 " LIKE pattern TABLE.\n"
1624 ".timeout MS Try opening locked tables for MS milliseconds\n"
1625 ".trace FILE|off Output each SQL statement as it is run\n"
1626 ".vfsname ?AUX? Print the name of the VFS stack\n"
1627 ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
 
1628 ;
1629
1630 static char zTimerHelp[] =
1631 ".timer ON|OFF Turn the CPU timer measurement on or off\n"
1632 ;
@@ -2897,10 +2900,24 @@
2897
2898 if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2899 sqlite3_snprintf(sizeof(p->separator), p->separator,
2900 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2901 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2902
2903 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2904 int i;
2905 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2906 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
2907
--- src/shell.c
+++ src/shell.c
@@ -1578,11 +1578,11 @@
1578 " LIKE pattern TABLE.\n"
1579 ".echo ON|OFF Turn command echo on or off\n"
1580 ".exit Exit this program\n"
1581 ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n"
1582 " With no args, it turns EXPLAIN on.\n"
1583 ".headers ON|OFF Turn display of headers on or off\n"
1584 ".help Show this message\n"
1585 ".import FILE TABLE Import data from FILE into TABLE\n"
1586 ".indices ?TABLE? Show names of all indices\n"
1587 " If TABLE specified, only show indices for tables\n"
1588 " matching LIKE pattern TABLE.\n"
@@ -1614,19 +1614,22 @@
1614 ".save FILE Write in-memory database into FILE\n"
1615 ".schema ?TABLE? Show the CREATE statements\n"
1616 " If TABLE specified, only show tables matching\n"
1617 " LIKE pattern TABLE.\n"
1618 ".separator STRING Change separator used by output mode and .import\n"
1619 ".shell CMD ARGS... Run CMD ARGS... in a system shell\n"
1620 ".show Show the current values for various settings\n"
1621 ".stats ON|OFF Turn stats on or off\n"
1622 ".system CMD ARGS... Run CMD ARGS... in a system shell\n"
1623 ".tables ?TABLE? List names of tables\n"
1624 " If TABLE specified, only list tables matching\n"
1625 " LIKE pattern TABLE.\n"
1626 ".timeout MS Try opening locked tables for MS milliseconds\n"
1627 ".trace FILE|off Output each SQL statement as it is run\n"
1628 ".vfsname ?AUX? Print the name of the VFS stack\n"
1629 ".width NUM1 NUM2 ... Set column widths for \"column\" mode\n"
1630 " Negative values right-justify\n"
1631 ;
1632
1633 static char zTimerHelp[] =
1634 ".timer ON|OFF Turn the CPU timer measurement on or off\n"
1635 ;
@@ -2897,10 +2900,24 @@
2900
2901 if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
2902 sqlite3_snprintf(sizeof(p->separator), p->separator,
2903 "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
2904 }else
2905
2906 if( c=='s'
2907 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2908 && nArg>=2
2909 ){
2910 char *zCmd;
2911 int i;
2912 zCmd = sqlite3_mprintf("\"%s\"", azArg[1]);
2913 for(i=2; i<nArg; i++){
2914 zCmd = sqlite3_mprintf("%z \"%s\"", zCmd, azArg[i]);
2915 }
2916 system(zCmd);
2917 sqlite3_free(zCmd);
2918 }else
2919
2920 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2921 int i;
2922 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2923 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
2924
+140 -61
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222222
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223223
** [sqlite_version()] and [sqlite_source_id()].
224224
*/
225225
#define SQLITE_VERSION "3.8.5"
226226
#define SQLITE_VERSION_NUMBER 3008005
227
-#define SQLITE_SOURCE_ID "2014-05-24 17:15:15 ebfb51fe40756713d269b4c0ade752666910bb6e"
227
+#define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
228228
229229
/*
230230
** CAPI3REF: Run-Time Library Version Numbers
231231
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232232
**
@@ -11141,11 +11141,11 @@
1114111141
int tnum; /* DB Page containing root of this index */
1114211142
LogEst szIdxRow; /* Estimated average row size in bytes */
1114311143
u16 nKeyCol; /* Number of columns forming the key */
1114411144
u16 nColumn; /* Number of columns stored in the index */
1114511145
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
11146
- unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
11146
+ unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
1114711147
unsigned bUnordered:1; /* Use this index for == or IN queries only */
1114811148
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
1114911149
unsigned isResized:1; /* True if resizeIndexObject() has been called */
1115011150
unsigned isCovering:1; /* True if this is a covering index */
1115111151
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -11154,10 +11154,20 @@
1115411154
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1115511155
IndexSample *aSample; /* Samples of the left-most key */
1115611156
#endif
1115711157
};
1115811158
11159
+/*
11160
+** Allowed values for Index.idxType
11161
+*/
11162
+#define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */
11163
+#define SQLITE_IDXTYPE_UNIQUE 1 /* Implements a UNIQUE constraint */
11164
+#define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */
11165
+
11166
+/* Return true if index X is a PRIMARY KEY index */
11167
+#define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY)
11168
+
1115911169
/*
1116011170
** Each sample stored in the sqlite_stat3 table is represented in memory
1116111171
** using a structure of this type. See documentation at the top of the
1116211172
** analyze.c source file for additional information.
1116311173
*/
@@ -34430,11 +34440,11 @@
3443034440
#endif
3443134441
if( res == 0 ){
3443234442
pFile->lastErrno = osGetLastError();
3443334443
/* No need to log a failure to lock */
3443434444
}
34435
- OSTRACE(("READ-LOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
34445
+ OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
3443634446
return res;
3443734447
}
3443834448
3443934449
/*
3444034450
** Undo a readlock
@@ -34454,11 +34464,11 @@
3445434464
if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
3445534465
pFile->lastErrno = lastErrno;
3445634466
winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
3445734467
"winUnlockReadLock", pFile->zPath);
3445834468
}
34459
- OSTRACE(("READ-UNLOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
34469
+ OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
3446034470
return res;
3446134471
}
3446234472
3446334473
/*
3446434474
** Lock the file with the lock specified by parameter locktype - one
@@ -34529,12 +34539,12 @@
3452934539
** around problems caused by indexing and/or anti-virus software on
3453034540
** Windows systems.
3453134541
** If you are using this code as a model for alternative VFSes, do not
3453234542
** copy this retry logic. It is a hack intended for Windows only.
3453334543
*/
34534
- OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, rc=%s\n",
34535
- pFile->h, cnt, sqlite3ErrName(res)));
34544
+ OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
34545
+ pFile->h, cnt, res));
3453634546
if( cnt ) sqlite3_win32_sleep(1);
3453734547
}
3453834548
gotPendingLock = res;
3453934549
if( !res ){
3454034550
lastErrno = osGetLastError();
@@ -34615,29 +34625,29 @@
3461534625
** This routine checks if there is a RESERVED lock held on the specified
3461634626
** file by this or any other process. If such a lock is held, return
3461734627
** non-zero, otherwise zero.
3461834628
*/
3461934629
static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
34620
- int rc;
34630
+ int res;
3462134631
winFile *pFile = (winFile*)id;
3462234632
3462334633
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
3462434634
OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
3462534635
3462634636
assert( id!=0 );
3462734637
if( pFile->locktype>=RESERVED_LOCK ){
34628
- rc = 1;
34629
- OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (local)\n", pFile->h, rc));
34638
+ res = 1;
34639
+ OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
3463034640
}else{
34631
- rc = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
34632
- if( rc ){
34641
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
34642
+ if( res ){
3463334643
winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
3463434644
}
34635
- rc = !rc;
34636
- OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (remote)\n", pFile->h, rc));
34645
+ res = !res;
34646
+ OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
3463734647
}
34638
- *pResOut = rc;
34648
+ *pResOut = res;
3463934649
OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
3464034650
pFile->h, pResOut, *pResOut));
3464134651
return SQLITE_OK;
3464234652
}
3464334653
@@ -55333,16 +55343,10 @@
5533355343
assert( pCur->eState==CURSOR_VALID );
5533455344
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5533555345
assert( cursorHoldsMutex(pCur) );
5533655346
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
5533755347
assert( pCur->info.nSize>0 );
55338
-#if 0
55339
- if( pCur->info.nSize==0 ){
55340
- btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
55341
- &pCur->info);
55342
- }
55343
-#endif
5534455348
*pAmt = pCur->info.nLocal;
5534555349
return (void*)(pCur->info.pCell + pCur->info.nHeader);
5534655350
}
5534755351
5534855352
@@ -73737,11 +73741,11 @@
7373773741
#ifdef SQLITE_USE_FCNTL_TRACE
7373873742
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
7373973743
if( zTrace ){
7374073744
int i;
7374173745
for(i=0; i<db->nDb; i++){
73742
- if( MASKBIT(i) & p->btreeMask)==0 ) continue;
73746
+ if( (MASKBIT(i) & p->btreeMask)==0 ) continue;
7374373747
sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
7374473748
}
7374573749
}
7374673750
#endif /* SQLITE_USE_FCNTL_TRACE */
7374773751
#ifdef SQLITE_DEBUG
@@ -74692,11 +74696,10 @@
7469274696
nRead = (int)(pSorter->iWriteOff - iStart);
7469374697
}
7469474698
rc = sqlite3OsRead(
7469574699
pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
7469674700
);
74697
- assert( rc!=SQLITE_IOERR_SHORT_READ );
7469874701
}
7469974702
7470074703
if( rc==SQLITE_OK ){
7470174704
u64 nByte; /* Size of PMA in bytes */
7470274705
pIter->iEof = pSorter->iWriteOff;
@@ -83655,11 +83658,11 @@
8365583658
nCol = pIdx->nKeyCol;
8365683659
aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
8365783660
if( aGotoChng==0 ) continue;
8365883661
8365983662
/* Populate the register containing the index name. */
83660
- if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
83663
+ if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
8366183664
zIdxName = pTab->zName;
8366283665
}else{
8366383666
zIdxName = pIdx->zName;
8366483667
}
8366583668
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
@@ -86022,11 +86025,11 @@
8602286025
/*
8602386026
** Return the PRIMARY KEY index of a table
8602486027
*/
8602586028
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
8602686029
Index *p;
86027
- for(p=pTab->pIndex; p && p->autoIndex!=2; p=p->pNext){}
86030
+ for(p=pTab->pIndex; p && !IsPrimaryKeyIndex(p); p=p->pNext){}
8602886031
return p;
8602986032
}
8603086033
8603186034
/*
8603286035
** Return the column of index pIdx that corresponds to table
@@ -86551,11 +86554,11 @@
8655186554
Index *p;
8655286555
if( v ) pParse->addrSkipPK = sqlite3VdbeAddOp0(v, OP_Noop);
8655386556
p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
8655486557
0, sortOrder, 0);
8655586558
if( p ){
86556
- p->autoIndex = 2;
86559
+ p->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
8655786560
if( v ) sqlite3VdbeJumpHere(v, pParse->addrSkipPK);
8655886561
}
8655986562
pList = 0;
8656086563
}
8656186564
@@ -86926,11 +86929,11 @@
8692686929
pTab->aCol[pTab->iPKey].zName);
8692786930
pList->a[0].sortOrder = pParse->iPkSortOrder;
8692886931
assert( pParse->pNewTable==pTab );
8692986932
pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
8693086933
if( pPk==0 ) return;
86931
- pPk->autoIndex = 2;
86934
+ pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
8693286935
pTab->iPKey = -1;
8693386936
}else{
8693486937
pPk = sqlite3PrimaryKeyIndex(pTab);
8693586938
}
8693686939
pPk->isCovering = 1;
@@ -86949,11 +86952,11 @@
8694986952
/* Update the in-memory representation of all UNIQUE indices by converting
8695086953
** the final rowid column into one or more columns of the PRIMARY KEY.
8695186954
*/
8695286955
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
8695386956
int n;
86954
- if( pIdx->autoIndex==2 ) continue;
86957
+ if( IsPrimaryKeyIndex(pIdx) ) continue;
8695586958
for(i=n=0; i<nPk; i++){
8695686959
if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
8695786960
}
8695886961
if( n==0 ){
8695986962
/* This index is a superset of the primary key */
@@ -88029,11 +88032,11 @@
8802988032
** is a primary key or unique-constraint on the most recent column added
8803088033
** to the table currently under construction.
8803188034
**
8803288035
** If the index is created successfully, return a pointer to the new Index
8803388036
** structure. This is used by sqlite3AddPrimaryKey() to mark the index
88034
-** as the tables primary key (Index.autoIndex==2).
88037
+** as the tables primary key (Index.idxType==SQLITE_IDXTYPE_PRIMARYKEY)
8803588038
*/
8803688039
SQLITE_PRIVATE Index *sqlite3CreateIndex(
8803788040
Parse *pParse, /* All information about this parse */
8803888041
Token *pName1, /* First part of index name. May be NULL */
8803988042
Token *pName2, /* Second part of index name. May be NULL */
@@ -88244,11 +88247,11 @@
8824488247
zExtra += nName + 1;
8824588248
memcpy(pIndex->zName, zName, nName+1);
8824688249
pIndex->pTable = pTab;
8824788250
pIndex->onError = (u8)onError;
8824888251
pIndex->uniqNotNull = onError!=OE_None;
88249
- pIndex->autoIndex = (u8)(pName==0);
88252
+ pIndex->idxType = pName ? SQLITE_IDXTYPE_APPDEF : SQLITE_IDXTYPE_UNIQUE;
8825088253
pIndex->pSchema = db->aDb[iDb].pSchema;
8825188254
pIndex->nKeyCol = pList->nExpr;
8825288255
if( pPIWhere ){
8825388256
sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
8825488257
pIndex->pPartIdxWhere = pPIWhere;
@@ -88356,11 +88359,11 @@
8835688359
*/
8835788360
Index *pIdx;
8835888361
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
8835988362
int k;
8836088363
assert( pIdx->onError!=OE_None );
88361
- assert( pIdx->autoIndex );
88364
+ assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
8836288365
assert( pIndex->onError!=OE_None );
8836388366
8836488367
if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
8836588368
for(k=0; k<pIdx->nKeyCol; k++){
8836688369
const char *z1;
@@ -88579,11 +88582,11 @@
8857988582
sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
8858088583
}
8858188584
pParse->checkSchema = 1;
8858288585
goto exit_drop_index;
8858388586
}
88584
- if( pIndex->autoIndex ){
88587
+ if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
8858588588
sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
8858688589
"or PRIMARY KEY constraint cannot be dropped", 0);
8858788590
goto exit_drop_index;
8858888591
}
8858988592
iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
@@ -89238,11 +89241,12 @@
8923889241
sqlite3StrAccumAppend(&errMsg, ".", 1);
8923989242
sqlite3StrAccumAppendAll(&errMsg, zCol);
8924089243
}
8924189244
zErr = sqlite3StrAccumFinish(&errMsg);
8924289245
sqlite3HaltConstraint(pParse,
89243
- (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
89246
+ IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
89247
+ : SQLITE_CONSTRAINT_UNIQUE,
8924489248
onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
8924589249
}
8924689250
8924789251
8924889252
/*
@@ -92816,12 +92820,12 @@
9281692820
** column of pFKey, then this index is a winner. */
9281792821
9281892822
if( zKey==0 ){
9281992823
/* If zKey is NULL, then this foreign key is implicitly mapped to
9282092824
** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
92821
- ** identified by the test (Index.autoIndex==2). */
92822
- if( pIdx->autoIndex==2 ){
92825
+ ** identified by the test. */
92826
+ if( IsPrimaryKeyIndex(pIdx) ){
9282392827
if( aiCol ){
9282492828
int i;
9282592829
for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
9282692830
}
9282792831
break;
@@ -95411,11 +95415,11 @@
9541195415
** For a UNIQUE index, only conflict if the PRIMARY KEY values
9541295416
** of the matched index row are different from the original PRIMARY
9541395417
** KEY values of this row before the update. */
9541495418
int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
9541595419
int op = OP_Ne;
95416
- int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
95420
+ int regCmp = (IsPrimaryKeyIndex(pIdx) ? regIdx : regR);
9541795421
9541895422
for(i=0; i<pPk->nKeyCol; i++){
9541995423
char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
9542095424
x = pPk->aiColumn[i];
9542195425
if( i==(pPk->nKeyCol-1) ){
@@ -95512,11 +95516,11 @@
9551295516
VdbeCoverage(v);
9551395517
}
9551495518
sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
9551595519
pik_flags = 0;
9551695520
if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
95517
- if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
95521
+ if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
9551895522
assert( pParse->nested==0 );
9551995523
pik_flags |= OPFLAG_NCHANGE;
9552095524
}
9552195525
if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
9552295526
}
@@ -95598,11 +95602,11 @@
9559895602
}
9559995603
if( piIdxCur ) *piIdxCur = iBase;
9560095604
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9560195605
int iIdxCur = iBase++;
9560295606
assert( pIdx->pSchema==pTab->pSchema );
95603
- if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
95607
+ if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) && piDataCur ){
9560495608
*piDataCur = iIdxCur;
9560595609
}
9560695610
if( aToOpen==0 || aToOpen[i+1] ){
9560795611
sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
9560895612
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
@@ -105060,11 +105064,11 @@
105060105064
Parse *pParse, /* Parse context */
105061105065
Table *pTab, /* Table being queried */
105062105066
Index *pIdx /* Index used to optimize scan, or NULL */
105063105067
){
105064105068
if( pParse->explain==2 ){
105065
- int bCover = (pIdx!=0 && (HasRowid(pTab) || pIdx->autoIndex!=2));
105069
+ int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
105066105070
char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
105067105071
pTab->zName,
105068105072
bCover ? " USING COVERING INDEX " : "",
105069105073
bCover ? pIdx->zName : ""
105070105074
);
@@ -107488,11 +107492,11 @@
107488107492
*/
107489107493
pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
107490107494
iIdxCur = iDataCur+1;
107491107495
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
107492107496
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
107493
- if( pIdx->autoIndex==2 && pPk!=0 ){
107497
+ if( IsPrimaryKeyIndex(pIdx) && pPk!=0 ){
107494107498
iDataCur = pParse->nTab;
107495107499
pTabList->a[0].iCursor = iDataCur;
107496107500
}
107497107501
pParse->nTab++;
107498107502
}
@@ -112732,11 +112736,11 @@
112732112736
){
112733112737
const char *zFmt;
112734112738
Index *pIdx = pLoop->u.btree.pIndex;
112735112739
char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
112736112740
assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
112737
- if( !HasRowid(pItem->pTab) && pIdx->autoIndex==2 ){
112741
+ if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
112738112742
zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
112739112743
}else if( flags & WHERE_AUTO_INDEX ){
112740112744
zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
112741112745
}else if( flags & WHERE_IDX_ONLY ){
112742112746
zFmt = "%s USING COVERING INDEX %s%s";
@@ -113233,11 +113237,11 @@
113233113237
}else if( HasRowid(pIdx->pTable) ){
113234113238
iRowidReg = ++pParse->nMem;
113235113239
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
113236113240
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
113237113241
sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
113238
- }else{
113242
+ }else if( iCur!=iIdxCur ){
113239113243
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
113240113244
iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
113241113245
for(j=0; j<pPk->nKeyCol; j++){
113242113246
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
113243113247
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
@@ -113303,10 +113307,14 @@
113303113307
**
113304113308
** Return 2 # Jump back to the Gosub
113305113309
**
113306113310
** B: <after the loop>
113307113311
**
113312
+ ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
113313
+ ** use an ephermeral index instead of a RowSet to record the primary
113314
+ ** keys of the rows we have already seen.
113315
+ **
113308113316
*/
113309113317
WhereClause *pOrWc; /* The OR-clause broken out into subterms */
113310113318
SrcList *pOrTab; /* Shortened table list or OR-clause generation */
113311113319
Index *pCov = 0; /* Potential covering index (or NULL) */
113312113320
int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
@@ -113317,10 +113325,11 @@
113317113325
int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113318113326
int iRetInit; /* Address of regReturn init */
113319113327
int untestedTerms = 0; /* Some terms not completely tested */
113320113328
int ii; /* Loop counter */
113321113329
Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
113330
+ Table *pTab = pTabItem->pTab;
113322113331
113323113332
pTerm = pLoop->aLTerm[0];
113324113333
assert( pTerm!=0 );
113325113334
assert( pTerm->eOperator & WO_OR );
113326113335
assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -113349,11 +113358,12 @@
113349113358
}else{
113350113359
pOrTab = pWInfo->pTabList;
113351113360
}
113352113361
113353113362
/* Initialize the rowset register to contain NULL. An SQL NULL is
113354
- ** equivalent to an empty rowset.
113363
+ ** equivalent to an empty rowset. Or, create an ephermeral index
113364
+ ** capable of holding primary keys in the case of a WITHOUT ROWID.
113355113365
**
113356113366
** Also initialize regReturn to contain the address of the instruction
113357113367
** immediately following the OP_Return at the bottom of the loop. This
113358113368
** is required in a few obscure LEFT JOIN cases where control jumps
113359113369
** over the top of the loop into the body of it. In this case the
@@ -113360,13 +113370,20 @@
113360113370
** correct response for the end-of-loop code (the OP_Return) is to
113361113371
** fall through to the next instruction, just as an OP_Next does if
113362113372
** called on an uninitialized cursor.
113363113373
*/
113364113374
if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
113365
- regRowset = ++pParse->nMem;
113375
+ if( HasRowid(pTab) ){
113376
+ regRowset = ++pParse->nMem;
113377
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
113378
+ }else{
113379
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
113380
+ regRowset = pParse->nTab++;
113381
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, regRowset, pPk->nKeyCol);
113382
+ sqlite3VdbeSetP4KeyInfo(pParse, pPk);
113383
+ }
113366113384
regRowid = ++pParse->nMem;
113367
- sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
113368113385
}
113369113386
iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
113370113387
113371113388
/* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
113372113389
** Then for every term xN, evaluate as the subexpression: xN AND z
@@ -113398,15 +113415,20 @@
113398113415
if( pAndExpr ){
113399113416
pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
113400113417
}
113401113418
}
113402113419
113420
+ /* Run a separate WHERE clause for each term of the OR clause. After
113421
+ ** eliminating duplicates from other WHERE clauses, the action for each
113422
+ ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
113423
+ */
113403113424
for(ii=0; ii<pOrWc->nTerm; ii++){
113404113425
WhereTerm *pOrTerm = &pOrWc->a[ii];
113405113426
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113406
- WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113407
- Expr *pOrExpr = pOrTerm->pExpr;
113427
+ WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113428
+ Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
113429
+ int j1 = 0; /* Address of jump operation */
113408113430
if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
113409113431
pAndExpr->pLeft = pOrExpr;
113410113432
pOrExpr = pAndExpr;
113411113433
}
113412113434
/* Loop through table entries that match term pOrTerm. */
@@ -113417,20 +113439,66 @@
113417113439
if( pSubWInfo ){
113418113440
WhereLoop *pSubLoop;
113419113441
explainOneScan(
113420113442
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
113421113443
);
113444
+ /* This is the sub-WHERE clause body. First skip over
113445
+ ** duplicate rows from prior sub-WHERE clauses, and record the
113446
+ ** rowid (or PRIMARY KEY) for the current row so that the same
113447
+ ** row will be skipped in subsequent sub-WHERE clauses.
113448
+ */
113422113449
if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
113423
- int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
113424113450
int r;
113425
- r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
113426
- regRowid, 0);
113427
- sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
113428
- sqlite3VdbeCurrentAddr(v)+2, r, iSet);
113429
- VdbeCoverage(v);
113451
+ int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
113452
+ if( HasRowid(pTab) ){
113453
+ r = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, regRowid, 0);
113454
+ j1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0, r,iSet);
113455
+ VdbeCoverage(v);
113456
+ }else{
113457
+ Index *pPk = sqlite3PrimaryKeyIndex(pTab);
113458
+ int nPk = pPk->nKeyCol;
113459
+ int iPk;
113460
+
113461
+ /* Read the PK into an array of temp registers. */
113462
+ r = sqlite3GetTempRange(pParse, nPk);
113463
+ for(iPk=0; iPk<nPk; iPk++){
113464
+ int iCol = pPk->aiColumn[iPk];
113465
+ sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0);
113466
+ }
113467
+
113468
+ /* Check if the temp table already contains this key. If so,
113469
+ ** the row has already been included in the result set and
113470
+ ** can be ignored (by jumping past the Gosub below). Otherwise,
113471
+ ** insert the key into the temp table and proceed with processing
113472
+ ** the row.
113473
+ **
113474
+ ** Use some of the same optimizations as OP_RowSetTest: If iSet
113475
+ ** is zero, assume that the key cannot already be present in
113476
+ ** the temp table. And if iSet is -1, assume that there is no
113477
+ ** need to insert the key into the temp table, as it will never
113478
+ ** be tested for. */
113479
+ if( iSet ){
113480
+ j1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
113481
+ VdbeCoverage(v);
113482
+ }
113483
+ if( iSet>=0 ){
113484
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
113485
+ sqlite3VdbeAddOp3(v, OP_IdxInsert, regRowset, regRowid, 0);
113486
+ if( iSet ) sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
113487
+ }
113488
+
113489
+ /* Release the array of temp registers */
113490
+ sqlite3ReleaseTempRange(pParse, r, nPk);
113491
+ }
113430113492
}
113493
+
113494
+ /* Invoke the main loop body as a subroutine */
113431113495
sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
113496
+
113497
+ /* Jump here (skipping the main loop body subroutine) if the
113498
+ ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
113499
+ if( j1 ) sqlite3VdbeJumpHere(v, j1);
113432113500
113433113501
/* The pSubWInfo->untestedTerms flag means that this OR term
113434113502
** contained one or more AND term from a notReady table. The
113435113503
** terms from the notReady table could not be tested and will
113436113504
** need to be tested later.
@@ -113451,10 +113519,11 @@
113451113519
*/
113452113520
pSubLoop = pSubWInfo->a[0].pWLoop;
113453113521
assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
113454113522
if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
113455113523
&& (ii==0 || pSubLoop->u.btree.pIndex==pCov)
113524
+ && (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
113456113525
){
113457113526
assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113458113527
pCov = pSubLoop->u.btree.pIndex;
113459113528
}else{
113460113529
pCov = 0;
@@ -114776,11 +114845,10 @@
114776114845
if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
114777114846
pWCEnd = pWC->a + pWC->nTerm;
114778114847
pNew = pBuilder->pNew;
114779114848
memset(&sSum, 0, sizeof(sSum));
114780114849
pItem = pWInfo->pTabList->a + pNew->iTab;
114781
- if( !HasRowid(pItem->pTab) ) return SQLITE_OK;
114782114850
iCur = pItem->iCursor;
114783114851
114784114852
for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
114785114853
if( (pTerm->eOperator & WO_OR)!=0
114786114854
&& (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -116025,11 +116093,18 @@
116025116093
Index *pIx = pLoop->u.btree.pIndex;
116026116094
int iIndexCur;
116027116095
int op = OP_OpenRead;
116028116096
/* iIdxCur is always set if to a positive value if ONEPASS is possible */
116029116097
assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
116030
- if( pWInfo->okOnePass ){
116098
+ if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
116099
+ && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0
116100
+ ){
116101
+ /* This is one term of an OR-optimization using the PRIMARY KEY of a
116102
+ ** WITHOUT ROWID table. No need for a separate index */
116103
+ iIndexCur = pLevel->iTabCur;
116104
+ op = 0;
116105
+ }else if( pWInfo->okOnePass ){
116031116106
Index *pJ = pTabItem->pTab->pIndex;
116032116107
iIndexCur = iIdxCur;
116033116108
assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
116034116109
while( ALWAYS(pJ) && pJ!=pIx ){
116035116110
iIndexCur++;
@@ -116043,13 +116118,15 @@
116043116118
iIndexCur = pParse->nTab++;
116044116119
}
116045116120
pLevel->iIdxCur = iIndexCur;
116046116121
assert( pIx->pSchema==pTab->pSchema );
116047116122
assert( iIndexCur>=0 );
116048
- sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
116049
- sqlite3VdbeSetP4KeyInfo(pParse, pIx);
116050
- VdbeComment((v, "%s", pIx->zName));
116123
+ if( op ){
116124
+ sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
116125
+ sqlite3VdbeSetP4KeyInfo(pParse, pIx);
116126
+ VdbeComment((v, "%s", pIx->zName));
116127
+ }
116051116128
}
116052116129
if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
116053116130
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
116054116131
}
116055116132
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
@@ -127015,11 +127092,13 @@
127015127092
/* Fill in the abNotindexed array */
127016127093
for(iCol=0; iCol<nCol; iCol++){
127017127094
int n = (int)strlen(p->azColumn[iCol]);
127018127095
for(i=0; i<nNotindexed; i++){
127019127096
char *zNot = azNotindexed[i];
127020
- if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
127097
+ if( zNot && n==(int)strlen(zNot)
127098
+ && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n)
127099
+ ){
127021127100
p->abNotindexed[iCol] = 1;
127022127101
sqlite3_free(zNot);
127023127102
azNotindexed[i] = 0;
127024127103
}
127025127104
}
@@ -132492,11 +132571,11 @@
132492132571
if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
132493132572
*pnConsumed = (int)(zInput - z) + 1 + nConsumed;
132494132573
return rc;
132495132574
}else if( *zInput==')' ){
132496132575
pParse->nNest--;
132497
- *pnConsumed = (zInput - z) + 1;
132576
+ *pnConsumed = (int)((zInput - z) + 1);
132498132577
*ppExpr = 0;
132499132578
return SQLITE_DONE;
132500132579
}
132501132580
}
132502132581
@@ -138568,11 +138647,11 @@
138568138647
** such segments are smaller than nLimit bytes in size, they will be
138569138648
** promoted to level iAbsLevel. */
138570138649
sqlite3_bind_int64(pRange, 1, iAbsLevel+1);
138571138650
sqlite3_bind_int64(pRange, 2, iLast);
138572138651
while( SQLITE_ROW==sqlite3_step(pRange) ){
138573
- i64 nSize, dummy;
138652
+ i64 nSize = 0, dummy;
138574138653
fts3ReadEndBlockField(pRange, 2, &dummy, &nSize);
138575138654
if( nSize<=0 || nSize>nLimit ){
138576138655
/* If nSize==0, then the %_segdir.end_block field does not not
138577138656
** contain a size value. This happens if it was written by an
138578138657
** old version of FTS. In this case it is not possible to determine
@@ -140373,11 +140452,11 @@
140373140452
140374140453
if( rc==SQLITE_OK ){
140375140454
rc = fts3IncrmergeOutputIdx(p, iAbsLevel, &iIdx);
140376140455
assert( bUseHint==1 || bUseHint==0 );
140377140456
if( iIdx==0 || (bUseHint && iIdx==1) ){
140378
- int bIgnore;
140457
+ int bIgnore = 0;
140379140458
rc = fts3SegmentIsMaxLevel(p, iAbsLevel+1, &bIgnore);
140380140459
if( bIgnore ){
140381140460
pFilter->flags |= FTS3_SEGMENT_IGNORE_EMPTY;
140382140461
}
140383140462
}
140384140463
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.5"
226 #define SQLITE_VERSION_NUMBER 3008005
227 #define SQLITE_SOURCE_ID "2014-05-24 17:15:15 ebfb51fe40756713d269b4c0ade752666910bb6e"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -11141,11 +11141,11 @@
11141 int tnum; /* DB Page containing root of this index */
11142 LogEst szIdxRow; /* Estimated average row size in bytes */
11143 u16 nKeyCol; /* Number of columns forming the key */
11144 u16 nColumn; /* Number of columns stored in the index */
11145 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
11146 unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
11147 unsigned bUnordered:1; /* Use this index for == or IN queries only */
11148 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
11149 unsigned isResized:1; /* True if resizeIndexObject() has been called */
11150 unsigned isCovering:1; /* True if this is a covering index */
11151 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -11154,10 +11154,20 @@
11154 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11155 IndexSample *aSample; /* Samples of the left-most key */
11156 #endif
11157 };
11158
 
 
 
 
 
 
 
 
 
 
11159 /*
11160 ** Each sample stored in the sqlite_stat3 table is represented in memory
11161 ** using a structure of this type. See documentation at the top of the
11162 ** analyze.c source file for additional information.
11163 */
@@ -34430,11 +34440,11 @@
34430 #endif
34431 if( res == 0 ){
34432 pFile->lastErrno = osGetLastError();
34433 /* No need to log a failure to lock */
34434 }
34435 OSTRACE(("READ-LOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
34436 return res;
34437 }
34438
34439 /*
34440 ** Undo a readlock
@@ -34454,11 +34464,11 @@
34454 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
34455 pFile->lastErrno = lastErrno;
34456 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
34457 "winUnlockReadLock", pFile->zPath);
34458 }
34459 OSTRACE(("READ-UNLOCK file=%p, rc=%s\n", pFile->h, sqlite3ErrName(res)));
34460 return res;
34461 }
34462
34463 /*
34464 ** Lock the file with the lock specified by parameter locktype - one
@@ -34529,12 +34539,12 @@
34529 ** around problems caused by indexing and/or anti-virus software on
34530 ** Windows systems.
34531 ** If you are using this code as a model for alternative VFSes, do not
34532 ** copy this retry logic. It is a hack intended for Windows only.
34533 */
34534 OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, rc=%s\n",
34535 pFile->h, cnt, sqlite3ErrName(res)));
34536 if( cnt ) sqlite3_win32_sleep(1);
34537 }
34538 gotPendingLock = res;
34539 if( !res ){
34540 lastErrno = osGetLastError();
@@ -34615,29 +34625,29 @@
34615 ** This routine checks if there is a RESERVED lock held on the specified
34616 ** file by this or any other process. If such a lock is held, return
34617 ** non-zero, otherwise zero.
34618 */
34619 static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
34620 int rc;
34621 winFile *pFile = (winFile*)id;
34622
34623 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
34624 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
34625
34626 assert( id!=0 );
34627 if( pFile->locktype>=RESERVED_LOCK ){
34628 rc = 1;
34629 OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (local)\n", pFile->h, rc));
34630 }else{
34631 rc = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
34632 if( rc ){
34633 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
34634 }
34635 rc = !rc;
34636 OSTRACE(("TEST-WR-LOCK file=%p, rc=%d (remote)\n", pFile->h, rc));
34637 }
34638 *pResOut = rc;
34639 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
34640 pFile->h, pResOut, *pResOut));
34641 return SQLITE_OK;
34642 }
34643
@@ -55333,16 +55343,10 @@
55333 assert( pCur->eState==CURSOR_VALID );
55334 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55335 assert( cursorHoldsMutex(pCur) );
55336 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
55337 assert( pCur->info.nSize>0 );
55338 #if 0
55339 if( pCur->info.nSize==0 ){
55340 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
55341 &pCur->info);
55342 }
55343 #endif
55344 *pAmt = pCur->info.nLocal;
55345 return (void*)(pCur->info.pCell + pCur->info.nHeader);
55346 }
55347
55348
@@ -73737,11 +73741,11 @@
73737 #ifdef SQLITE_USE_FCNTL_TRACE
73738 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
73739 if( zTrace ){
73740 int i;
73741 for(i=0; i<db->nDb; i++){
73742 if( MASKBIT(i) & p->btreeMask)==0 ) continue;
73743 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
73744 }
73745 }
73746 #endif /* SQLITE_USE_FCNTL_TRACE */
73747 #ifdef SQLITE_DEBUG
@@ -74692,11 +74696,10 @@
74692 nRead = (int)(pSorter->iWriteOff - iStart);
74693 }
74694 rc = sqlite3OsRead(
74695 pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
74696 );
74697 assert( rc!=SQLITE_IOERR_SHORT_READ );
74698 }
74699
74700 if( rc==SQLITE_OK ){
74701 u64 nByte; /* Size of PMA in bytes */
74702 pIter->iEof = pSorter->iWriteOff;
@@ -83655,11 +83658,11 @@
83655 nCol = pIdx->nKeyCol;
83656 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
83657 if( aGotoChng==0 ) continue;
83658
83659 /* Populate the register containing the index name. */
83660 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
83661 zIdxName = pTab->zName;
83662 }else{
83663 zIdxName = pIdx->zName;
83664 }
83665 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
@@ -86022,11 +86025,11 @@
86022 /*
86023 ** Return the PRIMARY KEY index of a table
86024 */
86025 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
86026 Index *p;
86027 for(p=pTab->pIndex; p && p->autoIndex!=2; p=p->pNext){}
86028 return p;
86029 }
86030
86031 /*
86032 ** Return the column of index pIdx that corresponds to table
@@ -86551,11 +86554,11 @@
86551 Index *p;
86552 if( v ) pParse->addrSkipPK = sqlite3VdbeAddOp0(v, OP_Noop);
86553 p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
86554 0, sortOrder, 0);
86555 if( p ){
86556 p->autoIndex = 2;
86557 if( v ) sqlite3VdbeJumpHere(v, pParse->addrSkipPK);
86558 }
86559 pList = 0;
86560 }
86561
@@ -86926,11 +86929,11 @@
86926 pTab->aCol[pTab->iPKey].zName);
86927 pList->a[0].sortOrder = pParse->iPkSortOrder;
86928 assert( pParse->pNewTable==pTab );
86929 pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
86930 if( pPk==0 ) return;
86931 pPk->autoIndex = 2;
86932 pTab->iPKey = -1;
86933 }else{
86934 pPk = sqlite3PrimaryKeyIndex(pTab);
86935 }
86936 pPk->isCovering = 1;
@@ -86949,11 +86952,11 @@
86949 /* Update the in-memory representation of all UNIQUE indices by converting
86950 ** the final rowid column into one or more columns of the PRIMARY KEY.
86951 */
86952 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
86953 int n;
86954 if( pIdx->autoIndex==2 ) continue;
86955 for(i=n=0; i<nPk; i++){
86956 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
86957 }
86958 if( n==0 ){
86959 /* This index is a superset of the primary key */
@@ -88029,11 +88032,11 @@
88029 ** is a primary key or unique-constraint on the most recent column added
88030 ** to the table currently under construction.
88031 **
88032 ** If the index is created successfully, return a pointer to the new Index
88033 ** structure. This is used by sqlite3AddPrimaryKey() to mark the index
88034 ** as the tables primary key (Index.autoIndex==2).
88035 */
88036 SQLITE_PRIVATE Index *sqlite3CreateIndex(
88037 Parse *pParse, /* All information about this parse */
88038 Token *pName1, /* First part of index name. May be NULL */
88039 Token *pName2, /* Second part of index name. May be NULL */
@@ -88244,11 +88247,11 @@
88244 zExtra += nName + 1;
88245 memcpy(pIndex->zName, zName, nName+1);
88246 pIndex->pTable = pTab;
88247 pIndex->onError = (u8)onError;
88248 pIndex->uniqNotNull = onError!=OE_None;
88249 pIndex->autoIndex = (u8)(pName==0);
88250 pIndex->pSchema = db->aDb[iDb].pSchema;
88251 pIndex->nKeyCol = pList->nExpr;
88252 if( pPIWhere ){
88253 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
88254 pIndex->pPartIdxWhere = pPIWhere;
@@ -88356,11 +88359,11 @@
88356 */
88357 Index *pIdx;
88358 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88359 int k;
88360 assert( pIdx->onError!=OE_None );
88361 assert( pIdx->autoIndex );
88362 assert( pIndex->onError!=OE_None );
88363
88364 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
88365 for(k=0; k<pIdx->nKeyCol; k++){
88366 const char *z1;
@@ -88579,11 +88582,11 @@
88579 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
88580 }
88581 pParse->checkSchema = 1;
88582 goto exit_drop_index;
88583 }
88584 if( pIndex->autoIndex ){
88585 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
88586 "or PRIMARY KEY constraint cannot be dropped", 0);
88587 goto exit_drop_index;
88588 }
88589 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
@@ -89238,11 +89241,12 @@
89238 sqlite3StrAccumAppend(&errMsg, ".", 1);
89239 sqlite3StrAccumAppendAll(&errMsg, zCol);
89240 }
89241 zErr = sqlite3StrAccumFinish(&errMsg);
89242 sqlite3HaltConstraint(pParse,
89243 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
 
89244 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
89245 }
89246
89247
89248 /*
@@ -92816,12 +92820,12 @@
92816 ** column of pFKey, then this index is a winner. */
92817
92818 if( zKey==0 ){
92819 /* If zKey is NULL, then this foreign key is implicitly mapped to
92820 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
92821 ** identified by the test (Index.autoIndex==2). */
92822 if( pIdx->autoIndex==2 ){
92823 if( aiCol ){
92824 int i;
92825 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
92826 }
92827 break;
@@ -95411,11 +95415,11 @@
95411 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
95412 ** of the matched index row are different from the original PRIMARY
95413 ** KEY values of this row before the update. */
95414 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
95415 int op = OP_Ne;
95416 int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
95417
95418 for(i=0; i<pPk->nKeyCol; i++){
95419 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
95420 x = pPk->aiColumn[i];
95421 if( i==(pPk->nKeyCol-1) ){
@@ -95512,11 +95516,11 @@
95512 VdbeCoverage(v);
95513 }
95514 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
95515 pik_flags = 0;
95516 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
95517 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
95518 assert( pParse->nested==0 );
95519 pik_flags |= OPFLAG_NCHANGE;
95520 }
95521 if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
95522 }
@@ -95598,11 +95602,11 @@
95598 }
95599 if( piIdxCur ) *piIdxCur = iBase;
95600 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
95601 int iIdxCur = iBase++;
95602 assert( pIdx->pSchema==pTab->pSchema );
95603 if( pIdx->autoIndex==2 && !HasRowid(pTab) && piDataCur ){
95604 *piDataCur = iIdxCur;
95605 }
95606 if( aToOpen==0 || aToOpen[i+1] ){
95607 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
95608 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
@@ -105060,11 +105064,11 @@
105060 Parse *pParse, /* Parse context */
105061 Table *pTab, /* Table being queried */
105062 Index *pIdx /* Index used to optimize scan, or NULL */
105063 ){
105064 if( pParse->explain==2 ){
105065 int bCover = (pIdx!=0 && (HasRowid(pTab) || pIdx->autoIndex!=2));
105066 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
105067 pTab->zName,
105068 bCover ? " USING COVERING INDEX " : "",
105069 bCover ? pIdx->zName : ""
105070 );
@@ -107488,11 +107492,11 @@
107488 */
107489 pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
107490 iIdxCur = iDataCur+1;
107491 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
107492 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
107493 if( pIdx->autoIndex==2 && pPk!=0 ){
107494 iDataCur = pParse->nTab;
107495 pTabList->a[0].iCursor = iDataCur;
107496 }
107497 pParse->nTab++;
107498 }
@@ -112732,11 +112736,11 @@
112732 ){
112733 const char *zFmt;
112734 Index *pIdx = pLoop->u.btree.pIndex;
112735 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
112736 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
112737 if( !HasRowid(pItem->pTab) && pIdx->autoIndex==2 ){
112738 zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
112739 }else if( flags & WHERE_AUTO_INDEX ){
112740 zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
112741 }else if( flags & WHERE_IDX_ONLY ){
112742 zFmt = "%s USING COVERING INDEX %s%s";
@@ -113233,11 +113237,11 @@
113233 }else if( HasRowid(pIdx->pTable) ){
113234 iRowidReg = ++pParse->nMem;
113235 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
113236 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
113237 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
113238 }else{
113239 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
113240 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
113241 for(j=0; j<pPk->nKeyCol; j++){
113242 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
113243 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
@@ -113303,10 +113307,14 @@
113303 **
113304 ** Return 2 # Jump back to the Gosub
113305 **
113306 ** B: <after the loop>
113307 **
 
 
 
 
113308 */
113309 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
113310 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
113311 Index *pCov = 0; /* Potential covering index (or NULL) */
113312 int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
@@ -113317,10 +113325,11 @@
113317 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113318 int iRetInit; /* Address of regReturn init */
113319 int untestedTerms = 0; /* Some terms not completely tested */
113320 int ii; /* Loop counter */
113321 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
 
113322
113323 pTerm = pLoop->aLTerm[0];
113324 assert( pTerm!=0 );
113325 assert( pTerm->eOperator & WO_OR );
113326 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -113349,11 +113358,12 @@
113349 }else{
113350 pOrTab = pWInfo->pTabList;
113351 }
113352
113353 /* Initialize the rowset register to contain NULL. An SQL NULL is
113354 ** equivalent to an empty rowset.
 
113355 **
113356 ** Also initialize regReturn to contain the address of the instruction
113357 ** immediately following the OP_Return at the bottom of the loop. This
113358 ** is required in a few obscure LEFT JOIN cases where control jumps
113359 ** over the top of the loop into the body of it. In this case the
@@ -113360,13 +113370,20 @@
113360 ** correct response for the end-of-loop code (the OP_Return) is to
113361 ** fall through to the next instruction, just as an OP_Next does if
113362 ** called on an uninitialized cursor.
113363 */
113364 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
113365 regRowset = ++pParse->nMem;
 
 
 
 
 
 
 
 
113366 regRowid = ++pParse->nMem;
113367 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
113368 }
113369 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
113370
113371 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
113372 ** Then for every term xN, evaluate as the subexpression: xN AND z
@@ -113398,15 +113415,20 @@
113398 if( pAndExpr ){
113399 pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
113400 }
113401 }
113402
 
 
 
 
113403 for(ii=0; ii<pOrWc->nTerm; ii++){
113404 WhereTerm *pOrTerm = &pOrWc->a[ii];
113405 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113406 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113407 Expr *pOrExpr = pOrTerm->pExpr;
 
113408 if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
113409 pAndExpr->pLeft = pOrExpr;
113410 pOrExpr = pAndExpr;
113411 }
113412 /* Loop through table entries that match term pOrTerm. */
@@ -113417,20 +113439,66 @@
113417 if( pSubWInfo ){
113418 WhereLoop *pSubLoop;
113419 explainOneScan(
113420 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
113421 );
 
 
 
 
 
113422 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
113423 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
113424 int r;
113425 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
113426 regRowid, 0);
113427 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
113428 sqlite3VdbeCurrentAddr(v)+2, r, iSet);
113429 VdbeCoverage(v);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113430 }
 
 
113431 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
 
 
 
 
113432
113433 /* The pSubWInfo->untestedTerms flag means that this OR term
113434 ** contained one or more AND term from a notReady table. The
113435 ** terms from the notReady table could not be tested and will
113436 ** need to be tested later.
@@ -113451,10 +113519,11 @@
113451 */
113452 pSubLoop = pSubWInfo->a[0].pWLoop;
113453 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
113454 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
113455 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
 
113456 ){
113457 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113458 pCov = pSubLoop->u.btree.pIndex;
113459 }else{
113460 pCov = 0;
@@ -114776,11 +114845,10 @@
114776 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
114777 pWCEnd = pWC->a + pWC->nTerm;
114778 pNew = pBuilder->pNew;
114779 memset(&sSum, 0, sizeof(sSum));
114780 pItem = pWInfo->pTabList->a + pNew->iTab;
114781 if( !HasRowid(pItem->pTab) ) return SQLITE_OK;
114782 iCur = pItem->iCursor;
114783
114784 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
114785 if( (pTerm->eOperator & WO_OR)!=0
114786 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -116025,11 +116093,18 @@
116025 Index *pIx = pLoop->u.btree.pIndex;
116026 int iIndexCur;
116027 int op = OP_OpenRead;
116028 /* iIdxCur is always set if to a positive value if ONEPASS is possible */
116029 assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
116030 if( pWInfo->okOnePass ){
 
 
 
 
 
 
 
116031 Index *pJ = pTabItem->pTab->pIndex;
116032 iIndexCur = iIdxCur;
116033 assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
116034 while( ALWAYS(pJ) && pJ!=pIx ){
116035 iIndexCur++;
@@ -116043,13 +116118,15 @@
116043 iIndexCur = pParse->nTab++;
116044 }
116045 pLevel->iIdxCur = iIndexCur;
116046 assert( pIx->pSchema==pTab->pSchema );
116047 assert( iIndexCur>=0 );
116048 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
116049 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
116050 VdbeComment((v, "%s", pIx->zName));
 
 
116051 }
116052 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
116053 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
116054 }
116055 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
@@ -127015,11 +127092,13 @@
127015 /* Fill in the abNotindexed array */
127016 for(iCol=0; iCol<nCol; iCol++){
127017 int n = (int)strlen(p->azColumn[iCol]);
127018 for(i=0; i<nNotindexed; i++){
127019 char *zNot = azNotindexed[i];
127020 if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
 
 
127021 p->abNotindexed[iCol] = 1;
127022 sqlite3_free(zNot);
127023 azNotindexed[i] = 0;
127024 }
127025 }
@@ -132492,11 +132571,11 @@
132492 if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
132493 *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
132494 return rc;
132495 }else if( *zInput==')' ){
132496 pParse->nNest--;
132497 *pnConsumed = (zInput - z) + 1;
132498 *ppExpr = 0;
132499 return SQLITE_DONE;
132500 }
132501 }
132502
@@ -138568,11 +138647,11 @@
138568 ** such segments are smaller than nLimit bytes in size, they will be
138569 ** promoted to level iAbsLevel. */
138570 sqlite3_bind_int64(pRange, 1, iAbsLevel+1);
138571 sqlite3_bind_int64(pRange, 2, iLast);
138572 while( SQLITE_ROW==sqlite3_step(pRange) ){
138573 i64 nSize, dummy;
138574 fts3ReadEndBlockField(pRange, 2, &dummy, &nSize);
138575 if( nSize<=0 || nSize>nLimit ){
138576 /* If nSize==0, then the %_segdir.end_block field does not not
138577 ** contain a size value. This happens if it was written by an
138578 ** old version of FTS. In this case it is not possible to determine
@@ -140373,11 +140452,11 @@
140373
140374 if( rc==SQLITE_OK ){
140375 rc = fts3IncrmergeOutputIdx(p, iAbsLevel, &iIdx);
140376 assert( bUseHint==1 || bUseHint==0 );
140377 if( iIdx==0 || (bUseHint && iIdx==1) ){
140378 int bIgnore;
140379 rc = fts3SegmentIsMaxLevel(p, iAbsLevel+1, &bIgnore);
140380 if( bIgnore ){
140381 pFilter->flags |= FTS3_SEGMENT_IGNORE_EMPTY;
140382 }
140383 }
140384
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223 ** [sqlite_version()] and [sqlite_source_id()].
224 */
225 #define SQLITE_VERSION "3.8.5"
226 #define SQLITE_VERSION_NUMBER 3008005
227 #define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
228
229 /*
230 ** CAPI3REF: Run-Time Library Version Numbers
231 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
232 **
@@ -11141,11 +11141,11 @@
11141 int tnum; /* DB Page containing root of this index */
11142 LogEst szIdxRow; /* Estimated average row size in bytes */
11143 u16 nKeyCol; /* Number of columns forming the key */
11144 u16 nColumn; /* Number of columns stored in the index */
11145 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
11146 unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
11147 unsigned bUnordered:1; /* Use this index for == or IN queries only */
11148 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
11149 unsigned isResized:1; /* True if resizeIndexObject() has been called */
11150 unsigned isCovering:1; /* True if this is a covering index */
11151 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -11154,10 +11154,20 @@
11154 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11155 IndexSample *aSample; /* Samples of the left-most key */
11156 #endif
11157 };
11158
11159 /*
11160 ** Allowed values for Index.idxType
11161 */
11162 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */
11163 #define SQLITE_IDXTYPE_UNIQUE 1 /* Implements a UNIQUE constraint */
11164 #define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */
11165
11166 /* Return true if index X is a PRIMARY KEY index */
11167 #define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY)
11168
11169 /*
11170 ** Each sample stored in the sqlite_stat3 table is represented in memory
11171 ** using a structure of this type. See documentation at the top of the
11172 ** analyze.c source file for additional information.
11173 */
@@ -34430,11 +34440,11 @@
34440 #endif
34441 if( res == 0 ){
34442 pFile->lastErrno = osGetLastError();
34443 /* No need to log a failure to lock */
34444 }
34445 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
34446 return res;
34447 }
34448
34449 /*
34450 ** Undo a readlock
@@ -34454,11 +34464,11 @@
34464 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
34465 pFile->lastErrno = lastErrno;
34466 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
34467 "winUnlockReadLock", pFile->zPath);
34468 }
34469 OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
34470 return res;
34471 }
34472
34473 /*
34474 ** Lock the file with the lock specified by parameter locktype - one
@@ -34529,12 +34539,12 @@
34539 ** around problems caused by indexing and/or anti-virus software on
34540 ** Windows systems.
34541 ** If you are using this code as a model for alternative VFSes, do not
34542 ** copy this retry logic. It is a hack intended for Windows only.
34543 */
34544 OSTRACE(("LOCK-PENDING-FAIL file=%p, count=%d, result=%d\n",
34545 pFile->h, cnt, res));
34546 if( cnt ) sqlite3_win32_sleep(1);
34547 }
34548 gotPendingLock = res;
34549 if( !res ){
34550 lastErrno = osGetLastError();
@@ -34615,29 +34625,29 @@
34625 ** This routine checks if there is a RESERVED lock held on the specified
34626 ** file by this or any other process. If such a lock is held, return
34627 ** non-zero, otherwise zero.
34628 */
34629 static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
34630 int res;
34631 winFile *pFile = (winFile*)id;
34632
34633 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
34634 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
34635
34636 assert( id!=0 );
34637 if( pFile->locktype>=RESERVED_LOCK ){
34638 res = 1;
34639 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
34640 }else{
34641 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE, 0, 1, 0);
34642 if( res ){
34643 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
34644 }
34645 res = !res;
34646 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
34647 }
34648 *pResOut = res;
34649 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
34650 pFile->h, pResOut, *pResOut));
34651 return SQLITE_OK;
34652 }
34653
@@ -55333,16 +55343,10 @@
55343 assert( pCur->eState==CURSOR_VALID );
55344 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55345 assert( cursorHoldsMutex(pCur) );
55346 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
55347 assert( pCur->info.nSize>0 );
 
 
 
 
 
 
55348 *pAmt = pCur->info.nLocal;
55349 return (void*)(pCur->info.pCell + pCur->info.nHeader);
55350 }
55351
55352
@@ -73737,11 +73741,11 @@
73741 #ifdef SQLITE_USE_FCNTL_TRACE
73742 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
73743 if( zTrace ){
73744 int i;
73745 for(i=0; i<db->nDb; i++){
73746 if( (MASKBIT(i) & p->btreeMask)==0 ) continue;
73747 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
73748 }
73749 }
73750 #endif /* SQLITE_USE_FCNTL_TRACE */
73751 #ifdef SQLITE_DEBUG
@@ -74692,11 +74696,10 @@
74696 nRead = (int)(pSorter->iWriteOff - iStart);
74697 }
74698 rc = sqlite3OsRead(
74699 pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
74700 );
 
74701 }
74702
74703 if( rc==SQLITE_OK ){
74704 u64 nByte; /* Size of PMA in bytes */
74705 pIter->iEof = pSorter->iWriteOff;
@@ -83655,11 +83658,11 @@
83658 nCol = pIdx->nKeyCol;
83659 aGotoChng = sqlite3DbMallocRaw(db, sizeof(int)*(nCol+1));
83660 if( aGotoChng==0 ) continue;
83661
83662 /* Populate the register containing the index name. */
83663 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
83664 zIdxName = pTab->zName;
83665 }else{
83666 zIdxName = pIdx->zName;
83667 }
83668 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
@@ -86022,11 +86025,11 @@
86025 /*
86026 ** Return the PRIMARY KEY index of a table
86027 */
86028 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table *pTab){
86029 Index *p;
86030 for(p=pTab->pIndex; p && !IsPrimaryKeyIndex(p); p=p->pNext){}
86031 return p;
86032 }
86033
86034 /*
86035 ** Return the column of index pIdx that corresponds to table
@@ -86551,11 +86554,11 @@
86554 Index *p;
86555 if( v ) pParse->addrSkipPK = sqlite3VdbeAddOp0(v, OP_Noop);
86556 p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
86557 0, sortOrder, 0);
86558 if( p ){
86559 p->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
86560 if( v ) sqlite3VdbeJumpHere(v, pParse->addrSkipPK);
86561 }
86562 pList = 0;
86563 }
86564
@@ -86926,11 +86929,11 @@
86929 pTab->aCol[pTab->iPKey].zName);
86930 pList->a[0].sortOrder = pParse->iPkSortOrder;
86931 assert( pParse->pNewTable==pTab );
86932 pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
86933 if( pPk==0 ) return;
86934 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
86935 pTab->iPKey = -1;
86936 }else{
86937 pPk = sqlite3PrimaryKeyIndex(pTab);
86938 }
86939 pPk->isCovering = 1;
@@ -86949,11 +86952,11 @@
86952 /* Update the in-memory representation of all UNIQUE indices by converting
86953 ** the final rowid column into one or more columns of the PRIMARY KEY.
86954 */
86955 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
86956 int n;
86957 if( IsPrimaryKeyIndex(pIdx) ) continue;
86958 for(i=n=0; i<nPk; i++){
86959 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
86960 }
86961 if( n==0 ){
86962 /* This index is a superset of the primary key */
@@ -88029,11 +88032,11 @@
88032 ** is a primary key or unique-constraint on the most recent column added
88033 ** to the table currently under construction.
88034 **
88035 ** If the index is created successfully, return a pointer to the new Index
88036 ** structure. This is used by sqlite3AddPrimaryKey() to mark the index
88037 ** as the tables primary key (Index.idxType==SQLITE_IDXTYPE_PRIMARYKEY)
88038 */
88039 SQLITE_PRIVATE Index *sqlite3CreateIndex(
88040 Parse *pParse, /* All information about this parse */
88041 Token *pName1, /* First part of index name. May be NULL */
88042 Token *pName2, /* Second part of index name. May be NULL */
@@ -88244,11 +88247,11 @@
88247 zExtra += nName + 1;
88248 memcpy(pIndex->zName, zName, nName+1);
88249 pIndex->pTable = pTab;
88250 pIndex->onError = (u8)onError;
88251 pIndex->uniqNotNull = onError!=OE_None;
88252 pIndex->idxType = pName ? SQLITE_IDXTYPE_APPDEF : SQLITE_IDXTYPE_UNIQUE;
88253 pIndex->pSchema = db->aDb[iDb].pSchema;
88254 pIndex->nKeyCol = pList->nExpr;
88255 if( pPIWhere ){
88256 sqlite3ResolveSelfReference(pParse, pTab, NC_PartIdx, pPIWhere, 0);
88257 pIndex->pPartIdxWhere = pPIWhere;
@@ -88356,11 +88359,11 @@
88359 */
88360 Index *pIdx;
88361 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
88362 int k;
88363 assert( pIdx->onError!=OE_None );
88364 assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
88365 assert( pIndex->onError!=OE_None );
88366
88367 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
88368 for(k=0; k<pIdx->nKeyCol; k++){
88369 const char *z1;
@@ -88579,11 +88582,11 @@
88582 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
88583 }
88584 pParse->checkSchema = 1;
88585 goto exit_drop_index;
88586 }
88587 if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
88588 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
88589 "or PRIMARY KEY constraint cannot be dropped", 0);
88590 goto exit_drop_index;
88591 }
88592 iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
@@ -89238,11 +89241,12 @@
89241 sqlite3StrAccumAppend(&errMsg, ".", 1);
89242 sqlite3StrAccumAppendAll(&errMsg, zCol);
89243 }
89244 zErr = sqlite3StrAccumFinish(&errMsg);
89245 sqlite3HaltConstraint(pParse,
89246 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
89247 : SQLITE_CONSTRAINT_UNIQUE,
89248 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
89249 }
89250
89251
89252 /*
@@ -92816,12 +92820,12 @@
92820 ** column of pFKey, then this index is a winner. */
92821
92822 if( zKey==0 ){
92823 /* If zKey is NULL, then this foreign key is implicitly mapped to
92824 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
92825 ** identified by the test. */
92826 if( IsPrimaryKeyIndex(pIdx) ){
92827 if( aiCol ){
92828 int i;
92829 for(i=0; i<nCol; i++) aiCol[i] = pFKey->aCol[i].iFrom;
92830 }
92831 break;
@@ -95411,11 +95415,11 @@
95415 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
95416 ** of the matched index row are different from the original PRIMARY
95417 ** KEY values of this row before the update. */
95418 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
95419 int op = OP_Ne;
95420 int regCmp = (IsPrimaryKeyIndex(pIdx) ? regIdx : regR);
95421
95422 for(i=0; i<pPk->nKeyCol; i++){
95423 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
95424 x = pPk->aiColumn[i];
95425 if( i==(pPk->nKeyCol-1) ){
@@ -95512,11 +95516,11 @@
95516 VdbeCoverage(v);
95517 }
95518 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
95519 pik_flags = 0;
95520 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
95521 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
95522 assert( pParse->nested==0 );
95523 pik_flags |= OPFLAG_NCHANGE;
95524 }
95525 if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
95526 }
@@ -95598,11 +95602,11 @@
95602 }
95603 if( piIdxCur ) *piIdxCur = iBase;
95604 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
95605 int iIdxCur = iBase++;
95606 assert( pIdx->pSchema==pTab->pSchema );
95607 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) && piDataCur ){
95608 *piDataCur = iIdxCur;
95609 }
95610 if( aToOpen==0 || aToOpen[i+1] ){
95611 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
95612 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
@@ -105060,11 +105064,11 @@
105064 Parse *pParse, /* Parse context */
105065 Table *pTab, /* Table being queried */
105066 Index *pIdx /* Index used to optimize scan, or NULL */
105067 ){
105068 if( pParse->explain==2 ){
105069 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
105070 char *zEqp = sqlite3MPrintf(pParse->db, "SCAN TABLE %s%s%s",
105071 pTab->zName,
105072 bCover ? " USING COVERING INDEX " : "",
105073 bCover ? pIdx->zName : ""
105074 );
@@ -107488,11 +107492,11 @@
107492 */
107493 pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++;
107494 iIdxCur = iDataCur+1;
107495 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
107496 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
107497 if( IsPrimaryKeyIndex(pIdx) && pPk!=0 ){
107498 iDataCur = pParse->nTab;
107499 pTabList->a[0].iCursor = iDataCur;
107500 }
107501 pParse->nTab++;
107502 }
@@ -112732,11 +112736,11 @@
112736 ){
112737 const char *zFmt;
112738 Index *pIdx = pLoop->u.btree.pIndex;
112739 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
112740 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
112741 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
112742 zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
112743 }else if( flags & WHERE_AUTO_INDEX ){
112744 zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
112745 }else if( flags & WHERE_IDX_ONLY ){
112746 zFmt = "%s USING COVERING INDEX %s%s";
@@ -113233,11 +113237,11 @@
113237 }else if( HasRowid(pIdx->pTable) ){
113238 iRowidReg = ++pParse->nMem;
113239 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
113240 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
113241 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
113242 }else if( iCur!=iIdxCur ){
113243 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
113244 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
113245 for(j=0; j<pPk->nKeyCol; j++){
113246 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
113247 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
@@ -113303,10 +113307,14 @@
113307 **
113308 ** Return 2 # Jump back to the Gosub
113309 **
113310 ** B: <after the loop>
113311 **
113312 ** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
113313 ** use an ephermeral index instead of a RowSet to record the primary
113314 ** keys of the rows we have already seen.
113315 **
113316 */
113317 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
113318 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
113319 Index *pCov = 0; /* Potential covering index (or NULL) */
113320 int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
@@ -113317,10 +113325,11 @@
113325 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
113326 int iRetInit; /* Address of regReturn init */
113327 int untestedTerms = 0; /* Some terms not completely tested */
113328 int ii; /* Loop counter */
113329 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
113330 Table *pTab = pTabItem->pTab;
113331
113332 pTerm = pLoop->aLTerm[0];
113333 assert( pTerm!=0 );
113334 assert( pTerm->eOperator & WO_OR );
113335 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
@@ -113349,11 +113358,12 @@
113358 }else{
113359 pOrTab = pWInfo->pTabList;
113360 }
113361
113362 /* Initialize the rowset register to contain NULL. An SQL NULL is
113363 ** equivalent to an empty rowset. Or, create an ephermeral index
113364 ** capable of holding primary keys in the case of a WITHOUT ROWID.
113365 **
113366 ** Also initialize regReturn to contain the address of the instruction
113367 ** immediately following the OP_Return at the bottom of the loop. This
113368 ** is required in a few obscure LEFT JOIN cases where control jumps
113369 ** over the top of the loop into the body of it. In this case the
@@ -113360,13 +113370,20 @@
113370 ** correct response for the end-of-loop code (the OP_Return) is to
113371 ** fall through to the next instruction, just as an OP_Next does if
113372 ** called on an uninitialized cursor.
113373 */
113374 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
113375 if( HasRowid(pTab) ){
113376 regRowset = ++pParse->nMem;
113377 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
113378 }else{
113379 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
113380 regRowset = pParse->nTab++;
113381 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, regRowset, pPk->nKeyCol);
113382 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
113383 }
113384 regRowid = ++pParse->nMem;
 
113385 }
113386 iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn);
113387
113388 /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
113389 ** Then for every term xN, evaluate as the subexpression: xN AND z
@@ -113398,15 +113415,20 @@
113415 if( pAndExpr ){
113416 pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
113417 }
113418 }
113419
113420 /* Run a separate WHERE clause for each term of the OR clause. After
113421 ** eliminating duplicates from other WHERE clauses, the action for each
113422 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
113423 */
113424 for(ii=0; ii<pOrWc->nTerm; ii++){
113425 WhereTerm *pOrTerm = &pOrWc->a[ii];
113426 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
113427 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
113428 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
113429 int j1 = 0; /* Address of jump operation */
113430 if( pAndExpr && !ExprHasProperty(pOrExpr, EP_FromJoin) ){
113431 pAndExpr->pLeft = pOrExpr;
113432 pOrExpr = pAndExpr;
113433 }
113434 /* Loop through table entries that match term pOrTerm. */
@@ -113417,20 +113439,66 @@
113439 if( pSubWInfo ){
113440 WhereLoop *pSubLoop;
113441 explainOneScan(
113442 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
113443 );
113444 /* This is the sub-WHERE clause body. First skip over
113445 ** duplicate rows from prior sub-WHERE clauses, and record the
113446 ** rowid (or PRIMARY KEY) for the current row so that the same
113447 ** row will be skipped in subsequent sub-WHERE clauses.
113448 */
113449 if( (pWInfo->wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
 
113450 int r;
113451 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
113452 if( HasRowid(pTab) ){
113453 r = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, regRowid, 0);
113454 j1 = sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, 0, r,iSet);
113455 VdbeCoverage(v);
113456 }else{
113457 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
113458 int nPk = pPk->nKeyCol;
113459 int iPk;
113460
113461 /* Read the PK into an array of temp registers. */
113462 r = sqlite3GetTempRange(pParse, nPk);
113463 for(iPk=0; iPk<nPk; iPk++){
113464 int iCol = pPk->aiColumn[iPk];
113465 sqlite3ExprCodeGetColumn(pParse, pTab, iCol, iCur, r+iPk, 0);
113466 }
113467
113468 /* Check if the temp table already contains this key. If so,
113469 ** the row has already been included in the result set and
113470 ** can be ignored (by jumping past the Gosub below). Otherwise,
113471 ** insert the key into the temp table and proceed with processing
113472 ** the row.
113473 **
113474 ** Use some of the same optimizations as OP_RowSetTest: If iSet
113475 ** is zero, assume that the key cannot already be present in
113476 ** the temp table. And if iSet is -1, assume that there is no
113477 ** need to insert the key into the temp table, as it will never
113478 ** be tested for. */
113479 if( iSet ){
113480 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
113481 VdbeCoverage(v);
113482 }
113483 if( iSet>=0 ){
113484 sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
113485 sqlite3VdbeAddOp3(v, OP_IdxInsert, regRowset, regRowid, 0);
113486 if( iSet ) sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
113487 }
113488
113489 /* Release the array of temp registers */
113490 sqlite3ReleaseTempRange(pParse, r, nPk);
113491 }
113492 }
113493
113494 /* Invoke the main loop body as a subroutine */
113495 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
113496
113497 /* Jump here (skipping the main loop body subroutine) if the
113498 ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
113499 if( j1 ) sqlite3VdbeJumpHere(v, j1);
113500
113501 /* The pSubWInfo->untestedTerms flag means that this OR term
113502 ** contained one or more AND term from a notReady table. The
113503 ** terms from the notReady table could not be tested and will
113504 ** need to be tested later.
@@ -113451,10 +113519,11 @@
113519 */
113520 pSubLoop = pSubWInfo->a[0].pWLoop;
113521 assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
113522 if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0
113523 && (ii==0 || pSubLoop->u.btree.pIndex==pCov)
113524 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pSubLoop->u.btree.pIndex))
113525 ){
113526 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
113527 pCov = pSubLoop->u.btree.pIndex;
113528 }else{
113529 pCov = 0;
@@ -114776,11 +114845,10 @@
114845 if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK;
114846 pWCEnd = pWC->a + pWC->nTerm;
114847 pNew = pBuilder->pNew;
114848 memset(&sSum, 0, sizeof(sSum));
114849 pItem = pWInfo->pTabList->a + pNew->iTab;
 
114850 iCur = pItem->iCursor;
114851
114852 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
114853 if( (pTerm->eOperator & WO_OR)!=0
114854 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -116025,11 +116093,18 @@
116093 Index *pIx = pLoop->u.btree.pIndex;
116094 int iIndexCur;
116095 int op = OP_OpenRead;
116096 /* iIdxCur is always set if to a positive value if ONEPASS is possible */
116097 assert( iIdxCur!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
116098 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
116099 && (wctrlFlags & WHERE_ONETABLE_ONLY)!=0
116100 ){
116101 /* This is one term of an OR-optimization using the PRIMARY KEY of a
116102 ** WITHOUT ROWID table. No need for a separate index */
116103 iIndexCur = pLevel->iTabCur;
116104 op = 0;
116105 }else if( pWInfo->okOnePass ){
116106 Index *pJ = pTabItem->pTab->pIndex;
116107 iIndexCur = iIdxCur;
116108 assert( wctrlFlags & WHERE_ONEPASS_DESIRED );
116109 while( ALWAYS(pJ) && pJ!=pIx ){
116110 iIndexCur++;
@@ -116043,13 +116118,15 @@
116118 iIndexCur = pParse->nTab++;
116119 }
116120 pLevel->iIdxCur = iIndexCur;
116121 assert( pIx->pSchema==pTab->pSchema );
116122 assert( iIndexCur>=0 );
116123 if( op ){
116124 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
116125 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
116126 VdbeComment((v, "%s", pIx->zName));
116127 }
116128 }
116129 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
116130 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
116131 }
116132 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
@@ -127015,11 +127092,13 @@
127092 /* Fill in the abNotindexed array */
127093 for(iCol=0; iCol<nCol; iCol++){
127094 int n = (int)strlen(p->azColumn[iCol]);
127095 for(i=0; i<nNotindexed; i++){
127096 char *zNot = azNotindexed[i];
127097 if( zNot && n==(int)strlen(zNot)
127098 && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n)
127099 ){
127100 p->abNotindexed[iCol] = 1;
127101 sqlite3_free(zNot);
127102 azNotindexed[i] = 0;
127103 }
127104 }
@@ -132492,11 +132571,11 @@
132571 if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
132572 *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
132573 return rc;
132574 }else if( *zInput==')' ){
132575 pParse->nNest--;
132576 *pnConsumed = (int)((zInput - z) + 1);
132577 *ppExpr = 0;
132578 return SQLITE_DONE;
132579 }
132580 }
132581
@@ -138568,11 +138647,11 @@
138647 ** such segments are smaller than nLimit bytes in size, they will be
138648 ** promoted to level iAbsLevel. */
138649 sqlite3_bind_int64(pRange, 1, iAbsLevel+1);
138650 sqlite3_bind_int64(pRange, 2, iLast);
138651 while( SQLITE_ROW==sqlite3_step(pRange) ){
138652 i64 nSize = 0, dummy;
138653 fts3ReadEndBlockField(pRange, 2, &dummy, &nSize);
138654 if( nSize<=0 || nSize>nLimit ){
138655 /* If nSize==0, then the %_segdir.end_block field does not not
138656 ** contain a size value. This happens if it was written by an
138657 ** old version of FTS. In this case it is not possible to determine
@@ -140373,11 +140452,11 @@
140452
140453 if( rc==SQLITE_OK ){
140454 rc = fts3IncrmergeOutputIdx(p, iAbsLevel, &iIdx);
140455 assert( bUseHint==1 || bUseHint==0 );
140456 if( iIdx==0 || (bUseHint && iIdx==1) ){
140457 int bIgnore = 0;
140458 rc = fts3SegmentIsMaxLevel(p, iAbsLevel+1, &bIgnore);
140459 if( bIgnore ){
140460 pFilter->flags |= FTS3_SEGMENT_IGNORE_EMPTY;
140461 }
140462 }
140463
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.5"
111111
#define SQLITE_VERSION_NUMBER 3008005
112
-#define SQLITE_SOURCE_ID "2014-05-24 17:15:15 ebfb51fe40756713d269b4c0ade752666910bb6e"
112
+#define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.5"
111 #define SQLITE_VERSION_NUMBER 3008005
112 #define SQLITE_SOURCE_ID "2014-05-24 17:15:15 ebfb51fe40756713d269b4c0ade752666910bb6e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.5"
111 #define SQLITE_VERSION_NUMBER 3008005
112 #define SQLITE_SOURCE_ID "2014-05-28 20:22:28 d018a34a05cec6adda61ed225d084c587343f2a6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

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