From 228479a28ce7e4c91f96962159fccc8dc71b5a36 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Mon, 29 May 2017 11:35:36 +0300 Subject: MDEV-8075: DROP TEMPORARY TABLE not marked as ddl, causing optimistic parallel replication to fail CREATE/DROP TEMPORARY TABLE are not safe to optimistically replicate in parallel with other transactions, so they need to be marked as "ddl" in the binlog. This was already done for stand-alone CREATE/DROP TEMPORARY. But temporary tables can also be created and dropped inside a BEGIN...END transaction, and such transactions were not marked as ddl. Nor was the DROP TEMPORARY TABLE statement emitted implicitly when a client connection is closed. So this patch adds such ddl mark for the missing cases. The difference to Kristian's original patch is mainly a fix in mysql_trans_commit_alter_copy_data() to remember the unsafe_rollback_flags over the temporary commit. --- sql/sql_table.cc | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index db0d6d4f377..ace8ff1a7a9 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2560,6 +2560,9 @@ err: if (non_trans_tmp_table_deleted || trans_tmp_table_deleted || non_tmp_table_deleted) { + if (non_trans_tmp_table_deleted || trans_tmp_table_deleted) + thd->transaction.stmt.mark_dropped_temp_table(); + query_cache_invalidate3(thd, tables, 0); if (!dont_log_query && mysql_bin_log.is_open()) { @@ -5073,6 +5076,9 @@ err: if (thd->is_current_stmt_binlog_format_row() && create_info->tmp_table()) DBUG_RETURN(result); + if (create_info->tmp_table()) + thd->transaction.stmt.mark_created_temp_table(); + /* Write log if no error or if we already deleted a table */ if (!result || thd->log_current_statement) { @@ -5567,13 +5573,17 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, DBUG_PRINT("info", ("res: %d tmp_table: %d create_info->table: %p", res, create_info->tmp_table(), local_create_info.table)); - if (!res && create_info->tmp_table() && local_create_info.table) + if (create_info->tmp_table()) { - /* - Remember that tmp table creation was logged so that we know if - we should log a delete of it. - */ - local_create_info.table->s->table_creation_was_logged= 1; + thd->transaction.stmt.mark_created_temp_table(); + if (!res && local_create_info.table) + { + /* + Remember that tmp table creation was logged so that we know if + we should log a delete of it. + */ + local_create_info.table->s->table_creation_was_logged= 1; + } } do_logging= TRUE; } @@ -9366,8 +9376,12 @@ bool mysql_trans_prepare_alter_copy_data(THD *thd) bool mysql_trans_commit_alter_copy_data(THD *thd) { bool error= FALSE; + uint save_unsafe_rollback_flags; DBUG_ENTER("mysql_trans_commit_alter_copy_data"); + /* Save flags as transcommit_implicit_are_deleting_them */ + save_unsafe_rollback_flags= thd->transaction.stmt.m_unsafe_rollback_flags; + if (ha_enable_transaction(thd, TRUE)) DBUG_RETURN(TRUE); @@ -9382,6 +9396,7 @@ bool mysql_trans_commit_alter_copy_data(THD *thd) if (trans_commit_implicit(thd)) error= TRUE; + thd->transaction.stmt.m_unsafe_rollback_flags= save_unsafe_rollback_flags; DBUG_RETURN(error); } -- cgit v1.2.1 From 9edfc00697b6b97e838d517cdb1883ea115c4746 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 23 Jun 2017 18:15:07 +0200 Subject: MDEV-11930 Unexpected ER_ERROR_EVALUATING_EXPRESSION warning upon dropping database with a bad table DBUG_EXECUTE_IF was wrong, it used my_error, but didn't do error=1. It's not clear what it was actually testing, what it was supposed to be testing, and what it has to do with bug#43138, so I removed it. --- sql/sql_table.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dcae5435d57..db708ff613c 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2522,10 +2522,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, DBUG_PRINT("table", ("table: 0x%lx s: 0x%lx", (long) table->table, table->table ? (long) table->table->s : (long) -1)); - - DBUG_EXECUTE_IF("bug43138", - my_error(ER_BAD_TABLE_ERROR, MYF(0), - table->table_name);); } DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog"); thd->thread_specific_used|= (trans_tmp_table_deleted || -- cgit v1.2.1 From 504eff0ca13ef93fa46f919e1fb60b58ac9a34eb Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 28 Jun 2017 12:50:18 +0200 Subject: cleanup: generate_partition_syntax() Don't write to a temporary file, use String. Remove strange one-liner "helpers", use String methods. Don't use current_thd, don't allocate memory for 1-byte strings, etc. --- sql/sql_table.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index db708ff613c..222b3182114 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1820,11 +1820,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) if (part_info) { if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info, - &syntax_len, - TRUE, TRUE, + &syntax_len, TRUE, lpt->create_info, - lpt->alter_info, - NULL))) + lpt->alter_info))) { DBUG_RETURN(TRUE); } @@ -1903,11 +1901,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) TABLE_SHARE *share= lpt->table->s; char *tmp_part_syntax_str; if (!(part_syntax_buf= generate_partition_syntax(lpt->thd, part_info, - &syntax_len, - TRUE, TRUE, + &syntax_len, TRUE, lpt->create_info, - lpt->alter_info, - NULL))) + lpt->alter_info))) { error= 1; goto err; @@ -4548,11 +4544,9 @@ handler *mysql_create_frm_image(THD *thd, for syntax stored in frm file. */ if (!(part_syntax_buf= generate_partition_syntax(thd, part_info, - &syntax_len, - TRUE, TRUE, + &syntax_len, TRUE, create_info, - alter_info, - NULL))) + alter_info))) goto err; part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; -- cgit v1.2.1 From 48c22a68b1ea3c2004e31ace37d56fa8a515dba8 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 28 Jun 2017 16:06:07 +0200 Subject: MDEV-13089 identifier quoting in partitioning remove ANSI_QUOTES when generating partition syntax for frm --- sql/sql_table.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 222b3182114..5e247915905 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4543,10 +4543,12 @@ handler *mysql_create_frm_image(THD *thd, We reverse the partitioning parser and generate a standard format for syntax stored in frm file. */ - if (!(part_syntax_buf= generate_partition_syntax(thd, part_info, - &syntax_len, TRUE, - create_info, - alter_info))) + sql_mode_t old_mode= thd->variables.sql_mode; + thd->variables.sql_mode &= ~MODE_ANSI_QUOTES; + part_syntax_buf= generate_partition_syntax(thd, part_info, &syntax_len, + true, create_info, alter_info); + thd->variables.sql_mode= old_mode; + if (!part_syntax_buf) goto err; part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; -- cgit v1.2.1