Commit de240a1c authored by serg@serg.mylan's avatar serg@serg.mylan

ft_boolean_syntax made changeable

parent 3c1e8aa4
......@@ -641,3 +641,5 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
INSTALL-WIN-SOURCE
libmysqld/item_subselect.cc
libmysqld/sql_derived.cc
......@@ -52,7 +52,7 @@ extern const char *ft_precompiled_stopwords[];
extern ulong ft_min_word_len;
extern ulong ft_max_word_len;
extern ulong ft_query_expansion_limit;
extern const char *ft_boolean_syntax;
extern char ft_boolean_syntax[15];
int ft_init_stopwords(void);
void ft_free_stopwords(void);
......@@ -63,6 +63,7 @@ void ft_free_stopwords(void);
#define FT_EXPAND 4 /* query expansion */
FT_INFO *ft_init_search(uint,void *, uint, byte *, uint, byte *);
my_bool ft_boolean_check_syntax_string(const byte *);
#ifdef __cplusplus
}
......
......@@ -73,6 +73,26 @@ FT_WORD * ft_linearize(TREE *wtree)
DBUG_RETURN(wlist);
}
my_bool ft_boolean_check_syntax_string(const byte *str)
{
uint i, j;
if (!str ||
(strlen(str)+1 != sizeof(ft_boolean_syntax)) ||
(str[0] != ' ' && str[1] != ' '))
return 1;
for (i=0; i<sizeof(ft_boolean_syntax); i++)
{
/* limiting to 7-bit ascii only */
if ((unsigned char)(str[i]) > 127 || my_isalnum(default_charset_info, str[i]))
return 1;
for (j=0; j<i; j++)
if (str[i] == str[j] && (i != 11 || j != 10))
return 1;
}
return 0;
}
/* returns:
* 0 - eof
* 1 - word found
......
......@@ -21,7 +21,7 @@
ulong ft_min_word_len=4;
ulong ft_max_word_len=HA_FT_MAXCHARLEN;
ulong ft_query_expansion_limit=5;
const char *ft_boolean_syntax="+ -><()~*:\"\"&|";
char ft_boolean_syntax[]="+ -><()~*:\"\"&|";
const HA_KEYSEG ft_keysegs[FT_SEGS]={
{
......
drop table if exists t1;
show variables like "ft\_%";
Variable_name Value
ft_boolean_syntax + -><()~*:""&|
......@@ -5,3 +6,33 @@ ft_min_word_len 4
ft_max_word_len 84
ft_query_expansion_limit 20
ft_stopword_file (built-in)
create table t1 (b text not null);
insert t1 values ('aaaaaa bbbbbb cccccc');
insert t1 values ('bbbbbb cccccc');
insert t1 values ('aaaaaa cccccc');
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
aaaaaa cccccc
set ft_boolean_syntax=' +-><()~*:""&|';
ERROR HY000: Variable 'ft_boolean_syntax' is a GLOBAL variable and should be set with SET GLOBAL
set global ft_boolean_syntax=' +-><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
set global ft_boolean_syntax='@ -><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
aaaaaa cccccc
select * from t1 where match b against ('+aaaaaa @bbbbbb' in boolean mode);
b
aaaaaa bbbbbb cccccc
bbbbbb cccccc
set global ft_boolean_syntax='@ -><()~*:""@|';
ERROR 42000: Variable 'ft_boolean_syntax' can't be set to the value of '@ -><()~*:""@|'
set global ft_boolean_syntax='+ -><()~*:""@!|';
ERROR 42000: Variable 'ft_boolean_syntax' can't be set to the value of '+ -><()~*:""@!|'
drop table t1;
#
# Fulltext configurable parameters
#
--disable_warnings
drop table if exists t1;
--enable_warnings
show variables like "ft\_%";
create table t1 (b text not null);
insert t1 values ('aaaaaa bbbbbb cccccc');
insert t1 values ('bbbbbb cccccc');
insert t1 values ('aaaaaa cccccc');
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
-- error 1229
set ft_boolean_syntax=' +-><()~*:""&|';
set global ft_boolean_syntax=' +-><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
set global ft_boolean_syntax='@ -><()~*:""&|';
select * from t1 where match b against ('+aaaaaa bbbbbb' in boolean mode);
select * from t1 where match b against ('+aaaaaa @bbbbbb' in boolean mode);
-- error 1231
set global ft_boolean_syntax='@ -><()~*:""@|';
-- error 1231
set global ft_boolean_syntax='+ -><()~*:""@!|';
drop table t1;
......@@ -776,7 +776,8 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
extern time_t start_time;
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[];
mysql_real_data_home[], *opt_mysql_tmpdir, mysql_charsets_dir[],
opt_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
extern MY_TMPDIR mysql_tmpdir_list;
extern const char *command_name[];
......
......@@ -317,7 +317,8 @@ char* log_error_file_ptr= log_error_file;
char mysql_real_data_home[FN_REFLEN],
language[LIBLEN],reg_ext[FN_EXTLEN], mysql_charsets_dir[FN_REFLEN],
max_sort_char,*mysqld_user,*mysqld_chroot, *opt_init_file,
*opt_init_connect, *opt_init_slave;
*opt_init_connect, *opt_init_slave,
opt_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
const char *opt_date_time_formats[3];
......@@ -3590,7 +3591,7 @@ enum options_mysqld
OPT_BACK_LOG, OPT_BINLOG_CACHE_SIZE,
OPT_CONNECT_TIMEOUT, OPT_DELAYED_INSERT_TIMEOUT,
OPT_DELAYED_INSERT_LIMIT, OPT_DELAYED_QUEUE_SIZE,
OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN,
OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN, OPT_FT_BOOLEAN_SYNTAX,
OPT_FT_MAX_WORD_LEN, OPT_FT_QUERY_EXPANSION_LIMIT, OPT_FT_STOPWORD_FILE,
OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE,
OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
......@@ -3903,7 +3904,8 @@ Disable with --skip-bdb (will save memory).",
0, 0, 0, 0},
{"master-password", OPT_MASTER_PASSWORD,
"The password the slave thread will authenticate with when connecting to the master. If not set, an empty password is assumed.The value in master.info will take precedence if it can be read.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
(gptr*)&master_password, (gptr*)&master_password, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"master-port", OPT_MASTER_PORT,
"The port the master is listening on. If not set, the compiled setting of MYSQL_PORT is assumed. If you have not tinkered with configure options, this should be 3306. The value in master.info will take precedence if it can be read.",
(gptr*) &master_port, (gptr*) &master_port, 0, GET_UINT, REQUIRED_ARG,
......@@ -4238,6 +4240,10 @@ replicating a LOAD DATA INFILE command.",
"A dedicated thread is created to flush all tables at the given interval.",
(gptr*) &flush_time, (gptr*) &flush_time, 0, GET_ULONG, REQUIRED_ARG,
FLUSH_TIME, 0, LONG_TIMEOUT, 0, 1, 0},
{ "ft_boolean_syntax", OPT_FT_BOOLEAN_SYNTAX,
"List of operators for MATCH ... AGAINST ( ... IN BOOLEAN MODE)",
0, 0, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{ "ft_min_word_len", OPT_FT_MIN_WORD_LEN,
"The minimum length of the word to be included in a FULLTEXT index. Note: FULLTEXT indexes must be rebuilt after changing this variable.",
(gptr*) &ft_min_word_len, (gptr*) &ft_min_word_len, 0, GET_ULONG,
......@@ -5415,8 +5421,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
case OPT_STORAGE_ENGINE:
{
if ((enum db_type)((global_system_variables.table_type=
ha_resolve_by_name(argument, strlen(argument)))) == DB_TYPE_UNKNOWN)
if ((enum db_type)((global_system_variables.table_type=
ha_resolve_by_name(argument, strlen(argument)))) == DB_TYPE_UNKNOWN)
{
fprintf(stderr,"Unknown table type: %s\n",argument);
exit(1);
......@@ -5581,8 +5587,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
global_system_variables.sql_mode= fix_sql_mode(global_system_variables.
sql_mode);
}
case OPT_MASTER_PASSWORD:
master_password=argument;
case OPT_FT_BOOLEAN_SYNTAX:
if (ft_boolean_check_syntax_string(argument))
{
fprintf(stderr, "Invalid ft-boolean-syntax string: %s\n", argument);
exit(1);
}
strnmov(opt_ft_boolean_syntax, argument, sizeof(ft_boolean_syntax));
break;
case OPT_SKIP_SAFEMALLOC:
#ifdef SAFEMALLOC
......@@ -5628,6 +5639,7 @@ static void get_options(int argc,char **argv)
int ho_error;
my_getopt_register_get_addr(mysql_getopt_value);
strnmov(opt_ft_boolean_syntax, ft_boolean_syntax, sizeof(ft_boolean_syntax));
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
if (argc > 0)
......@@ -5683,6 +5695,8 @@ static void get_options(int argc,char **argv)
table_alias_charset= (lower_case_table_names ?
files_charset_info :
&my_charset_bin);
strnmov(ft_boolean_syntax, opt_ft_boolean_syntax, sizeof(ft_boolean_syntax));
if (opt_short_log_format)
opt_specialflag|= SPECIAL_SHORT_LOG_FORMAT;
if (opt_log_queries_not_using_indexes)
......
......@@ -19,18 +19,18 @@
To add a new variable, one has to do the following:
- If the variable is thread specific, add it to 'system_variables' struct.
If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
- Don't forget to initialize new fields in global_system_variables and
max_system_variables!
- Use one of the 'sys_var... classes from set_var.h or write a specific
one for the variable type.
- Define it in the 'variable definition list' in this file.
- If the variable should be changeable or one should be able to access it
with @@variable_name, it should be added to the 'list of all variables'
list in this file.
list (sys_variables) in this file.
- If the variable is thread specific, add it to 'system_variables' struct.
If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
- If the variable should be changed from the command line, add a definition
of it in the my_option structure list in mysqld.dcc
- Don't forget to initialize new fields in global_system_variables and
max_system_variables!
- If the variable should show up in 'show variables' add it to the
init_vars[] struct in this file
......@@ -73,9 +73,12 @@ TYPELIB delay_key_write_typelib=
array_elements(delay_key_write_type_names)-1, "", delay_key_write_type_names
};
static bool sys_check_charset(THD *thd, set_var *var);
static int sys_check_charset(THD *thd, set_var *var);
static bool sys_update_charset(THD *thd, set_var *var);
static void sys_set_default_charset(THD *thd, enum_var_type type);
static int sys_check_ftb_syntax(THD *thd, set_var *var);
static bool sys_update_ftb_syntax(THD *thd, set_var * var);
static void sys_default_ftb_syntax(THD *thd, enum_var_type type);
static bool sys_update_init_connect(THD*, set_var*);
static void sys_default_init_connect(THD*, enum_var_type type);
static bool sys_update_init_slave(THD*, set_var*);
......@@ -117,12 +120,6 @@ sys_var_str sys_charset_system("character_set_system",
sys_check_charset,
sys_update_charset,
sys_set_default_charset);
sys_var_str sys_init_connect("init_connect", 0,
sys_update_init_connect,
sys_default_init_connect);
sys_var_str sys_init_slave("init_slave", 0,
sys_update_init_slave,
sys_default_init_slave);
sys_var_character_set_database sys_character_set_database("character_set_database");
sys_var_character_set_client sys_character_set_client("character_set_client");
sys_var_character_set_connection sys_character_set_connection("character_set_connection");
......@@ -148,6 +145,16 @@ sys_var_long_ptr sys_expire_logs_days("expire_logs_days",
&expire_logs_days);
sys_var_bool_ptr sys_flush("flush", &myisam_flush);
sys_var_long_ptr sys_flush_time("flush_time", &flush_time);
sys_var_str sys_ft_boolean_syntax("ft_boolean_syntax",
sys_check_ftb_syntax,
sys_update_ftb_syntax,
sys_default_ftb_syntax);
sys_var_str sys_init_connect("init_connect", 0,
sys_update_init_connect,
sys_default_init_connect);
sys_var_str sys_init_slave("init_slave", 0,
sys_update_init_slave,
sys_default_init_slave);
sys_var_thd_ulong sys_interactive_timeout("interactive_timeout",
&SV::net_interactive_timeout);
sys_var_thd_ulong sys_join_buffer_size("join_buffer_size",
......@@ -312,7 +319,7 @@ sys_var_thd_ulong sys_net_wait_timeout("wait_timeout",
#ifdef HAVE_INNOBASE_DB
sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct",
&srv_max_buf_pool_modified_pct);
#endif
#endif
/* Time/date/datetime formats */
......@@ -444,6 +451,7 @@ sys_var *sys_variables[]=
&sys_expire_logs_days,
&sys_flush,
&sys_flush_time,
&sys_ft_boolean_syntax,
&sys_foreign_key_checks,
&sys_group_concat_max_len,
&sys_identity,
......@@ -587,7 +595,7 @@ struct show_var_st init_vars[]= {
{sys_expire_logs_days.name, (char*) &sys_expire_logs_days, SHOW_SYS},
{sys_flush.name, (char*) &sys_flush, SHOW_SYS},
{sys_flush_time.name, (char*) &sys_flush_time, SHOW_SYS},
{"ft_boolean_syntax", (char*) ft_boolean_syntax, SHOW_CHAR},
{sys_ft_boolean_syntax.name,(char*) &ft_boolean_syntax, SHOW_CHAR},
{"ft_min_word_len", (char*) &ft_min_word_len, SHOW_LONG},
{"ft_max_word_len", (char*) &ft_max_word_len, SHOW_LONG},
{"ft_query_expansion_limit",(char*) &ft_query_expansion_limit, SHOW_LONG},
......@@ -769,6 +777,18 @@ bool sys_var::check(THD *thd, set_var *var)
return 0;
}
bool sys_var_str::check(THD *thd, set_var *var)
{
int res;
if (!check_func)
return 0;
if ((res=(*check_func)(thd, var)) < 0)
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
var->value->str_value.ptr());
return res;
}
/*
Functions to check and update variables
*/
......@@ -831,13 +851,35 @@ static void sys_default_init_slave(THD* thd, enum_var_type type)
update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
}
static int sys_check_ftb_syntax(THD *thd, set_var *var)
{
if (thd->master_access & SUPER_ACL)
return ft_boolean_check_syntax_string(var->value->str_value.ptr()) ?
-1 : 0;
else
{
my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
return 1;
}
}
static bool sys_update_ftb_syntax(THD *thd, set_var * var)
{
strnmov(ft_boolean_syntax, var->value->str_value.ptr(), sizeof(ft_boolean_syntax));
return 0;
}
static void sys_default_ftb_syntax(THD *thd, enum_var_type type)
{
strnmov(ft_boolean_syntax, opt_ft_boolean_syntax, sizeof(ft_boolean_syntax));
}
/*
The following 3 functions need to be changed in 4.1 when we allow
one to change character sets
*/
static bool sys_check_charset(THD *thd, set_var *var)
static int sys_check_charset(THD *thd, set_var *var)
{
return 0;
}
......@@ -1875,7 +1917,7 @@ byte *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type,
key_cache= &zero_key_cache;
return (byte*) key_cache + offset ;
}
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
{
......@@ -1970,14 +2012,14 @@ bool sys_var_key_cache_long::update(THD *thd, set_var *var)
pthread_mutex_lock(&LOCK_global_system_variables);
KEY_CACHE *key_cache= get_key_cache(base_name);
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
base_name->length)))
{
error= 1;
goto end;
}
/*
Abort if some other thread is changing the key cache
TODO: This should be changed so that we wait until the previous
......
......@@ -35,7 +35,7 @@ enum enum_var_type
OPT_DEFAULT, OPT_SESSION, OPT_GLOBAL
};
typedef bool (*sys_check_func)(THD *, set_var *);
typedef int (*sys_check_func)(THD *, set_var *);
typedef bool (*sys_update_func)(THD *, set_var *);
typedef void (*sys_after_update_func)(THD *,enum_var_type);
typedef void (*sys_set_default_func)(THD *, enum_var_type);
......@@ -143,10 +143,7 @@ public:
:sys_var(name_arg), check_func(check_func_arg),
update_func(update_func_arg),set_default_func(set_default_func_arg)
{}
bool check(THD *thd, set_var *var)
{
return check_func ? (*check_func)(thd, var) : 0;
}
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var)
{
return (*update_func)(thd, var);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment