When tokendata=1 queries require multiple segment-cursors, allow those cursors to share a single array of in-memory tombstone pages.

FossilOrigin-Name: e0175d07e4094db5ea4b0378a5ff480dafb6ba9da86a113fa767c4c89c3c866f
This commit is contained in:
dan 2023-12-02 18:14:07 +00:00
parent c44041e03b
commit 94c521295a
3 changed files with 56 additions and 23 deletions

View File

@ -324,6 +324,7 @@ typedef struct Fts5Structure Fts5Structure;
typedef struct Fts5StructureLevel Fts5StructureLevel;
typedef struct Fts5StructureSegment Fts5StructureSegment;
typedef struct Fts5TokenDataIter Fts5TokenDataIter;
typedef struct Fts5TombstoneArray Fts5TombstoneArray;
struct Fts5Data {
u8 *p; /* Pointer to buffer containing record */
@ -520,8 +521,7 @@ struct Fts5SegIter {
Fts5Data *pLeaf; /* Current leaf data */
Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
i64 iLeafOffset; /* Byte offset within current leaf */
Fts5Data **apTombstone; /* Array of tombstone pages */
int nTombstone;
Fts5TombstoneArray *pTombArray; /* Array of tombstone pages */
/* Next method */
void (*xNext)(Fts5Index*, Fts5SegIter*, int*);
@ -548,6 +548,12 @@ struct Fts5SegIter {
u8 bDel; /* True if the delete flag is set */
};
struct Fts5TombstoneArray {
int nRef; /* Number of pointers to this object */
int nTombstone;
Fts5Data *apTombstone[1]; /* Array of tombstone pages */
};
/*
** Argument is a pointer to an Fts5Data structure that contains a
** leaf page.
@ -1924,11 +1930,13 @@ static void fts5SegIterSetNext(Fts5Index *p, Fts5SegIter *pIter){
static void fts5SegIterAllocTombstone(Fts5Index *p, Fts5SegIter *pIter){
const int nTomb = pIter->pSeg->nPgTombstone;
if( nTomb>0 ){
Fts5Data **apTomb = 0;
apTomb = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data)*nTomb);
if( apTomb ){
pIter->apTombstone = apTomb;
pIter->nTombstone = nTomb;
int nByte = nTomb * sizeof(Fts5Data*) + sizeof(Fts5TombstoneArray);
Fts5TombstoneArray *pNew;
pNew = (Fts5TombstoneArray*)sqlite3Fts5MallocZero(&p->rc, nByte);
if( pNew ){
pNew->nTombstone = nTomb;
pNew->nRef = 1;
pIter->pTombArray = pNew;
}
}
}
@ -2677,7 +2685,9 @@ static void fts5SegIterSeekInit(
}
fts5SegIterSetNext(p, pIter);
fts5SegIterAllocTombstone(p, pIter);
if( 0==(flags & FTS5INDEX_QUERY_SCANONETERM) ){
fts5SegIterAllocTombstone(p, pIter);
}
/* Either:
**
@ -2852,6 +2862,19 @@ static void fts5IndexFreeArray(Fts5Data **ap, int n){
}
}
static void fts5TombstoneArrayDelete(Fts5TombstoneArray *p){
if( p ){
p->nRef--;
if( p->nRef<=0 ){
int ii;
for(ii=0; ii<p->nTombstone; ii++){
fts5DataRelease(p->apTombstone[ii]);
}
sqlite3_free(p);
}
}
}
/*
** Zero the iterator passed as the only argument.
*/
@ -2859,7 +2882,7 @@ static void fts5SegIterClear(Fts5SegIter *pIter){
fts5BufferFree(&pIter->term);
fts5DataRelease(pIter->pLeaf);
fts5DataRelease(pIter->pNextLeaf);
fts5IndexFreeArray(pIter->apTombstone, pIter->nTombstone);
fts5TombstoneArrayDelete(pIter->pTombArray);
fts5DlidxIterFree(pIter->pDlidx);
sqlite3_free(pIter->aRowidOffset);
memset(pIter, 0, sizeof(Fts5SegIter));
@ -3248,24 +3271,25 @@ static int fts5IndexTombstoneQuery(
static int fts5MultiIterIsDeleted(Fts5Iter *pIter){
int iFirst = pIter->aFirst[1].iFirst;
Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
Fts5TombstoneArray *pArray = pSeg->pTombArray;
if( pSeg->pLeaf && pSeg->nTombstone ){
if( pSeg->pLeaf && pArray ){
/* Figure out which page the rowid might be present on. */
int iPg = ((u64)pSeg->iRowid) % pSeg->nTombstone;
int iPg = ((u64)pSeg->iRowid) % pArray->nTombstone;
assert( iPg>=0 );
/* If tombstone hash page iPg has not yet been loaded from the
** database, load it now. */
if( pSeg->apTombstone[iPg]==0 ){
pSeg->apTombstone[iPg] = fts5DataRead(pIter->pIndex,
if( pArray->apTombstone[iPg]==0 ){
pArray->apTombstone[iPg] = fts5DataRead(pIter->pIndex,
FTS5_TOMBSTONE_ROWID(pSeg->pSeg->iSegid, iPg)
);
if( pSeg->apTombstone[iPg]==0 ) return 0;
if( pArray->apTombstone[iPg]==0 ) return 0;
}
return fts5IndexTombstoneQuery(
pSeg->apTombstone[iPg],
pSeg->nTombstone,
pArray->apTombstone[iPg],
pArray->nTombstone,
pSeg->iRowid
);
}
@ -6886,6 +6910,15 @@ static Fts5Iter *fts5SetupTokendataIter(
fts5SegIterSeekInit(p, bSeek.p, bSeek.n, flags, pSeg, pNewIter);
}
if( pPrevIter ){
if( pPrevIter->pTombArray ){
pNewIter->pTombArray = pPrevIter->pTombArray;
pNewIter->pTombArray->nRef++;
}
}else{
fts5SegIterAllocTombstone(p, pNewIter);
}
pNewIter++;
if( pPrevIter ) pPrevIter++;
}

View File

@ -1,5 +1,5 @@
C Ensure\sthat\stokendata=1\squeries\savoid\sloading\slarge\sdoclists\sfor\squeries\slike\s"common\sAND\suncommon",\sjust\sas\stokendata=0\squeries\sdo.
D 2023-12-02T17:32:16.568
C When\stokendata=1\squeries\srequire\smultiple\ssegment-cursors,\sallow\sthose\scursors\sto\sshare\sa\ssingle\sarray\sof\sin-memory\stombstone\spages.
D 2023-12-02T18:14:07.393
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -96,7 +96,7 @@ F ext/fts5/fts5_buffer.c 3001fbabb585d6de52947b44b455235072b741038391f830d6b7292
F ext/fts5/fts5_config.c 8072a207034b51ae9b7694121d1b5715c794e94b275e088f70ae532378ca5cdf
F ext/fts5/fts5_expr.c f83259b52b7b3e76768b835fe155cb7e345affdfafb96574372b4127d5f5496a
F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1
F ext/fts5/fts5_index.c a02b6ff2d391dd9c2119f437eba1e8af5ac4b2f1798c7c39a93d73de95ad2337
F ext/fts5/fts5_index.c 21f8f449666ac44c12d5051e153ad84a886a729cb2f5d6ad02a113095c3f8ec6
F ext/fts5/fts5_main.c 075995302198fe6f591fdbbedd415dfac564a9bfc20aea81e6fa0503b2d94af0
F ext/fts5/fts5_storage.c 5d10b9bdcce5b90656cad13c7d12ad4148677d4b9e3fca0481fca56d6601426d
F ext/fts5/fts5_tcl.c cf0fd0dbe64ec272491b749e0d594f563cda03336aeb60900129e6d18b0aefb8
@ -2149,8 +2149,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P b0a489e8e1bf0290c2117ab32d78b1cc7d67bcb226b55ec044c8367ebde3815b
R aa740197e8da931b3ffaf4ddf853a1ed
P 7bda09ab404a110d57449e149a3281fca8dc4cacf7bd9832ea2a1356ad20fe8e
R 1ce6343b4aa590c869e9b9aa51095415
U dan
Z 62655ccf950056e7477fcaff4611778d
Z 8664660cde606ab1a6fdc20b18622c4a
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
7bda09ab404a110d57449e149a3281fca8dc4cacf7bd9832ea2a1356ad20fe8e
e0175d07e4094db5ea4b0378a5ff480dafb6ba9da86a113fa767c4c89c3c866f