From 26bba5c38e83eea061bcfd1f3a8a0a228c466c58 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Thu, 23 Mar 2023 17:44:03 +1300 Subject: [PATCH v1 2/2] Remove unused datum_image_eq() and datum_image_hash() functions --- src/backend/utils/adt/datum.c | 121 ---------------------------------- src/include/utils/datum.h | 17 ----- 2 files changed, 138 deletions(-) diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 3947120a42..db095d7f7c 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -257,76 +257,6 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen) return res; } -/*------------------------------------------------------------------------- - * datum_image_eq -- Use datum_image_attr_eq instead - * - * Compares two datums for identical contents, based on byte images. Return - * true if the two datums are equal, false otherwise. - *------------------------------------------------------------------------- - */ -bool -datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen) -{ - Size len1, - len2; - bool result = true; - - if (typByVal) - { - result = (value1 == value2); - } - else if (typLen > 0) - { - result = (memcmp(DatumGetPointer(value1), - DatumGetPointer(value2), - typLen) == 0); - } - else if (typLen == -1) - { - len1 = toast_raw_datum_size(value1); - len2 = toast_raw_datum_size(value2); - /* No need to de-toast if lengths don't match. */ - if (len1 != len2) - result = false; - else - { - struct varlena *arg1val; - struct varlena *arg2val; - - arg1val = PG_DETOAST_DATUM_PACKED(value1); - arg2val = PG_DETOAST_DATUM_PACKED(value2); - - result = (memcmp(VARDATA_ANY(arg1val), - VARDATA_ANY(arg2val), - len1 - VARHDRSZ) == 0); - - /* Only free memory if it's a copy made here. */ - if ((Pointer) arg1val != (Pointer) value1) - pfree(arg1val); - if ((Pointer) arg2val != (Pointer) value2) - pfree(arg2val); - } - } - else if (typLen == -2) - { - char *s1, - *s2; - - /* Compare cstring datums */ - s1 = DatumGetCString(value1); - s2 = DatumGetCString(value2); - len1 = strlen(s1) + 1; - len2 = strlen(s2) + 1; - if (len1 != len2) - return false; - result = (memcmp(s1, s2, len1) == 0); - } - else - elog(ERROR, "unexpected typLen: %d", typLen); - - return result; -} - /*------------------------------------------------------------------------- * datum_image_attr_eq * @@ -411,57 +341,6 @@ datum_image_attr_eq(Datum value1, Datum value2, FormData_pg_attribute *atttype) return result; } -/*------------------------------------------------------------------------- - * datum_image_hash -- Use datum_image_attr_hash instead - * - * Generate a hash value based on the binary representation of 'value'. Most - * use cases will want to use the hash function specific to the Datum's type, - * however, some corner cases require generating a hash value based on the - * actual bits rather than the logical value. - *------------------------------------------------------------------------- - */ -uint32 -datum_image_hash(Datum value, bool typByVal, int typLen) -{ - Size len; - uint32 result; - - if (typByVal) - result = hash_bytes((unsigned char *) &value, sizeof(Datum)); - else if (typLen > 0) - result = hash_bytes((unsigned char *) DatumGetPointer(value), typLen); - else if (typLen == -1) - { - struct varlena *val; - - len = toast_raw_datum_size(value); - - val = PG_DETOAST_DATUM_PACKED(value); - - result = hash_bytes((unsigned char *) VARDATA_ANY(val), len - VARHDRSZ); - - /* Only free memory if it's a copy made here. */ - if ((Pointer) val != (Pointer) value) - pfree(val); - } - else if (typLen == -2) - { - char *s; - - s = DatumGetCString(value); - len = strlen(s) + 1; - - result = hash_bytes((unsigned char *) s, len); - } - else - { - elog(ERROR, "unexpected typLen: %d", typLen); - result = 0; /* keep compiler quiet */ - } - - return result; -} - /*------------------------------------------------------------------------- * datum_image_attr_hash * diff --git a/src/include/utils/datum.h b/src/include/utils/datum.h index 046e789f7c..cbe45333e8 100644 --- a/src/include/utils/datum.h +++ b/src/include/utils/datum.h @@ -48,15 +48,6 @@ extern Datum datumTransfer(Datum value, bool typByVal, int typLen); extern bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen); -/* - * datum_image_eq -- Use datum_image_attr_eq instead - * - * Compares two datums for identical contents, based on byte images. Return - * true if the two datums are equal, false otherwise. - */ -extern bool datum_image_eq(Datum value1, Datum value2, - bool typByVal, int typLen); - /* * datum_image_attr_eq * @@ -66,14 +57,6 @@ extern bool datum_image_eq(Datum value1, Datum value2, extern bool datum_image_attr_eq(Datum value1, Datum value2, struct FormData_pg_attribute *atttype); -/* - * datum_image_hash -- Use datum_image_attr_hash instead - * - * Generates hash value for 'value' based on its bits rather than logical - * value. - */ -extern uint32 datum_image_hash(Datum value, bool typByVal, int typLen); - /* * datum_image_attr_hash * -- 2.37.2