Skip to content

perf: push filters into test report subqueries (~830x improvement)#3290

Open
stbenjam wants to merge 2 commits intoopenshift:mainfrom
stbenjam:perf-tests
Open

perf: push filters into test report subqueries (~830x improvement)#3290
stbenjam wants to merge 2 commits intoopenshift:mainfrom
stbenjam:perf-tests

Conversation

@stbenjam
Copy link
Member

@stbenjam stbenjam commented Feb 23, 2026

When collapse=false, TestsByNURPAndStandardDeviation builds a query that self-joins prow_test_report_7d_matview 3 times:

  1. Outer query - gets the raw rows
  2. pass_rates subquery - computes per-variant percentages
  3. stats subquery - computes AVG/STDDEV across variants

The name/variant filters were only applied to the outermost query. Subqueries 2 and 3 scanned all rows for the release to compute aggregates for every test, even when only a single test was requested.

For release 4.22 with a name filter, this meant:

Before (outer only) After (pushed down)
Stats subquery Seq Scan, 1.28M rows Index Scan, 142
Estimated cost 802,603 - 1,137,530 7.53 - 1,371
Speedup - ~830x

TestsByNURPAndStandardDeviation now accepts optional filter functions (variadic, backward-compatible) that are applied to both the stats and pass_rates subqueries. The filter is still also applied to the outer query, so results are identical.

Summary by CodeRabbit

  • Chores

    • Improved backend test-query filtering to preserve cross-variant statistics by default and allow more precise variant-specific filters.
    • Optimized subquery filtering and application paths for more accurate and efficient aggregation of test stats and pass rates.
  • Bug Fixes

    • Fixed incorrect filter propagation so optional filters are applied to the intended subqueries, yielding more consistent results.

When collapse=false, TestsByNURPAndStandardDeviation builds a query
that self-joins prow_test_report_7d_matview 3 times:

  1. Outer query - gets the raw rows
  2. pass_rates subquery - computes per-variant percentages
  3. stats subquery - computes AVG/STDDEV across variants

The name/variant filters were only applied to the outermost query.
Subqueries 2 and 3 scanned all rows for the release to compute
aggregates for every test, even when only a single test was requested.

For release 4.22 with a name filter, this meant:

  |                    | Before (outer only)     | After (pushed down) |
  |--------------------|-------------------------|---------------------|
  | Stats subquery     | Seq Scan, 1.28M rows    | Index Scan, 142     |
  | Estimated cost     | 802,603 - 1,137,530     | 7.53 - 1,371        |
  | Speedup            | -                       | ~830x               |

TestsByNURPAndStandardDeviation now accepts optional filter functions
(variadic, backward-compatible) that are applied to both the stats and
pass_rates subqueries. The filter is still also applied to the outer
query, so results are identical.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci-robot
Copy link

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
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 2511559 and 9476a82.

📒 Files selected for processing (2)
  • pkg/api/tests.go
  • pkg/db/query/test_queries.go

Walkthrough

Adds a SubqueryFilter type and propagates optional subquery filters from the API into TestsByNURPAndStandardDeviation, which now accepts variadic filters and applies them (via funcs taking *gorm.DB) to stats and passRates subqueries before joining and aggregating.

Changes

Cohort / File(s) Summary
API: construct and pass filters
pkg/api/tests.go
When collapse is false, split raw filters into name/variant parts, build subquery filter functions (wrapping ToSQL as funcs accepting *gorm.DB), and pass them variadically to TestsByNURPAndStandardDeviation instead of calling it without filters. Added gorm import usage in this path.
Query: accept and apply filters
pkg/db/query/test_queries.go
Introduces SubqueryFilter type (Apply func(*gorm.DB) *gorm.DB; VariantOnly bool) and isVariantFilter helper. Updates TestsByNURPAndStandardDeviation signature to accept ...SubqueryFilter and applies non-variant filters to both stats and passRates subqueries and variant-only filters to passRates only. Preserves existing subquery construction and final join/aggregation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Single Responsibility And Clear Naming ⚠️ Warning The Apply field name in SubqueryFilter is too generic and doesn't evoke the specific concept of applying a database filter transformation, failing to meet the check's guidance on descriptive naming. Rename Apply to a more specific name like FilterFunc or ApplyFilter to clearly communicate that it applies a database filter transformation.
Sql Injection Prevention ❓ Inconclusive Source code files (pkg/api/tests.go and pkg/db/query/test_queries.go) required for SQL injection prevention analysis are not accessible in the repository. Verify repository clone integrity, ensure correct branch/commit checkout, and provide access to modified files for comprehensive SQL injection vulnerability assessment.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: pushing filters into test report subqueries with significant performance improvement, which is the core focus of the PR.
Go Error Handling ✅ Passed The pull request modifications demonstrate proper Go error handling patterns with no ignored errors, panic statements outside init/fatal conditions, or unhandled error returns.
Excessive Css In React Should Use Styles ✅ Passed The custom check for excessive CSS in React is not applicable; PR modifications only affect backend Go files with no React components or styling patterns.
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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

@openshift-ci openshift-ci bot requested review from dgoodwin and xueqzhan February 23, 2026 16:04
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 23, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: stbenjam

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 Feb 23, 2026
Copy link
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 the current code and only fix it if needed.

Inline comments:
In `@pkg/db/query/test_queries.go`:
- Around line 267-272: Applying all subqueryFilters to both stats and passRates
can alter stats semantics (delta/stddev); split filters so variant-specific
conditions only affect passRates. Update the loop over subqueryFilters to
classify each filter (e.g., via a new helper isVariantFilter(f) or a method on
the filter) and then apply: if isVariantFilter(f) { passRates = f(passRates) }
else { stats = f(stats); passRates = f(passRates) }; keep names subqueryFilters,
stats and passRates to locate the change and add the isVariantFilter helper
implementation to detect filters that reference variant-specific fields.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 327e327 and 2511559.

📒 Files selected for processing (2)
  • pkg/api/tests.go
  • pkg/db/query/test_queries.go

Variant-specific filters (e.g., NOT has entry "never-stable") must not
be pushed into the stats subquery, which computes AVG/STDDEV across all
variants for a test. Filtering out variants there would skew the
delta_from_*_average and standard deviation calculations.

Split SubqueryFilter into a struct with a VariantOnly flag and an
isVariantFilter helper. At the call site, the rawFilter is further
split: name filters go to both stats and passRates subqueries (safe,
just narrows to the matching test), while variant filters go only to
passRates (preserving cross-variant stats semantics).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci-robot
Copy link

Scheduling required tests:
/test e2e

@stbenjam
Copy link
Member Author

/test e2e

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 23, 2026

@stbenjam: 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/e2e 9476a82 link true /test e2e

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.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants