Skip to content

Sampled partition stats have greatly underestimated NDVs for some columns #50

Open

Description

@sopel39

Incorporated from: prestodb/presto#11959 (discussion there)

tpch_sf100. orders (partitioned):

presto> show stats for hive.tpch_sf100_orc_part.orders;
  column_name  |      data_size      | distinct_values_count | nulls_fraction |   row_count    | low_value  | high_value
---------------+---------------------+-----------------------+----------------+----------------+------------+------------
 orderkey      | NULL                |               62881.0 |            0.0 | NULL           | 162        | 599999942
 custkey       | NULL                |               62881.0 |            0.0 | NULL           | 2          | 14999998
 orderstatus   |      1.4999663244E8 |                   3.0 |            0.0 | NULL           | NULL       | NULL
 totalprice    | NULL                |               62881.0 |            0.0 | NULL           | 851.17     | 571417.48
 orderpriority |     1.25999070546E9 |                   5.0 |            0.0 | NULL           | NULL       | NULL
 clerk         |      2.2499494866E9 |               49276.0 |            0.0 | NULL           | NULL       | NULL
 shippriority  | NULL                |                   1.0 |            0.0 | NULL           | 0          | 0
 comment       | 7.275173681759999E9 |               62881.0 |            0.0 | NULL           | NULL       | NULL
 orderdate     | NULL                |                2406.0 |            0.0 | NULL           | 1992-01-01 | 1998-08-02
 NULL          | NULL                | NULL                  | NULL           | 1.4999663244E8 | NULL       | NULL
(10 rows)
presto> show stats for hive.tpch_sf100_orc.orders;
  column_name  |      data_size       | distinct_values_count | nulls_fraction | row_count | low_value  | high_value
---------------+----------------------+-----------------------+----------------+-----------+------------+------------
 orderkey      | NULL                 |                 1.5E8 |            0.0 | NULL      | 1          | 600000000
 custkey       | NULL                 |           1.0165457E7 |            0.0 | NULL      | 1          | 14999999
 orderstatus   |                1.5E8 |                   3.0 |            0.0 | NULL      | NULL       | NULL
 totalprice    | NULL                 |           3.4038282E7 |            0.0 | NULL      | 811.73     | 591036.15
 orderdate     | NULL                 |                2449.0 |            0.0 | NULL      | 1992-01-01 | 1998-08-02
 orderpriority | 1.2600248040000002E9 |                   5.0 |            0.0 | NULL      | NULL       | NULL
 clerk         |               2.25E9 |              100816.0 |            0.0 | NULL      | NULL       | NULL
 shippriority  | NULL                 |                   1.0 |            0.0 | NULL      | 0          | 0
 comment       |        7.275038709E9 |          1.12463191E8 |            0.0 | NULL      | NULL       | NULL
 NULL          | NULL                 | NULL                  | NULL           |     1.5E8 | NULL       | NULL

Should we add extrapolate NDVs instead? It seems that partitions might often be different chunks of data so that NDVs don't overlap.
Alternatively we could store HLL state per column as an auxiliary partition property and calculate extrapolation based on merged HLLs

Activity

  1. arhimondr commented on Jan 25, 2019

    @arhimondr
    Contributor

    Should we add extrapolate NDVs instead?

    Currently we chose the maximum NDV. If we decided to sum NDV's then we would need to extrapolate.

    It seems that partitions might often be different chunks of data so that NDVs don't overlap.

    It depends for what column, and what type of partitions. For daily rolling partitions NDV will be likely overlapping.

    Alternatively we could store HLL state per column as an auxiliary partition property and calculate extrapolation based on merged HLLs

    I think that's the only options we have. In order to do so - we need to store HLL states per columns in the partition properties, as the Mestastore API doesn't allow you to store arbitrary statistics.

  2. arhimondr commented on Jan 25, 2019

    @arhimondr
    Contributor

    @findepi I'm not sure if we should call it a "bug". The decision of taking MAX NDV was a thoughtful decision. Let's change the label to "enhancment".

  3. added
    enhancementNew feature or request
    and removed on Jan 25, 2019
  4. sopel39 commented on Jan 25, 2019

    @sopel39
    MemberAuthor

    I think that's the only options we have. In order to do so - we need to store HLL states per columns in the partition properties, as the Mestastore API doesn't allow you to store arbitrary statistics.

    We could store HLL in table/partition properties

  5. sopel39 commented on Jan 25, 2019

    @sopel39
    MemberAuthor

    It depends for what column, and what type of partitions. For daily rolling partitions NDV will be likely overlapping.

    Yup. Discussion from original issue: let's say you partition by date and you have two data columns:

    • userId
    • eventId

    Then for 1) you should rather take max (users come from the same id pool), even though userId NDV could be approximate the same as partition row count
    For 2) you should sum because each eventId is unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions