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 387A02AAE1 for ; Mon, 17 Sep 2018 16:33:19 -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 ATGMJh6TX2rH for ; Mon, 17 Sep 2018 16:33:19 -0400 (EDT) Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (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 EB6732AA8D for ; Mon, 17 Sep 2018 16:33:18 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 6/6] sql: discard numeric conversion by unary plus Date: Mon, 17 Sep 2018 23:32:30 +0300 Message-Id: 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: Nikita Pettik In SQLite unary plus behaves as implicit conversion to numeric type. Consider following example: CREATE TABLE t1 (id INT PRIMARY KEY, a TEXT, b BLOB); INSERT INTO t1 VALUES (1, '99', '99'); SELECT * FROM t1 WHERE a = b; (*) SELECT * FROM t1 WHERE +a = +b; (**) Since BLOB and TEXT are incompatible, result of (*) would be empty set. However, comparison in second query (**) would be of types, and result set would consist of one tuple [1, '99', '99']. Lets discard this conversion produced by unary plus, since it implicitly affects result set of query and no one other DB support such behaviour. Instead, simply use type of operand it is related to. --- src/box/sql/expr.c | 9 ++++++ test/sql-tap/whereB.test.lua | 72 ++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 534d856eb..aff1f35fd 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -115,6 +115,15 @@ sqlite3ExprAffinity(Expr * pExpr) &field_no); return pExpr->space_def->fields[field_no].affinity; } + /* + * In case of unary plus we shouldn't discard + * affinity of operand (since plus always features + * NUMERIC affinity). + */ + if (op == TK_UPLUS) { + assert(pExpr->pRight == NULL); + return pExpr->pLeft->affinity; + } return pExpr->affinity; } diff --git a/test/sql-tap/whereB.test.lua b/test/sql-tap/whereB.test.lua index 7e2aff078..42d90fa18 100755 --- a/test/sql-tap/whereB.test.lua +++ b/test/sql-tap/whereB.test.lua @@ -357,14 +357,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-4.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -393,14 +393,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-4.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -457,14 +457,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-5.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -493,14 +493,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-5.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -557,14 +557,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-6.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -593,14 +593,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-6.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -657,14 +657,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-7.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -693,14 +693,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-7.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -757,14 +757,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-8.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -793,14 +793,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-8.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -857,14 +857,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-9.4", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) @@ -893,14 +893,14 @@ test:do_execsql_test( test:do_execsql_test( "whereB-9.102", - -- In this case the unary "+" operator removes the column affinity so - -- the columns compare false + -- In this case the unary "+" operator shouldn't + -- affect result set of query. [[ SELECT x, a, y=b FROM t1, t2 WHERE +y=+b; ]], { -- - + 1, 2, 1 -- }) -- 2.15.1