Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Design a Covering Index

A frequent query is SELECT customer_id, SUM(amount) FROM Orders WHERE status = 'Delivered' GROUP BY customer_id. Create an index that lets the database answer it from the index alone.

Table schema

Orders(id INT PRIMARY KEY, customer_id INT, status VARCHAR(20), amount INT)

Sample data

Check with EXPLAIN: the plan should show 'Using index' (MySQL) or an index-only scan (PostgreSQL).

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.