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

Add the stub function: optimizeAggregateUsingIndexedExpr(). The hope is that

we can fill this in with a routine that does useful optimizations.

FossilOrigin-Name: d85bb724fdd6fbad2b88ed7f60e4174e3f65182356f404d04620c5cf6b17f77e
This commit is contained in:
drh
2022-11-22 20:37:41 +00:00
parent cbef156d93
commit b23f1572ab
3 changed files with 38 additions and 7 deletions

View File

@@ -6654,6 +6654,34 @@ static void printAggInfo(AggInfo *pAggInfo){
}
#endif /* TREETRACE_ENABLED */
/*
** An index on expressions is being used in the inner loop of an
** aggregate query with a GROUP BY clause. This routine attempts
** to adjust the AggInfo object to take advantage of index and to
** perhaps use the index as a covering index.
**
*/
static int optimizeAggregateUsingIndexedExpr(
Parse *pParse, /* Parsing context */
Select *pSelect, /* The SELECT being coded */
AggInfo *pAggInfo /* The aggregate info */
){
#if TREETRACE_ENABLED
if( sqlite3TreeTrace & 0x100000 ){
IndexedExpr *pIEpr;
TREETRACE(0x1000000, pParse, pSelect,
("Attempting to optimize AggInfo for Indexed Exprs\n"));
for(pIEpr=pParse->pIdxEpr; pIEpr; pIEpr=pIEpr->pIENext){
printf("cur=%d\n", pIEpr->iDataCur);
sqlite3TreeViewExpr(0, pIEpr->pExpr, 0);
}
printAggInfo(pAggInfo);
}
#endif
return 0;
}
/*
** Generate code for the SELECT statement given in the p argument.
**
@@ -7535,6 +7563,9 @@ int sqlite3Select(
sqlite3ExprListDelete(db, pDistinct);
goto select_end;
}
if( pParse->pIdxEpr ){
optimizeAggregateUsingIndexedExpr(pParse, p, pAggInfo);
}
assignAggregateRegisters(pParse, pAggInfo);
eDist = sqlite3WhereIsDistinct(pWInfo);
TREETRACE(0x2,pParse,p,("WhereBegin returns\n"));