Summary - Index tuning
- SQL course
- Expert
- Lesson 12/45
- 5 min
Speed up a query with a covering index.
Summary - Index tuning
Index tuning: B-tree as base, covering index for index-only scan, partial index for few rows, selectivity should be high, maintenance with REINDEX. The right index speeds the right query.
-- CREATE INDEX ... INCLUDE ... WHERE ...
-- ANALYZE -> REINDEXIndex design and maintenance go together.
Practice Summary - Index tuning
Summary task: create a covering index on orders: customer_id as key, amount in INCLUDE.
Starter code
-- summary index
CREATE INDEX idx_orders_cust ON orders(customer_id)Sample solution
CREATE INDEX idx_orders_cust ON orders(customer_id) INCLUDE (amount);Expected output
CREATE INDEX
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Index maintenance
REINDEX INDEX ____
REINDEX INDEX idx_products_name
Explanation: idx_products_name is the right answer.
2 What does a covering index enable?
- Full scan
- Index-only scan Correct answer
- Seq scan
- Cross join
Explanation: A covering index enables index-only scan.
3 Summary - Index tuning: match the terms
| Term | Meaning |
|---|---|
B-tree |
balanced |
covering |
covering |
partial |
partial |
REINDEX |
rebuild |