1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Merge recent enhancements from trunk.

FossilOrigin-Name: c705ce266ad25af71791035590875f0ea9f2c72826b3eda17f065d2bf091de92
This commit is contained in:
drh
2020-03-31 18:41:21 +00:00
42 changed files with 477 additions and 274 deletions

View File

@@ -3580,6 +3580,38 @@ static void substSelect(
}
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
/*
** pSelect is a SELECT statement and pSrcItem is one item in the FROM
** clause of that SELECT.
**
** This routine scans the entire SELECT statement and recomputes the
** pSrcItem->colUsed mask.
*/
static int recomputeColumnsUsedExpr(Walker *pWalker, Expr *pExpr){
struct SrcList_item *pItem;
if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
pItem = pWalker->u.pSrcItem;
if( pItem->iCursor!=pExpr->iTable ) return WRC_Continue;
if( pExpr->iColumn<0 ) return WRC_Continue;
pItem->colUsed |= sqlite3ExprColUsed(pExpr);
return WRC_Continue;
}
static void recomputeColumnsUsed(
Select *pSelect, /* The complete SELECT statement */
struct SrcList_item *pSrcItem /* Which FROM clause item to recompute */
){
Walker w;
if( NEVER(pSrcItem->pTab==0) ) return;
memset(&w, 0, sizeof(w));
w.xExprCallback = recomputeColumnsUsedExpr;
w.xSelectCallback = sqlite3SelectWalkNoop;
w.u.pSrcItem = pSrcItem;
pSrcItem->colUsed = 0;
sqlite3WalkSelect(&w, pSelect);
}
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
/*
** This routine attempts to flatten subqueries as a performance optimization.
@@ -4118,6 +4150,12 @@ static int flattenSubquery(
pParent->pLimit = pSub->pLimit;
pSub->pLimit = 0;
}
/* Recompute the SrcList_item.colUsed masks for the flattened
** tables. */
for(i=0; i<nSubSrc; i++){
recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
}
}
/* Finially, delete what is left of the subquery and return