summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2000-11-25 23:30:02 -0700
committerunknown <sasha@mysql.sashanet.com>2000-11-25 23:30:02 -0700
commit7648e3bc3c3dd27f97b878760938f748499fd378 (patch)
tree9458409b0b7f19a9c39b35787b75b1000b592652 /sql
parentc3cc5856a5d9ee8fa3d01207613f961ae110b2cd (diff)
downloadmariadb-git-7648e3bc3c3dd27f97b878760938f748499fd378.tar.gz
yes, and a small change to log_event.h
sql/log_event.h: thread_id needs to be ulong sql/sql_base.cc: log drop of temp tables after disconnect add info about original thread on the master to table_cache_key
Diffstat (limited to 'sql')
-rw-r--r--sql/log_event.h4
-rw-r--r--sql/sql_base.cc68
2 files changed, 65 insertions, 7 deletions
diff --git a/sql/log_event.h b/sql/log_event.h
index c956cfde396..b31d444ad21 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -115,7 +115,7 @@ public:
// otherwise, set it to 0, in which case, we compute it with strlen()
uint32 db_len;
uint16 error_code;
- int thread_id;
+ ulong thread_id;
#if !defined(MYSQL_CLIENT)
THD* thd;
Query_log_event(THD* thd_arg, const char* query_arg):
@@ -186,7 +186,7 @@ protected:
void copy_log_event(const char *buf, ulong data_len);
public:
- int thread_id;
+ ulong thread_id;
uint32 table_name_len;
uint32 db_len;
uint32 fname_len;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 3560fc42d49..45bd8959a8e 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -422,11 +422,48 @@ void close_temporary(TABLE *table,bool delete_table)
void close_temporary_tables(THD *thd)
{
TABLE *table,*next;
+ uint init_query_buf_size = 11, query_buf_size; // "drop table "
+ char* query, *p;
+ LINT_INIT(p);
+ query_buf_size = init_query_buf_size;
+
+ for (table=thd->temporary_tables ; table ; table=table->next)
+ {
+ query_buf_size += table->key_length;
+
+ }
+
+ if(query_buf_size == init_query_buf_size)
+ return; // no tables to close
+
+ if((query = alloc_root(&thd->mem_root, query_buf_size)))
+ {
+ memcpy(query, "drop table ", init_query_buf_size);
+ p = query + init_query_buf_size;
+ }
+
for (table=thd->temporary_tables ; table ; table=next)
{
+ if(query) // we might be out of memory, but this is not fatal
+ {
+ p = strmov(p,table->table_cache_key); // here we assume it always starts
+ // with \0 terminated db name
+ *p++ = '.';
+ p = strmov(p,table->table_name);
+ *p++ = ',';
+ }
next=table->next;
close_temporary(table);
}
+ if(query && mysql_bin_log.is_open())
+ {
+ uint save_query_len = thd->query_length;
+ *--p = 0;
+ thd->query_length = (uint)(p-query);
+ Query_log_event qinfo(thd, query);
+ mysql_bin_log.write(&qinfo);
+ thd->query_length = save_query_len;
+ }
thd->temporary_tables=0;
}
@@ -437,6 +474,9 @@ TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name)
uint key_length= (uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
TABLE *table,**prev;
+ *((ulong*)(key+key_length)) = thd->slave_proxy_id;
+ key_length += 4;
+
prev= &thd->temporary_tables;
for (table=thd->temporary_tables ; table ; table=table->next)
{
@@ -457,21 +497,25 @@ bool close_temporary_table(THD *thd, const char *db, const char *table_name)
table= *prev;
*prev= table->next;
close_temporary(table);
+ if(thd->slave_thread)
+ --slave_open_temp_tables;
return 0;
}
-bool rename_temporary_table(TABLE *table, const char *db,
+bool rename_temporary_table(THD* thd, TABLE *table, const char *db,
const char *table_name)
{
char *key;
if (!(key=(char*) alloc_root(&table->mem_root,
(uint) strlen(db)+
- (uint) strlen(table_name)+2)))
+ (uint) strlen(table_name)+6)))
return 1; /* purecov: inspected */
table->key_length=(uint)
(strmov((table->real_name=strmov(table->table_cache_key=key,
db)+1),
table_name) - table->table_cache_key)+1;
+ *((ulong*)(key+table->key_length)) = thd->slave_proxy_id;
+ table->key_length += 4;
return 0;
}
@@ -624,8 +668,10 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
*refresh=0;
if (thd->killed)
DBUG_RETURN(0);
- key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
-
+ key_length= (uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
+ *((ulong*)(key + key_length)) = thd->slave_proxy_id;
+ key_length += 4;
+
for (table=thd->temporary_tables; table ; table=table->next)
{
if (table->key_length == key_length &&
@@ -1339,8 +1385,14 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
{
TABLE *tmp_table;
DBUG_ENTER("open_temporary_table");
+
+ // the extra size in my_malloc() is for table_cache_key
+ // 4 bytes for master thread id if we are in the slave
+ // 1 byte to terminate db
+ // 1 byte to terminate table_name
+ // total of 6 extra bytes in my_malloc in addition to table/db stuff
if (!(tmp_table=(TABLE*) my_malloc(sizeof(*tmp_table)+(uint) strlen(db)+
- (uint) strlen(table_name)+2,
+ (uint) strlen(table_name)+6,
MYF(MY_WME))))
DBUG_RETURN(0); /* purecov: inspected */
@@ -1361,10 +1413,16 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
tmp_table->key_length= (uint) (strmov(strmov(tmp_table->table_cache_key,db)
+1, table_name)
- tmp_table->table_cache_key)+1;
+ *((ulong*)(tmp_table->table_cache_key + tmp_table->key_length)) =
+ thd->slave_proxy_id;
+ tmp_table->key_length += 4;
+
if (link_in_list)
{
tmp_table->next=thd->temporary_tables;
thd->temporary_tables=tmp_table;
+ if(thd->slave_thread)
+ ++slave_open_temp_tables;
}
DBUG_RETURN(tmp_table);
}