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:
17
src/expr.c
17
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user