Create db indexing for upstream ref#1043
Conversation
✅ Deploy Preview for kpt-porch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
f3efe9b to
ec228d2
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds a persisted upstream_ref_name to package_revisions so upstream-reference lookups can use an indexed column instead of regex matching against tasks.
Changes:
- Add
upstream_ref_namecolumn and an index to support fast upstream reference lookups. - Populate
upstream_ref_nameon write/update and switchfindUpstreamRefsFromDBto query the new column. - Add a startup backfill to populate
upstream_ref_namefor existing rows.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cache/dbcache/dbpackagerevisionsql.go | Writes/updates the new column, replaces regex search with indexed lookup, and adds a backfill routine. |
| pkg/cache/dbcache/dbcachefactory.go | Runs the new upstream_ref_name backfill during cache initialization. |
| deployments/porch/3-porch-postgres-bundle.yaml | Updates bundled Postgres schema with the new column and index. |
| api/sql/porch-db.sql | Updates canonical schema with the new column and index. |
| api/sql/porch-db-1.6.0-1.5.9.sql | Alters downgrade migration behavior for the new column. |
| api/sql/porch-db-1.5.11-1.6.0.sql | Adds upgrade migration for the new column and related indexes. |
7394cf4 to
983adac
Compare
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
c6f5b72 to
6f3c16f
Compare
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
|
Signed-off-by: Kushal Harish Naidu <kushal.harish.naidu@ericsson.com>
|
Why does the backfill methods need to be broken down to multiple transactions? |
Copilot suggested it so that there won't be sudden spike at the start of the system pod when there are 1000s of entries which require an update. |



Title
Create db indexing for upstream ref, so that, looking up for references is quick.
Description
Why it’s needed: The previous findUpstreamRefsFromDB used a PostgreSQL regex operator (~) against the full tasks text column, which forces a sequential scan on every call — no index can accelerate regex matches over arbitrary JSON text. This query runs on every package revision delete to check for downstream references, so it becomes a bottleneck as the number of package revisions grows.
How it works:
On write/update, extractUpstreamRefName inspects the task list: for clone tasks it reads task.Clone.Upstream.UpstreamRef.Name, for upgrade tasks it reads task.Upgrade.NewUpstream.Name. The result is stored in upstream_ref_name.
Related Issue(s)
Type of Change
Checklist
Testing Instructions (Optional)
Additional Notes (Optional)
AI Disclosure
If so, please describe how:
Microsoft Copilot to analyse the code.
Kiro to generate unit tests and DB backfill code.