From c37577bb2dfb602a5cdbba8322a01b548c34c185 Mon Sep 17 00:00:00 2001 From: drh Date: Sun, 24 May 2020 03:38:37 +0000 Subject: When rewriting a query for window functions, if the rewrite changes the depth of TK_AGG_FUNCTION nodes, be sure to adjust the Expr.op2 field appropriately. Fix for ticket [7a5279a25c57adf1] FossilOrigin-Name: ad7bb70af9bb68d192137188bb2528f1e9e43ad164c925174ca1dafc9e1f5339 --- src/resolve.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/resolve.c') diff --git a/src/resolve.c b/src/resolve.c index 60fed0b10..aff6dbead 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -24,6 +24,8 @@ ** ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) ** is a helper function - a callback for the tree walker. +** +** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c */ static int incrAggDepth(Walker *pWalker, Expr *pExpr){ if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; -- cgit v1.2.3 From ec43d8040a063d39b5fccf24c60c4b206cafa671 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 29 Jun 2020 20:20:40 +0000 Subject: Change the magic number used to identify the "excluded" pseudo-table in an UPSERT statement into a #define constant. FossilOrigin-Name: e96c2ac9ab1a1c51b1498f4b91fb71d2987c30579d072b2f0297da9eb945cb97 --- src/resolve.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/resolve.c') diff --git a/src/resolve.c b/src/resolve.c index aff6dbead..3b88073da 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -16,6 +16,11 @@ */ #include "sqliteInt.h" +/* +** Magic table number to mean the EXCLUDED table in an UPSERT statement. +*/ +#define EXCLUDED_TABLE_NUMBER 2 + /* ** Walk the expression tree pExpr and increase the aggregate function ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. @@ -386,7 +391,7 @@ static int lookupName( Upsert *pUpsert = pNC->uNC.pUpsert; if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){ pTab = pUpsert->pUpsertSrc->a[0].pTab; - pExpr->iTable = 2; + pExpr->iTable = EXCLUDED_TABLE_NUMBER; } } #endif /* SQLITE_OMIT_UPSERT */ @@ -411,7 +416,7 @@ static int lookupName( if( iColnCol ){ cnt++; #ifndef SQLITE_OMIT_UPSERT - if( pExpr->iTable==2 ){ + if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ testcase( iCol==(-1) ); if( IN_RENAME_OBJECT ){ pExpr->iColumn = iCol; -- cgit v1.2.3 From b8fec2198335145ede8a8675fb00e7860cd64c1d Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 29 Jun 2020 20:26:50 +0000 Subject: Fix generated columns so that they play well with upsert. See the [https://sqlite.org/forum/forumpost/73b9a8ccfb|forum post] by "iffycan" for details. FossilOrigin-Name: fa9d93cf32fac4b86044acf5d1b9ea2f36e964ed7142cf1d270986c9ef3fb766 --- src/resolve.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/resolve.c') diff --git a/src/resolve.c b/src/resolve.c index 3b88073da..a1d9a155b 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -423,7 +423,8 @@ static int lookupName( pExpr->y.pTab = pTab; eNewExprOp = TK_COLUMN; }else{ - pExpr->iTable = pNC->uNC.pUpsert->regData + iCol; + pExpr->iTable = pNC->uNC.pUpsert->regData + + sqlite3TableColumnToStorage(pTab, iCol); eNewExprOp = TK_REGISTER; ExprSetProperty(pExpr, EP_Alias); } -- cgit v1.2.3