aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2022-11-22 20:37:41 +0000
committerdrh <>2022-11-22 20:37:41 +0000
commitb23f1572ab9c11e524023678a5347152aae48b04 (patch)
treeab8d83330d7d7095464c06305ddc841e8f3b5a76 /src
parentcbef156d936d57bf9a5dd60e02156fcdf0996987 (diff)
downloadsqlite-b23f1572ab9c11e524023678a5347152aae48b04.tar.gz
sqlite-b23f1572ab9c11e524023678a5347152aae48b04.zip
Add the stub function: optimizeAggregateUsingIndexedExpr(). The hope is that
we can fill this in with a routine that does useful optimizations. FossilOrigin-Name: d85bb724fdd6fbad2b88ed7f60e4174e3f65182356f404d04620c5cf6b17f77e
Diffstat (limited to 'src')
-rw-r--r--src/select.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/select.c b/src/select.c
index 946649ad0..ecd179106 100644
--- a/src/select.c
+++ b/src/select.c
@@ -6655,6 +6655,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.
**
** The results are returned according to the SelectDest structure.
@@ -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"));