On Mon, Jun 9, 2025 at 7:14 PM Dilip Kumar <dilipbal...@gmail.com> wrote: > > I was reviewing the code for conflict reporting and became curious > about the choice of ERRCODE_T_R_SERIALIZATION_FAILURE. This error code > typically signifies a serialization failure within a transaction under > serializable isolation, so its use here for a different type of > conflict seems somewhat out of place. I did notice its use in other > contexts for recovery conflicts in physical replication, which also > struck me as a bit unusual. >
I examined the usage of ERRCODE_T_R_SERIALIZATION_FAILURE in the code, and it appears that, apart from logical and recovery conflicts, it is also used in places other than the cases under the serializable isolation level. For example, if (ItemPointerIndicatesMovedPartitions(tid)) ereport(ERROR, (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE), errmsg("tuple to be locked was already moved to another partition due to concurrent update"))); if (ItemPointerIndicatesMovedPartitions(&context->tmfd.ctid)) ereport(ERROR, (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE), errmsg("tuple to be merged was already moved to another partition due to concurrent update"))); Then it is also used in ExecCheckTupleVisible and execReplication.c without serializable isolation. Seeing this, it seems SERIALIZATION in the errod_code refers to the case where the transaction could not be serialized due to concurrent access conflicts. Now, we typically use it for serializable isolation, but its use at other places where transactions attempt to modify the same data simultaneously doesn't seem unreasonable. > Given these observations, I'm wondering if it would be more > appropriate to introduce a new, more specific error code for this > purpose? > If we want to have separate errorcode(s) for logical and recovery conflicts, one possibility is to add new codes in Class 55 (Object Not In Prerequisite State (class borrowed from DB2)). ERRCODE_CONFLICT_CANT_ACCESS: all recovery conflicts, delete_missing, and update_missing ERRCODE_CONFLICT_CANT_MODIFY : update_origin_differ and delete_origin_differ The reason I thought class 55 is suitable because it has other codes like ERRCODE_CANT_CHANGE_RUNTIME_PARAM, ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE, ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE, which to me appear to have some similarity. I have checked the same class in DB2 [1] and it had a few related codes like: 55019 The object is in an invalid state for the operation. 55079 The operation cannot be performed because the XML column is not in the versioning format. [1] - https://www.ibm.com/docs/en/db2-for-zos/12.0.0?topic=codes-sqlstate-values-common-error#db2z_sqlstatevalues__classcode55 -- With Regards, Amit Kapila.