@ -1824,14 +1824,12 @@ ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
* the partition constraint , if any .
* the partition constraint , if any .
*
*
* Note : ' slot ' contains the tuple to check the constraints of , which may
* Note : ' slot ' contains the tuple to check the constraints of , which may
* have been converted from the original input tuple after tuple routing ,
* have been converted from the original input tuple after tuple routing .
* while ' orig_slot ' contains the original tuple to be shown in the message ,
* ' resultRelInfo ' is the original result relation , before tuple routing .
* if an error occurs .
*/
*/
void
void
ExecConstraints ( ResultRelInfo * resultRelInfo ,
ExecConstraints ( ResultRelInfo * resultRelInfo ,
TupleTableSlot * slot , TupleTableSlot * orig_slot ,
TupleTableSlot * slot , EState * estate )
EState * estate )
{
{
Relation rel = resultRelInfo - > ri_RelationDesc ;
Relation rel = resultRelInfo - > ri_RelationDesc ;
TupleDesc tupdesc = RelationGetDescr ( rel ) ;
TupleDesc tupdesc = RelationGetDescr ( rel ) ;
@ -1854,23 +1852,37 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
{
{
char * val_desc ;
char * val_desc ;
Relation orig_rel = rel ;
Relation orig_rel = rel ;
TupleDesc orig_tupdesc = tupdesc ;
TupleDesc orig_tupdesc = RelationGetDescr ( rel ) ;
/*
/*
* choose the correct relation to build val_desc from the
* If the tuple has been routed , it ' s been converted to the
* tuple contained in orig_slot
* partition ' s rowtype , which might differ from the root
* table ' s . We must convert it back to the root table ' s
* rowtype so that val_desc shown error message matches the
* input tuple .
*/
*/
if ( resultRelInfo - > ri_PartitionRoot )
if ( resultRelInfo - > ri_PartitionRoot )
{
{
HeapTuple tuple = ExecFetchSlotTuple ( slot ) ;
TupleConversionMap * map ;
rel = resultRelInfo - > ri_PartitionRoot ;
rel = resultRelInfo - > ri_PartitionRoot ;
tupdesc = RelationGetDescr ( rel ) ;
tupdesc = RelationGetDescr ( rel ) ;
/* a reverse map */
map = convert_tuples_by_name ( orig_tupdesc , tupdesc ,
gettext_noop ( " could not convert row type " ) ) ;
if ( map ! = NULL )
{
tuple = do_convert_tuple ( tuple , map ) ;
ExecStoreTuple ( tuple , slot , InvalidBuffer , false ) ;
}
}
}
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
orig_slot ,
slot ,
tupdesc ,
tupdesc ,
modifiedCols ,
modifiedCols ,
64 ) ;
64 ) ;
@ -1897,15 +1909,27 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
/* See the comment above. */
/* See the comment above. */
if ( resultRelInfo - > ri_PartitionRoot )
if ( resultRelInfo - > ri_PartitionRoot )
{
{
HeapTuple tuple = ExecFetchSlotTuple ( slot ) ;
TupleDesc old_tupdesc = RelationGetDescr ( rel ) ;
TupleConversionMap * map ;
rel = resultRelInfo - > ri_PartitionRoot ;
rel = resultRelInfo - > ri_PartitionRoot ;
tupdesc = RelationGetDescr ( rel ) ;
tupdesc = RelationGetDescr ( rel ) ;
/* a reverse map */
map = convert_tuples_by_name ( old_tupdesc , tupdesc ,
gettext_noop ( " could not convert row type " ) ) ;
if ( map ! = NULL )
{
tuple = do_convert_tuple ( tuple , map ) ;
ExecStoreTuple ( tuple , slot , InvalidBuffer , false ) ;
}
}
}
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
orig_slot ,
slot ,
tupdesc ,
tupdesc ,
modifiedCols ,
modifiedCols ,
64 ) ;
64 ) ;
@ -1927,15 +1951,27 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
/* See the comment above. */
/* See the comment above. */
if ( resultRelInfo - > ri_PartitionRoot )
if ( resultRelInfo - > ri_PartitionRoot )
{
{
HeapTuple tuple = ExecFetchSlotTuple ( slot ) ;
TupleDesc old_tupdesc = RelationGetDescr ( rel ) ;
TupleConversionMap * map ;
rel = resultRelInfo - > ri_PartitionRoot ;
rel = resultRelInfo - > ri_PartitionRoot ;
tupdesc = RelationGetDescr ( rel ) ;
tupdesc = RelationGetDescr ( rel ) ;
/* a reverse map */
map = convert_tuples_by_name ( old_tupdesc , tupdesc ,
gettext_noop ( " could not convert row type " ) ) ;
if ( map ! = NULL )
{
tuple = do_convert_tuple ( tuple , map ) ;
ExecStoreTuple ( tuple , slot , InvalidBuffer , false ) ;
}
}
}
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
insertedCols = GetInsertedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
updatedCols = GetUpdatedColumns ( resultRelInfo , estate ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
modifiedCols = bms_union ( insertedCols , updatedCols ) ;
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
val_desc = ExecBuildSlotValueDescription ( RelationGetRelid ( rel ) ,
orig_slot ,
slot ,
tupdesc ,
tupdesc ,
modifiedCols ,
modifiedCols ,
64 ) ;
64 ) ;