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 608996EC57; Fri, 15 Oct 2021 01:42:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 608996EC57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1634251377; bh=/K9a1RCAG/DeH1K1flVnmkFoydn6RJIgKRo6vp1MtCY=; 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=SRTNbsrtDOySSsUjcJeuXldUK/z0w/CYEGUcxfqOPP0cgbrnQmwjEi5ZuusAJmAAv llEQHQAxpvSnHvxSHLdOOjjZNMQi0VMtHi4mxsf6lTbsQGcWA0kIggc5P/tyTLSepV acfr+NOwENlP29hrdYGTAAK0/IA69nX77pW2Ghwk= 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 A4C7E6EC57 for ; Fri, 15 Oct 2021 01:42:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A4C7E6EC57 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mb9R5-0008NL-Tc; Fri, 15 Oct 2021 01:42:52 +0300 Message-ID: <7e30f0f7-3d1c-cce0-fe92-d179a0a2eaa8@tarantool.org> Date: Fri, 15 Oct 2021 00:42:50 +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 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <54d782249ceddfa9d8dbc427413c3b1df669c5d6.1633713432.git.imeevma@gmail.com> Content-Language: en-US In-Reply-To: <54d782249ceddfa9d8dbc427413c3b1df669c5d6.1633713432.git.imeevma@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9AE9EF867AE584ADA95BFAE125EB81830277DAF1B4CFC2816182A05F538085040E4416F21C72429215CF78460EC050F3F933E5DE5051CD9E6490BAD1F937E2EFF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78E8764B5BC580342EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371E4BC0E00C009995EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2272FCF5EC63B58D4BC35FE650BBC7492CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2DCF9CF1F528DBCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDAE3FA6833AEA0C275ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50580647984BABFFB52FD26E8D3DFB77C9E X-C1DE0DAB: 0D63561A33F958A52F3CE3CC34F0771513C988810E3292935096C4A3886FD312D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7557E988E9157162368E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349C39CCCDAABCB54B4AFED56C45F956F91B1507A53D6E217E5CEC06DB6AAB4350A6FDA18F9FEB12121D7E09C32AA3244C91D32DF494C06A374343B31792E31AE5A8CE788DE6831205729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojZCle+NCKLXHqf55UU1v/rw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D5FFFAE4368933B4C6C21CCE05C7A236E3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 02/21] sql: refactor GREATEST() and LEAST() functions 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 working on this! > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index dd5e7d785..7886f5f40 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -777,6 +777,29 @@ func_char(struct sql_context *ctx, int argc, struct Mem *argv) > mem_set_str_allocated(ctx->pOut, str, (char *)ptr - str); > } > > +/** Implementation of the GREATEST() and LEAST() functions. */ > +static void > +func_greatest_least(struct sql_context *ctx, int argc, struct Mem *argv) > +{ > + assert(argc > 1); > + int mask = ctx->func->def->name[0] == 'G' ? -1 : 0; > + assert(ctx->func->def->name[0] == 'G' || > + ctx->func->def->name[0] == 'L'); Why don't you use the flag SQL_FUNC_MAX like it was done before? > + > + if (mem_is_null(&argv[0])) > + return; > + int best = 0; > + for (int i = 1; i < argc; ++i) { > + if (mem_is_null(&argv[i])) > + return; > + int cmp = mem_cmp_scalar(&argv[best], &argv[i], ctx->coll); > + if ((cmp ^ mask) >= 0) > + best = i; > + } > + if (mem_copy(ctx->pOut, &argv[best]) != 0) > + ctx->is_aborted = true; > +}