mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Create a GUC variable REGEX_FLAVOR to control the type of regular
expression accepted by the regex operators, per discussion yesterday. Along the way, reduce deadlock_timeout from PGC_POSTMASTER to PGC_SIGHUP category. It is probably best to insist that all backends share the same setting, but that doesn't mean it has to be frozen at startup.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.44 2003/02/05 17:41:32 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.45 2003/02/06 20:25:33 tgl Exp $
|
||||
*
|
||||
* Alistair Crooks added the code for the regex caching
|
||||
* agc - cached the regular expressions used - there's a good chance
|
||||
@@ -34,6 +34,10 @@
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
/* GUC-settable flavor parameter */
|
||||
static int regex_flavor = REG_ADVANCED;
|
||||
|
||||
|
||||
/*
|
||||
* We cache precompiled regular expressions using a "self organizing list"
|
||||
* structure, in which recently-used items tend to be near the front.
|
||||
@@ -216,6 +220,34 @@ RE_compile_and_execute(text *text_re, unsigned char *dat, int dat_len,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* assign_regex_flavor - GUC hook to validate and set REGEX_FLAVOR
|
||||
*/
|
||||
const char *
|
||||
assign_regex_flavor(const char *value,
|
||||
bool doit, bool interactive)
|
||||
{
|
||||
if (strcasecmp(value, "advanced") == 0)
|
||||
{
|
||||
if (doit)
|
||||
regex_flavor = REG_ADVANCED;
|
||||
}
|
||||
else if (strcasecmp(value, "extended") == 0)
|
||||
{
|
||||
if (doit)
|
||||
regex_flavor = REG_EXTENDED;
|
||||
}
|
||||
else if (strcasecmp(value, "basic") == 0)
|
||||
{
|
||||
if (doit)
|
||||
regex_flavor = REG_BASIC;
|
||||
}
|
||||
else
|
||||
return NULL; /* fail */
|
||||
return value; /* OK */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* interface routines called by the function manager
|
||||
*/
|
||||
@@ -229,7 +261,7 @@ nameregexeq(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(RE_compile_and_execute(p,
|
||||
(unsigned char *) NameStr(*n),
|
||||
strlen(NameStr(*n)),
|
||||
REG_ADVANCED,
|
||||
regex_flavor,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -242,7 +274,7 @@ nameregexne(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(!RE_compile_and_execute(p,
|
||||
(unsigned char *) NameStr(*n),
|
||||
strlen(NameStr(*n)),
|
||||
REG_ADVANCED,
|
||||
regex_flavor,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -255,7 +287,7 @@ textregexeq(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(RE_compile_and_execute(p,
|
||||
(unsigned char *) VARDATA(s),
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ADVANCED,
|
||||
regex_flavor,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -268,7 +300,7 @@ textregexne(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(!RE_compile_and_execute(p,
|
||||
(unsigned char *) VARDATA(s),
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ADVANCED,
|
||||
regex_flavor,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -288,7 +320,7 @@ nameicregexeq(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(RE_compile_and_execute(p,
|
||||
(unsigned char *) NameStr(*n),
|
||||
strlen(NameStr(*n)),
|
||||
REG_ICASE | REG_ADVANCED,
|
||||
regex_flavor | REG_ICASE,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -301,7 +333,7 @@ nameicregexne(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(!RE_compile_and_execute(p,
|
||||
(unsigned char *) NameStr(*n),
|
||||
strlen(NameStr(*n)),
|
||||
REG_ICASE | REG_ADVANCED,
|
||||
regex_flavor | REG_ICASE,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -314,7 +346,7 @@ texticregexeq(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(RE_compile_and_execute(p,
|
||||
(unsigned char *) VARDATA(s),
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ICASE | REG_ADVANCED,
|
||||
regex_flavor | REG_ICASE,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -327,7 +359,7 @@ texticregexne(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(!RE_compile_and_execute(p,
|
||||
(unsigned char *) VARDATA(s),
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ICASE | REG_ADVANCED,
|
||||
regex_flavor | REG_ICASE,
|
||||
0, NULL));
|
||||
}
|
||||
|
||||
@@ -353,7 +385,7 @@ textregexsubstr(PG_FUNCTION_ARGS)
|
||||
match = RE_compile_and_execute(p,
|
||||
(unsigned char *) VARDATA(s),
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ADVANCED,
|
||||
regex_flavor,
|
||||
2, pmatch);
|
||||
|
||||
/* match? then return the substring matching the pattern */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* command, configuration file, and command line options.
|
||||
* See src/backend/utils/misc/README for more information.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.113 2003/01/28 18:04:02 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.114 2003/02/06 20:25:33 tgl Exp $
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
@@ -127,6 +127,7 @@ static double phony_random_seed;
|
||||
static char *client_encoding_string;
|
||||
static char *datestyle_string;
|
||||
static char *default_iso_level_string;
|
||||
static char *regex_flavor_string;
|
||||
static char *server_encoding_string;
|
||||
static char *session_authorization_string;
|
||||
static char *timezone_string;
|
||||
@@ -568,7 +569,7 @@ static struct config_int
|
||||
},
|
||||
|
||||
{
|
||||
{"deadlock_timeout", PGC_POSTMASTER}, &DeadlockTimeout,
|
||||
{"deadlock_timeout", PGC_SIGHUP}, &DeadlockTimeout,
|
||||
1000, 0, INT_MAX, NULL, NULL
|
||||
},
|
||||
|
||||
@@ -818,6 +819,11 @@ static struct config_string
|
||||
"C", locale_time_assign, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"regex_flavor", PGC_USERSET}, ®ex_flavor_string,
|
||||
"advanced", assign_regex_flavor, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"search_path", PGC_USERSET, GUC_LIST_INPUT | GUC_LIST_QUOTE},
|
||||
&namespace_search_path,
|
||||
|
||||
@@ -208,6 +208,7 @@
|
||||
#max_expr_depth = 10000 # min 10
|
||||
#max_files_per_process = 1000 # min 25
|
||||
#password_encryption = true
|
||||
#regex_flavor = advanced # advanced, extended, or basic
|
||||
#sql_inheritance = true
|
||||
#transform_null_equals = false
|
||||
#statement_timeout = 0 # 0 is disabled, in milliseconds
|
||||
|
||||
Reference in New Issue
Block a user