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 2E235711BA; Tue, 26 Oct 2021 13:37:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2E235711BA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635244664; bh=TfRUvkX5sosvYNDjxzI6g4VoumW8UWmD60oXONiTIuA=; 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=EiiDiPo6x2B/b5DvorE9pGSCsqMFAXPbRNtg5KFLN/33KtiAGALEdkHSb6Zng7miX HgGK1jdUzIjwQdTJB5w2yoJwfVzH/Lpo4cRVN53Ic4wVw69INrbdHcLR2gbKqLDRqh DMP+0w9kZ3PDcU8P4cKu5d2wBvEvKk4gHYWWfCxo= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [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 21750711BA for ; Tue, 26 Oct 2021 13:34:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 21750711BA Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mfJma-0000e3-2M; Tue, 26 Oct 2021 13:34:16 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 26 Oct 2021 13:34:15 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D1D35DBD2D15487EB9438C392F7C4E682D6CFA95551ADAC3182A05F5380850405A9BF17D7CAE92D533F5F31EB0DC5B7EA6D7D590CF546111BD18DB83BCE98C94 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A352E4F59960F77CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375D6F9E2FC7F7A8E98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8EBC2BA32BB18BE67E3F89D942BFC46F7117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF80095D1E57F4578A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C2749EEF4D85F8CCA30FD50D4ED9E3410A63559BC9E5E181D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF166FC1BB2721D293DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346E67BC984B8ABCB59A0AFE7BDFD90A5AECEBE29EFEB49C44946C21DF10B133F565C7128A9EA178E81D7E09C32AA3244C2BA88AB0E7B758587A941DFB234F91AF853296C06374E602729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojNvH0qP3qm72XLp6WW1+J7Q== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D39BA681451D8ED23C0B7BA121068F92383D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v4 07/16] sql: remove sql_vdbemem_finalize() 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" We don't need this function, since it is easier to call finalizers directly. This patch also allows us to make further simplifications. Needed for #4145 --- src/box/sql/mem.c | 33 ++------------------------------- src/box/sql/mem.h | 12 ------------ src/box/sql/vdbe.c | 27 ++++++++++++++++++++------- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 44ac5ad1e..917ff458c 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -217,15 +217,11 @@ mem_create(struct Mem *mem) static inline void mem_clear(struct Mem *mem) { - if ((mem->type & (MEM_TYPE_AGG | MEM_TYPE_FRAME)) != 0 || - (mem->flags & MEM_Dyn) != 0) { - if (mem->type == MEM_TYPE_AGG) - sql_vdbemem_finalize(mem, mem->u.func); - assert(mem->type != MEM_TYPE_AGG); + if (mem->type == MEM_TYPE_FRAME || (mem->flags & MEM_Dyn) != 0) { if ((mem->flags & MEM_Dyn) != 0) { assert(mem->xDel != SQL_DYNAMIC && mem->xDel != NULL); mem->xDel((void *)mem->z); - } else if (mem->type == MEM_TYPE_FRAME) { + } else { struct VdbeFrame *frame = mem->u.pFrame; frame->pParent = frame->v->pDelFrame; frame->v->pDelFrame = frame; @@ -2976,31 +2972,6 @@ sqlVdbeMemTooBig(Mem * p) return 0; } -int -sql_vdbemem_finalize(struct Mem *mem, struct func *func) -{ - assert(func != NULL); - assert(func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); - assert(func->def->aggregate == FUNC_AGGREGATE_GROUP); - assert(mem->type == MEM_TYPE_NULL || func == mem->u.func); - sql_context ctx; - memset(&ctx, 0, sizeof(ctx)); - Mem t; - memset(&t, 0, sizeof(t)); - t.type = MEM_TYPE_NULL; - assert(t.flags == 0); - t.db = mem->db; - ctx.pOut = &t; - ctx.pMem = mem; - ctx.func = func; - ((struct func_sql_builtin *)func)->finalize(&ctx); - assert((mem->flags & MEM_Dyn) == 0); - if (mem->szMalloc > 0) - sqlDbFree(mem->db, mem->zMalloc); - memcpy(mem, &t, sizeof(t)); - return ctx.is_aborted ? -1 : 0; -} - int sqlVdbeRecordCompareMsgpack(const void *key1, struct UnpackedRecord *key2) diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index b567aea50..7d5a750f5 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -949,18 +949,6 @@ int sqlVdbeMemTooBig(Mem *); #define VdbeMemDynamic(X) (((X)->flags & MEM_Dyn) != 0 ||\ ((X)->type & (MEM_TYPE_AGG | MEM_TYPE_FRAME)) != 0) -/** MEM manipulate functions. */ - -/** - * Memory cell mem contains the context of an aggregate function. - * This routine calls the finalize method for that function. The - * result of the aggregate is stored back into mem. - * - * Returns -1 if the finalizer reports an error. 0 otherwise. - */ -int -sql_vdbemem_finalize(struct Mem *mem, struct func *func); - /** * Perform comparison of two tuples: unpacked (key1) and packed (key2) * diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 7f1965492..067065a97 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4196,16 +4196,29 @@ case OP_AggStep: { * the step function was not previously called. */ case OP_AggFinal: { - Mem *pMem; assert(pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor)); - pMem = &aMem[pOp->p1]; - assert(mem_is_null(pMem) || mem_is_agg(pMem)); - if (sql_vdbemem_finalize(pMem, pOp->p4.func) != 0) + struct func_sql_builtin *func = (struct func_sql_builtin *)pOp->p4.func; + struct Mem *pIn1 = &aMem[pOp->p1]; + assert(mem_is_null(pIn1) || mem_is_agg(pIn1)); + + struct sql_context ctx; + memset(&ctx, 0, sizeof(ctx)); + struct Mem t; + mem_create(&t); + ctx.pOut = &t; + ctx.pMem = pIn1; + ctx.func = pOp->p4.func; + func->finalize(&ctx); + assert((pIn1->flags & MEM_Dyn) == 0); + if (pIn1->szMalloc > 0) + sqlDbFree(pIn1->db, pIn1->zMalloc); + memcpy(pIn1, &t, sizeof(t)); + + if (ctx.is_aborted) goto abort_due_to_error; - UPDATE_MAX_BLOBSIZE(pMem); - if (sqlVdbeMemTooBig(pMem)) { + UPDATE_MAX_BLOBSIZE(pIn1); + if (sqlVdbeMemTooBig(pIn1) != 0) goto too_big; - } break; } -- 2.25.1