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
0001-Fix-applying-rules-whose-command-contains-lockingCla.patch
Description: Binary data