Re: TRUNCATE on foreign table

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Kohei KaiGai <kaigai(at)heterodb(dot)com>
Cc: Kazutaka Onishi <onishi(at)heterodb(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Zhihong Yu <zyu(at)yugabyte(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, Ibrar Ahmed <ibrar(dot)ahmad(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Subject: Re: TRUNCATE on foreign table
Date: 2021-04-08 09:25:29
Message-ID: 43f71643-5068-8a77-4bda-005b0ff7bd4f@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2021/04/08 15:48, Kohei KaiGai wrote:
> 2021年4月8日(木) 15:04 Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>:
>>
>> On 2021/04/08 13:43, Kohei KaiGai wrote:
>>> In case when a local table (with no children) has same contents,
>>> TRUNCATE command
>>> witll remove the entire table contents.
>>
>> But if there are local child tables that inherit the local parent table, and TRUNCATE ONLY <parent table> is executed, only the contents in the parent will be truncated. I was thinking that this behavior should be applied to the foreign table whose remote (parent) table have remote child tables.
>>
>> So what we need to reach the consensus is; how far ONLY option affects. Please imagine the case where we have
>>
>> (1) local parent table, also foreign table of remote parent table
>> (2) local child table, inherits local parent table
>> (3) remote parent table
>> (4) remote child table, inherits remote parent table
>>
>> I think that we agree all (1), (2), (3) and (4) should be truncated if local parent table (1) is specified without ONLY in TRUNCATE command. OTOH, if ONLY is specified, we agree that at least local child table (2) should NOT be truncated.
>>
> My understanding of a foreign table is a representation of external
> data, including remote RDBMS but not only RDBMS,
> regardless of the parent-child relationship at the local side.
> So, once a local foreign table wraps entire tables tree (a parent and
> relevant children) at the remote side, at least, it shall
> be considered as a unified data chunk from the standpoint of the local side.

At least for me it's not intuitive to truncate the remote table and its all dependent tables even though users explicitly specify ONLY for the foreign table. As far as I read the past discussion, some people was thinking the same.

>
> Please assume if file_fdw could map 3 different CSV files, then
> truncate on the foreign table may eliminate just 1 of 3 files.
> Is it an expected / preferable behavior?

I think that's up to each FDW. That is, IMO the information about whether ONLY is specified or not for each table should be passed to FDW. Then FDW itself should determine how to handle that information.

Anyway, attached is the updated version of the patch. This is still based on the latest Kazutaka-san's patch. That is, extra list for ONLY is still passed to FDW. What about committing this version at first? Then we can continue the discussion and change the behavior later if necessary.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachment Content-Type Size
pgsql14-truncate-on-foreign-table.v17.patch text/plain 40.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2021-04-08 09:41:17 Re: A new function to wait for the backend exit after termination
Previous Message Amit Langote 2021-04-08 09:03:52 Re: Wired if-statement in gen_partprune_steps_internal