# Result site takes 30 seconds: Database indexes (Mock Interview Notes)

> How to answer the slow-query interview question: why a bigger server or a cache is the weak answer, EXPLAIN and Seq Scan, how a B-tree index works, the...

Canonical: https://www.internhack.in/notes/db-index-interview
Last updated: 2026-11-03

By InternHack Team · 2026-11-03 · 8 min read · Interview Prep

The interview question: **"It's result day. A student types their roll number and the site takes 30 seconds. The query is slow. What do you do?"**

Every year some result site struggles on result day. CBSE Class 12 2025 alone had **17,04,367** registered students, and they all look up exactly one thing: their own row, by roll number. (To be clear: no result-day outage has been officially traced to a missing index. The official lines have been "technical issue" or traffic. The scenario here is a hypothetical, say your college's result portal.)

In these notes: the weak answer and why it fails, how to find the slow query with EXPLAIN, how a B-tree index works, composite indexes and the leftmost prefix rule, why you shouldn't index everything, the three ways an index silently gets ignored, and a ready interview answer.

## The weak answer: bigger server, Redis cache, index everything

A typical fresher answer: *"Sir, we'll get a bigger server, add RAM. We'll put Redis in front. And we'll index every column, everything gets fast."*

Here's why an interviewer pushes back on each part:

- **Bigger server:** same slow query, just a higher bill. You haven't found out *which* query is slow or *why*.
- **Redis cache:** each student looks up their own roll number roughly once. With lakhs of different roll numbers, almost every request is a first-time request, so it's a cache **miss**. The cache barely helps. (This is our reasoning, not a measured figure.)
- **Index every column:** every index has to be updated on every insert, so uploading the results gets slower, and unused indexes waste disk and memory.

The strong answer starts with **measuring**, not buying. One-liner to remember: **"EXPLAIN first, then index. A bigger server is the last option, not the first."**

## Sign up free to unlock the full notes

The rest of these notes needs a free InternHack account:

- Step 1: Find it with EXPLAIN
- Step 2: Add a B-tree index
- Step 3: Composite indexes and the leftmost prefix rule
- Step 4: Why not index everything
- Step 5: When the index exists but isn't used
- The reel's question: FUNCTION, LIKE or TYPE?
- How to answer this in an interview

Sign up free: https://www.internhack.in/register?from=%2Fnotes%2Fdb-index-interview

## Sources

- PostgreSQL docs, Indexes: Introduction (seq scan vs index, write overhead): https://www.postgresql.org/docs/current/indexes-intro.html
- PostgreSQL docs, Using EXPLAIN (tenk1 example, 445 vs 8.30): https://www.postgresql.org/docs/current/using-explain.html
- PostgreSQL docs, Indexes on Expressions: https://www.postgresql.org/docs/current/indexes-expressional.html
- PostgreSQL docs, Database Page Layout: https://www.postgresql.org/docs/current/storage-page-layout.html
- MySQL 8.0 docs, Multiple-Column Indexes (leftmost prefix): https://dev.mysql.com/doc/refman/8.0/en/multiple-column-indexes.html
- MySQL 8.0 docs, Type Conversion in Expression Evaluation (string column vs number): https://dev.mysql.com/doc/refman/8.0/en/type-conversion.html
- MySQL 8.0 docs, Avoiding Full Table Scans (type=ALL, low cardinality, small tables): https://dev.mysql.com/doc/refman/8.0/en/table-scan-avoidance.html
- Use The Index, Luke: the B-tree (depth 4-5): https://use-the-index-luke.com/sql/anatomy/the-tree
- Use The Index, Luke: slow indexes (3 steps of a lookup, rebuild myth): https://use-the-index-luke.com/sql/anatomy/slow-indexes
- Use The Index, Luke: functions on columns: https://use-the-index-luke.com/sql/where-clause/functions/case-insensitive-search
- Use The Index, Luke: LIKE with leading wildcards: https://use-the-index-luke.com/sql/where-clause/searching-for-ranges/like-performance-tuning
- Percona blog, Tuning InnoDB primary keys (~1,200 pointers per page): https://www.percona.com/blog/tuning-innodb-primary-keys/
- SQLServerCentral, indexing every column: https://www.sqlservercentral.com/blogs/common-sql-server-mistakes-%e2%80%93-indexing-every-column
- Navicat, the downside of database indexing: https://navicat.com/company/aboutus/blog/1764-the-downside-of-database-indexing
- CBSE Class 12 2025 results (17,04,367 registered, 88.39% pass): https://news.careers360.com/cbse-class-12-board-results-2025-declared-over-17-lakh-at-cbseresults-nic-in-88-39-pass-digilocker-download
- CBSE result site down, 13 Jul 2020 (NIC "technical issue"): https://www.tribuneindia.com/news/schools/cbse-website-crashes-after-declaration-of-results-112398

Page counts, tree depths for 1 crore rows and the 2.7 GB figure are our arithmetic on the cited fanouts, shown as estimates. No result-site outage has been officially attributed to a missing index.

## Related

- [Home](https://www.internhack.in/)
- [Notes](https://www.internhack.in/notes)
