Your App Got Slow at 1 Million Rows: The Database Indexes Most Startups Never Add

Your database slowed down at 1 million rows. Learn which indexes most startups miss, how to read a query plan, and Postgres index best practices that scale.

Your App Got Slow at 1 Million Rows: The Database Indexes Most Startups Never Add

The query ran fine for months. Then one morning, a page that loaded in 200 milliseconds starts taking four seconds. Nothing changed in the application code. No new deploy. No spike in traffic. The only thing that changed was the row count in one table quietly crossing a million, and a query that used to scan a manageable dataset now scans enough rows to bring your P95 latency into unacceptable territory.

This is one of the most common inflection points for growing applications, and it catches teams off guard because the symptoms look like an infrastructure problem. Someone suggests upgrading the database instance. Someone else floats adding a read replica. These are expensive answers to what is usually a foundational indexing problem — the kind of soil work that should have been done early but is easy to skip when everything is fast on a small dataset.

Why Indexes Get Skipped in the First Place

Most startups begin with an ORM generating their queries and a migration tool generating their schema. The ORM handles the primary key index automatically. Beyond that, engineers tend to add indexes reactively — after something breaks — rather than designing them alongside the data model.

There are real reasons for this. Early on, every table fits in memory. A sequential scan across 10,000 rows is imperceptible. The team is shipping features, not optimizing queries. And indexing decisions require understanding access patterns that may not be fully known yet.

The problem is that by the time the slowdown hits, the team is often under pressure. A founder debugging a slow dashboard at one million rows does not have the luxury of a careful indexing audit. The fix gets rushed, and it is frequently the wrong index — or too many indexes, which introduces its own costs.

How to Read a Query Plan (The Skill That Pays for Itself)

Before you add any index, you need to understand what the database is actually doing with your query. In Postgres, this starts with EXPLAIN ANALYZE.

Run EXPLAIN ANALYZE before your slow query, and Postgres will execute it and return the plan it chose, including actual row counts and timing at each step. Here is what to look for:

Sequential Scan (Seq Scan)

This means Postgres is reading every row in the table and filtering as it goes. On a small table, this is fine — sometimes even faster than an index lookup. On a table with a million-plus rows, a sequential scan on a filtered query is almost always the bottleneck. If you see Seq Scan on a large table with a Filter removing most of the rows, that is your signal.

Index Scan vs. Index Only Scan

An Index Scan means Postgres found and used an index, then went back to the table (the heap) to fetch the remaining columns. An Index Only Scan means the index contained everything the query needed — no heap access required. The second is faster, and you can design for it with covering indexes (more on that below).

Rows Removed by Filter

This number tells you how much wasted work the database did. If a step scanned 900,000 rows and removed 899,000 by filter, the engine did almost a million row reads to return a thousand results. An index on the filter column would let it skip directly to those thousand rows.

Nested Loop with Inner Seq Scan

This appears in joins and is often the most expensive pattern in a slow query. It means for each row from one side of the join, Postgres is doing a full sequential scan of the other table. If the outer set has 10,000 rows and the inner table has a million, you are scanning a million rows ten thousand times. An index on the join column of the inner table changes this from O(n*m) to O(n*log m).

Learning to read a query plan is foundational. It turns database performance from guesswork into engineering.

The Five Indexes Most Startups Miss

These are not exotic. They are the straightforward, high-impact indexes that consistently go unbuilt in early-stage applications.

1. Foreign Key Columns

Postgres does not automatically index foreign key columns. This surprises many engineers, because the constraint exists and the ORM shows the relationship. But the constraint only enforces referential integrity — it does not create an index. Every JOIN on an unindexed foreign key becomes a sequential scan on the child table as the dataset grows.

If you have an orders table with a customer_id foreign key, and you are querying orders by customer, that column needs an index. This is the single most common missing index in growing applications.

2. Columns in WHERE Clauses on Status or Type Filters

Almost every application has queries that filter on a status column — WHERE status = 'active' or WHERE type = 'subscription'. These columns tend to have low cardinality (a small number of distinct values), which sometimes leads engineers to skip the index because they remember reading that low-cardinality indexes are not useful.

That advice is incomplete. A partial index — CREATE INDEX idx_orders_active ON orders (created_at) WHERE status = 'active' — is smaller than a full index and precisely targeted. If 90% of your queries filter to the 10% of rows that are active, a partial index is one of the most efficient structures Postgres offers.

3. Composite Indexes That Match Query Patterns

A single-column index on customer_id helps with WHERE customer_id = ?. But if your application consistently queries WHERE customer_id = ? AND status = 'active' ORDER BY created_at DESC, a composite index on (customer_id, status, created_at DESC) lets Postgres satisfy the filter and the sort in a single index traversal.

Column order matters. Postgres uses a composite index left to right. If the first column in the index is not in the query, the index will not be used. Design composite indexes around your actual query patterns, not your table structure.

4. Covering Indexes for Dashboard and List Queries

A covering index includes all columns a query needs, eliminating the heap lookup entirely. In Postgres, you can use the INCLUDE clause: CREATE INDEX idx_orders_summary ON orders (customer_id, status) INCLUDE (total, created_at).

This is especially effective for list pages and dashboards — queries that select a handful of columns from a filtered, sorted set. The difference between an Index Scan with heap access and an Index Only Scan can be significant at scale, particularly on tables with wide rows where heap pages are expensive to fetch.

5. Expression Indexes for Computed Lookups

If your application queries WHERE LOWER(email) = ?, a standard index on email will not help — Postgres cannot use it because the query applies a function. You need an expression index: CREATE INDEX idx_users_email_lower ON users (LOWER(email)).

The same applies to date truncation (WHERE DATE(created_at) = ?), JSON field access, and any computed expression in a WHERE clause. If the query transforms the column before comparing, the index must match that transformation.

The Cost Side: Why You Should Not Index Everything

Every index has a write cost. When you insert, update, or delete a row, every index on that table must also be updated. On a write-heavy table — event logs, analytics events, IoT telemetry — too many indexes slow down ingestion and increase storage.

There is a real trade-off here. The goal is not maximum indexes; it is the right indexes for your actual access patterns. This is why reading query plans matters more than following a checklist. The plan tells you what is slow. The index targets that specific bottleneck.

A few additional costs to track:

  • Index bloat — on tables with heavy updates, indexes accumulate dead tuples. Regular REINDEX or pg_repack maintenance keeps them efficient.
  • Planner confusion — too many overlapping indexes can cause the query planner to choose a suboptimal path. Periodically review pg_stat_user_indexes to identify indexes with zero scans.
  • Migration lock time — CREATE INDEX locks the table by default. On a production database with a million-plus rows, use CREATE INDEX CONCURRENTLY to avoid blocking writes during the build.

A Practical Starting Sequence

If you are facing a slowdown right now, here is a grounded approach:

  1. Identify the slow queries. Enable pg_stat_statements if you have not already. Sort by total time and mean time. The top five queries by total time are where you start.
  2. Run EXPLAIN ANALYZE on each. Look for sequential scans on large tables, high rows-removed-by-filter counts, and nested loops with inner sequential scans.
  3. Check foreign key columns first. Missing foreign key indexes are the most common finding and the easiest win.
  4. Design composite indexes around query patterns. Do not guess — look at the actual WHERE, JOIN, and ORDER BY clauses in your slow queries.
  5. Add indexes concurrently and measure. Run EXPLAIN ANALYZE again after creating the index. Confirm the plan changed and the timing improved. If it did not, the index may not be the right one.

This is methodical work. It is not glamorous, but it is the difference between an architecture that cracks under pressure and one that holds as your data scales.

When Indexing Is Not the Answer

Indexes solve read performance problems caused by missing access paths. They do not solve every database performance issue. A few situations where the fix lies elsewhere:

  • The query itself is poorly structured. An ORM-generated query that pulls every column from five joined tables with subqueries needs to be rewritten, not indexed around.
  • The schema needs normalization or denormalization. Sometimes the data model itself does not match the access pattern, and the right fix is a materialized view or a restructured table.
  • Connection pooling is the bottleneck. If your application opens a new database connection per request, you will hit limits that no index can address. Tools like PgBouncer solve a different category of problem.
  • The instance is genuinely undersized. If working set memory exceeds available RAM and every query hits disk, right-sizing the instance matters — but only after you have confirmed the indexes are correct, because bad indexes make the working set larger than it needs to be.

Related service: Cloud infrastructure and DevOps services in Tampa Bay — what we build, how we work, and what it costs.

Build It Right From the Start

Most database performance work is foundational. It is the soil work that determines whether your application can scale from a hundred thousand rows to ten million without a crisis. The indexes themselves are straightforward — the hard part is knowing which ones to build, in what order, and understanding the trade-offs of each.

That kind of judgment comes from experience. At FigTree Development, our infrastructure and architecture practice is grounded in years of building and operating systems at real scale — the kind of environments where a missing index does not just slow down a dashboard, it pages an on-call engineer at 2 AM.

If your application is hitting a wall and you are not sure whether the answer is a better index, a schema change, or an infrastructure redesign, we can help you find the root cause and build a path forward that does not crack under pressure.

Book a free 20-minute discovery call and walk us through what you are seeing. We will dig into the actual problem with you — no pitch deck, just the kind of direct technical conversation that moves things forward.

Ready to Build?

Let's Plant Something Real.

Every project starts with a free 20-minute discovery call — no pitch, just a real conversation about what you're building and where the friction is.

Book a Discovery Call → ← Back to Blog
Start a Project →