Skip to content

Commit bd6fdd6

Browse files
mstaebleclaude
andcommitted
Drop GIN index on prow_jobs.variants
All variant filtering now resolves through the variant_combinations table via variant_combination_id, making the GIN index on the variants TEXT[] column unused. Dropping it eliminates write overhead on prow_jobs inserts and updates. TestOutputs and TestDurations queries updated to use variant_combination_id IN (subquery) instead of array containment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d1660c8 commit bd6fdd6

6 files changed

Lines changed: 23 additions & 13 deletions

File tree

pkg/api/test_analysis.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ func GetTestAnalysisOverallFromDB(dbc *db.DB, filters *filter.Filter, release, t
5656
}
5757

5858
for _, bv := range blockedVariants {
59-
jq = jq.Where("? != ANY(prow_jobs.variants)", bv)
59+
jq = jq.Where("prow_jobs.variant_combination_id NOT IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", bv)
6060
}
6161

6262
for _, av := range allowedVariants {
63-
jq = jq.Where("? = ANY(prow_jobs.variants)", av)
63+
jq = jq.Where("prow_jobs.variant_combination_id IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", av)
6464
}
6565

6666
r := jq.Scan(&rows)
@@ -122,11 +122,11 @@ func GetTestAnalysisByJobFromDB(dbc *db.DB, filters *filter.Filter, release, tes
122122
}
123123

124124
for _, bv := range blockedVariants {
125-
jq = jq.Where("? != ANY(variants)", bv)
125+
jq = jq.Where("prow_jobs.variant_combination_id NOT IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", bv)
126126
}
127127

128128
for _, av := range allowedVariants {
129-
jq = jq.Where("? = ANY(variants)", av)
129+
jq = jq.Where("prow_jobs.variant_combination_id IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", av)
130130
}
131131

132132
r := jq.Scan(&rows)

pkg/db/db.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func (d *DB) UpdateSchema(reportEnd *time.Time) error {
167167
&models.ChatConversation{},
168168
&jobrunscan.Label{},
169169
&jobrunscan.Symptom{},
170-
&models.TestDailySummary{},
171170
}
172171

173172
// Currently we need RunMigrations to run prior
@@ -575,9 +574,15 @@ func ensureVariantCombinationTrigger(db *gorm.DB) error {
575574
AND prow_jobs.variants IS NOT NULL
576575
AND prow_jobs.variant_combination_id IS NULL;
577576
578-
-- Truncate test_daily_summaries if any rows lack variant_combination_id
579-
-- so the next refresh repopulates with it set.
580-
IF EXISTS (
577+
-- Add variant_combination_id to test_daily_summaries if missing,
578+
-- and truncate so the next refresh repopulates with it set.
579+
IF NOT EXISTS (
580+
SELECT 1 FROM information_schema.columns
581+
WHERE table_name = 'test_daily_summaries' AND column_name = 'variant_combination_id'
582+
) THEN
583+
ALTER TABLE test_daily_summaries ADD COLUMN variant_combination_id BIGINT;
584+
TRUNCATE test_daily_summaries;
585+
ELSIF EXISTS (
581586
SELECT 1 FROM test_daily_summaries WHERE variant_combination_id IS NULL LIMIT 1
582587
) THEN
583588
TRUNCATE test_daily_summaries;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE INDEX IF NOT EXISTS idx_prow_jobs_variants ON prow_jobs USING gin (variants);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Drop the GIN index on prow_jobs.variants. All variant filtering now
2+
-- goes through variant_combination_id lookups against the small
3+
-- variant_combinations table, so the GIN index is unused.
4+
DROP INDEX IF EXISTS idx_prow_jobs_variants;

pkg/db/models/prow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ProwJob struct {
2525
Kind ProwKind
2626
Name string `gorm:"unique"`
2727
Release string `gorm:"index"`
28-
Variants pq.StringArray `gorm:"type:text[];index:idx_prow_jobs_variants,type:gin"`
28+
Variants pq.StringArray `gorm:"type:text[]"`
2929
// VariantCombinationID references variant_combinations.id, maintained by a
3030
// BEFORE INSERT/UPDATE trigger. NULL only when Variants is NULL.
3131
VariantCombinationID *uint `gorm:"column:variant_combination_id"`

pkg/db/query/test_queries.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ func TestOutputs(dbc *db.DB, release, test string, includedVariants, excludedVar
268268
Where("prow_job_run_test_outputs.prow_job_run_test_release = ?", release)
269269

270270
for _, variant := range includedVariants {
271-
q = q.Where("? = any(prow_jobs.variants)", variant)
271+
q = q.Where("prow_jobs.variant_combination_id IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", variant)
272272
}
273273

274274
for _, variant := range excludedVariants {
275-
q = q.Where("NOT ? = any(prow_jobs.variants)", variant)
275+
q = q.Where("prow_jobs.variant_combination_id NOT IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", variant)
276276
}
277277

278278
res := q.
@@ -301,11 +301,11 @@ func TestDurations(dbc *db.DB, release, test string, includedVariants, excludedV
301301
Where("prow_job_run_tests.prow_job_run_release = ?", release)
302302

303303
for _, variant := range includedVariants {
304-
q = q.Where("? = any(prow_jobs.variants)", variant)
304+
q = q.Where("prow_jobs.variant_combination_id IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", variant)
305305
}
306306

307307
for _, variant := range excludedVariants {
308-
q = q.Where("NOT ? = any(prow_jobs.variants)", variant)
308+
q = q.Where("prow_jobs.variant_combination_id NOT IN (SELECT id FROM variant_combinations WHERE ? = any(variants))", variant)
309309
}
310310

311311
res := q.

0 commit comments

Comments
 (0)