See https://github.com/ClickHouse/ClickHouse/pull/13193
{
    if (pref_descr.size() > descr.size())
        return false;
    for (size_t i = 0; i < pref_descr.size(); ++i)
        if (pref_descr[i] != descr[i])
            return false;
    return true;
}
FinishSortingTransform::FinishSortingTransform(
    const Block & header, const SortDescription & description_sorted_,
    const SortDescription & description_to_sort_,
    size_t max_merged_block_size_, UInt64 limit_)
    : SortingTransform(header, description_to_sort_, max_merged_block_size_, limit_)
    , description_sorted(description_sorted_)
{
    const auto & sample = inputs.front().getHeader();
    
    for (auto & column_description : description_sorted)
    {
        if (!column_description.column_name.empty())
        {
            column_description.column_number = sample.getPositionByName(column_description.column_name);
            column_description.column_name.clear();
        }
    }
    if (!isPrefix(description_sorted, description))
        throw Exception("Can`t finish sorting. SortDescription of already sorted stream is not prefix of "
            "SortDescription needed to sort", ErrorCodes::LOGICAL_ERROR);
}
static bool less(const Columns & lhs, const Columns & rhs, size_t i, size_t j, const SortDescription & descr)