Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Reduce the size of the NameContext object by grouping seldom-used fields into a union. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: | dba3095feeeb55b5c0ebe33bdd4be8ba |
User & Date: | drh 2018-04-16 10:34:13 |
Context
2018-04-16
| ||
10:41 | Increase the version number to 3.24.0 check-in: f94528e1 user: drh tags: trunk | |
10:34 | Reduce the size of the NameContext object by grouping seldom-used fields into a union. check-in: dba3095f user: drh tags: trunk | |
2018-04-13
| ||
16:23 | Remove an always-true branch from the preupdate hook logic. check-in: 0ab45188 user: drh tags: trunk | |
Changes
Changes to src/expr.c.
5251 5251 ** for additional information. 5252 5252 */ 5253 5253 static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ 5254 5254 int i; 5255 5255 NameContext *pNC = pWalker->u.pNC; 5256 5256 Parse *pParse = pNC->pParse; 5257 5257 SrcList *pSrcList = pNC->pSrcList; 5258 - AggInfo *pAggInfo = pNC->pAggInfo; 5258 + AggInfo *pAggInfo = pNC->uNC.pAggInfo; 5259 5259 5260 + assert( pNC->ncFlags & NC_UAggInfo ); 5260 5261 switch( pExpr->op ){ 5261 5262 case TK_AGG_COLUMN: 5262 5263 case TK_COLUMN: { 5263 5264 testcase( pExpr->op==TK_AGG_COLUMN ); 5264 5265 testcase( pExpr->op==TK_COLUMN ); 5265 5266 /* Check to see if the column is in one of the tables in the FROM 5266 5267 ** clause of the aggregate query */
Changes to src/resolve.c.
379 379 ** 380 380 ** The ability to use an output result-set column in the WHERE, GROUP BY, 381 381 ** or HAVING clauses, or as part of a larger expression in the ORDER BY 382 382 ** clause is not standard SQL. This is a (goofy) SQLite extension, that 383 383 ** is supported for backwards compatibility only. Hence, we issue a warning 384 384 ** on sqlite3_log() whenever the capability is used. 385 385 */ 386 - if( (pEList = pNC->pEList)!=0 387 - && zTab==0 386 + if( (pNC->ncFlags & NC_UEList)!=0 388 387 && cnt==0 388 + && zTab==0 389 389 ){ 390 + pEList = pNC->uNC.pEList; 391 + assert( pEList!=0 ); 390 392 for(j=0; j<pEList->nExpr; j++){ 391 393 char *zAs = pEList->a[j].zName; 392 394 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ 393 395 Expr *pOrig; 394 396 assert( pExpr->pLeft==0 && pExpr->pRight==0 ); 395 397 assert( pExpr->x.pList==0 ); 396 398 assert( pExpr->x.pSelect==0 ); ................................................................................ 911 913 pEList = pSelect->pEList; 912 914 913 915 /* Resolve all names in the ORDER BY term expression 914 916 */ 915 917 memset(&nc, 0, sizeof(nc)); 916 918 nc.pParse = pParse; 917 919 nc.pSrcList = pSelect->pSrc; 918 - nc.pEList = pEList; 919 - nc.ncFlags = NC_AllowAgg; 920 + nc.uNC.pEList = pEList; 921 + nc.ncFlags = NC_AllowAgg|NC_UEList; 920 922 nc.nErr = 0; 921 923 db = pParse->db; 922 924 savedSuppErr = db->suppressErr; 923 925 db->suppressErr = 1; 924 926 rc = sqlite3ResolveExprNames(&nc, pE); 925 927 db->suppressErr = savedSuppErr; 926 928 if( rc ) return 0; ................................................................................ 1295 1297 ** other expressions in the SELECT statement. This is so that 1296 1298 ** expressions in the WHERE clause (etc.) can refer to expressions by 1297 1299 ** aliases in the result set. 1298 1300 ** 1299 1301 ** Minor point: If this is the case, then the expression will be 1300 1302 ** re-evaluated for each reference to it. 1301 1303 */ 1302 - sNC.pEList = p->pEList; 1304 + assert( (sNC.ncFlags & (NC_UAggInfo))==0 ); 1305 + sNC.uNC.pEList = p->pEList; 1306 + sNC.ncFlags |= NC_UEList; 1303 1307 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; 1304 1308 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; 1305 1309 1306 1310 /* Resolve names in table-valued-function arguments */ 1307 1311 for(i=0; i<p->pSrc->nSrc; i++){ 1308 1312 struct SrcList_item *pItem = &p->pSrc->a[i]; 1309 1313 if( pItem->fg.isTabFunc
Changes to src/select.c.
5679 5679 /* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in 5680 5680 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the 5681 5681 ** SELECT statement. 5682 5682 */ 5683 5683 memset(&sNC, 0, sizeof(sNC)); 5684 5684 sNC.pParse = pParse; 5685 5685 sNC.pSrcList = pTabList; 5686 - sNC.pAggInfo = &sAggInfo; 5686 + sNC.uNC.pAggInfo = &sAggInfo; 5687 + VVA_ONLY( sNC.ncFlags = NC_UAggInfo; ) 5687 5688 sAggInfo.mnReg = pParse->nMem+1; 5688 5689 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0; 5689 5690 sAggInfo.pGroupBy = pGroupBy; 5690 5691 sqlite3ExprAnalyzeAggList(&sNC, pEList); 5691 5692 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy); 5692 5693 if( pHaving ){ 5693 5694 if( pGroupBy ){
Changes to src/sqliteInt.h.
2678 2678 ** NameContext in the parent query. Thus the process of scanning the 2679 2679 ** NameContext list corresponds to searching through successively outer 2680 2680 ** subqueries looking for a match. 2681 2681 */ 2682 2682 struct NameContext { 2683 2683 Parse *pParse; /* The parser */ 2684 2684 SrcList *pSrcList; /* One or more tables used to resolve names */ 2685 - ExprList *pEList; /* Optional list of result-set columns */ 2686 - AggInfo *pAggInfo; /* Information about aggregates at this level */ 2685 + union { 2686 + ExprList *pEList; /* Optional list of result-set columns */ 2687 + AggInfo *pAggInfo; /* Information about aggregates at this level */ 2688 + } uNC; 2687 2689 NameContext *pNext; /* Next outer name context. NULL for outermost */ 2688 2690 int nRef; /* Number of names resolved by this context */ 2689 2691 int nErr; /* Number of errors encountered while resolving names */ 2690 2692 u16 ncFlags; /* Zero or more NC_* flags defined below */ 2691 2693 }; 2692 2694 2693 2695 /* ................................................................................ 2701 2703 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */ 2702 2704 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */ 2703 2705 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */ 2704 2706 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */ 2705 2707 #define NC_HasAgg 0x0010 /* One or more aggregate functions seen */ 2706 2708 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */ 2707 2709 #define NC_VarSelect 0x0040 /* A correlated subquery has been seen */ 2710 +#define NC_UEList 0x0080 /* True if uNC.pEList is used */ 2711 +#define NC_UAggInfo 0x0100 /* True if uNC.pAggInfo is used */ 2708 2712 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ 2709 2713 #define NC_Complex 0x2000 /* True if a function or subquery seen */ 2710 2714 2711 2715 /* 2712 2716 ** An instance of the following structure contains all information 2713 2717 ** needed to generate code for a single SELECT statement. 2714 2718 **