Commit ecf9b1b7 authored by Michael Widenius's avatar Michael Widenius

Fixed some wrong format strings.

Fixed OPTIMIZE with innodb


include/my_sys.h:
  Removed ATTRIBUTE_FORMAT() as it gave warnings for %'s
sql/log_event.cc:
  Optimization: 
  use my_b_write() and my_b_write_byte() instead of my_b_printf()
  use strmake() instead of my_snprintf()
sql/sql_admin.cc:
  Fixed bug in admin_recreate_table()
  Fixed OPTIMIZE with innodb
sql/sql_table.cc:
  Indentation fixes
strings/my_vsnprintf.c:
  Changed fprintf() to fputs()
parent 70092601
......@@ -782,8 +782,7 @@ extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
extern my_off_t my_b_filelength(IO_CACHE *info);
extern size_t my_b_write_backtick_quote(IO_CACHE *info, const char *str,
size_t len);
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...)
ATTRIBUTE_FORMAT(printf, 2, 3);
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
const char *prefix, size_t cache_size,
......
......@@ -2452,7 +2452,6 @@ MODIFY subject varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
MODIFY p varchar(255) CHARACTER SET utf8;
Warnings:
Warning 1071 Specified key was too long; max key length is 1000 bytes
Warning 1071 Specified key was too long; max key length is 1000 bytes
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
......
This diff is collapsed.
......@@ -42,6 +42,15 @@ static bool admin_recreate_table(THD *thd, TABLE_LIST *table_list)
trans_rollback(thd);
close_thread_tables(thd);
thd->mdl_context.release_transactional_locks();
/*
table_list->table has been closed and freed. Do not reference
uninitialized data. open_tables() could fail.
*/
table_list->table= NULL;
/* Same applies to MDL ticket. */
table_list->mdl_request.ticket= NULL;
DEBUG_SYNC(thd, "ha_admin_try_alter");
tmp_disable_binlog(thd); // binlogging is done by caller if wanted
result_code= (open_temporary_tables(thd, table_list) ||
......@@ -830,43 +839,61 @@ send_result_message:
case HA_ADMIN_TRY_ALTER:
{
/*
This is currently used only by InnoDB. ha_innobase::optimize() answers
"try with alter", so here we close the table, do an ALTER TABLE,
reopen the table and do ha_innobase::analyze() on it.
We have to end the row, so analyze could return more rows.
*/
Alter_info *alter_info= &lex->alter_info;
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
protocol->store(STRING_WITH_LEN(
"Table does not support optimize, doing recreate + analyze instead"),
system_charset_info);
if (alter_info->flags & Alter_info::ALTER_ADMIN_PARTITION)
{
protocol->store(STRING_WITH_LEN(
"Table does not support optimize on partitions. All partitions "
"will be rebuilt and analyzed."),system_charset_info);
}
else
{
protocol->store(STRING_WITH_LEN(
"Table does not support optimize, doing recreate + analyze instead"),
system_charset_info);
}
if (protocol->write())
goto err;
DBUG_PRINT("info", ("HA_ADMIN_TRY_ALTER, trying analyze..."));
TABLE_LIST *save_next_local= table->next_local,
*save_next_global= table->next_global;
table->next_local= table->next_global= 0;
result_code= admin_recreate_table(thd, table);
tmp_disable_binlog(thd); // binlogging is done by caller if wanted
result_code= admin_recreate_table(thd, table);
reenable_binlog(thd);
trans_commit_stmt(thd);
trans_commit(thd);
close_thread_tables(thd);
thd->mdl_context.release_transactional_locks();
/* Clear references to TABLE and MDL_ticket after releasing them. */
table->mdl_request.ticket= NULL;
if (!result_code) // recreation went ok
{
/* Clear the ticket released above. */
table->mdl_request.ticket= NULL;
DEBUG_SYNC(thd, "ha_admin_open_ltable");
table->mdl_request.set_type(MDL_SHARED_WRITE);
if (open_temporary_tables(thd, table) ||
if (!open_temporary_tables(thd, table) &&
(table->table= open_ltable(thd, table, lock_type, 0)))
{
uint save_flags;
/* Store the original value of alter_info->flags */
save_flags= alter_info->flags;
/*
Reset the ALTER_ADMIN_PARTITION bit in alter_info->flags
to force analyze on all partitions.
*/
alter_info->flags &= ~(Alter_info::ALTER_ADMIN_PARTITION);
result_code= table->table->file->ha_analyze(thd, check_opt);
if (result_code == HA_ADMIN_ALREADY_DONE)
result_code= HA_ADMIN_OK;
else if (result_code) // analyze failed
table->table->file->print_error(result_code, MYF(0));
alter_info->flags= save_flags;
}
else
result_code= -1; // open failed
......@@ -899,6 +926,9 @@ send_result_message:
}
thd->clear_error();
}
/* Make sure this table instance is not reused after the operation. */
if (table->table)
table->table->m_needs_reopen= true;
}
result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
table->next_local= save_next_local;
......@@ -997,14 +1027,15 @@ send_result_message:
err:
/* Make sure this table instance is not reused after the failure. */
if (table && table->table)
table->table->m_needs_reopen= true;
trans_rollback_stmt(thd);
trans_rollback(thd);
if (table && table->table)
{
table->table->m_needs_reopen= true;
table->table= 0;
}
close_thread_tables(thd); // Shouldn't be needed
thd->mdl_context.release_transactional_locks();
if (table)
table->table=0;
DBUG_RETURN(TRUE);
}
......
......@@ -8656,13 +8656,14 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
RETURN
Like mysql_alter_table().
*/
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list)
{
HA_CREATE_INFO create_info;
Alter_info alter_info;
DBUG_ENTER("mysql_recreate_table");
DBUG_ASSERT(!table_list->next_global);
/* Set lock type which is appropriate for ALTER TABLE. */
table_list->lock_type= TL_READ_NO_INSERT;
/* Same applies to MDL request. */
......
......@@ -735,7 +735,7 @@ int my_vfprintf(FILE *stream, const char* format, va_list args)
char cvtbuf[1024];
int alloc= 0;
char *p= cvtbuf;
size_t cur_len= sizeof(cvtbuf);
size_t cur_len= sizeof(cvtbuf), actual;
int ret;
/*
......@@ -746,7 +746,7 @@ int my_vfprintf(FILE *stream, const char* format, va_list args)
for (;;)
{
size_t new_len;
size_t actual= my_vsnprintf(p, cur_len, format, args);
actual= my_vsnprintf(p, cur_len, format, args);
if (actual < cur_len - 1)
break;
/*
......@@ -766,7 +766,9 @@ int my_vfprintf(FILE *stream, const char* format, va_list args)
if (!p)
return 0;
}
ret= fprintf(stream, "%s", p);
ret= (int) actual;
if (fputs(p, stream) < 0)
ret= -1;
if (alloc)
(*my_str_free)(p);
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment