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 8EB9A6ECE3; Tue, 19 Oct 2021 09:21:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8EB9A6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1634624477; 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=TCH5fBtIp7xhT5B1Yf8GN8Zqw460/aaYUK6RBiJ6rx86QSjDW5yrgpelMLbOMgro9 RzKUQRgnkRGbHkI7tm+DJxaxY4OnmQt9fptaARPW8t8tgO5+Js7zQoLJr3GSRmA2Pq cJHAYblF9LPzDZ8c+GHKIV25cWx80wzLsnXOO/6M= 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 D7B7C6EC40 for ; Tue, 19 Oct 2021 09:19:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D7B7C6EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mciTW-0003iY-JK; Tue, 19 Oct 2021 09:19:51 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 19 Oct 2021 09:19:50 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9C7814344C8C501C81DF2D982FCC3642A10B25E0CD3D2314B182A05F5380850404E06953F12C6E9829F8A28D58A5FC4ECD4572DCDC75B82F4F53210566A296666 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76574C3D62D66A535EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637657EF45424029EDA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89267BF092E2CE4B00BF4C97ED88253B9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CDA625C6CE8BBA1B994862ECC28F6AFEFF51630231678047E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA5DF9383870C0FED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53592357E8057733F897B6310EE6526CA3000EF03CA7CD0E1C2E83B046B7A095E1B0F7B094E4B641D7E09C32AA3244CD19E203B80365CAF5A194F8F8DB1FF3155E75C8D0ED9F6EE729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSRIpe8siFhU8WA37PtF4pw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DBEBCD05017AFBA7A8A284D90200DA75B83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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