/ Check-in [1d3bf6be]
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:Change the name of the BTREE_IDXDELETE flag to BTREE_AUXDELETE, to better reflect its purpose.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fordelete-assert
Files: files | file ages | folders
SHA1: 1d3bf6bebdda9f96734bc139601e9b05344ea0b4
User & Date: drh 2016-01-27 16:26:25
Context
2016-01-28
17:06
Modifications to ensure the nExtraDelete-related assert() statement does not fail. check-in: f43ff8f8 user: dan tags: fordelete-assert
2016-01-27
16:26
Change the name of the BTREE_IDXDELETE flag to BTREE_AUXDELETE, to better reflect its purpose. check-in: 1d3bf6be user: drh tags: fordelete-assert
16:17
Fix tests in fordelete.test to test for the BTREE_AUXDELETE flag. check-in: bbd25cf1 user: dan tags: fordelete-assert
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  8094   8094   **
  8095   8095   ** If the BTREE_SAVEPOSITION bit of the flags parameter is zero, then
  8096   8096   ** the cursor is left pointing at an arbitrary location after the delete.
  8097   8097   ** But if that bit is set, then the cursor is left in a state such that
  8098   8098   ** the next call to BtreeNext() or BtreePrev() moves it to the same row
  8099   8099   ** as it would have been on if the call to BtreeDelete() had been omitted.
  8100   8100   **
  8101         -** The BTREE_IDXDELETE bit of flags indicates that this is a delete of
  8102         -** an index entry where the corresponding table row has already been deleted.
  8103         -** The BTREE_IDXDELETE bit is a hint that is not used by this implementation,
         8101  +** The BTREE_AUXDELETE bit of flags indicates that is one of several deletes
         8102  +** associated with a single table entry and its indexes.  Only one of those
         8103  +** deletes is considered the "primary" delete.  The primary delete occurs
         8104  +** on a cursor that is not a BTREE_FORDELETE cursor.  All but one delete
         8105  +** operation on non-FORDELETE cursors is tagged with the AUXDELETE flag.
         8106  +** The BTREE_AUXDELETE bit is a hint that is not used by this implementation,
  8104   8107   ** but which might be used by alternative storage engines.
  8105   8108   */
  8106   8109   int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
  8107   8110     Btree *p = pCur->pBtree;
  8108   8111     BtShared *pBt = p->pBt;              
  8109   8112     int rc;                              /* Return code */
  8110   8113     MemPage *pPage;                      /* Page to delete cell from */
................................................................................
  8119   8122     assert( pBt->inTransaction==TRANS_WRITE );
  8120   8123     assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
  8121   8124     assert( pCur->curFlags & BTCF_WriteFlag );
  8122   8125     assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
  8123   8126     assert( !hasReadConflicts(p, pCur->pgnoRoot) );
  8124   8127     assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
  8125   8128     assert( pCur->eState==CURSOR_VALID );
  8126         -  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_IDXDELETE))==0 );
         8129  +  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
  8127   8130   
  8128   8131     iCellDepth = pCur->iPage;
  8129   8132     iCellIdx = pCur->aiIdx[iCellDepth];
  8130   8133     pPage = pCur->apPage[iCellDepth];
  8131   8134     pCell = findCell(pPage, iCellIdx);
  8132   8135   
  8133   8136     /* If the page containing the entry to delete is not a leaf page, move

Changes to src/btree.h.

   245    245   );
   246    246   int sqlite3BtreeCursorHasMoved(BtCursor*);
   247    247   int sqlite3BtreeCursorRestore(BtCursor*, int*);
   248    248   int sqlite3BtreeDelete(BtCursor*, u8 flags);
   249    249   
   250    250   /* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
   251    251   #define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
   252         -#define BTREE_IDXDELETE    0x04  /* this is index, table row already deleted */
          252  +#define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
   253    253   
   254    254   int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
   255    255                                     const void *pData, int nData,
   256    256                                     int nZero, int bias, int seekResult);
   257    257   int sqlite3BtreeFirst(BtCursor*, int *pRes);
   258    258   int sqlite3BtreeLast(BtCursor*, int *pRes);
   259    259   int sqlite3BtreeNext(BtCursor*, int *pRes);

Changes to src/delete.c.

   720    720       u8 p5 = 0;
   721    721       sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
   722    722       sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
   723    723       if( count ){
   724    724         sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
   725    725       }
   726    726       if( eMode!=ONEPASS_OFF ){
   727         -      sqlite3VdbeChangeP5(v, OPFLAG_IDXDELETE);
   728         -      p5 = OPFLAG_IDXDELETE;
          727  +      sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
   729    728       }
   730    729       if( iIdxNoSeek>=0 ){
   731    730         sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
   732         -      p5 = 0;
   733    731       }
   734    732       if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
   735    733       sqlite3VdbeChangeP5(v, p5);
   736    734     }
   737    735   
   738    736     /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
   739    737     ** handle rows (possibly in other tables) that refer via a foreign key

Changes to src/sqliteInt.h.

  2858   2858   #define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */
  2859   2859   #define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */
  2860   2860   #define OPFLAG_SEEKEQ        0x02    /* OP_Open** cursor uses EQ seek only */
  2861   2861   #define OPFLAG_FORDELETE     0x08    /* OP_Open should use BTREE_FORDELETE */
  2862   2862   #define OPFLAG_P2ISREG       0x10    /* P2 to OP_Open** is a register number */
  2863   2863   #define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
  2864   2864   #define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete: keep cursor position */
  2865         -#define OPFLAG_IDXDELETE     0x04    /* OP_Delete: index in a DELETE op */
         2865  +#define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */
  2866   2866   
  2867   2867   /*
  2868   2868    * Each trigger present in the database schema is stored as an instance of
  2869   2869    * struct Trigger. 
  2870   2870    *
  2871   2871    * Pointers to instances of struct Trigger are stored in two ways.
  2872   2872    * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 

Changes to src/vdbe.c.

   549    549   ){
   550    550     Op *aOp = p->aOp;          /* Copy of p->aOp */
   551    551     Op *pOp = aOp;             /* Current operation */
   552    552   #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
   553    553     Op *pOrigOp;               /* Value of pOp at the top of the loop */
   554    554   #endif
   555    555   #ifdef SQLITE_DEBUG
   556         -  int nExtraDelete = 0;      /* Verifies FORDELETE and IDXDELETE flags */
          556  +  int nExtraDelete = 0;      /* Verifies FORDELETE and AUXDELETE flags */
   557    557   #endif
   558    558     int rc = SQLITE_OK;        /* Value to return */
   559    559     sqlite3 *db = p->db;       /* The database */
   560    560     u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
   561    561     u8 encoding = ENC(db);     /* The database encoding */
   562    562     int iCompare = 0;          /* Result of last OP_Compare operation */
   563    563     unsigned nVmStep = 0;      /* Number of virtual machine steps */
................................................................................
  4351   4351   ** the cursor will be left pointing at  either the next or the previous
  4352   4352   ** record in the table. If it is left pointing at the next record, then
  4353   4353   ** the next Next instruction will be a no-op. As a result, in this case
  4354   4354   ** it is ok to delete a record from within a Next loop. If 
  4355   4355   ** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
  4356   4356   ** left in an undefined state.
  4357   4357   **
  4358         -** If the OPFLAG_IDXDELETE bit is set on P5, that indicates that this
  4359         -** delete is on an index cursor where the corresponding table row has
  4360         -** already been deleted.
         4358  +** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
         4359  +** delete one of several associated with deleting a table row and all its
         4360  +** associated index entries.  Exactly one of those deletes is the "primary"
         4361  +** delete.  The others are all on OPFLAG_FORDELETE cursors or else are
         4362  +** marked with the AUXDELETE flag.
  4361   4363   **
  4362   4364   ** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row
  4363   4365   ** change count is incremented (otherwise not).
  4364   4366   **
  4365   4367   ** P1 must not be pseudo-table.  It has to be a real table with
  4366   4368   ** multiple rows.
  4367   4369   **
................................................................................
  4393   4395     if( pOp->p4.z && pC->isTable && pOp->p5==0 ){
  4394   4396       i64 iKey = 0;
  4395   4397       sqlite3BtreeKeySize(pC->uc.pCursor, &iKey);
  4396   4398       assert( pC->movetoTarget==iKey ); 
  4397   4399     }
  4398   4400   #endif
  4399   4401   
  4400         -  /* Only flags that can be set are SAVEPOISTION and IDXDELETE */ 
  4401         -  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_IDXDELETE))==0 );
         4402  +  /* Only flags that can be set are SAVEPOISTION and AUXDELETE */ 
         4403  +  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
  4402   4404     assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION );
  4403         -  assert( OPFLAG_IDXDELETE==BTREE_IDXDELETE );
         4405  +  assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE );
  4404   4406   
  4405   4407   #ifdef SQLITE_DEBUG
  4406   4408     if( pC->isEphemeral==0
  4407         -   && (pOp->p5 & OPFLAG_IDXDELETE)==0
         4409  +   && (pOp->p5 & OPFLAG_AUXDELETE)==0
  4408   4410      && (pC->wrFlag & OPFLAG_FORDELETE)==0
  4409   4411     ){
  4410   4412       nExtraDelete++;
  4411   4413     }
  4412   4414     if( pOp->p2 & OPFLAG_NCHANGE ){
  4413   4415       nExtraDelete--;
  4414   4416     }
................................................................................
  4959   4961     r.default_rc = 0;
  4960   4962     r.aMem = &aMem[pOp->p2];
  4961   4963   #ifdef SQLITE_DEBUG
  4962   4964     {
  4963   4965       int i;
  4964   4966       for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) );
  4965   4967       if( pC->isEphemeral==0
  4966         -     && (pOp->p5 & OPFLAG_IDXDELETE)==0
         4968  +     && (pOp->p5 & OPFLAG_AUXDELETE)==0
  4967   4969        && (pC->wrFlag & OPFLAG_FORDELETE)==0
  4968   4970       ){
  4969   4971         nExtraDelete++;
  4970   4972       }
  4971   4973     }
  4972   4974   #endif
  4973   4975     rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);