What does INCLUDE (total) make possible?
-- PostgreSQL 11+ CREATE INDEX ON orders (customer_id) INCLUDE (total); SELECT total FROM orders WHERE customer_id = 42;
- A uniqueness check on
total - An index-only scan for this query
- Partitioning the table by
total - Sorting the index by
totaltoo
Storing
Play SQL & Databases ▸
total in the index leaves makes it covering, so the query can be answered without visiting the table heap.