Fix rules's command contains for-update - Mailing list pgsql-hackers

From Zhenghua Lyu
Subject Fix rules's command contains for-update
Date
Msg-id CAO0i4_QRMDnyAnAzEaWh3cP9ofTEbvOXWr9bzkvEFArzJTqh6w@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi hackers, 

   I run the following sql on the latest master branch (head commit: 6f0e19005) of Postgres:

   ```sql
 gpadmin=# create table t(c int);
CREATE TABLE
gpadmin=# create rule myrule as on insert to t do instead select * from t for update;
CREATE RULE
gpadmin=# insert into t values (1);
psql: ERROR:  no relation entry for relid 1
   ```

  It throws an error.
  
  After some investigation, I found that:

  1. in the function `transformRuleStmt`, it creates a new ParseState `sub_pstate` to transform
actions. And in this `sub_pstate`, it is initially contains two rangetblentry, "old" and "new".

  2. in the function `transformSelectStmt`, it will invoke `transformLockingClause` to handle `for update`. And it loops all the entries in rtables.

 I think for a CreateRuleStmt, its command part if is a select-for-update statement, the for-update clause should skip the two "new", "old" RangeTblEntry.

How to fix this:
1. forbid the syntax: rule's command cannot be a select-for-update
2. skip new and old: I have a patch to show this idea, please see the attachment.

Any thoughts? Thanks!


Best Regards,
Zhenghua Lyu
Attachment

pgsql-hackers by date:

Previous
From: Konstantin Knizhnik
Date:
Subject: Inheritance, invalidations and prepared statements.
Next
From: Julien Rouhaud
Date:
Subject: Re: Checksum errors in pg_stat_database