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 1C19B68F57; Tue, 23 Mar 2021 12:53:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1C19B68F57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616493229; bh=yt4Y7TF+/Pw8tfRbYikkEdEV7zO4miEBGTfU2UuN/QM=; 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=HHn2VwAow3mhS3gedOUKgkIYhatHVptlCJghmu3Jde8PRlW3g8YTtp9ml5AphLAuG CfC0s8Cds/rXmSw4UKZuqD8+WBJFZwxqW3VSwYEv/pOBAmlx+VIXdemO7SxLsRhVvu UT6/wuZpAuYuGVxJVE3jlRrIr7vJBarcp4tzxKsU= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 58EB868F5B for ; Tue, 23 Mar 2021 12:36:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 58EB868F5B Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1lOdST-0005DA-Hq; Tue, 23 Mar 2021 12:36:17 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 23 Mar 2021 12:36:17 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F10D3016C09B407F8B1E2E766A3410B623182A05F538085040FA1262EB0494830AD07942E2A61139B37BD6B2A0DDB372962D2D0D513C62C34F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE752E71F0C64B7C834EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AD1E1BF10F09609D8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C686AF563A045C75E99D9E32865DE1BAB842EF2C1694CA9B3A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77A825AB47F0FC8649FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3E3800B164E348C91117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF894DE5C3FF01FF54BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6731810A3EF82FA8F76E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A57739F23D657EF2B13377AFFFEAFD26923F8577A6DFFEA7C2C2559B29ED8195093EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B6D75B66E98413B381089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7024847893F9AA87235E5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D04B877BBFDA84438355D89D7DBCDD132 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C686AF563A045C75E99D9E32865DE1BAB842EF2C1694CA9B39C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34505665BFD4C7070503952874FF8E04D5FE52A41BEC104441AB710F24223700114F238D6ECA038EE41D7E09C32AA3244C874067A911E188DA63ECED6BEC11E624435BF7150578642FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWJZv20R+6Ug5/jCXu7QU4A== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDD0DE4071AED997C0D07942E2A61139B37B0B9A7C4E99E59B5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 38/53] sql: introduce mem_*_aggregate() 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 introduce mem_prepare_aggregare() and mem_get_aggregate() functions. These functions are used during execution of aggregate functions. Part of #5818 --- src/box/sql/mem.c | 23 +++++++++++++++++++++++ src/box/sql/mem.h | 6 ++++++ src/box/sql/vdbeapi.c | 33 ++++----------------------------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 078de0e62..0211069c6 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -613,6 +613,29 @@ mem_set_frame(struct Mem *mem, struct VdbeFrame *frame) mem->field_type = field_type_MAX; } +int +mem_prepare_aggregate(struct Mem *mem, struct func *func, int size) +{ + if (size <= 0) { + mem_clear(mem); + return 0; + } + if (sqlVdbeMemGrow(mem, size, 0) != 0) + return -1; + memset(mem->z, 0, size); + mem->n = size; + mem->flags = MEM_Agg; + mem->u.func = func; + mem->field_type = field_type_MAX; + return 0; +} + +void * +mem_get_aggregate(struct Mem *mem) +{ + return (void *)mem->z; +} + 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 a6c53c615..51802b450 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -271,6 +271,12 @@ mem_set_pointer(struct Mem *mem, void *ptr); void mem_set_frame(struct Mem *mem, struct VdbeFrame *frame); +int +mem_prepare_aggregate(struct Mem *mem, struct func *func, int size); + +void * +mem_get_aggregate(struct Mem *mem); + int mem_copy(struct Mem *to, const struct Mem *from); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 3ad89b87c..8f871ea95 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -403,29 +403,6 @@ sqlStmtCurrentTime(sql_context * p) return *piTime; } -/* - * Create a new aggregate context for p and return a pointer to - * its pMem->z element. - */ -static SQL_NOINLINE void * -createAggContext(sql_context * p, int nByte) -{ - Mem *pMem = p->pMem; - assert(!mem_is_aggregate(pMem)); - if (nByte <= 0) { - mem_set_null(pMem); - pMem->z = 0; - } else { - sqlVdbeMemClearAndResize(pMem, nByte); - pMem->flags = MEM_Agg; - pMem->u.func = p->func; - if (pMem->z) { - memset(pMem->z, 0, nByte); - } - } - return (void *)pMem->z; -} - /* * Allocate or return the aggregate context for a user function. A new * context is allocated on the first call. Subsequent calls return the @@ -437,12 +414,10 @@ sql_aggregate_context(sql_context * p, int nByte) assert(p != NULL && p->func != NULL); assert(p->func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); assert(p->func->def->aggregate == FUNC_AGGREGATE_GROUP); - testcase(nByte < 0); - if (!mem_is_aggregate(p->pMem)) { - return createAggContext(p, nByte); - } else { - return (void *)p->pMem->z; - } + if (!mem_is_aggregate(p->pMem) && + mem_prepare_aggregate(p->pMem, p->func, nByte) != 0) + return NULL; + return mem_get_aggregate(p->pMem); } /* -- 2.25.1