mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +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:
@@ -90,6 +90,7 @@ _copyPlannedStmt(const PlannedStmt *from)
|
||||
COPY_NODE_FIELD(planTree);
|
||||
COPY_NODE_FIELD(rtable);
|
||||
COPY_NODE_FIELD(resultRelations);
|
||||
COPY_NODE_FIELD(nonleafResultRelations);
|
||||
COPY_NODE_FIELD(subplans);
|
||||
COPY_BITMAPSET_FIELD(rewindPlanIDs);
|
||||
COPY_NODE_FIELD(rowMarks);
|
||||
@@ -200,6 +201,7 @@ _copyModifyTable(const ModifyTable *from)
|
||||
COPY_SCALAR_FIELD(operation);
|
||||
COPY_SCALAR_FIELD(canSetTag);
|
||||
COPY_SCALAR_FIELD(nominalRelation);
|
||||
COPY_NODE_FIELD(partitioned_rels);
|
||||
COPY_NODE_FIELD(resultRelations);
|
||||
COPY_SCALAR_FIELD(resultRelIndex);
|
||||
COPY_NODE_FIELD(plans);
|
||||
@@ -235,6 +237,7 @@ _copyAppend(const Append *from)
|
||||
/*
|
||||
* copy remainder of node
|
||||
*/
|
||||
COPY_NODE_FIELD(partitioned_rels);
|
||||
COPY_NODE_FIELD(appendplans);
|
||||
|
||||
return newnode;
|
||||
@@ -256,6 +259,7 @@ _copyMergeAppend(const MergeAppend *from)
|
||||
/*
|
||||
* copy remainder of node
|
||||
*/
|
||||
COPY_NODE_FIELD(partitioned_rels);
|
||||
COPY_NODE_FIELD(mergeplans);
|
||||
COPY_SCALAR_FIELD(numCols);
|
||||
COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
|
||||
@@ -2204,6 +2208,20 @@ _copyAppendRelInfo(const AppendRelInfo *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPartitionedChildRelInfo
|
||||
*/
|
||||
static PartitionedChildRelInfo *
|
||||
_copyPartitionedChildRelInfo(const PartitionedChildRelInfo *from)
|
||||
{
|
||||
PartitionedChildRelInfo *newnode = makeNode(PartitionedChildRelInfo);
|
||||
|
||||
COPY_SCALAR_FIELD(parent_relid);
|
||||
COPY_NODE_FIELD(child_rels);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPlaceHolderInfo
|
||||
*/
|
||||
@@ -4894,6 +4912,9 @@ copyObject(const void *from)
|
||||
case T_AppendRelInfo:
|
||||
retval = _copyAppendRelInfo(from);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
retval = _copyPartitionedChildRelInfo(from);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
retval = _copyPlaceHolderInfo(from);
|
||||
break;
|
||||
|
@@ -895,6 +895,15 @@ _equalAppendRelInfo(const AppendRelInfo *a, const AppendRelInfo *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalPartitionedChildRelInfo(const PartitionedChildRelInfo *a, const PartitionedChildRelInfo *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(parent_relid);
|
||||
COMPARE_NODE_FIELD(child_rels);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalPlaceHolderInfo(const PlaceHolderInfo *a, const PlaceHolderInfo *b)
|
||||
{
|
||||
@@ -3104,6 +3113,9 @@ equal(const void *a, const void *b)
|
||||
case T_AppendRelInfo:
|
||||
retval = _equalAppendRelInfo(a, b);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
retval = _equalPartitionedChildRelInfo(a, b);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
retval = _equalPlaceHolderInfo(a, b);
|
||||
break;
|
||||
|
@@ -252,6 +252,7 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
|
||||
WRITE_NODE_FIELD(planTree);
|
||||
WRITE_NODE_FIELD(rtable);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(nonleafResultRelations);
|
||||
WRITE_NODE_FIELD(subplans);
|
||||
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
@@ -344,6 +345,7 @@ _outModifyTable(StringInfo str, const ModifyTable *node)
|
||||
WRITE_ENUM_FIELD(operation, CmdType);
|
||||
WRITE_BOOL_FIELD(canSetTag);
|
||||
WRITE_UINT_FIELD(nominalRelation);
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_INT_FIELD(resultRelIndex);
|
||||
WRITE_NODE_FIELD(plans);
|
||||
@@ -368,6 +370,7 @@ _outAppend(StringInfo str, const Append *node)
|
||||
|
||||
_outPlanInfo(str, (const Plan *) node);
|
||||
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(appendplans);
|
||||
}
|
||||
|
||||
@@ -380,6 +383,7 @@ _outMergeAppend(StringInfo str, const MergeAppend *node)
|
||||
|
||||
_outPlanInfo(str, (const Plan *) node);
|
||||
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(mergeplans);
|
||||
|
||||
WRITE_INT_FIELD(numCols);
|
||||
@@ -1808,6 +1812,7 @@ _outAppendPath(StringInfo str, const AppendPath *node)
|
||||
|
||||
_outPathInfo(str, (const Path *) node);
|
||||
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(subpaths);
|
||||
}
|
||||
|
||||
@@ -1818,6 +1823,7 @@ _outMergeAppendPath(StringInfo str, const MergeAppendPath *node)
|
||||
|
||||
_outPathInfo(str, (const Path *) node);
|
||||
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(subpaths);
|
||||
WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
|
||||
}
|
||||
@@ -2023,6 +2029,7 @@ _outModifyTablePath(StringInfo str, const ModifyTablePath *node)
|
||||
WRITE_ENUM_FIELD(operation, CmdType);
|
||||
WRITE_BOOL_FIELD(canSetTag);
|
||||
WRITE_UINT_FIELD(nominalRelation);
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(subpaths);
|
||||
WRITE_NODE_FIELD(subroots);
|
||||
@@ -2099,6 +2106,7 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
|
||||
WRITE_NODE_FIELD(finalrtable);
|
||||
WRITE_NODE_FIELD(finalrowmarks);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(nonleafResultRelations);
|
||||
WRITE_NODE_FIELD(relationOids);
|
||||
WRITE_NODE_FIELD(invalItems);
|
||||
WRITE_INT_FIELD(nParamExec);
|
||||
@@ -2137,6 +2145,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
|
||||
WRITE_NODE_FIELD(full_join_clauses);
|
||||
WRITE_NODE_FIELD(join_info_list);
|
||||
WRITE_NODE_FIELD(append_rel_list);
|
||||
WRITE_NODE_FIELD(pcinfo_list);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
WRITE_NODE_FIELD(placeholder_list);
|
||||
WRITE_NODE_FIELD(fkey_list);
|
||||
@@ -2419,6 +2428,15 @@ _outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
|
||||
WRITE_OID_FIELD(parent_reloid);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPartitionedChildRelInfo(StringInfo str, const PartitionedChildRelInfo *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("PARTITIONEDCHILDRELINFO");
|
||||
|
||||
WRITE_UINT_FIELD(parent_relid);
|
||||
WRITE_NODE_FIELD(child_rels);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPlaceHolderInfo(StringInfo str, const PlaceHolderInfo *node)
|
||||
{
|
||||
@@ -3906,6 +3924,9 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_AppendRelInfo:
|
||||
_outAppendRelInfo(str, obj);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
_outPartitionedChildRelInfo(str, obj);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
_outPlaceHolderInfo(str, obj);
|
||||
break;
|
||||
|
@@ -1444,6 +1444,7 @@ _readPlannedStmt(void)
|
||||
READ_NODE_FIELD(planTree);
|
||||
READ_NODE_FIELD(rtable);
|
||||
READ_NODE_FIELD(resultRelations);
|
||||
READ_NODE_FIELD(nonleafResultRelations);
|
||||
READ_NODE_FIELD(subplans);
|
||||
READ_BITMAPSET_FIELD(rewindPlanIDs);
|
||||
READ_NODE_FIELD(rowMarks);
|
||||
@@ -1535,6 +1536,7 @@ _readModifyTable(void)
|
||||
READ_ENUM_FIELD(operation, CmdType);
|
||||
READ_BOOL_FIELD(canSetTag);
|
||||
READ_UINT_FIELD(nominalRelation);
|
||||
READ_NODE_FIELD(partitioned_rels);
|
||||
READ_NODE_FIELD(resultRelations);
|
||||
READ_INT_FIELD(resultRelIndex);
|
||||
READ_NODE_FIELD(plans);
|
||||
@@ -1564,6 +1566,7 @@ _readAppend(void)
|
||||
|
||||
ReadCommonPlan(&local_node->plan);
|
||||
|
||||
READ_NODE_FIELD(partitioned_rels);
|
||||
READ_NODE_FIELD(appendplans);
|
||||
|
||||
READ_DONE();
|
||||
@@ -1579,6 +1582,7 @@ _readMergeAppend(void)
|
||||
|
||||
ReadCommonPlan(&local_node->plan);
|
||||
|
||||
READ_NODE_FIELD(partitioned_rels);
|
||||
READ_NODE_FIELD(mergeplans);
|
||||
READ_INT_FIELD(numCols);
|
||||
READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
|
||||
|
Reference in New Issue
Block a user