mirror of
https://github.com/sqlite/sqlite.git
synced 2026-01-06 08:01:16 +03:00
Remove an unnecessary parameter from sqlite3VdbeRecordUnpack(). Improved
comments and assert()s on KeyInfo. FossilOrigin-Name: 387f4c4d98b8fb83f6ae406e4143dabda7766e8752b7f6ca104655e51330c978
This commit is contained in:
@@ -872,7 +872,7 @@ static int btreeMoveto(
|
||||
assert( nKey==(i64)(int)nKey );
|
||||
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
|
||||
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
|
||||
sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
|
||||
sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey);
|
||||
if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
}else{
|
||||
|
||||
@@ -2648,6 +2648,11 @@ struct FKey {
|
||||
** are nKeyField slots for the columns of an index then extra slots
|
||||
** for the rowid or key at the end. The aSortOrder array is located after
|
||||
** the aColl[] array.
|
||||
**
|
||||
** If SQLITE_ENABLE_PREUPDATE_HOOK is defined, then aSortFlags might be NULL
|
||||
** to indicate that this object is for use by a preupdate hook. When aSortFlags
|
||||
** is NULL, then nAllField is uninitialized and no space is allocated for
|
||||
** aColl[], so those fields may not be used.
|
||||
*/
|
||||
struct KeyInfo {
|
||||
u32 nRef; /* Number of references to this KeyInfo object */
|
||||
@@ -2659,7 +2664,9 @@ struct KeyInfo {
|
||||
CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
|
||||
};
|
||||
|
||||
/* The size (in bytes) of a KeyInfo object with up to N fields */
|
||||
/* The size (in bytes) of a KeyInfo object with up to N fields. This includes
|
||||
** the main body of the KeyInfo object and the aColl[] array of N elements,
|
||||
** but does not count the memory used to hold aSortFlags[]. */
|
||||
#define SZ_KEYINFO(N) (offsetof(KeyInfo,aColl) + (N)*sizeof(CollSeq*))
|
||||
|
||||
/* The size of a bare KeyInfo with no aColl[] entries */
|
||||
@@ -2687,9 +2694,8 @@ struct KeyInfo {
|
||||
**
|
||||
** An instance of this object serves as a "key" for doing a search on
|
||||
** an index b+tree. The goal of the search is to find the entry that
|
||||
** is closed to the key described by this object. This object might hold
|
||||
** just a prefix of the key. The number of fields is given by
|
||||
** pKeyInfo->nField.
|
||||
** is closest to the key described by this object. This object might hold
|
||||
** just a prefix of the key. The number of fields is given by nField.
|
||||
**
|
||||
** The r1 and r2 fields are the values to return if this key is less than
|
||||
** or greater than a key in the btree, respectively. These are normally
|
||||
@@ -2699,7 +2705,7 @@ struct KeyInfo {
|
||||
** The key comparison functions actually return default_rc when they find
|
||||
** an equals comparison. default_rc can be -1, 0, or +1. If there are
|
||||
** multiple entries in the b-tree with the same key (when only looking
|
||||
** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to
|
||||
** at the first nField elements) then default_rc can be set to -1 to
|
||||
** cause the search to find the last match, or +1 to cause the search to
|
||||
** find the first match.
|
||||
**
|
||||
@@ -2711,8 +2717,8 @@ struct KeyInfo {
|
||||
** b-tree.
|
||||
*/
|
||||
struct UnpackedRecord {
|
||||
KeyInfo *pKeyInfo; /* Collation and sort-order information */
|
||||
Mem *aMem; /* Values */
|
||||
KeyInfo *pKeyInfo; /* Comparison info for the index that is unpacked */
|
||||
Mem *aMem; /* Values for columns of the index */
|
||||
union {
|
||||
char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
|
||||
i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
|
||||
|
||||
@@ -2476,6 +2476,7 @@ case OP_Compare: {
|
||||
pKeyInfo = pOp->p4.pKeyInfo;
|
||||
assert( n>0 );
|
||||
assert( pKeyInfo!=0 );
|
||||
assert( pKeyInfo->aSortFlags!=0 );
|
||||
p1 = pOp->p1;
|
||||
p2 = pOp->p2;
|
||||
#ifdef SQLITE_DEBUG
|
||||
@@ -5349,7 +5350,7 @@ case OP_Found: { /* jump, in3, ncycle */
|
||||
if( rc ) goto no_mem;
|
||||
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
|
||||
if( pIdxKey==0 ) goto no_mem;
|
||||
sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey);
|
||||
sqlite3VdbeRecordUnpack(r.aMem->n, r.aMem->z, pIdxKey);
|
||||
pIdxKey->default_rc = 0;
|
||||
rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
|
||||
sqlite3DbFreeNN(db, pIdxKey);
|
||||
|
||||
@@ -301,7 +301,7 @@ void sqlite3VdbeSetVarmask(Vdbe*, int);
|
||||
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
int sqlite3BlobCompare(const Mem*, const Mem*);
|
||||
|
||||
void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
|
||||
void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*);
|
||||
int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
|
||||
int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
|
||||
UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
|
||||
|
||||
@@ -2163,7 +2163,7 @@ static UnpackedRecord *vdbeUnpackRecord(
|
||||
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
|
||||
if( pRet ){
|
||||
memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
|
||||
sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
|
||||
sqlite3VdbeRecordUnpack(nKey, pKey, pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
@@ -4218,7 +4218,6 @@ UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
|
||||
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
|
||||
if( !p ) return 0;
|
||||
p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
|
||||
assert( pKeyInfo->aSortFlags!=0 );
|
||||
p->pKeyInfo = pKeyInfo;
|
||||
p->nField = pKeyInfo->nKeyField + 1;
|
||||
return p;
|
||||
@@ -4230,7 +4229,6 @@ UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
|
||||
** contents of the decoded record.
|
||||
*/
|
||||
void sqlite3VdbeRecordUnpack(
|
||||
KeyInfo *pKeyInfo, /* Information about the record format */
|
||||
int nKey, /* Size of the binary record */
|
||||
const void *pKey, /* The binary record */
|
||||
UnpackedRecord *p /* Populate this structure before returning. */
|
||||
@@ -4241,9 +4239,9 @@ void sqlite3VdbeRecordUnpack(
|
||||
u16 u; /* Unsigned loop counter */
|
||||
u32 szHdr;
|
||||
Mem *pMem = p->aMem;
|
||||
KeyInfo *pKeyInfo = p->pKeyInfo;
|
||||
|
||||
p->default_rc = 0;
|
||||
assert( p->pKeyInfo==pKeyInfo );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
|
||||
idx = getVarint32(aKey, szHdr);
|
||||
d = szHdr;
|
||||
@@ -5130,6 +5128,7 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
|
||||
** The easiest way to enforce this limit is to consider only records with
|
||||
** 13 fields or less. If the first field is an integer, the maximum legal
|
||||
** header size is (12*5 + 1 + 1) bytes. */
|
||||
assert( p->pKeyInfo->aSortFlags!=0 );
|
||||
if( p->pKeyInfo->nAllField<=13 ){
|
||||
int flags = p->aMem[0].flags;
|
||||
if( p->pKeyInfo->aSortFlags[0] ){
|
||||
@@ -5488,7 +5487,6 @@ void sqlite3VdbePreUpdateHook(
|
||||
i64 iKey2;
|
||||
PreUpdate preupdate;
|
||||
const char *zTbl = pTab->zName;
|
||||
static const u8 fakeSortOrder = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
int nRealCol;
|
||||
if( pTab->tabFlags & TF_WithoutRowid ){
|
||||
@@ -5527,7 +5525,7 @@ void sqlite3VdbePreUpdateHook(
|
||||
preupdate.pKeyinfo->db = db;
|
||||
preupdate.pKeyinfo->enc = ENC(db);
|
||||
preupdate.pKeyinfo->nKeyField = pTab->nCol;
|
||||
preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder;
|
||||
preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
|
||||
preupdate.iKey1 = iKey1;
|
||||
preupdate.iKey2 = iKey2;
|
||||
preupdate.pTab = pTab;
|
||||
|
||||
@@ -766,7 +766,7 @@ static int vdbeSorterCompareTail(
|
||||
){
|
||||
UnpackedRecord *r2 = pTask->pUnpacked;
|
||||
if( *pbKey2Cached==0 ){
|
||||
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
|
||||
sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
|
||||
*pbKey2Cached = 1;
|
||||
}
|
||||
return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
|
||||
@@ -793,7 +793,7 @@ static int vdbeSorterCompare(
|
||||
){
|
||||
UnpackedRecord *r2 = pTask->pUnpacked;
|
||||
if( !*pbKey2Cached ){
|
||||
sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
|
||||
sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
|
||||
*pbKey2Cached = 1;
|
||||
}
|
||||
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
|
||||
@@ -833,6 +833,7 @@ static int vdbeSorterCompareText(
|
||||
);
|
||||
}
|
||||
}else{
|
||||
assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
|
||||
assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
|
||||
if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
|
||||
res = res * -1;
|
||||
@@ -896,6 +897,7 @@ static int vdbeSorterCompareInt(
|
||||
}
|
||||
}
|
||||
|
||||
assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
|
||||
if( res==0 ){
|
||||
if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
|
||||
res = vdbeSorterCompareTail(
|
||||
@@ -2769,7 +2771,7 @@ int sqlite3VdbeSorterCompare(
|
||||
assert( r2->nField==nKeyCol );
|
||||
|
||||
pKey = vdbeSorterRowkey(pSorter, &nKey);
|
||||
sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
|
||||
sqlite3VdbeRecordUnpack(nKey, pKey, r2);
|
||||
for(i=0; i<nKeyCol; i++){
|
||||
if( r2->aMem[i].flags & MEM_Null ){
|
||||
*pRes = -1;
|
||||
|
||||
Reference in New Issue
Block a user