Well, at least with PostgreSQL -- all CTEs were always materialized. It was optimized only in the version 12.