THN Interview Prep

Database query path

Core details

Repeatable workflow

  1. Find query text — slow query log, pg_stat_statements (Postgres) or vendor equivalent.
  2. EXPLAIN (ANALYZE)estimated vs actual rows; huge gap ⇒ stale statistics or bad parameter sniffing class issues.
  3. Access path — seq scan vs index vs bitmap; why did the optimizer choose it?
  4. Locks / waitspg_locks, wait events—low CPU + high latency often waiting, not “slow query.”
  5. Replica vs primaryread-your-writes and lag; intermittent “bugs” may be stale replica.

Write-path awareness

Indexes speed reads and cost writes. Hot updates on wide indexes → bloat and contention.

Understanding

“Add an index” without plan proof is index theater. Often the fix is narrower SELECT, batching, keyset pagination, or fresh stats—not more B-trees.

Use the diagnostic map below to keep the investigation honest: start from one measured query, split plan errors from wait states and replica lag, change one thing, then verify latency and write-path cost.

Database query path diagnostic workflow: slow log to EXPLAIN ANALYZE, planner proof, wait proof, freshness proof, and verified fixes.

Senior understanding

SymptomFirst split
High latency, low DB CPUlocks, disk, replication lag, pool wait
Plan flips across daysstats, skew, prepared statement plans

Deep relational + caching narrative: /databases and Indexing & query tuning.

Diagram

Loading diagram…

See also

Mark this page when you finish learning it.

Spotted something unclear or wrong on this page?

On this page