MCPcopy Create free account
hub / github.com/MariaDB/server / truncate_table

Method truncate_table

sql/sql_truncate.cc:445–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443*/
444
445bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
446{
447 int error;
448 bool binlog_stmt;
449 DBUG_ENTER("Sql_cmd_truncate_table::truncate_table");
450
451 DBUG_ASSERT((!table_ref->table) ||
452 (table_ref->table && table_ref->table->s));
453
454 /* Initialize, or reinitialize in case of reexecution (SP). */
455 m_ticket_downgrade= NULL;
456
457 /* If it is a temporary table, no need to take locks. */
458 if (is_temporary_table(table_ref))
459 {
460 /*
461 In RBR, the statement is not binlogged if the table is temporary or
462 table is not up to date in binlog.
463 */
464 binlog_stmt= (!thd->is_binlog_format_row() &&
465 table_ref->table->s->using_binlog());
466
467 thd->close_unused_temporary_table_instances(table_ref);
468
469 error= handler_truncate(thd, table_ref, TRUE);
470
471 /*
472 No need to invalidate the query cache, queries with temporary
473 tables are not in the cache. No need to write to the binary
474 log a failed row-by-row delete even if under RBR as the table
475 might not exist on the slave.
476 */
477 }
478 else /* It's not a temporary table. */
479 {
480 bool hton_can_recreate;
481
482#ifdef WITH_WSREP
483 if (WSREP(thd) && wsrep_thd_is_local(thd))
484 {
485 wsrep::key_array keys;
486 /* Do not start TOI if table is not found */
487 if (!wsrep_append_fk_parent_table(thd, table_ref, &keys))
488 {
489 if (keys.empty())
490 {
491 if (wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, NULL))
492 DBUG_RETURN(TRUE);
493 }
494 else
495 {
496 if (wsrep_to_isolation_begin(thd, NULL, NULL, table_ref, NULL, &keys))
497 DBUG_RETURN(TRUE);
498 }
499 }
500 }
501#endif /* WITH_WSREP */
502

Callers

nothing calls this directly

Calls 15

is_temporary_tableFunction · 0.85
wsrep_to_isolation_beginFunction · 0.85
dd_recreate_tableFunction · 0.85
write_bin_logFunction · 0.85
is_binlog_format_rowMethod · 0.80
using_binlogMethod · 0.80
reopen_tablesMethod · 0.80
query_lengthMethod · 0.80
downgrade_lockMethod · 0.80
wsrep_thd_is_localFunction · 0.70

Tested by

no test coverage detected