Anatomy of an Index
Think of an index like the index at the back of a textbook. Instead of reading every page to find "Photosynthesis", you look it up and go straight to page 42.
B-Trees
Most relational databases use B-Trees. They keep data sorted, allowing for O(log n) lookups instead of O(n) full table scans.
CREATE INDEX idx_published_created
ON Post(published, createdAt DESC);
Always check your EXPLAIN ANALYZE output!