Fossil SCM

Update the built-in SQLite to the third 3.8.9 beta.

drh 2015-04-06 11:48 UTC trunk
Commit 93e943d56ad6a710310e24dfa170fa6eb73d117d
2 files changed +76 -11 +1 -1
+76 -11
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -317,11 +317,11 @@
317317
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318318
** [sqlite_version()] and [sqlite_source_id()].
319319
*/
320320
#define SQLITE_VERSION "3.8.9"
321321
#define SQLITE_VERSION_NUMBER 3008009
322
-#define SQLITE_SOURCE_ID "2015-04-03 20:33:33 4ae9a3acc4eeeb7998769eb856c97c2233476f72"
322
+#define SQLITE_SOURCE_ID "2015-04-06 11:04:51 3ad829e50faca538db3abb2afb898b5521550c5c"
323323
324324
/*
325325
** CAPI3REF: Run-Time Library Version Numbers
326326
** KEYWORDS: sqlite3_version, sqlite3_sourceid
327327
**
@@ -12226,10 +12226,11 @@
1222612226
#define SF_AllValues 0x0100 /* All terms of compound are VALUES */
1222712227
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1222812228
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1222912229
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
1223012230
#define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12231
+#define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
1223112232
1223212233
1223312234
/*
1223412235
** The results of a SELECT can be distributed in several ways, as defined
1223512236
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -82115,10 +82116,24 @@
8211582116
sNC.pParse = pParse;
8211682117
if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
8211782118
sqlite3ResolveExprNames(&sNC, p->pOffset) ){
8211882119
return WRC_Abort;
8211982120
}
82121
+
82122
+ /* If the SF_Converted flags is set, then this Select object was
82123
+ ** was created by the convertCompoundSelectToSubquery() function.
82124
+ ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
82125
+ ** as if it were part of the sub-query, not the parent. This block
82126
+ ** moves the pOrderBy down to the sub-query. It will be moved back
82127
+ ** after the names have been resolved. */
82128
+ if( p->selFlags & SF_Converted ){
82129
+ Select *pSub = p->pSrc->a[0].pSelect;
82130
+ assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82131
+ assert( pSub->pPrior && pSub->pOrderBy==0 );
82132
+ pSub->pOrderBy = p->pOrderBy;
82133
+ p->pOrderBy = 0;
82134
+ }
8212082135
8212182136
/* Recursively resolve names in all subqueries
8212282137
*/
8212382138
for(i=0; i<p->pSrc->nSrc; i++){
8212482139
struct SrcList_item *pItem = &p->pSrc->a[i];
@@ -82196,10 +82211,21 @@
8219682211
/* The ORDER BY and GROUP BY clauses may not refer to terms in
8219782212
** outer queries
8219882213
*/
8219982214
sNC.pNext = 0;
8220082215
sNC.ncFlags |= NC_AllowAgg;
82216
+
82217
+ /* If this is a converted compound query, move the ORDER BY clause from
82218
+ ** the sub-query back to the parent query. At this point each term
82219
+ ** within the ORDER BY clause has been transformed to an integer value.
82220
+ ** These integers will be replaced by copies of the corresponding result
82221
+ ** set expressions by the call to resolveOrderGroupBy() below. */
82222
+ if( p->selFlags & SF_Converted ){
82223
+ Select *pSub = p->pSrc->a[0].pSelect;
82224
+ p->pOrderBy = pSub->pOrderBy;
82225
+ pSub->pOrderBy = 0;
82226
+ }
8220182227
8220282228
/* Process the ORDER BY clause for singleton SELECT statements.
8220382229
** The ORDER BY clause for compounds SELECT statements is handled
8220482230
** below, after all of the result-sets for all of the elements of
8220582231
** the compound have been resolved.
@@ -109909,10 +109935,12 @@
109909109935
pNew->pHaving = 0;
109910109936
pNew->pOrderBy = 0;
109911109937
p->pPrior = 0;
109912109938
p->pNext = 0;
109913109939
p->selFlags &= ~SF_Compound;
109940
+ assert( (p->selFlags & SF_Converted)==0 );
109941
+ p->selFlags |= SF_Converted;
109914109942
assert( pNew->pPrior!=0 );
109915109943
pNew->pPrior->pNext = pNew;
109916109944
pNew->pLimit = 0;
109917109945
pNew->pOffset = 0;
109918109946
return WRC_Continue;
@@ -134980,30 +135008,37 @@
134980135008
** parameter bDescDoclist should be false. If they are sorted in ascending
134981135009
** order, it should be passed a non-zero value.
134982135010
**
134983135011
** The right-hand input doclist is overwritten by this function.
134984135012
*/
134985
-static void fts3DoclistPhraseMerge(
135013
+static int fts3DoclistPhraseMerge(
134986135014
int bDescDoclist, /* True if arguments are desc */
134987135015
int nDist, /* Distance from left to right (1=adjacent) */
134988135016
char *aLeft, int nLeft, /* Left doclist */
134989
- char *aRight, int *pnRight /* IN/OUT: Right/output doclist */
135017
+ char **paRight, int *pnRight /* IN/OUT: Right/output doclist */
134990135018
){
134991135019
sqlite3_int64 i1 = 0;
134992135020
sqlite3_int64 i2 = 0;
134993135021
sqlite3_int64 iPrev = 0;
135022
+ char *aRight = *paRight;
134994135023
char *pEnd1 = &aLeft[nLeft];
134995135024
char *pEnd2 = &aRight[*pnRight];
134996135025
char *p1 = aLeft;
134997135026
char *p2 = aRight;
134998135027
char *p;
134999135028
int bFirstOut = 0;
135000
- char *aOut = aRight;
135029
+ char *aOut;
135001135030
135002135031
assert( nDist>0 );
135003
-
135032
+ if( bDescDoclist ){
135033
+ aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX);
135034
+ if( aOut==0 ) return SQLITE_NOMEM;
135035
+ }else{
135036
+ aOut = aRight;
135037
+ }
135004135038
p = aOut;
135039
+
135005135040
fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
135006135041
fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
135007135042
135008135043
while( p1 && p2 ){
135009135044
sqlite3_int64 iDiff = DOCID_CMP(i1, i2);
@@ -135028,10 +135063,16 @@
135028135063
fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
135029135064
}
135030135065
}
135031135066
135032135067
*pnRight = (int)(p - aOut);
135068
+ if( bDescDoclist ){
135069
+ sqlite3_free(aRight);
135070
+ *paRight = aOut;
135071
+ }
135072
+
135073
+ return SQLITE_OK;
135033135074
}
135034135075
135035135076
/*
135036135077
** Argument pList points to a position list nList bytes in size. This
135037135078
** function checks to see if the position list contains any entries for
@@ -135152,12 +135193,26 @@
135152135193
char *aDoclist, /* Pointer to doclist */
135153135194
int nDoclist /* Size of aDoclist in bytes */
135154135195
){
135155135196
if( pTS->aaOutput[0]==0 ){
135156135197
/* If this is the first term selected, copy the doclist to the output
135157
- ** buffer using memcpy(). */
135158
- pTS->aaOutput[0] = sqlite3_malloc(nDoclist);
135198
+ ** buffer using memcpy().
135199
+ **
135200
+ ** Add FTS3_VARINT_MAX bytes of unused space to the end of the
135201
+ ** allocation. This is so as to ensure that the buffer is big enough
135202
+ ** to hold the current doclist AND'd with any other doclist. If the
135203
+ ** doclists are stored in order=ASC order, this padding would not be
135204
+ ** required (since the size of [doclistA AND doclistB] is always less
135205
+ ** than or equal to the size of [doclistA] in that case). But this is
135206
+ ** not true for order=DESC. For example, a doclist containing (1, -1)
135207
+ ** may be smaller than (-1), as in the first example the -1 may be stored
135208
+ ** as a single-byte delta, whereas in the second it must be stored as a
135209
+ ** FTS3_VARINT_MAX byte varint.
135210
+ **
135211
+ ** Similar padding is added in the fts3DoclistOrMerge() function.
135212
+ */
135213
+ pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
135159135214
pTS->anOutput[0] = nDoclist;
135160135215
if( pTS->aaOutput[0] ){
135161135216
memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
135162135217
}else{
135163135218
return SQLITE_NOMEM;
@@ -136409,18 +136464,21 @@
136409136464
** It is merged into the main doclist stored in p->doclist.aAll/nAll.
136410136465
**
136411136466
** This function assumes that pList points to a buffer allocated using
136412136467
** sqlite3_malloc(). This function takes responsibility for eventually
136413136468
** freeing the buffer.
136469
+**
136470
+** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs.
136414136471
*/
136415
-static void fts3EvalPhraseMergeToken(
136472
+static int fts3EvalPhraseMergeToken(
136416136473
Fts3Table *pTab, /* FTS Table pointer */
136417136474
Fts3Phrase *p, /* Phrase to merge pList/nList into */
136418136475
int iToken, /* Token pList/nList corresponds to */
136419136476
char *pList, /* Pointer to doclist */
136420136477
int nList /* Number of bytes in pList */
136421136478
){
136479
+ int rc = SQLITE_OK;
136422136480
assert( iToken!=p->iDoclistToken );
136423136481
136424136482
if( pList==0 ){
136425136483
sqlite3_free(p->doclist.aAll);
136426136484
p->doclist.aAll = 0;
@@ -136455,17 +136513,20 @@
136455136513
pLeft = pList;
136456136514
nLeft = nList;
136457136515
nDiff = p->iDoclistToken - iToken;
136458136516
}
136459136517
136460
- fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight);
136518
+ rc = fts3DoclistPhraseMerge(
136519
+ pTab->bDescIdx, nDiff, pLeft, nLeft, &pRight, &nRight
136520
+ );
136461136521
sqlite3_free(pLeft);
136462136522
p->doclist.aAll = pRight;
136463136523
p->doclist.nAll = nRight;
136464136524
}
136465136525
136466136526
if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken;
136527
+ return rc;
136467136528
}
136468136529
136469136530
/*
136470136531
** Load the doclist for phrase p into p->doclist.aAll/nAll. The loaded doclist
136471136532
** does not take deferred tokens into account.
@@ -136487,11 +136548,11 @@
136487136548
if( pToken->pSegcsr ){
136488136549
int nThis = 0;
136489136550
char *pThis = 0;
136490136551
rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis);
136491136552
if( rc==SQLITE_OK ){
136492
- fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis);
136553
+ rc = fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis);
136493136554
}
136494136555
}
136495136556
assert( pToken->pSegcsr==0 );
136496136557
}
136497136558
@@ -137289,13 +137350,17 @@
137289137350
Fts3PhraseToken *pToken = pTC->pToken;
137290137351
int nList = 0;
137291137352
char *pList = 0;
137292137353
rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList);
137293137354
assert( rc==SQLITE_OK || pList==0 );
137355
+ if( rc==SQLITE_OK ){
137356
+ rc = fts3EvalPhraseMergeToken(
137357
+ pTab, pTC->pPhrase, pTC->iToken,pList,nList
137358
+ );
137359
+ }
137294137360
if( rc==SQLITE_OK ){
137295137361
int nCount;
137296
- fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList);
137297137362
nCount = fts3DoclistCountDocids(
137298137363
pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll
137299137364
);
137300137365
if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
137301137366
}
137302137367
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -317,11 +317,11 @@
317 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318 ** [sqlite_version()] and [sqlite_source_id()].
319 */
320 #define SQLITE_VERSION "3.8.9"
321 #define SQLITE_VERSION_NUMBER 3008009
322 #define SQLITE_SOURCE_ID "2015-04-03 20:33:33 4ae9a3acc4eeeb7998769eb856c97c2233476f72"
323
324 /*
325 ** CAPI3REF: Run-Time Library Version Numbers
326 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
327 **
@@ -12226,10 +12226,11 @@
12226 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12227 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12228 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12229 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12230 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
 
12231
12232
12233 /*
12234 ** The results of a SELECT can be distributed in several ways, as defined
12235 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -82115,10 +82116,24 @@
82115 sNC.pParse = pParse;
82116 if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
82117 sqlite3ResolveExprNames(&sNC, p->pOffset) ){
82118 return WRC_Abort;
82119 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82120
82121 /* Recursively resolve names in all subqueries
82122 */
82123 for(i=0; i<p->pSrc->nSrc; i++){
82124 struct SrcList_item *pItem = &p->pSrc->a[i];
@@ -82196,10 +82211,21 @@
82196 /* The ORDER BY and GROUP BY clauses may not refer to terms in
82197 ** outer queries
82198 */
82199 sNC.pNext = 0;
82200 sNC.ncFlags |= NC_AllowAgg;
 
 
 
 
 
 
 
 
 
 
 
82201
82202 /* Process the ORDER BY clause for singleton SELECT statements.
82203 ** The ORDER BY clause for compounds SELECT statements is handled
82204 ** below, after all of the result-sets for all of the elements of
82205 ** the compound have been resolved.
@@ -109909,10 +109935,12 @@
109909 pNew->pHaving = 0;
109910 pNew->pOrderBy = 0;
109911 p->pPrior = 0;
109912 p->pNext = 0;
109913 p->selFlags &= ~SF_Compound;
 
 
109914 assert( pNew->pPrior!=0 );
109915 pNew->pPrior->pNext = pNew;
109916 pNew->pLimit = 0;
109917 pNew->pOffset = 0;
109918 return WRC_Continue;
@@ -134980,30 +135008,37 @@
134980 ** parameter bDescDoclist should be false. If they are sorted in ascending
134981 ** order, it should be passed a non-zero value.
134982 **
134983 ** The right-hand input doclist is overwritten by this function.
134984 */
134985 static void fts3DoclistPhraseMerge(
134986 int bDescDoclist, /* True if arguments are desc */
134987 int nDist, /* Distance from left to right (1=adjacent) */
134988 char *aLeft, int nLeft, /* Left doclist */
134989 char *aRight, int *pnRight /* IN/OUT: Right/output doclist */
134990 ){
134991 sqlite3_int64 i1 = 0;
134992 sqlite3_int64 i2 = 0;
134993 sqlite3_int64 iPrev = 0;
 
134994 char *pEnd1 = &aLeft[nLeft];
134995 char *pEnd2 = &aRight[*pnRight];
134996 char *p1 = aLeft;
134997 char *p2 = aRight;
134998 char *p;
134999 int bFirstOut = 0;
135000 char *aOut = aRight;
135001
135002 assert( nDist>0 );
135003
 
 
 
 
 
135004 p = aOut;
 
135005 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
135006 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
135007
135008 while( p1 && p2 ){
135009 sqlite3_int64 iDiff = DOCID_CMP(i1, i2);
@@ -135028,10 +135063,16 @@
135028 fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
135029 }
135030 }
135031
135032 *pnRight = (int)(p - aOut);
 
 
 
 
 
 
135033 }
135034
135035 /*
135036 ** Argument pList points to a position list nList bytes in size. This
135037 ** function checks to see if the position list contains any entries for
@@ -135152,12 +135193,26 @@
135152 char *aDoclist, /* Pointer to doclist */
135153 int nDoclist /* Size of aDoclist in bytes */
135154 ){
135155 if( pTS->aaOutput[0]==0 ){
135156 /* If this is the first term selected, copy the doclist to the output
135157 ** buffer using memcpy(). */
135158 pTS->aaOutput[0] = sqlite3_malloc(nDoclist);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135159 pTS->anOutput[0] = nDoclist;
135160 if( pTS->aaOutput[0] ){
135161 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
135162 }else{
135163 return SQLITE_NOMEM;
@@ -136409,18 +136464,21 @@
136409 ** It is merged into the main doclist stored in p->doclist.aAll/nAll.
136410 **
136411 ** This function assumes that pList points to a buffer allocated using
136412 ** sqlite3_malloc(). This function takes responsibility for eventually
136413 ** freeing the buffer.
 
 
136414 */
136415 static void fts3EvalPhraseMergeToken(
136416 Fts3Table *pTab, /* FTS Table pointer */
136417 Fts3Phrase *p, /* Phrase to merge pList/nList into */
136418 int iToken, /* Token pList/nList corresponds to */
136419 char *pList, /* Pointer to doclist */
136420 int nList /* Number of bytes in pList */
136421 ){
 
136422 assert( iToken!=p->iDoclistToken );
136423
136424 if( pList==0 ){
136425 sqlite3_free(p->doclist.aAll);
136426 p->doclist.aAll = 0;
@@ -136455,17 +136513,20 @@
136455 pLeft = pList;
136456 nLeft = nList;
136457 nDiff = p->iDoclistToken - iToken;
136458 }
136459
136460 fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight);
 
 
136461 sqlite3_free(pLeft);
136462 p->doclist.aAll = pRight;
136463 p->doclist.nAll = nRight;
136464 }
136465
136466 if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken;
 
136467 }
136468
136469 /*
136470 ** Load the doclist for phrase p into p->doclist.aAll/nAll. The loaded doclist
136471 ** does not take deferred tokens into account.
@@ -136487,11 +136548,11 @@
136487 if( pToken->pSegcsr ){
136488 int nThis = 0;
136489 char *pThis = 0;
136490 rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis);
136491 if( rc==SQLITE_OK ){
136492 fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis);
136493 }
136494 }
136495 assert( pToken->pSegcsr==0 );
136496 }
136497
@@ -137289,13 +137350,17 @@
137289 Fts3PhraseToken *pToken = pTC->pToken;
137290 int nList = 0;
137291 char *pList = 0;
137292 rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList);
137293 assert( rc==SQLITE_OK || pList==0 );
 
 
 
 
 
137294 if( rc==SQLITE_OK ){
137295 int nCount;
137296 fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList);
137297 nCount = fts3DoclistCountDocids(
137298 pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll
137299 );
137300 if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
137301 }
137302
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -317,11 +317,11 @@
317 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
318 ** [sqlite_version()] and [sqlite_source_id()].
319 */
320 #define SQLITE_VERSION "3.8.9"
321 #define SQLITE_VERSION_NUMBER 3008009
322 #define SQLITE_SOURCE_ID "2015-04-06 11:04:51 3ad829e50faca538db3abb2afb898b5521550c5c"
323
324 /*
325 ** CAPI3REF: Run-Time Library Version Numbers
326 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
327 **
@@ -12226,10 +12226,11 @@
12226 #define SF_AllValues 0x0100 /* All terms of compound are VALUES */
12227 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
12228 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
12229 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
12230 #define SF_MinMaxAgg 0x1000 /* Aggregate containing min() or max() */
12231 #define SF_Converted 0x2000 /* By convertCompoundSelectToSubquery() */
12232
12233
12234 /*
12235 ** The results of a SELECT can be distributed in several ways, as defined
12236 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -82115,10 +82116,24 @@
82116 sNC.pParse = pParse;
82117 if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
82118 sqlite3ResolveExprNames(&sNC, p->pOffset) ){
82119 return WRC_Abort;
82120 }
82121
82122 /* If the SF_Converted flags is set, then this Select object was
82123 ** was created by the convertCompoundSelectToSubquery() function.
82124 ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
82125 ** as if it were part of the sub-query, not the parent. This block
82126 ** moves the pOrderBy down to the sub-query. It will be moved back
82127 ** after the names have been resolved. */
82128 if( p->selFlags & SF_Converted ){
82129 Select *pSub = p->pSrc->a[0].pSelect;
82130 assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
82131 assert( pSub->pPrior && pSub->pOrderBy==0 );
82132 pSub->pOrderBy = p->pOrderBy;
82133 p->pOrderBy = 0;
82134 }
82135
82136 /* Recursively resolve names in all subqueries
82137 */
82138 for(i=0; i<p->pSrc->nSrc; i++){
82139 struct SrcList_item *pItem = &p->pSrc->a[i];
@@ -82196,10 +82211,21 @@
82211 /* The ORDER BY and GROUP BY clauses may not refer to terms in
82212 ** outer queries
82213 */
82214 sNC.pNext = 0;
82215 sNC.ncFlags |= NC_AllowAgg;
82216
82217 /* If this is a converted compound query, move the ORDER BY clause from
82218 ** the sub-query back to the parent query. At this point each term
82219 ** within the ORDER BY clause has been transformed to an integer value.
82220 ** These integers will be replaced by copies of the corresponding result
82221 ** set expressions by the call to resolveOrderGroupBy() below. */
82222 if( p->selFlags & SF_Converted ){
82223 Select *pSub = p->pSrc->a[0].pSelect;
82224 p->pOrderBy = pSub->pOrderBy;
82225 pSub->pOrderBy = 0;
82226 }
82227
82228 /* Process the ORDER BY clause for singleton SELECT statements.
82229 ** The ORDER BY clause for compounds SELECT statements is handled
82230 ** below, after all of the result-sets for all of the elements of
82231 ** the compound have been resolved.
@@ -109909,10 +109935,12 @@
109935 pNew->pHaving = 0;
109936 pNew->pOrderBy = 0;
109937 p->pPrior = 0;
109938 p->pNext = 0;
109939 p->selFlags &= ~SF_Compound;
109940 assert( (p->selFlags & SF_Converted)==0 );
109941 p->selFlags |= SF_Converted;
109942 assert( pNew->pPrior!=0 );
109943 pNew->pPrior->pNext = pNew;
109944 pNew->pLimit = 0;
109945 pNew->pOffset = 0;
109946 return WRC_Continue;
@@ -134980,30 +135008,37 @@
135008 ** parameter bDescDoclist should be false. If they are sorted in ascending
135009 ** order, it should be passed a non-zero value.
135010 **
135011 ** The right-hand input doclist is overwritten by this function.
135012 */
135013 static int fts3DoclistPhraseMerge(
135014 int bDescDoclist, /* True if arguments are desc */
135015 int nDist, /* Distance from left to right (1=adjacent) */
135016 char *aLeft, int nLeft, /* Left doclist */
135017 char **paRight, int *pnRight /* IN/OUT: Right/output doclist */
135018 ){
135019 sqlite3_int64 i1 = 0;
135020 sqlite3_int64 i2 = 0;
135021 sqlite3_int64 iPrev = 0;
135022 char *aRight = *paRight;
135023 char *pEnd1 = &aLeft[nLeft];
135024 char *pEnd2 = &aRight[*pnRight];
135025 char *p1 = aLeft;
135026 char *p2 = aRight;
135027 char *p;
135028 int bFirstOut = 0;
135029 char *aOut;
135030
135031 assert( nDist>0 );
135032 if( bDescDoclist ){
135033 aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX);
135034 if( aOut==0 ) return SQLITE_NOMEM;
135035 }else{
135036 aOut = aRight;
135037 }
135038 p = aOut;
135039
135040 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
135041 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
135042
135043 while( p1 && p2 ){
135044 sqlite3_int64 iDiff = DOCID_CMP(i1, i2);
@@ -135028,10 +135063,16 @@
135063 fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
135064 }
135065 }
135066
135067 *pnRight = (int)(p - aOut);
135068 if( bDescDoclist ){
135069 sqlite3_free(aRight);
135070 *paRight = aOut;
135071 }
135072
135073 return SQLITE_OK;
135074 }
135075
135076 /*
135077 ** Argument pList points to a position list nList bytes in size. This
135078 ** function checks to see if the position list contains any entries for
@@ -135152,12 +135193,26 @@
135193 char *aDoclist, /* Pointer to doclist */
135194 int nDoclist /* Size of aDoclist in bytes */
135195 ){
135196 if( pTS->aaOutput[0]==0 ){
135197 /* If this is the first term selected, copy the doclist to the output
135198 ** buffer using memcpy().
135199 **
135200 ** Add FTS3_VARINT_MAX bytes of unused space to the end of the
135201 ** allocation. This is so as to ensure that the buffer is big enough
135202 ** to hold the current doclist AND'd with any other doclist. If the
135203 ** doclists are stored in order=ASC order, this padding would not be
135204 ** required (since the size of [doclistA AND doclistB] is always less
135205 ** than or equal to the size of [doclistA] in that case). But this is
135206 ** not true for order=DESC. For example, a doclist containing (1, -1)
135207 ** may be smaller than (-1), as in the first example the -1 may be stored
135208 ** as a single-byte delta, whereas in the second it must be stored as a
135209 ** FTS3_VARINT_MAX byte varint.
135210 **
135211 ** Similar padding is added in the fts3DoclistOrMerge() function.
135212 */
135213 pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
135214 pTS->anOutput[0] = nDoclist;
135215 if( pTS->aaOutput[0] ){
135216 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
135217 }else{
135218 return SQLITE_NOMEM;
@@ -136409,18 +136464,21 @@
136464 ** It is merged into the main doclist stored in p->doclist.aAll/nAll.
136465 **
136466 ** This function assumes that pList points to a buffer allocated using
136467 ** sqlite3_malloc(). This function takes responsibility for eventually
136468 ** freeing the buffer.
136469 **
136470 ** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs.
136471 */
136472 static int fts3EvalPhraseMergeToken(
136473 Fts3Table *pTab, /* FTS Table pointer */
136474 Fts3Phrase *p, /* Phrase to merge pList/nList into */
136475 int iToken, /* Token pList/nList corresponds to */
136476 char *pList, /* Pointer to doclist */
136477 int nList /* Number of bytes in pList */
136478 ){
136479 int rc = SQLITE_OK;
136480 assert( iToken!=p->iDoclistToken );
136481
136482 if( pList==0 ){
136483 sqlite3_free(p->doclist.aAll);
136484 p->doclist.aAll = 0;
@@ -136455,17 +136513,20 @@
136513 pLeft = pList;
136514 nLeft = nList;
136515 nDiff = p->iDoclistToken - iToken;
136516 }
136517
136518 rc = fts3DoclistPhraseMerge(
136519 pTab->bDescIdx, nDiff, pLeft, nLeft, &pRight, &nRight
136520 );
136521 sqlite3_free(pLeft);
136522 p->doclist.aAll = pRight;
136523 p->doclist.nAll = nRight;
136524 }
136525
136526 if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken;
136527 return rc;
136528 }
136529
136530 /*
136531 ** Load the doclist for phrase p into p->doclist.aAll/nAll. The loaded doclist
136532 ** does not take deferred tokens into account.
@@ -136487,11 +136548,11 @@
136548 if( pToken->pSegcsr ){
136549 int nThis = 0;
136550 char *pThis = 0;
136551 rc = fts3TermSelect(pTab, pToken, p->iColumn, &nThis, &pThis);
136552 if( rc==SQLITE_OK ){
136553 rc = fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis);
136554 }
136555 }
136556 assert( pToken->pSegcsr==0 );
136557 }
136558
@@ -137289,13 +137350,17 @@
137350 Fts3PhraseToken *pToken = pTC->pToken;
137351 int nList = 0;
137352 char *pList = 0;
137353 rc = fts3TermSelect(pTab, pToken, pTC->iCol, &nList, &pList);
137354 assert( rc==SQLITE_OK || pList==0 );
137355 if( rc==SQLITE_OK ){
137356 rc = fts3EvalPhraseMergeToken(
137357 pTab, pTC->pPhrase, pTC->iToken,pList,nList
137358 );
137359 }
137360 if( rc==SQLITE_OK ){
137361 int nCount;
 
137362 nCount = fts3DoclistCountDocids(
137363 pTC->pPhrase->doclist.aAll, pTC->pPhrase->doclist.nAll
137364 );
137365 if( ii==0 || nCount<nMinEst ) nMinEst = nCount;
137366 }
137367
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.8.9"
115115
#define SQLITE_VERSION_NUMBER 3008009
116
-#define SQLITE_SOURCE_ID "2015-04-03 20:33:33 4ae9a3acc4eeeb7998769eb856c97c2233476f72"
116
+#define SQLITE_SOURCE_ID "2015-04-06 11:04:51 3ad829e50faca538db3abb2afb898b5521550c5c"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
122122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.9"
115 #define SQLITE_VERSION_NUMBER 3008009
116 #define SQLITE_SOURCE_ID "2015-04-03 20:33:33 4ae9a3acc4eeeb7998769eb856c97c2233476f72"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.9"
115 #define SQLITE_VERSION_NUMBER 3008009
116 #define SQLITE_SOURCE_ID "2015-04-06 11:04:51 3ad829e50faca538db3abb2afb898b5521550c5c"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122

Keyboard Shortcuts

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