mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Add the BTREE_FORDELETE and BTREE_AUXDELETE flags to the b-tree layer interface
and use them. Add assert() statement to verify that they are correct. FossilOrigin-Name: 85c467041c9378cae3038756da815e9117ee8c7d
This commit is contained in:
44
src/btree.c
44
src/btree.c
@@ -4049,13 +4049,13 @@ int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){
|
||||
** on the database already. If a write-cursor is requested, then
|
||||
** the caller is assumed to have an open write transaction.
|
||||
**
|
||||
** If wrFlag==0, then the cursor can only be used for reading.
|
||||
** If wrFlag==1, then the cursor can be used for reading or for
|
||||
** writing if other conditions for writing are also met. These
|
||||
** are the conditions that must be met in order for writing to
|
||||
** be allowed:
|
||||
** If the BTREE_WRCSR bit of wrFlag is clear, then the cursor can only
|
||||
** be used for reading. If the BTREE_WRCSR bit is set, then the cursor
|
||||
** can be used for reading or for writing if other conditions for writing
|
||||
** are also met. These are the conditions that must be met in order
|
||||
** for writing to be allowed:
|
||||
**
|
||||
** 1: The cursor must have been opened with wrFlag==1
|
||||
** 1: The cursor must have been opened with wrFlag containing BTREE_WRCSR
|
||||
**
|
||||
** 2: Other database connections that share the same pager cache
|
||||
** but which are not in the READ_UNCOMMITTED state may not have
|
||||
@@ -4067,6 +4067,16 @@ int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){
|
||||
**
|
||||
** 4: There must be an active transaction.
|
||||
**
|
||||
** The BTREE_FORDELETE bit of wrFlag may optionally be set if BTREE_WRCSR
|
||||
** is set. If FORDELETE is set, that is a hint to the implementation that
|
||||
** this cursor will only be used to seek to and delete entries of an index
|
||||
** as part of a larger DELETE statement. The FORDELETE hint is not used by
|
||||
** this implementation. But in a hypothetical alternative storage engine
|
||||
** in which index entries are automatically deleted when corresponding table
|
||||
** rows are deleted, the FORDELETE flag is a hint that all SEEK and DELETE
|
||||
** operations on this cursor can be no-ops and all READ operations can
|
||||
** return a null row (2-bytes: 0x01 0x00).
|
||||
**
|
||||
** No checking is done to make sure that page iTable really is the
|
||||
** root page of a b-tree. If it is not, then the cursor acquired
|
||||
** will not work correctly.
|
||||
@@ -8082,13 +8092,21 @@ end_insert:
|
||||
/*
|
||||
** Delete the entry that the cursor is pointing to.
|
||||
**
|
||||
** If the second parameter is zero, then the cursor is left pointing at an
|
||||
** arbitrary location after the delete. If it is non-zero, 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 if the call to BtreeDelete() had
|
||||
** been omitted.
|
||||
** 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_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, int bPreserve){
|
||||
int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
||||
Btree *p = pCur->pBtree;
|
||||
BtShared *pBt = p->pBt;
|
||||
int rc; /* Return code */
|
||||
@@ -8098,6 +8116,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){
|
||||
int iCellDepth; /* Depth of node containing pCell */
|
||||
u16 szCell; /* Size of the cell being deleted */
|
||||
int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
|
||||
u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
|
||||
|
||||
assert( cursorOwnsBtShared(pCur) );
|
||||
assert( pBt->inTransaction==TRANS_WRITE );
|
||||
@@ -8107,6 +8126,7 @@ int sqlite3BtreeDelete(BtCursor *pCur, int bPreserve){
|
||||
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_AUXDELETE))==0 );
|
||||
|
||||
iCellDepth = pCur->iPage;
|
||||
iCellIdx = pCur->aiIdx[iCellDepth];
|
||||
|
Reference in New Issue
Block a user