]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix an fts5 problem where a transaction consisting of (a) a DELETE on rowid X, (b...
authordrh <>
Mon, 6 Nov 2023 19:01:25 +0000 (19:01 +0000)
committerdrh <>
Mon, 6 Nov 2023 19:01:25 +0000 (19:01 +0000)
FossilOrigin-Name: 34af510a5615339f2963875eab94d4b07725e766c20819f82add19faa229d552

ext/fts5/fts5_hash.c
ext/fts5/fts5_index.c
ext/fts5/test/fts5prefix2.test
manifest
manifest.uuid

index 7e50c366083cb45af57e2e311e47597bfe7ee77f..391791c7acd1e3a176873a73a0c4d4c3860e4139 100644 (file)
@@ -432,10 +432,8 @@ static Fts5HashEntry *fts5HashEntryMerge(
 }
 
 /*
-** Extract all tokens from hash table iHash and link them into a list
-** in sorted order. The hash table is cleared before returning. It is
-** the responsibility of the caller to free the elements of the returned
-** list.
+** Link all tokens from hash table iHash into a list in sorted order. The
+** tokens are not removed from the hash table.
 */
 static int fts5HashEntrySort(
   Fts5Hash *pHash, 
index 4e6afb2815d4fc69c9f4181e21e1289f65af66b5..c7c02cf6fe480eb40f9e0e8be6d276368c37a65f 100644 (file)
@@ -2719,6 +2719,14 @@ static void fts5SegIterHashInit(
         pLeaf->p = (u8*)pList;
       }
     }
+
+    /* The call to sqlite3Fts5HashScanInit() causes the hash table to
+    ** fill the size field of all existing position lists. This means they
+    ** can no longer be appended to. Since the only scenario in which they
+    ** can be appended to is if the previous operation on this table was
+    ** a DELETE, by clearing the Fts5Index.bDelete flag we can avoid this
+    ** possibility altogether.  */
+    p->bDelete = 0;
   }else{
     p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data), 
         (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
@@ -6204,7 +6212,7 @@ int sqlite3Fts5IndexBeginWrite(Fts5Index *p, int bDelete, i64 iRowid){
   /* Flush the hash table to disk if required */
   if( iRowid<p->iWriteRowid 
    || (iRowid==p->iWriteRowid && p->bDelete==0)
-   || (p->nPendingData > p->pConfig->nHashSize) 
+   || (p->nPendingData > p->pConfig->nHashSize)
   ){
     fts5IndexFlush(p);
   }
index bf16e81a732fdfd1e6ecf241d0a6e3550e6203f1..29744c86bf7d2a5a1e1f95cb4fa0b41f871fa453 100644 (file)
@@ -52,6 +52,36 @@ do_execsql_test 2.1 {
   SELECT * FROM t2('to*');
 } {top to tommy}
 
+#-------------------------------------------------------------------------
+
+foreach {tn newrowid} {
+  1   122
+  2   123
+  3   124
+} {
+  reset_db
+  do_execsql_test 3.$tn.0 {
+    CREATE VIRTUAL TABLE t12 USING fts5(x);
+    INSERT INTO t12(rowid, x) VALUES(123, 'wwww');
+  }
+  do_execsql_test 3.$tn.1 {
+    BEGIN;
+    DELETE FROM t12 WHERE rowid=123;
+    SELECT * FROM t12('wwww*');
+    INSERT INTO t12(rowid, x) VALUES($newrowid, 'wwww');
+    SELECT * FROM t12('wwww*');
+    END;
+  } {wwww}
+  do_execsql_test 3.$tn.2 {
+    INSERT INTO t12(t12) VALUES('integrity-check');
+  }
+  do_execsql_test 3.$tn.3 {
+    SELECT rowid FROM t12('wwww*');
+  } $newrowid
+}
+
+finish_test
+
 
 
 finish_test
index c8761ca34ec1a3cb775a9278c0be76ec45772c82..87b2e4be4169e482e720978d92c5b46c17c4abd7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\sversion\snumber\sto\s3.44.1
-D 2023-11-02T11:14:43.644
+C Fix\san\sfts5\sproblem\swhere\sa\stransaction\sconsisting\sof\s(a)\sa\sDELETE\son\srowid\sX,\s(b)\sa\sprefix\squery,\sand\s(c)\san\sINSERT\son\srowid\sX,\scould\scorrupt\sthe\sindex.
+D 2023-11-06T19:01:25.066
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -93,8 +93,8 @@ F ext/fts5/fts5_aux.c 35c4101613eff86902877a4dedd9400b07922e412cbdd637b45041dce2
 F ext/fts5/fts5_buffer.c 3001fbabb585d6de52947b44b455235072b741038391f830d6b729225eeaf6a5
 F ext/fts5/fts5_config.c 054359543566cbff1ba65a188330660a5457299513ac71c53b3a07d934c7b081
 F ext/fts5/fts5_expr.c bd3b81ce669c4104e34ffe66570af1999a317b142c15fccb112de9fb0caa57a6
-F ext/fts5/fts5_hash.c 65e7707bc8774706574346d18c20218facf87de3599b995963c3e6d6809f203d
-F ext/fts5/fts5_index.c 730c9c32ada18ce1eb7ff847b36507f4b005d88d47af7b47db521e695a8ea4c7
+F ext/fts5/fts5_hash.c 076058f93327051952a752dc765df1acfe783eb11b419b30652aa1fc1f987902
+F ext/fts5/fts5_index.c 01b671fedd2189f6969385d96facc4c06d9c441f0f91d584386a62b724282f9f
 F ext/fts5/fts5_main.c a07ed863b8bd9e6fefb62db2fd40a3518eb30a5f7dcfda5be915dd2db45efa2f
 F ext/fts5/fts5_storage.c 5d10b9bdcce5b90656cad13c7d12ad4148677d4b9e3fca0481fca56d6601426d
 F ext/fts5/fts5_tcl.c b1445cbe69908c411df8084a10b2485500ac70a9c747cdc8cda175a3da59d8ae
@@ -193,7 +193,7 @@ F ext/fts5/test/fts5plan.test b65cfcca9ddd6fdaa118c61e17aeec8e8433bc5b6bb307abd1
 F ext/fts5/test/fts5porter.test 8d08010c28527db66bc3feebd2b8767504aaeb9b101a986342fa7833d49d0d15
 F ext/fts5/test/fts5porter2.test 0d251a673f02fa13ca7f011654873b3add20745f7402f108600a23e52d8c7457
 F ext/fts5/test/fts5prefix.test a0fa67b06650f2deaa7bf27745899d94e0fb547ad9ecbd08bfad98c04912c056
-F ext/fts5/test/fts5prefix2.test 3847ce46f70b82d61c6095103a9d7c53f2952c40a4704157bc079c04d9c8b18b
+F ext/fts5/test/fts5prefix2.test ad751d4a5b029726ee908a7664e27d27bde7584218b8d7944c2a323afd381432
 F ext/fts5/test/fts5query.test ac363b17a442620bb0780e93c24f16a5f963dfe2f23dc85647b869efcfada728
 F ext/fts5/test/fts5rank.test 30f29e278cd7fb8831ba4f082feb74d8eb90c463bf07113ae200afc2b467ef32
 F ext/fts5/test/fts5rebuild.test 55d6f17715cddbf825680dd6551efbc72ed916d8cf1cde40a46fc5d785b451e7
@@ -2139,8 +2139,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P c8bf4f7a6a4c4f0f8cd21de25918f4d96f6831a145af4fb63e4b5984f79613b2
-R 2ea6650cd2adb393438e9ddbbc8346b3
+P 34f23c3d0d080fef82e3515ecb74257f68878c74fb0bdceac176a004aa1a84e9
+Q +c2058a045b57571b2b5d342adb212fe606717c633a0422755691ae6bf5725d25
+R 076f635f2ce923c956d7afe0c8e318bb
 U drh
-Z ab15481ff7b37ad473e850b646604348
+Z 51ac790dc9094eab5a57469e82ae7453
 # Remove this line to create a well-formed Fossil manifest.
index a603a178f6e89b851ccd8787e4c17a1f18034b0b..da8cfbfdaf72d5828e33410989d4c737ff163059 100644 (file)
@@ -1 +1 @@
-34f23c3d0d080fef82e3515ecb74257f68878c74fb0bdceac176a004aa1a84e9
\ No newline at end of file
+34af510a5615339f2963875eab94d4b07725e766c20819f82add19faa229d552
\ No newline at end of file