mirror of
https://github.com/postgres/postgres.git
synced 2025-12-01 12:18:01 +03:00
Fix oversight in initial implementation of PORTAL_ONE_RETURNING mode: we
cannot assume that there's exactly one Query in the Portal, as we can for ONE_SELECT mode, because non-SELECT queries might have extra queries added during rule rewrites. Fix things up so that we'll use ONE_RETURNING mode when a Portal contains one primary (canSetTag) query and that query has a RETURNING list. This appears to be a second showstopper reason for running the Portal to completion before we start to hand anything back --- we want to be sure that the rule-added queries get run too.
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.91 2006/08/08 01:23:15 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.92 2006/08/14 22:57:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -146,6 +146,34 @@ GetPortalByName(const char *name)
|
||||
return portal;
|
||||
}
|
||||
|
||||
/*
|
||||
* PortalListGetPrimaryQuery
|
||||
* Get the "primary" Query within a portal, ie, the one marked canSetTag.
|
||||
*
|
||||
* Returns NULL if no such Query. If multiple Query structs within the
|
||||
* portal are marked canSetTag, returns the first one. Neither of these
|
||||
* cases should occur in present usages of this function.
|
||||
*
|
||||
* Note: the reason this is just handed a List is so that prepared statements
|
||||
* can share the code. For use with a portal, use PortalGetPrimaryQuery
|
||||
* rather than calling this directly.
|
||||
*/
|
||||
Query *
|
||||
PortalListGetPrimaryQuery(List *parseTrees)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
foreach(lc, parseTrees)
|
||||
{
|
||||
Query *query = (Query *) lfirst(lc);
|
||||
|
||||
Assert(IsA(query, Query));
|
||||
if (query->canSetTag)
|
||||
return query;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* CreatePortal
|
||||
* Returns a new portal given a name.
|
||||
|
||||
Reference in New Issue
Block a user