Explore Library
Quiz

CTE Materialization and Optimization Fences

How PostgreSQL treats CTEs as optimization fences and when predicates can be pushed into them.

In PostgreSQL 12+, you write a query using a non-recursive CTE that is referenced only once, then filter the outer query with a WHERE clause on a column the CTE returns. Compared to PostgreSQL 11, why might this query suddenly run much faster on version 12+?