@@ -1998,12 +1998,12 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
1998
1998
{
1999
1999
TextSortSupport * tss = (TextSortSupport * ) ssup -> ssup_extra ;
2000
2000
text * authoritative = DatumGetTextPP (original );
2001
+ char * authoritative_data = VARDATA_ANY (authoritative );
2001
2002
2002
2003
/* working state */
2003
2004
Datum res ;
2004
2005
char * pres ;
2005
2006
int len ;
2006
- Size bsize ;
2007
2007
uint32 hash ;
2008
2008
2009
2009
/*
@@ -2017,14 +2017,16 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
2017
2017
2018
2018
/*
2019
2019
* If we're using the C collation, use memcmp(), rather than strxfrm(),
2020
- * to abbreviated keys. The full comparator for the C locale is always
2020
+ * to abbreviate keys. The full comparator for the C locale is always
2021
2021
* memcmp(), and we can't risk having this give a different answer.
2022
2022
* Besides, this should be faster, too.
2023
2023
*/
2024
2024
if (tss -> collate_c )
2025
- memcpy (pres , VARDATA_ANY ( authoritative ) , Min (len , sizeof (Datum )));
2025
+ memcpy (pres , authoritative_data , Min (len , sizeof (Datum )));
2026
2026
else
2027
2027
{
2028
+ Size bsize ;
2029
+
2028
2030
/*
2029
2031
* We're not using the C collation, so fall back on strxfrm.
2030
2032
*/
@@ -2067,6 +2069,14 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
2067
2069
Min (tss -> buflen2 * 2 , MaxAllocSize ));
2068
2070
tss -> buf2 = palloc (tss -> buflen2 );
2069
2071
}
2072
+
2073
+ /*
2074
+ * Every Datum byte is always compared. This is safe because the
2075
+ * strxfrm() blob is itself NUL terminated, leaving no danger of
2076
+ * misinterpreting any NUL bytes not intended to be interpreted as
2077
+ * logically representing termination.
2078
+ */
2079
+ memcpy (pres , tss -> buf2 , Min (sizeof (Datum ), bsize ));
2070
2080
}
2071
2081
2072
2082
/*
@@ -2080,15 +2090,14 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
2080
2090
* in order to compensate for cases where differences are past
2081
2091
* CACHE_LINE_SIZE bytes, so as to limit the overhead of hashing.
2082
2092
*/
2083
- hash = hash_any ((unsigned char * ) tss -> buf1 , Min (len , PG_CACHE_LINE_SIZE ));
2093
+ hash = hash_any ((unsigned char * ) authoritative_data ,
2094
+ Min (len , PG_CACHE_LINE_SIZE ));
2084
2095
2085
2096
if (len > PG_CACHE_LINE_SIZE )
2086
2097
hash ^= DatumGetUInt32 (hash_uint32 ((uint32 ) len ));
2087
2098
2088
2099
addHyperLogLog (& tss -> full_card , hash );
2089
2100
2090
- memcpy (pres , tss -> buf2 , Min (sizeof (Datum ), bsize ));
2091
-
2092
2101
/* Hash abbreviated key */
2093
2102
#if SIZEOF_DATUM == 8
2094
2103
{
@@ -2105,12 +2114,6 @@ bttext_abbrev_convert(Datum original, SortSupport ssup)
2105
2114
2106
2115
addHyperLogLog (& tss -> abbr_card , hash );
2107
2116
2108
- /*
2109
- * Every Datum byte is always compared. This is safe because the strxfrm()
2110
- * blob is itself NUL terminated, leaving no danger of misinterpreting any
2111
- * NUL bytes not intended to be interpreted as logically representing
2112
- * termination.
2113
- */
2114
2117
return res ;
2115
2118
}
2116
2119
0 commit comments