Skip to content

test(catalog): keep plan tests independent of database statistics - #3674

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/plan-tests-db-statistics
Nov 9, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/plan-tests-db-statistics

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3634
Related issue: N/A
Validation tasks: none

TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB fail on unrelated pull requests in the Go DB pins job, depending on the statistics earlier tests left in the shared database. Both tests fail on any Sort node in the plan. With few rows, the planner can choose a sort in an access-check subplan (personal lists) or in the page read itself (ratings), even though the index can supply the page order.

This change makes both tests fail only when no index can supply that order.

Approach

Both plan transactions now also run SET LOCAL enable_sort = off. Postgres then picks a plan without a sort whenever one exists, and still plans the disabled sort when none does, so the assertion keeps its meaning. TestDefaultRowQueriesWalkTypeIndexesPostgres already disables the same two settings. Only test code changes.

Validation

  • Reproduced each failure on pgvector/pgvector:pg18 with skewed statistics: the old tests failed 30 of 30 runs, and the new tests passed 30 of 30 on the same databases.
  • With idx_user_favorites_profile and idx_user_ratings_page_order dropped, both tests still fail.
  • Go build, vet, gofmt, go mod tidy -diff, make lint-changed, make lint-router-recovery, make verify-local-paths, make verify-size-ratchet and make verify-bidi pass.
  • make test-go passes except four packages (internal/api/handlers, internal/backup, internal/ebookconvert, internal/uploads) that reject the group-writable temp directories from a local umask of 0002. All four pass with umask 022.
  • make test-db-pins: all 165 pins pass and both changed tests pass. 32 backup contracts skipped locally because pg_dump and pg_restore are not installed, so CI has to cover those.
  • Web checks and the generated-contract checks were not run, since no web, API or generated code changes.

Evidence

Evidence: none, no user-visible change

Risks

None identified.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code; Codex CLI (review)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent medium-effort reviews of the full diff by claude-opus-5-5 and gpt-6.1-sol covering correctness, standards and spec; neither reported findings.

Note

Disable sort plans in catalog page query EXPLAIN tests

Adds transaction-local planner settings that discourage sort plans alongside sequential scans before running EXPLAIN in catalog.assertPersonalListPagePlans and TestRatingsPageIndexDB. Tests still fail if a Sort node appears or the expected index is missing. See personal_list_page_db_test.go and ratings_page_index_db_test.go.

Macroscope summarized 8873acb.

The personal list and ratings plan tests failed on any Sort node, so
statistics left in a shared database could fail them even when the index
can supply the page order. Disable sorts in their plan transactions: a
sort still appears when no index can supply the order.

Closes Silo-Server#3634
@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Nov 8, 2026
@silo-kody

silo-kody Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The personal-list and ratings page-plan tests now disable local sorts as well as sequential scans. Their comments describe how shared database statistics can affect index selection and page ordering.

Changes: Catalog page-plan tests

Layer / File(s) Summary
Make page-plan checks independent of sort selection
internal/catalog/personal_list_page_db_test.go, internal/catalog/ratings_page_index_db_test.go
Both test transactions disable local sorts while checking that the expected index supplies page order. Comments describe how shared statistics can affect planner choices and note that sorting remains possible when no index supplies the order.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Low

Possibly related PRs

Suggested labels: go

Suggested reviewers: blurbery, quick104

Merge Risk: Low · up to 8873a

The plan checks may pass even when an index cannot supply the complete page order. This affects test confidence, not production query behavior.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change, which is making the plan tests independent of database statistics in the catalog package. It uses the conventional test(scope) prefix and fits the changeset, which add…
Description check Passed The description states the problem, the approach, validation steps, and an evidence statement. It directly describes the changed tests (TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB) …
Linked Issues check Passed [#3634] Directly linked issue #3634 asks that TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB fail only when no index can supply page order, not because of shared-database statistic…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes only two files: internal/catalog/personal_list_page_db_test.go and internal/catalog/ratings_page_index_db_test.go. Both changes are test code. Each…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change, which is making the plan tests independent of database statistics in the catalog package. It uses the conventional test(scope) prefix and fits the changeset, which adds SET LOCAL enable_sort = off to two plan transactions. It is specific enough for a reader scanning history.

Full details: Description check

Explanation

The description states the problem, the approach, validation steps, and an evidence statement. It directly describes the changed tests (TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB) and the SET LOCAL enable_sort = off change, so it is related to the changeset.

Full details: Linked Issues check

Explanation

[#3634] Directly linked issue #3634 asks that TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB fail only when no index can supply page order, not because of shared-database statistics. The proposed remedy is SET LOCAL enable_sort = off in both plan transactions. The reviewed head implements this in both tests:

  • internal/catalog/personal_list_page_db_test.go, assertPersonalListPagePlans: the transaction now runs SET LOCAL enable_seqscan = off; SET LOCAL enable_sort = off. The assertion still requires idx_<list>_profile in the plan and rejects "Node Type": "Sort".
  • internal/catalog/ratings_page_index_db_test.go, TestRatingsPageIndexDB: the same SET LOCAL statement is added. The existing index and Sort assertions are unchanged.
    The assertion logic is preserved. A sort still appears in the plan when no index supplies the order, so the tests still fail in that case. The PR author reports a mutation check that drops both indexes and shows both tests failing. I did not re-run the tests. The Postgres planner behavior the PR relies on is the author's report. The check matches the exact node type Sort, so the top-level Incremental Sort in the issue's log is not matched. That behavior is pre-existing and not changed by this PR.
Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes only two files: internal/catalog/personal_list_page_db_test.go and internal/catalog/ratings_page_index_db_test.go. Both changes are test code. Each change adds the enable_sort = off setting that the linked issue #3634 requests. The comment edits in both files explain the same setting. No production code, schema, web, or generated code changes. No unrelated change was found.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 8, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a02418d-0159-435c-bb27-0e1cee9494cb
Commits

Reviewing files that changed from the base of the PR and between f69e14a and 8873acb.

Files selected for processing: 2

  • internal/catalog/personal_list_page_db_test.go
  • internal/catalog/ratings_page_index_db_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@Quick104

Quick104 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Reviewed head 8873acbe22. I found nothing to fix, so I haven't pushed anything to this branch.

What I checked

  • Ratings test. I ran the full internal/catalog package once against a scratch pgvector/pgvector:pg18 database. After that, TestRatingsPageIndexDB failed 30 of 30 runs on the base and passed 30 of 30 on this head, using the same database.
  • Personal-list test. It didn't fail with those statistics. With enable_hashjoin and enable_nestloop also off in the plan transaction, the base planned the [bug] Plan tests TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB fail depending on shared test DB statistics #3634 shape (Merge Join over a Sort in the access subplan) and failed 3 of 3. This head passed 3 of 3.
  • Missing or unusable index. Inside each plan transaction, I dropped idx_user_ratings_page_order and each list's _profile index, or replaced it with a same-name index on (user_id, profile_id). Every case failed on this head with a Sort node, as it does on the base.
  • Incremental Sort. A ratings index without the media_item_id tie-breaker passes on both base and head, because both checks accept Incremental Sort. That is the gap from the CodeRabbit thread. It predates this PR, this PR doesn't widen it, and the shipped index covers the full order.

Validated features: none affected. Only two DB test files change.
User manual: unaffected. Apple/Android parity: not applicable.
Cross-provider round: skipped because no runtime behavior changes.

Fit: 9/10 · Readiness: 9/10 — ready

Fit: a test-only fix for required CI checks that fail on unrelated PRs. It uses the planner settings TestDefaultRowQueriesWalkTypeIndexesPostgres already sets. Readiness: both failures reproduced on the base and are gone on this head. Both tests still fail when no index supplies the page order.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 7d1e761 into Silo-Server:main Nov 9, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/S 0–49 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Plan tests TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB fail depending on shared test DB statistics

2 participants