mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Merge sgluhov@bk-internal.mysql.com:/home/bk/mysql-5.0
into gluh.mysql.r18.ru:/home/gluh/MySQL/mysql-5.0 sql/sql_base.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/table.h: Auto merged
This commit is contained in:
@ -497,58 +497,58 @@ void close_temporary(TABLE *table,bool delete_table)
|
||||
void close_temporary_tables(THD *thd)
|
||||
{
|
||||
TABLE *table,*next;
|
||||
char *query, *end;
|
||||
uint query_buf_size;
|
||||
bool found_user_tables = 0;
|
||||
char *query, *name_in_query, *end;
|
||||
uint greatest_key_length= 0;
|
||||
|
||||
if (!thd->temporary_tables)
|
||||
return;
|
||||
|
||||
/*
|
||||
We write a DROP TEMPORARY TABLE for each temp table left, so that our
|
||||
replication slave can clean them up. Not one multi-table DROP TABLE binlog
|
||||
event: this would cause problems if slave uses --replicate-*-table.
|
||||
*/
|
||||
LINT_INIT(end);
|
||||
query_buf_size= 50; // Enough for DROP ... TABLE IF EXISTS
|
||||
|
||||
/* We'll re-use always same buffer so make it big enough for longest name */
|
||||
for (table=thd->temporary_tables ; table ; table=table->next)
|
||||
/*
|
||||
We are going to add 4 ` around the db/table names, so 1 does not look
|
||||
enough; indeed it is enough, because table->key_length is greater (by 8,
|
||||
because of server_id and thread_id) than db||table.
|
||||
*/
|
||||
query_buf_size+= table->s->key_length+1;
|
||||
greatest_key_length= max(greatest_key_length, table->s->key_length);
|
||||
|
||||
if ((query = alloc_root(thd->mem_root, query_buf_size)))
|
||||
if ((query = alloc_root(thd->mem_root, greatest_key_length+50)))
|
||||
// Better add "if exists", in case a RESET MASTER has been done
|
||||
end=strmov(query, "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS ");
|
||||
name_in_query= strmov(query, "DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `");
|
||||
|
||||
for (table=thd->temporary_tables ; table ; table=next)
|
||||
{
|
||||
if (query) // we might be out of memory, but this is not fatal
|
||||
/*
|
||||
In we are OOM for 'query' this is not fatal. We skip temporary tables
|
||||
not created directly by the user.
|
||||
*/
|
||||
if (query && mysql_bin_log.is_open() && (table->s->table_name[0] != '#'))
|
||||
{
|
||||
// skip temporary tables not created directly by the user
|
||||
if (table->s->table_name[0] != '#')
|
||||
found_user_tables = 1;
|
||||
end = strxmov(end,"`",table->s->db,"`.`",
|
||||
table->s->table_name,"`,", NullS);
|
||||
/*
|
||||
Here we assume table_cache_key always starts
|
||||
with \0 terminated db name
|
||||
*/
|
||||
end = strxmov(name_in_query, table->s->db, "`.`",
|
||||
table->s->table_name, "`", NullS);
|
||||
Query_log_event qinfo(thd, query, (ulong)(end-query), 0, FALSE);
|
||||
/*
|
||||
Imagine the thread had created a temp table, then was doing a SELECT, and
|
||||
the SELECT was killed. Then it's not clever to mark the statement above as
|
||||
"killed", because it's not really a statement updating data, and there
|
||||
are 99.99% chances it will succeed on slave. And, if thread is
|
||||
killed now, it's not clever either.
|
||||
If a real update (one updating a persistent table) was killed on the
|
||||
master, then this real update will be logged with error_code=killed,
|
||||
rightfully causing the slave to stop.
|
||||
*/
|
||||
qinfo.error_code= 0;
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
next=table->next;
|
||||
close_temporary(table);
|
||||
}
|
||||
if (query && found_user_tables && mysql_bin_log.is_open())
|
||||
{
|
||||
/* The -1 is to remove last ',' */
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, query, (ulong)(end-query)-1, 0, FALSE);
|
||||
/*
|
||||
Imagine the thread had created a temp table, then was doing a SELECT, and
|
||||
the SELECT was killed. Then it's not clever to mark the statement above as
|
||||
"killed", because it's not really a statement updating data, and there
|
||||
are 99.99% chances it will succeed on slave.
|
||||
If a real update (one updating a persistent table) was killed on the
|
||||
master, then this real update will be logged with error_code=killed,
|
||||
rightfully causing the slave to stop.
|
||||
*/
|
||||
qinfo.error_code= 0;
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
thd->temporary_tables=0;
|
||||
}
|
||||
|
||||
@ -854,7 +854,7 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
|
||||
table->tablenr=thd->current_tablenr++;
|
||||
table->used_fields=0;
|
||||
table->const_table=0;
|
||||
table->outer_join= table->null_row= table->maybe_null= table->force_index= 0;
|
||||
table->null_row= table->maybe_null= table->force_index= 0;
|
||||
table->status=STATUS_NO_RECORD;
|
||||
table->keys_in_use_for_query= share->keys_in_use;
|
||||
table->used_keys= share->keys_for_keyread;
|
||||
@ -1078,7 +1078,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
|
||||
table->tablenr=thd->current_tablenr++;
|
||||
table->used_fields=0;
|
||||
table->const_table=0;
|
||||
table->outer_join= table->null_row= table->maybe_null= table->force_index= 0;
|
||||
table->null_row= table->maybe_null= table->force_index= 0;
|
||||
table->status=STATUS_NO_RECORD;
|
||||
table->keys_in_use_for_query= table->s->keys_in_use;
|
||||
table->insert_values= 0;
|
||||
@ -1150,7 +1150,6 @@ bool reopen_table(TABLE *table,bool locked)
|
||||
tmp.tablenr= table->tablenr;
|
||||
tmp.used_fields= table->used_fields;
|
||||
tmp.const_table= table->const_table;
|
||||
tmp.outer_join= table->outer_join;
|
||||
tmp.null_row= table->null_row;
|
||||
tmp.maybe_null= table->maybe_null;
|
||||
tmp.status= table->status;
|
||||
|
Reference in New Issue
Block a user