Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Use a specialized sum accumulator for retractable aggregregates #6888

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jul 8, 2023

Which issue does this PR close?

Closes #6878

Rationale for this change

I noticed this while working on #4973

The SUM accumulator is general (it can handle sliding windows) but to be general it carries through an extra count for each group in the "state" -- this count is ignored. For low cardinality groups this likely isn't a problem but for large cardinality groups creating and carrying through the counts takes a measurable amount of time (I saw it in #6800)

What changes are included in this PR?

Use a specialized sum accumulator for retractable windows and only track the counts there. For non

Are these changes tested?

Existing coverage

Performance (the bigger changes like q15 have a sum` in them, so the change is plausible). The smaller changes don't have any sums which makes me suspicious

┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃ main_base ┃ alamb_sliding_sum ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1     │  493.94ms │          482.97ms │     no change │
│ QQuery 2     │  234.61ms │          224.64ms │     no change │
│ QQuery 3     │  166.23ms │          164.85ms │     no change │
│ QQuery 4     │  117.63ms │          113.72ms │     no change │
│ QQuery 5     │  357.76ms │          361.91ms │     no change │
│ QQuery 6     │   38.66ms │           38.06ms │     no change │
│ QQuery 7     │  834.50ms │          845.64ms │     no change │
│ QQuery 8     │  227.74ms │          232.79ms │     no change │
│ QQuery 9     │  522.91ms │          496.78ms │     no change │
│ QQuery 10    │  321.29ms │          313.16ms │     no change │
│ QQuery 11    │  178.21ms │          184.38ms │     no change │
│ QQuery 12    │  159.24ms │          155.57ms │     no change │
│ QQuery 13    │  516.62ms │          487.68ms │ +1.06x faster │
│ QQuery 14    │   48.16ms │           45.60ms │ +1.06x faster │
│ QQuery 15    │   92.66ms │           81.38ms │ +1.14x faster │
│ QQuery 16    │  206.11ms │          193.74ms │ +1.06x faster │
│ QQuery 17    │ 2336.67ms │         2271.10ms │     no change │
│ QQuery 18    │ 2296.14ms │         2242.11ms │     no change │
│ QQuery 19    │  155.26ms │          151.59ms │     no change │
│ QQuery 20    │  770.76ms │          683.80ms │ +1.13x faster │
│ QQuery 21    │ 1078.71ms │         1009.40ms │ +1.07x faster │
│ QQuery 22    │   84.39ms │           88.77ms │  1.05x slower │
└──────────────┴───────────┴───────────────────┴───────────────┘

Are there any user-facing changes?

a little faster performance. I really expect this to help the code in #6800 so I can simplify the sum accumulator

@github-actions github-actions bot added the physical-expr Physical Expressions label Jul 8, 2023
self.data_type.clone(),
self.nullable,
),
Field::new(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of the PR is to remove this "count" field

@@ -146,7 +139,7 @@ impl AggregateExpr for Sum {
}

fn create_sliding_accumulator(&self) -> Result<Box<dyn Accumulator>> {
Ok(Box::new(SumAccumulator::try_new(&self.data_type)?))
Ok(Box::new(SlidingSumAccumulator::try_new(&self.data_type)?))
Copy link
Contributor Author

@alamb alamb Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Dandandan Dandandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@alamb alamb marked this pull request as ready for review July 8, 2023 15:34
@Dandandan Dandandan merged commit aabd7ad into apache:main Jul 9, 2023
@alamb alamb deleted the alamb/sliding_sum branch July 9, 2023 10:28
@alamb
Copy link
Contributor Author

alamb commented Jul 9, 2023

FYI @mustafasrepo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance of the SUM accumulator
2 participants