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 0B4496ECE3; Tue, 19 Oct 2021 09:20:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0B4496ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1634624417; bh=tcjOwmGAS7yUpbl9EGGNEg+lIT/UJcSsHk7D6O4ACPk=; 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=PF3FC4NoQKSsP+51TNCN8ZYD78D1sKTotuuW6UQ6m3C9aedFjWe8C0NkMCCbprTd7 /Z5gFRcbgAM3iuidLOrhVwRzYJltxEnW4FnHvcmIg87FO7JOl9KnWPs5/bG/UxKlfP wqsX+AeL3c2qaCTaQbw6x7m/MhRYBTqXSiZXVXeQ= 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 F37276ECE4 for ; Tue, 19 Oct 2021 09:19:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F37276ECE4 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mciTS-0003hM-VX; Tue, 19 Oct 2021 09:19:47 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 19 Oct 2021 09:19:46 +0300 Message-Id: <2c1af4cf637304b33edbb6560f88cb8d8b2c1be6.1634624290.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: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9C7814344C8C501C83238E3156CE19B78C95C7AD4390B7974182A05F538085040FA3101679936D104F9CE5FC5267FF2A28E57BF922FD20D136A7430788DBE656A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE770FEBAE29342FA8FEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373F8F072802CB4B3E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8723611F3BC1D7CEB98EEEF0CEFD92E5A117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CDA625C6CE8BBA1B9B2BFAEFB1DFC44A23A39A25E79C4775D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA5DF9383870C0FED699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340E23B77EA1807817AB03C7994241874308EBED7557AE9BB868ED447A2E9B9C6811BAB4B4E472FBB61D7E09C32AA3244CA7D785AA8F3DB48585E1B51BA1716BFB30452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSRIpe8siFhUbVZup/Aby2g== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DF2F8CD00058689CEF74502C50B614BB783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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/engine.cfg | 1 + test/sql-tap/gh-6485-bugs-in-decimal.test.lua | 16 ++++++++++++++++ 3 files changed, 20 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/engine.cfg b/test/sql-tap/engine.cfg index a6f03307f..9d318a456 100644 --- a/test/sql-tap/engine.cfg +++ b/test/sql-tap/engine.cfg @@ -39,6 +39,7 @@ "gh-6376-wrong-double-to-dec-cmp.test.lua": {}, "gh-4077-iproto-execute-no-bind.test.lua": {}, "gh-6375-assert-on-unsupported-ext.test.lua": {}, + "gh-6485-bugs-in-decimal.test.lua": {}, "*": { "memtx": {"engine": "memtx"}, "vinyl": {"engine": "vinyl"} 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