diff options
author | Michael Widenius <monty@mysql.com> | 2009-04-25 12:04:38 +0300 |
---|---|---|
committer | Michael Widenius <monty@mysql.com> | 2009-04-25 12:04:38 +0300 |
commit | 210a412522b10115d34b431c66acf403faab7bfe (patch) | |
tree | 56c09cfd1053265897d114e4acb52d395185f27e /sql | |
parent | 059b9356a19118a48fbad31be81c4859e15d3bc8 (diff) | |
parent | 4aeeb1d157a67c5359475d8941267641fb894b22 (diff) | |
download | mariadb-git-210a412522b10115d34b431c66acf403faab7bfe.tar.gz |
bzr merge from guilhem's maria tree to our local 5.1
configure.in:
Manually merged
mysql-test/lib/My/ConfigFactory.pm:
Manually merged
mysql-test/mysql-test-run.pl:
Manually merged
mysql-test/t/information_schema.test:
Manually merged
sql/handler.cc:
Manually merged
support-files/mysql.spec.sh:
Manually merged
Diffstat (limited to 'sql')
46 files changed, 1049 insertions, 531 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 40c363f0182..1aa43fd6a51 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4929,10 +4929,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 2d5278faf7f..44efa1cbe68 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -428,17 +428,14 @@ int ha_initialize_handlerton(st_plugin_int *plugin) MYF(MY_WME | MY_ZEROFILL)); /* Historical Requirement */ plugin->data= hton; // shortcut for the future - if (plugin->plugin->init) + if (plugin->plugin->init && plugin->plugin->init(hton)) { - if (plugin->plugin->init(hton)) - { - sql_print_error("Plugin '%s' init function returned error.", - plugin->name.str); - /* Free data, so that we don't refer to it in ha_finalize_handlerton */ - my_free(hton, MYF(0)); - plugin->data= 0; - goto err; - } + sql_print_error("Plugin '%s' init function returned error.", + plugin->name.str); + /* Free data, so that we don't refer to it in ha_finalize_handlerton */ + my_free(hton, MYF(0)); + plugin->data= 0; + goto err; } /* @@ -467,7 +464,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin) sql_print_warning("Too many storage engines!"); my_free(hton, MYF(0)); plugin->data= 0; - DBUG_RETURN(1); + goto err_deinit; } if (hton->db_type != DB_TYPE_UNKNOWN) sql_print_warning("Storage engine '%s' has conflicting typecode. " @@ -498,11 +495,14 @@ int ha_initialize_handlerton(st_plugin_int *plugin) { sql_print_error("Too many plugins loaded. Limit is %lu. " "Failed on '%s'", (ulong) MAX_HA, plugin->name.str); - goto err; + goto err_deinit; } hton->slot= total_ha++; } - + installed_htons[hton->db_type]= hton; + tmp= hton->savepoint_offset; + hton->savepoint_offset= savepoint_alloc_size; + savepoint_alloc_size+= tmp; hton2plugin[hton->slot]=plugin; if (hton->prepare) total_ha_2pc++; @@ -534,7 +534,18 @@ int ha_initialize_handlerton(st_plugin_int *plugin) }; DBUG_RETURN(0); + +err_deinit: + /* + Let plugin do its inner deinitialization as plugin->init() + was successfully called before. + */ + if (plugin->plugin->deinit) + (void) plugin->plugin->deinit(NULL); + err: + my_free((uchar*) hton, MYF(0)); + plugin->data= NULL; DBUG_RETURN(1); } @@ -2932,7 +2943,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 f74d8df1045..35a88d10fe0 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1272,13 +1272,26 @@ Item::Type Item_name_const::type() const valid_args guarantees value_item->basic_const_item(); if type is FUNC_ITEM, then we have a fudged item_func_neg() on our hands and return the underlying type. + For Item_func_set_collation() + e.g. NAME_CONST('name', 'value' COLLATE collation) we return its + 'value' argument type. */ - return valid_args ? - (((value_item->type() == FUNC_ITEM) && - (((Item_func *) value_item)->functype() == Item_func::NEG_FUNC)) ? - ((Item_func *) value_item)->key_item()->type() : - value_item->type()) : - NULL_ITEM; + if (!valid_args) + return NULL_ITEM; + Item::Type value_type= value_item->type(); + if (value_type == FUNC_ITEM) + { + /* + The second argument of NAME_CONST('name', 'value') must be + a simple constant item or a NEG_FUNC/COLLATE_FUNC. + */ + DBUG_ASSERT(((Item_func *) value_item)->functype() == + Item_func::NEG_FUNC || + ((Item_func *) value_item)->functype() == + Item_func::COLLATE_FUNC); + return ((Item_func *) value_item)->key_item()->type(); + } + return value_type; } @@ -1624,48 +1637,11 @@ bool agg_item_collations_for_comparison(DTCollation &c, const char *fname, } -/** - Collect arguments' character sets together. - - We allow to apply automatic character set conversion in some cases. - The conditions when conversion is possible are: - - arguments A and B have different charsets - - A wins according to coercibility rules - (i.e. a column is stronger than a string constant, - an explicit COLLATE clause is stronger than a column) - - character set of A is either superset for character set of B, - or B is a string constant which can be converted into the - character set of A without data loss. - - If all of the above is true, then it's possible to convert - B into the character set of A, and then compare according - to the collation of A. - - For functions with more than two arguments: - @code - collect(A,B,C) ::= collect(collect(A,B),C) - @endcode - Since this function calls THD::change_item_tree() on the passed Item ** - pointers, it is necessary to pass the original Item **'s, not copies. - Otherwise their values will not be properly restored (see BUG#20769). - If the items are not consecutive (eg. args[2] and args[5]), use the - item_sep argument, ie. - @code - agg_item_charsets(coll, fname, &args[2], 2, flags, 3) - @endcode -*/ - -bool agg_item_charsets(DTCollation &coll, const char *fname, - Item **args, uint nargs, uint flags, int item_sep) +bool agg_item_set_converter(DTCollation &coll, const char *fname, + Item **args, uint nargs, uint flags, int item_sep) { Item **arg, *safe_args[2]; - LINT_INIT(safe_args[0]); - LINT_INIT(safe_args[1]); - - if (agg_item_collations(coll, fname, args, nargs, flags, item_sep)) - return TRUE; - /* For better error reporting: save the first and the second argument. We need this only if the the number of args is 3 or 2: @@ -1745,6 +1721,46 @@ bool agg_item_charsets(DTCollation &coll, const char *fname, } +/* + Collect arguments' character sets together. + We allow to apply automatic character set conversion in some cases. + The conditions when conversion is possible are: + - arguments A and B have different charsets + - A wins according to coercibility rules + (i.e. a column is stronger than a string constant, + an explicit COLLATE clause is stronger than a column) + - character set of A is either superset for character set of B, + or B is a string constant which can be converted into the + character set of A without data loss. + + If all of the above is true, then it's possible to convert + B into the character set of A, and then compare according + to the collation of A. + + For functions with more than two arguments: + + collect(A,B,C) ::= collect(collect(A,B),C) + + Since this function calls THD::change_item_tree() on the passed Item ** + pointers, it is necessary to pass the original Item **'s, not copies. + Otherwise their values will not be properly restored (see BUG#20769). + If the items are not consecutive (eg. args[2] and args[5]), use the + item_sep argument, ie. + + agg_item_charsets(coll, fname, &args[2], 2, flags, 3) + +*/ + +bool agg_item_charsets(DTCollation &coll, const char *fname, + Item **args, uint nargs, uint flags, int item_sep) +{ + if (agg_item_collations(coll, fname, args, nargs, flags, item_sep)) + return TRUE; + + return agg_item_set_converter(coll, fname, args, nargs, flags, item_sep); +} + + void Item_ident_for_show::make_field(Send_field *tmp_field) { tmp_field->table_name= tmp_field->org_table_name= table_name; @@ -3084,7 +3100,7 @@ bool Item_param::convert_str_value(THD *thd) str_value.set_charset(value.cs_info.final_character_set_of_str_value); /* Here str_value is guaranteed to be in final_character_set_of_str_value */ - max_length= str_value.length(); + max_length= str_value.numchars() * str_value.charset()->mbmaxlen; decimals= 0; /* str_value_ptr is returned from val_str(). It must be not alloced diff --git a/sql/item.h b/sql/item.h index e90cdbbc8f8..eb1b28b4004 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1304,6 +1304,8 @@ bool agg_item_collations(DTCollation &c, const char *name, Item **items, uint nitems, uint flags, int item_sep); bool agg_item_collations_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems, uint flags); +bool agg_item_set_converter(DTCollation &coll, const char *fname, + Item **args, uint nargs, uint flags, int item_sep); bool agg_item_charsets(DTCollation &c, const char *name, Item **items, uint nitems, uint flags, int item_sep); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 7ab5a95e5b4..bb391187fb9 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -549,7 +549,8 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type) my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols()); return 1; } - comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i)); + if (comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i))) + return 1; } break; } @@ -893,6 +894,16 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg, get_value_func= &get_time_value; return 0; } + else if (type == STRING_RESULT && + (*a)->result_type() == STRING_RESULT && + (*b)->result_type() == STRING_RESULT) + { + DTCollation coll; + coll.set((*a)->collation.collation); + if (agg_item_set_converter(coll, owner_arg->func_name(), + b, 1, MY_COLL_CMP_CONV, 1)) + return 1; + } return set_compare_func(owner_arg, type); } diff --git a/sql/item_func.cc b/sql/item_func.cc index eb7062aa8bc..fb4594e0e63 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4840,7 +4840,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)) { @@ -4870,8 +4872,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: @@ -5374,7 +5382,10 @@ bool Item_func_match::fix_fields(THD *thd, Item **ref) if (item->type() == Item::REF_ITEM) args[i]= item= *((Item_ref *)item)->ref; if (item->type() != Item::FIELD_ITEM) - key=NO_SUCH_KEY; + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "AGAINST"); + return TRUE; + } } /* Check that all columns come from the same table. diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index cf2453e13ec..298fbc39144 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 bae01542d5c..21501d9becf 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/item_timefunc.h b/sql/item_timefunc.h index 94b02d1eaf6..9e3c2e8c89f 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -419,6 +419,7 @@ public: { return save_time_in_field(field); } + longlong val_int() { return val_int_from_decimal(); } bool result_as_longlong() { return TRUE; } }; diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index 8494b4308eb..a2342975aec 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -1972,6 +1972,13 @@ my_xpath_parse_FilterExpr_opt_slashes_RelativeLocationPath(MY_XPATH *xpath) if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_SLASH)) return 1; + if (xpath->item->type() != Item::XPATH_NODESET) + { + xpath->lasttok= xpath->prevtok; + xpath->error= 1; + return 0; + } + my_xpath_parse_term(xpath, MY_XPATH_LEX_SLASH); return my_xpath_parse_RelativeLocationPath(xpath); } @@ -1979,7 +1986,6 @@ static int my_xpath_parse_PathExpr(MY_XPATH *xpath) { return my_xpath_parse_LocationPath(xpath) || my_xpath_parse_FilterExpr_opt_slashes_RelativeLocationPath(xpath); - } diff --git a/sql/log.cc b/sql/log.cc index 73f8b0d8157..a86bbac873a 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -4662,10 +4662,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) { @@ -4681,7 +4685,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 4dea2e5e62c..68d4c69f398 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -53,6 +53,8 @@ #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) +static int rows_event_stmt_cleanup(Relay_log_info const *rli, THD* thd); + static const char *HA_ERR(int i) { switch (i) { @@ -352,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); @@ -391,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; @@ -1255,7 +1257,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 */ @@ -2893,7 +2895,37 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos)); clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); - const_cast<Relay_log_info*>(rli)->clear_tables_to_lock(); + if (strcmp("COMMIT", query) == 0 && rli->tables_to_lock) + { + /* + Cleaning-up the last statement context: + the terminal event of the current statement flagged with + STMT_END_F got filtered out in ndb circular replication. + */ + int error; + char llbuff[22]; + if ((error= rows_event_stmt_cleanup(const_cast<Relay_log_info*>(rli), thd))) + { + const_cast<Relay_log_info*>(rli)->report(ERROR_LEVEL, error, + "Error in cleaning up after an event preceeding the commit; " + "the group log file/position: %s %s", + const_cast<Relay_log_info*>(rli)->group_master_log_name, + llstr(const_cast<Relay_log_info*>(rli)->group_master_log_pos, + llbuff)); + } + /* + Executing a part of rli->stmt_done() logics that does not deal + with group position change. The part is redundant now but is + future-change-proof addon, e.g if COMMIT handling will start checking + invariants like IN_STMT flag must be off at committing the transaction. + */ + const_cast<Relay_log_info*>(rli)->inc_event_relay_log_pos(); + const_cast<Relay_log_info*>(rli)->clear_flag(Relay_log_info::IN_STMT); + } + else + { + const_cast<Relay_log_info*>(rli)->clear_tables_to_lock(); + } /* Note: We do not need to execute reset_one_shot_variables() if this @@ -7405,16 +7437,20 @@ Rows_log_event::do_shall_skip(Relay_log_info *rli) return Log_event::do_shall_skip(rli); } -int -Rows_log_event::do_update_pos(Relay_log_info *rli) -{ - DBUG_ENTER("Rows_log_event::do_update_pos"); - int error= 0; - - DBUG_PRINT("info", ("flags: %s", - get_flags(STMT_END_F) ? "STMT_END_F " : "")); +/** + The function is called at Rows_log_event statement commit time, + normally from Rows_log_event::do_update_pos() and possibly from + Query_log_event::do_apply_event() of the COMMIT. + The function commits the last statement for engines, binlog and + releases resources have been allocated for the statement. + + @retval 0 Ok. + @retval non-zero Error at the commit. + */ - if (get_flags(STMT_END_F)) +static int rows_event_stmt_cleanup(Relay_log_info const *rli, THD * thd) +{ + int error; { /* This is the end of a statement or transaction, so close (and @@ -7456,14 +7492,39 @@ Rows_log_event::do_update_pos(Relay_log_info *rli) thd->reset_current_stmt_binlog_row_based(); - rli->cleanup_context(thd, 0); - if (error == 0) + const_cast<Relay_log_info*>(rli)->cleanup_context(thd, 0); + } + return error; +} + +/** + The method either increments the relay log position or + commits the current statement and increments the master group + possition if the event is STMT_END_F flagged and + the statement corresponds to the autocommit query (i.e replicated + without wrapping in BEGIN/COMMIT) + + @retval 0 Success + @retval non-zero Error in the statement commit + */ +int +Rows_log_event::do_update_pos(Relay_log_info *rli) +{ + DBUG_ENTER("Rows_log_event::do_update_pos"); + int error= 0; + + DBUG_PRINT("info", ("flags: %s", + get_flags(STMT_END_F) ? "STMT_END_F " : "")); + + if (get_flags(STMT_END_F)) + { + if ((error= rows_event_stmt_cleanup(rli, thd)) == 0) { /* Indicate that a statement is finished. Step the group log position if we are not in a transaction, otherwise increase the event log position. - */ + */ rli->stmt_done(log_pos, when); /* @@ -7477,11 +7538,13 @@ Rows_log_event::do_update_pos(Relay_log_info *rli) thd->clear_error(); } else + { rli->report(ERROR_LEVEL, error, "Error in %s event: commit of row events failed, " "table `%s`.`%s`", get_type_str(), m_table->s->db.str, m_table->s->table_name.str); + } } else { 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 7753e98da41..a8c7246d7e3 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -282,16 +282,12 @@ protected: */ #define TABLE_DEF_CACHE_MIN 256 -/* - Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper - Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added - 100 bytes as reasonable buffer against growth and other environments' - requirements.) - - Feel free to raise this by the smallest amount you can to get the - "execution_constants" test to pass. - */ -#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval. +/* + Stack reservation. + Feel free to raise this by the smallest amount you can to get the + "execution_constants" test to pass. +*/ +#define STACK_MIN_SIZE 16000 // Abort if less stack during eval. #define STACK_MIN_SIZE_FOR_OPEN 1024*80 #define STACK_BUFF_ALLOC 352 ///< For stack overrun checks @@ -1958,6 +1954,7 @@ extern my_bool opt_log, opt_slow_log; extern ulong log_output_options; extern my_bool opt_log_queries_not_using_indexes; extern bool opt_disable_networking, opt_skip_show_db; +extern bool opt_ignore_builtin_innodb; extern my_bool opt_character_set_client_handshake; extern bool volatile abort_loop, shutdown_in_progress; extern uint volatile thread_count, thread_running, global_read_lock; @@ -2425,7 +2422,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 7a988f1cbad..8af23d7fb2b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -178,39 +178,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 */ @@ -381,7 +383,7 @@ static pthread_cond_t COND_thread_cache, COND_flush_thread_cache; /* Global variables */ -bool opt_update_log, opt_bin_log; +bool opt_update_log, opt_bin_log, opt_ignore_builtin_innodb= 0; my_bool opt_log, opt_slow_log; ulong log_output_options; my_bool opt_log_queries_not_using_indexes= 0; @@ -692,6 +694,8 @@ bool mysqld_embedded=0; bool mysqld_embedded=1; #endif +static my_bool plugins_are_initialized= FALSE; + #ifndef DBUG_OFF static const char* default_dbug_option; #endif @@ -744,12 +748,12 @@ uint connection_count= 0, extra_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); @@ -763,7 +767,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); static void register_mutex_order(); @@ -1190,10 +1194,10 @@ extern "C" void unireg_abort(int exit_code) { DBUG_ENTER("unireg_abort"); + if (opt_help) + usage(); if (exit_code) sql_print_error("Aborting\n"); - else if (opt_help) - usage(); clean_up(!opt_help && (exit_code || !opt_bootstrap)); /* purecov: inspected */ DBUG_PRINT("quit",("done with cleanup in unireg_abort")); wait_for_signal_thread_to_end(); @@ -1201,7 +1205,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) @@ -3311,7 +3316,8 @@ static int init_common_variables(const char *conf_file_name, int argc, 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, @@ -3764,7 +3770,7 @@ static int init_server_components() query_cache_init(); query_cache_resize(query_cache_size); my_rnd_init(&sql_rand,(ulong) server_start_time,(ulong) server_start_time/2); - set_proper_floating_point_mode(); + setup_fpu(); init_thr_lock(); my_uuid_init((ulong) (my_rnd(&sql_rand))*12345,12345); #ifdef HAVE_REPLICATION @@ -3794,7 +3800,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); + } } } @@ -3946,12 +3955,15 @@ server."); if (ha_init_errors()) DBUG_RETURN(1); - if (plugin_init(&defaults_argc, defaults_argv, - (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) | - (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0))) - { - sql_print_error("Failed to initialize plugins."); - unireg_abort(1); + { + if (plugin_init(&defaults_argc, defaults_argv, + (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) | + (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0))) + { + sql_print_error("Failed to initialize plugins."); + unireg_abort(1); + } + plugins_are_initialized= TRUE; /* Don't separate from init function */ } if (opt_help) @@ -4425,6 +4437,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 @@ -5724,7 +5737,8 @@ enum options_mysqld OPT_DEADLOCK_TIMEOUT_SHORT, OPT_DEADLOCK_TIMEOUT_LONG, OPT_GENERAL_LOG_FILE, - OPT_SLOW_QUERY_LOG_FILE + OPT_SLOW_QUERY_LOG_FILE, + OPT_IGNORE_BUILTIN_INNODB }; @@ -5964,6 +5978,9 @@ Disable with --skip-large-pages.", (uchar**) &opt_large_pages, (uchar**) &opt_large_pages, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"ignore-builtin-innodb", OPT_IGNORE_BUILTIN_INNODB , + "Disable initialization of builtin InnoDB plugin", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"init-connect", OPT_INIT_CONNECT, "Command(s) that are executed for each new connection", (uchar**) &opt_init_connect, (uchar**) &opt_init_connect, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -6412,7 +6429,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.", @@ -7602,7 +7619,8 @@ static void usage(void) default_collation_name= (char*) default_charset_info->name; print_version(); puts("\ -Copyright (C) 2000-2008 MySQL AB, Monty and others, 2008-2009 Sun Microsystems, Inc.\n\ +Copyright (C) 2000-2008 MySQL AB, by Monty and others\n\ +Copyright (C) 2008 Sun Microsystems, Inc.\n\ This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ and you are welcome to modify and redistribute it under the GPL license\n\n\ Starts the MySQL database server\n"); @@ -7632,6 +7650,13 @@ Starts the MySQL database server\n"); /* Print out all the options including plugin supplied options */ my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option)); + if (! plugins_are_initialized) + { + puts("\n\ +Plugins have parameters that are not reflected in this list\n\ +because execution stopped before plugins were initialized."); + } + puts("\n\ To see what values a running MySQL server is using, type\n\ 'mysqladmin variables' instead of 'mysqld --verbose --help'."); @@ -7658,6 +7683,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; @@ -7670,6 +7696,7 @@ static int mysql_init_variables(void) log_output_options= find_bit_type(log_output_str, &log_output_typelib); opt_bin_log= 0; opt_disable_networking= opt_skip_show_db=0; + opt_ignore_builtin_innodb= 0; opt_logname= opt_update_logname= opt_binlog_index_name= opt_slow_logname= 0; opt_tc_log_file= (char *)"tc.log"; // no hostname in tc_log file name ! opt_secure_auth= 0; @@ -7717,7 +7744,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= base_ip_sock= extra_ip_sock= INVALID_SOCKET; mysql_home_ptr= mysql_home; @@ -7928,6 +7958,8 @@ mysqld_get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { + int error; + switch(optid) { #ifndef DBUG_OFF case '#': @@ -7981,7 +8013,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: @@ -8010,6 +8044,9 @@ mysqld_get_one_option(int optid, case (int) OPT_BIG_TABLES: thd_startup_options|=OPTION_BIG_TABLES; break; + case (int) OPT_IGNORE_BUILTIN_INNODB: + opt_ignore_builtin_innodb= 1; + break; case (int) OPT_ISAM_LOG: opt_myisam_log=1; break; @@ -8048,18 +8085,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; @@ -8067,9 +8102,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); @@ -8099,8 +8133,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; } @@ -8108,8 +8142,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; } @@ -8117,8 +8151,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; } @@ -8126,8 +8160,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; } @@ -8148,7 +8182,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; } @@ -8158,7 +8194,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: @@ -8197,7 +8233,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= mysqld_extra_port= 0; @@ -8264,8 +8300,8 @@ mysqld_get_one_option(int optid, case OPT_MASTER_SSL_CA: if (!slave_warning_issued) //only show the warning once { - slave_warning_issued = true; - WARN_DEPRECATED(NULL, "5.2", "for replication startup options", + slave_warning_issued = true; + WARN_DEPRECATED(NULL, "6.0", "for replication startup options", "'CHANGE MASTER'"); } break; @@ -8368,7 +8404,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; @@ -8414,7 +8453,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; @@ -8458,13 +8499,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: @@ -8473,7 +8518,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; @@ -8511,7 +8560,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; @@ -8525,7 +8574,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. */ @@ -8564,7 +8613,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 @@ -8592,7 +8642,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); @@ -8610,6 +8660,7 @@ static void get_options(int *argc,char **argv) &extra_max_connections, &extra_connection_count); #endif + return 0; } @@ -8673,7 +8724,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); @@ -8720,12 +8771,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 */ /* @@ -8738,30 +8789,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 37cc0b1ee7b..c17b7cf270a 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9240,32 +9240,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; @@ -9335,7 +9340,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++)) { @@ -9346,13 +9351,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); } @@ -9364,7 +9369,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; } @@ -9414,7 +9419,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; } @@ -9468,9 +9474,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) @@ -9482,7 +9488,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); @@ -9493,7 +9499,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; @@ -9503,11 +9508,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 e608420f21a..a99259ffbcf 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -576,7 +576,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 @@ -587,12 +588,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 fe8e17dc1c7..03ea244c4e5 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 c6650702cf9..c1071c90223 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); @@ -295,6 +294,11 @@ static sys_var_const sys_ft_query_expansion_limit(&vars, static sys_var_const sys_ft_stopword_file(&vars, "ft_stopword_file", OPT_GLOBAL, SHOW_CHAR_PTR, (uchar*) &ft_stopword_file); + +static sys_var_const sys_ignore_builtin_innodb(&vars, "ignore_builtin_innodb", + OPT_GLOBAL, SHOW_BOOL, + (uchar*) &opt_ignore_builtin_innodb); + sys_var_str sys_init_connect(&vars, "init_connect", 0, sys_update_init_connect, sys_default_init_connect,0); @@ -746,7 +750,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, @@ -1397,6 +1401,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) { @@ -1422,26 +1439,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; - throw_bounds_warning(thd, fixed, TRUE, option_limits->name, (longlong) num); - return out; + *num= getopt_ull_limit_value(unadjusted, option_limits, &fixed); + + 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; } @@ -1455,29 +1574,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; } @@ -1497,10 +1600,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; } @@ -1549,36 +1650,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; } @@ -1616,8 +1699,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 */ @@ -1658,27 +1741,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; } @@ -2309,10 +2386,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); @@ -2338,7 +2415,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; @@ -2363,8 +2440,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 @@ -2981,6 +3058,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) { @@ -3701,7 +3788,7 @@ bool sys_var_thd_storage_engine::update(THD *thd, set_var *var) void sys_var_thd_table_type::warn_deprecated(THD *thd) { - WARN_DEPRECATED(thd, "5.2", "@@table_type", "'@@storage_engine'"); + WARN_DEPRECATED(thd, "6.0", "@@table_type", "'@@storage_engine'"); } void sys_var_thd_table_type::set_default(THD *thd, enum_var_type type) @@ -3963,7 +4050,7 @@ bool process_key_caches(process_key_cache_t func) void sys_var_trust_routine_creators::warn_deprecated(THD *thd) { - WARN_DEPRECATED(thd, "5.2", "@@log_bin_trust_routine_creators", + WARN_DEPRECATED(thd, "6.0", "@@log_bin_trust_routine_creators", "'@@log_bin_trust_function_creators'"); } diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index fd75fee9737..aa1521acab6 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -571,30 +571,30 @@ ER_ERROR_ON_READ swe "Fick fel vid läsning av '%-.200s' (Felkod %d)" ukr "îÅ ÍÏÖÕ ÐÒÏÞÉÔÁÔÉ ÆÁÊÌ '%-.200s' (ÐÏÍÉÌËÁ: %d)" ER_ERROR_ON_RENAME - cze "Chyba p-Bøi pøejmenování '%-.150s' na '%-.150s' (chybový kód: %d)" - dan "Fejl ved omdøbning af '%-.150s' til '%-.150s' (Fejlkode: %d)" - nla "Fout bij het hernoemen van '%-.150s' naar '%-.150s' (Errcode: %d)" - eng "Error on rename of '%-.150s' to '%-.150s' (errno: %d)" - jps "'%-.150s' ‚ð '%-.150s' ‚É rename ‚Å‚«‚Ü‚¹‚ñ (errno: %d)", - est "Viga faili '%-.150s' ümbernimetamisel '%-.150s'-ks (veakood: %d)" - fre "Erreur en renommant '%-.150s' en '%-.150s' (Errcode: %d)" - ger "Fehler beim Umbenennen von '%-.150s' in '%-.150s' (Fehler: %d)" - greek "Ðñüâëçìá êáôÜ ôçí ìåôïíïìáóßá ôïõ áñ÷åßïõ '%-.150s' to '%-.150s' (êùäéêüò ëÜèïõò: %d)" - hun "Hiba a '%-.150s' file atnevezesekor '%-.150s'. (hibakod: %d)" - ita "Errore durante la rinominazione da '%-.150s' a '%-.150s' (errno: %d)" - jpn "'%-.150s' ¤ò '%-.150s' ¤Ë rename ¤Ç¤¤Þ¤»¤ó (errno: %d)" - kor "'%-.150s'¸¦ '%-.150s'·Î À̸§ º¯°æÁß ¿¡·¯ (¿¡·¯¹øÈ£: %d)" - nor "Feil ved omdøping av '%-.150s' til '%-.150s' (Feilkode: %d)" - norwegian-ny "Feil ved omdøyping av '%-.150s' til '%-.150s' (Feilkode: %d)" - pol "B³?d podczas zmieniania nazwy '%-.150s' na '%-.150s' (Kod b³êdu: %d)" - por "Erro ao renomear '%-.150s' para '%-.150s' (erro no. %d)" - rum "Eroare incercind sa renumesc '%-.150s' in '%-.150s' (errno: %d)" - rus "ïÛÉÂËÁ ÐÒÉ ÐÅÒÅÉÍÅÎÏ×ÁÎÉÉ '%-.150s' × '%-.150s' (ÏÛÉÂËÁ: %d)" - serbian "Greška pri promeni imena '%-.150s' na '%-.150s' (errno: %d)" - slo "Chyba pri premenovávaní '%-.150s' na '%-.150s' (chybový kód: %d)" - spa "Error en el renombrado de '%-.150s' a '%-.150s' (Error: %d)" - swe "Kan inte byta namn från '%-.150s' till '%-.150s' (Felkod: %d)" - ukr "îÅ ÍÏÖÕ ÐÅÒÅÊÍÅÎÕ×ÁÔÉ '%-.150s' Õ '%-.150s' (ÐÏÍÉÌËÁ: %d)" + cze "Chyba p-Bøi pøejmenování '%-.210s' na '%-.210s' (chybový kód: %d)" + dan "Fejl ved omdøbning af '%-.210s' til '%-.210s' (Fejlkode: %d)" + nla "Fout bij het hernoemen van '%-.210s' naar '%-.210s' (Errcode: %d)" + eng "Error on rename of '%-.210s' to '%-.210s' (errno: %d)" + jps "'%-.210s' ‚ð '%-.210s' ‚É rename ‚Å‚«‚Ü‚¹‚ñ (errno: %d)", + est "Viga faili '%-.210s' ümbernimetamisel '%-.210s'-ks (veakood: %d)" + fre "Erreur en renommant '%-.210s' en '%-.210s' (Errcode: %d)" + ger "Fehler beim Umbenennen von '%-.210s' in '%-.210s' (Fehler: %d)" + greek "Ðñüâëçìá êáôÜ ôçí ìåôïíïìáóßá ôïõ áñ÷åßïõ '%-.210s' to '%-.210s' (êùäéêüò ëÜèïõò: %d)" + hun "Hiba a '%-.210s' file atnevezesekor '%-.210s'. (hibakod: %d)" + ita "Errore durante la rinominazione da '%-.210s' a '%-.210s' (errno: %d)" + jpn "'%-.210s' ¤ò '%-.210s' ¤Ë rename ¤Ç¤¤Þ¤»¤ó (errno: %d)" + kor "'%-.210s'¸¦ '%-.210s'·Î À̸§ º¯°æÁß ¿¡·¯ (¿¡·¯¹øÈ£: %d)" + nor "Feil ved omdøping av '%-.210s' til '%-.210s' (Feilkode: %d)" + norwegian-ny "Feil ved omdøyping av '%-.210s' til '%-.210s' (Feilkode: %d)" + pol "B³?d podczas zmieniania nazwy '%-.210s' na '%-.210s' (Kod b³êdu: %d)" + por "Erro ao renomear '%-.210s' para '%-.210s' (erro no. %d)" + rum "Eroare incercind sa renumesc '%-.210s' in '%-.210s' (errno: %d)" + rus "ïÛÉÂËÁ ÐÒÉ ÐÅÒÅÉÍÅÎÏ×ÁÎÉÉ '%-.210s' × '%-.210s' (ÏÛÉÂËÁ: %d)" + serbian "Greška pri promeni imena '%-.210s' na '%-.210s' (errno: %d)" + slo "Chyba pri premenovávaní '%-.210s' na '%-.210s' (chybový kód: %d)" + spa "Error en el renombrado de '%-.210s' a '%-.210s' (Error: %d)" + swe "Kan inte byta namn från '%-.210s' till '%-.210s' (Felkod: %d)" + ukr "îÅ ÍÏÖÕ ÐÅÒÅÊÍÅÎÕ×ÁÔÉ '%-.210s' Õ '%-.210s' (ÐÏÍÉÌËÁ: %d)" ER_ERROR_ON_WRITE cze "Chyba p-Bøi zápisu do souboru '%-.200s' (chybový kód: %d)" dan "Fejl ved skriving av filen '%-.200s' (Fejlkode: %d)" @@ -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 1f086683aa2..0973e83ed32 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) @@ -5121,8 +5122,15 @@ int decide_logging_format(THD *thd, TABLE_LIST *tables) { if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG)) { - handler::Table_flags flags_some_set= handler::Table_flags(); - handler::Table_flags flags_all_set= ~handler::Table_flags(); + /* + Compute the starting vectors for the computations by creating a + set with all the capabilities bits set and one with no + capabilities bits set. + */ + handler::Table_flags flags_some_set= 0; + handler::Table_flags flags_all_set= + HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE; + my_bool multi_engine= FALSE; void* prev_ht= NULL; for (TABLE_LIST *table= tables; table; table= table->next_global) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 63a5af5e666..5ff5e596f63 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) *****************************************************************************/ @@ -1236,6 +1273,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); @@ -1524,6 +1571,9 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, invalidate_table(thd, tables_used); } + DBUG_EXECUTE_IF("wait_after_query_cache_invalidate", + debug_wait_for_kill("wait_after_query_cache_invalidate");); + DBUG_VOID_RETURN; } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index d2981b7b212..2ed0a339628 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -543,6 +543,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), @@ -798,6 +799,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; } @@ -1642,6 +1644,11 @@ bool select_send::send_data(List<Item> &items) my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); break; } + /* + Reset buffer to its original state, as it may have been altered in + Item::send(). + */ + buffer.set(buff, sizeof(buff), &my_charset_bin); } thd->sent_row_count++; if (thd->is_error()) @@ -3648,19 +3655,17 @@ 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) { - DBUG_ASSERT(this->query != NULL); push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN, ER_BINLOG_UNSAFE_STATEMENT, ER(ER_BINLOG_UNSAFE_STATEMENT)); if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED)) { - char warn_buf[MYSQL_ERRMSG_SIZE]; - my_snprintf(warn_buf, MYSQL_ERRMSG_SIZE, "%s Statement: %s", - ER(ER_BINLOG_UNSAFE_STATEMENT), this->query); - sql_print_warning(warn_buf); + sql_print_warning("%s Statement: %.*s", + ER(ER_BINLOG_UNSAFE_STATEMENT), + MYSQL_ERRMSG_SIZE, query_arg); binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED; } } diff --git a/sql/sql_class.h b/sql/sql_class.h index d24f65046d3..16956e07274 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1357,6 +1357,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_delete.cc b/sql/sql_delete.cc index cfdfbe52cf1..7a355bdd8c2 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -51,6 +51,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_delete"); + THD::enum_binlog_query_type query_type= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + THD::STMT_QUERY_TYPE : + THD::ROW_QUERY_TYPE; + if (open_and_lock_tables(thd, table_list)) DBUG_RETURN(TRUE); if (!(table= table_list->table)) @@ -135,6 +140,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_PRINT("debug", ("Trying to use delete_all_rows()")); if (!(error=table->file->ha_delete_all_rows())) { + /* + If delete_all_rows() is used, it is not possible to log the + query in row format, so we have to log it in statement format. + */ + query_type= THD::STMT_QUERY_TYPE; error= -1; // ok deleted= maybe_deleted; goto cleanup; @@ -374,6 +384,11 @@ cleanup: { if (mysql_bin_log.is_open()) { + bool const is_trans= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + FALSE : + transactional_table; + if (error < 0) thd->clear_error(); /* @@ -381,10 +396,13 @@ cleanup: storage engine does not inject the rows itself, we replicate statement-based; otherwise, 'ha_delete_row()' was used to delete specific rows which we might log row-based. + + Note that TRUNCATE TABLE is not transactional and should + therefore be treated as a DDL. */ - int log_result= thd->binlog_query(THD::ROW_QUERY_TYPE, + int log_result= thd->binlog_query(query_type, thd->query, thd->query_length, - transactional_table, FALSE, killed_status); + is_trans, FALSE, killed_status); if (log_result && transactional_table) { diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 79da1936eb9..bd8f9469571 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -177,7 +177,7 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code, const char *format, ...) { va_list args; - char warning[ERRMSGSIZE+20]; + char warning[MYSQL_ERRMSG_SIZE]; DBUG_ENTER("push_warning_printf"); DBUG_PRINT("enter",("warning: %u", code)); 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_insert.cc b/sql/sql_insert.cc index a64429fb7bc..aa8c6099fca 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -929,20 +929,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, } DBUG_ASSERT(transactional_table || !changed || thd->transaction.stmt.modified_non_trans_table); - - if (thd->lock) - { - /* - Invalidate the table in the query cache if something changed - after unlocking when changes become fisible. - TODO: this is workaround. right way will be move invalidating in - the unlock procedure. - */ - if (lock_type == TL_WRITE_CONCURRENT_INSERT && changed) - { - query_cache_invalidate3(thd, table_list, 1); - } - } } thd_proc_info(thd, "end"); /* @@ -1716,6 +1702,7 @@ public: class Delayed_insert :public ilink { uint locks_in_memory; + thr_lock_type delayed_lock; public: THD thd; TABLE *table; @@ -1758,6 +1745,8 @@ public: pthread_cond_init(&cond_client,NULL); VOID(pthread_mutex_lock(&LOCK_thread_count)); delayed_insert_threads++; + delayed_lock= global_system_variables.low_priority_updates ? + TL_WRITE_LOW_PRIORITY : TL_WRITE; VOID(pthread_mutex_unlock(&LOCK_thread_count)); } ~Delayed_insert() @@ -2569,7 +2558,7 @@ bool Delayed_insert::handle_inserts(void) table->use_all_columns(); thd_proc_info(&thd, "upgrading lock"); - if (thr_upgrade_write_delay_lock(*thd.lock->locks)) + if (thr_upgrade_write_delay_lock(*thd.lock->locks, delayed_lock)) { /* This can happen if thread is killed either by a shutdown diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 272c74917ad..1c1f3bbe06f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1569,6 +1569,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 7e199266db9..41c96a13829 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 b587d172b68..5b316f130b9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4449,6 +4449,7 @@ create_sp_error: case SP_KEY_NOT_FOUND: if (lex->drop_if_exists) { + write_bin_log(thd, TRUE, thd->query, thd->query_length); push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), SP_COM_STRING(lex), lex->spname->m_name.str); @@ -5475,9 +5476,10 @@ bool check_stack_overrun(THD *thd, long margin, if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >= (long) (my_thread_stack_size - margin)) { - sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE), - stack_used,my_thread_stack_size,margin); - my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(0)); + char ebuff[MYSQL_ERRMSG_SIZE]; + my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE), + stack_used, my_thread_stack_size, margin); + my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR)); thd->fatal_error(); return 1; } @@ -5600,6 +5602,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) { @@ -5614,6 +5624,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) { @@ -5987,7 +6009,7 @@ bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type, */ char buf[32]; my_snprintf(buf, sizeof(buf), "TIMESTAMP(%s)", length); - WARN_DEPRECATED(thd, "5.2", buf, "'TIMESTAMP'"); + WARN_DEPRECATED(thd, "6.0", buf, "'TIMESTAMP'"); } if (!(new_field= new Create_field()) || @@ -6431,7 +6453,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 5a961109ab2..6a59154dd22 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1138,6 +1138,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; /* by default, ndbcluster and federated are disabled */ def_enabled= my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 && diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7bf44183f2d..d7eed19d619 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -92,7 +92,6 @@ static store_key *get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables, KEY_PART_INFO *key_part, uchar *key_buff, uint maybe_null); -static bool make_simple_join(JOIN *join,TABLE *tmp_table); static void make_outerjoin_info(JOIN *join); static bool make_join_select(JOIN *join,SQL_SELECT *select,COND *item); static void make_join_readinfo(JOIN *join, ulonglong options); @@ -1897,7 +1896,7 @@ JOIN::exec() /* Free first data from old join */ curr_join->join_free(); - if (make_simple_join(curr_join, curr_tmp_table)) + if (curr_join->make_simple_join(this, curr_tmp_table)) DBUG_VOID_RETURN; calc_group_buffer(curr_join, group_list); count_field_types(select_lex, &curr_join->tmp_table_param, @@ -2029,7 +2028,7 @@ JOIN::exec() curr_join->select_distinct=0; } curr_tmp_table->reginfo.lock_type= TL_UNLOCK; - if (make_simple_join(curr_join, curr_tmp_table)) + if (curr_join->make_simple_join(this, curr_tmp_table)) DBUG_VOID_RETURN; calc_group_buffer(curr_join, curr_join->group_list); count_field_types(select_lex, &curr_join->tmp_table_param, @@ -2493,11 +2492,12 @@ typedef struct st_sargable_param */ static bool -make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, +make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds, DYNAMIC_ARRAY *keyuse_array) { int error; TABLE *table; + TABLE_LIST *tables= tables_arg; uint i,table_count,const_count,key; table_map found_const_table_map, all_table_map, found_ref, refs; key_map const_ref, eq_part; @@ -2534,10 +2534,11 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, s->needed_reg.init(); table_vector[i]=s->table=table=tables->table; table->pos_in_table_list= tables; - if ((error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK))) + error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + if (error) { table->file->print_error(error, MYF(0)); - DBUG_RETURN(1); + goto error; } table->quick_keys.clear_all(); table->reginfo.join_tab=s; @@ -2633,7 +2634,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, { join->tables=0; // Don't use join->table my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0)); - DBUG_RETURN(1); + goto error; } s->key_dependent= s->dependent; } @@ -2643,7 +2644,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, if (update_ref_and_keys(join->thd, keyuse_array, stat, join->tables, conds, join->cond_equal, ~outer_join, join->select_lex, &sargables)) - DBUG_RETURN(1); + goto error; /* Read tables with 0 or 1 rows (system tables) */ join->const_table_map= 0; @@ -2659,7 +2660,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, if ((tmp=join_read_const_table(s, p_pos))) { if (tmp > 0) - DBUG_RETURN(1); // Fatal error + goto error; // Fatal error } else found_const_table_map|= s->table->map; @@ -2731,7 +2732,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, if ((tmp= join_read_const_table(s, join->positions+const_count-1))) { if (tmp > 0) - DBUG_RETURN(1); // Fatal error + goto error; // Fatal error } else found_const_table_map|= table->map; @@ -2780,12 +2781,12 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, set_position(join,const_count++,s,start_keyuse); if (create_ref_for_key(join, s, start_keyuse, found_const_table_map)) - DBUG_RETURN(1); + goto error; if ((tmp=join_read_const_table(s, join->positions+const_count-1))) { if (tmp > 0) - DBUG_RETURN(1); // Fatal error + goto error; // Fatal error } else found_const_table_map|= table->map; @@ -2862,7 +2863,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, *s->on_expr_ref ? *s->on_expr_ref : conds, 1, &error); if (!select) - DBUG_RETURN(1); + goto error; records= get_quick_record_count(join->thd, select, s->table, &s->const_keys, join->row_limit); s->quick=select->quick; @@ -2908,7 +2909,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, { optimize_keyuse(join, keyuse_array); if (choose_plan(join, all_table_map & ~join->const_table_map)) - DBUG_RETURN(TRUE); + goto error; } else { @@ -2918,6 +2919,17 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, } /* Generate an execution plan from the found optimal join order. */ DBUG_RETURN(join->thd->killed || get_best_combination(join)); + +error: + /* + Need to clean up join_tab from TABLEs in case of error. + They won't get cleaned up by JOIN::cleanup() because JOIN::join_tab + may not be assigned yet by this function (which is building join_tab). + Dangling TABLE::reginfo.join_tab may cause part_of_refkey to choke. + */ + for (tables= tables_arg; tables; tables= tables->next_leaf) + tables->table->reginfo.join_tab= NULL; + DBUG_RETURN (1); } @@ -5717,48 +5729,42 @@ store_val_in_field(Field *field, Item *item, enum_check_fields check_flag) } -static bool -make_simple_join(JOIN *join,TABLE *tmp_table) +/** + @details Initialize a JOIN as a query execution plan + that accesses a single table via a table scan. + + @param parent contains JOIN_TAB and TABLE object buffers for this join + @param tmp_table temporary table + + @retval FALSE success + @retval TRUE error occurred +*/ +bool +JOIN::make_simple_join(JOIN *parent, TABLE *tmp_table) { - TABLE **tableptr; - JOIN_TAB *join_tab; - DBUG_ENTER("make_simple_join"); + DBUG_ENTER("JOIN::make_simple_join"); /* Reuse TABLE * and JOIN_TAB if already allocated by a previous call to this function through JOIN::exec (may happen for sub-queries). */ - if (!join->table_reexec) - { - if (!(join->table_reexec= (TABLE**) join->thd->alloc(sizeof(TABLE*)))) - DBUG_RETURN(TRUE); /* purecov: inspected */ - if (join->tmp_join) - join->tmp_join->table_reexec= join->table_reexec; - } - if (!join->join_tab_reexec) - { - if (!(join->join_tab_reexec= - (JOIN_TAB*) join->thd->alloc(sizeof(JOIN_TAB)))) - DBUG_RETURN(TRUE); /* purecov: inspected */ - if (join->tmp_join) - join->tmp_join->join_tab_reexec= join->join_tab_reexec; - } - tableptr= join->table_reexec; - join_tab= join->join_tab_reexec; - - join->join_tab=join_tab; - join->table=tableptr; tableptr[0]=tmp_table; - join->tables=1; - join->const_tables=0; - join->const_table_map=0; - join->tmp_table_param.field_count= join->tmp_table_param.sum_func_count= - join->tmp_table_param.func_count=0; - join->tmp_table_param.copy_field=join->tmp_table_param.copy_field_end=0; - join->first_record=join->sort_and_group=0; - join->send_records=(ha_rows) 0; - join->group=0; - join->row_limit=join->unit->select_limit_cnt; - join->do_send_rows = (join->row_limit) ? 1 : 0; + if (!parent->join_tab_reexec && + !(parent->join_tab_reexec= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) + DBUG_RETURN(TRUE); /* purecov: inspected */ + + join_tab= parent->join_tab_reexec; + table= &parent->table_reexec[0]; parent->table_reexec[0]= tmp_table; + tables= 1; + const_tables= 0; + const_table_map= 0; + tmp_table_param.field_count= tmp_table_param.sum_func_count= + tmp_table_param.func_count= 0; + tmp_table_param.copy_field= tmp_table_param.copy_field_end=0; + first_record= sort_and_group=0; + send_records= (ha_rows) 0; + group= 0; + row_limit= unit->select_limit_cnt; + do_send_rows= row_limit ? 1 : 0; join_tab->cache.buff=0; /* No caching */ join_tab->table=tmp_table; @@ -5775,7 +5781,7 @@ make_simple_join(JOIN *join,TABLE *tmp_table) join_tab->ref.key = -1; join_tab->not_used_in_distinct=0; join_tab->read_first_record= join_init_read_record; - join_tab->join=join; + join_tab->join= this; join_tab->ref.key_parts= 0; bzero((char*) &join_tab->read_record,sizeof(join_tab->read_record)); tmp_table->status=0; diff --git a/sql/sql_select.h b/sql/sql_select.h index eacd3d39905..43e26a6b4b2 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -402,9 +402,12 @@ public: cleared only at the end of the execution of the whole query and not caching allocations that occur in repetition at execution time will result in excessive memory usage. + Note: make_simple_join always creates an execution plan that accesses + a single table, thus it is sufficient to have a one-element array for + table_reexec. */ SORT_FIELD *sortorder; // make_unireg_sortorder() - TABLE **table_reexec; // make_simple_join() + TABLE *table_reexec[1]; // make_simple_join() JOIN_TAB *join_tab_reexec; // make_simple_join() /* end of allocation caching storage */ @@ -434,7 +437,7 @@ public: exec_tmp_table1= 0; exec_tmp_table2= 0; sortorder= 0; - table_reexec= 0; + table_reexec[0]= 0; join_tab_reexec= 0; thd= thd_arg; sum_funcs= sum_funcs2= 0; @@ -527,6 +530,8 @@ public: return (unit == &thd->lex->unit && (unit->fake_select_lex == 0 || select_lex == unit->fake_select_lex)); } +private: + bool make_simple_join(JOIN *join, TABLE *tmp_table); }; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 93240b7fd9a..8deb564e02b 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -286,7 +286,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"}, @@ -467,11 +467,18 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db, #ifndef NO_EMBEDDED_ACCESS_CHECKS uint col_access=thd->col_access; #endif + uint wild_length= 0; TABLE_LIST table_list; DBUG_ENTER("find_files"); - if (wild && !wild[0]) - wild=0; + if (wild) + { + if (!wild[0]) + wild= 0; + else + wild_length= strlen(wild); + } + bzero((char*) &table_list,sizeof(table_list)); @@ -536,8 +543,11 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db, { if (lower_case_table_names) { - if (wild_case_compare(files_charset_info, uname, wild)) - continue; + if (my_wildcmp(files_charset_info, + uname, uname + file_name_len, + wild, wild + wild_length, + wild_prefix, wild_one,wild_many)) + continue; } else if (wild_compare(uname, wild, 0)) continue; @@ -1589,21 +1599,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; @@ -1624,7 +1638,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('.'); @@ -3776,7 +3790,18 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables, table->field[4]->store((longlong) count, TRUE); field->sql_type(type); 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); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 4b2450c0093..f2c5b2750ef 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -71,25 +71,22 @@ bool String::realloc(uint32 alloc_length) uint32 len= ALIGN_SIZE(alloc_length+1); if (alloced) { - if ((new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) - { - Ptr=new_ptr; - Alloced_length=len; - } - else - return TRUE; // Signal error + if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME)))) + return TRUE; // Signal error } else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME)))) { + if (str_length > len - 1) + str_length= 0; if (str_length) // Avoid bugs in memcpy on AIX memcpy(new_ptr,Ptr,str_length); new_ptr[str_length]=0; - Ptr=new_ptr; - Alloced_length=len; alloced=1; } else return TRUE; // Signal error + Ptr= new_ptr; + Alloced_length= len; } Ptr[alloc_length]=0; // This make other funcs shorter return FALSE; @@ -115,7 +112,7 @@ bool String::set_real(double num,uint decimals, CHARSET_INFO *cs) str_charset=cs; if (decimals >= NOT_FIXED_DEC) { - uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME + uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); } #ifdef HAVE_FCONVERT @@ -667,7 +664,7 @@ void String::qs_append(const char *str, uint32 len) void String::qs_append(double d) { char *buff = Ptr + str_length; - str_length+= my_sprintf(buff, (buff, "%.14g", d)); + str_length+= my_sprintf(buff, (buff, "%.15g", d)); } void String::qs_append(double *d) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 45e55c6770b..7b76d9d6c56 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3322,7 +3322,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; } } @@ -4306,7 +4306,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; } @@ -4444,8 +4451,8 @@ send_result_message: switch (result_code) { case HA_ADMIN_NOT_IMPLEMENTED: { - char buf[ERRMSGSIZE+20]; - uint length=my_snprintf(buf, ERRMSGSIZE, + char buf[MYSQL_ERRMSG_SIZE]; + uint length=my_snprintf(buf, sizeof(buf), ER(ER_CHECK_NOT_IMPLEMENTED), operator_name); protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(buf, length, system_charset_info); @@ -4454,8 +4461,8 @@ send_result_message: case HA_ADMIN_NOT_BASE_TABLE: { - char buf[ERRMSGSIZE+20]; - uint length= my_snprintf(buf, ERRMSGSIZE, + char buf[MYSQL_ERRMSG_SIZE]; + uint length= my_snprintf(buf, sizeof(buf), ER(ER_BAD_TABLE_ERROR), table_name); protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(buf, length, system_charset_info); @@ -4582,11 +4589,12 @@ send_result_message: case HA_ADMIN_NEEDS_UPGRADE: case HA_ADMIN_NEEDS_ALTER: { - char buf[ERRMSGSIZE]; + char buf[MYSQL_ERRMSG_SIZE]; uint length; protocol->store(STRING_WITH_LEN("error"), system_charset_info); - length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name); + length=my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE), + table->table_name); protocol->store(buf, length, system_charset_info); fatal_error=1; break; @@ -4594,8 +4602,8 @@ send_result_message: default: // Probably HA_ADMIN_INTERNAL_ERROR { - char buf[ERRMSGSIZE+20]; - uint length=my_snprintf(buf, ERRMSGSIZE, + char buf[MYSQL_ERRMSG_SIZE]; + uint length=my_snprintf(buf, sizeof(buf), "Unknown - internal error %d during operation", result_code); protocol->store(STRING_WITH_LEN("error"), system_charset_info); @@ -4647,7 +4655,7 @@ err: bool mysql_backup_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("mysql_backup_table"); - WARN_DEPRECATED(thd, "5.2", "BACKUP TABLE", + WARN_DEPRECATED(thd, "6.0", "BACKUP TABLE", "MySQL Administrator (mysqldump, mysql)"); DBUG_RETURN(mysql_admin_table(thd, table_list, 0, "backup", TL_READ, 0, 0, 0, 0, @@ -4658,7 +4666,7 @@ bool mysql_backup_table(THD* thd, TABLE_LIST* table_list) bool mysql_restore_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("mysql_restore_table"); - WARN_DEPRECATED(thd, "5.2", "RESTORE TABLE", + WARN_DEPRECATED(thd, "6.0", "RESTORE TABLE", "MySQL Administrator (mysqldump, mysql)"); DBUG_RETURN(mysql_admin_table(thd, table_list, 0, "restore", TL_WRITE, 1, 1, 0, diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 2de3a5d67a9..302624a0e33 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -526,9 +526,11 @@ int mysql_update(THD *thd, init_read_record(&info, thd, table, select, 0, 1, FALSE); updated= found= 0; - /* Generate an error when trying to set a NOT NULL field to NULL. */ - thd->count_cuted_fields= ignore ? CHECK_FIELD_WARN - : CHECK_FIELD_ERROR_FOR_NULL; + /* + Generate an error (in TRADITIONAL mode) or warning + when trying to set a NOT NULL field to NULL. + */ + thd->count_cuted_fields= CHECK_FIELD_WARN; thd->cuted_fields=0L; thd_proc_info(thd, "Updating"); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 816040aa323..58448f82d82 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 4bbee0ba696..34d3bbf5887 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4392,7 +4392,7 @@ create_table_option: | TYPE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; - WARN_DEPRECATED(yythd, "5.2", "TYPE=storage_engine", + WARN_DEPRECATED(yythd, "6.0", "TYPE=storage_engine", "'ENGINE=storage_engine'"); Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } @@ -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; } ; @@ -9261,6 +9264,11 @@ drop: THD *thd= YYTHD; LEX *lex= thd->lex; sp_name *spname; + if ($4.str && check_db_name(&$4)) + { + my_error(ER_WRONG_DB_NAME, MYF(0), $4.str); + MYSQL_YYABORT; + } if (lex->sphead) { my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"); @@ -9869,7 +9877,7 @@ show_param: | opt_full PLUGIN_SYM { LEX *lex= Lex; - WARN_DEPRECATED(yythd, "5.2", "SHOW PLUGIN", "'SHOW PLUGINS'"); + WARN_DEPRECATED(yythd, "6.0", "SHOW PLUGIN", "'SHOW PLUGINS'"); lex->sql_command= SQLCOM_SHOW_PLUGINS; if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS)) MYSQL_YYABORT; @@ -9938,7 +9946,7 @@ show_param: { LEX *lex=Lex; lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES; - WARN_DEPRECATED(yythd, "5.2", "SHOW TABLE TYPES", "'SHOW [STORAGE] ENGINES'"); + WARN_DEPRECATED(yythd, "6.0", "SHOW TABLE TYPES", "'SHOW [STORAGE] ENGINES'"); if (prepare_schema_table(YYTHD, lex, 0, SCH_ENGINES)) MYSQL_YYABORT; } @@ -9999,7 +10007,7 @@ show_param: my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); MYSQL_YYABORT; } - WARN_DEPRECATED(yythd, "5.2", "SHOW INNODB STATUS", "'SHOW ENGINE INNODB STATUS'"); + WARN_DEPRECATED(yythd, "6.0", "SHOW INNODB STATUS", "'SHOW ENGINE INNODB STATUS'"); } | MUTEX_SYM STATUS_SYM { @@ -10011,7 +10019,7 @@ show_param: my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), "InnoDB"); MYSQL_YYABORT; } - WARN_DEPRECATED(yythd, "5.2", "SHOW MUTEX STATUS", "'SHOW ENGINE INNODB MUTEX'"); + WARN_DEPRECATED(yythd, "6.0", "SHOW MUTEX STATUS", "'SHOW ENGINE INNODB MUTEX'"); } | opt_full PROCESSLIST_SYM { Lex->sql_command= SQLCOM_SHOW_PROCESSLIST;} @@ -10406,7 +10414,7 @@ load: | LOAD TABLE_SYM table_ident FROM MASTER_SYM { LEX *lex=Lex; - WARN_DEPRECATED(yythd, "5.2", "LOAD TABLE FROM MASTER", + WARN_DEPRECATED(yythd, "6.0", "LOAD TABLE FROM MASTER", "MySQL Administrator (mysqldump, mysql)"); if (lex->sphead) { @@ -10453,7 +10461,7 @@ load_data: | FROM MASTER_SYM { Lex->sql_command = SQLCOM_LOAD_MASTER_DATA; - WARN_DEPRECATED(yythd, "5.2", "LOAD DATA FROM MASTER", + WARN_DEPRECATED(yythd, "6.0", "LOAD DATA FROM MASTER", "mysqldump or future " "BACKUP/RESTORE DATABASE facility"); } @@ -12914,6 +12922,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 c4c12208719..7184f145339 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2984,11 +2984,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 eedac2fd582..954f0bc3c7b 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -228,16 +228,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; } @@ -612,17 +612,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; } |