From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id EFDF06C185; Sat, 10 Apr 2021 00:11:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EFDF06C185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618002683; bh=3vfvk8vLMCAbDCkVK0MUiBnI7Gyb0lKMCUYSQj9LUrM=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=b7NTdys5NIIHkHRPaDIIhyMqv6iu/HrGSMlot32tvYW4sC1Q/NVKFTmq3il9rYYIc 4s/e40YdVGh1TR4BqzHVPkhagvfod3iEEk2dh7lqDg6DhywSJCvpKNRPnsRaaKwr28 OoRHBTzcqtK+ILDNMqOS0D7p+7lKI9+tsJuugv3Q= Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B00B16C185 for ; Sat, 10 Apr 2021 00:08:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B00B16C185 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1lUyMg-0003vj-QP; Sat, 10 Apr 2021 00:08:31 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Sat, 10 Apr 2021 00:08:30 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480B1C8842CE613979723F2FB4628545A35182A05F5380850402BC8C6938B9CFA0AD8B376DDFF0637AA3FB26DCC29446C3A0545DA2DFB3E85AA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E27C7C60963D4ED9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F0D8FAB78312C5B48638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2E1F30BC11DAAA96821C14138B128BAEA8FE4E5499B132CBCD2E47CDBA5A96583C09775C1D3CA48CF53FA85A707D24CADCC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C084ED00A64A654CBE8941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4FD732F71931345DEB3129807FBDFAD36E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34CAFBC0A7A4BEEE01A1DA1C2D16CF6C24A75A64E429EE90F5E67121D7AF23595222E089E0A53E404D1D7E09C32AA3244CF01630880558943854E708BABB05F5BA51E887DA02A9F7BFFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqcJA+pXcDumSkOlsDQM7Lw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638220AB5602BCA2DC72F9507358082A4D3B583D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 52/52] sql: introduce mem_get_agg() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch introduces mem_get_agg(). This function is used to receive address of memory allocated for accumulation structure of the aggregate function. Closes #5818 --- src/box/sql/mem.c | 9 +++++++++ src/box/sql/mem.h | 7 +++++++ src/box/sql/vdbeapi.c | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 3e9544cae..c7220190c 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1357,6 +1357,15 @@ mem_get_bytes_len(const struct Mem *mem, uint32_t *len) return 0; } +int +mem_get_agg(const struct Mem *mem, void **accum) +{ + if ((mem->flags & MEM_Agg) == 0) + return -1; + *accum = mem->z; + return 0; +} + int mem_copy(struct Mem *to, const struct Mem *from) { diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 9c6d18e1f..9ba7ef066 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -605,6 +605,13 @@ mem_get_bin(const struct Mem *mem, const char **s); int mem_get_bytes_len(const struct Mem *mem, uint32_t *len); +/** + * Return address of memory allocated for accumulation structure of the + * aggregate function. + */ +int +mem_get_agg(const struct Mem *mem, void **accum); + /** * Simple type to str convertor. It is used to simplify * error reporting. diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index b0334f3ed..a9a7dc97a 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -416,7 +416,10 @@ sql_aggregate_context(sql_context * p, int nByte) assert(p->func->def->aggregate == FUNC_AGGREGATE_GROUP); if (!mem_is_agg(p->pMem) && mem_set_agg(p->pMem, p->func, nByte) != 0) return NULL; - return p->pMem->z; + void *accum; + if (mem_get_agg(p->pMem, &accum) != 0) + return NULL; + return accum; } /* -- 2.25.1