Repository navigation
Conversation
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
marked this pull request as ready for review
November 30, 2026 02:14
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A
type:reposub-query (Sourcegraph'srepo: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 aRepoIDs,RepoSetorBranchesRepos, 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. ABranchesReposlimits 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%.