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 F3F796EC41; Fri, 13 Aug 2021 06:16:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F3F796EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628824587; bh=JxhWYIj+69/29E7NkUG+iCGEFizDvfLunD1450SCGZ4=; 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=PlztflvOilUzBjSfaa3ePv3o7CintXXgqXpjrYRWQZ0ZKpC8CAy+2JqsEL272so+O kL+9jmOXJbxhhq1Ih4GhqY1Nn2EK3ScdzWsSsg+Q446cXd/pQFe7xKQbAwMmuBPsM0 IIc5U/bcOSskDS2VFN2lk9d6m6ayowJ3OqRbzoVs= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (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 9219B6EC5D for ; Fri, 13 Aug 2021 06:13:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9219B6EC5D Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mENd5-00087K-NH; Fri, 13 Aug 2021 06:13:08 +0300 To: vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 13 Aug 2021 06:13:07 +0300 Message-Id: <6179b16e422a1349ebe5b0ed340c81d8f5a4e6a2.1628824286.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-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9736CF3E71F18CE0C3E1D5927724F4AAA182A05F538085040DF1664ACF07699A3631E7B1178814552C4F66F5BDB4F2F8FE0C602806CFE6CE1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72E2D36A15E1833D8EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EDC9855826FBDF5A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84868278F5A125882BFB497586974B2AB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B5059A91936EF7B6732D6343FE1DFB318527 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C69415AB31670C86C5D08A65AAC5263B2F447504E1C4185339C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE37876E7723AB534DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E20F2278F74481A1B326EDE655257D8A1AD7A0F9AD67AC7D8C7A9A4E4F2A54FDB86332D2AC4E01B71D7E09C32AA3244C47A07AC9B552EB685EB2D145991D4ACD3A92A9747B6CC886729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj0dLV0c3jbkxIHGa0feVAAA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D4D213DE0B77344969999EAC28C78A87B83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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 @TarantoolBot document Title: SCALAR and NUMBER values in SQL SCALAR values can now be compared with values of any other scalar type, but cannot be implicitly cast to any other scalar type. This means that SCALAR values cannot participate in arithmetic, bitwise operations, concatenation, or functions that, by definition, do not accept SCALAR values. NUMBER values now also cannot be implicitly cast to any other numeric type, which means that NUMBER values cannot participate in arithmetic and bitwise operations, or in functions that, by definition, do not accept NUMBER values. --- ...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