From: | Zhenghua Lyu <zlv(at)pivotal(dot)io> |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Fix rules's command contains for-update |
Date: | 2019-04-04 08:33:35 |
Message-ID: | CAO0i4_QRMDnyAnAzEaWh3cP9ofTEbvOXWr9bzkvEFArzJTqh6w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
0001-Fix-applying-rules-whose-command-contains-lockingCla.patch | application/octet-stream | 1.9 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Julien Rouhaud | 2019-04-04 08:47:37 | Re: Checksum errors in pg_stat_database |
Previous Message | Konstantin Knizhnik | 2019-04-04 08:30:12 | Inheritance, invalidations and prepared statements. |