Skip to content

search: limit type:repo sub-queries to the query's repositories - #1306

Open
eseliger wants to merge 1 commit into
mainfrom
es/type-repo-scope
Open

eseliger wants to merge 1 commit into
mainfrom
es/type-repo-scope

Conversation

@eseliger

Copy link
Copy Markdown
Member

A type:repo sub-query (Sourcegraph's repo:has.content(...)) is evaluated on its own: Zoekt lists the repositories that match it and replaces it with their names. That listing ran over every loaded shard, even when the query is limited to a few repositories by a RepoIDs, RepoSet or BranchesRepos, so a search of 20 repositories on a webserver with 2000 paid for the sub-query in all 2000. Because the replacement is a set of names, a repository outside the limit also selected a repository inside it that shares its name.

The sub-query is now listed only in the repositories the query is limited to: the repository filters reached from the top of the query through Ands. A BranchesRepos limits the listing by its repositories and not by its branches, so a repository still matches on any indexed branch, as before. Results change only for repositories that share a name.

On a benchmark with 2000 single-shard repositories, a query limited to 20 of them goes from 1.6–2.9 ms to 0.24–0.44 ms. A query limited to all 2000 has nothing to skip and pays for one more shard selection pass: 0.15–0.4 ms on 4–10 ms, up to 8%.

A `type:repo` sub-query (Sourcegraph's `repo:has.content(...)`) is evaluated on its own: Zoekt lists the repositories that match it and replaces it with their names. That listing ran over every loaded shard, even when the query is limited to a few repositories by a `RepoIDs`, `RepoSet` or `BranchesRepos`, so a search of 20 repositories on a webserver with 2000 paid for the sub-query in all 2000. Because the replacement is a set of names, a repository outside the limit also selected a repository inside it that shares its name.

The sub-query is now listed only in the repositories the query is limited to: the repository filters reached from the top of the query through `And`s. A `BranchesRepos` limits the listing by its repositories and not by its branches, so a repository still matches on any indexed branch, as before. Results change only for repositories that share a name.

On a benchmark with 2000 single-shard repositories, a query limited to 20 of them goes from 1.6–2.9 ms to 0.24–0.44 ms. A query limited to all 2000 has nothing to skip and pays for one more shard selection pass: 0.15–0.4 ms on 4–10 ms, up to 8%.

Amp-Thread-ID: https://ampcode.com/threads/T-e5fb710e-10b9-4ebe-a455-163f6e6c8538
@eseliger
eseliger marked this pull request as ready for review November 30, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant