You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/05/01 19:12:37 UTC

[GitHub] [calcite] vineetgarg02 commented on a change in pull request #1941: [CALCITE-3952] Improve SortRemoveRule to remove Sort based on rowcount (Vineet Garg)

vineetgarg02 commented on a change in pull request #1941:
URL: https://github.com/apache/calcite/pull/1941#discussion_r418693129



##########
File path: core/src/main/java/org/apache/calcite/rel/rules/SortRemoveRule.java
##########
@@ -63,5 +83,27 @@ public SortRemoveRule(RelBuilderFactory relBuilderFactory) {
         .getTrait(RelCollationTraitDef.INSTANCE);
     final RelTraitSet traits = sort.getInput().getTraitSet().replace(collation);
     call.transformTo(convert(sort.getInput(), traits));
+    return true;
+  }
+
+  // Sort is removed if all of following conditions are met
+  // 1. Sort's input is guaranteed to produce at most one row
+  // 2. If fetch is greater than 0
+  // 3. If offset is less than 1
+  public static boolean shouldRemoveSortBasedOnRowCount(final RelMetadataQuery mq,
+      final RelNode input, int fetch, int offset) {
+    Double maxRowCount = mq.getMaxRowCount(input);
+    if (maxRowCount != null && maxRowCount <= 1) {
+      if (fetch == 0) {
+        return false;
+      } else if (fetch > 0) {
+        if (offset < 1) {
+          return true;
+        }
+      } else {
+        return true;

Review comment:
       I see that other databases like MySql, Hive etc do not allow OFFSET without LIMIT. But looks like Calcite does. I will add update the code to handle this case. Thanks @jinxing64 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org