diff options
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/date.c | 15 | ||||
-rw-r--r-- | src/backend/utils/adt/mac.c | 23 | ||||
-rw-r--r-- | src/backend/utils/adt/network.c | 17 | ||||
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 11 | ||||
-rw-r--r-- | src/backend/utils/adt/uuid.c | 25 | ||||
-rw-r--r-- | src/backend/utils/adt/varlena.c | 34 |
6 files changed, 27 insertions, 98 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index fee610916f7..081dfa2450f 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -439,25 +439,12 @@ date_cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(0); } -static int -date_fastcmp(Datum x, Datum y, SortSupport ssup) -{ - DateADT a = DatumGetDateADT(x); - DateADT b = DatumGetDateADT(y); - - if (a < b) - return -1; - else if (a > b) - return 1; - return 0; -} - Datum date_sortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); - ssup->comparator = date_fastcmp; + ssup->comparator = ssup_datum_int32_cmp; PG_RETURN_VOID(); } diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c index 88a1698cf96..ac7342cfca7 100644 --- a/src/backend/utils/adt/mac.c +++ b/src/backend/utils/adt/mac.c @@ -44,7 +44,6 @@ typedef struct static int macaddr_cmp_internal(macaddr *a1, macaddr *a2); static int macaddr_fast_cmp(Datum x, Datum y, SortSupport ssup); -static int macaddr_cmp_abbrev(Datum x, Datum y, SortSupport ssup); static bool macaddr_abbrev_abort(int memtupcount, SortSupport ssup); static Datum macaddr_abbrev_convert(Datum original, SortSupport ssup); @@ -381,7 +380,7 @@ macaddr_sortsupport(PG_FUNCTION_ARGS) ssup->ssup_extra = uss; - ssup->comparator = macaddr_cmp_abbrev; + ssup->comparator = ssup_datum_unsigned_cmp; ssup->abbrev_converter = macaddr_abbrev_convert; ssup->abbrev_abort = macaddr_abbrev_abort; ssup->abbrev_full_comparator = macaddr_fast_cmp; @@ -406,22 +405,6 @@ macaddr_fast_cmp(Datum x, Datum y, SortSupport ssup) } /* - * SortSupport abbreviated key comparison function. Compares two MAC addresses - * quickly by treating them like integers, and without having to go to the - * heap. - */ -static int -macaddr_cmp_abbrev(Datum x, Datum y, SortSupport ssup) -{ - if (x > y) - return 1; - else if (x == y) - return 0; - else - return -1; -} - -/* * Callback for estimating effectiveness of abbreviated key optimization. * * We pay no attention to the cardinality of the non-abbreviated data, because @@ -537,8 +520,8 @@ macaddr_abbrev_convert(Datum original, SortSupport ssup) /* * Byteswap on little-endian machines. * - * This is needed so that macaddr_cmp_abbrev() (an unsigned integer 3-way - * comparator) works correctly on all platforms. Without this, the + * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer + * 3-way comparator) works correctly on all platforms. Without this, the * comparator would have to call memcmp() with a pair of pointers to the * first byte of each abbreviated key, which is slower. */ diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 0ab54316f8e..ea1c7390d0d 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -53,7 +53,6 @@ typedef struct static int32 network_cmp_internal(inet *a1, inet *a2); static int network_fast_cmp(Datum x, Datum y, SortSupport ssup); -static int network_cmp_abbrev(Datum x, Datum y, SortSupport ssup); static bool network_abbrev_abort(int memtupcount, SortSupport ssup); static Datum network_abbrev_convert(Datum original, SortSupport ssup); static List *match_network_function(Node *leftop, @@ -456,7 +455,7 @@ network_sortsupport(PG_FUNCTION_ARGS) ssup->ssup_extra = uss; - ssup->comparator = network_cmp_abbrev; + ssup->comparator = ssup_datum_unsigned_cmp; ssup->abbrev_converter = network_abbrev_convert; ssup->abbrev_abort = network_abbrev_abort; ssup->abbrev_full_comparator = network_fast_cmp; @@ -480,20 +479,6 @@ network_fast_cmp(Datum x, Datum y, SortSupport ssup) } /* - * Abbreviated key comparison func - */ -static int -network_cmp_abbrev(Datum x, Datum y, SortSupport ssup) -{ - if (x > y) - return 1; - else if (x == y) - return 0; - else - return -1; -} - -/* * Callback for estimating effectiveness of abbreviated key optimization. * * We pay no attention to the cardinality of the non-abbreviated data, because diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index ae36ff33285..2ba8d41284f 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -37,6 +37,7 @@ #include "utils/datetime.h" #include "utils/float.h" #include "utils/numeric.h" +#include "utils/sortsupport.h" /* * gcc's -ffast-math switch breaks routines that expect exact results from @@ -2155,6 +2156,7 @@ timestamp_cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); } +#ifndef USE_FLOAT8_BYVAL /* note: this is used for timestamptz also */ static int timestamp_fastcmp(Datum x, Datum y, SortSupport ssup) @@ -2164,13 +2166,22 @@ timestamp_fastcmp(Datum x, Datum y, SortSupport ssup) return timestamp_cmp_internal(a, b); } +#endif Datum timestamp_sortsupport(PG_FUNCTION_ARGS) { SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); +#ifdef USE_FLOAT8_BYVAL + /* + * If this build has pass-by-value timestamps, then we can use a standard + * comparator function. + */ + ssup->comparator = ssup_datum_signed_cmp; +#else ssup->comparator = timestamp_fastcmp; +#endif PG_RETURN_VOID(); } diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c index 9e06d9ba123..a157f864e12 100644 --- a/src/backend/utils/adt/uuid.c +++ b/src/backend/utils/adt/uuid.c @@ -34,7 +34,6 @@ typedef struct static void string_to_uuid(const char *source, pg_uuid_t *uuid); static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2); static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup); -static int uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup); static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup); static Datum uuid_abbrev_convert(Datum original, SortSupport ssup); @@ -255,7 +254,7 @@ uuid_sortsupport(PG_FUNCTION_ARGS) ssup->ssup_extra = uss; - ssup->comparator = uuid_cmp_abbrev; + ssup->comparator = ssup_datum_unsigned_cmp; ssup->abbrev_converter = uuid_abbrev_convert; ssup->abbrev_abort = uuid_abbrev_abort; ssup->abbrev_full_comparator = uuid_fast_cmp; @@ -279,20 +278,6 @@ uuid_fast_cmp(Datum x, Datum y, SortSupport ssup) } /* - * Abbreviated key comparison func - */ -static int -uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup) -{ - if (x > y) - return 1; - else if (x == y) - return 0; - else - return -1; -} - -/* * Callback for estimating effectiveness of abbreviated key optimization. * * We pay no attention to the cardinality of the non-abbreviated data, because @@ -390,10 +375,10 @@ uuid_abbrev_convert(Datum original, SortSupport ssup) /* * Byteswap on little-endian machines. * - * This is needed so that uuid_cmp_abbrev() (an unsigned integer 3-way - * comparator) works correctly on all platforms. If we didn't do this, - * the comparator would have to call memcmp() with a pair of pointers to - * the first byte of each abbreviated key, which is slower. + * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer + * 3-way comparator) works correctly on all platforms. If we didn't do + * this, the comparator would have to call memcmp() with a pair of pointers + * to the first byte of each abbreviated key, which is slower. */ res = DatumBigEndianToNative(res); diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 22ab5a4329f..cfc135c7beb 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -126,7 +126,6 @@ static int namefastcmp_c(Datum x, Datum y, SortSupport ssup); static int varlenafastcmp_locale(Datum x, Datum y, SortSupport ssup); static int namefastcmp_locale(Datum x, Datum y, SortSupport ssup); static int varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup); -static int varstrcmp_abbrev(Datum x, Datum y, SortSupport ssup); static Datum varstr_abbrev_convert(Datum original, SortSupport ssup); static bool varstr_abbrev_abort(int memtupcount, SortSupport ssup); static int32 text_length(Datum str); @@ -2159,7 +2158,7 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid) initHyperLogLog(&sss->abbr_card, 10); initHyperLogLog(&sss->full_card, 10); ssup->abbrev_full_comparator = ssup->comparator; - ssup->comparator = varstrcmp_abbrev; + ssup->comparator = ssup_datum_unsigned_cmp; ssup->abbrev_converter = varstr_abbrev_convert; ssup->abbrev_abort = varstr_abbrev_abort; } @@ -2446,27 +2445,6 @@ varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup) } /* - * Abbreviated key comparison func - */ -static int -varstrcmp_abbrev(Datum x, Datum y, SortSupport ssup) -{ - /* - * When 0 is returned, the core system will call varstrfastcmp_c() - * (bpcharfastcmp_c() in BpChar case) or varlenafastcmp_locale(). Even a - * strcmp() on two non-truncated strxfrm() blobs cannot indicate *equality* - * authoritatively, for the same reason that there is a strcoll() - * tie-breaker call to strcmp() in varstr_cmp(). - */ - if (x > y) - return 1; - else if (x == y) - return 0; - else - return -1; -} - -/* * Conversion routine for sortsupport. Converts original to abbreviated key * representation. Our encoding strategy is simple -- pack the first 8 bytes * of a strxfrm() blob into a Datum (on little-endian machines, the 8 bytes are @@ -2504,7 +2482,7 @@ varstr_abbrev_convert(Datum original, SortSupport ssup) * strings may contain NUL bytes. Besides, this should be faster, too. * * More generally, it's okay that bytea callers can have NUL bytes in - * strings because varstrcmp_abbrev() need not make a distinction between + * strings because abbreviated cmp need not make a distinction between * terminating NUL bytes, and NUL bytes representing actual NULs in the * authoritative representation. Hopefully a comparison at or past one * abbreviated key's terminating NUL byte will resolve the comparison @@ -2694,10 +2672,10 @@ done: /* * Byteswap on little-endian machines. * - * This is needed so that varstrcmp_abbrev() (an unsigned integer 3-way - * comparator) works correctly on all platforms. If we didn't do this, - * the comparator would have to call memcmp() with a pair of pointers to - * the first byte of each abbreviated key, which is slower. + * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer + * 3-way comparator) works correctly on all platforms. If we didn't do + * this, the comparator would have to call memcmp() with a pair of pointers + * to the first byte of each abbreviated key, which is slower. */ res = DatumBigEndianToNative(res); |