From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v2 4/5] sql: do not use struct func for finalization Date: Thu, 19 Aug 2021 08:31:32 +0300 [thread overview] Message-ID: <5f7df02aac30a94723228d805df47d31541925f0.1629350815.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1629350814.git.imeevma@gmail.com> This patch removes struct func from finalization of SQL built-in aggregate functions. Part of #6105 --- src/box/sql/func.c | 30 ++++++++++++++++++++++++++---- src/box/sql/vdbe.c | 2 +- src/box/sql/vdbe.h | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index adbc6d5a4..e09224bb8 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -3008,9 +3008,31 @@ int sql_emit_func_finalize(struct Vdbe *vdbe, struct Expr *expr, int reg, uint8_t argc) { - struct func *func = sql_func_find(expr); - if (func == NULL) - return -1; - sqlVdbeAddOp4(vdbe, OP_AggFinal, reg, argc, 0, (char *)func, P4_FUNC); + void (*finalize)(sql_context *ctx); + switch(expr->func_id) { + case TK_AVG: + finalize = avgFinalize; + break; + case TK_SUM: + finalize = sumFinalize; + break; + case TK_COUNT: + finalize = countFinalize; + break; + case TK_TOTAL: + finalize = totalFinalize; + break; + case TK_GROUP_CONCAT: + finalize = groupConcatFinalize; + break; + case TK_MAX: + case TK_MIN: + finalize = minMaxFinalize; + break; + default: + unreachable(); + } + sqlVdbeAddOp4(vdbe, OP_AggFinal, reg, argc, 0, (char *)finalize, + P4_STATIC); return 0; } diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index c63dbaa5a..f821ac98a 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4221,7 +4221,7 @@ case OP_AggFinal: { mem_create(&t); ctx.pOut = &t; ctx.pMem = pMem; - ((struct func_sql_builtin *)pOp->p4.func)->finalize(&ctx); + pOp->p4.finalize(&ctx); if (ctx.is_aborted) goto abort_due_to_error; assert((pMem->flags & MEM_Dyn) == 0); diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h index e40a1a0b3..1f6e566e1 100644 --- a/src/box/sql/vdbe.h +++ b/src/box/sql/vdbe.h @@ -97,6 +97,8 @@ struct VdbeOp { * Information about ephemeral space field types and key parts. */ struct sql_space_info *space_info; + /* Finalize method for SQL built-in aggregate function. */ + void (*finalize)(sql_context *ctx); } p4; #ifdef SQL_ENABLE_EXPLAIN_COMMENTS char *zComment; /* Comment to improve readability */ -- 2.25.1
next prev parent reply other threads:[~2021-08-19 5:33 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-19 5:31 [Tarantool-patches] [PATCH v2 0/5] Change structure of SQL-built-in functions Mergen Imeev via Tarantool-patches 2021-08-19 5:31 ` [Tarantool-patches] [PATCH v2 1/5] sql: remove OP_BuiltinFunction0 and OP_AggStep0 Mergen Imeev via Tarantool-patches 2021-08-19 5:31 ` [Tarantool-patches] [PATCH v2 2/5] sql: remove unnecessary MEM finalization Mergen Imeev via Tarantool-patches 2021-08-19 5:31 ` [Tarantool-patches] [PATCH v2 3/5] sql: remove struct func from struct sql_context Mergen Imeev via Tarantool-patches 2021-08-19 5:31 ` Mergen Imeev via Tarantool-patches [this message] 2021-08-19 5:31 ` [Tarantool-patches] [PATCH v2 5/5] sql: remove unused code Mergen Imeev via Tarantool-patches
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=5f7df02aac30a94723228d805df47d31541925f0.1629350815.git.imeevma@gmail.com \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=vdavydov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 4/5] sql: do not use struct func for finalization' \ /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