aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <>2022-07-25 20:21:57 +0000
committerdrh <>2022-07-25 20:21:57 +0000
commit47e2fe3ce78af0c2dd32a0e8f6e10d2211a932d2 (patch)
treefe6c357a0c92a6a06beb3e7e490801ea98d7f647 /src/expr.c
parent058e99502a70abb5e67bead9a4146f4523ff89d9 (diff)
downloadsqlite-47e2fe3ce78af0c2dd32a0e8f6e10d2211a932d2.tar.gz
sqlite-47e2fe3ce78af0c2dd32a0e8f6e10d2211a932d2.zip
Performance optimization in computing the Expr.nHeight field.
FossilOrigin-Name: 1798ce97c8763d75315e1716d10f6c5be301042c174f41ee8c1fb8d9db99d52b
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/expr.c b/src/expr.c
index c383f6f65..44744524a 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);
}
}