Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7245: retire unused issue description search indexes (#8255)

Multica Evebff833016a33
diff --git a/server/cmd/migrate/README.md b/server/cmd/migrate/README.md
index e758913bd8..7fac00cb61 100644
--- a/server/cmd/migrate/README.md
+++ b/server/cmd/migrate/README.md
@@ -1,5 +1,46 @@
# Migration runner operations
+## Issue description search index retirement
+
+Migrations 463 and 464 retire the two historical issue-description search
+indexes: `idx_issue_description_bigm` and `idx_issue_description_trgm`.
+`SearchIssues` now scans the selected workspace's issue candidates and evaluates
+description matches during projection, so neither global description GIN is
+read. Fresh installs also skip migration 139's historical trigram build. Do not
+repair or recreate these indexes after applying migrations 463 and 464.
+
+The down migrations restore the trigram index everywhere and also restore the
+CJK-friendly bigram index where `gin_bigm_ops` is available. Both use
+`CREATE INDEX CONCURRENTLY` and retry safely after an interrupted build.
+
+These migrations run during backend startup. A concurrent drop can wait for old
+transactions, so for multi-gigabyte production indexes prefer a low-traffic
+window: check for long-running transactions, then run each statement separately
+and outside a transaction before deploying:
+
+```sql
+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_description_bigm;
+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_description_trgm;
+```
+
+The subsequent migrations become fast no-ops. If startup performs a drop and
+is interrupted, `IF EXISTS` makes the next run retry safely; one index may
+remain until that retry completes. Rolling back to the current candidate-first
+search remains functionally correct without either index, but rolling back to
+the legacy search can make description queries much slower or time out until
+the database rollback rebuilds the indexes. Rebuilding up to two multi-gigabyte
+GIN indexes is not immediate; verify every restored index is live, ready, and
+valid before relying on it:
+
+```sql
+SELECT indexrelid::regclass AS index_name, indisvalid, indisready, indislive
+FROM pg_index
+WHERE indexrelid IN (
+ to_regclass('idx_issue_description_bigm'),
+ to_regclass('idx_issue_description_trgm')
+);
+```
+
## Comment content search index retirement
Migrations 454 and 455 retire both historical comment-content search indexes:
diff --git a/server/cmd/migrate/main.go b/server/cmd/migrate/main.go
index 1a2ffcc2e6..ed61b3df94 100644
--- a/server/cmd/migrate/main.go
+++ b/server/cmd/migrate/main.go
@@ -329,6 +329,8 @@ var concurrentDownIndexCleanups = map[string]string{
"453_drop_pending_issue_agent_unique": "idx_one_pending_task_per_issue_agent_v2",
"454_drop_comment_content_bigm_index": "idx_comment_content_bigm",
"455_drop_comment_content_trgm_index": "idx_comment_content_trgm",
+ "463_drop_issue_description_bigm_index": "idx_issue_description_bigm",
+ "464_drop_issue_description_trgm_index": "idx_issue_description_trgm",
}
var preMigrationHooks = func() map[string]preMigrationHook {
@@ -402,6 +404,9 @@ func refuseChannelChatRouteHistoryRollbackWith(ctx context.Context, query rowQue
}
var upMigrationConditions = map[string]migrationCondition{
+ // Current search no longer consumes an issue-description GIN. Fresh installs
+ // should not build the historical fallback only to retire it at migration 464.
+ "139_issue_description_trgm_index": skipMigration("issue description search indexes are retired by migration 464"),
// Current search no longer consumes a comment-content GIN. Fresh installs
// should not build the historical fallback only to retire it at migration 455.
"140_comment_content_trgm_index": skipMigration("comment content search indexes are retired by migration 455"),
@@ -419,9 +424,12 @@ var upMigrationConditions = map[string]migrationCondition{
// Migrations 454 and 455 restore the mutually exclusive comment search index
// selected before its retirement: pg_bigm deployments get the preferred bigram
// index, while pg_bigm-less self-hosted deployments get the trigram fallback.
+// Migration 463 independently restores the optional issue-description bigram;
+// migration 464's portable trigram rollback is unconditional.
var downMigrationConditions = map[string]migrationCondition{
- "454_drop_comment_content_bigm_index": whenOperatorClassAvailable(pgBigmOperatorClass),
- "455_drop_comment_content_trgm_index": whenOperatorClassUnavailable(pgBigmOperatorClass),
+ "454_drop_comment_content_bigm_index": whenOperatorClassAvailable(pgBigmOperatorClass),
+ "455_drop_comment_content_trgm_index": whenOperatorClassUnavailable(pgBigmOperatorClass),
+ "463_drop_issue_description_bigm_index": whenOperatorClassAvailable(pgBigmOperatorClass),
}
func hooksForDirection(direction string) map[string]preMigrationHook {
diff --git a/server/internal/migrations/migrations_lint_test.go b/server/internal/migrations/migrations_lint_test.go
index 9fda137217..5488bbfb22 100644
--- a/server/internal/migrations/migrations_lint_test.go
+++ b/server/internal/migrations/migrations_lint_test.go
@@ -5,10 +5,40 @@ import (
"path/filepath"
"runtime"
"sort"
+ "strconv"
"strings"
"testing"
)
+func TestMigrationNumericPrefixesAreUnique(t *testing.T) {
+ files := migrationFilesForLint(t, "*.up.sql")
+
+ // Migrations through 128 contain historical duplicate numeric prefixes.
+ // From 129 onward, keep the numeric sequence unique so release tooling and
+ // operators can identify one schema change unambiguously by its number.
+ const firstUniqueMigrationNumber = 129
+ stemByNumber := make(map[int]string)
+ for _, file := range files {
+ stem, _, ok := splitMigrationFilename(filepath.Base(file))
+ if !ok {
+ continue
+ }
+ prefix, _, ok := strings.Cut(stem, "_")
+ if !ok {
+ continue
+ }
+ number, err := strconv.Atoi(prefix)
+ if err != nil || number < firstUniqueMigrationNumber {
+ continue
+ }
+ if previous, exists := stemByNumber[number]; exists {
+ t.Errorf("migrations %s and %s share numeric prefix %s", previous, stem, prefix)
+ continue
+ }
+ stemByNumber[number] = stem
+ }
+}
+
func TestMigrationFilesHaveMatchingDirections(t *testing.T) {
files := migrationFilesForLint(t, "*.sql")
diff --git a/server/migrations/460_channel_trigger_snapshot.down.sql b/server/migrations/461_channel_trigger_snapshot.down.sql
similarity index 100%
rename from server/migrations/460_channel_trigger_snapshot.down.sql
rename to server/migrations/461_channel_trigger_snapshot.down.sql
diff --git a/server/migrations/460_channel_trigger_snapshot.up.sql b/server/migrations/461_channel_trigger_snapshot.up.sql
similarity index 100%
rename from server/migrations/460_channel_trigger_snapshot.up.sql
rename to server/migrations/461_channel_trigger_snapshot.up.sql
diff --git a/server/migrations/458_delete_reference_only_pr_links.down.sql b/server/migrations/462_delete_reference_only_pr_links.down.sql
similarity index 100%
rename from server/migrations/458_delete_reference_only_pr_links.down.sql
rename to server/migrations/462_delete_reference_only_pr_links.down.sql
diff --git a/server/migrations/458_delete_reference_only_pr_links.up.sql b/server/migrations/462_delete_reference_only_pr_links.up.sql
similarity index 100%
rename from server/migrations/458_delete_reference_only_pr_links.up.sql
rename to server/migrations/462_delete_reference_only_pr_links.up.sql
diff --git a/server/migrations/463_drop_issue_description_bigm_index.down.sql b/server/migrations/463_drop_issue_description_bigm_index.down.sql
new file mode 100644
index 0000000000..f6220bae6f
--- /dev/null
+++ b/server/migrations/463_drop_issue_description_bigm_index.down.sql
@@ -0,0 +1,4 @@
+-- Restore migration 036's CJK-friendly description search index where
+-- pg_bigm is available. The migration runner skips this statement elsewhere.
+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_issue_description_bigm
+ ON issue USING gin (LOWER(COALESCE(description, '')) gin_bigm_ops);
diff --git a/server/migrations/463_drop_issue_description_bigm_index.up.sql b/server/migrations/463_drop_issue_description_bigm_index.up.sql
new file mode 100644
index 0000000000..76c20b73fa
--- /dev/null
+++ b/server/migrations/463_drop_issue_description_bigm_index.up.sql
@@ -0,0 +1,3 @@
+-- SearchIssues evaluates description matches while scanning a workspace's
+-- issue candidates, so this global description GIN is no longer read.
+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_description_bigm;
diff --git a/server/migrations/464_drop_issue_description_trgm_index.down.sql b/server/migrations/464_drop_issue_description_trgm_index.down.sql
new file mode 100644
index 0000000000..9833d8602b
--- /dev/null
+++ b/server/migrations/464_drop_issue_description_trgm_index.down.sql
@@ -0,0 +1,3 @@
+-- Restore migration 139's portable issue-description search index.
+CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_issue_description_trgm
+ ON issue USING gin (LOWER(COALESCE(description, '')) gin_trgm_ops);
diff --git a/server/migrations/464_drop_issue_description_trgm_index.up.sql b/server/migrations/464_drop_issue_description_trgm_index.up.sql
new file mode 100644
index 0000000000..4afa791f2f
--- /dev/null
+++ b/server/migrations/464_drop_issue_description_trgm_index.up.sql
@@ -0,0 +1,3 @@
+-- Retire the portable fallback for the same workspace-first SearchIssues path.
+-- Keep this separate because concurrent index DDL must be the only statement.
+DROP INDEX CONCURRENTLY IF EXISTS idx_issue_description_trgm;