summaryrefslogtreecommitdiff
path: root/sql/sql_load.cc
diff options
context:
space:
mode:
authorLuis Soares <luis.soares@sun.com>2009-10-27 15:15:53 +0000
committerLuis Soares <luis.soares@sun.com>2009-10-27 15:15:53 +0000
commita3829176845d5f357d5d6a3288543cec93ba2450 (patch)
tree1cf73005cabb5c5d2ae471fa5fe2357d1e51fee4 /sql/sql_load.cc
parent74b0f6be2fd8f0f46f490fd2b10f6dbfef9dad41 (diff)
downloadmariadb-git-a3829176845d5f357d5d6a3288543cec93ba2450.tar.gz
BUG#48297: Schema name is ignored when LOAD DATA is written into
binlog, replication aborts In SBR or MBR, the schema name is not being written to the binlog when executing a LOAD DATA statement. This becomes a problem when the current database (lets call it db1) is different from the table's schema (lets call it db2). For instance, take the following statements: use db1; load data local infile 'infile.txt' into table db2.t Should this statement be logged without t's schema (db2), when replaying it, one can get db1.t populated instead of db2.t (if db1.t exists). On the other hand, if there is no db1.t at all, replication will stop. We fix this by always logging the table (in load file) with fully qualified name when its schema is different from the current database or when no default database was selected.
Diffstat (limited to 'sql/sql_load.cc')
-rw-r--r--sql/sql_load.cc30
1 files changed, 25 insertions, 5 deletions
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 59ba7b16d62..5500439b619 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -84,7 +84,7 @@ static int read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
bool ignore_check_option_errors);
#ifndef EMBEDDED_LIBRARY
static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
- const char* db_arg,
+ const char* db_arg, /* table's database */
const char* table_name_arg,
enum enum_duplicates duplicates,
bool ignore,
@@ -501,7 +501,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
if (thd->transaction.stmt.modified_non_trans_table)
write_execute_load_query_log_event(thd, ex,
- tdb, table_list->table_name,
+ table_list->db,
+ table_list->table_name,
handle_duplicates, ignore,
transactional_table,
errcode);
@@ -548,7 +549,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
{
int errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
write_execute_load_query_log_event(thd, ex,
- tdb, table_list->table_name,
+ table_list->db, table_list->table_name,
handle_duplicates, ignore,
transactional_table,
errcode);
@@ -573,7 +574,7 @@ err:
/* Not a very useful function; just to avoid duplication of code */
static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
- const char* db_arg,
+ const char* db_arg, /* table's database */
const char* table_name_arg,
enum enum_duplicates duplicates,
bool ignore,
@@ -590,8 +591,27 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
Item *item, *val;
String pfield, pfields;
int n;
+ const char *tbl= table_name_arg;
+ const char *tdb= (thd->db != NULL ? thd->db : db_arg);
+ String string_buf;
- Load_log_event lle(thd, ex, db_arg, table_name_arg, fv, duplicates,
+ if (!thd->db || strcmp(db_arg, thd->db))
+ {
+ /*
+ If used database differs from table's database,
+ prefix table name with database name so that it
+ becomes a FQ name.
+ */
+ string_buf.set_charset(system_charset_info);
+ string_buf.append(db_arg);
+ string_buf.append("`");
+ string_buf.append(".");
+ string_buf.append("`");
+ string_buf.append(table_name_arg);
+ tbl= string_buf.c_ptr_safe();
+ }
+
+ Load_log_event lle(thd, ex, tdb, tbl, fv, duplicates,
ignore, transactional_table);
/*