From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6105825EB0 for ; Thu, 8 Aug 2019 10:50:59 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mvgLjKiKXjRO for ; Thu, 8 Aug 2019 10:50:59 -0400 (EDT) Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id DDFD626A17 for ; Thu, 8 Aug 2019 10:50:58 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 4/8] sql: get rid of SQL_FUNC_COUNT flag Date: Thu, 8 Aug 2019 17:50:48 +0300 Message-Id: <2f18c9df1d818a222f2fb3005d13bd59228d4698.1565275469.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov Tarantool's SQL engine generates a different VDBE bytecode for ..COUNT(*).. and ..COUNT(fieldname).. operations: the first one produces a lightweight OP_Count operation that uses native mechanism to report the count of record in index while the second one pessimistically opens a space read iterator and uses Count aggregate function. A helper routine is_simple_count decides whether such optimisation is correct. Using SQL_FUNC_COUNT flag to mark a dummy (non-functional) function entry with 0 arguments is a bad practice and should be reworked in relation with introducing a uniform functions cache in further patches. Therefore SQL_FUNC_COUNT flag test in is_simple_count helper was replaced with more straightforward test with manually looking for count of function arguments passed. Needed for #2200, #4113, #2233 --- src/box/sql/sqlInt.h | 1 - src/box/sql/func.c | 4 ++-- src/box/sql/select.c | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 4adb30c5c..941c87420 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -1312,7 +1312,6 @@ 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 */ #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 */ diff --git a/src/box/sql/func.c b/src/box/sql/func.c index f9c0a819e..e011fd958 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1910,8 +1910,8 @@ sqlRegisterBuiltinFunctions(void) FIELD_TYPE_NUMBER), AGGREGATE(avg, 1, 0, 0, sum_step, avgFinalize, FIELD_TYPE_NUMBER), - AGGREGATE2(count, 0, 0, 0, countStep, countFinalize, - SQL_FUNC_COUNT, FIELD_TYPE_INTEGER), + AGGREGATE(count, 0, 0, 0, countStep, countFinalize, + FIELD_TYPE_INTEGER), AGGREGATE(count, 1, 0, 0, countStep, countFinalize, FIELD_TYPE_INTEGER), AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, diff --git a/src/box/sql/select.c b/src/box/sql/select.c index c31076694..921a52150 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -4381,7 +4381,8 @@ 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->pExpr->x.pList != NULL && + agg_info->aFunc->pExpr->x.pList->nExpr > 0) return NULL; if (expr->flags & EP_Distinct) return NULL; -- 2.22.0