PostgreSQL & Databases
Composite index ordering
A composite index sorts by its first column, then by its second, so column order decides which queries it helps. You learn to order columns from the queries that actually run.
What you will be able to do
- Explain why a condition on the leading column makes a composite index useful.
- Decide the column order of a composite index from the real queries.
What is in the lesson
- A real situation where this goes wrong
- How it works, step by step
- A walkthrough with commands you can run
- How it fails in production, and how to tell
- Three quiz questions with explanations
Read this lessonFree. No account needed.
More in PostgreSQL & Databases
- Deadlock detectionIntermediate · 4 min
A deadlock is a cycle of lock waits, and PostgreSQL aborts one transaction in the cycle after deadlock_timeout. You learn how to find the blocker, and how lock ordering…
- B tree indexesIntermediate · 4 min
A B-tree is the default index type, a sorted tree that serves equality, ranges and ordering. You learn how to test an index with EXPLAIN ANALYZE and check whether it is…
- Index only scansIntermediate · 4 min
An index-only scan answers from the index, but it still visits the heap for pages the visibility map has not marked all-visible. You learn to read Heap Fetches, and…
- EXPLAIN ANALYZE BUFFERSAdvanced · 4 min
EXPLAIN ANALYZE with BUFFERS shows how many pages each plan node reads from cache and from outside it. You learn to read the hit, read and temp counts before judging a…
- Planner statisticsAdvanced · 4 min
Planner statistics are sampled estimates that ANALYZE stores per column, and the planner uses them to pick plans. You learn to compare estimates with real counts and to…
- WAL fundamentalsAdvanced · 4 min
WAL records each change before the data page is written, so a crash is repaired by replaying the log. You learn why a commit waits for the log flush, and why fsync must…