xzw's recent activity
-
Comment on A PostgreSQL planner semi-join gotcha with CTE, LIMIT, and RETURNING in ~comp
-
Comment on Fiction with great “plot devices” in ~misc
xzw I think The Truman Show was inspired by The Prisoner (1967) series. They have a similar thematic. I loved both.I think The Truman Show was inspired by The Prisoner (1967) series. They have a similar thematic. I loved both.
-
Comment on Anyone interested in trying out Kagi? (trial giveaway: round #2) in ~tech
xzw I'm also interested in trying it out. Thanks.I'm also interested in trying it out. Thanks.
-
Comment on <deleted topic> in ~tech
xzw Is it really free if the content creator earns ad revenue for the clicks for example? Or AI just steals money by copying the content and making the information available elsewhere?Is it really free if the content creator earns ad revenue for the clicks for example? Or AI just steals money by copying the content and making the information available elsewhere?
I don't agree with this. In my opinion the key takeaway should be that if your conditional expression may return different results on different runs or contains side-effects, do not gamble with whether the optimizer runs it once or multiple times. Ironically it is materialized CTE that can help you preventing that, see https://www.postgresql.org/docs/17/queries-with.html#QUERIES-WITH-CTE-MATERIALIZATION
So something like this should work:
The point is, put the subquery with side-effects in CTE, not the whole delete expression, and use the
materialized
keyword to prevent the planner from optimizing it out. I'm not sure thematerialized
keyword is really needed there, as PostgreSQL should know that locking is a side-effect, and would materialize the CTE either way, but it is a good indicator for fellow developers.As a side note:
limit
is not part of the SQL standard,fetch
is.