RE: Bug in query rewriter - hasModifyingCTE not getting set
tsunakawa.takay@fujitsu.com <tsunakawa.takay@fujitsu.com>
From: "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: Greg Nancarrow <gregn4422@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-05-18T03:59:21Z
Lists: pgsql-hackers
From: Tom Lane <tgl@sss.pgh.pa.us> > In view of this, maybe the right thing is to disallow modifying CTEs > in rule actions in the first place. I see we already do that for > views (i.e. ON SELECT rules), but they're not really any safer in > other types of rules. You meant by views something like the following, didn't you? postgres=# create view myview as with t as (delete from b) select * from a; ERROR: views must not contain data-modifying statements in WITH OTOH, the examples Greg-san showed do not contain CTE in the rule action, but in the query that the rule is applied to. So, I think the solution would be something different. > Given that non-SELECT rules are an undertested > legacy thing, I'm not that excited about moving mountains to make > this case possible. > That semantic issue doesn't get any less pressing just because the query > was generated by rewrite. So I now think that what we have to do is > throw an error if we have a modifying CTE and sub_action is different > from rule_action. Not quite sure how to phrase the error though. So, how about just throwing an error when the original query (not the rule action) has a data-modifying CTE? The error message would be something like "a query containing a data-modifying CTE cannot be executed because there is some rule applicable to the relation". This may be overkill and too many regression tests might fail, so we may have to add some condition to determine if we error out. Or, I thought Greg-san's patch would suffice. What problem do you see in it? I couldn't imagine what "mountains" are. Could you tell me what's that? Regards Takayuki Tsunakawa
Commits
-
Fix rewriter to set hasModifyingCTE correctly on rewritten queries.
- 362e2dcc4619 15.0 landed
- cbba6ba3a062 13.5 landed
- 9de082399cfe 10.19 landed
- 882b7e728835 11.14 landed
- 595ab8a5451b 9.6.24 landed
- 1fedbcc7ab26 12.9 landed
- 03d01d746b93 14.0 landed
-
Enable parallel SELECT for "INSERT INTO ... SELECT ...".
- 05c8482f7f69 14.0 landed
-
Revert "Propagate CTE property flags when copying a CTE list into a rule."
- f94924f01e48 11.11 landed
- d6759ac6a41e 10.16 landed
- d1d297985253 14.0 landed
- ac1df003f253 13.2 landed
- a64aacf152fc 9.5.25 landed
- 6f8e393a79e4 9.6.21 landed
- 46f297113598 12.6 landed
-
Propagate CTE property flags when copying a CTE list into a rule.
- ed2908963354 14.0 landed
- ce5f27fcae61 11.11 landed
- 739375174ae8 13.2 landed
- 56ff63cac94d 10.16 landed
- 4384eccb1549 9.5.25 landed
- 2a7664a79c16 12.6 landed
- 01e3fe3275af 9.6.21 landed