From 8f6a6b7e9a48d04bc6912a968326277547dc7927 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 6 May 2003 21:01:04 +0000
Subject: [PATCH] Ensure that an Execute operation can't send tuples in cases
 where Describe would claim that no tuples will be returned.  Only affects
 SELECTs added to non-SELECT base queries by rewrite rules.  If you want to
 see the output of such a select, you gotta use 'simple Query' protocol.

---
 src/backend/tcop/pquery.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 0cb7865a9f6..e3a37b7310e 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.62 2003/05/06 20:26:27 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.63 2003/05/06 21:01:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -727,6 +727,23 @@ PortalRunMulti(Portal portal,
 	List	   *plantree_list = portal->planTrees;
 	List	   *querylist_item;
 
+	/*
+	 * If the destination is RemoteExecute, change to None.  The reason
+	 * is that the client won't be expecting any tuples, and indeed has no
+	 * way to know what they are, since there is no provision for Describe
+	 * to send a RowDescription message when this portal execution strategy
+	 * is in effect.  This presently will only affect SELECT commands added
+	 * to non-SELECT queries by rewrite rules: such commands will be executed,
+	 * but the results will be discarded unless you use "simple Query"
+	 * protocol.
+	 */
+	if (dest->mydest == RemoteExecute ||
+		dest->mydest == RemoteExecuteInternal)
+		dest = None_Receiver;
+	if (altdest->mydest == RemoteExecute ||
+		altdest->mydest == RemoteExecuteInternal)
+		altdest = None_Receiver;
+
 	/*
 	 * Loop to handle the individual queries generated from a
 	 * single parsetree by analysis and rewrite.
-- 
GitLab