Parece simples até o entrevistador perguntar "why?". Abaixo, uma estrutura de resposta que dá conta do follow-up.
Additional data structures that can accelerate filters, joins, or ordering by avoiding some scanning or sorting. They consume storage and add write maintenance. A planner may still prefer a sequential scan when many rows match.
Choose indexes for actual queries and inspect plans with representative data. Composite column order, selectivity, and index type matter. A boolean can support a useful partial index when the queried subset is small. PostgreSQL does not automatically index every foreign key's referencing columns.EXPLAIN (ANALYZE, BUFFERS) executes the statement. Run experiments on a disposable local database, especially for writes, and compare measured plans before and after the index.
Sources: PostgreSQL partial indexes and EXPLAIN.
Ler é o primeiro passo. No app, essa pergunta vira flashcard com repetição espaçada, e o módulo tem quiz e simulado para testar o que ficou.
Treinar essa pergunta no app