Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vblqP-00Chw8-0i for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jan 2026 20:33:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vblqO-00B5WD-0N for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jan 2026 20:33:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vblqN-00B5W4-2c for pgsql-hackers@lists.postgresql.org; Fri, 02 Jan 2026 20:33:56 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vblqM-003rmk-2n for pgsql-hackers@postgresql.org; Fri, 02 Jan 2026 20:33:55 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-bc17d39ccd2so7635257a12.3 for ; Fri, 02 Jan 2026 12:33:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767386033; x=1767990833; darn=postgresql.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gp64TUet6K5uhm6N5r3y4oaheDknpc2rgN9e4lGVLT8=; b=ZJAXZF3hC8TMQWQ2qPPkbOFkR7PXmHCof9s0KOw92xuwfGVBdt48wwwXT9tIUHhZeh Z3Ky3zWjYOTO23DJAnx1ZbPfXGOwiTWvBMITbYOkY/E9SKv/G9RDznvQefWvs2GxM6+/ no+yloGvZew5TcaXfwGL1C04nicvGbuZgRFBusGtiMp8ihXPj2P5CE6J1uACbaBeXWuO EUFEq/w2Yddzo2KGY8UQchE1cmZ500A1tIZDkhDGxosrR5YJzlMbzoAFow21IHvPYtSA +y0rcb7C4aytqXXNHcmc2+2OVoZPYpLGBYmUo7AA1Y31+UbtJZxJxepV6MgqxGNBt04i yRkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767386033; x=1767990833; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gp64TUet6K5uhm6N5r3y4oaheDknpc2rgN9e4lGVLT8=; b=qFBt0+mvd4siY2H5ekPmInDMygRhp0qDQL8oX31qYqTJDXZ/n2tQqQ31o92rHLig3P SLN/oTqiXClwfRYrrziZ5EumYZ4UD+H4CvSvnqbMcHBWj7oAA9MJrCUwAvYUHM7DkerJ S+O+HZ5rSTU3ryP33xC8h173l27hsCCbf7XtUS1NRGUs8eiYxzH0uDAaFy1g7y1WFXaW aNTORRUwFkeumO2nskKNUXkEN8hDBL+AsR26mTEK6Gc1VllWnH4QH+osOG1DQ9rPmMWv fEUKW/miF2a9WUvbDwV7pLsPnoH5uaEvmV2//jjDd4/TowSXOgEFU4YiY+8ktb89Dbod U14Q== X-Forwarded-Encrypted: i=1; AJvYcCUqed3Sq98uiIw+zv+/DYj+88mgV8tGINKwHqrI7DXbGMCDoihOoVlAwlTIpMbTTyPJy2PmYadPfTDz32mW@postgresql.org X-Gm-Message-State: AOJu0YwLZr0gRr2DKkebSLKq9m5mjY2RXvo85yZHjQe2Y42bOowd4/Vx s+Bm/VJ2gppfwil+Ppsmvy2BRTJFX8zCFr4+1coYGtT41/PnXXLqqjl9 X-Gm-Gg: AY/fxX4WzVupLerkK0IqTuBL1RV5SectPcFzS9PHqOF90kyRyNSrodsOidNgR13aNSG EQ9ExmO5tZQtooXKq0y2/6LPEMEv/GGPj4Dh1I8lKiu93mVltP9exExol8LITTlWnOuVhHrxIie EbL8qFRNf3Wd3/+LwJYvjpOrz8G0diC1yyhU+6rgwa4L9Ev7dV8TXPHxYAuoO5FZ32v5ayn7+Cn EzAwXdcTvLWlAUVvC73qWIiT/WiEb8Vc7IPqNGszmI/7my2kVasb8PkUSW/L8p5ZqYtbtqynRzl 2z0HjBbySH4dzjgsmvbBs0tSQ+Yq0Ml8npV7mu/ejz3OLKrbCoJxTbeTpL1GBu5v00jeG1qGXWs ZQhx7g9thEc6Ej7b7Dr9VbS71xUQVsvCdhp+cps30tBs4FRMVXZFP4rotFFSuMi8TR0h0vgSvVm 21kBI7cEOocm3hA0foADnm/AcX0M6ZokmSFw== X-Google-Smtp-Source: AGHT+IF0ezRDB8F2YceZCdkpq3gd2NJESzzAAOZaGzSPAhn990faV+6L3qp6cLWfNawNKj57fff8xQ== X-Received: by 2002:a05:7300:f58d:b0:2ac:2e71:90d with SMTP id 5a478bee46e88-2b05ebdd4fdmr34716081eec.6.1767386033072; Fri, 02 Jan 2026 12:33:53 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:6d00:2898:79ba:8896]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b140c42e16sm1805961eec.23.2026.01.02.12.33.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Jan 2026 12:33:52 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 02 Jan 2026 17:33:49 -0300 Message-Id: Cc: "Andrew Dunstan" , "jian he" , "Tomas Vondra" , Subject: Re: postgres_fdw: Use COPY to speed up batch inserts From: "Matheus Alcantara" To: "Masahiko Sawada" , "Matheus Alcantara" X-Mailer: aerc 0.21.0 References: <5c52f4c7-74fa-4594-8378-53fd49f39329@dunslane.net> In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri Jan 2, 2026 at 5:15 PM -03, Masahiko Sawada wrote: > + > + /* > + * Set batch_with_copy_threshold from foreign server/table options. W= e do > + * this outside of create_foreign_modify() because we only want to us= e > + * COPY as a remote SQL when a COPY FROM on a foreign table is execut= ed or > + * an insert is being performed on a table partition. In both cases t= he > + * BeginForeignInsert fdw routine is called. > + */ > + fmstate->batch_with_copy_threshold =3D get_batch_with_copy_threshold(= rel); > > Does it mean that we could end up using the COPY method not only when > executing COPY FROM but also when executing INSERT with tuple > routings? If so, how does the EXPLAIN command show the remote SQL? > It meas that we could also use the COPY method to insert rows into a specific table partition that is a foreign table. Let's say that an user execute an INSERT INTO on a partitioned table that has partitions that are postgres_fdw tables, with this patch we could use the COPY method to insert the rows on these partitions. On this scenario we would not have issue with EXPLAIN output because currently we do not show the remote SQL being executed on each partition that is involved on the INSERT statement. If an user execute an INSERT directly into a postgres_fdw table we will use the normal INSERT statement as we use today. Thanks for taking a look at this. -- Matheus Alcantara EDB: https://www.enterprisedb.com