diff options
author | Leonard Zhou <leonard@mysql.com> | 2009-03-16 17:06:22 +0800 |
---|---|---|
committer | Leonard Zhou <leonard@mysql.com> | 2009-03-16 17:06:22 +0800 |
commit | 53849a24f97ad28a46dfb2a76a987676dda476fe (patch) | |
tree | aa54713ea2cc67a7a6887c901cc613e25f7b8350 /sql | |
parent | b42c29cfe33b5c5aab33661357fa4eb309e86132 (diff) | |
parent | e0a1c593a6764603312e590c5ef320d5b2c6a9dd (diff) | |
download | mariadb-git-53849a24f97ad28a46dfb2a76a987676dda476fe.tar.gz |
Merge
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_partition.cc | 5 | ||||
-rw-r--r-- | sql/handler.cc | 2 | ||||
-rw-r--r-- | sql/item.cc | 1 | ||||
-rw-r--r-- | sql/item_func.cc | 10 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 5 | ||||
-rw-r--r-- | sql/item_sum.cc | 3 | ||||
-rw-r--r-- | sql/log.cc | 7 | ||||
-rw-r--r-- | sql/log_event.cc | 6 | ||||
-rw-r--r-- | sql/log_event.h | 2 | ||||
-rw-r--r-- | sql/mysql_priv.h | 6 | ||||
-rw-r--r-- | sql/mysqld.cc | 209 | ||||
-rw-r--r-- | sql/opt_range.cc | 57 | ||||
-rw-r--r-- | sql/protocol.cc | 23 | ||||
-rw-r--r-- | sql/rpl_record.cc | 34 | ||||
-rw-r--r-- | sql/rpl_rli.cc | 5 | ||||
-rw-r--r-- | sql/rpl_rli.h | 7 | ||||
-rw-r--r-- | sql/set_var.cc | 232 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 39 | ||||
-rw-r--r-- | sql/sp.cc | 4 | ||||
-rw-r--r-- | sql/sql_base.cc | 3 | ||||
-rw-r--r-- | sql/sql_cache.cc | 47 | ||||
-rw-r--r-- | sql/sql_class.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.h | 2 | ||||
-rw-r--r-- | sql/sql_handler.cc | 19 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 9 | ||||
-rw-r--r-- | sql/sql_load.cc | 29 | ||||
-rw-r--r-- | sql/sql_parse.cc | 57 | ||||
-rw-r--r-- | sql/sql_plugin.cc | 35 | ||||
-rw-r--r-- | sql/sql_select.cc | 12 | ||||
-rw-r--r-- | sql/sql_show.cc | 44 | ||||
-rw-r--r-- | sql/sql_table.cc | 11 | ||||
-rw-r--r-- | sql/sql_view.cc | 52 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 17 | ||||
-rw-r--r-- | sql/table.cc | 6 | ||||
-rw-r--r-- | sql/unireg.cc | 17 |
36 files changed, 708 insertions, 314 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 0e36a868b3e..67bc3156260 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4928,10 +4928,11 @@ int ha_partition::info(uint flag) This flag is used to get index number of the unique index that reported duplicate key We will report the errkey on the last handler used and ignore the rest + Note: all engines does not support HA_STATUS_ERRKEY, so set errkey. */ + file->errkey= errkey; file->info(HA_STATUS_ERRKEY); - if (file->errkey != (uint) -1) - errkey= file->errkey; + errkey= file->errkey; } if (flag & HA_STATUS_TIME) { diff --git a/sql/handler.cc b/sql/handler.cc index 853ab29d38a..18c8e6c1f5a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2932,7 +2932,7 @@ uint handler::get_dup_key(int error) if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL || error == HA_ERR_DROP_INDEX_FK) - info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK); + table->file->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK); DBUG_RETURN(table->file->errkey); } diff --git a/sql/item.cc b/sql/item.cc index 33ec4a1a255..28ace4b114d 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1758,7 +1758,6 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname, bool agg_item_charsets(DTCollation &coll, const char *fname, Item **args, uint nargs, uint flags, int item_sep) { - Item **arg, *safe_args[2]; if (agg_item_collations(coll, fname, args, nargs, flags, item_sep)) return TRUE; diff --git a/sql/item_func.cc b/sql/item_func.cc index ec95254baaa..4322fa058a7 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4837,7 +4837,9 @@ bool Item_func_get_system_var::is_written_to_binlog() void Item_func_get_system_var::fix_length_and_dec() { + char *cptr; maybe_null=0; + max_length= 0; if (var->check_type(var_type)) { @@ -4867,8 +4869,14 @@ void Item_func_get_system_var::fix_length_and_dec() break; case SHOW_CHAR: case SHOW_CHAR_PTR: + pthread_mutex_lock(&LOCK_global_system_variables); + cptr= var->show_type() == SHOW_CHAR_PTR ? + *(char**) var->value_ptr(current_thd, var_type, &component) : + (char*) var->value_ptr(current_thd, var_type, &component); + if (cptr) + max_length= strlen(cptr) * system_charset_info->mbmaxlen; + pthread_mutex_unlock(&LOCK_global_system_variables); collation.set(system_charset_info, DERIVATION_SYSCONST); - max_length= MAX_BLOB_WIDTH; decimals=NOT_FIXED_DEC; break; case SHOW_BOOL: diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index fc9375e68a5..05b9563c121 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -105,13 +105,10 @@ String *Item_func_md5::val_str(String *str) str->set_charset(&my_charset_bin); if (sptr) { - my_MD5_CTX context; uchar digest[16]; null_value=0; - my_MD5Init (&context); - my_MD5Update (&context,(uchar *) sptr->ptr(), sptr->length()); - my_MD5Final (digest, &context); + MY_MD5_HASH(digest,(uchar *) sptr->ptr(), sptr->length()); if (str->alloc(32)) // Ensure that memory is free { null_value=1; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 1821136cc9d..a6d8bb8a52d 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -439,7 +439,8 @@ void Item_sum::make_field(Send_field *tmp_field) void Item_sum::print(String *str, enum_query_type query_type) { - Item **pargs= orig_args; + /* orig_args is not filled with valid values until fix_fields() */ + Item **pargs= fixed ? orig_args : args; str->append(func_name()); for (uint i=0 ; i < arg_count ; i++) { diff --git a/sql/log.cc b/sql/log.cc index 74dc75702ae..44296daa939 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -4650,10 +4650,14 @@ bool flush_error_log() uchar buf[IO_SIZE]; freopen(err_temp,"a+",stderr); + setbuf(stderr, NULL); (void) my_delete(err_renamed, MYF(0)); my_rename(log_error_file,err_renamed,MYF(0)); if (freopen(log_error_file,"a+",stdout)) + { freopen(log_error_file,"a+",stderr); + setbuf(stderr, NULL); + } if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0) { @@ -4669,7 +4673,10 @@ bool flush_error_log() #else my_rename(log_error_file,err_renamed,MYF(0)); if (freopen(log_error_file,"a+",stdout)) + { freopen(log_error_file,"a+",stderr); + setbuf(stderr, NULL); + } else result= 1; #endif diff --git a/sql/log_event.cc b/sql/log_event.cc index 5d959412d36..e6f18a08a0d 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -354,7 +354,7 @@ static char *slave_load_file_stem(char *buf, uint file_id, int event_server_id, const char *ext) { char *res; - fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME); + fn_format(buf,PREFIX_SQL_LOAD,slave_load_tmpdir, "", MY_UNPACK_FILENAME); to_unix_path(buf); buf = strend(buf); @@ -393,7 +393,7 @@ static void cleanup_load_tmpdir() we cannot meet Start_log event in the middle of events from one LOAD DATA. */ - p= strmake(prefbuf, STRING_WITH_LEN("SQL_LOAD-")); + p= strmake(prefbuf, STRING_WITH_LEN(PREFIX_SQL_LOAD)); p= int10_to_str(::server_id, p, 10); *(p++)= '-'; *p= 0; @@ -1258,7 +1258,7 @@ void Log_event::print_header(IO_CACHE* file, my_b_printf(file, "#"); print_timestamp(file); - my_b_printf(file, " server id %d end_log_pos %s ", server_id, + my_b_printf(file, " server id %lu end_log_pos %s ", (ulong) server_id, llstr(log_pos,llbuff)); /* mysqlbinlog --hexdump */ diff --git a/sql/log_event.h b/sql/log_event.h index 1d11d7e2d5f..82fc8d771e1 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -47,6 +47,8 @@ #include "rpl_reporting.h" #endif +#define PREFIX_SQL_LOAD "SQL_LOAD-" + /** Either assert or return an error. diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 3fba9248940..2c938fc96a2 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -2047,6 +2047,9 @@ extern SHOW_COMP_OPTION have_geometry, have_rtree_keys; extern SHOW_COMP_OPTION have_crypt; extern SHOW_COMP_OPTION have_compress; +extern int orig_argc; +extern char **orig_argv; +extern const char *load_default_groups[]; #ifndef __WIN__ extern pthread_t signal_thread; @@ -2411,7 +2414,8 @@ extern "C" void unireg_abort(int exit_code) __attribute__((noreturn)); void kill_delayed_threads(void); bool check_stack_overrun(THD *thd, long margin, uchar *dummy); #else -#define unireg_abort(exit_code) DBUG_RETURN(exit_code) +extern "C" void unireg_clear(int exit_code); +#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0) inline void kill_delayed_threads(void) {} #define check_stack_overrun(A, B, C) 0 #endif diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 973073935a4..7fe498ae147 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -177,39 +177,41 @@ int initgroups(const char *,unsigned int); #ifdef HAVE_FP_EXCEPT // Fix type conflict typedef fp_except fp_except_t; #endif +#endif /* __FreeBSD__ && HAVE_IEEEFP_H */ +#ifdef HAVE_SYS_FPU_H +/* for IRIX to use set_fpc_csr() */ +#include <sys/fpu.h> +#endif -/** - We can't handle floating point exceptions with threads, so disable - this on freebsd. -*/ -inline void set_proper_floating_point_mode() +inline void setup_fpu() { - /* Don't fall for overflow, underflow,divide-by-zero or loss of precision */ +#if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H) + /* We can't handle floating point exceptions with threads, so disable + this on freebsd + Don't fall for overflow, underflow,divide-by-zero or loss of precision + */ #if defined(__i386__) fpsetmask(~(FP_X_INV | FP_X_DNML | FP_X_OFL | FP_X_UFL | FP_X_DZ | FP_X_IMP)); #else - fpsetmask(~(FP_X_INV | FP_X_OFL | FP_X_UFL | FP_X_DZ | - FP_X_IMP)); -#endif -} -#elif defined(__sgi) -/* for IRIX to use set_fpc_csr() */ -#include <sys/fpu.h> + fpsetmask(~(FP_X_INV | FP_X_OFL | FP_X_UFL | FP_X_DZ | + FP_X_IMP)); +#endif /* __i386__ */ +#endif /* __FreeBSD__ && HAVE_IEEEFP_H */ -inline void set_proper_floating_point_mode() -{ +#ifdef HAVE_FESETROUND + /* Set FPU rounding mode to "round-to-nearest" */ + fesetround(FE_TONEAREST); +#endif /* HAVE_FESETROUND */ + +#if defined(__sgi) && defined(HAVE_SYS_FPU_H) /* Enable denormalized DOUBLE values support for IRIX */ - { - union fpc_csr n; - n.fc_word = get_fpc_csr(); - n.fc_struct.flush = 0; - set_fpc_csr(n.fc_word); - } + union fpc_csr n; + n.fc_word = get_fpc_csr(); + n.fc_struct.flush = 0; + set_fpc_csr(n.fc_word); +#endif } -#else -#define set_proper_floating_point_mode() -#endif /* __FreeBSD__ && HAVE_IEEEFP_H */ } /* cplusplus */ @@ -646,6 +648,9 @@ static int defaults_argc; static char **defaults_argv; static char *opt_bin_logname; +int orig_argc; +char **orig_argv; + static my_socket unix_sock,ip_sock; struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD() @@ -742,12 +747,12 @@ uint connection_count= 0; pthread_handler_t signal_hand(void *arg); static int mysql_init_variables(void); -static void get_options(int *argc,char **argv); +static int get_options(int *argc,char **argv); extern "C" my_bool mysqld_get_one_option(int, const struct my_option *, char *); static void set_server_version(void); static int init_thread_environment(); static char *get_relative_path(const char *path); -static void fix_paths(void); +static int fix_paths(void); pthread_handler_t handle_connections_sockets(void *arg); pthread_handler_t kill_server_thread(void *arg); static void bootstrap(FILE *file); @@ -761,7 +766,7 @@ pthread_handler_t handle_connections_shared_memory(void *arg); pthread_handler_t handle_slave(void *arg); static ulong find_bit_type(const char *x, TYPELIB *bit_lib); static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib, - const char *option); + const char *option, int *error); static void clean_up(bool print_message); static int test_if_case_insensitive(const char *dir_name); @@ -1185,7 +1190,8 @@ extern "C" void unireg_abort(int exit_code) my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); exit(exit_code); /* purecov: inspected */ } -#endif + +#endif /*EMBEDDED_LIBRARY*/ void clean_up(bool print_message) @@ -2919,18 +2925,16 @@ pthread_handler_t handle_shutdown(void *arg) } #endif -#if !defined(EMBEDDED_LIBRARY) -static const char *load_default_groups[]= { +const char *load_default_groups[]= { #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE "mysql_cluster", #endif "mysqld","server", MYSQL_BASE_VERSION, 0, 0}; -#if defined(__WIN__) +#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) static const int load_default_groups_sz= sizeof(load_default_groups)/sizeof(load_default_groups[0]); #endif -#endif /*!EMBEDDED_LIBRARY*/ /** @@ -3218,10 +3222,13 @@ static int init_common_variables(const char *conf_file_name, int argc, SQLCOM_END + 8); #endif + orig_argc=argc; + orig_argv=argv; load_defaults(conf_file_name, groups, &argc, &argv); defaults_argv=argv; defaults_argc=argc; - get_options(&defaults_argc, defaults_argv); + if (get_options(&defaults_argc, defaults_argv)) + return 1; set_server_version(); DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, @@ -3671,7 +3678,7 @@ static int init_server_components() query_cache_init(); query_cache_resize(query_cache_size); randominit(&sql_rand,(ulong) server_start_time,(ulong) server_start_time/2); - set_proper_floating_point_mode(); + setup_fpu(); init_thr_lock(); #ifdef HAVE_REPLICATION init_slave_list(); @@ -3699,7 +3706,10 @@ static int init_server_components() #ifndef EMBEDDED_LIBRARY if (freopen(log_error_file, "a+", stdout)) #endif + { freopen(log_error_file, "a+", stderr); + setbuf(stderr, NULL); + } } } @@ -3879,6 +3889,7 @@ server."); if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts, mysqld_get_one_option))) unireg_abort(ho_error); + my_getopt_skip_unknown= TRUE; if (defaults_argc) { @@ -4327,6 +4338,7 @@ we force server id to 2, but this MySQL server will not act as a slave."); { freopen(log_error_file,"a+",stdout); freopen(log_error_file,"a+",stderr); + setbuf(stderr, NULL); FreeConsole(); // Remove window } #endif @@ -6241,7 +6253,7 @@ Can't be set to 1 if --log-slave-updates is used.", GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-id", OPT_SERVER_ID, "Uniquely identifies the server instance in the community of replication partners.", - (uchar**) &server_id, (uchar**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, + (uchar**) &server_id, (uchar**) &server_id, 0, GET_ULONG, REQUIRED_ARG, 0, 0, UINT_MAX32, 0, 0, 0}, {"set-variable", 'O', "Change the value of a variable. Please note that this option is deprecated;you can set variables directly with --variable-name=value.", @@ -7492,6 +7504,7 @@ To see what values a running MySQL server is using, type\n\ static int mysql_init_variables(void) { + int error; /* Things reset to zero */ opt_skip_slave_start= opt_reckless_slave = 0; mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0; @@ -7549,7 +7562,10 @@ static int mysql_init_variables(void) delay_key_write_options= (uint) DELAY_KEY_WRITE_ON; slave_exec_mode_options= 0; slave_exec_mode_options= (uint) - find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL); + find_bit_type_or_exit(slave_exec_mode_str, &slave_exec_mode_typelib, NULL, + &error); + if (error) + return 1; opt_specialflag= SPECIAL_ENGLISH; unix_sock= ip_sock= INVALID_SOCKET; mysql_home_ptr= mysql_home; @@ -7727,6 +7743,8 @@ mysqld_get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { + int error; + switch(optid) { case '#': #ifndef DBUG_OFF @@ -7770,7 +7788,9 @@ mysqld_get_one_option(int optid, break; case OPT_SLAVE_EXEC_MODE: slave_exec_mode_options= (uint) - find_bit_type_or_exit(argument, &slave_exec_mode_typelib, ""); + find_bit_type_or_exit(argument, &slave_exec_mode_typelib, "", &error); + if (error) + return 1; break; #endif case OPT_SAFEMALLOC_MEM_LIMIT: @@ -7838,18 +7858,16 @@ mysqld_get_one_option(int optid, if (!(p= strstr(argument, "->"))) { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - missing '->'!\n"); - exit(1); + sql_print_error("Bad syntax in replicate-rewrite-db - missing '->'!\n"); + return 1; } val= p--; while (my_isspace(mysqld_charset, *p) && p > argument) *p-- = 0; if (p == argument) { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - empty FROM db!\n"); - exit(1); + sql_print_error("Bad syntax in replicate-rewrite-db - empty FROM db!\n"); + return 1; } *val= 0; val+= 2; @@ -7857,9 +7875,8 @@ mysqld_get_one_option(int optid, *val++; if (!*val) { - fprintf(stderr, - "Bad syntax in replicate-rewrite-db - empty TO db!\n"); - exit(1); + sql_print_error("Bad syntax in replicate-rewrite-db - empty TO db!\n"); + return 1; } rpl_filter->add_db_rewrite(key, val); @@ -7887,8 +7904,8 @@ mysqld_get_one_option(int optid, { if (rpl_filter->add_do_table(argument)) { - fprintf(stderr, "Could not add do table rule '%s'!\n", argument); - exit(1); + sql_print_error("Could not add do table rule '%s'!\n", argument); + return 1; } break; } @@ -7896,8 +7913,8 @@ mysqld_get_one_option(int optid, { if (rpl_filter->add_wild_do_table(argument)) { - fprintf(stderr, "Could not add do table rule '%s'!\n", argument); - exit(1); + sql_print_error("Could not add do table rule '%s'!\n", argument); + return 1; } break; } @@ -7905,8 +7922,8 @@ mysqld_get_one_option(int optid, { if (rpl_filter->add_wild_ignore_table(argument)) { - fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); - exit(1); + sql_print_error("Could not add ignore table rule '%s'!\n", argument); + return 1; } break; } @@ -7914,8 +7931,8 @@ mysqld_get_one_option(int optid, { if (rpl_filter->add_ignore_table(argument)) { - fprintf(stderr, "Could not add ignore table rule '%s'!\n", argument); - exit(1); + sql_print_error("Could not add ignore table rule '%s'!\n", argument); + return 1; } break; } @@ -7936,7 +7953,9 @@ mysqld_get_one_option(int optid, { log_output_str= argument; log_output_options= - find_bit_type_or_exit(argument, &log_output_typelib, opt->name); + find_bit_type_or_exit(argument, &log_output_typelib, opt->name, &error); + if (error) + return 1; } break; } @@ -7946,7 +7965,7 @@ mysqld_get_one_option(int optid, sql_perror("Event scheduler is not supported in embedded build."); #else if (Events::set_opt_event_scheduler(argument)) - exit(1); + return 1; #endif break; case (int) OPT_SKIP_NEW: @@ -7985,7 +8004,7 @@ mysqld_get_one_option(int optid, case (int) OPT_SKIP_NETWORKING: #if defined(__NETWARE__) sql_perror("Can't start server: skip-networking option is currently not supported on NetWare"); - exit(1); + return 1; #endif opt_disable_networking=1; mysqld_port=0; @@ -8156,7 +8175,10 @@ mysqld_get_one_option(int optid, { myisam_recover_options_str=argument; myisam_recover_options= - find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name); + find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name, + &error); + if (error) + return 1; } ha_open_options|=HA_OPEN_ABORT_IF_CRASHED; break; @@ -8201,7 +8223,9 @@ mysqld_get_one_option(int optid, { sql_mode_str= argument; global_system_variables.sql_mode= - find_bit_type_or_exit(argument, &sql_mode_typelib, opt->name); + find_bit_type_or_exit(argument, &sql_mode_typelib, opt->name, &error); + if (error) + return 1; global_system_variables.sql_mode= fix_sql_mode(global_system_variables. sql_mode); break; @@ -8240,13 +8264,17 @@ mysqld_get_one_option(int optid, /** Handle arguments for multiple key caches. */ -extern "C" uchar **mysql_getopt_value(const char *keyname, uint key_length, - const struct my_option *option); +extern "C" int mysql_getopt_value(uchar **value, + const char *keyname, uint key_length, + const struct my_option *option, + int *error); -uchar* * +static uchar* * mysql_getopt_value(const char *keyname, uint key_length, - const struct my_option *option) + const struct my_option *option, int *error) { + if (error) + *error= 0; switch (option->id) { case OPT_KEY_BUFFER_SIZE: case OPT_KEY_CACHE_BLOCK_SIZE: @@ -8255,7 +8283,11 @@ mysql_getopt_value(const char *keyname, uint key_length, { KEY_CACHE *key_cache; if (!(key_cache= get_or_create_key_cache(keyname, key_length))) - exit(1); + { + if (error) + *error= EXIT_OUT_OF_MEMORY; + return 0; + } switch (option->id) { case OPT_KEY_BUFFER_SIZE: return (uchar**) &key_cache->param_buff_size; @@ -8293,7 +8325,7 @@ void option_error_reporter(enum loglevel level, const char *format, ...) @todo - FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code? */ -static void get_options(int *argc,char **argv) +static int get_options(int *argc,char **argv) { int ho_error; @@ -8307,7 +8339,7 @@ static void get_options(int *argc,char **argv) if ((ho_error= handle_options(argc, &argv, my_long_options, mysqld_get_one_option))) - exit(ho_error); + return ho_error; (*argc)++; /* add back one for the progname handle_options removes */ /* no need to do this for argv as we are discarding it. */ @@ -8346,7 +8378,8 @@ static void get_options(int *argc,char **argv) max_allowed_packet= global_system_variables.max_allowed_packet; net_buffer_length= global_system_variables.net_buffer_length; #endif - fix_paths(); + if (fix_paths()) + return 1; /* Set some global variables from the global_system_variables @@ -8373,7 +8406,7 @@ static void get_options(int *argc,char **argv) &global_system_variables.time_format) || init_global_datetime_format(MYSQL_TIMESTAMP_DATETIME, &global_system_variables.datetime_format)) - exit(1); + return 1; #ifdef EMBEDDED_LIBRARY one_thread_scheduler(&thread_scheduler); @@ -8386,6 +8419,7 @@ static void get_options(int *argc,char **argv) else pool_of_threads_scheduler(&thread_scheduler); /* purecov: tested */ #endif + return 0; } @@ -8449,7 +8483,7 @@ fn_format_relative_to_data_home(char * to, const char *name, } -static void fix_paths(void) +static int fix_paths(void) { char buff[FN_REFLEN],*pos; convert_dirname(mysql_home,mysql_home,NullS); @@ -8496,12 +8530,12 @@ static void fix_paths(void) charsets_dir=mysql_charsets_dir; if (init_tmpdir(&mysql_tmpdir_list, opt_mysql_tmpdir)) - exit(1); + return 1; #ifdef HAVE_REPLICATION if (!slave_load_tmpdir) { if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE)))) - exit(1); + return 1; } #endif /* HAVE_REPLICATION */ /* @@ -8514,30 +8548,37 @@ static void fix_paths(void) my_free(opt_secure_file_priv, MYF(0)); opt_secure_file_priv= my_strdup(buff, MYF(MY_FAE)); } + return 0; } static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib, - const char *option) + const char *option, int *error) { - ulong res; - + ulong result; const char **ptr; - if ((res= find_bit_type(x, bit_lib)) == ~(ulong) 0) + *error= 0; + if ((result= find_bit_type(x, bit_lib)) == ~(ulong) 0) { + char *buff= (char *) my_alloca(2048); + char *cbuf; ptr= bit_lib->type_names; - if (!*x) - fprintf(stderr, "No option given to %s\n", option); - else - fprintf(stderr, "Wrong option to %s. Option(s) given: %s\n", option, x); - fprintf(stderr, "Alternatives are: '%s'", *ptr); + cbuf= buff + ((!*x) ? + my_snprintf(buff, 2048, "No option given to %s\n", option) : + my_snprintf(buff, 2048, "Wrong option to %s. Option(s) given: %s\n", + option, x)); + cbuf+= my_snprintf(cbuf, 2048 - (cbuf-buff), "Alternatives are: '%s'", *ptr); while (*++ptr) - fprintf(stderr, ",'%s'", *ptr); - fprintf(stderr, "\n"); - exit(1); + cbuf+= my_snprintf(cbuf, 2048 - (cbuf-buff), ",'%s'", *ptr); + my_snprintf(cbuf, 2048 - (cbuf-buff), "\n"); + sql_perror(buff); + *error= 1; + my_afree(buff); + return 0; } - return res; + + return result; } diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 9f8f17eb4ba..31cb829fd93 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9239,32 +9239,37 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) */ KEY *cur_index_info= table->key_info; KEY *cur_index_info_end= cur_index_info + table->s->keys; - KEY_PART_INFO *cur_part= NULL; - KEY_PART_INFO *end_part; /* Last part for loops. */ - /* Last index part. */ - KEY_PART_INFO *last_part= NULL; - KEY_PART_INFO *first_non_group_part= NULL; - KEY_PART_INFO *first_non_infix_part= NULL; - uint key_infix_parts= 0; - uint cur_group_key_parts= 0; - uint cur_group_prefix_len= 0; /* Cost-related variables for the best index so far. */ double best_read_cost= DBL_MAX; ha_rows best_records= 0; SEL_ARG *best_index_tree= NULL; ha_rows best_quick_prefix_records= 0; uint best_param_idx= 0; - double cur_read_cost= DBL_MAX; - ha_rows cur_records; + + const uint pk= param->table->s->primary_key; SEL_ARG *cur_index_tree= NULL; ha_rows cur_quick_prefix_records= 0; uint cur_param_idx=MAX_KEY; - key_map cur_used_key_parts; - uint pk= param->table->s->primary_key; for (uint cur_index= 0 ; cur_index_info != cur_index_info_end ; cur_index_info++, cur_index++) { + KEY_PART_INFO *cur_part; + KEY_PART_INFO *end_part; /* Last part for loops. */ + /* Last index part. */ + KEY_PART_INFO *last_part; + KEY_PART_INFO *first_non_group_part; + KEY_PART_INFO *first_non_infix_part; + uint key_infix_parts; + uint cur_group_key_parts= 0; + uint cur_group_prefix_len= 0; + double cur_read_cost; + ha_rows cur_records; + key_map used_key_parts_map; + uint cur_key_infix_len= 0; + uchar cur_key_infix[MAX_KEY_LENGTH]; + uint cur_used_key_parts; + /* Check (B1) - if current index is covering. */ if (!table->covering_keys.is_set(cur_index)) goto next_index; @@ -9334,7 +9339,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) else if (join->select_distinct) { select_items_it.rewind(); - cur_used_key_parts.clear_all(); + used_key_parts_map.clear_all(); uint max_key_part= 0; while ((item= select_items_it++)) { @@ -9345,13 +9350,13 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) Check if this attribute was already present in the select list. If it was present, then its corresponding key part was alredy used. */ - if (cur_used_key_parts.is_set(key_part_nr)) + if (used_key_parts_map.is_set(key_part_nr)) continue; if (key_part_nr < 1 || key_part_nr > join->fields_list.elements) goto next_index; cur_part= cur_index_info->key_part + key_part_nr - 1; cur_group_prefix_len+= cur_part->store_length; - cur_used_key_parts.set_bit(key_part_nr); + used_key_parts_map.set_bit(key_part_nr); ++cur_group_key_parts; max_key_part= max(max_key_part,key_part_nr); } @@ -9363,7 +9368,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) */ ulonglong all_parts, cur_parts; all_parts= (1<<max_key_part) - 1; - cur_parts= cur_used_key_parts.to_ulonglong() >> 1; + cur_parts= used_key_parts_map.to_ulonglong() >> 1; if (all_parts != cur_parts) goto next_index; } @@ -9413,7 +9418,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) &dummy); if (!get_constant_key_infix(cur_index_info, index_range_tree, first_non_group_part, min_max_arg_part, - last_part, thd, key_infix, &key_infix_len, + last_part, thd, cur_key_infix, + &cur_key_infix_len, &first_non_infix_part)) goto next_index; } @@ -9467,9 +9473,9 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) } /* If we got to this point, cur_index_info passes the test. */ - key_infix_parts= key_infix_len ? + key_infix_parts= cur_key_infix_len ? (first_non_infix_part - first_non_group_part) : 0; - used_key_parts= cur_group_key_parts + key_infix_parts; + cur_used_key_parts= cur_group_key_parts + key_infix_parts; /* Compute the cost of using this index. */ if (tree) @@ -9481,7 +9487,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) cur_quick_prefix_records= check_quick_select(param, cur_param_idx, cur_index_tree, TRUE); } - cost_group_min_max(table, cur_index_info, used_key_parts, + cost_group_min_max(table, cur_index_info, cur_used_key_parts, cur_group_key_parts, tree, cur_index_tree, cur_quick_prefix_records, have_min, have_max, &cur_read_cost, &cur_records); @@ -9492,7 +9498,6 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) */ if (cur_read_cost < best_read_cost - (DBL_EPSILON * cur_read_cost)) { - DBUG_ASSERT(tree != 0 || cur_param_idx == MAX_KEY); index_info= cur_index_info; index= cur_index; best_read_cost= cur_read_cost; @@ -9502,11 +9507,13 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) best_param_idx= cur_param_idx; group_key_parts= cur_group_key_parts; group_prefix_len= cur_group_prefix_len; + key_infix_len= cur_key_infix_len; + if (key_infix_len) + memcpy (key_infix, cur_key_infix, sizeof (key_infix)); + used_key_parts= cur_used_key_parts; } - next_index: - cur_group_key_parts= 0; - cur_group_prefix_len= 0; + next_index:; } if (!index_info) /* No usable index found. */ DBUG_RETURN(NULL); diff --git a/sql/protocol.cc b/sql/protocol.cc index 4177cd0054d..16975c68a54 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -573,7 +573,8 @@ bool Protocol::send_fields(List<Item> *list, uint flags) else { /* With conversion */ - uint max_char_len; + ulonglong max_length; + uint32 field_length; int2store(pos, thd_charset->number); /* For TEXT/BLOB columns, field_length describes the maximum data @@ -584,12 +585,22 @@ bool Protocol::send_fields(List<Item> *list, uint flags) char_count * mbmaxlen, where character count is taken from the definition of the column. In other words, the maximum number of characters here is limited by the column definition. + + When one has a LONG TEXT column with a single-byte + character set, and the connection character set is multi-byte, the + client may get fields longer than UINT_MAX32, due to + <character set column> -> <character set connection> conversion. + In that case column max length does not fit into the 4 bytes + reserved for it in the protocol. */ - max_char_len= (field.type >= (int) MYSQL_TYPE_TINY_BLOB && - field.type <= (int) MYSQL_TYPE_BLOB) ? - field.length / item->collation.collation->mbminlen : - field.length / item->collation.collation->mbmaxlen; - int4store(pos+2, max_char_len * thd_charset->mbmaxlen); + max_length= (field.type >= MYSQL_TYPE_TINY_BLOB && + field.type <= MYSQL_TYPE_BLOB) ? + field.length / item->collation.collation->mbminlen : + field.length / item->collation.collation->mbmaxlen; + max_length*= thd_charset->mbmaxlen; + field_length= (max_length > UINT_MAX32) ? + UINT_MAX32 : (uint32) max_length; + int4store(pos + 2, field_length); } pos[6]= field.type; int2store(pos+7,field.flags); diff --git a/sql/rpl_record.cc b/sql/rpl_record.cc index 7c74dcba5a0..14a80cbb4b6 100644 --- a/sql/rpl_record.cc +++ b/sql/rpl_record.cc @@ -297,21 +297,16 @@ unpack_row(Relay_log_info const *rli, /** Fills @c table->record[0] with default values. - First @c empty_record() is called and then, additionally, fields are - initialized explicitly with a call to @c set_default(). - - For optimization reasons, the explicit initialization can be skipped for - first @c skip fields. This is useful if later we are going to fill these - fields from other source (e.g. from a Rows replication event). - - If @c check is true, fields are explicitly initialized only if they have - default value or can be NULL. Otherwise error is reported. + First @c restore_record() is called to restore the default values for + record concerning the given table. Then, if @c check is true, + a check is performed to see if fields are have default value or can + be NULL. Otherwise error is reported. @param table Table whose record[0] buffer is prepared. - @param skip Number of columns for which default value initialization + @param skip Number of columns for which default/nullable check should be skipped. - @param check Indicates if errors should be checked when setting default - values. + @param check Indicates if errors should be raised when checking + default/nullable field properties. @returns 0 on success or a handler level error code */ @@ -321,25 +316,28 @@ int prepare_record(TABLE *const table, DBUG_ENTER("prepare_record"); int error= 0; - empty_record(table); + restore_record(table, s->default_values); - if (skip >= table->s->fields) // nothing to do + /* + This skip should be revisited in 6.0, because in 6.0 RBR one + can have holes in the row (as the grain of the writeset is + the column and not the entire row). + */ + if (skip >= table->s->fields || !check) DBUG_RETURN(0); - /* Explicit initialization of fields */ + /* Checking if exists default/nullable fields in the default values. */ for (Field **field_ptr= table->field+skip ; *field_ptr ; ++field_ptr) { uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG; Field *const f= *field_ptr; - if (check && ((f->flags & mask) == mask)) + if (((f->flags & mask) == mask)) { my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), f->field_name); error = HA_ERR_ROWS_EVENT_APPLY; } - else - f->set_default(); } DBUG_RETURN(error); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 3a0f784d195..e93417374fe 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -104,6 +104,11 @@ int init_relay_log_info(Relay_log_info* rli, rli->tables_to_lock= 0; rli->tables_to_lock_count= 0; + fn_format(rli->slave_patternload_file, PREFIX_SQL_LOAD, slave_load_tmpdir, "", + MY_PACK_FILENAME | MY_UNPACK_FILENAME | + MY_RETURN_REAL_PATH); + rli->slave_patternload_file_size= strlen(rli->slave_patternload_file); + /* The relay log will now be opened, as a SEQ_READ_APPEND IO_CACHE. Note that the I/O thread flushes it to disk after writing every diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index e13ea93842c..171778d9675 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -260,6 +260,13 @@ public: char ign_master_log_name_end[FN_REFLEN]; ulonglong ign_master_log_pos_end; + /* + Indentifies where the SQL Thread should create temporary files for the + LOAD DATA INFILE. This is used for security reasons. + */ + char slave_patternload_file[FN_REFLEN]; + size_t slave_patternload_file_size; + Relay_log_info(); ~Relay_log_info(); diff --git a/sql/set_var.cc b/sql/set_var.cc index 7e2efd2d580..84e628fbddf 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -110,6 +110,7 @@ static void sys_default_init_connect(THD*, enum_var_type type); static bool sys_update_init_slave(THD*, set_var*); static void sys_default_init_slave(THD*, enum_var_type type); static bool set_option_bit(THD *thd, set_var *var); +static bool set_option_log_bin_bit(THD *thd, set_var *var); static bool set_option_autocommit(THD *thd, set_var *var); static int check_log_update(THD *thd, set_var *var); static bool set_log_update(THD *thd, set_var *var); @@ -134,8 +135,6 @@ static int check_max_delayed_threads(THD *thd, set_var *var); static void fix_thd_mem_root(THD *thd, enum_var_type type); static void fix_trans_mem_root(THD *thd, enum_var_type type); static void fix_server_id(THD *thd, enum_var_type type); -static ulonglong fix_unsigned(THD *, ulonglong, const struct my_option *); -static bool get_unsigned(THD *thd, set_var *var); bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, const char *name, longlong val); static KEY_CACHE *create_key_cache(const char *name, uint length); @@ -731,7 +730,7 @@ static sys_var_thd_bit sys_log_update(&vars, "sql_log_update", OPTION_BIN_LOG); static sys_var_thd_bit sys_log_binlog(&vars, "sql_log_bin", check_log_update, - set_option_bit, + set_option_log_bin_bit, OPTION_BIN_LOG); static sys_var_thd_bit sys_sql_warnings(&vars, "sql_warnings", 0, set_option_bit, @@ -1370,6 +1369,19 @@ static void fix_server_id(THD *thd, enum_var_type type) } +/** + Throw warning (error in STRICT mode) if value for variable needed bounding. + Only call from check(), not update(), because an error in update() would be + bad mojo. Plug-in interface also uses this. + + @param thd thread handle + @param fixed did we have to correct the value? (throw warn/err if so) + @param unsignd is value's type unsigned? + @param name variable's name + @param val variable's value + + @retval TRUE on error, FALSE otherwise (warning or OK) + */ bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, const char *name, longlong val) { @@ -1395,26 +1407,128 @@ bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, return FALSE; } -static ulonglong fix_unsigned(THD *thd, ulonglong num, + +/** + check an unsigned user-supplied value for a systemvariable against bounds. + + TODO: This is a wrapper function to call clipping from within an update() + function. Calling bounds from within update() is fair game in theory, + but we can only send warnings from in there, not errors, and besides, + it violates our model of separating check from update phase. + To avoid breaking out of the server with an ASSERT() in strict mode, + we pretend we're not in strict mode when we go through here. Bug#43233 + was opened to remind us to replace this kludge with The Right Thing, + which of course is to do the check in the actual check phase, and then + throw an error or warning accordingly. + + @param thd thread handle + @param num the value to limit + @param option_limits the bounds-record, or NULL if none + */ +static void bound_unsigned(THD *thd, ulonglong *num, const struct my_option *option_limits) { - my_bool fixed= FALSE; - ulonglong out= getopt_ull_limit_value(num, option_limits, &fixed); + if (option_limits) + { + my_bool fixed = FALSE; + ulonglong unadjusted= *num; + + *num= getopt_ull_limit_value(unadjusted, option_limits, &fixed); - throw_bounds_warning(thd, fixed, TRUE, option_limits->name, (longlong) num); - return out; + if (fixed) + { + ulong ssm= thd->variables.sql_mode; + thd->variables.sql_mode&= ~MODE_STRICT_ALL_TABLES; + throw_bounds_warning(thd, fixed, TRUE, option_limits->name, unadjusted); + thd->variables.sql_mode= ssm; + } + } } -static bool get_unsigned(THD *thd, set_var *var) -{ + +/** + Get unsigned system-variable. + Negative value does not wrap around, but becomes zero. + Check user-supplied value for a systemvariable against bounds. + If we needed to adjust the value, throw a warning or error depending + on SQL-mode. + + @param thd thread handle + @param var the system-variable to get + @param user_max a limit given with --maximum-variable-name=... or 0 + @param var_type function will bound on systems where necessary. + + @retval TRUE on error, FALSE otherwise (warning or OK) + */ +static bool get_unsigned(THD *thd, set_var *var, ulonglong user_max, + ulong var_type) +{ + int warnings= 0; + ulonglong unadjusted; + const struct my_option *limits= var->var->option_limits; + struct my_option fallback; + + /* get_unsigned() */ if (var->value->unsigned_flag) var->save_result.ulonglong_value= (ulonglong) var->value->val_int(); else { longlong v= var->value->val_int(); var->save_result.ulonglong_value= (ulonglong) ((v < 0) ? 0 : v); + if (v < 0) + { + warnings++; + if (throw_bounds_warning(thd, TRUE, FALSE, var->var->name, v)) + return TRUE; /* warning was promoted to error, give up */ + } } - return 0; + + unadjusted= var->save_result.ulonglong_value; + + /* max, if any */ + + if ((user_max > 0) && (unadjusted > user_max)) + { + var->save_result.ulonglong_value= user_max; + + if ((warnings == 0) && throw_bounds_warning(thd, TRUE, TRUE, + var->var->name, + (longlong) unadjusted)) + return TRUE; + + warnings++; + } + + /* + if the sysvar doesn't have a proper bounds record but the check + function would like bounding to ULONG where its size differs from + that of ULONGLONG, we make up a bogus limits record here and let + the usual suspects handle the actual limiting. + */ + + if (!limits && var_type != GET_ULL) + { + bzero(&fallback, sizeof(fallback)); + fallback.var_type= var_type; + limits= &fallback; + } + + /* fix_unsigned() */ + if (limits) + { + my_bool fixed; + + var->save_result.ulonglong_value= getopt_ull_limit_value(var->save_result. + ulonglong_value, + limits, &fixed); + + if ((warnings == 0) && throw_bounds_warning(thd, fixed, TRUE, + var->var->name, + (longlong) unadjusted)) + return TRUE; + } + + return FALSE; } @@ -1428,29 +1542,13 @@ sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_ar bool sys_var_long_ptr_global::check(THD *thd, set_var *var) { - return get_unsigned(thd, var); + return get_unsigned(thd, var, 0, GET_ULONG); } bool sys_var_long_ptr_global::update(THD *thd, set_var *var) { - ulonglong tmp= var->save_result.ulonglong_value; pthread_mutex_lock(guard); - if (option_limits) - *value= (ulong) fix_unsigned(thd, tmp, option_limits); - else - { -#if SIZEOF_LONG < SIZEOF_LONG_LONG - /* Avoid overflows on 32 bit systems */ - if (tmp > ULONG_MAX) - { - tmp= ULONG_MAX; - throw_bounds_warning(thd, TRUE, TRUE, name, - (longlong) var->save_result.ulonglong_value); - } -#endif - *value= (ulong) tmp; - } - + *value= (ulong) var->save_result.ulonglong_value; pthread_mutex_unlock(guard); return 0; } @@ -1470,10 +1568,8 @@ bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var) { ulonglong tmp= var->save_result.ulonglong_value; pthread_mutex_lock(&LOCK_global_system_variables); - if (option_limits) - *value= (ulonglong) fix_unsigned(thd, tmp, option_limits); - else - *value= (ulonglong) tmp; + bound_unsigned(thd, &tmp, option_limits); + *value= (ulonglong) tmp; pthread_mutex_unlock(&LOCK_global_system_variables); return 0; } @@ -1523,36 +1619,18 @@ uchar *sys_var_enum_const::value_ptr(THD *thd, enum_var_type type, bool sys_var_thd_ulong::check(THD *thd, set_var *var) { - return (get_unsigned(thd, var) || - (check_func && (*check_func)(thd, var))); + if (get_unsigned(thd, var, max_system_variables.*offset, GET_ULONG)) + return TRUE; + DBUG_ASSERT(var->save_result.ulonglong_value <= ULONG_MAX); + return ((check_func && (*check_func)(thd, var))); } bool sys_var_thd_ulong::update(THD *thd, set_var *var) { - ulonglong tmp= var->save_result.ulonglong_value; - - /* Don't use bigger value than given with --maximum-variable-name=.. */ - if (tmp > max_system_variables.*offset) - { - throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) tmp); - tmp= max_system_variables.*offset; - } - - if (option_limits) - tmp= fix_unsigned(thd, tmp, option_limits); -#if SIZEOF_LONG < SIZEOF_LONG_LONG - else if (tmp > ULONG_MAX) - { - tmp= ULONG_MAX; - throw_bounds_warning(thd, TRUE, TRUE, name, (longlong) var->save_result.ulonglong_value); - } -#endif - - DBUG_ASSERT(tmp <= ULONG_MAX); if (var->type == OPT_GLOBAL) - global_system_variables.*offset= (ulong) tmp; + global_system_variables.*offset= (ulong) var->save_result.ulonglong_value; else - thd->variables.*offset= (ulong) tmp; + thd->variables.*offset= (ulong) var->save_result.ulonglong_value; return 0; } @@ -1590,8 +1668,8 @@ bool sys_var_thd_ha_rows::update(THD *thd, set_var *var) if ((ha_rows) tmp > max_system_variables.*offset) tmp= max_system_variables.*offset; - if (option_limits) - tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits); + bound_unsigned(thd, &tmp, option_limits); + if (var->type == OPT_GLOBAL) { /* Lock is needed to make things safe on 32 bit systems */ @@ -1632,27 +1710,21 @@ uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type, bool sys_var_thd_ulonglong::check(THD *thd, set_var *var) { - return get_unsigned(thd, var); + return get_unsigned(thd, var, max_system_variables.*offset, GET_ULL); } bool sys_var_thd_ulonglong::update(THD *thd, set_var *var) { - ulonglong tmp= var->save_result.ulonglong_value; - - if (tmp > max_system_variables.*offset) - tmp= max_system_variables.*offset; - - if (option_limits) - tmp= fix_unsigned(thd, tmp, option_limits); if (var->type == OPT_GLOBAL) { /* Lock is needed to make things safe on 32 bit systems */ pthread_mutex_lock(&LOCK_global_system_variables); - global_system_variables.*offset= (ulonglong) tmp; + global_system_variables.*offset= (ulonglong) + var->save_result.ulonglong_value; pthread_mutex_unlock(&LOCK_global_system_variables); } else - thd->variables.*offset= (ulonglong) tmp; + thd->variables.*offset= (ulonglong) var->save_result.ulonglong_value; return 0; } @@ -2284,10 +2356,10 @@ bool sys_var_key_buffer_size::update(THD *thd, set_var *var) goto end; } - key_cache->param_buff_size= - (ulonglong) fix_unsigned(thd, tmp, option_limits); + bound_unsigned(thd, &tmp, option_limits); + key_cache->param_buff_size= (ulonglong) tmp; - /* If key cache didn't existed initialize it, else resize it */ + /* If key cache didn't exist initialize it, else resize it */ key_cache->in_init= 1; pthread_mutex_unlock(&LOCK_global_system_variables); @@ -2313,7 +2385,7 @@ end: */ bool sys_var_key_cache_long::update(THD *thd, set_var *var) { - ulong tmp= (ulong) var->value->val_int(); + ulonglong tmp= var->value->val_int(); LEX_STRING *base_name= &var->base; bool error= 0; @@ -2338,8 +2410,8 @@ bool sys_var_key_cache_long::update(THD *thd, set_var *var) if (key_cache->in_init) goto end; - *((ulong*) (((char*) key_cache) + offset))= - (ulong) fix_unsigned(thd, tmp, option_limits); + bound_unsigned(thd, &tmp, option_limits); + *((ulong*) (((char*) key_cache) + offset))= (ulong) tmp; /* Don't create a new key cache if it didn't exist @@ -2963,6 +3035,16 @@ static bool set_option_bit(THD *thd, set_var *var) return 0; } +/* + Functions to be only used to update thd->options OPTION_BIN_LOG bit +*/ +static bool set_option_log_bin_bit(THD *thd, set_var *var) +{ + set_option_bit(thd, var); + if (!thd->in_sub_stmt) + thd->sql_log_bin_toplevel= thd->options & OPTION_BIN_LOG; + return 0; +} static bool set_option_autocommit(THD *thd, set_var *var) { diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index befd064e3e3..aa1521acab6 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5775,9 +5775,9 @@ ER_PARTITION_MGMT_ON_NONPARTITIONED ger "Partitionsverwaltung einer nicht partitionierten Tabelle ist nicht möglich" swe "Partitioneringskommando på en opartitionerad tabell är inte möjligt" ER_FOREIGN_KEY_ON_PARTITIONED - eng "Foreign key condition is not yet supported in conjunction with partitioning" + eng "Foreign key clause is not yet supported in conjunction with partitioning" ger "Fremdschlüssel-Beschränkungen sind im Zusammenhang mit Partitionierung nicht zulässig" - swe "Foreign key villkor är inte ännu implementerad i kombination med partitionering" + swe "Foreign key klausul är inte ännu implementerad i kombination med partitionering" ER_DROP_PARTITION_NON_EXISTENT eng "Error in list of partitions to %-.64s" ger "Fehler in der Partitionsliste bei %-.64s" @@ -5791,13 +5791,13 @@ ER_COALESCE_ONLY_ON_HASH_PARTITION ger "COALESCE PARTITION kann nur auf HASH- oder KEY-Partitionen benutzt werden" swe "COALESCE PARTITION kan bara användas på HASH/KEY partitioner" ER_REORG_HASH_ONLY_ON_SAME_NO - eng "REORGANISE PARTITION can only be used to reorganise partitions not to change their numbers" + eng "REORGANIZE PARTITION can only be used to reorganize partitions not to change their numbers" ger "REORGANIZE PARTITION kann nur zur Reorganisation von Partitionen verwendet werden, nicht, um ihre Nummern zu ändern" - swe "REORGANISE PARTITION kan bara användas för att omorganisera partitioner, inte för att ändra deras antal" + swe "REORGANIZE PARTITION kan bara användas för att omorganisera partitioner, inte för att ändra deras antal" ER_REORG_NO_PARAM_ERROR - eng "REORGANISE PARTITION without parameters can only be used on auto-partitioned tables using HASH PARTITIONs" + eng "REORGANIZE PARTITION without parameters can only be used on auto-partitioned tables using HASH PARTITIONs" ger "REORGANIZE PARTITION ohne Parameter kann nur für auto-partitionierte Tabellen verwendet werden, die HASH-Partitionierung benutzen" - swe "REORGANISE PARTITION utan parametrar kan bara användas på auto-partitionerade tabeller som använder HASH partitionering" + swe "REORGANIZE PARTITION utan parametrar kan bara användas på auto-partitionerade tabeller som använder HASH partitionering" ER_ONLY_ON_RANGE_LIST_PARTITION eng "%-.64s PARTITION can only be used on RANGE/LIST partitions" ger "%-.64s PARTITION kann nur für RANGE- oder LIST-Partitionen verwendet werden" @@ -5815,7 +5815,7 @@ ER_COALESCE_PARTITION_NO_PARTITION ger "Zumindest eine Partition muss mit COALESCE PARTITION zusammengefügt werden" swe "Åtminstone en partition måste slås ihop vid COALESCE PARTITION" ER_REORG_PARTITION_NOT_EXIST - eng "More partitions to reorganise than there are partitions" + eng "More partitions to reorganize than there are partitions" ger "Es wurde versucht, mehr Partitionen als vorhanden zu reorganisieren" swe "Fler partitioner att reorganisera än det finns partitioner" ER_SAME_NAME_PARTITION @@ -5827,7 +5827,7 @@ ER_NO_BINLOG_ERROR ger "Es es nicht erlaubt, bei diesem Befehl binlog abzuschalten" swe "Det är inte tillåtet att stänga av binlog på detta kommando" ER_CONSECUTIVE_REORG_PARTITIONS - eng "When reorganising a set of partitions they must be in consecutive order" + eng "When reorganizing a set of partitions they must be in consecutive order" ger "Bei der Reorganisation eines Satzes von Partitionen müssen diese in geordneter Reihenfolge vorliegen" swe "När ett antal partitioner omorganiseras måste de vara i konsekutiv ordning" ER_REORG_OUTSIDE_RANGE @@ -6154,3 +6154,26 @@ WARN_PLUGIN_BUSY ER_VARIABLE_IS_READONLY eng "%s variable '%s' is read-only. Use SET %s to assign the value" + +ER_WARN_ENGINE_TRANSACTION_ROLLBACK + eng "Storage engine %s does not support rollback for this statement. Transaction rolled back and must be restarted" + +ER_SLAVE_HEARTBEAT_FAILURE + eng "Unexpected master's heartbeat data: %s" +ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE + eng "The requested value for the heartbeat period %s %s" + +ER_NDB_REPLICATION_SCHEMA_ERROR + eng "Bad schema for mysql.ndb_replication table. Message: %-.64s" +ER_CONFLICT_FN_PARSE_ERROR + eng "Error in parsing conflict function. Message: %-.64s" +ER_EXCEPTIONS_WRITE_ERROR + eng "Write to exceptions table failed. Message: %-.128s"" + +ER_TOO_LONG_TABLE_COMMENT + eng "Comment for table '%-.64s' is too long (max = %lu)" + por "Comentário para a tabela '%-.64s' é longo demais (max = %lu)" + +ER_TOO_LONG_FIELD_COMMENT + eng "Comment for field '%-.64s' is too long (max = %lu)" + por "Comentário para o campo '%-.64s' é longo demais (max = %lu)" diff --git a/sql/sp.cc b/sql/sp.cc index cc545992857..b2c7c389136 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -936,10 +936,12 @@ sp_create_routine(THD *thd, int type, sp_head *sp) ret= SP_INTERNAL_ERROR; goto done; } - + /* restore sql_mode when binloging */ + thd->variables.sql_mode= saved_mode; /* Such a statement can always go directly to binlog, no trans cache */ thd->binlog_query(THD::MYSQL_QUERY_TYPE, log_query.c_ptr(), log_query.length(), FALSE, FALSE); + thd->variables.sql_mode= 0; } } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d17bf085e3b..0db371a666d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1440,7 +1440,8 @@ void close_temporary_tables(THD *thd) if (!thd->temporary_tables) return; - if (!mysql_bin_log.is_open() || thd->current_stmt_binlog_row_based) + if (!mysql_bin_log.is_open() || + (thd->current_stmt_binlog_row_based && thd->variables.binlog_format == BINLOG_FORMAT_ROW)) { TABLE *tmp_next; for (table= thd->temporary_tables; table; table= tmp_next) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 4a5b75c4f78..25907d4ec20 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -418,6 +418,43 @@ TYPELIB query_cache_type_typelib= array_elements(query_cache_type_names)-1,"", query_cache_type_names, NULL }; + +/** + Helper function for determine if a SELECT statement has a SQL_NO_CACHE + directive. + + @param sql A pointer to the first white space character after SELECT + + @return + @retval TRUE The character string contains SQL_NO_CACHE + @retval FALSE No directive found. +*/ + +static bool has_no_cache_directive(char *sql) +{ + int i=0; + while (sql[i] == ' ') + ++i; + + if (my_toupper(system_charset_info, sql[i]) == 'S' && + my_toupper(system_charset_info, sql[i+1]) == 'Q' && + my_toupper(system_charset_info, sql[i+2]) == 'L' && + my_toupper(system_charset_info, sql[i+3]) == '_' && + my_toupper(system_charset_info, sql[i+4]) == 'N' && + my_toupper(system_charset_info, sql[i+5]) == 'O' && + my_toupper(system_charset_info, sql[i+6]) == '_' && + my_toupper(system_charset_info, sql[i+7]) == 'C' && + my_toupper(system_charset_info, sql[i+8]) == 'A' && + my_toupper(system_charset_info, sql[i+9]) == 'C' && + my_toupper(system_charset_info, sql[i+10]) == 'H' && + my_toupper(system_charset_info, sql[i+11]) == 'E' && + my_toupper(system_charset_info, sql[i+12]) == ' ') + return TRUE; + + return FALSE; +} + + /***************************************************************************** Query_cache_block_table method(s) *****************************************************************************/ @@ -1233,6 +1270,16 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached")); goto err; } + + if (query_length > 20 && has_no_cache_directive(&sql[i+6])) + { + /* + We do not increase 'refused' statistics here since it will be done + later when the query is parsed. + */ + DBUG_PRINT("qcache", ("The statement has a SQL_NO_CACHE directive")); + goto err; + } } STRUCT_LOCK(&structure_guard_mutex); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 597478933d6..cd00d0e20f1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -538,6 +538,7 @@ THD::THD() Open_tables_state(refresh_version), rli_fake(0), lock_id(&main_lock_id), user_time(0), in_sub_stmt(0), + sql_log_bin_toplevel(false), binlog_table_maps(0), binlog_flags(0UL), table_map_for_update(0), arg_of_last_insert_id_function(FALSE), @@ -787,6 +788,7 @@ void THD::init(void) update_charset(); reset_current_stmt_binlog_row_based(); bzero((char *) &status_var, sizeof(status_var)); + sql_log_bin_toplevel= options & OPTION_BIN_LOG; } @@ -3662,7 +3664,7 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, If we are in statement mode and trying to log an unsafe statement, we should print a warning. */ - if (lex->is_stmt_unsafe() && + if (sql_log_bin_toplevel && lex->is_stmt_unsafe() && variables.binlog_format == BINLOG_FORMAT_STMT) { push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN, diff --git a/sql/sql_class.h b/sql/sql_class.h index 3439e5b4f74..0a33d2767f5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1350,6 +1350,8 @@ public: /* <> 0 if we are inside of trigger or stored function. */ uint in_sub_stmt; + /* TRUE when the current top has SQL_LOG_BIN ON */ + bool sql_log_bin_toplevel; /* container for handler's private per-connection data */ Ha_data ha_data[MAX_HA]; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 28a9fb5c78e..9c8bba6208c 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -160,6 +160,9 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables, table->query_id= thd->query_id; table->open_by_handler= 0; } + + /* Mark table as closed, ready for re-open if necessary. */ + tables->table= NULL; } /* @@ -177,8 +180,7 @@ static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables, 'reopen' is set when a handler table is to be re-opened. In this case, 'tables' is the pointer to the hashed TABLE_LIST object which has been saved on the original open. - 'reopen' is also used to suppress the sending of an 'ok' message or - error messages. + 'reopen' is also used to suppress the sending of an 'ok' message. RETURN FALSE OK @@ -214,8 +216,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) strlen(tables->alias) + 1)) { DBUG_PRINT("info",("duplicate '%s'", tables->alias)); - if (! reopen) - my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias); + my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias); goto err; } } @@ -259,8 +260,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) /* There can be only one table in '*tables'. */ if (! (tables->table->file->ha_table_flags() & HA_CAN_SQL_HANDLER)) { - if (! reopen) - my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); + my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); goto err; } @@ -479,8 +479,7 @@ retry: if (need_reopen) { - mysql_ha_close_table(thd, tables, FALSE); - hash_tables->table= NULL; + mysql_ha_close_table(thd, hash_tables, FALSE); /* The lock might have been aborted, we need to manually reset thd->some_tables_deleted because handler's tables are closed @@ -761,11 +760,7 @@ void mysql_ha_flush(THD *thd) { hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i); if (hash_tables->table && hash_tables->table->needs_reopen_or_name_lock()) - { mysql_ha_close_table(thd, hash_tables, TRUE); - /* Mark table as closed, ready for re-open. */ - hash_tables->table= NULL; - } } DBUG_VOID_RETURN; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9619d26893c..19a19f2b6fb 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1559,6 +1559,7 @@ void st_select_lex::init_query() exclude_from_table_unique_test= no_wrap_view_item= FALSE; nest_level= 0; link_next= 0; + lock_option= TL_READ_DEFAULT; } void st_select_lex::init_select() diff --git a/sql/sql_lex.h b/sql/sql_lex.h index ed6b9e7d8df..a48b99d07c7 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -688,6 +688,15 @@ public: int cur_pos_in_select_list; List<udf_func> udf_list; /* udf function calls stack */ + + /** + Per sub-query locking strategy. + Note: This variable might interfer with the corresponding statement-level + variable Lex::lock_option because on how different parser rules depend + on eachother. + */ + thr_lock_type lock_option; + /* This is a copy of the original JOIN USING list that comes from the parser. The parser : diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 239fb1d49f3..0acc22c3daf 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -15,10 +15,10 @@ /* Copy data from a textfile to table */ - #include "mysql_priv.h" #include <my_dir.h> #include <m_ctype.h> +#include "rpl_mi.h" #include "sql_repl.h" #include "sp_head.h" #include "sql_trigger.h" @@ -310,8 +310,31 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, is_fifo = 1; #endif - if (opt_secure_file_priv && - strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv))) + if (thd->slave_thread) + { +#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) + if (strncmp(active_mi->rli.slave_patternload_file, name, + active_mi->rli.slave_patternload_file_size)) + { + /* + LOAD DATA INFILE in the slave SQL Thread can only read from + --slave-load-tmpdir". This should never happen. Please, report a bug. + */ + + sql_print_error("LOAD DATA INFILE in the slave SQL Thread can only read from --slave-load-tmpdir. " \ + "Please, report a bug."); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--slave-load-tmpdir"); + DBUG_RETURN(TRUE); + } +#else + /* + This is impossible and should never happen. + */ + DBUG_ASSERT(FALSE); +#endif + } + else if (opt_secure_file_priv && + strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv))) { /* Read only allowed from within dir specified by secure_file_priv */ my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv"); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f7d6d5bac4d..94725b1b53f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4129,9 +4129,32 @@ end_with_restore_list: res= (sp_result= lex->sphead->create(thd)); switch (sp_result) { - case SP_OK: + case SP_OK: { #ifndef NO_EMBEDDED_ACCESS_CHECKS /* only add privileges if really neccessary */ + + Security_context security_context; + bool restore_backup_context= false; + Security_context *backup= NULL; + LEX_USER *definer= thd->lex->definer; + /* + Check if the definer exists on slave, + then use definer privilege to insert routine privileges to mysql.procs_priv. + + For current user of SQL thread has GLOBAL_ACL privilege, + which doesn't any check routine privileges, + so no routine privilege record will insert into mysql.procs_priv. + */ + if (thd->slave_thread && is_acl_user(definer->host.str, definer->user.str)) + { + security_context.change_security_context(thd, + &thd->lex->definer->user, + &thd->lex->definer->host, + &thd->lex->sphead->m_db, + &backup); + restore_backup_context= true; + } + if (sp_automatic_privileges && !opt_noacl && check_routine_access(thd, DEFAULT_CREATE_PROC_ACLS, lex->sphead->m_db.str, name, @@ -4143,8 +4166,19 @@ end_with_restore_list: ER_PROC_AUTO_GRANT_FAIL, ER(ER_PROC_AUTO_GRANT_FAIL)); } + + /* + Restore current user with GLOBAL_ACL privilege of SQL thread + */ + if (restore_backup_context) + { + DBUG_ASSERT(thd->slave_thread == 1); + thd->security_ctx->restore_security_context(thd, backup); + } + #endif break; + } case SP_WRITE_ROW_FAILED: my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name); break; @@ -5580,6 +5614,14 @@ void mysql_reset_thd_for_next_command(THD *thd) } +/** + Resets the lex->current_select object. + @note It is assumed that lex->current_select != NULL + + This function is a wrapper around select_lex->init_select() with an added + check for the special situation when using INTO OUTFILE and LOAD DATA. +*/ + void mysql_init_select(LEX *lex) { @@ -5594,6 +5636,18 @@ mysql_init_select(LEX *lex) } +/** + Used to allocate a new SELECT_LEX object on the current thd mem_root and + link it into the relevant lists. + + This function is always followed by mysql_init_select. + + @see mysql_init_select + + @retval TRUE An error occurred + @retval FALSE The new SELECT_LEX was successfully allocated. +*/ + bool mysql_new_select(LEX *lex, bool move_down) { @@ -6411,7 +6465,6 @@ void st_select_lex::set_lock_for_tables(thr_lock_type lock_type) DBUG_ENTER("set_lock_for_tables"); DBUG_PRINT("enter", ("lock_type: %d for_update: %d", lock_type, for_update)); - for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first; tables; tables= tables->next_local) diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 60f205ec8e8..1465b6d2d30 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1139,8 +1139,9 @@ int plugin_init(int *argc, char **argv, int flags) for (plugin= *builtins; plugin->info; plugin++) { if (opt_ignore_builtin_innodb && - !my_strcasecmp(&my_charset_latin1, plugin->name, "InnoDB")) - continue; + !my_strnncoll(&my_charset_latin1, (const uchar*) plugin->name, + 6, (const uchar*) "InnoDB", 6)) + continue; /* by default, ndbcluster and federated are disabled */ def_enabled= my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 && @@ -1633,8 +1634,8 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl { TABLE_LIST tables; TABLE *table; - int error, argc; - char *argv[2]; + int error, argc=orig_argc; + char **argv=orig_argv; struct st_plugin_int *tmp; DBUG_ENTER("mysql_install_plugin"); @@ -1650,21 +1651,31 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl pthread_mutex_lock(&LOCK_plugin); rw_wrlock(&LOCK_system_variables_hash); - /* handle_options() assumes arg0 (program name) always exists */ - argv[0]= const_cast<char*>(""); // without a cast gcc emits a warning - argv[1]= 0; - argc= 1; + + my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL); error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER); + if (argv) + free_defaults(argv); rw_unlock(&LOCK_system_variables_hash); if (error || !(tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) goto err; - if (plugin_initialize(tmp)) + if (tmp->state == PLUGIN_IS_DISABLED) { - my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, - "Plugin initialization function failed."); - goto deinit; + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_CANT_INITIALIZE_UDF, ER(ER_CANT_INITIALIZE_UDF), + name->str, "Plugin is disabled"); + } + else + { + DBUG_ASSERT(tmp->state == PLUGIN_IS_UNINITIALIZED); + if (plugin_initialize(tmp)) + { + my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, + "Plugin initialization function failed."); + goto deinit; + } } /* diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bea748562eb..0a3238b0185 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7625,7 +7625,7 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, if (and_level) { /* - Retrieve all conjucts of this level detecting the equality + Retrieve all conjuncts of this level detecting the equality that are subject to substitution by multiple equality items and removing each such predicate from the conjunction after having found/created a multiple equality whose inference the predicate is. @@ -7641,6 +7641,15 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, li.remove(); } + /* + Check if we eliminated all the predicates of the level, e.g. + (a=a AND b=b AND a=a). + */ + if (!args->elements && + !cond_equal.current_level.elements && + !eq_list.elements) + return new Item_int((longlong) 1, 1); + List_iterator_fast<Item_equal> it(cond_equal.current_level); while ((item_equal= it++)) { @@ -9788,6 +9797,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, table->in_use= thd; table->quick_keys.init(); table->covering_keys.init(); + table->merge_keys.init(); table->keys_in_use_for_query.init(); table->s= share; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 71fd79b597a..d08b3a248c4 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -287,7 +287,7 @@ static struct show_privileges_st sys_privileges[]= {"Alter", "Tables", "To alter the table"}, {"Alter routine", "Functions,Procedures", "To alter or drop stored functions/procedures"}, {"Create", "Databases,Tables,Indexes", "To create new databases and tables"}, - {"Create routine","Functions,Procedures","To use CREATE FUNCTION/PROCEDURE"}, + {"Create routine","Databases","To use CREATE FUNCTION/PROCEDURE"}, {"Create temporary tables","Databases","To use CREATE TEMPORARY TABLE"}, {"Create view", "Tables", "To create new views"}, {"Create user", "Server Admin", "To create new users"}, @@ -1598,21 +1598,25 @@ void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user, int view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) { + my_bool compact_view_name= TRUE; my_bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL | MODE_ORACLE | MODE_MSSQL | MODE_DB2 | MODE_MAXDB | MODE_ANSI)) != 0; - /* - Compact output format for view can be used - - if user has db of this view as current db - - if this view only references table inside it's own db - */ + if (!thd->db || strcmp(thd->db, table->view_db.str)) - table->compact_view_format= FALSE; + /* + print compact view name if the view belongs to the current database + */ + compact_view_name= table->compact_view_format= FALSE; else { + /* + Compact output format for view body can be used + if this view only references table inside it's own db + */ TABLE_LIST *tbl; table->compact_view_format= TRUE; for (tbl= thd->lex->query_tables; @@ -1633,7 +1637,7 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) view_store_options(thd, table, buff); } buff->append(STRING_WITH_LEN("VIEW ")); - if (!table->compact_view_format) + if (!compact_view_name) { append_identifier(thd, buff, table->view_db.str, table->view_db.length); buff->append('.'); @@ -1700,7 +1704,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN)); field->maybe_null=1; field_list.push_back(new Item_empty_string("Command",16)); - field_list.push_back(new Item_return_int("Time",7, MYSQL_TYPE_LONG)); + field_list.push_back(field= new Item_return_int("Time",7, MYSQL_TYPE_LONG)); + field->unsigned_flag= 0; field_list.push_back(field=new Item_empty_string("State",30)); field->maybe_null=1; field_list.push_back(field=new Item_empty_string("Info",max_query_length)); @@ -1793,7 +1798,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) else protocol->store(command_name[thd_info->command].str, system_charset_info); if (thd_info->start_time) - protocol->store((uint32) (now - thd_info->start_time)); + protocol->store_long ((longlong) (now - thd_info->start_time)); else protocol->store_null(); protocol->store(thd_info->state_info, system_charset_info); @@ -1868,8 +1873,8 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) table->field[4]->store(command_name[tmp->command].str, command_name[tmp->command].length, cs); /* MYSQL_TIME */ - table->field[5]->store((uint32)(tmp->start_time ? - now - tmp->start_time : 0), TRUE); + table->field[5]->store((longlong)(tmp->start_time ? + now - tmp->start_time : 0), FALSE); /* STATE */ #ifndef EMBEDDED_LIBRARY val= (char*) (tmp->locked ? "Locked" : @@ -3792,8 +3797,19 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables, cs); table->field[4]->store((longlong) count, TRUE); field->sql_type(type); - table->field[14]->store(type.ptr(), type.length(), cs); + table->field[14]->store(type.ptr(), type.length(), cs); + /* + MySQL column type has the following format: + base_type [(dimension)] [unsigned] [zerofill]. + For DATA_TYPE column we extract only base type. + */ tmp_buff= strchr(type.ptr(), '('); + if (!tmp_buff) + /* + if there is no dimention part then check the presence of + [unsigned] [zerofill] attributes and cut them of if exist. + */ + tmp_buff= strchr(type.ptr(), ' '); table->field[7]->store(type.ptr(), (tmp_buff ? tmp_buff - type.ptr() : type.length()), cs); @@ -6543,7 +6559,7 @@ ST_FIELD_INFO processlist_fields_info[]= SKIP_OPEN_TABLE}, {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Db", SKIP_OPEN_TABLE}, {"COMMAND", 16, MYSQL_TYPE_STRING, 0, 0, "Command", SKIP_OPEN_TABLE}, - {"TIME", 7, MYSQL_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE}, + {"TIME", 7, MYSQL_TYPE_LONG, 0, 0, "Time", SKIP_OPEN_TABLE}, {"STATE", 64, MYSQL_TYPE_STRING, 0, 1, "State", SKIP_OPEN_TABLE}, {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info", SKIP_OPEN_TABLE}, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f0059e7a95b..60714348d03 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3321,7 +3321,7 @@ bool mysql_create_table_no_lock(THD *thd, if (key->type == Key::FOREIGN_KEY && !part_info->is_auto_partitioned) { - my_error(ER_CANNOT_ADD_FOREIGN, MYF(0)); + my_error(ER_FOREIGN_KEY_ON_PARTITIONED, MYF(0)); goto err; } } @@ -4297,7 +4297,14 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, view_checksum(thd, table) == HA_ADMIN_WRONG_CHECKSUM) push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, ER_VIEW_CHECKSUM, ER(ER_VIEW_CHECKSUM)); - result_code= HA_ADMIN_CORRUPT; + if (thd->main_da.is_error() && + (thd->main_da.sql_errno() == ER_NO_SUCH_TABLE || + thd->main_da.sql_errno() == ER_FILE_NOT_FOUND)) + /* A missing table is just issued as a failed command */ + result_code= HA_ADMIN_FAILED; + else + /* Default failure code is corrupt table */ + result_code= HA_ADMIN_CORRUPT; goto send_result; } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index be66f7c2d80..b6ea6579d08 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -564,24 +564,36 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, fill_effective_table_privileges(thd, &view->grant, view->db, view->table_name); + /* + Make sure that the current user does not have more column-level privileges + on the newly created view than he/she does on the underlying + tables. E.g. it must not be so that the user has UPDATE privileges on a + view column of he/she doesn't have it on the underlying table's + corresponding column. In that case, return an error for CREATE VIEW. + */ { Item *report_item= NULL; + /* + This will hold the intersection of the priviliges on all columns in the + view. + */ uint final_priv= VIEW_ANY_ACL; - - for (sl= select_lex; sl; sl= sl->next_select()) - { - DBUG_ASSERT(view->db); /* Must be set in the parser */ - List_iterator_fast<Item> it(sl->item_list); - Item *item; - while ((item= it++)) + + for (sl= select_lex; sl; sl= sl->next_select()) { + DBUG_ASSERT(view->db); /* Must be set in the parser */ + List_iterator_fast<Item> it(sl->item_list); + Item *item; + while ((item= it++)) + { Item_field *fld= item->filed_for_view_update(); - uint priv= (get_column_grant(thd, &view->grant, view->db, - view->table_name, item->name) & - VIEW_ANY_ACL); + uint priv= (get_column_grant(thd, &view->grant, view->db, + view->table_name, item->name) & + VIEW_ANY_ACL); if (fld && !fld->field->table->s->tmp_table) - { + { + final_priv&= fld->have_privileges; if (~fld->have_privileges & priv) @@ -589,17 +601,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, } } } - - if (!final_priv) - { - DBUG_ASSERT(report_item); - - my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), - "create view", thd->security_ctx->priv_user, + + if (!final_priv && report_item) + { + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + "create view", thd->security_ctx->priv_user, thd->security_ctx->priv_host, report_item->name, - view->table_name); - res= TRUE; - goto err; + view->table_name); + res= TRUE; + goto err; } } #endif diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 371a146696d..e56ff7c6ad7 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6489,7 +6489,8 @@ select_option: { if (check_simple_select()) MYSQL_YYABORT; - Lex->lock_option= TL_READ_HIGH_PRIORITY; + Lex->lock_option= TL_READ_HIGH_PRIORITY; + Lex->current_select->lock_option= TL_READ_HIGH_PRIORITY; } | DISTINCT { Select->options|= SELECT_DISTINCT; } | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; } @@ -6535,6 +6536,7 @@ select_lock_type: { LEX *lex=Lex; lex->current_select->set_lock_for_tables(TL_WRITE); + lex->current_select->lock_option= TL_WRITE; lex->safe_to_cache_query=0; } | LOCK_SYM IN_SYM SHARE_SYM MODE_SYM @@ -6542,6 +6544,7 @@ select_lock_type: LEX *lex=Lex; lex->current_select-> set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS); + lex->current_select->lock_option= TL_READ_WITH_SHARED_LOCKS; lex->safe_to_cache_query=0; } ; @@ -12909,6 +12912,18 @@ subselect_start: subselect_end: { LEX *lex=Lex; + /* + Set the required lock level for the tables associated with the + current sub-select. This will overwrite previous lock options set + using st_select_lex::add_table_to_list in any of the following + rules: single_multi, table_wild_one, load_data, table_alias_ref, + table_factor. + The default lock level is TL_READ_DEFAULT but it can be modified + with query options specific for a certain (sub-)SELECT. + */ + lex->current_select-> + set_lock_for_tables(lex->current_select->lock_option); + lex->pop_context(); SELECT_LEX *child= lex->current_select; lex->current_select = lex->current_select->return_after_parsing(); diff --git a/sql/table.cc b/sql/table.cc index 17454ffb012..d24ee4c6a27 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1652,6 +1652,7 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, goto err; outparam->quick_keys.init(); outparam->covering_keys.init(); + outparam->merge_keys.init(); outparam->keys_in_use_for_query.init(); /* Allocate handler */ @@ -2982,11 +2983,8 @@ void st_table::reset_item_list(List<Item> *item_list) const void TABLE_LIST::calc_md5(char *buffer) { - my_MD5_CTX context; uchar digest[16]; - my_MD5Init(&context); - my_MD5Update(&context,(uchar *) select_stmt.str, select_stmt.length); - my_MD5Final(digest, &context); + MY_MD5_HASH(digest, (uchar *) select_stmt.str, select_stmt.length); sprintf((char *) buffer, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", digest[0], digest[1], digest[2], digest[3], diff --git a/sql/unireg.cc b/sql/unireg.cc index da018ebec3d..51293184ad8 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -229,16 +229,16 @@ bool mysql_create_frm(THD *thd, const char *file_name, create_info->comment.length, 60); if (tmp_len < create_info->comment.length) { - (void) my_snprintf(buff, sizeof(buff), "Too long comment for table '%s'", - table); if ((thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES))) { - my_message(ER_UNKNOWN_ERROR, buff, MYF(0)); + my_error(ER_TOO_LONG_TABLE_COMMENT, MYF(0), table, tmp_len); goto err; } push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), buff); + ER_TOO_LONG_TABLE_COMMENT, + ER(ER_TOO_LONG_TABLE_COMMENT), + table, tmp_len); create_info->comment.length= tmp_len; } @@ -613,17 +613,16 @@ static bool pack_header(uchar *forminfo, enum legacy_db_type table_type, 255); if (tmp_len < field->comment.length) { - char buff[128]; - (void) my_snprintf(buff,sizeof(buff), "Too long comment for field '%s'", - field->field_name); if ((current_thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES))) { - my_message(ER_UNKNOWN_ERROR, buff, MYF(0)); + my_error(ER_TOO_LONG_FIELD_COMMENT, MYF(0), field->field_name, tmp_len); DBUG_RETURN(1); } push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), buff); + ER_TOO_LONG_FIELD_COMMENT, + ER(ER_TOO_LONG_FIELD_COMMENT), + field->field_name, tmp_len); field->comment.length= tmp_len; } |