Skip to content

Trt 1989 migration queries#3542

Open
neisw wants to merge 7 commits into
openshift:mainfrom
neisw:trt-1989-migration-queries
Open

Trt 1989 migration queries#3542
neisw wants to merge 7 commits into
openshift:mainfrom
neisw:trt-1989-migration-queries

Conversation

@neisw
Copy link
Copy Markdown
Contributor

@neisw neisw commented May 19, 2026

Depends on #3541, updates queries to use new indexes.

Summary by CodeRabbit

  • Documentation

    • Added three detailed guides for the multi-phase DB partitioning and indexing strategy; corrected foreign-key partitioning guidance.
  • Performance Improvements

    • Added composite indexes on denormalized release/timestamp fields and updated queries to use local columns for faster filtering.
  • Behavior Changes

    • Several reports and APIs now scope results by run-test–level release/timestamp, yielding more accurate time/release-scoped results.
  • Tests

    • Added benchmarks and a query-comparison test for release/time filtering.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds Phase 2 index docs and Phase 3 query rules, adds GORM index tags, rewrites SQL/functions/views/queries to use denormalized prow_job_run_tests release/timestamp, updates API calls and benchmarks, and switches DB init to a pgx-backed connection pool.

Changes

TRT-1989 Phase 2 & 3: Partitioning Preparation

Layer / File(s) Summary
Migration Plan & Phase Documentation
docs/plans/trt-1989-partitioning-prep.md, docs/plans/trt-1989-phase2-indexes.md, docs/plans/trt-1989-phase3-query-optimization.md
Clarifies FK constraint direction for partitioned tables, adds Phase 2 index list and CREATE INDEX statements, and enumerates Phase 3 query rollout rules and per-query changes.
GORM Index Tags (Phase 2)
pkg/db/models/prow.go
Adds composite index tags on denormalized release/timestamp fields across prow job-run-related models and a standalone index on ProwJobRunTest.ProwJobID.
Database Layer: functions & views (Phase 3)
pkg/db/functions.go, pkg/db/views.go
Embedded SQL functions (test_results, job_results) and materialized views rewired to source release/timestamp from prow_job_run_tests and to add explicit prow_job_runs/relation release/time predicates where still required.
Query helpers & queries
pkg/db/query/* (build_clusters.go, job_queries.go, test_queries.go, pull_request_queries.go, repository_queries.go)
Queries updated to filter on denormalized run-test-level release/timestamp fields, remove or rewire joins that previously relied on prow_job_runs/prow_jobs, and tighten release/time scoping.
API/provider callsites
pkg/api/* (componentreadiness/dataprovider/postgres/provider.go, recent_test_failures.go, tests.go, job_analysis.go, job_runs.go, jobs.go, test_analysis.go)
Provider and API methods updated to pass additional release/start/end parameters, apply run-test–level timestamp scoping for recent failures/counts/outputs, and restrict annotation/PR/repository lookups to the requested release.
Benchmarking & tests
pkg/flags/postgres_benchmarking_test.go
Benchmark SQL and harness updated to use denormalized filters, extract and pass connection name, add benchmark cases and a Test_CompareTestOutputsQueries integration test.
DB init & deps
pkg/db/db.go, go.mod
Switch DB initialization to parse DSN with pgx, use a pgx/stdlib pool with plan_cache_mode=force_custom_plan, and add github.com/jackc/pgx/v4 as a direct dependency.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • openshift/sippy#3557: Overlapping benchmark harness and benchmark-case changes affecting pkg/flags/postgres_benchmarking_test.go.

Suggested labels

lgtm

Suggested reviewers

  • stbenjam
  • deads2k
🚥 Pre-merge checks | ✅ 19 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (19 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Trt 1989 migration queries' clearly relates to the main objective of updating queries to use new indexes as part of the TRT-1989 partitioning/migration strategy, which is the primary theme across most file changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Go Error Handling ✅ Passed All error handling correct: pgx.ParseConfig() error properly checked, no ignored errors, fmt.Errorf %w used, no panic() calls, pointers validated.
Sql Injection Prevention ✅ Passed All modified SQL queries use proper parameter binding via GORM Where() placeholders, sql.Named(), and positional parameters. No unsafe fmt.Sprintf SQL concatenation found. DB init improved with pgx.
Excessive Css In React Should Use Styles ✅ Passed PR contains only Go backend code and documentation; no React components present. Custom check for React CSS patterns is inapplicable.
Test Coverage For New Features ✅ Passed 47 new test files added providing integration, e2e, and benchmark tests. Modified query functions covered via API tests and Test_CompareTestOutputsQueries validation.
Single Responsibility And Clear Naming ✅ Passed All new functions have clear, action-oriented names; no generic names added; parameters logically grouped; struct fields reasonable; code organized by responsibility.
Stable And Deterministic Test Names ✅ Passed Project does not use Ginkgo framework; it uses standard Go testing. No Ginkgo test titles exist to validate. Check is not applicable.
Test Structure And Quality ✅ Passed This repository uses standard Go testing (testing.T), not Ginkgo. No Ginkgo imports, suite files, or tests exist in the codebase. Custom check is not applicable.
Microshift Test Compatibility ✅ Passed PR adds no Ginkgo e2e tests. Modified test file (postgres_benchmarking_test.go) contains only standard Go unit/benchmark tests, so MicroShift compatibility check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR contains only documentation updates and database unit/benchmark tests using standard Go testing.T. No Ginkgo e2e tests are added; SNO compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR contains only database schema, query optimization, and test code changes; no deployment manifests, operator controllers, or Kubernetes scheduling constraints are modified.
Ote Binary Stdout Contract ✅ Passed No OTE Binary Stdout Contract violations found. All stdout writes (fmt.Print/Printf in postgres_benchmarking_test.go) are within test functions/helpers, not process-level code.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests were added in this PR. Changes are limited to query/SQL migration updates and benchmark unit tests, which do not contain IPv4 assumptions or external connectivity requirements.
No-Weak-Crypto ✅ Passed No weak crypto (MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB), custom ciphers, or timing-unsafe comparisons found. Only SHA256 for schema integrity used.
Container-Privileges ✅ Passed PR contains no container/K8s manifest modifications; all changes are Go code and documentation only.
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data logging found. DSN credentials are never logged, only safe hostname prefixes are used for benchmark reporting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from deads2k and stbenjam May 19, 2026 18:27
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neisw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
docs/plans/trt-1989-phase2-indexes.md (1)

14-16: ⚡ Quick win

Clarify the intentional index-order exception.

The doc says indexes mirror (release, timestamp), but prow_job_run_tests is documented as (timestamp, release). Add an explicit “except for prow_job_run_tests” qualifier where the mirror rule is introduced.

Also applies to: 41-43, 127-128

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-phase2-indexes.md` around lines 14 - 16, Update the
description that says indexes mirror the future partition key "(release,
timestamp)" to explicitly note the intentional exception for the
prow_job_run_tests index (which is documented as "(timestamp, release)"); add a
parenthetical or sentence like "except for prow_job_run_tests, which
intentionally uses (timestamp, release)" at the point where the mirror rule is
introduced and make the same clarification in the other repeated occurrences of
this rule later in the doc (the subsequent paragraph and the later section that
repeats the mirror-index guidance).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/plans/trt-1989-partitioning-prep.md`:
- Around line 86-88: The sentence incorrectly describes FK direction: change the
wording that currently reads "Tables with FKs from `prow_job_runs` to
non-partitioned tables (annotations, pull request join table)..." to clarify
that annotations and the pull-request join table hold FKs referencing
`prow_job_runs` (i.e., FKs to `prow_job_runs`), and therefore any tables that
reference `prow_job_runs` must be co-partitioned with it or have their FKs
dropped; update the line and any examples to use "tables with FKs to
`prow_job_runs` (annotations, pull request join table) must either be
co-partitioned or have their FKs dropped" and ensure surrounding text
consistently treats `prow_job_runs` as the referenced table.

In `@docs/plans/trt-1989-phase2-indexes.md`:
- Around line 36-37: Update the doc line that incorrectly references
ProwJobRunTest.ProwJobID: it should point to the prow_job_run_tests table /
ProwJobRunTests model field instead of prow_job_runs; replace the reference with
either "prow_job_run_tests" or "ProwJobRunTests.ProwJobID" so the standalone
index is correctly attributed to the prow_job_run_tests model.

In `@docs/plans/trt-1989-phase3-query-optimization.md`:
- Around line 28-31: The document's principle "Add filters, don't replace"
contradicts later rollout rules that replace/drop joins; update the principle
heading and first paragraph (the "Add filters, don't replace" paragraph) to
explicitly match the rollout: state that join-based filters are retained until
local columns are validated and tested, then replaced/dropped when safe, and
mirror this clarified wording in the other affected sections referenced
(sections covering the same guidance around lines 73-80, 81-86, and 126-132) so
the high-level principle and the detailed rollout rules are consistent.

---

Nitpick comments:
In `@docs/plans/trt-1989-phase2-indexes.md`:
- Around line 14-16: Update the description that says indexes mirror the future
partition key "(release, timestamp)" to explicitly note the intentional
exception for the prow_job_run_tests index (which is documented as "(timestamp,
release)"); add a parenthetical or sentence like "except for prow_job_run_tests,
which intentionally uses (timestamp, release)" at the point where the mirror
rule is introduced and make the same clarification in the other repeated
occurrences of this rule later in the doc (the subsequent paragraph and the
later section that repeats the mirror-index guidance).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 44fd03d2-a25c-47af-9a09-37386bb12690

📥 Commits

Reviewing files that changed from the base of the PR and between 134d39a and 9cefc7d.

📒 Files selected for processing (16)
  • cmd/sippy/seed_data.go
  • docs/plans/trt-1989-partitioning-prep.md
  • docs/plans/trt-1989-phase2-indexes.md
  • docs/plans/trt-1989-phase3-query-optimization.md
  • pkg/api/componentreadiness/dataprovider/postgres/provider.go
  • pkg/api/job_runs_test.go
  • pkg/api/recent_test_failures.go
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/db.go
  • pkg/db/functions.go
  • pkg/db/models/prow.go
  • pkg/db/query/build_clusters.go
  • pkg/db/query/job_queries.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go
  • pkg/sippyserver/pr_new_tests_worker_test.go

Comment thread docs/plans/trt-1989-partitioning-prep.md Outdated
Comment on lines +36 to +37
Also added a standalone index on `ProwJobRunTest.ProwJobID` to support
variant queries that previously required joining through `prow_job_runs`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Correct the model/table reference for the standalone index.

The text points to ProwJobRunTest.ProwJobID, but this index is on prow_job_run_tests (ProwJobRunTests model field), not prow_job_runs.

Proposed doc fix
-Also added a standalone index on `ProwJobRunTest.ProwJobID` to support
+Also added a standalone index on `ProwJobRunTests.ProwJobID` to support
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Also added a standalone index on `ProwJobRunTest.ProwJobID` to support
variant queries that previously required joining through `prow_job_runs`.
Also added a standalone index on `ProwJobRunTests.ProwJobID` to support
variant queries that previously required joining through `prow_job_runs`.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-phase2-indexes.md` around lines 36 - 37, Update the doc
line that incorrectly references ProwJobRunTest.ProwJobID: it should point to
the prow_job_run_tests table / ProwJobRunTests model field instead of
prow_job_runs; replace the reference with either "prow_job_run_tests" or
"ProwJobRunTests.ProwJobID" so the standalone index is correctly attributed to
the prow_job_run_tests model.

Comment thread docs/plans/trt-1989-phase3-query-optimization.md Outdated
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@neisw
Copy link
Copy Markdown
Contributor Author

neisw commented May 19, 2026

/hold
depends on #3542

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 19, 2026
@neisw neisw force-pushed the trt-1989-migration-queries branch from 9cefc7d to 66753c4 Compare May 20, 2026 00:11
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
docs/plans/trt-1989-phase3-query-optimization.md (1)

28-31: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align the guiding principle with the rollout rules.

This principle conflicts with later sections that replace filters and drop joins after local-column validation. Please reword it to: keep join-based filters initially, then replace/drop when validated safe.

Proposed doc fix
-1. **Add filters, don't replace** — keep existing join-based filters
-   alongside the new local filters. The planner uses whichever is cheaper.
-   Removing them risks behavior change if denormalized data has gaps.
+1. **Add filters first, then replace when validated** — keep existing
+   join-based filters alongside new local filters during rollout.
+   After local denormalized columns are validated, replace old filters
+   and drop no-longer-needed joins where safe.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-phase3-query-optimization.md` around lines 28 - 31,
Update the principle titled "Add filters, don't replace" so it matches the
rollout rules: reword the sentence to state that join-based filters should be
retained initially alongside new local filters and only replaced/dropped after
local-column validation proves it safe; ensure the new wording explicitly says
"keep join-based filters initially, then replace/drop when validated safe" and
that it aligns with later sections that describe replacing filters and dropping
joins post-validation.
docs/plans/trt-1989-partitioning-prep.md (1)

86-88: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix inverted FK direction in migration constraints.

This still states FKs are from prow_job_runs to annotations/PR join rows, but those tables reference prow_job_runs. Please flip the direction to avoid incorrect partitioning/FK planning.

Proposed doc fix
-3. Tables with FKs **from** `prow_job_runs` to non-partitioned tables
-   (annotations, pull request join table) must either be co-partitioned
-   or have their FKs dropped.
+3. Tables with FKs **to** `prow_job_runs` from non-partitioned tables
+   (annotations, pull request join table) must either be co-partitioned
+   or have their FKs dropped.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-partitioning-prep.md` around lines 86 - 88, The sentence
incorrectly states foreign keys are "from prow_job_runs to annotations/pull
request join table"; update the wording to say the annotations and pull request
join table have FKs referencing prow_job_runs (i.e., FKs are to prow_job_runs
from those tables) and therefore those referencing tables must be co-partitioned
with prow_job_runs or have their FKs dropped; locate and change the phrase
mentioning prow_job_runs, annotations, and pull request join table so the FK
direction is flipped to "annotations/PR join rows -> prow_job_runs" and clarify
the co-partition/drop requirement.
🧹 Nitpick comments (1)
pkg/db/query/test_queries.go (1)

281-291: ⚡ Quick win

Add short inline comments for major query sections in changed builders.

The modified JOIN/WHERE/grouping sections are non-trivial and currently undocumented in-place; please add brief “why”-focused comments for the main sections.

As per coding guidelines, "BigQuery and SQL query-building code should have inline comments explaining the purpose of each major query section (CTEs, JOINs, window functions, WHERE clauses)."

Also applies to: 321-325, 336-339

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/db/query/test_queries.go` around lines 281 - 291, The query builder
chains (the q := dbc.DB.Table(...) blocks that join prow_job_run_test_outputs ->
prow_job_run_tests -> prow_job_runs -> prow_jobs and the grouped WHERE clauses
using current_date - interval '14' day and release/test filters) need short
inline “why” comments: add brief comments above the JOIN group explaining why
these tables are joined and what relationship/intent each JOIN captures, and
above the WHERE block explaining the purpose of the 14-day time filters and why
release/test filters are applied; do the same for the other similar q :=
dbc.DB.Table(...) builders in this file (the other blocks that start the same
chain and contain the WHERE/grouping logic) so each major section (JOINs,
time-window WHEREs, release/test filters, and any grouping/aggregation sections)
has a succinct purpose-focused comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/db/query/test_queries.go`:
- Around line 285-291: Remove the legacy parent-table predicates that
over-constrain the denormalized TestOutputs path: drop the
Where("prow_job_runs.timestamp > current_date - interval '14' day") and
Where("prow_jobs.release = ?", release) clauses from the query so that filtering
relies on the child-table fields
(prow_job_run_test_outputs.prow_job_run_test_timestamp,
prow_job_run_test_outputs.prow_job_run_test_release,
prow_job_run_tests.prow_job_run_timestamp,
prow_job_run_tests.prow_job_run_release, and prow_job_run_tests.test_id = (?))
and thus preserves the denormalized/partition/index benefits.

---

Duplicate comments:
In `@docs/plans/trt-1989-partitioning-prep.md`:
- Around line 86-88: The sentence incorrectly states foreign keys are "from
prow_job_runs to annotations/pull request join table"; update the wording to say
the annotations and pull request join table have FKs referencing prow_job_runs
(i.e., FKs are to prow_job_runs from those tables) and therefore those
referencing tables must be co-partitioned with prow_job_runs or have their FKs
dropped; locate and change the phrase mentioning prow_job_runs, annotations, and
pull request join table so the FK direction is flipped to "annotations/PR join
rows -> prow_job_runs" and clarify the co-partition/drop requirement.

In `@docs/plans/trt-1989-phase3-query-optimization.md`:
- Around line 28-31: Update the principle titled "Add filters, don't replace" so
it matches the rollout rules: reword the sentence to state that join-based
filters should be retained initially alongside new local filters and only
replaced/dropped after local-column validation proves it safe; ensure the new
wording explicitly says "keep join-based filters initially, then replace/drop
when validated safe" and that it aligns with later sections that describe
replacing filters and dropping joins post-validation.

---

Nitpick comments:
In `@pkg/db/query/test_queries.go`:
- Around line 281-291: The query builder chains (the q := dbc.DB.Table(...)
blocks that join prow_job_run_test_outputs -> prow_job_run_tests ->
prow_job_runs -> prow_jobs and the grouped WHERE clauses using current_date -
interval '14' day and release/test filters) need short inline “why” comments:
add brief comments above the JOIN group explaining why these tables are joined
and what relationship/intent each JOIN captures, and above the WHERE block
explaining the purpose of the 14-day time filters and why release/test filters
are applied; do the same for the other similar q := dbc.DB.Table(...) builders
in this file (the other blocks that start the same chain and contain the
WHERE/grouping logic) so each major section (JOINs, time-window WHEREs,
release/test filters, and any grouping/aggregation sections) has a succinct
purpose-focused comment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 1d655e29-3ac0-40c3-bada-f206e2d07cf1

📥 Commits

Reviewing files that changed from the base of the PR and between 9cefc7d and 66753c4.

📒 Files selected for processing (16)
  • cmd/sippy/seed_data.go
  • docs/plans/trt-1989-partitioning-prep.md
  • docs/plans/trt-1989-phase2-indexes.md
  • docs/plans/trt-1989-phase3-query-optimization.md
  • pkg/api/componentreadiness/dataprovider/postgres/provider.go
  • pkg/api/job_runs_test.go
  • pkg/api/recent_test_failures.go
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/db.go
  • pkg/db/functions.go
  • pkg/db/models/prow.go
  • pkg/db/query/build_clusters.go
  • pkg/db/query/job_queries.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go
  • pkg/sippyserver/pr_new_tests_worker_test.go
✅ Files skipped from review due to trivial changes (1)
  • docs/plans/trt-1989-phase2-indexes.md
🚧 Files skipped from review as they are similar to previous changes (12)
  • pkg/api/job_runs_test.go
  • pkg/db/query/job_queries.go
  • pkg/api/componentreadiness/dataprovider/postgres/provider.go
  • pkg/db/functions.go
  • pkg/db/db.go
  • pkg/api/recent_test_failures.go
  • cmd/sippy/seed_data.go
  • pkg/sippyserver/pr_new_tests_worker_test.go
  • pkg/db/query/build_clusters.go
  • pkg/db/views.go
  • pkg/db/models/prow.go
  • pkg/dataloader/prowloader/prow.go

Comment thread pkg/db/query/test_queries.go Outdated
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

1 similar comment
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 21, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/flags/postgres_benchmarking_test.go`:
- Around line 77-85: The code currently treats an empty benchmarking_file_path
as "/" and may write to root; change the guard so you only append a trailing
slash and attempt writing when benchmarking_file_path is non-empty: check
len(benchmarkFilePath) > 0 immediately after reading
os.Getenv("benchmarking_file_path") and return/skip writing if it's empty; when
non-empty, normalize the path (use filepath.Join or ensure a single separator)
before building filename and calling os.WriteFile with
benchmarkFilePath+filename (or filepath.Join(benchmarkFilePath, filename));
update the conditions that control writing (the connName != "" &&
len(benchmarkFilePath) > 0 check) to run only when the env var was set.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 283306bf-07cc-4e29-836a-9ce3b0189ce9

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf023a and 6d7b778.

📒 Files selected for processing (8)
  • config/openshift-customizations.yaml
  • config/openshift.yaml
  • pkg/api/job_runs.go
  • pkg/db/functions.go
  • pkg/db/query/pull_request_queries.go
  • pkg/db/query/repository_queries.go
  • pkg/flags/postgres_benchmarking_test.go
  • pkg/variantregistry/snapshot.yaml
✅ Files skipped from review due to trivial changes (1)
  • config/openshift-customizations.yaml

Comment thread pkg/flags/postgres_benchmarking_test.go Outdated
@neisw neisw force-pushed the trt-1989-migration-queries branch from 6d7b778 to a2b4e6c Compare May 25, 2026 21:09
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 25, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/plans/trt-1989-phase2-indexes.md`:
- Around line 31-37: The documentation incorrectly places the standalone index
note for prow_job_run_tests.prow_job_id under the prow_job_runs section; move
the two lines describing the index on prow_job_run_tests.prow_job_id (and the
index name if mentioned) out from under the "### prow_job_runs" header and place
them under the "### prow_job_run_tests" header (or create a short subsection
there) so the descriptive text matches the SQL shown later for the idx on
prow_job_run_tests.prow_job_id.

In `@pkg/db/models/prow.go`:
- Line 106: The ProwJobID field currently uses a generic GORM `index` tag which
lets GORM auto-generate the index name; update the struct tag for ProwJobID
(symbol: ProwJobID) to use an explicit index name
`idx_prow_job_run_tests_prow_job_id` (e.g.
`gorm:"index:idx_prow_job_run_tests_prow_job_id"`) so the created index name
matches the documentation and other composite indexes in this file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: dd119370-9d91-4bd1-82eb-8a245a901131

📥 Commits

Reviewing files that changed from the base of the PR and between 6d7b778 and a2b4e6c.

📒 Files selected for processing (17)
  • docs/plans/trt-1989-partitioning-prep.md
  • docs/plans/trt-1989-phase2-indexes.md
  • docs/plans/trt-1989-phase3-query-optimization.md
  • pkg/api/componentreadiness/dataprovider/postgres/provider.go
  • pkg/api/job_analysis.go
  • pkg/api/job_runs.go
  • pkg/api/recent_test_failures.go
  • pkg/api/tests.go
  • pkg/db/functions.go
  • pkg/db/models/prow.go
  • pkg/db/query/build_clusters.go
  • pkg/db/query/job_queries.go
  • pkg/db/query/pull_request_queries.go
  • pkg/db/query/repository_queries.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go
  • pkg/flags/postgres_benchmarking_test.go
✅ Files skipped from review due to trivial changes (1)
  • docs/plans/trt-1989-phase3-query-optimization.md

Comment on lines +31 to +37
### prow_job_runs

Added composite index `idx_prow_job_runs_release_timestamp` across
`ProwJobRelease` and `Timestamp`.

Also added a standalone index on `ProwJobRunTest.ProwJobID` to support
variant queries that previously required joining through `prow_job_runs`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Move the standalone index documentation to the correct section.

Lines 36-37 describe an index on prow_job_run_tests.prow_job_id, but they appear under the ### prow_job_runs section header. This creates confusion about which table is being indexed.

📝 Proposed reorganization

Move lines 36-37 to appear under the ### prow_job_run_tests section (after line 38), or create a separate subsection if this index deserves its own explanation distinct from the composite release-timestamp index.

The SQL at lines 79-80 correctly shows this index on prow_job_run_tests, so the documentation sections should match the SQL organization.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-phase2-indexes.md` around lines 31 - 37, The
documentation incorrectly places the standalone index note for
prow_job_run_tests.prow_job_id under the prow_job_runs section; move the two
lines describing the index on prow_job_run_tests.prow_job_id (and the index name
if mentioned) out from under the "### prow_job_runs" header and place them under
the "### prow_job_run_tests" header (or create a short subsection there) so the
descriptive text matches the SQL shown later for the idx on
prow_job_run_tests.prow_job_id.

Comment thread pkg/db/models/prow.go Outdated
@neisw neisw force-pushed the trt-1989-migration-queries branch 2 times, most recently from 35565d2 to 6e7dde0 Compare May 28, 2026 20:51
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@neisw
Copy link
Copy Markdown
Contributor Author

neisw commented Jun 1, 2026

Capturing results verifying the refactored TestOutputs queries results match

=== RUN   Test_CompareTestOutputsQueries
    postgres_benchmarking_test.go:577: baseline: 16 results in 4h41m44.034645357s
    postgres_benchmarking_test.go:578: current:  16 results in 247.374048ms
    postgres_benchmarking_test.go:612: comparison: baseline=16 current=16 missing_from_current=0 extra_in_current=0 output_mismatch=0
--- PASS: Test_CompareTestOutputsQueries (16913.77s)

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@neisw neisw force-pushed the trt-1989-migration-queries branch from 0e1bda0 to 912c2fa Compare June 2, 2026 21:03
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

@neisw: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/yaml-lint 6d7b778 link true /test yaml-lint

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@neisw
Copy link
Copy Markdown
Contributor Author

neisw commented Jun 3, 2026

/test images

@neisw
Copy link
Copy Markdown
Contributor Author

neisw commented Jun 3, 2026

@coderabbitai refresh your review based on the latest updates

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

@neisw Sure! I'll re-review the PR based on the latest updates. The performance improvement captured in your test results is impressive — the TestOutputs query went from ~4h 42m to ~247ms, which is a massive win!

✅ Action performed

Full review finished.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/sippyserver/pr_new_tests_worker.go (1)

235-244: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Cache key may not account for release-scoped historical counts.

The historicalTestCount cache uses run.ProwJob.ID as the key (line 243), but ProwJobHistoricalTestCounts now returns release-scoped counts. If the same job ID is queried for different releases, the cached value from the first release will be incorrectly reused.

Consider using a composite key that includes both job ID and release.

🔧 Proposed fix
 type pgJobRunFilter struct {
 	dbc                 *db.DB
-	historicalTestCount map[uint]int // in-memory cache of historical test counts per job id
+	historicalTestCount map[string]int // in-memory cache of historical test counts per job id + release
 }

And update the cache key usage:

+	cacheKey := fmt.Sprintf("%d:%s", run.ProwJob.ID, run.ProwJob.Release)
-	historicalCount, ok := jrf.historicalTestCount[run.ProwJob.ID]
+	historicalCount, ok := jrf.historicalTestCount[cacheKey]
 	if !ok {
 		var err error
 		historicalCount, err = query.ProwJobHistoricalTestCounts(jrf.dbc, run.ProwJobID, run.ProwJob.Release)
 		if err != nil {
 			logger.WithError(err).Error("Error determining historical job test count, ignoring this run")
 			return true
 		}
-		jrf.historicalTestCount[run.ProwJob.ID] = historicalCount
+		jrf.historicalTestCount[cacheKey] = historicalCount
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/sippyserver/pr_new_tests_worker.go` around lines 235 - 244, The cache
currently keys jrf.historicalTestCount by run.ProwJob.ID but
ProwJobHistoricalTestCounts(jrf.dbc, run.ProwJobID, run.ProwJob.Release) returns
release-scoped counts, so create a composite key that includes both
run.ProwJob.ID and run.ProwJob.Release (e.g. fmt.Sprintf("%s|%s",
run.ProwJob.ID, run.ProwJob.Release) or a small struct key) and use that key
when reading from and writing to jrf.historicalTestCount; update the lookup and
assignment around the historicalTestCount variable and any other places that
access jrf.historicalTestCount to use the new composite key so cached counts are
release-specific.
♻️ Duplicate comments (2)
docs/plans/trt-1989-partitioning-prep.md (2)

31-37: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Move standalone index documentation to the correct section.

Lines 36-37 describe an index on prow_job_run_tests.prow_job_id, but they appear under the ### prow_job_runs section header (line 31). The SQL at lines 79-80 correctly creates this index on the prow_job_run_tests table.

Move lines 36-37 to appear under the ### prow_job_run_tests section (after line 38) so the descriptive text matches the SQL organization and table scope.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-partitioning-prep.md` around lines 31 - 37, The two-line
description about the standalone index for prow_job_run_tests.prow_job_id is
misplaced under the "### prow_job_runs" section; move that description so it
appears under the "### prow_job_run_tests" header (immediately after that
section header) so it matches the SQL that creates the index for
prow_job_run_tests.prow_job_id; update the prose only—no SQL changes—and keep
the same wording so the documentation aligns with the existing CREATE INDEX
statement.

36-37: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify table/model reference for the standalone index.

The text references ProwJobRunTest.ProwJobID (Go struct field), but in the context of database index documentation it would be clearer to reference the table name directly: prow_job_run_tests.prow_job_id to match the SQL convention used throughout the rest of this doc.

📝 Proposed clarification
-Also added a standalone index on `ProwJobRunTest.ProwJobID` to support
+Also added a standalone index on `prow_job_run_tests.prow_job_id` to support
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/trt-1989-partitioning-prep.md` around lines 36 - 37, Update the
doc to reference the DB column/table name instead of the Go struct field:
replace or augment the mention of ProwJobRunTest.ProwJobID with the SQL-style
name prow_job_run_tests.prow_job_id (or include both, e.g.,
"prow_job_run_tests.prow_job_id (Go: ProwJobRunTest.ProwJobID)") so the index
documentation consistently uses table/column naming like the rest of the
document.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@go.mod`:
- Line 23: Update the pinned pgx dependency in go.mod from
github.com/jackc/pgx/v4 v4.18.2 to v4.18.3, and add a short TODO note in the
repo (e.g., in README or a migration planning doc) to plan migrating from pgx v4
to pgx v5 before the v4 EOL date; search for the module string
"github.com/jackc/pgx/v4" and change the version to "v4.18.3" and create/update
a migration task referencing pgx v5.

---

Outside diff comments:
In `@pkg/sippyserver/pr_new_tests_worker.go`:
- Around line 235-244: The cache currently keys jrf.historicalTestCount by
run.ProwJob.ID but ProwJobHistoricalTestCounts(jrf.dbc, run.ProwJobID,
run.ProwJob.Release) returns release-scoped counts, so create a composite key
that includes both run.ProwJob.ID and run.ProwJob.Release (e.g.
fmt.Sprintf("%s|%s", run.ProwJob.ID, run.ProwJob.Release) or a small struct key)
and use that key when reading from and writing to jrf.historicalTestCount;
update the lookup and assignment around the historicalTestCount variable and any
other places that access jrf.historicalTestCount to use the new composite key so
cached counts are release-specific.

---

Duplicate comments:
In `@docs/plans/trt-1989-partitioning-prep.md`:
- Around line 31-37: The two-line description about the standalone index for
prow_job_run_tests.prow_job_id is misplaced under the "### prow_job_runs"
section; move that description so it appears under the "### prow_job_run_tests"
header (immediately after that section header) so it matches the SQL that
creates the index for prow_job_run_tests.prow_job_id; update the prose only—no
SQL changes—and keep the same wording so the documentation aligns with the
existing CREATE INDEX statement.
- Around line 36-37: Update the doc to reference the DB column/table name
instead of the Go struct field: replace or augment the mention of
ProwJobRunTest.ProwJobID with the SQL-style name prow_job_run_tests.prow_job_id
(or include both, e.g., "prow_job_run_tests.prow_job_id (Go:
ProwJobRunTest.ProwJobID)") so the index documentation consistently uses
table/column naming like the rest of the document.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 2e60b60d-7d5e-49fc-85e5-327cf0b469a2

📥 Commits

Reviewing files that changed from the base of the PR and between e29e458 and 912c2fa.

📒 Files selected for processing (22)
  • docs/plans/trt-1989-partitioning-prep.md
  • docs/plans/trt-1989-phase2-indexes.md
  • docs/plans/trt-1989-phase3-query-optimization.md
  • go.mod
  • pkg/api/componentreadiness/dataprovider/postgres/provider.go
  • pkg/api/job_analysis.go
  • pkg/api/job_runs.go
  • pkg/api/jobs.go
  • pkg/api/recent_test_failures.go
  • pkg/api/test_analysis.go
  • pkg/api/tests.go
  • pkg/db/db.go
  • pkg/db/functions.go
  • pkg/db/models/prow.go
  • pkg/db/query/build_clusters.go
  • pkg/db/query/job_queries.go
  • pkg/db/query/pull_request_queries.go
  • pkg/db/query/repository_queries.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go
  • pkg/flags/postgres_benchmarking_test.go
  • pkg/sippyserver/pr_new_tests_worker.go

Comment thread go.mod
github.com/gorilla/websocket v1.5.3
github.com/hashicorp/go-version v1.7.0
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgx/v4 v4.18.2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What is the latest stable version of github.com/jackc/pgx/v4 and are there any known CVEs for v4.18.2?

💡 Result:

The latest stable version of github.com/jackc/pgx/v4 is v4.18.3 [1][2][3]. Regarding version v4.18.2, there are no known CVEs specifically targeting this version; rather, v4.18.2 was the patched release that addressed two specific security vulnerabilities [4][5]. These vulnerabilities affected versions prior to v4.18.2 [4][5]: 1. CVE-2024-27289: An SQL injection vulnerability that could occur when using the non-default simple protocol with specific parameter placements [4][6]. 2. CVE-2024-27304: An SQL injection vulnerability caused by an integer overflow in the calculated protocol message size when a query or bind message exceeded 4 GB [5]. As of June 3, 2026, it should be noted that pgx v4 has reached its end-of-life, which occurred on July 1, 2025 [7][8]. Users are encouraged to upgrade to v5 [1][7][3].

Citations:


Upgrade pgx/v4 from v4.18.2 to v4.18.3 and plan v5 migration (v4 EOL)

  • go.mod pins github.com/jackc/pgx/v4 v4.18.2; no known CVEs specifically affect v4.18.2 (CVE-2024-27289 and CVE-2024-27304 were fixed in prior releases including v4.18.2).
  • Latest stable pgx/v4 is v4.18.3, and pgx v4 is end-of-life (July 1, 2025) → upgrade and plan migration to pgx v5.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@go.mod` at line 23, Update the pinned pgx dependency in go.mod from
github.com/jackc/pgx/v4 v4.18.2 to v4.18.3, and add a short TODO note in the
repo (e.g., in README or a migration planning doc) to plan migrating from pgx v4
to pgx v5 before the v4 EOL date; search for the module string
"github.com/jackc/pgx/v4" and change the version to "v4.18.3" and create/update
a migration task referencing pgx v5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant