From: drh <> Date: Mon, 25 Jul 2022 20:21:57 +0000 (+0000) Subject: Performance optimization in computing the Expr.nHeight field. X-Git-Tag: version-3.40.0~276 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47e2fe3ce78af0c2dd32a0e8f6e10d2211a932d2;p=thirdparty%2Fsqlite.git Performance optimization in computing the Expr.nHeight field. FossilOrigin-Name: 1798ce97c8763d75315e1716d10f6c5be301042c174f41ee8c1fb8d9db99d52b --- diff --git a/manifest b/manifest index 8d9ac4ab45..3d1d1a278e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Small\sperformance\sincrease\sand\ssize\sreduction\sby\ssplitting\sout\sthe\nsqlite3VdbeGetLastOp()\sfrom\ssqlite3VdbeGetOp(). -D 2022-07-25T19:05:24.840 +C Performance\soptimization\sin\scomputing\sthe\sExpr.nHeight\sfield. +D 2022-07-25T20:21:57.291 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -521,7 +521,7 @@ F src/date.c 272162554168e7af4976213850e1c4c5f33b964d299ceb0983f3d5cceba01d05 F src/dbpage.c 5808e91bc27fa3981b028000f8fadfdc10ce9e59a34ce7dc4e035a69be3906ec F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d F src/delete.c 13eca2beee5b758ed033a11230971310cc4a58fcd8f6bc33cad4f677c985e96c -F src/expr.c 375b8285b347a33ea239eb1dad378d4044fe5a6b0d9ee1e7db7370f97d5fb14e +F src/expr.c afc33c8b4f72a61e49194aa2c6f475e4e7ba87e91a5102701d02978d292000e2 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c d965ede15d8360c09ed59348940649ee647b192e784466837d7aefa836d1d91e F src/func.c 8f72e88cccdee22185133c10f96ccd61dc34c5ea4b1fa9a73c237ef59b2e64f1 @@ -1981,8 +1981,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b52393ac28debe9867227f901d05cccf54f1b467272474500a549d956a5fb4d7 -R d4f59dff4c0149f1eec71fecf2aaf224 +P 92ac01d41d46ab73e189b1e5596ea63e5edb5b15639c5d7bdb981b95366c069b +R 5546500321041b9016b316ba858300f9 U drh -Z da216fd20b1c63c1a0740d95d247a9a9 +Z dddc2675e82e808f6c9034d235b5fa31 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e1b00675ab..e9a838e5a8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -92ac01d41d46ab73e189b1e5596ea63e5edb5b15639c5d7bdb981b95366c069b \ No newline at end of file +1798ce97c8763d75315e1716d10f6c5be301042c174f41ee8c1fb8d9db99d52b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index c383f6f65f..44744524ab 100644 --- a/src/expr.c +++ b/src/expr.c @@ -770,7 +770,9 @@ static void heightOfSelect(const Select *pSelect, int *pnHeight){ */ static void exprSetHeight(Expr *p){ int nHeight = p->pLeft ? p->pLeft->nHeight : 0; - if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight; + if( NEVER(p->pRight) && p->pRight->nHeight>nHeight ){ + nHeight = p->pRight->nHeight; + } if( ExprUseXSelect(p) ){ heightOfSelect(p->x.pSelect, &nHeight); }else if( p->x.pList ){ @@ -913,15 +915,26 @@ void sqlite3ExprAttachSubtrees( sqlite3ExprDelete(db, pLeft); sqlite3ExprDelete(db, pRight); }else{ + assert( ExprUseXList(pRoot) ); + assert( pRoot->x.pSelect==0 ); if( pRight ){ pRoot->pRight = pRight; pRoot->flags |= EP_Propagate & pRight->flags; +#if SQLITE_MAX_EXPR_DEPTH>0 + pRoot->nHeight = pRight->nHeight+1; + }else{ + pRoot->nHeight = 1; +#endif } if( pLeft ){ pRoot->pLeft = pLeft; pRoot->flags |= EP_Propagate & pLeft->flags; +#if SQLITE_MAX_EXPR_DEPTH>0 + if( pLeft->nHeight>=pRoot->nHeight ){ + pRoot->nHeight = pLeft->nHeight+1; + } +#endif } - exprSetHeight(pRoot); } }