[ 
https://issues.apache.org/jira/browse/HIVE-22408?focusedWorklogId=357906&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-357906
 ]

ASF GitHub Bot logged work on HIVE-22408:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/Dec/19 15:31
            Start Date: 11/Dec/19 15:31
    Worklog Time Spent: 10m 
      Work Description: kgyrtkirk commented on 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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 357906)
    Time Spent: 0.5h  (was: 20m)

> The fix for CALCITE-2991 creates wrong results on edge case
> -----------------------------------------------------------
>
>                 Key: HIVE-22408
>                 URL: https://issues.apache.org/jira/browse/HIVE-22408
>             Project: Hive
>          Issue Type: Bug
>          Components: CBO
>    Affects Versions: 3.1.2
>            Reporter: Steve Carlin
>            Assignee: Vineet Garg
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-22408.1.patch, HIVE-22408.2.patch, 
> HIVE-22408.3.patch, HIVE-22408.4.patch, HIVE-22408.5.patch, HIVE-22408.6.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The Calcite upgrade from 1.19 to 1.21 includes a fix for CALCITE-2991.  This 
> patch causes a failure in subquery_ALL.q
> In order to proceed with the upgrade, the patch was bypassed by creating the 
> HiveRelMdMaxRowCount class which overrides the behavior in Calcite.  
> In order to recreate the regression, remove this file and the references to 
> the class in HiveDefaultRelMetadataProvider.
> This Jira is being created before the HIVE-22274 PR has been pushed, so 
> please wait until that is pushed before working on this.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to