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 C4D6C6EC43; Mon, 9 Aug 2021 10:19:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C4D6C6EC43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628493564; bh=X3yGvden2sR/Jkm+iykyi8RGqPf+Kt2nf1by7MJ7WQQ=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dJb05u34K1UXcp7ZF3Pb2KZiBDY0RMXwuovN3caZD9Ixbj/zc+1f1N1KIg96AgKNt Y7XrlcZIu2UJqW0cd26VXns7XZ1JtXJ/IxiVWGSPB5FTqYPXonY3aLFTHy/Z+Kfz9f 8WLZHyIznMh3tbte4id9XmiafRLd0Z6jUiOlhU2g= Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 07EE96EC43 for ; Mon, 9 Aug 2021 10:18:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 07EE96EC43 Received: by smtp17.mail.ru with esmtpa (envelope-from ) id 1mCzYl-0005k1-0n; Mon, 09 Aug 2021 10:18:55 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 9 Aug 2021 10:18:54 +0300 Message-Id: <9f04ffb91f7347af0fe7ce83f80e6e62d7d4a64f.1628493342.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F56291F8739A291D6182A05F53808504032D745D412B0E4958024CE70BBFF7737D3E9405867DEFD843DC2F72E0CD5555F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76B1ACD3B92AC1F27EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637509039C6BFF921C08638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84715D2715BA62EE05131F116A6F59471117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE599709FD55CB46A603F1AB874ED890284AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3AEB4DDBFD72C8FA176E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D021B5E63FB919E5C2 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C72045CD04223AD153F226F1A61F88ED0FC2CC159473C4DB79C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF5218A6880B2A9D02699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344B4608D01B1CB59A5F9BC65EDD06C340C4BB985A850DDBDB7D96B574899236F1937DC7024D8FAF631D7E09C32AA3244C3F463F0C3998FF14C3DFA866DDF9F0054DBEAD0ED6C55A80729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMTMPlNJj3ShDa3PozQzBuw== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306EDFB7531A7BF75C9278024CE70BBFF77375F9045B74F665CC85105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 1/6] sql: introduce sql_func_flags() 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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This function returns a set of parameters for the function with the given name. This function is used when we do not need to call a function, but we need its parameters. In addition, this function will allow us to split the parameters between those that are the same for all implementations, and the parameters, the value of which is implementation-dependent. Needed for #6105 Part of #6106 --- src/box/sql/expr.c | 9 +++------ src/box/sql/func.c | 12 ++++++++++++ src/box/sql/sqlInt.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index d2624516c..80f2d349a 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -328,11 +328,8 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id, if (op == TK_FUNCTION) { uint32_t arg_count = p->x.pList == NULL ? 0 : p->x.pList->nExpr; - struct func *func = - sql_func_by_signature(p->u.zToken, arg_count); - if (func == NULL) - break; - if (sql_func_flag_is_set(func, SQL_FUNC_DERIVEDCOLL) && + uint32_t flags = sql_func_flags(p->u.zToken); + if (((flags & SQL_FUNC_DERIVEDCOLL) != 0) && arg_count > 0) { /* * Now we use quite straightforward @@ -342,7 +339,7 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id, * built-in functions: trim, upper, * lower, replace, substr. */ - assert(func->def->returns == FIELD_TYPE_STRING); + assert(p->type == FIELD_TYPE_STRING); p = p->x.pList->a->pExpr; continue; } diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 6ca852dec..28d383293 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -2655,6 +2655,18 @@ static struct { }, }; +uint32_t +sql_func_flags(const char *name) +{ + struct func *func = func_by_name(name, strlen(name)); + if (func == NULL || func->def->language != FUNC_LANGUAGE_SQL_BUILTIN) + return 0; + uint32_t flags = ((struct func_sql_builtin *)func)->flags; + if (func->def->aggregate == FUNC_AGGREGATE_GROUP) + flags |= SQL_FUNC_AGG; + return flags; +} + static struct func_vtab func_sql_builtin_vtab; struct func * diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 115c52f96..a92de0a2f 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -1186,6 +1186,8 @@ struct type_def { * SQL_FUNC_LENGTH == OPFLAG_LENGTHARG * SQL_FUNC_TYPEOF == OPFLAG_TYPEOFARG */ +/** Function is one of aggregate functions. */ +#define SQL_FUNC_AGG 0x0001 #define SQL_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ #define SQL_FUNC_NEEDCOLL 0x0020 /* sqlGetFuncCollSeq() might be called. * The flag is set when the collation @@ -4372,6 +4374,14 @@ sql_func_flag_is_set(struct func *func, uint16_t flag) struct func * sql_func_by_signature(const char *name, int argc); +/** + * Return the parameters of the function with the given name. If the function + * with the given name does not exist, or the function is not a built-in SQL + * function, 0 is returned, which means no parameters have been set. + */ +uint32_t +sql_func_flags(const char *name); + /** * Generate VDBE code to halt execution with correct error if * the object with specified key is already present (or doesn't -- 2.25.1