From 66313b1887074e4348e2ff018b4b12394a966138 Mon Sep 17 00:00:00 2001 From: Zhigao Tong Date: Mon, 19 Sep 2022 20:26:10 +0800 Subject: [PATCH] Revert "*: fix incorrect results about string cmp with collation (#5429)" This reverts commit f99b74c393c2ca05d35b7a804200672232026e27. --- dbms/src/Columns/ColumnString.cpp | 10 ++++------ dbms/src/Columns/ColumnString.h | 6 ++---- .../tidb-ci/new_collation_fullstack/expr.test | 18 +----------------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/dbms/src/Columns/ColumnString.cpp b/dbms/src/Columns/ColumnString.cpp index 40b09272742..2985b124ea6 100644 --- a/dbms/src/Columns/ColumnString.cpp +++ b/dbms/src/Columns/ColumnString.cpp @@ -320,10 +320,9 @@ int ColumnString::compareAtWithCollationImpl(size_t n, size_t m, const IColumn & return collator.compare( reinterpret_cast(&chars[offsetAt(n)]), - sizeAt(n) - 1, // Skip last zero byte. + sizeAt(n), reinterpret_cast(&rhs.chars[rhs.offsetAt(m)]), - rhs.sizeAt(m) - 1 // Skip last zero byte. - ); + rhs.sizeAt(m)); } @@ -342,10 +341,9 @@ struct ColumnString::lessWithCollation { int res = collator.compare( reinterpret_cast(&parent.chars[parent.offsetAt(lhs)]), - parent.sizeAt(lhs) - 1, // Skip last zero byte. + parent.sizeAt(lhs), reinterpret_cast(&parent.chars[parent.offsetAt(rhs)]), - parent.sizeAt(rhs) - 1 // Skip last zero byte. - ); + parent.sizeAt(rhs)); return positive ? (res < 0) : (res > 0); } diff --git a/dbms/src/Columns/ColumnString.h b/dbms/src/Columns/ColumnString.h index c6326f88674..48b02388a6c 100644 --- a/dbms/src/Columns/ColumnString.h +++ b/dbms/src/Columns/ColumnString.h @@ -246,8 +246,7 @@ class ColumnString final : public COWPtrHelper size_t offset = offsetAt(n); if (collator != nullptr) { - // Skip last zero byte. - auto sort_key = collator->sortKey(reinterpret_cast(&chars[offset]), string_size - 1, sort_key_container); + auto sort_key = collator->sortKey(reinterpret_cast(&chars[offset]), string_size, sort_key_container); string_size = sort_key.size; hash.update(reinterpret_cast(&string_size), sizeof(string_size)); hash.update(sort_key.data, sort_key.size); @@ -268,8 +267,7 @@ class ColumnString final : public COWPtrHelper size_t string_size = sizeAt(i); size_t offset = offsetAt(i); - /// Skip last zero byte. - auto sort_key = collator->sortKey(reinterpret_cast(&chars[offset]), string_size - 1, sort_key_container); + auto sort_key = collator->sortKey(reinterpret_cast(&chars[offset]), string_size, sort_key_container); string_size = sort_key.size; hash_values[i].update(reinterpret_cast(&string_size), sizeof(string_size)); hash_values[i].update(sort_key.data, sort_key.size); diff --git a/tests/tidb-ci/new_collation_fullstack/expr.test b/tests/tidb-ci/new_collation_fullstack/expr.test index c88db20ba2f..1e2135c4f2d 100644 --- a/tests/tidb-ci/new_collation_fullstack/expr.test +++ b/tests/tidb-ci/new_collation_fullstack/expr.test @@ -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 | -+------------------+ ++------------+------------+-------------+-------------+ \ No newline at end of file