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 1k0hZJ-0003AY-V5 for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jul 2020 08:36:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k0hZI-0005HM-TF for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jul 2020 08:36:08 +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 1k0hZI-0005HF-IO for pgsql-hackers@lists.postgresql.org; Wed, 29 Jul 2020 08:36:08 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k0hZF-0000NY-4Y for pgsql-hackers@postgresql.org; Wed, 29 Jul 2020 08:36:07 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 0246621C2C19; Wed, 29 Jul 2020 11:36:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.129.197] (unknown [94.25.177.55]) (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 630DB21C2C0B; Wed, 29 Jul 2020 11:36:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1596011762; bh=P0wZISjA2FVkKpN1ucRif6axsXQMnKFBKYDtxXtkaDM=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=fGWkgBUeXvFHWKMrWbhmZGRBXomm5zRksBa9U51pY4HPJqZilt2k3wKQiqCvTMvhr IE75NRIV8zKUPJndzluIIgdsvVl/WfdSgN+Xk32ey4Af3nzil/vJv84oYCL8OD7vpX nKD8UeNGxBSCpWEJokNrKuiMpnKgWnYfRLlsq9eA= Subject: Re: [POC] Fast COPY FROM command for the table with foreign partitions To: Amit Langote Cc: Ashutosh Bapat , Ashutosh Bapat , Etsuro Fujita , PostgreSQL-Dev References: <3d0909dc-3691-a576-208a-90986e55489f@postgrespro.ru> <7a3c3bdd-dc43-68a7-7cc5-ae139f1de4a7@postgrespro.ru> From: "Andrey V. Lepikhov" Organization: Postgres Professional Message-ID: <9a65d03b-250f-b086-5a3c-541d8e2de30d@postgrespro.ru> Date: Wed, 29 Jul 2020 13:36:01 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/29/20 1:03 PM, Amit Langote wrote: > Hi Andrey, > > Thanks for updating the patch. I will try to take a look later. > > On Wed, Jul 22, 2020 at 6:09 PM Andrey V. Lepikhov > wrote: >> On 7/16/20 2:14 PM, Amit Langote wrote: >>> * Why the "In" in these API names? >>> >>> + /* COPY a bulk of tuples into a foreign relation */ >>> + BeginForeignCopyIn_function BeginForeignCopyIn; >>> + EndForeignCopyIn_function EndForeignCopyIn; >>> + ExecForeignCopyIn_function ExecForeignCopyIn; >> >> I used an analogy from copy.c. > > Hmm, if we were going to also need *ForeignCopyOut APIs, maybe it > makes sense to have "In" here, but maybe we don't, so how about > leaving out the "In" for clarity? Ok, sounds good. > >>> * I see that the remote copy is performed from scratch on every call >>> of postgresExecForeignCopyIn(), but wouldn't it be more efficient to >>> send the `COPY remote_table FROM STDIN` in >>> postgresBeginForeignCopyIn() and end it in postgresEndForeignCopyIn() >>> when there are no errors during the copy? >> >> It is not possible. FDW share one connection between all foreign >> relations from a server. If two or more partitions will be placed at one >> foreign server you will have problems with concurrent COPY command. > > Ah, you're right. I didn't consider multiple foreign partitions > pointing to the same server. Indeed, we would need separate > connections to a given server to COPY to multiple remote relations on > that server in parallel. > >> May be we can create new connection for each partition? > > Yeah, perhaps, although it sounds like something that might be more > generally useful and so we should work on that separately if at all. I will try to prepare a separate patch. > >>> I tried implementing these two changes -- pgfdw_copy_data_dest_cb() >>> and sending `COPY remote_table FROM STDIN` only once instead of on >>> every flush -- and I see significant speedup. Please check the >>> attached patch that applies on top of yours. >> >> I integrated first change and rejected the second by the reason as above. > > Thanks. > > Will send more comments after reading the v5 patch. > Ok. I'll be waiting for the end of your review. -- regards, Andrey Lepikhov Postgres Professional