Commit 79b2e526 authored by Alvaro Herrera's avatar Alvaro Herrera

Remove quick path in ExecInitPartitionInfo for equal tupdescs

I added this "optimization" on top of Amit Langote's 158b7bc6, but
the quick path is never taken because the partition uses a different
pg_type oid than its parent table (causing equalTupleDescs to return
false).  Changing that requires more analysis and is too considered
dangerous at this point in the cycle, so revert it.

We might make it work someday, but not for pg11.

Discussion: https://postgr.es/m/825031be-942c-8c24-6163-13c27f217a3d@lab.ntt.co.jp
parent 2d625176
...@@ -313,7 +313,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -313,7 +313,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
MemoryContext oldContext; MemoryContext oldContext;
AttrNumber *part_attnos = NULL; AttrNumber *part_attnos = NULL;
bool found_whole_row; bool found_whole_row;
bool equalTupdescs;
/* /*
* We locked all the partitions in ExecSetupPartitionTupleRouting * We locked all the partitions in ExecSetupPartitionTupleRouting
...@@ -361,10 +360,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -361,10 +360,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
(node != NULL && (node != NULL &&
node->onConflictAction != ONCONFLICT_NONE)); node->onConflictAction != ONCONFLICT_NONE));
/* if tuple descs are identical, we don't need to map the attrs */
equalTupdescs = equalTupleDescs(RelationGetDescr(partrel),
RelationGetDescr(firstResultRel));
/* /*
* Build WITH CHECK OPTION constraints for the partition. Note that we * Build WITH CHECK OPTION constraints for the partition. Note that we
* didn't build the withCheckOptionList for partitions within the planner, * didn't build the withCheckOptionList for partitions within the planner,
...@@ -405,21 +400,18 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -405,21 +400,18 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
/* /*
* Convert Vars in it to contain this partition's attribute numbers. * Convert Vars in it to contain this partition's attribute numbers.
*/ */
if (!equalTupdescs) part_attnos =
{ convert_tuples_by_name_map(RelationGetDescr(partrel),
part_attnos = RelationGetDescr(firstResultRel),
convert_tuples_by_name_map(RelationGetDescr(partrel), gettext_noop("could not convert row type"));
RelationGetDescr(firstResultRel), wcoList = (List *)
gettext_noop("could not convert row type")); map_variable_attnos((Node *) wcoList,
wcoList = (List *) firstVarno, 0,
map_variable_attnos((Node *) wcoList, part_attnos,
firstVarno, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row);
/* We ignore the value of found_whole_row. */
}
foreach(ll, wcoList) foreach(ll, wcoList)
{ {
...@@ -464,25 +456,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -464,25 +456,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
*/ */
returningList = linitial(node->returningLists); returningList = linitial(node->returningLists);
if (!equalTupdescs) /*
{ * Convert Vars in it to contain this partition's attribute numbers.
/* */
* Convert Vars in it to contain this partition's attribute numbers. if (part_attnos == NULL)
*/ part_attnos =
if (part_attnos == NULL) convert_tuples_by_name_map(RelationGetDescr(partrel),
part_attnos = RelationGetDescr(firstResultRel),
convert_tuples_by_name_map(RelationGetDescr(partrel), gettext_noop("could not convert row type"));
RelationGetDescr(firstResultRel), returningList = (List *)
gettext_noop("could not convert row type")); map_variable_attnos((Node *) returningList,
returningList = (List *) firstVarno, 0,
map_variable_attnos((Node *) returningList, part_attnos,
firstVarno, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row);
/* We ignore the value of found_whole_row. */
}
leaf_part_rri->ri_returningList = returningList; leaf_part_rri->ri_returningList = returningList;
...@@ -583,33 +572,30 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -583,33 +572,30 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
* target relation (firstVarno). * target relation (firstVarno).
*/ */
onconflset = (List *) copyObject((Node *) node->onConflictSet); onconflset = (List *) copyObject((Node *) node->onConflictSet);
if (!equalTupdescs) if (part_attnos == NULL)
{ part_attnos =
if (part_attnos == NULL) convert_tuples_by_name_map(RelationGetDescr(partrel),
part_attnos = RelationGetDescr(firstResultRel),
convert_tuples_by_name_map(RelationGetDescr(partrel), gettext_noop("could not convert row type"));
RelationGetDescr(firstResultRel), onconflset = (List *)
gettext_noop("could not convert row type")); map_variable_attnos((Node *) onconflset,
onconflset = (List *) INNER_VAR, 0,
map_variable_attnos((Node *) onconflset, part_attnos,
INNER_VAR, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row); onconflset = (List *)
/* We ignore the value of found_whole_row. */ map_variable_attnos((Node *) onconflset,
onconflset = (List *) firstVarno, 0,
map_variable_attnos((Node *) onconflset, part_attnos,
firstVarno, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row);
/* We ignore the value of found_whole_row. */ /* Finally, adjust this tlist to match the partition. */
onconflset = adjust_partition_tlist(onconflset, map);
/* Finally, adjust this tlist to match the partition. */
onconflset = adjust_partition_tlist(onconflset, map);
}
/* /*
* Build UPDATE SET's projection info. The user of this * Build UPDATE SET's projection info. The user of this
...@@ -637,25 +623,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -637,25 +623,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
List *clause; List *clause;
clause = copyObject((List *) node->onConflictWhere); clause = copyObject((List *) node->onConflictWhere);
if (!equalTupdescs) clause = (List *)
{ map_variable_attnos((Node *) clause,
clause = (List *) INNER_VAR, 0,
map_variable_attnos((Node *) clause, part_attnos,
INNER_VAR, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row); clause = (List *)
/* We ignore the value of found_whole_row. */ map_variable_attnos((Node *) clause,
clause = (List *) firstVarno, 0,
map_variable_attnos((Node *) clause, part_attnos,
firstVarno, 0, RelationGetDescr(firstResultRel)->natts,
part_attnos, RelationGetForm(partrel)->reltype,
RelationGetDescr(firstResultRel)->natts, &found_whole_row);
RelationGetForm(partrel)->reltype, /* We ignore the value of found_whole_row. */
&found_whole_row);
/* We ignore the value of found_whole_row. */
}
leaf_part_rri->ri_onConflict->oc_WhereClause = leaf_part_rri->ri_onConflict->oc_WhereClause =
ExecInitQual((List *) clause, &mtstate->ps); ExecInitQual((List *) clause, &mtstate->ps);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment