diff options
author | drh <drh@noemail.net> | 2004-05-28 16:00:21 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2004-05-28 16:00:21 +0000 |
commit | 51846b56edaba72e986cd7128f38547690c48671 (patch) | |
tree | f6b4001f3d42bdca49717dff08c6b7d0b135c11d /src/delete.c | |
parent | 76d505baadc5afeaab6cdfb862c8a666a9f2eb5c (diff) | |
download | sqlite-51846b56edaba72e986cd7128f38547690c48671.tar.gz sqlite-51846b56edaba72e986cd7128f38547690c48671.zip |
Factor common code for generating index keys into a procedure. Other
speed improvements and bug fixes. (CVS 1487)
FossilOrigin-Name: 6661bb5f9c1692f94b8b7d900b6be07f027e6324
Diffstat (limited to 'src/delete.c')
-rw-r--r-- | src/delete.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/delete.c b/src/delete.c index 2e69961d7..bd77b59bc 100644 --- a/src/delete.c +++ b/src/delete.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle DELETE FROM statements. ** -** $Id: delete.c,v 1.70 2004/05/26 10:11:05 danielk1977 Exp $ +** $Id: delete.c,v 1.71 2004/05/28 16:00:22 drh Exp $ */ #include "sqliteInt.h" @@ -379,17 +379,34 @@ void sqlite3GenerateRowIndexDelete( for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){ int j; if( aIdxUsed!=0 && aIdxUsed[i-1]==0 ) continue; - sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); - for(j=0; j<pIdx->nColumn; j++){ - int idx = pIdx->aiColumn[j]; - if( idx==pTab->iPKey ){ - sqlite3VdbeAddOp(v, OP_Dup, j, 0); - }else{ - sqlite3VdbeAddOp(v, OP_Column, iCur, idx); - } - } - sqlite3VdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0); - sqlite3IndexAffinityStr(v, pIdx); + sqlite3GenerateIndexKey(v, pIdx, iCur); sqlite3VdbeAddOp(v, OP_IdxDelete, iCur+i, 0); } } + +/* +** Generate code that will assemble an index key and put it on the top +** of the tack. The key with be for index pIdx which is an index on pTab. +** iCur is the index of a cursor open on the pTab table and pointing to +** the entry that needs indexing. +*/ +void sqlite3GenerateIndexKey( + Vdbe *v, /* Generate code into this VDBE */ + Index *pIdx, /* The index for which to generate a key */ + int iCur /* Cursor number for the pIdx->pTable table */ +){ + int j; + Table *pTab = pIdx->pTable; + + sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); + for(j=0; j<pIdx->nColumn; j++){ + int idx = pIdx->aiColumn[j]; + if( idx==pTab->iPKey ){ + sqlite3VdbeAddOp(v, OP_Dup, j, 0); + }else{ + sqlite3VdbeAddOp(v, OP_Column, iCur, idx); + } + } + sqlite3VdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0); + sqlite3IndexAffinityStr(v, pIdx); +} |