/ Check-in [3a695263]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Simplification to the logic used to decide between OP_Seek and OP_NotExists. Use OP_NotExists for both DELETE and UPDATE.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3a695263183303e3f64eb2320752d0fdef53eaf2
User & Date: drh 2016-05-06 20:23:12
Context
2016-05-07
12:15
Fix typo in the intpkey-17.2 test. check-in: a45fda65 user: drh tags: trunk
2016-05-06
20:23
Simplification to the logic used to decide between OP_Seek and OP_NotExists. Use OP_NotExists for both DELETE and UPDATE. check-in: 3a695263 user: drh tags: trunk
18:47
Corrections to comments on the whereScanInit() interface. check-in: ab7ab415 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/update.c.

   348    348   #endif
   349    349   
   350    350     /* Begin the database scan
   351    351     */
   352    352     if( HasRowid(pTab) ){
   353    353       sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
   354    354       pWInfo = sqlite3WhereBegin(
   355         -        pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur
          355  +        pParse, pTabList, pWhere, 0, 0,
          356  +            WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur
   356    357       );
   357    358       if( pWInfo==0 ) goto update_cleanup;
   358    359       okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
   359    360     
   360    361       /* Remember the rowid of every item to be updated.
   361    362       */
   362    363       sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);

Changes to src/wherecode.c.

  1320   1320   
  1321   1321       /* Seek the table cursor, if required */
  1322   1322       disableTerm(pLevel, pRangeStart);
  1323   1323       disableTerm(pLevel, pRangeEnd);
  1324   1324       if( omitTable ){
  1325   1325         /* pIdx is a covering index.  No need to access the main table. */
  1326   1326       }else if( HasRowid(pIdx->pTable) ){
  1327         -      if( pWInfo->eOnePass!=ONEPASS_OFF
  1328         -       || (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0
  1329         -      ){
         1327  +      if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){
  1330   1328           iRowidReg = ++pParse->nMem;
  1331   1329           sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
  1332   1330           sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
  1333   1331           sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
  1334   1332           VdbeCoverage(v);
  1335   1333         }else{
  1336   1334           codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);

Changes to test/intpkey.test.

   627    627     DELETE FROM t17 WHERE x=99 OR x<130;
   628    628     SELECT * FROM t17;
   629    629   } {248 giraffe}
   630    630   do_execsql_test intpkey-17.1 {
   631    631     DROP INDEX t17x;
   632    632     DELETE FROM t17;
   633    633     INSERT INTO t17(x,y) VALUES(123,'elephant'),(248,'giraffe');
   634         -  CREATE INDEX t17x ON t17(abs(x));
          634  +  CREATE UNIQUE INDEX t17x ON t17(abs(x));
   635    635     DELETE FROM t17 WHERE abs(x) IS NULL OR abs(x)<130;
   636    636     SELECT * FROM t17;
   637    637   } {248 giraffe}
          638  +do_execsql_test intpkey-17.2 {
          639  +  DELETE FROM t17;
          640  +  INSERT INTO t17(x,y) VALUES(123,'elephant'),(248,'giraffe');
          641  +  UPDATE FROM t17 SET y='ostrich' WHERE abs(x)=248;
          642  +  SELECT * FROM t17 ORDER BY +x;
          643  +} {123 elephant 248 ostrich}
   638    644   
   639    645   finish_test