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 8253E6EC40; Mon, 5 Jul 2021 18:06:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8253E6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1625497605; bh=EG3iqGGQMFRFK04QawNwx83SXeBzu4kNFH4xIj0fXsE=; 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=hYvGPfc9M1/W5nl32o0+NTHTqmiCx3WdFq5v4IVOmkpYOZ4DUS6aa9Ha54qL1Xx5U z4vLjqohy9gTuEa5xHPe99jaWqCKy4p5EzeLzLR91BhH/nyxk/2GtX5A7HyUt/O4g1 lNzFCXXl/Hl7hNyvXqtNNfO93kwVlMonnw5YNFHQ= 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 DCE436EC40 for ; Mon, 5 Jul 2021 18:06:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DCE436EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m0QAp-0005Bh-AQ; Mon, 05 Jul 2021 18:06:15 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 5 Jul 2021 18:06:15 +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: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD954DFF1DC42D673FB703477AD6D36A6E3C7EF2853D6A1C7C1182A05F538085040B57E5AACFEE22E16F498F745182892BD2CC43ACCF5DE66E7A27094AF858C3501 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C6068CE86C2B75F5EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F5B2F26146BDF5648638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D877A028597108936543E43066D152C61F117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C62E2A2CC9B321AEEDAC0D71DFFA962DFF10299D4966B2E379C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFB1D0AC14175A0720699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34CC972AA0E2E780C44BE870E1D46C8EED1619DEC67C9F5B1F0731E1DB188EEEA823AAB47B175F9EC41D7E09C32AA3244C2D13B93503E14E860C0CEB8FF221A3553FD9C8CA1B0515E0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXj8QT+zeI9PXZ/3/pjhCskS X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D43A84EB1F1132456A0ACD31BFA76B53183D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 2/3] sql: fix uuid behaviour in least() and greatest() 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" Prior to this patch, the built-in SQL functions greatest() and least() could return incorrect results if their arguments contained at least one uuid and at least one value of a different type. These values are now sorted according to the rules of SCALAR comparison, where UUID values are larger than any other scalar values. Part of #6164 --- src/box/sql/mem.c | 4 ++-- test/sql-tap/gh-6164-uuid-follow-ups.test.lua | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 6f3bf52e5..330ddfd8e 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -2480,8 +2480,8 @@ sqlMemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll * pColl) if (mem_cmp_uuid(pMem1, pMem2, &res) == 0) return res; if (type1 != MEM_TYPE_UUID) - return +1; - return -1; + return -1; + return +1; } /* At least one of the two values is a number diff --git a/test/sql-tap/gh-6164-uuid-follow-ups.test.lua b/test/sql-tap/gh-6164-uuid-follow-ups.test.lua index d8fa700ea..8872f9f23 100755 --- a/test/sql-tap/gh-6164-uuid-follow-ups.test.lua +++ b/test/sql-tap/gh-6164-uuid-follow-ups.test.lua @@ -1,6 +1,8 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(1) +test:plan(3) + +local uuid = require('uuid').fromstr('11111111-1111-1111-1111-111111111111') box.execute([[select quote(cast('11111111-1111-1111-1111-111111111111' as uuid));]]) @@ -13,4 +15,21 @@ test:do_execsql_test( '11111111-1111-1111-1111-111111111111' }) +-- Make sure that functions greatest() and least() can properly work with uuid. +test:do_execsql_test( + "gh-6164-2", + [[ + SELECT GREATEST(true, 1, x'33', cast('11111111-1111-1111-1111-111111111111' as uuid), 1e10); + ]], { + uuid + }) + +test:do_execsql_test( + "gh-6164-3", + [[ + SELECT LEAST(true, 1, x'33', cast('11111111-1111-1111-1111-111111111111' as uuid), 1e10); + ]], { + true + }) + test:finish_test() -- 2.25.1