summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorsjaakola <seppo.jaakola@iki.fi>2017-02-16 23:19:10 +0200
committerJan Lindström <jan.lindstrom@mariadb.com>2017-08-11 13:23:51 +0300
commit7ef2d5aa5b5d0179d40bd42afea874235b8b60f8 (patch)
treefd6a5094243c31e603ef65c77f582d7867aba18a /sql/sql_table.cc
parent364b15c090e7337eb752eec4bea239052f73b2ed (diff)
downloadmariadb-git-7ef2d5aa5b5d0179d40bd42afea874235b8b60f8.tar.gz
Refs: MW-360 * splitting DROP TABLE query in separate DROP commands for temporary and real tables * not replicating temporary table DROP command * using wsrep_sidno GTID group only for innodb table drop command part all this follows more or less the logic of how mysql wants to split drop table list
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index e591b8a1eb7..6a9107cb240 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -2156,7 +2156,95 @@ static uint32 comment_length(THD *thd, uint32 comment_pos,
return 0;
}
+#ifdef WITH_WSREP
+static void
+wsrep_append_name(THD *thd, String *packet, const char *name, uint length,
+ const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs)
+{
+ const char *to_name= name;
+ size_t to_length= length;
+ String to_string(name,length, from_cs);
+ if (from_cs != NULL && to_cs != NULL && from_cs != to_cs)
+ thd->convert_string(&to_string, from_cs, to_cs);
+
+ if (to_cs != NULL)
+ {
+ to_name= to_string.c_ptr();
+ to_length= to_string.length();
+ }
+ packet->append(to_name, to_length, packet->charset());
+}
+
+int wsrep_replicate_drop_query(THD *thd, TABLE_LIST *tables, bool if_exists,
+ bool drop_temporary, bool dont_log_query)
+{
+ TABLE_LIST *table;
+ int error= 0;
+ String built_query;
+ bool non_tmp_table_deleted= FALSE;
+ DBUG_ENTER("wsrep_build_drop_query");
+
+ if (!dont_log_query)
+ {
+ if (!drop_temporary)
+ {
+ built_query.set_charset(system_charset_info);
+ if (if_exists)
+ built_query.append("DROP TABLE IF EXISTS ");
+ else
+ built_query.append("DROP TABLE ");
+ }
+ }
+
+ for (table= tables; table; table= table->next_local)
+ {
+ char *db=table->db;
+ int db_len= table->db_length;
+
+ DBUG_PRINT("table", ("table_l: '%s'.'%s' table: 0x%lx s: 0x%lx",
+ table->db, table->table_name, (long) table->table,
+ table->table ? (long) table->table->s : (long) -1));
+
+ if (!find_temporary_table(thd, table))
+ {
+ non_tmp_table_deleted= TRUE;
+
+ if (thd->db == NULL || strcmp(db,thd->db) != 0)
+ {
+ wsrep_append_name(thd, &built_query, db, db_len,
+ system_charset_info, thd->charset());
+ built_query.append(".");
+ }
+
+ thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE;
+ wsrep_append_name(thd, &built_query, table->table_name,
+ strlen(table->table_name), system_charset_info,
+ thd->charset());
+ built_query.append(",");
+ }
+ }
+
+err:
+ if (non_tmp_table_deleted)
+ {
+ /* Chop of the last comma */
+ built_query.chop();
+ built_query.append(" /* generated by server */");
+ WSREP_DEBUG("TOI for %s", built_query.ptr());
+ if (WSREP_TO_ISOLATION_BEGIN_QUERY(built_query.ptr(), NULL, NULL, tables))
+ {
+ WSREP_DEBUG("TOI failed for DROP TABLE: %s", WSREP_QUERY(thd));
+ error= 1;
+ goto end;
+ }
+ }
+
+end:
+ DBUG_RETURN(error);
+}
+
+#endif /* WITH_WSREP */
/**
Execute the drop of a normal or temporary table.
@@ -2591,6 +2679,9 @@ err:
/* Chop of the last comma */
built_non_trans_tmp_query.chop();
built_non_trans_tmp_query.append(" /* generated by server */");
+#ifdef WITH_WSREP
+ thd->wsrep_skip_wsrep_GTID = true;
+#endif /* WITH_WSREP */
error |= thd->binlog_query(THD::STMT_QUERY_TYPE,
built_non_trans_tmp_query.ptr(),
built_non_trans_tmp_query.length(),
@@ -2603,6 +2694,9 @@ err:
/* Chop of the last comma */
built_trans_tmp_query.chop();
built_trans_tmp_query.append(" /* generated by server */");
+#ifdef WITH_WSREP
+ thd->wsrep_skip_wsrep_GTID = true;
+#endif /* WITH_WSREP */
error |= thd->binlog_query(THD::STMT_QUERY_TYPE,
built_trans_tmp_query.ptr(),
built_trans_tmp_query.length(),
@@ -2617,6 +2711,9 @@ err:
built_query.append(" /* generated by server */");
int error_code = non_tmp_error ? thd->get_stmt_da()->sql_errno()
: 0;
+#ifdef WITH_WSREP
+ thd->wsrep_skip_wsrep_GTID = false;
+#endif /* WITH_WSREP */
error |= thd->binlog_query(THD::STMT_QUERY_TYPE,
built_query.ptr(),
built_query.length(),
@@ -2665,6 +2762,9 @@ err:
}
end:
+#ifdef WITH_WSREP
+ thd->wsrep_skip_wsrep_GTID = false;
+#endif /* WITH_WSREP */
DBUG_RETURN(error);
}