SQLIntermediate#indexes#performance

What is an index? What are the trade-offs?

An index is usually a B-tree that lets the engine locate rows without scanning the whole table. It speeds up filtering, joining and sorting but slows down INSERT/UPDATE/DELETE and consumes storage.

Example
CREATE INDEX idx_orders_customer ON orders(customer_id);
-- SELECT * FROM orders WHERE customer_id = 42; now uses an index seek

Related Questions

1
SQLAdvanced#indexes

Clustered vs non-clustered index?

Open
2
SQLAdvanced#indexes#performance

What is a covering index?

Open
3
SQLAdvanced#indexes#performance

Why might an index not be used by a query?

Open