Skip to content

group by high cardinality column in datafusion 10 times slower than low cardinality column #1246

Closed

Description

@jiangzhx

Describe the bug
group by high cardinality column in datafusion 10 times slower than low cardinality column.
also i tested on other olap engine, there are only 2 times slow or less;

  • trino olap engine write by java

    low cardinality  usage ms: 1400ms±
    high cardinality  usage ms: 2700ms±
    
  • doris olap engine write by c++

    low cardinality  usage ms: 350ms±
    high cardinality  usage ms: 500ms±
    

To Reproduce
Steps to reproduce the behavior:
parquet table with 60,000,000 rows; data generate by ssb-dbgen

group by LO_ORDERPRIORITY

SELECT sum(LO_EXTENDEDPRICE) AS revenue  FROM lineorder_flat group by LO_ORDERPRIORITY;
5 rows in set. Query took 0.341 seconds.

group by S_ADDRESS

SELECT sum(LO_EXTENDEDPRICE) AS revenue  FROM lineorder_flat group by S_ADDRESS;
20000 rows in set. Query took 2.582 seconds.

Expected behavior
should some with other engine;

Additional context
Add any other context about the problem here.

Activity

  1. xudong963 commented on Nov 5, 2021

    @xudong963
    Member

    If I recall correctly, datafusion doesn't do fine optimization about group by and aggregate functions at present. Datafusion as an AP system, It's worth adding to our RoadMap and doing it in the future.

  2. jiangzhx commented on Nov 5, 2021

    @jiangzhx
    ContributorAuthor

    If I recall correctly, datafusion doesn't do fine optimization about group by and aggregate functions at present. It's worth adding it to our RoadMap and doing it in the future.

    i try to dig code in trino and doris; there are all have streaming aggregate node; but i can't understand how they working.

    aggregate functions was working fine; with sum(LO_EXTENDEDPRICE) or without; the performence has no big difference,there are also have 5~10 times slow;

    low cardinality:

    select 1  FROM lineorder_flat group by LO_ORDERPRIORITY;
    5 rows in set. Query took 0.236 seconds.
    

    high cardinality:

    select 1  FROM lineorder_flat group by S_ADDRESS;
    20000 rows in set. Query took 1.429 seconds.
    
  3. xudong963 commented on Nov 5, 2021

    @xudong963
    Member

    I'll take a look at Doris on the weekend. Until then, we can wait for someone else to answer your questions. Thanks for your comparison @jiangzhx

  4. Dandandan commented on Nov 5, 2021

    @Dandandan
    Contributor

    Some relevant tickets:

    #418
    #956

  5. reopened this on Nov 5, 2021
  6. alamb commented on Nov 5, 2021

    @alamb
    Contributor

    Accidentally closed

  7. alamb commented on Nov 5, 2021

    @alamb
    Contributor

    I think there is a lot of overhead creating and managing group keys via ScalarValues that is a good thing to look into if we want to optimize the performance here

  8. alamb commented on Jun 25, 2023

    @alamb
    Contributor

    Related PR: #6657

  9. alamb commented on Jun 27, 2023

    @alamb
    Contributor

    see #4973 (comment) for proposal

  10. alamb commented on Jul 13, 2023

    @alamb
    Contributor

    This should be closed by #6904

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions