diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index 11c6a4eee..7e0a3a994 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -911,9 +911,6 @@ CanUseBinaryCopyFormat(TupleDesc tupleDescription) { Form_pg_attribute currentColumn = TupleDescAttr(tupleDescription, columnIndex); Oid typeId = InvalidOid; - char typeCategory = '\0'; - bool typePreferred = false; - bool binaryOutputFunctionDefined = false; if (currentColumn->attisdropped) { @@ -921,31 +918,48 @@ CanUseBinaryCopyFormat(TupleDesc tupleDescription) } typeId = currentColumn->atttypid; - - /* built-in types may also don't have binary output function */ - binaryOutputFunctionDefined = BinaryOutputFunctionDefined(typeId); - if (!binaryOutputFunctionDefined) + if (!CanUseBinaryCopyFormatForType(typeId)) { useBinaryCopyFormat = false; break; } - - if (typeId >= FirstNormalObjectId) - { - get_type_category_preferred(typeId, &typeCategory, &typePreferred); - if (typeCategory == TYPCATEGORY_ARRAY || - typeCategory == TYPCATEGORY_COMPOSITE) - { - useBinaryCopyFormat = false; - break; - } - } } return useBinaryCopyFormat; } +/* + * CanUseBinaryCopyFormatForType determines whether it is safe to use the + * binary copy format for the given type. The binary copy format cannot + * be used for arrays or composite types that contain user-defined types, + * or when there is no binary output function defined. + */ +bool +CanUseBinaryCopyFormatForType(Oid typeId) +{ + if (!BinaryOutputFunctionDefined(typeId)) + { + return false; + } + + if (typeId >= FirstNormalObjectId) + { + char typeCategory = '\0'; + bool typePreferred = false; + + get_type_category_preferred(typeId, &typeCategory, &typePreferred); + if (typeCategory == TYPCATEGORY_ARRAY || + typeCategory == TYPCATEGORY_COMPOSITE) + { + return false; + } + } + + return true; +} + + /* * BinaryOutputFunctionDefined checks whether binary output function is defined * for the given type. diff --git a/src/include/distributed/multi_copy.h b/src/include/distributed/multi_copy.h index 0c9b4a2f8..5269a61f1 100644 --- a/src/include/distributed/multi_copy.h +++ b/src/include/distributed/multi_copy.h @@ -116,6 +116,7 @@ extern CitusCopyDestReceiver * CreateCitusCopyDestReceiver(Oid relationId, bool stopOnFailure); extern FmgrInfo * ColumnOutputFunctions(TupleDesc rowDescriptor, bool binaryFormat); extern bool CanUseBinaryCopyFormat(TupleDesc tupleDescription); +extern bool CanUseBinaryCopyFormatForType(Oid typeId); extern void AppendCopyRowData(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor, CopyOutState rowOutputState,