How to Detect Missing Database Indexes in Small Test Tables Using PostgreSQL
A common blind spot in test suites is the failure to catch missing database indexes when test tables contain only a small number of rows. PostgreSQL's query planner legitimately chooses sequential scans over index scans on small tables, making Seq Scan detection unreliable as a test signal. The workaround involves setting the PostgreSQL planner flag enable_seqscan to off, which penalises sequential scans and forces the planner to reveal whether a usable index exists. If a query still shows a Seq Scan after this setting is applied, it confirms that no suitable index is available, regardless of table size. This technique can be integrated into test frameworks like pytest with SQLAlchemy to automatically flag unindexed queries during development.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in