Fix slow /api/v1/jobs endpoint by optimizing RunDao queries#3091
Open
jni-bot wants to merge 1 commit intoMarquezProject:mainfrom
Open
Fix slow /api/v1/jobs endpoint by optimizing RunDao queries#3091jni-bot wants to merge 1 commit intoMarquezProject:mainfrom
jni-bot wants to merge 1 commit intoMarquezProject:mainfrom
Conversation
…roject#2987) The findByLatestJob query was scanning millions of rows in run_facets and dataset_facets by joining runs_view with jobs_view in the WHERE clause. This caused 7+ minute query times per job, making the jobs list page unusable at scale. Two changes: - Add findCurrentRunByJob using jobs.current_run_uuid (from MarquezProject#2929) for the jobs list page, reducing it to a single indexed UUID lookup - Optimize findByLatestJob to filter on runs.job_uuid (indexed) with symlink resolution, instead of the expensive runs_view/jobs_view join Closes MarquezProject#2987 Signed-off-by: jni-bot <jni-bot@users.noreply.github.com>
|
Thanks for opening your first pull request in the Marquez project! Please check out our contributing guidelines (https://github.com/MarquezProject/marquez/blob/main/CONTRIBUTING.md). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3091 +/- ##
=========================================
Coverage 81.18% 81.18%
Complexity 1506 1506
=========================================
Files 268 268
Lines 7356 7356
Branches 325 325
=========================================
Hits 5972 5972
Misses 1226 1226
Partials 158 158 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2987 — the
/api/v1/jobsendpoint takes 7+ minutes per job at scale due to an unoptimized query inRunDao.findByLatestJob.The root cause: the
findByLatestJobWHERE clause joinsruns_viewwithjobs_viewto find matching run UUIDs. This forces PostgreSQL to build the fullruns_view(~2.3M rows) and scan the entirerun_facetstable (~21M rows) anddataset_facetstable (~22GB) in the LEFT JOIN subqueries before filtering — even though only 1-10 runs are needed.Changes
RunDao.java:findCurrentRunByJobmethod — usesjobs.current_run_uuid(added in Add colcurrent_run_uuidtojobs#2929 but never leveraged here) for a direct indexed UUID lookup. Returns only the single latest run.findByLatestJobmethod — replaces theruns_view JOIN jobs_viewWHERE clause with a filter onruns.job_uuidwhich hits the existing composite indexruns_job_uuid ON runs(job_uuid, transitioned_at DESC). Includes symlink resolution for aliased jobs.JobDao.java:findAllWithRun(jobs list page) now callsfindCurrentRunByJobwithlimit=1instead offindByLatestJobwithlimit=10. This is the hot path — called once per job on every list page load.Why this works
runs_view⨝jobs_viewscan → 7 mincurrent_run_uuidindexed lookup → msruns_view⨝jobs_viewscan → 7 minjob_uuidcomposite index scan → secondsTest plan
RunDaoTest.testFindByLatestJob— passes (validates symlink resolution)RunDaoTestfull suite — all 6 tests passJobDaoTestfull suite — all 8 tests passspotlessApply— clean