InterviewStack.io LogoInterviewStack.io

Indexing Strategy and Design Questions

Choosing and designing indexes: B-tree, hash, composite, covering, and partial indexes, and the trade-offs between read acceleration and write/storage overhead. Covers selecting index columns from query patterns, cardinality and selectivity reasoning, and diagnosing why an index is or is not used. Central to database performance interviews.

EasyTechnical
44 practiced

Describe what an index is in relational databases and list three different index types (e.g., B-tree, hash, bitmap). For each type, state one advantage and one limitation in a data-analytics context.

HardTechnical
33 practiced

For recurring analytics that compute ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY event_ts DESC) on a 2B row events table, propose index and partitioning strategies across OLAP systems to speed queries, and discuss trade-offs such as insert throughput vs query latency and maintenance costs.

MediumTechnical
34 practiced

You need to speed up a frequent query: SELECT user_id, amount FROM transactions WHERE user_id = ? AND created_at >= ? ORDER BY created_at DESC LIMIT 100. Propose an index for Postgres that could make this an index-only scan and explain the concept of a covering index and index-only scan.

MediumTechnical
56 practiced

You need to suggest indexes for a complex query provided below. Query:

SELECT u.user_id, SUM(o.amount) total
FROM users u
JOIN orders o ON u.user_id = o.user_id
JOIN order_items oi ON o.order_id = oi.order_id
WHERE o.order_date >= '2024-01-01' AND oi.product_id = 123
GROUP BY u.user_id
HAVING SUM(o.amount) > 1000;

Recommend specific indexes (table and column order) and justify each recommendation with expected read/write trade-offs.

That is every published Indexing Strategy and Design question for Data Scientist so far. Browse the other topics in this category, or practice this one interactively.