Assignment Overview
In this assignment, you will optimize a Large E-Commerce Database with millions of records. You'll be given slow queries and must make them fast using indexes, query rewrites, and other optimization techniques.
Indexing
B-tree, composite, covering
Execution Plans
EXPLAIN, cost analysis
Optimization
Query rewriting, statistics
The Scenario
FastShop Performance Crisis
FastShop's database has grown to millions of rows and critical queries are running slowly. The DBA team needs you to identify and fix the performance bottlenecks.
"Our order lookup queries are taking 30+ seconds. Customer complaints are increasing. We need these queries optimized to under 1 second!"
Optimization Tasks
Index Creation (5 tasks)
- Create single-column index for frequent lookups
- Create composite index for multi-column WHERE
- Create covering index to eliminate table access
- Create unique index for constraint enforcement
- Evaluate and drop redundant indexes
Execution Plan Analysis (5 tasks)
- Analyze EXPLAIN output for table scan vs index scan
- Identify missing index from execution plan
- Compare costs before and after optimization
- Identify join order optimization opportunities
- Detect suboptimal index usage
Query Optimization (5 tasks)
- Rewrite query to avoid function on indexed column
- Optimize OR conditions with UNION
- Replace correlated subquery with JOIN
- Add appropriate hints for query optimizer
- Document before/after performance metrics
Submission Guidelines
GitHub Repository
- Create a repository named
sql-assignment-6-optimization - Include
indexes.sqlwith CREATE INDEX statements - Include
before-after.mdwith EXPLAIN outputs - Include
optimized-queries.sqlwith rewritten queries - Document performance improvements with timing data
Grading Rubric
| Criteria | Points |
|---|---|
| Index creation tasks (5 × 10 pts) | 50 |
| Execution plan analysis (5 × 10 pts) | 50 |
| Query optimization (5 × 10 pts) | 50 |
| Total | 150 |