Skip to content

Commit

Permalink
Revert "Optimize comparision for collation UTF8_BIN and `UTF8MB4_BI…
Browse files Browse the repository at this point in the history
…N` (pingcap#5299)"

This reverts commit 97342db.
  • Loading branch information
solotzg committed Sep 19, 2022
1 parent 66313b1 commit c899c83
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 287 deletions.
3 changes: 1 addition & 2 deletions dbms/src/Columns/ColumnConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ class ColumnConst final : public COWPtrHelper<IColumn, ColumnConst>
template <typename T>
T getValue() const
{
auto && tmp = getField();
return std::move(tmp.safeGet<typename NearestFieldType<T>::Type>());
return getField().safeGet<typename NearestFieldType<T>::Type>();
}
};

Expand Down
210 changes: 0 additions & 210 deletions dbms/src/Functions/CollationOperatorOptimized.h

This file was deleted.

54 changes: 9 additions & 45 deletions dbms/src/Functions/FunctionsComparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypesNumber.h>
#include <Functions/CollationOperatorOptimized.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/FunctionsLogical.h>
#include <Functions/IFunction.h>
Expand Down Expand Up @@ -302,12 +301,6 @@ struct StringComparisonWithCollatorImpl
const TiDB::TiDBCollatorPtr & collator,
PaddedPODArray<ResultType> & c)
{
bool optimized_path = StringVectorStringVector<Op>(a_data, a_offsets, b_data, b_offsets, collator, c);
if (optimized_path)
{
return;
}

size_t size = a_offsets.size();

for (size_t i = 0; i < size; ++i)
Expand All @@ -324,17 +317,10 @@ struct StringComparisonWithCollatorImpl
static void NO_INLINE stringVectorConstant(
const ColumnString::Chars_t & a_data,
const ColumnString::Offsets & a_offsets,
const std::string_view & b,
const std::string & b,
const TiDB::TiDBCollatorPtr & collator,
PaddedPODArray<ResultType> & c)
{
bool optimized_path = StringVectorConstant<Op>(a_data, a_offsets, b, collator, c);

if (optimized_path)
{
return;
}

size_t size = a_offsets.size();
ColumnString::Offset b_size = b.size();
const char * b_data = reinterpret_cast<const char *>(b.data());
Expand All @@ -346,7 +332,7 @@ struct StringComparisonWithCollatorImpl
}

static void constantStringVector(
const std::string_view & a,
const std::string & a,
const ColumnString::Chars_t & b_data,
const ColumnString::Offsets & b_offsets,
const TiDB::TiDBCollatorPtr & collator,
Expand All @@ -356,8 +342,8 @@ struct StringComparisonWithCollatorImpl
}

static void constantConstant(
const std::string_view & a,
const std::string_view & b,
const std::string & a,
const std::string & b,
const TiDB::TiDBCollatorPtr & collator,
ResultType & c)
{
Expand Down Expand Up @@ -720,25 +706,6 @@ class FunctionComparison : public IFunction
}
}

static inline std::string_view genConstStrRef(const ColumnConst * c0_const)
{
std::string_view c0_const_str_ref{};
if (c0_const)
{
if (const auto * c0_const_string = checkAndGetColumn<ColumnString>(&c0_const->getDataColumn()); c0_const_string)
{
c0_const_str_ref = std::string_view(c0_const_string->getDataAt(0));
}
else if (const auto * c0_const_fixed_string = checkAndGetColumn<ColumnFixedString>(&c0_const->getDataColumn()); c0_const_fixed_string)
{
c0_const_str_ref = std::string_view(c0_const_fixed_string->getDataAt(0));
}
else
throw Exception("Logical error: ColumnConst contains not String nor FixedString column", ErrorCodes::ILLEGAL_COLUMN);
}
return c0_const_str_ref;
}

template <typename ResultColumnType>
bool executeStringWithCollator(
Block & block,
Expand All @@ -753,13 +720,10 @@ class FunctionComparison : public IFunction
using ResultType = typename ResultColumnType::value_type;
using StringImpl = StringComparisonWithCollatorImpl<Op<int, int>, ResultType>;

std::string_view c0_const_str_ref = genConstStrRef(c0_const);
std::string_view c1_const_str_ref = genConstStrRef(c1_const);

if (c0_const && c1_const)
{
ResultType res = 0;
StringImpl::constantConstant(c0_const_str_ref, c1_const_str_ref, collator, res);
StringImpl::constantConstant(c0_const->getValue<String>(), c1_const->getValue<String>(), collator, res);
block.getByPosition(result).column = block.getByPosition(result).type->createColumnConst(c0_const->size(), toField(res));
return true;
}
Expand All @@ -781,12 +745,12 @@ class FunctionComparison : public IFunction
StringImpl::stringVectorConstant(
c0_string->getChars(),
c0_string->getOffsets(),
c1_const_str_ref,
c1_const->getValue<String>(),
collator,
c_res->getData());
else if (c0_const && c1_string)
StringImpl::constantStringVector(
c0_const_str_ref,
c0_const->getValue<String>(),
c1_string->getChars(),
c1_string->getOffsets(),
collator,
Expand All @@ -806,8 +770,8 @@ class FunctionComparison : public IFunction
template <typename ReturnColumnType = ColumnUInt8>
bool executeString(Block & block, size_t result, const IColumn * c0, const IColumn * c1) const
{
const auto * c0_string = checkAndGetColumn<ColumnString>(c0);
const auto * c1_string = checkAndGetColumn<ColumnString>(c1);
const ColumnString * c0_string = checkAndGetColumn<ColumnString>(c0);
const ColumnString * c1_string = checkAndGetColumn<ColumnString>(c1);
const ColumnConst * c0_const = checkAndGetColumnConstStringOrFixedString(c0);
const ColumnConst * c1_const = checkAndGetColumnConstStringOrFixedString(c1);

Expand Down
Loading

0 comments on commit c899c83

Please sign in to comment.