diff options
author | Mats Kindahl <mats@sun.com> | 2010-04-21 08:15:10 +0200 |
---|---|---|
committer | Mats Kindahl <mats@sun.com> | 2010-04-21 08:15:10 +0200 |
commit | b5c45fb624c3d7d97dc394986a6b77165ebc1aeb (patch) | |
tree | 3f93fdd5f8cf3205b3c23f1a1ae8987e2e4d3a46 /sql | |
parent | c0817bacafacfd3199551a64acae8c6cb60dc238 (diff) | |
parent | 20f5c421e7a70fa4338da34ab123002cf9b00ad3 (diff) | |
download | mariadb-git-b5c45fb624c3d7d97dc394986a6b77165ebc1aeb.tar.gz |
Merging with mysql-trunk-bugfixing
Diffstat (limited to 'sql')
-rwxr-xr-x | sql/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sql/Makefile.am | 3 | ||||
-rw-r--r-- | sql/item.cc | 4 | ||||
-rw-r--r-- | sql/item.h | 7 | ||||
-rw-r--r-- | sql/item_create.cc | 23 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 153 | ||||
-rw-r--r-- | sql/item_strfunc.h | 12 | ||||
-rw-r--r-- | sql/log.cc | 115 | ||||
-rw-r--r-- | sql/log.h | 3 | ||||
-rw-r--r-- | sql/log_event.cc | 27 | ||||
-rw-r--r-- | sql/log_event_old.cc | 10 | ||||
-rw-r--r-- | sql/mdl.h | 8 | ||||
-rw-r--r-- | sql/mysqld.cc | 26 | ||||
-rw-r--r-- | sql/sha2.cc | 68 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 9 | ||||
-rw-r--r-- | sql/sp_head.cc | 11 | ||||
-rw-r--r-- | sql/sql_acl.cc | 4 | ||||
-rw-r--r-- | sql/sql_audit.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.cc | 167 | ||||
-rw-r--r-- | sql/sql_class.h | 4 | ||||
-rw-r--r-- | sql/sql_connect.cc | 10 | ||||
-rw-r--r-- | sql/sql_lex.cc | 4 | ||||
-rw-r--r-- | sql/sql_lex.h | 12 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 | ||||
-rw-r--r-- | sql/sql_string.cc | 10 | ||||
-rw-r--r-- | sql/sql_string.h | 1 | ||||
-rw-r--r-- | sql/sql_table.cc | 67 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 35 | ||||
-rw-r--r-- | sql/sys_vars.cc | 45 |
29 files changed, 650 insertions, 193 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 31110c5e201..396c8b1fd27 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -41,7 +41,7 @@ ENDIF() SET (SQL_SOURCE ../sql-common/client.c derror.cc des_key_file.cc discover.cc ../libmysql/errmsg.c field.cc field_conv.cc - filesort.cc gstream.cc + filesort.cc gstream.cc sha2.cc ha_partition.cc handler.cc hash_filo.cc hash_filo.h sql_plugin_services.h hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc diff --git a/sql/Makefile.am b/sql/Makefile.am index 696f608c879..93595a964eb 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -167,7 +167,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ sql_plugin.cc sql_binlog.cc \ sql_builtin.cc sql_tablespace.cc partition_info.cc \ sql_servers.cc event_parse_data.cc sql_signal.cc \ - rpl_handler.cc mdl.cc transaction.cc sql_audit.cc + rpl_handler.cc mdl.cc transaction.cc sql_audit.cc \ + sha2.cc nodist_mysqld_SOURCES = mini_client_errors.c pack.c client.c my_time.c my_user.c diff --git a/sql/item.cc b/sql/item.cc index 209d5aa0197..4199f8a409a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1186,7 +1186,9 @@ Item_splocal::Item_splocal(const LEX_STRING &sp_var_name, enum_field_types sp_var_type, uint pos_in_q, uint len_in_q) :Item_sp_variable(sp_var_name.str, sp_var_name.length), - m_var_idx(sp_var_idx), pos_in_query(pos_in_q), len_in_query(len_in_q) + m_var_idx(sp_var_idx), + limit_clause_param(FALSE), + pos_in_query(pos_in_q), len_in_query(len_in_q) { maybe_null= TRUE; diff --git a/sql/item.h b/sql/item.h index 4241074c659..11b4199da2c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1302,6 +1302,13 @@ class Item_splocal :public Item_sp_variable, Item_result m_result_type; enum_field_types m_field_type; public: + /* + Is this variable a parameter in LIMIT clause. + Used only during NAME_CONST substitution, to not append + NAME_CONST to the resulting query and thus not break + the slave. + */ + bool limit_clause_param; /* Position of this reference to SP variable in the statement (the statement itself is in sp_instr_stmt::m_query). diff --git a/sql/item_create.cc b/sql/item_create.cc index beb7b40dc18..5f30a10d1e0 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -1834,6 +1834,19 @@ protected: }; +class Create_func_sha2 : public Create_func_arg2 +{ +public: + virtual Item* create(THD *thd, Item *arg1, Item *arg2); + + static Create_func_sha2 s_singleton; + +protected: + Create_func_sha2() {} + virtual ~Create_func_sha2() {} +}; + + class Create_func_sign : public Create_func_arg1 { public: @@ -4363,6 +4376,15 @@ Create_func_sha::create(THD *thd, Item *arg1) } +Create_func_sha2 Create_func_sha2::s_singleton; + +Item* +Create_func_sha2::create(THD *thd, Item *arg1, Item *arg2) +{ + return new (thd->mem_root) Item_func_sha2(arg1, arg2); +} + + Create_func_sign Create_func_sign::s_singleton; Item* @@ -4973,6 +4995,7 @@ static Native_func_registry func_array[] = { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)}, { { C_STRING_WITH_LEN("SHA") }, BUILDER(Create_func_sha)}, { { C_STRING_WITH_LEN("SHA1") }, BUILDER(Create_func_sha)}, + { { C_STRING_WITH_LEN("SHA2") }, BUILDER(Create_func_sha2)}, { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)}, { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)}, { { C_STRING_WITH_LEN("SLEEP") }, BUILDER(Create_func_sleep)}, diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9ae15322265..32baae87c50 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -29,6 +29,8 @@ #pragma implementation // gcc: Class implementation #endif +/* May include caustic 3rd-party defs. Use early, so it can override nothing. */ +#include "sha2.h" #include "my_global.h" // HAVE_* @@ -94,9 +96,9 @@ String *Item_str_ascii_func::val_str(String *str) Used to generate a hexadecimal representation of a message digest. */ -static void array_to_hex(char *to, const char *str, uint len) +static void array_to_hex(char *to, const unsigned char *str, uint len) { - const char *str_end= str + len; + const unsigned char *str_end= str + len; for (; str != str_end; ++str) { *to++= _dig_vec_lower[((uchar) *str) >> 4]; @@ -175,7 +177,7 @@ String *Item_func_md5::val_str_ascii(String *str) null_value=1; return 0; } - array_to_hex((char *) str->ptr(), (const char*) digest, 16); + array_to_hex((char *) str->ptr(), digest, 16); str->length((uint) 32); return str; } @@ -216,7 +218,7 @@ String *Item_func_sha::val_str_ascii(String *str) if (!( str->alloc(SHA1_HASH_SIZE*2) || (mysql_sha1_result(&context,digest)))) { - array_to_hex((char *) str->ptr(), (const char*) digest, SHA1_HASH_SIZE); + array_to_hex((char *) str->ptr(), digest, SHA1_HASH_SIZE); str->length((uint) SHA1_HASH_SIZE*2); null_value=0; return str; @@ -240,6 +242,144 @@ void Item_func_sha::fix_length_and_dec() fix_length_and_charset(SHA1_HASH_SIZE * 2, default_charset()); } +String *Item_func_sha2::val_str(String *str) +{ + DBUG_ASSERT(fixed == 1); +#ifdef HAVE_OPENSSL + unsigned char digest_buf[SHA512_DIGEST_LENGTH]; + String *input_string; + unsigned char *input_ptr; + size_t input_len; + uint digest_length= 0; + + str->set_charset(&my_charset_bin); + + input_string= args[0]->val_str(str); + if (input_string == NULL) + { + null_value= TRUE; + return (String *) NULL; + } + + null_value= args[0]->null_value; + if (null_value) + return (String *) NULL; + + input_ptr= (unsigned char *) input_string->ptr(); + input_len= input_string->length(); + + switch ((uint) args[1]->val_int()) { +#ifndef OPENSSL_NO_SHA512 + case 512: + digest_length= SHA512_DIGEST_LENGTH; + (void) SHA512(input_ptr, input_len, digest_buf); + break; + case 384: + digest_length= SHA384_DIGEST_LENGTH; + (void) SHA384(input_ptr, input_len, digest_buf); + break; +#endif +#ifndef OPENSSL_NO_SHA256 + case 224: + digest_length= SHA224_DIGEST_LENGTH; + (void) SHA224(input_ptr, input_len, digest_buf); + break; + case 256: + case 0: // SHA-256 is the default + digest_length= SHA256_DIGEST_LENGTH; + (void) SHA256(input_ptr, input_len, digest_buf); + break; +#endif + default: + if (!args[1]->const_item()) + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WRONG_PARAMETERS_TO_NATIVE_FCT, + ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + null_value= TRUE; + return NULL; + } + + /* + Since we're subverting the usual String methods, we must make sure that + the destination has space for the bytes we're about to write. + */ + str->realloc((uint) digest_length*2 + 1); /* Each byte as two nybbles */ + + /* Convert the large number to a string-hex representation. */ + array_to_hex((char *) str->ptr(), digest_buf, digest_length); + + /* We poked raw bytes in. We must inform the the String of its length. */ + str->length((uint) digest_length*2); /* Each byte as two nybbles */ + + null_value= FALSE; + return str; + +#else + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); + null_value= TRUE; + return (String *) NULL; +#endif +} + + +void Item_func_sha2::fix_length_and_dec() +{ + maybe_null = 1; + max_length = 0; + +#if defined(HAVE_OPENSSL) + int sha_variant= args[1]->const_item() ? args[1]->val_int() : 512; + + switch (sha_variant) { +#ifndef OPENSSL_NO_SHA512 + case 512: + max_length= SHA512_DIGEST_LENGTH*2; + break; + case 384: + max_length= SHA384_DIGEST_LENGTH*2; + break; +#endif +#ifndef OPENSSL_NO_SHA256 + case 256: + case 0: // SHA-256 is the default + max_length= SHA256_DIGEST_LENGTH*2; + break; + case 224: + max_length= SHA224_DIGEST_LENGTH*2; + break; +#endif + default: + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WRONG_PARAMETERS_TO_NATIVE_FCT, + ER(ER_WRONG_PARAMETERS_TO_NATIVE_FCT), "sha2"); + } + + /* + The SHA2() function treats its parameter as being a case sensitive. + Thus we set binary collation on it so different instances of SHA2() + will be compared properly. + */ + + args[0]->collation.set( + get_charset_by_csname( + args[0]->collation.collation->csname, + MY_CS_BINSORT, + MYF(0)), + DERIVATION_COERCIBLE); +#else + push_warning_printf(current_thd, + MYSQL_ERROR::WARN_LEVEL_WARN, + ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), + "sha2", "--with-ssl"); +#endif +} /* Implementation of AES encryption routines */ @@ -510,7 +650,6 @@ String *Item_func_des_encrypt::val_str(String *str) return 0; // ENCRYPT(NULL) == NULL if ((res_length=res->length()) == 0) return &my_empty_string; - if (arg_count == 1) { /* Protect against someone doing FLUSH DES_KEY_FILE */ @@ -583,7 +722,7 @@ error: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_encrypt","--with-openssl"); + "des_encrypt", "--with-ssl"); #endif /* HAVE_OPENSSL */ null_value=1; return 0; @@ -661,7 +800,7 @@ wrong_key: #else push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_WARN, ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), - "des_decrypt","--with-openssl"); + "des_decrypt", "--with-ssl"); #endif /* HAVE_OPENSSL */ null_value=1; return 0; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index e3008a5daab..7b7f8d3308a 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -82,6 +82,18 @@ public: const char *func_name() const { return "sha"; } }; +class Item_func_sha2 :public Item_str_func +{ +public: + Item_func_sha2(Item *a, Item *b) :Item_str_func(a, b) + { + collation.set(&my_charset_bin); + } + String *val_str(String *); + void fix_length_and_dec(); + const char *func_name() const { return "sha2"; } +}; + class Item_func_aes_encrypt :public Item_str_func { public: diff --git a/sql/log.cc b/sql/log.cc index 551072d2d47..18f812d96bf 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1576,7 +1576,7 @@ binlog_truncate_trx_cache(THD *thd, binlog_cache_mngr *cache_mngr, bool all) inside a transaction, we reset the transaction cache. */ thd->binlog_remove_pending_rows_event(TRUE, is_transactional); - if (all || !thd->in_multi_stmt_transaction()) + if (ending_trans(thd, all)) { if (cache_mngr->trx_cache.has_incident()) error= mysql_bin_log.write_incident(thd, TRUE); @@ -1640,7 +1640,10 @@ binlog_flush_stmt_cache(THD *thd, binlog_cache_mngr *cache_mngr) */ bool const is_transactional= FALSE; IO_CACHE *cache_log= &cache_mngr->stmt_cache.cache_log; - thd->binlog_flush_pending_rows_event(TRUE, is_transactional); + + if (thd->binlog_flush_pending_rows_event(TRUE, is_transactional)) + DBUG_RETURN(1); + Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0); if ((error= mysql_bin_log.write(thd, cache_log, &qev, cache_mngr->stmt_cache.has_incident()))) @@ -1679,12 +1682,11 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) DBUG_ENTER("binlog_commit"); binlog_cache_mngr *const cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); - bool const in_transaction= thd->in_multi_stmt_transaction(); DBUG_PRINT("debug", ("all: %d, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s", all, - YESNO(in_transaction), + YESNO(thd->in_multi_stmt_transaction()), YESNO(thd->transaction.all.modified_non_trans_table), YESNO(thd->transaction.stmt.modified_non_trans_table))); @@ -1708,7 +1710,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) - We are in a transaction and a full transaction is committed. Otherwise, we accumulate the changes. */ - if (!in_transaction || all) + if (ending_trans(thd, all)) { Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0); error= binlog_flush_trx_cache(thd, cache_mngr, &qev); @@ -1786,29 +1788,28 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all) { /* We flush the cache wrapped in a beging/rollback if: - . aborting a transcation that modified a non-transactional table or; - . aborting a statement that modified both transactional and - non-transctional tables but which is not in the boundaries of any - transaction; + . aborting a single or multi-statement transaction and; + . the format is STMT and non-trans engines were updated or; . the OPTION_KEEP_LOG is activate. */ - if (thd->variables.binlog_format == BINLOG_FORMAT_STMT && - ((all && thd->transaction.all.modified_non_trans_table) || - (!all && thd->transaction.stmt.modified_non_trans_table && - !thd->in_multi_stmt_transaction()) || - (thd->variables.option_bits & OPTION_KEEP_LOG))) + if (ending_trans(thd, all) && + ((thd->variables.option_bits & OPTION_KEEP_LOG) || + (trans_has_updated_non_trans_table(thd) && + thd->variables.binlog_format == BINLOG_FORMAT_STMT))) { Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE, TRUE, 0); error= binlog_flush_trx_cache(thd, cache_mngr, &qev); } /* - Otherwise, we simply truncate the cache as there is no change on - non-transactional tables as follows. + Truncate the cache if: + . aborting a single or multi-statement transaction or; + . the OPTION_KEEP_LOG is not activate and; + . the format is not STMT or no non-trans were updated. */ - else if (all || (!all && - (!thd->transaction.stmt.modified_non_trans_table || - !thd->in_multi_stmt_transaction() || - thd->variables.binlog_format != BINLOG_FORMAT_STMT))) + else if (ending_trans(thd, all) || + (!(thd->variables.option_bits & OPTION_KEEP_LOG) && + ((!stmt_has_updated_non_trans_table(thd) || + thd->variables.binlog_format != BINLOG_FORMAT_STMT)))) error= binlog_truncate_trx_cache(thd, cache_mngr, all); } @@ -1906,7 +1907,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) non-transactional table. Otherwise, truncate the binlog cache starting from the SAVEPOINT command. */ - if (unlikely(thd->transaction.all.modified_non_trans_table || + if (unlikely(trans_has_updated_non_trans_table(thd) || (thd->variables.option_bits & OPTION_KEEP_LOG))) { int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); @@ -4189,7 +4190,7 @@ bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param) } /** - This function checks if a transactional talbe was updated by the + This function checks if a transactional table was updated by the current transaction. @param thd The client thread that executed the current statement. @@ -4202,11 +4203,11 @@ trans_has_updated_trans_table(const THD* thd) binlog_cache_mngr *const cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); - return (cache_mngr ? my_b_tell (&cache_mngr->trx_cache.cache_log) : 0); + return (cache_mngr ? !cache_mngr->trx_cache.empty() : 0); } /** - This function checks if a transactional talbe was updated by the + This function checks if a transactional table was updated by the current statement. @param thd The client thread that executed the current statement. @@ -4218,7 +4219,8 @@ stmt_has_updated_trans_table(const THD *thd) { Ha_trx_info *ha_info; - for (ha_info= thd->transaction.stmt.ha_list; ha_info; ha_info= ha_info->next()) + for (ha_info= thd->transaction.stmt.ha_list; ha_info; + ha_info= ha_info->next()) { if (ha_info->is_trx_read_write() && ha_info->ht() != binlog_hton) return (TRUE); @@ -4228,11 +4230,14 @@ stmt_has_updated_trans_table(const THD *thd) /** This function checks if either a trx-cache or a non-trx-cache should - be used. If @c bin_log_direct_non_trans_update is active, the cache - to be used depends on the flag @c is_transactional. + be used. If @c bin_log_direct_non_trans_update is active or the format + is either MIXED or ROW, the cache to be used depends on the flag @c + is_transactional. - Otherswise, we use the trx-cache if either the @c is_transactional - is true or the trx-cache is not empty. + On the other hand, if binlog_format is STMT or direct option is + OFF, the trx-cache should be used if and only if the statement is + transactional or the trx-cache is not empty. Otherwise, the + non-trx-cache should be used. @param thd The client thread. @param is_transactional The changes are related to a trx-table. @@ -4245,8 +4250,52 @@ bool use_trans_cache(const THD* thd, bool is_transactional) (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); return - (thd->variables.binlog_direct_non_trans_update ? is_transactional : - (cache_mngr->trx_cache.empty() && !is_transactional ? FALSE : TRUE)); + ((thd->variables.binlog_format != BINLOG_FORMAT_STMT || + thd->variables.binlog_direct_non_trans_update) ? is_transactional : + (is_transactional || !cache_mngr->trx_cache.empty())); +} + +/** + This function checks if a transaction, either a multi-statement + or a single statement transaction is about to commit or not. + + @param thd The client thread that executed the current statement. + @param all Committing a transaction (i.e. TRUE) or a statement + (i.e. FALSE). + @return + @c true if committing a transaction, otherwise @c false. +*/ +bool ending_trans(THD* thd, const bool all) +{ + return (all || (!all && !thd->in_multi_stmt_transaction())); +} + +/** + This function checks if a non-transactional table was updated by + the current transaction. + + @param thd The client thread that executed the current statement. + @return + @c true if a non-transactional table was updated, @c false + otherwise. +*/ +bool trans_has_updated_non_trans_table(const THD* thd) +{ + return (thd->transaction.all.modified_non_trans_table || + thd->transaction.stmt.modified_non_trans_table); +} + +/** + This function checks if a non-transactional table was updated by the + current statement. + + @param thd The client thread that executed the current statement. + @return + @c true if a non-transactional table was updated, @c false otherwise. +*/ +bool stmt_has_updated_non_trans_table(const THD* thd) +{ + return (thd->transaction.stmt.modified_non_trans_table); } /* @@ -4531,7 +4580,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, { set_write_error(thd); if (check_write_error(thd) && cache_data && - thd->transaction.stmt.modified_non_trans_table) + stmt_has_updated_non_trans_table(thd)) cache_data->set_incident(); DBUG_RETURN(1); } @@ -4732,7 +4781,7 @@ unlock: { set_write_error(thd); if (check_write_error(thd) && cache_data && - thd->transaction.stmt.modified_non_trans_table) + stmt_has_updated_non_trans_table(thd)) cache_data->set_incident(); } } diff --git a/sql/log.h b/sql/log.h index 71c27f50f78..12e02969485 100644 --- a/sql/log.h +++ b/sql/log.h @@ -26,6 +26,9 @@ class Format_description_log_event; bool trans_has_updated_trans_table(const THD* thd); bool stmt_has_updated_trans_table(const THD *thd); bool use_trans_cache(const THD* thd, bool is_transactional); +bool ending_trans(THD* thd, const bool all); +bool trans_has_updated_non_trans_table(const THD* thd); +bool stmt_has_updated_non_trans_table(const THD* thd); /* Transaction Coordinator log - a base abstract class diff --git a/sql/log_event.cc b/sql/log_event.cc index a1f8a791c49..3a52b72909a 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -679,6 +679,7 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) server_id= thd->server_id; when= thd->start_time; cache_type= (using_trans || stmt_has_updated_trans_table(thd) + || thd->thread_specific_used ? Log_event::EVENT_TRANSACTIONAL_CACHE : Log_event::EVENT_STMT_CACHE); } @@ -1729,8 +1730,8 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr, { uint32 tmp= uint3korr(ptr); int part; - char buf[10]; - char *pos= &buf[10]; + char buf[11]; + char *pos= &buf[10]; // start from '\0' to the beginning /* Copied from field.cc */ *pos--=0; // End NULL @@ -2470,6 +2471,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, */ LEX *lex= thd->lex; bool implicit_commit= FALSE; + bool force_trans= FALSE; cache_type= Log_event::EVENT_INVALID_CACHE; switch (lex->sql_command) { @@ -2483,14 +2485,16 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, implicit_commit= TRUE; break; case SQLCOM_DROP_TABLE: - implicit_commit= !(lex->drop_temporary && thd->in_multi_stmt_transaction()); + force_trans= lex->drop_temporary && thd->in_multi_stmt_transaction(); + implicit_commit= !force_trans; break; case SQLCOM_ALTER_TABLE: case SQLCOM_CREATE_TABLE: - implicit_commit= !((lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && - thd->in_multi_stmt_transaction()) && - !(lex->select_lex.item_list.elements && - thd->is_current_stmt_binlog_format_row()); + force_trans= (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && + thd->in_multi_stmt_transaction(); + implicit_commit= !force_trans && + !(lex->select_lex.item_list.elements && + thd->is_current_stmt_binlog_format_row()); break; case SQLCOM_SET_OPTION: implicit_commit= (lex->autocommit ? TRUE : FALSE); @@ -2548,7 +2552,8 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, } else { - cache_type= (using_trans || stmt_has_updated_trans_table(thd) + cache_type= ((using_trans || stmt_has_updated_trans_table(thd) || + force_trans || thd->thread_specific_used) ? Log_event::EVENT_TRANSACTIONAL_CACHE : Log_event::EVENT_STMT_CACHE); } @@ -7733,12 +7738,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); error= 0; } - - if (!use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - thd->variables.option_bits|= OPTION_KEEP_LOG; - } } // if (table) diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index a80e8f4b1a2..f6c5b5d1023 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -241,11 +241,6 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info DBUG_EXECUTE_IF("stop_slave_middle_group", const_cast<Relay_log_info*>(rli)->abort_slave= 1;); error= do_after_row_operations(table, error); - if (!ev->use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - ev_thd->variables.option_bits|= OPTION_KEEP_LOG; - } } if (error) @@ -1683,11 +1678,6 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli) DBUG_EXECUTE_IF("stop_slave_middle_group", const_cast<Relay_log_info*>(rli)->abort_slave= 1;); error= do_after_row_operations(rli, error); - if (!use_trans_cache()) - { - DBUG_PRINT("info", ("Marked that we need to keep log")); - thd->variables.option_bits|= OPTION_KEEP_LOG; - } } // if (table) if (error) diff --git a/sql/mdl.h b/sql/mdl.h index 124151798ae..2fb21a5aa18 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -15,6 +15,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(__IBMC__) || defined(__IBMCPP__) +/* Further down, "next_in_lock" and "next_in_context" have the same type, + and in "sql_plist.h" this leads to an identical signature, which causes + problems in function overloading. +*/ +#pragma namemangling(v5) +#endif + #include "sql_plist.h" #include <my_sys.h> diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2bc47849915..b35e2545a18 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -957,7 +957,9 @@ static void openssl_lock(int, openssl_lock_t *, const char *, int); static unsigned long openssl_id_function(); #endif char *des_key_file; +#ifndef EMBEDDED_LIBRARY struct st_VioSSLFd *ssl_acceptor_fd; +#endif #endif /* HAVE_OPENSSL */ /** @@ -1003,8 +1005,8 @@ static void clean_up_mutexes(void); static void wait_for_signal_thread_to_end(void); static void create_pid_file(); static void mysqld_exit(int exit_code) __attribute__((noreturn)); -static void end_ssl(); #endif +static void end_ssl(); #ifndef EMBEDDED_LIBRARY @@ -1524,9 +1526,7 @@ void clean_up(bool print_message) #endif delete binlog_filter; delete rpl_filter; -#ifndef EMBEDDED_LIBRARY end_ssl(); -#endif vio_end(); #ifdef USE_REGEX my_regex_end(); @@ -3916,11 +3916,10 @@ static void openssl_lock(int mode, openssl_lock_t *lock, const char *file, #endif /* HAVE_OPENSSL */ -#ifndef EMBEDDED_LIBRARY - static void init_ssl() { #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY if (opt_use_ssl) { enum enum_ssl_init_error error= SSL_INITERR_NOERROR; @@ -3942,6 +3941,9 @@ static void init_ssl() { have_ssl= SHOW_OPTION_DISABLED; } +#else + have_ssl= SHOW_OPTION_DISABLED; +#endif /* ! EMBEDDED_LIBRARY */ if (des_key_file) load_des_key_file(des_key_file); #endif /* HAVE_OPENSSL */ @@ -3951,16 +3953,16 @@ static void init_ssl() static void end_ssl() { #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY if (ssl_acceptor_fd) { free_vio_ssl_acceptor_fd(ssl_acceptor_fd); ssl_acceptor_fd= 0; } +#endif /* ! EMBEDDED_LIBRARY */ #endif /* HAVE_OPENSSL */ } -#endif /* EMBEDDED_LIBRARY */ - static int init_server_components() { @@ -6434,7 +6436,7 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) return 0; } -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Functions relying on CTX */ static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) { @@ -6690,7 +6692,7 @@ static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) return 0; } -#endif /* HAVE_OPENSSL */ +#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ /* @@ -6781,6 +6783,7 @@ SHOW_VAR status_vars[]= { {"Sort_rows", (char*) offsetof(STATUS_VAR, filesort_rows), SHOW_LONG_STATUS}, {"Sort_scan", (char*) offsetof(STATUS_VAR, filesort_scan_count), SHOW_LONG_STATUS}, #ifdef HAVE_OPENSSL +#ifndef EMBEDDED_LIBRARY {"Ssl_accept_renegotiates", (char*) &show_ssl_ctx_sess_accept_renegotiate, SHOW_FUNC}, {"Ssl_accepts", (char*) &show_ssl_ctx_sess_accept, SHOW_FUNC}, {"Ssl_callback_cache_hits", (char*) &show_ssl_ctx_sess_cb_hits, SHOW_FUNC}, @@ -6804,6 +6807,7 @@ SHOW_VAR status_vars[]= { {"Ssl_verify_depth", (char*) &show_ssl_get_verify_depth, SHOW_FUNC}, {"Ssl_verify_mode", (char*) &show_ssl_get_verify_mode, SHOW_FUNC}, {"Ssl_version", (char*) &show_ssl_get_version, SHOW_FUNC}, +#endif #endif /* HAVE_OPENSSL */ {"Table_locks_immediate", (char*) &locks_immediate, SHOW_LONG}, {"Table_locks_waited", (char*) &locks_waited, SHOW_LONG}, @@ -7103,8 +7107,10 @@ static int mysql_init_variables(void) #endif #ifdef HAVE_OPENSSL des_key_file = 0; +#ifndef EMBEDDED_LIBRARY ssl_acceptor_fd= 0; -#endif +#endif /* ! EMBEDDED_LIBRARY */ +#endif /* HAVE_OPENSSL */ #ifdef HAVE_SMEM shared_memory_base_name= default_shared_memory_base_name; #endif diff --git a/sql/sha2.cc b/sql/sha2.cc new file mode 100644 index 00000000000..1a9de86f2e0 --- /dev/null +++ b/sql/sha2.cc @@ -0,0 +1,68 @@ +/* Copyright (C) 2007 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +/** + @file + A compatibility layer to our built-in SSL implementation, to mimic the + oft-used external library, OpenSSL. +*/ + +#include <my_global.h> +#include <sha2.h> + +#ifdef HAVE_YASSL + +/* + If TaoCrypt::SHA512 or ::SHA384 are not defined (but ::SHA256 is), it's + probably that neither of config.h's SIZEOF_LONG or SIZEOF_LONG_LONG are + 64 bits long. At present, both OpenSSL and YaSSL require 64-bit integers + for SHA-512. (The SIZEOF_* definitions come from autoconf's config.h .) +*/ + +# define GEN_YASSL_SHA2_BRIDGE(size) \ +unsigned char* SHA##size(const unsigned char *input_ptr, size_t input_length, \ + char unsigned *output_ptr) { \ + TaoCrypt::SHA##size hasher; \ + \ + hasher.Update(input_ptr, input_length); \ + hasher.Final(output_ptr); \ + return(output_ptr); \ +} + + +/** + @fn SHA512 + @fn SHA384 + @fn SHA256 + @fn SHA224 + + Instantiate an hash object, fill in the cleartext value, compute the digest, + and extract the result from the object. + + (Generate the functions. See similar .h code for the prototypes.) +*/ +# ifndef OPENSSL_NO_SHA512 +GEN_YASSL_SHA2_BRIDGE(512); +GEN_YASSL_SHA2_BRIDGE(384); +# else +# warning Some SHA2 functionality is missing. See OPENSSL_NO_SHA512. +# endif +GEN_YASSL_SHA2_BRIDGE(256); +GEN_YASSL_SHA2_BRIDGE(224); + +# undef GEN_YASSL_SHA2_BRIDGE + +#endif /* HAVE_YASSL */ diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 21f5dd32663..ed1ed47b70f 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6327,3 +6327,12 @@ ER_LOCK_ABORTED ER_DATA_OUT_OF_RANGE 22003 eng "%s value is out of range in '%s'" + +ER_WRONG_SPVAR_TYPE_IN_LIMIT + eng "A variable of a non-integer type in LIMIT clause" + +ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE + eng "Mixing self-logging and non-self-logging engines in a statement is unsafe." + +ER_BINLOG_UNSAFE_MIXED_STATEMENT + eng "Statements that read from both transactional (or a temporary table of any engine type) and non-transactional tables and write to any of them are unsafe." diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 62d53888149..c91ba2a68b4 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -978,11 +978,20 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) res|= qbuf.append(cur + prev_pos, (*splocal)->pos_in_query - prev_pos); prev_pos= (*splocal)->pos_in_query + (*splocal)->len_in_query; + res|= (*splocal)->fix_fields(thd, (Item **) splocal); + if (res) + break; + + if ((*splocal)->limit_clause_param) + { + res|= qbuf.append_ulonglong((*splocal)->val_uint()); + continue; + } + /* append the spvar substitute */ res|= qbuf.append(STRING_WITH_LEN(" NAME_CONST('")); res|= qbuf.append((*splocal)->m_name.str, (*splocal)->m_name.length); res|= qbuf.append(STRING_WITH_LEN("',")); - res|= (*splocal)->fix_fields(thd, (Item **) splocal); if (res) break; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index a5e5b4ec2a1..f8be3ff6d4a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -929,7 +929,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, if (acl_user) { /* OK. User found and password checked continue validation */ -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) Vio *vio=thd->net.vio; SSL *ssl= (SSL*) vio->ssl_arg; X509 *cert; @@ -946,7 +946,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, case SSL_TYPE_NONE: // SSL is not required user_access= acl_user->access; break; -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) case SSL_TYPE_ANY: // Any kind of SSL is ok if (vio_type(vio) == VIO_TYPE_SSL) user_access= acl_user->access; diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 39ab33abfe6..7d269d455a9 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -65,6 +65,7 @@ static void general_class_handler(THD *thd, uint event_subtype, va_list ap) { mysql_event_general event; event.event_class= MYSQL_AUDIT_GENERAL_CLASS; + event.event_subclass= event_subtype; event.general_error_code= va_arg(ap, int); event.general_thread_id= thd ? thd->thread_id : 0; event.general_time= va_arg(ap, time_t); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 256f2fa730a..88f67175d02 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3601,13 +3601,33 @@ int THD::decide_logging_format(TABLE_LIST *tables) capabilities, and one with the intersection of all the engine capabilities. */ + handler::Table_flags flags_write_some_set= 0; handler::Table_flags flags_some_set= 0; - handler::Table_flags flags_all_set= + handler::Table_flags flags_write_all_set= HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE; - my_bool multi_engine= FALSE; - my_bool mixed_engine= FALSE; - my_bool all_trans_engines= TRUE; + /* + If different types of engines are about to be updated. + For example: Innodb and Falcon; Innodb and MyIsam. + */ + my_bool multi_write_engine= FALSE; + /* + If different types of engines are about to be accessed + and any of them is about to be updated. For example: + Innodb and Falcon; Innodb and MyIsam. + */ + my_bool multi_access_engine= FALSE; + /* + If non-transactional and transactional engines are about + to be accessed and any of them is about to be updated. + For example: Innodb and MyIsam. + */ + my_bool trans_non_trans_access_engines= FALSE; + /* + If all engines that are about to be updated are + transactional. + */ + my_bool all_trans_write_engines= TRUE; TABLE* prev_write_table= NULL; TABLE* prev_access_table= NULL; @@ -3633,32 +3653,111 @@ int THD::decide_logging_format(TABLE_LIST *tables) continue; if (table->table->s->table_category == TABLE_CATEGORY_PERFORMANCE) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_TABLE); + handler::Table_flags const flags= table->table->file->ha_table_flags(); + DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", + table->table_name, flags)); if (table->lock_type >= TL_WRITE_ALLOW_WRITE) { - handler::Table_flags const flags= table->table->file->ha_table_flags(); - DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", - table->table_name, flags)); if (prev_write_table && prev_write_table->file->ht != table->table->file->ht) - multi_engine= TRUE; - all_trans_engines= all_trans_engines && - table->table->file->has_transactions(); + multi_write_engine= TRUE; + /* + Every temporary table must be always written to the binary + log in transaction boundaries and as such we artificially + classify them as transactional. + + Indirectly, this avoids classifying a temporary table created + on a non-transactional engine as unsafe when it is modified + after any transactional table: + + BEGIN; + INSERT INTO innodb_t VALUES (1); + INSERT INTO myisam_t_temp VALUES (1); + COMMIT; + + BINARY LOG: + + BEGIN; + INSERT INTO innodb_t VALUES (1); + INSERT INTO myisam_t_temp VALUES (1); + COMMIT; + */ + all_trans_write_engines= all_trans_write_engines && + (table->table->file->has_transactions() || + table->table->s->tmp_table); prev_write_table= table->table; - flags_all_set &= flags; - flags_some_set |= flags; + flags_write_all_set &= flags; + flags_write_some_set |= flags; + } + flags_some_set |= flags; + /* + The mixture of non-transactional and transactional tables must + identified and classified as unsafe. However, a temporary table + must be always handled as a transactional table. Based on that, + we have the following statements classified as mixed and by + consequence as unsafe: + + 1: INSERT INTO myisam_t SELECT * FROM innodb_t; + + 2: INSERT INTO innodb_t SELECT * FROM myisam_t; + + 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp; + + 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t; + + 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t; + + The following statements are not considered mixed and as such + are safe: + + 1: INSERT INTO innodb_t SELECT * FROM myisam_t_temp; + + 2: INSERT INTO myisam_t_temp SELECT * FROM innodb_t_temp; + */ + if (!trans_non_trans_access_engines && prev_access_table && + (lex->sql_command != SQLCOM_CREATE_TABLE || + (lex->sql_command == SQLCOM_CREATE_TABLE && + (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)))) + { + my_bool prev_trans; + my_bool act_trans; + if (prev_access_table->s->tmp_table || table->table->s->tmp_table) + { + prev_trans= prev_access_table->s->tmp_table ? TRUE : + prev_access_table->file->has_transactions(); + act_trans= table->table->s->tmp_table ? TRUE : + table->table->file->has_transactions(); + } + else + { + prev_trans= prev_access_table->file->has_transactions(); + act_trans= table->table->file->has_transactions(); + } + trans_non_trans_access_engines= (prev_trans != act_trans); + multi_access_engine= TRUE; } - if (prev_access_table && prev_access_table->file->ht != table->table->file->ht) - mixed_engine= mixed_engine || (prev_access_table->file->has_transactions() != - table->table->file->has_transactions()); prev_access_table= table->table; } + DBUG_PRINT("info", ("flags_write_all_set: 0x%llx", flags_write_all_set)); + DBUG_PRINT("info", ("flags_write_some_set: 0x%llx", flags_write_some_set)); + DBUG_PRINT("info", ("flags_some_set: 0x%llx", flags_some_set)); + DBUG_PRINT("info", ("multi_write_engine: %d", multi_write_engine)); + DBUG_PRINT("info", ("multi_access_engine: %d", multi_access_engine)); + DBUG_PRINT("info", ("trans_non_trans_access_engines: %d", + trans_non_trans_access_engines)); + + int error= 0; + int unsafe_flags; + /* Set the statement as unsafe if: . it is a mixed statement, i.e. access transactional and non-transactional - tables, and updates at least one; - or + tables, and update any of them; + + or: + . an early statement updated a transactional table; . and, the current statement updates a non-transactional table. @@ -3672,6 +3771,12 @@ int THD::decide_logging_format(TABLE_LIST *tables) 2: INSERT INTO innodb_t SELECT * FROM myisam_t; + 3: INSERT INTO myisam_t SELECT * FROM myisam_t_temp; + + 4: INSERT INTO myisam_t_temp SELECT * FROM myisam_t; + + 5: CREATE TEMPORARY TABLE myisam_t_temp SELECT * FROM mysiam_t; + are classified as unsafe to ensure that in mixed mode the execution is completely safe and equivalent to the row mode. Consider the following statements and sessions (connections) to understand the reason: @@ -3722,32 +3827,26 @@ int THD::decide_logging_format(TABLE_LIST *tables) isolation level but if we have pure repeatable read or serializable the lock history on the slave will be different from the master. */ - if (mixed_engine || - (trans_has_updated_trans_table(this) && !all_trans_engines)) + if (trans_non_trans_access_engines) + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MIXED_STATEMENT); + else if (trans_has_updated_trans_table(this) && !all_trans_write_engines) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS); - DBUG_PRINT("info", ("flags_all_set: 0x%llx", flags_all_set)); - DBUG_PRINT("info", ("flags_some_set: 0x%llx", flags_some_set)); - DBUG_PRINT("info", ("multi_engine: %d", multi_engine)); - - int error= 0; - int unsafe_flags; - /* If more than one engine is involved in the statement and at least one is doing it's own logging (is *self-logging*), the statement cannot be logged atomically, so we generate an error rather than allowing the binlog to become corrupt. */ - if (multi_engine && - (flags_some_set & HA_HAS_OWN_BINLOGGING)) - { + if (multi_write_engine && + (flags_write_some_set & HA_HAS_OWN_BINLOGGING)) my_error((error= ER_BINLOG_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE), MYF(0)); - } + else if (multi_access_engine && flags_some_set & HA_HAS_OWN_BINLOGGING) + lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE); /* both statement-only and row-only engines involved */ - if ((flags_all_set & (HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE)) == 0) + if ((flags_write_all_set & (HA_BINLOG_STMT_CAPABLE | HA_BINLOG_ROW_CAPABLE)) == 0) { /* 1. Error: Binary logging impossible since both row-incapable @@ -3756,7 +3855,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) my_error((error= ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE), MYF(0)); } /* statement-only engines involved */ - else if ((flags_all_set & HA_BINLOG_ROW_CAPABLE) == 0) + else if ((flags_write_all_set & HA_BINLOG_ROW_CAPABLE) == 0) { if (lex->is_stmt_row_injection()) { @@ -3804,7 +3903,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) */ my_error((error= ER_BINLOG_ROW_INJECTION_AND_STMT_MODE), MYF(0)); } - else if ((flags_all_set & HA_BINLOG_STMT_CAPABLE) == 0) + else if ((flags_write_all_set & HA_BINLOG_STMT_CAPABLE) == 0) { /* 5. Error: Cannot modify table that uses a storage engine @@ -3832,7 +3931,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) else { if (lex->is_stmt_unsafe() || lex->is_stmt_row_injection() - || (flags_all_set & HA_BINLOG_STMT_CAPABLE) == 0) + || (flags_write_all_set & HA_BINLOG_STMT_CAPABLE) == 0) { /* log in row format! */ set_current_stmt_binlog_format_row_if_mixed(); diff --git a/sql/sql_class.h b/sql/sql_class.h index 950db01d1cd..c75d91baada 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2531,11 +2531,11 @@ public: ("temporary_tables: %s, in_sub_stmt: %s, system_thread: %s", YESNO(temporary_tables), YESNO(in_sub_stmt), show_system_thread(system_thread))); - if ((temporary_tables == NULL) && (in_sub_stmt == 0)) + if (in_sub_stmt == 0) { if (variables.binlog_format == BINLOG_FORMAT_ROW) set_current_stmt_binlog_format_row(); - else + else if (temporary_tables == NULL) clear_current_stmt_binlog_format_row(); } DBUG_VOID_RETURN; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index cfcf1754581..e2d0977def7 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -36,7 +36,7 @@ // reset_host_errors #include "sql_acl.h" // acl_getroot, NO_ACCESS, SUPER_ACL -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Without SSL the handshake consists of one packet. This packet has both client capabilites and scrambled password. @@ -52,7 +52,7 @@ #define MIN_HANDSHAKE_SIZE 2 #else #define MIN_HANDSHAKE_SIZE 6 -#endif /* HAVE_OPENSSL */ +#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ /* Get structure for logging connection data for the current user @@ -654,6 +654,7 @@ bool init_new_connection_handler_thread() return 0; } +#ifndef EMBEDDED_LIBRARY /* Perform handshake, authorize client and update thd ACL variables. @@ -667,7 +668,6 @@ bool init_new_connection_handler_thread() > 0 error code (not sent to user) */ -#ifndef EMBEDDED_LIBRARY static int check_connection(THD *thd) { uint connect_errors= 0; @@ -749,7 +749,7 @@ static int check_connection(THD *thd) #ifdef HAVE_COMPRESS server_capabilites|= CLIENT_COMPRESS; #endif /* HAVE_COMPRESS */ -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) if (ssl_acceptor_fd) { server_capabilites |= CLIENT_SSL; /* Wow, SSL is available! */ @@ -827,7 +827,7 @@ static int check_connection(THD *thd) if (thd->client_capabilities & CLIENT_IGNORE_SPACE) thd->variables.sql_mode|= MODE_IGNORE_SPACE; -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) DBUG_PRINT("info", ("client capabilities: %lu", thd->client_capabilities)); if (thd->client_capabilities & CLIENT_SSL) { diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 6384aa575fe..13f85b24299 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -56,7 +56,9 @@ Query_tables_list::binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT] = ER_BINLOG_UNSAFE_UDF, ER_BINLOG_UNSAFE_SYSTEM_VARIABLE, ER_BINLOG_UNSAFE_SYSTEM_FUNCTION, - ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS + ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS, + ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE, + ER_BINLOG_UNSAFE_MIXED_STATEMENT, }; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index cb8a96ad2ed..85ae2697f21 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1161,6 +1161,18 @@ public: */ BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS, + /** + Mixing self-logging and non-self-logging engines in a statement + is unsafe. + */ + BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE, + + /** + Statements that read from both transactional and non-transactional + tables and write to any of them are unsafe. + */ + BINLOG_STMT_UNSAFE_MIXED_STATEMENT, + /* The last element of this enumeration type. */ BINLOG_STMT_UNSAFE_COUNT }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7d379ab34de..62a51a32ca2 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4157,7 +4157,7 @@ is_indexed_agg_distinct(JOIN *join, List<Item_field> *out_args) optimization is applicable */ if (out_args) - out_args->push_back((Item_field *) expr); + out_args->push_back((Item_field *) expr->real_item()); result= true; } } diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 75e8ca30cf0..9fbc06b7529 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -405,6 +405,16 @@ bool String::append(const char *s) } + +bool String::append_ulonglong(ulonglong val) +{ + if (realloc(str_length+MAX_BIGINT_WIDTH+2)) + return TRUE; + char *end= (char*) longlong10_to_str(val, (char*) Ptr + str_length, 10); + str_length= end - Ptr; + return FALSE; +} + /* Append a string in the given charset to the string with character set recoding diff --git a/sql/sql_string.h b/sql/sql_string.h index f67d6de9a0f..debfb7aa9c6 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -267,6 +267,7 @@ public: bool append(const char *s); bool append(const char *s,uint32 arg_length); bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs); + bool append_ulonglong(ulonglong val); bool append(IO_CACHE* file, uint32 arg_length); bool append_with_prefill(const char *s, uint32 arg_length, uint32 full_length, char fill_char); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c3a39354ff1..709fee07aac 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1998,8 +1998,13 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, case 0: // removed temporary table tmp_table_deleted= 1; - if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED && - thd->is_current_stmt_binlog_format_row()) + /* + One needs to always log any temporary table drop if the current + statement logging format is set to row. This happens because one + might have created a temporary table while the statement logging + format was statement and then switched to mixed or row format. + */ + if (thd->is_current_stmt_binlog_format_row()) { if (built_tmp_query.is_empty()) { @@ -2191,7 +2196,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, deleted one or more non-temporary tables (and no temporary tables). In this case, we can write the original query into the binary log. - */ + */ error |= write_bin_log(thd, !error, thd->query(), thd->query_length()); } else if (thd->is_current_stmt_binlog_format_row() && @@ -2218,11 +2223,12 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } /* - One needs to always log any temporary table drop, if: - 1. thread logging format is mixed mode; AND - 2. current statement logging format is set to row. + One needs to always log any temporary table drop if the current + statement logging format is set to row. This happens because one + might have created a temporary table while the statement logging + format was statement and then switched to mixed or row format. */ - if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED) + if (thd->is_current_stmt_binlog_format_row()) { /* In this case we have deleted some temporary tables but we are using @@ -2233,8 +2239,14 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, */ built_tmp_query.chop(); // Chop of the last comma built_tmp_query.append(" /* generated by server */"); - error|= write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length(), - thd->in_multi_stmt_transaction()); + /* + We cannot call the write_bin_log as we do not care about any errors + in the master as the statement is always DROP TEMPORARY TABLE IF EXISTS + and as such there will be no errors in the slave. + */ + error|= thd->binlog_query(THD::STMT_QUERY_TYPE, built_tmp_query.ptr(), + built_tmp_query.length(), FALSE, FALSE, FALSE, + 0); } } @@ -3749,43 +3761,6 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field) (void) prepare_blob_field(thd, sql_field); } - -/* - Write CREATE TABLE binlog - - SYNOPSIS - write_create_table_bin_log() - thd Thread object - create_info Create information - internal_tmp_table Set to 1 if this is an internal temporary table - - DESCRIPTION - This function only is called in mysql_create_table_no_lock and - mysql_create_table - - RETURN VALUES - NONE - */ -static inline int write_create_table_bin_log(THD *thd, - const HA_CREATE_INFO *create_info, - bool internal_tmp_table) -{ - /* - Don't write statement if: - - It is an internal temporary table, - - Row-based logging is used and it we are creating a temporary table, or - - The binary log is not open. - Otherwise, the statement shall be binlogged. - */ - if (!internal_tmp_table && - (!thd->is_current_stmt_binlog_format_row() || - (thd->is_current_stmt_binlog_format_row() && - !(create_info->options & HA_LEX_CREATE_TMP_TABLE)))) - return write_bin_log(thd, TRUE, thd->query(), thd->query_length()); - return 0; -} - - /* Create a table diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 207e72404ef..a0d64e6a378 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9830,7 +9830,40 @@ limit_options: ; limit_option: - param_marker + ident + { + Item_splocal *splocal; + THD *thd= YYTHD; + LEX *lex= thd->lex; + Lex_input_stream *lip= & thd->m_parser_state->m_lip; + sp_variable_t *spv; + sp_pcontext *spc = lex->spcont; + if (spc && (spv = spc->find_variable(&$1))) + { + splocal= new (thd->mem_root) + Item_splocal($1, spv->offset, spv->type, + lip->get_tok_start() - lex->sphead->m_tmp_query, + lip->get_ptr() - lip->get_tok_start()); + if (splocal == NULL) + MYSQL_YYABORT; +#ifndef DBUG_OFF + splocal->m_sp= lex->sphead; +#endif + lex->safe_to_cache_query=0; + } + else + { + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); + MYSQL_YYABORT; + } + if (splocal->type() != Item::INT_ITEM) + { + my_error(ER_WRONG_SPVAR_TYPE_IN_LIMIT, MYF(0)); + MYSQL_YYABORT; + } + splocal->limit_clause_param= TRUE; + $$= splocal; + } | param_marker { ((Item_param *) $1)->limit_clause_param= TRUE; } diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 3cb1e90b124..0331b5b32c3 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -258,6 +258,12 @@ static bool check_has_super(sys_var *self, THD *thd, set_var *var) } static bool binlog_format_check(sys_var *self, THD *thd, set_var *var) { + if (check_has_super(self, thd, var)) + return true; + + if (var->type == OPT_GLOBAL) + return false; + /* If RBR and open temporary tables, their CREATE TABLE may not be in the binlog, so we can't toggle to SBR in this connection. @@ -289,18 +295,12 @@ static bool binlog_format_check(sys_var *self, THD *thd, set_var *var) /* Make the session variable 'binlog_format' read-only inside a transaction. */ - if (thd->active_transaction() && (var->type == OPT_SESSION)) + if (thd->active_transaction()) { my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0)); return true; } - if (check_has_super(self, thd, var)) - return true; - if (var->type == OPT_GLOBAL || - (thd->variables.binlog_format == var->save_result.ulonglong_value)) - return false; - return false; } @@ -329,32 +329,31 @@ static Sys_var_enum Sys_binlog_format( static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var) { + if (check_has_super(self, thd, var)) + return true; + + if (var->type == OPT_GLOBAL) + return false; + /* Makes the session variable 'binlog_direct_non_transactional_updates' - read-only inside a transaction. + read-only if within a procedure, trigger or function. */ - if (thd->active_transaction() && (var->type == OPT_SESSION)) + if (thd->in_sub_stmt) { - my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); - return 1; + my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); + return true; } /* Makes the session variable 'binlog_direct_non_transactional_updates' - read-only if within a procedure, trigger or function. + read-only inside a transaction. */ - if (thd->in_sub_stmt) + if (thd->active_transaction()) { - my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); - return 1; + my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0)); + return true; } - if (check_has_super(self, thd, var)) - return true; - if (var->type == OPT_GLOBAL || - (thd->variables.binlog_direct_non_trans_update == - static_cast<my_bool>(var->save_result.ulonglong_value))) - return false; - return false; } @@ -1923,7 +1922,7 @@ static Sys_var_set Sys_sql_mode( sql_mode_names, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_sql_mode), ON_UPDATE(fix_sql_mode)); -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) #define SSL_OPT(X) CMD_LINE(REQUIRED_ARG,X) #else #define SSL_OPT(X) NO_CMD_LINE |