Merge pull request #13887 from ClickHouse/fix-fixed-string-partial-sort

Fix fixed string partial sort
This commit is contained in:
Nikolai Kochetov 2020-08-19 21:41:25 +03:00 committed by GitHub
commit 322cb241b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View File

@ -189,7 +189,7 @@ void ColumnFixedString::updatePermutation(bool reverse, size_t limit, int, Permu
auto new_first = first;
for (auto j = first + 1; j < last; ++j)
{
if (memcmpSmallAllowOverflow15(chars.data() + j * n, chars.data() + new_first * n, n) != 0)
if (memcmpSmallAllowOverflow15(chars.data() + res[j] * n, chars.data() + res[new_first] * n, n) != 0)
{
if (j - new_first > 1)
new_ranges.emplace_back(new_first, j);
@ -210,7 +210,7 @@ void ColumnFixedString::updatePermutation(bool reverse, size_t limit, int, Permu
auto new_first = first;
for (auto j = first + 1; j < limit; ++j)
{
if (memcmpSmallAllowOverflow15(chars.data() + j * n, chars.data() + new_first * n, n) != 0)
if (memcmpSmallAllowOverflow15(chars.data() + res[j] * n, chars.data() + res[new_first] * n, n) != 0)
{
if (j - new_first > 1)
new_ranges.emplace_back(new_first, j);
@ -221,7 +221,7 @@ void ColumnFixedString::updatePermutation(bool reverse, size_t limit, int, Permu
auto new_last = limit;
for (auto j = limit; j < last; ++j)
{
if (memcmpSmallAllowOverflow15(chars.data() + j * n, chars.data() + new_first * n, n) == 0)
if (memcmpSmallAllowOverflow15(chars.data() + res[j] * n, chars.data() + res[new_first] * n, n) == 0)
{
std::swap(res[new_last], res[j]);
++new_last;

View File

@ -0,0 +1,12 @@
8AD8FC5EA49E544C98E61140AFD79F80 1
8AD8FC5EA49E544C98E61140AFD79F80 1
8AD8FC5EA49E544C98E61140AFD79F80 2
8AD8FC5EA49E544C98E61140AFD79F80 2
999E114066EF56109C3AB3FB33E0FDA9 1
999E114066EF56109C3AB3FB33E0FDA9 1
999E114066EF56109C3AB3FB33E0FDA9 1
999E114066EF56109C3AB3FB33E0FDA9 1
999E114066EF56109C3AB3FB33E0FDA9 2
999E114066EF56109C3AB3FB33E0FDA9 2
999E114066EF56109C3AB3FB33E0FDA9 2
999E114066EF56109C3AB3FB33E0FDA9 2

View File

@ -0,0 +1,22 @@
drop table if exists badFixedStringSort;
CREATE TABLE IF NOT EXISTS badFixedStringSort (uuid5_old FixedString(16), subitem String) engine=MergeTree order by tuple();
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '2');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '2');
INSERT INTO badFixedStringSort values (UUIDStringToNum('8ad8fc5e-a49e-544c-98e6-1140afd79f80'), '2');
INSERT INTO badFixedStringSort values (UUIDStringToNum('8ad8fc5e-a49e-544c-98e6-1140afd79f80'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('8ad8fc5e-a49e-544c-98e6-1140afd79f80'), '2');
INSERT INTO badFixedStringSort values (UUIDStringToNum('8ad8fc5e-a49e-544c-98e6-1140afd79f80'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '2');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '1');
INSERT INTO badFixedStringSort values (UUIDStringToNum('999e1140-66ef-5610-9c3a-b3fb33e0fda9'), '2');
optimize table badFixedStringSort final;
select hex(uuid5_old), subitem from badFixedStringSort ORDER BY uuid5_old, subitem;
drop table if exists badFixedStringSort;