1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Fix a problem with prefix queries on fts5 offsets=0 tables.

FossilOrigin-Name: ad0987d83c252dd8d6a69321893629d7be805c28
This commit is contained in:
dan
2015-12-18 19:07:14 +00:00
parent b12dc84fbb
commit c58b9eeaaa
5 changed files with 41 additions and 22 deletions

View File

@ -1805,11 +1805,20 @@ Fts5ExprNode *sqlite3Fts5ParseNode(
for(iPhrase=0; iPhrase<pNear->nPhrase; iPhrase++){
pNear->apPhrase[iPhrase]->pNode = pRet;
}
if( pNear->nPhrase==1
&& pNear->apPhrase[0]->nTerm==1
&& pNear->apPhrase[0]->aTerm[0].pSynonym==0
){
pRet->eType = FTS5_TERM;
if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 ){
if( pNear->apPhrase[0]->aTerm[0].pSynonym==0 ){
pRet->eType = FTS5_TERM;
}
}else if( pParse->pConfig->bOffsets==0 ){
assert( pParse->rc==SQLITE_OK );
pParse->rc = SQLITE_ERROR;
assert( pParse->zErr==0 );
pParse->zErr = sqlite3_mprintf(
"fts5: %s queries are not supported (offsets=0)",
pNear->nPhrase==1 ? "phrase": "NEAR"
);
sqlite3_free(pRet);
pRet = 0;
}
}else{
fts5ExprAddChildren(pRet, pLeft);

View File

@ -4119,8 +4119,8 @@ static void fts5SegiterPoslist(
PoslistCallbackCtx sCtx;
sCtx.pBuf = pBuf;
sCtx.pColset = pColset;
assert( sCtx.eState==0 || sCtx.eState==1 );
sCtx.eState = fts5IndexColsetTest(pColset, 0);
assert( sCtx.eState==0 || sCtx.eState==1 );
fts5ChunkIterate(p, pSeg, (void*)&sCtx, fts5PoslistFilterCallback);
}
}
@ -4192,8 +4192,8 @@ static int fts5AppendPoslist(
assert( fts5MultiIterEof(p, pMulti)==0 );
assert( pSeg->nPos>0 );
if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+9+9) ){
if( pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf
if( p->pConfig->bOffsets
&& pSeg->iLeafOffset+pSeg->nPos<=pSeg->pLeaf->szLeaf
&& (pColset==0 || pColset->nCol==1)
){
const u8 *pPos = &pSeg->pLeaf->p[pSeg->iLeafOffset];
@ -4238,13 +4238,13 @@ static int fts5AppendPoslist(
}
}
}
}
}
return 0;
}
static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
u8 *p = pIter->aPoslist + pIter->nSize + pIter->nPoslist;
@ -4390,6 +4390,9 @@ static void fts5MergePrefixLists(
}
}
/*
** Swap the contents of buffer *p1 with that of *p2.
*/
static void fts5BufferSwap(Fts5Buffer *p1, Fts5Buffer *p2){
Fts5Buffer tmp = *p1;
*p1 = *p2;

View File

@ -22,9 +22,11 @@ ifcapable !fts5 {
}
#--------------------------------------------------------------------------
# Simple tests.
#
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, offsets=0);
INSERT INTO t1 VALUES('h d g', 'j b b g b', 'i e i d h g g'); -- 1
INSERT INTO t1 VALUES('h j d', 'j h d a h', 'f d d g g f b'); -- 2
INSERT INTO t1 VALUES('j c i', 'f f h e f', 'c j i j c h f'); -- 3
@ -55,5 +57,13 @@ foreach {tn match res} {
} $res
}
do_catchsql_test 1.3.1 {
SELECT rowid FROM t1('h + d');
} {1 {fts5: phrase queries are not supported (offsets=0)}}
do_catchsql_test 1.3.2 {
SELECT rowid FROM t1('NEAR(h d)');
} {1 {fts5: NEAR queries are not supported (offsets=0)}}
finish_test