diff options
Diffstat (limited to 'src/backend/commands')
| -rw-r--r-- | src/backend/commands/copyto.c | 5 | ||||
| -rw-r--r-- | src/backend/commands/createas.c | 5 | ||||
| -rw-r--r-- | src/backend/commands/explain.c | 22 | ||||
| -rw-r--r-- | src/backend/commands/extension.c | 4 | ||||
| -rw-r--r-- | src/backend/commands/matview.c | 5 | ||||
| -rw-r--r-- | src/backend/commands/portalcmds.c | 1 | ||||
| -rw-r--r-- | src/backend/commands/prepare.c | 9 | ||||
| -rw-r--r-- | src/backend/commands/trigger.c | 15 |
8 files changed, 52 insertions, 14 deletions
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index 99cb23cb347..091fbc12cc5 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -556,7 +556,7 @@ BeginCopyTo(ParseState *pstate, ((DR_copy *) dest)->cstate = cstate; /* Create a QueryDesc requesting no output */ - cstate->queryDesc = CreateQueryDesc(plan, pstate->p_sourcetext, + cstate->queryDesc = CreateQueryDesc(plan, NULL, pstate->p_sourcetext, GetActiveSnapshot(), InvalidSnapshot, dest, NULL, NULL, 0); @@ -566,7 +566,8 @@ BeginCopyTo(ParseState *pstate, * * ExecutorStart computes a result tupdesc for us */ - ExecutorStart(cstate->queryDesc, 0); + if (!ExecutorStart(cstate->queryDesc, 0)) + elog(ERROR, "ExecutorStart() failed unexpectedly"); tupDesc = cstate->queryDesc->tupDesc; } diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 23cecd99c9e..44b4665ccd3 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -332,12 +332,13 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, UpdateActiveSnapshotCommandId(); /* Create a QueryDesc, redirecting output to our tuple receiver */ - queryDesc = CreateQueryDesc(plan, pstate->p_sourcetext, + queryDesc = CreateQueryDesc(plan, NULL, pstate->p_sourcetext, GetActiveSnapshot(), InvalidSnapshot, dest, params, queryEnv, 0); /* call ExecutorStart to prepare the plan for execution */ - ExecutorStart(queryDesc, GetIntoRelEFlags(into)); + if (!ExecutorStart(queryDesc, GetIntoRelEFlags(into))) + elog(ERROR, "ExecutorStart() failed unexpectedly"); /* run the plan to completion */ ExecutorRun(queryDesc, ForwardScanDirection, 0); diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index dc4bef9ab81..c368261eeef 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -519,7 +519,8 @@ standard_ExplainOneQuery(Query *query, int cursorOptions, } /* run it (if needed) and produce output */ - ExplainOnePlan(plan, into, es, queryString, params, queryEnv, + ExplainOnePlan(plan, NULL, NULL, -1, into, es, queryString, params, + queryEnv, &planduration, (es->buffers ? &bufusage : NULL), es->memory ? &mem_counters : NULL); } @@ -641,7 +642,9 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, * to call it. */ void -ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, +ExplainOnePlan(PlannedStmt *plannedstmt, CachedPlan *cplan, + CachedPlanSource *plansource, int query_index, + IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration, const BufferUsage *bufusage, @@ -697,7 +700,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, dest = None_Receiver; /* Create a QueryDesc for the query */ - queryDesc = CreateQueryDesc(plannedstmt, queryString, + queryDesc = CreateQueryDesc(plannedstmt, cplan, queryString, GetActiveSnapshot(), InvalidSnapshot, dest, params, queryEnv, instrument_option); @@ -711,8 +714,17 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, if (into) eflags |= GetIntoRelEFlags(into); - /* call ExecutorStart to prepare the plan for execution */ - ExecutorStart(queryDesc, eflags); + /* Prepare the plan for execution. */ + if (queryDesc->cplan) + { + ExecutorStartCachedPlan(queryDesc, eflags, plansource, query_index); + Assert(queryDesc->planstate); + } + else + { + if (!ExecutorStart(queryDesc, eflags)) + elog(ERROR, "ExecutorStart() failed unexpectedly"); + } /* Execute the plan for statistics if asked for */ if (es->analyze) diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index ec1d38b2172..d9bb4ce5f1e 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -907,11 +907,13 @@ execute_sql_string(const char *sql, const char *filename) QueryDesc *qdesc; qdesc = CreateQueryDesc(stmt, + NULL, sql, GetActiveSnapshot(), NULL, dest, NULL, NULL, 0); - ExecutorStart(qdesc, 0); + if (!ExecutorStart(qdesc, 0)) + elog(ERROR, "ExecutorStart() failed unexpectedly"); ExecutorRun(qdesc, ForwardScanDirection, 0); ExecutorFinish(qdesc); ExecutorEnd(qdesc); diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index c12817091ed..0bfbc5ca6dc 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -438,12 +438,13 @@ refresh_matview_datafill(DestReceiver *dest, Query *query, UpdateActiveSnapshotCommandId(); /* Create a QueryDesc, redirecting output to our tuple receiver */ - queryDesc = CreateQueryDesc(plan, queryString, + queryDesc = CreateQueryDesc(plan, NULL, queryString, GetActiveSnapshot(), InvalidSnapshot, dest, NULL, NULL, 0); /* call ExecutorStart to prepare the plan for execution */ - ExecutorStart(queryDesc, 0); + if (!ExecutorStart(queryDesc, 0)) + elog(ERROR, "ExecutorStart() failed unexpectedly"); /* run the plan */ ExecutorRun(queryDesc, ForwardScanDirection, 0); diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index e7c8171c102..4c2ac045224 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -117,6 +117,7 @@ PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo pa queryString, CMDTAG_SELECT, /* cursor's query is always a SELECT */ list_make1(plan), + NULL, NULL); /*---------- diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 8989c0c882d..c025b1f9f8c 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -202,7 +202,8 @@ ExecuteQuery(ParseState *pstate, query_string, entry->plansource->commandTag, plan_list, - cplan); + cplan, + entry->plansource); /* * For CREATE TABLE ... AS EXECUTE, we must verify that the prepared @@ -582,6 +583,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, MemoryContextCounters mem_counters; MemoryContext planner_ctx = NULL; MemoryContext saved_ctx = NULL; + int query_index = 0; if (es->memory) { @@ -654,7 +656,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, PlannedStmt *pstmt = lfirst_node(PlannedStmt, p); if (pstmt->commandType != CMD_UTILITY) - ExplainOnePlan(pstmt, into, es, query_string, paramLI, pstate->p_queryEnv, + ExplainOnePlan(pstmt, cplan, entry->plansource, query_index, + into, es, query_string, paramLI, pstate->p_queryEnv, &planduration, (es->buffers ? &bufusage : NULL), es->memory ? &mem_counters : NULL); else @@ -665,6 +668,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, /* Separate plans with an appropriate separator */ if (lnext(plan_list, p) != NULL) ExplainSeparatePlans(es); + + query_index++; } if (estate) diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 67f8e70f9c1..c9f61130c69 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -5058,6 +5058,21 @@ AfterTriggerBeginQuery(void) /* ---------- + * AfterTriggerAbortQuery() + * + * Called by standard_ExecutorEnd() if the query execution was aborted due to + * the plan becoming invalid during initialization. + * ---------- + */ +void +AfterTriggerAbortQuery(void) +{ + /* Revert the actions of AfterTriggerBeginQuery(). */ + afterTriggers.query_depth--; +} + + +/* ---------- * AfterTriggerEndQuery() * * Called after one query has been completely processed. At this time |
