hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-21338) Remove order by and limit for aggregates
Date Wed, 06 Mar 2019 06:01:03 GMT

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

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

                Author: ASF GitHub Bot
            Created on: 06/Mar/19 06:00
            Start Date: 06/Mar/19 06:00
    Worklog Time Spent: 10m 
      Work Description: jcamachor commented on pull request #557: HIVE-21338 Remove order
by and limit for aggregates
URL: https://github.com/apache/hive/pull/557#discussion_r262800893
 
 

 ##########
 File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSortLimitRemoveRule.java
 ##########
 @@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelOptUtil;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit;
+
+/**
+ * Planner rule that removes
+ * a {@link org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit}.
+ * Note that this is different from HiveSortRemoveRule because this is not based on statistics
+ */
+public class HiveSortLimitRemoveRule extends RelOptRule {
+
+  //~ Constructors -----------------------------------------------------------
+
+  public HiveSortLimitRemoveRule() {
+    this(operand(HiveSortLimit.class, any()));
+  }
+
+  private HiveSortLimitRemoveRule(RelOptRuleOperand operand) {
+    super(operand);
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override
+  public boolean matches(RelOptRuleCall call) {
+    final HiveSortLimit sortLimit = call.rel(0);
+
+    return HiveRelOptUtil.produceAtmostOneRow(sortLimit.getInput());
 
 Review comment:
   The rules should be portable between planners, i.e., a rule should not be unwrapping a
HepRelVertex. If you want to remain generic, a workaround is matching RelNode. However, I
would try to make the rule matchers as restrictive as possible, since the more information
we expose to the planner, the smarter decisions it can make, e.g., avoiding unnecessary triggering
of rules.
   You do not need recursion. When the rule is executed, we should not have multiple consecutive
Project operators in the plan. If there were, we would get rid of them using ProjectMerge
and ProjectRemove rules.
 
----------------------------------------------------------------
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


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

    Worklog Id:     (was: 208435)
    Time Spent: 1h 10m  (was: 1h)

> Remove order by and limit for aggregates
> ----------------------------------------
>
>                 Key: HIVE-21338
>                 URL: https://issues.apache.org/jira/browse/HIVE-21338
>             Project: Hive
>          Issue Type: Improvement
>          Components: Query Planning
>            Reporter: Vineet Garg
>            Assignee: Vineet Garg
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: HIVE-21338.1.patch, HIVE-21338.2.patch, HIVE-21338.3.patch, HIVE-21338.4.patch
>
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> If a query is guaranteed to produce at most one row LIMIT and ORDER BY could be removed.
This saves unnecessary vertex for LIMIT/ORDER BY.
> {code:sql}
> explain select count(*) cs from store_sales where ss_ext_sales_price > 100.00 order
by cs limit 100
> {code}
> {code}
> STAGE PLANS:
>   Stage: Stage-1
>     Tez
>       DagId: vgarg_20190227131959_2914830f-eab6-425d-b9f0-b8cb56f8a1e9:4
>       Edges:
>         Reducer 2 <- Map 1 (CUSTOM_SIMPLE_EDGE)
>         Reducer 3 <- Reducer 2 (SIMPLE_EDGE)
>       DagName: vgarg_20190227131959_2914830f-eab6-425d-b9f0-b8cb56f8a1e9:4
>       Vertices:
>         Map 1
>             Map Operator Tree:
>                 TableScan
>                   alias: store_sales
>                   filterExpr: (ss_ext_sales_price > 100) (type: boolean)
>                   Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column
stats: NONE
>                   Filter Operator
>                     predicate: (ss_ext_sales_price > 100) (type: boolean)
>                     Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column
stats: NONE
>                     Select Operator
>                       Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE Column
stats: NONE
>                       Group By Operator
>                         aggregations: count()
>                         mode: hash
>                         outputColumnNames: _col0
>                         Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE
Column stats: NONE
>                         Reduce Output Operator
>                           sort order:
>                           Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE
Column stats: NONE
>                           value expressions: _col0 (type: bigint)
>             Execution mode: vectorized
>         Reducer 2
>             Execution mode: vectorized
>             Reduce Operator Tree:
>               Group By Operator
>                 aggregations: count(VALUE._col0)
>                 mode: mergepartial
>                 outputColumnNames: _col0
>                 Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE Column stats:
NONE
>                 Reduce Output Operator
>                   key expressions: _col0 (type: bigint)
>                   sort order: +
>                   Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE Column
stats: NONE
>                   TopN Hash Memory Usage: 0.1
>         Reducer 3
>             Execution mode: vectorized
>             Reduce Operator Tree:
>               Select Operator
>                 expressions: KEY.reducesinkkey0 (type: bigint)
>                 outputColumnNames: _col0
>                 Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE Column stats:
NONE
>                 Limit
>                   Number of rows: 100
>                   Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE Column
stats: NONE
>                   File Output Operator
>                     compressed: false
>                     Statistics: Num rows: 1 Data size: 120 Basic stats: COMPLETE Column
stats: NONE
>                     table:
>                         input format: org.apache.hadoop.mapred.SequenceFileInputFormat
>                         output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
>                         serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
>   Stage: Stage-0
>     Fetch Operator
>       limit: 100
>       Processor Tree:
>         ListSink
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message