]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix an fts5 problem where a transaction consisting of (a) a DELETE on rowid X, (b...
authordan <Dan Kennedy>
Mon, 6 Nov 2023 18:40:25 +0000 (18:40 +0000)
committerdan <Dan Kennedy>
Mon, 6 Nov 2023 18:40:25 +0000 (18:40 +0000)
FossilOrigin-Name: c2058a045b57571b2b5d342adb212fe606717c633a0422755691ae6bf5725d25

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 f81c5b0edcbb082961c3a295a055abfe8bee9d6e..23292f0087ce65365cfd085486e6a4f570cd6e01 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sincremental\sblob\sI/O\ssupport\sto\sJNI\swrapper1.
-D 2023-11-05T04:20:04.320
+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-06T18:40:25.654
 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 ee770eec0af8646db9e18fc01a0dad7345b5f5e8cbba236704cfae2d77
 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
@@ -2142,8 +2142,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 d081a126697e214082f3b203f23ea63510080e5c2aac1d8badc9e6e4bfea7c95
-R d10239966e7198eb47ba47ac2878d98e
-U stephan
-Z e8e87bde5ba89e299cdcc353d989a2b2
+P 7f1c76fe930d69a0274f70fa7b7e68e0db6226b731a065fa57d0936c8400ffb0
+R cd264cc39082738dd835b35e1796876f
+U dan
+Z ddf602c5afe5ca1e5ab19c1df349a6bc
 # Remove this line to create a well-formed Fossil manifest.
index 63c307a8c42e33890ae6929725f12394d2497afb..357f6f02e091ca3f50900573826984531d0a41ee 100644 (file)
@@ -1 +1 @@
-7f1c76fe930d69a0274f70fa7b7e68e0db6226b731a065fa57d0936c8400ffb0
\ No newline at end of file
+c2058a045b57571b2b5d342adb212fe606717c633a0422755691ae6bf5725d25
\ No newline at end of file