From 546548409a23629319695ac5dba00558173b7225 Mon Sep 17 00:00:00 2001 From: Bhupesh Varshney Date: Tue, 6 Oct 2026 18:22:34 +0530 Subject: [PATCH 1/2] feat: add artifact_id indexes on release_tags and image_comments --- ...4600_add_artifact_tagging_indexes.down.sql | 4 +++ ...404600_add_artifact_tagging_indexes.up.sql | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 scripts/sql/37404600_add_artifact_tagging_indexes.down.sql create mode 100644 scripts/sql/37404600_add_artifact_tagging_indexes.up.sql diff --git a/scripts/sql/37404600_add_artifact_tagging_indexes.down.sql b/scripts/sql/37404600_add_artifact_tagging_indexes.down.sql new file mode 100644 index 0000000000..43689bf9d7 --- /dev/null +++ b/scripts/sql/37404600_add_artifact_tagging_indexes.down.sql @@ -0,0 +1,4 @@ +-- Rollback: drop indexes added by 37004600_add_artifact_tagging_indexes.up.sql + +DROP INDEX IF EXISTS idx_release_tags_artifact_id; +DROP INDEX IF EXISTS idx_image_comments_artifact_id; diff --git a/scripts/sql/37404600_add_artifact_tagging_indexes.up.sql b/scripts/sql/37404600_add_artifact_tagging_indexes.up.sql new file mode 100644 index 0000000000..18d73c9d55 --- /dev/null +++ b/scripts/sql/37404600_add_artifact_tagging_indexes.up.sql @@ -0,0 +1,31 @@ +-- WS-G: add indexes for unindexed artifact_id lookups on release_tags/image_comments +-- to eliminate sequential scans on the following user-facing hot paths: +-- * ImageTaggingRepositoryImpl.GetTagsByArtifactId +-- (internal/sql/repository/imageTagging/ImageTaggingRepository.go) +-- — called from ImageTaggingService/ImageTaggingReadService when viewing/editing an +-- artifact's release tags. +-- * ImageTaggingRepositoryImpl.GetImageComment / GetImageCommentsByArtifactIds +-- (same file) — called from ImageTaggingService when rendering an artifact's comment +-- (build/deployment history rows). +-- +-- Note: CREATE INDEX CONCURRENTLY cannot run inside a transaction (golang-migrate wraps +-- each migration in one). We use plain CREATE INDEX IF NOT EXISTS here so the migration is +-- idempotent, matching this repo's existing convention (see 36304600_add_ci_artifact_query_indexes). +-- For large existing tables, operators SHOULD create these indexes manually with +-- CONCURRENTLY BEFORE deploying this release, to avoid blocking writes during pod startup: +-- +-- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_release_tags_artifact_id +-- ON release_tags (artifact_id); +-- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_image_comments_artifact_id +-- ON image_comments (artifact_id); +-- +-- Once the indexes exist, this migration is a no-op (IF NOT EXISTS). + +-- release_tags.artifact_id — the table's only existing index is UNIQUE(app_id, tag_name), +-- which doesn't help an artifact_id-only lookup. +CREATE INDEX IF NOT EXISTS idx_release_tags_artifact_id + ON release_tags (artifact_id); + +-- image_comments.artifact_id — no index beyond the primary key today. +CREATE INDEX IF NOT EXISTS idx_image_comments_artifact_id + ON image_comments (artifact_id); From 33ff2917a32fe154f3176ff4da62e63290acfc0b Mon Sep 17 00:00:00 2001 From: Bhupesh Varshney Date: Wed, 7 Oct 2026 16:51:12 +0530 Subject: [PATCH 2/2] fix: renumber artifact tagging indexes migration to avoid collision with devtron-enterprise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 37404600 was independently picked by a companion enterprise PR (feat/ws-g-artifact-promotion-index) for a different migration — golang-migrate refuses to start when two files share a version number, and devtron-enterprise's scripts/sql is merged from this repo's scripts/sql. Renumbered to 37504600, the next free number in both repos. --- ....down.sql => 37504600_add_artifact_tagging_indexes.down.sql} | 2 +- ...exes.up.sql => 37504600_add_artifact_tagging_indexes.up.sql} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename scripts/sql/{37404600_add_artifact_tagging_indexes.down.sql => 37504600_add_artifact_tagging_indexes.down.sql} (65%) rename scripts/sql/{37404600_add_artifact_tagging_indexes.up.sql => 37504600_add_artifact_tagging_indexes.up.sql} (100%) diff --git a/scripts/sql/37404600_add_artifact_tagging_indexes.down.sql b/scripts/sql/37504600_add_artifact_tagging_indexes.down.sql similarity index 65% rename from scripts/sql/37404600_add_artifact_tagging_indexes.down.sql rename to scripts/sql/37504600_add_artifact_tagging_indexes.down.sql index 43689bf9d7..ced89ac3f7 100644 --- a/scripts/sql/37404600_add_artifact_tagging_indexes.down.sql +++ b/scripts/sql/37504600_add_artifact_tagging_indexes.down.sql @@ -1,4 +1,4 @@ --- Rollback: drop indexes added by 37004600_add_artifact_tagging_indexes.up.sql +-- Rollback: drop indexes added by 37504600_add_artifact_tagging_indexes.up.sql DROP INDEX IF EXISTS idx_release_tags_artifact_id; DROP INDEX IF EXISTS idx_image_comments_artifact_id; diff --git a/scripts/sql/37404600_add_artifact_tagging_indexes.up.sql b/scripts/sql/37504600_add_artifact_tagging_indexes.up.sql similarity index 100% rename from scripts/sql/37404600_add_artifact_tagging_indexes.up.sql rename to scripts/sql/37504600_add_artifact_tagging_indexes.up.sql