Streamline the processing of the AND operator. Slightly smaller and faster.
FossilOrigin-Name: 7713996aa99ce6dd35b5a2db74dd26658fb8d9817169b2a7531cdef6edb41403
This commit is contained in:
parent
680f0fe32a
commit
d5c851c1cb
24
manifest
24
manifest
@ -1,5 +1,5 @@
|
||||
C Small\sperformance\sand\ssize\soptimization\sin\ssqlite3WalFindFrame().
|
||||
D 2019-04-17T21:12:05.934
|
||||
C Streamline\sthe\sprocessing\sof\sthe\sAND\soperator.\s\sSlightly\ssmaller\sand\sfaster.
|
||||
D 2019-04-19T13:38:34.610
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -470,9 +470,9 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
|
||||
F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7
|
||||
F src/dbstat.c c12833de69cb655751487d2c5a59607e36be1c58ba1f4bd536609909ad47b319
|
||||
F src/delete.c d08c9e01a2664afd12edcfa3a9c6578517e8ff8735f35509582693adbe0edeaf
|
||||
F src/expr.c e100212835d20498780e7c6d2bdb16c677ecc04350fb75db3bf192a86ba48c92
|
||||
F src/expr.c d9b219b2a20f9a99712c24b6c6b21588006260eb3f8bdc96df8262869b58512a
|
||||
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
|
||||
F src/fkey.c bd0138acdc008c1845ccf92f8e73787880562de649471804801c06fed814c765
|
||||
F src/fkey.c 0e14d4bef8eac2d87bbd517e492d9084c65008d117823f8922c5e7b2b599bd33
|
||||
F src/func.c 2ccf4ae12430b1ae7096be5f0675887e1bd0732828af0ac0f7496339b7c6edee
|
||||
F src/global.c 0dea3065ea72a65ae941559b6686aad6516d4913e76fa4f79a95ff7787f624ec
|
||||
F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19
|
||||
@ -507,7 +507,7 @@ F src/os_win.c 85d9e532d0444ab6c16d7431490c2e279e282aa0917b0e988996b1ae0de5c5a0
|
||||
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
|
||||
F src/pager.c 422fd8cfa59fb9173eff36a95878904a0eeb0dcc62ba49350acc8b1e51c4dc7b
|
||||
F src/pager.h 217921e81eb5fe455caa5cda96061959706bcdd29ddb57166198645ef7822ac3
|
||||
F src/parse.y 8de9b1da4dc0f9615cfa9f4cbdd368b4ac822e1cbbc57b0fe071d9a83988df6d
|
||||
F src/parse.y 22f64d8a8910acd17580450513b58d64187b0962848380c7f0a39376b8a48cee
|
||||
F src/pcache.c 696a01f1a6370c1b50a09c15972bc3bee3333f8fcd1f2da8e9a76b1b062c59ee
|
||||
F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
|
||||
F src/pcache1.c be64b2f3908a7f97c56c963676eb12f0d6254c95b28cdc1d73a186eff213219d
|
||||
@ -518,12 +518,12 @@ F src/printf.c 67f79227273a9009d86a017619717c3f554f50b371294526da59faa6014ed2cd
|
||||
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
|
||||
F src/resolve.c 567888ee3faec14dae06519b4306201771058364a37560186a3e0e755ebc4cb8
|
||||
F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
|
||||
F src/select.c 9263f5c30dd44c7ac2eb29f40a7ec64322a96885b71c00de6bc30b756c2e1c49
|
||||
F src/select.c e6c6a75e9aac747ea26b5e2d1d7a9af50b813ea5524d4ec556a0afc72a6d69d4
|
||||
F src/shell.c.in 0d1a1abd8f1056ac6b32981442618e988e1e192cec2e904e58c72fcf494c901e
|
||||
F src/sqlite.h.in 38390767acc1914d58930e03149595ee4710afa4e3c43ab6c3a8aea3f1a6b8cd
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 9ecc93b8493bd20c0c07d52e2ac0ed8bab9b549c7f7955b59869597b650dd8b5
|
||||
F src/sqliteInt.h d229b6a5f70fe6c57d2f91f0edc60a9c4437397b4a5b59fd72fe9eb3b94d3437
|
||||
F src/sqliteInt.h 3a9497a4d7261e348390a1390d00d50f51ebab2ee97335b287447aa9e12bf543
|
||||
F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
|
||||
F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e
|
||||
F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
|
||||
@ -604,9 +604,9 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
||||
F src/wal.c b09a2a9cab50efa08451a8c81d47052120ad5da174048c6d0b08d405384abdf2
|
||||
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
|
||||
F src/walker.c 7607f1a68130c028255d8d56094ea602fc402c79e1e35a46e6282849d90d5fe4
|
||||
F src/where.c ff2955dc2743c1af05ba5a8232ab72724d9a63b76dbee256368f40fd3ef82db5
|
||||
F src/where.c 99c7b718ef846ac952016083aaf4e22ede2290beceaf4730a2df55c023251369
|
||||
F src/whereInt.h 5f14db426ca46a83eabab1ae9aa6d4b8f27504ad35b64c290916289b1ddb2e88
|
||||
F src/wherecode.c 83be72e8d1c0231d0db06ffe5cfd32c7834bd00d2ed869306a2c1e0828488752
|
||||
F src/wherecode.c 0e76672930bea322eb3606d891a4744be55c09bcd3a995bfd501af62a46e0625
|
||||
F src/whereexpr.c 90859652920f153d2c03f075488744be2926625ebd36911bcbcb17d0d29c891c
|
||||
F src/window.c 038c248267e74ff70a2bb9b1884d40fd145c5183b017823ecb6cbb14bc781478
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
@ -1818,7 +1818,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 57638248de147efe8d663b3ae1389f590c7b2b7225ecfe295699d68c2893cd09
|
||||
R f55569b51e361d573aabfbfaa6d9bc9b
|
||||
P 03f2e78899fad99b0a0951b3a408268276954d4cd785389ed9a0192c9217f6fe
|
||||
R 4d121f6250fa4d728fb8a46a98d547d3
|
||||
U drh
|
||||
Z 08f602e532329cf65b2b6561fc1b8227
|
||||
Z 1c6157db33fa1baf603ced1f230aa369
|
||||
|
@ -1 +1 @@
|
||||
03f2e78899fad99b0a0951b3a408268276954d4cd785389ed9a0192c9217f6fe
|
||||
7713996aa99ce6dd35b5a2db74dd26658fb8d9817169b2a7531cdef6edb41403
|
31
src/expr.c
31
src/expr.c
@ -850,20 +850,16 @@ Expr *sqlite3PExpr(
|
||||
Expr *pRight /* Right operand */
|
||||
){
|
||||
Expr *p;
|
||||
if( op==TK_AND && pParse->nErr==0 && !IN_RENAME_OBJECT ){
|
||||
/* Take advantage of short-circuit false optimization for AND */
|
||||
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
|
||||
}else{
|
||||
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
|
||||
if( p ){
|
||||
memset(p, 0, sizeof(Expr));
|
||||
p->op = op & 0xff;
|
||||
p->iAgg = -1;
|
||||
}
|
||||
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
|
||||
if( p ){
|
||||
memset(p, 0, sizeof(Expr));
|
||||
p->op = op & 0xff;
|
||||
p->iAgg = -1;
|
||||
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
|
||||
}
|
||||
if( p ) {
|
||||
sqlite3ExprCheckHeight(pParse, p->nHeight);
|
||||
}else{
|
||||
sqlite3ExprDelete(pParse->db, pLeft);
|
||||
sqlite3ExprDelete(pParse->db, pRight);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -919,19 +915,20 @@ static int exprAlwaysFalse(Expr *p){
|
||||
** of returning an AND expression, just return a constant expression with
|
||||
** a value of false.
|
||||
*/
|
||||
Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
|
||||
if( pLeft==0 ){
|
||||
Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
|
||||
sqlite3 *db = pParse->db;
|
||||
if( pLeft==0 ){
|
||||
return pRight;
|
||||
}else if( pRight==0 ){
|
||||
return pLeft;
|
||||
}else if( pParse->nErr || IN_RENAME_OBJECT ){
|
||||
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
|
||||
}else if( exprAlwaysFalse(pLeft) || exprAlwaysFalse(pRight) ){
|
||||
sqlite3ExprDelete(db, pLeft);
|
||||
sqlite3ExprDelete(db, pRight);
|
||||
return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
|
||||
}else{
|
||||
Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
|
||||
sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
|
||||
return pNew;
|
||||
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
|
||||
}
|
||||
}
|
||||
|
||||
|
10
src/fkey.c
10
src/fkey.c
@ -591,7 +591,7 @@ static void fkScanChildren(
|
||||
zCol = pFKey->pFrom->aCol[iCol].zName;
|
||||
pRight = sqlite3Expr(db, TK_ID, zCol);
|
||||
pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
|
||||
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
|
||||
pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
|
||||
}
|
||||
|
||||
/* If the child table is the same as the parent table, then add terms
|
||||
@ -625,11 +625,11 @@ static void fkScanChildren(
|
||||
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
|
||||
pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
|
||||
pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
|
||||
pAll = sqlite3ExprAnd(db, pAll, pEq);
|
||||
pAll = sqlite3ExprAnd(pParse, pAll, pEq);
|
||||
}
|
||||
pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
|
||||
}
|
||||
pWhere = sqlite3ExprAnd(db, pWhere, pNe);
|
||||
pWhere = sqlite3ExprAnd(pParse, pWhere, pNe);
|
||||
}
|
||||
|
||||
/* Resolve the references in the WHERE clause. */
|
||||
@ -1235,7 +1235,7 @@ static Trigger *fkActionTrigger(
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
|
||||
);
|
||||
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
|
||||
pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
|
||||
|
||||
/* For ON UPDATE, construct the next term of the WHEN clause.
|
||||
** The final WHEN clause will be like this:
|
||||
@ -1251,7 +1251,7 @@ static Trigger *fkActionTrigger(
|
||||
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
|
||||
sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
|
||||
);
|
||||
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
|
||||
pWhen = sqlite3ExprAnd(pParse, pWhen, pEq);
|
||||
}
|
||||
|
||||
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
|
||||
|
@ -1064,7 +1064,7 @@ expr(A) ::= LP nexprlist(X) COMMA expr(Y) RP. {
|
||||
}
|
||||
}
|
||||
|
||||
expr(A) ::= expr(A) AND(OP) expr(Y). {A=sqlite3PExpr(pParse,@OP,A,Y);}
|
||||
expr(A) ::= expr(A) AND expr(Y). {A=sqlite3ExprAnd(pParse,A,Y);}
|
||||
expr(A) ::= expr(A) OR(OP) expr(Y). {A=sqlite3PExpr(pParse,@OP,A,Y);}
|
||||
expr(A) ::= expr(A) LT|GT|GE|LE(OP) expr(Y).
|
||||
{A=sqlite3PExpr(pParse,@OP,A,Y);}
|
||||
|
12
src/select.c
12
src/select.c
@ -355,7 +355,7 @@ static void addWhereTerm(
|
||||
ExprSetVVAProperty(pEq, EP_NoReduce);
|
||||
pEq->iRightJoinTable = (i16)pE2->iTable;
|
||||
}
|
||||
*ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
|
||||
*ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -489,7 +489,7 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){
|
||||
*/
|
||||
if( pRight->pOn ){
|
||||
if( isOuter ) setJoinExpr(pRight->pOn, pRight->iCursor);
|
||||
p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);
|
||||
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->pOn);
|
||||
pRight->pOn = 0;
|
||||
}
|
||||
|
||||
@ -4034,7 +4034,7 @@ static int flattenSubquery(
|
||||
if( isLeftJoin>0 ){
|
||||
setJoinExpr(pWhere, iNewParent);
|
||||
}
|
||||
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
|
||||
pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere);
|
||||
if( db->mallocFailed==0 ){
|
||||
SubstContext x;
|
||||
x.pParse = pParse;
|
||||
@ -4369,9 +4369,9 @@ static int pushDownWhereTerms(
|
||||
x.pEList = pSubq->pEList;
|
||||
pNew = substExpr(&x, pNew);
|
||||
if( pSubq->selFlags & SF_Aggregate ){
|
||||
pSubq->pHaving = sqlite3ExprAnd(pParse->db, pSubq->pHaving, pNew);
|
||||
pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew);
|
||||
}else{
|
||||
pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
|
||||
pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew);
|
||||
}
|
||||
pSubq = pSubq->pPrior;
|
||||
}
|
||||
@ -5418,7 +5418,7 @@ static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
|
||||
if( pNew ){
|
||||
Expr *pWhere = pS->pWhere;
|
||||
SWAP(Expr, *pNew, *pExpr);
|
||||
pNew = sqlite3ExprAnd(db, pWhere, pNew);
|
||||
pNew = sqlite3ExprAnd(pWalker->pParse, pWhere, pNew);
|
||||
pS->pWhere = pNew;
|
||||
pWalker->eCode = 1;
|
||||
}
|
||||
|
@ -3854,7 +3854,7 @@ Expr *sqlite3Expr(sqlite3*,int,const char*);
|
||||
void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
|
||||
Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
|
||||
void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
|
||||
Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
|
||||
Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*);
|
||||
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
|
||||
void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
|
||||
void sqlite3ExprDelete(sqlite3*, Expr*);
|
||||
|
@ -737,7 +737,7 @@ static void constructAutomaticIndex(
|
||||
&& (pTerm->wtFlags & TERM_VIRTUAL)==0
|
||||
&& !ExprHasProperty(pExpr, EP_FromJoin)
|
||||
&& sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
|
||||
pPartial = sqlite3ExprAnd(pParse->db, pPartial,
|
||||
pPartial = sqlite3ExprAnd(pParse, pPartial,
|
||||
sqlite3ExprDup(pParse->db, pExpr, 0));
|
||||
}
|
||||
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
|
||||
|
@ -999,7 +999,7 @@ static void codeCursorHint(
|
||||
}
|
||||
|
||||
/* If we survive all prior tests, that means this term is worth hinting */
|
||||
pExpr = sqlite3ExprAnd(db, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
|
||||
pExpr = sqlite3ExprAnd(pParse, pExpr, sqlite3ExprDup(db, pTerm->pExpr, 0));
|
||||
}
|
||||
if( pExpr!=0 ){
|
||||
sWalker.xExprCallback = codeCursorHintFixExpr;
|
||||
@ -1964,7 +1964,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
|
||||
testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
|
||||
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
||||
pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
|
||||
pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
|
||||
}
|
||||
if( pAndExpr ){
|
||||
/* The extra 0x10000 bit on the opcode is masked off and does not
|
||||
|
Loading…
Reference in New Issue
Block a user