mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Rewrite ExecPartitionCheckEmitError for clarity
The original was hard to follow and failed to comply with DRY principle. Discussion: https://postgr.es/m/20181206222221.g5witbsklvqthjll@alvherre.pgsql
This commit is contained in:
parent
f7ea1a4233
commit
e8b0e6b82d
@ -1837,25 +1837,26 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
|
|||||||
TupleTableSlot *slot,
|
TupleTableSlot *slot,
|
||||||
EState *estate)
|
EState *estate)
|
||||||
{
|
{
|
||||||
Relation rel = resultRelInfo->ri_RelationDesc;
|
Oid root_relid;
|
||||||
Relation orig_rel = rel;
|
TupleDesc tupdesc;
|
||||||
TupleDesc tupdesc = RelationGetDescr(rel);
|
|
||||||
char *val_desc;
|
char *val_desc;
|
||||||
Bitmapset *modifiedCols;
|
Bitmapset *modifiedCols;
|
||||||
Bitmapset *insertedCols;
|
|
||||||
Bitmapset *updatedCols;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Need to first convert the tuple to the root partitioned table's row
|
* If the tuple has been routed, it's been converted to the partition's
|
||||||
* type. For details, check similar comments in ExecConstraints().
|
* rowtype, which might differ from the root table's. We must convert it
|
||||||
|
* back to the root table's rowtype so that val_desc in the error message
|
||||||
|
* matches the input tuple.
|
||||||
*/
|
*/
|
||||||
if (resultRelInfo->ri_PartitionRoot)
|
if (resultRelInfo->ri_PartitionRoot)
|
||||||
{
|
{
|
||||||
TupleDesc old_tupdesc = RelationGetDescr(rel);
|
TupleDesc old_tupdesc;
|
||||||
AttrNumber *map;
|
AttrNumber *map;
|
||||||
|
|
||||||
rel = resultRelInfo->ri_PartitionRoot;
|
root_relid = RelationGetRelid(resultRelInfo->ri_PartitionRoot);
|
||||||
tupdesc = RelationGetDescr(rel);
|
tupdesc = RelationGetDescr(resultRelInfo->ri_PartitionRoot);
|
||||||
|
|
||||||
|
old_tupdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
|
||||||
/* a reverse map */
|
/* a reverse map */
|
||||||
map = convert_tuples_by_name_map_if_req(old_tupdesc, tupdesc,
|
map = convert_tuples_by_name_map_if_req(old_tupdesc, tupdesc,
|
||||||
gettext_noop("could not convert row type"));
|
gettext_noop("could not convert row type"));
|
||||||
@ -1868,11 +1869,16 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
|
|||||||
slot = execute_attr_map_slot(map, slot,
|
slot = execute_attr_map_slot(map, slot,
|
||||||
MakeTupleTableSlot(tupdesc, &TTSOpsVirtual));
|
MakeTupleTableSlot(tupdesc, &TTSOpsVirtual));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
root_relid = RelationGetRelid(resultRelInfo->ri_RelationDesc);
|
||||||
|
tupdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
|
||||||
|
}
|
||||||
|
|
||||||
insertedCols = GetInsertedColumns(resultRelInfo, estate);
|
modifiedCols = bms_add_members(GetInsertedColumns(resultRelInfo, estate),
|
||||||
updatedCols = GetUpdatedColumns(resultRelInfo, estate);
|
GetUpdatedColumns(resultRelInfo, estate));
|
||||||
modifiedCols = bms_union(insertedCols, updatedCols);
|
|
||||||
val_desc = ExecBuildSlotValueDescription(RelationGetRelid(rel),
|
val_desc = ExecBuildSlotValueDescription(root_relid,
|
||||||
slot,
|
slot,
|
||||||
tupdesc,
|
tupdesc,
|
||||||
modifiedCols,
|
modifiedCols,
|
||||||
@ -1880,7 +1886,7 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_CHECK_VIOLATION),
|
(errcode(ERRCODE_CHECK_VIOLATION),
|
||||||
errmsg("new row for relation \"%s\" violates partition constraint",
|
errmsg("new row for relation \"%s\" violates partition constraint",
|
||||||
RelationGetRelationName(orig_rel)),
|
RelationGetRelationName(resultRelInfo->ri_RelationDesc)),
|
||||||
val_desc ? errdetail("Failing row contains %s.", val_desc) : 0));
|
val_desc ? errdetail("Failing row contains %s.", val_desc) : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user