diff options
author | drh <drh@noemail.net> | 2013-08-05 19:11:29 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2013-08-05 19:11:29 +0000 |
commit | 323df7907ea733e5bfada834df934cd00565e3ab (patch) | |
tree | e196ce29001c0d55e536f9b6cdd2b6a400cb9280 /src/expr.c | |
parent | af5b2af77db148fb390a9423b70229e721c0d1ba (diff) | |
download | sqlite-323df7907ea733e5bfada834df934cd00565e3ab.tar.gz sqlite-323df7907ea733e5bfada834df934cd00565e3ab.zip |
Factor all KeyInfo object allocations into a single function:
sqlite3KeyInfoAlloc(). Always allocate enough space so that
sqlite3VdbeRecordCompare() can avoid checking boundaries and hence
run faster.
FossilOrigin-Name: 7301bedd94c8610568349953b18ff3575203e1b2
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/expr.c b/src/expr.c index e7ac855f7..3857d5d84 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1692,10 +1692,9 @@ int sqlite3CodeSubselect( switch( pExpr->op ){ 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 */ + KeyInfo *pKeyInfo = 0; /* Key information */ if( rMayHaveNull ){ sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull); @@ -1719,9 +1718,7 @@ int sqlite3CodeSubselect( pExpr->iTable = pParse->nTab++; addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid); if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED); - memset(&keyInfo, 0, sizeof(keyInfo)); - keyInfo.nField = 1; - keyInfo.aSortOrder = &sortOrder; + pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1); if( ExprHasProperty(pExpr, EP_xIsSelect) ){ /* Case 1: expr IN (SELECT ...) @@ -1738,11 +1735,12 @@ int sqlite3CodeSubselect( assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); pExpr->x.pSelect->iLimit = 0; if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){ + sqlite3DbFree(pParse->db, pKeyInfo); return 0; } pEList = pExpr->x.pSelect->pEList; - if( ALWAYS(pEList!=0 && pEList->nExpr>0) ){ - keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, + if( pKeyInfo && ALWAYS(pEList!=0 && pEList->nExpr>0) ){ + pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft, pEList->a[0].pExpr); } }else if( ALWAYS(pExpr->x.pList!=0) ){ @@ -1761,8 +1759,9 @@ int sqlite3CodeSubselect( if( !affinity ){ affinity = SQLITE_AFF_NONE; } - keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft); - keyInfo.aSortOrder = &sortOrder; + if( pKeyInfo ){ + pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft); + } /* Loop through each expression in <exprlist>. */ r1 = sqlite3GetTempReg(pParse); @@ -1801,8 +1800,8 @@ int sqlite3CodeSubselect( sqlite3ReleaseTempReg(pParse, r1); sqlite3ReleaseTempReg(pParse, r2); } - if( !isRowid ){ - sqlite3VdbeChangeP4(v, addr, (void *)&keyInfo, P4_KEYINFO); + if( pKeyInfo ){ + sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO_HANDOFF); } break; } |