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 B06BB70CBA; Tue, 12 Oct 2021 00:51:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B06BB70CBA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633989074; bh=bK44DJBstfUP/JSrjyNSkjNFmJNKoEhMWhVtlpeFAj8=; 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=n9Jdmky8ijCB2/jh0fV0qTjQ2YuHrN4zbq7AzgKLNE2rvzHK0X2YfbqnXoVQ01qE5 VhoHJmFYCozLpnt1ziKwyXcQQVGWe/cbSAHq+8SsT0/RO77ijlWUy73g3sqQ8FZ97J hCEXg2JaR+EIxEHSQPXWotfQiipM5WO2PKkVHi0E= 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 44C226FFA1 for ; Tue, 12 Oct 2021 00:51:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 44C226FFA1 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ma3CO-0003cj-M6; Tue, 12 Oct 2021 00:51:09 +0300 Message-ID: <88406fd6-2fc7-f2b8-ddbd-9757cc20b384@tarantool.org> Date: Mon, 11 Oct 2021 23:51:07 +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: <32c9fec9-30b6-f213-3a49-8772be433e99@tarantool.org> <20211005095537.GF55311@tarantool.org> In-Reply-To: <20211005095537.GF55311@tarantool.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD922964B4BA091D9ACDB65386DFBCFEF8EC4071E24A83365FC182A05F5380850405633A8BFE884895BFB5CB1FCA601E1353F6F4583200D60684111AA74C89D7493 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE788A2BECDB72C1542EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378BCFB34D7DDF138E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F48F2206CF2626C943407A7256946E8E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC44DFDAE72D78788F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC84CB6874B0BCFF0B8F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDAE3FA6833AEA0C275ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50559325BC3F25EBEA231C6321D2F1BEA1C X-C1DE0DAB: 0D63561A33F958A5EBBF1B31013B5C3FE58FEA1681FD113375352E5898750370D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349FD10E01B3CDC9E26F609366C6F41BBD4DECFB7F1E1F1BEAA7FA5C460830EC879C4AFAB0AC103CC21D7E09C32AA3244CF2AFEC819A06EDCC420E4DC9F0CF7FEBCE0B41342B755BCD729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioju/+AAevgYAVBuk67FQn4EQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC73D6D7FA71D6ED2DEBDEEB3EF87B9CC3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 11/16] sql: refactor COUNT() 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! >>> diff --git a/src/box/sql/func.c b/src/box/sql/func.c >>> index 94ec811ef..384c68be8 100644 >>> --- a/src/box/sql/func.c >>> +++ b/src/box/sql/func.c >>> @@ -154,6 +154,29 @@ fin_avg(struct sql_context *ctx) >>> ctx->is_aborted = true; >>> } >>> >>> +/** Implementation of the COUNT() function. */ >>> +static void >>> +step_count(struct sql_context *ctx, int argc, struct Mem **argv) >>> +{ >>> + assert(argc == 0 || argc == 1); >>> + if (mem_is_null(ctx->pMem)) >>> + mem_set_uint(ctx->pMem, 0); >> >> Would be nice to have a 'begin' step for the aggregation >> functions. This would allow to eliminate these 'if is null' >> ifs in some step functions in favor of having +1 virtual 'begin' >> call in the beginning. >> >> Do you think it would simplify/speed up things? If you agree, >> could you please create a ticket for that? As 'good first issue' >> even. >> >> If don't agree, then ignore this comment. > I think this is a good idea, but I don't see a suitable way to implement it. The > problem is that in case we receive NULL as an argument, we will have NULL in > pMem/pOut after the first step, and we still have to call begin() again or check > with 'if'. And there is no way to determine how much NULLs will there be. There are functions where it does not matter. For example, TOTAL() never returns NULL. You could initialize its accumulator with 0 from the beginning and drop mem_set_double(ctx->pMem, 0.0); from step_total() and fin_total(). The same for COUNT() and mem_set_uint(ctx->pMem, 0). We have more functions like these AFAIR.