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

feat: caching optd stats, 12x speedup on TPC-H SF1 #132

Merged
merged 16 commits into from
Mar 24, 2024

Conversation

wangpatrick57
Copy link
Member

@wangpatrick57 wangpatrick57 commented Mar 23, 2024

Summary: Now caching the stat objects used by OptCostModel, meaning we don't need to load data into DataFusion after doing it the first time.

Demo:
12x speedup on TPC-H SF1 compared to not caching stats.

Caching everything except optd stats takes 45.6s total.
Screenshot 2024-03-23 at 16 59 04

Caching everything, including optd stats, takes 3.9s total.
Screenshot 2024-03-23 at 16 57 45

Details:

  • This caching is disabled by default to avoid accidentally using stale stats. I added a CLI arg to enable it.
  • The main challenge of this PR was making PerTableStats a serializable object for serde.
  • The serializability refactor will also help down the line when we want to put statistics in the catalog, since that is fundamentally a serialization problem too. Having Box<dyn ...> would make putting stats in the catalog more difficult.
  • This required a significant refactor of how the MostCommonValues and Distribution traits are handled in OptCostModel. Instead of having Box<dyn ...> values in PerColumnStats which store any object that implements these traits, I made PerColumnStats a templated object.
  • The one downside of this refactor is that we can no longer have a database which uses different data structures for Distribution (like a t-digest for one column, a histogram for another, etc.). I didn't see this as a big enough reason to not do the refactor because it seems like a rare thing to do. Additionally, if we really needed to do this, we could just make an enum that had both types.

@wangpatrick57 wangpatrick57 changed the title feat: caching optd stats feat: caching optd stats, 12x speedup on TPC-H SF1 Mar 23, 2024
@wangpatrick57 wangpatrick57 marked this pull request as ready for review March 23, 2024 21:00
@@ -37,6 +37,17 @@ impl Benchmark {
dbname.to_lowercase()
}

/// Use this when you need a file name. The rules for file names are different from the rules
/// for database names, so this is a different function
pub fn get_fname(&self) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

More generally, it can be unique name

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, wdym?

Copy link
Contributor

@Gun9niR Gun9niR Mar 24, 2024

Choose a reason for hiding this comment

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

I mean it doesn't have to be a file name. The function's name is a bit confusing, like: file for what? But actually it's just a unique name that can be used as a file name

Copy link
Contributor

@Gun9niR Gun9niR left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@wangpatrick57 wangpatrick57 merged commit 204758e into main Mar 24, 2024
1 check passed
@wangpatrick57 wangpatrick57 deleted the phw2/df-stat-cache branch March 24, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants