]> granicus.if.org Git - postgresql/blobdiff - src/backend/tcop/pquery.c
Update copyright for the year 2010.
[postgresql] / src / backend / tcop / pquery.c
index 2a9764ac8b1ba7e297594245ace0da0cdc5283c2..05068fa406c9176a00a5bd20de5054b12082b3e1 100644 (file)
@@ -3,12 +3,12 @@
  * pquery.c
  *       POSTGRES process query command code
  *
- * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.126 2008/11/30 20:51:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.134 2010/01/02 16:57:52 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -36,6 +36,7 @@ Portal                ActivePortal = NULL;
 
 
 static void ProcessQuery(PlannedStmt *plan,
+                        const char *sourceText,
                         ParamListInfo params,
                         DestReceiver *dest,
                         char *completionTag);
@@ -61,23 +62,25 @@ static void DoPortalRewind(Portal portal);
  */
 QueryDesc *
 CreateQueryDesc(PlannedStmt *plannedstmt,
+                               const char *sourceText,
                                Snapshot snapshot,
                                Snapshot crosscheck_snapshot,
                                DestReceiver *dest,
                                ParamListInfo params,
-                               bool doInstrument)
+                               int instrument_options)
 {
        QueryDesc  *qd = (QueryDesc *) palloc(sizeof(QueryDesc));
 
        qd->operation = plannedstmt->commandType;       /* operation */
        qd->plannedstmt = plannedstmt;          /* plan */
        qd->utilitystmt = plannedstmt->utilityStmt; /* in case DECLARE CURSOR */
+       qd->sourceText = sourceText;    /* query text */
        qd->snapshot = RegisterSnapshot(snapshot);      /* snapshot */
        /* RI check snapshot */
        qd->crosscheck_snapshot = RegisterSnapshot(crosscheck_snapshot);
        qd->dest = dest;                        /* output dest */
        qd->params = params;            /* parameter values passed into query */
-       qd->doInstrument = doInstrument;        /* instrumentation wanted? */
+       qd->instrument_options = instrument_options;    /* instrumentation wanted? */
 
        /* null these fields until set by ExecutorStart */
        qd->tupDesc = NULL;
@@ -93,6 +96,7 @@ CreateQueryDesc(PlannedStmt *plannedstmt,
  */
 QueryDesc *
 CreateUtilityQueryDesc(Node *utilitystmt,
+                                          const char *sourceText,
                                           Snapshot snapshot,
                                           DestReceiver *dest,
                                           ParamListInfo params)
@@ -102,11 +106,12 @@ CreateUtilityQueryDesc(Node *utilitystmt,
        qd->operation = CMD_UTILITY;    /* operation */
        qd->plannedstmt = NULL;
        qd->utilitystmt = utilitystmt;          /* utility command */
+       qd->sourceText = sourceText;    /* query text */
        qd->snapshot = RegisterSnapshot(snapshot);      /* snapshot */
        qd->crosscheck_snapshot = InvalidSnapshot;      /* RI check snapshot */
        qd->dest = dest;                        /* output dest */
        qd->params = params;            /* parameter values passed into query */
-       qd->doInstrument = false;       /* uninteresting for utilities */
+       qd->instrument_options = false; /* uninteresting for utilities */
 
        /* null these fields until set by ExecutorStart */
        qd->tupDesc = NULL;
@@ -141,6 +146,7 @@ FreeQueryDesc(QueryDesc *qdesc)
  *             or PORTAL_ONE_RETURNING portal
  *
  *     plan: the plan tree for the query
+ *     sourceText: the source text of the query
  *     params: any parameters needed
  *     dest: where to send results
  *     completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
@@ -153,6 +159,7 @@ FreeQueryDesc(QueryDesc *qdesc)
  */
 static void
 ProcessQuery(PlannedStmt *plan,
+                        const char *sourceText,
                         ParamListInfo params,
                         DestReceiver *dest,
                         char *completionTag)
@@ -169,9 +176,9 @@ ProcessQuery(PlannedStmt *plan,
        /*
         * Create the QueryDesc object
         */
-       queryDesc = CreateQueryDesc(plan,
+       queryDesc = CreateQueryDesc(plan, sourceText,
                                                                GetActiveSnapshot(), InvalidSnapshot,
-                                                               dest, params, false);
+                                                               dest, params, 0);
 
        /*
         * Set up to collect AFTER triggers
@@ -331,7 +338,7 @@ ChoosePortalStrategy(List *stmts)
                        {
                                if (++nSetTag > 1)
                                        return PORTAL_MULTI_QUERY;      /* no need to look further */
-                               if (pstmt->returningLists == NIL)
+                               if (!pstmt->hasReturning)
                                        return PORTAL_MULTI_QUERY;      /* no need to look further */
                        }
                }
@@ -407,8 +414,8 @@ FetchStatementTargetList(Node *stmt)
                        pstmt->utilityStmt == NULL &&
                        pstmt->intoClause == NULL)
                        return pstmt->planTree->targetlist;
-               if (pstmt->returningLists)
-                       return (List *) linitial(pstmt->returningLists);
+               if (pstmt->hasReturning)
+                       return pstmt->planTree->targetlist;
                return NIL;
        }
        if (IsA(stmt, FetchStmt))
@@ -503,11 +510,12 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
                                 * the destination to DestNone.
                                 */
                                queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),
+                                                                                       portal->sourceText,
                                                                                        GetActiveSnapshot(),
                                                                                        InvalidSnapshot,
                                                                                        None_Receiver,
                                                                                        params,
-                                                                                       false);
+                                                                                       0);
 
                                /*
                                 * We do *not* call AfterTriggerBeginQuery() here.      We assume
@@ -562,9 +570,9 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
 
                                        pstmt = (PlannedStmt *) PortalGetPrimaryStmt(portal);
                                        Assert(IsA(pstmt, PlannedStmt));
-                                       Assert(pstmt->returningLists);
+                                       Assert(pstmt->hasReturning);
                                        portal->tupDesc =
-                                               ExecCleanTypeFromTL((List *) linitial(pstmt->returningLists),
+                                               ExecCleanTypeFromTL(pstmt->planTree->targetlist,
                                                                                        false);
                                }
 
@@ -863,7 +871,7 @@ PortalRun(Portal portal, long count, bool isTopLevel,
 
        if (log_executor_stats && portal->strategy != PORTAL_MULTI_QUERY)
                ShowUsage("EXECUTOR STATISTICS");
-       
+
        TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
 
        return result;
@@ -1036,7 +1044,8 @@ FillPortalStore(Portal portal, bool isTopLevel)
        treceiver = CreateDestReceiver(DestTuplestore);
        SetTuplestoreDestReceiverParams(treceiver,
                                                                        portal->holdStore,
-                                                                       portal->holdContext);
+                                                                       portal->holdContext,
+                                                                       false);
 
        completionTag[0] = '\0';
 
@@ -1109,7 +1118,8 @@ RunFromStore(Portal portal, ScanDirection direction, long count,
 
                        oldcontext = MemoryContextSwitchTo(portal->holdContext);
 
-                       ok = tuplestore_gettupleslot(portal->holdStore, forward, slot);
+                       ok = tuplestore_gettupleslot(portal->holdStore, forward, false,
+                                                                                slot);
 
                        MemoryContextSwitchTo(oldcontext);
 
@@ -1146,7 +1156,7 @@ static void
 PortalRunUtility(Portal portal, Node *utilityStmt, bool isTopLevel,
                                 DestReceiver *dest, char *completionTag)
 {
-       bool    active_snapshot_set;
+       bool            active_snapshot_set;
 
        elog(DEBUG3, "ProcessUtility");
 
@@ -1191,7 +1201,7 @@ PortalRunUtility(Portal portal, Node *utilityStmt, bool isTopLevel,
 
        /*
         * Some utility commands may pop the ActiveSnapshot stack from under us,
-        * so we only pop the stack if we actually see a snapshot set.  Note that
+        * so we only pop the stack if we actually see a snapshot set.  Note that
         * the set of utility commands that do this must be the same set
         * disallowed to run inside a transaction; otherwise, we could be popping
         * a snapshot that belongs to some other operation.
@@ -1257,6 +1267,7 @@ PortalRunMulti(Portal portal, bool isTopLevel,
                        {
                                /* statement can set tag string */
                                ProcessQuery(pstmt,
+                                                        portal->sourceText,
                                                         portal->portalParams,
                                                         dest, completionTag);
                        }
@@ -1264,6 +1275,7 @@ PortalRunMulti(Portal portal, bool isTopLevel,
                        {
                                /* stmt added by rewrite cannot set tag */
                                ProcessQuery(pstmt,
+                                                        portal->sourceText,
                                                         portal->portalParams,
                                                         altdest, NULL);
                        }