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 78E2C3002A for ; Fri, 24 May 2019 13:39:45 -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 HwCSdWcAtmFM for ; Fri, 24 May 2019 13:39:45 -0400 (EDT) Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 1FC6130036 for ; Fri, 24 May 2019 13:39:45 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 2/3] sql: remove redundant type derivation from QP Date: Fri, 24 May 2019 20:39:40 +0300 Message-Id: <20bccdb8bed2bab9e9eaaca3781e3d0b5b780d10.1558700151.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: Nikita Pettik Before value to be scanned in index search is passed to the iterator, it is subjected to implicit type casting (which is implemented by OP_ApplyType). If value can't be converted to required type, user-friendly message is raised. Without this cast, type of iterator may not match with type of key which in turn results in unexpected error. However, array of types which is used to provide type conversions is different from types of indexed fields: it is modified depending on types of comparison's operands. For instance, when boolean field is compared with blob value, resulting type is assumed to be scalar. In turn, conversion to scalar is no-op. As a result, value with MP_BIN format is passed to the iterator over boolean field. To fix that let's remove this transformation of types. Moreover, it seems to be redundant. Part of #4187 --- src/box/sql/wherecode.c | 10 ---------- test/sql/types.result | 30 ++++++++++++++++++++++++++++++ test/sql/types.test.lua | 12 ++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c index 6f72506ad..977c0fced 100644 --- a/src/box/sql/wherecode.c +++ b/src/box/sql/wherecode.c @@ -769,16 +769,6 @@ codeAllEqualityTerms(Parse * pParse, /* Parsing context */ pLevel->addrBrk); VdbeCoverage(v); } - if (type != NULL) { - enum field_type rhs_type = - sql_expr_type(pRight); - if (sql_type_result(rhs_type, type[j]) == - FIELD_TYPE_SCALAR) { - type[j] = FIELD_TYPE_SCALAR; - } - if (sql_expr_needs_no_type_change(pRight, type[j])) - type[j] = FIELD_TYPE_SCALAR; - } } } *res_type = type; diff --git a/test/sql/types.result b/test/sql/types.result index bc4518c01..758018eb5 100644 --- a/test/sql/types.result +++ b/test/sql/types.result @@ -897,3 +897,33 @@ box.execute('SELECT ?', {true}) rows: - [true] ... +-- gh-4187: make sure that value passsed to the iterator has +-- the same type as indexed fields. +-- +box.execute("CREATE TABLE tboolean (s1 BOOLEAN PRIMARY KEY);") +--- +- row_count: 1 +... +box.execute("INSERT INTO tboolean VALUES (TRUE);") +--- +- row_count: 1 +... +box.execute("SELECT * FROM tboolean WHERE s1 = x'44';") +--- +- error: 'Type mismatch: can not convert D to boolean' +... +box.execute("SELECT * FROM tboolean WHERE s1 = 'abc';") +--- +- error: 'Type mismatch: can not convert abc to boolean' +... +box.execute("SELECT * FROM tboolean WHERE s1 = 1;") +--- +- error: 'Type mismatch: can not convert INTEGER to boolean' +... +box.execute("SELECT * FROM tboolean WHERE s1 = 1.123;") +--- +- error: 'Type mismatch: can not convert REAL to boolean' +... +box.space.TBOOLEAN:drop() +--- +... diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua index c51660cb9..3c7bd5ea3 100644 --- a/test/sql/types.test.lua +++ b/test/sql/types.test.lua @@ -216,3 +216,15 @@ box.execute('SELECT \'9223372036854\' + 1;') -- Fix BOOLEAN bindings. box.execute('SELECT ?', {true}) + +-- gh-4187: make sure that value passsed to the iterator has +-- the same type as indexed fields. +-- +box.execute("CREATE TABLE tboolean (s1 BOOLEAN PRIMARY KEY);") +box.execute("INSERT INTO tboolean VALUES (TRUE);") +box.execute("SELECT * FROM tboolean WHERE s1 = x'44';") +box.execute("SELECT * FROM tboolean WHERE s1 = 'abc';") +box.execute("SELECT * FROM tboolean WHERE s1 = 1;") +box.execute("SELECT * FROM tboolean WHERE s1 = 1.123;") + +box.space.TBOOLEAN:drop() -- 2.15.1