aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2012-09-17 17:16:53 +0000
committerdrh <drh@noemail.net>2012-09-17 17:16:53 +0000
commite1a022e48be1e7f40a8310e0f917fac8593c66a4 (patch)
tree3e0b1ed603721516ca3782e3a08f80dffd754200 /src
parent56690b3d4935766cbe6a2d936e6371b03232ac04 (diff)
downloadsqlite-e1a022e48be1e7f40a8310e0f917fac8593c66a4.tar.gz
sqlite-e1a022e48be1e7f40a8310e0f917fac8593c66a4.zip
Make sure the KeyInfo.aSortOrder array is always allocated so that we never
have to test for KeyInfo.aSortOrder==0 in performance-critical loops. FossilOrigin-Name: 45793f0b844fee7445bc9269b403f89a58f77150
Diffstat (limited to 'src')
-rw-r--r--src/expr.c3
-rw-r--r--src/select.c1
-rw-r--r--src/vdbeaux.c14
3 files changed, 12 insertions, 6 deletions
diff --git a/src/expr.c b/src/expr.c
index 89172f94b..3fb51cf11 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1662,6 +1662,7 @@ int sqlite3CodeSubselect(
case TK_IN: {
char affinity; /* Affinity of the LHS of the IN */
KeyInfo keyInfo; /* Keyinfo for the generated table */
+ static u8 sortOrder = 0; /* Fake aSortOrder for keyInfo */
int addr; /* Address of OP_OpenEphemeral instruction */
Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
@@ -1689,6 +1690,7 @@ int sqlite3CodeSubselect(
if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
memset(&keyInfo, 0, sizeof(keyInfo));
keyInfo.nField = 1;
+ keyInfo.aSortOrder = &sortOrder;
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
/* Case 1: expr IN (SELECT ...)
@@ -1729,6 +1731,7 @@ int sqlite3CodeSubselect(
affinity = SQLITE_AFF_NONE;
}
keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
+ keyInfo.aSortOrder = &sortOrder;
/* Loop through each expression in <exprlist>. */
r1 = sqlite3GetTempReg(pParse);
diff --git a/src/select.c b/src/select.c
index 0bf47e852..656f39d6e 100644
--- a/src/select.c
+++ b/src/select.c
@@ -1892,6 +1892,7 @@ static int multiSelect(
*apColl = db->pDfltColl;
}
}
+ pKeyInfo->aSortOrder = (u8*)apColl;
for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
for(i=0; i<2; i++){
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index dd23d395b..9db3bf435 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -745,10 +745,9 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
u8 *aSortOrder;
memcpy((char*)pKeyInfo, zP4, nByte - nField);
aSortOrder = pKeyInfo->aSortOrder;
- if( aSortOrder ){
- pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
- memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
- }
+ assert( aSortOrder!=0 );
+ pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
+ memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
pOp->p4type = P4_KEYINFO;
}else{
p->db->mallocFailed = 1;
@@ -861,6 +860,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
case P4_KEYINFO: {
int i, j;
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
+ assert( pKeyInfo->aSortOrder!=0 );
sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
i = sqlite3Strlen30(zTemp);
for(j=0; j<pKeyInfo->nField; j++){
@@ -872,7 +872,7 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
break;
}
zTemp[i++] = ',';
- if( pKeyInfo->aSortOrder && pKeyInfo->aSortOrder[j] ){
+ if( pKeyInfo->aSortOrder[j] ){
zTemp[i++] = '-';
}
memcpy(&zTemp[i], pColl->zName,n+1);
@@ -2877,6 +2877,7 @@ UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
}
p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
+ assert( pKeyInfo->aSortOrder!=0 );
p->pKeyInfo = pKeyInfo;
p->nField = pKeyInfo->nField + 1;
return p;
@@ -2970,6 +2971,7 @@ int sqlite3VdbeRecordCompare(
idx1 = getVarint32(aKey1, szHdr1);
d1 = szHdr1;
nField = pKeyInfo->nField;
+ assert( pKeyInfo->aSortOrder!=0 );
while( idx1<szHdr1 && i<pPKey2->nField ){
u32 serial_type1;
@@ -2989,7 +2991,7 @@ int sqlite3VdbeRecordCompare(
assert( mem1.zMalloc==0 ); /* See comment below */
/* Invert the result if we are using DESC sort order. */
- if( pKeyInfo->aSortOrder && i<nField && pKeyInfo->aSortOrder[i] ){
+ if( i<nField && pKeyInfo->aSortOrder[i] ){
rc = -rc;
}