From 12040bbf249f13e6a57ddfd90a6f92801ff5be9e Mon Sep 17 00:00:00 2001 From: Alexander Gololobov Date: Mon, 25 Nov 2024 18:30:54 +0100 Subject: [PATCH] Fix for empty permutation --- src/Interpreters/sortBlock.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/sortBlock.cpp b/src/Interpreters/sortBlock.cpp index 1c4754b1ef2..064632d4c7b 100644 --- a/src/Interpreters/sortBlock.cpp +++ b/src/Interpreters/sortBlock.cpp @@ -282,10 +282,12 @@ void checkSortedWithPermutationImpl(size_t rows, Comparator compare, UInt64 limi if (limit && limit < rows) rows = limit; + const bool no_permutaiton = permutation.empty(); + for (size_t i = 1; i < rows; ++i) { - const size_t current_row = permutation[i]; - const size_t previous_row = permutation[i - 1]; + const size_t current_row = no_permutaiton ? i : permutation[i]; + const size_t previous_row = no_permutaiton ? (i - 1) : permutation[i - 1]; if (compare(current_row, previous_row)) throw Exception(ErrorCodes::LOGICAL_ERROR,