SQLite

Check-in [1d3bf6bebd]
Login

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
Timelines: family | ancestors | descendants | both | fordelete-assert
Files: files | file ages | folders
SHA1: 1d3bf6bebdda9f96734bc139601e9b05344ea0b4
User & Date: drh 2016-01-27 16:26:25.226
Context
2016-01-28
17:06
Modifications to ensure the nExtraDelete-related assert() statement does not fail. (check-in: f43ff8f82d 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: 1d3bf6bebd user: drh tags: fordelete-assert)
16:17
Fix tests in fordelete.test to test for the BTREE_AUXDELETE flag. (check-in: bbd25cf179 user: dan tags: fordelete-assert)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/btree.c.
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103






8104
8105
8106
8107
8108
8109
8110
8094
8095
8096
8097
8098
8099
8100



8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113







-
-
-
+
+
+
+
+
+







**
** If the BTREE_SAVEPOSITION bit of the flags parameter is zero, then
** the cursor is left pointing at an arbitrary location after the delete.
** But if that bit is set, then the cursor is left in a state such that
** the next call to BtreeNext() or BtreePrev() moves it to the same row
** as it would have been on if the call to BtreeDelete() had been omitted.
**
** The BTREE_IDXDELETE bit of flags indicates that this is a delete of
** an index entry where the corresponding table row has already been deleted.
** The BTREE_IDXDELETE bit is a hint that is not used by this implementation,
** The BTREE_AUXDELETE bit of flags indicates that is one of several deletes
** associated with a single table entry and its indexes.  Only one of those
** deletes is considered the "primary" delete.  The primary delete occurs
** on a cursor that is not a BTREE_FORDELETE cursor.  All but one delete
** operation on non-FORDELETE cursors is tagged with the AUXDELETE flag.
** The BTREE_AUXDELETE bit is a hint that is not used by this implementation,
** but which might be used by alternative storage engines.
*/
int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
  Btree *p = pCur->pBtree;
  BtShared *pBt = p->pBt;              
  int rc;                              /* Return code */
  MemPage *pPage;                      /* Page to delete cell from */
8119
8120
8121
8122
8123
8124
8125
8126

8127
8128
8129
8130
8131
8132
8133
8122
8123
8124
8125
8126
8127
8128

8129
8130
8131
8132
8133
8134
8135
8136







-
+







  assert( pBt->inTransaction==TRANS_WRITE );
  assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
  assert( pCur->curFlags & BTCF_WriteFlag );
  assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
  assert( !hasReadConflicts(p, pCur->pgnoRoot) );
  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
  assert( pCur->eState==CURSOR_VALID );
  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_IDXDELETE))==0 );
  assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );

  iCellDepth = pCur->iPage;
  iCellIdx = pCur->aiIdx[iCellDepth];
  pPage = pCur->apPage[iCellDepth];
  pCell = findCell(pPage, iCellIdx);

  /* If the page containing the entry to delete is not a leaf page, move
Changes to src/btree.h.
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259







-
+







);
int sqlite3BtreeCursorHasMoved(BtCursor*);
int sqlite3BtreeCursorRestore(BtCursor*, int*);
int sqlite3BtreeDelete(BtCursor*, u8 flags);

/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
#define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
#define BTREE_IDXDELETE    0x04  /* this is index, table row already deleted */
#define BTREE_AUXDELETE    0x04  /* not the primary delete operation */

int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
                                  const void *pData, int nData,
                                  int nZero, int bias, int seekResult);
int sqlite3BtreeFirst(BtCursor*, int *pRes);
int sqlite3BtreeLast(BtCursor*, int *pRes);
int sqlite3BtreeNext(BtCursor*, int *pRes);
Changes to src/delete.c.
720
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737
738
739
720
721
722
723
724
725
726

727

728
729
730

731
732
733
734
735
736
737







-
+
-



-







    u8 p5 = 0;
    sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
    sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
    if( count ){
      sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
    }
    if( eMode!=ONEPASS_OFF ){
      sqlite3VdbeChangeP5(v, OPFLAG_IDXDELETE);
      sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
      p5 = OPFLAG_IDXDELETE;
    }
    if( iIdxNoSeek>=0 ){
      sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
      p5 = 0;
    }
    if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
    sqlite3VdbeChangeP5(v, p5);
  }

  /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
  ** handle rows (possibly in other tables) that refer via a foreign key
Changes to src/sqliteInt.h.
2858
2859
2860
2861
2862
2863
2864
2865

2866
2867
2868
2869
2870
2871
2872
2858
2859
2860
2861
2862
2863
2864

2865
2866
2867
2868
2869
2870
2871
2872







-
+







#define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */
#define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */
#define OPFLAG_SEEKEQ        0x02    /* OP_Open** cursor uses EQ seek only */
#define OPFLAG_FORDELETE     0x08    /* OP_Open should use BTREE_FORDELETE */
#define OPFLAG_P2ISREG       0x10    /* P2 to OP_Open** is a register number */
#define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete: keep cursor position */
#define OPFLAG_IDXDELETE     0x04    /* OP_Delete: index in a DELETE op */
#define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */

/*
 * Each trigger present in the database schema is stored as an instance of
 * struct Trigger. 
 *
 * Pointers to instances of struct Trigger are stored in two ways.
 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 
Changes to src/vdbe.c.
549
550
551
552
553
554
555
556

557
558
559
560
561
562
563
549
550
551
552
553
554
555

556
557
558
559
560
561
562
563







-
+







){
  Op *aOp = p->aOp;          /* Copy of p->aOp */
  Op *pOp = aOp;             /* Current operation */
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
  Op *pOrigOp;               /* Value of pOp at the top of the loop */
#endif
#ifdef SQLITE_DEBUG
  int nExtraDelete = 0;      /* Verifies FORDELETE and IDXDELETE flags */
  int nExtraDelete = 0;      /* Verifies FORDELETE and AUXDELETE flags */
#endif
  int rc = SQLITE_OK;        /* Value to return */
  sqlite3 *db = p->db;       /* The database */
  u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
  u8 encoding = ENC(db);     /* The database encoding */
  int iCompare = 0;          /* Result of last OP_Compare operation */
  unsigned nVmStep = 0;      /* Number of virtual machine steps */
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360





4361
4362
4363
4364
4365
4366
4367
4351
4352
4353
4354
4355
4356
4357



4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369







-
-
-
+
+
+
+
+







** the cursor will be left pointing at  either the next or the previous
** record in the table. If it is left pointing at the next record, then
** the next Next instruction will be a no-op. As a result, in this case
** it is ok to delete a record from within a Next loop. If 
** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
** left in an undefined state.
**
** If the OPFLAG_IDXDELETE bit is set on P5, that indicates that this
** delete is on an index cursor where the corresponding table row has
** already been deleted.
** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
** delete one of several associated with deleting a table row and all its
** associated index entries.  Exactly one of those deletes is the "primary"
** delete.  The others are all on OPFLAG_FORDELETE cursors or else are
** marked with the AUXDELETE flag.
**
** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row
** change count is incremented (otherwise not).
**
** P1 must not be pseudo-table.  It has to be a real table with
** multiple rows.
**
4393
4394
4395
4396
4397
4398
4399
4400
4401


4402
4403

4404
4405
4406
4407

4408
4409
4410
4411
4412
4413
4414
4395
4396
4397
4398
4399
4400
4401


4402
4403
4404

4405
4406
4407
4408

4409
4410
4411
4412
4413
4414
4415
4416







-
-
+
+

-
+



-
+







  if( pOp->p4.z && pC->isTable && pOp->p5==0 ){
    i64 iKey = 0;
    sqlite3BtreeKeySize(pC->uc.pCursor, &iKey);
    assert( pC->movetoTarget==iKey ); 
  }
#endif

  /* Only flags that can be set are SAVEPOISTION and IDXDELETE */ 
  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_IDXDELETE))==0 );
  /* Only flags that can be set are SAVEPOISTION and AUXDELETE */ 
  assert( (pOp->p5 & ~(OPFLAG_SAVEPOSITION|OPFLAG_AUXDELETE))==0 );
  assert( OPFLAG_SAVEPOSITION==BTREE_SAVEPOSITION );
  assert( OPFLAG_IDXDELETE==BTREE_IDXDELETE );
  assert( OPFLAG_AUXDELETE==BTREE_AUXDELETE );

#ifdef SQLITE_DEBUG
  if( pC->isEphemeral==0
   && (pOp->p5 & OPFLAG_IDXDELETE)==0
   && (pOp->p5 & OPFLAG_AUXDELETE)==0
   && (pC->wrFlag & OPFLAG_FORDELETE)==0
  ){
    nExtraDelete++;
  }
  if( pOp->p2 & OPFLAG_NCHANGE ){
    nExtraDelete--;
  }
4959
4960
4961
4962
4963
4964
4965
4966

4967
4968
4969
4970
4971
4972
4973
4961
4962
4963
4964
4965
4966
4967

4968
4969
4970
4971
4972
4973
4974
4975







-
+







  r.default_rc = 0;
  r.aMem = &aMem[pOp->p2];
#ifdef SQLITE_DEBUG
  {
    int i;
    for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) );
    if( pC->isEphemeral==0
     && (pOp->p5 & OPFLAG_IDXDELETE)==0
     && (pOp->p5 & OPFLAG_AUXDELETE)==0
     && (pC->wrFlag & OPFLAG_FORDELETE)==0
    ){
      nExtraDelete++;
    }
  }
#endif
  rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);