]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests for fts3 and onepass update/delete operations. Also fix a problem with...
authordan <dan@noemail.net>
Tue, 29 Sep 2015 10:11:26 +0000 (10:11 +0000)
committerdan <dan@noemail.net>
Tue, 29 Sep 2015 10:11:26 +0000 (10:11 +0000)
FossilOrigin-Name: 820c804468abff692742952de670c5d906a50956

manifest
manifest.uuid
src/delete.c
src/update.c
src/wherecode.c
test/fts4onepass.test [new file with mode: 0644]

index db3cccbd974865280a73c31a62ffe70ce38e9691..7c78e99294b516df32c97cb3a126a953497757e4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Also\sallow\sUPDATE\son\svirtual\stables\sto\suse\sthe\sonepass\sstrategy.
-D 2015-09-28T20:03:49.551
+C Add\stests\sfor\sfts3\sand\sonepass\supdate/delete\soperations.\sAlso\sfix\sa\sproblem\swith\sonepass\supdates\sthat\sdo\snot\saffect\sany\srows.
+D 2015-09-29T10:11:26.685
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2143eeef6d0cc26006ae5fc4bb242a4a8b973412
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -291,7 +291,7 @@ F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f
 F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b
 F src/date.c fb1c99172017dcc8e237339132c91a21a0788584
 F src/dbstat.c e637e7a7ff40ef32132a418c6fdf1cfb63aa27c7
-F src/delete.c b454df59d57cb3f07118dfc68821760593fcaab3
+F src/delete.c 174b140317915e0e8c6e2eff28158eecf95c53d8
 F src/expr.c 3a76afcdac925294c39903b7002ddb9e5fd29863
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c 83e1baba999bed3144ea5a2143fc922edf51135f
@@ -399,7 +399,7 @@ F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0
 F src/tokenize.c 83c6ed569423a3af83a83973b444cf7123be33a6
 F src/treeview.c 154f0acc622fa3514de8777dcedf4c8a8802b4ce
 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f
-F src/update.c 779319e1d52c3dfb3b870c9acd26161b464fbe27
+F src/update.c 4fb82a2440bd8d66f266ada1ef31a2fcde48bd4f
 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c
 F src/util.c fc612367108b74573c5fd13a85d0a23027f438bd
 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
@@ -419,7 +419,7 @@ F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba
 F src/where.c d07fb77010949be9b96e9120b4653712bf9f74ae
 F src/whereInt.h 7892bb54cf9ca0ae5c7e6094491b94c9286dc647
-F src/wherecode.c 7660e1ad16817a921b099af553f3e1349352d16f
+F src/wherecode.c a87238178f8c300fd27afec54326ea8d0a18baa2
 F src/whereexpr.c 2473e4350e30f9b55d1c6a8f66ca23c689f23f1d
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@@ -736,6 +736,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891
 F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7
 F test/fts4merge4.test d895b1057a7798b67e03455d0fa50e9ea836c47b
 F test/fts4noti.test 524807f0c36d49deea7920cdd4cd687408b58849
+F test/fts4onepass.test bfca61f69c6ca74cd71e6dca12a0cdd47192fc24
 F test/fts4unicode.test 27378af76394542cf490cf001d8d1505fe55f6a9
 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
 F test/func.test ae97561957aba6ca9e3a7b8a13aac41830d701ef
@@ -1388,7 +1389,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P fffab4f70f85eeb2acbb89534064a6e397c39384
-R 57289d0ecbc93a6cd377511502833368
+P 1aa27d706db9b2e21737ce4b94b47ecd12c2570f
+R 906a452cbd4322b894c4cf3888c881fe
 U dan
-Z 186d4cd8527ef990e771b3fd7444e8fc
+Z 392788408df553b8d21ff2f5c84b91d4
index 7d87d8a7db1f68ea2996664eff61c1c3cbba9756..673713a60e1289ab8f3de375fac807aa445cdfbd 100644 (file)
@@ -1 +1 @@
-1aa27d706db9b2e21737ce4b94b47ecd12c2570f
\ No newline at end of file
+820c804468abff692742952de670c5d906a50956
\ No newline at end of file
index 9c928f8d511822cc07141f91b8f8ed607777dfc7..ed843c1a75ee04679053081ded546306332c840a 100644 (file)
@@ -465,7 +465,7 @@ void sqlite3DeleteFrom(
   
     /* If this DELETE cannot use the ONEPASS strategy, this is the 
     ** end of the WHERE loop */
-    if( eOnePass!=ONEPASS_OFF && !IsVirtual(pTab) ){
+    if( eOnePass!=ONEPASS_OFF ){
       addrBypass = sqlite3VdbeMakeLabel(v);
     }else{
       sqlite3WhereEnd(pWInfo);
@@ -535,10 +535,8 @@ void sqlite3DeleteFrom(
   
     /* End of the loop over all rowids/primary-keys. */
     if( eOnePass!=ONEPASS_OFF ){
-      if( !IsVirtual(pTab) ){
-        sqlite3VdbeResolveLabel(v, addrBypass);
-        sqlite3WhereEnd(pWInfo);
-      }
+      sqlite3VdbeResolveLabel(v, addrBypass);
+      sqlite3WhereEnd(pWInfo);
     }else if( pPk ){
       sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
       sqlite3VdbeJumpHere(v, addrLoop);
index b7071ce014def2eaeab6a39cd3ceae8e9cf1263a..ebf0d6c8eaeef8ad1cd632becec65a4ffa104d34 100644 (file)
@@ -777,12 +777,13 @@ static void updateVirtualTable(
     sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
   }
 
-  /* End the virtual table scan */
-  sqlite3WhereEnd(pWInfo);
 
   if( bOnePass==0 ){
+    /* End the virtual table scan */
+    sqlite3WhereEnd(pWInfo);
+
     /* Begin scannning through the ephemeral table. */
-    addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
+    addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);
 
     /* Extract arguments from the current row of the ephemeral table and 
     ** invoke the VUpdate method.  */
@@ -795,11 +796,14 @@ static void updateVirtualTable(
   sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
   sqlite3MayAbort(pParse);
 
-  /* End of the ephemeral table scan */
+  /* End of the ephemeral table scan. Or, if using the onepass strategy,
+  ** jump to here if the scan visited zero rows. */
   if( bOnePass==0 ){
     sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
     sqlite3VdbeJumpHere(v, addr);
     sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
+  }else{
+    sqlite3WhereEnd(pWInfo);
   }
 }
 #endif /* SQLITE_OMIT_VIRTUALTABLE */
index 77b8be4beee658905fab4f133ff45f206c9ddcda..f9b56e7c83d16e2957ac1ab2f466a45cb2d1df96 100644 (file)
@@ -700,8 +700,8 @@ Bitmask sqlite3WhereCodeOneLoopStart(
         disableTerm(pLevel, pLoop->aLTerm[j]);
       }
     }
-    pLevel->op = OP_VNext;
     pLevel->p1 = iCur;
+    pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
     pLevel->p2 = sqlite3VdbeCurrentAddr(v);
     sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
     sqlite3ExprCachePop(pParse);
diff --git a/test/fts4onepass.test b/test/fts4onepass.test
new file mode 100644 (file)
index 0000000..d290980
--- /dev/null
@@ -0,0 +1,147 @@
+# 2015 Sep 27
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#*************************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/fts3_common.tcl
+set ::testprefix fts4onepass
+
+# If SQLITE_ENABLE_FTS3 is defined, omit this file.
+ifcapable !fts3 {
+  finish_test
+  return
+}
+
+do_execsql_test 1.0 {
+  CREATE VIRTUAL TABLE ft USING fts3;
+  INSERT INTO ft(rowid, content) VALUES(1, '1 2 3');
+  INSERT INTO ft(rowid, content) VALUES(2, '4 5 6');
+  INSERT INTO ft(rowid, content) VALUES(3, '7 8 9');
+}
+
+#-------------------------------------------------------------------------
+# Check that UPDATE and DELETE statements that feature "WHERE rowid=?" or 
+# or "WHERE docid=?" clauses do not use statement journals. But that other
+# DELETE and UPDATE statements do.
+#
+# Note: "MATCH ? AND docid=?" does use a statement journal.
+#
+foreach {tn sql uses} {
+  1.1 { DELETE FROM ft } 1
+  1.2 { DELETE FROM ft WHERE docid=? } 0
+  1.3 { DELETE FROM ft WHERE rowid=? } 0
+  1.4 { DELETE FROM ft WHERE ft MATCH '1' } 1
+  1.5 { DELETE FROM ft WHERE ft MATCH '1' AND docid=? } 1
+  1.6 { DELETE FROM ft WHERE ft MATCH '1' AND rowid=? } 1
+
+  2.1 { UPDATE ft SET content='a b c' } 1
+  2.2 { UPDATE ft SET content='a b c' WHERE docid=? } 0
+  2.3 { UPDATE ft SET content='a b c' WHERE rowid=? } 0
+  2.4 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' } 1
+  2.5 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND docid=? } 1
+  2.6 { UPDATE ft SET content='a b c' WHERE ft MATCH '1' AND rowid=? } 1
+} {
+  do_test 1.$tn { sql_uses_stmt db $sql } $uses
+}
+
+#-------------------------------------------------------------------------
+# Check that putting a "DELETE/UPDATE ... WHERE rowid=?" statement in a
+# trigger program does not prevent the VM from using a statement 
+# transaction. Even if the calling statement cannot hit a constraint.
+#
+do_execsql_test 2.0 {
+  CREATE TABLE t1(x);
+
+  CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
+    DELETE FROM ft WHERE rowid=new.x;
+  END;
+
+  CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
+    UPDATE ft SET content = 'a b c' WHERE rowid=old.x;
+  END;
+
+  CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
+    DELETE FROM ft WHERE rowid=old.x;
+  END;
+}
+
+foreach {tn sql uses} {
+  1 { INSERT INTO t1 VALUES(1)      } 1
+  2 { DELETE FROM t1 WHERE x=4      } 1
+  3 { UPDATE t1 SET x=10 WHERE x=11 } 1
+} {
+  do_test 2.$tn { sql_uses_stmt db $sql } $uses
+}
+
+#-------------------------------------------------------------------------
+# Test that an "UPDATE ... WHERE rowid=?" works and does not corrupt the
+# index when it strikes a constraint. Both inside and outside a 
+# transaction.
+#
+foreach {tn tcl1 tcl2}  {
+  1 {} {}
+
+  2 {
+    execsql BEGIN
+  } {
+    if {[sqlite3_get_autocommit db]==1} { error "transaction rolled back!" }
+    execsql COMMIT
+  }
+} {
+
+  do_execsql_test 3.$tn.0 {
+    DROP TABLE IF EXISTS ft2;
+    CREATE VIRTUAL TABLE ft2 USING fts4;
+    INSERT INTO ft2(rowid, content) VALUES(1, 'a b c');
+    INSERT INTO ft2(rowid, content) VALUES(2, 'a b d');
+    INSERT INTO ft2(rowid, content) VALUES(3, 'a b e');
+  }
+
+  eval $tcl1
+  foreach {tn2 sql content} {
+    1 { UPDATE ft2 SET docid=2 WHERE docid=1 }
+      { 1 {a b c} 2 {a b d} 3 {a b e} }
+
+    2 { 
+      INSERT INTO ft2(rowid, content) VALUES(4, 'a b f');
+      UPDATE ft2 SET docid=5 WHERE docid=4;
+      UPDATE ft2 SET docid=3 WHERE docid=5;
+    } { 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} }
+
+    3 {
+      UPDATE ft2 SET docid=3 WHERE docid=4;           -- matches 0 rows
+      UPDATE ft2 SET docid=2 WHERE docid=3;
+    } { 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} }
+
+    4 {
+      INSERT INTO ft2(rowid, content) VALUES(4, 'a b g');
+      UPDATE ft2 SET docid=-1 WHERE docid=4;
+      UPDATE ft2 SET docid=3 WHERE docid=-1;
+    } {-1 {a b g} 1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} }
+
+    5 {
+      DELETE FROM ft2 WHERE rowid=451;
+      DELETE FROM ft2 WHERE rowid=-1;
+      UPDATE ft2 SET docid = 2 WHERE docid = 1;
+    } {1 {a b c} 2 {a b d} 3 {a b e} 5 {a b f} }
+  } {
+    do_catchsql_test 3.$tn.$tn2.a $sql {1 {constraint failed}}
+    do_execsql_test  3.$tn.$tn2.b { SELECT rowid, content FROM ft2 } $content
+    do_execsql_test  3.$tn.$tn2.c { 
+      INSERT INTO ft2(ft2) VALUES('integrity-check');
+    }
+  }
+  eval $tcl2
+}
+
+finish_test
+