You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(catalog): keep plan tests independent of database statistics - #3674
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.
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.
ClosesSilo-Server#3634
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.
Silo-Server/silo-server#3537: Adds the personal-list page query whose index ordering is checked by one of these tests.
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: 5
Check name
Status
Explanation
Title check
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
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
[#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
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
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
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/S0–49 added + deleted lines (all files); change volume, not priority.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #3634
Related issue: N/A
Validation tasks: none
TestPersonalListPageFollowsAccessDBandTestRatingsPageIndexDBfail on unrelated pull requests in theGo DB pinsjob, depending on the statistics earlier tests left in the shared database. Both tests fail on anySortnode 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.TestDefaultRowQueriesWalkTypeIndexesPostgresalready disables the same two settings. Only test code changes.Validation
pgvector/pgvector:pg18with skewed statistics: the old tests failed 30 of 30 runs, and the new tests passed 30 of 30 on the same databases.idx_user_favorites_profileandidx_user_ratings_page_orderdropped, both tests still fail.gofmt,go mod tidy -diff,make lint-changed,make lint-router-recovery,make verify-local-paths,make verify-size-ratchetandmake verify-bidipass.make test-gopasses 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 becausepg_dumpandpg_restoreare not installed, so CI has to cover those.Evidence
Evidence: none, no user-visible change
Risks
None identified.
Checklist
AI Disclosure
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.assertPersonalListPagePlansandTestRatingsPageIndexDB. 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.