1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

Performance optimization in computing the Expr.nHeight field.

FossilOrigin-Name: 1798ce97c8763d75315e1716d10f6c5be301042c174f41ee8c1fb8d9db99d52b
This commit is contained in:
drh
2022-07-25 20:21:57 +00:00
parent 058e99502a
commit 47e2fe3ce7
3 changed files with 22 additions and 9 deletions

View File

@@ -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);
}
}