4 ms·
It's more subtle than "worse." Apparently CTE optimization fence is part of SQL standard, and it can be useful to hand-optimize queries. But you are right, wh
by gleb 14y ago
It's more subtle than "worse." Apparently CTE optimization fence is part of SQL standard, and it can be useful to hand-optimize queries.
But you are right, when using CTEs for readability it tends to hurt more than help.
Interesting thread about being able to control this:
http://www.postgresql.org/message-id/201209191305.44674.db@kavod.com http://www.postgresql.org/message-id/201209191305.44674.db@k...
- bjourne 14y agoYeah, I've also heard that claim being made on the mailing list but it is probably wrong: http://dba.stackexchange.com/questions/27425/is-the-optimisation-fence-behaviour-of-a-cte-with-query-specified-in-the-sql2 http://dba.stackexchange.com/questions/27425/is-the-optimisa.... For writable cte:s it matters, for read-only ones the number of execution times doesn't.
- pvh 14y agoSorta. It can be handy for guiding the optimizer away from a bad optimization choice but that's really a bad habit to get into.