The impact of CTEs being &quot;optimization fences&quot; in PostgreSQL really depends on workload, and how cleverly you write your queries. If you are not aware of this - as most users using CTEs merely as an alias - you&#x27;ll be badly surprised.<p>I&#x27;ve been recently running TPC-DS on PostgreSQL 9.5 (alpha1 IIRC), to see how we&#x27;re doing (I&#x27;m one of the contributors). Thanks to the grouping sets, we&#x27;re now able to execute all 99 queries in the benchmark, which is awesome. Regarding performance, I&#x27;ve expected grouping sets to be a performance issue as the current implementation is rather simple. But to my mild surprise that&#x27;s not the case - CTEs are the main problem.<p>On 100GB data set some queries took hours to complete (well, I interrupted them so I&#x27;m not sure how long it&#x27;d actually take). After a rewrite (replace CTE with a subquery), the query took a a minute or so.