410
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)
413
bool mysql_truncate(Session& session, TableList *table_list, bool dont_send_ok)
415
415
HA_CREATE_INFO create_info;
416
416
char path[FN_REFLEN];
419
419
uint32_t path_length;
420
message::Table tmp_table;
422
423
memset(&create_info, 0, sizeof(create_info));
423
424
/* If it is a temporary table, close and regenerate it */
424
if (!dont_send_ok && (table= session->find_temporary_table(table_list)))
425
if (!dont_send_ok && (table= session.find_temporary_table(table_list)))
427
message::Table::StorageEngine *engine= tmp_table.mutable_engine();
426
428
plugin::StorageEngine *table_type= table->s->db_type();
427
429
TableShare *share= table->s;
432
434
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
434
session->close_temporary_table(table, false, false); // Don't free share
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());
435
447
plugin::StorageEngine::createTable(session, share->normalized_path.str,
436
share->db.str, share->table_name.str, &create_info,
448
share->db.str, share->table_name.str, create_info,
449
true, tmp_table, false);
438
450
// We don't need to call invalidate() because this table is not in cache
439
if ((error= (int) !(session->open_temporary_table(share->path.str,
451
if ((error= (int) !(session.open_temporary_table(share->path.str,
441
453
share->table_name.str, 1,
443
(void) session->rm_temporary_table(table_type, path);
455
(void) session.rm_temporary_table(table_type, path);
444
456
share->free_table_share();
445
457
free((char*) table);
459
471
pthread_mutex_lock(&LOCK_open); /* Recreate table for truncate */
460
472
error= plugin::StorageEngine::createTable(session, path, table_list->db, table_list->table_name,
461
&create_info, true, NULL);
473
create_info, true, tmp_table, false);
462
474
pthread_mutex_unlock(&LOCK_open);
470
482
TRUNCATE must always be statement-based binlogged (not row-based) so
471
483
we don't test current_stmt_binlog_row_based.
473
write_bin_log(session, session->query, session->query_length);
474
session->my_ok(); // This should return record count
485
write_bin_log(&session, session.query, session.query_length);
486
session.my_ok(); // This should return record count
476
488
pthread_mutex_lock(&LOCK_open); /* For truncate delete from hash when finished */
477
489
unlock_table_name(table_list);
489
501
/* Probably InnoDB table */
490
uint64_t save_options= session->options;
502
uint64_t save_options= session.options;
491
503
table_list->lock_type= TL_WRITE;
492
session->options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
493
ha_enable_transaction(session, false);
494
mysql_init_select(session->lex);
495
error= mysql_delete(session, table_list, (COND*) 0, (SQL_LIST*) 0,
504
session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
505
ha_enable_transaction(&session, false);
506
mysql_init_select(session.lex);
507
error= mysql_delete(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
496
508
HA_POS_ERROR, 0L, true);
497
ha_enable_transaction(session, true);
509
ha_enable_transaction(&session, true);
499
511
Safety, in case the engine ignored ha_enable_transaction(false)
500
512
above. Also clears session->transaction.*.
502
error= ha_autocommit_or_rollback(session, error);
504
session->options= save_options;
514
error= ha_autocommit_or_rollback(&session, error);
516
session.options= save_options;