Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR7sr-0002lU-IH for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Mar 2021 06:29:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lR7so-0002Uv-V3 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Mar 2021 06:29:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR7so-0002Uo-Mz for pgsql-hackers@lists.postgresql.org; Tue, 30 Mar 2021 06:29:46 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lR7sh-0000ph-HX for pgsql-hackers@lists.postgresql.org; Tue, 30 Mar 2021 06:29:45 +0000 Received: from hnk.local (p2350207-ipbf2126funabasi.chiba.ocn.ne.jp [114.167.184.207]) by oss.nttdata.com (Postfix) with ESMTPSA id DB0B76243D; Tue, 30 Mar 2021 15:29:34 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: TRUNCATE on foreign table To: Kohei KaiGai Cc: Kazutaka Onishi , Amit Langote , Ibrar Ahmed , Bharath Rupireddy , Zhihong Yu , PostgreSQL Developers , Ashutosh Bapat References: <66da56a4-ed5a-a18f-0f5e-b4d21cda71af@oss.nttdata.com> From: Fujii Masao Message-ID: <083f82e6-818a-b758-162b-6152ffa9224e@oss.nttdata.com> Date: Tue, 30 Mar 2021 15:29:33 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021/03/30 10:11, Kohei KaiGai wrote: > 2021年3月30日(火) 3:45 Fujii Masao : >> >> On 2021/03/28 2:37, Kazutaka Onishi wrote: >>> Fujii-san, >>> >>> Thank you for your review! >>> Now I prepare v5 patch and I'll answer to your each comment. please >>> check this again. >>> m(_ _)m >>> >>> 1. In postgres-fdw.sgml, "and truncatable" should be appended into the >>> above first description? >>> 2. truncate.sgml should be updated because, for example, it contains >>> the above descriptions. >>> >>> Yeah, you're right. I've fixed it. >>> >>> >>> >>> 3. Don't we need to document the detail information about frels_extra? >>> >>> I've written about frels_extra into fdwhander.sgml. >>> >>> >>> >>> 4. postgres_fdw determines whether to specify ONLY or not by checking >>> whether the passed extra value is zero or not. >>> >>> Please refer this: >>> https://www.postgresql.org/message-id/CAOP8fzb-t3WVNLjGMC%2B4sV4AZa9S%3DMAQ7Q6pQoADMCf_1jp4ew%40mail.gmail.com >>>> Negative value means that foreign-tables are not specified in the TRUNCATE >>>> command, but truncated due to dependency (like partition's child leaf). >>> >>> I've added this information into fdwhandler.sgml. >> >> Even when a foreign table is specified explicitly in TRUNCATE command, >> its extra value can be negative if it's found as an inherited children firstly >> (i.e., in the case where the partitioned table having that foreign table as >> its partition is specified explicitly in TRUNCATE command). >> Isn't this a problem? >> >> Please imagine the following example; >> >> ---------------------------------- >> create extension postgres_fdw; >> create server loopback foreign data wrapper postgres_fdw; >> create user mapping for public server loopback; >> >> create table t (i int, j int) partition by hash (j); >> create table t0 partition of t for values with (modulus 2, remainder 0); >> create table t1 partition of t for values with (modulus 2, remainder 1); >> >> create table test (i int, j int) partition by hash (i); >> create table test0 partition of test for values with (modulus 2, remainder 0); >> create foreign table ft partition of test for values with (modulus 2, remainder 1) server loopback options (table_name 't'); >> ---------------------------------- >> >> In this example, "truncate ft, test" works fine, but "truncate test, ft" causes >> an error though they should work in the same way basically. >> > (Although it was originally designed by me...) > If frels_extra would be a bit-masked value, we can avoid the problem. > > Please assume the three labels below: > #define TRUNCATE_REL_CONTEXT__NORMAL 0x01 > #define TRUNCATE_REL_CONTEXT__ONLY 0x02 > #define TRUNCATE_REL_CONTEXT__CASCADED 0x04 > > Then, assign these labels on the extra flag according to the context where > the foreign-tables appeared in the truncate command. > Even if it is specified multiple times in the different context, FDW extension > can handle the best option according to the flags. > >> In this example, "truncate ft, test" works fine, but "truncate test, ft" causes > > In both cases, ExecForeignTruncate shall be invoked to "ft" with > (NORMAL | CASCADED), > thus, postgres_fdw can determine the remote truncate command shall be > executed without "ONLY" clause. > > How about the idea? This idea looks better to me. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION