From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] [PATCH v3 4/9] sql: rework SQL_FUNC_COUNT flag semantics Date: Fri, 16 Aug 2019 16:26:50 +0300 [thread overview] Message-ID: <956bd6c2edf79b70d116d4755e35a4975f1f8075.1565961887.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1565961886.git.kshcherbatov@tarantool.org> 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. It used to use SQL_FUNC_COUNT flag to mark a dummy (non-functional) function entry with 0 arguments. This patch changes SQL_FUNC_COUNT semantics: now it is a marker of any COUNT function, while is_simple_count relies on count of arguments to distinguish aggregate and non-aggregate functions. Needed for #2200, #4113, #2233 --- src/box/sql/sqlInt.h | 3 ++- src/box/sql/func.c | 4 ++-- src/box/sql/select.c | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 4adb30c5c..bc3c639e6 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 */ diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 6bd2d0cd7..07c019db9 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 c31076694..ddb5de87e 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; -- 2.22.1
next prev parent reply other threads:[~2019-08-16 13:26 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-16 13:26 [tarantool-patches] [PATCH v3 0/9] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 1/9] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 2/9] sql: GREATEST, LEAST instead of MIN/MAX overload Kirill Shcherbatov 2019-08-16 18:57 ` [tarantool-patches] " n.pettik 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 3/9] sql: wrap all trim functions in dispatcher Kirill Shcherbatov 2019-08-16 13:26 ` Kirill Shcherbatov [this message] 2019-08-16 18:55 ` [tarantool-patches] Re: [PATCH v3 4/9] sql: rework SQL_FUNC_COUNT flag semantics n.pettik 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 5/9] sql: rename OP_Function to OP_BuiltinFunction Kirill Shcherbatov 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 6/9] sql: remove SQL_FUNC_SLOCHNG flag Kirill Shcherbatov 2019-08-16 18:54 ` [tarantool-patches] " n.pettik 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 7/9] sql: get rid of FuncDef function hash Kirill Shcherbatov 2019-08-16 14:09 ` [tarantool-patches] " Konstantin Osipov 2019-08-16 18:59 ` n.pettik 2019-08-19 15:51 ` Kirill Shcherbatov 2019-08-20 13:47 ` Konstantin Osipov 2019-08-20 19:04 ` n.pettik 2019-08-20 19:12 ` Konstantin Osipov 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 8/9] sql: get rid of box.internal.sql_function_create Kirill Shcherbatov 2019-08-16 13:26 ` [tarantool-patches] [PATCH v3 9/9] sql: better error messages on invalid arguments Kirill Shcherbatov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=956bd6c2edf79b70d116d4755e35a4975f1f8075.1565961887.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v3 4/9] sql: rework SQL_FUNC_COUNT flag semantics' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox