From bbea3643a3a6425f92d0db9ff16c7f73a31a466c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 25 Nov 2000 20:33:54 +0000 Subject: Store current LC_COLLATE and LC_CTYPE settings in pg_control during initdb; re-adopt these settings at every postmaster or standalone-backend startup. This should fix problems with indexes becoming corrupt due to failure to provide consistent locale environment for postmaster at all times. Also, refuse to start up a non-locale-enabled compilation in a database originally initdb'd with a non-C locale. Suppress LIKE index optimization if locale is not "C" or "POSIX" (are there any other locales where it's safe?). Issue NOTICE during initdb if selected locale disables LIKE optimization. --- src/backend/optimizer/path/indxpath.c | 82 ++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 35 deletions(-) (limited to 'src/backend/optimizer/path/indxpath.c') diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 43577f94f99..63e3a53af5a 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.98 2000/11/16 22:30:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.99 2000/11/25 20:33:51 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1746,56 +1746,68 @@ match_special_index_operator(Expr *clause, Oid opclass, Oid relam, case OID_BPCHAR_LIKE_OP: case OID_VARCHAR_LIKE_OP: case OID_NAME_LIKE_OP: - /* the right-hand const is type text for all of these */ - patt = DatumGetCString(DirectFunctionCall1(textout, - constvalue)); - isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like, - &prefix, &rest) != Pattern_Prefix_None; - if (prefix) - pfree(prefix); - pfree(patt); + if (locale_is_like_safe()) + { + /* the right-hand const is type text for all of these */ + patt = DatumGetCString(DirectFunctionCall1(textout, + constvalue)); + isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like, + &prefix, &rest) != Pattern_Prefix_None; + if (prefix) + pfree(prefix); + pfree(patt); + } break; case OID_TEXT_ICLIKE_OP: case OID_BPCHAR_ICLIKE_OP: case OID_VARCHAR_ICLIKE_OP: case OID_NAME_ICLIKE_OP: - /* the right-hand const is type text for all of these */ - patt = DatumGetCString(DirectFunctionCall1(textout, - constvalue)); - isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, - &prefix, &rest) != Pattern_Prefix_None; - if (prefix) - pfree(prefix); - pfree(patt); + if (locale_is_like_safe()) + { + /* the right-hand const is type text for all of these */ + patt = DatumGetCString(DirectFunctionCall1(textout, + constvalue)); + isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, + &prefix, &rest) != Pattern_Prefix_None; + if (prefix) + pfree(prefix); + pfree(patt); + } break; case OID_TEXT_REGEXEQ_OP: case OID_BPCHAR_REGEXEQ_OP: case OID_VARCHAR_REGEXEQ_OP: case OID_NAME_REGEXEQ_OP: - /* the right-hand const is type text for all of these */ - patt = DatumGetCString(DirectFunctionCall1(textout, - constvalue)); - isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex, - &prefix, &rest) != Pattern_Prefix_None; - if (prefix) - pfree(prefix); - pfree(patt); + if (locale_is_like_safe()) + { + /* the right-hand const is type text for all of these */ + patt = DatumGetCString(DirectFunctionCall1(textout, + constvalue)); + isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex, + &prefix, &rest) != Pattern_Prefix_None; + if (prefix) + pfree(prefix); + pfree(patt); + } break; case OID_TEXT_ICREGEXEQ_OP: case OID_BPCHAR_ICREGEXEQ_OP: case OID_VARCHAR_ICREGEXEQ_OP: case OID_NAME_ICREGEXEQ_OP: - /* the right-hand const is type text for all of these */ - patt = DatumGetCString(DirectFunctionCall1(textout, - constvalue)); - isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, - &prefix, &rest) != Pattern_Prefix_None; - if (prefix) - pfree(prefix); - pfree(patt); + if (locale_is_like_safe()) + { + /* the right-hand const is type text for all of these */ + patt = DatumGetCString(DirectFunctionCall1(textout, + constvalue)); + isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, + &prefix, &rest) != Pattern_Prefix_None; + if (prefix) + pfree(prefix); + pfree(patt); + } break; } @@ -2053,8 +2065,8 @@ prefix_quals(Var *leftop, Oid expr_op, result = makeList1(expr); /* - * If we can create a string larger than the prefix, say "x < - * greaterstr". + * If we can create a string larger than the prefix, we can say + * "x < greaterstr". */ greaterstr = make_greater_string(prefix, datatype); if (greaterstr) -- cgit v1.2.3