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 187A16ECE3; Tue, 19 Oct 2021 14:17:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 187A16ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1634642227; bh=TIJg6rXRgHI6gkqtSZ6tX+9bg4FoBOO6DAmoBnynn1U=; 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=quxDC48Q0A1bgLjGlTJUBMreGRH9tNrQqEQAELJR3LXs0+KqweboCjcBnTaDS4wvY nTWIgvyem3a9HwLeGDbht4t8bluZS8JsNiA5AVy4qt7QzgxTLJuxdyFYfx7sN3sl+H Pzm71yDpPtUpT3YNS3j45TnvqmzM/3M0qKDRe4Uo= 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 CD3556ECE3 for ; Tue, 19 Oct 2021 14:17:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CD3556ECE3 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mcn7B-0002dX-36; Tue, 19 Oct 2021 14:17:05 +0300 Date: Tue, 19 Oct 2021 14:17:03 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20211019111703.GA190326@tarantool.org> References: <32c9fec9-30b6-f213-3a49-8772be433e99@tarantool.org> <20211005095537.GF55311@tarantool.org> <88406fd6-2fc7-f2b8-ddbd-9757cc20b384@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <88406fd6-2fc7-f2b8-ddbd-9757cc20b384@tarantool.org> X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9C7814344C8C501C83238E3156CE19B78C95C7AD4390B7974182A05F538085040AD9E88A8F46950954714D7416A7B30FF324CF8AAA3DF24215D5D40D2DA3C868F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DEFE6A28F0C4BE99C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE763424119D34F5CBFEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2AEF9326B46303ADED31211E105B24AE7CC7F00164DA146DAFE8445B8C89999728AA50765F790063767B9C6E70FBE8DD8389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC84E7D9683544204AFF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B953A8A48A05D51F175ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A562AB07080F689CBACA25D3C22ADDACF16C24692D4DD12C71D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7557E988E9157162368E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3403182E70AE6895E0001D3C5288851B5070B8434EC1DEA0C9FF246732CF381214E42AF7AF0741F2DC1D7E09C32AA3244C8C8878AE1763BBFF98C0C59C9BC5FB07CE0B41342B755BCD729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSRIpe8siFhV1BO7fmP5jHw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DAB949B8886D7557848EE2DBD2DB9AFE683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you for the review! My answer below. On Mon, Oct 11, 2021 at 11:51:07PM +0200, Vladislav Shpilevoy wrote: > 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. Ok, understood. I filled an issue: https://github.com/tarantool/tarantool/issues/6533