Index: pool_proto_modules.c
===================================================================
RCS file: /cvsroot/pgpool/pgpool-II/pool_proto_modules.c,v
retrieving revision 1.89
diff -u -r1.89 pool_proto_modules.c
--- pool_proto_modules.c	20 Oct 2010 00:34:22 -0000	1.89
+++ pool_proto_modules.c	11 Jan 2011 11:08:31 -0000
@@ -1465,26 +1465,6 @@
 			pool_add_prepared_statement();
 			session_context->pending_pstmt = NULL;
 		}
-		else if (IsA(node, DeallocateStmt))
-		{
-			char *name;
-			
-			name = ((DeallocateStmt *)node)->name;
-			if (name == NULL)
-				pool_clear_prepared_statement_list();
-			else
-				pool_remove_prepared_statement();
-			session_context->pending_pstmt = NULL;
-		}
-		else if (IsA(node, DiscardStmt))
-		{
-			DiscardStmt *stmt = (DiscardStmt *)node;
-			if (stmt->target == DISCARD_ALL || stmt->target == DISCARD_PLANS)
-			{
-				pool_remove_pending_objects();
-				pool_clear_prepared_statement_list();
-			}
-		}
 		/*
 		 * JDBC driver sends "BEGIN" query internally if
 		 * setAutoCommit(false).  But it does not send Sync message
@@ -1675,6 +1655,32 @@
 
 	free(p1);
 
+	if (session_context->query_context != NULL)
+	{
+		Node *node = session_context->query_context->parse_tree;
+
+		if (IsA(node, DeallocateStmt))
+		{
+			char *name;
+			
+			name = ((DeallocateStmt *)node)->name;
+			if (name == NULL)
+				pool_clear_prepared_statement_list();
+			else
+				pool_remove_prepared_statement();
+			session_context->pending_pstmt = NULL;
+		}
+		else if (IsA(node, DiscardStmt))
+		{
+			DiscardStmt *stmt = (DiscardStmt *)node;
+			if (stmt->target == DISCARD_ALL || stmt->target == DISCARD_PLANS)
+			{
+				pool_remove_pending_objects();
+				pool_clear_prepared_statement_list();
+			}
+		}
+	}
+
 	return POOL_CONTINUE;
 }
 
Index: pool_query_context.c
===================================================================
RCS file: /cvsroot/pgpool/pgpool-II/pool_query_context.c,v
retrieving revision 1.32
diff -u -r1.32 pool_query_context.c
--- pool_query_context.c	20 Oct 2010 01:08:55 -0000	1.32
+++ pool_query_context.c	11 Jan 2011 11:08:31 -0000
@@ -972,6 +972,7 @@
 static
 void where_to_send_deallocate(POOL_QUERY_CONTEXT *query_context, Node *node)
 {
+	POOL_SESSION_CONTEXT *session_context;
 	DeallocateStmt *d = (DeallocateStmt *)node;
 	bool *wts;
 
@@ -997,6 +998,8 @@
 			ps = pool_get_prepared_statement_by_pstmt_name(d->name);
 			if (ps && ps->qctxt)
 			{
+				session_context = pool_get_session_context();
+				session_context->pending_pstmt = ps;
 				pool_copy_prep_where(ps->qctxt->where_to_send, query_context->where_to_send);
 				return;
 			}
Index: pool_session_context.c
===================================================================
RCS file: /cvsroot/pgpool/pgpool-II/pool_session_context.c,v
retrieving revision 1.25
diff -u -r1.25 pool_session_context.c
--- pool_session_context.c	19 Oct 2010 08:57:18 -0000	1.25
+++ pool_session_context.c	11 Jan 2011 11:08:32 -0000
@@ -1177,6 +1177,9 @@
 		}
 	}
 
+    if (!pool_is_doing_extended_query_message())
+		return false;
+
 	return true;
 }
 
