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

perf(prune): Only analyze when rebuilding #5186

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

leoyvens
Copy link
Collaborator

@leoyvens leoyvens commented Feb 2, 2024

When pruning by delete, it's overzealous to analyze. When combined with auto-prune on large tables, I've seen shards struggle with one long analyze after the other.

It can also conflict with the lock for autovacuum and result in a long running transaction waiting for the lock.

@leoyvens leoyvens requested a review from lutter February 2, 2024 15:43
// Analyze the new tables
let tables = prunable_tables.iter().map(|(table, _)| *table).collect();
self.analyze_tables(conn, reporter, tables, cancel)?;

Copy link
Collaborator

Choose a reason for hiding this comment

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

With default settings, Delete will be used if we think we'll delete between 5% and 50% of the table, where the latter is a lot and statistics from before deletion will likely be junk. It would be better to analyze the tables in the Delete branch for which catalog::needs_autoanalyze says that an analyze is needed. That would basically cut out waiting for the autoanalyze daemon to get around to analyzing these tables.

@leoyvens
Copy link
Collaborator Author

leoyvens commented Feb 7, 2024

@lutter thanks for reviewing, I've tried another approach on the latest commit, given I've learned about the very convenient analyze skip_locked. This is a Postgres 12 feature, do we document our minimum Postgres? Postgres 11 has hit end-of-life already anyways.

Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

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

Nice! I really like this solution.

@lutter
Copy link
Collaborator

lutter commented Feb 7, 2024

@lutter thanks for reviewing, I've tried another approach on the latest commit, given I've learned about the very convenient analyze skip_locked. This is a Postgres 12 feature, do we document our minimum Postgres? Postgres 11 has hit end-of-life already anyways.

I don't think we have a minimum version documented, but not worrying about EOL versions seems reasonable to me.

When pruning by delete, it's overzealous to analyze. When combined
with auto-prune on large tables, I've seen shards struggle with one long
analyze after the other.

It can also conflict with the lock for autovacuum and result in a long
running transaction waiting for the lock.
@leoyvens leoyvens merged commit 76f26d4 into master Feb 8, 2024
7 checks passed
@leoyvens leoyvens deleted the leo/overanalyzed branch February 8, 2024 12:57
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.

2 participants