kgyrtkirk commented on a change in pull request #860: HIVE-22408 The fix for 
CALCITE-2991 creates wrong results on edge case
URL: https://github.com/apache/hive/pull/860#discussion_r356660051
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSortLimitRemoveRule.java
 ##########
 @@ -41,8 +42,17 @@ public boolean matches(RelOptRuleCall call) {
     final HiveSortLimit sortLimit = call.rel(0);
 
     Double maxRowCount = 
call.getMetadataQuery().getMaxRowCount(sortLimit.getInput());
-    if (maxRowCount != null &&(maxRowCount <= 1)) {
-      return true;
+    if (maxRowCount != null) {
+      if (sortLimit.getFetchExpr() != null) {
+        // we have LIMIT
+        int limit = RexLiteral.intValue(sortLimit.getFetchExpr());
+        if (maxRowCount <= limit) {
 
 Review comment:
   if I understand this correctly: this condition seems to be heavily building 
on that `MaxRowCount` is an overestimation of the actual rowcount - at any time 
that's not the case and it's an underestimation - we may end up removing the 
limit.
   
   Because of the above: I think it would make sense to add a toggle to 
consider the removal in these cases or not...

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to