noCV
PQUERY-107 · Change the expensive paths

Explain the bad prepared plan used for the largest tenant

Practice briefBugExpert

The same prepared inbox statement serves tiny tenants and the dominant tenant. A plan that works for one distribution performs poorly for the other.

Focused work estimate
5h 30m + prerequisites
Priority in the scenario
Medium
Engineering practice
Query planning · Data skew

Estimated field mix

  • Database engineering60%
  • Performance engineering40%

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

  • Reproduce the plan difference with documented preparation and execution sequences.
  • Compare statistics correction, query restructuring and bounded per-query planning choices; select a justified option.
  • Keep tenant scope and result ordering unchanged, and document planning overhead as part of the decision.

Implementation constraints

  • Do not change a global planner setting as an unexplained workaround; record the exact PostgreSQL version because planning behavior matters.

Verification to include

  • Alternate large and small tenant executions across repeated sessions and retain planning plus execution measurements.
  • Rebuild statistics after a distribution change and verify the selected solution remains correct or clearly flags an invalid baseline.

Deliverables

  • Prepared-plan reproduction and a supported mitigation with regression cases

Rollout and recovery

Limit any configuration change to the affected query path; remove it and restore the baseline query if small-tenant latency breaches its budget.

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.