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 269E66EC45; Wed, 11 Aug 2021 19:05:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 269E66EC45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628697914; bh=/gXET1G8J6iy+4VsKyLG4yztaXn37aDGWvVOvEYZxI4=; 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=D58hTWkx+0QKvXcXcSC0/96o/snCW/wG/eplswpEcKvrHMCWsuwOb9p1H+zrU1tuU gZz8y8LW9sKJOq/2XwBIN6hVaO60AtLWWDsrPWt1uk8lJAYhJjeX/YaSABOy75dqTq elu8FXh7nqTUoR8HdYuY3PqwAMuRRXy8d4MgfCOM= 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 00B5A6EC5D for ; Wed, 11 Aug 2021 19:01:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 00B5A6EC5D Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mDqfx-0005km-CK; Wed, 11 Aug 2021 19:01:53 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Wed, 11 Aug 2021 19:01:53 +0300 Message-Id: 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: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F56291F8739A291D6182A05F5380850408B3F9271F7E75C19EB4B0F10CFC3488672221FBF31F30576F7A21FBA0C770DDE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76574C3D62D66A535EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E88AB9B4A10918C78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D858601B7958C54B5D5CE4A8720BBC8C3E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C6B668463F4F89F86BAB31AFD0C957B8F9977E5288FEDF3299C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA183FDCE24978B01699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34524B2D44961BF9C6ED826482DE6CFA218E812435291819E92050C3FB135C012C72B201702B32A3F91D7E09C32AA3244CD25B28BF2010EA1B094EFD103C79444E55E75C8D0ED9F6EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6qlzQV0oSZP6inpPHvZ91w== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DBA25F69691D7F34F4C44E09815BBBC9683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 7/7] sql: fix comparison with SCALAR value 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" After this patch, SCALAR values will be able to be compared with values of any other scalar type. The comparison will be done according to the SCALAR rules, which means boolean values < numeric values < string values < binary values < uuid values. Closes #6221 --- ...21-re-introduce-scalar-and-number-types.md | 8 +++ src/box/sql/mem.c | 4 ++ test/sql-tap/cast.test.lua | 4 +- test/sql-tap/metatypes.test.lua | 51 ++++++++++++++++++- test/sql/boolean.result | 14 +++-- 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 changelogs/unreleased/gh-6221-re-introduce-scalar-and-number-types.md diff --git a/changelogs/unreleased/gh-6221-re-introduce-scalar-and-number-types.md b/changelogs/unreleased/gh-6221-re-introduce-scalar-and-number-types.md new file mode 100644 index 000000000..842e8a4e2 --- /dev/null +++ b/changelogs/unreleased/gh-6221-re-introduce-scalar-and-number-types.md @@ -0,0 +1,8 @@ +## feature/sql + +* The SCALAR and NUMBER types have been reworked in SQL. Now SCALAR values +cannot be implicitly cast to any other scalar type, and NUMBER values cannot be +implicitly cast to any other numeric type. This means that arithmetic and +bitwise operations and concatenation are no longer allowed for SCALAR and NUMBER +values. In addition, any SCALAR value can now be compared with values of any +other scalar type using the SCALAR rules (gh-6221). diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 732d1b012..066940fac 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -2062,6 +2062,10 @@ mem_cmp(const struct Mem *a, const struct Mem *b, int *result, *result = 1; return 0; } + if (((a->flags | b->flags) & MEM_Scalar) != 0) { + *result = mem_cmp_scalar(a, b, coll); + return 0; + } if (class_a != class_b) { diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(b), mem_type_class_to_str(a)); diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua index e0295fd3b..68d2ae585 100755 --- a/test/sql-tap/cast.test.lua +++ b/test/sql-tap/cast.test.lua @@ -1157,12 +1157,12 @@ test:do_execsql_test( }) -- Make sure that there is no unnecessary implicit casts in IN operator. -test:do_catchsql_test( +test:do_execsql_test( "cast-12", [[ SELECT 1 IN (SELECT '1'); ]], { - 1, "Type mismatch: can not convert integer(1) to string" + false }) test:finish_test() diff --git a/test/sql-tap/metatypes.test.lua b/test/sql-tap/metatypes.test.lua index b767e3f31..349c670ba 100755 --- a/test/sql-tap/metatypes.test.lua +++ b/test/sql-tap/metatypes.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(13) +test:plan(19) -- Check that SCALAR and NUMBER meta-types works as intended. box.execute([[CREATE TABLE t (i INT PRIMARY KEY, s SCALAR, n NUMBER);]]) @@ -133,6 +133,55 @@ test:do_catchsql_test( 1, "Inconsistent types: expected string or varbinary got scalar('asd')" }) +-- Check that SCALAR values can be compared to values of any other scalar type. +test:do_execsql_test( + "metatypes-6.1", + [[ + SELECT s > false FROM t; + ]], { + true, true, true, true, true, true + }) + +test:do_execsql_test( + "metatypes-6.2", + [[ + SELECT s = 1 FROM t; + ]], { + true, false, false, false, false, false + }) + +test:do_execsql_test( + "metatypes-6.3", + [[ + SELECT s != 1.5 FROM t; + ]], { + true, true, true, true, true, true + }) + +test:do_execsql_test( + "metatypes-6.4", + [[ + SELECT s <= 'abc' FROM t; + ]], { + true, true, true, true, false, false + }) + +test:do_execsql_test( + "metatypes-6.5", + [[ + SELECT s < x'10' FROM t; + ]], { + true, true, true, true, false, false + }) + +test:do_execsql_test( + "metatypes-6.6", + [[ + SELECT s > CAST('11111111-1111-1111-1111-111111111110' AS UUID) FROM t; + ]], { + false, false, false, false, false, true + }) + box.execute([[DROP TABLE t;]]) test:finish_test() diff --git a/test/sql/boolean.result b/test/sql/boolean.result index a8400ee49..a9ce37e11 100644 --- a/test/sql/boolean.result +++ b/test/sql/boolean.result @@ -137,13 +137,19 @@ INSERT INTO ts(s) VALUES ('abc'), (12.5); | ... SELECT s FROM ts WHERE s = true; | --- - | - null - | - 'Type mismatch: can not convert boolean(TRUE) to string' + | - metadata: + | - name: S + | type: scalar + | rows: + | - [true] | ... SELECT s FROM ts WHERE s < true; | --- - | - null - | - 'Type mismatch: can not convert boolean(TRUE) to string' + | - metadata: + | - name: S + | type: scalar + | rows: + | - [false] | ... SELECT s FROM ts WHERE s IN (true, 1, 'abcd'); | --- -- 2.25.1