From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 8A17C27B2D for ; Mon, 11 Mar 2019 14:10:30 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JjpLozaA7roT for ; Mon, 11 Mar 2019 14:10:30 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B939727797 for ; Mon, 11 Mar 2019 14:10:29 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 2/2] sql: don't change type of function's retval after codegen Date: Mon, 11 Mar 2019 21:10:26 +0300 Message-Id: <9a7a2794d68a949b801a3210231a35562fcf8847.1552327461.git.korablev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik Proper type of function's returning value is set during names resolution (i.e. promotion from struct FuncDef to struct Expr, see resolveExprStep()). Accidentally, it was set again during byte-code generation for VDBE. What is more, in some cases it was set to a wrong type. For instance, built-in function randomblob() returns value to be encoded as MP_BIN, so its returning type is SCALAR. However, it was reset to INTEGER (as its first argument). This patch simply removes this second type promotion. --- src/box/sql/expr.c | 11 ----------- test/sql/iproto.result | 41 +++++++++++++++++++++++++++++++++++++++++ test/sql/iproto.test.lua | 15 +++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index a75f23756..8efd0631a 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4000,17 +4000,6 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) sql_parser_error(pParse); break; } - - if (pDef->ret_type != FIELD_TYPE_SCALAR) { - pExpr->type = pDef->ret_type; - } else { - /* - * Otherwise, use first arg as - * expression type. - */ - if (pFarg && pFarg->nExpr > 0) - pExpr->type = pFarg->a[0].pExpr->type; - } /* Attempt a direct implementation of the built-in COALESCE() and * IFNULL() functions. This avoids unnecessary evaluation of * arguments past the first non-NULL argument. diff --git a/test/sql/iproto.result b/test/sql/iproto.result index 3a77c8e93..26d55b60c 100644 --- a/test/sql/iproto.result +++ b/test/sql/iproto.result @@ -942,6 +942,47 @@ res.metadata - name: detail type: TEXT ... +-- Make sure that built-in functions have a right returning type. +-- +cn:execute("SELECT zeroblob(1);") +--- +- metadata: + - name: zeroblob(1) + type: scalar + rows: + - ["\0"] +... +-- randomblob() returns different results each time, so check only +-- type in meta. +-- +res = cn:execute("SELECT randomblob(1);") +--- +... +res.metadata +--- +- - name: randomblob(1) + type: scalar +... +-- Type set during compilation stage, and since min/max are accept +-- arguments of all scalar type, we can't say nothing more than +-- SCALAR. +-- +cn:execute("SELECT min(1, 2, 3);") +--- +- metadata: + - name: min(1, 2, 3) + type: scalar + rows: + - [1] +... +cn:execute("SELECT max(1, 2, 3);") +--- +- metadata: + - name: max(1, 2, 3) + type: scalar + rows: + - [3] +... cn:close() --- ... diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua index fbdc5a2ae..89d04b638 100644 --- a/test/sql/iproto.test.lua +++ b/test/sql/iproto.test.lua @@ -289,6 +289,21 @@ res.metadata res = cn:execute("EXPLAIN QUERY PLAN SELECT COUNT(*) FROM t1") res.metadata +-- Make sure that built-in functions have a right returning type. +-- +cn:execute("SELECT zeroblob(1);") +-- randomblob() returns different results each time, so check only +-- type in meta. +-- +res = cn:execute("SELECT randomblob(1);") +res.metadata +-- Type set during compilation stage, and since min/max are accept +-- arguments of all scalar type, we can't say nothing more than +-- SCALAR. +-- +cn:execute("SELECT min(1, 2, 3);") +cn:execute("SELECT max(1, 2, 3);") + cn:close() box.sql.execute('DROP TABLE t1') -- 2.15.1