[Tarantool-patches] [PATCH v2 4/5] sql: do not use struct func for finalization
imeevma at tarantool.org
imeevma at tarantool.org
Thu Aug 19 08:31:32 MSK 2021
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
More information about the Tarantool-patches
mailing list