RE: Bug in query rewriter - hasModifyingCTE not getting set

From: "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>
To: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Greg Nancarrow <gregn4422(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Bug in query rewriter - hasModifyingCTE not getting set
Date: 2021-05-18 03:59:21
Message-ID: TYAPR01MB2990399EE8E227C8512E76F2FE2C9@TYAPR01MB2990.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2021-05-18 04:09:20 Re: "ERROR: deadlock detected" when replicating TRUNCATE
Previous Message Fujii Masao 2021-05-18 03:48:38 Re: pg_get_wal_replay_pause_state() should not return 'paused' while a promotion is ongoing.