diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-04-08 17:39:59 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-04-08 17:40:20 -0400 |
commit | 466dac8656c11317b91c1a4bfd5cfca4508cba94 (patch) | |
tree | f5dae824a016b4b23c710c73c54bd959b1b773bf /src | |
parent | cdcdfca40199bbdb30c78d105e4db267b631289c (diff) | |
download | postgresql-466dac8656c11317b91c1a4bfd5cfca4508cba94.tar.gz postgresql-466dac8656c11317b91c1a4bfd5cfca4508cba94.zip |
Fix make_greater_string to not have an undocumented collation assumption.
The previous coding worked only if ltproc->fn_collation was always either
DEFAULT_COLLATION_OID or a C-compatible locale. While that's true at the
moment, it wasn't documented (and in fact wasn't true when this code was
committed...). But it only takes a couple more lines to make its internal
caching behavior locale-aware, so let's do that.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index f7358d198c5..092dc15a02b 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -5436,7 +5436,8 @@ pattern_selectivity(Const *patt, Pattern_Type ptype) * in the form of a Const node; else return NULL. * * The caller must provide the appropriate "less than" comparison function - * for testing the strings. + * for testing the strings. In particular, ltproc->fn_collation specifies + * the locale for comparisons. * * The key requirement here is that given a prefix string, say "foo", * we must be able to generate another string "fop" that is greater than @@ -5504,19 +5505,21 @@ make_greater_string(const Const *str_const, FmgrInfo *ltproc) { /* If first time through, determine the suffix to use */ static char suffixchar = 0; + static Oid suffixcollation = 0; - if (!suffixchar) + if (!suffixchar || suffixcollation != ltproc->fn_collation) { char *best; best = "Z"; - if (varstr_cmp(best, 1, "z", 1, DEFAULT_COLLATION_OID) < 0) + if (varstr_cmp(best, 1, "z", 1, ltproc->fn_collation) < 0) best = "z"; - if (varstr_cmp(best, 1, "y", 1, DEFAULT_COLLATION_OID) < 0) + if (varstr_cmp(best, 1, "y", 1, ltproc->fn_collation) < 0) best = "y"; - if (varstr_cmp(best, 1, "9", 1, DEFAULT_COLLATION_OID) < 0) + if (varstr_cmp(best, 1, "9", 1, ltproc->fn_collation) < 0) best = "9"; suffixchar = *best; + suffixcollation = ltproc->fn_collation; } /* And build the string to compare to */ |