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 1kjeYd-0006Ja-Fu for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2020 08:29:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kjeYb-00053O-4x for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2020 08:29:13 +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 1kjeYa-00053H-Gt for pgsql-hackers@lists.postgresql.org; Mon, 30 Nov 2020 08:29:12 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kjeYT-0000Mp-DP for pgsql-hackers@postgresql.org; Mon, 30 Nov 2020 08:29:11 +0000 Received: by fetter.org (Postfix, from userid 1001) id ED75641BA6; Mon, 30 Nov 2020 09:29:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fetter.org; s=default; t=1606724942; bh=TvHz/Zh0yEzdvK8Ws2juKG+22YmLtTXQlaP1II3Ecos=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xd9ooFaq9v5GfbZlH6wo0GFY3/CV0jxue3KVHL6zzEy/GJc+bm7cBmjyapURSJPMe MHFj/Ms/gQE7WMSz0NYo7lACNMCrIhwxEA8K0nFghjPNsFb7j8a5/Bh8bYhR4bzIgE Hi+fRe8fdzfC7BtagwHmZNz1hAjSuETWHd95f7sy2hVi4my5sChc7Xh2w37ihth4gg 2CaP0ggunKweggrdHt9I8n4G7HU5SNGdUajNM2j1IvZCY3kjXNjVVKRsatfQvGJkmW igSshoKOjWO56WRv/HexZMxAB+hOso3eKR0+dwpJEQ3Y62rr96MDmqWX35Dx81bZHX RiuuLA+t8Pduw== Date: Mon, 30 Nov 2020 09:29:02 +0100 From: David Fetter To: "tsunakawa.takay@fujitsu.com" Cc: 'Tomas Vondra' , 'Tomas Vondra' , "Andrey V. Lepikhov" , "pgsql-hackers@postgresql.org" Subject: Re: POC: postgres_fdw insert batching Message-ID: <20201130082902.GD9795@fetter.org> References: <71113ab1-ed31-3dbc-ce07-e081e17473b6@enterprisedb.com> <43b5d643-da69-70a5-16d2-d04d0851b723@enterprisedb.com> <0ab26876-9e89-ef24-094d-35b991672309@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Nov 25, 2020 at 05:04:36AM +0000, tsunakawa.takay@fujitsu.com wrote: > From: Tomas Vondra > > On 11/24/20 9:45 AM, tsunakawa.takay@fujitsu.com wrote: > > > OTOH, as for the name GetModifyBatchSize() you suggest, I think > > GetInsertBatchSize may be better. That is, this API deals with multiple > > records in a single INSERT statement. Your GetModifyBatchSize will be > > reserved for statement batching when libpq has supported batch/pipelining to > > execute multiple INSERT/UPDATE/DELETE statements, as in the following > > JDBC batch updates. What do you think? > > > > > > > I don't know. I was really only thinking about batching in the context > > of a single DML command, not about batching of multiple commands at the > > protocol level. IMHO it's far more likely we'll add support for batching > > for DELETE/UPDATE than libpq pipelining, which seems rather different > > from how the FDW API works. Which is why I was suggesting to use a name > > that would work for all DML commands, not just for inserts. > > Right, I can't imagine now how the interaction among the client, server core and FDWs would be regarding the statement batching. So I'll take your suggested name. > > > > Not sure, but I'd guess knowing whether batching is used would be > > useful. We only print the single-row SQL query, which kinda gives the > > impression that there's no batching. > > Added in postgres_fdw like "Remote SQL" when EXPLAIN VERBOSE is run. > > > > > Don't worry about this, too. GetMaxBulkInsertTuples() just returns a value > > that was already saved in a struct in create_foreign_modify(). > > > > > > > Well, I do worry for two reasons. > > > > Firstly, the fact that in postgres_fdw the call is cheap does not mean > > it'll be like that in every other FDW. Presumably, the other FDWs might > > cache it in the struct and do the same thing, of course. > > > > But the fact that we're calling it over and over for each row kinda > > seems like we allow the value to change during execution, but I very > > much doubt the code is expecting that. I haven't tried, but assume the > > function first returns 10 and then 100. ISTM the code will allocate > > ri_Slots with 25 slots, but then we'll try stashing 100 tuples there. > > That can't end well. Sure, we can claim it's a bug in the FDW extension, > > but it's also due to the API design. > > You worried about other FDWs than postgres_fdw. That's reasonable. I insisted in other threads that PG developers care only about postgres_fdw, not other FDWs, when designing the FDW interface, but I myself made the same mistake. I made changes so that the executor calls GetModifyBatchSize() once per relation per statement. Please pardon me for barging in late in this discussion, but if we're going to be using a bulk API here, wouldn't it make more sense to use COPY, except where RETURNING is specified, in place of INSERT? Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate