<#6672 Fix: add composite index on DatasetUUID and...
# flyte-github
a
#6672 Fix: add composite index on DatasetUUID and ArtifactID in tags model … Pull request opened by ihvol-freenome ## Tracking issue Closes #4583 ## Why are the changes needed? The Flyte tags table lacked a composite index on the DatasetUUID and ArtifactID columns. As a result, queries filtering by both fields (for example, fetching tags associated with a specific dataset and artifact) were less efficient, leading to unnecessary full-table scans in some cases. This change adds a composite index to improve query performance and reduce latency in database lookups involving both columns. ## What changes were proposed in this pull request? This PR adds a composite GORM index on the DatasetUUID and ArtifactID fields in the tags model. - ArtifactID string - DatasetUUID string
gorm:"type:uuid;index:tags_dataset_uuid_idx"
+ ArtifactID string
gorm:"index:tags_dataset_uuid_artifact_id_idx,priority:2"
+ DatasetUUID string
gorm:"type:uuid;index:tags_dataset_uuid_idx;index:tags_dataset_uuid_artifact_id_idx,priority:1"
### How this fixes the issue: • Introduces a composite index named
tags_dataset_uuid_artifact_id_idx
. • Sets index priority for
DatasetUUID
(1) and
ArtifactID
(2) to ensure optimal ordering for typical query patterns. • Addresses #4583 by improving query efficiency without changing existing schema behavior. ## How was this patch tested? ### Labels • changed: For changes in existing functionality. • fixed: For any bug fixed. This is important to improve the readability of release notes. ### Setup process No special setup required. Run database migrations after updating Flyte to apply the new index. ### Screenshots N/A — schema-level optimization. ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. ## Related PRs N/A ## Docs link N/A — this change affects backend model definitions only and does not modify public APIs or user-facing documentation. https://bito.ai#summarystart| ### Summary by Bito This pull request introduces a composite index on the DatasetUUID and ArtifactID fields in the tags model, significantly enhancing query performance and addressing inefficiencies in database lookups. The changes aim to optimize query execution and reduce latency in database operations. flyteorg/flyte