mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Don't scan partitioned tables.
Partitioned tables do not contain any data; only their unpartitioned descendents need to be scanned. However, the partitioned tables still need to be locked, even though they're not scanned. To make that work, Append and MergeAppend relations now need to carry a list of (unscanned) partitioned relations that must be locked, and InitPlan must lock all partitioned result relations. Aside from the obvious advantage of avoiding some work at execution time, this has two other advantages. First, it may improve the planner's decision-making in some cases since the empty relation might throw things off. Second, it paves the way to getting rid of the storage for partitioned tables altogether. Amit Langote, reviewed by me. Discussion: http://postgr.es/m/6837c359-45c4-8044-34d1-736756335a15@lab.ntt.co.jp
This commit is contained in:
@ -43,6 +43,7 @@
|
||||
#include "executor/executor.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
@ -953,3 +954,58 @@ 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 = getrelid(rti, estate->es_range_table);
|
||||
|
||||
/* 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;
|
||||
|
||||
foreach(l, stmt->rowMarks)
|
||||
{
|
||||
if (((PlanRowMark *) lfirst(l))->rti == rti)
|
||||
{
|
||||
rc = lfirst(l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc && RowMarkRequiresRowShareLock(rc->markType))
|
||||
LockRelationOid(relid, RowShareLock);
|
||||
else
|
||||
LockRelationOid(relid, AccessShareLock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user