Lists: | pgsql-bugs |
---|
From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | jiye_sw(at)126(dot)com |
Subject: | BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 09:27:38 |
Message-ID: | 17633-98cc85e1fa91e905@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 17633
Logged by: leafji's git home
Email address: jiye_sw(at)126(dot)com
PostgreSQL version: 14.5
Operating system: Centos
Description:
Just execute as follow sql:
drop view v1;
drop table t1;
drop table t2;
create table t1(i int, j int);
create table t2(a int, b int, c int, d int);
create or replace rule t1_r as on insert to t1 do also insert into t2(c,d)
values (new.i, new.j);
insert into t1 values (1,default);
insert into t1 values (1,default),(2, default);
-- create rule on t1 directly no issue
drop rule t1_r on t1;
create view v1 as select * from t1;
— create rule on view query t1 will trigger this issue
create or replace rule v1_r as on insert to v1 do also insert into t2(c,d)
values (new.i, new.j);
insert into v1 values (1,default);
-- must multi values.
insert into v1 values (1,default),(2, default);
=> it will trigger cache lookup failed for type.
From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
---|---|
To: | jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 10:05:09 |
Message-ID: | CAMbWs49K+LkBFTu3XqJgso=_BTJ81NJv9N5Bx0_4XikkmG-qdA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On Tue, Oct 11, 2022 at 5:48 PM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:
> Just execute as follow sql:
>
> drop view v1;
> drop table t1;
> drop table t2;
> create table t1(i int, j int);
> create table t2(a int, b int, c int, d int);
> create or replace rule t1_r as on insert to t1 do also insert into t2(c,d)
> values (new.i, new.j);
> insert into t1 values (1,default);
> insert into t1 values (1,default),(2, default);
> -- create rule on t1 directly no issue
> drop rule t1_r on t1;
> create view v1 as select * from t1;
> — create rule on view query t1 will trigger this issue
> create or replace rule v1_r as on insert to v1 do also insert into t2(c,d)
> values (new.i, new.j);
> insert into v1 values (1,default);
> -- must multi values.
> insert into v1 values (1,default),(2, default);
> => it will trigger cache lookup failed for type.
Thanks for the report! I can reproduce this issue.
Apparently there is something wrong when we process the DEFAULT marker
in rewriteValuesRTE, because the contents inside att_tup are invalid.
p /x att_tup->atttypid
$13 = 0x7f7f7f7f
Thanks
Richard
From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
---|---|
To: | jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 12:09:30 |
Message-ID: | CAMbWs4-Z8hSnHOTrCV4-Pp1+H9+i34O68pSkhEHLyDpYfPyqpQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On Tue, Oct 11, 2022 at 6:05 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
> On Tue, Oct 11, 2022 at 5:48 PM PG Bug reporting form <
> noreply(at)postgresql(dot)org> wrote:
>
>> -- must multi values.
>> insert into v1 values (1,default),(2, default);
>> => it will trigger cache lookup failed for type.
>
>
> Thanks for the report! I can reproduce this issue.
>
> Apparently there is something wrong when we process the DEFAULT marker
> in rewriteValuesRTE, because the contents inside att_tup are invalid.
>
> p /x att_tup->atttypid
> $13 = 0x7f7f7f7f
>
I think the problem exists for auto-updatable view, as we leave the
DEFAULT items untouched because we expect to apply the underlying base
rel's default.
In this case there is a rewrite rule on the view. Applying the rule
we'd get a product query whose target entries referring to the VALUES
RTE have attribute 3 and 4 while the relation has only two attributes.
Then we proceed to replacing the remaining DEFAULT items with NULLs.
And when we try to access the relation's 3rd and 4th attributes, we are
accessing illegal memory areas.
Thanks
Richard
From: | Japin Li <japinli(at)hotmail(dot)com> |
---|---|
To: | Richard Guo <guofenglinux(at)gmail(dot)com> |
Cc: | jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 12:29:16 |
Message-ID: | MEYP282MB1669B7492DAFE6913C127ED8B6239@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On Tue, 11 Oct 2022 at 20:09, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
> I think the problem exists for auto-updatable view, as we leave the
> DEFAULT items untouched because we expect to apply the underlying base
> rel's default.
>
> In this case there is a rewrite rule on the view. Applying the rule
> we'd get a product query whose target entries referring to the VALUES
> RTE have attribute 3 and 4 while the relation has only two attributes.
> Then we proceed to replacing the remaining DEFAULT items with NULLs.
> And when we try to access the relation's 3rd and 4th attributes, we are
> accessing illegal memory areas.
>
Yeah, I also notice this, attch a patch to fix it.
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
Attachment | Content-Type | Size |
---|---|---|
fix-trigger-cache-lookup-failed.patch | text/x-patch | 892 bytes |
From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
---|---|
To: | Japin Li <japinli(at)hotmail(dot)com> |
Cc: | jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 13:16:54 |
Message-ID: | CAMbWs491JOKxnc3f3XGj1oYAzi=OJP6=YjUZnQ=hAUxo3BF+hQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On Tue, Oct 11, 2022 at 8:29 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>
> On Tue, 11 Oct 2022 at 20:09, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> >
> > I think the problem exists for auto-updatable view, as we leave the
> > DEFAULT items untouched because we expect to apply the underlying base
> > rel's default.
> >
> > In this case there is a rewrite rule on the view. Applying the rule
> > we'd get a product query whose target entries referring to the VALUES
> > RTE have attribute 3 and 4 while the relation has only two attributes.
> > Then we proceed to replacing the remaining DEFAULT items with NULLs.
> > And when we try to access the relation's 3rd and 4th attributes, we are
> > accessing illegal memory areas.
> >
>
> Yeah, I also notice this, attch a patch to fix it.
+1 for the idea. We need to identify the right target relation for each
product query and rt_entry_relation is not the right one.
A minor comment is can we know the product query is not CMD_SELECT?
If so I suggest we add an assertion before fetching the target relation,
something like:
Assert(pt->resultRelation != 0);
Thanks
Richard
From: | Japin Li <japinli(at)hotmail(dot)com> |
---|---|
To: | Richard Guo <guofenglinux(at)gmail(dot)com> |
Cc: | jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 14:35:50 |
Message-ID: | MEYP282MB1669B5146A97FCD8D18A75EFB6239@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On Tue, 11 Oct 2022 at 21:16, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> On Tue, Oct 11, 2022 at 8:29 PM Japin Li <japinli(at)hotmail(dot)com> wrote:
>
>>
>> On Tue, 11 Oct 2022 at 20:09, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>>
>> Yeah, I also notice this, attch a patch to fix it.
>
>
> +1 for the idea. We need to identify the right target relation for each
> product query and rt_entry_relation is not the right one.
>
After some more thinking, I find the previous cannot work correctly.
For example:
CREATE OR REPLACE v1_r AS ON INSERT TO t1 DO ALSO SELECT * FROM t2;
> A minor comment is can we know the product query is not CMD_SELECT?
> If so I suggest we add an assertion before fetching the target relation,
> something like:
>
> Assert(pt->resultRelation != 0);
>
Oh, I think this might not be true. The product query comes from rules,
which might be a SELECT query, IIUC. See above example.
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Japin Li <japinli(at)hotmail(dot)com> |
Cc: | Richard Guo <guofenglinux(at)gmail(dot)com>, jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 15:07:45 |
Message-ID: | 312797.1665500865@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
Japin Li <japinli(at)hotmail(dot)com> writes:
> On Tue, 11 Oct 2022 at 21:16, Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>> +1 for the idea. We need to identify the right target relation for each
>> product query and rt_entry_relation is not the right one.
> After some more thinking, I find the previous cannot work correctly.
Yeah. The product query might not be an INSERT at all, yet
rewriteValuesRTE is assuming it is --- that whole business of
scanning the targetlist for referencing Vars and then saving
their resnos doesn't make sense otherwise.
I think the basic problem is that the two calls of rewriteValuesRTE
are really dealing with fundamentally different cases, and we should
probably not have tried to make the same function do both. I'm going
to try splitting it into two functions, one for the force_nulls case
and one for the !force_nulls case. The force_nulls case shouldn't
really need a target_relation parameter in the first place (since it
has no business assuming that the query is an INSERT). I think it
should just replace each SetToDefault with a NULL of the same type
as the SetToDefault, and call it good.
regards, tom lane
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Japin Li <japinli(at)hotmail(dot)com> |
Cc: | Richard Guo <guofenglinux(at)gmail(dot)com>, jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 15:37:12 |
Message-ID: | 348879.1665502632@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
I wrote:
> I think the basic problem is that the two calls of rewriteValuesRTE
> are really dealing with fundamentally different cases, and we should
> probably not have tried to make the same function do both. I'm going
> to try splitting it into two functions, one for the force_nulls case
> and one for the !force_nulls case.
As attached. This seems *way* cleaner to me, even if it means we need
two copies of the loops-over-VALUES-list-entries. I didn't write a
regression test yet, but this fixes the submitted bug and passes
check-world.
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
fix-bug-17633.patch | text/x-diff | 6.2 KB |
From: | Japin Li <japinli(at)hotmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Richard Guo <guofenglinux(at)gmail(dot)com>, jiye_sw(at)126(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17633: Define rule on views which do insert to another relation trigger cache lookup failed error. |
Date: | 2022-10-11 16:16:37 |
Message-ID: | MEYP282MB16690E8D4FCC095086FC9242B6239@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg젠 토토SQL : Postg젠 토토SQL 메일 링리스트 : 2022-10-11 이후 PGSQL-BUGS 16:16 |
On Tue, 11 Oct 2022 at 23:37, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I wrote:
>> I think the basic problem is that the two calls of rewriteValuesRTE
>> are really dealing with fundamentally different cases, and we should
>> probably not have tried to make the same function do both. I'm going
>> to try splitting it into two functions, one for the force_nulls case
>> and one for the !force_nulls case.
>
> As attached. This seems *way* cleaner to me, even if it means we need
> two copies of the loops-over-VALUES-list-entries. I didn't write a
> regression test yet, but this fixes the submitted bug and passes
> check-world.
>
Great. LGTM. Should we add the test-case for this?
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
Attachment | Content-Type | Size |
---|---|---|
test-case-for-bug-17633.patch | text/x-patch | 1.4 KB |