Skip to content

Investigate performance drop for DISTINCT queries #5313

Closed

Description

@comphead

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
ClickBench reported a performance drop for COUNT(DISTINCT) computation #5276 (comment)

Describe the solution you'd like
Its needed to investigate a performance drop root cause in DISTINCT queries and find out how is it possible to increase the speed.

Describe alternatives you've considered
Not doing this

Additional context
Metrics can be found #5276 (comment)
Reproduce the case #5276 (comment)

Activity

  1. comphead commented on Feb 17, 2023

    @comphead
    ContributorAuthor

    df-distinct-graph
    Adding Flamegraph profiler for query
    SELECT COUNT(*) AS c, COUNT(DISTINCT "UserID") FROM hits GROUP BY "RegionID" LIMIT 10;

  2. Dandandan commented on Feb 17, 2023

    @Dandandan
    Contributor

    So here we have the answer - it's very inefficient because of inefficiently tracking memory (which was added some versions ago). FYI @alamb

  3. alamb commented on Feb 17, 2023

    @alamb
    Contributor

    So here we have the answer - it's very inefficient because of inefficiently tracking memory (which was added some versions ago). FYI @alamb

    Nice sluthing -- thank you @comphead and @Dandandan - - I can file a ticket for the regression related to tracking memory if that would help

  4. comphead commented on Feb 17, 2023

    @comphead
    ContributorAuthor

    so yeah, size function needed to calc additional number of bytes that were allocated during aggregate_batch process.
    I have commented this out and the same query runs 4 sec instead of 100sec.

    @Dandandan @alamb I'll file a ticket to optimize this part

  5. changed the title [-]Improve performance for DISTINCT queries[/-] [+]Investigate performance drop for DISTINCT queries[/+] on Feb 17, 2023
  6. Dandandan commented on Feb 17, 2023

    @Dandandan
    Contributor

    so yeah, size function needed to calc additional number of bytes that were allocated during aggregate_batch process. I have commented this out and the same query runs 4 sec instead of 100sec.

    @Dandandan @alamb I'll file a ticket to optimize this part

    Yes, some quadratic complexity because of the growing state.

  7. Dandandan commented on Feb 17, 2023

    @Dandandan
    Contributor

    (you could identify it from your flamegraph, it's just the longest bar(s) at the top consuming all the time)

  8. comphead commented on Feb 17, 2023

    @comphead
    ContributorAuthor

    Right, the function was evident to identify, but it was introduced recently, took some time to figure out its purpose.

  9. comphead commented on Feb 17, 2023

    @comphead
    ContributorAuthor

    Filed #5325

    @Dandandan @alamb should we close this ticket?

  10. alamb commented on Feb 18, 2023

    @alamb
    Contributor

    I agree the analysis is done -- thank you @comphead

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