Commit 51392386 authored by Michael Widenius's avatar Michael Widenius

Switch automaticly to statement based replication for statements that can't...

Switch automaticly to statement based replication for statements that can't generate row based events. This is needed to avoid getting
updates to system, statistics and admin tables logged to binary log.
- Removed special code used to temporarily change to statement based replication.
- Changed to a faster and smaller interface for temporarily switching to statement based replication.

sql/event_db_repository.cc:
  Change to new interface to not use row based replication for system table changes.
sql/events.cc:
  Change to new interface to not use row based replication for system table changes.
sql/sp.cc:
  Removed temporarily switching to statement based replication (this is now done automaticly in mysql_execute_command())
sql/sql_acl.cc:
  Change to new interface to not use row based replication for system table changes.
  Removed temporarily switching to statement based replication (this is now done automaticly in mysql_execute_command())
sql/sql_class.h:
  Added new interface for temporarily switching to statement based replication.
sql/sql_parse.cc:
  Mark commands that needs original replication mode with CF_FORCE_ORIGINAL_BINLOG_FORMAT.
  Switch automaticly to statement based replication for statements that can't generate row based events (and can't change replication mode)
sql/sql_udf.cc:
  Removed temporarily switching to statement based replication (this is now done automaticly in mysql_execute_command())
parent bc644de9
...@@ -1112,17 +1112,15 @@ update_timing_fields_for_event(THD *thd, ...@@ -1112,17 +1112,15 @@ update_timing_fields_for_event(THD *thd,
TABLE *table= NULL; TABLE *table= NULL;
Field **fields; Field **fields;
int ret= 1; int ret= 1;
bool save_binlog_row_based; enum_binlog_format save_binlog_format;
MYSQL_TIME time; MYSQL_TIME time;
DBUG_ENTER("Event_db_repository::update_timing_fields_for_event"); DBUG_ENTER("Event_db_repository::update_timing_fields_for_event");
/* /*
Turn off row binlogging of event timing updates. These are not used Turn off row binlogging of event timing updates. These are not used
for RBR of events replicated to the slave. for RBR of events replicated to the slave.
*/ */
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) save_binlog_format= thd->set_current_stmt_binlog_format_stmt();
thd->clear_current_stmt_binlog_format_row();
DBUG_ASSERT(thd->security_ctx->master_access & SUPER_ACL); DBUG_ASSERT(thd->security_ctx->master_access & SUPER_ACL);
...@@ -1157,10 +1155,7 @@ end: ...@@ -1157,10 +1155,7 @@ end:
if (table) if (table)
close_mysql_tables(thd); close_mysql_tables(thd);
/* Restore the state of binlog format */ thd->restore_stmt_binlog_format(save_binlog_format);
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)); DBUG_RETURN(test(ret));
} }
......
...@@ -306,7 +306,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -306,7 +306,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
bool if_not_exists) bool if_not_exists)
{ {
bool ret; bool ret;
bool save_binlog_row_based, event_already_exists; bool event_already_exists;
enum_binlog_format save_binlog_format;
DBUG_ENTER("Events::create_event"); DBUG_ENTER("Events::create_event");
if (check_if_system_tables_error()) if (check_if_system_tables_error())
...@@ -338,8 +339,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -338,8 +339,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
Turn off row binlogging of this statement and use statement-based Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for CREATE EVENT command. so that all supporting tables are updated for CREATE EVENT command.
*/ */
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) save_binlog_format= thd->set_current_stmt_binlog_format_stmt();
thd->clear_current_stmt_binlog_format_row();
if (lock_object_name(thd, MDL_key::EVENT, if (lock_object_name(thd, MDL_key::EVENT,
parse_data->dbname.str, parse_data->name.str)) parse_data->dbname.str, parse_data->name.str))
...@@ -398,10 +398,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -398,10 +398,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
} }
} }
} }
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); thd->restore_stmt_binlog_format(save_binlog_format);
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -431,7 +429,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, ...@@ -431,7 +429,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
LEX_STRING *new_dbname, LEX_STRING *new_name) LEX_STRING *new_dbname, LEX_STRING *new_name)
{ {
int ret; int ret;
bool save_binlog_row_based; enum_binlog_format save_binlog_format;
Event_queue_element *new_element; Event_queue_element *new_element;
DBUG_ENTER("Events::update_event"); DBUG_ENTER("Events::update_event");
...@@ -478,8 +476,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, ...@@ -478,8 +476,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
Turn off row binlogging of this statement and use statement-based Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for UPDATE EVENT command. so that all supporting tables are updated for UPDATE EVENT command.
*/ */
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) save_binlog_format= thd->set_current_stmt_binlog_format_stmt();
thd->clear_current_stmt_binlog_format_row();
if (lock_object_name(thd, MDL_key::EVENT, if (lock_object_name(thd, MDL_key::EVENT,
parse_data->dbname.str, parse_data->name.str)) parse_data->dbname.str, parse_data->name.str))
...@@ -513,11 +510,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, ...@@ -513,11 +510,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
} }
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
thd->restore_stmt_binlog_format(save_binlog_format);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -550,7 +544,7 @@ bool ...@@ -550,7 +544,7 @@ bool
Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
{ {
int ret; int ret;
bool save_binlog_row_based; enum_binlog_format save_binlog_format;
DBUG_ENTER("Events::drop_event"); DBUG_ENTER("Events::drop_event");
if (check_if_system_tables_error()) if (check_if_system_tables_error())
...@@ -563,8 +557,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) ...@@ -563,8 +557,7 @@ 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 Turn off row binlogging of this statement and use statement-based so
that all supporting tables are updated for DROP EVENT command. that all supporting tables are updated for DROP EVENT command.
*/ */
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row())) save_binlog_format= thd->set_current_stmt_binlog_format_stmt();
thd->clear_current_stmt_binlog_format_row();
if (lock_object_name(thd, MDL_key::EVENT, if (lock_object_name(thd, MDL_key::EVENT,
dbname.str, name.str)) dbname.str, name.str))
...@@ -578,10 +571,8 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) ...@@ -578,10 +571,8 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
DBUG_ASSERT(thd->query() && thd->query_length()); DBUG_ASSERT(thd->query() && thd->query_length());
ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); thd->restore_stmt_binlog_format(save_binlog_format);
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
......
...@@ -984,9 +984,6 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) ...@@ -984,9 +984,6 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
enum_check_fields saved_count_cuted_fields; enum_check_fields saved_count_cuted_fields;
bool store_failed= FALSE; bool store_failed= FALSE;
bool save_binlog_row_based;
DBUG_ENTER("sp_create_routine"); DBUG_ENTER("sp_create_routine");
DBUG_PRINT("enter", ("type: %d name: %.*s", (int) type, DBUG_PRINT("enter", ("type: %d name: %.*s", (int) type,
(int) sp->m_name.length, (int) sp->m_name.length,
...@@ -1004,14 +1001,6 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) ...@@ -1004,14 +1001,6 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
/* Reset sql_mode during data dictionary operations. */ /* Reset sql_mode during data dictionary operations. */
thd->variables.sql_mode= 0; thd->variables.sql_mode= 0;
/*
This statement will be replicated as a statement, even when using
row-based replication. The flag will be reset at the end of the
statement.
*/
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; saved_count_cuted_fields= thd->count_cuted_fields;
thd->count_cuted_fields= CHECK_FIELD_WARN; thd->count_cuted_fields= CHECK_FIELD_WARN;
...@@ -1217,10 +1206,7 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp) ...@@ -1217,10 +1206,7 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
done: done:
thd->count_cuted_fields= saved_count_cuted_fields; thd->count_cuted_fields= saved_count_cuted_fields;
thd->variables.sql_mode= saved_mode; thd->variables.sql_mode= saved_mode;
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -1245,7 +1231,6 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name) ...@@ -1245,7 +1231,6 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name)
{ {
TABLE *table; TABLE *table;
int ret; int ret;
bool save_binlog_row_based;
MDL_key::enum_mdl_namespace mdl_type= type == TYPE_ENUM_FUNCTION ? MDL_key::enum_mdl_namespace mdl_type= type == TYPE_ENUM_FUNCTION ?
MDL_key::FUNCTION : MDL_key::PROCEDURE; MDL_key::FUNCTION : MDL_key::PROCEDURE;
DBUG_ENTER("sp_drop_routine"); DBUG_ENTER("sp_drop_routine");
...@@ -1267,9 +1252,6 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name) ...@@ -1267,9 +1252,6 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name)
row-based replication. The flag will be reset at the end of the row-based replication. The flag will be reset at the end of the
statement. statement.
*/ */
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK) if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
{ {
if (table->file->ha_delete_row(table->record[0])) if (table->file->ha_delete_row(table->record[0]))
...@@ -1296,10 +1278,7 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name) ...@@ -1296,10 +1278,7 @@ sp_drop_routine(THD *thd, stored_procedure_type type, sp_name *name)
sp_cache_flush_obsolete(spc, &sp); sp_cache_flush_obsolete(spc, &sp);
} }
} }
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -1327,7 +1306,6 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name, ...@@ -1327,7 +1306,6 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name,
{ {
TABLE *table; TABLE *table;
int ret; int ret;
bool save_binlog_row_based;
MDL_key::enum_mdl_namespace mdl_type= type == TYPE_ENUM_FUNCTION ? MDL_key::enum_mdl_namespace mdl_type= type == TYPE_ENUM_FUNCTION ?
MDL_key::FUNCTION : MDL_key::PROCEDURE; MDL_key::FUNCTION : MDL_key::PROCEDURE;
DBUG_ENTER("sp_update_routine"); DBUG_ENTER("sp_update_routine");
...@@ -1345,14 +1323,6 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name, ...@@ -1345,14 +1323,6 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name,
if (!(table= open_proc_table_for_update(thd))) if (!(table= open_proc_table_for_update(thd)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
/*
This statement will be replicated as a statement, even when using
row-based replication. The flag will be reset at the end of the
statement.
*/
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK) if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
{ {
if (type == TYPE_ENUM_FUNCTION && ! trust_function_creators && if (type == TYPE_ENUM_FUNCTION && ! trust_function_creators &&
...@@ -1406,10 +1376,7 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name, ...@@ -1406,10 +1376,7 @@ sp_update_routine(THD *thd, stored_procedure_type type, sp_name *name,
sp_cache_invalidate(); sp_cache_invalidate();
} }
err: err:
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row()); DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
......
This diff is collapsed.
...@@ -2722,6 +2722,27 @@ public: ...@@ -2722,6 +2722,27 @@ public:
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup); void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
void restore_active_arena(Query_arena *set, Query_arena *backup); void restore_active_arena(Query_arena *set, Query_arena *backup);
inline void get_binlog_format(enum_binlog_format *format,
enum_binlog_format *current_format)
{
*format= (enum_binlog_format) variables.binlog_format;
*current_format= current_stmt_binlog_format;
}
inline void set_binlog_format(enum_binlog_format format,
enum_binlog_format current_format)
{
DBUG_ENTER("set_binlog_format");
variables.binlog_format= format;
current_stmt_binlog_format= current_format;
DBUG_VOID_RETURN;
}
inline void set_binlog_format_stmt()
{
DBUG_ENTER("set_binlog_format_stmt");
variables.binlog_format= BINLOG_FORMAT_STMT;
current_stmt_binlog_format= BINLOG_FORMAT_STMT;
DBUG_VOID_RETURN;
}
/* /*
@todo Make these methods private or remove them completely. Only @todo Make these methods private or remove them completely. Only
decide_logging_format should call them. /Sven decide_logging_format should call them. /Sven
...@@ -2752,16 +2773,26 @@ public: ...@@ -2752,16 +2773,26 @@ public:
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
inline void set_current_stmt_binlog_format_row() inline void set_current_stmt_binlog_format_row()
{ {
DBUG_ENTER("set_current_stmt_binlog_format_row"); DBUG_ENTER("set_current_stmt_binlog_format_row");
current_stmt_binlog_format= BINLOG_FORMAT_ROW; current_stmt_binlog_format= BINLOG_FORMAT_ROW;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
inline void clear_current_stmt_binlog_format_row() /* Set binlog format temporarily to statement. Returns old format */
inline enum_binlog_format set_current_stmt_binlog_format_stmt()
{ {
DBUG_ENTER("clear_current_stmt_binlog_format_row"); enum_binlog_format orig_format= current_stmt_binlog_format;
DBUG_ENTER("set_current_stmt_binlog_format_stmt");
current_stmt_binlog_format= BINLOG_FORMAT_STMT; current_stmt_binlog_format= BINLOG_FORMAT_STMT;
DBUG_RETURN(orig_format);
}
inline void restore_stmt_binlog_format(enum_binlog_format format)
{
DBUG_ENTER("restore_stmt_binlog_format");
DBUG_ASSERT(!is_current_stmt_binlog_format_row());
current_stmt_binlog_format= format;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
inline void reset_current_stmt_binlog_format_row() inline void reset_current_stmt_binlog_format_row()
...@@ -2791,7 +2822,7 @@ public: ...@@ -2791,7 +2822,7 @@ public:
if (variables.binlog_format == BINLOG_FORMAT_ROW) if (variables.binlog_format == BINLOG_FORMAT_ROW)
set_current_stmt_binlog_format_row(); set_current_stmt_binlog_format_row();
else if (temporary_tables == NULL) else if (temporary_tables == NULL)
clear_current_stmt_binlog_format_row(); set_current_stmt_binlog_format_stmt();
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -4085,6 +4116,11 @@ public: ...@@ -4085,6 +4116,11 @@ public:
*/ */
#define CF_CAN_GENERATE_ROW_EVENTS (1U << 9) #define CF_CAN_GENERATE_ROW_EVENTS (1U << 9)
/**
Statement that need the binlog format to be unchanged.
*/
#define CF_FORCE_ORIGINAL_BINLOG_FORMAT (1U << 10)
/* Bits in server_command_flags */ /* Bits in server_command_flags */
/** /**
......
...@@ -350,7 +350,7 @@ void init_update_queries(void) ...@@ -350,7 +350,7 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_SHOW_CREATE_EVENT]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_CREATE_EVENT]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROFILES]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_PROFILES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PROFILE]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_PROFILE]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_BINLOG_BASE64_EVENT]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_BINLOG_BASE64_EVENT]= CF_STATUS_COMMAND | CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_SHOW_CLIENT_STATS]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_CLIENT_STATS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_USER_STATS]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_USER_STATS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_TABLE_STATS]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_TABLE_STATS]= CF_STATUS_COMMAND;
...@@ -385,6 +385,19 @@ void init_update_queries(void) ...@@ -385,6 +385,19 @@ void init_update_queries(void)
CF_CAN_GENERATE_ROW_EVENTS; CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_EXECUTE]= CF_CAN_GENERATE_ROW_EVENTS; sql_command_flags[SQLCOM_EXECUTE]= CF_CAN_GENERATE_ROW_EVENTS;
/*
We don't want to change to statement based replication for these commands
*/
sql_command_flags[SQLCOM_ROLLBACK]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
/* We don't want to replicate ALTER TABLE for temp tables in row format */
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
/* We don't want to replicate TRUNCATE for temp tables in row format */
sql_command_flags[SQLCOM_TRUNCATE]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
/* We don't want to replicate DROP for temp tables in row format */
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
/* One can change replication mode with SET */
sql_command_flags[SQLCOM_SET_OPTION]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
/* /*
The following admin table operations are allowed The following admin table operations are allowed
on log tables. on log tables.
...@@ -2102,6 +2115,22 @@ mysql_execute_command(THD *thd) ...@@ -2102,6 +2115,22 @@ mysql_execute_command(THD *thd)
DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE); DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE);
/* store old value of binlog format */
enum_binlog_format orig_binlog_format,orig_current_stmt_binlog_format;
thd->get_binlog_format(&orig_binlog_format,
&orig_current_stmt_binlog_format);
/*
Force statement logging for DDL commands to allow us to update
privilege, system or statistic tables directly without the updates
getting logged.
*/
if (!(sql_command_flags[lex->sql_command] &
(CF_CAN_GENERATE_ROW_EVENTS | CF_FORCE_ORIGINAL_BINLOG_FORMAT |
CF_STATUS_COMMAND)))
thd->set_binlog_format_stmt();
/* /*
End a active transaction so that this command will have it's End a active transaction so that this command will have it's
own transaction and will also sync the binary log. If a DDL is own transaction and will also sync the binary log. If a DDL is
...@@ -4529,6 +4558,11 @@ finish: ...@@ -4529,6 +4558,11 @@ finish:
if (lex->sql_command != SQLCOM_SET_OPTION && ! thd->in_sub_stmt) if (lex->sql_command != SQLCOM_SET_OPTION && ! thd->in_sub_stmt)
DEBUG_SYNC(thd, "execute_command_after_close_tables"); DEBUG_SYNC(thd, "execute_command_after_close_tables");
#endif #endif
if (!(sql_command_flags[lex->sql_command] &
(CF_CAN_GENERATE_ROW_EVENTS | CF_FORCE_ORIGINAL_BINLOG_FORMAT |
CF_STATUS_COMMAND)))
thd->set_binlog_format(orig_binlog_format,
orig_current_stmt_binlog_format);
if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END)) if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END))
{ {
......
...@@ -428,7 +428,6 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -428,7 +428,6 @@ int mysql_create_function(THD *thd,udf_func *udf)
TABLE *table; TABLE *table;
TABLE_LIST tables; TABLE_LIST tables;
udf_func *u_d; udf_func *u_d;
bool save_binlog_row_based;
DBUG_ENTER("mysql_create_function"); DBUG_ENTER("mysql_create_function");
if (!initialized) if (!initialized)
...@@ -459,13 +458,6 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -459,13 +458,6 @@ int mysql_create_function(THD *thd,udf_func *udf)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
/*
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for CREATE FUNCTION command.
*/
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); mysql_rwlock_wrlock(&THR_LOCK_udf);
if ((my_hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length))) if ((my_hash_search(&udf_hash,(uchar*) udf->name.str, udf->name.length)))
{ {
...@@ -533,27 +525,14 @@ int mysql_create_function(THD *thd,udf_func *udf) ...@@ -533,27 +525,14 @@ int mysql_create_function(THD *thd,udf_func *udf)
/* Binlog the create function. */ /* Binlog the create function. */
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
{
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1); DBUG_RETURN(1);
}
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
if (new_dl) if (new_dl)
dlclose(dl); dlclose(dl);
mysql_rwlock_unlock(&THR_LOCK_udf); mysql_rwlock_unlock(&THR_LOCK_udf);
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -565,7 +544,6 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) ...@@ -565,7 +544,6 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
udf_func *udf; udf_func *udf;
char *exact_name_str; char *exact_name_str;
uint exact_name_len; uint exact_name_len;
bool save_binlog_row_based;
DBUG_ENTER("mysql_drop_function"); DBUG_ENTER("mysql_drop_function");
if (!initialized) if (!initialized)
...@@ -577,13 +555,6 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) ...@@ -577,13 +555,6 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
/*
Turn off row binlogging of this statement and use statement-based
so that all supporting tables are updated for DROP FUNCTION command.
*/
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); mysql_rwlock_wrlock(&THR_LOCK_udf);
if (!(udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) udf_name->str, if (!(udf=(udf_func*) my_hash_search(&udf_hash,(uchar*) udf_name->str,
(uint) udf_name->length))) (uint) udf_name->length)))
...@@ -623,24 +594,12 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) ...@@ -623,24 +594,12 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
while binlogging, to avoid binlog inconsistency. while binlogging, to avoid binlog inconsistency.
*/ */
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length())) if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
{
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1); DBUG_RETURN(1);
}
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
mysql_rwlock_unlock(&THR_LOCK_udf); mysql_rwlock_unlock(&THR_LOCK_udf);
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment