diff options
Diffstat (limited to 'src/backend/utils/adt/varchar.c')
-rw-r--r-- | src/backend/utils/adt/varchar.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 0498fef4049..94d6da5eb57 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -17,6 +17,7 @@ #include "access/hash.h" #include "access/tuptoaster.h" +#include "catalog/pg_collation.h" #include "libpq/pqformat.h" #include "nodes/nodeFuncs.h" #include "utils/array.h" @@ -649,14 +650,21 @@ varchartypmodout(PG_FUNCTION_ARGS) *****************************************************************************/ /* "True" length (not counting trailing blanks) of a BpChar */ -static int +static inline int bcTruelen(BpChar *arg) { - char *s = VARDATA_ANY(arg); + return bpchartruelen(VARDATA_ANY(arg), VARSIZE_ANY_EXHDR(arg)); +} + +int +bpchartruelen(char *s, int len) +{ int i; - int len; - len = VARSIZE_ANY_EXHDR(arg); + /* + * Note that we rely on the assumption that ' ' is a singleton unit on + * every supported multibyte server encoding. + */ for (i = len - 1; i >= 0; i--) { if (s[i] != ' ') @@ -859,6 +867,23 @@ bpcharcmp(PG_FUNCTION_ARGS) } Datum +bpchar_sortsupport(PG_FUNCTION_ARGS) +{ + SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); + Oid collid = ssup->ssup_collation; + MemoryContext oldcontext; + + oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt); + + /* Use generic string SortSupport */ + varstr_sortsupport(ssup, collid, true); + + MemoryContextSwitchTo(oldcontext); + + PG_RETURN_VOID(); +} + +Datum bpchar_larger(PG_FUNCTION_ARGS) { BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); @@ -926,8 +951,9 @@ hashbpchar(PG_FUNCTION_ARGS) /* * The following operators support character-by-character comparison * of bpchar datums, to allow building indexes suitable for LIKE clauses. - * Note that the regular bpchareq/bpcharne comparison operators are assumed - * to be compatible with these! + * Note that the regular bpchareq/bpcharne comparison operators, and + * regular support functions 1 and 2 with "C" collation are assumed to be + * compatible with these! */ static int @@ -1030,3 +1056,20 @@ btbpchar_pattern_cmp(PG_FUNCTION_ARGS) PG_RETURN_INT32(result); } + + +Datum +btbpchar_pattern_sortsupport(PG_FUNCTION_ARGS) +{ + SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); + MemoryContext oldcontext; + + oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt); + + /* Use generic string SortSupport, forcing "C" collation */ + varstr_sortsupport(ssup, C_COLLATION_OID, true); + + MemoryContextSwitchTo(oldcontext); + + PG_RETURN_VOID(); +} |