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 04DCC6EC5C; Mon, 30 Aug 2021 09:13:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 04DCC6EC5C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630304001; bh=tZE1FnrgLzZiK5PWp1tTdaH3KXfVMQ3BBqUknaWdiWg=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cpj4/888EpGjyJbp+S3T7Aulylm4nHLT3u/+RmH+5y6LpWFnXStOreCeLNFtf34x3 /ugo+90DzYnauc+z4wiCzRJeEclvXJgk9SfYiNLIXP4PhCAcqoYXuQ+wuOuLUipUd0 CWVPBNF63T/tM8g+2pGCLEJ7C6ZaUSaG7CYqfNF4= 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 E3E6A6EC5C for ; Mon, 30 Aug 2021 09:13:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E3E6A6EC5C Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mKaXn-00069e-5a; Mon, 30 Aug 2021 09:13:19 +0300 To: tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 30 Aug 2021 09:13:18 +0300 Message-Id: <6229320676324201d74e78ac1f2832b79fd159cb.1630303937.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: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F56291F8739A291D6182A05F538085040985D9EB63D4647A423AA97C1CB03113883D5A87DD29685ABAA74D2D8F7EF0784 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7518FA0CDCCF25698EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637429436EB3A52E9348638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D878BCAA1C395DF83FF9C9A35F6F1FAA5B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6753C3A5E0A5AB5B7089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C4DDEBE0CC47FE269C8BB8D70CC6A195F6894E6232ED33F699C2B6934AE262D3EE7EAB7254005DCEDD39702B95798B1671E0A4E2319210D9B64D260DF9561598F01A9E91200F654B06CE7B4E551862B828E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E3E1DC0F9BD5530920D13820496CDD9EA139E640CC45C8883031138038DFE6D4ABC8917FE87F96E01D7E09C32AA3244C56A40AA8DD865093C14C52D16240C179E3D93501275E802F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXgyli5L067hg3pXdGXut/oT X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D6D186E1418C62F686003E337A5A846B383D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between DECIMAL and big DOUBLE 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 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 --- 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 | 3 ++ src/box/sql/mem.c | 4 +- test/sql-tap/engine.cfg | 1 + .../gh-6376-wrong-double-to-dec-cmp.test.lua | 38 +++++++++++++++++++ 4 files changed, 44 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..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 4c40f15dc..a3ab31af5 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 587adbed9..e4ec41edb 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": {}, "gh-6375-assert-on-unsupported-ext.test.lua": {}, "*": { 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() -- 2.25.1