Skip to content

Commit 466dac8

Browse files
committed
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.
1 parent cdcdfca commit 466dac8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,7 +5436,8 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
54365436
* in the form of a Const node; else return NULL.
54375437
*
54385438
* The caller must provide the appropriate "less than" comparison function
5439-
* for testing the strings.
5439+
* for testing the strings. In particular, ltproc->fn_collation specifies
5440+
* the locale for comparisons.
54405441
*
54415442
* The key requirement here is that given a prefix string, say "foo",
54425443
* 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)
55045505
{
55055506
/* If first time through, determine the suffix to use */
55065507
static char suffixchar = 0;
5508+
static Oid suffixcollation = 0;
55075509

5508-
if (!suffixchar)
5510+
if (!suffixchar || suffixcollation != ltproc->fn_collation)
55095511
{
55105512
char *best;
55115513

55125514
best = "Z";
5513-
if (varstr_cmp(best, 1, "z", 1, DEFAULT_COLLATION_OID) < 0)
5515+
if (varstr_cmp(best, 1, "z", 1, ltproc->fn_collation) < 0)
55145516
best = "z";
5515-
if (varstr_cmp(best, 1, "y", 1, DEFAULT_COLLATION_OID) < 0)
5517+
if (varstr_cmp(best, 1, "y", 1, ltproc->fn_collation) < 0)
55165518
best = "y";
5517-
if (varstr_cmp(best, 1, "9", 1, DEFAULT_COLLATION_OID) < 0)
5519+
if (varstr_cmp(best, 1, "9", 1, ltproc->fn_collation) < 0)
55185520
best = "9";
55195521
suffixchar = *best;
5522+
suffixcollation = ltproc->fn_collation;
55205523
}
55215524

55225525
/* And build the string to compare to */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy