NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle94 views

Пожалуйста, расскажите, какие части плана выполнения PostgreSQL вы обычно смотрите для оптимизации запросов?

Practice

Asked at

AI answer

I start with EXPLAIN (ANALYZE, BUFFERS), not just the estimated plan. I look at node types and join order, estimated and actual row counts (rows), the number of loops (loops), and discrepancies between estimates and reality. I check where Seq Scan, Index Scan, or Bitmap Scan are used, whether the filter conditions can use indexes, and whether many unnecessary rows are being read. For joins, I analyze the join type and the cost of intermediate results; for sorts and hash operations, I check whether they spill to disk. In BUFFERS, I compare cache hits with disk reads; in ANALYZE, I look at actual execution time. I also consider planner cost, statistics, and whether they’re up to date. EXPLAIN ANALYZE actually executes the query, so I use it cautiously with queries that modify data and in production.