diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index faf497d9a0..5aba849137 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -3321,6 +3321,25 @@ int sqlite3Fts3ExprLoadFtDoclist( return rc; } + +/* +** When called, *ppPoslist must point to the byte immediately following the +** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function +** moves *ppPoslist so that it instead points to the first byte of the +** position list. +*/ +static void fts3ReversePoslist(char *pStart, char **ppPoslist){ + char *p = &(*ppPoslist)[-3]; + char c = p[1]; + while( p>=pStart && (*p & 0x80) | c ){ + c = *p--; + } + if( p>pStart ){ p = &p[2]; } + while( *p++&0x80 ); + *ppPoslist = p; +} + + /* ** After ExprLoadDoclist() (see above) has been called, this function is ** used to iterate/search through the position lists that make up the doclist @@ -3337,21 +3356,37 @@ char *sqlite3Fts3FindPositions( char *pEnd = &pExpr->aDoclist[pExpr->nDoclist]; char *pCsr; - if( pExpr->pCurrent==0 || pCursor->desc ){ - pExpr->pCurrent = pExpr->aDoclist; - pExpr->iCurrent = 0; - pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent); + if( pExpr->pCurrent==0 ){ + if( pCursor->desc==0 ){ + pExpr->pCurrent = pExpr->aDoclist; + pExpr->iCurrent = 0; + fts3GetDeltaVarint(&pExpr->pCurrent, &pExpr->iCurrent); + }else{ + pCsr = pExpr->aDoclist; + while( pCsriCurrent); + fts3PoslistCopy(0, &pCsr); + } + fts3ReversePoslist(pExpr->aDoclist, &pCsr); + pExpr->pCurrent = pCsr; + } } pCsr = pExpr->pCurrent; assert( pCsr ); - while( pCsriCurrentdesc==0 && pCsrdesc && pCsr>pExpr->aDoclist) + ){ + if( pCursor->desc==0 && pExpr->iCurrentiCurrent); } pExpr->pCurrent = pCsr; + }else if( pCursor->desc && pExpr->iCurrent>iDocid ){ + fts3GetReverseDeltaVarint(&pCsr, pExpr->aDoclist, &pExpr->iCurrent); + fts3ReversePoslist(pExpr->aDoclist, &pCsr); + pExpr->pCurrent = pCsr; }else{ if( pExpr->iCurrent==iDocid ){ int iThis = 0; diff --git a/manifest b/manifest index fde6974ea3..6850c6a534 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Optimize\s"ORDER\sBY\srowid/docid\sDESC/ASC"\sclauses\son\sFTS\stables. -D 2011-05-04T12:52:59.896 +C Fix\sa\sperformance\sproblem\sin\squeries\sthat\suse\s"ORDER\sBY\srowid\sDESC"\sand\sone\sor\smore\sFTS\sauxiliary\sfunctions. +D 2011-05-04T15:41:18.367 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -61,7 +61,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 47e4f4da599e0ccd7b7fea08aaf2c77544e278e3 +F ext/fts3/fts3.c 18bf7e4eca7dcea86300ee4ead2427067c3b04c3 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 8c2ac39ee17362571c58ab2c4f0667324c31f738 F ext/fts3/fts3_aux.c 9e931f55eed8498dafe7bc1160f10cbb1a652fdf @@ -475,7 +475,7 @@ F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2 F test/fts3rnd.test 2b1a579be557ab8ac54a51b39caa4aa8043cc4ad F test/fts3shared.test 8bb266521d7c5495c0ae522bb4d376ad5387d4a2 F test/fts3snippet.test a12f22a3ba4dd59751a57c79b031d07ab5f51ddd -F test/fts3sort.test b33d4650e8d4bff2dc00d14359a29cd1c25769f8 +F test/fts3sort.test e6f24e9cffc46484bcc9fe63d3c2ce41afcaa6c9 F test/fts4aa.test eadf85621c0a113d4c7ad3ccbf8441130e007b8f F test/func.test 6c5ce11e3a0021ca3c0649234e2d4454c89110ca F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f @@ -933,7 +933,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 822ab52f1023b1c4973c806cc75454acd4e95fd0 -R bb599d547c2452f152daafa893566415 +P 13395121e3d17ab6581dc5f6736ea324321a374c +R b72c70132342e56f35c0ae4fa3c076bd U dan -Z 8f8ca68f3fd8a51bab340e5fb86e9e14 +Z f70b0240fad2f490b24e91d4b974b53a diff --git a/manifest.uuid b/manifest.uuid index 12102a8f27..ce4b5a06e5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -13395121e3d17ab6581dc5f6736ea324321a374c \ No newline at end of file +95e09b20e9aad28f829c8950f3632debe473070a \ No newline at end of file diff --git a/test/fts3sort.test b/test/fts3sort.test index 3f833a65cb..001bef1135 100644 --- a/test/fts3sort.test +++ b/test/fts3sort.test @@ -58,6 +58,7 @@ foreach {tn query} { 7 "SELECT docid, * FROM t1 WHERE t1 MATCH 'aa OR da'" 8 "SELECT docid, * FROM t1 WHERE t1 MATCH 'nosuchtoken'" 9 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR da'" + 10 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR nosuchtoken'" } { unset -nocomplain A B C D