summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2010-02-13 17:01:32 +0100
committerVladislav Vaintroub <vvaintroub@mysql.com>2010-02-13 17:01:32 +0100
commite3a4741d05138d3850c7ed1788e3065c2f34548b (patch)
tree6514a0ffb792cd133aac6e0062b8c49449f2ab8e /sql
parentcb31d4ccfeae5db50f46bf965cf561222696df02 (diff)
parent70cafe287e040123d325a82bddcdfe0ee7d613cd (diff)
downloadmariadb-git-e3a4741d05138d3850c7ed1788e3065c2f34548b.tar.gz
merge
Diffstat (limited to 'sql')
-rw-r--r--sql/event_db_repository.cc8
-rw-r--r--sql/events.cc28
-rw-r--r--sql/log.cc9
-rw-r--r--sql/log_event.cc49
-rw-r--r--sql/log_event.h10
-rw-r--r--sql/mysql_priv.h1
-rw-r--r--sql/mysqld.cc25
-rw-r--r--sql/opt_range.cc12
-rw-r--r--sql/repl_failsafe.cc2
-rw-r--r--sql/repl_failsafe.h2
-rw-r--r--sql/rpl_handler.cc10
-rw-r--r--sql/rpl_mi.cc23
-rw-r--r--sql/rpl_mi.h4
-rw-r--r--sql/rpl_rli.cc2
-rw-r--r--sql/share/errmsg-utf8.txt7
-rw-r--r--sql/slave.cc18
-rw-r--r--sql/sp.cc24
-rw-r--r--sql/sql_acl.cc104
-rw-r--r--sql/sql_base.cc5
-rw-r--r--sql/sql_class.cc6
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_lex.cc2
-rw-r--r--sql/sql_lex.h18
-rw-r--r--sql/sql_profile.cc43
-rw-r--r--sql/sql_profile.h2
-rw-r--r--sql/sql_repl.cc6
-rw-r--r--sql/sql_select.cc8
-rw-r--r--sql/sql_table.cc64
-rw-r--r--sql/sql_udf.cc32
-rw-r--r--sql/sql_yacc.yy107
-rw-r--r--sql/sys_vars.cc24
-rw-r--r--sql/unireg.h3
32 files changed, 438 insertions, 221 deletions
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index fd2c5a556a8..ff74dd0ab84 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -1053,8 +1053,8 @@ update_timing_fields_for_event(THD *thd,
Turn off row binlogging of event timing updates. These are not used
for RBR of events replicated to the slave.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
DBUG_ASSERT(thd->security_ctx->master_access & SUPER_ACL);
@@ -1097,7 +1097,9 @@ end:
if (table)
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(test(ret));
}
diff --git a/sql/events.cc b/sql/events.cc
index 73f3427607d..340ef8c7bd2 100644
--- a/sql/events.cc
+++ b/sql/events.cc
@@ -335,8 +335,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for CREATE EVENT command.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
mysql_mutex_lock(&LOCK_event_metadata);
@@ -377,7 +377,9 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
sql_print_error("Event Error: An error occurred while creating query string, "
"before writing it into binary log.");
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(TRUE);
}
/* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
@@ -387,7 +389,9 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
}
mysql_mutex_unlock(&LOCK_event_metadata);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
@@ -471,8 +475,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for UPDATE EVENT command.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
mysql_mutex_lock(&LOCK_event_metadata);
@@ -509,7 +513,9 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
}
mysql_mutex_unlock(&LOCK_event_metadata);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
@@ -570,8 +576,8 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
Turn off row binlogging of this statement and use statement-based so
that all supporting tables are updated for DROP EVENT command.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
mysql_mutex_lock(&LOCK_event_metadata);
/* On error conditions my_error() is called so no need to handle here */
@@ -585,7 +591,9 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
}
mysql_mutex_unlock(&LOCK_event_metadata);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
diff --git a/sql/log.cc b/sql/log.cc
index 6abf8713b60..27ff92055b1 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -4680,12 +4680,19 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
{
BINLOG_USER_VAR_EVENT *user_var_event;
get_dynamic(&thd->user_var_events,(uchar*) &user_var_event, i);
+
+ /* setting flags for user var log event */
+ uchar flags= User_var_log_event::UNDEF_F;
+ if (user_var_event->user_var_event->unsigned_flag)
+ flags|= User_var_log_event::UNSIGNED_F;
+
User_var_log_event e(thd, user_var_event->user_var_event->name.str,
user_var_event->user_var_event->name.length,
user_var_event->value,
user_var_event->length,
user_var_event->type,
- user_var_event->charset_number);
+ user_var_event->charset_number,
+ flags);
if (e.write(file))
goto err;
}
diff --git a/sql/log_event.cc b/sql/log_event.cc
index be167451cb3..b9196b91e5f 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -4717,10 +4717,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
thd->warning_info->opt_clear_warning_info(thd->query_id);
TABLE_LIST tables;
- bzero((char*) &tables,sizeof(tables));
- tables.db= thd->strmake(thd->db, thd->db_length);
- tables.alias = tables.table_name = (char*) table_name;
- tables.lock_type = TL_WRITE;
+ tables.init_one_table(thd->db, table_name, TL_WRITE);
tables.updating= 1;
// the table will be opened in mysql_load
@@ -5495,7 +5492,9 @@ void User_var_log_event::pack_info(Protocol* protocol)
case INT_RESULT:
if (!(buf= (char*) my_malloc(val_offset + 22, MYF(MY_WME))))
return;
- event_len= longlong10_to_str(uint8korr(val), buf + val_offset,-10)-buf;
+ event_len= longlong10_to_str(uint8korr(val), buf + val_offset,
+ ((flags & User_var_log_event::UNSIGNED_F) ?
+ 10 : -10))-buf;
break;
case DECIMAL_RESULT:
{
@@ -5553,12 +5552,14 @@ User_var_log_event(const char* buf,
:Log_event(buf, description_event)
{
/* The Post-Header is empty. The Variable Data part begins immediately. */
+ const char *start= buf;
buf+= description_event->common_header_len +
description_event->post_header_len[USER_VAR_EVENT-1];
name_len= uint4korr(buf);
name= (char *) buf + UV_NAME_LEN_SIZE;
buf+= UV_NAME_LEN_SIZE + name_len;
is_null= (bool) *buf;
+ flags= User_var_log_event::UNDEF_F; // defaults to UNDEF_F
if (is_null)
{
type= STRING_RESULT;
@@ -5574,6 +5575,27 @@ User_var_log_event(const char* buf,
UV_CHARSET_NUMBER_SIZE);
val= (char *) (buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE);
+
+ /**
+ We need to check if this is from an old server
+ that did not pack information for flags.
+ We do this by checking if there are extra bytes
+ after the packed value. If there are we take the
+ extra byte and it's value is assumed to contain
+ the flags value.
+
+ Old events will not have this extra byte, thence,
+ we keep the flags set to UNDEF_F.
+ */
+ uint bytes_read= ((val + val_len) - start);
+ DBUG_ASSERT(bytes_read==data_written ||
+ bytes_read==(data_written-1));
+ if ((data_written - bytes_read) > 0)
+ {
+ flags= (uint) *(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
+ UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE +
+ val_len);
+ }
}
}
@@ -5585,6 +5607,7 @@ bool User_var_log_event::write(IO_CACHE* file)
char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE];
uchar buf2[max(8, DECIMAL_MAX_FIELD_SIZE + 2)], *pos= buf2;
+ uint unsigned_len= 0;
uint buf1_length;
ulong event_length;
@@ -5606,6 +5629,7 @@ bool User_var_log_event::write(IO_CACHE* file)
break;
case INT_RESULT:
int8store(buf2, *(longlong*) val);
+ unsigned_len= 1;
break;
case DECIMAL_RESULT:
{
@@ -5630,13 +5654,14 @@ bool User_var_log_event::write(IO_CACHE* file)
}
/* Length of the whole event */
- event_length= sizeof(buf)+ name_len + buf1_length + val_len;
+ event_length= sizeof(buf)+ name_len + buf1_length + val_len + unsigned_len;
return (write_header(file, event_length) ||
my_b_safe_write(file, (uchar*) buf, sizeof(buf)) ||
my_b_safe_write(file, (uchar*) name, name_len) ||
my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
- my_b_safe_write(file, pos, val_len));
+ my_b_safe_write(file, pos, val_len) ||
+ my_b_safe_write(file, &flags, unsigned_len));
}
#endif
@@ -5677,7 +5702,8 @@ void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
break;
case INT_RESULT:
char int_buf[22];
- longlong10_to_str(uint8korr(val), int_buf, -10);
+ longlong10_to_str(uint8korr(val), int_buf,
+ ((flags & User_var_log_event::UNSIGNED_F) ? 10 : -10));
my_b_printf(&cache, ":=%s%s\n", int_buf, print_event_info->delimiter);
break;
case DECIMAL_RESULT:
@@ -5824,7 +5850,8 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli)
a single record and with a single column. Thus, like
a column value, it could always have IMPLICIT derivation.
*/
- e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
+ e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT,
+ (flags & User_var_log_event::UNSIGNED_F));
free_root(thd->mem_root,0);
return 0;
@@ -6491,9 +6518,7 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli)
DBUG_EXECUTE_IF("remove_slave_load_file_before_write",
{
- mysql_file_close(fd, MYF(0));
- fd= -1;
- mysql_file_delete(0, fname, MYF(0));
+ my_delete_allow_opened(fname, MYF(0));
});
if (mysql_file_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP)))
diff --git a/sql/log_event.h b/sql/log_event.h
index 5530444b0d4..81669e24708 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -2498,6 +2498,10 @@ private:
class User_var_log_event: public Log_event
{
public:
+ enum {
+ UNDEF_F= 0,
+ UNSIGNED_F= 1
+ };
char *name;
uint name_len;
char *val;
@@ -2505,12 +2509,14 @@ public:
Item_result type;
uint charset_number;
bool is_null;
+ uchar flags;
#ifndef MYSQL_CLIENT
User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
char *val_arg, ulong val_len_arg, Item_result type_arg,
- uint charset_number_arg)
+ uint charset_number_arg, uchar flags_arg)
:Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
- val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg)
+ val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg),
+ flags(flags_arg)
{ is_null= !val; }
void pack_info(Protocol* protocol);
#else
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 944bc9d4cdd..8daf8f5ecb3 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -235,6 +235,7 @@ typedef struct my_locale_errmsgs
extern char err_shared_dir[];
+/** @note Keep this a POD-type because we use offsetof() on it */
typedef struct my_locale_st
{
uint number;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index cfbf46819fe..90d82202e2b 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -935,8 +935,6 @@ static bool add_terminator(DYNAMIC_ARRAY *options);
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 void init_error_log_mutex();
-static void clean_up_error_log_mutex();
static char *get_relative_path(const char *path);
static int fix_paths(void);
void handle_connections_sockets();
@@ -1353,6 +1351,18 @@ extern "C" sig_handler print_signal_warning(int sig)
#ifndef EMBEDDED_LIBRARY
+static void init_error_log_mutex()
+{
+ mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log, MY_MUTEX_INIT_FAST);
+}
+
+
+static void clean_up_error_log_mutex()
+{
+ mysql_mutex_destroy(&LOCK_error_log);
+}
+
+
/**
cleanup all memory and end program nicely.
@@ -3367,7 +3377,7 @@ static int init_common_variables()
set the def_value member to 0 in my_long_options and initialize it
to the correct value here.
*/
- default_storage_engine="MyISAM";
+ default_storage_engine= const_cast<char *>("MyISAM");
/*
Add server status variables to the dynamic list of
@@ -3708,15 +3718,6 @@ You should consider changing lower_case_table_names to 1 or 2",
return 0;
}
-static void init_error_log_mutex()
-{
- mysql_mutex_init(key_LOCK_error_log, &LOCK_error_log, MY_MUTEX_INIT_FAST);
-}
-
-static void clean_up_error_log_mutex()
-{
- mysql_mutex_destroy(&LOCK_error_log);
-}
static int init_thread_environment()
{
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 741815585e2..b9ea8c7c991 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -10955,17 +10955,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next()
} while ((result == HA_ERR_KEY_NOT_FOUND || result == HA_ERR_END_OF_FILE) &&
is_last_prefix != 0);
- if (result == 0)
- {
- /*
- Partially mimic the behavior of end_select_send. Copy the
- field data from Item_field::field into Item_field::result_field
- of each non-aggregated field (the group fields, and optionally
- other fields in non-ANSI SQL mode).
- */
- copy_fields(&join->tmp_table_param);
- }
- else if (result == HA_ERR_KEY_NOT_FOUND)
+ if (result == HA_ERR_KEY_NOT_FOUND)
result= HA_ERR_END_OF_FILE;
DBUG_RETURN(result);
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 5bf87dea90e..29443eb6e65 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -38,7 +38,7 @@
#define SLAVE_ERRMSG_SIZE (FN_REFLEN+64)
-uint rpl_status=RPL_NULL;
+RPL_STATUS rpl_status=RPL_NULL;
mysql_mutex_t LOCK_rpl_status;
mysql_cond_t COND_rpl_status;
HASH slave_list;
diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h
index dd6770be0b4..94b151aaee7 100644
--- a/sql/repl_failsafe.h
+++ b/sql/repl_failsafe.h
@@ -26,7 +26,7 @@ typedef enum {RPL_AUTH_MASTER=0,RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE,
RPL_LOST_SOLDIER,RPL_TROOP_SOLDIER,
RPL_RECOVERY_CAPTAIN,RPL_NULL /* inactive */,
RPL_ANY /* wild card used by change_rpl_status */ } RPL_STATUS;
-extern uint rpl_status;
+extern RPL_STATUS rpl_status;
extern mysql_mutex_t LOCK_rpl_status;
extern mysql_cond_t COND_rpl_status;
diff --git a/sql/rpl_handler.cc b/sql/rpl_handler.cc
index ebd6e4e0c0b..5a406866513 100644
--- a/sql/rpl_handler.cc
+++ b/sql/rpl_handler.cc
@@ -190,8 +190,8 @@ int Trans_delegate::after_commit(THD *thd, bool all)
{
Trans_param param;
bool is_real_trans= (all || thd->transaction.all.ha_list == 0);
- if (is_real_trans)
- param.flags |= TRANS_IS_REAL_TRANS;
+
+ param.flags = is_real_trans ? TRANS_IS_REAL_TRANS : 0;
Trans_binlog_info *log_info=
my_pthread_getspecific_ptr(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
@@ -218,8 +218,8 @@ int Trans_delegate::after_rollback(THD *thd, bool all)
{
Trans_param param;
bool is_real_trans= (all || thd->transaction.all.ha_list == 0);
- if (is_real_trans)
- param.flags |= TRANS_IS_REAL_TRANS;
+
+ param.flags = is_real_trans ? TRANS_IS_REAL_TRANS : 0;
Trans_binlog_info *log_info=
my_pthread_getspecific_ptr(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
@@ -228,7 +228,7 @@ int Trans_delegate::after_rollback(THD *thd, bool all)
param.log_pos= log_info ? log_info->log_pos : 0;
int ret= 0;
- FOREACH_OBSERVER(ret, after_commit, thd, (&param));
+ FOREACH_OBSERVER(ret, after_rollback, thd, (&param));
/*
This is the end of a real transaction or autocommit statement, we
diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc
index 38382fd2a0e..7dad340cfa6 100644
--- a/sql/rpl_mi.cc
+++ b/sql/rpl_mi.cc
@@ -33,8 +33,8 @@ int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f);
Master_info::Master_info(bool is_slave_recovery)
:Slave_reporting_capability("I/O"),
ssl(0), ssl_verify_server_cert(0), fd(-1), io_thd(0),
- port(MYSQL_PORT), connect_retry(DEFAULT_CONNECT_RETRY), inited(0),
- rli(is_slave_recovery), abort_slave(0),
+ rli(is_slave_recovery), port(MYSQL_PORT),
+ connect_retry(DEFAULT_CONNECT_RETRY), inited(0), abort_slave(0),
slave_running(0), slave_run_id(0), sync_counter(0),
heartbeat_period(0), received_heartbeats(0), master_id(0)
{
@@ -369,7 +369,7 @@ file '%s')", fname);
mi->rli.is_relay_log_recovery= FALSE;
// now change cache READ -> WRITE - must do this before flush_master_info
reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1);
- if ((error=test(flush_master_info(mi, 1))))
+ if ((error=test(flush_master_info(mi, TRUE, TRUE))))
sql_print_error("Failed to flush master info file");
mysql_mutex_unlock(&mi->data_lock);
DBUG_RETURN(error);
@@ -395,7 +395,9 @@ err:
1 - flush master info failed
0 - all ok
*/
-int flush_master_info(Master_info* mi, bool flush_relay_log_cache)
+int flush_master_info(Master_info* mi,
+ bool flush_relay_log_cache,
+ bool need_lock_relay_log)
{
IO_CACHE* file = &mi->file;
char lbuf[22];
@@ -418,8 +420,19 @@ int flush_master_info(Master_info* mi, bool flush_relay_log_cache)
*/
if (flush_relay_log_cache)
{
+ mysql_mutex_t *log_lock= mi->rli.relay_log.get_log_lock();
IO_CACHE *log_file= mi->rli.relay_log.get_log_file();
- if (flush_io_cache(log_file))
+
+ if (need_lock_relay_log)
+ mysql_mutex_lock(log_lock);
+
+ mysql_mutex_assert_owner(log_lock);
+ err= flush_io_cache(log_file);
+
+ if (need_lock_relay_log)
+ mysql_mutex_unlock(log_lock);
+
+ if (err)
DBUG_RETURN(2);
}
diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h
index 6dd9fab7904..c4ca5714306 100644
--- a/sql/rpl_mi.h
+++ b/sql/rpl_mi.h
@@ -119,7 +119,9 @@ int init_master_info(Master_info* mi, const char* master_info_fname,
bool abort_if_no_master_info_file,
int thread_mask);
void end_master_info(Master_info* mi);
-int flush_master_info(Master_info* mi, bool flush_relay_log_cache);
+int flush_master_info(Master_info* mi,
+ bool flush_relay_log_cache,
+ bool need_lock_relay_log);
int change_master_server_id_cmp(ulong *id1, ulong *id2);
#endif /* HAVE_REPLICATION */
diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc
index a982cfd25a4..1b3c25dfda2 100644
--- a/sql/rpl_rli.cc
+++ b/sql/rpl_rli.cc
@@ -123,7 +123,7 @@ int init_relay_log_info(Relay_log_info* rli,
/*
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
- event, in flush_master_info(mi, 1).
+ event, in flush_master_info(mi, 1, ?).
*/
/*
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 33a68f1489e..8ed5bef2046 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -6280,8 +6280,8 @@ ER_BINLOG_UNSAFE_INSERT_DELAYED
eng "Statement uses INSERT DELAYED. This is unsafe because the time when rows are inserted cannot be predicted."
ER_BINLOG_UNSAFE_SYSTEM_TABLE
eng "Statement uses the general_log, slow_log or performance_schema table(s). This is unsafe because system tables may differ on slave."
-ER_BINLOG_UNSAFE_TWO_AUTOINC_COLUMNS
- eng "Statement updates two AUTO_INCREMENT columns. This is unsafe because the generated value cannot be predicted by slave."
+ER_BINLOG_UNSAFE_AUTOINC_COLUMNS
+ eng "Statement invokes a trigger or a stored function that inserts into AUTO_INCREMENT column which is unsafe to binlog in STATEMENT format because slave may execute it non-deterministically."
ER_BINLOG_UNSAFE_UDF
eng "Statement uses a UDF. It cannot be determined if the UDF will return the same value on slave."
ER_BINLOG_UNSAFE_SYSTEM_VARIABLE
@@ -6316,3 +6316,6 @@ ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction"
ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot change the binlog direct flag inside a stored function or trigger"
+ER_SPATIAL_MUST_HAVE_GEOM_COL 42000
+ eng "A SPATIAL index may only contain a geometrical type column"
+
diff --git a/sql/slave.cc b/sql/slave.cc
index a4f16f6ed28..c7469d41a26 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -510,7 +510,7 @@ int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
DBUG_PRINT("info",("Flushing relay log and master info file."));
if (current_thd)
thd_proc_info(current_thd, "Flushing relay log and master info files.");
- if (flush_master_info(mi, TRUE /* flush relay log */))
+ if (flush_master_info(mi, TRUE, FALSE))
DBUG_RETURN(ER_ERROR_DURING_FLUSH_LOGS);
if (my_sync(mi->rli.relay_log.get_log_file()->file, MYF(MY_WME)))
@@ -1111,7 +1111,7 @@ int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f)
memcpy(buf_act, buf, read_size);
snd_size= my_b_gets(f, buf_act + read_size, max_size - read_size);
if (snd_size == 0 ||
- (snd_size + 1 == max_size - read_size) && buf[max_size - 2] != '\n')
+ ((snd_size + 1 == max_size - read_size) && buf[max_size - 2] != '\n'))
{
/*
failure to make the 2nd read or short read again
@@ -1601,7 +1601,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi)
" to the relay log, SHOW SLAVE STATUS may be"
" inaccurate");
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
- if (flush_master_info(mi, 1))
+ if (flush_master_info(mi, TRUE, FALSE))
sql_print_error("Failed to flush master info file");
delete ev;
}
@@ -2928,7 +2928,7 @@ Stopping slave I/O thread due to out-of-memory error from master");
goto err;
}
- if (flush_master_info(mi, 1))
+ if (flush_master_info(mi, TRUE, TRUE))
{
sql_print_error("Failed to flush master info file");
goto err;
@@ -3943,8 +3943,8 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
/* everything is filtered out from non-master */
(s_id != mi->master_id ||
/* for the master meta information is necessary */
- buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
- buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT)))
+ (buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
+ buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT))))
{
/*
Do not write it to the relay log.
@@ -3964,9 +3964,9 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
as well as rli->group_relay_log_pos.
*/
if (!(s_id == ::server_id && !mi->rli.replicate_same_server_id) ||
- buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
- buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT &&
- buf[EVENT_TYPE_OFFSET] != STOP_EVENT)
+ (buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
+ buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT &&
+ buf[EVENT_TYPE_OFFSET] != STOP_EVENT))
{
mi->master_log_pos+= inc_pos;
memcpy(rli->ign_master_log_name_end, mi->master_log_name, FN_REFLEN);
diff --git a/sql/sp.cc b/sql/sp.cc
index cbc0d003c9f..aae825c6c0d 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -927,8 +927,8 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
saved_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_WARN;
@@ -1136,7 +1136,9 @@ done:
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
@@ -1174,8 +1176,8 @@ sp_drop_routine(THD *thd, int type, sp_name *name)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
if (!(table= open_proc_table_for_update(thd)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
@@ -1194,7 +1196,9 @@ sp_drop_routine(THD *thd, int type, sp_name *name)
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
@@ -1233,8 +1237,8 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
if (!(table= open_proc_table_for_update(thd)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
@@ -1269,7 +1273,9 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
}
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 012542a9467..334d6474169 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -3119,8 +3119,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
#ifdef HAVE_REPLICATION
/*
@@ -3137,7 +3137,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
if (!(thd->spcont || rpl_filter->tables_ok(0, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(FALSE);
}
}
@@ -3153,7 +3155,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{ // Should never happen
close_thread_tables(thd); /* purecov: deadcode */
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(TRUE); /* purecov: deadcode */
}
@@ -3281,7 +3285,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
/* Tables are automatically closed */
thd->lex->restore_backup_query_tables_list(&backup);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result);
}
@@ -3346,8 +3352,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
#ifdef HAVE_REPLICATION
/*
@@ -3364,7 +3370,9 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
if (!(thd->spcont || rpl_filter->tables_ok(0, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(FALSE);
}
}
@@ -3374,7 +3382,9 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
{ // Should never happen
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(TRUE);
}
@@ -3452,7 +3462,9 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
mysql_rwlock_unlock(&LOCK_grant);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
/* Tables are automatically closed */
DBUG_RETURN(result);
@@ -3496,8 +3508,8 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
#ifdef HAVE_REPLICATION
/*
@@ -3514,7 +3526,9 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
if (!(thd->spcont || rpl_filter->tables_ok(0, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(FALSE);
}
}
@@ -3524,7 +3538,9 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
{ // This should never happen
close_thread_tables(thd); /* purecov: deadcode */
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(TRUE); /* purecov: deadcode */
}
@@ -3585,7 +3601,9 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
if (!result)
my_ok(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result);
}
@@ -5797,14 +5815,16 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
/* CREATE USER may be skipped on replication client. */
if ((result= open_grant_tables(thd, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result != 1);
}
@@ -5850,7 +5870,9 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
mysql_rwlock_unlock(&LOCK_grant);
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result);
}
@@ -5885,14 +5907,16 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
/* DROP USER may be skipped on replication client. */
if ((result= open_grant_tables(thd, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result != 1);
}
@@ -5932,7 +5956,9 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
close_thread_tables(thd);
thd->variables.sql_mode= old_sql_mode;
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result);
}
@@ -5967,14 +5993,16 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
/* RENAME USER may be skipped on replication client. */
if ((result= open_grant_tables(thd, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result != 1);
}
@@ -6024,7 +6052,9 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
mysql_rwlock_unlock(&LOCK_grant);
close_thread_tables(thd);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result);
}
@@ -6057,13 +6087,15 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list)
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
if ((result= open_grant_tables(thd, tables)))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result != 1);
}
@@ -6219,7 +6251,9 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list)
if (result && !binlog_error)
my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0));
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(result || binlog_error);
}
@@ -6328,8 +6362,8 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name,
row-based replication. The flag will be reset at the end of the
statement.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
/* Remove procedure access */
do
@@ -6366,7 +6400,9 @@ bool sp_revoke_privileges(THD *thd, const char *sp_db, const char *sp_name,
thd->pop_internal_handler();
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(error_handler.has_errors());
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index eb59600b360..7b742364e62 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -5180,10 +5180,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen)
*/
if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables &&
has_write_table_with_auto_increment(thd->lex->first_not_own_table()))
- {
- thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_TWO_AUTOINC_COLUMNS);
- thd->set_current_stmt_binlog_format_row_if_mixed();
- }
+ thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS);
}
DEBUG_SYNC(thd, "before_lock_tables_takes_lock");
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index e8a00974a56..527b84a795c 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3536,7 +3536,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
{
DBUG_ENTER("THD::decide_logging_format");
DBUG_PRINT("info", ("query: %s", query()));
- DBUG_PRINT("info", ("variables.binlog_format: %ld",
+ DBUG_PRINT("info", ("variables.binlog_format: %u",
variables.binlog_format));
DBUG_PRINT("info", ("lex->get_stmt_unsafe_flags(): 0x%x",
lex->get_stmt_unsafe_flags()));
@@ -3677,7 +3677,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
lock history on the slave will be different from the master.
*/
if (mixed_engine ||
- trans_has_updated_trans_table(this) && !all_trans_engines)
+ (trans_has_updated_trans_table(this) && !all_trans_engines))
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS);
DBUG_PRINT("info", ("flags_all_set: 0x%llx", flags_all_set));
@@ -3807,7 +3807,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
DBUG_PRINT("info", ("decision: no logging since "
"mysql_bin_log.is_open() = %d "
"and (options & OPTION_BIN_LOG) = 0x%llx "
- "and binlog_format = %ld "
+ "and binlog_format = %u "
"and binlog_filter->db_ok(db) = %d",
mysql_bin_log.is_open(),
(variables.option_bits & OPTION_BIN_LOG),
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 31c4eaa194e..b42c0cec502 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1723,7 +1723,6 @@ public:
bool slave_thread, one_shot_set;
/* tells if current statement should binlog row-based(1) or stmt-based(0) */
- bool current_stmt_binlog_row_based;
bool locked, some_tables_deleted;
bool last_cuted_field;
bool no_errors, password;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 0d423ba85eb..6da734592dc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -48,7 +48,7 @@ Query_tables_list::binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT] =
ER_BINLOG_UNSAFE_LIMIT,
ER_BINLOG_UNSAFE_INSERT_DELAYED,
ER_BINLOG_UNSAFE_SYSTEM_TABLE,
- ER_BINLOG_UNSAFE_TWO_AUTOINC_COLUMNS,
+ ER_BINLOG_UNSAFE_AUTOINC_COLUMNS,
ER_BINLOG_UNSAFE_UDF,
ER_BINLOG_UNSAFE_SYSTEM_VARIABLE,
ER_BINLOG_UNSAFE_SYSTEM_FUNCTION,
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 800a16cf2b6..80cb1e0f210 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1101,13 +1101,15 @@ public:
*/
BINLOG_STMT_UNSAFE_SYSTEM_TABLE,
/**
- Update of two autoincrement columns is unsafe. With one
- autoincrement column, we store the counter in the binlog so that
- slave can restore the correct value. But we can only store one
- such counter per statement, so updating more than one
- autoincrement column is not safe.
+ Inserting into an autoincrement column in a stored routine is unsafe.
+ Even with just one autoincrement column, if the routine is invoked more than
+ once slave is not guaranteed to execute the statement graph same way as
+ the master.
+ And since it's impossible to estimate how many times a routine can be invoked at
+ the query pre-execution phase (see lock_tables), the statement is marked
+ pessimistically unsafe.
*/
- BINLOG_STMT_UNSAFE_TWO_AUTOINC_COLUMNS,
+ BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS,
/**
Using a UDF (user-defined function) is unsafe.
*/
@@ -1903,7 +1905,9 @@ struct LEX: public Query_tables_list
uint profile_options;
uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
- uint fk_delete_opt, fk_update_opt, fk_match_option;
+ enum Foreign_key::fk_match_opt fk_match_option;
+ enum Foreign_key::fk_option fk_update_opt;
+ enum Foreign_key::fk_option fk_delete_opt;
uint slave_thd_opt, start_transaction_opt;
int nest_level;
/*
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 84ee0768b25..f8c11cb71b9 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -134,6 +134,26 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table)
#define RUSAGE_USEC(tv) ((tv).tv_sec*1000*1000 + (tv).tv_usec)
#define RUSAGE_DIFF_USEC(tv1, tv2) (RUSAGE_USEC((tv1))-RUSAGE_USEC((tv2)))
+#ifdef _WIN32
+static ULONGLONG FileTimeToQuadWord(FILETIME *ft)
+{
+ // Overlay FILETIME onto a ULONGLONG.
+ union {
+ ULONGLONG qwTime;
+ FILETIME ft;
+ } u;
+
+ u.ft = *ft;
+ return u.qwTime;
+}
+
+
+// Get time difference between to FILETIME objects in seconds.
+static double GetTimeDiffInSeconds(FILETIME *a, FILETIME *b)
+{
+ return ((FileTimeToQuadWord(a) - FileTimeToQuadWord(b)) / 1e7);
+}
+#endif
PROF_MEASUREMENT::PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char
*status_arg)
@@ -224,6 +244,12 @@ void PROF_MEASUREMENT::collect()
time_usecs= (double) my_getsystime() / 10.0; /* 1 sec was 1e7, now is 1e6 */
#ifdef HAVE_GETRUSAGE
getrusage(RUSAGE_SELF, &rusage);
+#elif defined(_WIN32)
+ FILETIME ftDummy;
+ // NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
+ // which is typically ~15ms. So intervals shorter than that will not be
+ // measurable by this function.
+ GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
#endif
}
@@ -593,6 +619,23 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
table->field[5]->store_decimal(&cpu_stime_decimal);
table->field[4]->set_notnull();
table->field[5]->set_notnull();
+#elif defined(_WIN32)
+ my_decimal cpu_utime_decimal, cpu_stime_decimal;
+
+ double2my_decimal(E_DEC_FATAL_ERROR,
+ GetTimeDiffInSeconds(&entry->ftUser,
+ &previous->ftUser),
+ &cpu_utime_decimal);
+ double2my_decimal(E_DEC_FATAL_ERROR,
+ GetTimeDiffInSeconds(&entry->ftKernel,
+ &previous->ftKernel),
+ &cpu_stime_decimal);
+
+ // Store the result.
+ table->field[4]->store_decimal(&cpu_utime_decimal);
+ table->field[5]->store_decimal(&cpu_stime_decimal);
+ table->field[4]->set_notnull();
+ table->field[5]->set_notnull();
#else
/* TODO: Add CPU-usage info for non-BSD systems */
#endif
diff --git a/sql/sql_profile.h b/sql/sql_profile.h
index bffe1cb576b..31e2f1a7c50 100644
--- a/sql/sql_profile.h
+++ b/sql/sql_profile.h
@@ -173,6 +173,8 @@ private:
char *status;
#ifdef HAVE_GETRUSAGE
struct rusage rusage;
+#elif defined(_WIN32)
+ FILETIME ftKernel, ftUser;
#endif
char *function;
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 436e979df1e..510f9d8dc01 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -828,11 +828,11 @@ impossible position";
{
if (coord)
{
- DBUG_ASSERT(heartbeat_ts && heartbeat_period != LL(0));
+ DBUG_ASSERT(heartbeat_ts && heartbeat_period != 0);
set_timespec_nsec(*heartbeat_ts, heartbeat_period);
}
ret= mysql_bin_log.wait_for_update_bin_log(thd, heartbeat_ts);
- DBUG_ASSERT(ret == 0 || heartbeat_period != LL(0) && coord != NULL);
+ DBUG_ASSERT(ret == 0 || (heartbeat_period != 0 && coord != NULL));
if (ret == ETIMEDOUT || ret == ETIME)
{
#ifndef DBUG_OFF
@@ -1525,7 +1525,7 @@ bool change_master(THD* thd, Master_info* mi)
Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
a slave before).
*/
- if (flush_master_info(mi, 0))
+ if (flush_master_info(mi, FALSE, FALSE))
{
my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
ret= TRUE;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index bddfbb1bd0b..e429e4cd0c5 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -4392,7 +4392,7 @@ best_access_path(JOIN *join,
*/
if (table->quick_keys.is_set(key) &&
(const_part & ((1 << table->quick_key_parts[key])-1)) ==
- ((1 << table->quick_key_parts[key])-1) &&
+ (((key_part_map)1 << table->quick_key_parts[key])-1) &&
table->quick_n_ranges[key] == 1 &&
records > (double) table->quick_rows[key])
{
@@ -12316,6 +12316,12 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if (!end_of_records)
{
int error;
+ if (join->tables &&
+ join->join_tab->is_using_loose_index_scan())
+ {
+ /* Copy non-aggregated fields when loose index scan is used. */
+ copy_fields(&join->tmp_table_param);
+ }
if (join->having && join->having->val_int() == 0)
DBUG_RETURN(NESTED_LOOP_OK); // Didn't match having
error=0;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index f323b99dfed..5790a196835 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -292,7 +292,8 @@ uint explain_filename(THD* thd,
{
if (explain_mode == EXPLAIN_ALL_VERBOSE)
{
- to_p= strnmov(to_p, ER(ER_DATABASE_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_DATABASE_NAME),
+ end_p - to_p);
*(to_p++)= ' ';
to_p= add_identifier(thd, to_p, end_p, db_name, db_name_len);
to_p= strnmov(to_p, ", ", end_p - to_p);
@@ -305,7 +306,7 @@ uint explain_filename(THD* thd,
}
if (explain_mode == EXPLAIN_ALL_VERBOSE)
{
- to_p= strnmov(to_p, ER(ER_TABLE_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_TABLE_NAME), end_p - to_p);
*(to_p++)= ' ';
to_p= add_identifier(thd, to_p, end_p, table_name, table_name_len);
}
@@ -322,18 +323,22 @@ uint explain_filename(THD* thd,
if (name_type != NORMAL)
{
if (name_type == TEMP)
- to_p= strnmov(to_p, ER(ER_TEMPORARY_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_TEMPORARY_NAME),
+ end_p - to_p);
else
- to_p= strnmov(to_p, ER(ER_RENAMED_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_RENAMED_NAME),
+ end_p - to_p);
to_p= strnmov(to_p, " ", end_p - to_p);
}
- to_p= strnmov(to_p, ER(ER_PARTITION_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_PARTITION_NAME),
+ end_p - to_p);
*(to_p++)= ' ';
to_p= add_identifier(thd, to_p, end_p, part_name, part_name_len);
if (subpart_name)
{
to_p= strnmov(to_p, ", ", end_p - to_p);
- to_p= strnmov(to_p, ER(ER_SUBPARTITION_NAME), end_p - to_p);
+ to_p= strnmov(to_p, ER_THD_OR_DEFAULT(thd, ER_SUBPARTITION_NAME),
+ end_p - to_p);
*(to_p++)= ' ';
to_p= add_identifier(thd, to_p, end_p, subpart_name, subpart_name_len);
}
@@ -3191,11 +3196,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
{
column->length*= sql_field->charset->mbmaxlen;
- if (key->type == Key::SPATIAL && column->length)
+ if (key->type == Key::SPATIAL)
{
- my_error(ER_WRONG_SUB_KEY, MYF(0));
- DBUG_RETURN(TRUE);
- }
+ if (column->length)
+ {
+ my_error(ER_WRONG_SUB_KEY, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+ if (!f_is_geom(sql_field->pack_flag))
+ {
+ my_error(ER_SPATIAL_MUST_HAVE_GEOM_COL, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+ }
if (f_is_blob(sql_field->pack_flag) ||
(f_is_geom(sql_field->pack_flag) && key->type != Key::SPATIAL))
@@ -3290,22 +3303,21 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
}
}
}
+ // Catch invalid use of partial keys
else if (!f_is_geom(sql_field->pack_flag) &&
- ((column->length > length &&
- !Field::type_can_have_key_part (sql_field->sql_type)) ||
- ((f_is_packed(sql_field->pack_flag) ||
- ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
- (key_info->flags & HA_NOSAME))) &&
- column->length != length)))
- {
- /* Catch invalid uses of partial keys.
- A key is identified as 'partial' if column->length != length.
- A partial key is invalid if they data type does
- not allow it, or the field is packed (as in MyISAM),
- or the storage engine doesn't allow prefixed search and
- the key is primary key.
- */
-
+ // is the key partial?
+ column->length != length &&
+ // is prefix length bigger than field length?
+ (column->length > length ||
+ // can the field have a partial key?
+ !Field::type_can_have_key_part (sql_field->sql_type) ||
+ // a packed field can't be used in a partial key
+ f_is_packed(sql_field->pack_flag) ||
+ // does the storage engine allow prefixed search?
+ ((file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
+ // and is this a 'unique' key?
+ (key_info->flags & HA_NOSAME))))
+ {
my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
DBUG_RETURN(TRUE);
}
@@ -6550,7 +6562,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->clear_error();
Query_log_event qinfo(thd, thd->query(), thd->query_length(),
FALSE, TRUE, FALSE, 0);
- if (error= mysql_bin_log.write(&qinfo))
+ if ((error= mysql_bin_log.write(&qinfo)))
goto view_err_unlock;
}
my_ok(thd);
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index d0e446fb157..80c4791ab21 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -461,8 +461,8 @@ int mysql_create_function(THD *thd,udf_func *udf)
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for CREATE FUNCTION command.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
mysql_rwlock_wrlock(&THR_LOCK_udf);
if ((my_hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length)))
@@ -533,11 +533,15 @@ int mysql_create_function(THD *thd,udf_func *udf)
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1);
}
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(0);
err:
@@ -545,7 +549,9 @@ int mysql_create_function(THD *thd,udf_func *udf)
dlclose(dl);
mysql_rwlock_unlock(&THR_LOCK_udf);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1);
}
@@ -573,8 +579,8 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for DROP FUNCTION command.
*/
- save_binlog_row_based= thd->is_current_stmt_binlog_format_row();
- thd->clear_current_stmt_binlog_format_row();
+ if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
+ thd->clear_current_stmt_binlog_format_row();
mysql_rwlock_wrlock(&THR_LOCK_udf);
if (!(udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) udf_name->str,
@@ -617,16 +623,22 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
{
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1);
}
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(0);
err:
mysql_rwlock_unlock(&THR_LOCK_udf);
/* Restore the state of binlog format */
- thd->current_stmt_binlog_row_based= save_binlog_row_based;
+ DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
+ if (save_binlog_row_based)
+ thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1);
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index ab128a9b701..0b0ca2e6215 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -756,6 +756,7 @@ static bool add_create_index (LEX *lex, Key::Keytype type,
struct p_elem_val *p_elem_value;
enum index_hint_type index_hint;
enum enum_filetype filetype;
+ enum Foreign_key::fk_option m_fk_option;
Diag_condition_item_name diag_condition_item_name;
}
@@ -765,10 +766,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%pure_parser /* We have threads */
/*
- Currently there are 172 shift/reduce conflicts.
+ Currently there are 169 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
-%expect 172
+%expect 169
/*
Comments for TOKENS.
@@ -1422,7 +1423,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
type type_with_opt_collate int_type real_type order_dir lock_option
udf_type if_exists opt_local opt_table_options table_options
table_option opt_if_not_exists opt_no_write_to_binlog
- delete_option opt_temporary all_or_any opt_distinct
+ opt_temporary all_or_any opt_distinct
opt_ignore_leaves fulltext_options spatial_type union_option
start_transaction_opts opt_chain opt_release
union_opt select_derived_init option_type2
@@ -1430,6 +1431,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
opt_ev_status opt_ev_on_completion ev_on_completion opt_ev_comment
ev_alter_on_schedule_completion opt_ev_rename_to opt_ev_sql_stmt
+%type <m_fk_option>
+ delete_option
+
%type <ulong_num>
ulong_num real_ulong_num merge_insert_types
@@ -1544,7 +1548,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
opt_precision opt_ignore opt_column opt_restrict
grant revoke set lock unlock string_list field_options field_option
field_opt_list opt_binary ascii unicode table_lock_list table_lock
- ref_list opt_on_delete opt_on_delete_list opt_on_delete_item use
+ ref_list opt_match_clause opt_on_update_delete use
opt_delete_options opt_delete_option varchar nchar nvarchar
opt_outer table_list table_name table_alias_ref_list table_alias_ref
opt_option opt_place
@@ -5282,10 +5286,6 @@ key_def:
/* Only used for ALTER TABLE. Ignored otherwise. */
lex->alter_info.flags|= ALTER_FOREIGN_KEY;
}
- | constraint opt_check_constraint
- {
- Lex->col_list.empty(); /* Alloced by sql_alloc */
- }
| opt_constraint check_constraint
{
Lex->col_list.empty(); /* Alloced by sql_alloc */
@@ -5298,7 +5298,7 @@ opt_check_constraint:
;
check_constraint:
- CHECK_SYM expr
+ CHECK_SYM '(' expr ')'
;
opt_constraint:
@@ -5837,21 +5837,20 @@ opt_primary:
;
references:
- REFERENCES table_ident
- {
- LEX *lex=Lex;
- lex->fk_delete_opt= lex->fk_update_opt= lex->fk_match_option= 0;
- lex->ref_list.empty();
- }
+ REFERENCES
+ table_ident
opt_ref_list
+ opt_match_clause
+ opt_on_update_delete
{
$$=$2;
}
;
opt_ref_list:
- /* empty */ opt_on_delete {}
- | '(' ref_list ')' opt_on_delete {}
+ /* empty */
+ { Lex->ref_list.empty(); }
+ | '(' ref_list ')'
;
ref_list:
@@ -5867,34 +5866,64 @@ ref_list:
Key_part_spec *key= new Key_part_spec($1, 0);
if (key == NULL)
MYSQL_YYABORT;
- Lex->ref_list.push_back(key);
+ LEX *lex= Lex;
+ lex->ref_list.empty();
+ lex->ref_list.push_back(key);
}
;
-opt_on_delete:
- /* empty */ {}
- | opt_on_delete_list {}
- ;
-
-opt_on_delete_list:
- opt_on_delete_list opt_on_delete_item {}
- | opt_on_delete_item {}
+opt_match_clause:
+ /* empty */
+ { Lex->fk_match_option= Foreign_key::FK_MATCH_UNDEF; }
+ | MATCH FULL
+ { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
+ | MATCH PARTIAL
+ { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
+ | MATCH SIMPLE_SYM
+ { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
;
-opt_on_delete_item:
- ON DELETE_SYM delete_option { Lex->fk_delete_opt= $3; }
- | ON UPDATE_SYM delete_option { Lex->fk_update_opt= $3; }
- | MATCH FULL { Lex->fk_match_option= Foreign_key::FK_MATCH_FULL; }
- | MATCH PARTIAL { Lex->fk_match_option= Foreign_key::FK_MATCH_PARTIAL; }
- | MATCH SIMPLE_SYM { Lex->fk_match_option= Foreign_key::FK_MATCH_SIMPLE; }
+opt_on_update_delete:
+ /* empty */
+ {
+ LEX *lex= Lex;
+ lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
+ lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
+ }
+ | ON UPDATE_SYM delete_option
+ {
+ LEX *lex= Lex;
+ lex->fk_update_opt= $3;
+ lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
+ }
+ | ON DELETE_SYM delete_option
+ {
+ LEX *lex= Lex;
+ lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
+ lex->fk_delete_opt= $3;
+ }
+ | ON UPDATE_SYM delete_option
+ ON DELETE_SYM delete_option
+ {
+ LEX *lex= Lex;
+ lex->fk_update_opt= $3;
+ lex->fk_delete_opt= $6;
+ }
+ | ON DELETE_SYM delete_option
+ ON UPDATE_SYM delete_option
+ {
+ LEX *lex= Lex;
+ lex->fk_update_opt= $6;
+ lex->fk_delete_opt= $3;
+ }
;
delete_option:
- RESTRICT { $$= (int) Foreign_key::FK_OPTION_RESTRICT; }
- | CASCADE { $$= (int) Foreign_key::FK_OPTION_CASCADE; }
- | SET NULL_SYM { $$= (int) Foreign_key::FK_OPTION_SET_NULL; }
- | NO_SYM ACTION { $$= (int) Foreign_key::FK_OPTION_NO_ACTION; }
- | SET DEFAULT { $$= (int) Foreign_key::FK_OPTION_DEFAULT; }
+ RESTRICT { $$= Foreign_key::FK_OPTION_RESTRICT; }
+ | CASCADE { $$= Foreign_key::FK_OPTION_CASCADE; }
+ | SET NULL_SYM { $$= Foreign_key::FK_OPTION_SET_NULL; }
+ | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
+ | SET DEFAULT { $$= Foreign_key::FK_OPTION_DEFAULT; }
;
normal_key_type:
@@ -9218,8 +9247,8 @@ table_factor:
lex->pop_context();
lex->nest_level--;
}
- else if ($3->select_lex &&
- $3->select_lex->master_unit()->is_union() || $5)
+ else if (($3->select_lex &&
+ $3->select_lex->master_unit()->is_union()) || $5)
{
/* simple nested joins cannot have aliases or unions */
my_parse_error(ER(ER_SYNTAX_ERROR));
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index fe3114c9d50..eef403e1a86 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -241,15 +241,25 @@ 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 RBR and open temporary tables, their CREATE TABLE may not be in the
- binlog, so we can't toggle to SBR in this connection.
+ 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.
+
+ If binlog_format=MIXED, there are open temporary tables, and an unsafe
+ statement is executed, then subsequent statements are logged in row
+ format and hence changes to temporary tables may be lost. So we forbid
+ switching @@SESSION.binlog_format from MIXED to STATEMENT when there are
+ open temp tables and we are logging in row format.
*/
- if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
- thd->temporary_tables)
+ if (thd->temporary_tables && var->type == OPT_SESSION &&
+ var->save_result.ulonglong_value == BINLOG_FORMAT_STMT &&
+ ((thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
+ thd->is_current_stmt_binlog_format_row()) ||
+ thd->variables.binlog_format == BINLOG_FORMAT_ROW))
{
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
return true;
}
+
/*
if in a stored function/trigger, it's too late to change mode
*/
@@ -324,7 +334,7 @@ static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var)
return true;
if (var->type == OPT_GLOBAL ||
(thd->variables.binlog_direct_non_trans_update ==
- var->save_result.ulonglong_value))
+ static_cast<my_bool>(var->save_result.ulonglong_value)))
return false;
return false;
@@ -2956,14 +2966,14 @@ static bool check_locale(sys_var *self, THD *thd, set_var *var)
static Sys_var_struct Sys_lc_messages(
"lc_messages", "Set the language used for the error messages",
SESSION_VAR(lc_messages), NO_CMD_LINE,
- offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_messages),
+ my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_messages),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_locale));
static Sys_var_struct Sys_lc_time_names(
"lc_time_names", "Set the language used for the month "
"names and the days of the week",
SESSION_VAR(lc_time_names), NO_CMD_LINE,
- offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_time_names),
+ my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_time_names),
NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_locale));
static Sys_var_tz Sys_time_zone(
diff --git a/sql/unireg.h b/sql/unireg.h
index def4fb12b39..9932be7ae74 100644
--- a/sql/unireg.h
+++ b/sql/unireg.h
@@ -46,6 +46,9 @@
#define ER(X) CURRENT_THD_ERRMSGS[(X) - ER_ERROR_FIRST]
#define ER_DEFAULT(X) DEFAULT_ERRMSGS[(X) - ER_ERROR_FIRST]
#define ER_SAFE(X) (((X) >= ER_ERROR_FIRST && (X) <= ER_ERROR_LAST) ? ER(X) : "Invalid error code")
+#define ER_THD(thd,X) ((thd)->variables.lc_messages->errmsgs->errmsgs[(X) - \
+ ER_ERROR_FIRST])
+#define ER_THD_OR_DEFAULT(thd,X) ((thd) ? ER_THD(thd, X) : ER_DEFAULT(X))
#define ERRMAPP 1 /* Errormap f|r my_error */