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 DFD576EC55; Thu, 26 Aug 2021 14:08:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DFD576EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629976089; bh=dM4j//lSoj4p5CjxBfhh8vRen840jYBNJo73xIuWHkk=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=iFr+38dYU0Ls6huOPO7CPT7t18PeKuCICAxxRUAG4MtDjzc0iolLtYj6j3K/raNs1 uKbe2qE50EV8cmcV2qtZPRBG0KgVPLkLDHWfPHajj+yOVLEFEQ/UZaXy8wLoKr8eSO hmguL9P4P2AvGDkj0Vaud2Jnro70MeLxYOijFDOw= 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 7D83C6EC55 for ; Thu, 26 Aug 2021 14:08:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7D83C6EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mJDEs-0006DN-Rn; Thu, 26 Aug 2021 14:08:07 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 26 Aug 2021 14:08:06 +0300 Message-Id: <197e653c9b4d2a96dd4e701cd091d9aee8f0c1e9.1629976050.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F56291F8739A291D6182A05F538085040FC966F7A2FC6355FF37BC55A9EFC14BD5EB6E7B93C442BA6D9AD544F65711B09 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79B4AFF82F0254274EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637817108B649554FEC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B8BAABEAA4A4F4CFE561F1A1DDABD918117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD38A7E49931D2E15C02793773E2E6F3DE0FB7FA24481784B9C2B6934AE262D3EE7EAB7254005DCEDD39702B95798B1671E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0BDBC62CB1440F3B18E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34197948450CB5442AFA25BC08CEA59E3650C8EFEE71EFD2BB063018CD9B5A0A8AED1EC609058613371D7E09C32AA3244C29B8B5CA5C5406B92923E0A72B7A18544DBEAD0ED6C55A80729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXSF/Tsl6M2NDUplp750DOw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D75B95EB437B9237A14A6D0CDE9495B6483D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL 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 fixes comparison between DOUBLE values greater or equal to 1e38 or less or equal to -1e38 and DECIMAL value. Now any DOUBLE value greater or equal to 1e38 is more than any DECIMAL value and DOUBLE value less or equal to -1e38 is less than any DECIMAL value. Closes #6376 --- https://github.com/tarantool/tarantool/issues/6376 https://github.com/tarantool/tarantool/tree/imeevma/gh-6376-fix-cmp-between-big-double-and-dec .../gh-6376-fix-incorrect-dec-inf-cmp.md | 5 +++ src/box/sql/mem.c | 4 +- test/sql-tap/engine.cfg | 1 + .../gh-6376-wrong-double-to-dec-cmp.test.lua | 41 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md create mode 100755 test/sql-tap/gh-6376-wrong-double-to-dec-cmp.test.lua diff --git a/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md b/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md new file mode 100644 index 000000000..102b6b9ab --- /dev/null +++ b/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md @@ -0,0 +1,5 @@ +## bugfix/sql + +* Fixed wrong comparison between inf and -inf DOUBLE values and DECIMAL + values (gh-6376). + diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 0aca76112..fbfe81038 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -2451,9 +2451,9 @@ mem_cmp_num(const struct Mem *a, const struct Mem *b) } case MEM_TYPE_DOUBLE: { if (b->u.r >= 1e38) - return 1; - if (b->u.r <= -1e38) return -1; + if (b->u.r <= -1e38) + return 1; decimal_t dec; decimal_t *d = decimal_from_double(&dec, b->u.r); assert(d != NULL && d == &dec); diff --git a/test/sql-tap/engine.cfg b/test/sql-tap/engine.cfg index 35754f769..26d85b674 100644 --- a/test/sql-tap/engine.cfg +++ b/test/sql-tap/engine.cfg @@ -35,6 +35,7 @@ "built-in-functions.test.lua": { "memtx": {"engine": "memtx"} }, + "gh-6376-wrong-double-to-dec-cmp.test.lua": {}, "gh-4077-iproto-execute-no-bind.test.lua": {}, "*": { "memtx": {"engine": "memtx"}, diff --git a/test/sql-tap/gh-6376-wrong-double-to-dec-cmp.test.lua b/test/sql-tap/gh-6376-wrong-double-to-dec-cmp.test.lua new file mode 100755 index 000000000..8066e365b --- /dev/null +++ b/test/sql-tap/gh-6376-wrong-double-to-dec-cmp.test.lua @@ -0,0 +1,41 @@ +#!/usr/bin/env tarantool +local test = require("sqltester") +test:plan(4) + +-- +-- Make sure that the comparison between too large or too small DOUBLE and +-- DECIMAL is correct. +-- +test:do_execsql_test( + "gh-6376-1", + [[ + SELECT -1e40 > CAST(1 AS DECIMAL); + ]], { + false + }) + +test:do_execsql_test( + "gh-6376-2", + [[ + SELECT -1e400 < CAST(-1 AS DECIMAL); + ]], { + true + }) + +test:do_execsql_test( + "gh-6376-3", + [[ + SELECT 1e40 >= CAST(1 AS DECIMAL); + ]], { + true + }) + +test:do_execsql_test( + "gh-6376-4", + [[ + SELECT 1e400 <= CAST(1 AS DECIMAL); + ]], { + false + }) + +test:finish_test() -- 2.25.1