Design a Covering Index
Medium
Query Optimization
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.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.