aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2024-09-01 19:19:26 +0000
committerdrh <>2024-09-01 19:19:26 +0000
commit7aa01a0ffc3197551d19178797d3d6c5356f2996 (patch)
tree8c0509bd492faf414d971d715a6397757df8dbb3 /src
parent5d5d6194c93d115630b0f640675525d9e3c4016e (diff)
downloadsqlite-7aa01a0ffc3197551d19178797d3d6c5356f2996.tar.gz
sqlite-7aa01a0ffc3197551d19178797d3d6c5356f2996.zip
No prepare-time penality for ordered-set aggregates for applications that
do not use them. FossilOrigin-Name: e070c16d2183312e416ff6af770346041e4d3836c4db2c9ea6049f63fb0eaa07
Diffstat (limited to 'src')
-rw-r--r--src/parse.y18
-rw-r--r--src/resolve.c4
-rw-r--r--src/sqlite.h.in6
-rw-r--r--src/sqliteInt.h1
4 files changed, 16 insertions, 13 deletions
diff --git a/src/parse.y b/src/parse.y
index 3db20e9ac..c126c815d 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -1199,12 +1199,20 @@ expr(A) ::= idj(X) LP STAR RP. {
}
sqlite3ExprListDelete(pParse->db, pOrig);
}
- if( isDistinct==SF_Distinct ){
- sqlite3ErrorMsg(pParse, "DISTINCT not allows on ordered-set aggregate %T()",
- pFuncname);
- }
pExpr = sqlite3ExprFunction(pParse, p, pFuncname, 0);
- if( pExpr ) pExpr->iColumn = 1;
+ if( pParse->nErr==0 ){
+ FuncDef *pDef;
+ u8 enc = ENC(pParse->db);
+ assert( pExpr!=0 ); /* Because otherwise pParse->nErr would not be zero */
+ assert( p!=0 ); /* Because otherwise pParse->nErr would not be zero */
+ pDef = sqlite3FindFunction(pParse->db, pExpr->u.zToken, p->nExpr, enc, 0);
+ if( pDef==0 || (pDef->funcFlags & SQLITE_SELFORDER1)==0 ){
+ sqlite3ErrorMsg(pParse, "%#T() is not an ordered-set aggregate", pExpr);
+ }else if( isDistinct==SF_Distinct ){
+ sqlite3ErrorMsg(pParse, "DISTINCT not allows on ordered-set aggregate %T()",
+ pFuncname);
+ }
+ }
return pExpr;
}
}
diff --git a/src/resolve.c b/src/resolve.c
index f448bc324..b755cc864 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -1292,10 +1292,6 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
else if( ExprHasProperty(pExpr, EP_WinFunc) || pExpr->pLeft ){
is_agg = 1;
}
- if( pExpr->iColumn && (pDef->funcFlags & SQLITE_SELFORDER1)==0 ){
- sqlite3ErrorMsg(pParse, "%#T() is not a ordered-set aggregate function",
- pExpr);
- }
sqlite3WalkExprList(pWalker, pList);
if( is_agg ){
if( pExpr->pLeft ){
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 8e5e327c9..c1f1c1c36 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -5619,9 +5619,9 @@ int sqlite3_create_window_function(
** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>
** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate
** that internally orders the values provided to the first argument. The
-** ordered-set aggregate SQL notation can be used to invoke this function.
-** If the ordered-set aggregate notation is used on a function that lacks
-** this flag, then an error is raised.
+** ordered-set aggregate SQL notation with a single ORDER BY term can be
+** used to invoke this function. If the ordered-set aggregate notation is
+** used on a function that lacks this flag, then an error is raised.
** </dd>
** </dl>
*/
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index b77f035e7..0dab59f7a 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -3052,7 +3052,6 @@ struct Expr {
** TK_SELECT: 1st register of result vector */
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
** TK_VARIABLE: variable number (always >= 1).
- ** TK_FUNCTION: Uses ordered-set aggregate syntax
** TK_SELECT_COLUMN: column of the result vector */
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
union {