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 7ABDA6EC56; Mon, 4 Oct 2021 16:30:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7ABDA6EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633354248; bh=V+BSP93JKpsXaaM/RtZ32Ph20LTe/U1y7t96R28BXRg=; 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=pUUXpyN0135+MgpCxz+srv310g88SoTU8VTsDus7iJvmdJdabD8U8KnSKydUvuYHI wZYNB4A0Ll7dUu7WaREywQSl7T9W4CoL/M/C1+4SXEoYamDzqJr1HUthX90oEvc++N qFbP2gHioyQWfKYsrMKCdHdgBwteQE+YZzaJiIn8= 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 39FFA6EC56 for ; Mon, 4 Oct 2021 16:30:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 39FFA6EC56 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mXO2t-0004Ed-Jf; Mon, 04 Oct 2021 16:30:20 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 4 Oct 2021 16:30:19 +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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9064ADF4728AA0EE94DA2502EB1E16E3FDC0E4956A228147E182A05F5380850406B22D8E38C8DCC7F48BE1126708FA1EA2B275A2532ED155A9E7E769BAEB8F091 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A0175C48BD57B26BC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7560ADFC8AADDC107EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2F4F8F4C970CBD412210E00A81BCF671ACC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B953A8A48A05D51F175ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C80CE368667DD8FDE0B94FADBBB241ADEB14AADB15E7E6C7E9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFE323A604FE95ED09DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3453741B480A6503C3FCDA7872782CE2ED01519FF41687C3F1B149A1910904087436ED7FCE0F88723C1D7E09C32AA3244CD21EE0440F5179CACE5889B2581BE5C11DD47778AE04E04D729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+1ww+tpaZerwnjbs1dg9WA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D20A65DF9903393E27A44EBC8C1DA7B7F83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/3] sql: fix truncation of DECIMAL in implicit cast 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" In case the DECIMAL value is implicitly cast to INTEGER during a search using an index, it was possible that DECIMAL would be truncated, which is not correct according to the implicit cast rules. This patch removes this truncation. Part of #6485 --- src/box/sql/mem.c | 5 +++-- test/sql-tap/gh-6485-bugs-in-decimal.test.lua | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 test/sql-tap/gh-6485-bugs-in-decimal.test.lua diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 5e23c901c..b0eba303e 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -1134,6 +1134,7 @@ static inline int dec_to_int_forced(struct Mem *mem) { assert(mem->type == MEM_TYPE_DEC); + bool is_dec_int = decimal_is_int(&mem->u.d); if (decimal_is_neg(&mem->u.d)) { int64_t i; mem->type = MEM_TYPE_INT; @@ -1148,7 +1149,7 @@ dec_to_int_forced(struct Mem *mem) * Decimal is floored when cast to int, which means that after * cast it becomes bigger if it was not integer. */ - return decimal_is_int(&mem->u.d) ? 0 : -1; + return is_dec_int ? 0 : -1; } uint64_t u; mem->type = MEM_TYPE_UINT; @@ -1162,7 +1163,7 @@ dec_to_int_forced(struct Mem *mem) * Decimal is floored when cast to uint, which means that after cast it * becomes less if it was not integer. */ - return decimal_is_int(&mem->u.d) ? 0 : 1; + return is_dec_int ? 0 : 1; } static inline int diff --git a/test/sql-tap/gh-6485-bugs-in-decimal.test.lua b/test/sql-tap/gh-6485-bugs-in-decimal.test.lua new file mode 100755 index 000000000..3f63f2b76 --- /dev/null +++ b/test/sql-tap/gh-6485-bugs-in-decimal.test.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env tarantool +local test = require("sqltester") +test:plan(1) + +-- Make sure DECIMAL is not truncated when used in an index. +test:do_execsql_test( + "gh-6485-1", + [[ + CREATE TABLE t(i INTEGER PRIMARY KEY); + INSERT INTO t VALUES(1), (2); + SELECT i FROM t WHERE i IN (CAST(1.1 AS DECIMAL), CAST(2.2 AS DECIMAL)); + DROP TABLE t; + ]], { + }) + +test:finish_test() -- 2.25.1