A query can look index-friendly and still be slow in production. Before suggesting CREATE INDEX, I prefer to record a small set of facts: what the planner estimates, what actually executes, how tenant values differ, and what extra writes the proposed index would cause.

Below is a worked illustration, not a benchmark taken from a client's database.

The query shape

Imagine an API or analytics pipeline reading the 50 most recent pending events for a tenant:

SELECT id, tenant_id, event_type, payload, created_at FROM event_telemetry WHERE tenant_id = $1 AND status = 'pending' AND created_at >= NOW() - INTERVAL '7 days' ORDER BY created_at DESC LIMIT 50; 

The equality filter on tenant_id, timestamp range, and ordered LIMIT make a composite partial index plausible:

CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_telemetry_pending_tenant_created ON event_telemetry (tenant_id, created_at DESC) INCLUDE (id, event_type) WHERE status = 'pending'; 

This is a candidate to test, not a deployment instruction.

Five things to verify

1. Real plans, not guesses. Ask for EXPLAIN (ANALYZE, BUFFERS) in a safe, approved environment for the relevant read-only SELECT. ANALYZE executes the query. Capture the actual/estimated rows, loop counts, heap fetches, buffer hits/reads, sort nodes, and wall-clock information. For write statements, normal EXPLAIN ANALYZE executes writes, so never run it casually in production.

2. Tenant skew and predicate selectivity. If one tenant owns most rows while others have tiny datasets, a plan measured for a small tenant may misrepresent the heavy one. Likewise, a partial predicate status = 'pending' is only selective if the distribution supports it. Check representative workloads rather than a single parameter.

3. What the index does not cover. The query returns payload. Including a large JSON/JSONB payload just to avoid heap visits could make the index expensive to maintain. INCLUDE (id, event_type) is an explicit compromise; inspect the actual plan to see whether extra heap access matters.

4. Writes, locks and maintenance. More indexes mean more work for INSERT/UPDATE/DELETE, with potential disk and cache impact. CREATE INDEX CONCURRENTLY is operationally useful but must run outside an explicit transaction block; a failed build may require cleanup. Coordinate changes through normal deployment/rollback procedures.

5. Compare like with like. Test against a baseline using representative parameters, data and load. Record plan changes, buffer behavior, latency distribution, and write impact. A before/after number without controlled conditions is not evidence of a reliable gain.

A bounded review process

For each slow query, I document: the business operation affected, query text with sensitive values removed, PostgreSQL version, relevant indexes/schema, a safe plan capture, most likely bottleneck, and two or three changes worth testing. Then I list validation commands, trade-offs, and rollback steps. That report is useful even if the right outcome is not adding an index.

I published the fuller walkthrough and example SQL in my own GitHub portfolio:

PostgreSQL Slow Queries — Evidence-Based Audit Walkthrough

I also offer a fixed-scope paid audit (up to three queries, USD 300, written report within 48 hours after agreeing scope and receiving suitable sanitized plans). Contact details are on the linked repository, or email zongsm@gmail.com. No production credentials are requested over email, and no percentage speedup is promised without measurements.

Question for practitioners: When tenant_id is highly skewed, how do you sample representative plans before deciding whether a partial index is worth the extra writes?

Disclosure: This article links to my own technical/commercial portfolio. Drafting was AI-assisted; the example and its limitations are from the published technical note. No client performance figures are claimed.