287
table->file->unlock_row(); // Row failed selection, release lock on it
287
table->cursor->unlock_row(); // Row failed selection, release lock on it
289
289
killed_status= session->killed;
290
290
if (killed_status != Session::NOT_KILLED || session->is_error())
291
291
error= 1; // Aborted
292
if (will_batch && (loc_error= table->file->end_bulk_delete()))
292
if (will_batch && (loc_error= table->cursor->end_bulk_delete()))
295
table->file->print_error(loc_error,MYF(0));
295
table->cursor->print_error(loc_error,MYF(0));
298
298
session->set_proc_info("end");
299
299
end_read_record(&info);
300
300
if (options & OPTION_QUICK)
301
(void) table->file->extra(HA_EXTRA_NORMAL);
301
(void) table->cursor->extra(HA_EXTRA_NORMAL);
303
305
if (reset_auto_increment && (error < 0))
306
308
We're really doing a truncate and need to reset the table's
307
309
auto-increment counter.
309
int error2= table->file->ha_reset_auto_increment(0);
311
int error2= table->cursor->ha_reset_auto_increment(0);
311
313
if (error2 && (error2 != HA_ERR_WRONG_COMMAND))
313
table->file->print_error(error2, MYF(0));
315
table->cursor->print_error(error2, MYF(0));
321
transactional_table= table->file->has_transactions();
321
transactional_table= table->cursor->has_transactions();
323
323
if (!transactional_table && deleted > 0)
324
324
session->transaction.stmt.modified_non_trans_table= true;
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);