Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 2/3] sql: fix uuid behaviour in least() and greatest()
Date: Mon,  5 Jul 2021 18:06:15 +0300	[thread overview]
Message-ID: <ad5229b069c8fefe8b9e7510e0ac42e25b5939d2.1625497228.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1625497228.git.imeevma@gmail.com>

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


  parent reply	other threads:[~2021-07-05 15:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-05 15:04 [Tarantool-patches] [PATCH v1 0/3] Follow ups for uuid introduction Mergen Imeev via Tarantool-patches
2021-07-05 15:06 ` [Tarantool-patches] [PATCH v1 1/3] sql: introduce uuid to quote() Mergen Imeev via Tarantool-patches
2021-07-07 21:41   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-05 15:06 ` Mergen Imeev via Tarantool-patches [this message]
2021-07-07 21:42   ` [Tarantool-patches] [PATCH v1 2/3] sql: fix uuid behaviour in least() and greatest() Vladislav Shpilevoy via Tarantool-patches
2021-07-10 14:36     ` Mergen Imeev via Tarantool-patches
2021-07-05 15:06 ` [Tarantool-patches] [PATCH v1 3/3] sql: allow to bind uuid values Mergen Imeev via Tarantool-patches
2021-07-07 21:44   ` Vladislav Shpilevoy via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad5229b069c8fefe8b9e7510e0ac42e25b5939d2.1625497228.git.imeevma@gmail.com \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 2/3] sql: fix uuid behaviour in least() and greatest()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox