Lists: | pgsql-hackers |
---|
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-14 12:05:25 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hello hackers,
i was experimenting with fdw tables recently, and discovered two bugs
in postgres core code (tested on stable 9.6 and master).
Steps to reproduce:
1) create parent table
2) create child local table
3) create child foreign table
4) create 'before row update` trigger at foreign table
5) make update query on parent table.
I attached sql file with these steps. At the end postgres will show an
error like:
ERROR: could not open file "base/12410/33037": No such file or
directory
33037 is relid of the foreign table. Bug is related with the fact that
postgres will try use latest scanned tupleid from local table to try
get an old tuple for trigger of foreign table.
It should be fixed with the patch like:
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1324,7 +1324,6 @@ ExecModifyTable(ModifyTableState *node)
JunkFilter *junkfilter;
TupleTableSlot *slot;
TupleTableSlot *planSlot;
- ItemPointer tupleid = NULL;
ItemPointerData tuple_ctid;
HeapTupleData oldtupdata;
HeapTuple oldtuple;
@@ -1381,6 +1380,8 @@ ExecModifyTable(ModifyTableState *node)
*/
for (;;)
{
+ ItemPointer tupleid = NULL;
+
After this patch the second bug will appear:
TRAP: FailedAssertion("!(((const void*)(fdw_trigtuple) != ((void *)0))
^ ((bool) (((const void*)(tupleid) != ((void *)0)) &&
((tupleid)->ip_posid != 0))))", File: "trigger.c", Line: 2428)
I'm not sure how it should be fixed, because as I see `oldtuple` will
be set only for AFTER ROW triggers by `wholerow` junk attribute.
Regards,
Ildus Kurbangaliev
Attachment | Content-Type | Size |
---|---|---|
test.sql | application/sql | 1.2 KB |
From: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-14 16:24:41 |
Message-ID: | CAFiTN-v_WOycpycrh2c_TpzVU=yOjMNWwHnUYYxccK-fOaWjpw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Sun, May 14, 2017 at 5:35 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> TRAP: FailedAssertion("!(((const void*)(fdw_trigtuple) != ((void *)0))
> ^ ((bool) (((const void*)(tupleid) != ((void *)0)) &&
> ((tupleid)->ip_posid != 0))))", File: "trigger.c", Line: 2428)
>
> I'm not sure how it should be fixed, because as I see `oldtuple` will
> be set only for AFTER ROW triggers by `wholerow` junk attribute.
There is comment on the ExecUpdate function
* When updating a foreign table,
* tupleid is invalid; the FDW has to figure out which row to
* update using data from the planSlot. oldtuple is passed to
* foreign table triggers; it is NULL when the foreign table has
* no relevant triggers.
After your fix, now tupleid is invalid which is expected, but seems
like we need to do something more. As per the comments seems like it
is expected to get the oldtuple from planSlot. But I don't see any
code for handling that part.
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
From: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 05:04:58 |
Message-ID: | CAFiTN-vx1pYKbtkFdX9srL+dghCJdZ9-DgRb57oDs5GuCDCD2Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> After your fix, now tupleid is invalid which is expected, but seems
> like we need to do something more. As per the comments seems like it
> is expected to get the oldtuple from planSlot. But I don't see any
> code for handling that part.
Maybe we should do something like attached patch.
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
Attachment | Content-Type | Size |
---|---|---|
fix_fdw_trigger.patch | application/octet-stream | 1.1 KB |
From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 05:48:53 |
Message-ID: | CAB7nPqTDH22V+9Otz3SH2n9_-skVhM8fOxVBCksgf5mbqN+rgA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 2:04 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
>> After your fix, now tupleid is invalid which is expected, but seems
>> like we need to do something more. As per the comments seems like it
>> is expected to get the oldtuple from planSlot. But I don't see any
>> code for handling that part.
>
> Maybe we should do something like attached patch.
As a deficiency, shouldn't this try as well to improve regression test
coverage for FDW triggers with inheritance trees? Those tests are in
postgres_fdw. You may find other issues on the way..
--
Michael
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 09:16:38 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, 15 May 2017 10:34:58 +0530
Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com>
> wrote:
> > After your fix, now tupleid is invalid which is expected, but seems
> > like we need to do something more. As per the comments seems like it
> > is expected to get the oldtuple from planSlot. But I don't see any
> > code for handling that part.
>
> Maybe we should do something like attached patch.
>
Hi,
planSlot contains already projected tuple, you can't use it as oldtuple.
I think problem is that `rewriteTargetListUD` called only for parent
relation, so there is no `wholerow` attribute for foreign tables.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 10:02:31 |
Message-ID: | CAFiTN-u6esmPzEUm5epzT1G1-wuEfQjf0Fz_nEST5dhNOr9rqg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 2:46 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> Hi,
> planSlot contains already projected tuple, you can't use it as oldtuple.
> I think problem is that `rewriteTargetListUD` called only for parent
> relation, so there is no `wholerow` attribute for foreign tables.
Oh, right!
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 12:13:52 |
Message-ID: | CAFjFpRfQ1pkCjNQFVOP_BPJfc7OR3596nqVVFBgAiDEZqB4Azg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 2:46 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> On Mon, 15 May 2017 10:34:58 +0530
> Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
>
>> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com>
>> wrote:
>> > After your fix, now tupleid is invalid which is expected, but seems
>> > like we need to do something more. As per the comments seems like it
>> > is expected to get the oldtuple from planSlot. But I don't see any
>> > code for handling that part.
>>
>> Maybe we should do something like attached patch.
>>
>
> Hi,
> planSlot contains already projected tuple, you can't use it as oldtuple.
> I think problem is that `rewriteTargetListUD` called only for parent
> relation, so there is no `wholerow` attribute for foreign tables.
Yes. postgresAddForeignUpdateTargets() which is called by
rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
for postgres_fdw but for other wrappers it might be a bad news. ctid,
whole row obtained from the remote postgres server will fit the tuple
descriptor of parent, but for other FDWs the column injected by
rewriteTargetListUD() may make the child tuple look different from
that of the parent, so we may not pass that column down to the child.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 12:34:39 |
Message-ID: | CAFiTN-vxd+ABRNqiEu0ANmjHfY-oBy7Q55VAiObPacPNFCuAGA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 5:43 PM, Ashutosh Bapat
<ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
> Yes. postgresAddForeignUpdateTargets() which is called by
> rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
> for postgres_fdw but for other wrappers it might be a bad news. ctid,
> whole row obtained from the remote postgres server will fit the tuple
> descriptor of parent, but for other FDWs the column injected by
> rewriteTargetListUD() may make the child tuple look different from
> that of the parent, so we may not pass that column down to the child.
But, can't we call rewriteTargetListUD for all the inheritors if the
inheritor is a foreign table which will intern call the
postgresAddForeignUpdateTargets?
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 12:50:39 |
Message-ID: | CAFjFpRdFYpJDSqeE2A-=mtA5e6H8dT9g4_3ByPsWWR0Sj78uqA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 6:04 PM, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> On Mon, May 15, 2017 at 5:43 PM, Ashutosh Bapat
> <ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
>> Yes. postgresAddForeignUpdateTargets() which is called by
>> rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
>> for postgres_fdw but for other wrappers it might be a bad news. ctid,
>> whole row obtained from the remote postgres server will fit the tuple
>> descriptor of parent, but for other FDWs the column injected by
>> rewriteTargetListUD() may make the child tuple look different from
>> that of the parent, so we may not pass that column down to the child.
>
> But, can't we call rewriteTargetListUD for all the inheritors if the
> inheritor is a foreign table which will intern call the
> postgresAddForeignUpdateTargets?
>
Yes. But it's not necessary to have all children use same FDW.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-15 13:54:55 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, 15 May 2017 17:43:52 +0530
Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
> On Mon, May 15, 2017 at 2:46 PM, Ildus Kurbangaliev
> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> > On Mon, 15 May 2017 10:34:58 +0530
> > Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> >
> >> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar
> >> <dilipbalaut(at)gmail(dot)com> wrote:
> >> > After your fix, now tupleid is invalid which is expected, but
> >> > seems like we need to do something more. As per the comments
> >> > seems like it is expected to get the oldtuple from planSlot.
> >> > But I don't see any code for handling that part.
> >>
> >> Maybe we should do something like attached patch.
> >>
> >
> > Hi,
> > planSlot contains already projected tuple, you can't use it as
> > oldtuple. I think problem is that `rewriteTargetListUD` called only
> > for parent relation, so there is no `wholerow` attribute for
> > foreign tables.
>
> Yes. postgresAddForeignUpdateTargets() which is called by
> rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
> for postgres_fdw but for other wrappers it might be a bad news. ctid,
> whole row obtained from the remote postgres server will fit the tuple
> descriptor of parent, but for other FDWs the column injected by
> rewriteTargetListUD() may make the child tuple look different from
> that of the parent, so we may not pass that column down to the child.
>
I'm trying to say that when we have a regular table as parent, and
foreign table as child, in rewriteTargetListUD `wholerow` won't be
added, because rewriteTargetListUD will be called only for parent
relation. You can see that by running the script i provided in the first
message of this thread.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-16 09:51:27 |
Message-ID: | CAFjFpRcQudmKYU4PJRN1-wp5K4aksupSoVpcRVAzES_49T=Vng@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, May 15, 2017 at 7:24 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> On Mon, 15 May 2017 17:43:52 +0530
> Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
>
>> On Mon, May 15, 2017 at 2:46 PM, Ildus Kurbangaliev
>> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>> > On Mon, 15 May 2017 10:34:58 +0530
>> > Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
>> >
>> >> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar
>> >> <dilipbalaut(at)gmail(dot)com> wrote:
>> >> > After your fix, now tupleid is invalid which is expected, but
>> >> > seems like we need to do something more. As per the comments
>> >> > seems like it is expected to get the oldtuple from planSlot.
>> >> > But I don't see any code for handling that part.
>> >>
>> >> Maybe we should do something like attached patch.
>> >>
>> >
>> > Hi,
>> > planSlot contains already projected tuple, you can't use it as
>> > oldtuple. I think problem is that `rewriteTargetListUD` called only
>> > for parent relation, so there is no `wholerow` attribute for
>> > foreign tables.
>>
>> Yes. postgresAddForeignUpdateTargets() which is called by
>> rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
>> for postgres_fdw but for other wrappers it might be a bad news. ctid,
>> whole row obtained from the remote postgres server will fit the tuple
>> descriptor of parent, but for other FDWs the column injected by
>> rewriteTargetListUD() may make the child tuple look different from
>> that of the parent, so we may not pass that column down to the child.
>>
>
> I'm trying to say that when we have a regular table as parent, and
> foreign table as child, in rewriteTargetListUD `wholerow` won't be
> added, because rewriteTargetListUD will be called only for parent
> relation. You can see that by running the script i provided in the first
> message of this thread.
You are right.
explain verbose update parent set val = random();
QUERY PLAN
-------------------------------------------------------------------------------
Update on public.parent (cost=0.00..258.63 rows=5535 width=10)
Update on public.parent
Update on public.child1
Foreign Update on public.ftable
Remote SQL: UPDATE public.child1 SET val = $2 WHERE ctid = $1
-> Seq Scan on public.parent (cost=0.00..4.83 rows=255 width=10)
Output: random(), parent.ctid
-> Seq Scan on public.child1 (cost=0.00..48.25 rows=2550 width=10)
Output: random(), child1.ctid
-> Foreign Scan on public.ftable (cost=100.00..205.55 rows=2730 width=10)
Output: random(), ftable.ctid
Remote SQL: SELECT ctid FROM public.child1 FOR UPDATE
(12 rows)
explain verbose update ftable set val = random();
QUERY PLAN
-------------------------------------------------------------------------------
Update on public.ftable (cost=100.00..159.42 rows=1412 width=38)
Remote SQL: UPDATE public.child1 SET val = $2 WHERE ctid = $1
-> Foreign Scan on public.ftable (cost=100.00..159.42 rows=1412 width=38)
Output: random(), ctid, ftable.*
Remote SQL: SELECT val, ctid FROM public.child1 FOR UPDATE
(5 rows)
Anyway, the problem I am stating, i.e. we have a bigger problem to fix
when there are FDWs other than postgres_fdw involved seems to be still
valid.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-16 12:05:16 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, 16 May 2017 15:21:27 +0530
Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
> On Mon, May 15, 2017 at 7:24 PM, Ildus Kurbangaliev
> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> > On Mon, 15 May 2017 17:43:52 +0530
> > Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
> >
> >> On Mon, May 15, 2017 at 2:46 PM, Ildus Kurbangaliev
> >> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> >> > On Mon, 15 May 2017 10:34:58 +0530
> >> > Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> >> >
> >> >> On Sun, May 14, 2017 at 9:54 PM, Dilip Kumar
> >> >> <dilipbalaut(at)gmail(dot)com> wrote:
> >> >> > After your fix, now tupleid is invalid which is expected, but
> >> >> > seems like we need to do something more. As per the comments
> >> >> > seems like it is expected to get the oldtuple from planSlot.
> >> >> > But I don't see any code for handling that part.
> >> >>
> >> >> Maybe we should do something like attached patch.
> >> >>
> >> >
> >> > Hi,
> >> > planSlot contains already projected tuple, you can't use it as
> >> > oldtuple. I think problem is that `rewriteTargetListUD` called
> >> > only for parent relation, so there is no `wholerow` attribute for
> >> > foreign tables.
> >>
> >> Yes. postgresAddForeignUpdateTargets() which is called by
> >> rewriteTargetListUD injects "ctid". "wholerow" is always there. Not
> >> for postgres_fdw but for other wrappers it might be a bad news.
> >> ctid, whole row obtained from the remote postgres server will fit
> >> the tuple descriptor of parent, but for other FDWs the column
> >> injected by rewriteTargetListUD() may make the child tuple look
> >> different from that of the parent, so we may not pass that column
> >> down to the child.
> >
> > I'm trying to say that when we have a regular table as parent, and
> > foreign table as child, in rewriteTargetListUD `wholerow` won't be
> > added, because rewriteTargetListUD will be called only for parent
> > relation. You can see that by running the script i provided in the
> > first message of this thread.
>
>
> You are right.
>
> explain verbose update parent set val = random();
> QUERY PLAN
> -------------------------------------------------------------------------------
> Update on public.parent (cost=0.00..258.63 rows=5535 width=10)
> Update on public.parent
> Update on public.child1
> Foreign Update on public.ftable
> Remote SQL: UPDATE public.child1 SET val = $2 WHERE ctid = $1
> -> Seq Scan on public.parent (cost=0.00..4.83 rows=255
> width=10) Output: random(), parent.ctid
> -> Seq Scan on public.child1 (cost=0.00..48.25 rows=2550
> width=10) Output: random(), child1.ctid
> -> Foreign Scan on public.ftable (cost=100.00..205.55 rows=2730
> width=10) Output: random(), ftable.ctid
> Remote SQL: SELECT ctid FROM public.child1 FOR UPDATE
> (12 rows)
>
> explain verbose update ftable set val = random();
> QUERY PLAN
> -------------------------------------------------------------------------------
> Update on public.ftable (cost=100.00..159.42 rows=1412 width=38)
> Remote SQL: UPDATE public.child1 SET val = $2 WHERE ctid = $1
> -> Foreign Scan on public.ftable (cost=100.00..159.42 rows=1412
> width=38) Output: random(), ctid, ftable.*
> Remote SQL: SELECT val, ctid FROM public.child1 FOR UPDATE
> (5 rows)
>
> Anyway, the problem I am stating, i.e. we have a bigger problem to fix
> when there are FDWs other than postgres_fdw involved seems to be still
> valid.
I agree. Maybe this issue should be added to Postgresql Open Items?
I think there should be some complex solution that fixes not only
triggers for foreign tables at table partitioning, but covers other
possible not working cases.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-16 12:11:44 |
Message-ID: | CAFjFpReeA3G3-U-FsR79zx_xFBVZc73hhWcH4OVWMb+ZFViRQg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>
> I agree. Maybe this issue should be added to Postgresql Open Items?
> I think there should be some complex solution that fixes not only
> triggers for foreign tables at table partitioning, but covers other
> possible not working cases.
>
I doubt if this is an open item, since DMLs on foreign tables are
supported since 9.3 and support to add foreign tables to inheritance
was added back in 9.5.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-16 12:36:11 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/05/16 21:11, Ashutosh Bapat wrote:
> On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>> I agree. Maybe this issue should be added to Postgresql Open Items?
>> I think there should be some complex solution that fixes not only
>> triggers for foreign tables at table partitioning, but covers other
>> possible not working cases.
> I doubt if this is an open item, since DMLs on foreign tables are
> supported since 9.3 and support to add foreign tables to inheritance
> was added back in 9.5.
I think this issue was introduced by the latter, so that was my fault.
One approach I came up with to fix this issue is to rewrite the
targetList entries of an inherited UPDATE/DELETE properly using
rewriteTargetListUD, when generating a plan for each child table in
inheritance_planner. Attached is a WIP patch for that. Maybe I am
missing something, though.
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
inherited-foreign-modify-WIP.patch | application/x-patch | 5.0 KB |
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-16 14:26:00 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, 16 May 2017 21:36:11 +0900
Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/05/16 21:11, Ashutosh Bapat wrote:
> > On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
> > <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>
> >> I agree. Maybe this issue should be added to Postgresql Open Items?
> >> I think there should be some complex solution that fixes not only
> >> triggers for foreign tables at table partitioning, but covers other
> >> possible not working cases.
>
> > I doubt if this is an open item, since DMLs on foreign tables are
> > supported since 9.3 and support to add foreign tables to inheritance
> > was added back in 9.5.
>
> I think this issue was introduced by the latter, so that was my fault.
>
> One approach I came up with to fix this issue is to rewrite the
> targetList entries of an inherited UPDATE/DELETE properly using
> rewriteTargetListUD, when generating a plan for each child table in
> inheritance_planner. Attached is a WIP patch for that. Maybe I am
> missing something, though.
>
> Best regards,
> Etsuro Fujita
I tested the patch, looks good.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-17 06:28:24 |
Message-ID: | CAB7nPqR3JNuWfoUxYH_rVbGA=Oy=iJN0wyvubS_H6h7tX=LsWQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Tue, May 16, 2017 at 11:26 PM, Ildus Kurbangaliev
<i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> On Tue, 16 May 2017 21:36:11 +0900
> Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
>> On 2017/05/16 21:11, Ashutosh Bapat wrote:
>> > On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
>> > <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>>
>> >> I agree. Maybe this issue should be added to Postgresql Open Items?
>> >> I think there should be some complex solution that fixes not only
>> >> triggers for foreign tables at table partitioning, but covers other
>> >> possible not working cases.
>>
>> > I doubt if this is an open item, since DMLs on foreign tables are
>> > supported since 9.3 and support to add foreign tables to inheritance
>> > was added back in 9.5.
>>
>> I think this issue was introduced by the latter, so that was my fault.
>>
>> One approach I came up with to fix this issue is to rewrite the
>> targetList entries of an inherited UPDATE/DELETE properly using
>> rewriteTargetListUD, when generating a plan for each child table in
>> inheritance_planner. Attached is a WIP patch for that. Maybe I am
>> missing something, though.
Could this patch include some regression tests to see at what extent
it has been tested? We surely don't want to see that broken again in
the future as well. (Nit: I did not look at the patch in details yet)
> I tested the patch, looks good.
What kind of tests did you do?
junkfilter = resultRelInfo->ri_junkFilter;
+ tupleid = NULL;
estate->es_result_relation_info = resultRelInfo;
Er, what is that?
--
Michael
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-17 08:54:37 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, 17 May 2017 15:28:24 +0900
Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
> On Tue, May 16, 2017 at 11:26 PM, Ildus Kurbangaliev
> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> > On Tue, 16 May 2017 21:36:11 +0900
> > Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> >> On 2017/05/16 21:11, Ashutosh Bapat wrote:
> >> > On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
> >> > <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
> >>
> >> >> I agree. Maybe this issue should be added to Postgresql Open
> >> >> Items? I think there should be some complex solution that fixes
> >> >> not only triggers for foreign tables at table partitioning, but
> >> >> covers other possible not working cases.
> >>
> >> > I doubt if this is an open item, since DMLs on foreign tables are
> >> > supported since 9.3 and support to add foreign tables to
> >> > inheritance was added back in 9.5.
> >>
> >> I think this issue was introduced by the latter, so that was my
> >> fault.
> >>
> >> One approach I came up with to fix this issue is to rewrite the
> >> targetList entries of an inherited UPDATE/DELETE properly using
> >> rewriteTargetListUD, when generating a plan for each child table in
> >> inheritance_planner. Attached is a WIP patch for that. Maybe I am
> >> missing something, though.
>
> Could this patch include some regression tests to see at what extent
> it has been tested? We surely don't want to see that broken again in
> the future as well. (Nit: I did not look at the patch in details yet)
>
> > I tested the patch, looks good.
>
> What kind of tests did you do?
I tested update triggers for foreign table when regular table is a
parent and foreign table is a child. Case like this:
explain verbose update parent set val = random();
QUERY PLAN
-------------------------------------------------------------------------------
Update on public.parent (cost=0.00..258.63 rows=5535 width=10)
Update on public.parent
Update on public.child1
Foreign Update on public.ftable // we have triggers on ftable here
>
> junkfilter = resultRelInfo->ri_junkFilter;
> + tupleid = NULL;
> estate->es_result_relation_info = resultRelInfo;
> Er, what is that?
That fixes the bug when tupleid from regular tuple is used to get
oldtuple for triggers of foreign table.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-05-17 09:06:29 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/05/17 17:54, Ildus Kurbangaliev wrote:
> On Wed, 17 May 2017 15:28:24 +0900
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
>
>> On Tue, May 16, 2017 at 11:26 PM, Ildus Kurbangaliev
>> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>>> On Tue, 16 May 2017 21:36:11 +0900
>>> Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
>>>> On 2017/05/16 21:11, Ashutosh Bapat wrote:
>>>>> On Tue, May 16, 2017 at 5:35 PM, Ildus Kurbangaliev
>>>>> <i(dot)kurbangaliev(at)postgrespro(dot)ru> wrote:
>>>>
>>>>>> I agree. Maybe this issue should be added to Postgresql Open
>>>>>> Items? I think there should be some complex solution that fixes
>>>>>> not only triggers for foreign tables at table partitioning, but
>>>>>> covers other possible not working cases.
>>>>
>>>>> I doubt if this is an open item, since DMLs on foreign tables are
>>>>> supported since 9.3 and support to add foreign tables to
>>>>> inheritance was added back in 9.5.
>>>>
>>>> I think this issue was introduced by the latter, so that was my
>>>> fault.
>>>>
>>>> One approach I came up with to fix this issue is to rewrite the
>>>> targetList entries of an inherited UPDATE/DELETE properly using
>>>> rewriteTargetListUD, when generating a plan for each child table in
>>>> inheritance_planner. Attached is a WIP patch for that. Maybe I am
>>>> missing something, though.
>>
>> Could this patch include some regression tests to see at what extent
>> it has been tested? We surely don't want to see that broken again in
>> the future as well. (Nit: I did not look at the patch in details yet)
OK, I'll include regression tests in the next version of the patch.
>>> I tested the patch, looks good.
>>
>> What kind of tests did you do?
>
> I tested update triggers for foreign table when regular table is a
> parent and foreign table is a child. Case like this:
>
> explain verbose update parent set val = random();
> QUERY PLAN
> -------------------------------------------------------------------------------
> Update on public.parent (cost=0.00..258.63 rows=5535 width=10)
> Update on public.parent
> Update on public.child1
> Foreign Update on public.ftable // we have triggers on ftable here
>
>>
>> junkfilter = resultRelInfo->ri_junkFilter;
>> + tupleid = NULL;
>> estate->es_result_relation_info = resultRelInfo;
>> Er, what is that?
>
> That fixes the bug when tupleid from regular tuple is used to get
> oldtuple for triggers of foreign table.
That's right. Let me explain in more detail. Currently, tupleid is
only initialized at the top of ExecModifyTable, so if we just loop
within the for(;;) code in that function (without returning RETURNING to
caller), tupleid won't be initialized even when advancing to next
subplan in case of inherited UPDATE/DELETE. This would cause a problem.
Assume that the current subplan is for the parent, which is a plain
table, that the next subplan is for the child, which is a foreign table,
and that the foreign table has a BEFORE trigger, as tested by Ildus. In
that case the current subplan would set tupleid to ctid for each row
from the plain table, and after advancing to the next subplan, the
subplan would set oldtuple to wholerow for the first row from the
foreign table, *without initializing tupleid to NULL*, and then call
ExecBRUpdateTriggers/ExecBRDeleteTriggers during ExecUpdate/ExecDelete,
which would cause an assertion error for
Assert(HeapTupleIsValid(fdw_trigtuple) ^ ItemPointerIsValid(tupleid)) in
those trigger functions, because oldtuple and tupleid are both valid.
So, tupleid should be initialized at least when advancing to next
subplan. It might be better to initialize that at each iteration of the
for(;;) code, like oldtuple, though.
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-02 09:10:27 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/05/16 21:36, Etsuro Fujita wrote:
> One approach I came up with to fix this issue is to rewrite the
> targetList entries of an inherited UPDATE/DELETE properly using
> rewriteTargetListUD, when generating a plan for each child table in
> inheritance_planner. Attached is a WIP patch for that. Maybe I am
> missing something, though.
While updating the patch, I noticed the patch rewrites the UPDATE
targetList incorrectly in some cases; rewrite_inherited_tlist I added to
adjust_appendrel_attrs (1) removes all junk items from the targetList
and (2) adds junk items for the child table using rewriteTargetListUD,
but it's wrong to drop all junk items in cases where there are junk
items for some other reasons than rewriteTargetListUD. Consider junk
items containing MULTIEXPR SubLink. One way I came up with to fix this
is to change (1) to only remove junk items with resname; since junk
items added by rewriteTargetListUD should have resname (note: we would
need resname to call ExecFindJunkAttributeInTlist at execution time!)
while other junk items wouldn't have resname (see
transformUpdateTargetList), we could correctly replace junk items added
by rewriteTargetListUD for the parent with ones for the child, by that
change. I might be missing something, though. Comments welcome.
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-05 08:25:27 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/02 18:10, Etsuro Fujita wrote:
> On 2017/05/16 21:36, Etsuro Fujita wrote:
>> One approach I came up with to fix this issue is to rewrite the
>> targetList entries of an inherited UPDATE/DELETE properly using
>> rewriteTargetListUD, when generating a plan for each child table in
>> inheritance_planner. Attached is a WIP patch for that. Maybe I am
>> missing something, though.
>
> While updating the patch, I noticed the patch rewrites the UPDATE
> targetList incorrectly in some cases; rewrite_inherited_tlist I added to
> adjust_appendrel_attrs (1) removes all junk items from the targetList
> and (2) adds junk items for the child table using rewriteTargetListUD,
> but it's wrong to drop all junk items in cases where there are junk
> items for some other reasons than rewriteTargetListUD. Consider junk
> items containing MULTIEXPR SubLink. One way I came up with to fix this
> is to change (1) to only remove junk items with resname; since junk
> items added by rewriteTargetListUD should have resname (note: we would
> need resname to call ExecFindJunkAttributeInTlist at execution time!)
> while other junk items wouldn't have resname (see
> transformUpdateTargetList), we could correctly replace junk items added
> by rewriteTargetListUD for the parent with ones for the child, by that
> change. I might be missing something, though. Comments welcome.
I updated the patch that way. Please find attached an updated version.
Other changes:
* Moved the initialization for "tupleid" I added in ExecModifyTable as
discussed before, which I think is essentially the same as proposed by
Ildus in [1], since I think that would be more consistent with "oldtuple".
* Added regression tests.
Anyway I'll add this to the next commitfest.
Best regards,
Etsuro Fujita
[1]
https://www.postgresql.org/message-id/20170514150525.0346ba72%40postgrespro.ru
Attachment | Content-Type | Size |
---|---|---|
adjust-inherited-update-tlist-v1.patch | text/plain | 12.9 KB |
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-05 08:39:53 |
Message-ID: | CAFjFpRfTpamoUz6fNyk6gPh=ecfBJjbUHJNKbDxscpyPJ3FfjQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Fri, Jun 2, 2017 at 2:40 PM, Etsuro Fujita
<fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/05/16 21:36, Etsuro Fujita wrote:
>>
>> One approach I came up with to fix this issue is to rewrite the targetList
>> entries of an inherited UPDATE/DELETE properly using rewriteTargetListUD,
>> when generating a plan for each child table in inheritance_planner.
>> Attached is a WIP patch for that. Maybe I am missing something, though.
>
>
> While updating the patch, I noticed the patch rewrites the UPDATE targetList
> incorrectly in some cases; rewrite_inherited_tlist I added to
> adjust_appendrel_attrs (1) removes all junk items from the targetList and
> (2) adds junk items for the child table using rewriteTargetListUD, but it's
> wrong to drop all junk items in cases where there are junk items for some
> other reasons than rewriteTargetListUD. Consider junk items containing
> MULTIEXPR SubLink. One way I came up with to fix this is to change (1) to
> only remove junk items with resname; since junk items added by
> rewriteTargetListUD should have resname (note: we would need resname to call
> ExecFindJunkAttributeInTlist at execution time!) while other junk items
> wouldn't have resname (see transformUpdateTargetList), we could correctly
> replace junk items added by rewriteTargetListUD for the parent with ones for
> the child, by that change. I might be missing something, though. Comments
> welcome.
I haven't looked at the patch, but that doesn't look right. In future
some code path other than rewriteTargetListUD() may add junk items
with resname and this fix will remove those junk items as well.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-05 09:25:26 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/05 17:39, Ashutosh Bapat wrote:
> On Fri, Jun 2, 2017 at 2:40 PM, Etsuro Fujita
>> While updating the patch, I noticed the patch rewrites the UPDATE targetList
>> incorrectly in some cases; rewrite_inherited_tlist I added to
>> adjust_appendrel_attrs (1) removes all junk items from the targetList and
>> (2) adds junk items for the child table using rewriteTargetListUD, but it's
>> wrong to drop all junk items in cases where there are junk items for some
>> other reasons than rewriteTargetListUD. Consider junk items containing
>> MULTIEXPR SubLink. One way I came up with to fix this is to change (1) to
>> only remove junk items with resname; since junk items added by
>> rewriteTargetListUD should have resname (note: we would need resname to call
>> ExecFindJunkAttributeInTlist at execution time!) while other junk items
>> wouldn't have resname (see transformUpdateTargetList), we could correctly
>> replace junk items added by rewriteTargetListUD for the parent with ones for
>> the child, by that change. I might be missing something, though. Comments
>> welcome.
>
> I haven't looked at the patch, but that doesn't look right. In future
> some code path other than rewriteTargetListUD() may add junk items
> with resname and this fix will remove those junk items as well.
Yeah, I thought that too. I think we could replace junk tlist entries
added by rewriteTargetListUD() more safely, by adding a lot more code,
but I'm not sure it's worth complicating the code at the current stage.
Best regards,
Etsuro Fujita
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-15 15:05:48 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, 5 Jun 2017 17:25:27 +0900
Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/06/02 18:10, Etsuro Fujita wrote:
> > On 2017/05/16 21:36, Etsuro Fujita wrote:
> >> One approach I came up with to fix this issue is to rewrite the
> >> targetList entries of an inherited UPDATE/DELETE properly using
> >> rewriteTargetListUD, when generating a plan for each child table
> >> in inheritance_planner. Attached is a WIP patch for that. Maybe
> >> I am missing something, though.
> >
> > While updating the patch, I noticed the patch rewrites the UPDATE
> > targetList incorrectly in some cases; rewrite_inherited_tlist I
> > added to adjust_appendrel_attrs (1) removes all junk items from the
> > targetList and (2) adds junk items for the child table using
> > rewriteTargetListUD, but it's wrong to drop all junk items in cases
> > where there are junk items for some other reasons than
> > rewriteTargetListUD. Consider junk items containing MULTIEXPR
> > SubLink. One way I came up with to fix this is to change (1) to
> > only remove junk items with resname; since junk items added by
> > rewriteTargetListUD should have resname (note: we would need
> > resname to call ExecFindJunkAttributeInTlist at execution time!)
> > while other junk items wouldn't have resname (see
> > transformUpdateTargetList), we could correctly replace junk items
> > added by rewriteTargetListUD for the parent with ones for the
> > child, by that change. I might be missing something, though.
> > Comments welcome.
>
> I updated the patch that way. Please find attached an updated
> version.
>
> Other changes:
> * Moved the initialization for "tupleid" I added in ExecModifyTable
> as discussed before, which I think is essentially the same as
> proposed by Ildus in [1], since I think that would be more consistent
> with "oldtuple".
> * Added regression tests.
>
> Anyway I'll add this to the next commitfest.
>
> Best regards,
> Etsuro Fujita
>
> [1]
> https://www.postgresql.org/message-id/20170514150525.0346ba72%40postgrespro.ru
Checked the latest patch. Looks good.
Shouldn't this patch be backported to 9.6 and 10beta? The bug
affects them too.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-16 10:05:47 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/16 0:05, Ildus Kurbangaliev wrote:
I wrote:
>>>> One approach I came up with to fix this issue is to rewrite the
>>>> targetList entries of an inherited UPDATE/DELETE properly using
>>>> rewriteTargetListUD, when generating a plan for each child table
>>>> in inheritance_planner. Attached is a WIP patch for that. Maybe
>>>> I am missing something, though.
>>>
>>> While updating the patch, I noticed the patch rewrites the UPDATE
>>> targetList incorrectly in some cases; rewrite_inherited_tlist I
>>> added to adjust_appendrel_attrs (1) removes all junk items from the
>>> targetList and (2) adds junk items for the child table using
>>> rewriteTargetListUD, but it's wrong to drop all junk items in cases
>>> where there are junk items for some other reasons than
>>> rewriteTargetListUD. Consider junk items containing MULTIEXPR
>>> SubLink. One way I came up with to fix this is to change (1) to
>>> only remove junk items with resname; since junk items added by
>>> rewriteTargetListUD should have resname (note: we would need
>>> resname to call ExecFindJunkAttributeInTlist at execution time!)
>>> while other junk items wouldn't have resname (see
>>> transformUpdateTargetList), we could correctly replace junk items
>>> added by rewriteTargetListUD for the parent with ones for the
>>> child, by that change. I might be missing something, though.
>>> Comments welcome.
>>
>> I updated the patch that way. Please find attached an updated
>> version.
>>
>> Other changes:
>> * Moved the initialization for "tupleid" I added in ExecModifyTable
>> as discussed before, which I think is essentially the same as
>> proposed by Ildus in [1], since I think that would be more consistent
>> with "oldtuple".
>> * Added regression tests.
>>
>> Anyway I'll add this to the next commitfest.
> Checked the latest patch. Looks good.
> Shouldn't this patch be backported to 9.6 and 10beta? The bug
> affects them too.
Thank you for the review!
The bug is in foreign table inheritance, which was supported in 9.5, so
I think this patch should be backported to 9.5.
Ashutosh mentioned his concern about what I proposed above before [2],
but I'm not sure we should address that. And there have been no
opinions from him (or anyone else) since then. So, I'd like to leave
that for committer (ie, +1 for Ready for Committer).
Attached is a slightly-updated version; I renamed some variables used in
rewrite_inherited_tlist() to match other existing code in prepunion.c
and revised some comments a bit. I didn't make any functional changes,
so I'll keep this Ready for Committer.
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
adjust-inherited-update-tlist-v2.patch | text/plain | 12.9 KB |
From: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-16 10:26:13 |
Message-ID: | CAFjFpReUW9JhuyEq5mhi2Hrt3KpjHHP8LnWBZQhrHek3c0KGVQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Fri, Jun 16, 2017 at 3:35 PM, Etsuro Fujita
<fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/06/16 0:05, Ildus Kurbangaliev wrote:
>
>
> I wrote:
>>>>>
>>>>> One approach I came up with to fix this issue is to rewrite the
>>>>> targetList entries of an inherited UPDATE/DELETE properly using
>>>>> rewriteTargetListUD, when generating a plan for each child table
>>>>> in inheritance_planner. Attached is a WIP patch for that. Maybe
>>>>> I am missing something, though.
>>>>
>>>>
>>>> While updating the patch, I noticed the patch rewrites the UPDATE
>>>> targetList incorrectly in some cases; rewrite_inherited_tlist I
>>>> added to adjust_appendrel_attrs (1) removes all junk items from the
>>>> targetList and (2) adds junk items for the child table using
>>>> rewriteTargetListUD, but it's wrong to drop all junk items in cases
>>>> where there are junk items for some other reasons than
>>>> rewriteTargetListUD. Consider junk items containing MULTIEXPR
>>>> SubLink. One way I came up with to fix this is to change (1) to
>>>> only remove junk items with resname; since junk items added by
>>>> rewriteTargetListUD should have resname (note: we would need
>>>> resname to call ExecFindJunkAttributeInTlist at execution time!)
>>>> while other junk items wouldn't have resname (see
>>>> transformUpdateTargetList), we could correctly replace junk items
>>>> added by rewriteTargetListUD for the parent with ones for the
>>>> child, by that change. I might be missing something, though.
>>>> Comments welcome.
>>>
>>>
>>> I updated the patch that way. Please find attached an updated
>>> version.
>>>
>>> Other changes:
>>> * Moved the initialization for "tupleid" I added in ExecModifyTable
>>> as discussed before, which I think is essentially the same as
>>> proposed by Ildus in [1], since I think that would be more consistent
>>> with "oldtuple".
>>> * Added regression tests.
>>>
>>> Anyway I'll add this to the next commitfest.
>
>
>> Checked the latest patch. Looks good.
>> Shouldn't this patch be backported to 9.6 and 10beta? The bug
>> affects them too.
>
>
> Thank you for the review!
>
> The bug is in foreign table inheritance, which was supported in 9.5, so I
> think this patch should be backported to 9.5.
>
> Ashutosh mentioned his concern about what I proposed above before [2], but
> I'm not sure we should address that. And there have been no opinions from
> him (or anyone else) since then. So, I'd like to leave that for committer
> (ie, +1 for Ready for Committer).
That issue has not been addressed. The reason stated was that it would
make code complicated. But I have not had chance to look at how
complicated would be and assess myself whether that's worth the
trouble. There was another issue
Also, I don't see any discussion about my concern [3] about a parent
with child from multiple foreign servers with different FDWs. So, I am
not sure whether the patch really fixes the problem in its entirety.
--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-16 10:45:24 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/16 19:26, Ashutosh Bapat wrote:
> Also, I don't see any discussion about my concern [3] about a parent
> with child from multiple foreign servers with different FDWs. So, I am
> not sure whether the patch really fixes the problem in its entirety.
The patch would allow child tables to have different foreign servers
with different FDWs since it applies rewriteTargetListUD to each child
table when generating a modified query with that child table with the
target in inheritance_planner. I didn't any regression tests for that,
though.
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-16 12:29:17 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/16 19:26, Ashutosh Bapat wrote:
> On Fri, Jun 16, 2017 at 3:35 PM, Etsuro Fujita
>> Ashutosh mentioned his concern about what I proposed above before [2], but
>> I'm not sure we should address that. And there have been no opinions from
>> him (or anyone else) since then. So, I'd like to leave that for committer
>> (ie, +1 for Ready for Committer).
>
> That issue has not been addressed. The reason stated was that it would
> make code complicated. But I have not had chance to look at how
> complicated would be and assess myself whether that's worth the
> trouble.
I have to admit that what I proposed upthread is a quick-and-dirty
kluge. One thing I thought to address your concern was to move
rewriteTargetListUD entirely from the rewriter to the planner when doing
inherited UPDATE/DELETE, but I'm not sure that's a good idea, because at
least I think that would need a lot more changes to the rewriter.
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-06-30 09:44:02 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/16 21:29, Etsuro Fujita wrote:
> On 2017/06/16 19:26, Ashutosh Bapat wrote:
>> That issue has not been addressed. The reason stated was that it would
>> make code complicated. But I have not had chance to look at how
>> complicated would be and assess myself whether that's worth the
>> trouble.
> I have to admit that what I proposed upthread is a quick-and-dirty
> kluge. One thing I thought to address your concern was to move
> rewriteTargetListUD entirely from the rewriter to the planner when doing
> inherited UPDATE/DELETE, but I'm not sure that's a good idea, because at
> least I think that would need a lot more changes to the rewriter.
I'll have second thought about this, so I'll mark this as waiting on author.
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-13 12:10:20 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/06/30 18:44, Etsuro Fujita wrote:
> On 2017/06/16 21:29, Etsuro Fujita wrote:
> I'll have second thought about this, so I'll mark this as waiting on
> author.
I spent quite a bit of time on this and came up with a solution for
addressing the concern mentioned by Ashutosh [1]. The basic idea is, as
I said before, to move rewriteTargetListUD from the rewriter to the
planner (whether the update or delete is inherited or not), except for
the view case. In case of inherited UPDATE/DELETE, the planner adds a
necessary junk column needed for the update or delete for each child
relation, without the assumption I made before about junk tlist entries,
so I think this would be more robust for future changes as mentioned in
[1]. It wouldn't work well that the planner does the same thing for the
view case (ie, add a whole-row reference to the given target relation),
unlike other cases, because what we need to do for that case is to add a
whole-row reference to the view as the source for an INSTEAD OF trigger,
not the target. So, ISTM that it's reasonable to handle that case in
the rewriter as-is, not in the planner, but one thing I'd like to
propose to simplify the code in rewriteHandler.c is to move the code for
the view case in rewriteTargetListUD to ApplyRetrieveRule. By that
change, we won't add a whole-row reference to the view in RewriteQuery,
so we don't need this annoying thing in rewriteTargetView any more:
/*
* For UPDATE/DELETE, rewriteTargetListUD will have added a
wholerow junk
* TLE for the view to the end of the targetlist, which we no
longer need.
* Remove it to avoid unnecessary work when we process the targetlist.
* Note that when we recurse through rewriteQuery a new junk TLE
will be
* added to allow the executor to find the proper row in the new target
* relation. (So, if we failed to do this, we might have multiple junk
* TLEs with the same name, which would be disastrous.)
*/
if (parsetree->commandType != CMD_INSERT)
{
TargetEntry *tle = (TargetEntry *) llast(parsetree->targetList);
Assert(tle->resjunk);
Assert(IsA(tle->expr, Var) &&
((Var *) tle->expr)->varno == parsetree->resultRelation &&
((Var *) tle->expr)->varattno == 0);
parsetree->targetList = list_delete_ptr(parsetree->targetList,
tle);
}
Attached is an updated version of the patch. Comments are welcome!
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
fix-rewrite-tlist.patch | text/plain | 22.0 KB |
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> |
Cc: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-19 10:21:04 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/07/13 21:10, Etsuro Fujita wrote:
> Attached is an updated version of the patch.
Here is an updated version of the patch. Changes are:
* Modified rewrite_targetlist(), which is a new function added to
preptlist.c, so that we do const-simplification to junk TLEs that
AddForeignUpdateTargets() added, as that API allows the FDW to add junk
TLEs containing non-Var expressions to the query's targetlist.
* Updated docs in fdwhandler.sgml.
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
fix-rewrite-tlist-v2.patch | text/plain | 23.3 KB |
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-19 14:36:51 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> writes:
> * Modified rewrite_targetlist(), which is a new function added to
> preptlist.c, so that we do const-simplification to junk TLEs that
> AddForeignUpdateTargets() added, as that API allows the FDW to add junk
> TLEs containing non-Var expressions to the query's targetlist.
This does not seem like a good idea to me. eval_const_expressions is not
a cheap thing, and for most use-cases those cycles will be wasted, and it
has never been the responsibility of preprocess_targetlist to do this sort
of thing.
Please put the responsibility of doing const-expression simplification
in these cases somewhere closer to where the problem is being created.
regards, tom lane
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-20 02:21:57 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/07/19 23:36, Tom Lane wrote:
> Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> writes:
>> * Modified rewrite_targetlist(), which is a new function added to
>> preptlist.c, so that we do const-simplification to junk TLEs that
>> AddForeignUpdateTargets() added, as that API allows the FDW to add junk
>> TLEs containing non-Var expressions to the query's targetlist.
>
> This does not seem like a good idea to me. eval_const_expressions is not
> a cheap thing, and for most use-cases those cycles will be wasted, and it
> has never been the responsibility of preprocess_targetlist to do this sort
> of thing.
Hm, I added that const-simplification to that function so that the
existing FDWs that append junk TLEs that need const-simplification,
which I don't know really exist, would work well for this fix, without
any changes, but I agree on that point.
> Please put the responsibility of doing const-expression simplification
> in these cases somewhere closer to where the problem is being created.
It would be reasonable that it's the FDW's responsibility to do that
const-simplification if necessary?
Best regards,
Etsuro Fujita
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-21 10:16:13 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/07/20 11:21, Etsuro Fujita wrote:
> On 2017/07/19 23:36, Tom Lane wrote:
>> Please put the responsibility of doing const-expression simplification
>> in these cases somewhere closer to where the problem is being created.
>
> It would be reasonable that it's the FDW's responsibility to do that
> const-simplification if necessary?
There seems to be no objections, so I removed the const-expression
simplification from the patch and I added the note to the docs for
AddForeignUpdateTargets.
Attached is an updated version of the patch.
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
fix-rewrite-tlist-v3.patch | text/plain | 23.3 KB |
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-07-24 02:59:13 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 2017/07/21 19:16, Etsuro Fujita wrote:
> On 2017/07/20 11:21, Etsuro Fujita wrote:
>> On 2017/07/19 23:36, Tom Lane wrote:
>>> Please put the responsibility of doing const-expression simplification
>>> in these cases somewhere closer to where the problem is being created.
>>
>> It would be reasonable that it's the FDW's responsibility to do that
>> const-simplification if necessary?
> There seems to be no objections, so I removed the const-expression
> simplification from the patch and I added the note to the docs for
> AddForeignUpdateTargets.
>
> Attached is an updated version of the patch.
I cleaned up the patch a bit. PFA a new version of the patch.
Best regards,
Etsuro Fujita
Attachment | Content-Type | Size |
---|---|---|
fix-rewrite-tlist-v4.patch | text/plain | 23.2 KB |
From: | Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-09-12 15:26:22 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Mon, 24 Jul 2017 11:59:13 +0900
Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2017/07/21 19:16, Etsuro Fujita wrote:
> > On 2017/07/20 11:21, Etsuro Fujita wrote:
> >> On 2017/07/19 23:36, Tom Lane wrote:
> >>> Please put the responsibility of doing const-expression
> >>> simplification in these cases somewhere closer to where the
> >>> problem is being created.
> >>
> >> It would be reasonable that it's the FDW's responsibility to do
> >> that const-simplification if necessary?
> > There seems to be no objections, so I removed the const-expression
> > simplification from the patch and I added the note to the docs for
> > AddForeignUpdateTargets.
> >
> > Attached is an updated version of the patch.
>
> I cleaned up the patch a bit. PFA a new version of the patch.
>
> Best regards,
> Etsuro Fujita
Checked, looks good to me. Changed status to 'Ready for Commiter'.
--
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-26 22:56:32 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> writes:
> [ fix-rewrite-tlist-v4.patch ]
I started reviewing this patch. I did not much like the fact that it
effectively moved rewriteTargetListUD to a different file and renamed it.
That seems like unnecessary code churn, plus it breaks the analogy with
rewriteTargetListIU, plus it will make back-patching harder (since that
code isn't exactly the same in back branches). I see little reason why
we can't leave it where it is and just make it non-static. It's not like
there's no other parts of the rewriter that the planner calls.
I revised the patch along that line, and while at it, refactored
preptlist.c a bit to eliminate repeated heap_opens of the target
relation. I've not really reviewed any other aspects of the patch
yet, but in the meantime, does anyone object to proceeding this way?
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
fix-rewrite-tlist-v5.patch | text/x-diff | 25.5 KB |
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 05:38:12 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
(2017/11/27 7:56), Tom Lane wrote:
> Etsuro Fujita<fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> writes:
>> [ fix-rewrite-tlist-v4.patch ]
>
> I started reviewing this patch.
Great!
> I did not much like the fact that it
> effectively moved rewriteTargetListUD to a different file and renamed it.
> That seems like unnecessary code churn, plus it breaks the analogy with
> rewriteTargetListIU, plus it will make back-patching harder (since that
> code isn't exactly the same in back branches). I see little reason why
> we can't leave it where it is and just make it non-static. It's not like
> there's no other parts of the rewriter that the planner calls.
Agreed.
Best regards,
Etsuro Fujita
From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 11:19:31 |
Message-ID: | CAEZATCUGUnUoDJC=bf-L_vdMjMKDxUXN+XudkuN5wf4FDKNT=A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 26 November 2017 at 22:56, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> writes:
>> [ fix-rewrite-tlist-v4.patch ]
>
> I started reviewing this patch. I did not much like the fact that it
> effectively moved rewriteTargetListUD to a different file and renamed it.
> That seems like unnecessary code churn, plus it breaks the analogy with
> rewriteTargetListIU, plus it will make back-patching harder (since that
> code isn't exactly the same in back branches). I see little reason why
> we can't leave it where it is and just make it non-static. It's not like
> there's no other parts of the rewriter that the planner calls.
>
I wonder if, years from now, it might look a bit odd that
rewriteTargetListUD() is doing part of work of preptlist.c, is only
called from there, and yet is located in the rewriter.
Aside from having a similar name to rewriteTargetListIU(), what
rewriteTargetListUD() does seems more like what
preprocess_targetlist() does for rowmarks. The fact that
rewriteTargetListIU() intentionally only applies to the parent,
whereas preprocess_targetlist() and now rewriteTargetListUD() apply to
each child, further destroys any similarity between
rewriteTargetListUD() and rewriteTargetListIU().
The point about back-patching is a reasonable one though, so I won't
mind either way.
A separate point -- it might be marginally more efficient to have the
work of rewriteTargetListUD() done after expand_targetlist() to avoid
the possible renumbering of the resjunk entries.
Regards,
Dean
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 15:49:32 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> I wonder if, years from now, it might look a bit odd that
> rewriteTargetListUD() is doing part of work of preptlist.c, is only
> called from there, and yet is located in the rewriter.
Yeah, I probably wouldn't have done it like this in a green field,
but maintaining traceability to the existing code is valuable IMO.
> A separate point -- it might be marginally more efficient to have the
> work of rewriteTargetListUD() done after expand_targetlist() to avoid
> the possible renumbering of the resjunk entries.
Hm. It wouldn't save a lot, but yeah, doing it in this order seems
a bit silly when you put it like that.
regards, tom lane
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 16:35:36 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
I wrote:
> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
>> A separate point -- it might be marginally more efficient to have the
>> work of rewriteTargetListUD() done after expand_targetlist() to avoid
>> the possible renumbering of the resjunk entries.
> Hm. It wouldn't save a lot, but yeah, doing it in this order seems
> a bit silly when you put it like that.
On looking closer, the reason it's like that in Fujita-san's patch
is to minimize the API churn seen by FDW AddForeignUpdateTargets
functions, specifically whether they see a tlist that's before or
after what expand_targetlist() does. I'm doubtful that the
potential savings is worth taking risks there. In particular,
it seems like a good thing that expand_targetlist() verifies the
correct tlist ordering *after* the FDW function has acted.
So now my inclination is to leave this alone.
regards, tom lane
From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 17:22:00 |
Message-ID: | CAEZATCUvwW4nacdHcaG3E7EaEj6Pqa86FHOuzUEXaahuo10F5g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 27 November 2017 at 16:35, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I wrote:
>> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
>>> A separate point -- it might be marginally more efficient to have the
>>> work of rewriteTargetListUD() done after expand_targetlist() to avoid
>>> the possible renumbering of the resjunk entries.
>
>> Hm. It wouldn't save a lot, but yeah, doing it in this order seems
>> a bit silly when you put it like that.
>
> On looking closer, the reason it's like that in Fujita-san's patch
> is to minimize the API churn seen by FDW AddForeignUpdateTargets
> functions, specifically whether they see a tlist that's before or
> after what expand_targetlist() does. I'm doubtful that the
> potential savings is worth taking risks there. In particular,
> it seems like a good thing that expand_targetlist() verifies the
> correct tlist ordering *after* the FDW function has acted.
> So now my inclination is to leave this alone.
>
Ah yes, that seems like a worthwhile check to keep. Never mind then.
Regards,
Dean
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Cc: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-27 22:58:23 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> On 27 November 2017 at 16:35, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> On looking closer, the reason it's like that in Fujita-san's patch
>> is to minimize the API churn seen by FDW AddForeignUpdateTargets
>> functions, specifically whether they see a tlist that's before or
>> after what expand_targetlist() does. I'm doubtful that the
>> potential savings is worth taking risks there. In particular,
>> it seems like a good thing that expand_targetlist() verifies the
>> correct tlist ordering *after* the FDW function has acted.
>> So now my inclination is to leave this alone.
> Ah yes, that seems like a worthwhile check to keep. Never mind then.
Pushed with that and some cosmetic fiddling with comments and docs.
Thanks for the discussion!
regards, tom lane
From: | Etsuro Fujita <fujita(dot)etsuro(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com> |
Subject: | Re: [HACKERS] Bug in ExecModifyTable function and trigger issues for foreign tables |
Date: | 2017-11-28 01:55:37 |
Message-ID: | [email protected] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
(2017/11/28 7:58), Tom Lane wrote:
> Pushed with that and some cosmetic fiddling with comments and docs.
Thank you.
Best regards,
Etsuro Fujita