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 1kFwcK-0005nt-9E for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2020 09:42:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFwcJ-0001va-22 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2020 09:42:15 +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 1kFwcI-0001vT-RK for pgsql-hackers@lists.postgresql.org; Wed, 09 Sep 2020 09:42:14 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFwcE-0001Qa-N9 for pgsql-hackers@postgresql.org; Wed, 09 Sep 2020 09:42:13 +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 BA6C721C2B5F; Wed, 9 Sep 2020 12:42:09 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1599644529; bh=nI7YbxIswHymrxalGmRr+D4sIU2AKPCIMmI8yA2OIRc=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Q1eESfs3T93jimTIXUcNPHmOgUTgk+hnsEqkcYU/I+aBfkw8iLeIMomPff51soei6 uM2DdA23frzAdkSSzmqIXvswgO0ntKNzFdnYlVaPPjHKSROIHQapIVNLw/Ma/m0QND Hyr+pRgAYS9Bu93Yldpo6zFJjqUp43yXx2X+5mbk= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 09 Sep 2020 12:42:09 +0300 From: Alexey Kondratov To: "Andrey V. Lepikhov" Cc: Amit Langote , 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: <27e119ab-70a4-a08a-deb2-d882e2ce9435@postgrespro.ru> References: <9a65d03b-250f-b086-5a3c-541d8e2de30d@postgrespro.ru> <20200907072651.GF4867@paquier.xyz> <19ba27e7-ee1e-9117-68ad-fd609b5763ca@postgrespro.ru> <0c67618c2e43b1dccb260dd6f90eeac2@postgrespro.ru> <27e119ab-70a4-a08a-deb2-d882e2ce9435@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <21741c8e5df397d88e9eff3e741baf91@postgrespro.ru> X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-09-09 11:45, Andrey V. Lepikhov wrote: > On 9/8/20 8:34 PM, Alexey Kondratov wrote: >> On 2020-09-08 17:00, Amit Langote wrote: >>> wrote: >>>> On 2020-09-08 10:34, Amit Langote wrote: >>>> 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. > I didn't feel what the problem was and prepared a patch version > according to Alexey's suggestion (see Alternate.patch). Yes, that's very close to what I've meant. + leaf_part_rri->ri_usesMultiInsert = (leaf_part_rri->ri_usesMultiInsert && + rootResultRelInfo->ri_usesMultiInsert) ? true : false; This could be just: + leaf_part_rri->ri_usesMultiInsert = (leaf_part_rri->ri_usesMultiInsert && + rootResultRelInfo->ri_usesMultiInsert); > This does not seem very convenient and will lead to errors in the > future. So, I agree with Amit. And InitResultRelInfo() may set ri_usesMultiInsert to false by default, since it's used only by COPY now. Then you won't need this in several places: + resultRelInfo->ri_usesMultiInsert = false; While the logic of turning multi-insert on with all the validations required could be factored out of InitResultRelInfo() to a separate routine. Anyway, I don't insist at all and think it's fine to stick to the original v7's logic. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company