From: drh Date: Mon, 17 Sep 2012 17:16:53 +0000 (+0000) Subject: Make sure the KeyInfo.aSortOrder array is always allocated so that we never X-Git-Tag: version-3.7.15~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1a022e48be1e7f40a8310e0f917fac8593c66a4;p=thirdparty%2Fsqlite.git 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 --- diff --git a/manifest b/manifest index 0a9b567d70..949d71190f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancement\sin\sthe\ssqlite3VdbeSerialType()\sroutine. -D 2012-09-17T15:36:31.241 +C Make\ssure\sthe\sKeyInfo.aSortOrder\sarray\sis\salways\sallocated\sso\sthat\swe\snever\nhave\sto\stest\sfor\sKeyInfo.aSortOrder==0\sin\sperformance-critical\sloops. +D 2012-09-17T17:16:53.958 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -130,7 +130,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 72a70dcfda75d3a1f81041ce4573e7afddcd8e4e F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/delete.c 335f36750dc6ac88d580aa36a6487459be9889de -F src/expr.c 217840a107dcc1e5dbb57cea311daad04bedbb9a +F src/expr.c 70ded09d6ac529718aec57589ddb378c23153693 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c c82a04e7a92bb728f9ab972b76590403283be2af F src/func.c b4e88b92838fdab8e0088cc8411c06664b4dcf55 @@ -174,7 +174,7 @@ F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 -F src/select.c 171ec5fd5eae6d7a19b54f8f0abdfdd9a1c8f3ad +F src/select.c 1278b07a8c9a7f2f65b8efa8565993a56c4a58a3 F src/shell.c 87953c5d9c73d9494db97d1607e2e2280418f261 F src/sqlite.h.in d1071b0fc6de9a0d11392bc01305803122c3ec61 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 @@ -240,7 +240,7 @@ F src/vdbe.c fd82787f9fb5bfb48dea822d41f28c2a73c25e2e F src/vdbe.h 18f581cac1f4339ec3299f3e0cc6e11aec654cdb F src/vdbeInt.h a668b303644377433e31a18d3d9efb87eefb6332 F src/vdbeapi.c 4c2418161cf45392ba76a7ca92f9a5f06b96f89c -F src/vdbeaux.c aeeee6c97e0c2ad31c376a781cb7462090b9827b +F src/vdbeaux.c fac025c798ad19070451b41eddc5dcd4696fdd1e F src/vdbeblob.c 32f2a4899d67f69634ea4dd93e3f651936d732cb F src/vdbemem.c cb55e84b8e2c15704968ee05f0fae25883299b74 F src/vdbesort.c 0dc1b274dcb4d4c8e71b0b2b15261f286caba39b @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 8711a8447d28275602287faf533de3d6e50d535d -R 34d4f192c96f51569b1d84a4c81787ab +P ad298f52efd0ff123a1a4d6a0fa16fbd4c6b6dad +R 399ab3eadb581c96415fb9d89f0fbcd1 U drh -Z c99f61ab4f3b0b408fc647ac1fcea198 +Z 939733a13ef406dcc12020fe5915f839 diff --git a/manifest.uuid b/manifest.uuid index 3a105ea7dc..ddfbcb8578 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad298f52efd0ff123a1a4d6a0fa16fbd4c6b6dad \ No newline at end of file +45793f0b844fee7445bc9269b403f89a58f77150 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 89172f94bf..3fb51cf11f 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 . */ r1 = sqlite3GetTempReg(pParse); diff --git a/src/select.c b/src/select.c index 0bf47e8521..656f39d6e8 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 dd23d395bd..9db3bf435c 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; jnField; 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( idx1nField ){ 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 && iaSortOrder[i] ){ + if( iaSortOrder[i] ){ rc = -rc; }