openlang

Should the total and the page share one snapshot?

Partly reviewed

A hypothetical reporting screen first counts 12 matching orders. Another session inserts a matching order and commits. The screen then fetches the first page under Read Committed.

In PostgreSQL 18, each SELECT uses a snapshot from its own statement start, so the total can describe the earlier set while the page includes the newly committed order. Putting both SELECTs in a transaction does not by itself give them the same snapshot at Read Committed.

The intended rule is that the count and rows describe the same report, even if newer orders exist by display time. Would one Repeatable Read transaction around both reads express that rule clearly, or should the report come from one combined query? I would display the pair together whichever approach supplies it.

The conversation continues 1

Follow the reasoning
  1. Permalink

    A combined query would make the pair one read operation. I would also replace the displayed pair together, since publishing each half independently can reintroduce a mixed report in the interface. Repeatable Read can supply a shared snapshot too, provided both reads belong to that transaction.