Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-5369 Annotate hive operator tree with statistics from metastore
  3. HIVE-7990

With fetch column stats disabled number of elements in grouping set is not taken into account

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.13.1
    • 0.14.0
    • Statistics
    • None

    Description

      For queries with rollup and cube the number of rows calculation in GroupByStatsRule should be multiplied by number of elements in grouping set.
      A side effect of this defect is that reducers will under estimate data size and end up with small number of tasks which negatively affects query runtime.

                  // since we do not know if hash-aggregation will be enabled or disabled
                  // at runtime we will assume that map-side group by does not do any
                  // reduction.hence no group by rule will be applied
      
                  // map-side grouping set present. if grouping set is present then
                  // multiply the number of rows by number of elements in grouping set
                  if (gop.getConf().isGroupingSetsPresent()) {
                    int multiplier = gop.getConf().getListGroupingSets().size();
      
                    // take into account the map-side parallelism as well, default is 1
                    multiplier *= mapSideParallelism;
                    newNumRows = multiplier * stats.getNumRows();
                    long dataSize = multiplier * stats.getDataSize();
                    stats.setNumRows(newNumRows);
                    stats.setDataSize(dataSize);
                    for (ColStatistics cs : colStats) {
                      if (cs != null) {
                        long oldNumNulls = cs.getNumNulls();
                        long newNumNulls = multiplier * oldNumNulls;
                        cs.setNumNulls(newNumNulls);
                      }
                    }
                  } else {
      
                    // map side no grouping set
                    newNumRows = stats.getNumRows() * mapSideParallelism;
                    updateStats(stats, newNumRows, true);
                  }
                
      

      Query

      select  *
      from (select i_category
                  ,i_class
                  ,i_brand
                  ,i_product_name
                  ,d_year
                  ,d_qoy
                  ,d_moy
                  ,s_store_id
                  ,sumsales
                  ,rank() over (partition by i_category order by sumsales desc) rk
            from (select i_category
                        ,i_class
                        ,i_brand
                        ,i_product_name
                        ,d_year
                        ,d_qoy
                        ,d_moy
                        ,s_store_id
                        ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales
                  from store_sales
                      ,date_dim
                      ,store
                      ,item
             where  store_sales.ss_sold_date_sk=date_dim.d_date_sk
                and store_sales.ss_item_sk=item.i_item_sk
                and store_sales.ss_store_sk = store.s_store_sk
                and d_month_seq between 1193 and 1193+11
                and ss_sold_date between '1999-06-01' and '2000-05-31'
             group by i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id with rollup)dw1) dw2
      where rk <= 100
      order by i_category
              ,i_class
              ,i_brand
              ,i_product_name
              ,d_year
              ,d_qoy
              ,d_moy
              ,s_store_id
              ,sumsales
              ,rk
      limit 100
      

      Plan generated , note the data size for Map 1

      STAGE DEPENDENCIES:
        Stage-1 is a root stage
        Stage-0 depends on stages: Stage-1
      
      STAGE PLANS:
        Stage: Stage-1
          Tez
            Edges:
              Map 1 <- Map 5 (BROADCAST_EDGE), Map 6 (BROADCAST_EDGE), Map 7 (BROADCAST_EDGE)
              Reducer 2 <- Map 1 (SIMPLE_EDGE)
              Reducer 3 <- Reducer 2 (SIMPLE_EDGE)
              Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
            DagName: mmokhtar_20140903154848_7cf1519f-e95c-47ab-9f10-6d2130cd5734:1
            Vertices:
              Map 1 
                  Map Operator Tree:
                      TableScan
                        alias: store_sales
                        filterExpr: (((ss_sold_date_sk is not null and ss_store_sk is not null) and ss_item_sk is not null) and ss_sold_date BETWEEN '1999-06-01' AND '2000-05-31') (type: boolean)
                        Statistics: Num rows: 110339135 Data size: 4817453454 Basic stats: COMPLETE Column stats: NONE
                        Filter Operator
                          predicate: ((ss_sold_date_sk is not null and ss_store_sk is not null) and ss_item_sk is not null) (type: boolean)
                          Statistics: Num rows: 13792392 Data size: 602181687 Basic stats: COMPLETE Column stats: NONE
                          Map Join Operator
                            condition map:
                                 Inner Join 0 to 1
                            condition expressions:
                              0 {ss_sold_date_sk} {ss_item_sk} {ss_store_sk} {ss_quantity} {ss_sales_price} {ss_sold_date}
                              1 {d_date_sk} {d_month_seq} {d_year} {d_moy} {d_qoy}
                            keys:
                              0 ss_sold_date_sk (type: int)
                              1 d_date_sk (type: int)
                            outputColumnNames: _col0, _col2, _col7, _col10, _col13, _col23, _col27, _col30, _col33, _col35, _col37
                            input vertices:
                              1 Map 6
                            Statistics: Num rows: 15171632 Data size: 662399872 Basic stats: COMPLETE Column stats: NONE
                            Map Join Operator
                              condition map:
                                   Inner Join 0 to 1
                              condition expressions:
                                0 {_col0} {_col2} {_col7} {_col10} {_col13} {_col23} {_col27} {_col30} {_col33} {_col35} {_col37}
                                1 {s_store_sk} {s_store_id}
                              keys:
                                0 _col7 (type: int)
                                1 s_store_sk (type: int)
                              outputColumnNames: _col0, _col2, _col7, _col10, _col13, _col23, _col27, _col30, _col33, _col35, _col37, _col58, _col59
                              input vertices:
                                1 Map 5
                              Statistics: Num rows: 16688796 Data size: 728639872 Basic stats: COMPLETE Column stats: NONE
                              Map Join Operator
                                condition map:
                                     Inner Join 0 to 1
                                condition expressions:
                                  0 {_col0} {_col2} {_col7} {_col10} {_col13} {_col23} {_col27} {_col30} {_col33} {_col35} {_col37} {_col58} {_col59}
                                  1 {i_item_sk} {i_brand} {i_class} {i_category} {i_product_name}
                                keys:
                                  0 _col2 (type: int)
                                  1 i_item_sk (type: int)
                                outputColumnNames: _col0, _col2, _col7, _col10, _col13, _col23, _col27, _col30, _col33, _col35, _col37, _col58, _col59, _col90, _col98, _col100, _col102, _col111
                                input vertices:
                                  1 Map 7
                                Statistics: Num rows: 18357676 Data size: 801503872 Basic stats: COMPLETE Column stats: NONE
                                Filter Operator
                                  predicate: (((((_col0 = _col27) and (_col2 = _col90)) and (_col7 = _col58)) and _col30 BETWEEN 1193 AND 1204) and _col23 BETWEEN '1999-06-01' AND '2000-05-31') (type: boolean)
                                  Statistics: Num rows: 573677 Data size: 25046979 Basic stats: COMPLETE Column stats: NONE
                                  Select Operator
                                    expressions: _col102 (type: string), _col100 (type: string), _col98 (type: string), _col111 (type: string), _col33 (type: int), _col37 (type: int), _col35 (type: int), _col59 (type: string), _col13 (type: float), _col10 (type: int)
                                    outputColumnNames: _col102, _col100, _col98, _col111, _col33, _col37, _col35, _col59, _col13, _col10
                                    Statistics: Num rows: 573677 Data size: 25046979 Basic stats: COMPLETE Column stats: NONE
                                    Group By Operator
                                      aggregations: sum(COALESCE((_col13 * _col10),0))
                                      keys: _col102 (type: string), _col100 (type: string), _col98 (type: string), _col111 (type: string), _col33 (type: int), _col37 (type: int), _col35 (type: int), _col59 (type: string), '0' (type: string)
                                      mode: hash
                                      outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                                      Statistics: Num rows: 573677 Data size: 25046979 Basic stats: COMPLETE Column stats: NONE
                                      Reduce Output Operator
                                        key expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col8 (type: string)
                                        sort order: +++++++++
                                        Map-reduce partition columns: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col8 (type: string)
                                        Statistics: Num rows: 573677 Data size: 25046979 Basic stats: COMPLETE Column stats: NONE
                                        value expressions: _col9 (type: double)
              Map 5 
                  Map Operator Tree:
                      TableScan
                        alias: store
                        filterExpr: s_store_sk is not null (type: boolean)
                        Statistics: Num rows: 212 Data size: 405680 Basic stats: COMPLETE Column stats: COMPLETE
                        Filter Operator
                          predicate: s_store_sk is not null (type: boolean)
                          Statistics: Num rows: 212 Data size: 22048 Basic stats: COMPLETE Column stats: COMPLETE
                          Reduce Output Operator
                            key expressions: s_store_sk (type: int)
                            sort order: +
                            Map-reduce partition columns: s_store_sk (type: int)
                            Statistics: Num rows: 212 Data size: 22048 Basic stats: COMPLETE Column stats: COMPLETE
                            value expressions: s_store_id (type: string)
                  Execution mode: vectorized
              Map 6 
                  Map Operator Tree:
                      TableScan
                        alias: date_dim
                        filterExpr: (d_date_sk is not null and d_month_seq BETWEEN 1193 AND 1204) (type: boolean)
                        Statistics: Num rows: 73049 Data size: 81741831 Basic stats: COMPLETE Column stats: COMPLETE
                        Filter Operator
                          predicate: (d_date_sk is not null and d_month_seq BETWEEN 1193 AND 1204) (type: boolean)
                          Statistics: Num rows: 36524 Data size: 730480 Basic stats: COMPLETE Column stats: COMPLETE
                          Reduce Output Operator
                            key expressions: d_date_sk (type: int)
                            sort order: +
                            Map-reduce partition columns: d_date_sk (type: int)
                            Statistics: Num rows: 36524 Data size: 730480 Basic stats: COMPLETE Column stats: COMPLETE
                            value expressions: d_month_seq (type: int), d_year (type: int), d_moy (type: int), d_qoy (type: int)
                  Execution mode: vectorized
              Map 7 
                  Map Operator Tree:
                      TableScan
                        alias: item
                        filterExpr: i_item_sk is not null (type: boolean)
                        Statistics: Num rows: 48000 Data size: 68732712 Basic stats: COMPLETE Column stats: COMPLETE
                        Filter Operator
                          predicate: i_item_sk is not null (type: boolean)
                          Statistics: Num rows: 48000 Data size: 18672000 Basic stats: COMPLETE Column stats: COMPLETE
                          Reduce Output Operator
                            key expressions: i_item_sk (type: int)
                            sort order: +
                            Map-reduce partition columns: i_item_sk (type: int)
                            Statistics: Num rows: 48000 Data size: 18672000 Basic stats: COMPLETE Column stats: COMPLETE
                            value expressions: i_brand (type: string), i_class (type: string), i_category (type: string), i_product_name (type: string)
                  Execution mode: vectorized
              Reducer 2 
                  Reduce Operator Tree:
                    Group By Operator
                      aggregations: sum(VALUE._col0)
                      keys: KEY._col0 (type: string), KEY._col1 (type: string), KEY._col2 (type: string), KEY._col3 (type: string), KEY._col4 (type: int), KEY._col5 (type: int), KEY._col6 (type: int), KEY._col7 (type: string), KEY._col8 (type: string)
                      mode: mergepartial
                      outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                      Statistics: Num rows: 286838 Data size: 12523467 Basic stats: COMPLETE Column stats: NONE
                      Select Operator
                        expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col9 (type: double)
                        outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8
                        Statistics: Num rows: 286838 Data size: 12523467 Basic stats: COMPLETE Column stats: NONE
                        Reduce Output Operator
                          key expressions: _col0 (type: string), _col8 (type: double)
                          sort order: +-
                          Map-reduce partition columns: _col0 (type: string)
                          Statistics: Num rows: 286838 Data size: 12523467 Basic stats: COMPLETE Column stats: NONE
                          TopN Hash Memory Usage: 0.04
                          value expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col8 (type: double)
              Reducer 3 
                  Reduce Operator Tree:
                    Extract
                      Statistics: Num rows: 286838 Data size: 12523467 Basic stats: COMPLETE Column stats: NONE
                      PTF Operator
                        Statistics: Num rows: 286838 Data size: 12523467 Basic stats: COMPLETE Column stats: NONE
                        Filter Operator
                          predicate: (_wcol0 <= 100) (type: boolean)
                          Statistics: Num rows: 95612 Data size: 4174459 Basic stats: COMPLETE Column stats: NONE
                          Select Operator
                            expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col8 (type: double), _wcol0 (type: int)
                            outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                            Statistics: Num rows: 95612 Data size: 4174459 Basic stats: COMPLETE Column stats: NONE
                            Reduce Output Operator
                              key expressions: _col0 (type: string), _col1 (type: string), _col2 (type: string), _col3 (type: string), _col4 (type: int), _col5 (type: int), _col6 (type: int), _col7 (type: string), _col8 (type: double), _col9 (type: int)
                              sort order: ++++++++++
                              Statistics: Num rows: 95612 Data size: 4174459 Basic stats: COMPLETE Column stats: NONE
                              TopN Hash Memory Usage: 0.04
              Reducer 4 
                  Reduce Operator Tree:
                    Select Operator
                      expressions: KEY.reducesinkkey0 (type: string), KEY.reducesinkkey1 (type: string), KEY.reducesinkkey2 (type: string), KEY.reducesinkkey3 (type: string), KEY.reducesinkkey4 (type: int), KEY.reducesinkkey5 (type: int), KEY.reducesinkkey6 (type: int), KEY.reducesinkkey7 (type: string), KEY.reducesinkkey8 (type: double), KEY.reducesinkkey9 (type: int)
                      outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6, _col7, _col8, _col9
                      Statistics: Num rows: 95612 Data size: 4174459 Basic stats: COMPLETE Column stats: NONE
                      Limit
                        Number of rows: 100
                        Statistics: Num rows: 100 Data size: 4300 Basic stats: COMPLETE Column stats: NONE
                        File Output Operator
                          compressed: false
                          Statistics: Num rows: 100 Data size: 4300 Basic stats: COMPLETE Column stats: NONE
                          table:
                              input format: org.apache.hadoop.mapred.TextInputFormat
                              output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                              serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
                  Execution mode: vectorized
      
        Stage: Stage-0
          Fetch Operator
            limit: 100
            Processor Tree:
              ListSink
      

      Attachments

        1. HIVE-7990.3.patch
          60 kB
          Prasanth Jayachandran
        2. HIVE-7990.2.patch
          53 kB
          Prasanth Jayachandran
        3. HIVE-7990.1.patch
          52 kB
          Prasanth Jayachandran

        Issue Links

          Activity

            People

              prasanth_j Prasanth Jayachandran
              mmokhtar Mostafa Mokhtar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: