mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Revert "Don't lock partitions pruned by initial pruning"
As pointed out by Tom Lane, the patch introduced fragile and invasive
design around plan invalidation handling when locking of prunable
partitions was deferred from plancache.c to the executor. In
particular, it violated assumptions about CachedPlan immutability and
altered executor APIs in ways that are difficult to justify given the
added complexity and overhead.
This also removes the firstResultRels field added to PlannedStmt in
commit 28317de72, which was intended to support deferred locking of
certain ModifyTable result relations.
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/605328.1747710381@sss.pgh.pa.us
This commit is contained in:
@@ -835,7 +835,7 @@ BeginCopyTo(ParseState *pstate,
|
||||
((DR_copy *) dest)->cstate = cstate;
|
||||
|
||||
/* Create a QueryDesc requesting no output */
|
||||
cstate->queryDesc = CreateQueryDesc(plan, NULL, pstate->p_sourcetext,
|
||||
cstate->queryDesc = CreateQueryDesc(plan, pstate->p_sourcetext,
|
||||
GetActiveSnapshot(),
|
||||
InvalidSnapshot,
|
||||
dest, NULL, NULL, 0);
|
||||
@@ -845,8 +845,7 @@ BeginCopyTo(ParseState *pstate,
|
||||
*
|
||||
* ExecutorStart computes a result tupdesc for us
|
||||
*/
|
||||
if (!ExecutorStart(cstate->queryDesc, 0))
|
||||
elog(ERROR, "ExecutorStart() failed unexpectedly");
|
||||
ExecutorStart(cstate->queryDesc, 0);
|
||||
|
||||
tupDesc = cstate->queryDesc->tupDesc;
|
||||
}
|
||||
|
||||
@@ -334,13 +334,12 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
|
||||
UpdateActiveSnapshotCommandId();
|
||||
|
||||
/* Create a QueryDesc, redirecting output to our tuple receiver */
|
||||
queryDesc = CreateQueryDesc(plan, NULL, pstate->p_sourcetext,
|
||||
queryDesc = CreateQueryDesc(plan, pstate->p_sourcetext,
|
||||
GetActiveSnapshot(), InvalidSnapshot,
|
||||
dest, params, queryEnv, 0);
|
||||
|
||||
/* call ExecutorStart to prepare the plan for execution */
|
||||
if (!ExecutorStart(queryDesc, GetIntoRelEFlags(into)))
|
||||
elog(ERROR, "ExecutorStart() failed unexpectedly");
|
||||
ExecutorStart(queryDesc, GetIntoRelEFlags(into));
|
||||
|
||||
/* run the plan to completion */
|
||||
ExecutorRun(queryDesc, ForwardScanDirection, 0);
|
||||
|
||||
@@ -369,8 +369,7 @@ standard_ExplainOneQuery(Query *query, int cursorOptions,
|
||||
}
|
||||
|
||||
/* run it (if needed) and produce output */
|
||||
ExplainOnePlan(plan, NULL, NULL, -1, into, es, queryString, params,
|
||||
queryEnv,
|
||||
ExplainOnePlan(plan, into, es, queryString, params, queryEnv,
|
||||
&planduration, (es->buffers ? &bufusage : NULL),
|
||||
es->memory ? &mem_counters : NULL);
|
||||
}
|
||||
@@ -492,9 +491,7 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es,
|
||||
* to call it.
|
||||
*/
|
||||
void
|
||||
ExplainOnePlan(PlannedStmt *plannedstmt, CachedPlan *cplan,
|
||||
CachedPlanSource *plansource, int query_index,
|
||||
IntoClause *into, ExplainState *es,
|
||||
ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es,
|
||||
const char *queryString, ParamListInfo params,
|
||||
QueryEnvironment *queryEnv, const instr_time *planduration,
|
||||
const BufferUsage *bufusage,
|
||||
@@ -550,7 +547,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, CachedPlan *cplan,
|
||||
dest = None_Receiver;
|
||||
|
||||
/* Create a QueryDesc for the query */
|
||||
queryDesc = CreateQueryDesc(plannedstmt, cplan, queryString,
|
||||
queryDesc = CreateQueryDesc(plannedstmt, queryString,
|
||||
GetActiveSnapshot(), InvalidSnapshot,
|
||||
dest, params, queryEnv, instrument_option);
|
||||
|
||||
@@ -564,17 +561,8 @@ ExplainOnePlan(PlannedStmt *plannedstmt, CachedPlan *cplan,
|
||||
if (into)
|
||||
eflags |= GetIntoRelEFlags(into);
|
||||
|
||||
/* 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");
|
||||
}
|
||||
/* call ExecutorStart to prepare the plan for execution */
|
||||
ExecutorStart(queryDesc, eflags);
|
||||
|
||||
/* Execute the plan for statistics if asked for */
|
||||
if (es->analyze)
|
||||
|
||||
@@ -993,13 +993,11 @@ execute_sql_string(const char *sql, const char *filename)
|
||||
QueryDesc *qdesc;
|
||||
|
||||
qdesc = CreateQueryDesc(stmt,
|
||||
NULL,
|
||||
sql,
|
||||
GetActiveSnapshot(), NULL,
|
||||
dest, NULL, NULL, 0);
|
||||
|
||||
if (!ExecutorStart(qdesc, 0))
|
||||
elog(ERROR, "ExecutorStart() failed unexpectedly");
|
||||
ExecutorStart(qdesc, 0);
|
||||
ExecutorRun(qdesc, ForwardScanDirection, 0);
|
||||
ExecutorFinish(qdesc);
|
||||
ExecutorEnd(qdesc);
|
||||
|
||||
@@ -438,13 +438,12 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
|
||||
UpdateActiveSnapshotCommandId();
|
||||
|
||||
/* Create a QueryDesc, redirecting output to our tuple receiver */
|
||||
queryDesc = CreateQueryDesc(plan, NULL, queryString,
|
||||
queryDesc = CreateQueryDesc(plan, queryString,
|
||||
GetActiveSnapshot(), InvalidSnapshot,
|
||||
dest, NULL, NULL, 0);
|
||||
|
||||
/* call ExecutorStart to prepare the plan for execution */
|
||||
if (!ExecutorStart(queryDesc, 0))
|
||||
elog(ERROR, "ExecutorStart() failed unexpectedly");
|
||||
ExecutorStart(queryDesc, 0);
|
||||
|
||||
/* run the plan */
|
||||
ExecutorRun(queryDesc, ForwardScanDirection, 0);
|
||||
|
||||
@@ -117,7 +117,6 @@ PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo pa
|
||||
queryString,
|
||||
CMDTAG_SELECT, /* cursor's query is always a SELECT */
|
||||
list_make1(plan),
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
/*----------
|
||||
|
||||
@@ -205,8 +205,7 @@ ExecuteQuery(ParseState *pstate,
|
||||
query_string,
|
||||
entry->plansource->commandTag,
|
||||
plan_list,
|
||||
cplan,
|
||||
entry->plansource);
|
||||
cplan);
|
||||
|
||||
/*
|
||||
* For CREATE TABLE ... AS EXECUTE, we must verify that the prepared
|
||||
@@ -586,7 +585,6 @@ 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)
|
||||
{
|
||||
@@ -659,8 +657,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
|
||||
PlannedStmt *pstmt = lfirst_node(PlannedStmt, p);
|
||||
|
||||
if (pstmt->commandType != CMD_UTILITY)
|
||||
ExplainOnePlan(pstmt, cplan, entry->plansource, query_index,
|
||||
into, es, query_string, paramLI, pstate->p_queryEnv,
|
||||
ExplainOnePlan(pstmt, into, es, query_string, paramLI, pstate->p_queryEnv,
|
||||
&planduration, (es->buffers ? &bufusage : NULL),
|
||||
es->memory ? &mem_counters : NULL);
|
||||
else
|
||||
@@ -671,8 +668,6 @@ 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)
|
||||
|
||||
@@ -5057,21 +5057,6 @@ 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()
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user