Wrong Rows From a Self-Join
A self-join with duplicate sort keys was returning wrong rows. How I traced it through the optimizer, where my first fix went wrong, and how physical projection got rebuilt on column indices.
PostgreSQL Internals · Case study