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

Optimize sqlite-to-postgres migration speed for large tables via temporary constraint suspension #1824

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

eth3lbert
Copy link
Contributor

@eth3lbert eth3lbert commented Feb 26, 2024

This PR introduces an optimization to improve the migration speed from SQLite to PostgreSQL for large tables. It temporarily disables constraints during the migration process by dropping constraints before copying data and adding them back afterwards, allowing for faster data transfer.

Previously Optimization
pstat ≈ 1289s 234.54s
Copied 87437248 rows from pstat table in 1289.337736334s (67816 rows/second) Drop constraints for table pstat in 6.66825ms
Copied 87437248 rows from pstat table in 147.218779125s (593927 rows/second)
Add constraints for table pstat in 87.332639042s
raw_self_profile ≈ 46s 14.05s
Copied 3677103 rows from raw_self_profile table in 46.025009083s (79894 rows/second) Drop constraints for table raw_self_profile in 1.851375ms
Copied 3677103 rows from raw_self_profile table in 7.032711416s (522857 rows/second)
Add constraints for table raw_self_profile in 7.020468166s

Note: This approach prioritizes speed over data integrity. However, since we are migrating from an existing database, the risk of compromising data integrity is likely minimal in this specific case.

@eth3lbert
Copy link
Contributor Author

eth3lbert commented Feb 27, 2024

typo fixed and feedback addressed.

Disabled table triggers
Copied 8879 rows from artifact table in 31.013791ms (286292 rows/second)
Copied 6909 rows from artifact_collection_duration table in 21.010667ms (328833 rows/second)
Copied 74 rows from benchmark table in 599.708µs (123393 rows/second)
Copied 11240494 rows from collection table in 19.367619292s (580376 rows/second)
Copied 308525 rows from collector_progress table in 1.909368375s (161585 rows/second)
Copied 2550 rows from error table in 1.433280209s (1779 rows/second)
Copied 9398 rows from pstat_series table in 56.046292ms (167683 rows/second)
Copied 87437248 rows from pstat table in 189.191683833s (462162 rows/second)
Copied 4332 rows from pull_request_build table in 27.5315ms (157347 rows/second)
Copied 3677103 rows from raw_self_profile table in 12.662463167s (290394 rows/second)
Copied 1175371 rows from rustc_compilation table in 3.671286584s (320152 rows/second)
Enabled table triggers

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Nice perf. boost :) Thank you!

@Kobzol Kobzol enabled auto-merge February 27, 2024 08:03
@Kobzol Kobzol merged commit 8aa3c08 into rust-lang:master Feb 27, 2024
11 checks passed
@eth3lbert eth3lbert deleted the speedup-sqlite2pg branch February 27, 2024 14:08
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