From ab2071b53d0043032a770a77a50f7fbf1900179f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 2 Apr 2008 18:32:00 +0000 Subject: Revert my bad decision of about a year ago to make PortalDefineQuery responsible for copying the query string into the new Portal. Such copying is unnecessary in the common code path through exec_simple_query, and in this case it can be enormously expensive because the string might contain a large number of individual commands; we were copying the entire, long string for each command, resulting in O(N^2) behavior for N commands. (This is the cause of bug #4079.) A second problem with it is that PortalDefineQuery really can't risk error, because if it elog's before having set up the Portal, we will leak the plancache refcount that the caller is trying to hand off to the portal. So go back to the design in which the caller is responsible for making sure everything is copied into the portal if necessary. --- src/backend/commands/portalcmds.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/portalcmds.c') diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 6efd09c44b1..5a93aec6890 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.69 2008/01/01 19:45:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.69.2.1 2008/04/02 18:32:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -76,6 +76,9 @@ PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params, stmt = copyObject(stmt); stmt->utilityStmt = NULL; /* make it look like plain SELECT */ + if (queryString) /* copy the source text too for safety */ + queryString = pstrdup(queryString); + PortalDefineQuery(portal, NULL, queryString, -- cgit v1.2.3