0Pricing
PostgreSQL Performance & Query Optimization · Aula

Lendo a saída de EXPLAIN e EXPLAIN ANALYZE

Decodifique os planos de consulta do PostgreSQL com EXPLAIN para ver como o planejador executa uma consulta e onde o tempo é realmente gasto.

Lendo a saída de EXPLAIN e EXPLAIN ANALYZE é uma aula grátis de PostgreSQL Performance & Query Optimization no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de PostgreSQL Performance & Query Optimization, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de PostgreSQL Performance & Query Optimization inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Why Read Query Plans

Before tuning a slow query, see what PostgreSQL actually does. EXPLAIN shows the planner's chosen execution plan as a tree of nodes.

EXPLAIN vs EXPLAIN ANALYZE

EXPLAIN shows estimates only; EXPLAIN ANALYZE actually runs the query and reports real timings and row counts — far more useful for diagnosis.

EXPLAIN ANALYZE
SELECT * FROM orders WHERE customer_id = 42;

The Plan Tree

Read plan trees inside-out and bottom-up: leaf nodes scan data, parents join or aggregate. Each node reports its cost, rows, and width.

The cost Numbers

The cost reads as cost=0.00..18.45: first is startup cost, second is total, both in arbitrary planner units used to compare competing plans.

Sequential Scan

A Seq Scan reads the whole table — fine for small tables or when most rows match, but a red flag on a selective query over a large one.

Index Scan

An Index Scan uses an index to find matching rows, then fetches them from the table. It's the win for selective predicates.

Estimated vs Actual Rows

Compare estimated rows with actual rows. A big mismatch means stale statistics and often a bad plan — run ANALYZE to refresh them, as shown below.

ANALYZE orders;

Spotting the Bottleneck

To find the bottleneck, hunt for the node with the largest actual time, or one whose loops multiply its cost. That's where to focus tuning.

BUFFERS for I/O Insight

Add BUFFERS to your EXPLAIN to see how many pages came from cache versus disk — the fast way to spot I/O-bound queries. See the example below.

EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM orders WHERE total > 100;

Join Strategies

Watch the join strategy: Nested Loop, Hash Join, or Merge Join. A Nested Loop over many rows without an index is a classic slow pattern.

Readable Formats

For big plans, switch to FORMAT JSON or a visual tool to explore them more easily. The query below shows the JSON option.

EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM orders;

Quick Check

Test what you have learned.

Recap

Recap: read EXPLAIN trees, compare estimates with ANALYZE actuals, tell Seq from Index scans and join types, use BUFFERS, and find the bottleneck node.

Perguntas Frequentes

A aula “Lendo a saída de EXPLAIN e EXPLAIN ANALYZE” é grátis?

Sim — o texto completo de “Lendo a saída de EXPLAIN e EXPLAIN ANALYZE” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de PostgreSQL Performance & Query Optimization, atualize para CoddyKit PRO. O curso de PostgreSQL Performance & Query Optimization inclui 4 aulas no total.

O que vou aprender em “Lendo a saída de EXPLAIN e EXPLAIN ANALYZE”?

Decodifique os planos de consulta do PostgreSQL com EXPLAIN para ver como o planejador executa uma consulta e onde o tempo é realmente gasto. Você pratica PostgreSQL Performance & Query Optimization com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar PostgreSQL Performance & Query Optimization?

Nenhuma experiência prévia é necessária. PostgreSQL Performance & Query Optimization no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Lendo a saída de EXPLAIN e EXPLAIN ANALYZE”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de PostgreSQL Performance & Query Optimization?

Sim. Cada aula de PostgreSQL Performance & Query Optimization inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Entendendo os fundamentos do desempenho de bancos de dados
  2. Visão geral da arquitetura do PostgreSQL
  3. Fluxo básico de execução de consultas
  4. Lendo a saída de EXPLAIN e EXPLAIN ANALYZE
← Voltar para PostgreSQL Performance & Query Optimization