[Tarantool-patches] [PATCH v2 1/4] sql: fix COUNT() optimization conditions

imeevma at tarantool.org imeevma at tarantool.org
Tue Feb 1 16:37:22 MSK 2022


This patch fixes the conditions under which COUNT() is optimized. At
some point, the conditions were broken, but since there was no other
aggregate function requiring zero arguments, this problem did not change
the behavior.

Needed for #2579
---
 src/box/sql/select.c | 2 +-
 src/box/sql/sqlInt.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 55aaff87f..b532cac4e 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4650,7 +4650,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
 		return NULL;
 	assert(agg_info->aFunc->func->def->language ==
 	       FUNC_LANGUAGE_SQL_BUILTIN);
-	if (sql_func_flag_is_set(agg_info->aFunc->func, SQL_FUNC_COUNT) ||
+	if (strcmp(agg_info->aFunc->func->def->name, "COUNT") != 0 ||
 	    (agg_info->aFunc->pExpr->x.pList != NULL &&
 	     agg_info->aFunc->pExpr->x.pList->nExpr > 0))
 		return NULL;
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0db16b293..f49522dc8 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1117,8 +1117,6 @@ struct type_def {
 					 */
 #define SQL_FUNC_LENGTH   0x0040	/* Built-in length() function */
 #define SQL_FUNC_TYPEOF   0x0080	/* Built-in typeof() function */
-/** 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 */
 /** Built-in min() or least() function. */
-- 
2.25.1



More information about the Tarantool-patches mailing list