Indexing Strategy and Design Questions

Choosing and designing indexes: B-tree, hash, composite, covering, partial, and full-text/inverted indexes, and the trade-offs between read acceleration and write/storage overhead. Covers selecting index columns from query patterns, cardinality and selectivity reasoning, diagnosing why an index is or is not used, and index maintenance: rebuilding or reorganizing a fragmented index, finding and dropping redundant or unused indexes, and rolling out a new index to production safely. Also covers indexing in analytical (bitmap, columnar), partitioned, and distributed/NoSQL systems. Central to database performance interviews.

EasyTechnical
37 practiced

You have a PostgreSQL table customers:

sql
CREATE TABLE customers (
  customer_id serial PRIMARY KEY,
  first_name text,
  last_name text,
  email text,
  created_at timestamptz
);

Write the SQL to create a B-tree index to speed queries like SELECT * FROM customers WHERE last_name = 'Smith';. Explain when the optimizer will use that index versus doing a sequential scan, mentioning selectivity and statistics.

EasyTechnical
57 practiced

Explain what a B-tree index is and why adding an index on customer_id in a large orders table might speed up lookups but slow down inserts. Include impact on storage, and how index choice changes read/write trade-offs for BI reporting vs OLTP.

MediumTechnical
44 practiced

Given these two tables:

orders(order_id PK, customer_id, order_date, total_amount)
customers(customer_id PK, country, tier)

Query: SELECT o.order_id, o.total_amount FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.country = 'US' AND o.order_date >= '2025-01-01' ORDER BY o.total_amount DESC LIMIT 50;

Propose one or more indexes (SQL statements) to improve that query and explain your reasoning about column order and covering possibilities.

MediumTechnical
41 practiced

You are given a query that runs slowly: it filters on LOWER(email) = 'abc@example.com'. Explain why this may prevent index usage and propose alternatives to make lookups case-insensitive while remaining sargable. Include SQL examples and index recommendations for PostgreSQL.

MediumTechnical
42 practiced

Explain the difference between a clustered index and a nonclustered index. Use an orders table example where queries often filter by customer_id but the primary key is order_id. Discuss implications for physical layout, read performance, and insert/update cost, and name two databases with different clustered-index semantics.

Unlock Full Question Bank

Get access to all 14 Indexing Strategy and Design interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.