PostgreSQL 19 will transform NOT IN into an anti-join
PostgreSQL 19 will rewrite NOT IN queries as NOT EXISTS when NOT NULL is guaranteed, enabling anti-joins via Nested Loop, Merge Join or Hash Join. A 1M-row example that never finished on PG18 ran in 3.2 seconds on PG19 beta 4.
- PG19 rewrites NOT IN as an anti-join when NOT NULL is guaranteed
- 1M-row example: PG18 never finished, PG19 beta 4 ran in 3.2 seconds
- With an FK index, time drops from 17,199 ms to 3.2 ms
- Enables Nested Loop, Merge Join and Hash Join instead of SubPlan
Read next
Software