Commit d9752d85 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-31926 UUID v7 are compared incorrectly

According to the standart draft UUIDv6 and UUIDv7 values
must be compared as opaque raw bytes.

Let's only compare with byte-swapping if both values need
byte swapping.
parent 5436b5dd
......@@ -756,6 +756,36 @@ NULL 48
NULL 52
NULL 56
NULL 60
select * from t1, t1 t where t1.b div 4 in (6,7) and t.b div 4 in (6,7) and t1.a > t.a;
a b a b
02601234-5566-6777-c888-99aabbccddee 26 02401234-5566-6777-0888-99aabbccddee 24
02801234-5566-7777-0888-99aabbccddee 28 02401234-5566-6777-0888-99aabbccddee 24
02801234-5566-7777-0888-99aabbccddee 28 02601234-5566-6777-c888-99aabbccddee 26
03001234-5566-7777-c888-99aabbccddee 30 02401234-5566-6777-0888-99aabbccddee 24
03001234-5566-7777-c888-99aabbccddee 30 02601234-5566-6777-c888-99aabbccddee 26
03001234-5566-7777-c888-99aabbccddee 30 02801234-5566-7777-0888-99aabbccddee 28
12501234-5566-6777-8888-99aabbccddee 25 02401234-5566-6777-0888-99aabbccddee 24
12501234-5566-6777-8888-99aabbccddee 25 02601234-5566-6777-c888-99aabbccddee 26
12501234-5566-6777-8888-99aabbccddee 25 02801234-5566-7777-0888-99aabbccddee 28
12501234-5566-6777-8888-99aabbccddee 25 03001234-5566-7777-c888-99aabbccddee 30
12701234-5566-6777-e888-99aabbccddee 27 02401234-5566-6777-0888-99aabbccddee 24
12701234-5566-6777-e888-99aabbccddee 27 02601234-5566-6777-c888-99aabbccddee 26
12701234-5566-6777-e888-99aabbccddee 27 02801234-5566-7777-0888-99aabbccddee 28
12701234-5566-6777-e888-99aabbccddee 27 03001234-5566-7777-c888-99aabbccddee 30
12701234-5566-6777-e888-99aabbccddee 27 12501234-5566-6777-8888-99aabbccddee 25
12901234-5566-7777-8888-99aabbccddee 29 02401234-5566-6777-0888-99aabbccddee 24
12901234-5566-7777-8888-99aabbccddee 29 02601234-5566-6777-c888-99aabbccddee 26
12901234-5566-7777-8888-99aabbccddee 29 02801234-5566-7777-0888-99aabbccddee 28
12901234-5566-7777-8888-99aabbccddee 29 03001234-5566-7777-c888-99aabbccddee 30
12901234-5566-7777-8888-99aabbccddee 29 12501234-5566-6777-8888-99aabbccddee 25
12901234-5566-7777-8888-99aabbccddee 29 12701234-5566-6777-e888-99aabbccddee 27
13101234-5566-7777-e888-99aabbccddee 31 02401234-5566-6777-0888-99aabbccddee 24
13101234-5566-7777-e888-99aabbccddee 31 02601234-5566-6777-c888-99aabbccddee 26
13101234-5566-7777-e888-99aabbccddee 31 02801234-5566-7777-0888-99aabbccddee 28
13101234-5566-7777-e888-99aabbccddee 31 03001234-5566-7777-c888-99aabbccddee 30
13101234-5566-7777-e888-99aabbccddee 31 12501234-5566-6777-8888-99aabbccddee 25
13101234-5566-7777-e888-99aabbccddee 31 12701234-5566-6777-e888-99aabbccddee 27
13101234-5566-7777-e888-99aabbccddee 31 12901234-5566-7777-8888-99aabbccddee 29
alter ignore table t2 force;
Warnings:
Warning 1292 Incorrect uuid value: '03201234-5566-8777-0888-99aabbccddee' for column `test`.`t2`.`a` at row 33
......@@ -766,4 +796,38 @@ Warning 1292 Incorrect uuid value: '04801234-5566-c777-0888-99aabbccddee' for co
Warning 1292 Incorrect uuid value: '05201234-5566-d777-0888-99aabbccddee' for column `test`.`t2`.`a` at row 53
Warning 1292 Incorrect uuid value: '05601234-5566-e777-0888-99aabbccddee' for column `test`.`t2`.`a` at row 57
Warning 1292 Incorrect uuid value: '06001234-5566-f777-0888-99aabbccddee' for column `test`.`t2`.`a` at row 61
drop table t1, t2;
drop table t2;
#
# MDEV-31926 UUID v7 are compared incorrectly
#
select * from t1, t1 t where t1.b div 4 in (6,7) and t.b div 4 in (6,7) and concat(t1.a) > concat(t.a);
a b a b
02601234-5566-6777-c888-99aabbccddee 26 02401234-5566-6777-0888-99aabbccddee 24
02801234-5566-7777-0888-99aabbccddee 28 02401234-5566-6777-0888-99aabbccddee 24
02801234-5566-7777-0888-99aabbccddee 28 02601234-5566-6777-c888-99aabbccddee 26
03001234-5566-7777-c888-99aabbccddee 30 02401234-5566-6777-0888-99aabbccddee 24
03001234-5566-7777-c888-99aabbccddee 30 02601234-5566-6777-c888-99aabbccddee 26
03001234-5566-7777-c888-99aabbccddee 30 02801234-5566-7777-0888-99aabbccddee 28
12501234-5566-6777-8888-99aabbccddee 25 02401234-5566-6777-0888-99aabbccddee 24
12501234-5566-6777-8888-99aabbccddee 25 02601234-5566-6777-c888-99aabbccddee 26
12501234-5566-6777-8888-99aabbccddee 25 02801234-5566-7777-0888-99aabbccddee 28
12501234-5566-6777-8888-99aabbccddee 25 03001234-5566-7777-c888-99aabbccddee 30
12701234-5566-6777-e888-99aabbccddee 27 02401234-5566-6777-0888-99aabbccddee 24
12701234-5566-6777-e888-99aabbccddee 27 02601234-5566-6777-c888-99aabbccddee 26
12701234-5566-6777-e888-99aabbccddee 27 02801234-5566-7777-0888-99aabbccddee 28
12701234-5566-6777-e888-99aabbccddee 27 03001234-5566-7777-c888-99aabbccddee 30
12701234-5566-6777-e888-99aabbccddee 27 12501234-5566-6777-8888-99aabbccddee 25
12901234-5566-7777-8888-99aabbccddee 29 02401234-5566-6777-0888-99aabbccddee 24
12901234-5566-7777-8888-99aabbccddee 29 02601234-5566-6777-c888-99aabbccddee 26
12901234-5566-7777-8888-99aabbccddee 29 02801234-5566-7777-0888-99aabbccddee 28
12901234-5566-7777-8888-99aabbccddee 29 03001234-5566-7777-c888-99aabbccddee 30
12901234-5566-7777-8888-99aabbccddee 29 12501234-5566-6777-8888-99aabbccddee 25
12901234-5566-7777-8888-99aabbccddee 29 12701234-5566-6777-e888-99aabbccddee 27
13101234-5566-7777-e888-99aabbccddee 31 02401234-5566-6777-0888-99aabbccddee 24
13101234-5566-7777-e888-99aabbccddee 31 02601234-5566-6777-c888-99aabbccddee 26
13101234-5566-7777-e888-99aabbccddee 31 02801234-5566-7777-0888-99aabbccddee 28
13101234-5566-7777-e888-99aabbccddee 31 03001234-5566-7777-c888-99aabbccddee 30
13101234-5566-7777-e888-99aabbccddee 31 12501234-5566-6777-8888-99aabbccddee 25
13101234-5566-7777-e888-99aabbccddee 31 12701234-5566-6777-e888-99aabbccddee 27
13101234-5566-7777-e888-99aabbccddee 31 12901234-5566-7777-8888-99aabbccddee 29
drop table t1;
......@@ -36,6 +36,27 @@ select * from t2 left join t1 on (t1.a<=>t2.a);
--sorted_result
select * from t1 union select * from t2;
--sorted_result
select * from t1, t1 t where t1.b div 4 in (6,7) and t.b div 4 in (6,7) and t1.a > t.a;
alter ignore table t2 force;
drop table t1, t2;
drop table t2;
--echo #
--echo # MDEV-31926 UUID v7 are compared incorrectly
--echo #
# for v6 and v7 string comparison should produce the same result.
# Quoting the standard draft:
#
# 6.11. Sorting
#
# UUIDv6 and UUIDv7 are designed so that implementations that require
# sorting (e.g., database indexes) sort as opaque raw bytes, without
# need for parsing or introspection.
#
--sorted_result
select * from t1, t1 t where t1.b div 4 in (6,7) and t.b div 4 in (6,7) and concat(t1.a) > concat(t.a);
drop table t1;
......@@ -3182,10 +3182,10 @@ d
11111111-0000-0000-0000-000000000000
SELECT * FROM t1 WHERE d <= ALL (SELECT * FROM t1);
d
11111111-0000-0000-0000-000000000000
00000000-0000-0000-0000-111111111111
SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1);
d
00000000-0000-0000-0000-111111111111
11111111-0000-0000-0000-000000000000
DROP TABLE t1;
#
# MDEV-31719 Wrong result of: WHERE inet6_column IN ('','::1')
......
......@@ -241,14 +241,20 @@ class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
{
DBUG_ASSERT(a.length == binary_length());
DBUG_ASSERT(b.length == binary_length());
int res;
if ((res= segment(4).cmp_memory(a.str, b.str)) ||
(res= segment(3).cmp_memory(a.str, b.str)) ||
(res= segment(2).cmp_memory(a.str, b.str)) ||
(res= segment(1).cmp_memory(a.str, b.str)) ||
(res= segment(0).cmp_memory(a.str, b.str)))
return res;
return 0;
bool swap_a= force_swap || mem_need_swap(a.str);
bool swap_b= force_swap || mem_need_swap(b.str);
if (swap_a && swap_b)
{
int res;
if ((res= segment(4).cmp_memory(a.str, b.str)) ||
(res= segment(3).cmp_memory(a.str, b.str)) ||
(res= segment(2).cmp_memory(a.str, b.str)) ||
(res= segment(1).cmp_memory(a.str, b.str)) ||
(res= segment(0).cmp_memory(a.str, b.str)))
return res;
return 0;
}
return memcmp(a.str, b.str, binary_length());
}
static ulong KEY_pack_flags(uint column_nr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment