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 796B26EC56; Mon, 4 Oct 2021 16:31:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 796B26EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633354309; bh=QArfVXThNpormSuN1I4QRpJIV7RmS7QMW0duDqbNOwg=; 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=DYuzDqh56Iqrp5nJlp82Zh0yxClleIAll00TVXzeLZoxwXtsyZI8VMnTpDI4YMgeZ PZLreTQtD2cSOM0Zgb8ej+LKTSk+FgjJ4CRowGKAXRA4kEnIsV3nc2HHDZWytJaYMV nCvGvcnlVMW7/jiH188Vh96E2p9N/eRykZKzUofA= 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 F3C606DB01 for ; Mon, 4 Oct 2021 16:30:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F3C606DB01 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mXO2x-0004Ge-9a; Mon, 04 Oct 2021 16:30:23 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 4 Oct 2021 16:30:23 +0300 Message-Id: <51f777fff4af90470d36f9e5af85970d0234efc4.1633352298.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-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96A58C36AA2E99649E38D86FE9CCA94CF599BDB229C9CF279182A05F538085040C25289EA7CC0B7C73433E3D1F64ADBC99BBD972E1E744DC319F0940A565172BD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76574C3D62D66A535EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637657EF45424029EDA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81FCE3C800C716466D97506E3C37E9756117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C80CE368667DD8FDE9A1CC2B12FE7FC9FF7179912C47278BF9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE323A604FE95ED09DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53592357E8057733F897B6310EE6526CA3000EF03CA7CD0E1C2E83B046B7A095E1B0F7B094E4B641D7E09C32AA3244CFA0499FF696D6975DE004AC63E6CC91AE3D93501275E802F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+1ww+tpaZeq6buD8wCjFFw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DE18EEA69974DED5393C8331CA1F85D7B83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 3/3] sql: do not truncate DECIMAL in LIMIT and OFFSET 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" This patch removes the DECIMAL truncation in LIMIT and OFFSET, because according to the implicit casting rules, DECIMAL with digits after the decimal point cannot be implicitly cast to INTEGER. Closes #6485 --- .../unreleased/gh-6485-bug-of-decimal.md | 8 +++++++ src/box/sql/mem.c | 2 +- test/sql-tap/gh-6485-bugs-in-decimal.test.lua | 21 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/gh-6485-bug-of-decimal.md diff --git a/changelogs/unreleased/gh-6485-bug-of-decimal.md b/changelogs/unreleased/gh-6485-bug-of-decimal.md new file mode 100644 index 000000000..bcf023b31 --- /dev/null +++ b/changelogs/unreleased/gh-6485-bug-of-decimal.md @@ -0,0 +1,8 @@ +## bugfix/sql + +* Fixed truncation of DECIMAL during implicit cast to INTEGER in LIMIT and + OFFSET. +* Fixed truncation of DECIMAL during implicit cast to INTEGER when value is used + in an index. +* Fixed assert on cast of DECIMAL value that greater than -1.0 and less than 0.0 + to INTEGER (gh-6485). diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index bc6f9b35a..7e94dc8bb 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1338,7 +1338,7 @@ mem_to_int_precise(struct Mem *mem) if (mem->type == MEM_TYPE_DOUBLE) return double_to_int_precise(mem); if (mem->type == MEM_TYPE_DEC) - return dec_to_int(mem); + return dec_to_int_precise(mem); return -1; } diff --git a/test/sql-tap/gh-6485-bugs-in-decimal.test.lua b/test/sql-tap/gh-6485-bugs-in-decimal.test.lua index 0b9b2ea0a..fc2ac963d 100755 --- a/test/sql-tap/gh-6485-bugs-in-decimal.test.lua +++ b/test/sql-tap/gh-6485-bugs-in-decimal.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(3) +test:plan(5) -- Make sure DECIMAL is not truncated when used in an index. test:do_execsql_test( @@ -35,4 +35,23 @@ test:do_execsql_test( ]], { }) +-- Make sure DECIMAL is not truncated when used in LIMIT and OFFSET. +test:do_catchsql_test( + "gh-6485-4", + [[ + SELECT 1 LIMIT CAST(1.5 AS DECIMAL); + ]], { + 1, [[Failed to execute SQL statement: ]].. + [[Only positive integers are allowed in the LIMIT clause]] + }) + +test:do_catchsql_test( + "gh-6485-5", + [[ + SELECT 1 LIMIT 1 OFFSET CAST(1.5 AS DECIMAL); + ]], { + 1, [[Failed to execute SQL statement: ]].. + [[Only positive integers are allowed in the OFFSET clause]] + }) + test:finish_test() -- 2.25.1