forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortCursor.h
730 lines (589 loc) · 23.5 KB
/
SortCursor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
#pragma once
#include <cassert>
#include <vector>
#include <algorithm>
#include <Common/typeid_cast.h>
#include <Common/assert_cast.h>
#include <Core/callOnTypeIndex.h>
#include <Core/SortDescription.h>
#include <Core/Block.h>
#include <Core/ColumnNumbers.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypesDecimal.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeFixedString.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDate32.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeEnum.h>
#include <DataTypes/DataTypeUUID.h>
#include <Columns/IColumn.h>
#include <Columns/ColumnDecimal.h>
#include <Columns/ColumnString.h>
#include <Columns/ColumnFixedString.h>
#include "config.h"
#if USE_EMBEDDED_COMPILER
#include <Interpreters/JIT/compileFunction.h>
#endif
namespace DB
{
/** Cursor allows to compare rows in different blocks (and parts).
* Cursor moves inside single block.
* It is used in priority queue.
*/
struct SortCursorImpl
{
ColumnRawPtrs sort_columns;
ColumnRawPtrs all_columns;
SortDescription desc;
size_t sort_columns_size = 0;
size_t rows = 0;
/** Determines order if comparing columns are equal.
* Order is determined by number of cursor.
*
* Cursor number (always?) equals to number of merging part.
* Therefore this field can be used to determine part number of current row (see ColumnGathererStream).
*/
size_t order = 0;
using NeedCollationFlags = std::vector<UInt8>;
/** Should we use Collator to sort a column? */
NeedCollationFlags need_collation;
/** Is there at least one column with Collator. */
bool has_collation = false;
/** We could use SortCursorImpl in case when columns aren't sorted
* but we have their sorted permutation
*/
IColumn::Permutation * permutation = nullptr;
#if USE_EMBEDDED_COMPILER
std::vector<ColumnData> raw_sort_columns_data;
#endif
SortCursorImpl() = default;
SortCursorImpl(const Block & block, const SortDescription & desc_, size_t order_ = 0, IColumn::Permutation * perm = nullptr)
: desc(desc_), sort_columns_size(desc.size()), order(order_), need_collation(desc.size())
{
reset(block, perm);
}
SortCursorImpl(
const Block & header,
const Columns & columns,
const SortDescription & desc_,
size_t order_ = 0,
IColumn::Permutation * perm = nullptr)
: desc(desc_), sort_columns_size(desc.size()), order(order_), need_collation(desc.size())
{
reset(columns, header, perm);
}
bool empty() const { return rows == 0; }
/// Set the cursor to the beginning of the new block.
void reset(const Block & block, IColumn::Permutation * perm = nullptr) { reset(block.getColumns(), block, perm); }
/// Set the cursor to the beginning of the new block.
void reset(const Columns & columns, const Block & block, IColumn::Permutation * perm = nullptr)
{
all_columns.clear();
sort_columns.clear();
#if USE_EMBEDDED_COMPILER
raw_sort_columns_data.clear();
#endif
size_t num_columns = columns.size();
for (size_t j = 0; j < num_columns; ++j)
all_columns.push_back(columns[j].get());
for (size_t j = 0, size = desc.size(); j < size; ++j)
{
auto & column_desc = desc[j];
size_t column_number = block.getPositionByName(column_desc.column_name);
sort_columns.push_back(columns[column_number].get());
#if USE_EMBEDDED_COMPILER
if (desc.compiled_sort_description)
raw_sort_columns_data.emplace_back(getColumnData(sort_columns.back()));
#endif
need_collation[j] = desc[j].collator != nullptr && sort_columns.back()->isCollationSupported();
has_collation |= need_collation[j];
}
pos = 0;
rows = all_columns[0]->size();
permutation = perm;
}
size_t getRow() const
{
if (permutation)
return (*permutation)[pos];
return pos;
}
/// We need a possibility to change pos (see MergeJoin).
size_t & getPosRef() { return pos; }
bool isFirst() const { return pos == 0; }
bool isLast() const { return pos + 1 >= rows; }
bool isLast(size_t size) const { return pos + size >= rows; }
bool isValid() const { return pos < rows; }
void next() { ++pos; }
void next(size_t size) { pos += size; }
size_t getSize() const { return rows; }
size_t rowsLeft() const { return rows - pos; }
/// Prevent using pos instead of getRow()
private:
size_t pos = 0;
};
using SortCursorImpls = std::vector<SortCursorImpl>;
/// For easy copying.
template <typename Derived>
struct SortCursorHelper
{
SortCursorImpl * impl;
const Derived & derived() const { return static_cast<const Derived &>(*this); }
explicit SortCursorHelper(SortCursorImpl * impl_) : impl(impl_) {}
SortCursorImpl * operator-> () { return impl; }
const SortCursorImpl * operator-> () const { return impl; }
bool ALWAYS_INLINE greater(const SortCursorHelper & rhs) const
{
return derived().greaterAt(rhs.derived(), impl->getRow(), rhs.impl->getRow());
}
bool ALWAYS_INLINE greaterWithOffset(const SortCursorHelper & rhs, size_t lhs_offset, size_t rhs_offset) const
{
return derived().greaterAt(rhs.derived(), impl->getRow() + lhs_offset, rhs.impl->getRow() + rhs_offset);
}
/// Inverted so that the priority queue elements are removed in ascending order.
bool ALWAYS_INLINE operator< (const SortCursorHelper & rhs) const
{
return derived().greater(rhs.derived());
}
/// Checks that all rows in the current block of this cursor are less than or equal to all the rows of the current block of another cursor.
bool ALWAYS_INLINE totallyLessOrEquals(const SortCursorHelper & rhs) const
{
if (impl->rows == 0 || rhs.impl->rows == 0)
return false;
/// The last row of this cursor is no larger than the first row of the another cursor.
return !derived().greaterAt(rhs.derived(), impl->rows - 1, 0);
}
};
struct SortCursor : SortCursorHelper<SortCursor>
{
using SortCursorHelper<SortCursor>::SortCursorHelper;
/// The specified row of this cursor is greater than the specified row of another cursor.
bool ALWAYS_INLINE greaterAt(const SortCursor & rhs, size_t lhs_pos, size_t rhs_pos) const
{
#if USE_EMBEDDED_COMPILER
if (impl->desc.compiled_sort_description && rhs.impl->desc.compiled_sort_description)
{
assert(impl->raw_sort_columns_data.size() == rhs.impl->raw_sort_columns_data.size());
auto sort_description_func_typed = reinterpret_cast<JITSortDescriptionFunc>(impl->desc.compiled_sort_description);
int res = sort_description_func_typed(lhs_pos, rhs_pos, impl->raw_sort_columns_data.data(), rhs.impl->raw_sort_columns_data.data()); /// NOLINT
if (res > 0)
return true;
if (res < 0)
return false;
return impl->order > rhs.impl->order;
}
#endif
for (size_t i = 0; i < impl->sort_columns_size; ++i)
{
const auto & desc = impl->desc[i];
int direction = desc.direction;
int nulls_direction = desc.nulls_direction;
int res = direction * impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction);
if (res > 0)
return true;
if (res < 0)
return false;
}
return impl->order > rhs.impl->order;
}
};
/// For the case with a single column and when there is no order between different cursors.
struct SimpleSortCursor : SortCursorHelper<SimpleSortCursor>
{
using SortCursorHelper<SimpleSortCursor>::SortCursorHelper;
bool ALWAYS_INLINE greaterAt(const SimpleSortCursor & rhs, size_t lhs_pos, size_t rhs_pos) const
{
int res = 0;
#if USE_EMBEDDED_COMPILER
if (impl->desc.compiled_sort_description && rhs.impl->desc.compiled_sort_description)
{
assert(impl->raw_sort_columns_data.size() == rhs.impl->raw_sort_columns_data.size());
auto sort_description_func_typed = reinterpret_cast<JITSortDescriptionFunc>(impl->desc.compiled_sort_description);
res = sort_description_func_typed(lhs_pos, rhs_pos, impl->raw_sort_columns_data.data(), rhs.impl->raw_sort_columns_data.data()); /// NOLINT
}
else
#endif
{
const auto & desc = impl->desc[0];
int direction = desc.direction;
int nulls_direction = desc.nulls_direction;
res = direction * impl->sort_columns[0]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[0]), nulls_direction);
}
if (res > 0)
return true;
if (res < 0)
return false;
return impl->order > rhs.impl->order;
}
};
template <typename ColumnType>
struct SpecializedSingleColumnSortCursor : SortCursorHelper<SpecializedSingleColumnSortCursor<ColumnType>>
{
using SortCursorHelper<SpecializedSingleColumnSortCursor>::SortCursorHelper;
bool ALWAYS_INLINE greaterAt(const SortCursorHelper<SpecializedSingleColumnSortCursor> & rhs, size_t lhs_pos, size_t rhs_pos) const
{
auto & this_impl = this->impl;
auto & lhs_columns = this_impl->sort_columns;
auto & rhs_columns = rhs.impl->sort_columns;
assert(lhs_columns.size() == 1);
assert(rhs_columns.size() == 1);
const auto & lhs_column = assert_cast<const ColumnType &>(*lhs_columns[0]);
const auto & rhs_column = assert_cast<const ColumnType &>(*rhs_columns[0]);
const auto & desc = this->impl->desc[0];
int res = desc.direction * lhs_column.compareAt(lhs_pos, rhs_pos, rhs_column, desc.nulls_direction);
if (res > 0)
return true;
if (res < 0)
return false;
return this_impl->order > rhs.impl->order;
}
};
/// Separate comparator for locale-sensitive string comparisons
struct SortCursorWithCollation : SortCursorHelper<SortCursorWithCollation>
{
using SortCursorHelper<SortCursorWithCollation>::SortCursorHelper;
bool ALWAYS_INLINE greaterAt(const SortCursorWithCollation & rhs, size_t lhs_pos, size_t rhs_pos) const
{
for (size_t i = 0; i < impl->sort_columns_size; ++i)
{
const auto & desc = impl->desc[i];
int direction = desc.direction;
int nulls_direction = desc.nulls_direction;
int res;
if (impl->need_collation[i])
res = impl->sort_columns[i]->compareAtWithCollation(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction, *impl->desc[i].collator);
else
res = impl->sort_columns[i]->compareAt(lhs_pos, rhs_pos, *(rhs.impl->sort_columns[i]), nulls_direction);
res *= direction;
if (res > 0)
return true;
if (res < 0)
return false;
}
return impl->order > rhs.impl->order;
}
};
enum class SortingQueueStrategy
{
Default,
Batch
};
/// Allows to fetch data from multiple sort cursors in sorted order (merging sorted data streams).
template <typename Cursor, SortingQueueStrategy strategy>
class SortingQueueImpl
{
public:
SortingQueueImpl() = default;
template <typename Cursors>
explicit SortingQueueImpl(Cursors & cursors)
{
size_t size = cursors.size();
queue.reserve(size);
for (size_t i = 0; i < size; ++i)
{
if (cursors[i].empty())
continue;
queue.emplace_back(&cursors[i]);
}
std::make_heap(queue.begin(), queue.end());
if constexpr (strategy == SortingQueueStrategy::Batch)
{
if (!queue.empty())
updateBatchSize();
}
}
bool isValid() const { return !queue.empty(); }
Cursor & current() requires (strategy == SortingQueueStrategy::Default)
{
return queue.front();
}
std::pair<Cursor *, size_t> current() requires (strategy == SortingQueueStrategy::Batch)
{
return {&queue.front(), batch_size};
}
size_t size() { return queue.size(); }
Cursor & nextChild() { return queue[nextChildIndex()]; }
void ALWAYS_INLINE next() requires (strategy == SortingQueueStrategy::Default)
{
assert(isValid());
if (!queue.front()->isLast())
{
queue.front()->next();
updateTop(true /*check_in_order*/);
}
else
{
removeTop();
}
}
void ALWAYS_INLINE next(size_t batch_size_value) requires (strategy == SortingQueueStrategy::Batch)
{
assert(isValid());
assert(batch_size_value <= batch_size);
assert(batch_size_value > 0);
batch_size -= batch_size_value;
if (batch_size > 0)
{
queue.front()->next(batch_size_value);
return;
}
if (!queue.front()->isLast(batch_size_value))
{
queue.front()->next(batch_size_value);
updateTop(false /*check_in_order*/);
}
else
{
removeTop();
}
}
void replaceTop(Cursor new_top)
{
queue.front() = new_top;
updateTop(true /*check_in_order*/);
}
void removeTop()
{
std::pop_heap(queue.begin(), queue.end());
queue.pop_back();
next_child_idx = 0;
if constexpr (strategy == SortingQueueStrategy::Batch)
{
if (queue.empty())
batch_size = 0;
else
updateBatchSize();
}
}
void push(SortCursorImpl & cursor)
{
queue.emplace_back(&cursor);
std::push_heap(queue.begin(), queue.end());
next_child_idx = 0;
if constexpr (strategy == SortingQueueStrategy::Batch)
updateBatchSize();
}
private:
using Container = std::vector<Cursor>;
Container queue;
/// Cache comparison between first and second child if the order in queue has not been changed.
size_t next_child_idx = 0;
size_t batch_size = 0;
size_t ALWAYS_INLINE nextChildIndex()
{
if (next_child_idx == 0)
{
next_child_idx = 1;
if (queue.size() > 2 && queue[1].greater(queue[2]))
++next_child_idx;
}
return next_child_idx;
}
/// This is adapted version of the function __sift_down from libc++.
/// Why cannot simply use std::priority_queue?
/// - because it doesn't support updating the top element and requires pop and push instead.
/// Also look at "Boost.Heap" library.
void ALWAYS_INLINE updateTop(bool check_in_order)
{
size_t size = queue.size();
if (size < 2)
return;
auto begin = queue.begin();
size_t child_idx = nextChildIndex();
auto child_it = begin + child_idx;
/// Check if we are in order.
if (check_in_order && (*child_it).greater(*begin))
{
if constexpr (strategy == SortingQueueStrategy::Batch)
updateBatchSize();
return;
}
next_child_idx = 0;
auto curr_it = begin;
auto top(std::move(*begin));
do
{
/// We are not in heap-order, swap the parent with it's largest child.
*curr_it = std::move(*child_it);
curr_it = child_it;
// recompute the child based off of the updated parent
child_idx = 2 * child_idx + 1;
if (child_idx >= size)
break;
child_it = begin + child_idx;
if ((child_idx + 1) < size && (*child_it).greater(*(child_it + 1)))
{
/// Right child exists and is greater than left child.
++child_it;
++child_idx;
}
/// Check if we are in order.
} while (!((*child_it).greater(top)));
*curr_it = std::move(top);
if constexpr (strategy == SortingQueueStrategy::Batch)
updateBatchSize();
}
/// Update batch size of elements that client can extract from current cursor
void updateBatchSize()
{
assert(!queue.empty());
auto & begin_cursor = *queue.begin();
size_t min_cursor_size = begin_cursor->getSize();
size_t min_cursor_pos = begin_cursor->getPosRef();
if (queue.size() == 1)
{
batch_size = min_cursor_size - min_cursor_pos;
return;
}
batch_size = 1;
size_t child_idx = nextChildIndex();
auto & next_child_cursor = *(queue.begin() + child_idx);
if (min_cursor_pos + batch_size < min_cursor_size && next_child_cursor.greaterWithOffset(begin_cursor, 0, batch_size))
++batch_size;
else
return;
if (unlikely(begin_cursor.totallyLessOrEquals(next_child_cursor)))
{
batch_size = min_cursor_size - min_cursor_pos;
return;
}
while (min_cursor_pos + batch_size < min_cursor_size && next_child_cursor.greaterWithOffset(begin_cursor, 0, batch_size))
++batch_size;
}
};
template <typename Cursor>
using SortingQueue = SortingQueueImpl<Cursor, SortingQueueStrategy::Default>;
template <typename Cursor>
using SortingQueueBatch = SortingQueueImpl<Cursor, SortingQueueStrategy::Batch>;
/** SortQueueVariants allow to specialize sorting queue for concrete types and sort description.
* To access queue variant callOnVariant method must be used.
* To access batch queue variant callOnBatchVariant method must be used.
*/
class SortQueueVariants
{
public:
SortQueueVariants() = default;
SortQueueVariants(const DataTypes & sort_description_types, const SortDescription & sort_description)
{
bool has_collation = false;
for (const auto & column_description : sort_description)
{
if (column_description.collator)
{
has_collation = true;
break;
}
}
if (has_collation)
{
initializeQueues<SortCursorWithCollation>();
return;
}
else if (sort_description.size() == 1)
{
TypeIndex column_type_index = sort_description_types[0]->getTypeId();
bool result = callOnIndexAndDataType<void>(
column_type_index,
[&](const auto & types)
{
using Types = std::decay_t<decltype(types)>;
using ColumnDataType = typename Types::LeftType;
using ColumnType = typename ColumnDataType::ColumnType;
initializeQueues<SpecializedSingleColumnSortCursor<ColumnType>>();
return true;
});
if (!result)
initializeQueues<SimpleSortCursor>();
}
else
{
initializeQueues<SortCursor>();
}
}
SortQueueVariants(const Block & header, const SortDescription & sort_description)
: SortQueueVariants(extractSortDescriptionTypesFromHeader(header, sort_description), sort_description)
{
}
template <typename Func>
decltype(auto) callOnVariant(Func && func)
{
return std::visit(func, default_queue_variants);
}
template <typename Func>
decltype(auto) callOnBatchVariant(Func && func)
{
return std::visit(func, batch_queue_variants);
}
bool variantSupportJITCompilation() const
{
return std::holds_alternative<SortingQueue<SimpleSortCursor>>(default_queue_variants)
|| std::holds_alternative<SortingQueue<SortCursor>>(default_queue_variants)
|| std::holds_alternative<SortingQueue<SortCursorWithCollation>>(default_queue_variants);
}
private:
template <typename Cursor>
void initializeQueues()
{
default_queue_variants = SortingQueue<Cursor>();
batch_queue_variants = SortingQueueBatch<Cursor>();
}
static DataTypes extractSortDescriptionTypesFromHeader(const Block & header, const SortDescription & sort_description)
{
size_t sort_description_size = sort_description.size();
DataTypes data_types(sort_description_size);
for (size_t i = 0; i < sort_description_size; ++i)
{
const auto & column_sort_description = sort_description[i];
data_types[i] = header.getByName(column_sort_description.column_name).type;
}
return data_types;
}
template <SortingQueueStrategy strategy>
using QueueVariants = std::variant<
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt8>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt16>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt32>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt64>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt128>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UInt256>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int8>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int16>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int32>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int64>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int128>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Int256>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Float32>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<Float64>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnDecimal<Decimal32>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnDecimal<Decimal64>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnDecimal<Decimal128>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnDecimal<Decimal256>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnDecimal<DateTime64>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnVector<UUID>>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnString>, strategy>,
SortingQueueImpl<SpecializedSingleColumnSortCursor<ColumnFixedString>, strategy>,
SortingQueueImpl<SimpleSortCursor, strategy>,
SortingQueueImpl<SortCursor, strategy>,
SortingQueueImpl<SortCursorWithCollation, strategy>>;
using DefaultQueueVariants = QueueVariants<SortingQueueStrategy::Default>;
using BatchQueueVariants = QueueVariants<SortingQueueStrategy::Batch>;
DefaultQueueVariants default_queue_variants;
BatchQueueVariants batch_queue_variants;
};
template <typename TLeftColumns, typename TRightColumns>
bool less(const TLeftColumns & lhs, const TRightColumns & rhs, size_t i, size_t j, const SortDescriptionWithPositions & descr)
{
for (const auto & elem : descr)
{
size_t ind = elem.column_number;
int res = elem.base.direction * lhs[ind]->compareAt(i, j, *rhs[ind], elem.base.nulls_direction);
if (res < 0)
return true;
else if (res > 0)
return false;
}
return false;
}
}