If I make a query using CTEs that looks like that:
WITH cte_a AS ( SELECT a.id, a.something FROM a WHERE a.something IS NOT NULL ),-- [...] some other CTEscte_d AS ( SELECT cte_a.id, cte_a.something FROM cte_a JOIN -- something JOIN -- something WHERE -- something ORDER BY cte_a.id ASC FOR UPDATE -- Here, will the `FOR UPDATE` locks `a` rows?),-- rest of the query, which will update `a.something`.
Will the lock for update apply on the rows of the table a
, or will the lock apply on a materialized table generated by cte_a
?
If the lock applies to the materialized table, would the following solve the problem?
WITH cte_a AS NOT MATERIALIZED (-- Rest of the query
I'm using PostgreSQL v14.
If it changes anything, I'm mostly interested in the behavior with the default READ COMMITTED isolation level.