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 6F4A76EC55; Fri, 27 Aug 2021 10:41:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6F4A76EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630050080; bh=Y+2H98Ay51uQtH7qaECWZhEgyVr+yhJPUqoCO0oXlCk=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=szaLgC9NBAJOSy67Q9lVly8DbsbBHr+tKS6TWgqODZMNV+CIAFO/wy4cTv4wUQQl5 vvOw+nc8Au0JPV8AtYdOVWuq0EXdk39eN96nn2EJA63eB2QzQEKWRmXgaohm/mWSNd eHHECowjZXE1OWURv9R2swy4R9RCpRhJpKZGtLdk= 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 869046EC55 for ; Fri, 27 Aug 2021 10:41:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 869046EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mJWUH-0000Zu-8s; Fri, 27 Aug 2021 10:41:17 +0300 Date: Fri, 27 Aug 2021 10:41:16 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210827074116.GA32766@tarantool.org> References: <197e653c9b4d2a96dd4e701cd091d9aee8f0c1e9.1629976050.git.imeevma@gmail.com> <003f11f0-5ecc-2e69-dc89-47a34b5f24ac@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <003f11f0-5ecc-2e69-dc89-47a34b5f24ac@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD91BCCB18F2C129F87F36E61E9E4584E9D182A05F538085040FBED090DBA94F94B90E138D2E768358157C83A153E1546F4382C6F2EBEA1713A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BA0D57D3459E5640EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373103A56A89D9083FEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2937C5A905F624FA4BD5E90EB504E9D65CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8A9FF340AA05FB58CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B9F5955FECEF5819E75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A58E6489E2445BE39179047099E9C1A9EFB9F777F90800F349D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA756665624D6DDF07B5410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E9B0C12ABED551371BB38E1B1E63A17B245C831F1ABD34F63AD5234A13D5403082D961C6C37558EE1D7E09C32AA3244C206BF5DCA1904FC2D9E92117EB062CA2B018FE5BB746DCD1729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+bzRAXO2P1RYiR0cy60u3Q== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D51EEF7692BAA36B9AE9C924CE73B094683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [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: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thank you for the review! I fixed test and made some changes in descriprions. Diff and new patch below. On Thu, Aug 26, 2021 at 10:15:31PM +0200, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > The new test passes even without the changes in mem.c. Diff: diff --git a/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md b/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md index 102b6b9ab..70de655f1 100644 --- a/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md +++ b/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md @@ -1,5 +1,3 @@ ## bugfix/sql -* Fixed wrong comparison between inf and -inf DOUBLE values and DECIMAL - values (gh-6376). - +* Fixed wrong comparison between DECIMAL and large DOUBLE values (gh-6376). 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 index 8066e365b..edfc851a2 100755 --- 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 @@ -2,14 +2,11 @@ local test = require("sqltester") test:plan(4) --- --- Make sure that the comparison between too large or too small DOUBLE and --- DECIMAL is correct. --- +-- Make sure that the comparison between DECIMAL and large DOUBLE is correct. test:do_execsql_test( "gh-6376-1", [[ - SELECT -1e40 > CAST(1 AS DECIMAL); + SELECT CAST(1 AS DECIMAL) < -1e40; ]], { false }) @@ -17,7 +14,7 @@ test:do_execsql_test( test:do_execsql_test( "gh-6376-2", [[ - SELECT -1e400 < CAST(-1 AS DECIMAL); + SELECT CAST(-1 AS DECIMAL) > -1e400; ]], { true }) @@ -25,7 +22,7 @@ test:do_execsql_test( test:do_execsql_test( "gh-6376-3", [[ - SELECT 1e40 >= CAST(1 AS DECIMAL); + SELECT CAST(1 AS DECIMAL) <= 1e40; ]], { true }) @@ -33,7 +30,7 @@ test:do_execsql_test( test:do_execsql_test( "gh-6376-4", [[ - SELECT 1e400 <= CAST(1 AS DECIMAL); + SELECT CAST(1 AS DECIMAL) >= 1e400; ]], { false }) New patch: commit 710054a586ca94cf3a8db67fdfb3530ffdf1153d Author: Mergen Imeev Date: Mon Aug 23 09:34:23 2021 +0300 sql: fix comparison between DECIMAL and big DOUBLE This patch fixes comparison between DECIMAL value and DOUBLE values greater or equal to 1e38 or less or equal to -1e38. 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 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..70de655f1 --- /dev/null +++ b/changelogs/unreleased/gh-6376-fix-incorrect-dec-inf-cmp.md @@ -0,0 +1,3 @@ +## bugfix/sql + +* Fixed wrong comparison between DECIMAL and large DOUBLE 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..edfc851a2 --- /dev/null +++ b/test/sql-tap/gh-6376-wrong-double-to-dec-cmp.test.lua @@ -0,0 +1,38 @@ +#!/usr/bin/env tarantool +local test = require("sqltester") +test:plan(4) + +-- Make sure that the comparison between DECIMAL and large DOUBLE is correct. +test:do_execsql_test( + "gh-6376-1", + [[ + SELECT CAST(1 AS DECIMAL) < -1e40; + ]], { + false + }) + +test:do_execsql_test( + "gh-6376-2", + [[ + SELECT CAST(-1 AS DECIMAL) > -1e400; + ]], { + true + }) + +test:do_execsql_test( + "gh-6376-3", + [[ + SELECT CAST(1 AS DECIMAL) <= 1e40; + ]], { + true + }) + +test:do_execsql_test( + "gh-6376-4", + [[ + SELECT CAST(1 AS DECIMAL) >= 1e400; + ]], { + false + }) + +test:finish_test()