4 ms·
SQL is a declarative language with semantics derived from relational algebra, which to me implies that there should be no execution semantics at all. So the st
by CuriousSkeptic 11y ago
SQL is a declarative language with semantics derived from relational algebra, which to me implies that there should be no execution semantics at all.
So the statement that "a CTE is only evaluated once" should not be part of any specification for the language. And I would not expect two different executions of a query to maintain that invariant if the optimizer finds it better not to.
- pgaddict 11y agoYep, I agree with that. The problem is we currently have an implementation that behaves as explained above (planned in isolation, evaluated once), and there are applications relying on that behaviour. We can't just change that without breaking them.
- CuriousSkeptic 11y agoTrue. At the same time you can't condemn future users to this suboptimal behavior just because a bad desicion in the past. I'm not arguing for just abruptly reverse the design, but that the aim should be to reverse in an orderly manner with suitable deprecations and migration paths in place.
- radiowave 11y agoIn order to be free of execution semantics, you'd have to disallow calling side-effectful functions within a query, which would be a major departure from the current behaviour.