Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX IF EXISTS idx_object_uid_not_deleted;
17 changes: 17 additions & 0 deletions pkg/db/migration/000058_add_object_uid_partial_index.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- ============================================================================
-- Migration: Add partial index on object(uid) for soft-delete queries
-- ============================================================================
-- This migration adds a partial index to optimize queries like:
-- SELECT ... FROM object WHERE uid = '...' AND delete_time IS NULL
--
-- The primary key on uid doesn't include delete_time, so the query planner
-- must perform a filter step after the index scan. Under high concurrency
-- (e.g., many simultaneous file uploads), this causes slow queries (200-400ms).
--
-- A partial index allows direct lookups without filtering.
-- ============================================================================
-- Note: Not using CONCURRENTLY as it cannot run in a transaction,
-- and most migration frameworks require transaction support.
CREATE INDEX IF NOT EXISTS idx_object_uid_not_deleted ON object(uid)
WHERE delete_time IS NULL;
COMMENT ON INDEX idx_object_uid_not_deleted IS 'Partial index for efficient lookup of non-deleted objects by uid';
2 changes: 1 addition & 1 deletion pkg/db/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// TargetSchemaVersion determines the database schema version.
const TargetSchemaVersion uint = 57
const TargetSchemaVersion uint = 58

type migration interface {
Migrate() error
Expand Down
Loading