Update SQL in backfill script for facet tables to improve performance #2461
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The backfill script to populate the facet tables relies on some SQL that consistently times out on large Marquez installations. E.g., the initial lock query relies on ordering the
lineage_events
table, which takes more than 10 minutes (I don't know how long it actually takes because I stopped increasing the statement timeout at this point) just to determine that the installation is too large to apply the migration. Additionally, populating the facets takes more than 8 mins per batch, even when reducing the batch size from 10,000 to 1,000. In an installation of ~30M records, the migration at that rate will take multiple weeks to complete.Solution
The SQL changes here introduce a temp table that tracks the runs that need to be migrated and use that table to handle sorting the runs by time. Using the
run_uuid
allows us to take advantage of the index onlineage_events
so that fetching the events happens much faster. As there is typically two events per run, it effectively doubles the batch size. Using the default chunk size of 10,000, with an effective batch size of ~20,000, the query now completes in about 45 seconds.Checklist
CHANGELOG.md
(Depending on the change, this may not be necessary)..sql
database schema migration according to Flyway's naming convention (if relevant)