diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 6bd2d0cd7c867b7159749dee06fbfb8340adaaaf..07c019db9577e2fde10d010be274408b9dd02853 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1903,9 +1903,9 @@ sqlRegisterBuiltinFunctions(void) AGGREGATE(avg, 1, 0, 0, sum_step, avgFinalize, FIELD_TYPE_NUMBER), AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, + SQL_FUNC_COUNT, FIELD_TYPE_INTEGER), + AGGREGATE2(count, 1, 0, 0, countStep, countFinalize, SQL_FUNC_COUNT, FIELD_TYPE_INTEGER), - AGGREGATE(count, 1, 0, 0, countStep, countFinalize, - FIELD_TYPE_INTEGER), AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize, FIELD_TYPE_STRING), AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, diff --git a/src/box/sql/select.c b/src/box/sql/select.c index c310766945db052ad2c97ec9e9e806803a52fe1a..ddb5de87ee591bcdc5c51b64a896e1bcb6078d71 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -4381,7 +4381,9 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info) return NULL; if (NEVER(agg_info->nFunc == 0)) return NULL; - if ((agg_info->aFunc[0].pFunc->funcFlags & SQL_FUNC_COUNT) == 0) + if ((agg_info->aFunc->pFunc->funcFlags & SQL_FUNC_COUNT) == 0 || + (agg_info->aFunc->pExpr->x.pList != NULL && + agg_info->aFunc->pExpr->x.pList->nExpr > 0)) return NULL; if (expr->flags & EP_Distinct) return NULL; diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 4adb30c5c82a498d4ac22488dbeea2251b9d0f30..bc3c639e68e73d1334ca36511547619a33c49295 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -1312,7 +1312,8 @@ struct FuncDestructor { */ #define SQL_FUNC_LENGTH 0x0040 /* Built-in length() function */ #define SQL_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ -#define SQL_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ +/** Built-in count() function. */ +#define SQL_FUNC_COUNT 0x0100 #define SQL_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */ #define SQL_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ #define SQL_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */