1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

Remove more redundant relation locking during executor startup.

We already have appropriate locks on every relation listed in the
query's rangetable before we reach the executor.  Take the next step
in exploiting that knowledge by removing code that worries about
taking locks on non-leaf result relations in a partitioned table.

In particular, get rid of ExecLockNonLeafAppendTables and a stanza in
InitPlan that asserts we already have locks on certain such tables.

In passing, clean up some now-obsolete comments in InitPlan.

Amit Langote, reviewed by David Rowley and Jesper Pedersen,
and whacked around a bit more by me

Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp
This commit is contained in:
Tom Lane
2018-10-06 15:12:51 -04:00
parent 0209f0285d
commit f2343653f5
5 changed files with 14 additions and 116 deletions

View File

@ -899,66 +899,6 @@ ShutdownExprContext(ExprContext *econtext, bool isCommit)
MemoryContextSwitchTo(oldcontext);
}
/*
* ExecLockNonLeafAppendTables
*
* Locks, if necessary, the tables indicated by the RT indexes contained in
* the partitioned_rels list. These are the non-leaf tables in the partition
* tree controlled by a given Append or MergeAppend node.
*/
void
ExecLockNonLeafAppendTables(List *partitioned_rels, EState *estate)
{
PlannedStmt *stmt = estate->es_plannedstmt;
ListCell *lc;
foreach(lc, partitioned_rels)
{
ListCell *l;
Index rti = lfirst_int(lc);
bool is_result_rel = false;
Oid relid = exec_rt_fetch(rti, estate)->relid;
/* If this is a result relation, already locked in InitPlan */
foreach(l, stmt->nonleafResultRelations)
{
if (rti == lfirst_int(l))
{
is_result_rel = true;
break;
}
}
/*
* Not a result relation; check if there is a RowMark that requires
* taking a RowShareLock on this rel.
*/
if (!is_result_rel)
{
PlanRowMark *rc = NULL;
LOCKMODE lockmode;
foreach(l, stmt->rowMarks)
{
if (((PlanRowMark *) lfirst(l))->rti == rti)
{
rc = lfirst(l);
break;
}
}
if (rc && RowMarkRequiresRowShareLock(rc->markType))
lockmode = RowShareLock;
else
lockmode = AccessShareLock;
Assert(lockmode == exec_rt_fetch(rti, estate)->rellockmode);
LockRelationOid(relid, lockmode);
}
}
}
/*
* GetAttributeByName
* GetAttributeByNum