From pryzbyj@telsasoft.com Fri Jul  10 16:25:29 2026
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Fri, 8 May 2020 02:17:32 -0500
Subject: [PATCH v1] Make INSERT SELECT use a BulkInsertState

---
 src/backend/executor/nodeModifyTable.c | 21 +++++++++++++++++++--
 src/include/nodes/execnodes.h          |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 20a4c474cc..aa85245f39 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -578,7 +578,7 @@ ExecInsert(ModifyTableState *mtstate,
 			table_tuple_insert_speculative(resultRelationDesc, slot,
 										   estate->es_output_cid,
 										   0,
-										   NULL,
+										   NULL, /* Bulk insert not supported */
 										   specToken);
 
 			/* insert index entries for tuple */
@@ -617,7 +617,7 @@ ExecInsert(ModifyTableState *mtstate,
 			/* insert the tuple normally */
 			table_tuple_insert(resultRelationDesc, slot,
 							   estate->es_output_cid,
-							   0, NULL);
+							   0, mtstate->bistate);
 
 			/* insert index entries for tuple */
 			if (resultRelInfo->ri_NumIndices > 0)
@@ -2332,6 +2332,17 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
 
 	mtstate->mt_arowmarks = (List **) palloc0(sizeof(List *) * nplans);
 	mtstate->mt_nplans = nplans;
+	mtstate->bistate = NULL;
+	if (operation == CMD_INSERT &&
+			node->onConflictAction != ONCONFLICT_UPDATE &&
+			node->rootResultRelIndex < 0)
+	{
+		Plan *p = linitial(node->plans);
+		Assert(nplans == 1);
+
+		if (!IsA(p, Result) && !IsA(p, ProjectSet) && !IsA(p, ValuesScan))
+			mtstate->bistate = GetBulkInsertState();
+	}
 
 	/* set up epqstate with dummy subplan data for the moment */
 	EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL, node->epqParam);
@@ -2776,6 +2787,12 @@ ExecEndModifyTable(ModifyTableState *node)
 														   resultRelInfo);
 	}
 
+	if (node->bistate)
+	{
+		FreeBulkInsertState(node->bistate);
+		table_finish_bulk_insert((getTargetResultRelInfo(node))->ri_RelationDesc, 0);
+	}
+
 	/*
 	 * Close all the partitioned tables, leaf partitions, and their indices
 	 * and release the slot used for tuple routing, if set.
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 4fee043bb2..daf365f181 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -14,6 +14,7 @@
 #ifndef EXECNODES_H
 #define EXECNODES_H
 
+#include "access/heapam.h"
 #include "access/tupconvert.h"
 #include "executor/instrument.h"
 #include "fmgr.h"
@@ -1177,6 +1178,7 @@ typedef struct ModifyTableState
 	List	  **mt_arowmarks;	/* per-subplan ExecAuxRowMark lists */
 	EPQState	mt_epqstate;	/* for evaluating EvalPlanQual rechecks */
 	bool		fireBSTriggers; /* do we need to fire stmt triggers? */
+	BulkInsertState	bistate;	/* State for bulk insert like INSERT SELECT */
 
 	/*
 	 * Slot for storing tuples in the root partitioned table's rowtype during
-- 
2.17.0


--4Ckj6UjgE2iN1+kY--





From mbanck@gmx.net Fri May  15 23:39:30 2026
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.94.2)
	(envelope-from <pgsql-hackers-owner+archive@lists.postgresql.org>)
	id 1scKne-006HxW-4z
	for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2024 08:16:38 +0000
Received: from localhost ([127.0.0.1] helo=malur.postgresql.org)
	by malur.postgresql.org with esmtp (Exim 4.94.2)
	(envelope-from <pgsql-hackers-owner+archive@lists.postgresql.org>)
	id 1scKnb-0022Aj-2v
	for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2024 08:16:35 +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.94.2)
	(envelope-from <mbanck@gmail.com>)
	id 1scKna-0022Ab-P0
	for pgsql-hackers@lists.postgresql.org; Fri, 09 Aug 2024 08:16:34 +0000
Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434])
	by makus.postgresql.org with esmtps  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
	(Exim 4.94.2)
	(envelope-from <mbanck@gmail.com>)
	id 1scKnX-003qvx-HF
	for pgsql-hackers@postgresql.org; Fri, 09 Aug 2024 08:16:33 +0000
Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-368712acb8dso1037977f8f.2
        for <pgsql-hackers@postgresql.org>; Fri, 09 Aug 2024 01:16:31 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1723191390; x=1723796190; darn=postgresql.org;
        h=user-agent:content-disposition:mime-version:subject:cc:to:from:date
         :sender:message-id:from:to:cc:subject:date:message-id:reply-to;
        bh=XqC8nsPsIgG7T+FSr8hgNfpe0f600D2AElGi+IATikg=;
        b=neKnlMGabS3NxD37CpvIjoDiOg0/8rNrk+sBo9vynyRS9cUXAPswKgRivaFk9dxF1n
         ywocfpoakvL1bOg6DhF14L/KU997qrrrNz5EMxkm+jjxOw5fr6YH9ftr2YWxYljHNsL/
         95ZE2jGrZd7FTXLbnZVoI1IiLyMFef/2xAGuAtHl6U99bgzwAqT1lvG8UKLQcvHIrre3
         ci8iqxiedntDYbLlBIfQlADN8DhNmj5k8bCmGfAoWYCPAuvZ5j1yYkd6Kym+jdNd5/f1
         OxRHWtOYW6uZFEnGDRfD8H66qnzxo6xGPzHfMJ5hasjw6EU51LtrRAhT84FWqtSbsGC9
         ZqJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1723191390; x=1723796190;
        h=user-agent:content-disposition:mime-version:subject:cc:to:from:date
         :sender:message-id:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=XqC8nsPsIgG7T+FSr8hgNfpe0f600D2AElGi+IATikg=;
        b=YcirmEIA35J7SddjSyJFzt+Sxxssz8fv+wD5M7HtkilhxupmddN8wc3HRt52p1lGkb
         3G+tV47NL/saNXv2Myf+8CDx/B5KD00UG7z5eAMmAD0ETm+ACCuuPKvAjivMt2ILmH+e
         dIQEugJYYCMhoduOZqvX9q8RLZ4eBzjWTnzwtg21qDfKe8x/MoLWahZhmQufNVJFpoA5
         0fGoTXzQHGS6EmCjhq5HDgVvKhnt+SeUbsaxBCP8YXufMmuxC52CjA7COAHXiFux11Ed
         J4fBa3uwMGgE5vIlTMjOibZiVg87YNVZ7VfFzCd8MxzQWIw7JFmH3F4vusaZWvSzSV14
         A6Ww==
X-Gm-Message-State: AOJu0Yxa06egoOz3ceFmdCb1lleHbInRVmKu8hY7UHp6RqnpI+CTwiuR
	2ll5NgQcjNoAzKw9SkcfH4Xgeflb2G75tiUz/ldmuUZ95yAg6BBNc8CM+g==
X-Google-Smtp-Source: AGHT+IHN0mJsWAAupbFQlPm5A1iizXPZ9K2Z8zGQQAx1vE4xvijKUX8IikQMeIFU1uZWYqYMHWaBVw==
X-Received: by 2002:adf:f74d:0:b0:368:74a8:6c34 with SMTP id ffacd0b85a97d-36d5ebfce2amr571741f8f.36.1723191389336;
        Fri, 09 Aug 2024 01:16:29 -0700 (PDT)
Received: from lightning.caipicrew.dd-dns.de ([2001:a61:a05:fe01:9333:ff0e:c35f:d646])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36d2716e3b3sm4501656f8f.42.2024.08.09.01.16.28
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 09 Aug 2024 01:16:28 -0700 (PDT)
Message-ID: <66b5d05c.050a0220.7c8ce.a951@mx.google.com>
X-Google-Original-Message-ID: <20240809081628.GC4146@caipicrew.dd-dns.de;lightning.caipicrew.dd-dns.de>
Sender: Michael Banck <mbanck@gmail.com>
Received: from mbanck by lightning.caipicrew.dd-dns.de with local (Exim 4.92)
	(envelope-from <mbanck@caipicrew.dd-dns.de>)
	id 1scKnU-0001mu-Ag; Fri, 09 Aug 2024 10:16:28 +0200
Date: Fri, 9 Aug 2024 10:16:28 +0200
From: Michael Banck <mbanck@gmx.net>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Holger Jakobs <holger@jakobs.com>
Subject: Improve error message for ICU libraries if pkg-config is absent
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.10.1 (2018-07-13)
List-Id: <pgsql-hackers.lists.postgresql.org>
List-Help: <https://lists.postgresql.org/manage/>
List-Subscribe: <https://lists.postgresql.org/manage/>
List-Post: <mailto:pgsql-hackers@lists.postgresql.org>
List-Owner: <mailto:pgsql-hackers-owner@lists.postgresql.org>
List-Archive: <https://www.postgresql.org/list/pgsql-hackers>
Archived-At: <https://www.postgresql.org/message-id/66b5d05c.050a0220.7c8ce.a951%40mx.google.com>
Precedence: bulk

Hi,

Holger Jacobs complained in pgsql-admin that in v17, if you have the ICU
development libraries installed but not pkg-config, you get a somewhat
unhelpful error message about ICU not being present:

|checking for pkg-config... no
|checking whether to build with ICU support... yes
|checking for icu-uc icu-i18n... no
|configure: error: ICU library not found
|If you have ICU already installed, see config.log for details on the
|failure.  It is possible the compiler isn't looking in the proper directory.
|Use --without-icu to disable ICU support.

The attached patch improves things to that:

|checking for pkg-config... no
|checking whether to build with ICU support... yes
|configure: error: ICU library not found
|The ICU library could not be found because pkg-config is not available, see
|config.log for details on the failure.  If ICU is installed, the variables
|ICU_CFLAGS and ICU_LIBS can be set explicitly in this case, or use
|--without-icu to disable ICU support.


Michael






From mbanck@gmx.net Fri May  15 23:49:24 2026
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.94.2)
	(envelope-from <pgsql-hackers-owner+archive@lists.postgresql.org>)
	id 1scKuu-006J1F-0D
	for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2024 08:24:08 +0000
Received: from localhost ([127.0.0.1] helo=malur.postgresql.org)
	by malur.postgresql.org with esmtp (Exim 4.94.2)
	(envelope-from <pgsql-hackers-owner+archive@lists.postgresql.org>)
	id 1scKus-0024oO-6W
	for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Aug 2024 08:24:06 +0000
Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29])
	by malur.postgresql.org with esmtps  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
	(Exim 4.94.2)
	(envelope-from <mbanck@gmail.com>)
	id 1scKur-0024oG-SP
	for pgsql-hackers@lists.postgresql.org; Fri, 09 Aug 2024 08:24:05 +0000
Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332])
	by magus.postgresql.org with esmtps  (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
	(Exim 4.94.2)
	(envelope-from <mbanck@gmail.com>)
	id 1scKup-003wGq-5r
	for pgsql-hackers@postgresql.org; Fri, 09 Aug 2024 08:24:05 +0000
Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4281faefea9so12775565e9.2
        for <pgsql-hackers@postgresql.org>; Fri, 09 Aug 2024 01:24:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1723191841; x=1723796641; darn=postgresql.org;
        h=user-agent:in-reply-to:content-disposition:mime-version:references
         :subject:cc:to:from:date:sender:message-id:from:to:cc:subject:date
         :message-id:reply-to;
        bh=7wTNRO65R5K26UaJK9Q8+bhSxufilV4KDU55fd5IMcE=;
        b=Z4gx+yPyGwHTCU4aQa7OltFdAJ+jSMTaGzwAHj8Qh9EuO3BxLk91qkXNE4fnbcdDMN
         g9Ft2ph3XjbImPThdg4APGd9siskeGYlp5Ver68oTvXlnr7blodbeX7iQsiOhPrOyjXM
         xr897uoSU1D2EiqQUQ2BSxahEVdqHgD5TE+njuyVbGqKeMtds/fKq7EDWhAlZE8N322+
         LH7bNtLie61mcHCgvzsnniObRjfbN9b8XcI0TqRKF39kgWtbs3D3ilGATeJ4SkN821+s
         zh+ji9NF4uh9PJmw2gem0WtJUE0+sYeDWVHheZ1Xy7bV/2uWDVF/bqNuEcXZCpPBjQ/U
         ArkQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1723191841; x=1723796641;
        h=user-agent:in-reply-to:content-disposition:mime-version:references
         :subject:cc:to:from:date:sender:message-id:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to;
        bh=7wTNRO65R5K26UaJK9Q8+bhSxufilV4KDU55fd5IMcE=;
        b=FJSi73Dxww0WnlpRXP1vGN8RqvrOZP9Hwc0Qzz2wYXi8LMsW9HKgo3CNUOb7tmNpbz
         btPq85ETk4+JxmQeDThOCE5ZdVIs334gZCXKg9a2CVHs83QibRINa13wXGYzIo2XOfWL
         Iv2hrf1K82MvgVyN5xE4yQkdEie6Dzc2ZqTdnsu/T/HTDF0b2rVlHxzR2LETbOf494+Q
         9XsSNc6Shq9G2wmrQ1Gn50/1HUSG1T4EemGcpKg75ZBm9MdzOIlzHo3jrUodXPI8TBXT
         z7Be4Ro8zeH8H+lcnKb+6n6reeG4FtngZAgyTch6y2yI/QRveSb6wWhn9G9YxU3LUC8Z
         QHUw==
X-Gm-Message-State: AOJu0Yx9q5s3JRouvQhCjpqYbuz95GP9U/aNwbNHZkaVFKBzQ8guMg33
	TaVqcbRKJvU+fWan2OtYWIyzKi+vez15kRDFxkjtZFKUSRjF+ujJNgB32Q==
X-Google-Smtp-Source: AGHT+IGs5q4syLAqjUNur+TwyIODYAnRbt6R2dJTXfPufjD9HvV5W63yVtHByWHnNV6jivhdN2YpJg==
X-Received: by 2002:a05:600c:4f0d:b0:426:5f0b:a49b with SMTP id 5b1f17b1804b1-429c3a51465mr5532885e9.23.1723191841359;
        Fri, 09 Aug 2024 01:24:01 -0700 (PDT)
Received: from lightning.caipicrew.dd-dns.de ([2001:a61:a05:fe01:9333:ff0e:c35f:d646])
        by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4290c777017sm63375355e9.35.2024.08.09.01.24.00
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 09 Aug 2024 01:24:00 -0700 (PDT)
Message-ID: <66b5d220.050a0220.31a88.ebd6@mx.google.com>
X-Google-Original-Message-ID: <20240809082359.GD4146@caipicrew.dd-dns.de;lightning.caipicrew.dd-dns.de>
Sender: Michael Banck <mbanck@gmail.com>
Received: from mbanck by lightning.caipicrew.dd-dns.de with local (Exim 4.92)
	(envelope-from <mbanck@caipicrew.dd-dns.de>)
	id 1scKum-0001qw-An; Fri, 09 Aug 2024 10:24:00 +0200
Date: Fri, 9 Aug 2024 10:24:00 +0200
From: Michael Banck <mbanck@gmx.net>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Holger Jakobs <holger@jakobs.com>
Subject: Re: Improve error message for ICU libraries if pkg-config is absent
References: <66b5d05c.050a0220.7c8ce.a951@mx.google.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz"
Content-Disposition: inline
In-Reply-To: <66b5d05c.050a0220.7c8ce.a951@mx.google.com>
User-Agent: Mutt/1.10.1 (2018-07-13)
List-Id: <pgsql-hackers.lists.postgresql.org>
List-Help: <https://lists.postgresql.org/manage/>
List-Subscribe: <https://lists.postgresql.org/manage/>
List-Post: <mailto:pgsql-hackers@lists.postgresql.org>
List-Owner: <mailto:pgsql-hackers-owner@lists.postgresql.org>
List-Archive: <https://www.postgresql.org/list/pgsql-hackers>
Archived-At: <https://www.postgresql.org/message-id/66b5d220.050a0220.31a88.ebd6%40mx.google.com>
Precedence: bulk


--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Meh, forgot the attachment. Also, this should be backpatched to v17 if
accepted.


Michael

--3V7upXqbjpZ4EhLz
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0001-Improve-configure-error-for-ICU-libraries-if-pkg-con.patch"

>From b696949180437a3c7307ac0509cba54828b44259 Mon Sep 17 00:00:00 2001
From: Michael Banck <michael.banck@credativ.de>
Date: Fri, 9 Aug 2024 10:13:27 +0200
Subject: [PATCH] Improve configure error for ICU libraries if pkg-config is
 absent.

If pkg-config is not installed, the ICU libraries cannot be found, but
this was not mentioned in the error message and might lead to confusion
about the actual problem. To improve this, add an additional error
message for the case that pkg-config is not available.

Reported-by: Holger Jakobs
Discussion: https://www.postgresql.org/message-id/ccd579ed-4949-d3de-ab13-9e6456fd2caf%40jakobs.com
---
 configure    | 7 +++++++
 configure.ac | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/configure b/configure
index 4f3aa44756..b3a2774f1b 100755
--- a/configure
+++ b/configure
@@ -8094,6 +8094,13 @@ $as_echo "$with_icu" >&6; }
 
 
 if test "$with_icu" = yes; then
+  if test -z "$PKG_CONFIG"; then
+    as_fn_error $? "ICU library not found
+The ICU library could not be found because pkg-config is not available, see
+config.log for details on the failure.  If ICU is installed, the variables
+ICU_CFLAGS and ICU_LIBS can be set explicitly in this case, or use
+--without-icu to disable ICU support." "$LINENO" 5
+  fi
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for icu-uc icu-i18n" >&5
diff --git a/configure.ac b/configure.ac
index 049bc01491..18472a464a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -829,6 +829,13 @@ AC_MSG_RESULT([$with_icu])
 AC_SUBST(with_icu)
 
 if test "$with_icu" = yes; then
+  if test -z "$PKG_CONFIG"; then
+    AC_MSG_ERROR([ICU library not found
+The ICU library could not be found because pkg-config is not available, see
+config.log for details on the failure.  If ICU is installed, the variables
+ICU_CFLAGS and ICU_LIBS can be set explicitly in this case, or use
+--without-icu to disable ICU support.])
+  fi
   PKG_CHECK_MODULES(ICU, icu-uc icu-i18n, [],
     [AC_MSG_ERROR([ICU library not found
 If you have ICU already installed, see config.log for details on the
-- 
2.39.2


--3V7upXqbjpZ4EhLz--






