AMashenkov commented on code in PR #1629:
URL: https://github.com/apache/ignite-3/pull/1629#discussion_r1114797387
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/rel/SortNode.java:
##########
@@ -38,16 +43,45 @@
/** Rows buffer. */
private final PriorityQueue<RowT> rows;
+ /** SQL select limit. Negative if disabled. */
+ private final int limit;
+
+ /** Reverse-ordered rows in case of limited sort. */
+ private List<RowT> reversed;
+
/**
* Constructor.
*
- * @param ctx Execution context.
+ * @param ctx Execution context.
* @param comp Rows comparator.
+ * @param offset Offset.
+ * @param fetch Limit.
*/
- public SortNode(ExecutionContext<RowT> ctx, Comparator<RowT> comp) {
+ public SortNode(ExecutionContext<RowT> ctx,
+ Comparator<RowT> comp,
+ @Nullable Supplier<Integer> offset,
+ @Nullable Supplier<Integer> fetch) {
super(ctx);
+ assert fetch == null || fetch.get() >= 0;
+ assert offset == null || offset.get() >= 0;
- rows = comp == null ? new PriorityQueue<>() : new
PriorityQueue<>(comp);
+ limit = fetch == null ? -1 : fetch.get() + (offset == null ? 0 :
offset.get());
+
+ if (limit < 1) {
+ rows = new PriorityQueue<>(comp);
+ } else {
+ rows = new BoundedPriorityQueue<>(limit, comp == null ?
(Comparator<RowT>) Comparator.reverseOrder() : comp.reversed());
Review Comment:
Maybe we can use reverse order in both cases? or it will be less effective?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]