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 1kQeBG-0004hv-Ms for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Oct 2020 22:14:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQeBF-0004Av-J7 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Oct 2020 22:14:33 +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 1kQeBF-0004Ao-CM for pgsql-hackers@lists.postgresql.org; Thu, 08 Oct 2020 22:14:33 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQeB8-0000dQ-Fm for pgsql-hackers@postgresql.org; Thu, 08 Oct 2020 22:14:32 +0000 Received: by mail-ed1-x541.google.com with SMTP id v19so7392840edx.9 for ; Thu, 08 Oct 2020 15:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dcuyxWuVioEeKsppBkGN06B6v3ZMGfxnFPTDsP5cELg=; b=e+7dhHVYBuYFhrcbT5omH1Zz0txrew9hImGGKQEadk2T3noY8Lq9z4QP9H6o58CIFj cNuiIavamJb4zvizZtnhseWOTMaZK/hp6tAX71r8g0KPF/b3KWLO5dAW1yK3QaJZwOMf miNR9qC5ankOCr7ZS6MDluA/o6kf28i0NKFU9XnhywQpBZ8/1UmZhAdj0QC0AZorX8+S qw9ybnChesl53LqgfiZPzdEBVBfBlZ1aj4zWd2+jTKhv/4AUEfxgWuHRd/VZCTNA0aLJ O0CXGIkNr22sOlNdUrpKfvZwbpaYAJ8MapkjcGbebfvSIRByJjatsQW0Rjbsqi+z2owj V2yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dcuyxWuVioEeKsppBkGN06B6v3ZMGfxnFPTDsP5cELg=; b=Xa63gEV6hsqJtiaKx+Jcc0l3RvDnIXi65OVeOff9yaJpxfroBdw045cFT4Sux/xYs5 j2Tv7lcVrsfMO2URcg9uxc9lv8w4Q8L2MxGYDvpv1qTo6+8U3mBqk3DRSmlb15RZ2NHg r2tZPQRaBFGXMZvja5ADFWf2B6jOyIjBIi8rFsZB2fANZ7igNQNXJaBtQrXKjEmzFw0b 7qwqNCLbICvMnNdf21idIvq7Pzy1DYvs7FocKwnQNLyqe5wtD3uAsaO6LdmiJXq975oo HUCKYHgPAO7iDz66nYM+gTUOUEh7dMwiXg/n+jtIsmRSetuAhjP/ZLwBTRrEmDCCdOn4 gPww== X-Gm-Message-State: AOAM532Pp+VeeJfyiCiTUo5FIk4SBCxGhdkSC4yIzGsDv25ZMzys/GnC iUCTkkxjkPNIv7RhUIGSTUYfuQ== X-Google-Smtp-Source: ABdhPJweVPMdOYyT7d1J3/UTx4GqhCuGYJ8pCf6YyXH0+JbslVLRyrPnFeNwns1MFAJww/5GbozsAw== X-Received: by 2002:a05:6402:1615:: with SMTP id f21mr11590572edv.257.1602195263469; Thu, 08 Oct 2020 15:14:23 -0700 (PDT) Received: from localhost (ip-86-49-245-76.net.upcbroadband.cz. [86.49.245.76]) by smtp.gmail.com with ESMTPSA id o11sm4974351ejd.60.2020.10.08.15.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 15:14:22 -0700 (PDT) Date: Fri, 9 Oct 2020 00:14:21 +0200 From: Tomas Vondra To: "tsunakawa.takay@fujitsu.com" Cc: "Andrey V. Lepikhov" , "pgsql-hackers@postgresql.org" Subject: Re: POC: postgres_fdw insert batching Message-ID: <20201008221421.foasnh5of66rupnm@development> References: <20200628151002.7x5laxwpgvkyiu3q@development> <0300d7df-854b-6f72-1e93-dfbf98f3fc8a@postgrespro.ru> <20200712001101.x65f3hvsanvamtgj@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Oct 08, 2020 at 02:40:10AM +0000, tsunakawa.takay@fujitsu.com wrote: >Hello Tomas san, > > >Thank you for picking up this. I'm interested in this topic, too. (As an aside, we'd like to submit a bulk insert patch for ECPG in the near future.) > >As others referred, Andrey-san's fast COPY to foreign partitions is also promising. But I think your bulk INSERT is a separate feature and offers COPY cannot do -- data transformation during loading with INSERT SELECT and CREATE TABLE AS SELECT. > >Is there anything that makes you worry and stops development? Could I give it a try to implement this (I'm not sure I can, sorry. I'm worried if we can change the executor's call chain easily.) > It's primarily a matter of having too much other stuff on my plate, thus not having time to work on this feature. I was not too worried about any particular issue, but I wanted some feedback before spending more time on extending the API. I'm not sure when I'll have time to work on this again, so if you are interested and willing to work on it, please go ahead. I'll gladly do reviews and help you with it. > >> 1) Extend the FDW API? > >Yes, I think, because FDWs for other DBMSs will benefit from this. (But it's questionable whether we want users to transfer data in Postgres database to other DBMSs...) > I think transferring data to other databases is fine - interoperability is a big advantage for users, I don't see it as something threatening the PostgreSQL project. I doubt this would make it more likely for users to migrate from PostgreSQL - there are many ways to do that already. >MySQL and SQL Server has the same bulk insert syntax as Postgres, i.e., INSERT INTO table VALUES(record1), (record2), ... Oracle doesn't have this syntax, but it can use CTE as follows: > > INSERT INTO table > WITH t AS ( > SELECT record1 FROM DUAL UNION ALL > SELECT record2 FROM DUAL UNION ALL > ... > ) > SELECT * FROM t; > >And many DBMSs should have CTAS, INSERT SELECT, and INSERT SELECT record1 UNION ALL SELECT record2 ... > True. In some cases INSERT may be replaced by COPY, but it has various other features too. >The API would simply be: > >TupleTableSlot ** >ExecForeignMultiInsert(EState *estate, > ResultRelInfo *rinfo, > TupleTableSlot **slot, > TupleTableSlot **planSlot, > int numSlots); > > +1, seems quite reasonable >> 2) What about the insert results? > >I'm wondering if we can report success or failure of each inserted row, because the remote INSERT will fail entirely. Other FDWs may be able to do it, so the API can be like above. > Yeah. I think handling complete failure should not be very difficult, but there are cases that worry me more. For example, what if there's a before trigger (on the remote db) that "skips" inserting some of the rows by returning NULL? >For the same reason, support for RETURNING clause will vary from DBMS to DBMS. > Yeah. I wonder if the FDW needs to indicate which features are supported by the ExecForeignMultiInsert, e.g. by adding a function that decides whether batch insert is supported (it might also do that internally by calling ExecForeignInsert, of course). > >> 3) What about the other DML operations (DELETE/UPDATE)? > >I don't think they are necessary for the time being. If we want them, they will be implemented using the libpq batch/pipelining as Andres-san said. > I agree. > >> 3) Should we do batching for COPY insteads? > >I'm thinking of issuing INSERT with multiple records as your patch does, because: > >* When the user executed INSERT statements, it would look strange to the user if the remote SQL is displayed as COPY. > >* COPY doesn't invoke rules unlike INSERT. (I don't think the rule is a feature what users care about, though.) Also, I'm a bit concerned that there might be, or will be, other differences between INSERT and COPY. > I agree. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services