Earlier quoted context omitted.
The things with SQL is that it's more like parroting RelAlgebra instead of trying to implement it with a comfortable syntax. All the bad ideas of the Cobol language generation come with it. And, like you said, SQL kills one of the core ideas of RelAlgebra: composability. I find it very sad that behind the scenes in most relational DBs, the mess off SQL gets translated to the operator language which the optimizer work…
The optimizer does not work work on pure relational algebra. Or works on something very similar to SQL in the case of PostgreSQL.
Admittedly, I haven't looked at pgsql code for 10+ years so this could have changed.