Re: TRUNCATE on foreign table - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: TRUNCATE on foreign table
Date
Msg-id CALj2ACWBFB7+rLucPhW3R_=nGmGVsaiOOMqV+s+pPziry7QiSw@mail.gmail.com
Whole thread Raw
In response to Re: TRUNCATE on foreign table  (Fujii Masao <masao.fujii@oss.nttdata.com>)
List pgsql-hackers
On Fri, Apr 9, 2021 at 7:06 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
> >      > 2. Currently when the same foreign table is specified multiple times in the command, the extra information
onlyfor the foreign table found first is collected. For example, when "TRUNCATE ft, ONLY ft" is executed,
TRUNCATE_REL_CONTEXT_NORMALis collected and _ONLY is ignored because "ft" is found first. Is this OK? Or we should
collectall, e.g., both _NORMAL and _ONLY should be collected in that example? I think that the current approach (i.e.,
collectthe extra info about table found first if the same table is specified multiple times) is good because even local
tablesare also treated the same way. But Kaigai-san does not. 
> >
> >     IMO, the foreign truncate command should be constructed by collecting
> >     all the information i.e. "TRUNCATE ft, ONLY ft" and let the remote
> >     server execute how it wants to execute. That will be consistent and no
> >     extra logic is required to track the already seen foreign tables while
> >     foreign table collection/foreign truncate command is being prepared on
> >     the local server.
>
> But isn't it difficult for remote server to determine how to execute? Please imagine the case where there are four
tablesas follows. 
>
> - regular table "remote_parent" in the remote server
> - regular table "remote_child" inheriting "remote_parent" table in the remote server
> - foreign table "local_parent" in the local server, accessing "remote_parent" table
> - regular table "local_child" inheriting "local_parent" table in the local server
>
> When "TRUNCATE ONLY local_parent, local_parent" is executed, local_child is not truncated because of ONLY clause.
Thenif we collect all the information about context, both TRUNCATE_REL_CONTEXT_NORMAL and _ONLY are passed to FDW. In
thiscase how should FDW determine whether to use ONLY when issuing TRUNCATE command to the remote server? Isn't it
difficultto do that? If FDW determines not to use ONLY because _NORMAL flag is passed, both remote_parent and
remote_childtables are truncated. That is, though both local_child and remote_child are the inheriting tables, isn't it
strangethat only the former is ignored and the latter is truncated? 

My understanding was wrong. I see below code from ExecuteTruncate:
        /* don't throw error for "TRUNCATE foo, foo" */
        if (list_member_oid(relids, myrelid))
        {
            table_close(rel, lockmode);
            continue;
        }

This basically tells us that the first occurence of a table is
considered, rest all ignored. This is what we are going to have in our
relids_extra and relids. So, we will be sending only the first
occurence info to the foreign truncate command.  I agree with the
current approach "i.e., collect the extra info about table found first
if the same table is specified multiple times" for the same reason
that "local tables are also treated the same way."

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: TRUNCATE on foreign table
Next
From: Kohei KaiGai
Date:
Subject: Re: TRUNCATE on foreign table