How does a CTE differ from a subquery, and is it materialized?
How does a CTE defined with WITH differ from a subquery in FROM? Does PostgreSQL calculate it once and store the result, or inline it into the main query? How does that choice affect performance?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONSeniorData EngineerBackendAnalyst