Skip to content

fix(plumber): index keyset listings filtered by git ref type - #1378

Open
adbatista wants to merge 5 commits into
mainfrom
adb/plumber-keyset-ref-type-index
Open

adbatista wants to merge 5 commits into
mainfrom
adb/plumber-keyset-ref-type-index

Conversation

@adbatista

Copy link
Copy Markdown
Contributor

📝 Description

Project-page listings in all-pipelines mode filtered by a single ref type (e.g. "Pull Requests only") timed out on large projects. With the ref type bound as = ANY($n) under a generic plan, Postgres walked pipeline_requests_project_id_inserted_at_id and filtered row by row until it found a page, scanning the whole project history when matches were rare, and hit the 15s pool timeout.

Add a (project_id, git_ref_type, inserted_at DESC, id DESC) partial index and compare a single ref type as a scalar, so the index returns rows already ordered and the scan stops at the page limit. Multiple ref types keep using ANY.

✅ Checklist

  • I have tested this change
  • This change requires documentation update

Project-page listings in all-pipelines mode filtered by ref type (e.g.
"Pull Requests only") timed out on large projects. With the ref types
bound as `= ANY($n)`, Postgres walked the project's history newest first
and filtered row by row, reading thousands of rows when the type was
rare and the whole history when it had none.

Compare a single ref type as a scalar. For several types, query each
one separately with its own order, keyset cursor and page limit inside
a subquery, then merge them. Postgres does not push an outer ORDER BY
or LIMIT into UNION ALL branches that have WHERE clauses, and with a
project/ref-type index a generic plan for `= ANY($n)` fetches and sorts
every matching row. Each branch now reads at most one page.
Add a (project_id, git_ref_type, inserted_at DESC, id DESC) partial
index on initial pipeline requests, built concurrently. Ref-type
filtered listings read it in order and stop at the page limit instead
of walking the project's history.

Ship together with the per-type keyset queries: the previous
`= ANY($n)` query picks a bitmap scan and sort over every matching row
once this index exists.
@adbatista
adbatista force-pushed the adb/plumber-keyset-ref-type-index branch from 212f56d to 6e9103b Compare October 29, 2026 17:58
@adbatista
adbatista marked this pull request as ready for review October 29, 2026 17:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T18:52:23.425980Z 2dd0103 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e9103b4a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A repeated value in git_ref_types (e.g. ["branch", "branch"]) built
identical UNION ALL branches, so every matching workflow came back once
per repeat and took extra slots on the page. The previous IN filter
treated the values as a set; do the same before splitting per type.

[api] Deduplicate git_ref_types before building per-type keyset queries
[test] Cover duplicate ref types in the SQL shape and in returned pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant