402
402
Optimize delete of all rows by doing a full generate of the table
403
403
This will work even if the .ISM and .ISD tables are destroyed
405
dont_send_ok should be set if:
406
- We should always wants to generate the table (even if the table type
407
normally can't safely do this.
408
- We don't want an ok to be sent to the end user.
409
- We don't want to log the truncate command
410
- If we want to have a name lock on the table on exit without errors.
413
bool mysql_truncate(Session& session, TableList *table_list, bool dont_send_ok)
406
bool mysql_truncate(Session& session, TableList *table_list)
415
HA_CREATE_INFO create_info;
416
char path[FN_REFLEN];
419
uint32_t path_length;
420
message::Table tmp_table;
423
memset(&create_info, 0, sizeof(create_info));
424
/* If it is a temporary table, close and regenerate it */
425
if (!dont_send_ok && (table= session.find_temporary_table(table_list)))
427
message::Table::StorageEngine *engine= tmp_table.mutable_engine();
428
plugin::StorageEngine *table_type= table->s->db_type();
429
TableShare *share= table->s;
431
if (!table_type->check_flag(HTON_BIT_CAN_RECREATE))
434
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
437
Because we bypass "all" of what it takes to create a Table we are on shakey ground in this
438
execution path. Not everything will be properly created in order to use the table
443
assert(share->storage_engine);
444
session.close_temporary_table(table, false, false); // Don't free share
445
assert(share->storage_engine);
446
engine->set_name(share->db_type()->getName());
447
plugin::StorageEngine::createTable(session, share->normalized_path.str,
448
share->db.str, share->table_name.str, create_info,
449
true, tmp_table, false);
450
// We don't need to call invalidate() because this table is not in cache
451
if ((error= (int) !(session.open_temporary_table(share->path.str,
453
share->table_name.str, 1,
455
(void) session.rm_temporary_table(table_type, path);
456
share->free_table_share();
459
If we return here we will not have logged the truncation to the bin log
460
and we will not my_ok() to the client.
465
path_length= build_table_filename(path, sizeof(path), table_list->db,
466
table_list->table_name, 0);
471
pthread_mutex_lock(&LOCK_open); /* Recreate table for truncate */
472
error= plugin::StorageEngine::createTable(session, path, table_list->db, table_list->table_name,
473
create_info, true, tmp_table, false);
474
pthread_mutex_unlock(&LOCK_open);
482
TRUNCATE must always be statement-based binlogged (not row-based) so
483
we don't test current_stmt_binlog_row_based.
485
write_bin_log(&session, session.query, session.query_length);
486
session.my_ok(); // This should return record count
488
pthread_mutex_lock(&LOCK_open); /* For truncate delete from hash when finished */
489
unlock_table_name(table_list);
490
pthread_mutex_unlock(&LOCK_open);
494
pthread_mutex_lock(&LOCK_open); /* For truncate delete from hash when finished */
495
unlock_table_name(table_list);
496
pthread_mutex_unlock(&LOCK_open);
501
/* Probably InnoDB table */
502
410
uint64_t save_options= session.options;
503
411
table_list->lock_type= TL_WRITE;
504
412
session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);