Instead of disallowing writes to fts5 tables if there are fts5vocab cursors open on them (commit [c49a6ed7]), abort any fts5vocab queries if the on-disk structure of the fts5 table changes.

FossilOrigin-Name: 9dbdc9001e3258e71ca995fbcdebf66ab95890ded87fa7125c6cb4bd43010aaf
This commit is contained in:
dan 2021-07-07 11:51:03 +00:00
parent 9289f5103d
commit cc516af4cc
8 changed files with 65 additions and 32 deletions

View File

@ -435,6 +435,9 @@ void sqlite3Fts5IndexCloseReader(Fts5Index*);
*/ */
const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*); const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*);
int sqlite3Fts5IterNextScan(Fts5IndexIter*); int sqlite3Fts5IterNextScan(Fts5IndexIter*);
void *sqlite3Fts5StructureRef(Fts5Index*);
void sqlite3Fts5StructureRelease(void*);
int sqlite3Fts5StructureTest(Fts5Index*, void*);
/* /*
@ -564,7 +567,6 @@ int sqlite3Fts5GetTokenizer(
Fts5Table *sqlite3Fts5TableFromCsrid(Fts5Global*, i64); Fts5Table *sqlite3Fts5TableFromCsrid(Fts5Global*, i64);
int sqlite3Fts5FlushToDisk(Fts5Table*); int sqlite3Fts5FlushToDisk(Fts5Table*);
void sqlite3Fts5VocabLock(Fts5Table*, int);
/* /*
** End of interface to code in fts5.c. ** End of interface to code in fts5.c.

View File

@ -821,6 +821,22 @@ static void fts5StructureRef(Fts5Structure *pStruct){
pStruct->nRef++; pStruct->nRef++;
} }
void *sqlite3Fts5StructureRef(Fts5Index *p){
fts5StructureRef(p->pStruct);
return (void*)p->pStruct;
}
void sqlite3Fts5StructureRelease(void *p){
if( p ){
fts5StructureRelease((Fts5Structure*)p);
}
}
int sqlite3Fts5StructureTest(Fts5Index *p, void *pStruct){
if( p->pStruct!=(Fts5Structure*)pStruct ){
return SQLITE_ABORT;
}
return SQLITE_OK;
}
/* /*
** Deserialize and return the structure record currently stored in serialized ** Deserialize and return the structure record currently stored in serialized
** form within buffer pData/nData. ** form within buffer pData/nData.

View File

@ -117,7 +117,6 @@ struct Fts5FullTable {
Fts5Storage *pStorage; /* Document store */ Fts5Storage *pStorage; /* Document store */
Fts5Global *pGlobal; /* Global (connection wide) data */ Fts5Global *pGlobal; /* Global (connection wide) data */
Fts5Cursor *pSortCsr; /* Sort data from this cursor */ Fts5Cursor *pSortCsr; /* Sort data from this cursor */
int nVocabLock; /* Number of locks held by fts5vocab csrs */
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
struct Fts5TransactionState ts; struct Fts5TransactionState ts;
#endif #endif
@ -1635,9 +1634,7 @@ static int fts5UpdateMethod(
assert( pTab->p.pConfig->pzErrmsg==0 ); assert( pTab->p.pConfig->pzErrmsg==0 );
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg; pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
/* Return an error if there are any fts5vocab cursors open. Put any active /* Put any active cursors into REQUIRE_SEEK state. */
** fts5 cursors into REQUIRE_SEEK state. */
if( pTab->nVocabLock ) return SQLITE_LOCKED;
fts5TripCursors(pTab); fts5TripCursors(pTab);
eType0 = sqlite3_value_type(apVal[0]); eType0 = sqlite3_value_type(apVal[0]);
@ -2561,17 +2558,6 @@ int sqlite3Fts5FlushToDisk(Fts5Table *pTab){
return sqlite3Fts5StorageSync(((Fts5FullTable*)pTab)->pStorage); return sqlite3Fts5StorageSync(((Fts5FullTable*)pTab)->pStorage);
} }
/*
** Take (bUnlock==0) or release (bUnlock==1) a vocab lock on the table
** passed as the only argument. It is not possible to modify the
** structure of the table if there are one or more vocab locks.
*/
void sqlite3Fts5VocabLock(Fts5Table *pVtab, int bUnlock){
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
pTab->nVocabLock += (bUnlock ? -1 : +1);
assert( pTab->nVocabLock>=0 );
}
/* /*
** The xSavepoint() method. ** The xSavepoint() method.
** **

View File

@ -60,6 +60,7 @@ struct Fts5VocabCursor {
int bEof; /* True if this cursor is at EOF */ int bEof; /* True if this cursor is at EOF */
Fts5IndexIter *pIter; /* Term/rowid iterator object */ Fts5IndexIter *pIter; /* Term/rowid iterator object */
void *pStruct; /* From sqlite3Fts5StructureRef() */
int nLeTerm; /* Size of zLeTerm in bytes */ int nLeTerm; /* Size of zLeTerm in bytes */
char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */ char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */
@ -382,7 +383,6 @@ static int fts5VocabOpenMethod(
pCsr->pStmt = pStmt; pCsr->pStmt = pStmt;
pCsr->aCnt = (i64*)&pCsr[1]; pCsr->aCnt = (i64*)&pCsr[1];
pCsr->aDoc = &pCsr->aCnt[pFts5->pConfig->nCol]; pCsr->aDoc = &pCsr->aCnt[pFts5->pConfig->nCol];
sqlite3Fts5VocabLock(pFts5, 0);
}else{ }else{
sqlite3_finalize(pStmt); sqlite3_finalize(pStmt);
} }
@ -394,6 +394,8 @@ static int fts5VocabOpenMethod(
static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){ static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
pCsr->rowid = 0; pCsr->rowid = 0;
sqlite3Fts5IterClose(pCsr->pIter); sqlite3Fts5IterClose(pCsr->pIter);
sqlite3Fts5StructureRelease(pCsr->pStruct);
pCsr->pStruct = 0;
pCsr->pIter = 0; pCsr->pIter = 0;
sqlite3_free(pCsr->zLeTerm); sqlite3_free(pCsr->zLeTerm);
pCsr->nLeTerm = -1; pCsr->nLeTerm = -1;
@ -408,7 +410,6 @@ static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
static int fts5VocabCloseMethod(sqlite3_vtab_cursor *pCursor){ static int fts5VocabCloseMethod(sqlite3_vtab_cursor *pCursor){
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor; Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
fts5VocabResetCursor(pCsr); fts5VocabResetCursor(pCsr);
sqlite3Fts5VocabLock(pCsr->pFts5, 1);
sqlite3Fts5BufferFree(&pCsr->term); sqlite3Fts5BufferFree(&pCsr->term);
sqlite3_finalize(pCsr->pStmt); sqlite3_finalize(pCsr->pStmt);
sqlite3_free(pCsr); sqlite3_free(pCsr);
@ -472,9 +473,11 @@ static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){ static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor; Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab; Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
int rc = SQLITE_OK;
int nCol = pCsr->pFts5->pConfig->nCol; int nCol = pCsr->pFts5->pConfig->nCol;
int rc;
rc = sqlite3Fts5StructureTest(pCsr->pFts5->pIndex, pCsr->pStruct);
if( rc!=SQLITE_OK ) return rc;
pCsr->rowid++; pCsr->rowid++;
if( pTab->eType==FTS5_VOCAB_INSTANCE ){ if( pTab->eType==FTS5_VOCAB_INSTANCE ){
@ -648,6 +651,9 @@ static int fts5VocabFilterMethod(
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
Fts5Index *pIndex = pCsr->pFts5->pIndex; Fts5Index *pIndex = pCsr->pFts5->pIndex;
rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter); rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
if( rc==SQLITE_OK ){
pCsr->pStruct = sqlite3Fts5StructureRef(pIndex);
}
} }
if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){ if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
rc = fts5VocabInstanceNewTerm(pCsr); rc = fts5VocabInstanceNewTerm(pCsr);

View File

@ -15364,7 +15364,7 @@ do_execsql_test 79.1 {
do_catchsql_test 79.2 { do_catchsql_test 79.2 {
INSERT INTO t1(t1) SELECT 'merge' FROM t2; INSERT INTO t1(t1) SELECT 'merge' FROM t2;
} {1 {database table is locked}} } {1 {query aborted}}
sqlite3_fts5_may_be_corrupt 0 sqlite3_fts5_may_be_corrupt 0
finish_test finish_test

View File

@ -234,4 +234,27 @@ ifcapable fts3 {
} {1 {no such fts5 table: main.nosuchtable}} } {1 {no such fts5 table: main.nosuchtable}}
} }
#-------------------------------------------------------------------------
# Check that the fts5 table cannot be written while there are vocab
# cursors open.
reset_db
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
INSERT INTO t1 VALUES('one'), ('two'), ('three'), ('four');
}
do_test 5.1 {
list [catch {
db eval { SELECT * FROM v1 } {
db eval {INSERT INTO t1 VALUES('five')}
}
} msg] $msg
} {1 {query aborted}}
do_execsql_test 5.2 {
SELECT * FROM t1
} {one two three four five}
finish_test finish_test

View File

@ -1,5 +1,5 @@
C Handle\s"<vector>\sIN\s(<vector>,\s<vector>\s...)"\sin\sthe\ssame\sway\sas\s"<vector>\sIN\s(VALUES(<vector>,\s<vector>,\s...)". C Instead\sof\sdisallowing\swrites\sto\sfts5\stables\sif\sthere\sare\sfts5vocab\scursors\sopen\son\sthem\s(commit\s[c49a6ed7]),\sabort\sany\sfts5vocab\squeries\sif\sthe\son-disk\sstructure\sof\sthe\sfts5\stable\schanges.
D 2021-07-06T20:44:32.552 D 2021-07-07T11:51:03.885
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -113,14 +113,14 @@ F ext/fts3/unicode/mkunicode.tcl d5aebf022fa4577ee8cdf27468f0d847879993959101f6d
F ext/fts3/unicode/parseunicode.tcl a981bd6466d12dd17967515801c3ff23f74a281be1a03cf1e6f52a6959fc77eb F ext/fts3/unicode/parseunicode.tcl a981bd6466d12dd17967515801c3ff23f74a281be1a03cf1e6f52a6959fc77eb
F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0 F ext/fts5/extract_api_docs.tcl a36e54ec777172ddd3f9a88daf593b00848368e0
F ext/fts5/fts5.h c132a9323f22a972c4c93a8d5a3d901113a6e612faf30ca8e695788438c5ca2a F ext/fts5/fts5.h c132a9323f22a972c4c93a8d5a3d901113a6e612faf30ca8e695788438c5ca2a
F ext/fts5/fts5Int.h cc824fe126e8d87e5a6f9893d18e063fd341b7171c8d0a87ca8fd987f72e8953 F ext/fts5/fts5Int.h 49c1ef3aa6edabd235ce57bc3749453078d69aa02171fe3f361bcf159d1ebd62
F ext/fts5/fts5_aux.c f558e1fb9f0f86a4f7489e258c162e1f947de5ff2709087fbb465fddb7092f98 F ext/fts5/fts5_aux.c f558e1fb9f0f86a4f7489e258c162e1f947de5ff2709087fbb465fddb7092f98
F ext/fts5/fts5_buffer.c 89a51b37c4aa1c02c1ec24c18c55196c0693b29a752fedfd036938df59a1347f F ext/fts5/fts5_buffer.c 89a51b37c4aa1c02c1ec24c18c55196c0693b29a752fedfd036938df59a1347f
F ext/fts5/fts5_config.c 8336d0ff6db0933f63cfec8ae0ab76e68393259cbccc0b46e1f79f7fa1842ff3 F ext/fts5/fts5_config.c 8336d0ff6db0933f63cfec8ae0ab76e68393259cbccc0b46e1f79f7fa1842ff3
F ext/fts5/fts5_expr.c 6ea447b0cb1888110087a8c04133817b0ccf964fe22414371b0e32189a556533 F ext/fts5/fts5_expr.c 6ea447b0cb1888110087a8c04133817b0ccf964fe22414371b0e32189a556533
F ext/fts5/fts5_hash.c 1aa93c9b5f461afba66701ee226297dc78402b3bdde81e90a10de5fe3df14959 F ext/fts5/fts5_hash.c 1aa93c9b5f461afba66701ee226297dc78402b3bdde81e90a10de5fe3df14959
F ext/fts5/fts5_index.c eb1864c6abacf08d959956183a55a4f9767af76be289f2bb519bb0f197b3fd72 F ext/fts5/fts5_index.c 75249b8218dac9c9e7d62362e2be414c1399fdc380c838e5512e2042967b38c8
F ext/fts5/fts5_main.c 3c9d42bef0e6df2fd0fdda0ae58c71fb9fc1e10e18019d8e5da146e9bf064754 F ext/fts5/fts5_main.c 35ebbcae681a4a40027c47bc2e94d7e7c81e331dc406bb9b23c546454ee8f98a
F ext/fts5/fts5_storage.c 58ba71e6cd3d43a5735815e7956ee167babb4d2cbfe206905174792af4d09d75 F ext/fts5/fts5_storage.c 58ba71e6cd3d43a5735815e7956ee167babb4d2cbfe206905174792af4d09d75
F ext/fts5/fts5_tcl.c b1445cbe69908c411df8084a10b2485500ac70a9c747cdc8cda175a3da59d8ae F ext/fts5/fts5_tcl.c b1445cbe69908c411df8084a10b2485500ac70a9c747cdc8cda175a3da59d8ae
F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee F ext/fts5/fts5_test_mi.c 08c11ec968148d4cb4119d96d819f8c1f329812c568bac3684f5464be177d3ee
@ -128,7 +128,7 @@ F ext/fts5/fts5_test_tok.c a2bed8edb25f6432e8cdb62aad5916935c19dba8dac2b8324950c
F ext/fts5/fts5_tokenize.c 5e251efb0f1af99a25ed50010ba6b1ad1250aca5921af1988fdcabe5ebc3cb43 F ext/fts5/fts5_tokenize.c 5e251efb0f1af99a25ed50010ba6b1ad1250aca5921af1988fdcabe5ebc3cb43
F ext/fts5/fts5_unicode2.c eca63dbc797f8ff0572e97caf4631389c0ab900d6364861b915bdd4735973f00 F ext/fts5/fts5_unicode2.c eca63dbc797f8ff0572e97caf4631389c0ab900d6364861b915bdd4735973f00
F ext/fts5/fts5_varint.c e64d2113f6e1bfee0032972cffc1207b77af63319746951bf1d09885d1dadf80 F ext/fts5/fts5_varint.c e64d2113f6e1bfee0032972cffc1207b77af63319746951bf1d09885d1dadf80
F ext/fts5/fts5_vocab.c 68d55d31c0c3f80ffcad9cda056e0d5da3959225cb555cbd6e8f8d61f9fcdb48 F ext/fts5/fts5_vocab.c 925a05c891edf6abd0ac4fdf4dc998c4c13bf6612d0b6c4102157bc459c0c86b
F ext/fts5/fts5parse.y eb526940f892ade5693f22ffd6c4f2702543a9059942772526eac1fde256bb05 F ext/fts5/fts5parse.y eb526940f892ade5693f22ffd6c4f2702543a9059942772526eac1fde256bb05
F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba
F ext/fts5/test/fts5_common.tcl b01c584144b5064f30e6c648145a2dd6bc440841 F ext/fts5/test/fts5_common.tcl b01c584144b5064f30e6c648145a2dd6bc440841
@ -160,7 +160,7 @@ F ext/fts5/test/fts5connect.test 08030168fc96fc278fa81f28654fb7e90566f33aff269c0
F ext/fts5/test/fts5content.test 213506436fb2c87567b8e31f6d43ab30aab99354cec74ed679f22aad0cdbf283 F ext/fts5/test/fts5content.test 213506436fb2c87567b8e31f6d43ab30aab99354cec74ed679f22aad0cdbf283
F ext/fts5/test/fts5corrupt.test 77ae6f41a7eba10620efb921cf7dbe218b0ef232b04519deb43581cb17a57ebe F ext/fts5/test/fts5corrupt.test 77ae6f41a7eba10620efb921cf7dbe218b0ef232b04519deb43581cb17a57ebe
F ext/fts5/test/fts5corrupt2.test 7453752ba12ce91690c469a6449d412561cc604b1dec994e16ab132952e7805f F ext/fts5/test/fts5corrupt2.test 7453752ba12ce91690c469a6449d412561cc604b1dec994e16ab132952e7805f
F ext/fts5/test/fts5corrupt3.test 6bf58259387847de3e9c41f4d5d8f5d1390748cf0c142dc5ff90fec42426b71d F ext/fts5/test/fts5corrupt3.test 0e473620582a53ac61f468f364db8a151c1e18d2a879b16439d172c12c4c9828
F ext/fts5/test/fts5corrupt4.test f4c08e2182a48d8b70975fd869ee5391855c06d8a0ff87b6a2529e7c5a88a1d3 F ext/fts5/test/fts5corrupt4.test f4c08e2182a48d8b70975fd869ee5391855c06d8a0ff87b6a2529e7c5a88a1d3
F ext/fts5/test/fts5delete.test 619295b20dbc1d840b403ee07c878f52378849c3c02e44f2ee143b3e978a0aa7 F ext/fts5/test/fts5delete.test 619295b20dbc1d840b403ee07c878f52378849c3c02e44f2ee143b3e978a0aa7
F ext/fts5/test/fts5detail.test 54015e9c43ec4ba542cfb93268abdf280e0300f350efd08ee411284b03595cc4 F ext/fts5/test/fts5detail.test 54015e9c43ec4ba542cfb93268abdf280e0300f350efd08ee411284b03595cc4
@ -229,7 +229,7 @@ F ext/fts5/test/fts5unindexed.test 9021af86a0fb9fc616f7a69a996db0116e7936d0db638
F ext/fts5/test/fts5update.test b8affd796e45c94a4d19ad5c26606ea06065a0f162a9562d9f005b5a80ccf0bc F ext/fts5/test/fts5update.test b8affd796e45c94a4d19ad5c26606ea06065a0f162a9562d9f005b5a80ccf0bc
F ext/fts5/test/fts5version.test c8f2cc105f0abf0224965f93e584633dee3e06c91478bc67e468f7cfdf97fd6a F ext/fts5/test/fts5version.test c8f2cc105f0abf0224965f93e584633dee3e06c91478bc67e468f7cfdf97fd6a
F ext/fts5/test/fts5vocab.test 7ed80d9af1ddaaa1637da05e406327b5aac250848bc604c1c1cc667908b87760 F ext/fts5/test/fts5vocab.test 7ed80d9af1ddaaa1637da05e406327b5aac250848bc604c1c1cc667908b87760
F ext/fts5/test/fts5vocab2.test e0fdc3a3095f6eda68ac9bf9a443ff929a124d46f00af19933604085712e9d47 F ext/fts5/test/fts5vocab2.test c0a8397523561eb780b4f439e75d4969fade0ac40bc73e0c8fd2f3e065111161
F ext/fts5/tool/fts5speed.tcl b0056f91a55b2d1a3684ec05729de92b042e2f85 F ext/fts5/tool/fts5speed.tcl b0056f91a55b2d1a3684ec05729de92b042e2f85
F ext/fts5/tool/fts5txt2db.tcl c0d43c8590656f8240e622b00957b3a0facc49482411a9fdc2870b45c0c82f9f F ext/fts5/tool/fts5txt2db.tcl c0d43c8590656f8240e622b00957b3a0facc49482411a9fdc2870b45c0c82f9f
F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093 F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093
@ -1920,7 +1920,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P c49a6ed78a917d4972e048e2a9bbe4d400691f97ce7e022f0e4436ceaed7fb73 P 981d230ece98ce89502dab02aa44f73699a9d0e4fce3e9e9dfd47444a5a9990f
R 088831e8438f8281d3a5f02f1fe2374b R 91d740a235eafc0a31ee5704cdc62cbc
U dan U dan
Z e8e70fe2aaf0c6a219c124f4d93d407b Z 274ccaf9ffc17905402a8367ad18dcac

View File

@ -1 +1 @@
981d230ece98ce89502dab02aa44f73699a9d0e4fce3e9e9dfd47444a5a9990f 9dbdc9001e3258e71ca995fbcdebf66ab95890ded87fa7125c6cb4bd43010aaf