Commit 5436b5dd authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: UUID

* modify the test to use different and not monotonous timestamps
* rename methods to be unambiguous (for IDE challenged devs)
* move byte swap checks into helpers
parent b9e210bb
......@@ -2,8 +2,9 @@
source include/have_sequence.inc;
create table t1 (a uuid, b int not null, index (a));
insert t1 select sformat('11223344-5566-{:x}777-{}888-99aabbccddee', seq div 4, elt(1+(seq % 4),0,8,'c','e')),seq from seq_0_to_63;
select * from t1;
insert t1 select sformat('{:03}01234-5566-{:x}777-{}888-99aabbccddee',
(seq % 2)*100 + seq, seq div 4, elt(1+(seq % 4),0,8,'c','e')),seq from seq_0_to_63;
select * from t1 order by b;
select * from t1 order by a;
show create table t1;
......@@ -12,7 +13,7 @@ let $datadir= `select @@datadir`;
--copy_file $MTR_SUITE_DIR/std_data/mdev-29959.frm $datadir/test/t2.frm
--copy_file $MTR_SUITE_DIR/std_data/mdev-29959.MYI $datadir/test/t2.MYI
--copy_file $MTR_SUITE_DIR/std_data/mdev-29959.MYD $datadir/test/t2.MYD
select * from t2;
select * from t2 order by b;
select * from t2 order by a;
show create table t2;
......
......@@ -142,11 +142,11 @@ class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
constexpr Segment(size_t memory_pos, size_t record_pos, size_t length)
:m_memory_pos(memory_pos), m_record_pos(record_pos), m_length(length)
{ }
void memory_to_record(char *to, const char *from) const
void mem2rec(char *to, const char *from) const
{
memcpy(to + m_record_pos, from + m_memory_pos, m_length);
}
void record_to_memory(char *to, const char * from) const
void rec2mem(char *to, const char * from) const
{
memcpy(to + m_memory_pos, from + m_record_pos, m_length);
}
......@@ -173,16 +173,24 @@ class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
return segments[i];
}
// version > 0 && version < 6 && variant != 0
static bool mem_need_swap(const char *s)
{ return s[6] > 0 && s[6] < 0x60 && s[8] & 0x80; }
// s[6] & 0x80 && s[8] > 0: this means a swapped uuid
static bool rec_need_swap(const char *s)
{ return s[6] & -s[8] & 0x80; }
// Convert the in-memory representation to the in-record representation
static void memory_to_record(char *to, const char *from)
{
if (force_swap || (from[6] > 0 && from[6] < 0x60 && from[8] & 0x80))
if (force_swap || mem_need_swap(from))
{
segment(0).memory_to_record(to, from);
segment(1).memory_to_record(to, from);
segment(2).memory_to_record(to, from);
segment(3).memory_to_record(to, from);
segment(4).memory_to_record(to, from);
segment(0).mem2rec(to, from);
segment(1).mem2rec(to, from);
segment(2).mem2rec(to, from);
segment(3).mem2rec(to, from);
segment(4).mem2rec(to, from);
}
else
memcpy(to, from, binary_length());
......@@ -191,13 +199,13 @@ class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
// Convert the in-record representation to the in-memory representation
static void record_to_memory(char *to, const char *from)
{
if (force_swap || (from[6] & -from[8] & 0x80))
if (force_swap || rec_need_swap(from))
{
segment(0).record_to_memory(to, from);
segment(1).record_to_memory(to, from);
segment(2).record_to_memory(to, from);
segment(3).record_to_memory(to, from);
segment(4).record_to_memory(to, from);
segment(0).rec2mem(to, from);
segment(1).rec2mem(to, from);
segment(2).rec2mem(to, from);
segment(3).rec2mem(to, from);
segment(4).rec2mem(to, from);
}
else
memcpy(to, from, binary_length());
......
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