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 8EAB86D3F5; Mon, 25 Oct 2021 11:17:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8EAB86D3F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635149833; bh=wg/sA3Ny6ihDHV1hAVVw9+LaItoTmUKWaMz52EVwDPM=; 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=K6sphrN9RgB+JzZbMDiRf3kfPZCCbLdwvcbzSxUY/SP/KvV8R14iCH1Qe3dKNxVwy xKzXPbka+yZPS76xg0naDHpir9QxJFPMn+bxISbDK+o7ie+su1RKJQcW1ypXd66HrK F+LhpAZkijkkskS7F5QBej/nSXzqNZBQ9emBax5Q= 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 1C5886D3F5 for ; Mon, 25 Oct 2021 11:17:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1C5886D3F5 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mevAN-00066m-Fq; Mon, 25 Oct 2021 11:17:11 +0300 Date: Mon, 25 Oct 2021 11:17:10 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20211025081710.GB36295@tarantool.org> References: <54d782249ceddfa9d8dbc427413c3b1df669c5d6.1633713432.git.imeevma@gmail.com> <7e30f0f7-3d1c-cce0-fe92-d179a0a2eaa8@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7e30f0f7-3d1c-cce0-fe92-d179a0a2eaa8@tarantool.org> X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9C7814344C8C501C81DF2D982FCC3642ABC592EA95DC3FE9F182A05F538085040411B7A35C3173297E17B7209E9457A0AD5C128F9BBBBE37274C1F4FFF85591D7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE752E71F0C64B7C834EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D8F1FE4E764DFCDEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F210AFCC721902006301E22677FC78129BCC7F00164DA146DAFE8445B8C89999728AA50765F7900637F6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9B5C8C57E37DE458B9E9CE733340B9D5F3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7354E672349037D5FA5C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A53CC80B761ED69B50DBCD5FFDEAE686CE553577876A6598CCD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75FA7FF33AA1A4D21C410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A08F09726D78E07B96E0EF789B907D83A11F844828A90056447DCCA6164AD8A5CB1D9E44AAFC4B1A1D7E09C32AA3244C306A59F9F54CF0C7C449C19F00E2BAA0435BF7150578642F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPL6H901iH3ETh0B89eQYZQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DDA2A942C08BAFE71F1F96AF39BFFA43983D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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: 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 and diff below. On Fri, Oct 15, 2021 at 12:42:50AM +0200, Vladislav Shpilevoy wrote: > 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? > This flag, together with SQL_FUNC_MIN, has only two uses. The first is to show that the aggregate function is a MIN() or MAX() function, and use the feature described in "Define rule for GROUP BY" discussion: https://github.com/tarantool/tarantool/discussions/6416 Another use is to determine is the function MIN() or MAX(). Since I am planning to drop that feature, I think it is best to remove these flags from LEAST()/GREATEST() now. I removed these flags from the definitions of the LEAST()/GREATEST() functions. In general, I find it awkward to use flags here, and I think we should drop them in the future. The only useful flag is SQL_FUNC_AGG. > > + > > + 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; > > +} Diff: diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 6bde3759d..7d2f03542 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -768,7 +768,12 @@ func_char(struct sql_context *ctx, int argc, struct Mem *argv) mem_set_str_allocated(ctx->pOut, str, len); } -/** Implementation of the GREATEST() and LEAST() functions. */ +/** + * Implementation of the GREATEST() and LEAST() functions. + * + * The GREATEST() function returns the largest of the given arguments. + * The LEAST() function returns the smallest of the given arguments. + */ static void func_greatest_least(struct sql_context *ctx, int argc, struct Mem *argv) { @@ -1766,13 +1771,11 @@ static struct sql_func_dictionary dictionaries[] = { {"CHAR_LENGTH", 1, 1, 0, true, 0, NULL}, {"COALESCE", 2, SQL_MAX_FUNCTION_ARG, SQL_FUNC_COALESCE, true, 0, NULL}, {"COUNT", 0, 1, SQL_FUNC_AGG, false, 0, NULL}, - {"GREATEST", 2, SQL_MAX_FUNCTION_ARG, SQL_FUNC_MAX | SQL_FUNC_NEEDCOLL, - true, 0, NULL}, + {"GREATEST", 2, SQL_MAX_FUNCTION_ARG, SQL_FUNC_NEEDCOLL, true, 0, NULL}, {"GROUP_CONCAT", 1, 2, SQL_FUNC_AGG, false, 0, NULL}, {"HEX", 1, 1, 0, true, 0, NULL}, {"IFNULL", 2, 2, SQL_FUNC_COALESCE, true, 0, NULL}, - {"LEAST", 2, SQL_MAX_FUNCTION_ARG, SQL_FUNC_MIN | SQL_FUNC_NEEDCOLL, - true, 0, NULL}, + {"LEAST", 2, SQL_MAX_FUNCTION_ARG, SQL_FUNC_NEEDCOLL, true, 0, NULL}, {"LENGTH", 1, 1, SQL_FUNC_LENGTH, true, 0, NULL}, {"LIKE", 2, 3, SQL_FUNC_LIKE | SQL_FUNC_NEEDCOLL, true, 0, NULL}, {"LIKELIHOOD", 2, 2, SQL_FUNC_UNLIKELY, true, 0, NULL},