[Tarantool-patches] [PATCH v1 08/13] sql: rework AVG()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Wed Sep 15 00:24:08 MSK 2021
Thanks for the patch!
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index 12a6a5a2c..9e0c09206 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -102,6 +102,44 @@ fin_total(struct sql_context *ctx)
> mem_copy_as_ephemeral(ctx->pOut, ctx->pMem);
> }
>
> +/** Implementation of the AVG() function. */
> +static void
> +step_avg(struct sql_context *ctx, int argc, struct Mem **argv)
> +{
> + assert(argc == 1);
> + (void)argc;
> + assert(ctx->pMem->type == MEM_TYPE_NULL || mem_is_bin(ctx->pMem));
> + if (argv[0]->type == MEM_TYPE_NULL)
> + return;
> + if (ctx->pMem->type == MEM_TYPE_NULL) {
> + uint32_t size = 2 * sizeof(struct Mem);
> + struct Mem *mems = sqlDbMallocRawNN(sql_get(), size);
Previously only size of mem + uint32 was allocated, now it is 2 size
of mem. Lets stick to the more compact version. For the division in the
end you can create a mem on the stack, for instance.
More information about the Tarantool-patches
mailing list