Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/tcop/postgres.c,v
retrieving revision 1.462
diff -c -c -r1.462 postgres.c
*** src/backend/tcop/postgres.c	24 Sep 2005 17:53:15 -0000	1.462
--- src/backend/tcop/postgres.c	26 Sep 2005 15:25:09 -0000
***************
*** 1466,1471 ****
--- 1466,1472 ----
  	else
  		portal = CreatePortal(portal_name, false, false);
  
+ 	/* We need to output the parameter values someday */
  	if (log_statement == LOGSTMT_ALL)
  		ereport(LOG,
  				(errmsg("statement: <BIND> %s", portal_name)));
***************
*** 1681,1686 ****
--- 1682,1688 ----
  	bool		save_log_duration = log_duration;
  	int			save_log_min_duration_statement = log_min_duration_statement;
  	bool		save_log_statement_stats = log_statement_stats;
+ 	bool		execute_is_fetch = false;
  
  	/* Adjust destination to tell printtup.c what to do */
  	dest = whereToSendOutput;
***************
*** 1694,1699 ****
--- 1696,1710 ----
  				 errmsg("portal \"%s\" does not exist", portal_name)));
  
  	/*
+ 	 * If we re-issue an Execute protocol request against an existing
+ 	 * portal, then we are only fetching more rows rather than 
+ 	 * completely re-executing the query from the start. atStart is never
+ 	 * reset for a v3 portal, so we are safe to use this check.
+ 	 */
+ 	if (!portal->atStart)
+ 		execute_is_fetch = true;
+ 
+ 	/*
  	 * If the original query was a null string, just return
  	 * EmptyQueryResponse.
  	 */
***************
*** 1704,1710 ****
  		return;
  	}
  
! 	if (portal->sourceText)
  	{
  		debug_query_string = portal->sourceText;
  		pgstat_report_activity(portal->sourceText);
--- 1715,1727 ----
  		return;
  	}
  
! 	/* Should we display the portal names here? */
! 	if (execute_is_fetch)
! 	{
! 		debug_query_string = "fetch message";
! 		pgstat_report_activity("<FETCH>");
! 	}
! 	else if (portal->sourceText)
  	{
  		debug_query_string = portal->sourceText;
  		pgstat_report_activity(portal->sourceText);
***************
*** 1732,1738 ****
  	if (log_statement == LOGSTMT_ALL)
  		/* We have the portal, so output the source query. */
  		ereport(LOG,
! 				(errmsg("statement: EXECUTE %s  [PREPARE:  %s]",
  						(*portal_name != '\0') ? portal_name : "<unnamed>",
  						portal->sourceText ? portal->sourceText : "")));
  
--- 1749,1756 ----
  	if (log_statement == LOGSTMT_ALL)
  		/* We have the portal, so output the source query. */
  		ereport(LOG,
! 				(errmsg("statement: %sEXECUTE %s  [PREPARE:  %s]",
! 						(execute_is_fetch) ? "FETCH from " : "",
  						(*portal_name != '\0') ? portal_name : "<unnamed>",
  						portal->sourceText ? portal->sourceText : "")));
  
***************
*** 1864,1873 ****
  			(save_log_min_duration_statement > 0 &&
  			 usecs >= save_log_min_duration_statement * 1000))
  			ereport(LOG,
! 					(errmsg("duration: %ld.%03ld ms  statement: EXECUTE %s  [PREPARE:  %s]",
  						(long) ((stop_t.tv_sec - start_t.tv_sec) * 1000 +
  							  (stop_t.tv_usec - start_t.tv_usec) / 1000),
  						(long) (stop_t.tv_usec - start_t.tv_usec) % 1000,
  							(*portal_name != '\0') ? portal_name : "<unnamed>",
  							portal->sourceText ? portal->sourceText : "")));
  	}
--- 1882,1892 ----
  			(save_log_min_duration_statement > 0 &&
  			 usecs >= save_log_min_duration_statement * 1000))
  			ereport(LOG,
! 					(errmsg("duration: %ld.%03ld ms  statement: %sEXECUTE %s  [PREPARE:  %s]",
  						(long) ((stop_t.tv_sec - start_t.tv_sec) * 1000 +
  							  (stop_t.tv_usec - start_t.tv_usec) / 1000),
  						(long) (stop_t.tv_usec - start_t.tv_usec) % 1000,
+ 							(execute_is_fetch) ? "FETCH from " : "",
  							(*portal_name != '\0') ? portal_name : "<unnamed>",
  							portal->sourceText ? portal->sourceText : "")));
  	}
