aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2022-11-25 13:08:20 +0000
committerdrh <>2022-11-25 13:08:20 +0000
commit7960da03466d96209f53defe088fc16916ba26fc (patch)
treeafc355b8eb3bb1586d7adacc79a2902454f92370 /src
parent8683c0928111707903654278e6c87634cbee5d8c (diff)
downloadsqlite-7960da03466d96209f53defe088fc16916ba26fc.tar.gz
sqlite-7960da03466d96209f53defe088fc16916ba26fc.zip
Improved comments. Add assert()s to verify that the AggInfo structure
is unchanged after registers have been assigned. FossilOrigin-Name: 5200b84195ee1ccaa387f7032eae3d463724c48cb53ba0251bbc79e927dd9752
Diffstat (limited to 'src')
-rw-r--r--src/expr.c2
-rw-r--r--src/select.c16
-rw-r--r--src/sqliteInt.h11
3 files changed, 26 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c
index d7f8cfa91..d30ae9766 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -6265,6 +6265,7 @@ static void findOrCreateAggInfoColumn(
struct AggInfo_col *pCol;
int k;
+ assert( pAggInfo->iFirstReg==0 );
pCol = pAggInfo->aCol;
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
if( pCol->iTable==pExpr->iTable
@@ -6328,6 +6329,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
AggInfo *pAggInfo = pNC->uNC.pAggInfo;
assert( pNC->ncFlags & NC_UAggInfo );
+ assert( pAggInfo->iFirstReg==0 );
switch( pExpr->op ){
default: {
IndexedExpr *pIEpr;
diff --git a/src/select.c b/src/select.c
index 2e6ad4561..e76198772 100644
--- a/src/select.c
+++ b/src/select.c
@@ -6253,6 +6253,7 @@ static void analyzeAggFuncArgs(
){
int i;
assert( pAggInfo!=0 );
+ assert( pAggInfo->iFirstReg==0 );
pNC->ncFlags |= NC_InAggFunc;
for(i=0; i<pAggInfo->nFunc; i++){
Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
@@ -6281,6 +6282,7 @@ static void optimizeAggregateUseOfIndexedExpr(
AggInfo *pAggInfo, /* The aggregate info */
NameContext *pNC /* Name context used to resolve agg-func args */
){
+ assert( pAggInfo->iFirstReg==0 );
pAggInfo->nColumn = pAggInfo->nAccumulator;
if( ALWAYS(pAggInfo->nSortingColumn>0) ){
if( pAggInfo->nColumn==0 ){
@@ -6348,6 +6350,18 @@ static void aggregateConvertIndexedExprRefToColumn(AggInfo *pAggInfo){
** Allocate a block of registers so that there is one register for each
** pAggInfo->aCol[] and pAggInfo->aFunc[] entry in pAggInfo. The first
** register in this block is stored in pAggInfo->iFirstReg.
+**
+** This routine may only be called once for each AggInfo object. Prior
+** to calling this routine:
+**
+** * The aCol[] and aFunc[] arrays may be modified
+** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
+**
+** After clling this routine:
+**
+** * The aCol[] and aFunc[] arrays are fixed
+** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
+**
*/
static void assignAggregateRegisters(Parse *pParse, AggInfo *pAggInfo){
assert( pAggInfo!=0 );
@@ -6369,6 +6383,7 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
int i;
struct AggInfo_func *pFunc;
int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
+ assert( pAggInfo->iFirstReg>0 );
assert( pParse->db->pParse==pParse );
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
if( nReg==0 ) return;
@@ -6436,6 +6451,7 @@ static void updateAccumulator(
struct AggInfo_func *pF;
struct AggInfo_col *pC;
+ assert( pAggInfo->iFirstReg>0 );
pAggInfo->directMode = 1;
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
int nArg;
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 3ecdb35fe..db65082bb 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2766,10 +2766,15 @@ struct AggInfo {
};
/*
-** Macros to compute aCol[] and aFunc[] register numbers:
+** Macros to compute aCol[] and aFunc[] register numbers.
+**
+** These macros should not be used prior to the call to
+** assignAggregateRegisters() that computes the value of pAggInfo->iFirstReg.
+** The assert()s that are part of this macro verify that constraint.
*/
-#define AggInfoColumnReg(A,I) ((A)->iFirstReg+(I))
-#define AggInfoFuncReg(A,I) ((A)->iFirstReg+(A)->nColumn+(I))
+#define AggInfoColumnReg(A,I) (assert((A)->iFirstReg),(A)->iFirstReg+(I))
+#define AggInfoFuncReg(A,I) \
+ (assert((A)->iFirstReg),(A)->iFirstReg+(A)->nColumn+(I))
/*
** The datatype ynVar is a signed integer, either 16-bit or 32-bit.