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 1kFfdn-0001nJ-4c for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2020 15:34:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFfdm-0003HB-1k for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2020 15:34:38 +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 1kFfdl-0003H3-O0 for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2020 15:34:37 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFfdi-0000G6-9k for pgsql-hackers@postgresql.org; Tue, 08 Sep 2020 15:34:36 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id D0C0421C31F2; Tue, 8 Sep 2020 18:34:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1599579271; bh=yK4XLgW2iUsEUSJ+EOkusW5qaCdURkTHY+yKPLk0+gI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=o6rW0W5yCTiJlHjeuiaxAg6XJ3pA1EeSBSexTmh5VvyKTjy89a9/2AiHxTljokEdt crGO3JMVVFeIKacrWKl9C2eaGIxx1rEbUo/J9ymKvmK8yS5o1DrVCs2CQ7wIr4KZbl DwfNwqeCllmOQ75wJasDllAK6gYH1svs4rPu4TP0= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 08 Sep 2020 18:34:31 +0300 From: Alexey Kondratov To: Amit Langote Cc: "Andrey V. Lepikhov" , Michael Paquier , Ashutosh Bapat , Ashutosh Bapat , Etsuro Fujita , PostgreSQL-Dev Subject: Re: [POC] Fast COPY FROM command for the table with foreign partitions In-Reply-To: References: <9a65d03b-250f-b086-5a3c-541d8e2de30d@postgrespro.ru> <20200907072651.GF4867@paquier.xyz> <19ba27e7-ee1e-9117-68ad-fd609b5763ca@postgrespro.ru> <0c67618c2e43b1dccb260dd6f90eeac2@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.0 Message-ID: X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-09-08 17:00, Amit Langote wrote: > Hi Alexey, > > On Tue, Sep 8, 2020 at 6:29 PM Alexey Kondratov > wrote: >> On 2020-09-08 10:34, Amit Langote wrote: >> > Any thoughts on the taking out the refactoring changes out of the main >> > patch as I suggested? >> > >> >> +1 for splitting the patch. It was rather difficult for me to >> distinguish changes required by COPY via postgres_fdw from this >> refactoring. >> >> Another ambiguous part of the refactoring was in changing >> InitResultRelInfo() arguments: >> >> @@ -1278,6 +1280,7 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo, >> Relation resultRelationDesc, >> Index resultRelationIndex, >> Relation partition_root, >> + bool use_multi_insert, >> int instrument_options) >> >> Why do we need to pass this use_multi_insert flag here? Would it be >> better to set resultRelInfo->ri_usesMultiInsert in the >> InitResultRelInfo() unconditionally like it is done for >> ri_usesFdwDirectModify? And after that it will be up to the caller >> whether to use multi-insert or not based on their own circumstances. >> Otherwise now we have a flag to indicate that we want to check for >> another flag, while this check doesn't look costly. > > Hmm, I think having two flags seems confusing and bug prone, > especially if you consider partitions. For example, if a partition's > ri_usesMultiInsert is true, but CopyFrom()'s local flag is false, then > execPartition.c: ExecInitPartitionInfo() would wrongly perform > BeginForeignCopy() based on only ri_usesMultiInsert, because it > wouldn't know CopyFrom()'s local flag. Am I missing something? No, you're right. If someone want to share a state and use ResultRelInfo (RRI) for that purpose, then it's fine, but CopyFrom() may simply override RRI->ri_usesMultiInsert if needed and pass this RRI further. This is how it's done for RRI->ri_usesFdwDirectModify. InitResultRelInfo() initializes it to false and then ExecInitModifyTable() changes the flag if needed. Probably this is just a matter of personal choice, but for me the current implementation with additional argument in InitResultRelInfo() doesn't look completely right. Maybe because a caller now should pass an additional argument (as false) even if it doesn't care about ri_usesMultiInsert at all. It also adds additional complexity and feels like abstractions leaking. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company