```
SET max_bytes_before_external_sort = 33554432;
set max_block_size = 1048576;
SELECT number FROM (SELECT number FROM numbers(2097152)) ORDER BY number * 1234567890123456789 LIMIT 2097142, 10;

Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Pipeline stuck. Current state:
digraph
{
  rankdir="LR";
  { node [shape = box]
    n140555455738912[label="Numbers(2 jobs) (Finished)"];
    n140554936614744[label="Limit(0 jobs) (Finished)"];
    n140554935957656[label="ExpressionTransform(2 jobs) (Finished)"];
    n140554935947416[label="ExpressionTransform(2 jobs) (Finished)"];
    n140554935947736[label="Converting(2 jobs) (Finished)"];
    n140554935957976[label="ExpressionTransform(2 jobs) (Finished)"];
    n140554935472152[label="PartialSortingTransform(2 jobs) (Finished)"];
    n140554935484312[label="LimitsCheckingTransform(2 jobs) (Finished)"];
    n140556954827928[label="MergeSortingTransform(5 jobs) (NeedData)"];
    n140556724839064[label="Limit(0 jobs) (NeedData)"];
    n140556724839704[label="ExpressionTransform(0 jobs) (NeedData)"];
    n140556724840024[label="Converting(0 jobs) (NeedData)"];
    n140554935476248[label="LimitsCheckingTransform(0 jobs) (NeedData)"];
    n140556954548216[label="NullSource(0 jobs) (NeedData)"];
    n140556954546872[label="NullSource(0 jobs) (NeedData)"];
    n140556716210200[label="LazyOutputFormat(0 jobs) (NeedData)"];
    n140556626042904[label="BufferingToFileTransform(4 jobs) (PortFull)"];
    n140556626043544[label="MergingSortedTransform(0 jobs) (NeedData)"];
  }
  n140555455738912 -> n140554936614744;
  n140554936614744 -> n140554935957656;
  n140554935957656 -> n140554935947416;
  n140554935947416 -> n140554935947736;
  n140554935947736 -> n140554935957976;
  n140554935957976 -> n140554935472152;
  n140554935472152 -> n140554935484312;
  n140554935484312 -> n140556954827928;
  n140556954827928 -> n140556724839064;
  n140556954827928 -> n140556626042904;
  n140556724839064 -> n140556724839704;
  n140556724839704 -> n140556724840024;
  n140556724840024 -> n140554935476248;
  n140554935476248 -> n140556716210200;
  n140556954548216 -> n140556716210200;
  n140556954546872 -> n140556716210200;
  n140556626042904 -> n140556626043544;
  n140556626043544 -> n140556954827928;
}
```
master (20.7.1.1)

removeConstColumns(chunk);
    sum_rows_in_blocks += chunk.getNumRows();
    sum_bytes_in_blocks += chunk.allocatedBytes();
    chunks.push_back(std::move(chunk));
    /** If significant amount of data was accumulated, perform preliminary merging step.
      */
    if (chunks.size() > 1
        && limit
        && limit * 2 < sum_rows_in_blocks   
        && remerge_is_useful
        && max_bytes_before_remerge
        && sum_bytes_in_blocks > max_bytes_before_remerge)
    {
        remerge();
    }
    /** If too many of them and if external sorting is enabled,
      *  will merge blocks that we have in memory at this moment and write merged stream to temporary (compressed) file.
      * NOTE. It's possible to check free space in filesystem.
      */
    if (max_bytes_before_external_sort && sum_bytes_in_blocks > max_bytes_before_external_sort)
    {
        size_t size = sum_bytes_in_blocks + min_free_disk_space;
        auto reservation = tmp_volume->reserve(size);
        if (!reservation)
            throw Exception("Not enough space for external sort in temporary storage", ErrorCodes::NOT_ENOUGH_SPACE);
        const std::string tmp_path(reservation->getDisk()->getPath());
        temporary_files.emplace_back(createTemporaryFile(tmp_path));
        const std::string & path = temporary_files.back()->path();
        merge_sorter = std::make_unique<MergeSorter>(std::move(chunks), description, max_merged_block_size, limit);
        auto current_processor = std::make_shared<BufferingToFileTransform>(header_without_constants, log, path);