2257
2255
session->client->store(STRING_WITH_LEN("Invalid argument"));
2260
case HA_ADMIN_TRY_ALTER:
2263
This is currently used only by InnoDB. ha_innobase::optimize() answers
2264
"try with alter", so here we close the table, do an ALTER Table,
2265
reopen the table and do ha_innobase::analyze() on it.
2267
ha_autocommit_or_rollback(session, 0);
2268
session->close_thread_tables();
2269
TableList *save_next_local= table->next_local,
2270
*save_next_global= table->next_global;
2271
table->next_local= table->next_global= 0;
2272
result_code= mysql_recreate_table(session, table);
2274
mysql_recreate_table() can push OK or ERROR.
2275
Clear 'OK' status. If there is an error, keep it:
2276
we will store the error message in a result set row
2279
if (session->main_da.is_ok())
2280
session->main_da.reset_diagnostics_area();
2281
ha_autocommit_or_rollback(session, 0);
2282
session->close_thread_tables();
2283
if (!result_code) // recreation went ok
2285
if ((table->table= session->openTableLock(table, lock_type)) &&
2286
((result_code= table->table->cursor->ha_analyze(session, check_opt)) > 0))
2287
result_code= 0; // analyze went ok
2289
if (result_code) // either mysql_recreate_table or analyze failed
2291
assert(session->is_error());
2292
if (session->is_error())
2294
const char *err_msg= session->main_da.message();
2295
/* Hijack the row already in-progress. */
2296
session->client->store(STRING_WITH_LEN("error"));
2297
session->client->store(err_msg);
2298
(void)session->client->flush();
2299
/* Start off another row for HA_ADMIN_FAILED */
2300
session->client->store(table_name);
2301
session->client->store(operator_name);
2302
session->clear_error();
2305
result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
2306
table->next_local= save_next_local;
2307
table->next_global= save_next_global;
2308
goto send_result_message;
2310
case HA_ADMIN_NEEDS_UPGRADE:
2311
case HA_ADMIN_NEEDS_ALTER:
2313
char buf[ERRMSGSIZE];
2316
session->client->store(STRING_WITH_LEN("error"));
2317
length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
2318
session->client->store(buf, length);
2323
2258
default: // Probably HA_ADMIN_INTERNAL_ERROR
2325
2260
char buf[ERRMSGSIZE+20];
2372
bool mysql_optimize_table(Session* session, TableList* tables, HA_CHECK_OPT* check_opt)
2374
return(mysql_admin_table(session, tables, check_opt,
2375
"optimize", TL_WRITE, 1,0,0,0,
2376
&Cursor::ha_optimize));
2380
2308
Create a table identical to the specified table