diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-18 20:26:06 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-18 20:26:06 +0000 |
commit | a1c692358bb9958b7cb67e4284aae6aa3aabf714 (patch) | |
tree | 30e5c80eabbbce990ec44aac20f37ff3d8fd80ca /src/backend/utils/mmgr/portalmem.c | |
parent | 6cc88f0af5b12b22ce1826a26b1a953c434bd165 (diff) | |
download | postgresql-a1c692358bb9958b7cb67e4284aae6aa3aabf714.tar.gz postgresql-a1c692358bb9958b7cb67e4284aae6aa3aabf714.zip |
Adjust things so that the query_string of a cached plan and the sourceText of
a portal are never NULL, but reliably provide the source text of the query.
It turns out that there was only one place that was really taking a short-cut,
which was the 'EXECUTE' utility statement. That doesn't seem like a
sufficiently critical performance hotspot to justify not offering a guarantee
of validity of the portal source text. Fix it to copy the source text over
from the cached plan. Add Asserts in the places that set up cached plans and
portals to reject null source strings, and simplify a bunch of places that
formerly needed to guard against nulls.
There may be a few places that cons up statements for execution without
having any source text at all; I found one such in ConvertTriggerToFK().
It seems sufficient to inject a phony source string in such a case,
for instance
ProcessUtility((Node *) atstmt,
"(generated ALTER TABLE ADD FOREIGN KEY command)",
NULL, false, None_Receiver, NULL);
We should take a second look at the usage of debug_query_string,
particularly the recently added current_query() SQL function.
ITAGAKI Takahiro and Tom Lane
Diffstat (limited to 'src/backend/utils/mmgr/portalmem.c')
-rw-r--r-- | src/backend/utils/mmgr/portalmem.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c index 4470961a282..b98b578ed24 100644 --- a/src/backend/utils/mmgr/portalmem.c +++ b/src/backend/utils/mmgr/portalmem.c @@ -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.110 2008/05/12 00:00:52 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.111 2008/07/18 20:26:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -271,7 +271,11 @@ CreateNewPortal(void) * PortalDefineQuery * A simple subroutine to establish a portal's query. * - * Notes: commandTag shall be NULL if and only if the original query string + * Notes: as of PG 8.4, caller MUST supply a sourceText string; it is not + * allowed anymore to pass NULL. (If you really don't have source text, + * you can pass a constant string, perhaps "(query not available)".) + * + * commandTag shall be NULL if and only if the original query string * (before rewriting) was an empty string. Also, the passed commandTag must * be a pointer to a constant string, since it is not copied. * @@ -284,7 +288,7 @@ CreateNewPortal(void) * copying them into the portal's heap context. * * The caller is also responsible for ensuring that the passed prepStmtName - * and sourceText (if not NULL) have adequate lifetime. + * (if not NULL) and sourceText have adequate lifetime. * * NB: this function mustn't do much beyond storing the passed values; in * particular don't do anything that risks elog(ERROR). If that were to @@ -302,7 +306,8 @@ PortalDefineQuery(Portal portal, AssertArg(PortalIsValid(portal)); AssertState(portal->status == PORTAL_NEW); - Assert(commandTag != NULL || stmts == NIL); + AssertArg(sourceText != NULL); + AssertArg(commandTag != NULL || stmts == NIL); portal->prepStmtName = prepStmtName; portal->sourceText = sourceText; @@ -927,10 +932,7 @@ pg_cursor(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); values[0] = CStringGetTextDatum(portal->name); - if (!portal->sourceText) - nulls[1] = true; - else - values[1] = CStringGetTextDatum(portal->sourceText); + values[1] = CStringGetTextDatum(portal->sourceText); values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD); values[3] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_BINARY); values[4] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_SCROLL); |