Sobes.tech
Junior — Middle

What can cause PostgreSQL to remove or disable an index for a specific table or query?

sobes.tech AI

Answer from AI

PostgreSQL may not use an index for a specific query or table for several reasons:

  • Small data volume: if the table is very small, the planner may decide that sequential scanning is faster than using an index.

  • Low index selectivity: if the index does not significantly reduce the number of rows (for example, many repeated values), PostgreSQL may choose not to use it.

  • Outdated or missing statistics: if the table statistics are not current, the planner may make an incorrect decision.

  • Query types and conditions: some operations (e.g., LIKE with a pattern at the beginning, functions on an indexable column) cannot efficiently utilize an index.

  • Configuration parameters: settings such as enable_indexscan can disable index usage.

  • Fragmentation or index corruption: rarely, but it can affect performance.

For diagnostics, use EXPLAIN ANALYZE and update statistics with the ANALYZE command.