Skip to content

Commit

Permalink
Revert "*: fix incorrect results about string cmp with collation (pin…
Browse files Browse the repository at this point in the history
…gcap#5429)"

This reverts commit f99b74c.
  • Loading branch information
solotzg committed Sep 19, 2022
1 parent c21f60b commit 66313b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
10 changes: 4 additions & 6 deletions dbms/src/Columns/ColumnString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,9 @@ int ColumnString::compareAtWithCollationImpl(size_t n, size_t m, const IColumn &

return collator.compare(
reinterpret_cast<const char *>(&chars[offsetAt(n)]),
sizeAt(n) - 1, // Skip last zero byte.
sizeAt(n),
reinterpret_cast<const char *>(&rhs.chars[rhs.offsetAt(m)]),
rhs.sizeAt(m) - 1 // Skip last zero byte.
);
rhs.sizeAt(m));
}


Expand All @@ -342,10 +341,9 @@ struct ColumnString::lessWithCollation
{
int res = collator.compare(
reinterpret_cast<const char *>(&parent.chars[parent.offsetAt(lhs)]),
parent.sizeAt(lhs) - 1, // Skip last zero byte.
parent.sizeAt(lhs),
reinterpret_cast<const char *>(&parent.chars[parent.offsetAt(rhs)]),
parent.sizeAt(rhs) - 1 // Skip last zero byte.
);
parent.sizeAt(rhs));

return positive ? (res < 0) : (res > 0);
}
Expand Down
6 changes: 2 additions & 4 deletions dbms/src/Columns/ColumnString.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ class ColumnString final : public COWPtrHelper<IColumn, ColumnString>
size_t offset = offsetAt(n);
if (collator != nullptr)
{
// Skip last zero byte.
auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size - 1, sort_key_container);
auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size, sort_key_container);
string_size = sort_key.size;
hash.update(reinterpret_cast<const char *>(&string_size), sizeof(string_size));
hash.update(sort_key.data, sort_key.size);
Expand All @@ -268,8 +267,7 @@ class ColumnString final : public COWPtrHelper<IColumn, ColumnString>
size_t string_size = sizeAt(i);
size_t offset = offsetAt(i);

/// Skip last zero byte.
auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size - 1, sort_key_container);
auto sort_key = collator->sortKey(reinterpret_cast<const char *>(&chars[offset]), string_size, sort_key_container);
string_size = sort_key.size;
hash_values[i].update(reinterpret_cast<const char *>(&string_size), sizeof(string_size));
hash_values[i].update(sort_key.data, sort_key.size);
Expand Down
18 changes: 1 addition & 17 deletions tests/tidb-ci/new_collation_fullstack/expr.test
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,4 @@ mysql> set session tidb_isolation_read_engines='tiflash'; select /*+ read_from_s
| min(value) | max(value) | min(value1) | max(value1) |
+------------+------------+-------------+-------------+
| abc | def | abc | def |
+------------+------------+-------------+-------------+

mysql> insert into test.t values (4, '', 'def\n'), (5, '', 'def ');

mysql> select /*+ read_from_storage(tiflash[t]) */ hex(max(value1)) from test.t;
+------------------+
| hex(max(value1)) |
+------------------+
| 6465660A |
+------------------+

mysql> select /*+ read_from_storage(tiflash[t]) */ hex(min(value1)) from test.t;
+------------------+
| hex(min(value1)) |
+------------------+
| 61626320 |
+------------------+
+------------+------------+-------------+-------------+

0 comments on commit 66313b1

Please sign in to comment.