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.
For a PostGIS-enabled table storing geospatial points, write the SQL to create an index to support nearest-neighbor (KNN) queries and spatial joins. Include SRID considerations and the appropriate GiST / SP-GiST operator class and explain why it improves performance.
How do you read a query execution plan to determine whether an index is being used? List 6 specific plan elements or metrics you inspect (for example: index scan vs seq scan, cost estimates, rows, filters, actual vs estimated rows), and explain what an 'index-only scan' indicates.
You have a JSONB column profile in users storing nested fields. Example query: SELECT id FROM users WHERE profile->'address'->>'city' = 'Seattle'. Write two different Postgres index strategies (functional b-tree and GIN) to accelerate this query and explain pros/cons of each.
Describe clustered and non-clustered indexes and how they differ across database systems (for example, SQL Server's clustered index vs PostgreSQL's approach). Explain when you would choose a clustered index versus a non-clustered index for a table with frequent range queries and a high insert volume. Include the effects on physical row order, insert cost, and I/O patterns.
You observe index-only scans are not occurring though a covering index exists. List reasons why index-only scans might not be used (visibility map, deleted tuples and VACUUM, versioning) and the actions to enable index-only scans in Postgres.
Unlock Full Question Bank
Get access to all Indexing Strategy and Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.