---
title: "A query with no limit: measure what it reads and how fast that grows | Proofline"
description: "A missing-limit comment matters when the rows a query reads grow with use and a page people open often reads them."
url: https://proofline.sh/learn/ai-review-unbounded-query-comment/
---

[Learning center](/learn/)

# A query with no limit: measure what it reads and how fast that grows

A missing-limit comment matters when the rows a query reads grow with use and a page people open often reads them. Bound the read when those rows already number in the thousands or will soon. When you have measured them small, page the display, open an issue that records the size, and defer the read. Decline the comment when the data model itself caps the rows.

Code review The Proofline team November 22, 2026 4 min read

## Separate what the page shows from what the query reads

Reviewers raise this claim in two forms. One says a listing has no pagination at all. The other, which comes up more often in reviewed code, says the pagination is in the wrong place: the code reads every row into memory and then hands a list to a paginator. Django's [`Paginator`](https://docs.djangoproject.com/en/5.2/ref/paginator/) accepts "A list, tuple, `QuerySet`, or other sliceable object". Given a `QuerySet`, it counts in SQL and [slices the queryset](https://docs.djangoproject.com/en/5.2/topics/db/queries/#limiting-querysets), which Django turns into `LIMIT` and `OFFSET`. Given a list, the database work is already done, and the page size bounds only the HTML.

Paging in SQL has a cost of its own. PostgreSQL's documentation notes that "The rows skipped by an `OFFSET` clause still have to be computed inside the server; therefore a large `OFFSET` might be inefficient." [LIMIT and OFFSET](https://www.postgresql.org/docs/current/queries-limit.html) Moving to SQL paging fixes the read for early pages and shifts some cost to late ones.

## A claim that led to paging and an open issue

In August 2026, a Gyrinx pull request added a history page for each gang, built by folding ledger events into acts. CodeRabbit asked the author to "Bound the data loaded by history.build before it materializes events, while preserving complete \_clusters batches so act folding remains correct." [CodeRabbit review](https://github.com/gyrinx-app/gyrinx/pull/2222#pullrequestreview-4948585414)

The author paged the display. The commit reads: "The page is paged at 50 acts, newest first". [Commit 697b8a8](https://github.com/gyrinx-app/gyrinx/commit/697b8a8) A second commit added a query-count test: "Three queries whether the gang has five acts or sixty — the events, the records they name, and who is still on the roster, none of them per act." [Commit b3a933c](https://github.com/gyrinx-app/gyrinx/commit/b3a933c) The pull request merged on 17 August 2026.

Neither commit bounded the read, and the author said so in an issue opened the same day: "The rendered page is bounded — 50 acts — but the work behind it is not." The issue gives the reason a SQL window does not fit: "An act is several events. Grouping needs an act's neighbours, so a SQL window could split a batch and mis-tell it." It records a measurement on a synthetic gang, "286 events, 256 acts", at about 130 milliseconds for the whole build, and decides: "Not urgent at present sizes: a season's play is a few hundred acts, which is the measurement above." It sets the trigger for doing the work: "Worth doing before gangs are routinely thousands of acts deep." [Issue #2232](https://github.com/gyrinx-app/gyrinx/issues/2232)

The CodeRabbit comment was correct, and deferring the read was a reasoned choice. The issue names the current size, the cost at that size and the growth that would change the answer. It was still open when I read it in November 2026.

The query-count test in that pull request could not have caught the unbounded read. Three queries that each return every event pass a test that counts queries. If a claim is about how many rows a query reads, the test has to measure rows or time at a realistic size.

## The same claim, accepted as a known limit

In October 2026, a second Gyrinx pull request added an ownership history to each campaign asset. Copilot titled its finding "Pagination occurs after loading all ownership history", on these lines: [Copilot comment](https://github.com/gyrinx-app/gyrinx/pull/2794#discussion_r4174603237)

```
history = list(reversed(asset_ownership_history(holding)))
page = Paginator(history, 50).get_page(request.GET.get("page"))
```

The pull request description had already stated the limitation: "The 50-entry page limit bounds what is displayed, rather than the SQL read." "CPU and memory therefore grow with this holding’s ownership history." "a future optimisation needs to paginate complete transfer batches." [Pull request](https://github.com/gyrinx-app/gyrinx/pull/2794) The finding was still open in Copilot's later reviews, and the pull request merged on 4 October 2026 without a change to it.

This one grows more slowly than the gang history. The query filters on one holding, so its rows are the transfers of a single territory or asset. A description that states the limit beats a silent merge, but it is weaker than an issue with a measured trigger, because nothing will bring it back to anyone's attention.

## Decide by growth and caller

| Rows the query reads | Caller | Decision |
| --- | --- | --- |
| Capped by the data model, such as one row per setting or a fixed set of choices | Any | Dismiss. Cite the constraint |
| Grow with use, measured small today | An interactive page | Page the display if needed, and open an issue with the size, the cost and the trigger |
| Grow with use, already in the thousands for some users | An interactive page or API | Change. Bound the read in SQL, by keyset or `LIMIT` |
| Grow with use | A public API | Change. Require pagination and cap the page size |
| Read in full on purpose | A batch job | Keep the full read, but stream or chunk it so memory stays flat, as the [memory growth guide](/learn/ai-review-memory-growth-comment/) describes |

To fill in the first column, count the largest value in production if you can read it, or the largest you can construct in a fixture, as the Gyrinx issue did. Then ask how that number grows: per user action, per day or per tenant. A table that grows with every event and is read by a page opened many times a day earns the change sooner than one that grows with rare transfers. When the bot raises the same pattern on later pull requests, the open issue is the reply. The [follow-through guide](/learn/review-finding-follow-through/) covers tracking what happens to a deferred finding.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Will this collection really grow without limit? Find what removes entries](/learn/ai-review-memory-growth-comment/)
    
    Code review The Proofline team November 22, 2026 5 min read
    
-   ### [Count the queries before you answer an N+1 review comment](/learn/ai-review-n-plus-one-comment/)
    
    Code review The Proofline team November 22, 2026 4 min read
