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 91B1770CBA; Tue, 12 Oct 2021 00:50:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 91B1770CBA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633989043; bh=1x+axS13vO08P91fjGR3v4ZVd0BeItrnzvkssBICM4c=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=A8O12yZ6JLdkEpU8f+05YuXE4Kdkmc5TA6cR4LjQLbB9k+Uw91R+F2mmtdNhAdwzm v6cmneeGOb2LrxkD+ryCItA3dWUL75orDtXIBk3WWyhaZbULjsjyu3ascnO9mJQup8 krEPeTG1Kxpw1P7ZqGDo4K3Jbs2cjfJ8eZiYV69Y= 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 85B916FC8B for ; Tue, 12 Oct 2021 00:50:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 85B916FC8B Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ma3Bw-0003Uj-QX; Tue, 12 Oct 2021 00:50:41 +0300 Message-ID: <38e0558f-2cce-bf78-0be9-92e9c60c2379@tarantool.org> Date: Mon, 11 Oct 2021 23:50:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Content-Language: en-US To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <3543f4417e240c74d1dea9a2b6e086aeca950167.1633092363.git.imeevma@gmail.com> <6dfd69ff-a807-b0d5-4896-4b5118ee2679@tarantool.org> <20211005094806.GE55311@tarantool.org> In-Reply-To: <20211005094806.GE55311@tarantool.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD922964B4BA091D9AC4A5E31101C019806DCD444E38A373F3D182A05F5380850404A90BD011D9C82E3379E21F7C00B0E39B95F12AF6946793EB947F711D7CA316F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CE015DA2C687B387EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748D05F5E01EE6C998638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85A081F467F7A88979A4D8845FAE2A0F8117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3733B5EC72352B9FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FCB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50559325BC3F25EBEA279C55DD6CCA3363C X-C1DE0DAB: 0D63561A33F958A5C0ADA25FCFCD3EE32C5EAB4D6E57DBA61659AAF9E830DC66D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34682FD2D2951524C562128AEE72EB463386CCAC38DFD7453332B84E87A803DC17FBBB11AE486DFC8A1D7E09C32AA3244C560D5592B668F539197FF2AFB7A948DC30452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioju/+AAevgYAVFSKHCKyZwHQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D2211DB804CA81C692CFDF750B87FB5303841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 10/16] sql: refactor AVG() function 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the fixes! >> @@ -141,17 +141,14 @@ fin_avg(struct sql_context *ctx) >> assert(mem_is_null(ctx->pMem) || mem_is_bin(ctx->pMem)); >> if (mem_is_null(ctx->pMem)) >> return mem_set_null(ctx->pOut); >> - struct Mem *tmp = (struct Mem *)ctx->pMem->z; >> - uint32_t *count_val = (uint32_t *)(tmp + 1); >> - struct Mem sum; >> - mem_create(&sum); >> - mem_copy_as_ephemeral(&sum, tmp); >> - mem_destroy(tmp); >> + struct Mem *sum = (struct Mem *)ctx->pMem->z; >> + uint32_t *count_val = (uint32_t *)(sum + 1); >> struct Mem count; >> mem_create(&count); >> mem_set_uint(&count, *count_val); >> if (mem_div(&sum, &count, ctx->pOut) != 0) >> ctx->is_aborted = true; >> + mem_destroy(sum); >> } > This will work, however, I think it will create some unnecessary restrictions > due to changes with pMem and pOut in a few patches. I suggest to apply part of > you diff with exception of mem_destroy(), which I sugget to replace by assert(). > We have full control over this tmp/sum mem and we know, that there will be no > memory to free, so assert should be enough. > > What do you think of this diff? It looks the same as mine except you didn't call the destroy. I am fine with it, but when I propose to wrap the check about a mem not needing a destroy into a function. We should not use mem members as is when possible. It is a too complicated structure. So far. Something like mem_is_trivial(). If it returns true, you don't need to call mem_clear()/mem_destroy() and nothing will leak.