perf(weave): skip zero-limit page queries - #7653
Open
gtarpenning wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
gtarpenning
marked this pull request as ready for review
July 28, 2026 22:47
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.
Summary
limit=0Why
Paginated agent queries return both
total_countand a page of rows. The sharedhandler currently issues both ClickHouse statements even when callers request
limit=0and only consumetotal_count.The zero-limit list statement reads no rows or bytes, but it still pays to parse,
analyze, and plan the normal spans-list query, including sorting, trace
attribution, a self-join, aggregation, and set construction.
Production evidence
Read-only production measurements used active projects at the p50, p95, and
maximum span-volume points from the preceding 24 hours. Each result is the
median of three executions against a fixed snapshot:
The zero-limit statement reported zero rows and zero bytes read in every run.
Skipping it removes one ClickHouse statement per count-only request. At the
observed volume of roughly 560k requests per day, that is roughly 560k fewer
statements per day.
The count statement also reduced bytes read:
EXPLAIN indexes=1For the p95 project, both the old aggregation and count query narrowed the
primary key to 99 of 295,262 granules. The count query then used:
The zero-limit list plan still contained:
ClickHouse ultimately reduced the attribution branch to
Ranges: 0, explainingthe zero data read, but the full list plan still had to be constructed.
Behavior
limit=0: execute the count query once, return itstotal_count, and returnan empty row list
limit>0: continue executing the existing count and list query pairValidation
uv run --group test python -m pytest tests/trace_server/test_genai_agent_query_handler.py -v— 3 passeduvx ruff check weave/trace_server/agents/clickhouse.py tests/trace_server/test_genai_agent_query_handler.pyuvx ruff format --check weave/trace_server/agents/clickhouse.py tests/trace_server/test_genai_agent_query_handler.pygit diff --check