A missing index turns a query into a silent full table scan
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
A database query filtering on an unindexed column performs a full table scan. In SQLite or PostgreSQL, the engine must inspect every single row sequentially on disk to evaluate the WHERE predicate. When the dataset is small during initial local testing with dozens of rows, this scan takes a fraction of a millisecond and feels instantaneous. However, as the table grows to hundreds of thousands or millions of records in production, the time taken scales linearly with the row count (O(N)). The query does not crash, return an error status, or trigger an alert immediately; it simply consumes more CPU cycles, monopolizes disk I/O, and causes connection starvation under concurrent traffic. Because no explicit exception is thrown, developers often only discover the problem when server response times spike, background workers time out, or database connection pool limits are exceeded.
Minimal reproduction
Without an index on category
EXPLAIN QUERY PLAN SELECT * FROM products WHERE category = 'gadgets';
Engine performs a SCAN of products inspecting every row.
The fix
Inspect the query plan using EXPLAIN QUERY PLAN (in SQLite) or EXPLAIN ANALYZE (in PostgreSQL). Look specifically for SCAN indicating that the database is reading the entire table rather than traversing an index. Add a B-tree index on the exact column or set of columns referenced in the filter, join condition, or sorting order (for , CREATE INDEX idx_products_category ON products(category)). When the index is in place, the query plan switches from SCAN to SEARCH USING INDEX, transforming the lookup complexity from linear O(N) to logarithmic O(log N). Be mindful that indexes are not completely free: every index incurs storage overhead and adds a small write penalty to INSERT, UPDATE, and DELETE operations because the index tree must be rebalanced on changes.
With a B-tree index on category
CREATE INDEX idx_products_category ON products(category);
EXPLAIN QUERY PLAN SELECT * FROM products WHERE category = 'gadgets';
Engine uses SEARCH products USING INDEX idx_products_category.