Improve the performance of docid merges in fts5.

FossilOrigin-Name: b2de77a01cc5edcea2f98f7916e64cb33e6bd414
This commit is contained in:
dan 2015-07-09 20:46:35 +00:00
parent 3dbd2397f4
commit d2454f47e7
5 changed files with 57 additions and 35 deletions

View File

@ -38,6 +38,12 @@ typedef sqlite3_uint64 u64;
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
/*
** Constants for the largest and smallest possible 64-bit signed integers.
*/
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
#endif

View File

@ -514,6 +514,8 @@ struct Fts5IndexIter {
int bRev; /* True to iterate in reverse order */
int bSkipEmpty; /* True to skip deleted entries */
int bEof; /* True at EOF */
i64 iSwitchRowid; /* Firstest rowid of other than aFirst[1] */
Fts5CResult *aFirst; /* Current merge state (see above) */
Fts5SegIter aSeg[1]; /* Array of segment iterators */
};
@ -2499,9 +2501,21 @@ static void fts5AssertComparisonResult(
*/
static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5IndexIter *pIter){
if( p->rc==SQLITE_OK ){
Fts5SegIter *pFirst = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
int i;
assert( (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->bEof );
assert( (pFirst->pLeaf==0)==pIter->bEof );
/* Check that pIter->iSwitchRowid is set correctly. */
for(i=0; i<pIter->nSeg; i++){
Fts5SegIter *p1 = &pIter->aSeg[i];
assert( p1==pFirst
|| p1->pLeaf==0
|| fts5BufferCompare(&pFirst->term, &p1->term)
|| p1->iRowid==pIter->iSwitchRowid
|| (p1->iRowid<pIter->iSwitchRowid)==pIter->bRev
);
}
for(i=0; i<pIter->nSeg; i+=2){
Fts5SegIter *p1 = &pIter->aSeg[i];
@ -2719,27 +2733,35 @@ static int fts5MultiIterAdvanceRowid(
Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */
int iChanged /* Index of sub-iterator just advanced */
){
int i;
Fts5SegIter *pNew = &pIter->aSeg[iChanged];
Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
Fts5CResult *pRes = &pIter->aFirst[i];
if( pNew->iRowid==pIter->iSwitchRowid
|| (pNew->iRowid<pIter->iSwitchRowid)==pIter->bRev
){
int i;
Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
pIter->iSwitchRowid = pIter->bRev ? SMALLEST_INT64 : LARGEST_INT64;
for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
Fts5CResult *pRes = &pIter->aFirst[i];
assert( pNew->pLeaf );
assert( pRes->bTermEq==0 || pOther->pLeaf );
if( pRes->bTermEq ){
if( pNew->iRowid==pOther->iRowid ){
return 1;
}else if( (pOther->iRowid>pNew->iRowid)==pIter->bRev ){
pNew = pOther;
assert( pNew->pLeaf );
assert( pRes->bTermEq==0 || pOther->pLeaf );
if( pRes->bTermEq ){
if( pNew->iRowid==pOther->iRowid ){
return 1;
}else if( (pOther->iRowid>pNew->iRowid)==pIter->bRev ){
pIter->iSwitchRowid = pOther->iRowid;
pNew = pOther;
}else if( (pOther->iRowid>pIter->iSwitchRowid)==pIter->bRev ){
pIter->iSwitchRowid = pOther->iRowid;
}
}
}
pRes->iFirst = (pNew - pIter->aSeg);
if( i==1 ) break;
pRes->iFirst = (pNew - pIter->aSeg);
if( i==1 ) break;
pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
}
}
return 0;
@ -2749,7 +2771,9 @@ static int fts5MultiIterAdvanceRowid(
** Set the pIter->bEof variable based on the state of the sub-iterators.
*/
static void fts5MultiIterSetEof(Fts5IndexIter *pIter){
pIter->bEof = pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0;
Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
pIter->bEof = pSeg->pLeaf==0;
pIter->iSwitchRowid = pSeg->iRowid;
}
/*

View File

@ -227,14 +227,6 @@ struct Fts5Cursor {
#define BitFlagAllTest(x,y) (((x) & (y))==(y))
#define BitFlagTest(x,y) (((x) & (y))!=0)
/*
** Constants for the largest and smallest possible 64-bit signed integers.
** These are copied from sqliteInt.h.
*/
#ifndef SQLITE_AMALGAMATION
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
#endif
/*
** Macros to Set(), Clear() and Test() cursor flags.

View File

@ -1,5 +1,5 @@
C Reduce\sthe\snumber\sof\scalls\sto\smalloc()\smade\sby\sfts5.
D 2015-07-09T19:02:19.523
C Improve\sthe\sperformance\sof\sdocid\smerges\sin\sfts5.
D 2015-07-09T20:46:35.829
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 017bf0511d1b2dd1db5e16488fbf75a17b526cbc
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -106,14 +106,14 @@ F ext/fts3/unicode/mkunicode.tcl 95cf7ec186e48d4985e433ff8a1c89090a774252
F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95
F ext/fts5/extract_api_docs.tcl 55a6d648d516f35d9a1e580ac00de27154e1904a
F ext/fts5/fts5.h 81d1a92fc2b4bd477af7e4e0b38b456f3e199fba
F ext/fts5/fts5Int.h 582eb73064b5a2837d44e72907f84f94e86a2f79
F ext/fts5/fts5Int.h 8d9bce1847a10df2e4ed9492ea4f3868276748fb
F ext/fts5/fts5_aux.c 7cd0e2858171dacf505fea4e2e84ee6126854c3d
F ext/fts5/fts5_buffer.c 80f9ba4431848cb857e3d2158f5280093dcd8015
F ext/fts5/fts5_config.c b2456e9625bca41c51d54c363e369c6356895c90
F ext/fts5/fts5_expr.c d2e148345639c5a5583e0daa39a639bf298ae6a7
F ext/fts5/fts5_hash.c 219f4edd72e5cf95b19c33f1058809a18fad5229
F ext/fts5/fts5_index.c ba397fe86f0b5ffdafe8eff71d5dbc85cc1180da
F ext/fts5/fts5_main.c 37b0055cb4036c4b4bb4eb36e30ebd1c21c63939
F ext/fts5/fts5_index.c 1a1fd996dfe2d632df1dd00689553bc0d205497d
F ext/fts5/fts5_main.c 2e43726b3ef40b3d5efc0adc7c279d857b1c74fe
F ext/fts5/fts5_storage.c 4cae85b5287b159d9d98174a4e70adf872b0930a
F ext/fts5/fts5_tcl.c 85eb4e0d0fefa9420b78151496ad4599a1783e20
F ext/fts5/fts5_tokenize.c 30f97a8c74683797b4cd233790444fbefb3b0708
@ -1365,7 +1365,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 372c1db2475f367d54270d5801aff0503745bff4
R cd5eb7bfe39c7cb521d188bde2e79a4e
P 898618ccf61d3ad166d9fc742e132d518338b5c3
R 67cbb00207cd0d10d2422bd26a9385a8
U dan
Z 5190374d0e2aa885aa84b71a9146c526
Z ab9be791b136092de6b55e47372c8b3c

View File

@ -1 +1 @@
898618ccf61d3ad166d9fc742e132d518338b5c3
b2de77a01cc5edcea2f98f7916e64cb33e6bd414