/ Check-in [2772404b]
Login

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

Overview
Comment:Avoid opening a statement journal on single-row UPDATEs without triggers or FK constraints.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:2772404b8c570caf3c31d2b0530cf347a24f6f60e220e726c086537b38ebfa85
User & Date: drh 2018-04-20 19:32:35
Context
2018-04-20
19:46
Avoid the use of statement journals on DELETEs of a single row without triggers or foreign keys. check-in: 20bf5800 user: drh tags: trunk
19:32
Avoid opening a statement journal on single-row UPDATEs without triggers or FK constraints. check-in: 2772404b user: drh tags: trunk
18:01
Fix a VDBE comment on upsert. Provide an error message when upsert detects index corruption. check-in: 279c48f6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/update.c.

   335    335       memset(aToOpen, 1, nIdx+1);
   336    336     }
   337    337   
   338    338     /* Begin generating code. */
   339    339     v = sqlite3GetVdbe(pParse);
   340    340     if( v==0 ) goto update_cleanup;
   341    341     if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
   342         -  sqlite3BeginWriteOperation(pParse, 1, iDb);
          342  +  sqlite3BeginWriteOperation(pParse, pTrigger || hasFK, iDb);
   343    343   
   344    344     /* Allocate required registers. */
   345    345     if( !IsVirtual(pTab) ){
   346    346       regRowSet = ++pParse->nMem;
   347    347       regOldRowid = regNewRowid = ++pParse->nMem;
   348    348       if( chngPk || pTrigger || hasFK ){
   349    349         regOld = pParse->nMem + 1;
................................................................................
   452    452       **
   453    453       **   UPDATE t1 SET b=b+1 WHERE b>?
   454    454       **
   455    455       ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
   456    456       ** strategy that uses an index for which one or more columns are being
   457    457       ** updated.  */
   458    458       eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
   459         -    if( eOnePass==ONEPASS_MULTI ){
   460         -      int iCur = aiCurOnePass[1];
   461         -      if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
   462         -        eOnePass = ONEPASS_OFF;
          459  +    if( eOnePass!=ONEPASS_SINGLE ){
          460  +      sqlite3MultiWrite(pParse);
          461  +      if( eOnePass==ONEPASS_MULTI ){
          462  +        int iCur = aiCurOnePass[1];
          463  +        if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
          464  +          eOnePass = ONEPASS_OFF;
          465  +        }
          466  +        assert( iCur!=iDataCur || !HasRowid(pTab) );
   463    467         }
   464         -      assert( iCur!=iDataCur || !HasRowid(pTab) );
   465    468       }
   466    469     }
   467    470   
   468    471     if( HasRowid(pTab) ){
   469    472       /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
   470    473       ** mode, write the rowid into the FIFO. In either of the one-pass modes,
   471    474       ** leave it in register regOldRowid.  */
................................................................................
   880    883       sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);
   881    884     }
   882    885   
   883    886     bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);
   884    887   
   885    888     if( bOnePass ){
   886    889       /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
   887         -    ** above. Also, if this is a top-level parse (not a trigger), clear the
   888         -    ** multi-write flag so that the VM does not open a statement journal */
          890  +    ** above. */
   889    891       sqlite3VdbeChangeToNoop(v, addr);
   890         -    if( sqlite3IsToplevel(pParse) ){
   891         -      pParse->isMultiWrite = 0;
   892         -    }
   893    892     }else{
   894    893       /* Create a record from the argument register contents and insert it into
   895    894       ** the ephemeral table. */
          895  +    sqlite3MultiWrite(pParse);
   896    896       sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
   897    897   #ifdef SQLITE_DEBUG
   898    898       /* Signal an assert() within OP_MakeRecord that it is allowed to
   899    899       ** accept no-change records with serial_type 10 */
   900    900       sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG_MAGIC);
   901    901   #endif
   902    902       sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);