noCV
PQUERY-106 · Change the expensive paths

Replace deep offset paging with a stable inbox cursor

Practice briefStoryAdvanced

An operator reaches old open work through hundreds of pages. Each offset request scans and discards an increasing number of matching rows.

Focused work estimate
4h + prerequisites
Priority in the scenario
High
Engineering practice
Pagination · Query performance

Estimated field mix

  • Database engineering40%
  • API design40%
  • Performance engineering20%

Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.

Your next step

Review it, then add it to your workspace.

The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.

Project context

A fictional maintenance service lists open work orders beside years of closed history. A query that was cheap in a small demo now scans far more rows than it returns. Recreate the schema and synthetic workload locally; no customer database or supplied fixture is assumed.

Setup prerequisites

  • Create an isolated local database with tenants, work orders and assignment history.
  • Seed 200,000 synthetic work orders with documented skew and a repeatable random seed; record PostgreSQL version, settings and resource limits.

Preceding work

Complete these dependencies, or supply their agreed outputs before taking this ticket.

Acceptance criteria

  • Use a stable sort tuple with a unique tie-breaker and an opaque versioned cursor.
  • Bind the cursor to the tenant and filter contract; reject mismatched or malformed cursors.
  • Document concurrent-insert behavior and preserve a bounded page size without promising a snapshot across requests.

Implementation constraints

  • Measure shallow and deep page requests against the same fixture; keep the response contract explicit for clients migrating from offsets.

Verification to include

  • Traverse the unchanged fixture and compare all returned IDs with the expected sorted set without duplicates or omissions.
  • Insert a tied-timestamp row between requests and test the documented behavior; reject a cursor from another tenant.

Deliverables

  • Cursor contract, implementation and depth-comparison report

Rollout and recovery

Offer the cursor route as an explicit version and migrate the local client behind a switch; retain the offset route during rehearsal.

Value of the work

For the engineer: Practice reading execution plans, balancing read and write cost, and validating performance without weakening tenant boundaries.

For the team: Create reproducible query diagnostics and reversible index or query proposals for an operational application.

Evidence boundaries

Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.

Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.