* [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL
@ 2021-08-26 11:08 Mergen Imeev via Tarantool-patches
2021-08-26 20:15 ` Vladislav Shpilevoy via Tarantool-patches
0 siblings, 1 reply; 4+ messages in thread
From: Mergen Imeev via Tarantool-patches @ 2021-08-26 11:08 UTC (permalink / raw)
To: v.shpilevoy; +Cc: 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL
2021-08-26 11:08 [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL Mergen Imeev via Tarantool-patches
@ 2021-08-26 20:15 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-27 7:41 ` Mergen Imeev via Tarantool-patches
0 siblings, 1 reply; 4+ messages in thread
From: Vladislav Shpilevoy via Tarantool-patches @ 2021-08-26 20:15 UTC (permalink / raw)
To: imeevma; +Cc: tarantool-patches
Hi! Thanks for the patch!
The new test passes even without the changes in mem.c.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL
2021-08-26 20:15 ` Vladislav Shpilevoy via Tarantool-patches
@ 2021-08-27 7:41 ` Mergen Imeev via Tarantool-patches
2021-08-27 21:24 ` Vladislav Shpilevoy via Tarantool-patches
0 siblings, 1 reply; 4+ messages in thread
From: Mergen Imeev via Tarantool-patches @ 2021-08-27 7:41 UTC (permalink / raw)
To: Vladislav Shpilevoy; +Cc: 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 <imeevma@gmail.com>
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()
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL
2021-08-27 7:41 ` Mergen Imeev via Tarantool-patches
@ 2021-08-27 21:24 ` Vladislav Shpilevoy via Tarantool-patches
0 siblings, 0 replies; 4+ messages in thread
From: Vladislav Shpilevoy via Tarantool-patches @ 2021-08-27 21:24 UTC (permalink / raw)
To: Mergen Imeev; +Cc: tarantool-patches
Hi! Thanks for the fixes!
LGTM.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-27 21:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 11:08 [Tarantool-patches] [PATCH v1 1/1] sql: fix comparison between big DOUBLE and DECIMAL Mergen Imeev via Tarantool-patches
2021-08-26 20:15 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-27 7:41 ` Mergen Imeev via Tarantool-patches
2021-08-27 21:24 ` Vladislav Shpilevoy via Tarantool-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox